Skip to content

Commit e6491aa

Browse files
committed
Merge pull request #49 from jakebolewski/py3_set_argv_ex
fix pyinitialize segfault on python 3.x
2 parents a292612 + 51ae086 commit e6491aa

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/PyCall.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,15 @@ function pyinitialize(libpy::Ptr{Void})
312312
pyexc_initialize()
313313
if !already_inited
314314
# some modules (e.g. IPython) expect sys.argv to be set
315-
argv_s = bytestring("")
316-
argv = convert(Ptr{Uint8}, argv_s)
317-
ccall(pysym(:PySys_SetArgvEx), Void, (Cint,Ptr{Ptr{Uint8}},Cint),
318-
1, &argv, 0)
315+
if pyversion.major < 3
316+
argv_s = bytestring("")
317+
argv = convert(Ptr{Uint8}, argv_s)
318+
ccall(pysym(:PySys_SetArgvEx), Void, (Cint,Ptr{Ptr{Uint8}},Cint), 1, &argv, 0)
319+
else
320+
argv_s = Cwchar_t[0]
321+
argv = convert(Ptr{Cwchar_t}, argv_s)
322+
ccall(pysym(:PySys_SetArgvEx), Void, (Cint, Ptr{Ptr{Cwchar_t}}, Cint), 1, &argv, 0)
323+
end
319324
end
320325
end
321326
return

0 commit comments

Comments
 (0)