[pypy-svn] pypy real-voidp: Various rffi.VOIDP fixes, all tests pass in module/cpyext
amauryfa
commits-noreply at bitbucket.org
Mon Feb 28 20:24:42 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: real-voidp
Changeset: r42351:267041210939
Date: 2011-02-28 16:39 +0100
http://bitbucket.org/pypy/pypy/changeset/267041210939/
Log: Various rffi.VOIDP fixes, all tests pass in module/cpyext
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1005,7 +1005,7 @@
# exception checking occurs in call_external_function.
argnames = ', '.join(['a%d' % i for i in range(len(FT.ARGS))])
source = py.code.Source("""
- def call_external_function(funcptr, %(argnames)s):
+ def cpy_call_external(funcptr, %(argnames)s):
# NB. it is essential that no exception checking occurs here!
res = funcptr(%(argnames)s)
return res
@@ -1013,12 +1013,10 @@
miniglobals = {'__name__': __name__, # for module name propagation
}
exec source.compile() in miniglobals
- call_external_function = miniglobals['call_external_function']
+ call_external_function = miniglobals['cpy_call_external']
call_external_function._dont_inline_ = True
call_external_function._annspecialcase_ = 'specialize:ll'
call_external_function._gctransformer_hint_close_stack_ = True
- call_external_function = func_with_new_name(call_external_function,
- 'ccall_' + name)
# don't inline, as a hack to guarantee that no GC pointer is alive
# anywhere in call_external_function
diff --git a/pypy/rpython/lltypesystem/ll2ctypes.py b/pypy/rpython/lltypesystem/ll2ctypes.py
--- a/pypy/rpython/lltypesystem/ll2ctypes.py
+++ b/pypy/rpython/lltypesystem/ll2ctypes.py
@@ -1026,7 +1026,10 @@
funcname, place))
# get_ctypes_type() can raise NotImplementedError too
- cfunc.argtypes = [get_ctypes_type(T) for T in FUNCTYPE.ARGS
+ from pypy.rpython.lltypesystem import rffi
+ cfunc.argtypes = [get_ctypes_type(T) if T is not rffi.VOIDP
+ else ctypes.c_void_p
+ for T in FUNCTYPE.ARGS
if not T is lltype.Void]
if FUNCTYPE.RESULT is lltype.Void:
cfunc.restype = None
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -372,12 +372,27 @@
Py_DecRef(space, pyref)
return space.len_w(w_str)
+ at cpython_api([PyObject, lltype.Signed, rffi.CCHARPP], lltype.Signed,
+ external=False, error=-1)
+def str_getcharbuffer(space, w_str, segment, ref):
+ from pypy.module.cpyext.stringobject import PyString_AsString
+ if segment != 0:
+ raise OperationError(space.w_SystemError, space.wrap
+ ("accessing non-existent string segment"))
+ pyref = make_ref(space, w_str)
+ ref[0] = PyString_AsString(space, pyref)
+ # Stolen reference: the object has better exist somewhere else
+ Py_DecRef(space, pyref)
+ return space.len_w(w_str)
+
def setup_string_buffer_procs(space, pto):
c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True)
c_buf.c_bf_getsegcount = llhelper(str_segcount.api_func.functype,
str_segcount.api_func.get_wrapper(space))
c_buf.c_bf_getreadbuffer = llhelper(str_getreadbuffer.api_func.functype,
str_getreadbuffer.api_func.get_wrapper(space))
+ c_buf.c_bf_getcharbuffer = llhelper(str_getcharbuffer.api_func.functype,
+ str_getcharbuffer.api_func.get_wrapper(space))
pto.c_tp_as_buffer = c_buf
@cpython_api([PyObject], lltype.Void, external=False)
diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -399,7 +399,7 @@
obj, lltype.nullptr(rffi.INTP.TO)) != 1:
raise OperationError(space.w_TypeError, space.wrap(
"expected a single-segment buffer object"))
- size = generic_cpy_call(space, pb.c_bf_getreadbuffer,
+ size = generic_cpy_call(space, pb.c_bf_getcharbuffer,
obj, 0, bufferp)
if size < 0:
return -1
diff --git a/pypy/rlib/rwin32.py b/pypy/rlib/rwin32.py
--- a/pypy/rlib/rwin32.py
+++ b/pypy/rlib/rwin32.py
@@ -172,7 +172,7 @@
def llimpl_FormatError(code):
"Return a message corresponding to the given Windows error code."
- buf = lltype.malloc(rffi.VOIDPP.TO, 1, flavor='raw')
+ buf = lltype.malloc(rffi.CCHARPP.TO, 1, flavor='raw')
try:
msglen = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
@@ -180,7 +180,7 @@
None,
code,
DEFAULT_LANGUAGE,
- rffi.cast(rffi.VOIDP, buf),
+ rffi.cast(rffi.CCHARP, buf),
0, None)
if msglen <= 2 or msglen > sys.maxint:
diff --git a/pypy/module/cpyext/test/test_stringobject.py b/pypy/module/cpyext/test/test_stringobject.py
--- a/pypy/module/cpyext/test/test_stringobject.py
+++ b/pypy/module/cpyext/test/test_stringobject.py
@@ -236,7 +236,7 @@
api.PyString_Format(space.wrap('%s %d'), space.wrap((1, 2))))
def test_asbuffer(self, space, api):
- bufp = lltype.malloc(rffi.VOIDPP.TO, 1, flavor='raw')
+ bufp = lltype.malloc(rffi.CCHARPP.TO, 1, flavor='raw')
lenp = lltype.malloc(Py_ssize_tP.TO, 1, flavor='raw')
w_text = space.wrap("text")
diff --git a/pypy/rpython/lltypesystem/lltype.py b/pypy/rpython/lltypesystem/lltype.py
--- a/pypy/rpython/lltypesystem/lltype.py
+++ b/pypy/rpython/lltypesystem/lltype.py
@@ -1139,6 +1139,11 @@
raise TypeError("cannot directly assign to container array items")
T2 = typeOf(val)
if T2 != T1:
+ from pypy.rpython.lltypesystem import rffi
+ if T1 is rffi.VOIDP and isinstance(T2, Ptr):
+ # Any pointer is convertible to void*
+ val = rffi.cast(rffi.VOIDP, val)
+ else:
raise TypeError("%r items:\n"
"expect %r\n"
" got %r" % (self._T, T1, T2))
@@ -1194,7 +1199,7 @@
assert a == value
# Any pointer is convertible to void*
elif (ARG is rffi.VOIDP and
- isinstance(typeOf(a), Ptr)):
+ (a is None or isinstance(typeOf(a), Ptr))):
pass
# special case: ARG can be a container type, in which
# case a should be a pointer to it. This must also be
More information about the Pypy-commit
mailing list