]> granicus.if.org Git - python/commitdiff
Merged revisions 58203-58210 via svnmerge from
authorThomas Wouters <thomas@python.org>
Wed, 19 Sep 2007 21:19:28 +0000 (21:19 +0000)
committerThomas Wouters <thomas@python.org>
Wed, 19 Sep 2007 21:19:28 +0000 (21:19 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r58204 | georg.brandl | 2007-09-19 08:37:19 +0200 (Wed, 19 Sep 2007) | 2 lines

  Fix #1169: remove docstrings in functions for -OO.
........
  r58206 | sean.reifschneider | 2007-09-19 09:52:56 +0200 (Wed, 19 Sep 2007) | 2 lines

  issue1177: Ported Facundo's from urllib2 to urllib, accepting 2xx responses.
........
  r58207 | facundo.batista | 2007-09-19 16:02:03 +0200 (Wed, 19 Sep 2007) | 3 lines

  Annotated the correction to urllib.py, issue #1177
........
  r58208 | facundo.batista | 2007-09-19 17:10:06 +0200 (Wed, 19 Sep 2007) | 7 lines

  Issue #1772851.  Alters long.__hash__ from being *almost* completely
  predictable to being completely predictable.  The value of hash(n)
  is unchanged for any n that's small enough to be representable as an
  int, and also unchanged for the vast majority of long integers n of
  reasonable size.
........
  r58209 | thomas.wouters | 2007-09-19 19:27:29 +0200 (Wed, 19 Sep 2007) | 4 lines

  Fix obvious typo in threaded test.
........
  r58210 | thomas.wouters | 2007-09-19 19:27:43 +0200 (Wed, 19 Sep 2007) | 4 lines

  Whitespace cleanup.
........

Lib/test/test_hash.py
Lib/urllib.py
Objects/longobject.c
Python/ceval.c
Python/compile.c

index eff0c7c5e5370a1d16bfdb8a89177cb300f6ffe9..a0364f2a30783b13d82e2b7d2f7191578221cc76 100644 (file)
@@ -18,10 +18,19 @@ class HashEqualityTestCase(unittest.TestCase):
 
     def test_numeric_literals(self):
         self.same_hash(1, 1, 1.0, 1.0+0.0j)
+        self.same_hash(0, 0.0, 0.0+0.0j)
+        self.same_hash(-1, -1.0, -1.0+0.0j)
+        self.same_hash(-2, -2.0, -2.0+0.0j)
 
     def test_coerced_integers(self):
         self.same_hash(int(1), int(1), float(1), complex(1),
                        int('1'), float('1.0'))
+        self.same_hash(int(-2**31), float(-2**31))
+        self.same_hash(int(1-2**31), float(1-2**31))
+        self.same_hash(int(2**31-1), float(2**31-1))
+        # for 64-bit platforms
+        self.same_hash(int(2**31), float(2**31))
+        self.same_hash(int(-2**63), float(-2**63))
 
     def test_coerced_floats(self):
         self.same_hash(int(1.23e300), float(1.23e300))
index 04fd50a6ca1f69a8dc421b9b9e0a39acff650d59..b2542fce24c88c9237fd620597b7ea3bfe9a94d2 100644 (file)
@@ -357,7 +357,9 @@ class URLopener:
             raise IOError('http protocol error', 0,
                           'got a bad status line', None)
 
-        if response.status == 200:
+        # According to RFC 2616, "2xx" code indicates that the client's
+        # request was successfully received, understood, and accepted.
+        if not (200 <= response.status < 300):
             return addinfourl(response.fp, response.msg, "http:" + url)
         else:
             return self.http_error(
index 1c127baccd3d10fe332f34ee7fb2fe11d17245c5..7f09bb66bade264df961c7f9744f6ea620eb7a42 100644 (file)
@@ -2197,10 +2197,18 @@ long_hash(PyLongObject *v)
                i = -(i);
        }
 #define LONG_BIT_PyLong_SHIFT  (8*sizeof(long) - PyLong_SHIFT)
+       /* The following loop produces a C long x such that (unsigned long)x
+          is congruent to the absolute value of v modulo ULONG_MAX.  The
+          resulting x is nonzero if and only if v is. */
        while (--i >= 0) {
                /* Force a native long #-bits (32 or 64) circular shift */
                x = ((x << PyLong_SHIFT) & ~PyLong_MASK) | ((x >> LONG_BIT_PyLong_SHIFT) & PyLong_MASK);
                x += v->ob_digit[i];
+               /* If the addition above overflowed (thinking of x as
+                  unsigned), we compensate by incrementing.  This preserves
+                  the value modulo ULONG_MAX. */
+               if ((unsigned long)x < v->ob_digit[i])
+                       x++;
        }
 #undef LONG_BIT_PyLong_SHIFT
        x = x * sign;
index fa08fe68403912880f65099fc188a63756c8a275..07e4013aae10940d844cbea8809c9a220fe097fa 100644 (file)
@@ -431,7 +431,7 @@ void
 Py_SetRecursionLimit(int new_limit)
 {
        recursion_limit = new_limit;
-        _Py_CheckRecursionLimit = recursion_limit;
+       _Py_CheckRecursionLimit = recursion_limit;
 }
 
 /* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
@@ -469,7 +469,7 @@ _Py_CheckRecursiveCall(char *where)
                             where);
                return -1;
        }
-        _Py_CheckRecursionLimit = recursion_limit;
+       _Py_CheckRecursionLimit = recursion_limit;
        return 0;
 }
 
@@ -805,11 +805,11 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
                   Py_MakePendingCalls() above. */
 
                if (--_Py_Ticker < 0) {
-                        if (*next_instr == SETUP_FINALLY) {
-                                /* Make the last opcode before
-                                   a try: finally: block uninterruptable. */
-                                goto fast_next_opcode;
-                        }
+                       if (*next_instr == SETUP_FINALLY) {
+                               /* Make the last opcode before
+                                  a try: finally: block uninterruptable. */
+                               goto fast_next_opcode;
+                       }
                        _Py_Ticker = _Py_CheckInterval;
                        tstate->tick_counter++;
 #ifdef WITH_TSC
@@ -2500,7 +2500,7 @@ fast_yield:
        }
 
        /* pop frame */
-    exit_eval_frame:
+exit_eval_frame:
        Py_LeaveRecursiveCall();
        tstate->frame = f->f_back;
 
@@ -2761,9 +2761,9 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
                return PyGen_New(f);
        }
 
