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

Skip to content

Commit fc43127

Browse files
committed
Merged revisions 76776 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ................ r76776 | benjamin.peterson | 2009-12-12 19:23:39 -0600 (Sat, 12 Dec 2009) | 25 lines Merged revisions 76534,76538,76628,76701,76774 via svnmerge from svn+ssh://[email protected]/python/trunk ........ r76534 | martin.v.loewis | 2009-11-26 02:42:05 -0600 (Thu, 26 Nov 2009) | 2 lines Fix typo. ........ r76538 | georg.brandl | 2009-11-26 14:48:25 -0600 (Thu, 26 Nov 2009) | 1 line #7400: typo. ........ r76628 | andrew.kuchling | 2009-12-02 08:27:11 -0600 (Wed, 02 Dec 2009) | 1 line Markup fixes ........ r76701 | andrew.kuchling | 2009-12-07 20:37:05 -0600 (Mon, 07 Dec 2009) | 1 line Typo fix; grammar fix ........ r76774 | benjamin.peterson | 2009-12-12 18:54:15 -0600 (Sat, 12 Dec 2009) | 1 line account for PyObject_IsInstance's new ability to fail ........ ................
1 parent a5a5ce9 commit fc43127

4 files changed

Lines changed: 480 additions & 94 deletions

File tree

Doc/library/functions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ are always available. They are listed here in alphabetical order.
965965
.. function:: set([iterable])
966966
:noindex:
967967

968-
Return a new set, optionally with elements are taken from *iterable*.
968+
Return a new set, optionally with elements taken from *iterable*.
969969
The set type is described in :ref:`types-set`.
970970

971971

Parser/asdl_c.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ def funcHeader(self, name):
366366
self.emit("obj2ast_%s(PyObject* obj, %s* out, PyArena* arena)" % (name, ctype), 0)
367367
self.emit("{", 0)
368368
self.emit("PyObject* tmp = NULL;", 1)
369+
self.emit("int isinstance;", 1)
369370
self.emit("", 0)
370371

371372
def sumTrailer(self, name):
@@ -385,7 +386,13 @@ def sumTrailer(self, name):
385386
def simpleSum(self, sum, name):
386387
self.funcHeader(name)
387388
for t in sum.types:
388-
self.emit("if (PyObject_IsInstance(obj, (PyObject*)%s_type)) {" % t.name, 1)
389+
line = ("isinstance = PyObject_IsInstance(obj, "
390+
"(PyObject *)%s_type);")
391+
self.emit(line % (t.name,), 1)
392+
self.emit("if (isinstance == -1) {", 1)
393+
self.emit("return 1;", 2)
394+
self.emit("}", 1)
395+
self.emit("if (isinstance) {", 1)
389396
self.emit("*out = %s;" % t.name, 2)
390397
self.emit("return 0;", 2)
391398
self.emit("}", 1)
@@ -407,7 +414,12 @@ def complexSum(self, sum, name):
407414
for a in sum.attributes:
408415
self.visitField(a, name, sum=sum, depth=1)
409416
for t in sum.types:
410-
self.emit("if (PyObject_IsInstance(obj, (PyObject*)%s_type)) {" % t.name, 1)
417+
line = "isinstance = PyObject_IsInstance(obj, (PyObject*)%s_type);"
418+
self.emit(line % (t.name,), 1)
419+
self.emit("if (isinstance == -1) {", 1)
420+
self.emit("return 1;", 2)
421+
self.emit("}", 1)
422+
self.emit("if (isinstance) {", 1)
411423
for f in t.fields:
412424
self.visitFieldDeclaration(f, t.name, sum=sum, depth=2)
413425
self.emit("", 0)
@@ -1077,11 +1089,15 @@ class PartingShots(StaticVisitor):
10771089
PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type,
10781090
(PyObject*)Interactive_type};
10791091
char *req_name[] = {"Module", "Expression", "Interactive"};
1092+
int isinstance;
10801093
assert(0 <= mode && mode <= 2);
10811094
10821095
init_types();
10831096
1084-
if (!PyObject_IsInstance(ast, req_type[mode])) {
1097+
isinstance = PyObject_IsInstance(ast, req_type[mode]);
1098+
if (isinstance == -1)
1099+
return NULL;
1100+
if (!isinstance) {
10851101
PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
10861102
req_name[mode], Py_TYPE(ast)->tp_name);
10871103
return NULL;

0 commit comments

Comments
 (0)