[pypy-svn] r73972 - in pypy/branch/cpython-extension/pypy/module/cpyext: . include

afa at codespeak.net afa at codespeak.net
Thu Apr 22 14:17:48 CEST 2010


Author: afa
Date: Thu Apr 22 14:17:46 2010
New Revision: 73972

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/include/structmember.h
   pypy/branch/cpython-extension/pypy/module/cpyext/structmember.py
   pypy/branch/cpython-extension/pypy/module/cpyext/structmemberdefs.py
Log:
Implement more basic types for struct members


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/structmember.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/structmember.h	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/structmember.h	Thu Apr 22 14:17:46 2010
@@ -21,10 +21,15 @@
 
 
 /* Types */
+#define T_SHORT		0
 #define T_INT		1
+#define T_LONG		2
 #define T_STRING	5
 #define T_OBJECT	6
 #define T_CHAR		7	/* 1-character string */
+#define T_USHORT	10
+#define T_UINT		11
+#define T_ULONG		12
 #define T_STRING_INPLACE 13     /* Strings contained in the structure */
 #define T_OBJECT_EX	16	/* Like T_OBJECT, but raises AttributeError
 				   when the value is NULL, instead of

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/structmember.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/structmember.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/structmember.py	Thu Apr 22 14:17:46 2010
@@ -3,7 +3,7 @@
 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.module.cpyext import structmemberdefs
 from pypy.module.cpyext.api import ADDR, PyObjectP, cpython_api
-from pypy.module.cpyext.intobject import PyInt_AsLong
+from pypy.module.cpyext.intobject import PyInt_AsLong, PyInt_AsUnsignedLong
 from pypy.module.cpyext.pyerrors import PyErr_Occurred
 from pypy.module.cpyext.pyobject import PyObject, Py_DecRef, from_ref, make_ref
 from pypy.module.cpyext.stringobject import (PyString_FromString,
@@ -16,9 +16,24 @@
     addr = rffi.cast(ADDR, obj)
     addr += w_member.c_offset
     member_type = rffi.cast(lltype.Signed, w_member.c_type)
-    if member_type == structmemberdefs.T_INT:
+    if member_type == structmemberdefs.T_SHORT:
+        result = rffi.cast(rffi.SHORTP, addr)
+        w_result = space.wrap(result[0])
+    elif member_type == structmemberdefs.T_INT:
         result = rffi.cast(rffi.INTP, addr)
         w_result = space.wrap(result[0])
+    elif member_type == structmemberdefs.T_LONG:
+        result = rffi.cast(rffi.LONGP, addr)
+        w_result = space.wrap(result[0])
+    elif member_type == structmemberdefs.T_USHORT:
+        result = rffi.cast(rffi.USHORTP, addr)
+        w_result = space.wrap(result[0])
+    elif member_type == structmemberdefs.T_UINT:
+        result = rffi.cast(rffi.UINTP, addr)
+        w_result = space.wrap(result[0])
+    elif member_type == structmemberdefs.T_ULONG:
+        result = rffi.cast(rffi.ULONGP, addr)
+        w_result = space.wrap(result[0])
     elif member_type == structmemberdefs.T_STRING:
         result = rffi.cast(rffi.CCHARPP, addr)
         if result[0]:
@@ -68,10 +83,30 @@
             raise OperationError(space.w_TypeError,
                              space.wrap("can't delete numeric/char attribute"))
 
-    if member_type == structmemberdefs.T_INT:
+    if member_type == structmemberdefs.T_SHORT:
+        w_long_value = PyInt_AsLong(space, w_value)
+        array = rffi.cast(rffi.SHORTP, addr)
+        array[0] = rffi.cast(rffi.SHORT, w_long_value)
+    elif member_type == structmemberdefs.T_INT:
         w_long_value = PyInt_AsLong(space, w_value)
         array = rffi.cast(rffi.INTP, addr)
         array[0] = rffi.cast(rffi.INT, w_long_value)
+    elif member_type == structmemberdefs.T_LONG:
+        w_long_value = PyInt_AsLong(space, w_value)
+        array = rffi.cast(rffi.LONGP, addr)
+        array[0] = rffi.cast(rffi.LONG, w_long_value)
+    elif member_type == structmemberdefs.T_USHORT:
+        w_long_value = PyInt_AsUnsignedLong(space, w_value)
+        array = rffi.cast(rffi.USHORTP, addr)
+        array[0] = rffi.cast(rffi.USHORT, w_long_value)
+    elif member_type == structmemberdefs.T_UINT:
+        w_long_value = PyInt_AsUnsignedLong(space, w_value)
+        array = rffi.cast(rffi.UINTP, addr)
+        array[0] = rffi.cast(rffi.UINT, w_long_value)
+    elif member_type == structmemberdefs.T_ULONG:
+        w_long_value = PyInt_AsUnsignedLong(space, w_value)
+        array = rffi.cast(rffi.ULONGP, addr)
+        array[0] = rffi.cast(rffi.ULONG, w_long_value)
     elif member_type == structmemberdefs.T_CHAR:
         str_value = space.str_w(w_value)
         if len(str_value) != 1:

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/structmemberdefs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/structmemberdefs.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/structmemberdefs.py	Thu Apr 22 14:17:46 2010
@@ -1,7 +1,12 @@
+T_SHORT = 0
 T_INT = 1
+T_LONG = 2
 T_STRING = 5
 T_OBJECT = 6
 T_CHAR = 7
+T_USHORT = 10
+T_UINT = 11
+T_ULONG = 12
 T_STRING_INPLACE = 13
 T_OBJECT_EX = 16
 



More information about the Pypy-commit mailing list