[pypy-svn] r47632 - in pypy/dist/pypy/rpython: lltypesystem lltypesystem/test module tool tool/test
fijal at codespeak.net
fijal at codespeak.net
Sat Oct 20 13:01:22 CEST 2007
Author: fijal
Date: Sat Oct 20 13:01:21 2007
New Revision: 47632
Modified:
pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/dist/pypy/rpython/lltypesystem/rffi.py
pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py
pypy/dist/pypy/rpython/module/ll_os.py
pypy/dist/pypy/rpython/tool/rffi_platform.py
pypy/dist/pypy/rpython/tool/test/test_rffi_platform.py
Log:
"Revert" changes from the morning - make COpaquePtr count it's size
lazy, but still use rffi_platform for that
Modified: pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py Sat Oct 20 13:01:21 2007
@@ -172,7 +172,7 @@
elif isinstance(T, lltype.OpaqueType):
if T.hints.get('external', None) != 'C':
raise TypeError("%s is not external" % T)
- return ctypes.c_char * T.hints['size']
+ return ctypes.c_char * T.hints['getsize']()
else:
_setup_ctypes_cache()
if T in _ctypes_cache:
@@ -410,7 +410,7 @@
elif isinstance(T.TO, lltype.Array):
convert_array(container)
elif isinstance(T.TO, lltype.OpaqueType):
- cbuf = ctypes.create_string_buffer(T.TO.hints['size'])
+ cbuf = ctypes.create_string_buffer(T.TO.hints['getsize']())
add_storage(container, _parentable_mixin, cbuf)
else:
raise NotImplementedError(T)
Modified: pypy/dist/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rffi.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/rffi.py Sat Oct 20 13:01:21 2007
@@ -222,14 +222,22 @@
return lltype.Ptr(CArray(tp))
CArray._annspecialcase_ = 'specialize:memo'
-def COpaque(name, size, hints=None, **kwds):
+def COpaque(name, hints=None, **kwds):
if hints is None:
hints = {}
else:
hints = hints.copy()
hints['external'] = 'C'
hints['c_name'] = name
- hints['size'] = size
+ def lazy_getsize():
+ from pypy.rpython.tool import rffi_platform
+ k = {}
+ for _name, value in kwds.items():
+ if _name in ['includes', 'include_dirs', 'libraries']:
+ k['_%s_' % _name] = value
+ return rffi_platform.sizeof(name, '', **k)
+
+ hints['getsize'] = lazy_getsize
return lltype.OpaqueType(name, hints)
def COpaquePtr(*args, **kwds):
Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Sat Oct 20 13:01:21 2007
@@ -275,8 +275,8 @@
def test_opaque_obj(self):
includes = ['sys/time.h', 'time.h']
- TIMEVALP = rffi_platform.copaque('struct timeval', '', _includes_=includes)
- TIMEZONEP = rffi_platform.copaque('struct timezone', '', _includes_=includes)
+ TIMEVALP = rffi.COpaquePtr('struct timeval', includes=includes)
+ TIMEZONEP = rffi.COpaquePtr('struct timezone', includes=includes)
gettimeofday = rffi.llexternal('gettimeofday', [TIMEVALP, TIMEZONEP],
rffi.INT, includes=includes)
ll_timevalp = lltype.malloc(TIMEVALP.TO, flavor='raw')
Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py Sat Oct 20 13:01:21 2007
@@ -224,8 +224,8 @@
h_file.write(h_source)
from pypy.rpython.tool import rffi_platform
- STUFFP = rffi_platform.copaque('struct stuff', '', _includes_=['opaque.h'],
- _include_dirs_=[str(udir)])
+ STUFFP = COpaquePtr('struct stuff', includes=['opaque.h'],
+ include_dirs=[str(udir)])
ll_get = llexternal('get', [STUFFP], lltype.Char, includes=['opaque.h'],
include_dirs=[str(udir)])
Modified: pypy/dist/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_os.py (original)
+++ pypy/dist/pypy/rpython/module/ll_os.py Sat Oct 20 13:01:21 2007
@@ -621,12 +621,11 @@
_includes_ = ['sys/types.h', 'dirent.h']
DIRENT = platform.Struct('struct dirent',
[('d_name', lltype.FixedSizeArray(rffi.CHAR, 1))])
- DIRP = platform.COpaquePtr('DIR')
+ DIRP = rffi.COpaquePtr('DIR')
config = platform.configure(CConfig)
DIRENT = config['DIRENT']
DIRENTP = lltype.Ptr(DIRENT)
- DIRP = config['DIRP']
os_opendir = self.llexternal('opendir', [rffi.CCHARP], DIRP,
includes=CConfig._includes_)
os_readdir = self.llexternal('readdir', [DIRP], DIRENTP,
Modified: pypy/dist/pypy/rpython/tool/rffi_platform.py
==============================================================================
--- pypy/dist/pypy/rpython/tool/rffi_platform.py (original)
+++ pypy/dist/pypy/rpython/tool/rffi_platform.py Sat Oct 20 13:01:21 2007
@@ -42,13 +42,13 @@
HAS = Has(name)
return configure(CConfig)['HAS']
-def copaque(name, c_header_source, **kwds):
+def sizeof(name, c_header_source, **kwds):
class CConfig:
_header_ = c_header_source
- C = COpaquePtr(name)
+ SIZE = SizeOf(name)
for k, v in kwds.items():
setattr(CConfig, k, v)
- return configure(CConfig)['C']
+ return configure(CConfig)['SIZE']
# ____________________________________________________________
#
@@ -278,24 +278,6 @@
kwds = {'hints': hints}
return rffi.CStruct(name, *fields, **kwds)
-class COpaquePtr(CConfigEntry):
- """An entry in a CConfig class that stands for
- some external opaque type
- """
- def __init__(self, name):
- self.name = name
-
- def prepare_code(self):
- yield 'dump("size", sizeof(%s));' % self.name
-
- def build_result(self, info, config_result):
- # XXX this is strange mapping, but well, I've got no
- # better idea
- kwds = {}
- for item in ['includes', 'include_dirs', 'libraries']:
- kwds[item] = getattr(config_result, '_%s_' % item, [])
- return rffi.COpaquePtr(self.name, info['size'], **kwds)
-
class SimpleType(CConfigEntry):
"""An entry in a CConfig class that stands for an externally
defined simple numeric type.
@@ -440,6 +422,19 @@
def question(self, ask_gcc):
return ask_gcc(self.name + ';')
+class SizeOf(CConfigEntry):
+ """An entry in a CConfig class that stands for
+ some external opaque type
+ """
+ def __init__(self, name):
+ self.name = name
+
+ def prepare_code(self):
+ yield 'dump("size", sizeof(%s));' % self.name
+
+ def build_result(self, info, config_result):
+ return info['size']
+
# ____________________________________________________________
#
# internal helpers
Modified: pypy/dist/pypy/rpython/tool/test/test_rffi_platform.py
==============================================================================
--- pypy/dist/pypy/rpython/tool/test/test_rffi_platform.py (original)
+++ pypy/dist/pypy/rpython/tool/test/test_rffi_platform.py Sat Oct 20 13:01:21 2007
@@ -193,4 +193,4 @@
assert not rffi_platform.has("x", "#include <some/path/which/cannot/exist>")
def test_sizeof():
- assert rffi_platform.copaque("char", "").TO.hints['size'] == 1
+ assert rffi_platform.sizeof("char", "") == 1
More information about the Pypy-commit
mailing list