1212 PyPtr, (Int,), i))
1313else
1414 PyObject (i:: Unsigned ) = PyObject (@pycheckn ccall (@pysym (:PyLong_FromUnsignedLongLong ),
15- PyPtr, (Culonglong,), i))
15+ PyPtr, (Culonglong,), i))
1616 PyObject (i:: Integer ) = PyObject (@pycheckn ccall (@pysym (:PyLong_FromLongLong ),
1717 PyPtr, (Clonglong,), i))
1818end
@@ -80,8 +80,8 @@ function PyObject(s::AbstractString)
8080 sb = String (s)
8181 if pyunicode_literals || ! isascii (sb)
8282 PyObject (@pycheckn ccall (@pysym (PyUnicode_DecodeUTF8),
83- PyPtr, (Ptr{UInt8}, Int, Ptr{UInt8}),
84- sb, sizeof (sb), C_NULL ))
83+ PyPtr, (Ptr{UInt8}, Int, Ptr{UInt8}),
84+ sb, sizeof (sb), C_NULL ))
8585 else
8686 pybytes (sb)
8787 end
@@ -92,7 +92,7 @@ const _ps_len = Int[0]
9292function convert (:: Type{T} , po:: PyObject ) where T<: AbstractString
9393 if pyisinstance (po, @pyglobalobj :PyUnicode_Type )
9494 convert (T, PyObject (@pycheckn ccall (@pysym (PyUnicode_AsUTF8String),
95- PyPtr, (PyPtr,), po)))
95+ PyPtr, (PyPtr,), po)))
9696 else
9797 @pycheckz ccall (@pysym (PyString_AsStringAndSize),
9898 Cint, (PyPtr, Ptr{Ptr{UInt8}}, Ptr{Int}),
@@ -223,8 +223,8 @@ function convert(tt::Type{T}, o::PyObject) where T<:Tuple
223223 end
224224 ntuple ((i ->
225225 convert (tuptype (T, isva, i),
226- PyObject (ccall ((@pysym :PySequence_GetItem ), PyPtr,
227- (PyPtr, Int), o, i- 1 )))),
226+ PyObject (@with_gil ccall ((@pysym :PySequence_GetItem ), PyPtr,
227+ (PyPtr, Int), o, i- 1 )))),
228228 len)
229229end
230230
@@ -346,7 +346,7 @@ function py2array(T, A::Array{TA,N}, o::PyObject,
346346 error (" dimension mismatch in py2array" )
347347 end
348348 s = stride (A, dim)
349- for j = 0 : len- 1
349+ @with_gil for j = 0 : len- 1
350350 A[i+ j* s] = convert (T, PyObject (ccall ((@pysym :PySequence_GetItem ),
351351 PyPtr, (PyPtr, Int), o, j)))
352352 end
@@ -357,7 +357,7 @@ function py2array(T, A::Array{TA,N}, o::PyObject,
357357 error (" dimension mismatch in py2array" )
358358 end
359359 s = stride (A, dim)
360- for j = 0 : len- 1
360+ @with_gil for j = 0 : len- 1
361361 py2array (T, A, PyObject (ccall ((@pysym :PySequence_GetItem ),
362362 PyPtr, (PyPtr, Int), o, j)),
363363 dim+ 1 , i+ j* s)
@@ -376,13 +376,13 @@ function pyarray_dims(o::PyObject, forcelist=true)
376376 if len == 0
377377 return (0 ,)
378378 end
379- dims0 = pyarray_dims (PyObject (ccall ((@pysym :PySequence_GetItem ),
380- PyPtr, (PyPtr, Int), o, 0 )),
379+ dims0 = pyarray_dims (PyObject (@with_gil ( ccall ((@pysym :PySequence_GetItem ),
380+ PyPtr, (PyPtr, Int), o, 0 ) )),
381381 false )
382382 if isempty (dims0) # not a nested sequence
383383 return (len,)
384384 end
385- for j = 1 : len- 1
385+ @with_gil for j = 1 : len- 1
386386 dims = pyarray_dims (PyObject (ccall ((@pysym :PySequence_GetItem ),
387387 PyPtr, (PyPtr, Int), o, j)),
388388 false )
@@ -408,7 +408,7 @@ function py2array(T, o::PyObject)
408408end
409409
410410function py2vector (T, o:: PyObject )
411- len = ccall ((@pysym :PySequence_Size ), Int, (PyPtr,), o)
411+ len = @with_gil ccall ((@pysym :PySequence_Size ), Int, (PyPtr,), o)
412412 if len < 0 || # not a sequence
413413 len+ 1 < 0 # object pretending to be a sequence of infinite length
414414 pyerr_clear ()
@@ -435,7 +435,7 @@ include("numpy.jl")
435435function is_mapping_object (o:: PyObject )
436436 pyisinstance (o, @pyglobalobj :PyDict_Type ) ||
437437 (pyquery ((@pyglobal :PyMapping_Check ), o) &&
438- ccall ((@pysym :PyObject_HasAttrString ), Cint, (PyPtr,Ptr{UInt8}), o, " items" ) == 1 )
438+ @with_gil ( ccall ((@pysym :PyObject_HasAttrString ), Cint, (PyPtr,Ptr{UInt8}), o, " items" ) ) == 1 )
439439end
440440
441441"""
@@ -472,13 +472,13 @@ convert(::Type{PyDict}, o::PyObject) = PyDict(o)
472472convert (:: Type{PyDict{K,V}} , o:: PyObject ) where {K,V} = PyDict {K,V} (o)
473473unsafe_convert (:: Type{PyPtr} , d:: PyDict ) = PyPtr (d. o)
474474
475- haskey (d:: PyDict{K,V,true} , key) where {K,V} = 1 == ccall (@pysym (:PyDict_Contains ), Cint, (PyPtr, PyPtr), d, PyObject (key))
475+ haskey (d:: PyDict{K,V,true} , key) where {K,V} = 1 == @with_gil ( ccall (@pysym (:PyDict_Contains ), Cint, (PyPtr, PyPtr), d, PyObject (key) ))
476476keys (:: Type{T} , d:: PyDict{K,V,true} ) where {T,K,V} = convert (Vector{T}, PyObject (@pycheckn ccall ((@pysym :PyDict_Keys ), PyPtr, (PyPtr,), d)))
477477values (:: Type{T} , d:: PyDict{K,V,true} ) where {T,K,V} = convert (Vector{T}, PyObject (@pycheckn ccall ((@pysym :PyDict_Values ), PyPtr, (PyPtr,), d)))
478478
479479keys (:: Type{T} , d:: PyDict{K,V,false} ) where {T,K,V} = convert (Vector{T}, pycall (d. o[" keys" ], PyObject))
480480values (:: Type{T} , d:: PyDict{K,V,false} ) where {T,K,V} = convert (Vector{T}, pycall (d. o[" values" ], PyObject))
481- haskey (d:: PyDict{K,V,false} , key) where {K,V} = 1 == ccall (@pysym (:PyMapping_HasKey ), Cint, (PyPtr, PyPtr), d, PyObject (key))
481+ haskey (d:: PyDict{K,V,false} , key) where {K,V} = 1 == @with_gil ( ccall (@pysym (:PyMapping_HasKey ), Cint, (PyPtr, PyPtr), d, PyObject (key) ))
482482
483483similar (d:: PyDict{K,V} ) where {K,V} = Dict {pyany_toany(K),pyany_toany(V)} ()
484484eltype (:: Type{PyDict{K,V}} ) where {K,V} = Pair{pyany_toany (K),pyany_toany (V)}
@@ -515,12 +515,12 @@ function pop!(d::PyDict, k, default)
515515end
516516
517517function delete! (d:: PyDict{K,V,true} , k) where {K,V}
518- e = ccall (@pysym (:PyDict_DelItem ), Cint, (PyPtr, PyPtr), d, PyObject (k))
518+ e = @with_gil ccall (@pysym (:PyDict_DelItem ), Cint, (PyPtr, PyPtr), d, PyObject (k))
519519 e == - 1 && pyerr_clear () # delete! ignores errors in Julia
520520 return d
521521end
522522function delete! (d:: PyDict{K,V,false} , k) where {K,V}
523- e = ccall (@pysym (:PyObject_DelItem ), Cint, (PyPtr, PyPtr), d, PyObject (k))
523+ e = @with_gil ccall (@pysym (:PyObject_DelItem ), Cint, (PyPtr, PyPtr), d, PyObject (k))
524524 e == - 1 && pyerr_clear () # delete! ignores errors in Julia
525525 return d
526526end
553553
554554function Base. iterate (d:: PyDict{K,V,true} , itr= PyDict_Iterator (Ref {PyPtr} (), Ref {PyPtr} (), Ref (0 ), 0 , length (d))) where {K,V}
555555 itr. i >= itr. len && return nothing
556- if 0 == ccall ((@pysym :PyDict_Next ), Cint,
557- (PyPtr, Ref{Int}, Ref{PyPtr}, Ref{PyPtr}),
558- d, itr. pa, itr. ka, itr. va)
556+ if 0 == @with_gil ( ccall ((@pysym :PyDict_Next ), Cint,
557+ (PyPtr, Ref{Int}, Ref{PyPtr}, Ref{PyPtr}),
558+ d, itr. pa, itr. ka, itr. va) )
559559 error (" unexpected end of PyDict_Next" )
560560 end
561561 ko = pyincref (itr. ka[]) # PyDict_Next returns
@@ -751,7 +751,7 @@ function pysequence_query(o::PyObject)
751751 # problems
752752 if pyisinstance (o, @pyglobalobj :PyTuple_Type )
753753 len = length (o)
754- return typetuple (pytype_query (PyObject (ccall ((@pysym :PySequence_GetItem ), PyPtr, (PyPtr,Int), o,i- 1 )), PyAny) for i = 1 : len)
754+ return typetuple (pytype_query (PyObject (@with_gil ( ccall ((@pysym :PySequence_GetItem ), PyPtr, (PyPtr,Int), o,i- 1 ) )), PyAny) for i = 1 : len)
755755 elseif pyisinstance (o, pyxrange[])
756756 return AbstractRange
757757 elseif ispybytearray (o)
0 commit comments