[Python-checkins] python/dist/src/Modules cPickle.c,2.100,2.101 datetimemodule.c,1.53,1.54

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Fri, 31 Jan 2003 18:16:39 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv14164/Modules

Modified Files:
	cPickle.c datetimemodule.c 
Log Message:
Removed all uses of the out-of-favor __safe_for_unpickling__ magic
attr, and copy_reg.safe_constructors.


Index: cPickle.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.100
retrieving revision 2.101
diff -C2 -d -r2.100 -r2.101
*** cPickle.c	31 Jan 2003 21:10:31 -0000	2.100
--- cPickle.c	1 Feb 2003 02:16:37 -0000	2.101
***************
*** 93,104 ****
  
  static PyObject *dispatch_table;
- static PyObject *safe_constructors;
  static PyObject *empty_tuple;
  
  static PyObject *__class___str, *__getinitargs___str, *__dict___str,
    *__getstate___str, *__setstate___str, *__name___str, *__reduce___str,
!   *write_str, *__safe_for_unpickling___str, *append_str,
    *read_str, *readline_str, *__main___str, *__basicnew___str,
!   *copy_reg_str, *dispatch_table_str, *safe_constructors_str;
  
  /*************************************************************************
--- 93,103 ----
  
  static PyObject *dispatch_table;
  static PyObject *empty_tuple;
  
  static PyObject *__class___str, *__getinitargs___str, *__dict___str,
    *__getstate___str, *__setstate___str, *__name___str, *__reduce___str,
!   *write_str, *append_str,
    *read_str, *readline_str, *__main___str, *__basicnew___str,
!   *copy_reg_str, *dispatch_table_str;
  
  /*************************************************************************
***************
*** 307,311 ****
  	int buf_size;
  	char *buf;
- 	PyObject *safe_constructors;
  	PyObject *find_class;
  } Unpicklerobject;
--- 306,309 ----
***************
*** 3079,3084 ****
  Instance_New(PyObject *cls, PyObject *args) 
  {
! 	int has_key;
! 	PyObject *safe=0, *r=0;
  
  	if (PyClass_Check(cls)) {
--- 3077,3081 ----
  Instance_New(PyObject *cls, PyObject *args) 
  {
! 	PyObject *r = 0;
  
  	if (PyClass_Check(cls)) {
***************
*** 3108,3126 ****
  	}
  
- 	/* Is safe_constructors always a dict? */
- 	has_key = cPickle_PyMapping_HasKey(safe_constructors, cls);
- 	if (!has_key) {
- 		safe = PyObject_GetAttr(cls, __safe_for_unpickling___str);
- 		if (!safe ||
- 		    !PyObject_IsTrue(safe)) {
- 			cPickle_ErrFormat(UnpicklingError,
- 					  "%s is not safe for unpickling", 
- 					  "O", cls);
- 			Py_XDECREF(safe);
- 			return NULL;
- 		}
- 		Py_DECREF(safe);
- 	}
- 
  	if (args==Py_None) {
  		/* Special case, call cls.__basicnew__() */
--- 3105,3108 ----
***************
*** 4333,4337 ****
  	self->read = NULL;
  	self->readline = NULL;
- 	self->safe_constructors = NULL;
  	self->find_class = NULL;
  
--- 4315,4318 ----
***************
*** 4374,4392 ****
  	}
  
- 	if (PyEval_GetRestricted()) {
- 		/* Restricted execution, get private tables */
- 		PyObject *m;
- 
- 		if (!( m=PyImport_Import(copy_reg_str)))  goto err;
- 		self->safe_constructors=PyObject_GetAttr(m, 
- 							 safe_constructors_str);
- 		Py_DECREF(m);
- 		if (!( self->safe_constructors ))  goto err;
- 	}
- 	else {
- 		self->safe_constructors=safe_constructors;
- 		Py_INCREF(safe_constructors);
- 	}
- 
  	return self;
  
--- 4355,4358 ----
***************
*** 4419,4423 ****
  	Py_XDECREF(self->arg);
  	Py_XDECREF(self->last_string);
- 	Py_XDECREF(self->safe_constructors);
  
  	if (self->marks) {
--- 4385,4388 ----
***************
*** 4694,4698 ****
  	INIT_STR(__reduce__);
  	INIT_STR(write);
- 	INIT_STR(__safe_for_unpickling__);
  	INIT_STR(append);
  	INIT_STR(read);
--- 4659,4662 ----
***************
*** 4700,4704 ****
  	INIT_STR(copy_reg);
  	INIT_STR(dispatch_table);
- 	INIT_STR(safe_constructors);
  	INIT_STR(__basicnew__);
  
--- 4664,4667 ----
***************
*** 4706,4717 ****
  		return -1;
  
! 	/* These next few are special because we want to use different
! 	   ones in restricted mode. */
  	dispatch_table = PyObject_GetAttr(copy_reg, dispatch_table_str);
  	if (!dispatch_table) 
- 		return -1;
- 
- 	if (!( safe_constructors = PyObject_GetAttr(copy_reg,
- 						    safe_constructors_str))) 
  		return -1;
  
--- 4669,4676 ----
  		return -1;
  
! 	/* This is special because we want to use a different
! 	   one in restricted mode. */
  	dispatch_table = PyObject_GetAttr(copy_reg, dispatch_table_str);
  	if (!dispatch_table) 
  		return -1;
  

Index: datetimemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/datetimemodule.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -d -r1.53 -r1.54
*** datetimemodule.c	1 Feb 2003 01:52:50 -0000	1.53
--- datetimemodule.c	1 Feb 2003 02:16:37 -0000	1.54
***************
*** 4517,4527 ****
  	PyObject *x;
  
- 	/* Types that use __reduce__ for pickling need to set the following
- 	 * magical attr in the type dict, with a true value.
- 	 */
- 	PyObject *safepickle = PyString_FromString("__safe_for_unpickling__");
- 	if (safepickle == NULL)
- 		return;
- 
  	m = Py_InitModule3("datetime", module_methods,
  			   "Fast implementation of the datetime type.");
--- 4517,4520 ----
***************
*** 4578,4593 ****
  	}
  
- 	/* tzinfo values */
- 	d = PyDateTime_TZInfoType.tp_dict;
- 
- 	if (PyDict_SetItem(d, safepickle, Py_True) < 0)
- 		return;
- 
  	/* timedelta values */
  	d = PyDateTime_DeltaType.tp_dict;
  
- 	if (PyDict_SetItem(d, safepickle, Py_True) < 0)
- 		return;
- 
  	x = new_delta(0, 0, 1, 0);
  	if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
--- 4571,4577 ----
***************
*** 4608,4614 ****
  	d = PyDateTime_DateType.tp_dict;
  
- 	if (PyDict_SetItem(d, safepickle, Py_True) < 0)
- 		return;
- 
  	x = new_date(1, 1, 1);
  	if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
--- 4592,4595 ----
***************
*** 4629,4635 ****
  	d = PyDateTime_TimeType.tp_dict;
  
- 	if (PyDict_SetItem(d, safepickle, Py_True) < 0)
- 		return;
- 
  	x = new_time(0, 0, 0, 0, Py_None);
  	if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
--- 4610,4613 ----
***************
*** 4650,4656 ****
  	d = PyDateTime_DateTimeType.tp_dict;
  
- 	if (PyDict_SetItem(d, safepickle, Py_True) < 0)
- 		return;
- 
  	x = new_datetime(1, 1, 1, 0, 0, 0, 0, Py_None);
  	if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
--- 4628,4631 ----
***************
*** 4667,4672 ****
  		return;
  	Py_DECREF(x);
- 
- 	Py_DECREF(safepickle);
  
  	/* module initialization */
--- 4642,4645 ----