[Python-checkins] CVS: python/dist/src/Modules cPickle.c,2.51,2.52

Guido van Rossum python-dev@python.org
Thu, 7 Sep 2000 07:35:40 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv12724

Modified Files:
	cPickle.c 
Log Message:
Oops.  Jim's fix didn't.  This one does -- I tested it a bit better
this time!


Index: cPickle.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.51
retrieving revision 2.52
diff -C2 -r2.51 -r2.52
*** cPickle.c	2000/09/07 00:11:40	2.51
--- cPickle.c	2000/09/07 14:35:37	2.52
***************
*** 4387,4391 ****
  
  static int
! init_stuff(PyObject *module, PyObject *module_dict) {
      PyObject *string, *copy_reg, *t, *r;
  
--- 4387,4391 ----
  
  static int
! init_stuff(PyObject *module_dict) {
      PyObject *string, *copy_reg, *t, *r;
  
***************
*** 4517,4531 ****
  DL_EXPORT(void)
  initcPickle(void) {
!     PyObject *m, *d, *v;
      char *rev="1.71";
      PyObject *format_version;
      PyObject *compatible_formats;
  
-     if (init_stuff(m, d) < 0) return;
- 
      Picklertype.ob_type = &PyType_Type;
      Unpicklertype.ob_type = &PyType_Type;
      PdataType.ob_type = &PyType_Type;
  
      /* Create the module and add the functions */
      m = Py_InitModule4("cPickle", cPickle_methods,
--- 4517,4537 ----
  DL_EXPORT(void)
  initcPickle(void) {
!     PyObject *m, *d, *di, *v, *k;
!     int i;
      char *rev="1.71";
      PyObject *format_version;
      PyObject *compatible_formats;
  
      Picklertype.ob_type = &PyType_Type;
      Unpicklertype.ob_type = &PyType_Type;
      PdataType.ob_type = &PyType_Type;
  
+     /* Initialize some pieces. We need to do this before module creation, 
+        so we're forced to use a temporary dictionary. :( 
+     */
+     di=PyDict_New();
+     if (!di) return;
+     if (init_stuff(di) < 0) return;
+ 
      /* Create the module and add the functions */
      m = Py_InitModule4("cPickle", cPickle_methods,
***************
*** 4537,4540 ****
--- 4543,4555 ----
      PyDict_SetItemString(d,"__version__", v = PyString_FromString(rev));
      Py_XDECREF(v);
+ 
+     /* Copy data from di. Waaa. */
+     for (i=0; PyDict_Next(di, &i, &k, &v); ) {
+         if (PyObject_SetItem(d, k, v) < 0) {
+             Py_DECREF(di);
+             return;
+         }
+     }
+     Py_DECREF(di);
  
      format_version = PyString_FromString("1.3");