[pypy-commit] pypy rffi-parser: Begin using parse_source() in pypy.module.cpyext.api
rlamy
pypy.commits at gmail.com
Fri Dec 16 23:11:03 EST 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: rffi-parser
Changeset: r89105:91730b67d4d6
Date: 2016-12-17 03:00 +0000
http://bitbucket.org/pypy/pypy/changeset/91730b67d4d6/
Log: Begin using parse_source() in pypy.module.cpyext.api
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
@@ -41,15 +41,10 @@
from rpython.rlib import rawrefcount
from rpython.rlib import rthread
from rpython.rlib.debug import fatalerror_notb
+from pypy.module.cpyext.cparser import parse_source
DEBUG_WRAPPER = True
-# update these for other platforms
-Py_ssize_t = lltype.Typedef(rffi.SSIZE_T, 'Py_ssize_t')
-Py_ssize_tP = rffi.CArrayPtr(Py_ssize_t)
-size_t = rffi.ULONG
-ADDR = lltype.Signed
-
pypydir = py.path.local(pypydir)
include_dir = pypydir / 'module' / 'cpyext' / 'include'
source_dir = pypydir / 'module' / 'cpyext' / 'src'
@@ -119,6 +114,9 @@
return is_valid_fd(c_fileno(fp))
pypy_decl = 'pypy_decl.h'
+udir.join(pypy_decl).write("/* Will be filled later */\n")
+udir.join('pypy_structmember_decl.h').write("/* Will be filled later */\n")
+udir.join('pypy_macros.h').write("/* Will be filled later */\n")
constant_names = """
Py_TPFLAGS_READY Py_TPFLAGS_READYING Py_TPFLAGS_HAVE_GETCHARBUFFER
@@ -129,9 +127,6 @@
""".split()
for name in constant_names:
setattr(CConfig_constants, name, rffi_platform.ConstantInteger(name))
-udir.join(pypy_decl).write("/* Will be filled later */\n")
-udir.join('pypy_structmember_decl.h').write("/* Will be filled later */\n")
-udir.join('pypy_macros.h').write("/* Will be filled later */\n")
globals().update(rffi_platform.configure(CConfig_constants))
def _copy_header_files(headers, dstdir):
@@ -607,6 +602,14 @@
% (cpyname, ))
build_exported_objects()
+# update these for other platforms
+h = parse_source("typedef ssize_t Py_ssize_t;")
+
+Py_ssize_t = h.definitions['Py_ssize_t']
+Py_ssize_tP = rffi.CArrayPtr(Py_ssize_t)
+size_t = rffi.ULONG
+ADDR = lltype.Signed
+
# Note: as a special case, "PyObject" is the pointer type in RPython,
# corresponding to "PyObject *" in C. We do that only for PyObject.
# For example, "PyTypeObject" is the struct type even in RPython.
diff --git a/pypy/module/cpyext/cparser.py b/pypy/module/cpyext/cparser.py
--- a/pypy/module/cpyext/cparser.py
+++ b/pypy/module/cpyext/cparser.py
@@ -2,7 +2,7 @@
from cffi.commontypes import COMMON_TYPES, resolve_common_type
import pycparser
import weakref, re
-from rpython.rtyper.lltypesystem import rffi
+from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rtyper.tool import rfficache
_r_comment = re.compile(r"/\*.*?\*/|//([^\n\\]|\\.)*?$",
@@ -682,17 +682,17 @@
if isinstance(tp, DelayedStruct):
tp = tp.realize(name)
self.structs[obj] = tp
- self.definitions[name] = tp
+ self.definitions[name] = lltype.Typedef(tp, name)
def add_macro(self, name, value):
assert name not in self.macros
self.macros[name] = value
def convert_type(self, obj):
- from pypy.module.cpyext.api import cpython_struct
if isinstance(obj, model.PrimitiveType):
return cname_to_lltype(obj.name)
elif isinstance(obj, model.StructType):
+ from pypy.module.cpyext.api import cpython_struct
if obj in self.structs:
return self.structs[obj]
fields = zip(
More information about the pypy-commit
mailing list