Author: Amaury Forgeot d'Arc <[email protected]>
Branch:
Changeset: r75859:7d23e48e92d6
Date: 2015-02-13 16:49 +0100
http://bitbucket.org/pypy/pypy/changeset/7d23e48e92d6/
Log: Rename more class attributes to follow ctypes convention for
_private_ names.
diff --git a/lib_pypy/_ctypes/array.py b/lib_pypy/_ctypes/array.py
--- a/lib_pypy/_ctypes/array.py
+++ b/lib_pypy/_ctypes/array.py
@@ -9,7 +9,7 @@
def __new__(self, name, cls, typedict):
res = type.__new__(self, name, cls, typedict)
if '_type_' in typedict:
- ffiarray = _rawffi.Array(typedict['_type_']._ffishape)
+ ffiarray = _rawffi.Array(typedict['_type_']._ffishape_)
res._ffiarray = ffiarray
subletter = getattr(typedict['_type_'], '_type_', None)
if subletter == 'c':
@@ -58,8 +58,8 @@
res.value = property(getvalue, setvalue)
if '_length_' in typedict:
- res._ffishape = (ffiarray, typedict['_length_'])
- res._fficompositesize = res._sizeofinstances()
+ res._ffishape_ = (ffiarray, typedict['_length_'])
+ res._fficompositesize_ = res._sizeofinstances()
else:
res._ffiarray = None
return res
@@ -156,7 +156,7 @@
class Array(_CData):
__metaclass__ = ArrayMeta
- _ffiargshape = 'P'
+ _ffiargshape_ = 'P'
def __init__(self, *args):
if not hasattr(self, '_buffer'):
@@ -191,13 +191,13 @@
if ensure_objects(cobj) is not None:
store_reference(self, index, cobj._objects)
arg = cobj._get_buffer_value()
- if self._type_._fficompositesize is None:
+ if self._type_._fficompositesize_ is None:
self._buffer[index] = arg
# something more sophisticated, cannot set field directly
else:
from ctypes import memmove
dest = self._buffer.itemaddress(index)
- memmove(dest, arg, self._type_._fficompositesize)
+ memmove(dest, arg, self._type_._fficompositesize_)
def __getitem__(self, index):
if isinstance(index, slice):
diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py
--- a/lib_pypy/_ctypes/basics.py
+++ b/lib_pypy/_ctypes/basics.py
@@ -52,7 +52,7 @@
def get_ffi_argtype(self):
if self._ffiargtype:
return self._ffiargtype
- self._ffiargtype = _shape_to_ffi_type(self._ffiargshape)
+ self._ffiargtype = _shape_to_ffi_type(self._ffiargshape_)
return self._ffiargtype
def _CData_output(self, resbuffer, base=None, index=-1):
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -65,9 +65,9 @@
_restype_ = None
_errcheck_ = None
_flags_ = 0
- _ffiargshape = 'P'
- _ffishape = 'P'
- _fficompositesize = None
+ _ffiargshape_ = 'P'
+ _ffishape_ = 'P'
+ _fficompositesize_ = None
_ffiarray = _rawffi.Array('P')
_needs_free = False
callable = None
@@ -98,7 +98,7 @@
argtypes = property(_getargtypes, _setargtypes)
def _check_argtypes_for_fastpath(self):
- if all([hasattr(argtype, '_ffiargshape') for argtype in
self._argtypes_]):
+ if all([hasattr(argtype, '_ffiargshape_') for argtype in
self._argtypes_]):
fastpath_cls = make_fastpath_subclass(self.__class__)
fastpath_cls.enable_fastpath_maybe(self)
@@ -135,7 +135,7 @@
_flag = flag & PARAMFLAG_COMBINED
if _flag == PARAMFLAG_FOUT:
typ = self._argtypes_[idx]
- if getattr(typ, '_ffiargshape', None) not in ('P', 'z', 'Z'):
+ if getattr(typ, '_ffiargshape_', None) not in ('P', 'z', 'Z'):
raise TypeError(
"'out' parameter %d must be a pointer type, not %s"
% (idx+1, type(typ).__name__)
@@ -182,11 +182,11 @@
def _ffishapes(self, args, restype):
if args is None:
args = []
- argtypes = [arg._ffiargshape for arg in args]
+ argtypes = [arg._ffiargshape_ for arg in args]
if restype is not None:
if not isinstance(restype, SimpleType):
raise TypeError("invalid result type for callback function")
- restype = restype._ffiargshape
+ restype = restype._ffiargshape_
else:
restype = 'O' # void
return argtypes, restype
@@ -599,7 +599,7 @@
if self._is_primitive(restype) and not restype._is_pointer_like():
return result
#
- shape = restype._ffishape
+ shape = restype._ffishape_
if is_struct_shape(shape):
buf = result
else:
diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py
--- a/lib_pypy/_ctypes/pointer.py
+++ b/lib_pypy/_ctypes/pointer.py
@@ -21,9 +21,9 @@
size = _rawffi.sizeof('P'),
align = _rawffi.alignment('P'),
length = 1,
- _ffiargshape = 'P',
- _ffishape = 'P',
- _fficompositesize = None,
+ _ffiargshape_ = 'P',
+ _ffishape_ = 'P',
+ _fficompositesize_ = None,
)
# XXX check if typedict['_type_'] is any sane
# XXX remember about paramfunc
diff --git a/lib_pypy/_ctypes/primitive.py b/lib_pypy/_ctypes/primitive.py
--- a/lib_pypy/_ctypes/primitive.py
+++ b/lib_pypy/_ctypes/primitive.py
@@ -117,9 +117,9 @@
default = TP_TO_DEFAULT[tp]
ffiarray = _rawffi.Array(tp)
result = type.__new__(self, name, bases, dct)
- result._ffiargshape = tp
- result._ffishape = tp
- result._fficompositesize = None
+ result._ffiargshape_ = tp
+ result._ffishape_ = tp
+ result._fficompositesize_ = None
result._ffiarray = ffiarray
if tp == 'z':
# c_char_p
diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py
--- a/lib_pypy/_ctypes/structure.py
+++ b/lib_pypy/_ctypes/structure.py
@@ -36,9 +36,9 @@
rawfields = []
for f in all_fields:
if len(f) > 2:
- rawfields.append((f[0], f[1]._ffishape, f[2]))
+ rawfields.append((f[0], f[1]._ffishape_, f[2]))
else:
- rawfields.append((f[0], f[1]._ffishape))
+ rawfields.append((f[0], f[1]._ffishape_))
_set_shape(self, rawfields, self._is_union)
@@ -48,8 +48,8 @@
value = field[1]
is_bitfield = (len(field) == 3)
fields[name] = Field(name,
- self._ffistruct.fieldoffset(name),
- self._ffistruct.fieldsize(name),
+ self._ffistruct_.fieldoffset(name),
+ self._ffistruct_.fieldsize(name),
value, i, is_bitfield)
if anonymous_fields:
@@ -58,7 +58,7 @@
name = field[0]
value = field[1]
is_bitfield = (len(field) == 3)
- startpos = self._ffistruct.fieldoffset(name)
+ startpos = self._ffistruct_.fieldoffset(name)
if name in anonymous_fields:
for subname in value._names_:
resnames.append(subname)
@@ -114,19 +114,19 @@
elif ensure_objects(cobj) is not None:
store_reference(obj, key, cobj._objects)
arg = cobj._get_buffer_value()
- if fieldtype._fficompositesize is not None:
+ if fieldtype._fficompositesize_ is not None:
from ctypes import memmove
dest = obj._buffer.fieldaddress(self.name)
- memmove(dest, arg, fieldtype._fficompositesize)
+ memmove(dest, arg, fieldtype._fficompositesize_)
else:
obj._buffer.__setattr__(self.name, arg)
def _set_shape(tp, rawfields, is_union=False):
- tp._ffistruct = _rawffi.Structure(rawfields, is_union,
+ tp._ffistruct_ = _rawffi.Structure(rawfields, is_union,
getattr(tp, '_pack_', 0))
- tp._ffiargshape = tp._ffishape = (tp._ffistruct, 1)
- tp._fficompositesize = tp._ffistruct.size
+ tp._ffiargshape_ = tp._ffishape_ = (tp._ffistruct_, 1)
+ tp._fficompositesize_ = tp._ffistruct_.size
def struct_setattr(self, name, value):
@@ -181,16 +181,16 @@
address = address.buffer
# fix the address: turn it into as unsigned, in case it is negative
address = address & (sys.maxint * 2 + 1)
- instance.__dict__['_buffer'] = self._ffistruct.fromaddress(address)
+ instance.__dict__['_buffer'] = self._ffistruct_.fromaddress(address)
return instance
def _sizeofinstances(self):
- if not hasattr(self, '_ffistruct'):
+ if not hasattr(self, '_ffistruct_'):
return 0
- return self._ffistruct.size
+ return self._ffistruct_.size
def _alignmentofinstances(self):
- return self._ffistruct.alignment
+ return self._ffistruct_.alignment
def from_param(self, value):
if isinstance(value, tuple):
@@ -203,7 +203,7 @@
def _CData_output(self, resarray, base=None, index=-1):
res = StructOrUnion.__new__(self)
- ffistruct = self._ffistruct.fromaddress(resarray.buffer)
+ ffistruct = self._ffistruct_.fromaddress(resarray.buffer)
res.__dict__['_buffer'] = ffistruct
res.__dict__['_base'] = base
res.__dict__['_index'] = index
@@ -224,8 +224,8 @@
self = super(_CData, cls).__new__(cls, *args, **kwds)
if '_abstract_' in cls.__dict__:
raise TypeError("abstract class")
- if hasattr(cls, '_ffistruct'):
- self.__dict__['_buffer'] = self._ffistruct(autofree=True)
+ if hasattr(cls, '_ffistruct_'):
+ self.__dict__['_buffer'] = self._ffistruct_(autofree=True)
return self
def __init__(self, *args, **kwds):
@@ -244,7 +244,7 @@
"""Return a _rawffi array of length 1 whose address is the same as
the address of the field 'name' of self."""
address = self._buffer.fieldaddress(name)
- A = _rawffi.Array(fieldtype._ffishape)
+ A = _rawffi.Array(fieldtype._ffishape_)
return A.fromaddress(address, 1)
def _get_buffer_for_param(self):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit