Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1f1b2d2e
Commit
1f1b2d2e
authored
Feb 01, 2003
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed all uses of the out-of-favor __safe_for_unpickling__ magic
attr, and copy_reg.safe_constructors.
parent
371935fc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
5 additions
and
79 deletions
+5
-79
Lib/copy_reg.py
Lib/copy_reg.py
+0
-3
Lib/test/pickletester.py
Lib/test/pickletester.py
+0
-2
Modules/cPickle.c
Modules/cPickle.c
+5
-46
Modules/datetimemodule.c
Modules/datetimemodule.c
+0
-27
Objects/structseq.c
Objects/structseq.c
+0
-1
No files found.
Lib/copy_reg.py
View file @
1f1b2d2e
...
@@ -10,7 +10,6 @@ __all__ = ["pickle", "constructor",
...
@@ -10,7 +10,6 @@ __all__ = ["pickle", "constructor",
"add_extension"
,
"remove_extension"
,
"clear_extension_cache"
]
"add_extension"
,
"remove_extension"
,
"clear_extension_cache"
]
dispatch_table
=
{}
dispatch_table
=
{}
safe_constructors
=
{}
def
pickle
(
ob_type
,
pickle_function
,
constructor_ob
=
None
):
def
pickle
(
ob_type
,
pickle_function
,
constructor_ob
=
None
):
if
type
(
ob_type
)
is
_ClassType
:
if
type
(
ob_type
)
is
_ClassType
:
...
@@ -26,7 +25,6 @@ def pickle(ob_type, pickle_function, constructor_ob=None):
...
@@ -26,7 +25,6 @@ def pickle(ob_type, pickle_function, constructor_ob=None):
def
constructor
(
object
):
def
constructor
(
object
):
if
not
callable
(
object
):
if
not
callable
(
object
):
raise
TypeError
(
"constructors must be callable"
)
raise
TypeError
(
"constructors must be callable"
)
safe_constructors
[
object
]
=
1
# Example: provide pickling support for complex numbers.
# Example: provide pickling support for complex numbers.
...
@@ -41,7 +39,6 @@ def _reconstructor(cls, base, state):
...
@@ -41,7 +39,6 @@ def _reconstructor(cls, base, state):
obj
=
base
.
__new__
(
cls
,
state
)
obj
=
base
.
__new__
(
cls
,
state
)
base
.
__init__
(
obj
,
state
)
base
.
__init__
(
obj
,
state
)
return
obj
return
obj
_reconstructor
.
__safe_for_unpickling__
=
1
_HEAPTYPE
=
1
<<
9
_HEAPTYPE
=
1
<<
9
...
...
Lib/test/pickletester.py
View file @
1f1b2d2e
...
@@ -15,8 +15,6 @@ class myint(int):
...
@@ -15,8 +15,6 @@ class myint(int):
class
initarg
(
C
):
class
initarg
(
C
):
__safe_for_unpickling__
=
1
def
__init__
(
self
,
a
,
b
):
def
__init__
(
self
,
a
,
b
):
self
.
a
=
a
self
.
a
=
a
self
.
b
=
b
self
.
b
=
b
...
...
Modules/cPickle.c
View file @
1f1b2d2e
...
@@ -92,14 +92,13 @@ static PyObject *BadPickleGet;
...
@@ -92,14 +92,13 @@ static PyObject *BadPickleGet;
static
PyObject
*
dispatch_table
;
static
PyObject
*
dispatch_table
;
static
PyObject
*
safe_constructors
;
static
PyObject
*
empty_tuple
;
static
PyObject
*
empty_tuple
;
static
PyObject
*
__class___str
,
*
__getinitargs___str
,
*
__dict___str
,
static
PyObject
*
__class___str
,
*
__getinitargs___str
,
*
__dict___str
,
*
__getstate___str
,
*
__setstate___str
,
*
__name___str
,
*
__reduce___str
,
*
__getstate___str
,
*
__setstate___str
,
*
__name___str
,
*
__reduce___str
,
*
write_str
,
*
__safe_for_unpickling___str
,
*
append_str
,
*
write_str
,
*
append_str
,
*
read_str
,
*
readline_str
,
*
__main___str
,
*
__basicnew___str
,
*
read_str
,
*
readline_str
,
*
__main___str
,
*
__basicnew___str
,
*
copy_reg_str
,
*
dispatch_table_str
,
*
safe_constructors_str
;
*
copy_reg_str
,
*
dispatch_table_str
;
/*************************************************************************
/*************************************************************************
Internal Data type for pickle data. */
Internal Data type for pickle data. */
...
@@ -306,7 +305,6 @@ typedef struct Unpicklerobject {
...
@@ -306,7 +305,6 @@ typedef struct Unpicklerobject {
int
(
*
readline_func
)(
struct
Unpicklerobject
*
,
char
**
);
int
(
*
readline_func
)(
struct
Unpicklerobject
*
,
char
**
);
int
buf_size
;
int
buf_size
;
char
*
buf
;
char
*
buf
;
PyObject
*
safe_constructors
;
PyObject
*
find_class
;
PyObject
*
find_class
;
}
Unpicklerobject
;
}
Unpicklerobject
;
...
@@ -3078,8 +3076,7 @@ load_dict(Unpicklerobject *self)
...
@@ -3078,8 +3076,7 @@ load_dict(Unpicklerobject *self)
static
PyObject
*
static
PyObject
*
Instance_New
(
PyObject
*
cls
,
PyObject
*
args
)
Instance_New
(
PyObject
*
cls
,
PyObject
*
args
)
{
{
int
has_key
;
PyObject
*
r
=
0
;
PyObject
*
safe
=
0
,
*
r
=
0
;
if
(
PyClass_Check
(
cls
))
{
if
(
PyClass_Check
(
cls
))
{
int
l
;
int
l
;
...
@@ -3107,21 +3104,6 @@ Instance_New(PyObject *cls, PyObject *args)
...
@@ -3107,21 +3104,6 @@ Instance_New(PyObject *cls, PyObject *args)
else
goto
err
;
else
goto
err
;
}
}
/* 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
)
{
if
(
args
==
Py_None
)
{
/* Special case, call cls.__basicnew__() */
/* Special case, call cls.__basicnew__() */
PyObject
*
basicnew
;
PyObject
*
basicnew
;
...
@@ -4332,7 +4314,6 @@ newUnpicklerobject(PyObject *f)
...
@@ -4332,7 +4314,6 @@ newUnpicklerobject(PyObject *f)
self
->
buf_size
=
0
;
self
->
buf_size
=
0
;
self
->
read
=
NULL
;
self
->
read
=
NULL
;
self
->
readline
=
NULL
;
self
->
readline
=
NULL
;
self
->
safe_constructors
=
NULL
;
self
->
find_class
=
NULL
;
self
->
find_class
=
NULL
;
if
(
!
(
self
->
memo
=
PyDict_New
()))
if
(
!
(
self
->
memo
=
PyDict_New
()))
...
@@ -4373,21 +4354,6 @@ newUnpicklerobject(PyObject *f)
...
@@ -4373,21 +4354,6 @@ newUnpicklerobject(PyObject *f)
}
}
}
}
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
;
return
self
;
err:
err:
...
@@ -4418,7 +4384,6 @@ Unpickler_dealloc(Unpicklerobject *self)
...
@@ -4418,7 +4384,6 @@ Unpickler_dealloc(Unpicklerobject *self)
Py_XDECREF
(
self
->
pers_func
);
Py_XDECREF
(
self
->
pers_func
);
Py_XDECREF
(
self
->
arg
);
Py_XDECREF
(
self
->
arg
);
Py_XDECREF
(
self
->
last_string
);
Py_XDECREF
(
self
->
last_string
);
Py_XDECREF
(
self
->
safe_constructors
);
if
(
self
->
marks
)
{
if
(
self
->
marks
)
{
free
(
self
->
marks
);
free
(
self
->
marks
);
...
@@ -4693,28 +4658,22 @@ init_stuff(PyObject *module_dict)
...
@@ -4693,28 +4658,22 @@ init_stuff(PyObject *module_dict)
INIT_STR
(
__main__
);
INIT_STR
(
__main__
);
INIT_STR
(
__reduce__
);
INIT_STR
(
__reduce__
);
INIT_STR
(
write
);
INIT_STR
(
write
);
INIT_STR
(
__safe_for_unpickling__
);
INIT_STR
(
append
);
INIT_STR
(
append
);
INIT_STR
(
read
);
INIT_STR
(
read
);
INIT_STR
(
readline
);
INIT_STR
(
readline
);
INIT_STR
(
copy_reg
);
INIT_STR
(
copy_reg
);
INIT_STR
(
dispatch_table
);
INIT_STR
(
dispatch_table
);
INIT_STR
(
safe_constructors
);
INIT_STR
(
__basicnew__
);
INIT_STR
(
__basicnew__
);
if
(
!
(
copy_reg
=
PyImport_ImportModule
(
"copy_reg"
)))
if
(
!
(
copy_reg
=
PyImport_ImportModule
(
"copy_reg"
)))
return
-
1
;
return
-
1
;
/* Th
ese next few are special because we want to use
different
/* Th
is is special because we want to use a
different
one
s
in restricted mode. */
one in restricted mode. */
dispatch_table
=
PyObject_GetAttr
(
copy_reg
,
dispatch_table_str
);
dispatch_table
=
PyObject_GetAttr
(
copy_reg
,
dispatch_table_str
);
if
(
!
dispatch_table
)
if
(
!
dispatch_table
)
return
-
1
;
return
-
1
;
if
(
!
(
safe_constructors
=
PyObject_GetAttr
(
copy_reg
,
safe_constructors_str
)))
return
-
1
;
Py_DECREF
(
copy_reg
);
Py_DECREF
(
copy_reg
);
/* Down to here ********************************** */
/* Down to here ********************************** */
...
...
Modules/datetimemodule.c
View file @
1f1b2d2e
...
@@ -4516,13 +4516,6 @@ initdatetime(void)
...
@@ -4516,13 +4516,6 @@ initdatetime(void)
PyObject
*
d
;
/* its dict */
PyObject
*
d
;
/* its dict */
PyObject
*
x
;
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
,
m
=
Py_InitModule3
(
"datetime"
,
module_methods
,
"Fast implementation of the datetime type."
);
"Fast implementation of the datetime type."
);
...
@@ -4577,18 +4570,9 @@ initdatetime(void)
...
@@ -4577,18 +4570,9 @@ initdatetime(void)
}
}
}
}
/* tzinfo values */
d
=
PyDateTime_TZInfoType
.
tp_dict
;
if
(
PyDict_SetItem
(
d
,
safepickle
,
Py_True
)
<
0
)
return
;
/* timedelta values */
/* timedelta values */
d
=
PyDateTime_DeltaType
.
tp_dict
;
d
=
PyDateTime_DeltaType
.
tp_dict
;
if
(
PyDict_SetItem
(
d
,
safepickle
,
Py_True
)
<
0
)
return
;
x
=
new_delta
(
0
,
0
,
1
,
0
);
x
=
new_delta
(
0
,
0
,
1
,
0
);
if
(
x
==
NULL
||
PyDict_SetItemString
(
d
,
"resolution"
,
x
)
<
0
)
if
(
x
==
NULL
||
PyDict_SetItemString
(
d
,
"resolution"
,
x
)
<
0
)
return
;
return
;
...
@@ -4607,9 +4591,6 @@ initdatetime(void)
...
@@ -4607,9 +4591,6 @@ initdatetime(void)
/* date values */
/* date values */
d
=
PyDateTime_DateType
.
tp_dict
;
d
=
PyDateTime_DateType
.
tp_dict
;
if
(
PyDict_SetItem
(
d
,
safepickle
,
Py_True
)
<
0
)
return
;
x
=
new_date
(
1
,
1
,
1
);
x
=
new_date
(
1
,
1
,
1
);
if
(
x
==
NULL
||
PyDict_SetItemString
(
d
,
"min"
,
x
)
<
0
)
if
(
x
==
NULL
||
PyDict_SetItemString
(
d
,
"min"
,
x
)
<
0
)
return
;
return
;
...
@@ -4628,9 +4609,6 @@ initdatetime(void)
...
@@ -4628,9 +4609,6 @@ initdatetime(void)
/* time values */
/* time values */
d
=
PyDateTime_TimeType
.
tp_dict
;
d
=
PyDateTime_TimeType
.
tp_dict
;
if
(
PyDict_SetItem
(
d
,
safepickle
,
Py_True
)
<
0
)
return
;
x
=
new_time
(
0
,
0
,
0
,
0
,
Py_None
);
x
=
new_time
(
0
,
0
,
0
,
0
,
Py_None
);
if
(
x
==
NULL
||
PyDict_SetItemString
(
d
,
"min"
,
x
)
<
0
)
if
(
x
==
NULL
||
PyDict_SetItemString
(
d
,
"min"
,
x
)
<
0
)
return
;
return
;
...
@@ -4649,9 +4627,6 @@ initdatetime(void)
...
@@ -4649,9 +4627,6 @@ initdatetime(void)
/* datetime values */
/* datetime values */
d
=
PyDateTime_DateTimeType
.
tp_dict
;
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
);
x
=
new_datetime
(
1
,
1
,
1
,
0
,
0
,
0
,
0
,
Py_None
);
if
(
x
==
NULL
||
PyDict_SetItemString
(
d
,
"min"
,
x
)
<
0
)
if
(
x
==
NULL
||
PyDict_SetItemString
(
d
,
"min"
,
x
)
<
0
)
return
;
return
;
...
@@ -4667,8 +4642,6 @@ initdatetime(void)
...
@@ -4667,8 +4642,6 @@ initdatetime(void)
return
;
return
;
Py_DECREF
(
x
);
Py_DECREF
(
x
);
Py_DECREF
(
safepickle
);
/* module initialization */
/* module initialization */
PyModule_AddIntConstant
(
m
,
"MINYEAR"
,
MINYEAR
);
PyModule_AddIntConstant
(
m
,
"MINYEAR"
,
MINYEAR
);
PyModule_AddIntConstant
(
m
,
"MAXYEAR"
,
MAXYEAR
);
PyModule_AddIntConstant
(
m
,
"MAXYEAR"
,
MAXYEAR
);
...
...
Objects/structseq.c
View file @
1f1b2d2e
...
@@ -392,5 +392,4 @@ PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)
...
@@ -392,5 +392,4 @@ PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)
PyInt_FromLong
((
long
)
n_members
));
PyInt_FromLong
((
long
)
n_members
));
PyDict_SetItemString
(
dict
,
unnamed_fields_key
,
PyDict_SetItemString
(
dict
,
unnamed_fields_key
,
PyInt_FromLong
((
long
)
n_unnamed_members
));
PyInt_FromLong
((
long
)
n_unnamed_members
));
PyDict_SetItemString
(
dict
,
"__safe_for_unpickling__"
,
Py_True
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment