本文整理汇总了Python中pypy.module.cpyext.pyobject.get_typedescr函数的典型用法代码示例。如果您正苦于以下问题:Python get_typedescr函数的具体用法?Python get_typedescr怎么用?Python get_typedescr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_typedescr函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: PyFrame_New
def PyFrame_New(space, tstate, w_code, w_globals, w_locals):
typedescr = get_typedescr(PyFrame.typedef)
py_obj = typedescr.allocate(space, space.gettypeobject(PyFrame.typedef))
py_frame = rffi.cast(PyFrameObject, py_obj)
space.interp_w(PyCode, w_code) # sanity check
py_frame.c_f_code = rffi.cast(PyCodeObject, make_ref(space, w_code))
py_frame.c_f_globals = make_ref(space, w_globals)
return py_frame
开发者ID:gorakhargosh,项目名称:pypy,代码行数:8,代码来源:frameobject.py
示例2: type_attach
def type_attach(space, py_obj, w_type):
"""
Fills a newly allocated PyTypeObject from an existing type.
"""
from pypy.module.cpyext.object import PyObject_Del
assert isinstance(w_type, W_TypeObject)
pto = rffi.cast(PyTypeObjectPtr, py_obj)
typedescr = get_typedescr(w_type.layout.typedef)
# dealloc
pto.c_tp_dealloc = typedescr.get_dealloc(space)
# buffer protocol
if space.is_w(w_type, space.w_str):
setup_string_buffer_procs(space, pto)
if space.is_w(w_type, space.w_buffer):
setup_buffer_buffer_procs(space, pto)
pto.c_tp_free = llhelper(PyObject_Del.api_func.functype,
PyObject_Del.api_func.get_wrapper(space))
pto.c_tp_alloc = llhelper(PyType_GenericAlloc.api_func.functype,
PyType_GenericAlloc.api_func.get_wrapper(space))
if pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE:
w_typename = space.getattr(w_type, space.wrap('__name__'))
heaptype = rffi.cast(PyHeapTypeObject, pto)
heaptype.c_ht_name = make_ref(space, w_typename)
from pypy.module.cpyext.bytesobject import PyString_AsString
pto.c_tp_name = PyString_AsString(space, heaptype.c_ht_name)
else:
pto.c_tp_name = rffi.str2charp(w_type.name)
# uninitialized fields:
# c_tp_print, c_tp_getattr, c_tp_setattr
# XXX implement
# c_tp_compare and the following fields (see http://docs.python.org/c-api/typeobj.html )
w_base = best_base(space, w_type.bases_w)
pto.c_tp_base = rffi.cast(PyTypeObjectPtr, make_ref(space, w_base))
builder = space.fromcache(StaticObjectBuilder)
if builder.cpyext_type_init is not None:
builder.cpyext_type_init.append((pto, w_type))
else:
finish_type_1(space, pto)
finish_type_2(space, pto, w_type)
pto.c_tp_basicsize = rffi.sizeof(typedescr.basestruct)
if pto.c_tp_base:
if pto.c_tp_base.c_tp_basicsize > pto.c_tp_basicsize:
pto.c_tp_basicsize = pto.c_tp_base.c_tp_basicsize
# will be filled later on with the correct value
# may not be 0
if space.is_w(w_type, space.w_object):
pto.c_tp_new = rffi.cast(newfunc, 1)
update_all_slots(space, w_type, pto)
pto.c_tp_flags |= Py_TPFLAGS_READY
return pto
开发者ID:abhinavthomas,项目名称:pypy,代码行数:58,代码来源:typeobject.py
示例3: _PyObject_NewVar
def _PyObject_NewVar(space, type, itemcount):
w_type = from_ref(space, rffi.cast(PyObject, type))
assert isinstance(w_type, W_TypeObject)
typedescr = get_typedescr(w_type.instancetypedef)
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount)
py_obj.c_ob_refcnt = 0
if type.c_tp_itemsize == 0:
w_obj = PyObject_Init(space, py_obj, type)
else:
py_objvar = rffi.cast(PyVarObject, py_obj)
w_obj = PyObject_InitVar(space, py_objvar, type, itemcount)
return py_obj
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:12,代码来源:object.py
示例4: new_empty_str
def new_empty_str(space, length):
"""
Allocate a PyBytesObject and its ob_sval, but without a corresponding
interpreter object. The ob_sval may be mutated, until bytes_realize() is
called. Refcount of the result is 1.
"""
typedescr = get_typedescr(space.w_str.layout.typedef)
py_obj = typedescr.allocate(space, space.w_str, length)
py_str = rffi.cast(PyBytesObject, py_obj)
py_str.c_ob_shash = -1
py_str.c_ob_sstate = rffi.cast(rffi.INT, 0) # SSTATE_NOT_INTERNED
return py_str
开发者ID:mozillazg,项目名称:pypy,代码行数:12,代码来源:bytesobject.py
示例5: new_empty_tuple
def new_empty_tuple(space, length):
"""
Allocate a PyTupleObject and its array of PyObject *, but without a
corresponding interpreter object. The array may be mutated, until
tuple_realize() is called. Refcount of the result is 1.
"""
typedescr = get_typedescr(space.w_tuple.layout.typedef)
py_obj = typedescr.allocate(space, space.w_tuple, length)
py_tup = rffi.cast(PyTupleObject, py_obj)
p = py_tup.c_ob_item
for i in range(py_tup.c_ob_size):
p[i] = lltype.nullptr(PyObject.TO)
return py_obj
开发者ID:mozillazg,项目名称:pypy,代码行数:13,代码来源:tupleobject.py
示例6: new_empty_tuple
def new_empty_tuple(space, length):
"""
Allocate a PyTupleObject and its array of PyObject *, but without a
corresponding interpreter object. The array may be mutated, until
tuple_realize() is called. Refcount of the result is 1.
"""
typedescr = get_typedescr(space.w_tuple.layout.typedef)
py_obj = typedescr.allocate(space, space.w_tuple)
py_tup = rffi.cast(PyTupleObject, py_obj)
py_tup.c_ob_item = lltype.malloc(ObjectItems, length,
flavor='raw', zero=True)
py_tup.c_ob_size = length
return py_tup
开发者ID:cimarieta,项目名称:usp,代码行数:14,代码来源:tupleobject.py
示例7: new_empty_str
def new_empty_str(space, length):
"""
Allocate a PyStringObject and its buffer, but without a corresponding
interpreter object. The buffer may be mutated, until string_realize() is
called. Refcount of the result is 1.
"""
typedescr = get_typedescr(space.w_str.layout.typedef)
py_obj = typedescr.allocate(space, space.w_str)
py_str = rffi.cast(PyStringObject, py_obj)
buflen = length + 1
py_str.c_size = length
py_str.c_buffer = lltype.malloc(rffi.CCHARP.TO, buflen,
flavor='raw', zero=True)
return py_str
开发者ID:cimarieta,项目名称:usp,代码行数:15,代码来源:bytesobject.py
示例8: new_empty_str
def new_empty_str(space, length):
"""
Allocates a PyBytesObject and its buffer, but without a corresponding
interpreter object. The buffer may be mutated, until bytes_realize() is
called.
"""
typedescr = get_typedescr(space.w_bytes.instancetypedef)
py_obj = typedescr.allocate(space, space.w_bytes)
py_str = rffi.cast(PyBytesObject, py_obj)
buflen = length + 1
py_str.c_size = length
py_str.c_buffer = lltype.malloc(rffi.CCHARP.TO, buflen,
flavor='raw', zero=True)
return py_str
开发者ID:Qointum,项目名称:pypy,代码行数:15,代码来源:bytesobject.py
示例9: type_attach
def type_attach(space, py_obj, w_type):
"""
Fills a newly allocated PyTypeObject from an existing type.
"""
from pypy.module.cpyext.object import PyObject_Del
assert isinstance(w_type, W_TypeObject)
pto = rffi.cast(PyTypeObjectPtr, py_obj)
typedescr = get_typedescr(w_type.instancetypedef)
# dealloc
pto.c_tp_dealloc = typedescr.get_dealloc(space)
# buffer protocol
if space.is_w(w_type, space.w_str):
setup_string_buffer_procs(space, pto)
pto.c_tp_flags |= Py_TPFLAGS_HEAPTYPE
pto.c_tp_free = llhelper(PyObject_Del.api_func.functype,
PyObject_Del.api_func.get_wrapper(space))
pto.c_tp_alloc = llhelper(PyType_GenericAlloc.api_func.functype,
PyType_GenericAlloc.api_func.get_wrapper(space))
pto.c_tp_name = rffi.str2charp(w_type.getname(space))
pto.c_tp_basicsize = -1 # hopefully this makes malloc bail out
pto.c_tp_itemsize = 0
# uninitialized fields:
# c_tp_print, c_tp_getattr, c_tp_setattr
# XXX implement
# c_tp_compare and the following fields (see http://docs.python.org/c-api/typeobj.html )
w_base = best_base(space, w_type.bases_w)
pto.c_tp_base = rffi.cast(PyTypeObjectPtr, make_ref(space, w_base))
finish_type_1(space, pto)
finish_type_2(space, pto, w_type)
pto.c_tp_basicsize = rffi.sizeof(typedescr.basestruct)
if pto.c_tp_base:
if pto.c_tp_base.c_tp_basicsize > pto.c_tp_basicsize:
pto.c_tp_basicsize = pto.c_tp_base.c_tp_basicsize
# will be filled later on with the correct value
# may not be 0
if space.is_w(w_type, space.w_object):
pto.c_tp_new = rffi.cast(newfunc, 1)
update_all_slots(space, w_type, pto)
pto.c_tp_flags |= Py_TPFLAGS_READY
return pto
开发者ID:gorakhargosh,项目名称:pypy,代码行数:48,代码来源:typeobject.py
示例10: new_empty_unicode
def new_empty_unicode(space, length):
"""
Allocate a PyUnicodeObject and its buffer, but without a corresponding
interpreter object. The buffer may be mutated, until unicode_realize() is
called. Refcount of the result is 1.
"""
typedescr = get_typedescr(space.w_unicode.layout.typedef)
py_obj = typedescr.allocate(space, space.w_unicode)
py_uni = rffi.cast(PyUnicodeObject, py_obj)
buflen = length + 1
py_uni.c_length = length
py_uni.c_str = lltype.malloc(rffi.CWCHARP.TO, buflen,
flavor='raw', zero=True,
add_memory_pressure=True)
py_uni.c_hash = -1
py_uni.c_defenc = lltype.nullptr(PyObject.TO)
return py_uni
开发者ID:mozillazg,项目名称:pypy,代码行数:18,代码来源:unicodeobject.py
示例11: type_attach
def type_attach(space, py_obj, w_type):
"""
Fills a newly allocated PyTypeObject from an existing type.
"""
from pypy.module.cpyext.object import PyObject_Free
assert isinstance(w_type, W_TypeObject)
pto = rffi.cast(PyTypeObjectPtr, py_obj)
typedescr = get_typedescr(w_type.layout.typedef)
# dealloc
if space.gettypeobject(w_type.layout.typedef) is w_type:
# only for the exact type, like 'space.w_tuple' or 'space.w_list'
pto.c_tp_dealloc = typedescr.get_dealloc().get_llhelper(space)
else:
# for all subtypes, use subtype_dealloc()
pto.c_tp_dealloc = llslot(space, subtype_dealloc)
if space.is_w(w_type, space.w_str):
pto.c_tp_itemsize = 1
elif space.is_w(w_type, space.w_tuple):
pto.c_tp_itemsize = rffi.sizeof(PyObject)
# buffer protocol
setup_buffer_procs(space, w_type, pto)
pto.c_tp_free = llslot(space, PyObject_Free)
pto.c_tp_alloc = llslot(space, PyType_GenericAlloc)
builder = space.fromcache(StaticObjectBuilder)
if ((pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE) != 0
and builder.cpyext_type_init is None):
# this ^^^ is not None only during startup of cpyext. At that
# point we might get into troubles by doing make_ref() when
# things are not initialized yet. So in this case, simply use
# str2charp() and "leak" the string.
w_typename = space.getattr(w_type, space.wrap('__name__'))
heaptype = rffi.cast(PyHeapTypeObject, pto)
heaptype.c_ht_name = make_ref(space, w_typename)
from pypy.module.cpyext.bytesobject import PyString_AsString
pto.c_tp_name = PyString_AsString(space, heaptype.c_ht_name)
else:
pto.c_tp_name = rffi.str2charp(w_type.name)
# uninitialized fields:
# c_tp_print
# XXX implement
# c_tp_compare and more?
w_base = best_base(space, w_type.bases_w)
pto.c_tp_base = rffi.cast(PyTypeObjectPtr, make_ref(space, w_base))
if builder.cpyext_type_init is not None:
builder.cpyext_type_init.append((pto, w_type))
else:
finish_type_1(space, pto)
finish_type_2(space, pto, w_type)
pto.c_tp_basicsize = rffi.sizeof(typedescr.basestruct)
if pto.c_tp_base:
if pto.c_tp_base.c_tp_basicsize > pto.c_tp_basicsize:
pto.c_tp_basicsize = pto.c_tp_base.c_tp_basicsize
if pto.c_tp_itemsize < pto.c_tp_base.c_tp_itemsize:
pto.c_tp_itemsize = pto.c_tp_base.c_tp_itemsize
# will be filled later on with the correct value
# may not be 0
if space.is_w(w_type, space.w_object):
pto.c_tp_new = rffi.cast(newfunc, 1)
update_all_slots(space, w_type, pto)
pto.c_tp_flags |= Py_TPFLAGS_READY
return pto
开发者ID:mozillazg,项目名称:pypy,代码行数:69,代码来源:typeobject.py
注:本文中的pypy.module.cpyext.pyobject.get_typedescr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论