當前位置: 首頁>>代碼示例>>Python>>正文


Python ctypeobj.W_CType類代碼示例

本文整理匯總了Python中pypy.module._cffi_backend.ctypeobj.W_CType的典型用法代碼示例。如果您正苦於以下問題:Python W_CType類的具體用法?Python W_CType怎麽用?Python W_CType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了W_CType類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

 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
開發者ID:bukzor,項目名稱:pypy,代碼行數:10,代碼來源:ctypeptr.py

示例2: __init__

 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)
開發者ID:charred,項目名稱:pypy,代碼行數:12,代碼來源:ctypeptr.py

示例3: string

 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)
開發者ID:charred,項目名稱:pypy,代碼行數:34,代碼來源:ctypeptr.py

示例4: getcfield

 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)
開發者ID:bukzor,項目名稱:pypy,代碼行數:9,代碼來源:ctypestruct.py

示例5: _fget

 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)
開發者ID:bukzor,項目名稱:pypy,代碼行數:12,代碼來源:ctypestruct.py

示例6: getcfield

 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)
開發者ID:Qointum,項目名稱:pypy,代碼行數:13,代碼來源:ctypestruct.py

示例7: cast

 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)
開發者ID:charred,項目名稱:pypy,代碼行數:15,代碼來源:ctypeptr.py

示例8: __init__

 def __init__(self, space, name):
     W_CType.__init__(self, space, -1, name, len(name))
開發者ID:bukzor,項目名稱:pypy,代碼行數:2,代碼來源:ctypestruct.py

示例9: string

 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)
開發者ID:Darriall,項目名稱:pypy,代碼行數:6,代碼來源:ctypeprim.py

示例10: __init__

 def __init__(self, space, size, name, name_position, align):
     W_CType.__init__(self, space, size, name, name_position)
     self.align = align
開發者ID:Darriall,項目名稱:pypy,代碼行數:3,代碼來源:ctypeprim.py

示例11: string

 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)
開發者ID:kipras,項目名稱:pypy,代碼行數:6,代碼來源:ctypeprim.py

示例12: __init__

 def __init__(self, space):
     W_CType.__init__(self, space, -1, "void", len("void"))
開發者ID:Darriall,項目名稱:pypy,代碼行數:2,代碼來源:ctypevoid.py

示例13: string

 def string(self, cdataobj, maxlen):
     # Can't use ffi.string() on a function pointer
     return W_CType.string(self, cdataobj, maxlen)
開發者ID:mozillazg,項目名稱:pypy,代碼行數:3,代碼來源:ctypefunc.py

示例14: unpack_ptr

 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)
開發者ID:sota,項目名稱:pypy,代碼行數:5,代碼來源:ctypeprim.py


注:本文中的pypy.module._cffi_backend.ctypeobj.W_CType類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。