-        retval = PyEval_EvalFrameEx(f,0);
+       retval = PyEval_EvalFrameEx(f,0);
 
-  fail: /* Jump here from prelude on failure */
+fail: /* Jump here from prelude on failure */
 
        /* decref'ing the frame can cause __del__ methods to get invoked,
           which can call back into Python.  While we're done with the
@@ -2772,7 +2772,7 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
        */
        assert(tstate != NULL);
        ++tstate->recursion_depth;
-        Py_DECREF(f);
+       Py_DECREF(f);
        --tstate->recursion_depth;
        return retval;
 }
@@ -3186,18 +3186,18 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
            represents a jump backwards, call the trace function.
         */
        if ((frame->f_lasti < *instr_lb || frame->f_lasti >= *instr_ub)) {
-                int line;
-                PyAddrPair bounds;
+               int line;
+               PyAddrPair bounds;
 
-                line = PyCode_CheckLineNumber(frame->f_code, frame->f_lasti,
-                                              &bounds);
-                if (line >= 0) {
+               line = PyCode_CheckLineNumber(frame->f_code, frame->f_lasti,
+                                             &bounds);
+               if (line >= 0) {
                        frame->f_lineno = line;
                        result = call_trace(func, obj, frame,
                                            PyTrace_LINE, Py_None);
-                }
-                *instr_lb = bounds.ap_lower;
-                *instr_ub = bounds.ap_upper;
+               }
+               *instr_lb = bounds.ap_lower;
+               *instr_ub = bounds.ap_upper;
        }
        else if (frame->f_lasti <= *instr_prev) {
                result = call_trace(func, obj, frame, PyTrace_LINE, Py_None);
@@ -3583,9 +3583,9 @@ update_keyword_args(PyObject *orig_kwdict, int nk, PyObject ***pp_stack,
                PyObject *value = EXT_POP(*pp_stack);
                PyObject *key = EXT_POP(*pp_stack);
                if (PyDict_GetItem(kwdict, key) != NULL) {
-                        PyErr_Format(PyExc_TypeError,
-                                     "%.200s%s got multiple values "
-                                     "for keyword argument '%.200s'",
+                       PyErr_Format(PyExc_TypeError,
+                                    "%.200s%s got multiple values "
+                                    "for keyword argument '%.200s'",
                                     PyEval_GetFuncName(func),
                                     PyEval_GetFuncDesc(func),
                                     PyUnicode_AsString(key));
@@ -3763,7 +3763,7 @@ ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
                PCALL(PCALL_OTHER);
 #endif
        result = PyObject_Call(func, callargs, kwdict);
-      ext_call_fail:
+ext_call_fail:
        Py_XDECREF(callargs);
        Py_XDECREF(kwdict);
        Py_XDECREF(stararg);
index e569102f3b54edf4555047eead21889a4dee9ce3..d20da0af84c9f20cb9fc1bd1d9ffd925ebf547db 100644 (file)
@@ -1428,7 +1428,7 @@ compiler_function(struct compiler *c, stmt_ty s)
 
        st = (stmt_ty)asdl_seq_GET(s->v.FunctionDef.body, 0);
        docstring = compiler_isdocstring(st);
-       if (docstring)
+       if (docstring && Py_OptimizeFlag < 2)
            first_const = st->v.Expr.value->v.Str.s;
        if (compiler_add_o(c, c->u->u_consts, first_const) < 0)  {
            compiler_exit_scope(c);