コード例 #1
0
ファイル: ctypeptr.py プロジェクト: juokaz/pypy
 def __init__(self, space, size, extra, extra_position, ctitem,
              could_cast_anything=True):
     name, name_position = ctitem.insert_name(extra, extra_position)
     W_CType.__init__(self, space, size, name, name_position)
     # this is the "underlying type":
     #  - for pointers, it is the pointed-to type
     #  - for arrays, it is the array item type
     #  - for functions, it is the return type
     self.ctitem = ctitem
     self.can_cast_anything = could_cast_anything and ctitem.cast_anything
コード例 #2
0
ファイル: ctypeptr.py プロジェクト: charred/pypy
 def __init__(self, space, size, extra, extra_position, ctitem,
              could_cast_anything=True):
     from pypy.module._cffi_backend.ctypestruct import W_CTypeStructOrUnion
     name, name_position = ctitem.insert_name(extra, extra_position)
     W_CType.__init__(self, space, size, name, name_position)
     # this is the "underlying type":
     #  - for pointers, it is the pointed-to type
     #  - for arrays, it is the array item type
     #  - for functions, it is the return type
     self.ctitem = ctitem
     self.can_cast_anything = could_cast_anything and ctitem.cast_anything
     self.is_struct_ptr = isinstance(ctitem, W_CTypeStructOrUnion)
コード例 #3
0
 def __init__(self, space, size, extra, extra_position, ctitem):
     name, name_position = ctitem.insert_name(extra, extra_position)
     W_CType.__init__(self, space, size, name, name_position)
     # this is the "underlying type":
     #  - for pointers, it is the pointed-to type
     #  - for arrays, it is the array item type
     #  - for functions, it is the return type
     self.ctitem = ctitem
     self.accept_str = (self.is_nonfunc_pointer_or_array and
             (isinstance(ctitem, ctypevoid.W_CTypeVoid) or
              isinstance(ctitem, ctypeprim.W_CTypePrimitiveChar) or
              (ctitem.is_primitive_integer and
               ctitem.size == rffi.sizeof(lltype.Char))))
コード例 #4
0
ファイル: ctypeptr.py プロジェクト: juokaz/pypy
 def string(self, cdataobj, maxlen):
     space = self.space
     if isinstance(self.ctitem, ctypeprim.W_CTypePrimitive):
         cdata = cdataobj._cdata
         if not cdata:
             raise oefmt(space.w_RuntimeError, "cannot use string() on %s",
                         space.str_w(cdataobj.repr()))
         #
         from pypy.module._cffi_backend import ctypearray
         length = maxlen
         if length < 0 and isinstance(self, ctypearray.W_CTypeArray):
             length = cdataobj.get_array_length()
         #
         # pointer to a primitive type of size 1: builds and returns a str
         if self.ctitem.size == rffi.sizeof(lltype.Char):
             if length < 0:
                 s = rffi.charp2str(cdata)
             else:
                 s = rffi.charp2strn(cdata, length)
             keepalive_until_here(cdataobj)
             return space.wrap(s)
         #
         # pointer to a wchar_t: builds and returns a unicode
         if self.is_unichar_ptr_or_array():
             cdata = rffi.cast(rffi.CWCHARP, cdata)
             if length < 0:
                 u = rffi.wcharp2unicode(cdata)
             else:
                 u = rffi.wcharp2unicoden(cdata, length)
             keepalive_until_here(cdataobj)
             return space.wrap(u)
     #
     return W_CType.string(self, cdataobj, maxlen)
コード例 #5
0
ファイル: ctypeptr.py プロジェクト: charred/pypy
 def string(self, cdataobj, maxlen):
     space = self.space
     if isinstance(self.ctitem, ctypeprim.W_CTypePrimitive):
         cdata = cdataobj._cdata
         if not cdata:
             raise operationerrfmt(space.w_RuntimeError,
                                   "cannot use string() on %s",
                                   space.str_w(cdataobj.repr()))
         #
         from pypy.module._cffi_backend import ctypearray
         length = maxlen
         if length < 0 and isinstance(self, ctypearray.W_CTypeArray):
             length = cdataobj.get_array_length()
         #
         # pointer to a primitive type of size 1: builds and returns a str
         if self.ctitem.size == rffi.sizeof(lltype.Char):
             if length < 0:
                 s = rffi.charp2str(cdata)
             else:
                 s = rffi.charp2strn(cdata, length)
             keepalive_until_here(cdataobj)
             return space.wrap(s)
         #
         # pointer to a wchar_t: builds and returns a unicode
         if self.is_unichar_ptr_or_array():
             cdata = rffi.cast(rffi.CWCHARP, cdata)
             if length < 0:
                 u = rffi.wcharp2unicode(cdata)
             else:
                 u = rffi.wcharp2unicoden(cdata, length)
             keepalive_until_here(cdataobj)
             return space.wrap(u)
     #
     return W_CType.string(self, cdataobj, maxlen)
