]> granicus.if.org Git - python/commitdiff
Merged revisions 60210-60233 via svnmerge from
authorChristian Heimes <christian@cheimes.de>
Thu, 24 Jan 2008 09:42:52 +0000 (09:42 +0000)
committerChristian Heimes <christian@cheimes.de>
Thu, 24 Jan 2008 09:42:52 +0000 (09:42 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r60213 | christian.heimes | 2008-01-23 15:00:25 +0100 (Wed, 23 Jan 2008) | 1 line

  Use Py_TYPE() instead of ->ob_type
........
  r60214 | armin.rigo | 2008-01-23 15:07:13 +0100 (Wed, 23 Jan 2008) | 3 lines

  patch 1754489 by vlahan:
  improve portability of address length calculation for AF_UNIX sockets
........
  r60216 | christian.heimes | 2008-01-23 15:20:50 +0100 (Wed, 23 Jan 2008) | 1 line

  Fixed bug #1915: Python compiles with --enable-unicode=no again. However several extension methods and modules do not work without unicode support.
........
  r60221 | christian.heimes | 2008-01-23 18:15:06 +0100 (Wed, 23 Jan 2008) | 2 lines

  Applied #1069410
  The "can't load dll" message box on Windows is suppressed while an extension is loaded by calling SetErrorMode in dynload_win.c. The error is still reported properly.
........
  r60224 | guido.van.rossum | 2008-01-23 21:19:01 +0100 (Wed, 23 Jan 2008) | 2 lines

  Fix two crashers.
........
  r60225 | kurt.kaiser | 2008-01-23 23:19:23 +0100 (Wed, 23 Jan 2008) | 3 lines

  Could not open files in .idlerc directory if latter was hidden on Windows.
  Issue 1743, Issue 1862.
........
  r60226 | guido.van.rossum | 2008-01-23 23:43:27 +0100 (Wed, 23 Jan 2008) | 2 lines

  Fix misleading comment reported in issue #1917.
........
  r60227 | kurt.kaiser | 2008-01-23 23:55:26 +0100 (Wed, 23 Jan 2008) | 2 lines

  There was an error on exit if no sys.exitfunc was defined. Issue 1647.
........
  r60228 | guido.van.rossum | 2008-01-24 00:23:43 +0100 (Thu, 24 Jan 2008) | 2 lines

  Turn three recently fixed crashers into regular tests.
........
  r60229 | raymond.hettinger | 2008-01-24 01:54:21 +0100 (Thu, 24 Jan 2008) | 1 line

  Add first-cut at an approximation function (still needs rounding tweaks).  Add continued fraction conversions.
........
  r60230 | raymond.hettinger | 2008-01-24 03:00:25 +0100 (Thu, 24 Jan 2008) | 1 line

  Minor clean-up and more tests.
........
  r60231 | raymond.hettinger | 2008-01-24 03:05:06 +0100 (Thu, 24 Jan 2008) | 1 line

  Cleanup
........
  r60232 | neal.norwitz | 2008-01-24 05:14:50 +0100 (Thu, 24 Jan 2008) | 1 line

  Fix the tests by restoring __import__.  I think the test is still valid.
........
  r60233 | neal.norwitz | 2008-01-24 08:40:51 +0100 (Thu, 24 Jan 2008) | 4 lines

  Fix the test_urllib2net failures that were caused by r58067.
  I'm not sure this is the correct fix, but at least the test passes
  now and should be closer to correct.
........

Lib/idlelib/NEWS.txt
Lib/idlelib/configHandler.py
Lib/rational.py
Lib/test/test_descr.py
Lib/test/test_rational.py
Lib/urllib2.py
Modules/config.c.in
Modules/socketmodule.c
Python/bltinmodule.c
Python/ceval.c
Python/dynload_win.c

index 12a0c6f726eea58051c5952e840d1ac2e107b061..d51d94e20204b13dec14a837e0eb8eba0cf28188 100644 (file)
@@ -45,6 +45,11 @@ What's New in IDLE 2.6a1?
 
 *Release date: XX-XXX-200X*  UNRELEASED, but merged into 3.0
 
+- There was an error on exit if no sys.exitfunc was defined. Issue 1647.
+
+- Could not open files in .idlerc directory if latter was hidden on Windows.
+  Issue 1743, Issue 1862.
+
 - Configure Dialog: improved layout for keybinding.  Patch 1457 Tal Einat.
 
 - tabpage.py updated: tabbedPages.py now supports multiple dynamic rows
index b5d976900d763bb3c268d5a1948d8aafb0d81b72..66bad74bf0b3046f6ece13e14d6f0edd1b35e9f4 100644 (file)
@@ -139,7 +139,12 @@ class IdleUserConfParser(IdleConfParser):
 
         """
         if not self.IsEmpty():
-            cfgFile=open(self.file,'w')
+            fname = self.file
+            try:
+                cfgFile = open(fname, 'w')
+            except IOError:
+                fname.unlink()
+                cfgFile = open(fname, 'w')
             self.write(cfgFile)
         else:
             self.RemoveFile()
index 71ffff750fd41b6b643f8bba9499292a142b831f..4a56cf20fa939165ee81fdfe3d5e7a97cf272bc9 100755 (executable)
@@ -171,6 +171,42 @@ class Rational(RationalAbc):
         else:
             return cls(digits, 10 ** -exp)
 
+    @classmethod
+    def from_continued_fraction(cls, seq):
+        'Build a Rational from a continued fraction expessed as a sequence'
+        n, d = 1, 0
+        for e in reversed(seq):
+            n, d = d, n
+            n += e * d
+        return cls(n, d) if seq else cls(0)
+
+    def as_continued_fraction(self):
+        'Return continued fraction expressed as a list'
+        n = self.numerator
+        d = self.denominator
+        cf = []
+        while d:
+            e = int(n // d)
+            cf.append(e)
+            n -= e * d
+            n, d = d, n
+        return cf
+
+    @classmethod
+    def approximate_from_float(cls, f, max_denominator):
+        'Best rational approximation to f with a denominator <= max_denominator'
+        # XXX First cut at algorithm
+        # Still needs rounding rules as specified at
+        #       http://en.wikipedia.org/wiki/Continued_fraction
+        cf = cls.from_float(f).as_continued_fraction()
+        result = Rational(0)
+        for i in range(1, len(cf)):
+            new = cls.from_continued_fraction(cf[:i])
+            if new.denominator > max_denominator:
+                break
+            result = new
+        return result
+
     @property
     def numerator(a):
         return a._numerator
index 8ccece1e833ed282f1f268c0d90bfa0e3bc81909..7ef702b1f89375168dc6470a0ef1446e075a9df8 100644 (file)
@@ -1,7 +1,7 @@
 # Test enhancements related to descriptors and new-style classes
 
-from test.test_support import verify, vereq, verbose, TestFailed, TESTFN
-from test.test_support import get_original_stdout
+# XXX Please, please, please, someone convert this to unittest style!
+from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout
 from copy import deepcopy
 import types
 
@@ -4173,6 +4173,8 @@ def test_assign_slice():
     # ceval.c's assign_slice used to check for
     # tp->tp_as_sequence->sq_slice instead of
     # tp->tp_as_sequence->sq_ass_slice
+    if verbose:
+        print("Testing assign_slice...")
 
     class C(object):
         def __setitem__(self, idx, value):
@@ -4182,8 +4184,72 @@ def test_assign_slice():
     c[1:2] = 3
     vereq(c.value, 3)
 
+def test_weakref_in_del_segfault():
+    # This used to segfault until r60057
+    if verbose:
+        print("Testing weakref in del segfault...")
+
+    import weakref
+    global ref
+
+    class Target():
+        def __del__(self):
+            global ref
+            ref = weakref.ref(self)
+
+    w = Target()
+    del w
+    del ref
+
+def test_borrowed_ref_3_segfault():
+    # This used to segfault until r60224
+    if verbose:
+        print("Testing borrowed ref 3 segfault...")
+
+    class KeyFunc(object):
+        def __call__(self, n):
+            del d['key']
+            return 1
+
+    d = {'key': KeyFunc()}
+    try:
+        min(range(10), **d)
+    except:
+        pass
+
+def test_borrowed_ref_4_segfault():
+    # This used to segfault until r60224
+    if verbose:
+        print("Testing borrowed ref 4 segfault...")
+
+    import types
+    import builtins
+
+    class X(object):
+        def __getattr__(self, name):
+            # this is called with name == '__bases__' by PyObject_IsInstance()
+            # during the unbound method call -- it frees the unbound method
+            # itself before it invokes its im_func.
+            del builtins.__import__
+            return ()
+
+    pseudoclass = X()
+
+    class Y(object):
+        def __call__(self, *args):
+            # 'self' was freed already
+            return (self, args)
+
+    # make an unbound method
+    orig_import = __import__
+    try:
+        builtins.__import__ = types.MethodType(Y(), (pseudoclass, str))
+        import spam
+    finally:
+        builtins.__import__ = orig_import
+
 def test_main():
-    weakref_segfault() # Must be first, somehow
+    #XXXweakref_segfault() # Must be first, somehow
     wrapper_segfault() # NB This one is slow
     do_this_first()
     class_docstrings()
@@ -4279,6 +4345,9 @@ def test_main():
     methodwrapper()
     notimplemented()
     test_assign_slice()
+    test_weakref_in_del_segfault()
+    test_borrowed_ref_3_segfault()
+    test_borrowed_ref_4_segfault()
 
     if verbose: print("All OK")
 
index e57adce1dcff765f187ea6d7730a40db13798df7..1bd18142c6be80f10ced2d18377c85918024103d 100644 (file)
@@ -135,6 +135,29 @@ class RationalTest(unittest.TestCase):
             TypeError, "Cannot convert sNaN to Rational.",
             R.from_decimal, Decimal("snan"))
 
+    def testFromContinuedFraction(self):
+        self.assertRaises(TypeError, R.from_continued_fraction, None)
+        phi = R.from_continued_fraction([1]*100)
+        self.assertEquals(round(phi - (1 + 5 ** 0.5) / 2, 10), 0.0)
+
+        minusphi = R.from_continued_fraction([-1]*100)
+        self.assertEquals(round(minusphi + (1 + 5 ** 0.5) / 2, 10), 0.0)
+
+        self.assertEquals(R.from_continued_fraction([0]), R(0))
+        self.assertEquals(R.from_continued_fraction([]), R(0))
+
+    def testAsContinuedFraction(self):
+        self.assertEqual(R.from_float(math.pi).as_continued_fraction()[:15],
+                         [3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 3, 3])
+        self.assertEqual(R.from_float(-math.pi).as_continued_fraction()[:16],
+                         [-4, 1, 6, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 3, 3])
+        self.assertEqual(R(0).as_continued_fraction(), [0])
+
+    def testApproximateFromFloat(self):
+        self.assertEqual(R.approximate_from_float(math.pi, 10000), R(355, 113))
+        self.assertEqual(R.approximate_from_float(-math.pi, 10000), R(-355, 113))
+        self.assertEqual(R.approximate_from_float(0.0, 10000), R(0))
+
     def testConversions(self):
         self.assertTypedEquals(-1, trunc(R(-11, 10)))
         self.assertTypedEquals(-2, math.floor(R(-11, 10)))
index fb2c3033bdc3dd2748b22174d147e3943128ca52..3ad0b156227487b00c594041454c713b5f395e06 100644 (file)
@@ -1286,7 +1286,7 @@ class FTPHandler(BaseHandler):
             headers = mimetools.Message(sf)
             return addinfourl(fp, headers, req.get_full_url())
         except ftplib.all_errors as msg:
-            raise URLError('ftp error %s' % msg).with_traceback(sys.exc_info()[2])
+            raise URLError('ftp error: %s' % msg).with_traceback(sys.exc_info()[2])
 
     def connect_ftp(self, user, passwd, host, port, dirs, timeout):
         fw = ftpwrapper(user, passwd, host, port, dirs, timeout)
index 0531fab6bb039485c82065032ba49f10ee9cb8a1..a5658f58a6a385b2b4dc9ba0beffac668e41a943 100644 (file)
@@ -43,7 +43,7 @@ struct _inittab _PyImport_Inittab[] = {
        /* This lives in Python/Python-ast.c */
        {"_ast", init_ast},
 
-       /* This lives in Python/_types.c */
+       /* This lives in Modules/_typesmodule.c */
        {"_types", init_types},
 
        /* These entries are here for sys.builtin_module_names */
index 5eb5a1e3e8e5b1f59384875da08c8d4bc6314730..aed8bb81f6c22a3826f1188de1cb31fc82335f6e 100644 (file)
@@ -966,7 +966,7 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
                struct sockaddr_un *a = (struct sockaddr_un *) addr;
 #ifdef linux
                if (a->sun_path[0] == 0) {  /* Linux abstract namespace */
-                       addrlen -= (sizeof(*a) - sizeof(a->sun_path));
+                       addrlen -= offsetof(struct sockaddr_un, sun_path);
                        return PyString_FromStringAndSize(a->sun_path, addrlen);
                }
                else
@@ -1171,7 +1171,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
 #if defined(PYOS_OS2)
                *len_ret = sizeof(*addr);
 #else
-               *len_ret = len + sizeof(*addr) - sizeof(addr->sun_path);
+               *len_ret = len + offsetof(struct sockaddr_un, sun_path);
 #endif
                return 1;
        }
index a5b97163de1eb334e84ac473ec687c13ec73822d..2a0376a95d1f80cf5833fe545fb18fc6bd8b2160 100644 (file)
@@ -1008,11 +1008,14 @@ min_max(PyObject *args, PyObject *kwds, int op)
                                "%s() got an unexpected keyword argument", name);
                        return NULL;
                }
+               Py_INCREF(keyfunc);
        }
 
        it = PyObject_GetIter(v);
-       if (it == NULL)
+       if (it == NULL) {
+               Py_XDECREF(keyfunc);
                return NULL;
+       }
 
        maxitem = NULL; /* the result */
        maxval = NULL;  /* the value associated with the result */
@@ -1061,6 +1064,7 @@ min_max(PyObject *args, PyObject *kwds, int op)
        else
                Py_DECREF(maxval);
        Py_DECREF(it);
+       Py_XDECREF(keyfunc);
        return maxitem;
 
 Fail_it_item_and_val:
@@ -1071,6 +1075,7 @@ Fail_it:
        Py_XDECREF(maxval);
        Py_XDECREF(maxitem);
        Py_DECREF(it);
+       Py_XDECREF(keyfunc);
        return NULL;
 }
 
index 778bbe022367ca4ace1151810e5398b4f48d8323..10f2db4808c8c33b28fde02738a7e922af4680a9 100644 (file)
@@ -1833,6 +1833,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
                                                "__import__ not found");
                                break;
                        }
+                       Py_INCREF(x);
                        v = POP();
                        u = TOP();
                        if (PyLong_AsLong(u) != -1 || PyErr_Occurred())
@@ -1854,11 +1855,14 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
                        Py_DECREF(u);
                        if (w == NULL) {
                                u = POP();
+                               Py_DECREF(x);
                                x = NULL;
                                break;
                        }
                        READ_TIMESTAMP(intr0);
-                       x = PyEval_CallObject(x, w);
+                       v = x;
+                       x = PyEval_CallObject(v, w);
+                       Py_DECREF(v);
                        READ_TIMESTAMP(intr1);
                        Py_DECREF(w);
                        SET_TOP(x);
index 39c091b39a819654be3241c5a8f1ab6629e5e1b6..4db12c48c7966265c52357d89635d2c6a69e8ca0 100644 (file)
@@ -171,11 +171,16 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
                HINSTANCE hDLL = NULL;
                char pathbuf[260];
                LPTSTR dummy;
+               unsigned int old_mode;
                /* We use LoadLibraryEx so Windows looks for dependent DLLs 
                    in directory of pathname first.  However, Windows95
                    can sometimes not work correctly unless the absolute
                    path is used.  If GetFullPathName() fails, the LoadLibrary
                    will certainly fail too, so use its error code */
+
+               /* Don't display a message box when Python can't load a DLL */
+               old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
+
                if (GetFullPathName(pathname,
                                    sizeof(pathbuf),
                                    pathbuf,
@@ -183,6 +188,10 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
                        /* XXX This call doesn't exist in Windows CE */
                        hDLL = LoadLibraryEx(pathname, NULL,
                                             LOAD_WITH_ALTERED_SEARCH_PATH);
+
+               /* restore old error mode settings */
+               SetErrorMode(old_mode);
+
                if (hDLL==NULL){
                        PyObject *message;
                        unsigned int errorCode;