[pypy-svn] r50530 - pypy/branch/applevel-ctypes2/pypy/lib/_ctypes
fijal at codespeak.net
fijal at codespeak.net
Sat Jan 12 15:44:56 CET 2008
Author: fijal
Date: Sat Jan 12 15:44:54 2008
New Revision: 50530
Added:
pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/basics.py (contents, props changed)
pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/structure.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/function.py
pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/pointer.py
pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/primitive.py
Log:
Shuffle stuff around a bit
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 Sat Jan 12 15:44:54 2008
@@ -1,14 +1,15 @@
-from _ctypes.dummy import Union, Structure, Array
+from _ctypes.dummy import Union, 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.basics import _CData
-from _ctypes.primitive import _SimpleCData, sizeof, alignment, byref
+from _ctypes.basics import _CData, sizeof, alignment, byref
+from _ctypes.primitive import _SimpleCData
from _ctypes.pointer import _Pointer
from _ctypes.function import CFuncPtr
from _ctypes.dll import dlopen
+from _ctypes.structure import Structure
__version__ = '1.0.2'
Added: pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/basics.py
==============================================================================
--- (empty file)
+++ pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/basics.py Sat Jan 12 15:44:54 2008
@@ -0,0 +1,30 @@
+
+import _ffi
+
+class _CData(object):
+ """ The most basic object for all ctypes types
+ """
+ pass
+
+class CArgObject(object):
+ def __init__(self, letter, raw_value, _type):
+ self.ffiletter = letter
+ self.raw_value = raw_value
+ self._type = _type
+
+ def __repr__(self):
+ return "<cparam '%s' %r>" % (self.ffiletter, self.raw_value)
+
+
+def sizeof(tp):
+ return _ffi.sizeof(tp._type_)
+
+def alignment(tp):
+ return _ffi.alignment(tp._type_)
+
+def byref(cdata):
+ from ctypes import pointer, _SimpleCData
+ if not isinstance(cdata, _SimpleCData):
+ raise TypeError("expected CData instance")
+ return pointer(cdata)._as_ffi()
+
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 Sat Jan 12 15:44:54 2008
@@ -4,9 +4,6 @@
class Union(object):
__metaclass__ = UnionType
-class Structure(type):
- pass
-
class Array(type):
pass
Modified: pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/function.py
==============================================================================
--- pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/function.py (original)
+++ pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/function.py Sat Jan 12 15:44:54 2008
@@ -1,5 +1,5 @@
import _ffi
-from _ctypes.param import CArgObject
+from _ctypes.basics import CArgObject
class CFuncPtrType(type):
# XXX write down here defaults and such things
Modified: pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/pointer.py
==============================================================================
--- pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/pointer.py (original)
+++ pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/pointer.py Sat Jan 12 15:44:54 2008
@@ -1,7 +1,6 @@
import _ffi
-from _ctypes.basics import _CData
-from _ctypes.param import CArgObject
+from _ctypes.basics import _CData, CArgObject
DEFAULT_VALUE = object()
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 Sat Jan 12 15:44:54 2008
@@ -2,8 +2,7 @@
SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXOv"
-from _ctypes.basics import _CData
-from _ctypes.param import CArgObject
+from _ctypes.basics import _CData, CArgObject
class NULL(object):
pass
@@ -84,16 +83,3 @@
def __repr__(self):
return "%s(%s)" % (type(self).__name__, self.value)
-
-def sizeof(tp):
- return _ffi.sizeof(tp._type_)
-
-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)._as_ffi()
-
Added: pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/structure.py
==============================================================================
--- (empty file)
+++ pypy/branch/applevel-ctypes2/pypy/lib/_ctypes/structure.py Sat Jan 12 15:44:54 2008
@@ -0,0 +1,9 @@
+
+from _ctypes.basics import _CData
+
+class StructureMeta(type):
+ def __new__(self, name, cls, typedict):
+ return type.__new__(self, name, cls, typedict)
+
+class Structure(_CData):
+ __metaclass__ = StructureMeta
More information about the Pypy-commit
mailing list