コード例 #6
0
 def string(self, cdataobj, maxlen):
     space = self.space
     if (isinstance(self.ctitem, ctypeprim.W_CTypePrimitive) and
             not isinstance(self.ctitem, ctypeprim.W_CTypePrimitiveBool)):
         with cdataobj as ptr:
             if not ptr:
                 raise oefmt(space.w_RuntimeError,
                             "cannot use string() on %R", cdataobj)
             #
             from pypy.module._cffi_backend import ctypearray
             length = maxlen
             if length < 0 and isinstance(self, ctypearray.W_CTypeArray):
                 length = cdataobj.get_array_length()
             #
             # pointer to a primitive type of size 1: builds and returns a str
             if self.ctitem.size == rffi.sizeof(lltype.Char):
                 if length < 0:
                     s = rffi.charp2str(ptr)
                 else:
                     s = rffi.charp2strn(ptr, length)
                 return space.newbytes(s)
             #
             # pointer to a wchar_t: builds and returns a unicode
             if self.is_unichar_ptr_or_array():
                 from pypy.module._cffi_backend import wchar_helper
                 if self.ctitem.size == 2:
                     length = wchar_helper.measure_length_16(ptr, length)
                 else:
                     length = wchar_helper.measure_length_32(ptr, length)
                 return self.ctitem.unpack_ptr(self, ptr, length)
     #
     return W_CType.string(self, cdataobj, maxlen)
コード例 #7
0
 def getcfield(self, attr):
     if self.fields_dict is not None:
         self = jit.promote(self)
         attr = jit.promote_string(attr)
         try:
             return self._getcfield_const(attr)
         except KeyError:
             pass
     return W_CType.getcfield(self, attr)
コード例 #8
0
ファイル: ctypestruct.py プロジェクト: bukzor/pypy
 def getcfield(self, attr):
     if self.fields_dict is not None:
         self = jit.promote(self)
         attr = jit.promote_string(attr)
         try:
             return self._getcfield_const(attr)
         except KeyError:
             pass
     return W_CType.getcfield(self, attr)
コード例 #9
0
ファイル: ctypestruct.py プロジェクト: bukzor/pypy
 def _fget(self, attrchar):
     if attrchar == 'f':     # fields
         space = self.space
         if self.size < 0:
             return space.w_None
         result = [None] * len(self.fields_list)
         for fname, field in self.fields_dict.iteritems():
             i = self.fields_list.index(field)
             result[i] = space.newtuple([space.wrap(fname),
                                         space.wrap(field)])
         return space.newlist(result)
     return W_CType._fget(self, attrchar)
コード例 #10
0
ファイル: ctypestruct.py プロジェクト: fhalde/pypy
 def _fget(self, attrchar):
     if attrchar == 'f':  # fields
         space = self.space
         if self.size < 0:
             return space.w_None
         self.force_lazy_struct()
         result = [None] * len(self._fields_list)
         for fname, field in self._fields_dict.iteritems():
             i = self._fields_list.index(field)
             result[i] = space.newtuple([space.newtext(fname), field])
         return space.newlist(result)
     return W_CType._fget(self, attrchar)
コード例 #11
0
ファイル: ctypestruct.py プロジェクト: Qointum/pypy
 def getcfield(self, attr):
     ready = self._fields_dict is not None
     if not ready and self.size >= 0:
         self.force_lazy_struct()
         ready = True
     if ready:
         self = jit.promote(self)
         attr = jit.promote_string(attr)
         try:
             return self._getcfield_const(attr)
         except KeyError:
             pass
     return W_CType.getcfield(self, attr)
コード例 #12
0
ファイル: ctypestruct.py プロジェクト: Qointum/pypy
 def getcfield(self, attr):
     ready = self._fields_dict is not None
     if not ready and self.size >= 0:
         self.force_lazy_struct()
         ready = True
     if ready:
         self = jit.promote(self)
         attr = jit.promote_string(attr)
         try:
             return self._getcfield_const(attr)
         except KeyError:
             pass
     return W_CType.getcfield(self, attr)
