Skip to content

Commit 5cfffbd

Browse files
author
christian.heimes
committed
Merged revisions 60210-60233 via svnmerge from
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. ........ git-svn-id: http://svn.python.org/projects/python/branches/py3k@60235 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 21a9bd1 commit 5cfffbd

11 files changed

Lines changed: 166 additions & 10 deletions

File tree

Lib/idlelib/NEWS.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ What's New in IDLE 2.6a1?
4545

4646
*Release date: XX-XXX-200X* UNRELEASED, but merged into 3.0
4747

48+
- There was an error on exit if no sys.exitfunc was defined. Issue 1647.
49+
50+
- Could not open files in .idlerc directory if latter was hidden on Windows.
51+
Issue 1743, Issue 1862.
52+
4853
- Configure Dialog: improved layout for keybinding. Patch 1457 Tal Einat.
4954

5055
- tabpage.py updated: tabbedPages.py now supports multiple dynamic rows

Lib/idlelib/configHandler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ def Save(self):
139139
140140
"""
141141
if not self.IsEmpty():
142-
cfgFile=open(self.file,'w')
142+
fname = self.file
143+
try:
144+
cfgFile = open(fname, 'w')
145+
except IOError:
146+
fname.unlink()
147+
cfgFile = open(fname, 'w')
143148
self.write(cfgFile)
144149
else:
145150
self.RemoveFile()

Lib/rational.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,42 @@ def from_decimal(cls, dec):
171171
else:
172172
return cls(digits, 10 ** -exp)
173173

174+
@classmethod
175+
def from_continued_fraction(cls, seq):
176+
'Build a Rational from a continued fraction expessed as a sequence'
177+
n, d = 1, 0
178+
for e in reversed(seq):
179+
n, d = d, n
180+
n += e * d
181+
return cls(n, d) if seq else cls(0)
182+
183+
def as_continued_fraction(self):
184+
'Return continued fraction expressed as a list'
185+
n = self.numerator
186+
d = self.denominator
187+
cf = []
188+
while d:
189+
e = int(n // d)
190+
cf.append(e)
191+
n -= e * d
192+
n, d = d, n
193+
return cf
194+
195+
@classmethod
196+
def approximate_from_float(cls, f, max_denominator):
197+
'Best rational approximation to f with a denominator <= max_denominator'
198+
# XXX First cut at algorithm
199+
# Still needs rounding rules as specified at
200+
# http://en.wikipedia.org/wiki/Continued_fraction
201+
cf = cls.from_float(f).as_continued_fraction()
202+
result = Rational(0)
203+
for i in range(1, len(cf)):
204+
new = cls.from_continued_fraction(cf[:i])
205+
if new.denominator > max_denominator:
206+
break
207+
result = new
208+
return result
209+
174210
@property
175211
def numerator(a):
176212
return a._numerator

Lib/test/test_descr.py

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Test enhancements related to descriptors and new-style classes
22

3-
from test.test_support import verify, vereq, verbose, TestFailed, TESTFN
4-
from test.test_support import get_original_stdout
3+
# XXX Please, please, please, someone convert this to unittest style!
4+
from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout
55
from copy import deepcopy
66
import types
77

@@ -4173,6 +4173,8 @@ def test_assign_slice():
41734173
# ceval.c's assign_slice used to check for
41744174
# tp->tp_as_sequence->sq_slice instead of
41754175
# tp->tp_as_sequence->sq_ass_slice
4176+
if verbose:
4177+
print("Testing assign_slice...")
41764178

41774179
class C(object):
41784180
def __setitem__(self, idx, value):
@@ -4182,8 +4184,72 @@ def __setitem__(self, idx, value):
41824184
c[1:2] = 3
41834185
vereq(c.value, 3)
41844186

4187+
def test_weakref_in_del_segfault():
4188+
# This used to segfault until r60057
4189+
if verbose:
4190+
print("Testing weakref in del segfault...")
4191+
4192+
import weakref
4193+
global ref
4194+
4195+
class Target():
4196+
def __del__(self):
4197+
global ref
4198+
ref = weakref.ref(self)
4199+
4200+
w = Target()
4201+
del w
4202+
del ref
4203+
4204+
def test_borrowed_ref_3_segfault():
4205+
# This used to segfault until r60224
4206+
if verbose:
4207+
print("Testing borrowed ref 3 segfault...")
4208+
4209+
class KeyFunc(object):
4210+
def __call__(self, n):
4211+
del d['key']
4212+
return 1
4213+
4214+
d = {'key': KeyFunc()}
4215+
try:
4216+
min(range(10), **d)
4217+
except:
4218+
pass
4219+
4220+
def test_borrowed_ref_4_segfault():
4221+
# This used to segfault until r60224
4222+
if verbose:
4223+
print("Testing borrowed ref 4 segfault...")
4224+
4225+
import types
4226+
import builtins
4227+
4228+
class X(object):
4229+
def __getattr__(self, name):
4230+
# this is called with name == '__bases__' by PyObject_IsInstance()
4231+
# during the unbound method call -- it frees the unbound method
4232+
# itself before it invokes its im_func.
4233+
del builtins.__import__
4234+
return ()
4235+
4236+
pseudoclass = X()
4237+
4238+
class Y(object):
4239+
def __call__(self, *args):
4240+
# 'self' was freed already
4241+
return (self, args)
4242+
4243+
# make an unbound method
4244+
orig_import = __import__
4245+
try:
4246+
builtins.__import__ = types.MethodType(Y(), (pseudoclass, str))
4247+
import spam
4248+
finally:
4249+
builtins.__import__ = orig_import
4250+
41854251
def test_main():
4186-
weakref_segfault() # Must be first, somehow
4252+
#XXXweakref_segfault() # Must be first, somehow
41874253
wrapper_segfault() # NB This one is slow
41884254
do_this_first()
41894255
class_docstrings()
@@ -4279,6 +4345,9 @@ def test_main():
42794345
methodwrapper()
42804346
notimplemented()
42814347
test_assign_slice()
4348+
test_weakref_in_del_segfault()
4349+
test_borrowed_ref_3_segfault()
4350+
test_borrowed_ref_4_segfault()
42824351

42834352
if verbose: print("All OK")
42844353

Lib/test/test_rational.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,29 @@ def testFromDecimal(self):
135135
TypeError, "Cannot convert sNaN to Rational.",
136136
R.from_decimal, Decimal("snan"))
137137

138+
def testFromContinuedFraction(self):
139+
self.assertRaises(TypeError, R.from_continued_fraction, None)
140+
phi = R.from_continued_fraction([1]*100)
141+
self.assertEquals(round(phi - (1 + 5 ** 0.5) / 2, 10), 0.0)
142+
143+
minusphi = R.from_continued_fraction([-1]*100)
144+
self.assertEquals(round(minusphi + (1 + 5 ** 0.5) / 2, 10), 0.0)
145+
146+
self.assertEquals(R.from_continued_fraction([0]), R(0))
147+
self.assertEquals(R.from_continued_fraction([]), R(0))
148+
149+
def testAsContinuedFraction(self):
150+
self.assertEqual(R.from_float(math.pi).as_continued_fraction()[:15],
151+
[3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 3, 3])
152+
self.assertEqual(R.from_float(-math.pi).as_continued_fraction()[:16],
153+
[-4, 1, 6, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 3, 3])
154+
self.assertEqual(R(0).as_continued_fraction(), [0])
155+
156+
def testApproximateFromFloat(self):
157+
self.assertEqual(R.approximate_from_float(math.pi, 10000), R(355, 113))
158+
self.assertEqual(R.approximate_from_float(-math.pi, 10000), R(-355, 113))
159+
self.assertEqual(R.approximate_from_float(0.0, 10000), R(0))
160+
138161
def testConversions(self):
139162
self.assertTypedEquals(-1, trunc(R(-11, 10)))
140163
self.assertTypedEquals(-2, math.floor(R(-11, 10)))

Lib/urllib2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ def ftp_open(self, req):
12861286
headers = mimetools.Message(sf)
12871287
return addinfourl(fp, headers, req.get_full_url())
12881288
except ftplib.all_errors as msg:
1289-
raise URLError('ftp error %s' % msg).with_traceback(sys.exc_info()[2])
1289+
raise URLError('ftp error: %s' % msg).with_traceback(sys.exc_info()[2])
12901290

12911291
def connect_ftp(self, user, passwd, host, port, dirs, timeout):
12921292
fw = ftpwrapper(user, passwd, host, port, dirs, timeout)

Modules/config.c.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct _inittab _PyImport_Inittab[] = {
4343
/* This lives in Python/Python-ast.c */
4444
{"_ast", init_ast},
4545

46-
/* This lives in Python/_types.c */
46+
/* This lives in Modules/_typesmodule.c */
4747
{"_types", init_types},
4848

4949
/* These entries are here for sys.builtin_module_names */

Modules/socketmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
966966
struct sockaddr_un *a = (struct sockaddr_un *) addr;
967967
#ifdef linux
968968
if (a->sun_path[0] == 0) { /* Linux abstract namespace */
969-
addrlen -= (sizeof(*a) - sizeof(a->sun_path));
969+
addrlen -= offsetof(struct sockaddr_un, sun_path);
970970
return PyString_FromStringAndSize(a->sun_path, addrlen);
971971
}
972972
else
@@ -1171,7 +1171,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
11711171
#if defined(PYOS_OS2)
11721172
*len_ret = sizeof(*addr);
11731173
#else
1174-
*len_ret = len + sizeof(*addr) - sizeof(addr->sun_path);
1174+
*len_ret = len + offsetof(struct sockaddr_un, sun_path);
11751175
#endif
11761176
return 1;
11771177
}

Python/bltinmodule.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,11 +1008,14 @@ min_max(PyObject *args, PyObject *kwds, int op)
10081008
"%s() got an unexpected keyword argument", name);
10091009
return NULL;
10101010
}
1011+
Py_INCREF(keyfunc);
10111012
}
10121013

10131014
it = PyObject_GetIter(v);
1014-
if (it == NULL)
1015+
if (it == NULL) {
1016+
Py_XDECREF(keyfunc);
10151017
return NULL;
1018+
}
10161019

10171020
maxitem = NULL; /* the result */
10181021
maxval = NULL; /* the value associated with the result */
@@ -1061,6 +1064,7 @@ min_max(PyObject *args, PyObject *kwds, int op)
10611064
else
10621065
Py_DECREF(maxval);
10631066
Py_DECREF(it);
1067+
Py_XDECREF(keyfunc);
10641068
return maxitem;
10651069

10661070
Fail_it_item_and_val:
@@ -1071,6 +1075,7 @@ min_max(PyObject *args, PyObject *kwds, int op)
10711075
Py_XDECREF(maxval);
10721076
Py_XDECREF(maxitem);
10731077
Py_DECREF(it);
1078+
Py_XDECREF(keyfunc);
10741079
return NULL;
10751080
}
10761081

Python/ceval.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
18331833
"__import__ not found");
18341834
break;
18351835
}
1836+
Py_INCREF(x);
18361837
v = POP();
18371838
u = TOP();
18381839
if (PyLong_AsLong(u) != -1 || PyErr_Occurred())
@@ -1854,11 +1855,14 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
18541855
Py_DECREF(u);
18551856
if (w == NULL) {
18561857
u = POP();
1858+
Py_DECREF(x);
18571859
x = NULL;
18581860
break;
18591861
}
18601862
READ_TIMESTAMP(intr0);
1861-
x = PyEval_CallObject(x, w);
1863+
v = x;
1864+
x = PyEval_CallObject(v, w);
1865+
Py_DECREF(v);
18621866
READ_TIMESTAMP(intr1);
18631867
Py_DECREF(w);
18641868
SET_TOP(x);

0 commit comments

Comments
 (0)