[Python-checkins] CVS: python/dist/src/Doc/api api.tex,1.116,1.117

Fred L. Drake fdrake@users.sourceforge.net
Fri, 13 Apr 2001 10:55:04 -0700


Update of /cvsroot/python/python/dist/src/Doc/api
In directory usw-pr-cvs1:/tmp/cvs-serv21253/api

Modified Files:
	api.tex 
Log Message:

Michael Hudson:
Update docs for PyDict_Next() based on the most recent changes to the
dictionary code.

This closes SF patch #409864.


Index: api.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/api/api.tex,v
retrieving revision 1.116
retrieving revision 1.117
diff -C2 -r1.116 -r1.117
*** api.tex	2001/04/13 14:52:39	1.116
--- api.tex	2001/04/13 17:55:02	1.117
***************
*** 3398,3402 ****
  \var{pvalue} should either point to \ctype{PyObject*} variables that
  will be filled in with each key and value, respectively, or may be
! \NULL.  The dictionary \var{p} must not be mutated during iteration.
  For example:
  
--- 3398,3403 ----
  \var{pvalue} should either point to \ctype{PyObject*} variables that
  will be filled in with each key and value, respectively, or may be
! \NULL.
! 
  For example:
  
***************
*** 3408,3411 ****
--- 3409,3433 ----
      /* do something interesting with the values... */
      ...
+ }
+ \end{verbatim}
+ 
+ The dictionary \var{p} should not be mutated during iteration.  It is
+ safe (since Python 2.1) to modify the values of the keys as you
+ iterate over the dictionary, for example:
+ 
+ \begin{verbatim}
+ PyObject *key, *value;
+ int pos = 0;
+ 
+ while (PyDict_Next(self->dict, &pos, &key, &value)) {
+     int i = PyInt_AS_LONG(value) + 1;
+     PyObject *o = PyInt_FromLong(i);
+     if (o == NULL)
+         return -1;
+     if (PyDict_SetItem(self->dict, key, o) < 0) {
+         Py_DECREF(o);
+         return -1;
+     }
+     Py_DECREF(o);
  }
  \end{verbatim}