]> granicus.if.org Git - python/commitdiff
Merge of the release22 branch changes back into the trunk.
authorBarry Warsaw <barry@python.org>
Fri, 21 Dec 2001 20:04:22 +0000 (20:04 +0000)
committerBarry Warsaw <barry@python.org>
Fri, 21 Dec 2001 20:04:22 +0000 (20:04 +0000)
Lib/compiler/ast.py
Lib/compiler/pycodegen.py
Lib/compiler/symbols.py
Lib/compiler/transformer.py
Lib/test/test_cpickle.py
Misc/NEWS
Modules/cPickle.c

index 23c463b39895b552baac93f3a9a8177fee0391f8..680afeea23d68ee0ae2a5af047975d9aa597a3a1 100644 (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):
index f526ae18bbe76a3c30dd8fe77328f4eed2a9093a..4194d27e25e7167d2b680ad8a2dc94e68500acda 100644 (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"""
index 200341fa29f8a5f3ebbec470126a1fed7da25f56..cd7bcebe0f83cbaf84ff906701fdcbdf7e0e01f4 100644 (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:
index 987556102facbb71dd690d9b02d6d8452a93d9cb..cd36aaeac9a137bff762f5e5a29ecb45f723f09d 100644 (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
index dda606f3a44643a728f06a8c514770c508f9a31e..874735bfceb9ab1ab267ee671bc5b9bc90672ae4 100644 (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()
index eafe10ea1f1d9971296adb206d00365d7daad66e..323aae74e4b2a27e78b180fcc97484a81dd3b0a3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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
index a4943ce8211eb44f125adb72ef38d05887d7ec80..adf7e4449f0241417ae859cfa7707a44f1358448 100644 (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;