本文整理汇总了Python中pypy.module.cpyext.pyobject.borrow_from函数的典型用法代码示例。如果您正苦于以下问题:Python borrow_from函数的具体用法?Python borrow_from怎么用?Python borrow_from使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了borrow_from函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: PyEval_GetGlobals
def PyEval_GetGlobals(space):
"""Return a dictionary of the global variables in the current execution
frame, or NULL if no frame is currently executing."""
caller = space.getexecutioncontext().gettopframe_nohidden()
if caller is None:
return None
return borrow_from(None, caller.w_globals)
开发者ID:Qointum,项目名称:pypy,代码行数:7,代码来源:eval.py
示例2: PySys_GetObject
def PySys_GetObject(space, name):
"""Return the object name from the sys module or NULL if it does
not exist, without setting an exception."""
name = rffi.charp2str(name)
w_dict = space.sys.getdict(space)
w_obj = space.finditem_str(w_dict, name)
return borrow_from(None, w_obj)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:sysmodule.py
示例3: _Py_InitPyPyModule
def _Py_InitPyPyModule(space, name, methods, doc, w_self, apiver):
"""
Create a new module object based on a name and table of functions, returning
the new module object. If doc is non-NULL, it will be used to define the
docstring for the module. If self is non-NULL, it will passed to the
functions of the module as their (otherwise NULL) first parameter. (This was
added as an experimental feature, and there are no known uses in the current
version of Python.) For apiver, the only value which should be passed is
defined by the constant PYTHON_API_VERSION.
Note that the name parameter is actually ignored, and the module name is
taken from the package_context attribute of the cpyext.State in the space
cache. CPython includes some extra checking here to make sure the module
being initialized lines up with what's expected, but we don't.
"""
from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr
modname = rffi.charp2str(name)
state = space.fromcache(State)
f_name, f_path = state.package_context
w_mod = PyImport_AddModule(space, f_name)
dict_w = {'__file__': space.wrap(f_path)}
convert_method_defs(space, dict_w, methods, None, w_self, modname)
for key, w_value in dict_w.items():
space.setattr(w_mod, space.wrap(key), w_value)
if doc:
space.setattr(w_mod, space.wrap("__doc__"),
space.wrap(rffi.charp2str(doc)))
return borrow_from(None, w_mod)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:29,代码来源:modsupport.py
示例4: PyModule_GetDict
def PyModule_GetDict(space, w_mod):
if PyModule_Check(space, w_mod):
assert isinstance(w_mod, Module)
w_dict = w_mod.getdict(space)
return borrow_from(w_mod, w_dict)
else:
PyErr_BadInternalCall(space)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:modsupport.py
示例5: test_borrowing
def test_borrowing(self, space, api):
w_int = space.wrap(1)
w_tuple = space.newtuple([w_int])
api.Py_IncRef(w_tuple)
one_pyo = borrow_from(w_tuple, w_int).get_ref(space)
api.Py_DecRef(w_tuple)
state = space.fromcache(RefcountState)
state.print_refcounts()
py.test.raises(AssertionError, api.Py_DecRef, one_pyo)
开发者ID:Qointum,项目名称:pypy,代码行数:9,代码来源:test_borrow.py
示例6: PyDict_GetItemString
def PyDict_GetItemString(space, w_dict, key):
"""This is the same as PyDict_GetItem(), but key is specified as a
char*, rather than a PyObject*."""
try:
w_res = space.finditem_str(w_dict, rffi.charp2str(key))
except:
w_res = None
if w_res is None:
return None
return borrow_from(w_dict, w_res)
开发者ID:pypyjs,项目名称:pypy,代码行数:10,代码来源:dictobject.py
示例7: PySequence_Fast_GET_ITEM
def PySequence_Fast_GET_ITEM(space, w_obj, index):
"""Return the ith element of o, assuming that o was returned by
PySequence_Fast(), o is not NULL, and that i is within bounds.
"""
if isinstance(w_obj, listobject.W_ListObject):
w_res = w_obj.getitem(index)
else:
assert isinstance(w_obj, tupleobject.W_TupleObject)
w_res = w_obj.wrappeditems[index]
return borrow_from(w_obj, w_res)
开发者ID:charred,项目名称:pypy,代码行数:10,代码来源:sequence.py
示例8: _PyType_Lookup
def _PyType_Lookup(space, type, w_name):
"""Internal API to look for a name through the MRO.
This returns a borrowed reference, and doesn't set an exception!"""
w_type = from_ref(space, rffi.cast(PyObject, type))
assert isinstance(w_type, W_TypeObject)
if not space.isinstance_w(w_name, space.w_str):
return None
name = space.str_w(w_name)
w_obj = w_type.lookup(name)
return borrow_from(w_type, w_obj)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:11,代码来源:typeobject.py
示例9: PyList_GetItem
def PyList_GetItem(space, w_list, index):
"""Return the object at position pos in the list pointed to by p. The
position must be positive, indexing from the end of the list is not
supported. If pos is out of bounds, return NULL and set an
IndexError exception."""
if not isinstance(w_list, W_ListObject):
PyErr_BadInternalCall(space)
wrappeditems = w_list.getitems()
if index < 0 or index >= len(wrappeditems):
raise OperationError(space.w_IndexError, space.wrap(
"list index out of range"))
return borrow_from(w_list, wrappeditems[index])
开发者ID:charred,项目名称:pypy,代码行数:12,代码来源:listobject.py
示例10: PyEval_GetBuiltins
def PyEval_GetBuiltins(space):
"""Return a dictionary of the builtins in the current execution
frame, or the interpreter of the thread state if no frame is
currently executing."""
caller = space.getexecutioncontext().gettopframe_nohidden()
if caller is not None:
w_globals = caller.w_globals
w_builtins = space.getitem(w_globals, space.wrap('__builtins__'))
if not space.isinstance_w(w_builtins, space.w_dict):
w_builtins = w_builtins.getdict(space)
else:
w_builtins = space.builtin.getdict(space)
return borrow_from(None, w_builtins)
开发者ID:Qointum,项目名称:pypy,代码行数:13,代码来源:eval.py
示例11: PyImport_AddModule
def PyImport_AddModule(space, name):
"""Return the module object corresponding to a module name. The name
argument may be of the form package.module. First check the modules
dictionary if there's one there, and if not, create a new one and insert
it in the modules dictionary. Return NULL with an exception set on
failure.
This function does not load or import the module; if the module wasn't
already loaded, you will get an empty module object. Use
PyImport_ImportModule() or one of its variants to import a module.
Package structures implied by a dotted name for name are not created if
not already present."""
from pypy.module.imp.importing import check_sys_modules_w
modulename = rffi.charp2str(name)
w_mod = check_sys_modules_w(space, modulename)
if not w_mod or space.is_w(w_mod, space.w_None):
w_mod = Module(space, space.wrap(modulename))
return borrow_from(None, w_mod)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:18,代码来源:import_.py
示例12: PyErr_Occurred
def PyErr_Occurred(space):
state = space.fromcache(State)
if state.operror is None:
return None
return borrow_from(None, state.operror.w_type)
开发者ID:Qointum,项目名称:pypy,代码行数:5,代码来源:pyerrors.py
示例13: PyTuple_GetItem
def PyTuple_GetItem(space, w_t, pos):
if not PyTuple_Check(space, w_t):
PyErr_BadInternalCall(space)
w_obj = space.getitem(w_t, space.wrap(pos))
return borrow_from(w_t, w_obj)
开发者ID:Darriall,项目名称:pypy,代码行数:5,代码来源:tupleobject.py
示例14: PyWeakref_GET_OBJECT
def PyWeakref_GET_OBJECT(space, w_ref):
"""Similar to PyWeakref_GetObject(), but implemented as a macro that does no
error checking.
"""
return borrow_from(w_ref, space.call_function(w_ref))
开发者ID:gorakhargosh,项目名称:pypy,代码行数:5,代码来源:weakrefobject.py
示例15: PyFile_Name
def PyFile_Name(space, w_p):
"""Return the name of the file specified by p as a string object."""
return borrow_from(w_p, space.getattr(w_p, space.wrap("name")))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:3,代码来源:pyfile.py
示例16: PyDict_GetItem
def PyDict_GetItem(space, w_dict, w_key):
try:
w_res = space.getitem(w_dict, w_key)
except:
return None
return borrow_from(w_dict, w_res)
开发者ID:pypyjs,项目名称:pypy,代码行数:6,代码来源:dictobject.py
示例17: PyWeakref_GetObject
def PyWeakref_GetObject(space, w_ref):
"""Return the referenced object from a weak reference. If the referent is
no longer live, returns None. This function returns a borrowed reference.
"""
return borrow_from(w_ref, space.call_function(w_ref))
开发者ID:ieure,项目名称:pypy,代码行数:5,代码来源:weakrefobject.py
示例18: PyImport_GetModuleDict
def PyImport_GetModuleDict(space):
"""Return the dictionary used for the module administration (a.k.a.
sys.modules). Note that this is a per-interpreter variable."""
w_modulesDict = space.sys.get('modules')
return borrow_from(None, w_modulesDict)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:5,代码来源:import_.py
示例19: PyPy_Borrow
def PyPy_Borrow(space, w_parentobj, w_obj):
"""Returns a borrowed reference to 'obj', borrowing from the 'parentobj'.
"""
return borrow_from(w_parentobj, w_obj)
开发者ID:Darriall,项目名称:pypy,代码行数:4,代码来源:pypyintf.py
注:本文中的pypy.module.cpyext.pyobject.borrow_from函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论