Skip to content

Commit 75e93fc

Browse files
committed
Fix most of 0.7 depwarns
1 parent 0550f89 commit 75e93fc

File tree

10 files changed

+60
-42
lines changed

10 files changed

+60
-42
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
julia 0.5
2-
Compat 0.27.0
2+
Compat 0.30.0
33
Conda 0.2
44
MacroTools 0.3

deps/build.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function pythonenv(cmd::Cmd)
3636
setenv(cmd, env)
3737
end
3838

39-
pyvar(python::AbstractString, mod::AbstractString, var::AbstractString) = chomp(readstring(pythonenv(`$python -c "import $mod; print($mod.$var)"`)))
39+
pyvar(python::AbstractString, mod::AbstractString, var::AbstractString) = chomp(read(pythonenv(`$python -c "import $mod; print($mod.$var)"`), String))
4040

4141
pyconfigvar(python::AbstractString, var::AbstractString) = pyvar(python, "distutils.sysconfig", "get_config_var('$var')")
4242
pyconfigvar(python, var, default) = let v = pyconfigvar(python, var)
@@ -113,7 +113,7 @@ function find_libpython(python::AbstractString)
113113
print(s, "\n\n")
114114
end
115115
println(STDERR, "---------------------------------- get_config_vars ---------------------------------------")
116-
print(STDERR, readstring(`python -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_vars())"`))
116+
print(STDERR, read(`python -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_vars())"`, String))
117117
println(STDERR, "--------------------------------- directory contents -------------------------------------")
118118
for libpath in libpaths
119119
if isdir(libpath)
@@ -221,7 +221,7 @@ wstringconst(s) = string("Base.cconvert(Cwstring, \"", escape_string(s), "\")")
221221
# to prevent unnecessary recompilation and to minimize
222222
# problems in the unlikely event of read-only directories.
223223
function writeifchanged(filename, str)
224-
if !isfile(filename) || readstring(filename) != str
224+
if !isfile(filename) || read(filename, String) != str
225225
info(abspath(filename), " has been updated")
226226
write(filename, str)
227227
else

src/PyCall.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,15 @@ end
462462
macro pyimport(name, optional_varname...)
463463
mname = modulename(name)
464464
Name = pyimport_name(name, optional_varname)
465+
quoteName = Expr(:quote, Name)
466+
# VERSION 0.7
467+
@static if isdefined(Base, Symbol("@isdefined"))
468+
isdef_check = :(isdefined($__module__, $quoteName))
469+
else
470+
isdef_check = :(isdefined($quoteName))
471+
end
465472
quote
466-
if !isdefined($(Expr(:quote, Name)))
473+
if !$isdef_check
467474
const $(esc(Name)) = pywrap(pyimport($mname))
468475
elseif !isa($(esc(Name)), Module)
469476
error("@pyimport: ", $(Expr(:quote, Name)), " already defined")

src/io.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function pyio_initialize()
108108
String(read(pyio_jl(self), nb < 0 ? typemax(Int) : nb)) :
109109
pybytes(read(pyio_jl(self), nb < 0 ? typemax(Int) : nb)))
110110
readall(self) =
111-
@with_ioraise(self[:istextio] ? readstring(pyio_jl(self)) :
111+
@with_ioraise(self[:istextio] ? read(pyio_jl(self), String) :
112112
pybytes(read(pyio_jl(self))))
113113
readinto(self, b) = @with_ioraise(pybytes(readbytes!(pyio_jl(self), b)))
114114
write(self, b) = @with_ioraise(write(pyio_jl(self), b))

src/numpy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function npyinitialize()
7474
# Parse __multiarray_api.h to obtain length and meaning of PyArray_API
7575
try
7676
hdrfile = open(joinpath(inc, "numpy", "__multiarray_api.h"))
77-
hdr = readstring(hdrfile);
77+
hdr = read(hdrfile, String)
7878
close(hdrfile)
7979
catch e
8080
error("could not read __multiarray_api.h to parse PyArray_API ", e)

src/pybuffer.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ end
4040
function pydecref(o::PyBuffer)
4141
# note that PyBuffer_Release sets o.obj to NULL, and
4242
# is a no-op if o.obj is already NULL
43-
ccall(@pysym(:PyBuffer_Release), Void, (Ptr{PyBuffer},), &o)
43+
# TODO change to `Ref{PyBuffer}` when 0.6 is dropped.
44+
ccall(@pysym(:PyBuffer_Release), Void, (Any,), o)
4445
o
4546
end
4647

@@ -85,9 +86,10 @@ function Base.stride(b::PyBuffer, d::Integer)
8586
return Int(unsafe_load(b.buf.strides, d))
8687
end
8788

89+
# TODO change to `Ref{PyBuffer}` when 0.6 is dropped.
8890
iscontiguous(b::PyBuffer) =
8991
1 == ccall((@pysym :PyBuffer_IsContiguous), Cint,
90-
(Ptr{PyBuffer}, Cchar), &b, 'A')
92+
(Any, Cchar), b, 'A')
9193

