mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-103092: Isolate _pickle module (#102982)
Co-authored-by: Mohamed Koubaa <koubaa.m@gmail.com> Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
This commit is contained in:
parent
810d365b5e
commit
c00dcf0e38
5 changed files with 724 additions and 690 deletions
1304
Modules/_pickle.c
1304
Modules/_pickle.c
File diff suppressed because it is too large
Load diff
76
Modules/clinic/_pickle.c.h
generated
76
Modules/clinic/_pickle.c.h
generated
|
|
@ -38,7 +38,42 @@ PyDoc_STRVAR(_pickle_Pickler_dump__doc__,
|
|||
"Write a pickled representation of the given object to the open file.");
|
||||
|
||||
#define _PICKLE_PICKLER_DUMP_METHODDEF \
|
||||
{"dump", (PyCFunction)_pickle_Pickler_dump, METH_O, _pickle_Pickler_dump__doc__},
|
||||
{"dump", _PyCFunction_CAST(_pickle_Pickler_dump), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _pickle_Pickler_dump__doc__},
|
||||
|
||||
static PyObject *
|
||||
_pickle_Pickler_dump_impl(PicklerObject *self, PyTypeObject *cls,
|
||||
PyObject *obj);
|
||||
|
||||
static PyObject *
|
||||
_pickle_Pickler_dump(PicklerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
|
||||
#else
|
||||
# define KWTUPLE NULL
|
||||
#endif
|
||||
|
||||
static const char * const _keywords[] = {"", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "dump",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[1];
|
||||
PyObject *obj;
|
||||
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||
if (!args) {
|
||||
goto exit;
|
||||
}
|
||||
obj = args[0];
|
||||
return_value = _pickle_Pickler_dump_impl(self, cls, obj);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_pickle_Pickler___sizeof____doc__,
|
||||
"__sizeof__($self, /)\n"
|
||||
|
|
@ -242,15 +277,19 @@ PyDoc_STRVAR(_pickle_Unpickler_load__doc__,
|
|||
"specified therein.");
|
||||
|
||||
#define _PICKLE_UNPICKLER_LOAD_METHODDEF \
|
||||
{"load", (PyCFunction)_pickle_Unpickler_load, METH_NOARGS, _pickle_Unpickler_load__doc__},
|
||||
{"load", _PyCFunction_CAST(_pickle_Unpickler_load), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _pickle_Unpickler_load__doc__},
|
||||
|
||||
static PyObject *
|
||||
_pickle_Unpickler_load_impl(UnpicklerObject *self);
|
||||
_pickle_Unpickler_load_impl(UnpicklerObject *self, PyTypeObject *cls);
|
||||
|
||||
static PyObject *
|
||||
_pickle_Unpickler_load(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
|
||||
_pickle_Unpickler_load(UnpicklerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
return _pickle_Unpickler_load_impl(self);
|
||||
if (nargs) {
|
||||
PyErr_SetString(PyExc_TypeError, "load() takes no arguments");
|
||||
return NULL;
|
||||
}
|
||||
return _pickle_Unpickler_load_impl(self, cls);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_pickle_Unpickler_find_class__doc__,
|
||||
|
|
@ -267,26 +306,41 @@ PyDoc_STRVAR(_pickle_Unpickler_find_class__doc__,
|
|||
"needed. Both arguments passed are str objects.");
|
||||
|
||||
#define _PICKLE_UNPICKLER_FIND_CLASS_METHODDEF \
|
||||
{"find_class", _PyCFunction_CAST(_pickle_Unpickler_find_class), METH_FASTCALL, _pickle_Unpickler_find_class__doc__},
|
||||
{"find_class", _PyCFunction_CAST(_pickle_Unpickler_find_class), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _pickle_Unpickler_find_class__doc__},
|
||||
|
||||
static PyObject *
|
||||
_pickle_Unpickler_find_class_impl(UnpicklerObject *self,
|
||||
_pickle_Unpickler_find_class_impl(UnpicklerObject *self, PyTypeObject *cls,
|
||||
PyObject *module_name,
|
||||
PyObject *global_name);
|
||||
|
||||
static PyObject *
|
||||
_pickle_Unpickler_find_class(UnpicklerObject *self, PyObject *const *args, Py_ssize_t nargs)
|
||||
_pickle_Unpickler_find_class(UnpicklerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
|
||||
#else
|
||||
# define KWTUPLE NULL
|
||||
#endif
|
||||
|
||||
static const char * const _keywords[] = {"", "", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "find_class",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[2];
|
||||
PyObject *module_name;
|
||||
PyObject *global_name;
|
||||
|
||||
if (!_PyArg_CheckPositional("find_class", nargs, 2, 2)) {
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
|
||||
if (!args) {
|
||||
goto exit;
|
||||
}
|
||||
module_name = args[0];
|
||||
global_name = args[1];
|
||||
return_value = _pickle_Unpickler_find_class_impl(self, module_name, global_name);
|
||||
return_value = _pickle_Unpickler_find_class_impl(self, cls, module_name, global_name);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
|
|
@ -980,4 +1034,4 @@ skip_optional_kwonly:
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=730dc26938561313 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=a0e04b85e7bae626 input=a9049054013a1b77]*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue