API question -- decref after adding to dictionary?
M.-A. Lemburg
mal at lemburg.com
Wed Jul 28 04:17:15 EDT 1999
Rich Salz wrote:
>
> I'm converting my own associative array into a python dictionary so I can
> callout to some python code. I think the snippet below should be clear
> enough.
>
> PyDictObject* newdict = PyDict_New();
> for (CKeyValList::iterator i(kvl); i; ++i) {
> PyString* v = Pystring_FromString(i.value());
> PyDict__SetItemString(p, i.key(), v);
> Py_DECREF(v);
> }
>
> Is the DECREF necessary? Reading the source of dictobject.c makes me think
> it is, but the comments in object.h say otherwise.
Yes it is needed. (Trust the code in dictobject.c, after all, that's
what gets executed !)
--
Marc-Andre Lemburg
______________________________________________________________________
Y2000: 156 days left
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/
Rich Salz wrote:
More information about the Python-list
mailing list