9294
#############################################################################
9395
# pybuffer constant values from Include/object.h
@@ -105,8 +107,9 @@ const PyBUF_INDIRECT = convert(Cint, 0x0100) | PyBUF_STRIDES
105107
# construct a PyBuffer from a PyObject, if possible
106108
function PyBuffer(o::Union{PyObject,PyPtr}, flags=PyBUF_SIMPLE)
107109
b = PyBuffer()
110+
# TODO change to `Ref{PyBuffer}` when 0.6 is dropped.
108111
@pycheckz ccall((@pysym :PyObject_GetBuffer), Cint,
109-
(PyPtr, Ptr{PyBuffer}, Cint), o, &b, flags)
112+
(PyPtr, Any, Cint), o, b, flags)
110113
return b
111114
end
112115

src/pyinit.jl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ const pyxrange = Ref{PyPtr}(0)
2323

2424
#########################################################################
2525

26+
type EmptyStringList
27+
x::Int32
28+
ptr::Ptr{Int32}
29+
function EmptyStringList()
30+
obj = new(0)
31+
obj.ptr = pointer_from_objref(obj)
32+
return obj
33+
end
34+
end
35+
Base.unsafe_convert(::Type{Ptr{UInt32}}, x::EmptyStringList) =
36+
Ptr{UInt32}(pointer_from_objref(x) + fieldoffset(EmptyStringList, 2))
37+
2638
function __init__()
2739
# issue #189
2840
libpy_handle = libpython === nothing ? C_NULL :
@@ -87,15 +99,7 @@ function __init__()
8799

88100
if !already_inited
89101
# some modules (e.g. IPython) expect sys.argv to be set
90-
if pyversion.major < 3
91-
argv_s = ""
92-
argv = unsafe_convert(Ptr{UInt8}, argv_s)
93-
ccall(@pysym(:PySys_SetArgvEx), Void, (Cint,Ptr{Ptr{UInt8}},Cint), 1, &argv, 0)
94-
else
95-
argv_s = Cwchar_t[0]
96-
argv = unsafe_convert(Ptr{Cwchar_t}, argv_s)
97-
ccall(@pysym(:PySys_SetArgvEx), Void, (Cint, Ptr{Ptr{Cwchar_t}}, Cint), 1, &argv, 0)
98-
end
102+
ccall(@pysym(:PySys_SetArgvEx), Void, (Cint, Ptr{UInt32}, Cint), 1, EmptyStringList(), 0)
99103

100104
# Some Python code checks sys.ps1 to see if it is running
101105
# interactively, and refuses to be interactive otherwise.

src/pyiterator.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ const jlWrapIteratorType = PyTypeObject()
4949
function jlwrap_iterator(o::Any)
5050
if jlWrapIteratorType.tp_name == C_NULL # lazily initialize
5151
pyjlwrap_type!(jlWrapIteratorType, "PyCall.jlwrap_iterator") do t
52-
t.tp_iter = cfunction(pyincref_, PyPtr, (PyPtr,)) # new reference to same object
53-
t.tp_iternext = cfunction(pyjlwrap_iternext, PyPtr, (PyPtr,))
52+
t.tp_iter = cfunction(pyincref_, PyPtr, Tuple{PyPtr}) # new reference to same object
53+
t.tp_iternext = cfunction(pyjlwrap_iternext, PyPtr, Tuple{PyPtr})
5454
end
5555
end
5656
return pyjlwrap_new(jlWrapIteratorType, (o, Ref(start(o))))

