[pypy-svn] r75040 - in pypy/branch/cpyext-init-cleanup/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Thu Jun 3 08:35:29 CEST 2010
Author: afa
Date: Thu Jun 3 08:35:27 2010
New Revision: 75040
Modified:
pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/api.py
pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/pyobject.py
pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/test/test_methodobject.py
pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/typeobject.py
Log:
Some progress
Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/api.py (original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/api.py Thu Jun 3 08:35:27 2010
@@ -99,6 +99,17 @@
udir.join('pypy_macros.h').write("/* Will be filled later */")
globals().update(rffi_platform.configure(CConfig_constants))
+class BaseApiObject:
+ """Base class for all objects defined by the CPython API. each
+ object kind may have a declaration in a header file, a definition,
+ and methods to initialize it, to retrive it in test."""
+
+ def get_llpointer(self, space):
+ raise NotImplementedError
+
+ def get_interpret(self, space):
+ raise NotImplementedError
+
def copy_header_files():
for name in ("pypy_decl.h", "pypy_macros.h"):
udir.join(name).copy(interfaces_dir / name)
@@ -125,7 +136,7 @@
# the error value specifed in the API.
#
-class ApiFunction:
+class ApiFunction(BaseApiObject):
def __init__(self, argtypes, restype, callable, error=_NOT_SPECIFIED):
self.argtypes = argtypes
self.restype = restype
@@ -134,9 +145,10 @@
if error is not _NOT_SPECIFIED:
self.error_value = error
- # extract the signature from the (CPython-level) code object
+ # extract the signature from user code object
from pypy.interpreter import pycode
- argnames, varargname, kwargname = pycode.cpython_code_signature(callable.func_code)
+ argnames, varargname, kwargname = pycode.cpython_code_signature(
+ callable.func_code)
assert argnames[0] == 'space'
self.argnames = argnames[1:]
@@ -145,15 +157,22 @@
def _freeze_(self):
return True
- def get_llhelper(self, space):
+ def get_llpointer(self, space):
+ "Returns a C function pointer"
+ assert not we_are_translated()
llh = getattr(self, '_llhelper', None)
if llh is None:
- llh = llhelper(self.functype, self.get_wrapper(space))
+ llh = llhelper(self.functype, self._get_wrapper(space))
self._llhelper = llh
return llh
@specialize.memo()
- def get_wrapper(self, space):
+ def get_llpointer_maker(self, space):
+ "Returns a callable that builds a C function pointer"
+ return lambda: llhelper(self.functype, self._get_wrapper(space))
+
+ @specialize.memo()
+ def _get_wrapper(self, space):
wrapper = getattr(self, '_wrapper', None)
if wrapper is None:
wrapper = make_wrapper(space, self.callable)
@@ -377,6 +396,7 @@
cpython_struct('PyBufferProcs', PyBufferProcsFields, PyBufferProcs)
PyVarObjectStruct = cpython_struct("PyVarObject", PyVarObjectFields)
PyVarObject = lltype.Ptr(PyVarObjectStruct)
+PyObjectP = rffi.CArrayPtr(PyObject)
@specialize.memo()
def is_PyObject(TYPE):
@@ -384,15 +404,6 @@
return False
return hasattr(TYPE.TO, 'c_ob_refcnt') and hasattr(TYPE.TO, 'c_ob_type')
-# a pointer to PyObject
-PyObjectP = rffi.CArrayPtr(PyObject)
-
-VA_TP_LIST = {}
-#{'int': lltype.Signed,
-# 'PyObject*': PyObject,
-# 'PyObject**': PyObjectP,
-# 'int*': rffi.INTP}
-
def configure_types():
for name, TYPE in rffi_platform.configure(CConfig).iteritems():
if name in TYPES:
@@ -522,16 +533,6 @@
wrapper.__name__ = "wrapper for %r" % (callable, )
return wrapper
-def process_va_name(name):
- return name.replace('*', '_star')
-
-def setup_va_functions(eci):
- for name, TP in VA_TP_LIST.iteritems():
- name_no_star = process_va_name(name)
- func = rffi.llexternal('pypy_va_get_%s' % name_no_star, [VA_LIST_P],
- TP, compilation_info=eci)
- globals()['va_get_%s' % name_no_star] = func
-
def setup_init_functions(eci):
init_buffer = rffi.llexternal('init_bufferobject', [], lltype.Void, compilation_info=eci)
init_pycobject = rffi.llexternal('init_pycobject', [], lltype.Void, compilation_info=eci)
@@ -657,11 +658,9 @@
# implement structure initialization code
for name, func in FUNCTIONS.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
- ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
+ ll2ctypes.lltype2ctypes(func.get_llpointer(space)),
ctypes.c_void_p)
- setup_va_functions(eci)
-
setup_init_functions(eci)
return modulename.new(ext='')
@@ -722,13 +721,6 @@
else:
body = "{ return _pypyAPI.%s(%s); }" % (name, callargs)
functions.append('%s %s(%s)\n%s' % (restype, name, args, body))
- for name in VA_TP_LIST:
- name_no_star = process_va_name(name)
- header = ('%s pypy_va_get_%s(va_list* vp)' %
- (name, name_no_star))
- pypy_decls.append(header + ';')
- functions.append(header + '\n{return va_arg(*vp, %s);}\n' % name)
- export_symbols.append('pypy_va_get_%s' % (name_no_star,))
for name, (typ, expr) in GLOBALS.iteritems():
if name.endswith('#'):
@@ -807,7 +799,6 @@
eci = build_eci(False, export_symbols, code)
run_bootstrap_functions(space)
- setup_va_functions(eci)
# populate static data
for name, (typ, expr) in GLOBALS.iteritems():
@@ -821,9 +812,9 @@
for name, func in FUNCTIONS.iteritems():
deco = entrypoint("cpyext", func.argtypes, name, relax=True)
- deco(func.get_wrapper(space))
+ deco(func._get_wrapper(space))
for name, func in FUNCTIONS_STATIC.iteritems():
- func.get_wrapper(space).c_name = name
+ func._get_wrapper(space).c_name = name
setup_init_functions(eci)
copy_header_files()
Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/pyobject.py
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/pyobject.py (original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/pyobject.py Thu Jun 3 08:35:27 2010
@@ -52,14 +52,10 @@
def get_dealloc(self, space):
if tp_dealloc:
- return llhelper(
- tp_dealloc.api_func.functype,
- tp_dealloc.api_func.get_wrapper(space))
+ return tp_dealloc.api_func.get_llpointer_maker(space)()
else:
from pypy.module.cpyext.typeobject import subtype_dealloc
- return llhelper(
- subtype_dealloc.api_func.functype,
- subtype_dealloc.api_func.get_wrapper(space))
+ return subtype_dealloc.api_func.get_llpointer_maker(space)()
def allocate(self, space, w_type, itemcount=0):
# similar to PyType_GenericAlloc?
Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/test/test_methodobject.py
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/test/test_methodobject.py (original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/test/test_methodobject.py Thu Jun 3 08:35:27 2010
@@ -78,7 +78,7 @@
ml = lltype.malloc(PyMethodDef, flavor='raw', zero=True)
namebuf = rffi.str2charp('func')
ml.c_ml_name = namebuf
- ml.c_ml_meth = c_func.get_llhelper(space)
+ ml.c_ml_meth = c_func.get_llpointer(space)
method = PyDescr_NewMethod(space, space.w_str, ml)
assert repr(method).startswith(
Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/typeobject.py (original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/typeobject.py Thu Jun 3 08:35:27 2010
@@ -111,8 +111,7 @@
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 = llhelper(slot_func.api_func.functype,
- slot_func.api_func.get_wrapper(space))
+ slot_func_helper = slot_func.api_func.get_llpointer_maker(space)()
# XXX special case wrapper-functions and use a "specific" slot func
if len(slot_name) == 1:
@@ -190,8 +189,7 @@
def setup_new_method_def(space):
ptr = get_new_method_def(space)
ptr.c_ml_meth = rffi.cast(PyCFunction,
- llhelper(tp_new_wrapper.api_func.functype,
- tp_new_wrapper.api_func.get_wrapper(space)))
+ tp_new_wrapper.api_func.get_llpointer_maker(space)())
def add_tp_new_wrapper(space, dict_w, pto):
if "__new__" in dict_w:
@@ -321,8 +319,7 @@
def subtype_dealloc(space, obj):
pto = obj.c_ob_type
base = pto
- this_func_ptr = llhelper(subtype_dealloc.api_func.functype,
- subtype_dealloc.api_func.get_wrapper(space))
+ this_func_ptr = subtype_dealloc.api_func.get_llpointer_maker(space)()
while base.c_tp_dealloc == this_func_ptr:
base = base.c_tp_base
assert base
@@ -355,10 +352,9 @@
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_getsegcount = str_segcount.api_func.get_llpointer_maker(space)()
+ c_buf.c_bf_getreadbuffer = str_getreadbuffer.api_func.get_llpointer_maker(
+ space)()
pto.c_tp_as_buffer = c_buf
@cpython_api([PyObject], lltype.Void, external=False)
@@ -402,10 +398,8 @@
setup_string_buffer_procs(space, pto)
pto.c_tp_flags = Py_TPFLAGS_HEAPTYPE
- 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_free = PyObject_Del.api_func.get_llpointer_maker(space)()
+ pto.c_tp_alloc = PyType_GenericAlloc.api_func.get_llpointer_maker(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
More information about the Pypy-commit
mailing list