Merge of the release22 branch changes back into the trunk.

This commit is contained in:
Barry Warsaw 2001-12-21 20:04:22 +00:00
parent 87fa3aa12c
commit 52acb49298
7 changed files with 80 additions and 7 deletions

View File

@ -282,6 +282,21 @@ class Module(Node):
def __repr__(self):
return "Module(%s, %s)" % (repr(self.doc), repr(self.node))
class Expression(Node):
# Expression is an artifical node class to support "eval"
nodes["expression"] = "Expression"
def __init__(self, node):
self.node = node
def getChildren(self):
return self.node,
def getChildNodes(self):
return self.node,
def __repr__(self):
return "Expression(%s)" % (repr(self.node))
class UnaryAdd(Node):
nodes["unaryadd"] = "UnaryAdd"
def __init__(self, expr):

View File

@ -34,6 +34,7 @@ EXCEPT = 2
TRY_FINALLY = 3
END_FINALLY = 4
# XXX this doesn't seem to be used
class BlockStack(misc.Stack):
__super_init = misc.Stack.__init__
@ -351,6 +352,13 @@ class CodeGenerator:
self.emit('LOAD_CONST', None)
self.emit('RETURN_VALUE')
def visitExpression(self, node):
self.set_lineno(node)
self.scopes = self.parseSymbols(node)
self.scope = self.scopes[node]
self.visit(node.node)
self.emit('RETURN_VALUE')
def visitFunction(self, node):
self._visitFuncOrLambda(node, isLambda=0)
if node.doc:
@ -1158,9 +1166,7 @@ class ExpressionCodeGenerator(NestedScopeMixin, CodeGenerator):
def __init__(self, tree):
self.graph = pyassem.PyFlowGraph("<expression>", tree.filename)
self.__super_init()
self.set_lineno(tree)
walk(tree, self)
self.emit('RETURN_VALUE')
def get_module(self):
return self
@ -1181,6 +1187,7 @@ class InteractiveCodeGenerator(NestedScopeMixin, CodeGenerator):
def get_module(self):
return self
def visitDiscard(self, node):
# XXX Discard means it's an expression. Perhaps this is a bad
# name.
@ -1299,7 +1306,6 @@ class ClassCodeGenerator(NestedScopeMixin, AbstractClassCode, CodeGenerator):
self.__super_init(klass, scopes, module)
self.graph.setFreeVars(self.scope.get_free_vars())
self.graph.setCellVars(self.scope.get_cell_vars())
## self.graph.setFlag(CO_NESTED)
def generateArgList(arglist):
"""Generate an arg list marking TupleArgs"""

View File

@ -206,6 +206,8 @@ class SymbolVisitor:
scope = self.module = self.scopes[node] = ModuleScope()
self.visit(node.node, scope)
visitExpression = visitModule
def visitFunction(self, node, parent):
parent.add_def(node.name)
for n in node.defaults:

View File

@ -172,7 +172,7 @@ class Transformer:
def eval_input(self, nodelist):
# from the built-in function input()
### is this sufficient?
return self.com_node(nodelist[0])
return Expression(self.com_node(nodelist[0]))
def funcdef(self, nodelist):
# funcdef: 'def' NAME parameters ':' suite

View File

@ -80,6 +80,13 @@ class cPickleFastPicklerTests(AbstractPickleTests):
AbstractPickleTests.test_recursive_multi,
self)
def test_nonrecursive_deep(self):
a = []
for i in range(100):
a = [a]
b = self.loads(self.dumps(a))
self.assertEqual(a, b)
def test_main():
loader = unittest.TestLoader()
suite = unittest.TestSuite()

View File

@ -4,12 +4,38 @@ Release date: 21-Dec-2001
Type/class unification and new-style classes
- pickle.py, cPickle: allow pickling instances of new-style classes
with a custom metaclass.
Core and builtins
- weakref proxy object: when comparing, unwrap both arguments if both
are proxies.
Extension modules
- binascii.b2a_base64(): fix a potential buffer overrun when encoding
very short strings.
- cPickle: the obscure "fast" mode was suspected of causing stack
overflows on the Mac. Hopefully fixed this by setting the recursion
limit much smaller. If the limit is too low (it only affects
performance), you can change it by defining PY_CPICKLE_FAST_LIMIT
when compiling cPickle.c (or in pyconfig.h).
Library
- dumbdbm.py: fixed a dumb old bug (the file didn't get synched at
close or delete time).
- rfc822.py: fixed a bug where the address '<>' was converted to None
instead of an empty string (also fixes the email.Utils module).
- xmlrpclib.py: version 1.0.0; uses precision for doubles.
- test suite: the pickle and cPickle tests were not executing any code
when run from the standard regresssion test.
Tools/Demos
Build
@ -22,8 +48,23 @@ Tests
Windows
- distutils package: fixed broken Windows installers (bdist_wininst).
- tempfile.py: prevent mysterious warnings when TemporaryFileWrapper
instances are deleted at process exit time.
- socket.py: prevent mysterious warnings when socket instances are
deleted at process exit time.
- posixmodule.c: fix a Windows crash with stat() of a filename ending
in backslash.
Mac
- The Carbon toolbox modules have been upgraded to Universal Headers
3.4, and experimental CoreGraphics and CarbonEvents modules have
been added. All only for framework-enabled MacOSX.
What's New in Python 2.2c1?
Release date: 14-Dec-2001

View File

@ -321,7 +321,9 @@ typedef struct Picklerobject {
PyObject *fast_memo;
} Picklerobject;
#define FAST_LIMIT 2000
#ifndef PY_CPICKLE_FAST_LIMIT
#define PY_CPICKLE_FAST_LIMIT 50
#endif
staticforward PyTypeObject Picklertype;
@ -891,7 +893,7 @@ static int
fast_save_enter(Picklerobject *self, PyObject *obj)
{
/* if fast_container < 0, we're doing an error exit. */
if (++self->fast_container >= FAST_LIMIT) {
if (++self->fast_container >= PY_CPICKLE_FAST_LIMIT) {
PyObject *key = NULL;
if (self->fast_memo == NULL) {
self->fast_memo = PyDict_New();
@ -921,7 +923,7 @@ fast_save_enter(Picklerobject *self, PyObject *obj)
int
fast_save_leave(Picklerobject *self, PyObject *obj)
{
if (self->fast_container-- >= FAST_LIMIT) {
if (self->fast_container-- >= PY_CPICKLE_FAST_LIMIT) {
PyObject *key = PyLong_FromVoidPtr(obj);
if (key == NULL)
return 0;