src/pytype.jl

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ end
6868

6969
function PyGetSetDef(name::AbstractString, get::Function,set::Function, doc::AbstractString="")
7070
PyGetSetDef(gstring_ptr(name, name),
71-
cfunction(get, PyPtr, (PyPtr,Ptr{Void})),
72-
cfunction(set, Int, (PyPtr,PyPtr,Ptr{Void})),
71+
cfunction(get, PyPtr, Tuple{PyPtr,Ptr{Void}}),
72+
cfunction(set, Int, Tuple{PyPtr,PyPtr,Ptr{Void}}),
7373
isempty(doc) ? NULL_UInt8_Ptr : gstring_ptr(name, doc),
7474
C_NULL)
7575
end
7676

7777
function PyGetSetDef(name::AbstractString, get::Function, doc::AbstractString="")
7878
PyGetSetDef(gstring_ptr(name, name),
79-
cfunction(get, PyPtr, (PyPtr,Ptr{Void})),
79+
cfunction(get, PyPtr, Tuple{PyPtr,Ptr{Void}}),
8080
C_NULL,
8181
isempty(doc) ? NULL_UInt8_Ptr : gstring_ptr(name, doc),
8282
C_NULL)
@@ -319,8 +319,9 @@ function PyTypeObject!(init::Function, t::PyTypeObject, name::AbstractString, ba
319319
if t.tp_new == C_NULL
320320
t.tp_new = @pyglobal :PyType_GenericNew
321321
end
322-
@pycheckz ccall((@pysym :PyType_Ready), Cint, (Ptr{PyTypeObject},), &t)
323-
ccall((@pysym :Py_IncRef), Void, (Ptr{PyTypeObject},), &t)
322+
# TODO change to `Ref{PyTypeObject}` when 0.6 is dropped.
323+
@pycheckz ccall((@pysym :PyType_Ready), Cint, (Any,), t)
324+
ccall((@pysym :Py_IncRef), Void, (Any,), t)
324325
return t
325326
end
326327

@@ -422,13 +423,13 @@ function pyjlwrap_init()
422423
PyMemberDef(C_NULL,0,0,0,C_NULL))
423424

424425
# all cfunctions must be compiled at runtime
425-
pyjlwrap_dealloc_ptr = cfunction(pyjlwrap_dealloc, Void, (PyPtr,))
426-
pyjlwrap_repr_ptr = cfunction(pyjlwrap_repr, PyPtr, (PyPtr,))
427-
pyjlwrap_hash_ptr = cfunction(pyjlwrap_hash, UInt, (PyPtr,))
428-
pyjlwrap_hash32_ptr = cfunction(pyjlwrap_hash32, UInt32, (PyPtr,))
429-
pyjlwrap_call_ptr = cfunction(pyjlwrap_call, PyPtr, (PyPtr,PyPtr,PyPtr))
430-
pyjlwrap_getattr_ptr = cfunction(pyjlwrap_getattr, PyPtr, (PyPtr,PyPtr))
431-
pyjlwrap_getiter_ptr = cfunction(pyjlwrap_getiter, PyPtr, (PyPtr,))
426+
pyjlwrap_dealloc_ptr = cfunction(pyjlwrap_dealloc, Void, Tuple{PyPtr})
427+
pyjlwrap_repr_ptr = cfunction(pyjlwrap_repr, PyPtr, Tuple{PyPtr})
428+
pyjlwrap_hash_ptr = cfunction(pyjlwrap_hash, UInt, Tuple{PyPtr})
429+
pyjlwrap_hash32_ptr = cfunction(pyjlwrap_hash32, UInt32, Tuple{PyPtr})
430+
pyjlwrap_call_ptr = cfunction(pyjlwrap_call, PyPtr, Tuple{PyPtr,PyPtr,PyPtr})
431+
pyjlwrap_getattr_ptr = cfunction(pyjlwrap_getattr, PyPtr, Tuple{PyPtr,PyPtr})
432+
pyjlwrap_getiter_ptr = cfunction(pyjlwrap_getiter, PyPtr, Tuple{PyPtr})
432433

