当前位置: 首页>>代码示例>>C++>>正文


C++ PyDict_GetItem函数代码示例

本文整理汇总了C++中PyDict_GetItem函数的典型用法代码示例。如果您正苦于以下问题:C++ PyDict_GetItem函数的具体用法?C++ PyDict_GetItem怎么用?C++ PyDict_GetItem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PyDict_GetItem函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的PyDict_GetItem函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。