コード例 #13
0
ファイル: ctypeptr.py プロジェクト: charred/pypy
 def cast(self, w_ob):
     # cast to a pointer, to a funcptr, or to an array.
     # Note that casting to an array is an extension to the C language,
     # which seems to be necessary in order to sanely get a
     # <cdata 'int[3]'> at some address.
     if self.size < 0:
         return W_CType.cast(self, w_ob)
     space = self.space
     if (isinstance(w_ob, cdataobj.W_CData) and
             isinstance(w_ob.ctype, W_CTypePtrOrArray)):
         value = w_ob._cdata
     else:
         value = misc.as_unsigned_long(space, w_ob, strict=False)
         value = rffi.cast(rffi.CCHARP, value)
     return cdataobj.W_CData(space, value, self)
コード例 #14
0
 def cast(self, w_ob):
     # cast to a pointer, to a funcptr, or to an array.
     # Note that casting to an array is an extension to the C language,
     # which seems to be necessary in order to sanely get a
     # <cdata 'int[3]'> at some address.
     if self.size < 0:
         return W_CType.cast(self, w_ob)
     space = self.space
     if (isinstance(w_ob, cdataobj.W_CData)
             and isinstance(w_ob.ctype, W_CTypePtrOrArray)):
         value = w_ob.unsafe_escaping_ptr()
     else:
         value = misc.as_unsigned_long(space, w_ob, strict=False)
         value = rffi.cast(rffi.CCHARP, value)
     return cdataobj.W_CData(space, value, self)
コード例 #15
0
 def string(self, cdataobj, maxlen):
     # Can't use ffi.string() on a function pointer
     return W_CType.string(self, cdataobj, maxlen)
コード例 #16
0
ファイル: ctypeprim.py プロジェクト: zielmicha/pypy
 def string(self, cdataobj, maxlen):
     if self.size == 1:
         with cdataobj as ptr:
             s = ptr[0]
         return self.space.wrap(s)
     return W_CType.string(self, cdataobj, maxlen)
コード例 #17
0
ファイル: ctypeprim.py プロジェクト: kipras/pypy
 def string(self, cdataobj, maxlen):
     if self.size == 1:
         s = cdataobj._cdata[0]
         keepalive_until_here(cdataobj)
         return self.space.wrap(s)
     return W_CType.string(self, cdataobj, maxlen)
コード例 #18
0
ファイル: ctypestruct.py プロジェクト: Qointum/pypy
 def __init__(self, space, name):
     W_CType.__init__(self, space, -1, name, len(name))
コード例 #19
0
ファイル: ctypestruct.py プロジェクト: bukzor/pypy
 def __init__(self, space, name):
     W_CType.__init__(self, space, -1, name, len(name))
コード例 #20
0
 def __init__(self, space):
     W_CType.__init__(self, space, -1, "void", len("void"))
コード例 #21
0
 def getcfield(self, attr):
     from pypy.module._cffi_backend.ctypestruct import W_CTypeStructOrUnion
     if isinstance(self.ctitem, W_CTypeStructOrUnion):
         return self.ctitem.getcfield(attr)
     return W_CType.getcfield(self, attr)
コード例 #22
0
ファイル: ctypefunc.py プロジェクト: mozillazg/pypy
 def string(self, cdataobj, maxlen):
     # Can't use ffi.string() on a function pointer
     return W_CType.string(self, cdataobj, maxlen)
コード例 #23
0
ファイル: ctypeprim.py プロジェクト: pointworld/pypy
 def unpack_ptr(self, w_ctypeptr, ptr, length):
     result = self.unpack_list_of_int_items(ptr, length)
     if result is not None:
         return self.space.newlist_int(result)
     return W_CType.unpack_ptr(self, w_ctypeptr, ptr, length)
コード例 #24
0
ファイル: ctypeprim.py プロジェクト: zielmicha/pypy
 def string(self, cdataobj, maxlen):
     # bypass the method 'string' implemented in W_CTypePrimitive
     return W_CType.string(self, cdataobj, maxlen)
コード例 #25
0
ファイル: ctypeprim.py プロジェクト: zielmicha/pypy
 def __init__(self, space, size, name, name_position, align):
     W_CType.__init__(self, space, size, name, name_position)
     self.align = align
コード例 #26
0
 def string(self, cdataobj, maxlen):
     if self.size == 1:
         s = cdataobj._cdata[0]
         keepalive_until_here(cdataobj)
         return self.space.wrap(s)
     return W_CType.string(self, cdataobj, maxlen)
コード例 #27
0
ファイル: ctypeprim.py プロジェクト: sota/pypy
 def unpack_ptr(self, w_ctypeptr, ptr, length):
     result = self.unpack_list_of_int_items(ptr, length)
     if result is not None:
         return self.space.newlist_int(result)
     return W_CType.unpack_ptr(self, w_ctypeptr, ptr, length)