433434
# detect at runtime whether we are using Stackless Python
434435
try
@@ -453,8 +454,9 @@ end
453454
function pyjlwrap_type!(init::Function, to::PyTypeObject, name::AbstractString)
454455
sz = sizeof(Py_jlWrap) + sizeof(PyPtr) # must be > base type
455456
PyTypeObject!(to, name, sz) do t::PyTypeObject
456-
t.tp_base = ccall(:jl_value_ptr, Ptr{Void}, (Ptr{PyTypeObject},), &jlWrapType)
457-
ccall((@pysym :Py_IncRef), Void, (Ptr{PyTypeObject},), &jlWrapType)
457+
# TODO change to `Ref{PyTypeObject}` when 0.6 is dropped.
458+
t.tp_base = ccall(:jl_value_ptr, Ptr{Void}, (Any,), jlWrapType)
459+
ccall((@pysym :Py_IncRef), Void, (Any,), jlWrapType)
458460
init(t)
459461
end
460462
end
@@ -467,8 +469,9 @@ pyjlwrap_type(init::Function, name::AbstractString) =
467469
# since, the jl_value_t* may be to a temporary copy. But don't need
468470
# to wrap isbits types in Python objects anyway.)
469471
function pyjlwrap_new(pyT::PyTypeObject, value::Any)
472+
# TODO change to `Ref{PyTypeObject}` when 0.6 is dropped.
470473
o = PyObject(@pycheckn ccall((@pysym :_PyObject_New),
471-
PyPtr, (Ptr{PyTypeObject},), &pyT))
474+
PyPtr, (Any,), pyT))
472475
pycall_gc[o.o] = value
473476
p = convert(Ptr{Ptr{Void}}, o.o)
474477
unsafe_store!(p, ccall(:jl_value_ptr, Ptr{Void}, (Any,), value), 3)
@@ -479,7 +482,8 @@ function pyjlwrap_new(x::Any)
479482
pyjlwrap_new(jlWrapType, x)
480483
end
481484

482-
is_pyjlwrap(o::PyObject) = jlWrapType.tp_new != C_NULL && ccall((@pysym :PyObject_IsInstance), Cint, (PyPtr,Ptr{PyTypeObject}), o, &jlWrapType) == 1
485+
# TODO change to `Ref{PyTypeObject}` when 0.6 is dropped.
486+
is_pyjlwrap(o::PyObject) = jlWrapType.tp_new != C_NULL && ccall((@pysym :PyObject_IsInstance), Cint, (PyPtr, Any), o, jlWrapType) == 1
483487

484488
################################################################
485489
# Fallback conversion: if we don't have a better conversion function,

test/runtests.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ let nm = tempname()
196196
pf[:write](pyutf8(nm))
197197
pf[:flush]()
198198
end
199-
@test readstring(nm) == nm
199+
@test read(nm, String) == nm
200200
end
201201

202202
# issue #112
@@ -420,9 +420,9 @@ end
420420

421421
# @pycall macro expands correctly
422422
_pycall = GlobalRef(PyCall,:pycall)
423-
@test macroexpand(:(@pycall foo(bar)::T)) == :($(_pycall)(foo, T, bar))
424-
@test macroexpand(:(@pycall foo(bar, args...)::T)) == :($(_pycall)(foo, T, bar, args...))
425-
@test macroexpand(:(@pycall foo(bar; kwargs...)::T)) == :($(_pycall)(foo, T, bar; kwargs...))
423+
@test macroexpand(@__MODULE__, :(@pycall foo(bar)::T)) == :($(_pycall)(foo, T, bar))
424+
@test macroexpand(@__MODULE__, :(@pycall foo(bar, args...)::T)) == :($(_pycall)(foo, T, bar, args...))
425+
@test macroexpand(@__MODULE__, :(@pycall foo(bar; kwargs...)::T)) == :($(_pycall)(foo, T, bar; kwargs...))
426426

427427

428428
# basic @pywith functionality
@@ -432,7 +432,7 @@ try
432432
@pywith pybuiltin("open")(fname,"w") as f begin
433433
f[:write]("test")
434434
end
435-
open(readstring,fname)=="test"
435+
open(io->read(io, String), fname)=="test"
436436
end
437437
finally
438438
rm(fname,force=true)

0 commit comments

Comments
 (0)