Lines Matching defs:obj
370 _Pickle_FastCall(PyObject *func, PyObject *obj)
374 result = PyObject_CallOneArg(func, obj);
375 Py_DECREF(obj);
429 call_method(PyObject *func, PyObject *self, PyObject *obj)
432 return PyObject_CallFunctionObjArgs(func, self, obj, NULL);
435 return PyObject_CallOneArg(func, obj);
560 Pdata_push(Pdata *self, PyObject *obj)
565 self->data[Py_SIZE(self)] = obj;
1758 memo_put(PicklerObject *self, PyObject *obj)
1770 if (PyMemoTable_Set(self->memo, obj, idx) < 0)
1812 get_dotted_path(PyObject *obj, PyObject *name)
1825 if (obj == NULL)
1830 "Can't pickle local attribute %R on %R", name, obj);
1839 get_deep_attribute(PyObject *obj, PyObject *names, PyObject **pparent)
1845 Py_INCREF(obj);
1850 parent = obj;
1851 (void)_PyObject_LookupAttr(parent, name, &obj);
1852 if (obj == NULL) {
1861 return obj;
1866 getattribute(PyObject *obj, PyObject *name, int allow_qualname)
1871 dotted_path = get_dotted_path(obj, name);
1874 attr = get_deep_attribute(obj, dotted_path, NULL);
1878 (void)_PyObject_LookupAttr(obj, name, &attr);
1882 "Can't get attribute %R on %R", name, obj);
1993 fast_save_enter(PicklerObject *self, PyObject *obj)
2005 key = PyLong_FromVoidPtr(obj);
2015 Py_TYPE(obj)->tp_name, obj);
2030 fast_save_leave(PicklerObject *self, PyObject *obj)
2033 PyObject *key = PyLong_FromVoidPtr(obj);
2046 save_none(PicklerObject *self, PyObject *obj)
2056 save_bool(PicklerObject *self, PyObject *obj)
2059 const char bool_op = (obj == Py_True) ? NEWTRUE : NEWFALSE;
2069 const char *bool_str = (obj == Py_True) ? "I01\n" : "I00\n";
2077 save_long(PicklerObject *self, PyObject *obj)
2085 val= PyLong_AsLongAndOverflow(obj, &overflow);
2138 int sign = _PyLong_Sign(obj);
2147 nbits = _PyLong_NumBits(obj);
2174 i = _PyLong_AsByteArray((PyLongObject *)obj,
2216 repr = PyObject_Repr(obj);
2240 save_float(PicklerObject *self, PyObject *obj)
2242 double x = PyFloat_AS_DOUBLE((PyFloatObject *)obj);
2355 _save_bytes_data(PicklerObject *self, PyObject *obj, const char *data,
2391 if (_Pickler_write_bytes(self, header, len, data, size, obj) < 0) {
2395 if (memo_put(self, obj) < 0) {
2403 save_bytes(PicklerObject *self, PyObject *obj)
2420 if (PyBytes_GET_SIZE(obj) == 0) {
2426 PyUnicode_DecodeLatin1(PyBytes_AS_STRING(obj),
2427 PyBytes_GET_SIZE(obj),
2442 status = save_reduce(self, reduce_value, obj);
2447 return _save_bytes_data(self, obj, PyBytes_AS_STRING(obj),
2448 PyBytes_GET_SIZE(obj));
2453 _save_bytearray_data(PicklerObject *self, PyObject *obj, const char *data,
2468 if (_Pickler_write_bytes(self, header, len, data, size, obj) < 0) {
2472 if (memo_put(self, obj) < 0) {
2480 save_bytearray(PicklerObject *self, PyObject *obj)
2488 if (PyByteArray_GET_SIZE(obj) == 0) {
2493 PyObject *bytes_obj = PyBytes_FromObject(obj);
2505 status = save_reduce(self, reduce_value, obj);
2510 return _save_bytearray_data(self, obj, PyByteArray_AS_STRING(obj),
2511 PyByteArray_GET_SIZE(obj));
2516 save_picklebuffer(PicklerObject *self, PyObject *obj)
2524 const Py_buffer* view = PyPickleBuffer_GetBuffer(obj);
2537 PyObject *ret = PyObject_CallOneArg(self->buffer_callback, obj);
2550 return _save_bytes_data(self, obj, (const char*) view->buf,
2554 return _save_bytearray_data(self, obj, (const char*) view->buf,
2577 raw_unicode_escape(PyObject *obj)
2585 if (PyUnicode_READY(obj))
2590 size = PyUnicode_GET_LENGTH(obj);
2591 data = PyUnicode_DATA(obj);
2592 kind = PyUnicode_KIND(obj);
2649 write_unicode_binary(PicklerObject *self, PyObject *obj)
2657 if (PyUnicode_READY(obj))
2660 data = PyUnicode_AsUTF8AndSize(obj, &size);
2665 encoded = PyUnicode_AsEncodedString(obj, "utf-8", "surrogatepass");
2709 save_unicode(PicklerObject *self, PyObject *obj)
2712 if (write_unicode_binary(self, obj) < 0)
2720 encoded = raw_unicode_escape(obj);
2739 if (memo_put(self, obj) < 0)
2772 save_tuple(PicklerObject *self, PyObject *obj)
2782 if ((len = PyTuple_Size(obj)) < 0)
2809 if (store_tuple_elements(self, obj, len) < 0)
2812 if (PyMemoTable_Get(self->memo, obj)) {
2818 if (memo_get(self, obj) < 0)
2836 if (store_tuple_elements(self, obj, len) < 0)
2839 if (PyMemoTable_Get(self->memo, obj)) {
2854 if (memo_get(self, obj) < 0)
2865 if (memo_put(self, obj) < 0)
2880 PyObject *obj = NULL;
2898 obj = PyIter_Next(iter);
2899 if (obj == NULL) {
2904 i = save(self, obj, 0);
2905 Py_DECREF(obj);
2927 obj = PyIter_Next(iter);
2928 if (obj == NULL) {
2953 while (obj) {
2954 if (save(self, obj, 0) < 0)
2956 Py_CLEAR(obj);
2962 obj = PyIter_Next(iter);
2963 if (obj == NULL) {
2978 Py_XDECREF(obj);
2994 batch_list_exact(PicklerObject *self, PyObject *obj)
3003 assert(obj != NULL);
3005 assert(PyList_CheckExact(obj));
3007 if (PyList_GET_SIZE(obj) == 1) {
3008 item = PyList_GET_ITEM(obj, 0);
3025 while (total < PyList_GET_SIZE(obj)) {
3026 item = PyList_GET_ITEM(obj, total);
3039 } while (total < PyList_GET_SIZE(obj));
3045 save_list(PicklerObject *self, PyObject *obj)
3051 if (self->fast && !fast_save_enter(self, obj))
3069 if ((len = PyList_Size(obj)) < 0)
3072 if (memo_put(self, obj) < 0)
3077 if (PyList_CheckExact(obj) && self->proto > 0) {
3080 status = batch_list_exact(self, obj);
3083 PyObject *iter = PyObject_GetIter(obj);
3101 if (self->fast && !fast_save_leave(self, obj))
3121 PyObject *obj = NULL;
3134 obj = PyIter_Next(iter);
3135 if (obj == NULL) {
3140 if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 2) {
3145 i = save(self, PyTuple_GET_ITEM(obj, 0), 0);
3147 i = save(self, PyTuple_GET_ITEM(obj, 1), 0);
3148 Py_DECREF(obj);
3175 obj = PyIter_Next(iter);
3176 if (obj == NULL) {
3205 while (obj) {
3206 if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 2) {
3211 if (save(self, PyTuple_GET_ITEM(obj, 0), 0) < 0 ||
3212 save(self, PyTuple_GET_ITEM(obj, 1), 0) < 0)
3214 Py_CLEAR(obj);
3220 obj = PyIter_Next(iter);
3221 if (obj == NULL) {
3236 Py_XDECREF(obj);
3250 batch_dict_exact(PicklerObject *self, PyObject *obj)
3260 assert(obj != NULL && PyDict_CheckExact(obj));
3263 dict_size = PyDict_GET_SIZE(obj);
3267 PyDict_Next(obj, &ppos, &key, &value);
3288 while (PyDict_Next(obj, &ppos, &key, &value)) {
3304 if (PyDict_GET_SIZE(obj) != dict_size) {
3320 save_dict(PicklerObject *self, PyObject *obj)
3326 assert(PyDict_Check(obj));
3328 if (self->fast && !fast_save_enter(self, obj))
3345 if (memo_put(self, obj) < 0)
3348 if (PyDict_GET_SIZE(obj)) {
3350 if (PyDict_CheckExact(obj) && self->proto > 0) {
3355 status = batch_dict_exact(self, obj);
3358 items = PyObject_CallMethodNoArgs(obj, &_Py_ID(items));
3380 if (self->fast && !fast_save_leave(self, obj))
3387 save_set(PicklerObject *self, PyObject *obj)
3403 items = PySequence_List(obj);
3413 status = save_reduce(self, reduce_value, obj);
3421 if (memo_put(self, obj) < 0)
3424 set_size = PySet_GET_SIZE(obj);
3433 while (_PySet_NextEntry(obj, &ppos, &item, &hash)) {
3444 if (PySet_GET_SIZE(obj) != set_size) {
3456 save_frozenset(PicklerObject *self, PyObject *obj)
3463 if (self->fast && !fast_save_enter(self, obj))
3471 items = PySequence_List(obj);
3482 status = save_reduce(self, reduce_value, obj);
3490 iter = PyObject_GetIter(obj);
3517 if (PyMemoTable_Get(self->memo, obj)) {
3522 if (memo_get(self, obj) < 0)
3529 if (memo_put(self, obj) < 0)
3602 save_global(PicklerObject *self, PyObject *obj, PyObject *name)
3621 if (_PyObject_LookupAttr(obj, &_Py_ID(__qualname__), &global_name) < 0)
3624 global_name = PyObject_GetAttr(obj, &_Py_ID(__name__));
3633 module_name = whichmodule(obj, dotted_path);
3649 obj, module_name);
3659 obj, global_name, module_name);
3662 if (cls != obj) {
3666 obj, module_name, global_name);
3705 obj, code_obj);
3712 "code %ld is out of range", obj, code);
3836 if (memo_put(self, obj) < 0)
3855 save_singleton_type(PicklerObject *self, PyObject *obj, PyObject *singleton)
3864 status = save_reduce(self, reduce_value, obj);
3870 save_type(PicklerObject *self, PyObject *obj)
3872 if (obj == (PyObject *)&_PyNone_Type) {
3873 return save_singleton_type(self, obj, Py_None);
3875 else if (obj == (PyObject *)&PyEllipsis_Type) {
3876 return save_singleton_type(self, obj, Py_Ellipsis);
3878 else if (obj == (PyObject *)&_PyNotImplemented_Type) {
3879 return save_singleton_type(self, obj, Py_NotImplemented);
3881 return save_global(self, obj, NULL);
3885 save_pers(PicklerObject *self, PyObject *obj)
3893 pid = call_method(self->pers_func, self->pers_func_self, obj);
3942 get_class(PyObject *obj)
3946 if (_PyObject_LookupAttr(obj, &_Py_ID(__class__), &cls) == 0) {
3947 cls = (PyObject *) Py_TYPE(obj);
3953 /* We're saving obj, and args is the 2-thru-5 tuple returned by the
3954 * appropriate __reduce__ method for obj.
3957 save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
4148 if (obj != NULL) {
4149 obj_class = get_class(obj);
4212 /* obj can be NULL when save_reduce() is used directly. A NULL obj means
4215 obj is None. */
4216 if (obj != NULL) {
4220 if (PyMemoTable_Get(self->memo, obj)) {
4225 if (memo_get(self, obj) < 0)
4230 else if (memo_put(self, obj) < 0)
4249 * update obj's with its previous state.
4251 * tuple of expected arguments (obj, state) onto the stack. The
4252 * REDUCE opcode triggers the state_setter(obj, state) function
4260 save(self, obj, 0) < 0 || save(self, state, 0) < 0 ||
4271 save(PicklerObject *self, PyObject *obj, int pers_save)
4289 if ((status = save_pers(self, obj)) != 0)
4293 type = Py_TYPE(obj);
4302 if (obj == Py_None) {
4303 return save_none(self, obj);
4305 else if (obj == Py_False || obj == Py_True) {
4306 return save_bool(self, obj);
4309 return save_long(self, obj);
4312 return save_float(self, obj);
4318 if (PyMemoTable_Get(self->memo, obj)) {
4319 return memo_get(self, obj);
4323 return save_bytes(self, obj);
4326 return save_unicode(self, obj);
4336 status = save_dict(self, obj);
4340 status = save_set(self, obj);
4344 status = save_frozenset(self, obj);
4348 status = save_list(self, obj);
4352 status = save_tuple(self, obj);
4356 status = save_bytearray(self, obj);
4360 status = save_picklebuffer(self, obj);
4369 reduce_value = PyObject_CallOneArg(self->reducer_override, obj);
4381 status = save_type(self, obj);
4385 status = save_global(self, obj, NULL);
4420 Py_INCREF(obj);
4421 reduce_value = _Pickle_FastCall(reduce_func, obj);
4424 status = save_global(self, obj, NULL);
4437 if (_PyObject_LookupAttr(obj, &_Py_ID(__reduce_ex__), &reduce_func) < 0) {
4449 if (_PyObject_LookupAttr(obj, &_Py_ID(__reduce__), &reduce_func) < 0) {
4459 type->tp_name, obj);
4470 status = save_global(self, obj, reduce_value);
4481 status = save_reduce(self, reduce_value, obj);
4497 dump(PicklerObject *self, PyObject *obj)
4527 if (save(self, obj, 0) < 0 ||
4574 obj: object
4581 _pickle_Pickler_dump(PicklerObject *self, PyObject *obj)
4598 if (dump(self, obj) < 0)
4974 Pickler_set_memo(PicklerObject *self, PyObject *obj, void *Py_UNUSED(ignored))
4978 if (obj == NULL) {
4984 if (Py_IS_TYPE(obj, &PicklerMemoProxyType)) {
4986 ((PicklerMemoProxyObject *)obj)->pickler;
4992 else if (PyDict_Check(obj)) {
5000 while (PyDict_Next(obj, &i, &key, &value)) {
5020 "or dict, not %.200s", Py_TYPE(obj)->tp_name);
5440 PyObject *obj;
5470 obj = bytes;
5473 obj = PyUnicode_FromEncodedObject(bytes, self->encoding, self->errors);
5475 if (obj == NULL) {
5480 PDATA_PUSH(self->stack, obj, -1);
5487 PyObject *obj;
5509 obj = PyBytes_FromStringAndSize(s, size);
5512 obj = PyUnicode_Decode(s, size, self->encoding, self->errors);
5514 if (obj == NULL) {
5518 PDATA_PUSH(self->stack, obj, -1);
5616 PyObject *obj = self->stack->data[len - 1];
5617 PyObject *view = PyMemoryView_FromObject(obj);
5625 Py_DECREF(obj);
5837 PyObject *cls, *args, *obj = NULL;
5852 obj = instantiate(cls, args);
5856 if (obj == NULL)
5859 PDATA_PUSH(self->stack, obj, -1);
5868 PyObject *obj = NULL;
5906 obj = instantiate(cls, args);
5911 if (obj == NULL)
5914 PDATA_PUSH(self->stack, obj, -1);
5931 PyObject *obj;
5975 obj = ((PyTypeObject *)cls)->tp_new((PyTypeObject *)cls, args, kwargs);
5976 if (obj == NULL) {
5982 PDATA_PUSH(self->stack, obj, -1);
6057 PyObject *pid, *obj;
6077 obj = call_method(self->pers_func, self->pers_func_self, pid);
6079 if (obj == NULL)
6082 PDATA_PUSH(self->stack, obj, -1);
6097 PyObject *pid, *obj;
6104 obj = call_method(self->pers_func, self->pers_func_self, pid);
6106 if (obj == NULL)
6109 PDATA_PUSH(self->stack, obj, -1);
6274 PyObject *obj; /* the object to push */
6293 obj = PyDict_GetItemWithError(st->extension_cache, py_code);
6294 if (obj != NULL) {
6297 PDATA_APPEND(self->stack, obj, -1);
6333 obj = find_class(self, module_name, class_name);
6334 if (obj == NULL) {
6338 /* Cache code -> obj. */
6339 code = PyDict_SetItem(st->extension_cache, py_code, obj);
6342 Py_DECREF(obj);
6345 PDATA_PUSH(self->stack, obj, -1);
6781 PyObject *obj = NULL;
6788 obj = PyObject_CallObject(callable, argtup);
6793 if (obj == NULL)
6796 PDATA_PUSH(self->stack, obj, -1);
7477 Unpickler_set_memo(UnpicklerObject *self, PyObject *obj, void *Py_UNUSED(ignored))
7482 if (obj == NULL) {
7488 if (Py_IS_TYPE(obj, &UnpicklerMemoProxyType)) {
7490 ((UnpicklerMemoProxyObject *)obj)->unpickler;
7502 else if (PyDict_Check(obj)) {
7506 new_memo_size = PyDict_GET_SIZE(obj);
7511 while (PyDict_Next(obj, &i, &key, &value)) {
7533 "or dict, not %.200s", Py_TYPE(obj)->tp_name);
7639 obj: object
7646 Write a pickled representation of obj to the open file object file.
7648 This is equivalent to ``Pickler(file, protocol).dump(obj)``, but may
7676 _pickle_dump_impl(PyObject *module, PyObject *obj, PyObject *file,
7695 if (dump(pickler, obj) < 0)
7713 obj: object
7741 _pickle_dumps_impl(PyObject *module, PyObject *obj, PyObject *protocol,
7757 if (dump(pickler, obj) < 0)