[Python-bugs-list] [ python-Bugs-614555 ] Rewrite _reduce and _reconstructor in C

noreply@sourceforge.net noreply@sourceforge.net
Thu, 14 Nov 2002 08:46:43 -0800


Bugs item #614555, was opened at 2002-09-25 14:15
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=614555&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Guido van Rossum (gvanrossum)
Summary: Rewrite _reduce and _reconstructor in C

Initial Comment:
The copy_reg defines two functions, _reduce() and
_reconstructor(), that are used for the pickling and
unpickling of new-style classes. These were originally
written in Python because the right implementation
wasn't entirely clear; _reduce() is actually called
from a C-level __reduce__ method defined in 'object',
and it references _reconstructor() in its return tuple.
It is now time to move both back into C for efficiency.


----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-11-14 11:46

Message:
Logged In: YES 
user_id=6380

I'd like to add some comments from Jim Fulton on this (or a
related) issue so they don't get lost.

"""
I still need to think of a good way to handle this. 
Currently, the pattern is a reduce return value of the form:

   reconstructor, (some_class, object, None), some_state

but there is a more general case where an uninitialized
object can be gotten by calling "type.__new__(some_class)",
or even: "some_class.__new__(some_class)".

There are really two issues:

- It's too hard to write __reduce__ functions for this case, and

- Too much data needs to be stored in pickles.

A new pickling code would handler the later, but I also want
to solve the former problem.

One thought is to return: (copy_reg.new, (some_class, ),
some_state) where copy_reg.new is:

   def new(class_): return class.__new__(class_)

The pickler could easily spot reduce returns with
copy_reg.new as the first value and generate a special
pickle code.
"""


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=614555&group_id=5470