diff --git a/src/callback.jl b/src/callback.jl index 0cd7152c..3ecabea7 100644 --- a/src/callback.jl +++ b/src/callback.jl @@ -15,9 +15,22 @@ # convert Python args to Julia; overridden below for a FuncWrapper type # that allows the user to specify the argument types. -julia_args(f, args) = convert(PyAny, args) +julia_args(f, args) = + [_julia_arg(_getindex(args, i, PyObject)) for i in 1:length(args)] julia_kwarg(f, kw, arg) = convert(PyAny, arg) +# For mutating functions such as fill! to mutate Python objects, +# arguments have to be wrapped by an appropriate wrapper (e.g., +# PyArray) rather than copying to a Julia object. +function _julia_arg(arg) + if haskey(PyCall.npy_api, :PyArray_Type) && + pyisinstance(arg, PyCall.npy_api[:PyArray_Type]) + return convert(PyArray, arg) + else + return convert(PyAny, arg) + end +end + function _pyjlwrap_call(f, args_::PyPtr, kw_::PyPtr) args = PyObject(args_) # don't need pyincref because of finally clause below try diff --git a/test/runtests.jl b/test/runtests.jl index 6f348a6c..fea4b623 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -151,6 +151,13 @@ const PyInt = pyversion < v"3" ? Int : Clonglong @test x == ["bar"] end + py""" + def apply(f, *args): + f(*args) + return args + """ + @test py"apply"(fill!, zeros(3), 10)[1] == [10, 10, 10] + @test roundtripeq(Dates.Date(2012,3,4)) @test roundtripeq(Dates.DateTime(2012,3,4, 7,8,9,11)) @test roundtripeq(Dates.Millisecond(typemax(Int32)))