Merged revisions 76776 via svnmerge from

svn+ssh://pythondev@svn.python.org/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://pythondev@svn.python.org/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
  ........
................
This commit is contained in:
Benjamin Peterson 2009-12-13 01:29:00 +00:00
parent a5a5ce90a2
commit fc431270ac
4 changed files with 480 additions and 94 deletions

View File

@ -965,7 +965,7 @@ are always available. They are listed here in alphabetical order.
.. function:: set([iterable])
:noindex:
Return a new set, optionally with elements are taken from *iterable*.
Return a new set, optionally with elements taken from *iterable*.
The set type is described in :ref:`types-set`.

View File

@ -366,6 +366,7 @@ class Obj2ModVisitor(PickleVisitor):
self.emit("obj2ast_%s(PyObject* obj, %s* out, PyArena* arena)" % (name, ctype), 0)
self.emit("{", 0)
self.emit("PyObject* tmp = NULL;", 1)
self.emit("int isinstance;", 1)
self.emit("", 0)
def sumTrailer(self, name):
@ -385,7 +386,13 @@ class Obj2ModVisitor(PickleVisitor):
def simpleSum(self, sum, name):
self.funcHeader(name)
for t in sum.types:
self.emit("if (PyObject_IsInstance(obj, (PyObject*)%s_type)) {" % t.name, 1)
line = ("isinstance = PyObject_IsInstance(obj, "
"(PyObject *)%s_type);")
self.emit(line % (t.name,), 1)
self.emit("if (isinstance == -1) {", 1)
self.emit("return 1;", 2)
self.emit("}", 1)
self.emit("if (isinstance) {", 1)
self.emit("*out = %s;" % t.name, 2)
self.emit("return 0;", 2)
self.emit("}", 1)
@ -407,7 +414,12 @@ class Obj2ModVisitor(PickleVisitor):
for a in sum.attributes:
self.visitField(a, name, sum=sum, depth=1)
for t in sum.types:
self.emit("if (PyObject_IsInstance(obj, (PyObject*)%s_type)) {" % t.name, 1)
line = "isinstance = PyObject_IsInstance(obj, (PyObject*)%s_type);"
self.emit(line % (t.name,), 1)
self.emit("if (isinstance == -1) {", 1)
self.emit("return 1;", 2)
self.emit("}", 1)
self.emit("if (isinstance) {", 1)
for f in t.fields:
self.visitFieldDeclaration(f, t.name, sum=sum, depth=2)
self.emit("", 0)
@ -1077,11 +1089,15 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type,
(PyObject*)Interactive_type};
char *req_name[] = {"Module", "Expression", "Interactive"};
int isinstance;
assert(0 <= mode && mode <= 2);
init_types();
if (!PyObject_IsInstance(ast, req_type[mode])) {
isinstance = PyObject_IsInstance(ast, req_type[mode]);
if (isinstance == -1)
return NULL;
if (!isinstance) {
PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
req_name[mode], Py_TYPE(ast)->tp_name);
return NULL;

File diff suppressed because it is too large Load Diff

View File

@ -529,6 +529,7 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)
int mode = -1;
int dont_inherit = 0;
int supplied_flags = 0;
int is_ast;
PyCompilerFlags cf;
PyObject *cmd;
static char *kwlist[] = {"source", "filename", "mode", "flags",
@ -567,7 +568,10 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)
return NULL;
}
if (PyAST_Check(cmd)) {
is_ast = PyAST_Check(cmd);
if (is_ast == -1)
return NULL;
if (is_ast) {
PyObject *result;
if (supplied_flags & PyCF_ONLY_AST) {
Py_INCREF(cmd);