Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
19b6fa6e
Kaydet (Commit)
19b6fa6e
authored
Ara 01, 2013
tarafından
Alexandre Vassalotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #6477: Added support for pickling the types of built-in singletons.
üst
f8ceb04f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
4 deletions
+58
-4
object.h
Include/object.h
+3
-0
pickle.py
Lib/pickle.py
+10
-1
pickletester.py
Lib/test/pickletester.py
+9
-0
NEWS
Misc/NEWS
+3
-0
_pickle.c
Modules/_pickle.c
+31
-1
object.c
Objects/object.c
+2
-2
No files found.
Include/object.h
Dosyayı görüntüle @
19b6fa6e
...
...
@@ -831,6 +831,9 @@ they can have object code that is not dependent on Python compilation flags.
PyAPI_FUNC
(
void
)
Py_IncRef
(
PyObject
*
);
PyAPI_FUNC
(
void
)
Py_DecRef
(
PyObject
*
);
PyAPI_DATA
(
PyTypeObject
)
PyNone_Type
;
PyAPI_DATA
(
PyTypeObject
)
PyNotImplemented_Type
;
/*
_Py_NoneStruct is an object of undefined type which can be used in contexts
where NULL (nil) is not suitable (since NULL often means 'error').
...
...
Lib/pickle.py
Dosyayı görüntüle @
19b6fa6e
...
...
@@ -728,9 +728,18 @@ class _Pickler:
self
.
memoize
(
obj
)
def
save_type
(
self
,
obj
):
if
obj
is
type
(
None
):
return
self
.
save_reduce
(
type
,
(
None
,),
obj
=
obj
)
elif
obj
is
type
(
NotImplemented
):
return
self
.
save_reduce
(
type
,
(
NotImplemented
,),
obj
=
obj
)
elif
obj
is
type
(
...
):
return
self
.
save_reduce
(
type
,
(
...
,),
obj
=
obj
)
return
self
.
save_global
(
obj
)
dispatch
[
FunctionType
]
=
save_global
dispatch
[
BuiltinFunctionType
]
=
save_global
dispatch
[
type
]
=
save_
global
dispatch
[
type
]
=
save_
type
# Pickling helpers
...
...
Lib/test/pickletester.py
Dosyayı görüntüle @
19b6fa6e
...
...
@@ -768,6 +768,15 @@ class AbstractPickleTests(unittest.TestCase):
u
=
self
.
loads
(
s
)
self
.
assertEqual
(
NotImplemented
,
u
)
def
test_singleton_types
(
self
):
# Issue #6477: Test that types of built-in singletons can be pickled.
singletons
=
[
None
,
...
,
NotImplemented
]
for
singleton
in
singletons
:
for
proto
in
protocols
:
s
=
self
.
dumps
(
type
(
singleton
),
proto
)
u
=
self
.
loads
(
s
)
self
.
assertIs
(
type
(
singleton
),
u
)
# Tests for protocol 2
def
test_proto
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
19b6fa6e
...
...
@@ -24,6 +24,9 @@ Library
- Fixed _pickle.Unpickler to not fail when loading empty strings as
persistent IDs.
- Issue #6477: Added support for pickling the types of built-in singletons
(i.e., Ellipsis, NotImplemented, None).
- Issue #11508: Fixed uuid.getnode() and uuid.uuid1() on environment with
virtual interface. Original patch by Kent Frazier.
...
...
Modules/_pickle.c
Dosyayı görüntüle @
19b6fa6e
...
...
@@ -2835,6 +2835,36 @@ save_notimplemented(PicklerObject *self, PyObject *obj)
return
res
;
}
static
int
save_singleton_type
(
PicklerObject
*
self
,
PyObject
*
obj
,
PyObject
*
singleton
)
{
PyObject
*
reduce_value
;
int
status
;
reduce_value
=
Py_BuildValue
(
"O(O)"
,
&
PyType_Type
,
singleton
);
if
(
reduce_value
==
NULL
)
{
return
-
1
;
}
status
=
save_reduce
(
self
,
reduce_value
,
obj
);
Py_DECREF
(
reduce_value
);
return
status
;
}
static
int
save_type
(
PicklerObject
*
self
,
PyObject
*
obj
)
{
if
(
obj
==
(
PyObject
*
)
&
PyNone_Type
)
{
return
save_singleton_type
(
self
,
obj
,
Py_None
);
}
else
if
(
obj
==
(
PyObject
*
)
&
PyEllipsis_Type
)
{
return
save_singleton_type
(
self
,
obj
,
Py_Ellipsis
);
}
else
if
(
obj
==
(
PyObject
*
)
&
PyNotImplemented_Type
)
{
return
save_singleton_type
(
self
,
obj
,
Py_NotImplemented
);
}
return
save_global
(
self
,
obj
,
NULL
);
}
static
int
save_pers
(
PicklerObject
*
self
,
PyObject
*
obj
,
PyObject
*
func
)
{
...
...
@@ -3189,7 +3219,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
goto
done
;
}
else
if
(
type
==
&
PyType_Type
)
{
status
=
save_
global
(
self
,
obj
,
NULL
);
status
=
save_
type
(
self
,
obj
);
goto
done
;
}
else
if
(
type
==
&
PyFunction_Type
)
{
...
...
Objects/object.c
Dosyayı görüntüle @
19b6fa6e
...
...
@@ -1459,7 +1459,7 @@ static PyNumberMethods none_as_number = {
0
,
/* nb_index */
};
static
PyTypeObject
PyNone_Type
=
{
PyTypeObject
PyNone_Type
=
{
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
"NoneType"
,
0
,
...
...
@@ -1524,7 +1524,7 @@ notimplemented_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
Py_RETURN_NOTIMPLEMENTED
;
}
static
PyTypeObject
PyNotImplemented_Type
=
{
PyTypeObject
PyNotImplemented_Type
=
{
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
"NotImplementedType"
,
0
,
...
...
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