[pypy-svn] r74523 - pypy/trunk/pypy/module/cpyext
afa at codespeak.net
afa at codespeak.net
Mon May 17 00:10:52 CEST 2010
Author: afa
Date: Mon May 17 00:10:50 2010
New Revision: 74523
Modified:
pypy/trunk/pypy/module/cpyext/api.py
pypy/trunk/pypy/module/cpyext/funcobject.py
pypy/trunk/pypy/module/cpyext/methodobject.py
pypy/trunk/pypy/module/cpyext/pyobject.py
pypy/trunk/pypy/module/cpyext/slotdefs.py
pypy/trunk/pypy/module/cpyext/stringobject.py
pypy/trunk/pypy/module/cpyext/typeobject.py
pypy/trunk/pypy/module/cpyext/unicodeobject.py
Log:
Revert my changes since r74517: they break translation.
I'll think harder about it.
Modified: pypy/trunk/pypy/module/cpyext/api.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/api.py (original)
+++ pypy/trunk/pypy/module/cpyext/api.py Mon May 17 00:10:50 2010
@@ -124,7 +124,6 @@
def _freeze_(self):
return True
- @specialize.memo()
def get_llhelper(self, space):
llh = getattr(self, '_llhelper', None)
if llh is None:
@@ -141,27 +140,7 @@
wrapper.relax_sig_check = True
return wrapper
-def make_static_function(argtypes, restype, error=_NOT_SPECIFIED):
- """
- Helper to build a static function pointer.
- """
- if error is _NOT_SPECIFIED:
- if restype is PyObject:
- error = lltype.nullptr(PyObject.TO)
- elif restype is lltype.Void:
- error = CANNOT_FAIL
- if type(error) is int:
- error = rffi.cast(restype, error)
-
- def decorate(func):
- func_name = func.func_name
- api_function = ApiFunction(argtypes, restype, func, error)
- func.api_func = api_function
- FUNCTIONS_STATIC[func_name] = api_function
- return func
- return decorate
-
-def cpython_api(argtypes, restype, error=_NOT_SPECIFIED):
+def cpython_api(argtypes, restype, error=_NOT_SPECIFIED, external=True):
"""
Declares a function to be exported.
- `argtypes`, `restype` are lltypes and describe the function signature.
@@ -251,8 +230,6 @@
finally:
for arg in to_decref:
Py_DecRef(space, arg)
- unwrapper = func_with_new_name(unwrapper,
- "unwrapper_%s" % (func_name,))
unwrapper.func = func
unwrapper.api_func = api_function
unwrapper._always_inline_ = True
@@ -260,7 +237,10 @@
unwrapper_catch = make_unwrapper(True)
unwrapper_raise = make_unwrapper(False)
- FUNCTIONS[func_name] = api_function
+ if external:
+ FUNCTIONS[func_name] = api_function
+ else:
+ FUNCTIONS_STATIC[func_name] = api_function
INTERPLEVEL_API[func_name] = unwrapper_catch # used in tests
return unwrapper_raise # used in 'normal' RPython code.
return decorate
Modified: pypy/trunk/pypy/module/cpyext/funcobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/funcobject.py (original)
+++ pypy/trunk/pypy/module/cpyext/funcobject.py Mon May 17 00:10:50 2010
@@ -27,6 +27,7 @@
assert isinstance(w_obj, Function)
py_func.c_func_name = make_ref(space, space.wrap(w_obj.name))
+ at cpython_api([PyObject], lltype.Void, external=False)
def function_dealloc(space, py_obj):
py_func = rffi.cast(PyFunctionObject, py_obj)
Py_DecRef(space, py_func.c_func_name)
Modified: pypy/trunk/pypy/module/cpyext/methodobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/methodobject.py (original)
+++ pypy/trunk/pypy/module/cpyext/methodobject.py Mon May 17 00:10:50 2010
@@ -49,6 +49,7 @@
py_func.c_m_ml = w_obj.ml
py_func.c_m_self = make_ref(space, w_obj.w_self)
+ at cpython_api([PyObject], lltype.Void, external=False)
def cfunction_dealloc(space, py_obj):
py_func = rffi.cast(PyCFunctionObject, py_obj)
Py_DecRef(space, py_func.c_m_self)
Modified: pypy/trunk/pypy/module/cpyext/pyobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/pyobject.py (original)
+++ pypy/trunk/pypy/module/cpyext/pyobject.py Mon May 17 00:10:50 2010
@@ -2,12 +2,13 @@
from pypy.interpreter.baseobjspace import W_Root, SpaceCache
from pypy.rpython.lltypesystem import rffi, lltype
-from pypy.module.cpyext.api import (
- cpython_api, make_static_function, bootstrap_function, PyObject, PyObjectP,
- ADDR, CANNOT_FAIL, Py_TPFLAGS_HEAPTYPE, PyTypeObjectPtr)
+from pypy.module.cpyext.api import cpython_api, bootstrap_function, \
+ PyObject, PyObjectP, ADDR, CANNOT_FAIL, \
+ Py_TPFLAGS_HEAPTYPE, PyTypeObjectPtr
from pypy.module.cpyext.state import State
from pypy.objspace.std.typeobject import W_TypeObject
from pypy.rlib.objectmodel import specialize, we_are_translated
+from pypy.rpython.annlowlevel import llhelper
#________________________________________________________
# type description
@@ -35,7 +36,7 @@
alloc : allocate and basic initialization of a raw PyObject
attach : Function called to tie a raw structure to a pypy object
realize : Function called to create a pypy object from a raw struct
- dealloc : Function called to free a structure
+ dealloc : a cpython_api(external=False), similar to PyObject_dealloc
"""
tp_basestruct = kw.pop('basestruct', PyObject.TO)
@@ -45,17 +46,22 @@
tp_dealloc = kw.pop('dealloc', None)
assert not kw, "Extra arguments to make_typedescr"
- if not tp_dealloc:
- from pypy.module.cpyext.typeobject import subtype_dealloc
- tp_dealloc = subtype_dealloc
- tp_dealloc = make_static_function([PyObject], lltype.Void)(tp_dealloc)
+ null_dealloc = lltype.nullptr(lltype.FuncType([PyObject], lltype.Void))
class CpyTypedescr(BaseCpyTypedescr):
basestruct = tp_basestruct
realize = tp_realize
def get_dealloc(self, space):
- return tp_dealloc.api_func.get_llhelper(space)
+ if tp_dealloc:
+ return llhelper(
+ tp_dealloc.api_func.functype,
+ tp_dealloc.api_func.get_wrapper(space))
+ else:
+ from pypy.module.cpyext.typeobject import subtype_dealloc
+ return llhelper(
+ subtype_dealloc.api_func.functype,
+ subtype_dealloc.api_func.get_wrapper(space))
def allocate(self, space, w_type, itemcount=0):
# similar to PyType_GenericAlloc?
@@ -118,7 +124,7 @@
from pypy.module.cpyext.object import PyObject_dealloc
# typedescr for the 'object' type
make_typedescr(space.w_object.instancetypedef,
- dealloc=PyObject_dealloc.func)
+ dealloc=PyObject_dealloc)
# almost all types, which should better inherit from object.
make_typedescr(None)
Modified: pypy/trunk/pypy/module/cpyext/slotdefs.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/slotdefs.py (original)
+++ pypy/trunk/pypy/module/cpyext/slotdefs.py Mon May 17 00:10:50 2010
@@ -106,8 +106,7 @@
raise OperationError(space.w_StopIteration, space.w_None)
return w_res
-# XXX why is it a "cpython_api"?
- at cpython_api([PyTypeObjectPtr, PyObject, PyObject], PyObject)
+ at cpython_api([PyTypeObjectPtr, PyObject, PyObject], PyObject, external=True)
def slot_tp_new(space, type, w_args, w_kwds):
from pypy.module.cpyext.tupleobject import PyTuple_Check
pyo = rffi.cast(PyObject, type)
Modified: pypy/trunk/pypy/module/cpyext/stringobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/stringobject.py (original)
+++ pypy/trunk/pypy/module/cpyext/stringobject.py Mon May 17 00:10:50 2010
@@ -102,6 +102,7 @@
track_reference(space, py_obj, w_obj)
return w_obj
+ at cpython_api([PyObject], lltype.Void, external=False)
def string_dealloc(space, py_obj):
"""Frees allocated PyStringObject resources.
"""
Modified: pypy/trunk/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/typeobject.py (original)
+++ pypy/trunk/pypy/module/cpyext/typeobject.py Mon May 17 00:10:50 2010
@@ -2,6 +2,7 @@
import sys
from pypy.rpython.lltypesystem import rffi, lltype
+from pypy.rpython.annlowlevel import llhelper
from pypy.rlib.rweakref import RWeakKeyDictionary
from pypy.interpreter.gateway import ObjSpace, W_Root, Arguments
from pypy.interpreter.gateway import interp2app, unwrap_spec
@@ -10,8 +11,8 @@
from pypy.objspace.std.typetype import _precheck_for_new
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from pypy.module.cpyext.api import (
- cpython_api, make_static_function, cpython_struct, bootstrap_function,
- Py_ssize_t, generic_cpy_call, Py_TPFLAGS_READY, Py_TPFLAGS_READYING,
+ cpython_api, cpython_struct, bootstrap_function, Py_ssize_t,
+ generic_cpy_call, Py_TPFLAGS_READY, Py_TPFLAGS_READYING,
Py_TPFLAGS_HEAPTYPE, METH_VARARGS, METH_KEYWORDS, CANNOT_FAIL,
PyBufferProcs, build_type_checkers)
from pypy.module.cpyext.pyobject import (
@@ -114,7 +115,8 @@
if WARN_ABOUT_MISSING_SLOT_FUNCTIONS:
os.write(2, method_name + " defined by the type but no slot function defined!\n")
continue
- slot_func_helper = slot_func.api_func.get_llhelper(space)
+ slot_func_helper = llhelper(slot_func.api_func.functype,
+ slot_func.api_func.get_wrapper(space))
# XXX special case wrapper-functions and use a "specific" slot func
# the special case of __new__ in CPython works a bit differently, hopefully
@@ -153,7 +155,7 @@
if pto.c_tp_new:
add_tp_new_wrapper(space, dict_w, pto)
- at make_static_function([PyObject, PyObject, PyObject], PyObject)
+ at cpython_api([PyObject, PyObject, PyObject], PyObject, external=False)
def tp_new_wrapper(space, self, w_args, w_kwds):
tp_new = rffi.cast(PyTypeObjectPtr, self).c_tp_new
@@ -189,7 +191,8 @@
def setup_new_method_def(space):
ptr = get_new_method_def(space)
ptr.c_ml_meth = rffi.cast(PyCFunction,
- tp_new_wrapper.api_func.get_llhelper(space))
+ llhelper(tp_new_wrapper.api_func.functype,
+ tp_new_wrapper.api_func.get_wrapper(space)))
def add_tp_new_wrapper(space, dict_w, pto):
if "__new__" in dict_w:
@@ -402,10 +405,12 @@
track_reference(space, py_tuple, space.w_tuple, replace=True)
+ at cpython_api([PyObject], lltype.Void, external=False)
def subtype_dealloc(space, obj):
pto = obj.c_ob_type
base = pto
- this_func_ptr = subtype_dealloc.api_func.get_llhelper(space)
+ this_func_ptr = llhelper(subtype_dealloc.api_func.functype,
+ subtype_dealloc.api_func.get_wrapper(space))
while base.c_tp_dealloc == this_func_ptr:
base = base.c_tp_base
assert base
@@ -428,14 +433,15 @@
lifeline_dict.set(w_obj, PyOLifeline(space, py_obj))
return py_obj
- at make_static_function([PyObject, rffi.INTP], lltype.Signed, error=CANNOT_FAIL)
+ at cpython_api([PyObject, rffi.INTP], lltype.Signed, external=False,
+ error=CANNOT_FAIL)
def str_segcount(space, w_obj, ref):
if ref:
ref[0] = rffi.cast(rffi.INT, space.int_w(space.len(w_obj)))
return 1
- at make_static_function([PyObject, lltype.Signed, rffi.VOIDPP], lltype.Signed,
- error=-1)
+ at cpython_api([PyObject, lltype.Signed, rffi.VOIDPP], lltype.Signed,
+ external=False, error=-1)
def str_getreadbuffer(space, w_str, segment, ref):
from pypy.module.cpyext.stringobject import PyString_AsString
if segment != 0:
@@ -449,10 +455,13 @@
def setup_string_buffer_procs(space, pto):
c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True)
- c_buf.c_bf_getsegcount = str_segcount.api_func.get_llhelper(space)
- c_buf.c_bf_getreadbuffer = str_getreadbuffer.api_func.get_llhelper(space)
+ 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))
pto.c_tp_as_buffer = c_buf
+ at cpython_api([PyObject], lltype.Void, external=False)
def type_dealloc(space, obj):
obj_pto = rffi.cast(PyTypeObjectPtr, obj)
type_pto = obj.c_ob_type
@@ -490,8 +499,10 @@
setup_string_buffer_procs(space, pto)
pto.c_tp_flags = Py_TPFLAGS_HEAPTYPE
- pto.c_tp_free = PyObject_Del.api_func.get_llhelper(space)
- pto.c_tp_alloc = PyType_GenericAlloc.api_func.get_llhelper(space)
+ pto.c_tp_free = llhelper(PyObject_Del.api_func.functype,
+ PyObject_Del.api_func.get_wrapper(space))
+ pto.c_tp_alloc = llhelper(PyType_GenericAlloc.api_func.functype,
+ PyType_GenericAlloc.api_func.get_wrapper(space))
pto.c_tp_name = rffi.str2charp(w_type.getname(space, "?"))
pto.c_tp_basicsize = -1 # hopefully this makes malloc bail out
pto.c_tp_itemsize = 0
Modified: pypy/trunk/pypy/module/cpyext/unicodeobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/unicodeobject.py (original)
+++ pypy/trunk/pypy/module/cpyext/unicodeobject.py Mon May 17 00:10:50 2010
@@ -42,6 +42,7 @@
py_unicode.c_size = len(space.unicode_w(w_obj))
py_unicode.c_buffer = lltype.nullptr(rffi.CWCHARP.TO)
+ at cpython_api([PyObject], lltype.Void, external=False)
def unicode_dealloc(space, py_obj):
py_unicode = rffi.cast(PyUnicodeObject, py_obj)
if py_unicode.c_buffer:
More information about the Pypy-commit
mailing list