[pypy-svn] r50732 - pypy/dist/pypy/lib/_ctypes
fijal at codespeak.net
fijal at codespeak.net
Thu Jan 17 21:57:09 CET 2008
Author: fijal
Date: Thu Jan 17 21:57:08 2008
New Revision: 50732
Modified:
pypy/dist/pypy/lib/_ctypes/array.py
pypy/dist/pypy/lib/_ctypes/function.py
pypy/dist/pypy/lib/_ctypes/pointer.py
pypy/dist/pypy/lib/_ctypes/structure.py
Log:
Few minor things. I hope to find tests for these features one day...
(rewritten from C)
Modified: pypy/dist/pypy/lib/_ctypes/array.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/array.py (original)
+++ pypy/dist/pypy/lib/_ctypes/array.py Thu Jan 17 21:57:08 2008
@@ -45,6 +45,14 @@
def _alignmentofinstances(self):
return self._type_._alignmentofinstances()
+ def from_param(self, value):
+ # check for iterable
+ if hasattr(value, '__iter__'):
+ if len(value) > self._length_:
+ raise ValueError("%s too long" % (value,))
+ return self(*value)
+ return _CDataMeta.from_param(self, value)
+
class Array(_CData):
__metaclass__ = ArrayMeta
_ffiletter = 'P'
Modified: pypy/dist/pypy/lib/_ctypes/function.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/function.py (original)
+++ pypy/dist/pypy/lib/_ctypes/function.py Thu Jan 17 21:57:08 2008
@@ -1,10 +1,16 @@
import types
from _ctypes.basics import _CData, _CDataMeta
+import _rawffi
class CFuncPtrType(_CDataMeta):
# XXX write down here defaults and such things
- pass
+
+ def _sizeofinstances(self):
+ return _rawffi.sizeof('P')
+
+ def _alignmentofinstances(self):
+ return _rawffi.alignment('P')
class CFuncPtr(_CData):
__metaclass__ = CFuncPtrType
@@ -12,7 +18,7 @@
_argtypes_ = None
_restype_ = None
_ffiletter = 'P'
- _buffer = 0
+ _ffishape = 'P'
def _getargtypes(self):
return self._argtypes_
@@ -31,6 +37,8 @@
self.name, self.dll = address_or_name_and_dll
else:
self.address = address_or_name_and_dll
+ if isinstance(self.address, int):
+ self._buffer = _rawffi.Array('P').fromaddress(self.address, 1)
self.name = None
def __call__(self, *args):
Modified: pypy/dist/pypy/lib/_ctypes/pointer.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/pointer.py (original)
+++ pypy/dist/pypy/lib/_ctypes/pointer.py Thu Jan 17 21:57:08 2008
@@ -21,16 +21,11 @@
for k, v in d.iteritems():
setattr(obj, k, v)
if '_type_' in typedict:
- ffiarray = _rawffi.Array('P')
- def __init__(self, value=None):
- self._buffer = ffiarray(1)
- if value is not None:
- self.contents = value
- obj._ffiarray = ffiarray
+ self.set_type(obj, typedict['_type_'])
else:
def __init__(self, value=None):
raise TypeError("%s has no type" % obj)
- obj.__init__ = __init__
+ obj.__init__ = __init__
return obj
def from_param(self, value):
@@ -56,7 +51,14 @@
return True
def set_type(self, TP):
- pass # XXX???
+ ffiarray = _rawffi.Array('P')
+ def __init__(self, value=None):
+ self._buffer = ffiarray(1)
+ if value is not None:
+ self.contents = value
+ self._ffiarray = ffiarray
+ self.__init__ = __init__
+ self._type_ = TP
from_address = cdata_from_address
Modified: pypy/dist/pypy/lib/_ctypes/structure.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/structure.py (original)
+++ pypy/dist/pypy/lib/_ctypes/structure.py Thu Jan 17 21:57:08 2008
@@ -44,6 +44,10 @@
def __setattr__(self, name, value):
raise AttributeError(name)
+ def __repr__(self):
+ return "<Field '%s' offset=%d size=%d>" % (self.name, self.offset,
+ self.size)
+
class StructureMeta(_CDataMeta):
def __new__(self, name, cls, typedict):
res = type.__new__(self, name, cls, typedict)
More information about the Pypy-commit
mailing list