本文整理汇总了C++中PyDict_SetItem函数的典型用法代码示例。如果您正苦于以下问题:C++ PyDict_SetItem函数的具体用法?C++ PyDict_SetItem怎么用?C++ PyDict_SetItem使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyDict_SetItem函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: already_warned
static int
already_warned(PyObject *registry, PyObject *key, int should_set)
{
PyObject *already_warned;
if (key == NULL)
return -1;
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;
}
示例2: rtopHash
PyObject* rtopHash(VALUE rHash)
{
PyObject *pDict,*pKey,*pVal;
VALUE rKeys;
VALUE rKey, rVal;
int i;
pDict = PyDict_New();
rKeys = rb_funcall(rHash, rb_intern("keys"), 0);
for(i = 0; i < RARRAY_LEN(rKeys); i++)
{
rKey = rb_ary_entry(rKeys, i);
rVal = rb_hash_aref(rHash, rKey);
PyDict_SetItem(pDict, rtopObject(rKey, 1), rtopObject(rVal, 0));
}
return pDict;
}
示例3: PYW_GIL_CHECK_LOCKED_SCOPE
//------------------------------------------------------------------------
//<inline(py_name)>
//------------------------------------------------------------------------
PyObject *get_debug_names(ea_t ea1, ea_t ea2)
{
// Get debug names
ea_name_vec_t names;
PYW_GIL_CHECK_LOCKED_SCOPE();
Py_BEGIN_ALLOW_THREADS;
get_debug_names(&names, ea1, ea2);
Py_END_ALLOW_THREADS;
PyObject *dict = Py_BuildValue("{}");
if ( dict != NULL )
{
for ( ea_name_vec_t::iterator it=names.begin(); it != names.end(); ++it )
{
PyDict_SetItem(dict,
Py_BuildValue(PY_BV_EA, bvea_t(it->ea)),
PyString_FromString(it->name.c_str()));
}
}
return dict;
}
示例4: tags_statistics_to_dict
static PyObject* tags_statistics_to_dict(libtocc::TagStatisticsCollection* statistics)
{
PyObject* result = PyDict_New();
if (statistics->size() <= 0)
{
// Returning an empty dict.
return result;
}
libtocc::TagStatisticsCollection::Iterator iterator(statistics);
for (; !iterator.is_finished(); iterator.next())
{
libtocc::TagStatistics item = iterator.get();
PyDict_SetItem(result, PyUnicode_FromString(item.get_tag()), PyLong_FromLong(item.get_assigned_files()));
}
return result;
}
示例5: builder_NamespaceDecl
static ExpatStatus
builder_NamespaceDecl(void *arg, PyObject *prefix, PyObject *uri)
{
ParserState *state = (ParserState *)arg;
#ifdef DEBUG_PARSER
fprintf(stderr, "--- builder_NamespaceDecl(prefix=");
PyObject_Print(prefix, stderr, 0);
fprintf(stderr, ", uri=");
PyObject_Print(uri, stderr, 0);
fprintf(stderr, ")\n");
#endif
if (uri == Py_None)
uri = empty_string;
if (PyDict_SetItem(state->new_namespaces, prefix, uri) < 0)
return EXPAT_STATUS_ERROR;
return EXPAT_STATUS_OK;
}
示例6: graph_all_pairs_shortest_path
// -----------------------------------------------------------------------------
PyObject* graph_all_pairs_shortest_path(PyObject* self, PyObject* _) {
INIT_SELF_GRAPH();
std::map<Node*, ShortestPathMap*> all_pairs =
so->_graph->all_pairs_shortest_path();
PyObject *res = PyDict_New();
for(std::map<Node*, ShortestPathMap*>::iterator it = all_pairs.begin();
it != all_pairs.end(); it++) {
Node* source_node = it->first;
ShortestPathMap* path = it->second;
PyObject* pypath = pathmap_to_dict(path);
PyObject* pysource = dynamic_cast<GraphDataPyObject*>(source_node->_value)->data;
PyDict_SetItem(res, pysource, pypath);
Py_DECREF(pypath);
delete path;
}
return res;
}
示例7: test
PyObject *
test(PyObject *self, PyObject *args)
{
PyObject *dict = NULL;
PyObject *key = NULL;
PyObject *value = NULL;
dict = PyDict_New();
if (!dict) {
goto error;
}
key = PyLong_FromLong(500);
if (!key) {
goto error;
}
value = PyLong_FromLong(1000);
if (!value) {
goto error;
}
if (-1 == PyDict_SetItem(dict, key, value)) {
goto error;
}
/*
The successful call added refs on both "key" and "value", owned by the
dictionary.
We must now drop our references on them:
*/
Py_DECREF(key);
Py_DECREF(value);
return dict;
error:
Py_XDECREF(dict);
Py_XDECREF(key);
Py_XDECREF(value);
return NULL;
}
示例8: PyList_New
static PyObject *set_intersection(PyObject *module, PyObject *args)
{
PyObject *a, *b, *set, *item;
if (!PyArg_ParseTuple(args, "OO:Intersection", &a, &b))
return NULL;
if (PyObject_IsTrue(a) == 0 || PyObject_IsTrue(b) == 0)
/* either a or b are empty so the intersection is empty as well */
return PyList_New(0);
set = PyDict_New();
if (set == NULL)
return NULL;
a = make_dict(a);
if (a == NULL) {
Py_DECREF(set);
return NULL;
}
b = PyObject_GetIter(b);
if (b == NULL) {
Py_DECREF(a);
Py_DECREF(set);
return NULL;
}
while ((item = PyIter_Next(b)) != NULL) {
if (PyDict_GetItem(a, item) != NULL) {
if (PyDict_SetItem(set, item, Py_True) == -1) {
Py_DECREF(item);
Py_DECREF(b);
Py_DECREF(a);
Py_DECREF(set);
return NULL;
}
}
Py_DECREF(item);
}
Py_DECREF(b);
Py_DECREF(a);
return make_ordered_set(set);
}
示例9: PyString_InternInPlace
void
PyString_InternInPlace(PyObject **p)
{
LOG("> PyString_InternInPlace\n"); {
register PyStringObject *s = (PyStringObject *)(*p);
PyObject *t;
if (s == NULL || !PyString_Check(s))
Py_FatalError("PyString_InternInPlace: strings only please!");
if (interned == NULL) {
interned = PyDict_New();
if (interned == NULL) {
return;
}
}
if ((t = PyDict_GetItem(interned, (PyObject *)s)) !=NULL) {
Py_INCREF(t);
Py_DECREF(*p);
*p = t;
return;
}
/* Ensure that only true string objects appear in the intern dict */
if (!PyString_CheckExact(s)) {
t = PyString_FromStringAndSize(PyString_AS_STRING(s),
PyString_GET_SIZE(s));
if (t == NULL) {
/* ERROR */
return;
}
} else {
t = (PyObject*) s;
Py_INCREF(t);
}
if (PyDict_SetItem(interned, t, t) == 0) {
((PyObject *)t)->ob_refcnt-=2;
PyString_CHECK_INTERNED(t) = SSTATE_INTERNED_MORTAL;
Py_DECREF(*p);
*p = t;
return;
}
Py_DECREF(t);
}}
示例10: do_mkdict
static PyObject *
do_mkdict(char **p_format, va_list *p_va, int endchar, int n)
{
PyObject *d;
int i;
if (n < 0)
return NULL;
if ((d = PyDict_New()) == NULL)
return NULL;
for (i = 0; i < n; i+= 2) {
PyObject *k, *v;
int err;
k = do_mkvalue(p_format, p_va);
if (k == NULL) {
Py_DECREF(d);
return NULL;
}
v = do_mkvalue(p_format, p_va);
if (v == NULL) {
Py_DECREF(k);
Py_DECREF(d);
return NULL;
}
err = PyDict_SetItem(d, k, v);
Py_DECREF(k);
Py_DECREF(v);
if (err < 0) {
Py_DECREF(d);
return NULL;
}
}
if (d != NULL && **p_format != endchar) {
Py_DECREF(d);
d = NULL;
PyErr_SetString(PyExc_SystemError,
"Unmatched paren in format");
}
else if (endchar)
++*p_format;
return d;
}
示例11: PEVENT_PLUGIN_LOADER
int PEVENT_PLUGIN_LOADER(struct pevent *pevent)
{
PyObject *globals, *m, *py_pevent, *str, *res;
char **plugin_list;
/* Only load plugins if they exist */
plugin_list = trace_util_find_plugin_files(".py");
if (!plugin_list)
return 0;
trace_util_free_plugin_files(plugin_list);
Py_Initialize();
m = PyImport_AddModule("__main__");
globals = PyModule_GetDict(m);
res = PyRun_String(pypath, Py_file_input, globals, globals);
if (!res) {
PyErr_Print();
return -1;
} else
Py_DECREF(res);
str = PyString_FromString("pevent");
if (!str)
return -ENOMEM;
py_pevent = PyLong_FromUnsignedLong((unsigned long)pevent);
if (!py_pevent)
return -ENOMEM;
if (PyDict_SetItem(globals, str, py_pevent))
fprintf(stderr, "failed to insert pevent\n");
Py_DECREF(py_pevent);
Py_DECREF(str);
trace_util_load_plugins(pevent, ".py", load_plugin, globals);
return 0;
}
示例12: psyco_stats_reset
DEFINEFN
void psyco_stats_reset(void)
{
/* reset all stats */
int i = 0;
PyObject *key, *value, *d;
stats_printf(("stats: reset\n"));
/* reset the charge of all PyCodeStats, keep only the used ones */
RECLIMIT_SAFE_ENTER();
d = PyDict_New();
if (d == NULL)
OUT_OF_MEMORY();
while (PyDict_Next(codestats_dict, &i, &key, &value)) {
PyCodeStats* cs = (PyCodeStats*) key;
if (cs->st_mergepoints) {
/* clear the charge and keep alive */
cs->st_charge = 0.0f;
if (PyDict_SetItem(d, key, value))
OUT_OF_MEMORY();
}
}
RECLIMIT_SAFE_LEAVE();
Py_DECREF(codestats_dict);
codestats_dict = d;
charge_total = 0.0;
charge_prelimit = 0.0f;
/* reset the time measure in all threads */
{
#if MEASURE_ALL_THREADS
PyInterpreterState* istate = PyThreadState_Get()->interp;
PyThreadState* tstate;
for (tstate=istate->tstate_head; tstate; tstate=tstate->next) {
(void) get_measure(tstate);
}
#else
(void) get_measure(NULL);
#endif
}
}
示例13: WrapCore
static
PyObject* WrapCore(PyObject *oldCap, bool owned) {
auto_pyobject cap = PyObject_CallFunctionObjArgs(GetCapsuleClass(), oldCap,
NULL);
auto_pyobject cls = PyObject_CallMethod(*cap, "get_class", "");
auto_pyobject addr = GetPointer(oldCap);
// look up cached object
auto_pyobject cache_cls = PyObject_GetItem(GetCache(), *cls);
Assert(*cache_cls);
PyObject* obj = NULL;
obj = PyObject_GetItem(*cache_cls, *addr);
if (obj) {
/* cache hit */
}
else {
if (!PyErr_ExceptionMatches(PyExc_KeyError))
return NULL;
/* cache miss */
PyErr_Clear();
if (!owned) {
auto_pyobject hasDtor = PyObject_CallMethod(*cls, "_has_dtor", "");
if (PyObject_IsTrue(*hasDtor)) {
auto_pyobject name = GetName(oldCap);
auto_pyobject key = PyTuple_Pack(2, *name, *addr);
auto_pyobject val = PyObject_GetAttrString(*cls, "_delete_");
int ok = PyDict_SetItem(GetAddrDtorDict(), *key, *val);
Assert(ok != -1);
}
}
obj = PyObject_CallMethod(*cap, "instantiate", "");
int ok = PyObject_SetItem(*cache_cls, *addr, obj);
Assert(ok != -1);
}
Assert(obj);
return obj;
}
示例14: PyDict_New
/*
* Utility function to extract an FrEvent's parameters into a Python dictionary
*/
static PyObject *extract_event_dict(FrEvent *event) {
PyObject *event_dict = NULL;
size_t j;
/* each FrEvent will be stored in a dict */
event_dict = PyDict_New();
if (!event_dict) return NULL;
/* guarantee these parameters exist */
PyDict_SetItemString(event_dict, "name",
PyString_FromString(event->name));
PyDict_SetItemString(event_dict, "comment",
PyString_FromString(event->comment));
PyDict_SetItemString(event_dict, "inputs",
PyString_FromString(event->inputs));
PyDict_SetItemString(event_dict, "GTimeS",
PyLong_FromUnsignedLong(event->GTimeS));
PyDict_SetItemString(event_dict, "GTimeN",
PyLong_FromUnsignedLong(event->GTimeN));
PyDict_SetItemString(event_dict, "timeBefore",
PyFloat_FromDouble(event->timeBefore));
PyDict_SetItemString(event_dict, "timeAfter",
PyFloat_FromDouble(event->timeAfter));
PyDict_SetItemString(event_dict, "eventStatus",
PyLong_FromUnsignedLong(event->eventStatus));
PyDict_SetItemString(event_dict, "amplitude",
PyFloat_FromDouble(event->amplitude));
PyDict_SetItemString(event_dict, "probability",
PyFloat_FromDouble(event->probability));
PyDict_SetItemString(event_dict, "statistics",
PyString_FromString(event->statistics));
/* additional parameters */
for (j = 0; j < event->nParam; j++) {
PyDict_SetItem(event_dict,
PyString_FromString(event->parameterNames[j]),
PyFloat_FromDouble(event->parameters[j]));
}
return event_dict;
}
示例15: weechat_python_hashtable_map_cb
void
weechat_python_hashtable_map_cb (void *data,
struct t_hashtable *hashtable,
const char *key,
const char *value)
{
PyObject *dict, *dict_key, *dict_value;
/* make C compiler happy */
(void) hashtable;
dict = (PyObject *)data;
dict_key = Py_BuildValue ("s", key);
dict_value = Py_BuildValue ("s", value);
PyDict_SetItem (dict, dict_key, dict_value);
Py_DECREF (dict_key);
Py_DECREF (dict_value);
}