本文整理匯總了Python中pypy.module._cffi_backend.ctypeobj.W_CType.string方法的典型用法代碼示例。如果您正苦於以下問題:Python W_CType.string方法的具體用法?Python W_CType.string怎麽用?Python W_CType.string使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pypy.module._cffi_backend.ctypeobj.W_CType
的用法示例。
在下文中一共展示了W_CType.string方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: string
# 需要導入模塊: from pypy.module._cffi_backend.ctypeobj import W_CType [as 別名]
# 或者: from pypy.module._cffi_backend.ctypeobj.W_CType import string [as 別名]
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)
示例2: string
# 需要導入模塊: from pypy.module._cffi_backend.ctypeobj import W_CType [as 別名]
# 或者: from pypy.module._cffi_backend.ctypeobj.W_CType import string [as 別名]
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)
示例3: string
# 需要導入模塊: from pypy.module._cffi_backend.ctypeobj import W_CType [as 別名]
# 或者: from pypy.module._cffi_backend.ctypeobj.W_CType import string [as 別名]
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)
示例4: string
# 需要導入模塊: from pypy.module._cffi_backend.ctypeobj import W_CType [as 別名]
# 或者: from pypy.module._cffi_backend.ctypeobj.W_CType import string [as 別名]
def string(self, cdataobj, maxlen):
# Can't use ffi.string() on a function pointer
return W_CType.string(self, cdataobj, maxlen)