• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PyDict_SetItem函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了PyDict_SetItem函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:GINK03,项目名称:StaticPython,代码行数:20,代码来源:_warnings.c


示例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;
}
开发者ID:hltbra,项目名称:rubypython,代码行数:20,代码来源:rtop.c


示例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;
}
开发者ID:AmesianX,项目名称:src,代码行数:23,代码来源:py_name.hpp


示例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;
}
开发者ID:aidin36,项目名称:libtocc-python,代码行数:20,代码来源:manager.cpp


示例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;
}
开发者ID:abed-hawa,项目名称:amara,代码行数:20,代码来源:builder.c


示例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;
}
开发者ID:DDMAL,项目名称:Gamera,代码行数:21,代码来源:graphobject_algorithm.cpp


示例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;
}
开发者ID:B-Rich,项目名称:gcc-python-plugin,代码行数:41,代码来源:input.c


示例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);
}
开发者ID:H1d3r,项目名称:binary_blobs,代码行数:41,代码来源:set.c


示例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);
}}
开发者ID:MatiasNAmendola,项目名称:cleese,代码行数:41,代码来源:stringobject.c


示例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;
}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:41,代码来源:modsupport.c


示例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;
}
开发者ID:ajfabbri,项目名称:trace-cmd-merging,代码行数:41,代码来源:plugin_python.c


示例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
	}
}
开发者ID:Galland,项目名称:nodebox-opengl,代码行数:41,代码来源:stats.c


示例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;
}
开发者ID:KennethNielsen,项目名称:llvmpy,代码行数:41,代码来源:capsule.cpp


示例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;
}
开发者ID:GeraintPratten,项目名称:lalsuite,代码行数:44,代码来源:Fr.c


示例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);
}
开发者ID:anders,项目名称:weechat,代码行数:21,代码来源:weechat-python.c


示例16: _getcache

/*
    def _getcache(self, provided, name):
        cache = self._cache.get(provided)
        if cache is None:
            cache = {}
            self._cache[provided] = cache
        if name:
            c = cache.get(name)
            if c is None:
                c = {}
                cache[name] = c
            cache = c
        return cache
*/
static PyObject *
_subcache(PyObject *cache, PyObject *key)
{
  PyObject *subcache;

  subcache = PyDict_GetItem(cache, key);
  if (subcache == NULL)
    {
      int status;

      subcache = PyDict_New();
      if (subcache == NULL)
        return NULL;
      status = PyDict_SetItem(cache, key, subcache);
      Py_DECREF(subcache);
      if (status < 0)
        return NULL;
    }

  return subcache;
}
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:35,代码来源:_zope_interface_coptimizations.c


示例17: make_callback_dict

PyObject* make_callback_dict(obj_list plugin_list){
	PyObject* dict = PyDict_New();
	int index = 0;

 
	while(index++ < obj_list_len(plugin_list)){
		PyObject* cur = obj_list_get(plugin_list, index);
		//Might need to add self reference to args, dunno
		PyObject* tuple = PyTuple_New((Py_ssize_t)0);
		if(!tuple){
			printf("Couldn't make tuple ?\n");
			PyErr_Print();
		}
		PyObject* getName = PyObject_GetAttrString(cur, "getName");
		if(!getName){
			printf("Couldn't get the getName method...\n");
			PyErr_Print();
		}
		PyObject* plugin_name = PyObject_Call(getName, tuple, NULL);
		if(!plugin_name){
			printf("Couldn't call the getName method...\n");
			PyErr_Print();
		}
		Py_DECREF(tuple);
		Py_DECREF(getName);
		PyObject* cur_plugin_write = PyObject_GetAttrString(cur, "addMessage");
		if(!cur_plugin_write){
			printf("Couldn't get addMessage method...\n");
			PyErr_Print();
		}
		if(!PyMethod_Check(cur_plugin_write) && !PyFunction_Check(cur_plugin_write)){
			printf("Not function or method...\n");
		}
		printf("Does it have the __call__ attribute %d\n", PyObject_HasAttrString(cur_plugin_write, "__call__"));
		PyDict_SetItem(dict, plugin_name, cur_plugin_write);
		Py_DECREF(plugin_name);
		Py_DECREF(cur_plugin_write);
	}
	return dict;
}
开发者ID:crew,项目名称:c-dds,代码行数:40,代码来源:dds_plugins.c


示例18: cbson_loads_set_item

static BSON_INLINE void
cbson_loads_set_item (PyObject   *obj,
                      const char *key,
                      PyObject   *value)
{
   PyObject *keyobj;

   if (PyDict_Check(obj)) {
      if (*key == '_' && !strcmp(key, "_id")) {
         keyobj = gStr_id;
         Py_INCREF(keyobj);
      } else if (!(keyobj = PyUnicode_DecodeUTF8(key, strlen(key), "strict"))) {
         keyobj = PyString_FromString(key);
      }
      if (keyobj) {
         PyDict_SetItem(obj, keyobj, value);
         Py_DECREF(keyobj);
      }
   } else {
      PyList_Append(obj, value);
   }
}
开发者ID:HeliumProject,项目名称:libbson,代码行数:22,代码来源:cbson.c


示例19: psyco_thread_dict

DEFINEFN
PyObject* psyco_thread_dict()
{
  PyObject* dict = PyThreadState_GetDict();
  PyObject* result;
  bool err;

  if (dict == NULL)
    return NULL;
  result = PyDict_GetItem(dict, thread_dict_key);
  if (result == NULL)
    {
      result = PyDict_New();
      if (result == NULL)
        return NULL;
      err = PyDict_SetItem(dict, thread_dict_key, result);
      Py_DECREF(result);  /* one reference left in 'dict' */
      if (err)
        result = NULL;
    }
  return result;
}
开发者ID:Galland,项目名称:nodebox-opengl,代码行数:22,代码来源:psyco.c


示例20: my_setattro

PYCURL_INTERNAL int
my_setattro(PyObject **dict, PyObject *name, PyObject *v)
{
    if( *dict == NULL )
    {
        *dict = PyDict_New();
        if( *dict == NULL )
            return -1;
    }
    if (v != NULL)
        return PyDict_SetItem(*dict, name, v);
    else {
        int v = PyDict_DelItem(*dict, name);
        if (v != 0) {
            /* need to convert KeyError to AttributeError */
            if (PyErr_ExceptionMatches(PyExc_KeyError)) {
                PyErr_SetString(PyExc_AttributeError, "trying to delete a non-existing attribute");
            }
        }
        return v;
    }
}
开发者ID:0312birdzhang,项目名称:SailfishWeiboPyModule,代码行数:22,代码来源:pythoncompat.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PyDict_SetItemString函数代码示例发布时间:2022-05-30
下一篇:
C++ PyDict_Keys函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap