Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce272b6

Browse files
committed
Merged revisions 58203-58210 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent 796d0b2 commit ce272b6

5 files changed

Lines changed: 44 additions & 25 deletions

File tree

Lib/test/test_hash.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,19 @@ def same_hash(self, *objlist):
1818

1919
def test_numeric_literals(self):
2020
self.same_hash(1, 1, 1.0, 1.0+0.0j)
21+
self.same_hash(0, 0.0, 0.0+0.0j)
22+
self.same_hash(-1, -1.0, -1.0+0.0j)
23+
self.same_hash(-2, -2.0, -2.0+0.0j)
2124

2225
def test_coerced_integers(self):
2326
self.same_hash(int(1), int(1), float(1), complex(1),
2427
int('1'), float('1.0'))
28+
self.same_hash(int(-2**31), float(-2**31))
29+
self.same_hash(int(1-2**31), float(1-2**31))
30+
self.same_hash(int(2**31-1), float(2**31-1))
31+
# for 64-bit platforms
32+
self.same_hash(int(2**31), float(2**31))
33+
self.same_hash(int(-2**63), float(-2**63))
2534

2635
def test_coerced_floats(self):
2736
self.same_hash(int(1.23e300), float(1.23e300))

Lib/urllib.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ def _open_generic_http(self, connection_factory, url, data):
357357
raise IOError('http protocol error', 0,
358358
'got a bad status line', None)
359359

360-
if response.status == 200:
360+
# According to RFC 2616, "2xx" code indicates that the client's
361+
# request was successfully received, understood, and accepted.
362+
if not (200 <= response.status < 300):
361363
return addinfourl(response.fp, response.msg, "http:" + url)
362364
else:
363365
return self.http_error(

Objects/longobject.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,10 +2197,18 @@ long_hash(PyLongObject *v)
21972197
i = -(i);
21982198
}
21992199
#define LONG_BIT_PyLong_SHIFT (8*sizeof(long) - PyLong_SHIFT)
2200+
/* The following loop produces a C long x such that (unsigned long)x
2201+
is congruent to the absolute value of v modulo ULONG_MAX. The
2202+
resulting x is nonzero if and only if v is. */
22002203
while (--i >= 0) {
22012204
/* Force a native long #-bits (32 or 64) circular shift */
22022205
x = ((x << PyLong_SHIFT) & ~PyLong_MASK) | ((x >> LONG_BIT_PyLong_SHIFT) & PyLong_MASK);
22032206
x += v->ob_digit[i];
2207+
/* If the addition above overflowed (thinking of x as
2208+
unsigned), we compensate by incrementing. This preserves
2209+
the value modulo ULONG_MAX. */
2210+
if ((unsigned long)x < v->ob_digit[i])
2211+
x++;
22042212
}
22052213
#undef LONG_BIT_PyLong_SHIFT
22062214
x = x * sign;

Python/ceval.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ void
431431
Py_SetRecursionLimit(int new_limit)
432432
{
433433
recursion_limit = new_limit;
434-
_Py_CheckRecursionLimit = recursion_limit;
434+
_Py_CheckRecursionLimit = recursion_limit;
435435
}
436436

437437
/* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
@@ -469,7 +469,7 @@ _Py_CheckRecursiveCall(char *where)
469469
where);
470470
return -1;
471471
}
472-
_Py_CheckRecursionLimit = recursion_limit;
472+
_Py_CheckRecursionLimit = recursion_limit;
473473
return 0;
474474
}
475475

@@ -805,11 +805,11 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
805805
Py_MakePendingCalls() above. */
806806

807807
if (--_Py_Ticker < 0) {
808-
if (*next_instr == SETUP_FINALLY) {
809-
/* Make the last opcode before
810-
a try: finally: block uninterruptable. */
811-
goto fast_next_opcode;
812-
}
808+
if (*next_instr == SETUP_FINALLY) {
809+
/* Make the last opcode before
810+
a try: finally: block uninterruptable. */
811+
goto fast_next_opcode;
812+
}
813813
_Py_Ticker = _Py_CheckInterval;
814814
tstate->tick_counter++;
815815
#ifdef WITH_TSC
@@ -2500,7 +2500,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
25002500
}
25012501

25022502
/* pop frame */
2503-
exit_eval_frame:
2503+
exit_eval_frame:
25042504
Py_LeaveRecursiveCall();
25052505
tstate->frame = f->f_back;
25062506

@@ -2761,9 +2761,9 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
27612761
return PyGen_New(f);
27622762
}
27632763

2764-
retval = PyEval_EvalFrameEx(f,0);
2764+
retval = PyEval_EvalFrameEx(f,0);
27652765

2766-
fail: /* Jump here from prelude on failure */
2766+
fail: /* Jump here from prelude on failure */
27672767

27682768
/* decref'ing the frame can cause __del__ methods to get invoked,
27692769
which can call back into Python. While we're done with the
@@ -2772,7 +2772,7 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
27722772
*/
27732773
assert(tstate != NULL);
27742774
++tstate->recursion_depth;
2775-
Py_DECREF(f);
2775+
Py_DECREF(f);
27762776
--tstate->recursion_depth;
27772777
return retval;
27782778
}
@@ -3186,18 +3186,18 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
31863186
represents a jump backwards, call the trace function.
31873187
*/
31883188
if ((frame->f_lasti < *instr_lb || frame->f_lasti >= *instr_ub)) {
3189-
int line;
3190-
PyAddrPair bounds;
3189+
int line;
3190+
PyAddrPair bounds;
31913191

3192-
line = PyCode_CheckLineNumber(frame->f_code, frame->f_lasti,
3193-
&bounds);
3194-
if (line >= 0) {
3192+
line = PyCode_CheckLineNumber(frame->f_code, frame->f_lasti,
3193+
&bounds);
3194+
if (line >= 0) {
31953195
frame->f_lineno = line;
31963196
result = call_trace(func, obj, frame,
31973197
PyTrace_LINE, Py_None);
3198-
}
3199-
*instr_lb = bounds.ap_lower;
3200-
*instr_ub = bounds.ap_upper;
3198+
}
3199+
*instr_lb = bounds.ap_lower;
3200+
*instr_ub = bounds.ap_upper;
32013201
}
32023202
else if (frame->f_lasti <= *instr_prev) {
32033203
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,
35833583
PyObject *value = EXT_POP(*pp_stack);
35843584
PyObject *key = EXT_POP(*pp_stack);
35853585
if (PyDict_GetItem(kwdict, key) != NULL) {
3586-
PyErr_Format(PyExc_TypeError,
3587-
"%.200s%s got multiple values "
3588-
"for keyword argument '%.200s'",
3586+
PyErr_Format(PyExc_TypeError,
3587+
"%.200s%s got multiple values "
3588+
"for keyword argument '%.200s'",
35893589
PyEval_GetFuncName(func),
35903590
PyEval_GetFuncDesc(func),
35913591
PyUnicode_AsString(key));
@@ -3763,7 +3763,7 @@ ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
37633763
PCALL(PCALL_OTHER);
37643764
#endif
37653765
result = PyObject_Call(func, callargs, kwdict);
3766-
ext_call_fail:
3766+
ext_call_fail:
37673767
Py_XDECREF(callargs);
37683768
Py_XDECREF(kwdict);
37693769
Py_XDECREF(stararg);

Python/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ compiler_function(struct compiler *c, stmt_ty s)
14281428

14291429
st = (stmt_ty)asdl_seq_GET(s->v.FunctionDef.body, 0);
14301430
docstring = compiler_isdocstring(st);
1431-
if (docstring)
1431+
if (docstring && Py_OptimizeFlag < 2)
14321432
first_const = st->v.Expr.value->v.Str.s;
14331433
if (compiler_add_o(c, c->u->u_consts, first_const) < 0) {
14341434
compiler_exit_scope(c);

0 commit comments

Comments
 (0)