@@ -244,9 +244,14 @@ function pyinitialize(libpy::Ptr{Void})
244
244
libpython:: Ptr{Void} = libpy == C_NULL ? ccall (:jl_load_dynamic_library , Ptr{Void}, (Ptr{Uint8},Cuint), C_NULL , 0 ) : libpy
245
245
already_inited = 0 != ccall ((@pysym :Py_IsInitialized ), Cint, ())
246
246
if ! already_inited
247
- if ! isempty (pyprogramname:: ASCIIString )
248
- ccall ((@pysym :Py_SetProgramName ), Void, (Ptr{Uint8},),
249
- pyprogramname:: ASCIIString )
247
+ if ! isempty (pyprogramname)
248
+ if pyversion. major < 3
249
+ ccall ((@pysym :Py_SetProgramName ), Void, (Ptr{Uint8},),
250
+ pyprogramname:: ASCIIString )
251
+ else
252
+ ccall ((@pysym :Py_SetProgramName ), Void, (Ptr{Cwchar_t},),
253
+ pyprogramname:: Array{Cwchar_t} )
254
+ end
250
255
end
251
256
ccall ((@pysym :Py_InitializeEx ), Void, (Cint,), 0 )
252
257
end
@@ -367,18 +372,33 @@ function dlopen_libpython(python::String)
367
372
end
368
373
end
369
374
375
+ # Python 3.x uses wchar_t arrays for some string arguments
376
+ function wbytestring (s:: String )
377
+ if pyversion. major < 3
378
+ bytestring (s)
379
+ else
380
+ n = length (s)
381
+ w = Array (Cwchar_t, n + 1 )
382
+ for i = 1 : n
383
+ w[i] = s[i]
384
+ end
385
+ w[n+ 1 ] = 0
386
+ w
387
+ end
388
+ end
389
+
370
390
# initialize the Python interpreter (no-op on subsequent calls)
371
391
function pyinitialize (python:: String )
372
392
global initialized
373
393
if ! initialized:: Bool
374
394
libpy = try
375
395
lib = dlopen_libpython (python)
376
- global pyprogramname = bytestring (pysys (python, " executable" ))
396
+ global pyprogramname = wbytestring (pysys (python, " executable" ))
377
397
lib
378
398
catch
379
399
# perhaps we were passed library name and not executable?
380
400
lib = dlopen (python, RTLD_LAZY| RTLD_DEEPBIND| RTLD_GLOBAL)
381
- global pyprogramname = bytestring (python)
401
+ global pyprogramname = wbytestring (python)
382
402
lib
383
403
end
384
404
pyinitialize (libpy)
0 commit comments