Author: Armin Rigo <[email protected]>
Branch: cpyext-gc-support
Changeset: r80414:dc4368563c7b
Date: 2015-10-23 15:58 +0100
http://bitbucket.org/pypy/pypy/changeset/dc4368563c7b/
Log: Some translation fixes
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
@@ -30,7 +30,6 @@
from rpython.rlib.rposix import is_valid_fd, validate_fd
from rpython.rlib.unroll import unrolling_iterable
from rpython.rlib.objectmodel import specialize
-from rpython.rlib.exports import export_struct
from pypy.module import exceptions
from pypy.module.exceptions import interp_exceptions
# CPython 2.4 compatibility
@@ -210,13 +209,14 @@
assert len(self.argnames) == len(self.argtypes)
self.gil = gil
self.result_borrowed = result_borrowed
+ #
+ def get_llhelper(space):
+ return llhelper(self.functype, self.get_wrapper(space))
+ self.get_llhelper = get_llhelper
def _freeze_(self):
return True
- def get_llhelper(self, space):
- return llhelper(self.functype, self.get_wrapper(space))
-
@specialize.memo()
def get_wrapper(self, space):
wrapper = getattr(self, '_wrapper', None)
@@ -387,9 +387,11 @@
INTERPLEVEL_API = {} # only for untranslated tests
FUNCTIONS = {}
[email protected]()
def constant_pyobj(space, name):
- if we_are_translated():
- ZZZ # should return the C symbol "Py" + name, constant-folded
+ # returns the C symbol "Py" + name, constant-folded
+ if space.config.translating:
+ return rffi.CConstant("((PyObject *)&PyPy%s)" % (name,), PyObject)
else:
from pypy.module.cpyext.pyobject import as_pyobj
w_obj = INTERPLEVEL_API[name]
@@ -800,6 +802,7 @@
def build_bridge(space):
"NOT_RPYTHON"
from pypy.module.cpyext.pyobject import setup_prebuilt_pyobj, _Py_Dealloc
+ from pypy.module.cpyext.pyobject import get_pyobj_and_incref
from rpython.rlib import rawrefcount
export_symbols = sorted(FUNCTIONS) + sorted(SYMBOLS_C) + sorted(GLOBALS)
@@ -881,7 +884,7 @@
if isptr:
ptr = ctypes.c_void_p.in_dll(bridge, name)
if typ == 'PyObject*':
- value = make_ref(space, w_obj)
+ value = get_pyobj_and_incref(space, w_obj)
elif typ == 'PyDateTime_CAPI*':
value = w_obj
else:
@@ -1097,10 +1100,9 @@
def setup_library(space):
"NOT_RPYTHON"
- from pypy.module.cpyext.pyobject import make_ref
-
export_symbols = sorted(FUNCTIONS) + sorted(SYMBOLS_C) + sorted(GLOBALS)
from rpython.translator.c.database import LowLevelDatabase
+ from pypy.module.cpyext.pyobject import get_pyobj_and_incref
db = LowLevelDatabase()
generate_macros(export_symbols, prefix='PyPy')
@@ -1116,21 +1118,21 @@
setup_va_functions(eci)
# populate static data
- for name, (typ, expr) in GLOBALS.iteritems():
- name = name.replace("#", "")
- if name.startswith('PyExc_'):
- name = '_' + name
- from pypy.module import cpyext
- w_obj = eval(expr)
- if typ in ('PyObject*', 'PyTypeObject*'):
- struct_ptr = make_ref(space, w_obj)
- elif typ == 'PyDateTime_CAPI*':
- continue
- else:
- assert False, "Unknown static data: %s %s" % (typ, name)
- struct = rffi.cast(get_structtype_for_ctype(typ), struct_ptr)._obj
- struct._compilation_info = eci
- export_struct(name, struct)
+ ## for name, (typ, expr) in GLOBALS.iteritems():
+ ## name = name.replace("#", "")
+ ## if name.startswith('PyExc_'):
+ ## name = '_' + name
+ ## from pypy.module import cpyext
+ ## w_obj = eval(expr)
+ ## if typ in ('PyObject*', 'PyTypeObject*'):
+ ## struct_ptr = get_pyobj_and_incref(space, w_obj)
+ ## elif typ == 'PyDateTime_CAPI*':
+ ## continue
+ ## else:
+ ## assert False, "Unknown static data: %s %s" % (typ, name)
+ ## struct = rffi.cast(get_structtype_for_ctype(typ), struct_ptr)._obj
+ ## struct._compilation_info = eci
+ ## export_struct(name, struct)
for name, func in FUNCTIONS.iteritems():
newname = mangle_name('PyPy', name) or name
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
@@ -3,6 +3,7 @@
from pypy.interpreter.error import OperationError
from pypy.interpreter.executioncontext import AsyncAction
from rpython.rtyper.lltypesystem import lltype
+from rpython.rtyper.annlowlevel import llhelper
from rpython.rlib.rdynload import DLLHANDLE
from rpython.rlib import rawrefcount
import sys
@@ -81,7 +82,8 @@
from pypy.module.cpyext.api import INIT_FUNCTIONS
if we_are_translated():
- rawrefcount.init(self.dealloc_trigger)
+ rawrefcount.init(llhelper(rawrefcount.RAWREFCOUNT_DEALLOC_TRIGGER,
+ self.dealloc_trigger))
setup_new_method_def(space)
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
@@ -520,7 +520,7 @@
key = space.str_w(w_key)
dict_w[key] = space.getitem(w_org_dict, w_key)
except OperationError, e:
- if e.async(self):
+ if e.async(space):
raise
add_operators(space, dict_w, pto)
diff --git a/rpython/rlib/rawrefcount.py b/rpython/rlib/rawrefcount.py
--- a/rpython/rlib/rawrefcount.py
+++ b/rpython/rlib/rawrefcount.py
@@ -21,7 +21,9 @@
def init(dealloc_trigger_callback=None):
- "NOT_RPYTHON: set up rawrefcount with the GC"
+ """NOT_RPYTHON: set up rawrefcount with the GC. This is only used
+ for tests; it should not be called at all during translation.
+ """
global _p_list, _o_list, _adr2pypy, _pypy2ob
global _d_list, _dealloc_trigger_callback
_p_list = []
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit