[pypy-svn] r50384 - pypy/branch/applevel-ctypes2/pypy/lib/_ctypes
fijal at codespeak.net
fijal at codespeak.net
Sun Jan 6 15:46:18 CET 2008
Author: fijal
Date: Sun Jan 6 15:46:18 2008
New Revision: 50384
Added:
pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/pointer.py (contents, props changed)
Modified:
pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/__init__.py
pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/dummy.py
pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/primitive.py
Log:
Wack until one test_pointer passes. (There is some deep problem right now though)
Modified: pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/__init__.py
==============================================================================
--- pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/__init__.py (original)
+++ pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/__init__.py Sun Jan 6 15:46:18 2008
@@ -1,10 +1,11 @@
-from _ctypes.dummy import Union, Structure, Array, _Pointer
-from _ctypes.dummy import ArgumentError, byref, addressof
+from _ctypes.dummy import Union, Structure, Array
+from _ctypes.dummy import ArgumentError, addressof
from _ctypes.dummy import resize
from _ctypes.dummy import _memmove_addr, _memset_addr, _string_at_addr
from _ctypes.dummy import _cast_addr
-from _ctypes.primitive import _SimpleCData, sizeof, alignment
+from _ctypes.primitive import _SimpleCData, sizeof, alignment, byref
+from _ctypes.pointer import _Pointer
from _ctypes.function import CFuncPtr
from _ctypes.dll import dlopen
Modified: pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/dummy.py
==============================================================================
--- pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/dummy.py (original)
+++ pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/dummy.py Sun Jan 6 15:46:18 2008
@@ -10,21 +10,12 @@
class Array(type):
pass
-class PointerType(type):
- pass
-
-class _Pointer(object):
- __metaclass__ = PointerType
-
-
class ArgumentError(Exception):
pass
-
def dummyfunc(*args, **kwargs):
return None
-byref = dummyfunc
addressof = dummyfunc
alignment = dummyfunc
resize = dummyfunc
Added: pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/pointer.py
==============================================================================
--- (empty file)
+++ pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/pointer.py Sun Jan 6 15:46:18 2008
@@ -0,0 +1,30 @@
+
+import _ffi
+
+class PointerType(type):
+ def __new__(self, name, cls, typedict):
+ d = dict(
+ size = _ffi.sizeof('P'),
+ align = _ffi.alignment('P'),
+ length = 1
+ )
+ # XXX check if typedict['_type_'] is any sane
+ # XXX remember about paramfunc
+ obj = type.__new__(self, name, cls, typedict)
+ for k, v in d.iteritems():
+ setattr(obj, k, v)
+ return obj
+
+class _Pointer(object):
+ __metaclass__ = PointerType
+
+ def __init__(self, value=None):
+ if value is None:
+ self.is_null = True
+ else:
+ self.value = value
+ # we should later check why exactly this is the case
+ try:
+ type(self).__dict__['_type_']
+ except KeyError:
+ raise TypeError("%s has no _type_" % self.__class__)
Modified: pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/primitive.py
==============================================================================
--- pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/primitive.py (original)
+++ pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/primitive.py Sun Jan 6 15:46:18 2008
@@ -11,7 +11,6 @@
'z': 's',
}
-
TP_TO_DEFAULT = {
'c': 0,
'b': 0,
@@ -78,3 +77,9 @@
def alignment(tp):
return _ffi.alignment(tp._type_)
+
+def byref(cdata):
+ from ctypes import pointer
+ if not isinstance(cdata, _SimpleCData):
+ raise TypeError("expected CData instance")
+ return pointer(cdata)
More information about the Pypy-commit
mailing list