[pypy-commit] pypy py3k: Partial fix for Py_GetProgramName() not returning wchar_t*
rlamy
pypy.commits at gmail.com
Wed Oct 5 23:17:05 EDT 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3k
Changeset: r87607:a6f5e346aab3
Date: 2016-10-06 04:14 +0100
http://bitbucket.org/pypy/pypy/changeset/a6f5e346aab3/
Log: Partial fix for Py_GetProgramName() not returning wchar_t*
diff --git a/pypy/module/cpyext/pythonrun.py b/pypy/module/cpyext/pythonrun.py
--- a/pypy/module/cpyext/pythonrun.py
+++ b/pypy/module/cpyext/pythonrun.py
@@ -8,7 +8,7 @@
def Py_IsInitialized(space):
return 1
- at cpython_api([], rffi.CCHARP, error=CANNOT_FAIL)
+ at cpython_api([], rffi.CWCHARP, error=CANNOT_FAIL)
def Py_GetProgramName(space):
"""
Return the program name set with Py_SetProgramName(), or the default.
@@ -52,4 +52,3 @@
@cpython_api([], PyObject, error=CANNOT_FAIL)
def PyThread_exit_thread(space):
PyErr_SetNone(space, space.w_SystemExit)
-
diff --git a/pypy/module/cpyext/state.py b/pypy/module/cpyext/state.py
--- a/pypy/module/cpyext/state.py
+++ b/pypy/module/cpyext/state.py
@@ -103,7 +103,8 @@
progname = space.str_w(argv0)
else:
progname = "pypy"
- self.programname = rffi.str2charp(progname)
+ progname = progname.decode('ascii') # XXX: which encoding??
+ self.programname = rffi.unicode2wcharp(progname)
lltype.render_immortal(self.programname)
return self.programname
diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -801,14 +801,14 @@
mod = self.import_extension('foo', [
('get_programname', 'METH_NOARGS',
'''
- char* name1 = Py_GetProgramName();
- char* name2 = Py_GetProgramName();
+ wchar_t* name1 = Py_GetProgramName();
+ wchar_t* name2 = Py_GetProgramName();
if (name1 != name2)
Py_RETURN_FALSE;
- return PyUnicode_FromString(name1);
+ return PyUnicode_FromWideChar(name1, wcslen(name1));
'''
- ),
- ])
+ )],
+ prologue='#include <wchar.h>')
p = mod.get_programname()
print(p)
assert 'py' in p
More information about the pypy-commit
mailing list