[pypy-svn] r26139 - in pypy/dist/pypy: objspace/cpy rpython/rctypes/tool
arigo at codespeak.net
arigo at codespeak.net
Sat Apr 22 13:41:21 CEST 2006
Author: arigo
Date: Sat Apr 22 13:41:20 2006
New Revision: 26139
Modified:
pypy/dist/pypy/objspace/cpy/capi.py
pypy/dist/pypy/rpython/rctypes/tool/ctypes_platform.py
Log:
ANSI-C-ification. Use ctypes_platform.configure() in the cpyobjspace.
Modified: pypy/dist/pypy/objspace/cpy/capi.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/capi.py (original)
+++ pypy/dist/pypy/objspace/cpy/capi.py Sat Apr 22 13:41:20 2006
@@ -14,23 +14,26 @@
###############################################################
# ____________________ Types and constants ____________________
-##Py_ssize_t = ctypes_platform.getsimpletype('Py_ssize_t',
-## """ #include <Python.h>
-## #if PY_VERSION_HEX < 0x02050000 /* < 2.5 */
-## typedef int Py_ssize_t;
-## #endif
-## """, c_int)
-
-##Py_LT = ctypes_platform.getconstantinteger('Py_LT', "#include <Python.h>")
-##Py_LE = ctypes_platform.getconstantinteger('Py_LE', "#include <Python.h>")
-##Py_EQ = ctypes_platform.getconstantinteger('Py_EQ', "#include <Python.h>")
-##Py_NE = ctypes_platform.getconstantinteger('Py_NE', "#include <Python.h>")
-##Py_GT = ctypes_platform.getconstantinteger('Py_GT', "#include <Python.h>")
-##Py_GE = ctypes_platform.getconstantinteger('Py_GE', "#include <Python.h>")
-
-# XXX ctypes_platform needs to be enhanced...
-Py_ssize_t = c_int
-Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE = range(6)
+class CConfig:
+ _header_ = """
+#include <Python.h>
+#if PY_VERSION_HEX < 0x02050000 /* < 2.5 */
+typedef int Py_ssize_t;
+#endif
+ """
+ _include_dirs_ = [ctypes_platform.get_python_include_dir()]
+
+ Py_ssize_t = ctypes_platform.SimpleType('Py_ssize_t')
+
+ Py_LT = ctypes_platform.ConstantInteger('Py_LT')
+ Py_LE = ctypes_platform.ConstantInteger('Py_LE')
+ Py_EQ = ctypes_platform.ConstantInteger('Py_EQ')
+ Py_NE = ctypes_platform.ConstantInteger('Py_NE')
+ Py_GT = ctypes_platform.ConstantInteger('Py_GT')
+ Py_GE = ctypes_platform.ConstantInteger('Py_GE')
+
+globals().update(ctypes_platform.configure(CConfig))
+del CConfig
###########################################################
Modified: pypy/dist/pypy/rpython/rctypes/tool/ctypes_platform.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/tool/ctypes_platform.py (original)
+++ pypy/dist/pypy/rpython/rctypes/tool/ctypes_platform.py Sat Apr 22 13:41:20 2006
@@ -57,18 +57,18 @@
print >> f
for key, entry in entries:
print >> f, 'void dump_section_%s(void) {' % (key,)
- print >> f, '\tprintf("-+- %s\\n");' % (key,)
for line in entry.prepare_code():
if line and line[0] != '#':
line = '\t' + line
print >> f, line
- print >> f, '\tprintf("---\\n");'
print >> f, '}'
print >> f
print >> f, 'int main(void) {'
for key, entry in entries:
+ print >> f, '\tprintf("-+- %s\\n");' % (key,)
print >> f, '\tdump_section_%s();' % (key,)
+ print >> f, '\tprintf("---\\n");'
print >> f, '\treturn 0;'
print >> f, '}'
f.close()
@@ -207,14 +207,14 @@
self.name = name
def prepare_code(self):
- yield ' if ((%s) < 0) {' % (self.name,)
- yield ' long long x = (long long)(%s);' % (self.name,)
- yield ' printf("value: %lld\\n", x);'
- yield ' } else {'
- yield ' unsigned long long x = (unsigned long long)(%s);' % (
- self.name,)
- yield ' printf("value: %llu\\n", x);'
- yield ' }'
+ yield 'if ((%s) < 0) {' % (self.name,)
+ yield ' long long x = (long long)(%s);' % (self.name,)
+ yield ' printf("value: %lld\\n", x);'
+ yield '} else {'
+ yield ' unsigned long long x = (unsigned long long)(%s);' % (
+ self.name,)
+ yield ' printf("value: %llu\\n", x);'
+ yield '}'
def build_result(self, info):
return info['value']
@@ -329,6 +329,11 @@
# ____________________________________________________________
+def get_python_include_dir():
+ from distutils import sysconfig
+ gcv = sysconfig.get_config_vars()
+ return gcv['INCLUDEPY']
+
if __name__ == '__main__':
doc = """Example:
More information about the Pypy-commit
mailing list