[pypy-svn] r78799 - pypy/branch/fast-forward/pypy/module/cpyext
afa at codespeak.net
afa at codespeak.net
Sat Nov 6 23:55:00 CET 2010
Author: afa
Date: Sat Nov 6 23:54:57 2010
New Revision: 78799
Modified:
pypy/branch/fast-forward/pypy/module/cpyext/structmember.py
Log:
Run tests, and fix mistakes
Modified: pypy/branch/fast-forward/pypy/module/cpyext/structmember.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/cpyext/structmember.py (original)
+++ pypy/branch/fast-forward/pypy/module/cpyext/structmember.py Sat Nov 6 23:54:57 2010
@@ -1,7 +1,7 @@
from pypy.interpreter.error import OperationError
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from pypy.rpython.lltypesystem import rffi, lltype
-from pypy.module.cpyext import structmemberdefs
+from pypy.module.cpyext.structmemberdefs import *
from pypy.module.cpyext.api import ADDR, PyObjectP, cpython_api
from pypy.module.cpyext.intobject import PyInt_AsLong, PyInt_AsUnsignedLong
from pypy.module.cpyext.pyerrors import PyErr_Occurred
@@ -12,13 +12,13 @@
from pypy.rlib.unroll import unrolling_iterable
integer_converters = unrolling_iterable([
- (structmemberdefs.T_SHORT, rffi.SHORT, PyInt_AsLong),
- (structmemberdefs.T_INT, rffi.INT, PyInt_AsLong),
- (structmemberdefs.T_LONG, rffi.LONG, PyInt_AsLong),
- (structmemberdefs.T_USHORT, rffi.USHORT, PyInt_AsUnsignedLong),
- (structmemberdefs.T_UINT, rffi.UINT, PyInt_AsUnsignedLong),
- (structmemberdefs.T_ULONG, rffi.ULONG, PyInt_AsUnsignedLong),
- (structmemberdefs.T_BYTE, rffi.UCHAR, PyInt_AsLong),
+ (T_SHORT, rffi.SHORT, PyInt_AsLong),
+ (T_INT, rffi.INT, PyInt_AsLong),
+ (T_LONG, rffi.LONG, PyInt_AsLong),
+ (T_USHORT, rffi.USHORT, PyInt_AsUnsignedLong),
+ (T_UINT, rffi.UINT, PyInt_AsUnsignedLong),
+ (T_ULONG, rffi.ULONG, PyInt_AsUnsignedLong),
+ (T_BYTE, rffi.UCHAR, PyInt_AsLong),
])
@@ -29,25 +29,25 @@
member_type = rffi.cast(lltype.Signed, w_member.c_type)
for converter in integer_converters:
- typ, lltype, _ = converter
- if typ == member_type
- result = rffi.cast(rffi.CArrayPtr(lltype), addr)
+ typ, lltyp, _ = converter
+ if typ == member_type:
+ result = rffi.cast(rffi.CArrayPtr(lltyp), addr)
w_result = space.wrap(result[0])
return w_result
- if member_type == structmemberdefs.T_STRING:
+ if member_type == T_STRING:
result = rffi.cast(rffi.CCHARPP, addr)
if result[0]:
w_result = PyString_FromString(space, result[0])
else:
w_result = space.w_None
- elif member_type == structmemberdefs.T_STRING_INPLACE:
+ elif member_type == T_STRING_INPLACE:
result = rffi.cast(rffi.CCHARP, addr)
w_result = PyString_FromString(space, result)
- elif member_type == structmemberdefs.T_CHAR:
+ elif member_type == T_CHAR:
result = rffi.cast(rffi.CCHARP, addr)
w_result = space.wrap(result[0])
- elif member_type == structmemberdefs.T_OBJECT:
+ elif member_type == T_OBJECT:
obj_ptr = rffi.cast(PyObjectP, addr)
if obj_ptr[0]:
w_result = from_ref(space, obj_ptr[0])
@@ -73,37 +73,35 @@
member_type = rffi.cast(lltype.Signed, w_member.c_type)
flags = rffi.cast(lltype.Signed, w_member.c_flags)
- if (flags & structmemberdefs.READONLY or
- member_type in [structmemberdefs.T_STRING,
- structmemberdefs.T_STRING_INPLACE]):
+ if (flags & READONLY or
+ member_type in [T_STRING, T_STRING_INPLACE]):
raise OperationError(space.w_TypeError,
space.wrap("readonly attribute"))
elif w_value is None:
- if member_type == structmemberdefs.T_OBJECT_EX:
+ if member_type == T_OBJECT_EX:
if not rffi.cast(PyObjectP, addr)[0]:
w_name = space.wrap(rffi.charp2str(w_member.c_name))
raise OperationError(space.w_AttributeError, w_name)
- elif member_type != structmemberdefs.T_OBJECT:
+ elif member_type != T_OBJECT:
raise OperationError(space.w_TypeError,
space.wrap("can't delete numeric/char attribute"))
for converter in integer_converters:
- typ, lltype, getter = converter
+ typ, lltyp, getter = converter
if typ == member_type:
value = getter(space, w_value)
- array = rffi.cast(rffi.CarrayPtr(lltype), addr)
- array[0] = rffi.cast(lltype, value)
+ array = rffi.cast(rffi.CArrayPtr(lltyp), addr)
+ array[0] = rffi.cast(lltyp, value)
return 0
- if member_type == structmemberdefs.T_CHAR:
+ if member_type == T_CHAR:
str_value = space.str_w(w_value)
if len(str_value) != 1:
raise OperationError(space.w_TypeError,
space.wrap("string of length 1 expected"))
array = rffi.cast(rffi.CCHARP, addr)
array[0] = str_value[0]
- elif member_type in [structmemberdefs.T_OBJECT,
- structmemberdefs.T_OBJECT_EX]:
+ elif member_type in [T_OBJECT, T_OBJECT_EX]:
array = rffi.cast(PyObjectP, addr)
if array[0]:
Py_DecRef(space, array[0])
More information about the Pypy-commit
mailing list