[pypy-svn] r72805 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
xoraxax at codespeak.net
xoraxax at codespeak.net
Thu Mar 25 15:01:18 CET 2010
Author: xoraxax
Date: Thu Mar 25 15:01:16 2010
New Revision: 72805
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/api.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py
Log:
Add NULL check and fix force_string.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/api.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/api.py Thu Mar 25 15:01:16 2010
@@ -200,13 +200,6 @@
class InvalidPointerException(Exception):
pass
-def force_string(space, ref):
- ref = rffi.cast(PyStringObjectPtr, ref)
- s = rffi.charpsize2str(ref.c_buffer, ref.c_size)
- w_str = space.wrap(s)
- s_ptr = make_ref(space, w_str)
- return w_str
-
def get_padded_type(T, size):
fields = T._flds.copy()
hints = T._hints.copy()
@@ -266,6 +259,19 @@
# XXX borrowed references?
return py_obj
+def force_string(space, ref):
+ state = space.fromcache(State)
+ ref = rffi.cast(PyStringObjectPtr, ref)
+ s = rffi.charpsize2str(ref.c_buffer, ref.c_size)
+ ref = rffi.cast(PyObject, ref)
+ w_str = space.wrap(s)
+ state.py_objects_w2r[w_str] = ref
+ ctypes_obj = ll2ctypes.lltype2ctypes(ref)
+ ptr = ctypes.cast(ctypes_obj, ctypes.c_void_p).value
+ state.py_objects_r2w[ptr] = w_str
+ return w_str
+
+
def from_ref(space, ref):
if not ref:
return None
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py Thu Mar 25 15:01:16 2010
@@ -53,6 +53,8 @@
("getstring", "METH_NOARGS",
"""
PyObject* s = PyString_FromStringAndSize(NULL, 3);
+ if (s == NULL)
+ return NULL;
char* c = PyString_AsString(s);
//Py_ssize_t len = PyString_Size(s);
c[0] = 'a';
More information about the Pypy-commit
mailing list