本文整理汇总了C++中PyDict_GetItem函数的典型用法代码示例。如果您正苦于以下问题:C++ PyDict_GetItem函数的具体用法?C++ PyDict_GetItem怎么用?C++ PyDict_GetItem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyDict_GetItem函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: py_win32_timer_callback
VOID CALLBACK
py_win32_timer_callback (HWND hwnd, UINT msg, UINT_PTR timer_id, DWORD time)
{
CEnterLeavePython _celp;
PyObject * py_timer_id = PyWinLong_FromVoidPtr((void *)timer_id);
if (!py_timer_id){
PyErr_Print();
return;
}
// is this timer id recognized?
PyObject * callback_function = PyDict_GetItem (timer_id_callback_map, py_timer_id);
if (!callback_function){
::KillTimer (NULL, timer_id);
PyErr_Warn(PyExc_RuntimeWarning, "Unrecognized timer id");
Py_DECREF(py_timer_id);
return;
}
// call the user's function
// create a 'death grip' on the callback function, just incase
// the callback itself removes the function from the map.
Py_INCREF(callback_function);
PyObject * callback_args = Py_BuildValue ("(Ok)", py_timer_id, time);
PyObject * result = PyEval_CallObject (callback_function, callback_args);
if (!result) {
// Is this necessary, or will python already have flagged
// an exception? Can we even catch exceptions here?
PyErr_Print();
}
// everything's ok, return
Py_DECREF(callback_function);
Py_XDECREF(callback_args);
Py_XDECREF(result);
Py_DECREF (py_timer_id);
return;
}
开发者ID:DavidGuben,项目名称:rcbplayspokemon,代码行数:37,代码来源:timermodule.cpp
示例2: already_warned
static int
already_warned(PyObject *registry, PyObject *key, int should_set)
{
PyObject *version_obj, *already_warned;
_Py_IDENTIFIER(version);
if (key == NULL)
return -1;
version_obj = _PyDict_GetItemId(registry, &PyId_version);
if (version_obj == NULL
|| !PyLong_CheckExact(version_obj)
|| PyLong_AsLong(version_obj) != _filters_version) {
PyDict_Clear(registry);
version_obj = PyLong_FromLong(_filters_version);
if (version_obj == NULL)
return -1;
if (_PyDict_SetItemId(registry, &PyId_version, version_obj) < 0) {
Py_DECREF(version_obj);
return -1;
}
Py_DECREF(version_obj);
}
else {
already_warned = PyDict_GetItem(registry, key);
if (already_warned != NULL) {
int rc = PyObject_IsTrue(already_warned);
if (rc != 0)
return rc;
}
}
/* This warning wasn't found in the registry, set it. */
if (should_set)
return PyDict_SetItem(registry, key, Py_True);
return 0;
}
开发者ID:Daetalus,项目名称:cpython,代码行数:37,代码来源:_warnings.c
示例3: PyDict_GetItem
static PyObject *t_tzinfo_getInstance(PyTypeObject *cls, PyObject *id)
{
PyObject *instance = PyDict_GetItem(_instances, id);
if (instance)
{
Py_INCREF(instance);
return instance;
}
int cmp = PyObject_RichCompareBool(id, FLOATING_TZNAME, Py_EQ);
if (cmp == -1)
return NULL;
if (cmp)
instance = t_tzinfo_getFloating(cls);
else
{
PyObject *tz = t_timezone_createTimeZone(&TimeZoneType_, id);
if (!tz)
return NULL;
#if PY_VERSION_HEX < 0x02040000
PyObject *args = Py_BuildValue("(O)", tz);
#else
PyObject *args = PyTuple_Pack(1, tz);
#endif
instance = PyObject_Call((PyObject *) &TZInfoType_, args, NULL);
Py_DECREF(args);
Py_DECREF(tz);
}
if (instance)
PyDict_SetItem(_instances, id, instance);
return instance;
}
开发者ID:felixonmars,项目名称:pyicu,代码行数:37,代码来源:tzinfo.cpp
示例4: CHECK_OBJECT
NUITKA_MAY_BE_UNUSED static PyObject *DICT_GET_ITEM( PyObject *dict, PyObject *key )
{
CHECK_OBJECT( dict );
assert( PyDict_CheckExact( dict ) );
CHECK_OBJECT( key );
PyObject *result = PyDict_GetItem( dict, key );
if ( result == NULL )
{
if (unlikely( PyErr_Occurred() ))
{
return NULL;
}
/* Wrap all kinds of tuples, because normalization will later unwrap
* it, but then that changes the key for the KeyError, which is not
* welcome. The check is inexact, as the unwrapping one is too.
*/
if ( PyTuple_Check( key ) )
{
PyObject *tuple = PyTuple_Pack( 1, key );
PyErr_SetObject( PyExc_KeyError, tuple );
Py_DECREF( tuple );
}
else
{
PyErr_SetObject( PyExc_KeyError, key );
}
return NULL;
}
else
{
return INCREASE_REFCOUNT( result );
}
}
开发者ID:601040605,项目名称:Nuitka,代码行数:37,代码来源:dictionaries.hpp
示例5: _class_remove_global_event_listener
/**
* Interface for AtkUtilClass->remove_global_event_listener.
*/
static void
_class_remove_global_event_listener (guint listener_id)
{
PyObject *dict = NULL;
PyObject *obj = NULL;
PyObject *key = NULL;
int pos = 0;
debug ("_class_remove_global_event_listener\n");
key = PyInt_FromLong ((long) listener_id);
while (PyDict_Next (_global_listeners, &pos, NULL, &dict))
{
obj = PyDict_GetItem (dict, key);
if (obj)
{
PyDict_DelItem (dict, key);
Py_DECREF (key);
return;
}
}
Py_DECREF (key);
return;
}
开发者ID:prim,项目名称:ocempgui,代码行数:27,代码来源:papi_atkutil.c
示例6: get_warnings_attr
/*
Returns a new reference.
A NULL return value can mean false or an error.
*/
static PyObject *
get_warnings_attr(const char *attr)
{
static PyObject *warnings_str = NULL;
PyObject *all_modules;
PyObject *warnings_module;
int result;
if (warnings_str == NULL) {
warnings_str = PyString_InternFromString("warnings");
if (warnings_str == NULL)
return NULL;
}
all_modules = PyImport_GetModuleDict();
result = PyDict_Contains(all_modules, warnings_str);
if (result == -1 || result == 0)
return NULL;
warnings_module = PyDict_GetItem(all_modules, warnings_str);
if (!PyObject_HasAttrString(warnings_module, attr))
return NULL;
return PyObject_GetAttrString(warnings_module, attr);
}
开发者ID:GINK03,项目名称:StaticPython,代码行数:28,代码来源:_warnings.c
示例7: CHECK_OBJECT
NUITKA_MAY_BE_UNUSED static PyObject *DICT_GET_ITEM( PyObject *dict, PyObject *key )
{
CHECK_OBJECT( dict );
assert( PyDict_Check( dict ) );
CHECK_OBJECT( key );
PyObject *result = PyDict_GetItem( dict, key );
if ( result == NULL )
{
if (unlikely( PyErr_Occurred() ))
{
return NULL;
}
PyErr_SetObject( PyExc_KeyError, key );
return NULL;
}
else
{
return INCREASE_REFCOUNT( result );
}
}
开发者ID:FireWalkerX,项目名称:Nuitka,代码行数:24,代码来源:dictionaries.hpp
示例8: handle_call
void handle_call(PyFrameObject *frame) {
PyObject *name, *value;
int i, argcount, count = 0;
increment_depth();
if (in_no_trace_context()) {
return;
}
if (FALSE == should_trace_frame(frame)) {
enter_no_trace_context();
return;
}
argcount = frame->f_code->co_argcount;
if (frame->f_code->co_flags & CO_VARARGS) {
argcount++;
}
if (frame->f_code->co_flags & CO_VARKEYWORDS) {
argcount++;
}
for (i = 0; i < min(argcount, MAX_ARGS); i++) {
name = PyTuple_GetItem(frame->f_code->co_varnames, i);
if (NULL == frame->f_locals) {
value = frame->f_localsplus[i];
} else {
value = PyDict_GetItem(frame->f_locals, name);
}
if (NULL != value) { // happens when exec is used
set_string(&(arguments[i]->name), PYSTR_TO_CHAR(name));
set_string(&(arguments[i]->type), value->ob_type->tp_name);
set_string(&(arguments[i]->value), pyobj_to_cstr(value));
count++;
}
}
handle_trace(frame, RECORD__RECORD_TYPE__CALL, count);
}
开发者ID:alonho,项目名称:pytrace,代码行数:36,代码来源:serial.c
示例9: Watchdog_CFRunLoopForEmitter_DelItem
/**
* Removes an entry from the runloop-for-emitter dictionary for the given
* emitter thread.
*
* :param emitter_thread:
* The emitter thread for which the dictionary entry will be removed.
* :type emitter_thread:
* A pointer to a Python object representing the emitter thread.
* :returns:
* The same as :func:`PyDict_DelItem`
*/
int
Watchdog_CFRunLoopForEmitter_DelItem(PyObject *emitter_thread)
{
CFRunLoopRef emitter_runloop = NULL;
int return_value = 0;
// refcount(emitter_thread) = 2
// refcount(emitter_runloop) = 2
// from previous successful addition to the dict.
emitter_runloop = PyDict_GetItem(g__runloop_for_emitter, emitter_thread);
RETURN_IF(NULL == emitter_runloop);
return_value = PyDict_DelItem(g__runloop_for_emitter, emitter_thread);
if (0 == return_value)
{
// Success!
// refcount(emitter_thread) = 1
// refcount(emitter_runloop) = 1
Py_DECREF(emitter_runloop);
// refcount(emitter_runloop) = 0
// refcount(emitter_thread) = 1
// back to python land.
}
return return_value;
}
开发者ID:aswadrangnekar,项目名称:watchdog,代码行数:35,代码来源:_watchdog_util.c
示例10: pyg_flags_from_gtype
PyObject*
pyg_flags_from_gtype (GType gtype, int value)
{
PyObject *pyclass, *values, *retval, *pyint;
g_return_val_if_fail(gtype != G_TYPE_INVALID, NULL);
/* Get a wrapper class by:
* 1. check for one attached to the gtype
* 2. lookup one in a typelib
* 3. creating a new one
*/
pyclass = (PyObject*)g_type_get_qdata(gtype, pygflags_class_key);
if (!pyclass)
pyclass = pygi_type_import_by_g_type(gtype);
if (!pyclass)
pyclass = pyg_flags_add(NULL, g_type_name(gtype), NULL, gtype);
if (!pyclass)
return PYGLIB_PyLong_FromLong(value);
values = PyDict_GetItemString(((PyTypeObject *)pyclass)->tp_dict,
"__flags_values__");
pyint = PYGLIB_PyLong_FromLong(value);
retval = PyDict_GetItem(values, pyint);
if (!retval) {
PyErr_Clear();
retval = pyg_flags_val_new(pyclass, gtype, pyint);
g_assert(retval != NULL);
} else {
Py_INCREF(retval);
}
Py_DECREF(pyint);
return retval;
}
开发者ID:Liuke86,项目名称:pygobject,代码行数:36,代码来源:pygflags.c
示例11: unpack_add_info
static int
unpack_add_info(LogReaderObject *self)
{
PyObject *key;
PyObject *value = NULL;
int err;
err = unpack_string(self, &key);
if (!err) {
err = unpack_string(self, &value);
if (err)
Py_DECREF(key);
else {
PyObject *list = PyDict_GetItem(self->info, key);
if (list == NULL) {
list = PyList_New(0);
if (list == NULL) {
err = ERR_EXCEPTION;
goto finally;
}
if (PyDict_SetItem(self->info, key, list)) {
Py_DECREF(list);
err = ERR_EXCEPTION;
goto finally;
}
Py_DECREF(list);
}
if (PyList_Append(list, value))
err = ERR_EXCEPTION;
}
}
finally:
Py_XDECREF(key);
Py_XDECREF(value);
return err;
}
开发者ID:xen0n,项目名称:cpython64-64,代码行数:36,代码来源:_hotshot.c
示例12: GetConnectionInfo
PyObject* GetConnectionInfo(PyObject* pConnectionString, Connection* cnxn)
{
// Looks-up or creates a CnxnInfo object for the given connection string. The connection string can be a Unicode
// or String object.
Object hash(GetHash(pConnectionString));
if (hash.IsValid())
{
PyObject* info = PyDict_GetItem(map_hash_to_info, hash);
if (info)
{
Py_INCREF(info);
return info;
}
}
PyObject* info = CnxnInfo_New(cnxn);
if (info != 0 && hash.IsValid())
PyDict_SetItem(map_hash_to_info, hash, info);
return info;
}
开发者ID:mkleehammer,项目名称:pyodbc,代码行数:24,代码来源:cnxninfo.cpp
示例13: get_error_object
/*
This function creates and returns a thread-local Python object that has
space to store two integer error numbers; once created the Python object is
kept alive in the thread state dictionary as long as the thread itself.
*/
PyObject *
get_error_object(int **pspace)
{
PyObject *dict = PyThreadState_GetDict();
PyObject *errobj;
static PyObject *error_object_name;
if (dict == 0) {
PyErr_SetString(PyExc_RuntimeError,
"cannot get thread state");
return NULL;
}
if (error_object_name == NULL) {
error_object_name = PyString_InternFromString("ctypes.error_object");
if (error_object_name == NULL)
return NULL;
}
errobj = PyDict_GetItem(dict, error_object_name);
if (errobj)
Py_INCREF(errobj);
else {
void *space = PyMem_Malloc(sizeof(int) * 2);
if (space == NULL)
return NULL;
memset(space, 0, sizeof(int) * 2);
errobj = PyCObject_FromVoidPtr(space, PyMem_Free);
if (errobj == NULL)
return NULL;
if (-1 == PyDict_SetItem(dict, error_object_name,
errobj)) {
Py_DECREF(errobj);
return NULL;
}
}
*pspace = (int *)PyCObject_AsVoidPtr(errobj);
return errobj;
}
开发者ID:pieper,项目名称:python,代码行数:41,代码来源:callproc.c
示例14: _buffer_clear_info
/* Clear buffer info from the global dictionary */
static void
_buffer_clear_info(PyObject *arr)
{
PyObject *key, *item_list, *item;
_buffer_info_t *info;
int k;
if (_buffer_info_cache == NULL) {
return;
}
key = PyLong_FromVoidPtr((void*)arr);
item_list = PyDict_GetItem(_buffer_info_cache, key);
if (item_list != NULL) {
for (k = 0; k < PyList_GET_SIZE(item_list); ++k) {
item = PyList_GET_ITEM(item_list, k);
info = (_buffer_info_t*)PyLong_AsVoidPtr(item);
_buffer_info_free(info);
}
PyDict_DelItem(_buffer_info_cache, key);
}
Py_DECREF(key);
}
开发者ID:Linxiao-Chen,项目名称:numpy,代码行数:25,代码来源:buffer.c
示例15: PyDict_New
static PyObject *t_jccenv__dumpRefs(PyObject *self,
PyObject *args, PyObject *kwds)
{
static char *kwnames[] = {
"classes", "values", NULL
};
int classes = 0, values = 0;
PyObject *result;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwnames,
&classes, &values))
return NULL;
if (classes)
result = PyDict_New();
else
result = PyList_New(env->refs.size());
int count = 0;
for (std::multimap<int, countedRef>::iterator iter = env->refs.begin();
iter != env->refs.end();
iter++) {
if (classes) // return dict of { class name: instance count }
{
char *name = env->getClassName(iter->second.global);
PyObject *key = PyString_FromString(name);
PyObject *value = PyDict_GetItem(result, key);
if (value == NULL)
value = PyInt_FromLong(1);
else
value = PyInt_FromLong(PyInt_AS_LONG(value) + 1);
PyDict_SetItem(result, key, value);
Py_DECREF(key);
Py_DECREF(value);
delete name;
}
else if (values) // return list of (value string, ref count)
{
char *str = env->toString(iter->second.global);
PyObject *key = PyString_FromString(str);
PyObject *value = PyInt_FromLong(iter->second.count);
#if PY_VERSION_HEX < 0x02040000
PyList_SET_ITEM(result, count++, Py_BuildValue("(OO)", key, value));
#else
PyList_SET_ITEM(result, count++, PyTuple_Pack(2, key, value));
#endif
Py_DECREF(key);
Py_DECREF(value);
delete str;
}
else // return list of (id hash code, ref count)
{
PyObject *key = PyInt_FromLong(iter->first);
PyObject *value = PyInt_FromLong(iter->second.count);
#if PY_VERSION_HEX < 0x02040000
PyList_SET_ITEM(result, count++, Py_BuildValue("(OO)", key, value));
#else
PyList_SET_ITEM(result, count++, PyTuple_Pack(2, key, value));
#endif
Py_DECREF(key);
Py_DECREF(value);
}
}
return result;
}
开发者ID:ahua,项目名称:java,代码行数:73,代码来源:jcc.cpp
示例16: pyrna_set_to_enum_bitmap
static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
{
#if 0 /* If someone knows how to get a proper 'self' in that case... */
BPy_StructRNA *pyrna = (BPy_StructRNA *)self;
Main *bmain = pyrna->ptr.data;
#else
Main *bmain = G.main; /* XXX Ugly, but should work! */
#endif
static const char *kwlist[] = {"subset", "key_types", "value_types", NULL};
PyObject *subset = NULL;
PyObject *key_types = NULL;
PyObject *val_types = NULL;
BLI_bitmap *key_types_bitmap = NULL;
BLI_bitmap *val_types_bitmap = NULL;
PyObject *ret = NULL;
if (!PyArg_ParseTupleAndKeywords(
args, kwds, "|O$O!O!:user_map", (char **)kwlist,
&subset,
&PySet_Type, &key_types,
&PySet_Type, &val_types))
{
return NULL;
}
if (key_types) {
key_types_bitmap = pyrna_set_to_enum_bitmap(
rna_enum_id_type_items, key_types, sizeof(short), true, USHRT_MAX, "key types");
if (key_types_bitmap == NULL) {
goto error;
}
}
if (val_types) {
val_types_bitmap = pyrna_set_to_enum_bitmap(
rna_enum_id_type_items, val_types, sizeof(short), true, USHRT_MAX, "value types");
if (val_types_bitmap == NULL) {
goto error;
}
}
IDUserMapData data_cb = {NULL};
if (subset) {
PyObject *subset_fast = PySequence_Fast(subset, "user_map");
if (subset_fast == NULL) {
goto error;
}
PyObject **subset_array = PySequence_Fast_ITEMS(subset_fast);
Py_ssize_t subset_len = PySequence_Fast_GET_SIZE(subset_fast);
data_cb.user_map = _PyDict_NewPresized(subset_len);
data_cb.is_subset = true;
for (; subset_len; subset_array++, subset_len--) {
PyObject *set = PySet_New(NULL);
PyDict_SetItem(data_cb.user_map, *subset_array, set);
Py_DECREF(set);
}
Py_DECREF(subset_fast);
}
else {
data_cb.user_map = PyDict_New();
}
data_cb.types_bitmap = key_types_bitmap;
ListBase *lb_array[MAX_LIBARRAY];
int lb_index;
lb_index = set_listbasepointers(bmain, lb_array);
while (lb_index--) {
if (val_types_bitmap && lb_array[lb_index]->first) {
if (!id_check_type(lb_array[lb_index]->first, val_types_bitmap)) {
continue;
}
}
for (ID *id = lb_array[lb_index]->first; id; id = id->next) {
/* One-time init, ID is just used as placeholder here, we abuse this in iterator callback
* to avoid having to rebuild a complete bpyrna object each time for the key searching
* (where only ID pointer value is used). */
if (data_cb.py_id_key_lookup_only == NULL) {
data_cb.py_id_key_lookup_only = pyrna_id_CreatePyObject(id);
}
if (!data_cb.is_subset) {
PyObject *key = data_cb.py_id_key_lookup_only;
PyObject *set;
RNA_id_pointer_create(id, &((BPy_StructRNA *)key)->ptr);
/* We have to insert the key now, otherwise ID unused would be missing from final dict... */
if ((set = PyDict_GetItem(data_cb.user_map, key)) == NULL) {
/* Cannot use our placeholder key here! */
//.........这里部分代码省略.........
开发者ID:diekev,项目名称:blender,代码行数:101,代码来源:bpy_rna_id_collection.c
示例17: PyErr_BadArgument
PyObject *_PyCodec_Lookup(const char *encoding)
{
PyInterpreterState *interp;
PyObject *result, *args = NULL, *v;
Py_ssize_t i, len;
if (encoding == NULL) {
PyErr_BadArgument();
goto onError;
}
interp = PyThreadState_GET()->interp;
if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())
goto onError;
/* Convert the encoding to a normalized Python string: all
characters are converted to lower case, spaces and hyphens are
replaced with underscores. */
v = normalizestring(encoding);
if (v == NULL)
goto onError;
PyString_InternInPlace(&v);
/* First, try to lookup the name in the registry dictionary */
result = PyDict_GetItem(interp->codec_search_cache, v);
if (result != NULL) {
Py_INCREF(result);
Py_DECREF(v);
return result;
}
/* Next, scan the search functions in order of registration */
args = PyTuple_New(1);
if (args == NULL)
goto onError;
PyTuple_SET_ITEM(args,0,v);
len = PyList_Size(interp->codec_search_path);
if (len < 0)
goto onError;
if (len == 0) {
PyErr_SetString(PyExc_LookupError,
"no codec search functions registered: "
"can't find encoding");
goto onError;
}
for (i = 0; i < len; i++) {
PyObject *func;
func = PyList_GetItem(interp->codec_search_path, i);
if (func == NULL)
goto onError;
result = PyEval_CallObject(func, args);
if (result == NULL)
goto onError;
if (result == Py_None) {
Py_DECREF(result);
continue;
}
if (!PyTuple_Check(result) || PyTuple_GET_SIZE(result) != 4) {
PyErr_SetString(PyExc_TypeError,
"codec search functions must return 4-tuples");
Py_DECREF(result);
goto onError;
}
break;
}
if (i == len) {
/* XXX Perhaps we should cache misses too ? */
PyErr_Format(PyExc_LookupError,
"unknown encoding: %s", encoding);
goto onError;
}
/* Cache and return the result */
PyDict_SetItem(interp->codec_search_cache, v, result);
Py_DECREF(args);
return result;
onError:
Py_XDECREF(args);
return NULL;
}
开发者ID:0xcc,项目名称:python-read,代码行数:84,代码来源:codecs.c
示例18: __Pyx_PyExec3
static PyObject* __Pyx_PyExec3(PyObject* o, PyObject* globals, PyObject* locals) {
PyObject* result;
PyObject* s = 0;
char *code = 0;
if (!globals || globals == Py_None) {
globals = PyModule_GetDict($module_cname);
if (!globals)
goto bad;
} else if (!PyDict_Check(globals)) {
PyErr_Format(PyExc_TypeError, "exec() arg 2 must be a dict, not %.200s",
Py_TYPE(globals)->tp_name);
goto bad;
}
if (!locals || locals == Py_None) {
locals = globals;
}
if (PyDict_GetItem(globals, PYIDENT("__builtins__")) == NULL) {
if (PyDict_SetItem(globals, PYIDENT("__builtins__"), PyEval_GetBuiltins()) < 0)
goto bad;
}
if (PyCode_Check(o)) {
if (PyCode_GetNumFree((PyCodeObject *)o) > 0) {
PyErr_SetString(PyExc_TypeError,
"code object passed to exec() may not contain free variables");
goto bad;
}
#if PY_VERSION_HEX < 0x030200B1
result = PyEval_EvalCode((PyCodeObject *)o, globals, locals);
#else
result = PyEval_EvalCode(o, globals, locals);
#endif
} else {
PyCompilerFlags cf;
cf.cf_flags = 0;
if (PyUnicode_Check(o)) {
cf.cf_flags = PyCF_SOURCE_IS_UTF8;
s = PyUnicode_AsUTF8String(o);
if (!s) goto bad;
o = s;
#if PY_MAJOR_VERSION >= 3
} else if (!PyBytes_Check(o)) {
#else
} else if (!PyString_Check(o)) {
#endif
PyErr_Format(PyExc_TypeError,
"exec: arg 1 must be string, bytes or code object, got %.200s",
Py_TYPE(o)->tp_name);
goto bad;
}
#if PY_MAJOR_VERSION >= 3
code = PyBytes_AS_STRING(o);
#else
code = PyString_AS_STRING(o);
#endif
if (PyEval_MergeCompilerFlags(&cf)) {
result = PyRun_StringFlags(code, Py_file_input, globals, locals, &cf);
} else {
result = PyRun_String(code, Py_file_input, globals, locals);
}
Py_XDECREF(s);
}
return result;
bad:
Py_XDECREF(s);
return 0;
}
开发者ID:B-Rich,项目名称:cython,代码行数:70,代码来源:Builtins.c
示例19: xcsoar_Airspaces_findIntrusions
PyObject* xcsoar_Airspaces_findIntrusions(Pyxcsoar_Airspaces *self, PyObject *args) {
PyObject *py_flight = nullptr;
if (!PyArg_ParseTuple(args, "O", &py_flight)) {
PyErr_SetString(PyExc_AttributeError, "Can't parse argument.");
return nullptr;
}
DebugReplay *replay = ((Pyxcsoar_Flight*)py_flight)->flight->Replay();
if (replay == nullptr) {
PyErr_SetString(PyExc_IOError, "Can't start replay - file not found.");
return nullptr;
}
PyObject *py_result = PyDict_New();
Airspaces::AirspaceVector last_airspaces;
while (replay->Next()) {
const MoreData &basic = replay->Basic();
if (!basic.time_available || !basic.location_available ||
!basic.NavAltitudeAvailable())
continue;
Airspaces::AirspaceVector airspaces = self->airspace_database->FindInside(
ToAircraftState(basic, replay->Calculated())
);
for (auto it = airspaces.begin(); it != airspaces.end(); it++) {
PyObject *py_name = PyString_FromString((*it).GetAirspace().GetName());
PyObject *py_airspace = nullptr,
*py_period = nullptr;
if (PyDict_Contains(py_result, py_name) == 0) {
// this is the first fix inside this airspace
py_airspace = PyList_New(0);
PyDict_SetItem(py_result, py_name, py_airspace);
py_period = PyList_New(0);
PyList_Append(py_airspace, py_period);
Py_DECREF(py_period);
} else {
// this airspace was hit some time before...
py_airspace = PyDict_GetItem(py_result, py_name);
// check if the last fix was already inside this airspace
auto in_last = std::find(last_airspaces.begin(), last_airspaces.end(), *it);
if (in_last == last_airspaces.end()) {
// create a new period
py_period = PyList_New(0);
PyList_Append(py_airspace, py_period);
Py_DECREF(py_period);
} else {
py_period = PyList_GET_ITEM(py_airspace, PyList_GET_SIZE(py_airspace) - 1);
}
}
PyList_Append(py_period, Py_BuildValue("{s:N,s:N}",
"time", Python::BrokenDateTimeToPy(basic.date_time_utc),
"location", Python::WriteLonLat(basic.location)));
}
last_airspaces.swap(airspaces);
}
delete replay;
return py_result;
}
开发者ID:CnZoom,项目名称:XcSoarWork,代码行数:72,代码来源:Airspaces.cpp
示例20: Base_getattro
PyObject *
Base_getattro(PyObject *obj, PyObject *name)
{
/* This is a modified copy of PyObject_GenericGetAttr.
See the change note below. */
PyTypeObject *tp = obj->ob_type;
PyObject *descr = NULL;
PyObject *res = NULL;
descrgetfunc f;
long dictoffset;
PyObject **dictptr;
if (!PyString_Check(name)){
#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
existing tp_setattro slots expect a string object as name
and we wouldn't want to break those. */
if (PyUnicode_Check(name)) {
name = PyUnicode_AsEncodedString(name, NULL, NULL);
if (name == NULL)
return NULL;
}
else
#endif
{
PyErr_SetString(PyExc_TypeError,
"attribute name must be string");
return NULL;
}
}
else
Py_INCREF(name);
if (tp->tp_dict == NULL) {
if (PyType_Ready(tp) < 0)
goto done;
}
#if !defined(Py_TPFLAGS_HAVE_VERSION_TAG)
/* Inline _PyType_Lookup */
/* this is not quite _PyType_Lookup anymore */
{
int i, n;
PyObject *mro, *base, *dict;
/* Look in tp_dict of types in MRO */
mro = tp->tp_mro;
assert(mro != NULL);
assert(PyTuple_Check(mro));
n = PyTuple_GET_SIZE(mro);
for (i = 0; i < n; i++) {
base = PyTuple_GET_ITEM(mro, i);
if (PyClass_Check(base))
dict = ((PyClassObject *)base)->cl_dict;
else {
assert(PyType_Check(base));
dict = ((PyTypeObject *)base)->tp_dict;
}
assert(dict && PyDict_Check(dict));
descr = PyDict_GetItem(dict, name);
if (descr != NULL)
break;
}
}
#else
descr = _PyType_Lookup(tp, name);
#endif
Py_XINCREF(descr);
f = NULL;
if (descr != NULL &&
PyType_HasFeature(descr->ob_type, Py_TPFLAGS_HAVE_CLASS)) {
f = descr->ob_type->tp_descr_get;
if (f != NULL && PyDescr_IsData(descr)) {
res = f(descr, obj, (PyObject *)obj->ob_type);
Py_DECREF(descr);
goto done;
}
}
/* Inline _PyObject_GetDictPtr */
dictoffset = tp->tp_dictoffset;
if (dictoffset != 0) {
PyObject *dict;
if (dictoffset < 0) {
int tsize;
size_t size;
tsize = ((PyVarObject *)obj)->ob_size;
if (tsize < 0)
tsize = -tsize;
size = _PyObject_VAR_SIZE(tp, tsize);
dictoffset += (long)size;
assert(dictoffset > 0);
assert(dictoffset % SIZEOF_VOID_P == 0);
}
dictptr = (PyObject **) ((char *)obj + dictoffset);
//.........这里部分代码省略.........
开发者ID:c0ns0le,项目名称:zenoss-4,代码行数:101,代码来源:_ExtensionClass.c
注:本文中的PyDict_GetItem函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论