]> git.proxmox.com Git - mirror_edk2.git/commitdiff
AppPkg/Applications/Python/Python-2.7.10: Initial Checkin part 1/5.
authorDaryl McDaniel <edk2-lists@mc2research.org>
Sat, 7 Nov 2015 19:19:19 +0000 (19:19 +0000)
committerdarylm503 <darylm503@Edk2>
Sat, 7 Nov 2015 19:19:19 +0000 (19:19 +0000)
The Include, Parser, and Python directories from the cPython 2.7.10 distribution.
These files are unchanged and set the baseline for subsequent commits.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Daryl McDaniel <edk2-lists@mc2research.org>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18737 6f19259b-4bc3-4df7-8a09-765794883524

145 files changed:
AppPkg/Applications/Python/Python-2.7.10/Include/Python-ast.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/Python.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/abstract.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/asdl.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/ast.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/bitset.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/boolobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/bufferobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/bytearrayobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/bytes_methods.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/bytesobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/cStringIO.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/cellobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/ceval.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/classobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/cobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/code.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/codecs.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/compile.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/complexobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/datetime.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/descrobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/dictobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/dtoa.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/enumobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/errcode.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/eval.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/fileobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/floatobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/frameobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/funcobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/genobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/graminit.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/grammar.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/import.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/intobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/intrcheck.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/iterobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/listobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/longintrepr.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/longobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/marshal.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/memoryobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/metagrammar.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/methodobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/modsupport.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/moduleobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/node.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/object.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/objimpl.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/opcode.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/osdefs.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/parsetok.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/patchlevel.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pgen.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pgenheaders.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/py_curses.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pyarena.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pycapsule.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pyctype.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pydebug.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pyerrors.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pyexpat.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pyfpe.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pygetopt.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pymacconfig.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pymactoolbox.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pymath.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pymem.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pyport.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pystate.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pystrcmp.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pystrtod.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pythonrun.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/pythread.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/rangeobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/setobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/sliceobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/stringobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/structmember.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/structseq.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/symtable.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/sysmodule.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/timefuncs.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/token.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/traceback.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/tupleobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/ucnhash.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/unicodeobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/warnings.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Include/weakrefobject.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/acceler.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/bitset.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/firstsets.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/grammar.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/grammar1.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/listnode.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/metagrammar.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/myreadline.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/node.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/parser.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/parser.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/parsetok.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/tokenizer.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Parser/tokenizer.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/Python-ast.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/_warnings.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/asdl.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/ast.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/bltinmodule.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/ceval.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/codecs.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/compile.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/dtoa.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/dynload_stub.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/errors.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/formatter_string.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/formatter_unicode.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/frozen.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/future.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/getargs.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/getcompiler.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/getopt.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/getplatform.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/getversion.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/graminit.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/import.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/importdl.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/importdl.h [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/modsupport.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/mysnprintf.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/mystrtoul.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/peephole.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/pyarena.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/pyctype.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/pyfpe.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/pymath.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/pystate.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/pystrcmp.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/pystrtod.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/pythonrun.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/structmember.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/symtable.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/sysmodule.c [new file with mode: 0644]
AppPkg/Applications/Python/Python-2.7.10/Python/traceback.c [new file with mode: 0644]

diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/Python-ast.h b/AppPkg/Applications/Python/Python-2.7.10/Include/Python-ast.h
new file mode 100644 (file)
index 0000000..d794c32
--- /dev/null
@@ -0,0 +1,535 @@
+/* File automatically generated by Parser/asdl_c.py. */\r
+\r
+#include "asdl.h"\r
+\r
+typedef struct _mod *mod_ty;\r
+\r
+typedef struct _stmt *stmt_ty;\r
+\r
+typedef struct _expr *expr_ty;\r
+\r
+typedef enum _expr_context { Load=1, Store=2, Del=3, AugLoad=4, AugStore=5,\r
+                             Param=6 } expr_context_ty;\r
+\r
+typedef struct _slice *slice_ty;\r
+\r
+typedef enum _boolop { And=1, Or=2 } boolop_ty;\r
+\r
+typedef enum _operator { Add=1, Sub=2, Mult=3, Div=4, Mod=5, Pow=6, LShift=7,\r
+                         RShift=8, BitOr=9, BitXor=10, BitAnd=11, FloorDiv=12 }\r
+                         operator_ty;\r
+\r
+typedef enum _unaryop { Invert=1, Not=2, UAdd=3, USub=4 } unaryop_ty;\r
+\r
+typedef enum _cmpop { Eq=1, NotEq=2, Lt=3, LtE=4, Gt=5, GtE=6, Is=7, IsNot=8,\r
+                      In=9, NotIn=10 } cmpop_ty;\r
+\r
+typedef struct _comprehension *comprehension_ty;\r
+\r
+typedef struct _excepthandler *excepthandler_ty;\r
+\r
+typedef struct _arguments *arguments_ty;\r
+\r
+typedef struct _keyword *keyword_ty;\r
+\r
+typedef struct _alias *alias_ty;\r
+\r
+\r
+enum _mod_kind {Module_kind=1, Interactive_kind=2, Expression_kind=3,\r
+                 Suite_kind=4};\r
+struct _mod {\r
+        enum _mod_kind kind;\r
+        union {\r
+                struct {\r
+                        asdl_seq *body;\r
+                } Module;\r
+                \r
+                struct {\r
+                        asdl_seq *body;\r
+                } Interactive;\r
+                \r
+                struct {\r
+                        expr_ty body;\r
+                } Expression;\r
+                \r
+                struct {\r
+                        asdl_seq *body;\r
+                } Suite;\r
+                \r
+        } v;\r
+};\r
+\r
+enum _stmt_kind {FunctionDef_kind=1, ClassDef_kind=2, Return_kind=3,\r
+                  Delete_kind=4, Assign_kind=5, AugAssign_kind=6, Print_kind=7,\r
+                  For_kind=8, While_kind=9, If_kind=10, With_kind=11,\r
+                  Raise_kind=12, TryExcept_kind=13, TryFinally_kind=14,\r
+                  Assert_kind=15, Import_kind=16, ImportFrom_kind=17,\r
+                  Exec_kind=18, Global_kind=19, Expr_kind=20, Pass_kind=21,\r
+                  Break_kind=22, Continue_kind=23};\r
+struct _stmt {\r
+        enum _stmt_kind kind;\r
+        union {\r
+                struct {\r
+                        identifier name;\r
+                        arguments_ty args;\r
+                        asdl_seq *body;\r
+                        asdl_seq *decorator_list;\r
+                } FunctionDef;\r
+                \r
+                struct {\r
+                        identifier name;\r
+                        asdl_seq *bases;\r
+                        asdl_seq *body;\r
+                        asdl_seq *decorator_list;\r
+                } ClassDef;\r
+                \r
+                struct {\r
+                        expr_ty value;\r
+                } Return;\r
+                \r
+                struct {\r
+                        asdl_seq *targets;\r
+                } Delete;\r
+                \r
+                struct {\r
+                        asdl_seq *targets;\r
+                        expr_ty value;\r
+                } Assign;\r
+                \r
+                struct {\r
+                        expr_ty target;\r
+                        operator_ty op;\r
+                        expr_ty value;\r
+                } AugAssign;\r
+                \r
+                struct {\r
+                        expr_ty dest;\r
+                        asdl_seq *values;\r
+                        bool nl;\r
+                } Print;\r
+                \r
+                struct {\r
+                        expr_ty target;\r
+                        expr_ty iter;\r
+                        asdl_seq *body;\r
+                        asdl_seq *orelse;\r
+                } For;\r
+                \r
+                struct {\r
+                        expr_ty test;\r
+                        asdl_seq *body;\r
+                        asdl_seq *orelse;\r
+                } While;\r
+                \r
+                struct {\r
+                        expr_ty test;\r
+                        asdl_seq *body;\r
+                        asdl_seq *orelse;\r
+                } If;\r
+                \r
+                struct {\r
+                        expr_ty context_expr;\r
+                        expr_ty optional_vars;\r
+                        asdl_seq *body;\r
+                } With;\r
+                \r
+                struct {\r
+                        expr_ty type;\r
+                        expr_ty inst;\r
+                        expr_ty tback;\r
+                } Raise;\r
+                \r
+                struct {\r
+                        asdl_seq *body;\r
+                        asdl_seq *handlers;\r
+                        asdl_seq *orelse;\r
+                } TryExcept;\r
+                \r
+                struct {\r
+                        asdl_seq *body;\r
+                        asdl_seq *finalbody;\r
+                } TryFinally;\r
+                \r
+                struct {\r
+                        expr_ty test;\r
+                        expr_ty msg;\r
+                } Assert;\r
+                \r
+                struct {\r
+                        asdl_seq *names;\r
+                } Import;\r
+                \r
+                struct {\r
+                        identifier module;\r
+                        asdl_seq *names;\r
+                        int level;\r
+                } ImportFrom;\r
+                \r
+                struct {\r
+                        expr_ty body;\r
+                        expr_ty globals;\r
+                        expr_ty locals;\r
+                } Exec;\r
+                \r
+                struct {\r
+                        asdl_seq *names;\r
+                } Global;\r
+                \r
+                struct {\r
+                        expr_ty value;\r
+                } Expr;\r
+                \r
+        } v;\r
+        int lineno;\r
+        int col_offset;\r
+};\r
+\r
+enum _expr_kind {BoolOp_kind=1, BinOp_kind=2, UnaryOp_kind=3, Lambda_kind=4,\r
+                  IfExp_kind=5, Dict_kind=6, Set_kind=7, ListComp_kind=8,\r
+                  SetComp_kind=9, DictComp_kind=10, GeneratorExp_kind=11,\r
+                  Yield_kind=12, Compare_kind=13, Call_kind=14, Repr_kind=15,\r
+                  Num_kind=16, Str_kind=17, Attribute_kind=18,\r
+                  Subscript_kind=19, Name_kind=20, List_kind=21, Tuple_kind=22};\r
+struct _expr {\r
+        enum _expr_kind kind;\r
+        union {\r
+                struct {\r
+                        boolop_ty op;\r
+                        asdl_seq *values;\r
+                } BoolOp;\r
+                \r
+                struct {\r
+                        expr_ty left;\r
+                        operator_ty op;\r
+                        expr_ty right;\r
+                } BinOp;\r
+                \r
+                struct {\r
+                        unaryop_ty op;\r
+                        expr_ty operand;\r
+                } UnaryOp;\r
+                \r
+                struct {\r
+                        arguments_ty args;\r
+                        expr_ty body;\r
+                } Lambda;\r
+                \r
+                struct {\r
+                        expr_ty test;\r
+                        expr_ty body;\r
+                        expr_ty orelse;\r
+                } IfExp;\r
+                \r
+                struct {\r
+                        asdl_seq *keys;\r
+                        asdl_seq *values;\r
+                } Dict;\r
+                \r
+                struct {\r
+                        asdl_seq *elts;\r
+                } Set;\r
+                \r
+                struct {\r
+                        expr_ty elt;\r
+                        asdl_seq *generators;\r
+                } ListComp;\r
+                \r
+                struct {\r
+                        expr_ty elt;\r
+                        asdl_seq *generators;\r
+                } SetComp;\r
+                \r
+                struct {\r
+                        expr_ty key;\r
+                        expr_ty value;\r
+                        asdl_seq *generators;\r
+                } DictComp;\r
+                \r
+                struct {\r
+                        expr_ty elt;\r
+                        asdl_seq *generators;\r
+                } GeneratorExp;\r
+                \r
+                struct {\r
+                        expr_ty value;\r
+                } Yield;\r
+                \r
+                struct {\r
+                        expr_ty left;\r
+                        asdl_int_seq *ops;\r
+                        asdl_seq *comparators;\r
+                } Compare;\r
+                \r
+                struct {\r
+                        expr_ty func;\r
+                        asdl_seq *args;\r
+                        asdl_seq *keywords;\r
+                        expr_ty starargs;\r
+                        expr_ty kwargs;\r
+                } Call;\r
+                \r
+                struct {\r
+                        expr_ty value;\r
+                } Repr;\r
+                \r
+                struct {\r
+                        object n;\r
+                } Num;\r
+                \r
+                struct {\r
+                        string s;\r
+                } Str;\r
+                \r
+                struct {\r
+                        expr_ty value;\r
+                        identifier attr;\r
+                        expr_context_ty ctx;\r
+                } Attribute;\r
+                \r
+                struct {\r
+                        expr_ty value;\r
+                        slice_ty slice;\r
+                        expr_context_ty ctx;\r
+                } Subscript;\r
+                \r
+                struct {\r
+                        identifier id;\r
+                        expr_context_ty ctx;\r
+                } Name;\r
+                \r
+                struct {\r
+                        asdl_seq *elts;\r
+                        expr_context_ty ctx;\r
+                } List;\r
+                \r
+                struct {\r
+                        asdl_seq *elts;\r
+                        expr_context_ty ctx;\r
+                } Tuple;\r
+                \r
+        } v;\r
+        int lineno;\r
+        int col_offset;\r
+};\r
+\r
+enum _slice_kind {Ellipsis_kind=1, Slice_kind=2, ExtSlice_kind=3, Index_kind=4};\r
+struct _slice {\r
+        enum _slice_kind kind;\r
+        union {\r
+                struct {\r
+                        expr_ty lower;\r
+                        expr_ty upper;\r
+                        expr_ty step;\r
+                } Slice;\r
+                \r
+                struct {\r
+                        asdl_seq *dims;\r
+                } ExtSlice;\r
+                \r
+                struct {\r
+                        expr_ty value;\r
+                } Index;\r
+                \r
+        } v;\r
+};\r
+\r
+struct _comprehension {\r
+        expr_ty target;\r
+        expr_ty iter;\r
+        asdl_seq *ifs;\r
+};\r
+\r
+enum _excepthandler_kind {ExceptHandler_kind=1};\r
+struct _excepthandler {\r
+        enum _excepthandler_kind kind;\r
+        union {\r
+                struct {\r
+                        expr_ty type;\r
+                        expr_ty name;\r
+                        asdl_seq *body;\r
+                } ExceptHandler;\r
+                \r
+        } v;\r
+        int lineno;\r
+        int col_offset;\r
+};\r
+\r
+struct _arguments {\r
+        asdl_seq *args;\r
+        identifier vararg;\r
+        identifier kwarg;\r
+        asdl_seq *defaults;\r
+};\r
+\r
+struct _keyword {\r
+        identifier arg;\r
+        expr_ty value;\r
+};\r
+\r
+struct _alias {\r
+        identifier name;\r
+        identifier asname;\r
+};\r
+\r
+\r
+#define Module(a0, a1) _Py_Module(a0, a1)\r
+mod_ty _Py_Module(asdl_seq * body, PyArena *arena);\r
+#define Interactive(a0, a1) _Py_Interactive(a0, a1)\r
+mod_ty _Py_Interactive(asdl_seq * body, PyArena *arena);\r
+#define Expression(a0, a1) _Py_Expression(a0, a1)\r
+mod_ty _Py_Expression(expr_ty body, PyArena *arena);\r
+#define Suite(a0, a1) _Py_Suite(a0, a1)\r
+mod_ty _Py_Suite(asdl_seq * body, PyArena *arena);\r
+#define FunctionDef(a0, a1, a2, a3, a4, a5, a6) _Py_FunctionDef(a0, a1, a2, a3, a4, a5, a6)\r
+stmt_ty _Py_FunctionDef(identifier name, arguments_ty args, asdl_seq * body,\r
+                        asdl_seq * decorator_list, int lineno, int col_offset,\r
+                        PyArena *arena);\r
+#define ClassDef(a0, a1, a2, a3, a4, a5, a6) _Py_ClassDef(a0, a1, a2, a3, a4, a5, a6)\r
+stmt_ty _Py_ClassDef(identifier name, asdl_seq * bases, asdl_seq * body,\r
+                     asdl_seq * decorator_list, int lineno, int col_offset,\r
+                     PyArena *arena);\r
+#define Return(a0, a1, a2, a3) _Py_Return(a0, a1, a2, a3)\r
+stmt_ty _Py_Return(expr_ty value, int lineno, int col_offset, PyArena *arena);\r
+#define Delete(a0, a1, a2, a3) _Py_Delete(a0, a1, a2, a3)\r
+stmt_ty _Py_Delete(asdl_seq * targets, int lineno, int col_offset, PyArena\r
+                   *arena);\r
+#define Assign(a0, a1, a2, a3, a4) _Py_Assign(a0, a1, a2, a3, a4)\r
+stmt_ty _Py_Assign(asdl_seq * targets, expr_ty value, int lineno, int\r
+                   col_offset, PyArena *arena);\r
+#define AugAssign(a0, a1, a2, a3, a4, a5) _Py_AugAssign(a0, a1, a2, a3, a4, a5)\r
+stmt_ty _Py_AugAssign(expr_ty target, operator_ty op, expr_ty value, int\r
+                      lineno, int col_offset, PyArena *arena);\r
+#define Print(a0, a1, a2, a3, a4, a5) _Py_Print(a0, a1, a2, a3, a4, a5)\r
+stmt_ty _Py_Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int\r
+                  col_offset, PyArena *arena);\r
+#define For(a0, a1, a2, a3, a4, a5, a6) _Py_For(a0, a1, a2, a3, a4, a5, a6)\r
+stmt_ty _Py_For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq *\r
+                orelse, int lineno, int col_offset, PyArena *arena);\r
+#define While(a0, a1, a2, a3, a4, a5) _Py_While(a0, a1, a2, a3, a4, a5)\r
+stmt_ty _Py_While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno,\r
+                  int col_offset, PyArena *arena);\r
+#define If(a0, a1, a2, a3, a4, a5) _Py_If(a0, a1, a2, a3, a4, a5)\r
+stmt_ty _Py_If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno,\r
+               int col_offset, PyArena *arena);\r
+#define With(a0, a1, a2, a3, a4, a5) _Py_With(a0, a1, a2, a3, a4, a5)\r
+stmt_ty _Py_With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body,\r
+                 int lineno, int col_offset, PyArena *arena);\r
+#define Raise(a0, a1, a2, a3, a4, a5) _Py_Raise(a0, a1, a2, a3, a4, a5)\r
+stmt_ty _Py_Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int\r
+                  col_offset, PyArena *arena);\r
+#define TryExcept(a0, a1, a2, a3, a4, a5) _Py_TryExcept(a0, a1, a2, a3, a4, a5)\r
+stmt_ty _Py_TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse,\r
+                      int lineno, int col_offset, PyArena *arena);\r
+#define TryFinally(a0, a1, a2, a3, a4) _Py_TryFinally(a0, a1, a2, a3, a4)\r
+stmt_ty _Py_TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int\r
+                       col_offset, PyArena *arena);\r
+#define Assert(a0, a1, a2, a3, a4) _Py_Assert(a0, a1, a2, a3, a4)\r
+stmt_ty _Py_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset,\r
+                   PyArena *arena);\r
+#define Import(a0, a1, a2, a3) _Py_Import(a0, a1, a2, a3)\r
+stmt_ty _Py_Import(asdl_seq * names, int lineno, int col_offset, PyArena\r
+                   *arena);\r
+#define ImportFrom(a0, a1, a2, a3, a4, a5) _Py_ImportFrom(a0, a1, a2, a3, a4, a5)\r
+stmt_ty _Py_ImportFrom(identifier module, asdl_seq * names, int level, int\r
+                       lineno, int col_offset, PyArena *arena);\r
+#define Exec(a0, a1, a2, a3, a4, a5) _Py_Exec(a0, a1, a2, a3, a4, a5)\r
+stmt_ty _Py_Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int\r
+                 col_offset, PyArena *arena);\r
+#define Global(a0, a1, a2, a3) _Py_Global(a0, a1, a2, a3)\r
+stmt_ty _Py_Global(asdl_seq * names, int lineno, int col_offset, PyArena\r
+                   *arena);\r
+#define Expr(a0, a1, a2, a3) _Py_Expr(a0, a1, a2, a3)\r
+stmt_ty _Py_Expr(expr_ty value, int lineno, int col_offset, PyArena *arena);\r
+#define Pass(a0, a1, a2) _Py_Pass(a0, a1, a2)\r
+stmt_ty _Py_Pass(int lineno, int col_offset, PyArena *arena);\r
+#define Break(a0, a1, a2) _Py_Break(a0, a1, a2)\r
+stmt_ty _Py_Break(int lineno, int col_offset, PyArena *arena);\r
+#define Continue(a0, a1, a2) _Py_Continue(a0, a1, a2)\r
+stmt_ty _Py_Continue(int lineno, int col_offset, PyArena *arena);\r
+#define BoolOp(a0, a1, a2, a3, a4) _Py_BoolOp(a0, a1, a2, a3, a4)\r
+expr_ty _Py_BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset,\r
+                   PyArena *arena);\r
+#define BinOp(a0, a1, a2, a3, a4, a5) _Py_BinOp(a0, a1, a2, a3, a4, a5)\r
+expr_ty _Py_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int\r
+                  col_offset, PyArena *arena);\r
+#define UnaryOp(a0, a1, a2, a3, a4) _Py_UnaryOp(a0, a1, a2, a3, a4)\r
+expr_ty _Py_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset,\r
+                    PyArena *arena);\r
+#define Lambda(a0, a1, a2, a3, a4) _Py_Lambda(a0, a1, a2, a3, a4)\r
+expr_ty _Py_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset,\r
+                   PyArena *arena);\r
+#define IfExp(a0, a1, a2, a3, a4, a5) _Py_IfExp(a0, a1, a2, a3, a4, a5)\r
+expr_ty _Py_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int\r
+                  col_offset, PyArena *arena);\r
+#define Dict(a0, a1, a2, a3, a4) _Py_Dict(a0, a1, a2, a3, a4)\r
+expr_ty _Py_Dict(asdl_seq * keys, asdl_seq * values, int lineno, int\r
+                 col_offset, PyArena *arena);\r
+#define Set(a0, a1, a2, a3) _Py_Set(a0, a1, a2, a3)\r
+expr_ty _Py_Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena);\r
+#define ListComp(a0, a1, a2, a3, a4) _Py_ListComp(a0, a1, a2, a3, a4)\r
+expr_ty _Py_ListComp(expr_ty elt, asdl_seq * generators, int lineno, int\r
+                     col_offset, PyArena *arena);\r
+#define SetComp(a0, a1, a2, a3, a4) _Py_SetComp(a0, a1, a2, a3, a4)\r
+expr_ty _Py_SetComp(expr_ty elt, asdl_seq * generators, int lineno, int\r
+                    col_offset, PyArena *arena);\r
+#define DictComp(a0, a1, a2, a3, a4, a5) _Py_DictComp(a0, a1, a2, a3, a4, a5)\r
+expr_ty _Py_DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int\r
+                     lineno, int col_offset, PyArena *arena);\r
+#define GeneratorExp(a0, a1, a2, a3, a4) _Py_GeneratorExp(a0, a1, a2, a3, a4)\r
+expr_ty _Py_GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int\r
+                         col_offset, PyArena *arena);\r
+#define Yield(a0, a1, a2, a3) _Py_Yield(a0, a1, a2, a3)\r
+expr_ty _Py_Yield(expr_ty value, int lineno, int col_offset, PyArena *arena);\r
+#define Compare(a0, a1, a2, a3, a4, a5) _Py_Compare(a0, a1, a2, a3, a4, a5)\r
+expr_ty _Py_Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators,\r
+                    int lineno, int col_offset, PyArena *arena);\r
+#define Call(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Call(a0, a1, a2, a3, a4, a5, a6, a7)\r
+expr_ty _Py_Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty\r
+                 starargs, expr_ty kwargs, int lineno, int col_offset, PyArena\r
+                 *arena);\r
+#define Repr(a0, a1, a2, a3) _Py_Repr(a0, a1, a2, a3)\r
+expr_ty _Py_Repr(expr_ty value, int lineno, int col_offset, PyArena *arena);\r
+#define Num(a0, a1, a2, a3) _Py_Num(a0, a1, a2, a3)\r
+expr_ty _Py_Num(object n, int lineno, int col_offset, PyArena *arena);\r
+#define Str(a0, a1, a2, a3) _Py_Str(a0, a1, a2, a3)\r
+expr_ty _Py_Str(string s, int lineno, int col_offset, PyArena *arena);\r
+#define Attribute(a0, a1, a2, a3, a4, a5) _Py_Attribute(a0, a1, a2, a3, a4, a5)\r
+expr_ty _Py_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int\r
+                      lineno, int col_offset, PyArena *arena);\r
+#define Subscript(a0, a1, a2, a3, a4, a5) _Py_Subscript(a0, a1, a2, a3, a4, a5)\r
+expr_ty _Py_Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int\r
+                      lineno, int col_offset, PyArena *arena);\r
+#define Name(a0, a1, a2, a3, a4) _Py_Name(a0, a1, a2, a3, a4)\r
+expr_ty _Py_Name(identifier id, expr_context_ty ctx, int lineno, int\r
+                 col_offset, PyArena *arena);\r
+#define List(a0, a1, a2, a3, a4) _Py_List(a0, a1, a2, a3, a4)\r
+expr_ty _Py_List(asdl_seq * elts, expr_context_ty ctx, int lineno, int\r
+                 col_offset, PyArena *arena);\r
+#define Tuple(a0, a1, a2, a3, a4) _Py_Tuple(a0, a1, a2, a3, a4)\r
+expr_ty _Py_Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int\r
+                  col_offset, PyArena *arena);\r
+#define Ellipsis(a0) _Py_Ellipsis(a0)\r
+slice_ty _Py_Ellipsis(PyArena *arena);\r
+#define Slice(a0, a1, a2, a3) _Py_Slice(a0, a1, a2, a3)\r
+slice_ty _Py_Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena);\r
+#define ExtSlice(a0, a1) _Py_ExtSlice(a0, a1)\r
+slice_ty _Py_ExtSlice(asdl_seq * dims, PyArena *arena);\r
+#define Index(a0, a1) _Py_Index(a0, a1)\r
+slice_ty _Py_Index(expr_ty value, PyArena *arena);\r
+#define comprehension(a0, a1, a2, a3) _Py_comprehension(a0, a1, a2, a3)\r
+comprehension_ty _Py_comprehension(expr_ty target, expr_ty iter, asdl_seq *\r
+                                   ifs, PyArena *arena);\r
+#define ExceptHandler(a0, a1, a2, a3, a4, a5) _Py_ExceptHandler(a0, a1, a2, a3, a4, a5)\r
+excepthandler_ty _Py_ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body,\r
+                                   int lineno, int col_offset, PyArena *arena);\r
+#define arguments(a0, a1, a2, a3, a4) _Py_arguments(a0, a1, a2, a3, a4)\r
+arguments_ty _Py_arguments(asdl_seq * args, identifier vararg, identifier\r
+                           kwarg, asdl_seq * defaults, PyArena *arena);\r
+#define keyword(a0, a1, a2) _Py_keyword(a0, a1, a2)\r
+keyword_ty _Py_keyword(identifier arg, expr_ty value, PyArena *arena);\r
+#define alias(a0, a1, a2) _Py_alias(a0, a1, a2)\r
+alias_ty _Py_alias(identifier name, identifier asname, PyArena *arena);\r
+\r
+PyObject* PyAST_mod2obj(mod_ty t);\r
+mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\r
+int PyAST_Check(PyObject* obj);\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/Python.h b/AppPkg/Applications/Python/Python-2.7.10/Include/Python.h
new file mode 100644 (file)
index 0000000..5abad47
--- /dev/null
@@ -0,0 +1,178 @@
+#ifndef Py_PYTHON_H\r
+#define Py_PYTHON_H\r
+/* Since this is a "meta-include" file, no #ifdef __cplusplus / extern "C" { */\r
+\r
+/* Include nearly all Python header files */\r
+\r
+#include "patchlevel.h"\r
+#include "pyconfig.h"\r
+#include "pymacconfig.h"\r
+\r
+/* Cyclic gc is always enabled, starting with release 2.3a1.  Supply the\r
+ * old symbol for the benefit of extension modules written before then\r
+ * that may be conditionalizing on it.  The core doesn't use it anymore.\r
+ */\r
+#ifndef WITH_CYCLE_GC\r
+#define WITH_CYCLE_GC 1\r
+#endif\r
+\r
+#include <limits.h>\r
+\r
+#ifndef UCHAR_MAX\r
+#error "Something's broken.  UCHAR_MAX should be defined in limits.h."\r
+#endif\r
+\r
+#if UCHAR_MAX != 255\r
+#error "Python's source code assumes C's unsigned char is an 8-bit type."\r
+#endif\r
+\r
+#if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE)\r
+#define _SGI_MP_SOURCE\r
+#endif\r
+\r
+#include <stdio.h>\r
+#ifndef NULL\r
+#   error "Python.h requires that stdio.h define NULL."\r
+#endif\r
+\r
+#include <string.h>\r
+#ifdef HAVE_ERRNO_H\r
+#include <errno.h>\r
+#endif\r
+#include <stdlib.h>\r
+#ifdef HAVE_UNISTD_H\r
+#include <unistd.h>\r
+#endif\r
+\r
+/* For size_t? */\r
+#ifdef HAVE_STDDEF_H\r
+#include <stddef.h>\r
+#endif\r
+\r
+/* CAUTION:  Build setups should ensure that NDEBUG is defined on the\r
+ * compiler command line when building Python in release mode; else\r
+ * assert() calls won't be removed.\r
+ */\r
+#include <assert.h>\r
+\r
+#include "pyport.h"\r
+\r
+/* pyconfig.h or pyport.h may or may not define DL_IMPORT */\r
+#ifndef DL_IMPORT      /* declarations for DLL import/export */\r
+#define DL_IMPORT(RTYPE) RTYPE\r
+#endif\r
+#ifndef DL_EXPORT      /* declarations for DLL import/export */\r
+#define DL_EXPORT(RTYPE) RTYPE\r
+#endif\r
+\r
+/* Debug-mode build with pymalloc implies PYMALLOC_DEBUG.\r
+ *  PYMALLOC_DEBUG is in error if pymalloc is not in use.\r
+ */\r
+#if defined(Py_DEBUG) && defined(WITH_PYMALLOC) && !defined(PYMALLOC_DEBUG)\r
+#define PYMALLOC_DEBUG\r
+#endif\r
+#if defined(PYMALLOC_DEBUG) && !defined(WITH_PYMALLOC)\r
+#error "PYMALLOC_DEBUG requires WITH_PYMALLOC"\r
+#endif\r
+#include "pymath.h"\r
+#include "pymem.h"\r
+\r
+#include "object.h"\r
+#include "objimpl.h"\r
+\r
+#include "pydebug.h"\r
+\r
+#include "unicodeobject.h"\r
+#include "intobject.h"\r
+#include "boolobject.h"\r
+#include "longobject.h"\r
+#include "floatobject.h"\r
+#ifndef WITHOUT_COMPLEX\r
+#include "complexobject.h"\r
+#endif\r
+#include "rangeobject.h"\r
+#include "stringobject.h"\r
+#include "memoryobject.h"\r
+#include "bufferobject.h"\r
+#include "bytesobject.h"\r
+#include "bytearrayobject.h"\r
+#include "tupleobject.h"\r
+#include "listobject.h"\r
+#include "dictobject.h"\r
+#include "enumobject.h"\r
+#include "setobject.h"\r
+#include "methodobject.h"\r
+#include "moduleobject.h"\r
+#include "funcobject.h"\r
+#include "classobject.h"\r
+#include "fileobject.h"\r
+#include "cobject.h"\r
+#include "pycapsule.h"\r
+#include "traceback.h"\r
+#include "sliceobject.h"\r
+#include "cellobject.h"\r
+#include "iterobject.h"\r
+#include "genobject.h"\r
+#include "descrobject.h"\r
+#include "warnings.h"\r
+#include "weakrefobject.h"\r
+\r
+#include "codecs.h"\r
+#include "pyerrors.h"\r
+\r
+#include "pystate.h"\r
+\r
+#include "pyarena.h"\r
+#include "modsupport.h"\r
+#include "pythonrun.h"\r
+#include "ceval.h"\r
+#include "sysmodule.h"\r
+#include "intrcheck.h"\r
+#include "import.h"\r
+\r
+#include "abstract.h"\r
+\r
+#include "compile.h"\r
+#include "eval.h"\r
+\r
+#include "pyctype.h"\r
+#include "pystrtod.h"\r
+#include "pystrcmp.h"\r
+#include "dtoa.h"\r
+\r
+/* _Py_Mangle is defined in compile.c */\r
+PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);\r
+\r
+/* PyArg_GetInt is deprecated and should not be used, use PyArg_Parse(). */\r
+#define PyArg_GetInt(v, a)     PyArg_Parse((v), "i", (a))\r
+\r
+/* PyArg_NoArgs should not be necessary.\r
+   Set ml_flags in the PyMethodDef to METH_NOARGS. */\r
+#define PyArg_NoArgs(v)                PyArg_Parse(v, "")\r
+\r
+/* Argument must be a char or an int in [-128, 127] or [0, 255]. */\r
+#define Py_CHARMASK(c)         ((unsigned char)((c) & 0xff))\r
+\r
+#include "pyfpe.h"\r
+\r
+/* These definitions must match corresponding definitions in graminit.h.\r
+   There's code in compile.c that checks that they are the same. */\r
+#define Py_single_input 256\r
+#define Py_file_input 257\r
+#define Py_eval_input 258\r
+\r
+#ifdef HAVE_PTH\r
+/* GNU pth user-space thread support */\r
+#include <pth.h>\r
+#endif\r
+\r
+/* Define macros for inline documentation. */\r
+#define PyDoc_VAR(name) static char name[]\r
+#define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)\r
+#ifdef WITH_DOC_STRINGS\r
+#define PyDoc_STR(str) str\r
+#else\r
+#define PyDoc_STR(str) ""\r
+#endif\r
+\r
+#endif /* !Py_PYTHON_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/abstract.h b/AppPkg/Applications/Python/Python-2.7.10/Include/abstract.h
new file mode 100644 (file)
index 0000000..61d56ff
--- /dev/null
@@ -0,0 +1,1396 @@
+#ifndef Py_ABSTRACTOBJECT_H\r
+#define Py_ABSTRACTOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifdef PY_SSIZE_T_CLEAN\r
+#define PyObject_CallFunction _PyObject_CallFunction_SizeT\r
+#define PyObject_CallMethod _PyObject_CallMethod_SizeT\r
+#endif\r
+\r
+/* Abstract Object Interface (many thanks to Jim Fulton) */\r
+\r
+/*\r
+   PROPOSAL: A Generic Python Object Interface for Python C Modules\r
+\r
+Problem\r
+\r
+  Python modules written in C that must access Python objects must do\r
+  so through routines whose interfaces are described by a set of\r
+  include files.  Unfortunately, these routines vary according to the\r
+  object accessed.  To use these routines, the C programmer must check\r
+  the type of the object being used and must call a routine based on\r
+  the object type.  For example, to access an element of a sequence,\r
+  the programmer must determine whether the sequence is a list or a\r
+  tuple:\r
+\r
+    if(is_tupleobject(o))\r
+      e=gettupleitem(o,i)\r
+    else if(is_listitem(o))\r
+      e=getlistitem(o,i)\r
+\r
+  If the programmer wants to get an item from another type of object\r
+  that provides sequence behavior, there is no clear way to do it\r
+  correctly.\r
+\r
+  The persistent programmer may peruse object.h and find that the\r
+  _typeobject structure provides a means of invoking up to (currently\r
+  about) 41 special operators.  So, for example, a routine can get an\r
+  item from any object that provides sequence behavior. However, to\r
+  use this mechanism, the programmer must make their code dependent on\r
+  the current Python implementation.\r
+\r
+  Also, certain semantics, especially memory management semantics, may\r
+  differ by the type of object being used.  Unfortunately, these\r
+  semantics are not clearly described in the current include files.\r
+  An abstract interface providing more consistent semantics is needed.\r
+\r
+Proposal\r
+\r
+  I propose the creation of a standard interface (with an associated\r
+  library of routines and/or macros) for generically obtaining the\r
+  services of Python objects.  This proposal can be viewed as one\r
+  components of a Python C interface consisting of several components.\r
+\r
+  From the viewpoint of C access to Python services, we have (as\r
+  suggested by Guido in off-line discussions):\r
+\r
+  - "Very high level layer": two or three functions that let you exec or\r
+    eval arbitrary Python code given as a string in a module whose name is\r
+    given, passing C values in and getting C values out using\r
+    mkvalue/getargs style format strings.  This does not require the user\r
+    to declare any variables of type "PyObject *".  This should be enough\r
+    to write a simple application that gets Python code from the user,\r
+    execs it, and returns the output or errors.  (Error handling must also\r
+    be part of this API.)\r
+\r
+  - "Abstract objects layer": which is the subject of this proposal.\r
+    It has many functions operating on objects, and lest you do many\r
+    things from C that you can also write in Python, without going\r
+    through the Python parser.\r
+\r
+  - "Concrete objects layer": This is the public type-dependent\r
+    interface provided by the standard built-in types, such as floats,\r
+    strings, and lists.  This interface exists and is currently\r
+    documented by the collection of include files provided with the\r
+    Python distributions.\r
+\r
+  From the point of view of Python accessing services provided by C\r
+  modules:\r
+\r
+  - "Python module interface": this interface consist of the basic\r
+    routines used to define modules and their members.  Most of the\r
+    current extensions-writing guide deals with this interface.\r
+\r
+  - "Built-in object interface": this is the interface that a new\r
+    built-in type must provide and the mechanisms and rules that a\r
+    developer of a new built-in type must use and follow.\r
+\r
+  This proposal is a "first-cut" that is intended to spur\r
+  discussion. See especially the lists of notes.\r
+\r
+  The Python C object interface will provide four protocols: object,\r
+  numeric, sequence, and mapping.  Each protocol consists of a\r
+  collection of related operations.  If an operation that is not\r
+  provided by a particular type is invoked, then a standard exception,\r
+  NotImplementedError is raised with a operation name as an argument.\r
+  In addition, for convenience this interface defines a set of\r
+  constructors for building objects of built-in types.  This is needed\r
+  so new objects can be returned from C functions that otherwise treat\r
+  objects generically.\r
+\r
+Memory Management\r
+\r
+  For all of the functions described in this proposal, if a function\r
+  retains a reference to a Python object passed as an argument, then the\r
+  function will increase the reference count of the object.  It is\r
+  unnecessary for the caller to increase the reference count of an\r
+  argument in anticipation of the object's retention.\r
+\r
+  All Python objects returned from functions should be treated as new\r
+  objects.  Functions that return objects assume that the caller will\r
+  retain a reference and the reference count of the object has already\r
+  been incremented to account for this fact.  A caller that does not\r
+  retain a reference to an object that is returned from a function\r
+  must decrement the reference count of the object (using\r
+  DECREF(object)) to prevent memory leaks.\r
+\r
+  Note that the behavior mentioned here is different from the current\r
+  behavior for some objects (e.g. lists and tuples) when certain\r
+  type-specific routines are called directly (e.g. setlistitem).  The\r
+  proposed abstraction layer will provide a consistent memory\r
+  management interface, correcting for inconsistent behavior for some\r
+  built-in types.\r
+\r
+Protocols\r
+\r
+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/\r
+\r
+/*  Object Protocol: */\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     int PyObject_Print(PyObject *o, FILE *fp, int flags);\r
+\r
+     Print an object, o, on file, fp.  Returns -1 on\r
+     error.  The flags argument is used to enable certain printing\r
+     options. The only option currently supported is Py_Print_RAW.\r
+\r
+     (What should be said about Py_Print_RAW?)\r
+\r
+       */\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     int PyObject_HasAttrString(PyObject *o, char *attr_name);\r
+\r
+     Returns 1 if o has the attribute attr_name, and 0 otherwise.\r
+     This is equivalent to the Python expression:\r
+     hasattr(o,attr_name).\r
+\r
+     This function always succeeds.\r
+\r
+       */\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     PyObject* PyObject_GetAttrString(PyObject *o, char *attr_name);\r
+\r
+     Retrieve an attributed named attr_name form object o.\r
+     Returns the attribute value on success, or NULL on failure.\r
+     This is the equivalent of the Python expression: o.attr_name.\r
+\r
+       */\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     int PyObject_HasAttr(PyObject *o, PyObject *attr_name);\r
+\r
+     Returns 1 if o has the attribute attr_name, and 0 otherwise.\r
+     This is equivalent to the Python expression:\r
+     hasattr(o,attr_name).\r
+\r
+     This function always succeeds.\r
+\r
+       */\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name);\r
+\r
+     Retrieve an attributed named attr_name form object o.\r
+     Returns the attribute value on success, or NULL on failure.\r
+     This is the equivalent of the Python expression: o.attr_name.\r
+\r
+       */\r
+\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     int PyObject_SetAttrString(PyObject *o, char *attr_name, PyObject *v);\r
+\r
+     Set the value of the attribute named attr_name, for object o,\r
+     to the value, v. Returns -1 on failure.  This is\r
+     the equivalent of the Python statement: o.attr_name=v.\r
+\r
+       */\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v);\r
+\r
+     Set the value of the attribute named attr_name, for object o,\r
+     to the value, v. Returns -1 on failure.  This is\r
+     the equivalent of the Python statement: o.attr_name=v.\r
+\r
+       */\r
+\r
+     /* implemented as a macro:\r
+\r
+     int PyObject_DelAttrString(PyObject *o, char *attr_name);\r
+\r
+     Delete attribute named attr_name, for object o. Returns\r
+     -1 on failure.  This is the equivalent of the Python\r
+     statement: del o.attr_name.\r
+\r
+       */\r
+#define  PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A),NULL)\r
+\r
+     /* implemented as a macro:\r
+\r
+     int PyObject_DelAttr(PyObject *o, PyObject *attr_name);\r
+\r
+     Delete attribute named attr_name, for object o. Returns -1\r
+     on failure.  This is the equivalent of the Python\r
+     statement: del o.attr_name.\r
+\r
+       */\r
+#define  PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A),NULL)\r
+\r
+     PyAPI_FUNC(int) PyObject_Cmp(PyObject *o1, PyObject *o2, int *result);\r
+\r
+       /*\r
+     Compare the values of o1 and o2 using a routine provided by\r
+     o1, if one exists, otherwise with a routine provided by o2.\r
+     The result of the comparison is returned in result.  Returns\r
+     -1 on failure.  This is the equivalent of the Python\r
+     statement: result=cmp(o1,o2).\r
+\r
+       */\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     int PyObject_Compare(PyObject *o1, PyObject *o2);\r
+\r
+     Compare the values of o1 and o2 using a routine provided by\r
+     o1, if one exists, otherwise with a routine provided by o2.\r
+     Returns the result of the comparison on success.  On error,\r
+     the value returned is undefined. This is equivalent to the\r
+     Python expression: cmp(o1,o2).\r
+\r
+       */\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     PyObject *PyObject_Repr(PyObject *o);\r
+\r
+     Compute the string representation of object, o.  Returns the\r
+     string representation on success, NULL on failure.  This is\r
+     the equivalent of the Python expression: repr(o).\r
+\r
+     Called by the repr() built-in function and by reverse quotes.\r
+\r
+       */\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     PyObject *PyObject_Str(PyObject *o);\r
+\r
+     Compute the string representation of object, o.  Returns the\r
+     string representation on success, NULL on failure.  This is\r
+     the equivalent of the Python expression: str(o).)\r
+\r
+     Called by the str() built-in function and by the print\r
+     statement.\r
+\r
+       */\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     PyObject *PyObject_Unicode(PyObject *o);\r
+\r
+     Compute the unicode representation of object, o.  Returns the\r
+     unicode representation on success, NULL on failure.  This is\r
+     the equivalent of the Python expression: unistr(o).)\r
+\r
+     Called by the unistr() built-in function.\r
+\r
+       */\r
+\r
+       /* Declared elsewhere\r
+\r
+     PyAPI_FUNC(int) PyCallable_Check(PyObject *o);\r
+\r
+     Determine if the object, o, is callable.  Return 1 if the\r
+     object is callable and 0 otherwise.\r
+\r
+     This function always succeeds.\r
+\r
+       */\r
+\r
+\r
+\r
+     PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable_object,\r
+                                         PyObject *args, PyObject *kw);\r
+\r
+       /*\r
+     Call a callable Python object, callable_object, with\r
+     arguments and keywords arguments.  The 'args' argument can not be\r
+     NULL, but the 'kw' argument can be NULL.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable_object,\r
+                                               PyObject *args);\r
+\r
+       /*\r
+     Call a callable Python object, callable_object, with\r
+     arguments given by the tuple, args.  If no arguments are\r
+     needed, then args may be NULL.  Returns the result of the\r
+     call on success, or NULL on failure.  This is the equivalent\r
+     of the Python expression: apply(o,args).\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable_object,\r
+                                                 char *format, ...);\r
+\r
+       /*\r
+     Call a callable Python object, callable_object, with a\r
+     variable number of C arguments. The C arguments are described\r
+     using a mkvalue-style format string. The format may be NULL,\r
+     indicating that no arguments are provided.  Returns the\r
+     result of the call on success, or NULL on failure.  This is\r
+     the equivalent of the Python expression: apply(o,args).\r
+\r
+       */\r
+\r
+\r
+     PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *o, char *m,\r
+                                               char *format, ...);\r
+\r
+       /*\r
+     Call the method named m of object o with a variable number of\r
+     C arguments.  The C arguments are described by a mkvalue\r
+     format string.  The format may be NULL, indicating that no\r
+     arguments are provided. Returns the result of the call on\r
+     success, or NULL on failure.  This is the equivalent of the\r
+     Python expression: o.method(args).\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,\r
+                                                         char *format, ...);\r
+     PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *o,\r
+                                                       char *name,\r
+                                                       char *format, ...);\r
+\r
+     PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,\r
+                                                        ...);\r
+\r
+       /*\r
+     Call a callable Python object, callable_object, with a\r
+     variable number of C arguments.  The C arguments are provided\r
+     as PyObject * values, terminated by a NULL.  Returns the\r
+     result of the call on success, or NULL on failure.  This is\r
+     the equivalent of the Python expression: apply(o,args).\r
+       */\r
+\r
+\r
+     PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(PyObject *o,\r
+                                                      PyObject *m, ...);\r
+\r
+       /*\r
+     Call the method named m of object o with a variable number of\r
+     C arguments.  The C arguments are provided as PyObject *\r
+     values, terminated by NULL.  Returns the result of the call\r
+     on success, or NULL on failure.  This is the equivalent of\r
+     the Python expression: o.method(args).\r
+       */\r
+\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     long PyObject_Hash(PyObject *o);\r
+\r
+     Compute and return the hash, hash_value, of an object, o.  On\r
+     failure, return -1.  This is the equivalent of the Python\r
+     expression: hash(o).\r
+\r
+       */\r
+\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     int PyObject_IsTrue(PyObject *o);\r
+\r
+     Returns 1 if the object, o, is considered to be true, 0 if o is\r
+     considered to be false and -1 on failure. This is equivalent to the\r
+     Python expression: not not o\r
+\r
+       */\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     int PyObject_Not(PyObject *o);\r
+\r
+     Returns 0 if the object, o, is considered to be true, 1 if o is\r
+     considered to be false and -1 on failure. This is equivalent to the\r
+     Python expression: not o\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o);\r
+\r
+       /*\r
+     On success, returns a type object corresponding to the object\r
+     type of object o. On failure, returns NULL.  This is\r
+     equivalent to the Python expression: type(o).\r
+       */\r
+\r
+     PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o);\r
+\r
+       /*\r
+     Return the size of object o.  If the object, o, provides\r
+     both sequence and mapping protocols, the sequence size is\r
+     returned. On error, -1 is returned.  This is the equivalent\r
+     to the Python expression: len(o).\r
+\r
+       */\r
+\r
+       /* For DLL compatibility */\r
+#undef PyObject_Length\r
+     PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);\r
+#define PyObject_Length PyObject_Size\r
+\r
+     PyAPI_FUNC(Py_ssize_t) _PyObject_LengthHint(PyObject *o, Py_ssize_t);\r
+\r
+       /*\r
+     Guess the size of object o using len(o) or o.__length_hint__().\r
+     If neither of those return a non-negative value, then return the\r
+     default value.  If one of the calls fails, this function returns -1.\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);\r
+\r
+       /*\r
+     Return element of o corresponding to the object, key, or NULL\r
+     on failure. This is the equivalent of the Python expression:\r
+     o[key].\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);\r
+\r
+       /*\r
+     Map the object, key, to the value, v.  Returns\r
+     -1 on failure.  This is the equivalent of the Python\r
+     statement: o[key]=v.\r
+       */\r
+\r
+     PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, char *key);\r
+\r
+       /*\r
+     Remove the mapping for object, key, from the object *o.\r
+     Returns -1 on failure.  This is equivalent to\r
+     the Python statement: del o[key].\r
+       */\r
+\r
+     PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);\r
+\r
+       /*\r
+     Delete the mapping for key from *o.  Returns -1 on failure.\r
+     This is the equivalent of the Python statement: del o[key].\r
+       */\r
+\r
+     PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,\r
+                                          const char **buffer,\r
+                                          Py_ssize_t *buffer_len);\r
+\r
+       /*\r
+      Takes an arbitrary object which must support the (character,\r
+      single segment) buffer interface and returns a pointer to a\r
+      read-only memory location useable as character based input\r
+      for subsequent processing.\r
+\r
+      0 is returned on success.  buffer and buffer_len are only\r
+      set in case no error occurs. Otherwise, -1 is returned and\r
+      an exception set.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);\r
+\r
+      /*\r
+      Checks whether an arbitrary object supports the (character,\r
+      single segment) buffer interface.  Returns 1 on success, 0\r
+      on failure.\r
+\r
+      */\r
+\r
+     PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,\r
+                                          const void **buffer,\r
+                                          Py_ssize_t *buffer_len);\r
+\r
+       /*\r
+      Same as PyObject_AsCharBuffer() except that this API expects\r
+      (readable, single segment) buffer interface and returns a\r
+      pointer to a read-only memory location which can contain\r
+      arbitrary data.\r
+\r
+      0 is returned on success.  buffer and buffer_len are only\r
+      set in case no error occurs.  Otherwise, -1 is returned and\r
+      an exception set.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,\r
+                                           void **buffer,\r
+                                           Py_ssize_t *buffer_len);\r
+\r
+       /*\r
+      Takes an arbitrary object which must support the (writeable,\r
+      single segment) buffer interface and returns a pointer to a\r
+      writeable memory location in buffer of size buffer_len.\r
+\r
+      0 is returned on success.  buffer and buffer_len are only\r
+      set in case no error occurs. Otherwise, -1 is returned and\r
+      an exception set.\r
+\r
+       */\r
+\r
+    /* new buffer API */\r
+\r
+#define PyObject_CheckBuffer(obj) \\r
+    (((obj)->ob_type->tp_as_buffer != NULL) &&                          \\r
+     (PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_NEWBUFFER)) && \\r
+     ((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL))\r
+\r
+    /* Return 1 if the getbuffer function is available, otherwise\r
+       return 0 */\r
+\r
+     PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view,\r
+                                        int flags);\r
+\r
+    /* This is a C-API version of the getbuffer function call.  It checks\r
+       to make sure object has the required function pointer and issues the\r
+       call.  Returns -1 and raises an error on failure and returns 0 on\r
+       success\r
+    */\r
+\r
+\r
+     PyAPI_FUNC(void *) PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices);\r
+\r
+    /* Get the memory area pointed to by the indices for the buffer given.\r
+       Note that view->ndim is the assumed size of indices\r
+    */\r
+\r
+     PyAPI_FUNC(int) PyBuffer_SizeFromFormat(const char *);\r
+\r
+    /* Return the implied itemsize of the data-format area from a\r
+       struct-style description */\r
+\r
+\r
+\r
+     PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, Py_buffer *view,\r
+                                           Py_ssize_t len, char fort);\r
+\r
+     PyAPI_FUNC(int) PyBuffer_FromContiguous(Py_buffer *view, void *buf,\r
+                                             Py_ssize_t len, char fort);\r
+\r
+\r
+    /* Copy len bytes of data from the contiguous chunk of memory\r
+       pointed to by buf into the buffer exported by obj.  Return\r
+       0 on success and return -1 and raise a PyBuffer_Error on\r
+       error (i.e. the object does not have a buffer interface or\r
+       it is not working).\r
+\r
+       If fort is 'F' and the object is multi-dimensional,\r
+       then the data will be copied into the array in\r
+       Fortran-style (first dimension varies the fastest).  If\r
+       fort is 'C', then the data will be copied into the array\r
+       in C-style (last dimension varies the fastest).  If fort\r
+       is 'A', then it does not matter and the copy will be made\r
+       in whatever way is more efficient.\r
+\r
+    */\r
+\r
+     PyAPI_FUNC(int) PyObject_CopyData(PyObject *dest, PyObject *src);\r
+\r
+    /* Copy the data from the src buffer to the buffer of destination\r
+     */\r
+\r
+     PyAPI_FUNC(int) PyBuffer_IsContiguous(Py_buffer *view, char fort);\r
+\r
+\r
+     PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims,\r
+                                                    Py_ssize_t *shape,\r
+                                                    Py_ssize_t *strides,\r
+                                                    int itemsize,\r
+                                                    char fort);\r
+\r
+    /*  Fill the strides array with byte-strides of a contiguous\r
+        (Fortran-style if fort is 'F' or C-style otherwise)\r
+        array of the given shape with the given number of bytes\r
+        per element.\r
+    */\r
+\r
+     PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf,\r
+                                       Py_ssize_t len, int readonly,\r
+                                       int flags);\r
+\r
+    /* Fills in a buffer-info structure correctly for an exporter\r
+       that can only share a contiguous chunk of memory of\r
+       "unsigned bytes" of the given length. Returns 0 on success\r
+       and -1 (with raising an error) on error.\r
+     */\r
+\r
+     PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view);\r
+\r
+       /* Releases a Py_buffer obtained from getbuffer ParseTuple's s*.\r
+    */\r
+\r
+     PyAPI_FUNC(PyObject *) PyObject_Format(PyObject* obj,\r
+                                            PyObject *format_spec);\r
+       /*\r
+     Takes an arbitrary object and returns the result of\r
+     calling obj.__format__(format_spec).\r
+       */\r
+\r
+/* Iterators */\r
+\r
+     PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);\r
+     /* Takes an object and returns an iterator for it.\r
+    This is typically a new iterator but if the argument\r
+    is an iterator, this returns itself. */\r
+\r
+#define PyIter_Check(obj) \\r
+    (PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_ITER) && \\r
+     (obj)->ob_type->tp_iternext != NULL && \\r
+     (obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented)\r
+\r
+     PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);\r
+     /* Takes an iterator object and calls its tp_iternext slot,\r
+    returning the next value.  If the iterator is exhausted,\r
+    this returns NULL without setting an exception.\r
+    NULL with an exception means an error occurred. */\r
+\r
+/*  Number Protocol:*/\r
+\r
+     PyAPI_FUNC(int) PyNumber_Check(PyObject *o);\r
+\r
+       /*\r
+     Returns 1 if the object, o, provides numeric protocols, and\r
+     false otherwise.\r
+\r
+     This function always succeeds.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of adding o1 and o2, or null on failure.\r
+     This is the equivalent of the Python expression: o1+o2.\r
+\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of subtracting o2 from o1, or null on\r
+     failure.  This is the equivalent of the Python expression:\r
+     o1-o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of multiplying o1 and o2, or null on\r
+     failure.  This is the equivalent of the Python expression:\r
+     o1*o2.\r
+\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Divide(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of dividing o1 by o2, or null on failure.\r
+     This is the equivalent of the Python expression: o1/o2.\r
+\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of dividing o1 by o2 giving an integral result,\r
+     or null on failure.\r
+     This is the equivalent of the Python expression: o1//o2.\r
+\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of dividing o1 by o2 giving a float result,\r
+     or null on failure.\r
+     This is the equivalent of the Python expression: o1/o2.\r
+\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the remainder of dividing o1 by o2, or null on\r
+     failure.  This is the equivalent of the Python expression:\r
+     o1%o2.\r
+\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     See the built-in function divmod.  Returns NULL on failure.\r
+     This is the equivalent of the Python expression:\r
+     divmod(o1,o2).\r
+\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,\r
+                                          PyObject *o3);\r
+\r
+       /*\r
+     See the built-in function pow.  Returns NULL on failure.\r
+     This is the equivalent of the Python expression:\r
+     pow(o1,o2,o3), where o3 is optional.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o);\r
+\r
+       /*\r
+     Returns the negation of o on success, or null on failure.\r
+     This is the equivalent of the Python expression: -o.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o);\r
+\r
+       /*\r
+     Returns the (what?) of o on success, or NULL on failure.\r
+     This is the equivalent of the Python expression: +o.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o);\r
+\r
+       /*\r
+     Returns the absolute value of o, or null on failure.  This is\r
+     the equivalent of the Python expression: abs(o).\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o);\r
+\r
+       /*\r
+     Returns the bitwise negation of o on success, or NULL on\r
+     failure.  This is the equivalent of the Python expression:\r
+     ~o.\r
+\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of left shifting o1 by o2 on success, or\r
+     NULL on failure.  This is the equivalent of the Python\r
+     expression: o1 << o2.\r
+\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of right shifting o1 by o2 on success, or\r
+     NULL on failure.  This is the equivalent of the Python\r
+     expression: o1 >> o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of bitwise and of o1 and o2 on success, or\r
+     NULL on failure. This is the equivalent of the Python\r
+     expression: o1&o2.\r
+\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the bitwise exclusive or of o1 by o2 on success, or\r
+     NULL on failure.  This is the equivalent of the Python\r
+     expression: o1^o2.\r
+\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of bitwise or on o1 and o2 on success, or\r
+     NULL on failure.  This is the equivalent of the Python\r
+     expression: o1|o2.\r
+\r
+       */\r
+\r
+     /* Implemented elsewhere:\r
+\r
+     int PyNumber_Coerce(PyObject **p1, PyObject **p2);\r
+\r
+     This function takes the addresses of two variables of type\r
+     PyObject*.\r
+\r
+     If the objects pointed to by *p1 and *p2 have the same type,\r
+     increment their reference count and return 0 (success).\r
+     If the objects can be converted to a common numeric type,\r
+     replace *p1 and *p2 by their converted value (with 'new'\r
+     reference counts), and return 0.\r
+     If no conversion is possible, or if some other error occurs,\r
+     return -1 (failure) and don't increment the reference counts.\r
+     The call PyNumber_Coerce(&o1, &o2) is equivalent to the Python\r
+     statement o1, o2 = coerce(o1, o2).\r
+\r
+       */\r
+\r
+#define PyIndex_Check(obj) \\r
+   ((obj)->ob_type->tp_as_number != NULL && \\r
+    PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_INDEX) && \\r
+    (obj)->ob_type->tp_as_number->nb_index != NULL)\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o);\r
+\r
+       /*\r
+     Returns the object converted to a Python long or int\r
+     or NULL with an error raised on failure.\r
+       */\r
+\r
+     PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);\r
+\r
+       /*\r
+     Returns the Integral instance converted to an int. The\r
+     instance is expected to be int or long or have an __int__\r
+     method. Steals integral's reference. error_format will be\r
+     used to create the TypeError if integral isn't actually an\r
+     Integral instance. error_format should be a format string\r
+     that can accept a char* naming integral's type.\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) _PyNumber_ConvertIntegralToInt(\r
+         PyObject *integral,\r
+         const char* error_format);\r
+\r
+       /*\r
+    Returns the object converted to Py_ssize_t by going through\r
+    PyNumber_Index first.  If an overflow error occurs while\r
+    converting the int-or-long to Py_ssize_t, then the second argument\r
+    is the error-type to return.  If it is NULL, then the overflow error\r
+    is cleared and the value is clipped.\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Int(PyObject *o);\r
+\r
+       /*\r
+     Returns the o converted to an integer object on success, or\r
+     NULL on failure.  This is the equivalent of the Python\r
+     expression: int(o).\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o);\r
+\r
+       /*\r
+     Returns the o converted to a long integer object on success,\r
+     or NULL on failure.  This is the equivalent of the Python\r
+     expression: long(o).\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o);\r
+\r
+       /*\r
+     Returns the o converted to a float object on success, or NULL\r
+     on failure.  This is the equivalent of the Python expression:\r
+     float(o).\r
+       */\r
+\r
+/*  In-place variants of (some of) the above number protocol functions */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of adding o2 to o1, possibly in-place, or null\r
+     on failure.  This is the equivalent of the Python expression:\r
+     o1 += o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of subtracting o2 from o1, possibly in-place or\r
+     null on failure.  This is the equivalent of the Python expression:\r
+     o1 -= o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of multiplying o1 by o2, possibly in-place, or\r
+     null on failure.  This is the equivalent of the Python expression:\r
+     o1 *= o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of dividing o1 by o2, possibly in-place, or null\r
+     on failure.  This is the equivalent of the Python expression:\r
+     o1 /= o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1,\r
+                                                       PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of dividing o1 by o2 giving an integral result,\r
+     possibly in-place, or null on failure.\r
+     This is the equivalent of the Python expression:\r
+     o1 /= o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1,\r
+                                                      PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of dividing o1 by o2 giving a float result,\r
+     possibly in-place, or null on failure.\r
+     This is the equivalent of the Python expression:\r
+     o1 /= o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the remainder of dividing o1 by o2, possibly in-place, or\r
+     null on failure.  This is the equivalent of the Python expression:\r
+     o1 %= o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,\r
+                                                 PyObject *o3);\r
+\r
+       /*\r
+     Returns the result of raising o1 to the power of o2, possibly\r
+     in-place, or null on failure.  This is the equivalent of the Python\r
+     expression: o1 **= o2, or pow(o1, o2, o3) if o3 is present.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of left shifting o1 by o2, possibly in-place, or\r
+     null on failure.  This is the equivalent of the Python expression:\r
+     o1 <<= o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of right shifting o1 by o2, possibly in-place or\r
+     null on failure.  This is the equivalent of the Python expression:\r
+     o1 >>= o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of bitwise and of o1 and o2, possibly in-place,\r
+     or null on failure. This is the equivalent of the Python\r
+     expression: o1 &= o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the bitwise exclusive or of o1 by o2, possibly in-place, or\r
+     null on failure.  This is the equivalent of the Python expression:\r
+     o1 ^= o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Returns the result of bitwise or of o1 and o2, possibly in-place,\r
+     or null on failure.  This is the equivalent of the Python\r
+     expression: o1 |= o2.\r
+\r
+       */\r
+\r
+\r
+     PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base);\r
+\r
+       /*\r
+     Returns the integer n converted to a string with a base, with a base\r
+     marker of 0b, 0o or 0x prefixed if applicable.\r
+     If n is not an int object, it is converted with PyNumber_Index first.\r
+       */\r
+\r
+\r
+/*  Sequence protocol:*/\r
+\r
+     PyAPI_FUNC(int) PySequence_Check(PyObject *o);\r
+\r
+       /*\r
+     Return 1 if the object provides sequence protocol, and zero\r
+     otherwise.\r
+\r
+     This function always succeeds.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o);\r
+\r
+       /*\r
+     Return the size of sequence object o, or -1 on failure.\r
+\r
+       */\r
+\r
+       /* For DLL compatibility */\r
+#undef PySequence_Length\r
+     PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o);\r
+#define PySequence_Length PySequence_Size\r
+\r
+\r
+     PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Return the concatenation of o1 and o2 on success, and NULL on\r
+     failure.   This is the equivalent of the Python\r
+     expression: o1+o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count);\r
+\r
+       /*\r
+     Return the result of repeating sequence object o count times,\r
+     or NULL on failure.  This is the equivalent of the Python\r
+     expression: o1*count.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i);\r
+\r
+       /*\r
+     Return the ith element of o, or NULL on failure. This is the\r
+     equivalent of the Python expression: o[i].\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);\r
+\r
+       /*\r
+     Return the slice of sequence object o between i1 and i2, or\r
+     NULL on failure. This is the equivalent of the Python\r
+     expression: o[i1:i2].\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);\r
+\r
+       /*\r
+     Assign object v to the ith element of o.  Returns\r
+     -1 on failure.  This is the equivalent of the Python\r
+     statement: o[i]=v.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);\r
+\r
+       /*\r
+     Delete the ith element of object v.  Returns\r
+     -1 on failure.  This is the equivalent of the Python\r
+     statement: del o[i].\r
+       */\r
+\r
+     PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2,\r
+                                        PyObject *v);\r
+\r
+       /*\r
+     Assign the sequence object, v, to the slice in sequence\r
+     object, o, from i1 to i2.  Returns -1 on failure. This is the\r
+     equivalent of the Python statement: o[i1:i2]=v.\r
+       */\r
+\r
+     PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);\r
+\r
+       /*\r
+     Delete the slice in sequence object, o, from i1 to i2.\r
+     Returns -1 on failure. This is the equivalent of the Python\r
+     statement: del o[i1:i2].\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o);\r
+\r
+       /*\r
+     Returns the sequence, o, as a tuple on success, and NULL on failure.\r
+     This is equivalent to the Python expression: tuple(o)\r
+       */\r
+\r
+\r
+     PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o);\r
+       /*\r
+     Returns the sequence, o, as a list on success, and NULL on failure.\r
+     This is equivalent to the Python expression: list(o)\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);\r
+       /*\r
+     Return the sequence, o, as a list, unless it's already a\r
+     tuple or list.  Use PySequence_Fast_GET_ITEM to access the\r
+     members of this list, and PySequence_Fast_GET_SIZE to get its length.\r
+\r
+     Returns NULL on failure.  If the object does not support iteration,\r
+     raises a TypeError exception with m as the message text.\r
+       */\r
+\r
+#define PySequence_Fast_GET_SIZE(o) \\r
+    (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))\r
+       /*\r
+     Return the size of o, assuming that o was returned by\r
+     PySequence_Fast and is not NULL.\r
+       */\r
+\r
+#define PySequence_Fast_GET_ITEM(o, i)\\r
+     (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))\r
+       /*\r
+     Return the ith element of o, assuming that o was returned by\r
+     PySequence_Fast, and that i is within bounds.\r
+       */\r
+\r
+#define PySequence_ITEM(o, i)\\r
+    ( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) )\r
+       /* Assume tp_as_sequence and sq_item exist and that i does not\r
+      need to be corrected for a negative index\r
+       */\r
+\r
+#define PySequence_Fast_ITEMS(sf) \\r
+    (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \\r
+                      : ((PyTupleObject *)(sf))->ob_item)\r
+    /* Return a pointer to the underlying item array for\r
+       an object retured by PySequence_Fast */\r
+\r
+     PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value);\r
+\r
+       /*\r
+     Return the number of occurrences on value on o, that is,\r
+     return the number of keys for which o[key]==value.  On\r
+     failure, return -1.  This is equivalent to the Python\r
+     expression: o.count(value).\r
+       */\r
+\r
+     PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob);\r
+       /*\r
+     Return -1 if error; 1 if ob in seq; 0 if ob not in seq.\r
+     Use __contains__ if possible, else _PySequence_IterSearch().\r
+       */\r
+\r
+#define PY_ITERSEARCH_COUNT    1\r
+#define PY_ITERSEARCH_INDEX    2\r
+#define PY_ITERSEARCH_CONTAINS 3\r
+     PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq,\r
+                                        PyObject *obj, int operation);\r
+    /*\r
+      Iterate over seq.  Result depends on the operation:\r
+      PY_ITERSEARCH_COUNT:  return # of times obj appears in seq; -1 if\r
+        error.\r
+      PY_ITERSEARCH_INDEX:  return 0-based index of first occurrence of\r
+        obj in seq; set ValueError and return -1 if none found;\r
+        also return -1 on error.\r
+      PY_ITERSEARCH_CONTAINS:  return 1 if obj in seq, else 0; -1 on\r
+        error.\r
+    */\r
+\r
+/* For DLL-level backwards compatibility */\r
+#undef PySequence_In\r
+     PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value);\r
+\r
+/* For source-level backwards compatibility */\r
+#define PySequence_In PySequence_Contains\r
+\r
+       /*\r
+     Determine if o contains value.  If an item in o is equal to\r
+     X, return 1, otherwise return 0.  On error, return -1.  This\r
+     is equivalent to the Python expression: value in o.\r
+       */\r
+\r
+     PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value);\r
+\r
+       /*\r
+     Return the first index for which o[i]=value.  On error,\r
+     return -1.    This is equivalent to the Python\r
+     expression: o.index(value).\r
+       */\r
+\r
+/* In-place versions of some of the above Sequence functions. */\r
+\r
+     PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);\r
+\r
+       /*\r
+     Append o2 to o1, in-place when possible. Return the resulting\r
+     object, which could be o1, or NULL on failure.  This is the\r
+     equivalent of the Python expression: o1 += o2.\r
+\r
+       */\r
+\r
+     PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count);\r
+\r
+       /*\r
+     Repeat o1 by count, in-place when possible. Return the resulting\r
+     object, which could be o1, or NULL on failure.  This is the\r
+     equivalent of the Python expression: o1 *= count.\r
+\r
+       */\r
+\r
+/*  Mapping protocol:*/\r
+\r
+     PyAPI_FUNC(int) PyMapping_Check(PyObject *o);\r
+\r
+       /*\r
+     Return 1 if the object provides mapping protocol, and zero\r
+     otherwise.\r
+\r
+     This function always succeeds.\r
+       */\r
+\r
+     PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o);\r
+\r
+       /*\r
+     Returns the number of keys in object o on success, and -1 on\r
+     failure.  For objects that do not provide sequence protocol,\r
+     this is equivalent to the Python expression: len(o).\r
+       */\r
+\r
+       /* For DLL compatibility */\r
+#undef PyMapping_Length\r
+     PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o);\r
+#define PyMapping_Length PyMapping_Size\r
+\r
+\r
+     /* implemented as a macro:\r
+\r
+     int PyMapping_DelItemString(PyObject *o, char *key);\r
+\r
+     Remove the mapping for object, key, from the object *o.\r
+     Returns -1 on failure.  This is equivalent to\r
+     the Python statement: del o[key].\r
+       */\r
+#define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K))\r
+\r
+     /* implemented as a macro:\r
+\r
+     int PyMapping_DelItem(PyObject *o, PyObject *key);\r
+\r
+     Remove the mapping for object, key, from the object *o.\r
+     Returns -1 on failure.  This is equivalent to\r
+     the Python statement: del o[key].\r
+       */\r
+#define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K))\r
+\r
+     PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, char *key);\r
+\r
+       /*\r
+     On success, return 1 if the mapping object has the key, key,\r
+     and 0 otherwise.  This is equivalent to the Python expression:\r
+     o.has_key(key).\r
+\r
+     This function always succeeds.\r
+       */\r
+\r
+     PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key);\r
+\r
+       /*\r
+     Return 1 if the mapping object has the key, key,\r
+     and 0 otherwise.  This is equivalent to the Python expression:\r
+     o.has_key(key).\r
+\r
+     This function always succeeds.\r
+\r
+       */\r
+\r
+     /* Implemented as macro:\r
+\r
+     PyObject *PyMapping_Keys(PyObject *o);\r
+\r
+     On success, return a list of the keys in object o.  On\r
+     failure, return NULL. This is equivalent to the Python\r
+     expression: o.keys().\r
+       */\r
+#define PyMapping_Keys(O) PyObject_CallMethod(O,"keys",NULL)\r
+\r
+     /* Implemented as macro:\r
+\r
+     PyObject *PyMapping_Values(PyObject *o);\r
+\r
+     On success, return a list of the values in object o.  On\r
+     failure, return NULL. This is equivalent to the Python\r
+     expression: o.values().\r
+       */\r
+#define PyMapping_Values(O) PyObject_CallMethod(O,"values",NULL)\r
+\r
+     /* Implemented as macro:\r
+\r
+     PyObject *PyMapping_Items(PyObject *o);\r
+\r
+     On success, return a list of the items in object o, where\r
+     each item is a tuple containing a key-value pair.  On\r
+     failure, return NULL. This is equivalent to the Python\r
+     expression: o.items().\r
+\r
+       */\r
+#define PyMapping_Items(O) PyObject_CallMethod(O,"items",NULL)\r
+\r
+     PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, char *key);\r
+\r
+       /*\r
+     Return element of o corresponding to the object, key, or NULL\r
+     on failure. This is the equivalent of the Python expression:\r
+     o[key].\r
+       */\r
+\r
+     PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, char *key,\r
+                                            PyObject *value);\r
+\r
+       /*\r
+     Map the object, key, to the value, v.  Returns\r
+     -1 on failure.  This is the equivalent of the Python\r
+     statement: o[key]=v.\r
+      */\r
+\r
+\r
+PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass);\r
+      /* isinstance(object, typeorclass) */\r
+\r
+PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);\r
+      /* issubclass(object, typeorclass) */\r
+\r
+\r
+PyAPI_FUNC(int) _PyObject_RealIsInstance(PyObject *inst, PyObject *cls);\r
+\r
+PyAPI_FUNC(int) _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls);\r
+\r
+\r
+/* For internal use by buffer API functions */\r
+PyAPI_FUNC(void) _Py_add_one_to_index_F(int nd, Py_ssize_t *index,\r
+                                        const Py_ssize_t *shape);\r
+PyAPI_FUNC(void) _Py_add_one_to_index_C(int nd, Py_ssize_t *index,\r
+                                        const Py_ssize_t *shape);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* Py_ABSTRACTOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/asdl.h b/AppPkg/Applications/Python/Python-2.7.10/Include/asdl.h
new file mode 100644 (file)
index 0000000..d72b2f8
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef Py_ASDL_H\r
+#define Py_ASDL_H\r
+\r
+typedef PyObject * identifier;\r
+typedef PyObject * string;\r
+typedef PyObject * object;\r
+\r
+#ifndef __cplusplus\r
+typedef enum {false, true} bool;\r
+#endif\r
+\r
+/* It would be nice if the code generated by asdl_c.py was completely\r
+   independent of Python, but it is a goal the requires too much work\r
+   at this stage.  So, for example, I'll represent identifiers as\r
+   interned Python strings.\r
+*/\r
+\r
+/* XXX A sequence should be typed so that its use can be typechecked. */\r
+\r
+typedef struct {\r
+    int size;\r
+    void *elements[1];\r
+} asdl_seq;\r
+\r
+typedef struct {\r
+    int size;\r
+    int elements[1];\r
+} asdl_int_seq;\r
+\r
+asdl_seq *asdl_seq_new(int size, PyArena *arena);\r
+asdl_int_seq *asdl_int_seq_new(int size, PyArena *arena);\r
+\r
+#define asdl_seq_GET(S, I) (S)->elements[(I)]\r
+#define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size)\r
+#ifdef Py_DEBUG\r
+#define asdl_seq_SET(S, I, V) { \\r
+        int _asdl_i = (I); \\r
+        assert((S) && _asdl_i < (S)->size); \\r
+        (S)->elements[_asdl_i] = (V); \\r
+}\r
+#else\r
+#define asdl_seq_SET(S, I, V) (S)->elements[I] = (V)\r
+#endif\r
+\r
+#endif /* !Py_ASDL_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/ast.h b/AppPkg/Applications/Python/Python-2.7.10/Include/ast.h
new file mode 100644 (file)
index 0000000..77dbe5f
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef Py_AST_H\r
+#define Py_AST_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_FUNC(mod_ty) PyAST_FromNode(const node *, PyCompilerFlags *flags,\r
+                                 const char *, PyArena *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_AST_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/bitset.h b/AppPkg/Applications/Python/Python-2.7.10/Include/bitset.h
new file mode 100644 (file)
index 0000000..028acdf
--- /dev/null
@@ -0,0 +1,32 @@
+\r
+#ifndef Py_BITSET_H\r
+#define Py_BITSET_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Bitset interface */\r
+\r
+#define BYTE           char\r
+\r
+typedef BYTE *bitset;\r
+\r
+bitset newbitset(int nbits);\r
+void delbitset(bitset bs);\r
+#define testbit(ss, ibit) (((ss)[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0)\r
+int addbit(bitset bs, int ibit); /* Returns 0 if already set */\r
+int samebitset(bitset bs1, bitset bs2, int nbits);\r
+void mergebitset(bitset bs1, bitset bs2, int nbits);\r
+\r
+#define BITSPERBYTE    (8*sizeof(BYTE))\r
+#define NBYTES(nbits)  (((nbits) + BITSPERBYTE - 1) / BITSPERBYTE)\r
+\r
+#define BIT2BYTE(ibit) ((ibit) / BITSPERBYTE)\r
+#define BIT2SHIFT(ibit)        ((ibit) % BITSPERBYTE)\r
+#define BIT2MASK(ibit) (1 << BIT2SHIFT(ibit))\r
+#define BYTE2BIT(ibyte)        ((ibyte) * BITSPERBYTE)\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_BITSET_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/boolobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/boolobject.h
new file mode 100644 (file)
index 0000000..9dd0e43
--- /dev/null
@@ -0,0 +1,36 @@
+/* Boolean object interface */\r
+\r
+#ifndef Py_BOOLOBJECT_H\r
+#define Py_BOOLOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+typedef PyIntObject PyBoolObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PyBool_Type;\r
+\r
+#define PyBool_Check(x) (Py_TYPE(x) == &PyBool_Type)\r
+\r
+/* Py_False and Py_True are the only two bools in existence.\r
+Don't forget to apply Py_INCREF() when returning either!!! */\r
+\r
+/* Don't use these directly */\r
+PyAPI_DATA(PyIntObject) _Py_ZeroStruct, _Py_TrueStruct;\r
+\r
+/* Use these macros */\r
+#define Py_False ((PyObject *) &_Py_ZeroStruct)\r
+#define Py_True ((PyObject *) &_Py_TrueStruct)\r
+\r
+/* Macros for returning Py_True or Py_False, respectively */\r
+#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True\r
+#define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False\r
+\r
+/* Function to return a bool from a C long */\r
+PyAPI_FUNC(PyObject *) PyBool_FromLong(long);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_BOOLOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/bufferobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/bufferobject.h
new file mode 100644 (file)
index 0000000..6c33a8b
--- /dev/null
@@ -0,0 +1,33 @@
+\r
+/* Buffer object interface */\r
+\r
+/* Note: the object's structure is private */\r
+\r
+#ifndef Py_BUFFEROBJECT_H\r
+#define Py_BUFFEROBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+PyAPI_DATA(PyTypeObject) PyBuffer_Type;\r
+\r
+#define PyBuffer_Check(op) (Py_TYPE(op) == &PyBuffer_Type)\r
+\r
+#define Py_END_OF_BUFFER       (-1)\r
+\r
+PyAPI_FUNC(PyObject *) PyBuffer_FromObject(PyObject *base,\r
+                                           Py_ssize_t offset, Py_ssize_t size);\r
+PyAPI_FUNC(PyObject *) PyBuffer_FromReadWriteObject(PyObject *base,\r
+                                                    Py_ssize_t offset,\r
+                                                    Py_ssize_t size);\r
+\r
+PyAPI_FUNC(PyObject *) PyBuffer_FromMemory(void *ptr, Py_ssize_t size);\r
+PyAPI_FUNC(PyObject *) PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size);\r
+\r
+PyAPI_FUNC(PyObject *) PyBuffer_New(Py_ssize_t size);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_BUFFEROBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/bytearrayobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/bytearrayobject.h
new file mode 100644 (file)
index 0000000..6d5af4d
--- /dev/null
@@ -0,0 +1,57 @@
+/* ByteArray object interface */\r
+\r
+#ifndef Py_BYTEARRAYOBJECT_H\r
+#define Py_BYTEARRAYOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#include <stdarg.h>\r
+\r
+/* Type PyByteArrayObject represents a mutable array of bytes.\r
+ * The Python API is that of a sequence;\r
+ * the bytes are mapped to ints in [0, 256).\r
+ * Bytes are not characters; they may be used to encode characters.\r
+ * The only way to go between bytes and str/unicode is via encoding\r
+ * and decoding.\r
+ * For the convenience of C programmers, the bytes type is considered\r
+ * to contain a char pointer, not an unsigned char pointer.\r
+ */\r
+\r
+/* Object layout */\r
+typedef struct {\r
+    PyObject_VAR_HEAD\r
+    /* XXX(nnorwitz): should ob_exports be Py_ssize_t? */\r
+    int ob_exports; /* how many buffer exports */\r
+    Py_ssize_t ob_alloc; /* How many bytes allocated */\r
+    char *ob_bytes;\r
+} PyByteArrayObject;\r
+\r
+/* Type object */\r
+PyAPI_DATA(PyTypeObject) PyByteArray_Type;\r
+PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type;\r
+\r
+/* Type check macros */\r
+#define PyByteArray_Check(self) PyObject_TypeCheck(self, &PyByteArray_Type)\r
+#define PyByteArray_CheckExact(self) (Py_TYPE(self) == &PyByteArray_Type)\r
+\r
+/* Direct API functions */\r
+PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyByteArray_Concat(PyObject *, PyObject *);\r
+PyAPI_FUNC(PyObject *) PyByteArray_FromStringAndSize(const char *, Py_ssize_t);\r
+PyAPI_FUNC(Py_ssize_t) PyByteArray_Size(PyObject *);\r
+PyAPI_FUNC(char *) PyByteArray_AsString(PyObject *);\r
+PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t);\r
+\r
+/* Macros, trading safety for speed */\r
+#define PyByteArray_AS_STRING(self) \\r
+    (assert(PyByteArray_Check(self)), \\r
+     Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_bytes : _PyByteArray_empty_string)\r
+#define PyByteArray_GET_SIZE(self)  (assert(PyByteArray_Check(self)),Py_SIZE(self))\r
+\r
+PyAPI_DATA(char) _PyByteArray_empty_string[];\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_BYTEARRAYOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/bytes_methods.h b/AppPkg/Applications/Python/Python-2.7.10/Include/bytes_methods.h
new file mode 100644 (file)
index 0000000..64ba0aa
--- /dev/null
@@ -0,0 +1,75 @@
+#ifndef Py_BYTES_CTYPE_H\r
+#define Py_BYTES_CTYPE_H\r
+\r
+/*\r
+ * The internal implementation behind PyString (bytes) and PyBytes (buffer)\r
+ * methods of the given names, they operate on ASCII byte strings.\r
+ */\r
+extern PyObject* _Py_bytes_isspace(const char *cptr, Py_ssize_t len);\r
+extern PyObject* _Py_bytes_isalpha(const char *cptr, Py_ssize_t len);\r
+extern PyObject* _Py_bytes_isalnum(const char *cptr, Py_ssize_t len);\r
+extern PyObject* _Py_bytes_isdigit(const char *cptr, Py_ssize_t len);\r
+extern PyObject* _Py_bytes_islower(const char *cptr, Py_ssize_t len);\r
+extern PyObject* _Py_bytes_isupper(const char *cptr, Py_ssize_t len);\r
+extern PyObject* _Py_bytes_istitle(const char *cptr, Py_ssize_t len);\r
+\r
+/* These store their len sized answer in the given preallocated *result arg. */\r
+extern void _Py_bytes_lower(char *result, const char *cptr, Py_ssize_t len);\r
+extern void _Py_bytes_upper(char *result, const char *cptr, Py_ssize_t len);\r
+extern void _Py_bytes_title(char *result, char *s, Py_ssize_t len);\r
+extern void _Py_bytes_capitalize(char *result, char *s, Py_ssize_t len);\r
+extern void _Py_bytes_swapcase(char *result, char *s, Py_ssize_t len);\r
+\r
+/* Shared __doc__ strings. */\r
+extern const char _Py_isspace__doc__[];\r
+extern const char _Py_isalpha__doc__[];\r
+extern const char _Py_isalnum__doc__[];\r
+extern const char _Py_isdigit__doc__[];\r
+extern const char _Py_islower__doc__[];\r
+extern const char _Py_isupper__doc__[];\r
+extern const char _Py_istitle__doc__[];\r
+extern const char _Py_lower__doc__[];\r
+extern const char _Py_upper__doc__[];\r
+extern const char _Py_title__doc__[];\r
+extern const char _Py_capitalize__doc__[];\r
+extern const char _Py_swapcase__doc__[];\r
+\r
+/* These are left in for backward compatibility and will be removed\r
+   in 2.8/3.2 */\r
+#define ISLOWER(c)  Py_ISLOWER(c)\r
+#define ISUPPER(c)  Py_ISUPPER(c)\r
+#define ISALPHA(c)  Py_ISALPHA(c)\r
+#define ISDIGIT(c)  Py_ISDIGIT(c)\r
+#define ISXDIGIT(c) Py_ISXDIGIT(c)\r
+#define ISALNUM(c)  Py_ISALNUM(c)\r
+#define ISSPACE(c)  Py_ISSPACE(c)\r
+\r
+#undef islower\r
+#define islower(c) undefined_islower(c)\r
+#undef isupper\r
+#define isupper(c) undefined_isupper(c)\r
+#undef isalpha\r
+#define isalpha(c) undefined_isalpha(c)\r
+#undef isdigit\r
+#define isdigit(c) undefined_isdigit(c)\r
+#undef isxdigit\r
+#define isxdigit(c) undefined_isxdigit(c)\r
+#undef isalnum\r
+#define isalnum(c) undefined_isalnum(c)\r
+#undef isspace\r
+#define isspace(c) undefined_isspace(c)\r
+\r
+/* These are left in for backward compatibility and will be removed\r
+   in 2.8/3.2 */\r
+#define TOLOWER(c) Py_TOLOWER(c)\r
+#define TOUPPER(c) Py_TOUPPER(c)\r
+\r
+#undef tolower\r
+#define tolower(c) undefined_tolower(c)\r
+#undef toupper\r
+#define toupper(c) undefined_toupper(c)\r
+\r
+/* this is needed because some docs are shared from the .o, not static */\r
+#define PyDoc_STRVAR_shared(name,str) const char name[] = PyDoc_STR(str)\r
+\r
+#endif /* !Py_BYTES_CTYPE_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/bytesobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/bytesobject.h
new file mode 100644 (file)
index 0000000..d60bdc0
--- /dev/null
@@ -0,0 +1,27 @@
+#define PyBytesObject PyStringObject\r
+#define PyBytes_Type PyString_Type\r
+\r
+#define PyBytes_Check PyString_Check\r
+#define PyBytes_CheckExact PyString_CheckExact \r
+#define PyBytes_CHECK_INTERNED PyString_CHECK_INTERNED\r
+#define PyBytes_AS_STRING PyString_AS_STRING\r
+#define PyBytes_GET_SIZE PyString_GET_SIZE\r
+#define Py_TPFLAGS_BYTES_SUBCLASS Py_TPFLAGS_STRING_SUBCLASS\r
+\r
+#define PyBytes_FromStringAndSize PyString_FromStringAndSize\r
+#define PyBytes_FromString PyString_FromString\r
+#define PyBytes_FromFormatV PyString_FromFormatV\r
+#define PyBytes_FromFormat PyString_FromFormat\r
+#define PyBytes_Size PyString_Size\r
+#define PyBytes_AsString PyString_AsString\r
+#define PyBytes_Repr PyString_Repr\r
+#define PyBytes_Concat PyString_Concat\r
+#define PyBytes_ConcatAndDel PyString_ConcatAndDel\r
+#define _PyBytes_Resize _PyString_Resize\r
+#define _PyBytes_Eq _PyString_Eq\r
+#define PyBytes_Format PyString_Format\r
+#define _PyBytes_FormatLong _PyString_FormatLong\r
+#define PyBytes_DecodeEscape PyString_DecodeEscape\r
+#define _PyBytes_Join _PyString_Join\r
+#define PyBytes_AsStringAndSize PyString_AsStringAndSize\r
+#define _PyBytes_InsertThousandsGrouping _PyString_InsertThousandsGrouping\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/cStringIO.h b/AppPkg/Applications/Python/Python-2.7.10/Include/cStringIO.h
new file mode 100644 (file)
index 0000000..391309a
--- /dev/null
@@ -0,0 +1,73 @@
+#ifndef Py_CSTRINGIO_H\r
+#define Py_CSTRINGIO_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+/*\r
+\r
+  This header provides access to cStringIO objects from C.\r
+  Functions are provided for calling cStringIO objects and\r
+  macros are provided for testing whether you have cStringIO\r
+  objects.\r
+\r
+  Before calling any of the functions or macros, you must initialize\r
+  the routines with:\r
+\r
+    PycString_IMPORT\r
+\r
+  This would typically be done in your init function.\r
+\r
+*/\r
+\r
+#define PycStringIO_CAPSULE_NAME "cStringIO.cStringIO_CAPI"\r
+\r
+#define PycString_IMPORT \\r
+  PycStringIO = ((struct PycStringIO_CAPI*)PyCapsule_Import(\\r
+    PycStringIO_CAPSULE_NAME, 0))\r
+\r
+/* Basic functions to manipulate cStringIO objects from C */\r
+\r
+static struct PycStringIO_CAPI {\r
+\r
+ /* Read a string from an input object.  If the last argument\r
+    is -1, the remainder will be read.\r
+    */\r
+  int(*cread)(PyObject *, char **, Py_ssize_t);\r
+\r
+ /* Read a line from an input object.  Returns the length of the read\r
+    line as an int and a pointer inside the object buffer as char** (so\r
+    the caller doesn't have to provide its own buffer as destination).\r
+    */\r
+  int(*creadline)(PyObject *, char **);\r
+\r
+  /* Write a string to an output object*/\r
+  int(*cwrite)(PyObject *, const char *, Py_ssize_t);\r
+\r
+  /* Get the output object as a Python string (returns new reference). */\r
+  PyObject *(*cgetvalue)(PyObject *);\r
+\r
+  /* Create a new output object */\r
+  PyObject *(*NewOutput)(int);\r
+\r
+  /* Create an input object from a Python string\r
+     (copies the Python string reference).\r
+     */\r
+  PyObject *(*NewInput)(PyObject *);\r
+\r
+  /* The Python types for cStringIO input and output objects.\r
+     Note that you can do input on an output object.\r
+     */\r
+  PyTypeObject *InputType, *OutputType;\r
+\r
+} *PycStringIO;\r
+\r
+/* These can be used to test if you have one */\r
+#define PycStringIO_InputCheck(O) \\r
+  (Py_TYPE(O)==PycStringIO->InputType)\r
+#define PycStringIO_OutputCheck(O) \\r
+  (Py_TYPE(O)==PycStringIO->OutputType)\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_CSTRINGIO_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/cellobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/cellobject.h
new file mode 100644 (file)
index 0000000..8d27f35
--- /dev/null
@@ -0,0 +1,28 @@
+/* Cell object interface */\r
+\r
+#ifndef Py_CELLOBJECT_H\r
+#define Py_CELLOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct {\r
+       PyObject_HEAD\r
+       PyObject *ob_ref;       /* Content of the cell or NULL when empty */\r
+} PyCellObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PyCell_Type;\r
+\r
+#define PyCell_Check(op) (Py_TYPE(op) == &PyCell_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PyCell_New(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *);\r
+PyAPI_FUNC(int) PyCell_Set(PyObject *, PyObject *);\r
+\r
+#define PyCell_GET(op) (((PyCellObject *)(op))->ob_ref)\r
+#define PyCell_SET(op, v) (((PyCellObject *)(op))->ob_ref = v)\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_TUPLEOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/ceval.h b/AppPkg/Applications/Python/Python-2.7.10/Include/ceval.h
new file mode 100644 (file)
index 0000000..58b2ded
--- /dev/null
@@ -0,0 +1,153 @@
+#ifndef Py_CEVAL_H\r
+#define Py_CEVAL_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Interface to random parts in ceval.c */\r
+\r
+PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(\r
+    PyObject *, PyObject *, PyObject *);\r
+\r
+/* Inline this */\r
+#define PyEval_CallObject(func,arg) \\r
+    PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)\r
+\r
+PyAPI_FUNC(PyObject *) PyEval_CallFunction(PyObject *obj,\r
+                                           const char *format, ...);\r
+PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj,\r
+                                         const char *methodname,\r
+                                         const char *format, ...);\r
+\r
+PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);\r
+PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);\r
+\r
+struct _frame; /* Avoid including frameobject.h */\r
+\r
+PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void);\r
+PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void);\r
+PyAPI_FUNC(PyObject *) PyEval_GetLocals(void);\r
+PyAPI_FUNC(struct _frame *) PyEval_GetFrame(void);\r
+PyAPI_FUNC(int) PyEval_GetRestricted(void);\r
+\r
+/* Look at the current frame's (if any) code's co_flags, and turn on\r
+   the corresponding compiler flags in cf->cf_flags.  Return 1 if any\r
+   flag was set, else return 0. */\r
+PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);\r
+\r
+PyAPI_FUNC(int) Py_FlushLine(void);\r
+\r
+PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);\r
+PyAPI_FUNC(int) Py_MakePendingCalls(void);\r
+\r
+/* Protection against deeply nested recursive calls */\r
+PyAPI_FUNC(void) Py_SetRecursionLimit(int);\r
+PyAPI_FUNC(int) Py_GetRecursionLimit(void);\r
+\r
+#define Py_EnterRecursiveCall(where)                                    \\r
+            (_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) &&  \\r
+             _Py_CheckRecursiveCall(where))\r
+#define Py_LeaveRecursiveCall()                         \\r
+            (--PyThreadState_GET()->recursion_depth)\r
+PyAPI_FUNC(int) _Py_CheckRecursiveCall(char *where);\r
+PyAPI_DATA(int) _Py_CheckRecursionLimit;\r
+#ifdef USE_STACKCHECK\r
+#  define _Py_MakeRecCheck(x)  (++(x) > --_Py_CheckRecursionLimit)\r
+#else\r
+#  define _Py_MakeRecCheck(x)  (++(x) > _Py_CheckRecursionLimit)\r
+#endif\r
+\r
+PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *);\r
+PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);\r
+\r
+PyAPI_FUNC(PyObject *) PyEval_GetCallStats(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *);\r
+PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);\r
+\r
+/* this used to be handled on a per-thread basis - now just two globals */\r
+PyAPI_DATA(volatile int) _Py_Ticker;\r
+PyAPI_DATA(int) _Py_CheckInterval;\r
+\r
+/* Interface for threads.\r
+\r
+   A module that plans to do a blocking system call (or something else\r
+   that lasts a long time and doesn't touch Python data) can allow other\r
+   threads to run as follows:\r
+\r
+    ...preparations here...\r
+    Py_BEGIN_ALLOW_THREADS\r
+    ...blocking system call here...\r
+    Py_END_ALLOW_THREADS\r
+    ...interpret result here...\r
+\r
+   The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a\r
+   {}-surrounded block.\r
+   To leave the block in the middle (e.g., with return), you must insert\r
+   a line containing Py_BLOCK_THREADS before the return, e.g.\r
+\r
+    if (...premature_exit...) {\r
+        Py_BLOCK_THREADS\r
+        PyErr_SetFromErrno(PyExc_IOError);\r
+        return NULL;\r
+    }\r
+\r
+   An alternative is:\r
+\r
+    Py_BLOCK_THREADS\r
+    if (...premature_exit...) {\r
+        PyErr_SetFromErrno(PyExc_IOError);\r
+        return NULL;\r
+    }\r
+    Py_UNBLOCK_THREADS\r
+\r
+   For convenience, that the value of 'errno' is restored across\r
+   Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.\r
+\r
+   WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND\r
+   Py_END_ALLOW_THREADS!!!\r
+\r
+   The function PyEval_InitThreads() should be called only from\r
+   initthread() in "threadmodule.c".\r
+\r
+   Note that not yet all candidates have been converted to use this\r
+   mechanism!\r
+*/\r
+\r
+PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);\r
+PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);\r
+\r
+#ifdef WITH_THREAD\r
+\r
+PyAPI_FUNC(int)  PyEval_ThreadsInitialized(void);\r
+PyAPI_FUNC(void) PyEval_InitThreads(void);\r
+PyAPI_FUNC(void) PyEval_AcquireLock(void);\r
+PyAPI_FUNC(void) PyEval_ReleaseLock(void);\r
+PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);\r
+PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);\r
+PyAPI_FUNC(void) PyEval_ReInitThreads(void);\r
+\r
+#define Py_BEGIN_ALLOW_THREADS { \\r
+                        PyThreadState *_save; \\r
+                        _save = PyEval_SaveThread();\r
+#define Py_BLOCK_THREADS        PyEval_RestoreThread(_save);\r
+#define Py_UNBLOCK_THREADS      _save = PyEval_SaveThread();\r
+#define Py_END_ALLOW_THREADS    PyEval_RestoreThread(_save); \\r
+                 }\r
+\r
+#else /* !WITH_THREAD */\r
+\r
+#define Py_BEGIN_ALLOW_THREADS {\r
+#define Py_BLOCK_THREADS\r
+#define Py_UNBLOCK_THREADS\r
+#define Py_END_ALLOW_THREADS }\r
+\r
+#endif /* !WITH_THREAD */\r
+\r
+PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_CEVAL_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/classobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/classobject.h
new file mode 100644 (file)
index 0000000..8e42e53
--- /dev/null
@@ -0,0 +1,83 @@
+\r
+/* Class object interface */\r
+\r
+/* Revealing some structures (not for general use) */\r
+\r
+#ifndef Py_CLASSOBJECT_H\r
+#define Py_CLASSOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    PyObject   *cl_bases;      /* A tuple of class objects */\r
+    PyObject   *cl_dict;       /* A dictionary */\r
+    PyObject   *cl_name;       /* A string */\r
+    /* The following three are functions or NULL */\r
+    PyObject   *cl_getattr;\r
+    PyObject   *cl_setattr;\r
+    PyObject   *cl_delattr;\r
+    PyObject    *cl_weakreflist; /* List of weak references */\r
+} PyClassObject;\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    PyClassObject *in_class;   /* The class object */\r
+    PyObject     *in_dict;     /* A dictionary */\r
+    PyObject     *in_weakreflist; /* List of weak references */\r
+} PyInstanceObject;\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    PyObject *im_func;   /* The callable object implementing the method */\r
+    PyObject *im_self;   /* The instance it is bound to, or NULL */\r
+    PyObject *im_class;  /* The class that asked for the method */\r
+    PyObject *im_weakreflist; /* List of weak references */\r
+} PyMethodObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PyClass_Type, PyInstance_Type, PyMethod_Type;\r
+\r
+#define PyClass_Check(op) ((op)->ob_type == &PyClass_Type)\r
+#define PyInstance_Check(op) ((op)->ob_type == &PyInstance_Type)\r
+#define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *);\r
+PyAPI_FUNC(PyObject *) PyInstance_New(PyObject *, PyObject *,\r
+                                            PyObject *);\r
+PyAPI_FUNC(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *);\r
+PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);\r
+\r
+PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyMethod_Class(PyObject *);\r
+\r
+/* Look up attribute with name (a string) on instance object pinst, using\r
+ * only the instance and base class dicts.  If a descriptor is found in\r
+ * a class dict, the descriptor is returned without calling it.\r
+ * Returns NULL if nothing found, else a borrowed reference to the\r
+ * value associated with name in the dict in which name was found.\r
+ * The point of this routine is that it never calls arbitrary Python\r
+ * code, so is always "safe":  all it does is dict lookups.  The function\r
+ * can't fail, never sets an exception, and NULL is not an error (it just\r
+ * means "not found").\r
+ */\r
+PyAPI_FUNC(PyObject *) _PyInstance_Lookup(PyObject *pinst, PyObject *name);\r
+\r
+/* Macros for direct access to these values. Type checks are *not*\r
+   done, so use with care. */\r
+#define PyMethod_GET_FUNCTION(meth) \\r
+        (((PyMethodObject *)meth) -> im_func)\r
+#define PyMethod_GET_SELF(meth) \\r
+       (((PyMethodObject *)meth) -> im_self)\r
+#define PyMethod_GET_CLASS(meth) \\r
+       (((PyMethodObject *)meth) -> im_class)\r
+\r
+PyAPI_FUNC(int) PyClass_IsSubclass(PyObject *, PyObject *);\r
+\r
+PyAPI_FUNC(int) PyMethod_ClearFreeList(void);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_CLASSOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/cobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/cobject.h
new file mode 100644 (file)
index 0000000..11a8b43
--- /dev/null
@@ -0,0 +1,89 @@
+/*\r
+   CObjects are marked Pending Deprecation as of Python 2.7.\r
+   The full schedule for 2.x is as follows:\r
+     - CObjects are marked Pending Deprecation in Python 2.7.\r
+     - CObjects will be marked Deprecated in Python 2.8\r
+       (if there is one).\r
+     - CObjects will be removed in Python 2.9 (if there is one).\r
+\r
+   Additionally, for the Python 3.x series:\r
+     - CObjects were marked Deprecated in Python 3.1.\r
+     - CObjects will be removed in Python 3.2.\r
+\r
+   You should switch all use of CObjects to capsules.  Capsules\r
+   have a safer and more consistent API.  For more information,\r
+   see Include/pycapsule.h, or read the "Capsules" topic in\r
+   the "Python/C API Reference Manual".\r
+\r
+   Python 2.7 no longer uses CObjects itself; all objects which\r
+   were formerly CObjects are now capsules.  Note that this change\r
+   does not by itself break binary compatibility with extensions\r
+   built for previous versions of Python--PyCObject_AsVoidPtr()\r
+   has been changed to also understand capsules.\r
+\r
+*/\r
+\r
+/* original file header comment follows: */\r
+\r
+/* C objects to be exported from one extension module to another.\r
\r
+   C objects are used for communication between extension modules.\r
+   They provide a way for an extension module to export a C interface\r
+   to other extension modules, so that extension modules can use the\r
+   Python import mechanism to link to one another.\r
+\r
+*/\r
+\r
+#ifndef Py_COBJECT_H\r
+#define Py_COBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_DATA(PyTypeObject) PyCObject_Type;\r
+\r
+#define PyCObject_Check(op) (Py_TYPE(op) == &PyCObject_Type)\r
+\r
+/* Create a PyCObject from a pointer to a C object and an optional\r
+   destructor function.  If the second argument is non-null, then it\r
+   will be called with the first argument if and when the PyCObject is\r
+   destroyed.\r
+\r
+*/\r
+PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtr(\r
+       void *cobj, void (*destruct)(void*));\r
+\r
+\r
+/* Create a PyCObject from a pointer to a C object, a description object,\r
+   and an optional destructor function.  If the third argument is non-null,\r
+   then it will be called with the first and second arguments if and when \r
+   the PyCObject is destroyed.\r
+*/\r
+PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtrAndDesc(\r
+       void *cobj, void *desc, void (*destruct)(void*,void*));\r
+\r
+/* Retrieve a pointer to a C object from a PyCObject. */\r
+PyAPI_FUNC(void *) PyCObject_AsVoidPtr(PyObject *);\r
+\r
+/* Retrieve a pointer to a description object from a PyCObject. */\r
+PyAPI_FUNC(void *) PyCObject_GetDesc(PyObject *);\r
+\r
+/* Import a pointer to a C object from a module using a PyCObject. */\r
+PyAPI_FUNC(void *) PyCObject_Import(char *module_name, char *cobject_name);\r
+\r
+/* Modify a C object. Fails (==0) if object has a destructor. */\r
+PyAPI_FUNC(int) PyCObject_SetVoidPtr(PyObject *self, void *cobj);\r
+\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    void *cobject;\r
+    void *desc;\r
+    void (*destructor)(void *);\r
+} PyCObject;\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_COBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/code.h b/AppPkg/Applications/Python/Python-2.7.10/Include/code.h
new file mode 100644 (file)
index 0000000..4015159
--- /dev/null
@@ -0,0 +1,107 @@
+/* Definitions for bytecode */\r
+\r
+#ifndef Py_CODE_H\r
+#define Py_CODE_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Bytecode object */\r
+typedef struct {\r
+    PyObject_HEAD\r
+    int co_argcount;           /* #arguments, except *args */\r
+    int co_nlocals;            /* #local variables */\r
+    int co_stacksize;          /* #entries needed for evaluation stack */\r
+    int co_flags;              /* CO_..., see below */\r
+    PyObject *co_code;         /* instruction opcodes */\r
+    PyObject *co_consts;       /* list (constants used) */\r
+    PyObject *co_names;                /* list of strings (names used) */\r
+    PyObject *co_varnames;     /* tuple of strings (local variable names) */\r
+    PyObject *co_freevars;     /* tuple of strings (free variable names) */\r
+    PyObject *co_cellvars;      /* tuple of strings (cell variable names) */\r
+    /* The rest doesn't count for hash/cmp */\r
+    PyObject *co_filename;     /* string (where it was loaded from) */\r
+    PyObject *co_name;         /* string (name, for reference) */\r
+    int co_firstlineno;                /* first source line number */\r
+    PyObject *co_lnotab;       /* string (encoding addr<->lineno mapping) See\r
+                                  Objects/lnotab_notes.txt for details. */\r
+    void *co_zombieframe;     /* for optimization only (see frameobject.c) */\r
+    PyObject *co_weakreflist;   /* to support weakrefs to code objects */\r
+} PyCodeObject;\r
+\r
+/* Masks for co_flags above */\r
+#define CO_OPTIMIZED   0x0001\r
+#define CO_NEWLOCALS   0x0002\r
+#define CO_VARARGS     0x0004\r
+#define CO_VARKEYWORDS 0x0008\r
+#define CO_NESTED       0x0010\r
+#define CO_GENERATOR    0x0020\r
+/* The CO_NOFREE flag is set if there are no free or cell variables.\r
+   This information is redundant, but it allows a single flag test\r
+   to determine whether there is any extra work to be done when the\r
+   call frame it setup.\r
+*/\r
+#define CO_NOFREE       0x0040\r
+\r
+#if 0\r
+/* This is no longer used.  Stopped defining in 2.5, do not re-use. */\r
+#define CO_GENERATOR_ALLOWED    0x1000\r
+#endif\r
+#define CO_FUTURE_DIVISION     0x2000\r
+#define CO_FUTURE_ABSOLUTE_IMPORT 0x4000 /* do absolute imports by default */\r
+#define CO_FUTURE_WITH_STATEMENT  0x8000\r
+#define CO_FUTURE_PRINT_FUNCTION  0x10000\r
+#define CO_FUTURE_UNICODE_LITERALS 0x20000\r
+\r
+/* This should be defined if a future statement modifies the syntax.\r
+   For example, when a keyword is added.\r
+*/\r
+#if 1\r
+#define PY_PARSER_REQUIRES_FUTURE_KEYWORD\r
+#endif\r
+\r
+#define CO_MAXBLOCKS 20 /* Max static block nesting within a function */\r
+\r
+PyAPI_DATA(PyTypeObject) PyCode_Type;\r
+\r
+#define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type)\r
+#define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars))\r
+\r
+/* Public interface */\r
+PyAPI_FUNC(PyCodeObject *) PyCode_New(\r
+       int, int, int, int, PyObject *, PyObject *, PyObject *, PyObject *,\r
+       PyObject *, PyObject *, PyObject *, PyObject *, int, PyObject *); \r
+        /* same as struct above */\r
+\r
+/* Creates a new empty code object with the specified source location. */\r
+PyAPI_FUNC(PyCodeObject *)\r
+PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno);\r
+\r
+/* Return the line number associated with the specified bytecode index\r
+   in this code object.  If you just need the line number of a frame,\r
+   use PyFrame_GetLineNumber() instead. */\r
+PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);\r
+\r
+/* for internal use only */\r
+#define _PyCode_GETCODEPTR(co, pp) \\r
+       ((*Py_TYPE((co)->co_code)->tp_as_buffer->bf_getreadbuffer) \\r
+        ((co)->co_code, 0, (void **)(pp)))\r
+\r
+typedef struct _addr_pair {\r
+        int ap_lower;\r
+        int ap_upper;\r
+} PyAddrPair;\r
+\r
+/* Update *bounds to describe the first and one-past-the-last instructions in the\r
+   same line as lasti.  Return the number of that line.\r
+*/\r
+PyAPI_FUNC(int) _PyCode_CheckLineNumber(PyCodeObject* co,\r
+                                        int lasti, PyAddrPair *bounds);\r
+\r
+PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts,\r
+                                      PyObject *names, PyObject *lineno_obj);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_CODE_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/codecs.h b/AppPkg/Applications/Python/Python-2.7.10/Include/codecs.h
new file mode 100644 (file)
index 0000000..79c19a8
--- /dev/null
@@ -0,0 +1,167 @@
+#ifndef Py_CODECREGISTRY_H\r
+#define Py_CODECREGISTRY_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* ------------------------------------------------------------------------\r
+\r
+   Python Codec Registry and support functions\r
+\r
+\r
+Written by Marc-Andre Lemburg (mal@lemburg.com).\r
+\r
+Copyright (c) Corporation for National Research Initiatives.\r
+\r
+   ------------------------------------------------------------------------ */\r
+\r
+/* Register a new codec search function.\r
+\r
+   As side effect, this tries to load the encodings package, if not\r
+   yet done, to make sure that it is always first in the list of\r
+   search functions.\r
+\r
+   The search_function's refcount is incremented by this function. */\r
+\r
+PyAPI_FUNC(int) PyCodec_Register(\r
+       PyObject *search_function\r
+       );\r
+\r
+/* Codec register lookup API.\r
+\r
+   Looks up the given encoding and returns a CodecInfo object with\r
+   function attributes which implement the different aspects of\r
+   processing the encoding.\r
+\r
+   The encoding string is looked up converted to all lower-case\r
+   characters. This makes encodings looked up through this mechanism\r
+   effectively case-insensitive.\r
+\r
+   If no codec is found, a KeyError is set and NULL returned.\r
+\r
+   As side effect, this tries to load the encodings package, if not\r
+   yet done. This is part of the lazy load strategy for the encodings\r
+   package.\r
+\r
+ */\r
+\r
+PyAPI_FUNC(PyObject *) _PyCodec_Lookup(\r
+       const char *encoding\r
+       );\r
+\r
+/* Generic codec based encoding API.\r
+\r
+   object is passed through the encoder function found for the given\r
+   encoding using the error handling method defined by errors. errors\r
+   may be NULL to use the default method defined for the codec.\r
+   \r
+   Raises a LookupError in case no encoder can be found.\r
+\r
+ */\r
+\r
+PyAPI_FUNC(PyObject *) PyCodec_Encode(\r
+       PyObject *object,\r
+       const char *encoding,\r
+       const char *errors\r
+       );\r
+\r
+/* Generic codec based decoding API.\r
+\r
+   object is passed through the decoder function found for the given\r
+   encoding using the error handling method defined by errors. errors\r
+   may be NULL to use the default method defined for the codec.\r
+   \r
+   Raises a LookupError in case no encoder can be found.\r
+\r
+ */\r
+\r
+PyAPI_FUNC(PyObject *) PyCodec_Decode(\r
+       PyObject *object,\r
+       const char *encoding,\r
+       const char *errors\r
+       );\r
+\r
+/* --- Codec Lookup APIs -------------------------------------------------- \r
+\r
+   All APIs return a codec object with incremented refcount and are\r
+   based on _PyCodec_Lookup().  The same comments w/r to the encoding\r
+   name also apply to these APIs.\r
+\r
+*/\r
+\r
+/* Get an encoder function for the given encoding. */\r
+\r
+PyAPI_FUNC(PyObject *) PyCodec_Encoder(\r
+       const char *encoding\r
+       );\r
+\r
+/* Get a decoder function for the given encoding. */\r
+\r
+PyAPI_FUNC(PyObject *) PyCodec_Decoder(\r
+       const char *encoding\r
+       );\r
+\r
+/* Get a IncrementalEncoder object for the given encoding. */\r
+\r
+PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder(\r
+       const char *encoding,\r
+       const char *errors\r
+       );\r
+\r
+/* Get a IncrementalDecoder object function for the given encoding. */\r
+\r
+PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder(\r
+       const char *encoding,\r
+       const char *errors\r
+       );\r
+\r
+/* Get a StreamReader factory function for the given encoding. */\r
+\r
+PyAPI_FUNC(PyObject *) PyCodec_StreamReader(\r
+       const char *encoding,\r
+       PyObject *stream,\r
+       const char *errors\r
+       );\r
+\r
+/* Get a StreamWriter factory function for the given encoding. */\r
+\r
+PyAPI_FUNC(PyObject *) PyCodec_StreamWriter(\r
+       const char *encoding,\r
+       PyObject *stream,\r
+       const char *errors\r
+       );\r
+\r
+/* Unicode encoding error handling callback registry API */\r
+\r
+/* Register the error handling callback function error under the given\r
+   name. This function will be called by the codec when it encounters\r
+   unencodable characters/undecodable bytes and doesn't know the\r
+   callback name, when name is specified as the error parameter\r
+   in the call to the encode/decode function.\r
+   Return 0 on success, -1 on error */\r
+PyAPI_FUNC(int) PyCodec_RegisterError(const char *name, PyObject *error);\r
+\r
+/* Lookup the error handling callback function registered under the given\r
+   name. As a special case NULL can be passed, in which case\r
+   the error handling callback for "strict" will be returned. */\r
+PyAPI_FUNC(PyObject *) PyCodec_LookupError(const char *name);\r
+\r
+/* raise exc as an exception */\r
+PyAPI_FUNC(PyObject *) PyCodec_StrictErrors(PyObject *exc);\r
+\r
+/* ignore the unicode error, skipping the faulty input */\r
+PyAPI_FUNC(PyObject *) PyCodec_IgnoreErrors(PyObject *exc);\r
+\r
+/* replace the unicode encode error with ? or U+FFFD */\r
+PyAPI_FUNC(PyObject *) PyCodec_ReplaceErrors(PyObject *exc);\r
+\r
+/* replace the unicode encode error with XML character references */\r
+PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc);\r
+\r
+/* replace the unicode encode error with backslash escapes (\x, \u and \U) */\r
+PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_CODECREGISTRY_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/compile.h b/AppPkg/Applications/Python/Python-2.7.10/Include/compile.h
new file mode 100644 (file)
index 0000000..22cb75f
--- /dev/null
@@ -0,0 +1,40 @@
+\r
+#ifndef Py_COMPILE_H\r
+#define Py_COMPILE_H\r
+\r
+#include "code.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Public interface */\r
+struct _node; /* Declare the existence of this type */\r
+PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *);\r
+\r
+/* Future feature support */\r
+\r
+typedef struct {\r
+    int ff_features;      /* flags set by future statements */\r
+    int ff_lineno;        /* line number of last future statement */\r
+} PyFutureFeatures;\r
+\r
+#define FUTURE_NESTED_SCOPES "nested_scopes"\r
+#define FUTURE_GENERATORS "generators"\r
+#define FUTURE_DIVISION "division"\r
+#define FUTURE_ABSOLUTE_IMPORT "absolute_import"\r
+#define FUTURE_WITH_STATEMENT "with_statement"\r
+#define FUTURE_PRINT_FUNCTION "print_function"\r
+#define FUTURE_UNICODE_LITERALS "unicode_literals"\r
+\r
+\r
+struct _mod; /* Declare the existence of this type */\r
+PyAPI_FUNC(PyCodeObject *) PyAST_Compile(struct _mod *, const char *,\r
+                                       PyCompilerFlags *, PyArena *);\r
+PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(struct _mod *, const char *);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_COMPILE_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/complexobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/complexobject.h
new file mode 100644 (file)
index 0000000..747048a
--- /dev/null
@@ -0,0 +1,66 @@
+/* Complex number structure */\r
+\r
+#ifndef Py_COMPLEXOBJECT_H\r
+#define Py_COMPLEXOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct {\r
+    double real;\r
+    double imag;\r
+} Py_complex;\r
+\r
+/* Operations on complex numbers from complexmodule.c */\r
+\r
+#define c_sum _Py_c_sum\r
+#define c_diff _Py_c_diff\r
+#define c_neg _Py_c_neg\r
+#define c_prod _Py_c_prod\r
+#define c_quot _Py_c_quot\r
+#define c_pow _Py_c_pow\r
+#define c_abs _Py_c_abs\r
+\r
+PyAPI_FUNC(Py_complex) c_sum(Py_complex, Py_complex);\r
+PyAPI_FUNC(Py_complex) c_diff(Py_complex, Py_complex);\r
+PyAPI_FUNC(Py_complex) c_neg(Py_complex);\r
+PyAPI_FUNC(Py_complex) c_prod(Py_complex, Py_complex);\r
+PyAPI_FUNC(Py_complex) c_quot(Py_complex, Py_complex);\r
+PyAPI_FUNC(Py_complex) c_pow(Py_complex, Py_complex);\r
+PyAPI_FUNC(double) c_abs(Py_complex);\r
+\r
+\r
+/* Complex object interface */\r
+\r
+/*\r
+PyComplexObject represents a complex number with double-precision\r
+real and imaginary parts.\r
+*/\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    Py_complex cval;\r
+} PyComplexObject;     \r
+\r
+PyAPI_DATA(PyTypeObject) PyComplex_Type;\r
+\r
+#define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type)\r
+#define PyComplex_CheckExact(op) (Py_TYPE(op) == &PyComplex_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);\r
+PyAPI_FUNC(PyObject *) PyComplex_FromDoubles(double real, double imag);\r
+\r
+PyAPI_FUNC(double) PyComplex_RealAsDouble(PyObject *op);\r
+PyAPI_FUNC(double) PyComplex_ImagAsDouble(PyObject *op);\r
+PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op);\r
+\r
+/* Format the object based on the format_spec, as defined in PEP 3101\r
+   (Advanced String Formatting). */\r
+PyAPI_FUNC(PyObject *) _PyComplex_FormatAdvanced(PyObject *obj,\r
+                                                 char *format_spec,\r
+                                                 Py_ssize_t format_spec_len);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_COMPLEXOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/datetime.h b/AppPkg/Applications/Python/Python-2.7.10/Include/datetime.h
new file mode 100644 (file)
index 0000000..47d0162
--- /dev/null
@@ -0,0 +1,239 @@
+/*  datetime.h\r
+ */\r
+\r
+#ifndef DATETIME_H\r
+#define DATETIME_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Fields are packed into successive bytes, each viewed as unsigned and\r
+ * big-endian, unless otherwise noted:\r
+ *\r
+ * byte offset\r
+ *  0           year     2 bytes, 1-9999\r
+ *  2           month    1 byte, 1-12\r
+ *  3           day      1 byte, 1-31\r
+ *  4           hour     1 byte, 0-23\r
+ *  5           minute   1 byte, 0-59\r
+ *  6           second   1 byte, 0-59\r
+ *  7           usecond  3 bytes, 0-999999\r
+ * 10\r
+ */\r
+\r
+/* # of bytes for year, month, and day. */\r
+#define _PyDateTime_DATE_DATASIZE 4\r
+\r
+/* # of bytes for hour, minute, second, and usecond. */\r
+#define _PyDateTime_TIME_DATASIZE 6\r
+\r
+/* # of bytes for year, month, day, hour, minute, second, and usecond. */\r
+#define _PyDateTime_DATETIME_DATASIZE 10\r
+\r
+\r
+typedef struct\r
+{\r
+    PyObject_HEAD\r
+    long hashcode;              /* -1 when unknown */\r
+    int days;                   /* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */\r
+    int seconds;                /* 0 <= seconds < 24*3600 is invariant */\r
+    int microseconds;           /* 0 <= microseconds < 1000000 is invariant */\r
+} PyDateTime_Delta;\r
+\r
+typedef struct\r
+{\r
+    PyObject_HEAD               /* a pure abstract base class */\r
+} PyDateTime_TZInfo;\r
+\r
+\r
+/* The datetime and time types have hashcodes, and an optional tzinfo member,\r
+ * present if and only if hastzinfo is true.\r
+ */\r
+#define _PyTZINFO_HEAD          \\r
+    PyObject_HEAD               \\r
+    long hashcode;              \\r
+    char hastzinfo;             /* boolean flag */\r
+\r
+/* No _PyDateTime_BaseTZInfo is allocated; it's just to have something\r
+ * convenient to cast to, when getting at the hastzinfo member of objects\r
+ * starting with _PyTZINFO_HEAD.\r
+ */\r
+typedef struct\r
+{\r
+    _PyTZINFO_HEAD\r
+} _PyDateTime_BaseTZInfo;\r
+\r
+/* All time objects are of PyDateTime_TimeType, but that can be allocated\r
+ * in two ways, with or without a tzinfo member.  Without is the same as\r
+ * tzinfo == None, but consumes less memory.  _PyDateTime_BaseTime is an\r
+ * internal struct used to allocate the right amount of space for the\r
+ * "without" case.\r
+ */\r
+#define _PyDateTime_TIMEHEAD    \\r
+    _PyTZINFO_HEAD              \\r
+    unsigned char data[_PyDateTime_TIME_DATASIZE];\r
+\r
+typedef struct\r
+{\r
+    _PyDateTime_TIMEHEAD\r
+} _PyDateTime_BaseTime;         /* hastzinfo false */\r
+\r
+typedef struct\r
+{\r
+    _PyDateTime_TIMEHEAD\r
+    PyObject *tzinfo;\r
+} PyDateTime_Time;              /* hastzinfo true */\r
+\r
+\r
+/* All datetime objects are of PyDateTime_DateTimeType, but that can be\r
+ * allocated in two ways too, just like for time objects above.  In addition,\r
+ * the plain date type is a base class for datetime, so it must also have\r
+ * a hastzinfo member (although it's unused there).\r
+ */\r
+typedef struct\r
+{\r
+    _PyTZINFO_HEAD\r
+    unsigned char data[_PyDateTime_DATE_DATASIZE];\r
+} PyDateTime_Date;\r
+\r
+#define _PyDateTime_DATETIMEHEAD        \\r
+    _PyTZINFO_HEAD                      \\r
+    unsigned char data[_PyDateTime_DATETIME_DATASIZE];\r
+\r
+typedef struct\r
+{\r
+    _PyDateTime_DATETIMEHEAD\r
+} _PyDateTime_BaseDateTime;     /* hastzinfo false */\r
+\r
+typedef struct\r
+{\r
+    _PyDateTime_DATETIMEHEAD\r
+    PyObject *tzinfo;\r
+} PyDateTime_DateTime;          /* hastzinfo true */\r
+\r
+\r
+/* Apply for date and datetime instances. */\r
+#define PyDateTime_GET_YEAR(o)     ((((PyDateTime_Date*)o)->data[0] << 8) | \\r
+                     ((PyDateTime_Date*)o)->data[1])\r
+#define PyDateTime_GET_MONTH(o)    (((PyDateTime_Date*)o)->data[2])\r
+#define PyDateTime_GET_DAY(o)      (((PyDateTime_Date*)o)->data[3])\r
+\r
+#define PyDateTime_DATE_GET_HOUR(o)        (((PyDateTime_DateTime*)o)->data[4])\r
+#define PyDateTime_DATE_GET_MINUTE(o)      (((PyDateTime_DateTime*)o)->data[5])\r
+#define PyDateTime_DATE_GET_SECOND(o)      (((PyDateTime_DateTime*)o)->data[6])\r
+#define PyDateTime_DATE_GET_MICROSECOND(o)              \\r
+    ((((PyDateTime_DateTime*)o)->data[7] << 16) |       \\r
+     (((PyDateTime_DateTime*)o)->data[8] << 8)  |       \\r
+      ((PyDateTime_DateTime*)o)->data[9])\r
+\r
+/* Apply for time instances. */\r
+#define PyDateTime_TIME_GET_HOUR(o)        (((PyDateTime_Time*)o)->data[0])\r
+#define PyDateTime_TIME_GET_MINUTE(o)      (((PyDateTime_Time*)o)->data[1])\r
+#define PyDateTime_TIME_GET_SECOND(o)      (((PyDateTime_Time*)o)->data[2])\r
+#define PyDateTime_TIME_GET_MICROSECOND(o)              \\r
+    ((((PyDateTime_Time*)o)->data[3] << 16) |           \\r
+     (((PyDateTime_Time*)o)->data[4] << 8)  |           \\r
+      ((PyDateTime_Time*)o)->data[5])\r
+\r
+\r
+/* Define structure for C API. */\r
+typedef struct {\r
+    /* type objects */\r
+    PyTypeObject *DateType;\r
+    PyTypeObject *DateTimeType;\r
+    PyTypeObject *TimeType;\r
+    PyTypeObject *DeltaType;\r
+    PyTypeObject *TZInfoType;\r
+\r
+    /* constructors */\r
+    PyObject *(*Date_FromDate)(int, int, int, PyTypeObject*);\r
+    PyObject *(*DateTime_FromDateAndTime)(int, int, int, int, int, int, int,\r
+        PyObject*, PyTypeObject*);\r
+    PyObject *(*Time_FromTime)(int, int, int, int, PyObject*, PyTypeObject*);\r
+    PyObject *(*Delta_FromDelta)(int, int, int, int, PyTypeObject*);\r
+\r
+    /* constructors for the DB API */\r
+    PyObject *(*DateTime_FromTimestamp)(PyObject*, PyObject*, PyObject*);\r
+    PyObject *(*Date_FromTimestamp)(PyObject*, PyObject*);\r
+\r
+} PyDateTime_CAPI;\r
+\r
+#define PyDateTime_CAPSULE_NAME "datetime.datetime_CAPI"\r
+\r
+\r
+/* "magic" constant used to partially protect against developer mistakes. */\r
+#define DATETIME_API_MAGIC 0x414548d5\r
+\r
+#ifdef Py_BUILD_CORE\r
+\r
+/* Macros for type checking when building the Python core. */\r
+#define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType)\r
+#define PyDate_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateType)\r
+\r
+#define PyDateTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeType)\r
+#define PyDateTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateTimeType)\r
+\r
+#define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType)\r
+#define PyTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TimeType)\r
+\r
+#define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType)\r
+#define PyDelta_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DeltaType)\r
+\r
+#define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType)\r
+#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TZInfoType)\r
+\r
+#else\r
+\r
+/* Define global variable for the C API and a macro for setting it. */\r
+static PyDateTime_CAPI *PyDateTimeAPI = NULL;\r
+\r
+#define PyDateTime_IMPORT \\r
+    PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)\r
+\r
+/* Macros for type checking when not building the Python core. */\r
+#define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType)\r
+#define PyDate_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateType)\r
+\r
+#define PyDateTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateTimeType)\r
+#define PyDateTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateTimeType)\r
+\r
+#define PyTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TimeType)\r
+#define PyTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TimeType)\r
+\r
+#define PyDelta_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DeltaType)\r
+#define PyDelta_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DeltaType)\r
+\r
+#define PyTZInfo_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TZInfoType)\r
+#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TZInfoType)\r
+\r
+/* Macros for accessing constructors in a simplified fashion. */\r
+#define PyDate_FromDate(year, month, day) \\r
+    PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType)\r
+\r
+#define PyDateTime_FromDateAndTime(year, month, day, hour, min, sec, usec) \\r
+    PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, \\r
+        min, sec, usec, Py_None, PyDateTimeAPI->DateTimeType)\r
+\r
+#define PyTime_FromTime(hour, minute, second, usecond) \\r
+    PyDateTimeAPI->Time_FromTime(hour, minute, second, usecond, \\r
+        Py_None, PyDateTimeAPI->TimeType)\r
+\r
+#define PyDelta_FromDSU(days, seconds, useconds) \\r
+    PyDateTimeAPI->Delta_FromDelta(days, seconds, useconds, 1, \\r
+        PyDateTimeAPI->DeltaType)\r
+\r
+/* Macros supporting the DB API. */\r
+#define PyDateTime_FromTimestamp(args) \\r
+    PyDateTimeAPI->DateTime_FromTimestamp( \\r
+        (PyObject*) (PyDateTimeAPI->DateTimeType), args, NULL)\r
+\r
+#define PyDate_FromTimestamp(args) \\r
+    PyDateTimeAPI->Date_FromTimestamp( \\r
+        (PyObject*) (PyDateTimeAPI->DateType), args)\r
+\r
+#endif  /* Py_BUILD_CORE */\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/descrobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/descrobject.h
new file mode 100644 (file)
index 0000000..5a9c3e1
--- /dev/null
@@ -0,0 +1,94 @@
+/* Descriptors */\r
+#ifndef Py_DESCROBJECT_H\r
+#define Py_DESCROBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef PyObject *(*getter)(PyObject *, void *);\r
+typedef int (*setter)(PyObject *, PyObject *, void *);\r
+\r
+typedef struct PyGetSetDef {\r
+    char *name;\r
+    getter get;\r
+    setter set;\r
+    char *doc;\r
+    void *closure;\r
+} PyGetSetDef;\r
+\r
+typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args,\r
+                                 void *wrapped);\r
+\r
+typedef PyObject *(*wrapperfunc_kwds)(PyObject *self, PyObject *args,\r
+                                      void *wrapped, PyObject *kwds);\r
+\r
+struct wrapperbase {\r
+    char *name;\r
+    int offset;\r
+    void *function;\r
+    wrapperfunc wrapper;\r
+    char *doc;\r
+    int flags;\r
+    PyObject *name_strobj;\r
+};\r
+\r
+/* Flags for above struct */\r
+#define PyWrapperFlag_KEYWORDS 1 /* wrapper function takes keyword args */\r
+\r
+/* Various kinds of descriptor objects */\r
+\r
+#define PyDescr_COMMON \\r
+    PyObject_HEAD \\r
+    PyTypeObject *d_type; \\r
+    PyObject *d_name\r
+\r
+typedef struct {\r
+    PyDescr_COMMON;\r
+} PyDescrObject;\r
+\r
+typedef struct {\r
+    PyDescr_COMMON;\r
+    PyMethodDef *d_method;\r
+} PyMethodDescrObject;\r
+\r
+typedef struct {\r
+    PyDescr_COMMON;\r
+    struct PyMemberDef *d_member;\r
+} PyMemberDescrObject;\r
+\r
+typedef struct {\r
+    PyDescr_COMMON;\r
+    PyGetSetDef *d_getset;\r
+} PyGetSetDescrObject;\r
+\r
+typedef struct {\r
+    PyDescr_COMMON;\r
+    struct wrapperbase *d_base;\r
+    void *d_wrapped; /* This can be any function pointer */\r
+} PyWrapperDescrObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;\r
+PyAPI_DATA(PyTypeObject) PyDictProxy_Type;\r
+PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;\r
+PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;\r
+\r
+PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);\r
+PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);\r
+PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *,\r
+                                               struct PyMemberDef *);\r
+PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *,\r
+                                               struct PyGetSetDef *);\r
+PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,\r
+                                                struct wrapperbase *, void *);\r
+#define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set != NULL)\r
+\r
+PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);\r
+\r
+\r
+PyAPI_DATA(PyTypeObject) PyProperty_Type;\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_DESCROBJECT_H */\r
+\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/dictobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/dictobject.h
new file mode 100644 (file)
index 0000000..0f3ab17
--- /dev/null
@@ -0,0 +1,156 @@
+#ifndef Py_DICTOBJECT_H\r
+#define Py_DICTOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Dictionary object type -- mapping from hashable object to object */\r
+\r
+/* The distribution includes a separate file, Objects/dictnotes.txt,\r
+   describing explorations into dictionary design and optimization.\r
+   It covers typical dictionary use patterns, the parameters for\r
+   tuning dictionaries, and several ideas for possible optimizations.\r
+*/\r
+\r
+/*\r
+There are three kinds of slots in the table:\r
+\r
+1. Unused.  me_key == me_value == NULL\r
+   Does not hold an active (key, value) pair now and never did.  Unused can\r
+   transition to Active upon key insertion.  This is the only case in which\r
+   me_key is NULL, and is each slot's initial state.\r
+\r
+2. Active.  me_key != NULL and me_key != dummy and me_value != NULL\r
+   Holds an active (key, value) pair.  Active can transition to Dummy upon\r
+   key deletion.  This is the only case in which me_value != NULL.\r
+\r
+3. Dummy.  me_key == dummy and me_value == NULL\r
+   Previously held an active (key, value) pair, but that was deleted and an\r
+   active pair has not yet overwritten the slot.  Dummy can transition to\r
+   Active upon key insertion.  Dummy slots cannot be made Unused again\r
+   (cannot have me_key set to NULL), else the probe sequence in case of\r
+   collision would have no way to know they were once active.\r
+\r
+Note: .popitem() abuses the me_hash field of an Unused or Dummy slot to\r
+hold a search finger.  The me_hash field of Unused or Dummy slots has no\r
+meaning otherwise.\r
+*/\r
+\r
+/* PyDict_MINSIZE is the minimum size of a dictionary.  This many slots are\r
+ * allocated directly in the dict object (in the ma_smalltable member).\r
+ * It must be a power of 2, and at least 4.  8 allows dicts with no more\r
+ * than 5 active entries to live in ma_smalltable (and so avoid an\r
+ * additional malloc); instrumentation suggested this suffices for the\r
+ * majority of dicts (consisting mostly of usually-small instance dicts and\r
+ * usually-small dicts created to pass keyword arguments).\r
+ */\r
+#define PyDict_MINSIZE 8\r
+\r
+typedef struct {\r
+    /* Cached hash code of me_key.  Note that hash codes are C longs.\r
+     * We have to use Py_ssize_t instead because dict_popitem() abuses\r
+     * me_hash to hold a search finger.\r
+     */\r
+    Py_ssize_t me_hash;\r
+    PyObject *me_key;\r
+    PyObject *me_value;\r
+} PyDictEntry;\r
+\r
+/*\r
+To ensure the lookup algorithm terminates, there must be at least one Unused\r
+slot (NULL key) in the table.\r
+The value ma_fill is the number of non-NULL keys (sum of Active and Dummy);\r
+ma_used is the number of non-NULL, non-dummy keys (== the number of non-NULL\r
+values == the number of Active items).\r
+To avoid slowing down lookups on a near-full table, we resize the table when\r
+it's two-thirds full.\r
+*/\r
+typedef struct _dictobject PyDictObject;\r
+struct _dictobject {\r
+    PyObject_HEAD\r
+    Py_ssize_t ma_fill;  /* # Active + # Dummy */\r
+    Py_ssize_t ma_used;  /* # Active */\r
+\r
+    /* The table contains ma_mask + 1 slots, and that's a power of 2.\r
+     * We store the mask instead of the size because the mask is more\r
+     * frequently needed.\r
+     */\r
+    Py_ssize_t ma_mask;\r
+\r
+    /* ma_table points to ma_smalltable for small tables, else to\r
+     * additional malloc'ed memory.  ma_table is never NULL!  This rule\r
+     * saves repeated runtime null-tests in the workhorse getitem and\r
+     * setitem calls.\r
+     */\r
+    PyDictEntry *ma_table;\r
+    PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, long hash);\r
+    PyDictEntry ma_smalltable[PyDict_MINSIZE];\r
+};\r
+\r
+PyAPI_DATA(PyTypeObject) PyDict_Type;\r
+PyAPI_DATA(PyTypeObject) PyDictIterKey_Type;\r
+PyAPI_DATA(PyTypeObject) PyDictIterValue_Type;\r
+PyAPI_DATA(PyTypeObject) PyDictIterItem_Type;\r
+PyAPI_DATA(PyTypeObject) PyDictKeys_Type;\r
+PyAPI_DATA(PyTypeObject) PyDictItems_Type;\r
+PyAPI_DATA(PyTypeObject) PyDictValues_Type;\r
+\r
+#define PyDict_Check(op) \\r
+                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)\r
+#define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)\r
+#define PyDictKeys_Check(op) (Py_TYPE(op) == &PyDictKeys_Type)\r
+#define PyDictItems_Check(op) (Py_TYPE(op) == &PyDictItems_Type)\r
+#define PyDictValues_Check(op) (Py_TYPE(op) == &PyDictValues_Type)\r
+/* This excludes Values, since they are not sets. */\r
+# define PyDictViewSet_Check(op) \\r
+    (PyDictKeys_Check(op) || PyDictItems_Check(op))\r
+\r
+PyAPI_FUNC(PyObject *) PyDict_New(void);\r
+PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);\r
+PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item);\r
+PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key);\r
+PyAPI_FUNC(void) PyDict_Clear(PyObject *mp);\r
+PyAPI_FUNC(int) PyDict_Next(\r
+    PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value);\r
+PyAPI_FUNC(int) _PyDict_Next(\r
+    PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, long *hash);\r
+PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp);\r
+PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp);\r
+PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp);\r
+PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp);\r
+PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp);\r
+PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key);\r
+PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, long hash);\r
+PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);\r
+PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);\r
+\r
+/* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */\r
+PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other);\r
+\r
+/* PyDict_Merge updates/merges from a mapping object (an object that\r
+   supports PyMapping_Keys() and PyObject_GetItem()).  If override is true,\r
+   the last occurrence of a key wins, else the first.  The Python\r
+   dict.update(other) is equivalent to PyDict_Merge(dict, other, 1).\r
+*/\r
+PyAPI_FUNC(int) PyDict_Merge(PyObject *mp,\r
+                                   PyObject *other,\r
+                                   int override);\r
+\r
+/* PyDict_MergeFromSeq2 updates/merges from an iterable object producing\r
+   iterable objects of length 2.  If override is true, the last occurrence\r
+   of a key wins, else the first.  The Python dict constructor dict(seq2)\r
+   is equivalent to dict={}; PyDict_MergeFromSeq(dict, seq2, 1).\r
+*/\r
+PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d,\r
+                                           PyObject *seq2,\r
+                                           int override);\r
+\r
+PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key);\r
+PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item);\r
+PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_DICTOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/dtoa.h b/AppPkg/Applications/Python/Python-2.7.10/Include/dtoa.h
new file mode 100644 (file)
index 0000000..c7e80bc
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef PY_NO_SHORT_FLOAT_REPR\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_FUNC(double) _Py_dg_strtod(const char *str, char **ptr);\r
+PyAPI_FUNC(char *) _Py_dg_dtoa(double d, int mode, int ndigits,\r
+                        int *decpt, int *sign, char **rve);\r
+PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/enumobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/enumobject.h
new file mode 100644 (file)
index 0000000..42dc2d2
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef Py_ENUMOBJECT_H\r
+#define Py_ENUMOBJECT_H\r
+\r
+/* Enumerate Object */\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_DATA(PyTypeObject) PyEnum_Type;\r
+PyAPI_DATA(PyTypeObject) PyReversed_Type;\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* !Py_ENUMOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/errcode.h b/AppPkg/Applications/Python/Python-2.7.10/Include/errcode.h
new file mode 100644 (file)
index 0000000..295295c
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef Py_ERRCODE_H\r
+#define Py_ERRCODE_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Error codes passed around between file input, tokenizer, parser and\r
+   interpreter.  This is necessary so we can turn them into Python\r
+   exceptions at a higher level.  Note that some errors have a\r
+   slightly different meaning when passed from the tokenizer to the\r
+   parser than when passed from the parser to the interpreter; e.g.\r
+   the parser only returns E_EOF when it hits EOF immediately, and it\r
+   never returns E_OK. */\r
+\r
+#define E_OK           10      /* No error */\r
+#define E_EOF          11      /* End Of File */\r
+#define E_INTR         12      /* Interrupted */\r
+#define E_TOKEN                13      /* Bad token */\r
+#define E_SYNTAX       14      /* Syntax error */\r
+#define E_NOMEM                15      /* Ran out of memory */\r
+#define E_DONE         16      /* Parsing complete */\r
+#define E_ERROR                17      /* Execution error */\r
+#define E_TABSPACE     18      /* Inconsistent mixing of tabs and spaces */\r
+#define E_OVERFLOW      19     /* Node had too many children */\r
+#define E_TOODEEP      20      /* Too many indentation levels */\r
+#define E_DEDENT       21      /* No matching outer block for dedent */\r
+#define E_DECODE       22      /* Error in decoding into Unicode */\r
+#define E_EOFS         23      /* EOF in triple-quoted string */\r
+#define E_EOLS         24      /* EOL in single-quoted string */\r
+#define E_LINECONT     25      /* Unexpected characters after a line continuation */\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_ERRCODE_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/eval.h b/AppPkg/Applications/Python/Python-2.7.10/Include/eval.h
new file mode 100644 (file)
index 0000000..fe1d47a
--- /dev/null
@@ -0,0 +1,25 @@
+\r
+/* Interface to execute compiled code */\r
+\r
+#ifndef Py_EVAL_H\r
+#define Py_EVAL_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyCodeObject *, PyObject *, PyObject *);\r
+\r
+PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyCodeObject *co,\r
+                                       PyObject *globals,\r
+                                       PyObject *locals,\r
+                                       PyObject **args, int argc,\r
+                                       PyObject **kwds, int kwdc,\r
+                                       PyObject **defs, int defc,\r
+                                       PyObject *closure);\r
+\r
+PyAPI_FUNC(PyObject *) _PyEval_CallTracing(PyObject *func, PyObject *args);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_EVAL_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/fileobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/fileobject.h
new file mode 100644 (file)
index 0000000..c16aed9
--- /dev/null
@@ -0,0 +1,97 @@
+\r
+/* File object interface */\r
+\r
+#ifndef Py_FILEOBJECT_H\r
+#define Py_FILEOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    FILE *f_fp;\r
+    PyObject *f_name;\r
+    PyObject *f_mode;\r
+    int (*f_close)(FILE *);\r
+    int f_softspace;            /* Flag used by 'print' command */\r
+    int f_binary;               /* Flag which indicates whether the file is\r
+                               open in binary (1) or text (0) mode */\r
+    char* f_buf;                /* Allocated readahead buffer */\r
+    char* f_bufend;             /* Points after last occupied position */\r
+    char* f_bufptr;             /* Current buffer position */\r
+    char *f_setbuf;             /* Buffer for setbuf(3) and setvbuf(3) */\r
+    int f_univ_newline;         /* Handle any newline convention */\r
+    int f_newlinetypes;         /* Types of newlines seen */\r
+    int f_skipnextlf;           /* Skip next \n */\r
+    PyObject *f_encoding;\r
+    PyObject *f_errors;\r
+    PyObject *weakreflist; /* List of weak references */\r
+    int unlocked_count;         /* Num. currently running sections of code\r
+                               using f_fp with the GIL released. */\r
+    int readable;\r
+    int writable;\r
+} PyFileObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PyFile_Type;\r
+\r
+#define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type)\r
+#define PyFile_CheckExact(op) (Py_TYPE(op) == &PyFile_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *);\r
+PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int);\r
+PyAPI_FUNC(int) PyFile_SetEncoding(PyObject *, const char *);\r
+PyAPI_FUNC(int) PyFile_SetEncodingAndErrors(PyObject *, const char *, char *errors);\r
+PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *,\r
+                                             int (*)(FILE *));\r
+PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *);\r
+PyAPI_FUNC(void) PyFile_IncUseCount(PyFileObject *);\r
+PyAPI_FUNC(void) PyFile_DecUseCount(PyFileObject *);\r
+PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);\r
+PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);\r
+PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int);\r
+PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);\r
+PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);\r
+\r
+/* The default encoding used by the platform file system APIs\r
+   If non-NULL, this is different than the default encoding for strings\r
+*/\r
+PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;\r
+\r
+/* Routines to replace fread() and fgets() which accept any of \r, \n\r
+   or \r\n as line terminators.\r
+*/\r
+#define PY_STDIOTEXTMODE "b"\r
+char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);\r
+size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);\r
+\r
+/* A routine to do sanity checking on the file mode string.  returns\r
+   non-zero on if an exception occurred\r
+*/\r
+int _PyFile_SanitizeMode(char *mode);\r
+\r
+#if defined _MSC_VER && _MSC_VER >= 1400\r
+/* A routine to check if a file descriptor is valid on Windows.  Returns 0\r
+ * and sets errno to EBADF if it isn't.  This is to avoid Assertions\r
+ * from various functions in the Windows CRT beginning with\r
+ * Visual Studio 2005\r
+ */\r
+int _PyVerify_fd(int fd);\r
+#elif defined _MSC_VER && _MSC_VER >= 1200\r
+/* fdopen doesn't set errno EBADF and crashes for large fd on debug build */\r
+#define _PyVerify_fd(fd) (_get_osfhandle(fd) >= 0)\r
+#else\r
+#define _PyVerify_fd(A) (1) /* dummy */\r
+#endif\r
+\r
+/* A routine to check if a file descriptor can be select()-ed. */\r
+#ifdef HAVE_SELECT\r
+ #define _PyIsSelectable_fd(FD) (((FD) >= 0) && ((FD) < FD_SETSIZE))\r
+#else\r
+ #define _PyIsSelectable_fd(FD) (1)\r
+#endif /* HAVE_SELECT */\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_FILEOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/floatobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/floatobject.h
new file mode 100644 (file)
index 0000000..92c69fe
--- /dev/null
@@ -0,0 +1,140 @@
+\r
+/* Float object interface */\r
+\r
+/*\r
+PyFloatObject represents a (double precision) floating point number.\r
+*/\r
+\r
+#ifndef Py_FLOATOBJECT_H\r
+#define Py_FLOATOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    double ob_fval;\r
+} PyFloatObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PyFloat_Type;\r
+\r
+#define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type)\r
+#define PyFloat_CheckExact(op) (Py_TYPE(op) == &PyFloat_Type)\r
+\r
+/* The str() precision PyFloat_STR_PRECISION is chosen so that in most cases,\r
+   the rounding noise created by various operations is suppressed, while\r
+   giving plenty of precision for practical use. */\r
+\r
+#define PyFloat_STR_PRECISION 12\r
+\r
+#ifdef Py_NAN\r
+#define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN)\r
+#endif\r
+\r
+#define Py_RETURN_INF(sign) do                                 \\r
+       if (copysign(1., sign) == 1.) {                         \\r
+               return PyFloat_FromDouble(Py_HUGE_VAL); \\r
+       } else {                                                \\r
+               return PyFloat_FromDouble(-Py_HUGE_VAL);        \\r
+       } while(0)\r
+\r
+PyAPI_FUNC(double) PyFloat_GetMax(void);\r
+PyAPI_FUNC(double) PyFloat_GetMin(void);\r
+PyAPI_FUNC(PyObject *) PyFloat_GetInfo(void);\r
+\r
+/* Return Python float from string PyObject.  Second argument ignored on\r
+   input, and, if non-NULL, NULL is stored into *junk (this tried to serve a\r
+   purpose once but can't be made to work as intended). */\r
+PyAPI_FUNC(PyObject *) PyFloat_FromString(PyObject*, char** junk);\r
+\r
+/* Return Python float from C double. */\r
+PyAPI_FUNC(PyObject *) PyFloat_FromDouble(double);\r
+\r
+/* Extract C double from Python float.  The macro version trades safety for\r
+   speed. */\r
+PyAPI_FUNC(double) PyFloat_AsDouble(PyObject *);\r
+#define PyFloat_AS_DOUBLE(op) (((PyFloatObject *)(op))->ob_fval)\r
+\r
+/* Write repr(v) into the char buffer argument, followed by null byte.  The\r
+   buffer must be "big enough"; >= 100 is very safe.\r
+   PyFloat_AsReprString(buf, x) strives to print enough digits so that\r
+   PyFloat_FromString(buf) then reproduces x exactly. */\r
+PyAPI_FUNC(void) PyFloat_AsReprString(char*, PyFloatObject *v);\r
+\r
+/* Write str(v) into the char buffer argument, followed by null byte.  The\r
+   buffer must be "big enough"; >= 100 is very safe.  Note that it's\r
+   unusual to be able to get back the float you started with from\r
+   PyFloat_AsString's result -- use PyFloat_AsReprString() if you want to\r
+   preserve precision across conversions. */\r
+PyAPI_FUNC(void) PyFloat_AsString(char*, PyFloatObject *v);\r
+\r
+/* _PyFloat_{Pack,Unpack}{4,8}\r
+ *\r
+ * The struct and pickle (at least) modules need an efficient platform-\r
+ * independent way to store floating-point values as byte strings.\r
+ * The Pack routines produce a string from a C double, and the Unpack\r
+ * routines produce a C double from such a string.  The suffix (4 or 8)\r
+ * specifies the number of bytes in the string.\r
+ *\r
+ * On platforms that appear to use (see _PyFloat_Init()) IEEE-754 formats\r
+ * these functions work by copying bits.  On other platforms, the formats the\r
+ * 4- byte format is identical to the IEEE-754 single precision format, and\r
+ * the 8-byte format to the IEEE-754 double precision format, although the\r
+ * packing of INFs and NaNs (if such things exist on the platform) isn't\r
+ * handled correctly, and attempting to unpack a string containing an IEEE\r
+ * INF or NaN will raise an exception.\r
+ *\r
+ * On non-IEEE platforms with more precision, or larger dynamic range, than\r
+ * 754 supports, not all values can be packed; on non-IEEE platforms with less\r
+ * precision, or smaller dynamic range, not all values can be unpacked.  What\r
+ * happens in such cases is partly accidental (alas).\r
+ */\r
+\r
+/* The pack routines write 4 or 8 bytes, starting at p.  le is a bool\r
+ * argument, true if you want the string in little-endian format (exponent\r
+ * last, at p+3 or p+7), false if you want big-endian format (exponent\r
+ * first, at p).\r
+ * Return value:  0 if all is OK, -1 if error (and an exception is\r
+ * set, most likely OverflowError).\r
+ * There are two problems on non-IEEE platforms:\r
+ * 1):  What this does is undefined if x is a NaN or infinity.\r
+ * 2):  -0.0 and +0.0 produce the same string.\r
+ */\r
+PyAPI_FUNC(int) _PyFloat_Pack4(double x, unsigned char *p, int le);\r
+PyAPI_FUNC(int) _PyFloat_Pack8(double x, unsigned char *p, int le);\r
+\r
+/* Used to get the important decimal digits of a double */\r
+PyAPI_FUNC(int) _PyFloat_Digits(char *buf, double v, int *signum);\r
+PyAPI_FUNC(void) _PyFloat_DigitsInit(void);\r
+\r
+/* The unpack routines read 4 or 8 bytes, starting at p.  le is a bool\r
+ * argument, true if the string is in little-endian format (exponent\r
+ * last, at p+3 or p+7), false if big-endian (exponent first, at p).\r
+ * Return value:  The unpacked double.  On error, this is -1.0 and\r
+ * PyErr_Occurred() is true (and an exception is set, most likely\r
+ * OverflowError).  Note that on a non-IEEE platform this will refuse\r
+ * to unpack a string that represents a NaN or infinity.\r
+ */\r
+PyAPI_FUNC(double) _PyFloat_Unpack4(const unsigned char *p, int le);\r
+PyAPI_FUNC(double) _PyFloat_Unpack8(const unsigned char *p, int le);\r
+\r
+/* free list api */\r
+PyAPI_FUNC(int) PyFloat_ClearFreeList(void);\r
+\r
+/* Format the object based on the format_spec, as defined in PEP 3101\r
+   (Advanced String Formatting). */\r
+PyAPI_FUNC(PyObject *) _PyFloat_FormatAdvanced(PyObject *obj,\r
+                                              char *format_spec,\r
+                                              Py_ssize_t format_spec_len);\r
+\r
+/* Round a C double x to the closest multiple of 10**-ndigits.  Returns a\r
+   Python float on success, or NULL (with an appropriate exception set) on\r
+   failure.  Used in builtin_round in bltinmodule.c. */\r
+PyAPI_FUNC(PyObject *) _Py_double_round(double x, int ndigits);\r
+\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_FLOATOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/frameobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/frameobject.h
new file mode 100644 (file)
index 0000000..2298ed3
--- /dev/null
@@ -0,0 +1,89 @@
+\r
+/* Frame object interface */\r
+\r
+#ifndef Py_FRAMEOBJECT_H\r
+#define Py_FRAMEOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct {\r
+    int b_type;                        /* what kind of block this is */\r
+    int b_handler;             /* where to jump to find handler */\r
+    int b_level;               /* value stack level to pop to */\r
+} PyTryBlock;\r
+\r
+typedef struct _frame {\r
+    PyObject_VAR_HEAD\r
+    struct _frame *f_back;     /* previous frame, or NULL */\r
+    PyCodeObject *f_code;      /* code segment */\r
+    PyObject *f_builtins;      /* builtin symbol table (PyDictObject) */\r
+    PyObject *f_globals;       /* global symbol table (PyDictObject) */\r
+    PyObject *f_locals;                /* local symbol table (any mapping) */\r
+    PyObject **f_valuestack;   /* points after the last local */\r
+    /* Next free slot in f_valuestack.  Frame creation sets to f_valuestack.\r
+       Frame evaluation usually NULLs it, but a frame that yields sets it\r
+       to the current stack top. */\r
+    PyObject **f_stacktop;\r
+    PyObject *f_trace;         /* Trace function */\r
+\r
+    /* If an exception is raised in this frame, the next three are used to\r
+     * record the exception info (if any) originally in the thread state.  See\r
+     * comments before set_exc_info() -- it's not obvious.\r
+     * Invariant:  if _type is NULL, then so are _value and _traceback.\r
+     * Desired invariant:  all three are NULL, or all three are non-NULL.  That\r
+     * one isn't currently true, but "should be".\r
+     */\r
+    PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;\r
+\r
+    PyThreadState *f_tstate;\r
+    int f_lasti;               /* Last instruction if called */\r
+    /* Call PyFrame_GetLineNumber() instead of reading this field\r
+       directly.  As of 2.3 f_lineno is only valid when tracing is\r
+       active (i.e. when f_trace is set).  At other times we use\r
+       PyCode_Addr2Line to calculate the line from the current\r
+       bytecode index. */\r
+    int f_lineno;              /* Current line number */\r
+    int f_iblock;              /* index in f_blockstack */\r
+    PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */\r
+    PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */\r
+} PyFrameObject;\r
+\r
+\r
+/* Standard object interface */\r
+\r
+PyAPI_DATA(PyTypeObject) PyFrame_Type;\r
+\r
+#define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)\r
+#define PyFrame_IsRestricted(f) \\r
+       ((f)->f_builtins != (f)->f_tstate->interp->builtins)\r
+\r
+PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,\r
+                                       PyObject *, PyObject *);\r
+\r
+\r
+/* The rest of the interface is specific for frame objects */\r
+\r
+/* Block management functions */\r
+\r
+PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int);\r
+PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *);\r
+\r
+/* Extend the value stack */\r
+\r
+PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int);\r
+\r
+/* Conversions between "fast locals" and locals in dictionary */\r
+\r
+PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);\r
+PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);\r
+\r
+PyAPI_FUNC(int) PyFrame_ClearFreeList(void);\r
+\r
+/* Return the line of code the frame is currently executing. */\r
+PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_FRAMEOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/funcobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/funcobject.h
new file mode 100644 (file)
index 0000000..07c05ce
--- /dev/null
@@ -0,0 +1,76 @@
+\r
+/* Function object interface */\r
+\r
+#ifndef Py_FUNCOBJECT_H\r
+#define Py_FUNCOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Function objects and code objects should not be confused with each other:\r
+ *\r
+ * Function objects are created by the execution of the 'def' statement.\r
+ * They reference a code object in their func_code attribute, which is a\r
+ * purely syntactic object, i.e. nothing more than a compiled version of some\r
+ * source code lines.  There is one code object per source code "fragment",\r
+ * but each code object can be referenced by zero or many function objects\r
+ * depending only on how many times the 'def' statement in the source was\r
+ * executed so far.\r
+ */\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    PyObject *func_code;       /* A code object */\r
+    PyObject *func_globals;    /* A dictionary (other mappings won't do) */\r
+    PyObject *func_defaults;   /* NULL or a tuple */\r
+    PyObject *func_closure;    /* NULL or a tuple of cell objects */\r
+    PyObject *func_doc;                /* The __doc__ attribute, can be anything */\r
+    PyObject *func_name;       /* The __name__ attribute, a string object */\r
+    PyObject *func_dict;       /* The __dict__ attribute, a dict or NULL */\r
+    PyObject *func_weakreflist;        /* List of weak references */\r
+    PyObject *func_module;     /* The __module__ attribute, can be anything */\r
+\r
+    /* Invariant:\r
+     *     func_closure contains the bindings for func_code->co_freevars, so\r
+     *     PyTuple_Size(func_closure) == PyCode_GetNumFree(func_code)\r
+     *     (func_closure may be NULL if PyCode_GetNumFree(func_code) == 0).\r
+     */\r
+} PyFunctionObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PyFunction_Type;\r
+\r
+#define PyFunction_Check(op) (Py_TYPE(op) == &PyFunction_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PyFunction_New(PyObject *, PyObject *);\r
+PyAPI_FUNC(PyObject *) PyFunction_GetCode(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyFunction_GetGlobals(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyFunction_GetModule(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyFunction_GetDefaults(PyObject *);\r
+PyAPI_FUNC(int) PyFunction_SetDefaults(PyObject *, PyObject *);\r
+PyAPI_FUNC(PyObject *) PyFunction_GetClosure(PyObject *);\r
+PyAPI_FUNC(int) PyFunction_SetClosure(PyObject *, PyObject *);\r
+\r
+/* Macros for direct access to these values. Type checks are *not*\r
+   done, so use with care. */\r
+#define PyFunction_GET_CODE(func) \\r
+        (((PyFunctionObject *)func) -> func_code)\r
+#define PyFunction_GET_GLOBALS(func) \\r
+       (((PyFunctionObject *)func) -> func_globals)\r
+#define PyFunction_GET_MODULE(func) \\r
+       (((PyFunctionObject *)func) -> func_module)\r
+#define PyFunction_GET_DEFAULTS(func) \\r
+       (((PyFunctionObject *)func) -> func_defaults)\r
+#define PyFunction_GET_CLOSURE(func) \\r
+       (((PyFunctionObject *)func) -> func_closure)\r
+\r
+/* The classmethod and staticmethod types lives here, too */\r
+PyAPI_DATA(PyTypeObject) PyClassMethod_Type;\r
+PyAPI_DATA(PyTypeObject) PyStaticMethod_Type;\r
+\r
+PyAPI_FUNC(PyObject *) PyClassMethod_New(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_FUNCOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/genobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/genobject.h
new file mode 100644 (file)
index 0000000..ab9680d
--- /dev/null
@@ -0,0 +1,40 @@
+\r
+/* Generator object interface */\r
+\r
+#ifndef Py_GENOBJECT_H\r
+#define Py_GENOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+struct _frame; /* Avoid including frameobject.h */\r
+\r
+typedef struct {\r
+       PyObject_HEAD\r
+       /* The gi_ prefix is intended to remind of generator-iterator. */\r
+\r
+       /* Note: gi_frame can be NULL if the generator is "finished" */\r
+       struct _frame *gi_frame;\r
+\r
+       /* True if generator is being executed. */\r
+       int gi_running;\r
+    \r
+       /* The code object backing the generator */\r
+       PyObject *gi_code;\r
+\r
+       /* List of weak reference. */\r
+       PyObject *gi_weakreflist;\r
+} PyGenObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PyGen_Type;\r
+\r
+#define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type)\r
+#define PyGen_CheckExact(op) (Py_TYPE(op) == &PyGen_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *);\r
+PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_GENOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/graminit.h b/AppPkg/Applications/Python/Python-2.7.10/Include/graminit.h
new file mode 100644 (file)
index 0000000..b083e9d
--- /dev/null
@@ -0,0 +1,87 @@
+/* Generated by Parser/pgen */\r
+\r
+#define single_input 256\r
+#define file_input 257\r
+#define eval_input 258\r
+#define decorator 259\r
+#define decorators 260\r
+#define decorated 261\r
+#define funcdef 262\r
+#define parameters 263\r
+#define varargslist 264\r
+#define fpdef 265\r
+#define fplist 266\r
+#define stmt 267\r
+#define simple_stmt 268\r
+#define small_stmt 269\r
+#define expr_stmt 270\r
+#define augassign 271\r
+#define print_stmt 272\r
+#define del_stmt 273\r
+#define pass_stmt 274\r
+#define flow_stmt 275\r
+#define break_stmt 276\r
+#define continue_stmt 277\r
+#define return_stmt 278\r
+#define yield_stmt 279\r
+#define raise_stmt 280\r
+#define import_stmt 281\r
+#define import_name 282\r
+#define import_from 283\r
+#define import_as_name 284\r
+#define dotted_as_name 285\r
+#define import_as_names 286\r
+#define dotted_as_names 287\r
+#define dotted_name 288\r
+#define global_stmt 289\r
+#define exec_stmt 290\r
+#define assert_stmt 291\r
+#define compound_stmt 292\r
+#define if_stmt 293\r
+#define while_stmt 294\r
+#define for_stmt 295\r
+#define try_stmt 296\r
+#define with_stmt 297\r
+#define with_item 298\r
+#define except_clause 299\r
+#define suite 300\r
+#define testlist_safe 301\r
+#define old_test 302\r
+#define old_lambdef 303\r
+#define test 304\r
+#define or_test 305\r
+#define and_test 306\r
+#define not_test 307\r
+#define comparison 308\r
+#define comp_op 309\r
+#define expr 310\r
+#define xor_expr 311\r
+#define and_expr 312\r
+#define shift_expr 313\r
+#define arith_expr 314\r
+#define term 315\r
+#define factor 316\r
+#define power 317\r
+#define atom 318\r
+#define listmaker 319\r
+#define testlist_comp 320\r
+#define lambdef 321\r
+#define trailer 322\r
+#define subscriptlist 323\r
+#define subscript 324\r
+#define sliceop 325\r
+#define exprlist 326\r
+#define testlist 327\r
+#define dictorsetmaker 328\r
+#define classdef 329\r
+#define arglist 330\r
+#define argument 331\r
+#define list_iter 332\r
+#define list_for 333\r
+#define list_if 334\r
+#define comp_iter 335\r
+#define comp_for 336\r
+#define comp_if 337\r
+#define testlist1 338\r
+#define encoding_decl 339\r
+#define yield_expr 340\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/grammar.h b/AppPkg/Applications/Python/Python-2.7.10/Include/grammar.h
new file mode 100644 (file)
index 0000000..f82ee9c
--- /dev/null
@@ -0,0 +1,93 @@
+\r
+/* Grammar interface */\r
+\r
+#ifndef Py_GRAMMAR_H\r
+#define Py_GRAMMAR_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#include "bitset.h" /* Sigh... */\r
+\r
+/* A label of an arc */\r
+\r
+typedef struct {\r
+    int                 lb_type;\r
+    char       *lb_str;\r
+} label;\r
+\r
+#define EMPTY 0                /* Label number 0 is by definition the empty label */\r
+\r
+/* A list of labels */\r
+\r
+typedef struct {\r
+    int                 ll_nlabels;\r
+    label      *ll_label;\r
+} labellist;\r
+\r
+/* An arc from one state to another */\r
+\r
+typedef struct {\r
+    short      a_lbl;          /* Label of this arc */\r
+    short      a_arrow;        /* State where this arc goes to */\r
+} arc;\r
+\r
+/* A state in a DFA */\r
+\r
+typedef struct {\r
+    int                 s_narcs;\r
+    arc                *s_arc;         /* Array of arcs */\r
+       \r
+    /* Optional accelerators */\r
+    int                 s_lower;       /* Lowest label index */\r
+    int                 s_upper;       /* Highest label index */\r
+    int                *s_accel;       /* Accelerator */\r
+    int                 s_accept;      /* Nonzero for accepting state */\r
+} state;\r
+\r
+/* A DFA */\r
+\r
+typedef struct {\r
+    int                 d_type;        /* Non-terminal this represents */\r
+    char       *d_name;        /* For printing */\r
+    int                 d_initial;     /* Initial state */\r
+    int                 d_nstates;\r
+    state      *d_state;       /* Array of states */\r
+    bitset      d_first;\r
+} dfa;\r
+\r
+/* A grammar */\r
+\r
+typedef struct {\r
+    int                 g_ndfas;\r
+    dfa                *g_dfa;         /* Array of DFAs */\r
+    labellist   g_ll;\r
+    int                 g_start;       /* Start symbol of the grammar */\r
+    int                 g_accel;       /* Set if accelerators present */\r
+} grammar;\r
+\r
+/* FUNCTIONS */\r
+\r
+grammar *newgrammar(int start);\r
+dfa *adddfa(grammar *g, int type, char *name);\r
+int addstate(dfa *d);\r
+void addarc(dfa *d, int from, int to, int lbl);\r
+dfa *PyGrammar_FindDFA(grammar *g, int type);\r
+\r
+int addlabel(labellist *ll, int type, char *str);\r
+int findlabel(labellist *ll, int type, char *str);\r
+char *PyGrammar_LabelRepr(label *lb);\r
+void translatelabels(grammar *g);\r
+\r
+void addfirstsets(grammar *g);\r
+\r
+void PyGrammar_AddAccelerators(grammar *g);\r
+void PyGrammar_RemoveAccelerators(grammar *);\r
+\r
+void printgrammar(grammar *g, FILE *fp);\r
+void printnonterminals(grammar *g, FILE *fp);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_GRAMMAR_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/import.h b/AppPkg/Applications/Python/Python-2.7.10/Include/import.h
new file mode 100644 (file)
index 0000000..a731f24
--- /dev/null
@@ -0,0 +1,71 @@
+\r
+/* Module definition and import interface */\r
+\r
+#ifndef Py_IMPORT_H\r
+#define Py_IMPORT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_FUNC(long) PyImport_GetMagicNumber(void);\r
+PyAPI_FUNC(PyObject *) PyImport_ExecCodeModule(char *name, PyObject *co);\r
+PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleEx(\r
+       char *name, PyObject *co, char *pathname);\r
+PyAPI_FUNC(PyObject *) PyImport_GetModuleDict(void);\r
+PyAPI_FUNC(PyObject *) PyImport_AddModule(const char *name);\r
+PyAPI_FUNC(PyObject *) PyImport_ImportModule(const char *name);\r
+PyAPI_FUNC(PyObject *) PyImport_ImportModuleNoBlock(const char *);\r
+PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel(char *name,\r
+       PyObject *globals, PyObject *locals, PyObject *fromlist, int level);\r
+\r
+#define PyImport_ImportModuleEx(n, g, l, f) \\r
+       PyImport_ImportModuleLevel(n, g, l, f, -1)\r
+\r
+PyAPI_FUNC(PyObject *) PyImport_GetImporter(PyObject *path);\r
+PyAPI_FUNC(PyObject *) PyImport_Import(PyObject *name);\r
+PyAPI_FUNC(PyObject *) PyImport_ReloadModule(PyObject *m);\r
+PyAPI_FUNC(void) PyImport_Cleanup(void);\r
+PyAPI_FUNC(int) PyImport_ImportFrozenModule(char *);\r
+\r
+#ifdef WITH_THREAD\r
+PyAPI_FUNC(void) _PyImport_AcquireLock(void);\r
+PyAPI_FUNC(int) _PyImport_ReleaseLock(void);\r
+#else\r
+#define _PyImport_AcquireLock()\r
+#define _PyImport_ReleaseLock() 1\r
+#endif\r
+\r
+PyAPI_FUNC(struct filedescr *) _PyImport_FindModule(\r
+       const char *, PyObject *, char *, size_t, FILE **, PyObject **);\r
+PyAPI_FUNC(int) _PyImport_IsScript(struct filedescr *);\r
+PyAPI_FUNC(void) _PyImport_ReInitLock(void);\r
+\r
+PyAPI_FUNC(PyObject *) _PyImport_FindExtension(char *, char *);\r
+PyAPI_FUNC(PyObject *) _PyImport_FixupExtension(char *, char *);\r
+\r
+struct _inittab {\r
+    char *name;\r
+    void (*initfunc)(void);\r
+};\r
+\r
+PyAPI_DATA(PyTypeObject) PyNullImporter_Type;\r
+PyAPI_DATA(struct _inittab *) PyImport_Inittab;\r
+\r
+PyAPI_FUNC(int) PyImport_AppendInittab(const char *name, void (*initfunc)(void));\r
+PyAPI_FUNC(int) PyImport_ExtendInittab(struct _inittab *newtab);\r
+\r
+struct _frozen {\r
+    char *name;\r
+    unsigned char *code;\r
+    int size;\r
+};\r
+\r
+/* Embedding apps may change this pointer to point to their favorite\r
+   collection of frozen modules: */\r
+\r
+PyAPI_DATA(struct _frozen *) PyImport_FrozenModules;\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_IMPORT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/intobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/intobject.h
new file mode 100644 (file)
index 0000000..b286ec6
--- /dev/null
@@ -0,0 +1,81 @@
+\r
+/* Integer object interface */\r
+\r
+/*\r
+PyIntObject represents a (long) integer.  This is an immutable object;\r
+an integer cannot change its value after creation.\r
+\r
+There are functions to create new integer objects, to test an object\r
+for integer-ness, and to get the integer value.  The latter functions\r
+returns -1 and sets errno to EBADF if the object is not an PyIntObject.\r
+None of the functions should be applied to nil objects.\r
+\r
+The type PyIntObject is (unfortunately) exposed here so we can declare\r
+_Py_TrueStruct and _Py_ZeroStruct in boolobject.h; don't use this.\r
+*/\r
+\r
+#ifndef Py_INTOBJECT_H\r
+#define Py_INTOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    long ob_ival;\r
+} PyIntObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PyInt_Type;\r
+\r
+#define PyInt_Check(op) \\r
+                PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_INT_SUBCLASS)\r
+#define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);\r
+#ifdef Py_USING_UNICODE\r
+PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, Py_ssize_t, int);\r
+#endif\r
+PyAPI_FUNC(PyObject *) PyInt_FromLong(long);\r
+PyAPI_FUNC(PyObject *) PyInt_FromSize_t(size_t);\r
+PyAPI_FUNC(PyObject *) PyInt_FromSsize_t(Py_ssize_t);\r
+PyAPI_FUNC(long) PyInt_AsLong(PyObject *);\r
+PyAPI_FUNC(Py_ssize_t) PyInt_AsSsize_t(PyObject *);\r
+PyAPI_FUNC(int) _PyInt_AsInt(PyObject *);\r
+PyAPI_FUNC(unsigned long) PyInt_AsUnsignedLongMask(PyObject *);\r
+#ifdef HAVE_LONG_LONG\r
+PyAPI_FUNC(unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *);\r
+#endif\r
+\r
+PyAPI_FUNC(long) PyInt_GetMax(void);\r
+\r
+/* Macro, trading safety for speed */\r
+#define PyInt_AS_LONG(op) (((PyIntObject *)(op))->ob_ival)\r
+\r
+/* These aren't really part of the Int object, but they're handy; the protos\r
+ * are necessary for systems that need the magic of PyAPI_FUNC and that want\r
+ * to have stropmodule as a dynamically loaded module instead of building it\r
+ * into the main Python shared library/DLL.  Guido thinks I'm weird for\r
+ * building it this way.  :-)  [cjh]\r
+ */\r
+PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int);\r
+PyAPI_FUNC(long) PyOS_strtol(char *, char **, int);\r
+\r
+/* free list api */\r
+PyAPI_FUNC(int) PyInt_ClearFreeList(void);\r
+\r
+/* Convert an integer to the given base.  Returns a string.\r
+   If base is 2, 8 or 16, add the proper prefix '0b', '0o' or '0x'.\r
+   If newstyle is zero, then use the pre-2.6 behavior of octal having\r
+   a leading "0" */\r
+PyAPI_FUNC(PyObject*) _PyInt_Format(PyIntObject* v, int base, int newstyle);\r
+\r
+/* Format the object based on the format_spec, as defined in PEP 3101\r
+   (Advanced String Formatting). */\r
+PyAPI_FUNC(PyObject *) _PyInt_FormatAdvanced(PyObject *obj,\r
+                                            char *format_spec,\r
+                                            Py_ssize_t format_spec_len);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_INTOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/intrcheck.h b/AppPkg/Applications/Python/Python-2.7.10/Include/intrcheck.h
new file mode 100644 (file)
index 0000000..11d759e
--- /dev/null
@@ -0,0 +1,15 @@
+\r
+#ifndef Py_INTRCHECK_H\r
+#define Py_INTRCHECK_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_FUNC(int) PyOS_InterruptOccurred(void);\r
+PyAPI_FUNC(void) PyOS_InitInterrupts(void);\r
+PyAPI_FUNC(void) PyOS_AfterFork(void);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_INTRCHECK_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/iterobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/iterobject.h
new file mode 100644 (file)
index 0000000..ac49cb6
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef Py_ITEROBJECT_H\r
+#define Py_ITEROBJECT_H\r
+/* Iterators (the basic kind, over a sequence) */\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_DATA(PyTypeObject) PySeqIter_Type;\r
+\r
+#define PySeqIter_Check(op) (Py_TYPE(op) == &PySeqIter_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PySeqIter_New(PyObject *);\r
+\r
+PyAPI_DATA(PyTypeObject) PyCallIter_Type;\r
+\r
+#define PyCallIter_Check(op) (Py_TYPE(op) == &PyCallIter_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PyCallIter_New(PyObject *, PyObject *);\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_ITEROBJECT_H */\r
+\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/listobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/listobject.h
new file mode 100644 (file)
index 0000000..1b55d62
--- /dev/null
@@ -0,0 +1,68 @@
+\r
+/* List object interface */\r
+\r
+/*\r
+Another generally useful object type is an list of object pointers.\r
+This is a mutable type: the list items can be changed, and items can be\r
+added or removed.  Out-of-range indices or non-list objects are ignored.\r
+\r
+*** WARNING *** PyList_SetItem does not increment the new item's reference\r
+count, but does decrement the reference count of the item it replaces,\r
+if not nil.  It does *decrement* the reference count if it is *not*\r
+inserted in the list.  Similarly, PyList_GetItem does not increment the\r
+returned item's reference count.\r
+*/\r
+\r
+#ifndef Py_LISTOBJECT_H\r
+#define Py_LISTOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct {\r
+    PyObject_VAR_HEAD\r
+    /* Vector of pointers to list elements.  list[0] is ob_item[0], etc. */\r
+    PyObject **ob_item;\r
+\r
+    /* ob_item contains space for 'allocated' elements.  The number\r
+     * currently in use is ob_size.\r
+     * Invariants:\r
+     *     0 <= ob_size <= allocated\r
+     *     len(list) == ob_size\r
+     *     ob_item == NULL implies ob_size == allocated == 0\r
+     * list.sort() temporarily sets allocated to -1 to detect mutations.\r
+     *\r
+     * Items must normally not be NULL, except during construction when\r
+     * the list is not yet visible outside the function that builds it.\r
+     */\r
+    Py_ssize_t allocated;\r
+} PyListObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PyList_Type;\r
+\r
+#define PyList_Check(op) \\r
+    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)\r
+#define PyList_CheckExact(op) (Py_TYPE(op) == &PyList_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);\r
+PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, Py_ssize_t);\r
+PyAPI_FUNC(int) PyList_SetItem(PyObject *, Py_ssize_t, PyObject *);\r
+PyAPI_FUNC(int) PyList_Insert(PyObject *, Py_ssize_t, PyObject *);\r
+PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *);\r
+PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);\r
+PyAPI_FUNC(int) PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);\r
+PyAPI_FUNC(int) PyList_Sort(PyObject *);\r
+PyAPI_FUNC(int) PyList_Reverse(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *);\r
+PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *);\r
+\r
+/* Macro, trading safety for speed */\r
+#define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])\r
+#define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))\r
+#define PyList_GET_SIZE(op)    Py_SIZE(op)\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_LISTOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/longintrepr.h b/AppPkg/Applications/Python/Python-2.7.10/Include/longintrepr.h
new file mode 100644 (file)
index 0000000..3d1cd25
--- /dev/null
@@ -0,0 +1,103 @@
+#ifndef Py_LONGINTREPR_H\r
+#define Py_LONGINTREPR_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* This is published for the benefit of "friend" marshal.c only. */\r
+\r
+/* Parameters of the long integer representation.  There are two different\r
+   sets of parameters: one set for 30-bit digits, stored in an unsigned 32-bit\r
+   integer type, and one set for 15-bit digits with each digit stored in an\r
+   unsigned short.  The value of PYLONG_BITS_IN_DIGIT, defined either at\r
+   configure time or in pyport.h, is used to decide which digit size to use.\r
+\r
+   Type 'digit' should be able to hold 2*PyLong_BASE-1, and type 'twodigits'\r
+   should be an unsigned integer type able to hold all integers up to\r
+   PyLong_BASE*PyLong_BASE-1.  x_sub assumes that 'digit' is an unsigned type,\r
+   and that overflow is handled by taking the result modulo 2**N for some N >\r
+   PyLong_SHIFT.  The majority of the code doesn't care about the precise\r
+   value of PyLong_SHIFT, but there are some notable exceptions:\r
+\r
+   - long_pow() requires that PyLong_SHIFT be divisible by 5\r
+\r
+   - PyLong_{As,From}ByteArray require that PyLong_SHIFT be at least 8\r
+\r
+   - long_hash() requires that PyLong_SHIFT is *strictly* less than the number\r
+     of bits in an unsigned long, as do the PyLong <-> long (or unsigned long)\r
+     conversion functions\r
+\r
+   - the long <-> size_t/Py_ssize_t conversion functions expect that\r
+     PyLong_SHIFT is strictly less than the number of bits in a size_t\r
+\r
+   - the marshal code currently expects that PyLong_SHIFT is a multiple of 15\r
+\r
+  The values 15 and 30 should fit all of the above requirements, on any\r
+  platform.\r
+*/\r
+\r
+#if PYLONG_BITS_IN_DIGIT == 30\r
+#if !(defined HAVE_UINT64_T && defined HAVE_UINT32_T &&          \\r
+      defined HAVE_INT64_T && defined HAVE_INT32_T)\r
+#error "30-bit long digits requested, but the necessary types are not available on this platform"\r
+#endif\r
+typedef PY_UINT32_T digit;\r
+typedef PY_INT32_T sdigit; /* signed variant of digit */\r
+typedef PY_UINT64_T twodigits;\r
+typedef PY_INT64_T stwodigits; /* signed variant of twodigits */\r
+#define PyLong_SHIFT   30\r
+#define _PyLong_DECIMAL_SHIFT  9 /* max(e such that 10**e fits in a digit) */\r
+#define _PyLong_DECIMAL_BASE   ((digit)1000000000) /* 10 ** DECIMAL_SHIFT */\r
+#elif PYLONG_BITS_IN_DIGIT == 15\r
+typedef unsigned short digit;\r
+typedef short sdigit; /* signed variant of digit */\r
+typedef unsigned long twodigits;\r
+typedef long stwodigits; /* signed variant of twodigits */\r
+#define PyLong_SHIFT   15\r
+#define _PyLong_DECIMAL_SHIFT  4 /* max(e such that 10**e fits in a digit) */\r
+#define _PyLong_DECIMAL_BASE   ((digit)10000) /* 10 ** DECIMAL_SHIFT */\r
+#else\r
+#error "PYLONG_BITS_IN_DIGIT should be 15 or 30"\r
+#endif\r
+#define PyLong_BASE    ((digit)1 << PyLong_SHIFT)\r
+#define PyLong_MASK    ((digit)(PyLong_BASE - 1))\r
+\r
+/* b/w compatibility with Python 2.5 */\r
+#define SHIFT  PyLong_SHIFT\r
+#define BASE   PyLong_BASE\r
+#define MASK   PyLong_MASK\r
+\r
+#if PyLong_SHIFT % 5 != 0\r
+#error "longobject.c requires that PyLong_SHIFT be divisible by 5"\r
+#endif\r
+\r
+/* Long integer representation.\r
+   The absolute value of a number is equal to\r
+       SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i)\r
+   Negative numbers are represented with ob_size < 0;\r
+   zero is represented by ob_size == 0.\r
+   In a normalized number, ob_digit[abs(ob_size)-1] (the most significant\r
+   digit) is never zero.  Also, in all cases, for all valid i,\r
+       0 <= ob_digit[i] <= MASK.\r
+   The allocation function takes care of allocating extra memory\r
+   so that ob_digit[0] ... ob_digit[abs(ob_size)-1] are actually available.\r
+\r
+   CAUTION:  Generic code manipulating subtypes of PyVarObject has to\r
+   aware that longs abuse  ob_size's sign bit.\r
+*/\r
+\r
+struct _longobject {\r
+       PyObject_VAR_HEAD\r
+       digit ob_digit[1];\r
+};\r
+\r
+PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);\r
+\r
+/* Return a copy of src. */\r
+PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_LONGINTREPR_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/longobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/longobject.h
new file mode 100644 (file)
index 0000000..71453b4
--- /dev/null
@@ -0,0 +1,135 @@
+#ifndef Py_LONGOBJECT_H\r
+#define Py_LONGOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Long (arbitrary precision) integer object interface */\r
+\r
+typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */\r
+\r
+PyAPI_DATA(PyTypeObject) PyLong_Type;\r
+\r
+#define PyLong_Check(op) \\r
+               PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)\r
+#define PyLong_CheckExact(op) (Py_TYPE(op) == &PyLong_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PyLong_FromLong(long);\r
+PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long);\r
+PyAPI_FUNC(PyObject *) PyLong_FromDouble(double);\r
+PyAPI_FUNC(PyObject *) PyLong_FromSize_t(size_t);\r
+PyAPI_FUNC(PyObject *) PyLong_FromSsize_t(Py_ssize_t);\r
+PyAPI_FUNC(long) PyLong_AsLong(PyObject *);\r
+PyAPI_FUNC(long) PyLong_AsLongAndOverflow(PyObject *, int *);\r
+PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);\r
+PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);\r
+PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *);\r
+PyAPI_FUNC(int) _PyLong_AsInt(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyLong_GetInfo(void);\r
+\r
+/* For use by intobject.c only */\r
+#define _PyLong_AsSsize_t PyLong_AsSsize_t\r
+#define _PyLong_FromSize_t PyLong_FromSize_t\r
+#define _PyLong_FromSsize_t PyLong_FromSsize_t\r
+PyAPI_DATA(int) _PyLong_DigitValue[256];\r
+\r
+/* _PyLong_Frexp returns a double x and an exponent e such that the\r
+   true value is approximately equal to x * 2**e.  e is >= 0.  x is\r
+   0.0 if and only if the input is 0 (in which case, e and x are both\r
+   zeroes); otherwise, 0.5 <= abs(x) < 1.0.  On overflow, which is\r
+   possible if the number of bits doesn't fit into a Py_ssize_t, sets\r
+   OverflowError and returns -1.0 for x, 0 for e. */\r
+PyAPI_FUNC(double) _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e);\r
+\r
+PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);\r
+PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *);\r
+\r
+#ifdef HAVE_LONG_LONG\r
+PyAPI_FUNC(PyObject *) PyLong_FromLongLong(PY_LONG_LONG);\r
+PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG);\r
+PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLong(PyObject *);\r
+PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLong(PyObject *);\r
+PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *);\r
+PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLongAndOverflow(PyObject *, int *);\r
+#endif /* HAVE_LONG_LONG */\r
+\r
+PyAPI_FUNC(PyObject *) PyLong_FromString(char *, char **, int);\r
+#ifdef Py_USING_UNICODE\r
+PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int);\r
+#endif\r
+\r
+/* _PyLong_Sign.  Return 0 if v is 0, -1 if v < 0, +1 if v > 0.\r
+   v must not be NULL, and must be a normalized long.\r
+   There are no error cases.\r
+*/\r
+PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);\r
+\r
+\r
+/* _PyLong_NumBits.  Return the number of bits needed to represent the\r
+   absolute value of a long.  For example, this returns 1 for 1 and -1, 2\r
+   for 2 and -2, and 2 for 3 and -3.  It returns 0 for 0.\r
+   v must not be NULL, and must be a normalized long.\r
+   (size_t)-1 is returned and OverflowError set if the true result doesn't\r
+   fit in a size_t.\r
+*/\r
+PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v);\r
+\r
+/* _PyLong_FromByteArray:  View the n unsigned bytes as a binary integer in\r
+   base 256, and return a Python long with the same numeric value.\r
+   If n is 0, the integer is 0.  Else:\r
+   If little_endian is 1/true, bytes[n-1] is the MSB and bytes[0] the LSB;\r
+   else (little_endian is 0/false) bytes[0] is the MSB and bytes[n-1] the\r
+   LSB.\r
+   If is_signed is 0/false, view the bytes as a non-negative integer.\r
+   If is_signed is 1/true, view the bytes as a 2's-complement integer,\r
+   non-negative if bit 0x80 of the MSB is clear, negative if set.\r
+   Error returns:\r
+   + Return NULL with the appropriate exception set if there's not\r
+     enough memory to create the Python long.\r
+*/\r
+PyAPI_FUNC(PyObject *) _PyLong_FromByteArray(\r
+       const unsigned char* bytes, size_t n,\r
+       int little_endian, int is_signed);\r
+\r
+/* _PyLong_AsByteArray: Convert the least-significant 8*n bits of long\r
+   v to a base-256 integer, stored in array bytes.  Normally return 0,\r
+   return -1 on error.\r
+   If little_endian is 1/true, store the MSB at bytes[n-1] and the LSB at\r
+   bytes[0]; else (little_endian is 0/false) store the MSB at bytes[0] and\r
+   the LSB at bytes[n-1].\r
+   If is_signed is 0/false, it's an error if v < 0; else (v >= 0) n bytes\r
+   are filled and there's nothing special about bit 0x80 of the MSB.\r
+   If is_signed is 1/true, bytes is filled with the 2's-complement\r
+   representation of v's value.  Bit 0x80 of the MSB is the sign bit.\r
+   Error returns (-1):\r
+   + is_signed is 0 and v < 0.  TypeError is set in this case, and bytes\r
+     isn't altered.\r
+   + n isn't big enough to hold the full mathematical value of v.  For\r
+     example, if is_signed is 0 and there are more digits in the v than\r
+     fit in n; or if is_signed is 1, v < 0, and n is just 1 bit shy of\r
+     being large enough to hold a sign bit.  OverflowError is set in this\r
+     case, but bytes holds the least-signficant n bytes of the true value.\r
+*/\r
+PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v,\r
+       unsigned char* bytes, size_t n,\r
+       int little_endian, int is_signed);\r
+\r
+/* _PyLong_Format: Convert the long to a string object with given base,\r
+   appending a base prefix of 0[box] if base is 2, 8 or 16.\r
+   Add a trailing "L" if addL is non-zero.\r
+   If newstyle is zero, then use the pre-2.6 behavior of octal having\r
+   a leading "0", instead of the prefix "0o" */\r
+PyAPI_FUNC(PyObject *) _PyLong_Format(PyObject *aa, int base, int addL, int newstyle);\r
+\r
+/* Format the object based on the format_spec, as defined in PEP 3101\r
+   (Advanced String Formatting). */\r
+PyAPI_FUNC(PyObject *) _PyLong_FormatAdvanced(PyObject *obj,\r
+                                             char *format_spec,\r
+                                             Py_ssize_t format_spec_len);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_LONGOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/marshal.h b/AppPkg/Applications/Python/Python-2.7.10/Include/marshal.h
new file mode 100644 (file)
index 0000000..43ac538
--- /dev/null
@@ -0,0 +1,25 @@
+\r
+/* Interface for marshal.c */\r
+\r
+#ifndef Py_MARSHAL_H\r
+#define Py_MARSHAL_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#define Py_MARSHAL_VERSION 2\r
+\r
+PyAPI_FUNC(void) PyMarshal_WriteLongToFile(long, FILE *, int);\r
+PyAPI_FUNC(void) PyMarshal_WriteObjectToFile(PyObject *, FILE *, int);\r
+PyAPI_FUNC(PyObject *) PyMarshal_WriteObjectToString(PyObject *, int);\r
+\r
+PyAPI_FUNC(long) PyMarshal_ReadLongFromFile(FILE *);\r
+PyAPI_FUNC(int) PyMarshal_ReadShortFromFile(FILE *);\r
+PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromFile(FILE *);\r
+PyAPI_FUNC(PyObject *) PyMarshal_ReadLastObjectFromFile(FILE *);\r
+PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_MARSHAL_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/memoryobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/memoryobject.h
new file mode 100644 (file)
index 0000000..ca5064e
--- /dev/null
@@ -0,0 +1,74 @@
+/* Memory view object. In Python this is available as "memoryview". */\r
+\r
+#ifndef Py_MEMORYOBJECT_H\r
+#define Py_MEMORYOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_DATA(PyTypeObject) PyMemoryView_Type;\r
+\r
+#define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type)\r
+\r
+/* Get a pointer to the underlying Py_buffer of a memoryview object. */\r
+#define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view)\r
+/* Get a pointer to the PyObject from which originates a memoryview object. */\r
+#define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj)\r
+\r
+\r
+PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, \r
+                                                 int buffertype, \r
+                                                 char fort);\r
+\r
+    /* Return a contiguous chunk of memory representing the buffer\r
+       from an object in a memory view object.  If a copy is made then the\r
+       base object for the memory view will be a *new* bytes object. \r
+       \r
+       Otherwise, the base-object will be the object itself and no \r
+       data-copying will be done. \r
+\r
+       The buffertype argument can be PyBUF_READ, PyBUF_WRITE,\r
+       PyBUF_SHADOW to determine whether the returned buffer\r
+       should be READONLY, WRITABLE, or set to update the\r
+       original buffer if a copy must be made.  If buffertype is\r
+       PyBUF_WRITE and the buffer is not contiguous an error will\r
+       be raised.  In this circumstance, the user can use\r
+       PyBUF_SHADOW to ensure that a a writable temporary\r
+       contiguous buffer is returned.  The contents of this\r
+       contiguous buffer will be copied back into the original\r
+       object after the memoryview object is deleted as long as\r
+       the original object is writable and allows setting an\r
+       exclusive write lock. If this is not allowed by the\r
+       original object, then a BufferError is raised.\r
+       \r
+       If the object is multi-dimensional and if fortran is 'F',\r
+       the first dimension of the underlying array will vary the\r
+       fastest in the buffer.  If fortran is 'C', then the last\r
+       dimension will vary the fastest (C-style contiguous).  If\r
+       fortran is 'A', then it does not matter and you will get\r
+       whatever the object decides is more efficient.  \r
+\r
+       A new reference is returned that must be DECREF'd when finished.\r
+    */\r
+\r
+PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);\r
+\r
+PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info);\r
+    /* create new if bufptr is NULL \r
+        will be a new bytesobject in base */\r
+\r
+\r
+/* The struct is declared here so that macros can work, but it shouldn't\r
+   be considered public. Don't access those fields directly, use the macros\r
+   and functions instead! */\r
+typedef struct {\r
+    PyObject_HEAD\r
+    PyObject *base;\r
+    Py_buffer view;\r
+} PyMemoryViewObject;\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_MEMORYOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/metagrammar.h b/AppPkg/Applications/Python/Python-2.7.10/Include/metagrammar.h
new file mode 100644 (file)
index 0000000..1fb471a
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef Py_METAGRAMMAR_H\r
+#define Py_METAGRAMMAR_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+#define MSTART 256\r
+#define RULE 257\r
+#define RHS 258\r
+#define ALT 259\r
+#define ITEM 260\r
+#define ATOM 261\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_METAGRAMMAR_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/methodobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/methodobject.h
new file mode 100644 (file)
index 0000000..8b28288
--- /dev/null
@@ -0,0 +1,93 @@
+\r
+/* Method object interface */\r
+\r
+#ifndef Py_METHODOBJECT_H\r
+#define Py_METHODOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* This is about the type 'builtin_function_or_method',\r
+   not Python methods in user-defined classes.  See classobject.h\r
+   for the latter. */\r
+\r
+PyAPI_DATA(PyTypeObject) PyCFunction_Type;\r
+\r
+#define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type)\r
+\r
+typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);\r
+typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,\r
+                                            PyObject *);\r
+typedef PyObject *(*PyNoArgsFunction)(PyObject *);\r
+\r
+PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);\r
+PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);\r
+\r
+/* Macros for direct access to these values. Type checks are *not*\r
+   done, so use with care. */\r
+#define PyCFunction_GET_FUNCTION(func) \\r
+        (((PyCFunctionObject *)func) -> m_ml -> ml_meth)\r
+#define PyCFunction_GET_SELF(func) \\r
+       (((PyCFunctionObject *)func) -> m_self)\r
+#define PyCFunction_GET_FLAGS(func) \\r
+       (((PyCFunctionObject *)func) -> m_ml -> ml_flags)\r
+PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);\r
+\r
+struct PyMethodDef {\r
+    const char *ml_name;       /* The name of the built-in function/method */\r
+    PyCFunction  ml_meth;      /* The C function that implements it */\r
+    int                 ml_flags;      /* Combination of METH_xxx flags, which mostly\r
+                                  describe the args expected by the C func */\r
+    const char *ml_doc;        /* The __doc__ attribute, or NULL */\r
+};\r
+typedef struct PyMethodDef PyMethodDef;\r
+\r
+PyAPI_FUNC(PyObject *) Py_FindMethod(PyMethodDef[], PyObject *, const char *);\r
+\r
+#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)\r
+PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, \r
+                                        PyObject *);\r
+\r
+/* Flag passed to newmethodobject */\r
+#define METH_OLDARGS  0x0000\r
+#define METH_VARARGS  0x0001\r
+#define METH_KEYWORDS 0x0002\r
+/* METH_NOARGS and METH_O must not be combined with the flags above. */\r
+#define METH_NOARGS   0x0004\r
+#define METH_O        0x0008\r
+\r
+/* METH_CLASS and METH_STATIC are a little different; these control\r
+   the construction of methods for a class.  These cannot be used for\r
+   functions in modules. */\r
+#define METH_CLASS    0x0010\r
+#define METH_STATIC   0x0020\r
+\r
+/* METH_COEXIST allows a method to be entered eventhough a slot has\r
+   already filled the entry.  When defined, the flag allows a separate\r
+   method, "__contains__" for example, to coexist with a defined \r
+   slot like sq_contains. */\r
+\r
+#define METH_COEXIST   0x0040\r
+\r
+typedef struct PyMethodChain {\r
+    PyMethodDef *methods;              /* Methods of this type */\r
+    struct PyMethodChain *link;        /* NULL or base type */\r
+} PyMethodChain;\r
+\r
+PyAPI_FUNC(PyObject *) Py_FindMethodInChain(PyMethodChain *, PyObject *,\r
+                                            const char *);\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    PyMethodDef *m_ml; /* Description of the C function to call */\r
+    PyObject    *m_self; /* Passed as 'self' arg to the C func, can be NULL */\r
+    PyObject    *m_module; /* The __module__ attribute, can be anything */\r
+} PyCFunctionObject;\r
+\r
+PyAPI_FUNC(int) PyCFunction_ClearFreeList(void);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_METHODOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/modsupport.h b/AppPkg/Applications/Python/Python-2.7.10/Include/modsupport.h
new file mode 100644 (file)
index 0000000..8a8cf8d
--- /dev/null
@@ -0,0 +1,134 @@
+\r
+#ifndef Py_MODSUPPORT_H\r
+#define Py_MODSUPPORT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Module support interface */\r
+\r
+#include <stdarg.h>\r
+\r
+/* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier\r
+   to mean Py_ssize_t */\r
+#ifdef PY_SSIZE_T_CLEAN\r
+#define PyArg_Parse                    _PyArg_Parse_SizeT\r
+#define PyArg_ParseTuple               _PyArg_ParseTuple_SizeT\r
+#define PyArg_ParseTupleAndKeywords    _PyArg_ParseTupleAndKeywords_SizeT\r
+#define PyArg_VaParse                  _PyArg_VaParse_SizeT\r
+#define PyArg_VaParseTupleAndKeywords  _PyArg_VaParseTupleAndKeywords_SizeT\r
+#define Py_BuildValue                  _Py_BuildValue_SizeT\r
+#define Py_VaBuildValue                        _Py_VaBuildValue_SizeT\r
+#else\r
+PyAPI_FUNC(PyObject *) _Py_VaBuildValue_SizeT(const char *, va_list);\r
+#endif\r
+\r
+PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);\r
+PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...) Py_FORMAT_PARSETUPLE(PyArg_ParseTuple, 2, 3);\r
+PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,\r
+                                                  const char *, char **, ...);\r
+PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, const char *, Py_ssize_t, Py_ssize_t, ...);\r
+PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...);\r
+PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...);\r
+PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kw);\r
+\r
+PyAPI_FUNC(int) PyArg_VaParse(PyObject *, const char *, va_list);\r
+PyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,\r
+                                                  const char *, char **, va_list);\r
+PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list);\r
+\r
+PyAPI_FUNC(int) PyModule_AddObject(PyObject *, const char *, PyObject *);\r
+PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);\r
+PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *);\r
+#define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)\r
+#define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant(m, #c, c)\r
+\r
+#define PYTHON_API_VERSION 1013\r
+#define PYTHON_API_STRING "1013"\r
+/* The API version is maintained (independently from the Python version)\r
+   so we can detect mismatches between the interpreter and dynamically\r
+   loaded modules.  These are diagnosed by an error message but\r
+   the module is still loaded (because the mismatch can only be tested\r
+   after loading the module).  The error message is intended to\r
+   explain the core dump a few seconds later.\r
+\r
+   The symbol PYTHON_API_STRING defines the same value as a string\r
+   literal.  *** PLEASE MAKE SURE THE DEFINITIONS MATCH. ***\r
+\r
+   Please add a line or two to the top of this log for each API\r
+   version change:\r
+\r
+   22-Feb-2006  MvL    1013    PEP 353 - long indices for sequence lengths\r
+\r
+   19-Aug-2002  GvR    1012    Changes to string object struct for\r
+                               interning changes, saving 3 bytes.\r
+\r
+   17-Jul-2001 GvR     1011    Descr-branch, just to be on the safe side\r
+\r
+   25-Jan-2001  FLD     1010    Parameters added to PyCode_New() and\r
+                                PyFrame_New(); Python 2.1a2\r
+\r
+   14-Mar-2000  GvR     1009    Unicode API added\r
+\r
+   3-Jan-1999  GvR     1007    Decided to change back!  (Don't reuse 1008!)\r
+\r
+   3-Dec-1998  GvR     1008    Python 1.5.2b1\r
+\r
+   18-Jan-1997 GvR     1007    string interning and other speedups\r
+\r
+   11-Oct-1996 GvR     renamed Py_Ellipses to Py_Ellipsis :-(\r
+\r
+   30-Jul-1996 GvR     Slice and ellipses syntax added\r
+\r
+   23-Jul-1996 GvR     For 1.4 -- better safe than sorry this time :-)\r
+\r
+   7-Nov-1995  GvR     Keyword arguments (should've been done at 1.3 :-( )\r
+\r
+   10-Jan-1995 GvR     Renamed globals to new naming scheme\r
+\r
+   9-Jan-1995  GvR     Initial version (incompatible with older API)\r
+*/\r
+\r
+#ifdef MS_WINDOWS\r
+/* Special defines for Windows versions used to live here.  Things\r
+   have changed, and the "Version" is now in a global string variable.\r
+   Reason for this is that this for easier branding of a "custom DLL"\r
+   without actually needing a recompile.  */\r
+#endif /* MS_WINDOWS */\r
+\r
+#if SIZEOF_SIZE_T != SIZEOF_INT\r
+/* On a 64-bit system, rename the Py_InitModule4 so that 2.4\r
+   modules cannot get loaded into a 2.5 interpreter */\r
+#define Py_InitModule4 Py_InitModule4_64\r
+#endif\r
+\r
+#ifdef Py_TRACE_REFS\r
+ /* When we are tracing reference counts, rename Py_InitModule4 so\r
+    modules compiled with incompatible settings will generate a\r
+    link-time error. */\r
+ #if SIZEOF_SIZE_T != SIZEOF_INT\r
+ #undef Py_InitModule4\r
+ #define Py_InitModule4 Py_InitModule4TraceRefs_64\r
+ #else\r
+ #define Py_InitModule4 Py_InitModule4TraceRefs\r
+ #endif\r
+#endif\r
+\r
+PyAPI_FUNC(PyObject *) Py_InitModule4(const char *name, PyMethodDef *methods,\r
+                                      const char *doc, PyObject *self,\r
+                                      int apiver);\r
+\r
+#define Py_InitModule(name, methods) \\r
+       Py_InitModule4(name, methods, (char *)NULL, (PyObject *)NULL, \\r
+                      PYTHON_API_VERSION)\r
+\r
+#define Py_InitModule3(name, methods, doc) \\r
+       Py_InitModule4(name, methods, doc, (PyObject *)NULL, \\r
+                      PYTHON_API_VERSION)\r
+\r
+PyAPI_DATA(char *) _Py_PackageContext;\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_MODSUPPORT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/moduleobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/moduleobject.h
new file mode 100644 (file)
index 0000000..ff16ad2
--- /dev/null
@@ -0,0 +1,24 @@
+\r
+/* Module object interface */\r
+\r
+#ifndef Py_MODULEOBJECT_H\r
+#define Py_MODULEOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_DATA(PyTypeObject) PyModule_Type;\r
+\r
+#define PyModule_Check(op) PyObject_TypeCheck(op, &PyModule_Type)\r
+#define PyModule_CheckExact(op) (Py_TYPE(op) == &PyModule_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PyModule_New(const char *);\r
+PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *);\r
+PyAPI_FUNC(char *) PyModule_GetName(PyObject *);\r
+PyAPI_FUNC(char *) PyModule_GetFilename(PyObject *);\r
+PyAPI_FUNC(void) _PyModule_Clear(PyObject *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_MODULEOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/node.h b/AppPkg/Applications/Python/Python-2.7.10/Include/node.h
new file mode 100644 (file)
index 0000000..9baa89a
--- /dev/null
@@ -0,0 +1,41 @@
+\r
+/* Parse tree node interface */\r
+\r
+#ifndef Py_NODE_H\r
+#define Py_NODE_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct _node {\r
+    short              n_type;\r
+    char               *n_str;\r
+    int                        n_lineno;\r
+    int                        n_col_offset;\r
+    int                        n_nchildren;\r
+    struct _node       *n_child;\r
+} node;\r
+\r
+PyAPI_FUNC(node *) PyNode_New(int type);\r
+PyAPI_FUNC(int) PyNode_AddChild(node *n, int type,\r
+                                      char *str, int lineno, int col_offset);\r
+PyAPI_FUNC(void) PyNode_Free(node *n);\r
+PyAPI_FUNC(Py_ssize_t) _PyNode_SizeOf(node *n);\r
+\r
+/* Node access functions */\r
+#define NCH(n)         ((n)->n_nchildren)\r
+       \r
+#define CHILD(n, i)    (&(n)->n_child[i])\r
+#define RCHILD(n, i)   (CHILD(n, NCH(n) + i))\r
+#define TYPE(n)                ((n)->n_type)\r
+#define STR(n)         ((n)->n_str)\r
+\r
+/* Assert that the type of a node is what we expect */\r
+#define REQ(n, type) assert(TYPE(n) == (type))\r
+\r
+PyAPI_FUNC(void) PyNode_ListTree(node *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_NODE_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/object.h b/AppPkg/Applications/Python/Python-2.7.10/Include/object.h
new file mode 100644 (file)
index 0000000..bb5fa3c
--- /dev/null
@@ -0,0 +1,1013 @@
+#ifndef Py_OBJECT_H\r
+#define Py_OBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Object and type object interface */\r
+\r
+/*\r
+Objects are structures allocated on the heap.  Special rules apply to\r
+the use of objects to ensure they are properly garbage-collected.\r
+Objects are never allocated statically or on the stack; they must be\r
+accessed through special macros and functions only.  (Type objects are\r
+exceptions to the first rule; the standard types are represented by\r
+statically initialized type objects, although work on type/class unification\r
+for Python 2.2 made it possible to have heap-allocated type objects too).\r
+\r
+An object has a 'reference count' that is increased or decreased when a\r
+pointer to the object is copied or deleted; when the reference count\r
+reaches zero there are no references to the object left and it can be\r
+removed from the heap.\r
+\r
+An object has a 'type' that determines what it represents and what kind\r
+of data it contains.  An object's type is fixed when it is created.\r
+Types themselves are represented as objects; an object contains a\r
+pointer to the corresponding type object.  The type itself has a type\r
+pointer pointing to the object representing the type 'type', which\r
+contains a pointer to itself!).\r
+\r
+Objects do not float around in memory; once allocated an object keeps\r
+the same size and address.  Objects that must hold variable-size data\r
+can contain pointers to variable-size parts of the object.  Not all\r
+objects of the same type have the same size; but the size cannot change\r
+after allocation.  (These restrictions are made so a reference to an\r
+object can be simply a pointer -- moving an object would require\r
+updating all the pointers, and changing an object's size would require\r
+moving it if there was another object right next to it.)\r
+\r
+Objects are always accessed through pointers of the type 'PyObject *'.\r
+The type 'PyObject' is a structure that only contains the reference count\r
+and the type pointer.  The actual memory allocated for an object\r
+contains other data that can only be accessed after casting the pointer\r
+to a pointer to a longer structure type.  This longer type must start\r
+with the reference count and type fields; the macro PyObject_HEAD should be\r
+used for this (to accommodate for future changes).  The implementation\r
+of a particular object type can cast the object pointer to the proper\r
+type and back.\r
+\r
+A standard interface exists for objects that contain an array of items\r
+whose size is determined when the object is allocated.\r
+*/\r
+\r
+/* Py_DEBUG implies Py_TRACE_REFS. */\r
+#if defined(Py_DEBUG) && !defined(Py_TRACE_REFS)\r
+#define Py_TRACE_REFS\r
+#endif\r
+\r
+/* Py_TRACE_REFS implies Py_REF_DEBUG. */\r
+#if defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG)\r
+#define Py_REF_DEBUG\r
+#endif\r
+\r
+#ifdef Py_TRACE_REFS\r
+/* Define pointers to support a doubly-linked list of all live heap objects. */\r
+#define _PyObject_HEAD_EXTRA            \\r
+    struct _object *_ob_next;           \\r
+    struct _object *_ob_prev;\r
+\r
+#define _PyObject_EXTRA_INIT 0, 0,\r
+\r
+#else\r
+#define _PyObject_HEAD_EXTRA\r
+#define _PyObject_EXTRA_INIT\r
+#endif\r
+\r
+/* PyObject_HEAD defines the initial segment of every PyObject. */\r
+#define PyObject_HEAD                   \\r
+    _PyObject_HEAD_EXTRA                \\r
+    Py_ssize_t ob_refcnt;               \\r
+    struct _typeobject *ob_type;\r
+\r
+#define PyObject_HEAD_INIT(type)        \\r
+    _PyObject_EXTRA_INIT                \\r
+    1, type,\r
+\r
+#define PyVarObject_HEAD_INIT(type, size)       \\r
+    PyObject_HEAD_INIT(type) size,\r
+\r
+/* PyObject_VAR_HEAD defines the initial segment of all variable-size\r
+ * container objects.  These end with a declaration of an array with 1\r
+ * element, but enough space is malloc'ed so that the array actually\r
+ * has room for ob_size elements.  Note that ob_size is an element count,\r
+ * not necessarily a byte count.\r
+ */\r
+#define PyObject_VAR_HEAD               \\r
+    PyObject_HEAD                       \\r
+    Py_ssize_t ob_size; /* Number of items in variable part */\r
+#define Py_INVALID_SIZE (Py_ssize_t)-1\r
+\r
+/* Nothing is actually declared to be a PyObject, but every pointer to\r
+ * a Python object can be cast to a PyObject*.  This is inheritance built\r
+ * by hand.  Similarly every pointer to a variable-size Python object can,\r
+ * in addition, be cast to PyVarObject*.\r
+ */\r
+typedef struct _object {\r
+    PyObject_HEAD\r
+} PyObject;\r
+\r
+typedef struct {\r
+    PyObject_VAR_HEAD\r
+} PyVarObject;\r
+\r
+#define Py_REFCNT(ob)           (((PyObject*)(ob))->ob_refcnt)\r
+#define Py_TYPE(ob)             (((PyObject*)(ob))->ob_type)\r
+#define Py_SIZE(ob)             (((PyVarObject*)(ob))->ob_size)\r
+\r
+/*\r
+Type objects contain a string containing the type name (to help somewhat\r
+in debugging), the allocation parameters (see PyObject_New() and\r
+PyObject_NewVar()),\r
+and methods for accessing objects of the type.  Methods are optional, a\r
+nil pointer meaning that particular kind of access is not available for\r
+this type.  The Py_DECREF() macro uses the tp_dealloc method without\r
+checking for a nil pointer; it should always be implemented except if\r
+the implementation can guarantee that the reference count will never\r
+reach zero (e.g., for statically allocated type objects).\r
+\r
+NB: the methods for certain type groups are now contained in separate\r
+method blocks.\r
+*/\r
+\r
+typedef PyObject * (*unaryfunc)(PyObject *);\r
+typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);\r
+typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);\r
+typedef int (*inquiry)(PyObject *);\r
+typedef Py_ssize_t (*lenfunc)(PyObject *);\r
+typedef int (*coercion)(PyObject **, PyObject **);\r
+typedef PyObject *(*intargfunc)(PyObject *, int) Py_DEPRECATED(2.5);\r
+typedef PyObject *(*intintargfunc)(PyObject *, int, int) Py_DEPRECATED(2.5);\r
+typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);\r
+typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);\r
+typedef int(*intobjargproc)(PyObject *, int, PyObject *);\r
+typedef int(*intintobjargproc)(PyObject *, int, int, PyObject *);\r
+typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);\r
+typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);\r
+typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);\r
+\r
+\r
+\r
+/* int-based buffer interface */\r
+typedef int (*getreadbufferproc)(PyObject *, int, void **);\r
+typedef int (*getwritebufferproc)(PyObject *, int, void **);\r
+typedef int (*getsegcountproc)(PyObject *, int *);\r
+typedef int (*getcharbufferproc)(PyObject *, int, char **);\r
+/* ssize_t-based buffer interface */\r
+typedef Py_ssize_t (*readbufferproc)(PyObject *, Py_ssize_t, void **);\r
+typedef Py_ssize_t (*writebufferproc)(PyObject *, Py_ssize_t, void **);\r
+typedef Py_ssize_t (*segcountproc)(PyObject *, Py_ssize_t *);\r
+typedef Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, char **);\r
+\r
+\r
+/* Py3k buffer interface */\r
+typedef struct bufferinfo {\r
+    void *buf;\r
+    PyObject *obj;        /* owned reference */\r
+    Py_ssize_t len;\r
+    Py_ssize_t itemsize;  /* This is Py_ssize_t so it can be\r
+                             pointed to by strides in simple case.*/\r
+    int readonly;\r
+    int ndim;\r
+    char *format;\r
+    Py_ssize_t *shape;\r
+    Py_ssize_t *strides;\r
+    Py_ssize_t *suboffsets;\r
+    Py_ssize_t smalltable[2];  /* static store for shape and strides of\r
+                                  mono-dimensional buffers. */\r
+    void *internal;\r
+} Py_buffer;\r
+\r
+typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);\r
+typedef void (*releasebufferproc)(PyObject *, Py_buffer *);\r
+\r
+    /* Flags for getting buffers */\r
+#define PyBUF_SIMPLE 0\r
+#define PyBUF_WRITABLE 0x0001\r
+/*  we used to include an E, backwards compatible alias  */\r
+#define PyBUF_WRITEABLE PyBUF_WRITABLE\r
+#define PyBUF_FORMAT 0x0004\r
+#define PyBUF_ND 0x0008\r
+#define PyBUF_STRIDES (0x0010 | PyBUF_ND)\r
+#define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)\r
+#define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)\r
+#define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)\r
+#define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)\r
+\r
+#define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)\r
+#define PyBUF_CONTIG_RO (PyBUF_ND)\r
+\r
+#define PyBUF_STRIDED (PyBUF_STRIDES | PyBUF_WRITABLE)\r
+#define PyBUF_STRIDED_RO (PyBUF_STRIDES)\r
+\r
+#define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT)\r
+#define PyBUF_RECORDS_RO (PyBUF_STRIDES | PyBUF_FORMAT)\r
+\r
+#define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT)\r
+#define PyBUF_FULL_RO (PyBUF_INDIRECT | PyBUF_FORMAT)\r
+\r
+\r
+#define PyBUF_READ  0x100\r
+#define PyBUF_WRITE 0x200\r
+#define PyBUF_SHADOW 0x400\r
+/* end Py3k buffer interface */\r
+\r
+typedef int (*objobjproc)(PyObject *, PyObject *);\r
+typedef int (*visitproc)(PyObject *, void *);\r
+typedef int (*traverseproc)(PyObject *, visitproc, void *);\r
+\r
+typedef struct {\r
+    /* For numbers without flag bit Py_TPFLAGS_CHECKTYPES set, all\r
+       arguments are guaranteed to be of the object's type (modulo\r
+       coercion hacks -- i.e. if the type's coercion function\r
+       returns other types, then these are allowed as well).  Numbers that\r
+       have the Py_TPFLAGS_CHECKTYPES flag bit set should check *both*\r
+       arguments for proper type and implement the necessary conversions\r
+       in the slot functions themselves. */\r
+\r
+    binaryfunc nb_add;\r
+    binaryfunc nb_subtract;\r
+    binaryfunc nb_multiply;\r
+    binaryfunc nb_divide;\r
+    binaryfunc nb_remainder;\r
+    binaryfunc nb_divmod;\r
+    ternaryfunc nb_power;\r
+    unaryfunc nb_negative;\r
+    unaryfunc nb_positive;\r
+    unaryfunc nb_absolute;\r
+    inquiry nb_nonzero;\r
+    unaryfunc nb_invert;\r
+    binaryfunc nb_lshift;\r
+    binaryfunc nb_rshift;\r
+    binaryfunc nb_and;\r
+    binaryfunc nb_xor;\r
+    binaryfunc nb_or;\r
+    coercion nb_coerce;\r
+    unaryfunc nb_int;\r
+    unaryfunc nb_long;\r
+    unaryfunc nb_float;\r
+    unaryfunc nb_oct;\r
+    unaryfunc nb_hex;\r
+    /* Added in release 2.0 */\r
+    binaryfunc nb_inplace_add;\r
+    binaryfunc nb_inplace_subtract;\r
+    binaryfunc nb_inplace_multiply;\r
+    binaryfunc nb_inplace_divide;\r
+    binaryfunc nb_inplace_remainder;\r
+    ternaryfunc nb_inplace_power;\r
+    binaryfunc nb_inplace_lshift;\r
+    binaryfunc nb_inplace_rshift;\r
+    binaryfunc nb_inplace_and;\r
+    binaryfunc nb_inplace_xor;\r
+    binaryfunc nb_inplace_or;\r
+\r
+    /* Added in release 2.2 */\r
+    /* The following require the Py_TPFLAGS_HAVE_CLASS flag */\r
+    binaryfunc nb_floor_divide;\r
+    binaryfunc nb_true_divide;\r
+    binaryfunc nb_inplace_floor_divide;\r
+    binaryfunc nb_inplace_true_divide;\r
+\r
+    /* Added in release 2.5 */\r
+    unaryfunc nb_index;\r
+} PyNumberMethods;\r
+\r
+typedef struct {\r
+    lenfunc sq_length;\r
+    binaryfunc sq_concat;\r
+    ssizeargfunc sq_repeat;\r
+    ssizeargfunc sq_item;\r
+    ssizessizeargfunc sq_slice;\r
+    ssizeobjargproc sq_ass_item;\r
+    ssizessizeobjargproc sq_ass_slice;\r
+    objobjproc sq_contains;\r
+    /* Added in release 2.0 */\r
+    binaryfunc sq_inplace_concat;\r
+    ssizeargfunc sq_inplace_repeat;\r
+} PySequenceMethods;\r
+\r
+typedef struct {\r
+    lenfunc mp_length;\r
+    binaryfunc mp_subscript;\r
+    objobjargproc mp_ass_subscript;\r
+} PyMappingMethods;\r
+\r
+typedef struct {\r
+    readbufferproc bf_getreadbuffer;\r
+    writebufferproc bf_getwritebuffer;\r
+    segcountproc bf_getsegcount;\r
+    charbufferproc bf_getcharbuffer;\r
+    getbufferproc bf_getbuffer;\r
+    releasebufferproc bf_releasebuffer;\r
+} PyBufferProcs;\r
+\r
+\r
+typedef void (*freefunc)(void *);\r
+typedef void (*destructor)(PyObject *);\r
+typedef int (*printfunc)(PyObject *, FILE *, int);\r
+typedef PyObject *(*getattrfunc)(PyObject *, char *);\r
+typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);\r
+typedef int (*setattrfunc)(PyObject *, char *, PyObject *);\r
+typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);\r
+typedef int (*cmpfunc)(PyObject *, PyObject *);\r
+typedef PyObject *(*reprfunc)(PyObject *);\r
+typedef long (*hashfunc)(PyObject *);\r
+typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);\r
+typedef PyObject *(*getiterfunc) (PyObject *);\r
+typedef PyObject *(*iternextfunc) (PyObject *);\r
+typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *);\r
+typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *);\r
+typedef int (*initproc)(PyObject *, PyObject *, PyObject *);\r
+typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);\r
+typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);\r
+\r
+typedef struct _typeobject {\r
+    PyObject_VAR_HEAD\r
+    const char *tp_name; /* For printing, in format "<module>.<name>" */\r
+    Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */\r
+\r
+    /* Methods to implement standard operations */\r
+\r
+    destructor tp_dealloc;\r
+    printfunc tp_print;\r
+    getattrfunc tp_getattr;\r
+    setattrfunc tp_setattr;\r
+    cmpfunc tp_compare;\r
+    reprfunc tp_repr;\r
+\r
+    /* Method suites for standard classes */\r
+\r
+    PyNumberMethods *tp_as_number;\r
+    PySequenceMethods *tp_as_sequence;\r
+    PyMappingMethods *tp_as_mapping;\r
+\r
+    /* More standard operations (here for binary compatibility) */\r
+\r
+    hashfunc tp_hash;\r
+    ternaryfunc tp_call;\r
+    reprfunc tp_str;\r
+    getattrofunc tp_getattro;\r
+    setattrofunc tp_setattro;\r
+\r
+    /* Functions to access object as input/output buffer */\r
+    PyBufferProcs *tp_as_buffer;\r
+\r
+    /* Flags to define presence of optional/expanded features */\r
+    long tp_flags;\r
+\r
+    const char *tp_doc; /* Documentation string */\r
+\r
+    /* Assigned meaning in release 2.0 */\r
+    /* call function for all accessible objects */\r
+    traverseproc tp_traverse;\r
+\r
+    /* delete references to contained objects */\r
+    inquiry tp_clear;\r
+\r
+    /* Assigned meaning in release 2.1 */\r
+    /* rich comparisons */\r
+    richcmpfunc tp_richcompare;\r
+\r
+    /* weak reference enabler */\r
+    Py_ssize_t tp_weaklistoffset;\r
+\r
+    /* Added in release 2.2 */\r
+    /* Iterators */\r
+    getiterfunc tp_iter;\r
+    iternextfunc tp_iternext;\r
+\r
+    /* Attribute descriptor and subclassing stuff */\r
+    struct PyMethodDef *tp_methods;\r
+    struct PyMemberDef *tp_members;\r
+    struct PyGetSetDef *tp_getset;\r
+    struct _typeobject *tp_base;\r
+    PyObject *tp_dict;\r
+    descrgetfunc tp_descr_get;\r
+    descrsetfunc tp_descr_set;\r
+    Py_ssize_t tp_dictoffset;\r
+    initproc tp_init;\r
+    allocfunc tp_alloc;\r
+    newfunc tp_new;\r
+    freefunc tp_free; /* Low-level free-memory routine */\r
+    inquiry tp_is_gc; /* For PyObject_IS_GC */\r
+    PyObject *tp_bases;\r
+    PyObject *tp_mro; /* method resolution order */\r
+    PyObject *tp_cache;\r
+    PyObject *tp_subclasses;\r
+    PyObject *tp_weaklist;\r
+    destructor tp_del;\r
+\r
+    /* Type attribute cache version tag. Added in version 2.6 */\r
+    unsigned int tp_version_tag;\r
+\r
+#ifdef COUNT_ALLOCS\r
+    /* these must be last and never explicitly initialized */\r
+    Py_ssize_t tp_allocs;\r
+    Py_ssize_t tp_frees;\r
+    Py_ssize_t tp_maxalloc;\r
+    struct _typeobject *tp_prev;\r
+    struct _typeobject *tp_next;\r
+#endif\r
+} PyTypeObject;\r
+\r
+\r
+/* The *real* layout of a type object when allocated on the heap */\r
+typedef struct _heaptypeobject {\r
+    /* Note: there's a dependency on the order of these members\r
+       in slotptr() in typeobject.c . */\r
+    PyTypeObject ht_type;\r
+    PyNumberMethods as_number;\r
+    PyMappingMethods as_mapping;\r
+    PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,\r
+                                      so that the mapping wins when both\r
+                                      the mapping and the sequence define\r
+                                      a given operator (e.g. __getitem__).\r
+                                      see add_operators() in typeobject.c . */\r
+    PyBufferProcs as_buffer;\r
+    PyObject *ht_name, *ht_slots;\r
+    /* here are optional user slots, followed by the members. */\r
+} PyHeapTypeObject;\r
+\r
+/* access macro to the members which are floating "behind" the object */\r
+#define PyHeapType_GET_MEMBERS(etype) \\r
+    ((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))\r
+\r
+\r
+/* Generic type check */\r
+PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);\r
+#define PyObject_TypeCheck(ob, tp) \\r
+    (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))\r
+\r
+PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */\r
+PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */\r
+PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */\r
+\r
+#define PyType_Check(op) \\r
+    PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)\r
+#define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type)\r
+\r
+PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);\r
+PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);\r
+PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,\r
+                                               PyObject *, PyObject *);\r
+PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);\r
+PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, char *, PyObject **);\r
+PyAPI_FUNC(unsigned int) PyType_ClearCache(void);\r
+PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);\r
+\r
+/* Generic operations on objects */\r
+PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);\r
+PyAPI_FUNC(void) _PyObject_Dump(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *);\r
+PyAPI_FUNC(PyObject *) _PyObject_Str(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyObject_Str(PyObject *);\r
+#define PyObject_Bytes PyObject_Str\r
+#ifdef Py_USING_UNICODE\r
+PyAPI_FUNC(PyObject *) PyObject_Unicode(PyObject *);\r
+#endif\r
+PyAPI_FUNC(int) PyObject_Compare(PyObject *, PyObject *);\r
+PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);\r
+PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);\r
+PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *);\r
+PyAPI_FUNC(int) PyObject_SetAttrString(PyObject *, const char *, PyObject *);\r
+PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *);\r
+PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);\r
+PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);\r
+PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);\r
+PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);\r
+PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);\r
+PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *,\r
+                                              PyObject *, PyObject *);\r
+PyAPI_FUNC(long) PyObject_Hash(PyObject *);\r
+PyAPI_FUNC(long) PyObject_HashNotImplemented(PyObject *);\r
+PyAPI_FUNC(int) PyObject_IsTrue(PyObject *);\r
+PyAPI_FUNC(int) PyObject_Not(PyObject *);\r
+PyAPI_FUNC(int) PyCallable_Check(PyObject *);\r
+PyAPI_FUNC(int) PyNumber_Coerce(PyObject **, PyObject **);\r
+PyAPI_FUNC(int) PyNumber_CoerceEx(PyObject **, PyObject **);\r
+\r
+PyAPI_FUNC(void) PyObject_ClearWeakRefs(PyObject *);\r
+\r
+/* A slot function whose address we need to compare */\r
+extern int _PyObject_SlotCompare(PyObject *, PyObject *);\r
+/* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes\r
+   dict as the last parameter. */\r
+PyAPI_FUNC(PyObject *)\r
+_PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *);\r
+PyAPI_FUNC(int)\r
+_PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,\r
+                                 PyObject *, PyObject *);\r
+\r
+\r
+/* PyObject_Dir(obj) acts like Python __builtin__.dir(obj), returning a\r
+   list of strings.  PyObject_Dir(NULL) is like __builtin__.dir(),\r
+   returning the names of the current locals.  In this case, if there are\r
+   no current locals, NULL is returned, and PyErr_Occurred() is false.\r
+*/\r
+PyAPI_FUNC(PyObject *) PyObject_Dir(PyObject *);\r
+\r
+\r
+/* Helpers for printing recursive container types */\r
+PyAPI_FUNC(int) Py_ReprEnter(PyObject *);\r
+PyAPI_FUNC(void) Py_ReprLeave(PyObject *);\r
+\r
+/* Helpers for hash functions */\r
+PyAPI_FUNC(long) _Py_HashDouble(double);\r
+PyAPI_FUNC(long) _Py_HashPointer(void*);\r
+\r
+typedef struct {\r
+    long prefix;\r
+    long suffix;\r
+} _Py_HashSecret_t;\r
+PyAPI_DATA(_Py_HashSecret_t) _Py_HashSecret;\r
+\r
+#ifdef Py_DEBUG\r
+PyAPI_DATA(int) _Py_HashSecret_Initialized;\r
+#endif\r
+\r
+/* Helper for passing objects to printf and the like.\r
+   Leaks refcounts.  Don't use it!\r
+*/\r
+#define PyObject_REPR(obj) PyString_AS_STRING(PyObject_Repr(obj))\r
+\r
+/* Flag bits for printing: */\r
+#define Py_PRINT_RAW    1       /* No string quotes etc. */\r
+\r
+/*\r
+`Type flags (tp_flags)\r
+\r
+These flags are used to extend the type structure in a backwards-compatible\r
+fashion. Extensions can use the flags to indicate (and test) when a given\r
+type structure contains a new feature. The Python core will use these when\r
+introducing new functionality between major revisions (to avoid mid-version\r
+changes in the PYTHON_API_VERSION).\r
+\r
+Arbitration of the flag bit positions will need to be coordinated among\r
+all extension writers who publically release their extensions (this will\r
+be fewer than you might expect!)..\r
+\r
+Python 1.5.2 introduced the bf_getcharbuffer slot into PyBufferProcs.\r
+\r
+Type definitions should use Py_TPFLAGS_DEFAULT for their tp_flags value.\r
+\r
+Code can use PyType_HasFeature(type_ob, flag_value) to test whether the\r
+given type object has a specified feature.\r
+\r
+NOTE: when building the core, Py_TPFLAGS_DEFAULT includes\r
+Py_TPFLAGS_HAVE_VERSION_TAG; outside the core, it doesn't.  This is so\r
+that extensions that modify tp_dict of their own types directly don't\r
+break, since this was allowed in 2.5.  In 3.0 they will have to\r
+manually remove this flag though!\r
+*/\r
+\r
+/* PyBufferProcs contains bf_getcharbuffer */\r
+#define Py_TPFLAGS_HAVE_GETCHARBUFFER  (1L<<0)\r
+\r
+/* PySequenceMethods contains sq_contains */\r
+#define Py_TPFLAGS_HAVE_SEQUENCE_IN (1L<<1)\r
+\r
+/* This is here for backwards compatibility.  Extensions that use the old GC\r
+ * API will still compile but the objects will not be tracked by the GC. */\r
+#define Py_TPFLAGS_GC 0 /* used to be (1L<<2) */\r
+\r
+/* PySequenceMethods and PyNumberMethods contain in-place operators */\r
+#define Py_TPFLAGS_HAVE_INPLACEOPS (1L<<3)\r
+\r
+/* PyNumberMethods do their own coercion */\r
+#define Py_TPFLAGS_CHECKTYPES (1L<<4)\r
+\r
+/* tp_richcompare is defined */\r
+#define Py_TPFLAGS_HAVE_RICHCOMPARE (1L<<5)\r
+\r
+/* Objects which are weakly referencable if their tp_weaklistoffset is >0 */\r
+#define Py_TPFLAGS_HAVE_WEAKREFS (1L<<6)\r
+\r
+/* tp_iter is defined */\r
+#define Py_TPFLAGS_HAVE_ITER (1L<<7)\r
+\r
+/* New members introduced by Python 2.2 exist */\r
+#define Py_TPFLAGS_HAVE_CLASS (1L<<8)\r
+\r
+/* Set if the type object is dynamically allocated */\r
+#define Py_TPFLAGS_HEAPTYPE (1L<<9)\r
+\r
+/* Set if the type allows subclassing */\r
+#define Py_TPFLAGS_BASETYPE (1L<<10)\r
+\r
+/* Set if the type is 'ready' -- fully initialized */\r
+#define Py_TPFLAGS_READY (1L<<12)\r
+\r
+/* Set while the type is being 'readied', to prevent recursive ready calls */\r
+#define Py_TPFLAGS_READYING (1L<<13)\r
+\r
+/* Objects support garbage collection (see objimp.h) */\r
+#define Py_TPFLAGS_HAVE_GC (1L<<14)\r
+\r
+/* These two bits are preserved for Stackless Python, next after this is 17 */\r
+#ifdef STACKLESS\r
+#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION (3L<<15)\r
+#else\r
+#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0\r
+#endif\r
+\r
+/* Objects support nb_index in PyNumberMethods */\r
+#define Py_TPFLAGS_HAVE_INDEX (1L<<17)\r
+\r
+/* Objects support type attribute cache */\r
+#define Py_TPFLAGS_HAVE_VERSION_TAG   (1L<<18)\r
+#define Py_TPFLAGS_VALID_VERSION_TAG  (1L<<19)\r
+\r
+/* Type is abstract and cannot be instantiated */\r
+#define Py_TPFLAGS_IS_ABSTRACT (1L<<20)\r
+\r
+/* Has the new buffer protocol */\r
+#define Py_TPFLAGS_HAVE_NEWBUFFER (1L<<21)\r
+\r
+/* These flags are used to determine if a type is a subclass. */\r
+#define Py_TPFLAGS_INT_SUBCLASS         (1L<<23)\r
+#define Py_TPFLAGS_LONG_SUBCLASS        (1L<<24)\r
+#define Py_TPFLAGS_LIST_SUBCLASS        (1L<<25)\r
+#define Py_TPFLAGS_TUPLE_SUBCLASS       (1L<<26)\r
+#define Py_TPFLAGS_STRING_SUBCLASS      (1L<<27)\r
+#define Py_TPFLAGS_UNICODE_SUBCLASS     (1L<<28)\r
+#define Py_TPFLAGS_DICT_SUBCLASS        (1L<<29)\r
+#define Py_TPFLAGS_BASE_EXC_SUBCLASS    (1L<<30)\r
+#define Py_TPFLAGS_TYPE_SUBCLASS        (1L<<31)\r
+\r
+#define Py_TPFLAGS_DEFAULT_EXTERNAL ( \\r
+                 Py_TPFLAGS_HAVE_GETCHARBUFFER | \\r
+                 Py_TPFLAGS_HAVE_SEQUENCE_IN | \\r
+                 Py_TPFLAGS_HAVE_INPLACEOPS | \\r
+                 Py_TPFLAGS_HAVE_RICHCOMPARE | \\r
+                 Py_TPFLAGS_HAVE_WEAKREFS | \\r
+                 Py_TPFLAGS_HAVE_ITER | \\r
+                 Py_TPFLAGS_HAVE_CLASS | \\r
+                 Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \\r
+                 Py_TPFLAGS_HAVE_INDEX | \\r
+                 0)\r
+#define Py_TPFLAGS_DEFAULT_CORE (Py_TPFLAGS_DEFAULT_EXTERNAL | \\r
+                 Py_TPFLAGS_HAVE_VERSION_TAG)\r
+\r
+#ifdef Py_BUILD_CORE\r
+#define Py_TPFLAGS_DEFAULT Py_TPFLAGS_DEFAULT_CORE\r
+#else\r
+#define Py_TPFLAGS_DEFAULT Py_TPFLAGS_DEFAULT_EXTERNAL\r
+#endif\r
+\r
+#define PyType_HasFeature(t,f)  (((t)->tp_flags & (f)) != 0)\r
+#define PyType_FastSubclass(t,f)  PyType_HasFeature(t,f)\r
+\r
+\r
+/*\r
+The macros Py_INCREF(op) and Py_DECREF(op) are used to increment or decrement\r
+reference counts.  Py_DECREF calls the object's deallocator function when\r
+the refcount falls to 0; for\r
+objects that don't contain references to other objects or heap memory\r
+this can be the standard function free().  Both macros can be used\r
+wherever a void expression is allowed.  The argument must not be a\r
+NULL pointer.  If it may be NULL, use Py_XINCREF/Py_XDECREF instead.\r
+The macro _Py_NewReference(op) initialize reference counts to 1, and\r
+in special builds (Py_REF_DEBUG, Py_TRACE_REFS) performs additional\r
+bookkeeping appropriate to the special build.\r
+\r
+We assume that the reference count field can never overflow; this can\r
+be proven when the size of the field is the same as the pointer size, so\r
+we ignore the possibility.  Provided a C int is at least 32 bits (which\r
+is implicitly assumed in many parts of this code), that's enough for\r
+about 2**31 references to an object.\r
+\r
+XXX The following became out of date in Python 2.2, but I'm not sure\r
+XXX what the full truth is now.  Certainly, heap-allocated type objects\r
+XXX can and should be deallocated.\r
+Type objects should never be deallocated; the type pointer in an object\r
+is not considered to be a reference to the type object, to save\r
+complications in the deallocation function.  (This is actually a\r
+decision that's up to the implementer of each new type so if you want,\r
+you can count such references to the type object.)\r
+\r
+*** WARNING*** The Py_DECREF macro must have a side-effect-free argument\r
+since it may evaluate its argument multiple times.  (The alternative\r
+would be to mace it a proper function or assign it to a global temporary\r
+variable first, both of which are slower; and in a multi-threaded\r
+environment the global variable trick is not safe.)\r
+*/\r
+\r
+/* First define a pile of simple helper macros, one set per special\r
+ * build symbol.  These either expand to the obvious things, or to\r
+ * nothing at all when the special mode isn't in effect.  The main\r
+ * macros can later be defined just once then, yet expand to different\r
+ * things depending on which special build options are and aren't in effect.\r
+ * Trust me <wink>:  while painful, this is 20x easier to understand than,\r
+ * e.g, defining _Py_NewReference five different times in a maze of nested\r
+ * #ifdefs (we used to do that -- it was impenetrable).\r
+ */\r
+#ifdef Py_REF_DEBUG\r
+PyAPI_DATA(Py_ssize_t) _Py_RefTotal;\r
+PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname,\r
+                                            int lineno, PyObject *op);\r
+PyAPI_FUNC(PyObject *) _PyDict_Dummy(void);\r
+PyAPI_FUNC(PyObject *) _PySet_Dummy(void);\r
+PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);\r
+#define _Py_INC_REFTOTAL        _Py_RefTotal++\r
+#define _Py_DEC_REFTOTAL        _Py_RefTotal--\r
+#define _Py_REF_DEBUG_COMMA     ,\r
+#define _Py_CHECK_REFCNT(OP)                                    \\r
+{       if (((PyObject*)OP)->ob_refcnt < 0)                             \\r
+                _Py_NegativeRefcount(__FILE__, __LINE__,        \\r
+                                     (PyObject *)(OP));         \\r
+}\r
+#else\r
+#define _Py_INC_REFTOTAL\r
+#define _Py_DEC_REFTOTAL\r
+#define _Py_REF_DEBUG_COMMA\r
+#define _Py_CHECK_REFCNT(OP)    /* a semicolon */;\r
+#endif /* Py_REF_DEBUG */\r
+\r
+#ifdef COUNT_ALLOCS\r
+PyAPI_FUNC(void) inc_count(PyTypeObject *);\r
+PyAPI_FUNC(void) dec_count(PyTypeObject *);\r
+#define _Py_INC_TPALLOCS(OP)    inc_count(Py_TYPE(OP))\r
+#define _Py_INC_TPFREES(OP)     dec_count(Py_TYPE(OP))\r
+#define _Py_DEC_TPFREES(OP)     Py_TYPE(OP)->tp_frees--\r
+#define _Py_COUNT_ALLOCS_COMMA  ,\r
+#else\r
+#define _Py_INC_TPALLOCS(OP)\r
+#define _Py_INC_TPFREES(OP)\r
+#define _Py_DEC_TPFREES(OP)\r
+#define _Py_COUNT_ALLOCS_COMMA\r
+#endif /* COUNT_ALLOCS */\r
+\r
+#ifdef Py_TRACE_REFS\r
+/* Py_TRACE_REFS is such major surgery that we call external routines. */\r
+PyAPI_FUNC(void) _Py_NewReference(PyObject *);\r
+PyAPI_FUNC(void) _Py_ForgetReference(PyObject *);\r
+PyAPI_FUNC(void) _Py_Dealloc(PyObject *);\r
+PyAPI_FUNC(void) _Py_PrintReferences(FILE *);\r
+PyAPI_FUNC(void) _Py_PrintReferenceAddresses(FILE *);\r
+PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);\r
+\r
+#else\r
+/* Without Py_TRACE_REFS, there's little enough to do that we expand code\r
+ * inline.\r
+ */\r
+#define _Py_NewReference(op) (                          \\r
+    _Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA         \\r
+    _Py_INC_REFTOTAL  _Py_REF_DEBUG_COMMA               \\r
+    Py_REFCNT(op) = 1)\r
+\r
+#define _Py_ForgetReference(op) _Py_INC_TPFREES(op)\r
+\r
+#define _Py_Dealloc(op) (                               \\r
+    _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA          \\r
+    (*Py_TYPE(op)->tp_dealloc)((PyObject *)(op)))\r
+#endif /* !Py_TRACE_REFS */\r
+\r
+#define Py_INCREF(op) (                         \\r
+    _Py_INC_REFTOTAL  _Py_REF_DEBUG_COMMA       \\r
+    ((PyObject*)(op))->ob_refcnt++)\r
+\r
+#define Py_DECREF(op)                                   \\r
+    do {                                                \\r
+        if (_Py_DEC_REFTOTAL  _Py_REF_DEBUG_COMMA       \\r
+        --((PyObject*)(op))->ob_refcnt != 0)            \\r
+            _Py_CHECK_REFCNT(op)                        \\r
+        else                                            \\r
+        _Py_Dealloc((PyObject *)(op));                  \\r
+    } while (0)\r
+\r
+/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear\r
+ * and tp_dealloc implementatons.\r
+ *\r
+ * Note that "the obvious" code can be deadly:\r
+ *\r
+ *     Py_XDECREF(op);\r
+ *     op = NULL;\r
+ *\r
+ * Typically, `op` is something like self->containee, and `self` is done\r
+ * using its `containee` member.  In the code sequence above, suppose\r
+ * `containee` is non-NULL with a refcount of 1.  Its refcount falls to\r
+ * 0 on the first line, which can trigger an arbitrary amount of code,\r
+ * possibly including finalizers (like __del__ methods or weakref callbacks)\r
+ * coded in Python, which in turn can release the GIL and allow other threads\r
+ * to run, etc.  Such code may even invoke methods of `self` again, or cause\r
+ * cyclic gc to trigger, but-- oops! --self->containee still points to the\r
+ * object being torn down, and it may be in an insane state while being torn\r
+ * down.  This has in fact been a rich historic source of miserable (rare &\r
+ * hard-to-diagnose) segfaulting (and other) bugs.\r
+ *\r
+ * The safe way is:\r
+ *\r
+ *      Py_CLEAR(op);\r
+ *\r
+ * That arranges to set `op` to NULL _before_ decref'ing, so that any code\r
+ * triggered as a side-effect of `op` getting torn down no longer believes\r
+ * `op` points to a valid object.\r
+ *\r
+ * There are cases where it's safe to use the naive code, but they're brittle.\r
+ * For example, if `op` points to a Python integer, you know that destroying\r
+ * one of those can't cause problems -- but in part that relies on that\r
+ * Python integers aren't currently weakly referencable.  Best practice is\r
+ * to use Py_CLEAR() even if you can't think of a reason for why you need to.\r
+ */\r
+#define Py_CLEAR(op)                            \\r
+    do {                                        \\r
+        if (op) {                               \\r
+            PyObject *_py_tmp = (PyObject *)(op);               \\r
+            (op) = NULL;                        \\r
+            Py_DECREF(_py_tmp);                 \\r
+        }                                       \\r
+    } while (0)\r
+\r
+/* Macros to use in case the object pointer may be NULL: */\r
+#define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0)\r
+#define Py_XDECREF(op) do { if ((op) == NULL) ; else Py_DECREF(op); } while (0)\r
+\r
+/*\r
+These are provided as conveniences to Python runtime embedders, so that\r
+they can have object code that is not dependent on Python compilation flags.\r
+*/\r
+PyAPI_FUNC(void) Py_IncRef(PyObject *);\r
+PyAPI_FUNC(void) Py_DecRef(PyObject *);\r
+\r
+/*\r
+_Py_NoneStruct is an object of undefined type which can be used in contexts\r
+where NULL (nil) is not suitable (since NULL often means 'error').\r
+\r
+Don't forget to apply Py_INCREF() when returning this value!!!\r
+*/\r
+PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */\r
+#define Py_None (&_Py_NoneStruct)\r
+\r
+/* Macro for returning Py_None from a function */\r
+#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None\r
+\r
+/*\r
+Py_NotImplemented is a singleton used to signal that an operation is\r
+not implemented for a given type combination.\r
+*/\r
+PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */\r
+#define Py_NotImplemented (&_Py_NotImplementedStruct)\r
+\r
+/* Rich comparison opcodes */\r
+#define Py_LT 0\r
+#define Py_LE 1\r
+#define Py_EQ 2\r
+#define Py_NE 3\r
+#define Py_GT 4\r
+#define Py_GE 5\r
+\r
+/* Maps Py_LT to Py_GT, ..., Py_GE to Py_LE.\r
+ * Defined in object.c.\r
+ */\r
+PyAPI_DATA(int) _Py_SwappedOp[];\r
+\r
+/*\r
+Define staticforward and statichere for source compatibility with old\r
+C extensions.\r
+\r
+The staticforward define was needed to support certain broken C\r
+compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the\r
+static keyword when it was used with a forward declaration of a static\r
+initialized structure.  Standard C allows the forward declaration with\r
+static, and we've decided to stop catering to broken C compilers.\r
+(In fact, we expect that the compilers are all fixed eight years later.)\r
+*/\r
+\r
+#define staticforward static\r
+#define statichere static\r
+\r
+\r
+/*\r
+More conventions\r
+================\r
+\r
+Argument Checking\r
+-----------------\r
+\r
+Functions that take objects as arguments normally don't check for nil\r
+arguments, but they do check the type of the argument, and return an\r
+error if the function doesn't apply to the type.\r
+\r
+Failure Modes\r
+-------------\r
+\r
+Functions may fail for a variety of reasons, including running out of\r
+memory.  This is communicated to the caller in two ways: an error string\r
+is set (see errors.h), and the function result differs: functions that\r
+normally return a pointer return NULL for failure, functions returning\r
+an integer return -1 (which could be a legal return value too!), and\r
+other functions return 0 for success and -1 for failure.\r
+Callers should always check for errors before using the result.  If\r
+an error was set, the caller must either explicitly clear it, or pass\r
+the error on to its caller.\r
+\r
+Reference Counts\r
+----------------\r
+\r
+It takes a while to get used to the proper usage of reference counts.\r
+\r
+Functions that create an object set the reference count to 1; such new\r
+objects must be stored somewhere or destroyed again with Py_DECREF().\r
+Some functions that 'store' objects, such as PyTuple_SetItem() and\r
+PyList_SetItem(),\r
+don't increment the reference count of the object, since the most\r
+frequent use is to store a fresh object.  Functions that 'retrieve'\r
+objects, such as PyTuple_GetItem() and PyDict_GetItemString(), also\r
+don't increment\r
+the reference count, since most frequently the object is only looked at\r
+quickly.  Thus, to retrieve an object and store it again, the caller\r
+must call Py_INCREF() explicitly.\r
+\r
+NOTE: functions that 'consume' a reference count, like\r
+PyList_SetItem(), consume the reference even if the object wasn't\r
+successfully stored, to simplify error handling.\r
+\r
+It seems attractive to make other functions that take an object as\r
+argument consume a reference count; however, this may quickly get\r
+confusing (even the current practice is already confusing).  Consider\r
+it carefully, it may save lots of calls to Py_INCREF() and Py_DECREF() at\r
+times.\r
+*/\r
+\r
+\r
+/* Trashcan mechanism, thanks to Christian Tismer.\r
+\r
+When deallocating a container object, it's possible to trigger an unbounded\r
+chain of deallocations, as each Py_DECREF in turn drops the refcount on "the\r
+next" object in the chain to 0.  This can easily lead to stack faults, and\r
+especially in threads (which typically have less stack space to work with).\r
+\r
+A container object that participates in cyclic gc can avoid this by\r
+bracketing the body of its tp_dealloc function with a pair of macros:\r
+\r
+static void\r
+mytype_dealloc(mytype *p)\r
+{\r
+    ... declarations go here ...\r
+\r
+    PyObject_GC_UnTrack(p);        // must untrack first\r
+    Py_TRASHCAN_SAFE_BEGIN(p)\r
+    ... The body of the deallocator goes here, including all calls ...\r
+    ... to Py_DECREF on contained objects.                         ...\r
+    Py_TRASHCAN_SAFE_END(p)\r
+}\r
+\r
+CAUTION:  Never return from the middle of the body!  If the body needs to\r
+"get out early", put a label immediately before the Py_TRASHCAN_SAFE_END\r
+call, and goto it.  Else the call-depth counter (see below) will stay\r
+above 0 forever, and the trashcan will never get emptied.\r
+\r
+How it works:  The BEGIN macro increments a call-depth counter.  So long\r
+as this counter is small, the body of the deallocator is run directly without\r
+further ado.  But if the counter gets large, it instead adds p to a list of\r
+objects to be deallocated later, skips the body of the deallocator, and\r
+resumes execution after the END macro.  The tp_dealloc routine then returns\r
+without deallocating anything (and so unbounded call-stack depth is avoided).\r
+\r
+When the call stack finishes unwinding again, code generated by the END macro\r
+notices this, and calls another routine to deallocate all the objects that\r
+may have been added to the list of deferred deallocations.  In effect, a\r
+chain of N deallocations is broken into N / PyTrash_UNWIND_LEVEL pieces,\r
+with the call stack never exceeding a depth of PyTrash_UNWIND_LEVEL.\r
+*/\r
+\r
+/* This is the old private API, invoked by the macros before 2.7.4.\r
+   Kept for binary compatibility of extensions. */\r
+PyAPI_FUNC(void) _PyTrash_deposit_object(PyObject*);\r
+PyAPI_FUNC(void) _PyTrash_destroy_chain(void);\r
+PyAPI_DATA(int) _PyTrash_delete_nesting;\r
+PyAPI_DATA(PyObject *) _PyTrash_delete_later;\r
+\r
+/* The new thread-safe private API, invoked by the macros below. */\r
+PyAPI_FUNC(void) _PyTrash_thread_deposit_object(PyObject*);\r
+PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(void);\r
+\r
+#define PyTrash_UNWIND_LEVEL 50\r
+\r
+/* Note the workaround for when the thread state is NULL (issue #17703) */\r
+#define Py_TRASHCAN_SAFE_BEGIN(op) \\r
+    do { \\r
+        PyThreadState *_tstate = PyThreadState_GET(); \\r
+        if (!_tstate || \\r
+            _tstate->trash_delete_nesting < PyTrash_UNWIND_LEVEL) { \\r
+            if (_tstate) \\r
+                ++_tstate->trash_delete_nesting;\r
+            /* The body of the deallocator is here. */\r
+#define Py_TRASHCAN_SAFE_END(op) \\r
+            if (_tstate) { \\r
+                --_tstate->trash_delete_nesting; \\r
+                if (_tstate->trash_delete_later \\r
+                    && _tstate->trash_delete_nesting <= 0) \\r
+                    _PyTrash_thread_destroy_chain(); \\r
+            } \\r
+        } \\r
+        else \\r
+            _PyTrash_thread_deposit_object((PyObject*)op); \\r
+    } while (0);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_OBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/objimpl.h b/AppPkg/Applications/Python/Python-2.7.10/Include/objimpl.h
new file mode 100644 (file)
index 0000000..79d7e2d
--- /dev/null
@@ -0,0 +1,354 @@
+/* The PyObject_ memory family:  high-level object memory interfaces.\r
+   See pymem.h for the low-level PyMem_ family.\r
+*/\r
+\r
+#ifndef Py_OBJIMPL_H\r
+#define Py_OBJIMPL_H\r
+\r
+#include "pymem.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* BEWARE:\r
+\r
+   Each interface exports both functions and macros.  Extension modules should\r
+   use the functions, to ensure binary compatibility across Python versions.\r
+   Because the Python implementation is free to change internal details, and\r
+   the macros may (or may not) expose details for speed, if you do use the\r
+   macros you must recompile your extensions with each Python release.\r
+\r
+   Never mix calls to PyObject_ memory functions with calls to the platform\r
+   malloc/realloc/ calloc/free, or with calls to PyMem_.\r
+*/\r
+\r
+/*\r
+Functions and macros for modules that implement new object types.\r
+\r
+ - PyObject_New(type, typeobj) allocates memory for a new object of the given\r
+   type, and initializes part of it.  'type' must be the C structure type used\r
+   to represent the object, and 'typeobj' the address of the corresponding\r
+   type object.  Reference count and type pointer are filled in; the rest of\r
+   the bytes of the object are *undefined*!  The resulting expression type is\r
+   'type *'.  The size of the object is determined by the tp_basicsize field\r
+   of the type object.\r
+\r
+ - PyObject_NewVar(type, typeobj, n) is similar but allocates a variable-size\r
+   object with room for n items.  In addition to the refcount and type pointer\r
+   fields, this also fills in the ob_size field.\r
+\r
+ - PyObject_Del(op) releases the memory allocated for an object.  It does not\r
+   run a destructor -- it only frees the memory.  PyObject_Free is identical.\r
+\r
+ - PyObject_Init(op, typeobj) and PyObject_InitVar(op, typeobj, n) don't\r
+   allocate memory.  Instead of a 'type' parameter, they take a pointer to a\r
+   new object (allocated by an arbitrary allocator), and initialize its object\r
+   header fields.\r
+\r
+Note that objects created with PyObject_{New, NewVar} are allocated using the\r
+specialized Python allocator (implemented in obmalloc.c), if WITH_PYMALLOC is\r
+enabled.  In addition, a special debugging allocator is used if PYMALLOC_DEBUG\r
+is also #defined.\r
+\r
+In case a specific form of memory management is needed (for example, if you\r
+must use the platform malloc heap(s), or shared memory, or C++ local storage or\r
+operator new), you must first allocate the object with your custom allocator,\r
+then pass its pointer to PyObject_{Init, InitVar} for filling in its Python-\r
+specific fields:  reference count, type pointer, possibly others.  You should\r
+be aware that Python no control over these objects because they don't\r
+cooperate with the Python memory manager.  Such objects may not be eligible\r
+for automatic garbage collection and you have to make sure that they are\r
+released accordingly whenever their destructor gets called (cf. the specific\r
+form of memory management you're using).\r
+\r
+Unless you have specific memory management requirements, use\r
+PyObject_{New, NewVar, Del}.\r
+*/\r
+\r
+/*\r
+ * Raw object memory interface\r
+ * ===========================\r
+ */\r
+\r
+/* Functions to call the same malloc/realloc/free as used by Python's\r
+   object allocator.  If WITH_PYMALLOC is enabled, these may differ from\r
+   the platform malloc/realloc/free.  The Python object allocator is\r
+   designed for fast, cache-conscious allocation of many "small" objects,\r
+   and with low hidden memory overhead.\r
+\r
+   PyObject_Malloc(0) returns a unique non-NULL pointer if possible.\r
+\r
+   PyObject_Realloc(NULL, n) acts like PyObject_Malloc(n).\r
+   PyObject_Realloc(p != NULL, 0) does not return  NULL, or free the memory\r
+   at p.\r
+\r
+   Returned pointers must be checked for NULL explicitly; no action is\r
+   performed on failure other than to return NULL (no warning it printed, no\r
+   exception is set, etc).\r
+\r
+   For allocating objects, use PyObject_{New, NewVar} instead whenever\r
+   possible.  The PyObject_{Malloc, Realloc, Free} family is exposed\r
+   so that you can exploit Python's small-block allocator for non-object\r
+   uses.  If you must use these routines to allocate object memory, make sure\r
+   the object gets initialized via PyObject_{Init, InitVar} after obtaining\r
+   the raw memory.\r
+*/\r
+PyAPI_FUNC(void *) PyObject_Malloc(size_t);\r
+PyAPI_FUNC(void *) PyObject_Realloc(void *, size_t);\r
+PyAPI_FUNC(void) PyObject_Free(void *);\r
+\r
+\r
+/* Macros */\r
+#ifdef WITH_PYMALLOC\r
+#ifdef PYMALLOC_DEBUG   /* WITH_PYMALLOC && PYMALLOC_DEBUG */\r
+PyAPI_FUNC(void *) _PyObject_DebugMalloc(size_t nbytes);\r
+PyAPI_FUNC(void *) _PyObject_DebugRealloc(void *p, size_t nbytes);\r
+PyAPI_FUNC(void) _PyObject_DebugFree(void *p);\r
+PyAPI_FUNC(void) _PyObject_DebugDumpAddress(const void *p);\r
+PyAPI_FUNC(void) _PyObject_DebugCheckAddress(const void *p);\r
+PyAPI_FUNC(void) _PyObject_DebugMallocStats(void);\r
+PyAPI_FUNC(void *) _PyObject_DebugMallocApi(char api, size_t nbytes);\r
+PyAPI_FUNC(void *) _PyObject_DebugReallocApi(char api, void *p, size_t nbytes);\r
+PyAPI_FUNC(void) _PyObject_DebugFreeApi(char api, void *p);\r
+PyAPI_FUNC(void) _PyObject_DebugCheckAddressApi(char api, const void *p);\r
+PyAPI_FUNC(void *) _PyMem_DebugMalloc(size_t nbytes);\r
+PyAPI_FUNC(void *) _PyMem_DebugRealloc(void *p, size_t nbytes);\r
+PyAPI_FUNC(void) _PyMem_DebugFree(void *p);\r
+#define PyObject_MALLOC         _PyObject_DebugMalloc\r
+#define PyObject_Malloc         _PyObject_DebugMalloc\r
+#define PyObject_REALLOC        _PyObject_DebugRealloc\r
+#define PyObject_Realloc        _PyObject_DebugRealloc\r
+#define PyObject_FREE           _PyObject_DebugFree\r
+#define PyObject_Free           _PyObject_DebugFree\r
+\r
+#else   /* WITH_PYMALLOC && ! PYMALLOC_DEBUG */\r
+#define PyObject_MALLOC         PyObject_Malloc\r
+#define PyObject_REALLOC        PyObject_Realloc\r
+#define PyObject_FREE           PyObject_Free\r
+#endif\r
+\r
+#else   /* ! WITH_PYMALLOC */\r
+#define PyObject_MALLOC         PyMem_MALLOC\r
+#define PyObject_REALLOC        PyMem_REALLOC\r
+#define PyObject_FREE           PyMem_FREE\r
+\r
+#endif  /* WITH_PYMALLOC */\r
+\r
+#define PyObject_Del            PyObject_Free\r
+#define PyObject_DEL            PyObject_FREE\r
+\r
+/* for source compatibility with 2.2 */\r
+#define _PyObject_Del           PyObject_Free\r
+\r
+/*\r
+ * Generic object allocator interface\r
+ * ==================================\r
+ */\r
+\r
+/* Functions */\r
+PyAPI_FUNC(PyObject *) PyObject_Init(PyObject *, PyTypeObject *);\r
+PyAPI_FUNC(PyVarObject *) PyObject_InitVar(PyVarObject *,\r
+                                                 PyTypeObject *, Py_ssize_t);\r
+PyAPI_FUNC(PyObject *) _PyObject_New(PyTypeObject *);\r
+PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);\r
+\r
+#define PyObject_New(type, typeobj) \\r
+                ( (type *) _PyObject_New(typeobj) )\r
+#define PyObject_NewVar(type, typeobj, n) \\r
+                ( (type *) _PyObject_NewVar((typeobj), (n)) )\r
+\r
+/* Macros trading binary compatibility for speed. See also pymem.h.\r
+   Note that these macros expect non-NULL object pointers.*/\r
+#define PyObject_INIT(op, typeobj) \\r
+    ( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )\r
+#define PyObject_INIT_VAR(op, typeobj, size) \\r
+    ( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) )\r
+\r
+#define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )\r
+\r
+/* _PyObject_VAR_SIZE returns the number of bytes (as size_t) allocated for a\r
+   vrbl-size object with nitems items, exclusive of gc overhead (if any).  The\r
+   value is rounded up to the closest multiple of sizeof(void *), in order to\r
+   ensure that pointer fields at the end of the object are correctly aligned\r
+   for the platform (this is of special importance for subclasses of, e.g.,\r
+   str or long, so that pointers can be stored after the embedded data).\r
+\r
+   Note that there's no memory wastage in doing this, as malloc has to\r
+   return (at worst) pointer-aligned memory anyway.\r
+*/\r
+#if ((SIZEOF_VOID_P - 1) & SIZEOF_VOID_P) != 0\r
+#   error "_PyObject_VAR_SIZE requires SIZEOF_VOID_P be a power of 2"\r
+#endif\r
+\r
+#define _PyObject_VAR_SIZE(typeobj, nitems)     \\r
+    (size_t)                                    \\r
+    ( ( (typeobj)->tp_basicsize +               \\r
+        (nitems)*(typeobj)->tp_itemsize +       \\r
+        (SIZEOF_VOID_P - 1)                     \\r
+      ) & ~(SIZEOF_VOID_P - 1)                  \\r
+    )\r
+\r
+#define PyObject_NEW(type, typeobj) \\r
+( (type *) PyObject_Init( \\r
+    (PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) )\r
+\r
+#define PyObject_NEW_VAR(type, typeobj, n) \\r
+( (type *) PyObject_InitVar( \\r
+      (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE((typeobj),(n)) ),\\r
+      (typeobj), (n)) )\r
+\r
+/* This example code implements an object constructor with a custom\r
+   allocator, where PyObject_New is inlined, and shows the important\r
+   distinction between two steps (at least):\r
+       1) the actual allocation of the object storage;\r
+       2) the initialization of the Python specific fields\r
+      in this storage with PyObject_{Init, InitVar}.\r
+\r
+   PyObject *\r
+   YourObject_New(...)\r
+   {\r
+       PyObject *op;\r
+\r
+       op = (PyObject *) Your_Allocator(_PyObject_SIZE(YourTypeStruct));\r
+       if (op == NULL)\r
+       return PyErr_NoMemory();\r
+\r
+       PyObject_Init(op, &YourTypeStruct);\r
+\r
+       op->ob_field = value;\r
+       ...\r
+       return op;\r
+   }\r
+\r
+   Note that in C++, the use of the new operator usually implies that\r
+   the 1st step is performed automatically for you, so in a C++ class\r
+   constructor you would start directly with PyObject_Init/InitVar\r
+*/\r
+\r
+/*\r
+ * Garbage Collection Support\r
+ * ==========================\r
+ */\r
+\r
+/* C equivalent of gc.collect(). */\r
+PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void);\r
+\r
+/* Test if a type has a GC head */\r
+#define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)\r
+\r
+/* Test if an object has a GC head */\r
+#define PyObject_IS_GC(o) (PyType_IS_GC(Py_TYPE(o)) && \\r
+    (Py_TYPE(o)->tp_is_gc == NULL || Py_TYPE(o)->tp_is_gc(o)))\r
+\r
+PyAPI_FUNC(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, Py_ssize_t);\r
+#define PyObject_GC_Resize(type, op, n) \\r
+                ( (type *) _PyObject_GC_Resize((PyVarObject *)(op), (n)) )\r
+\r
+/* for source compatibility with 2.2 */\r
+#define _PyObject_GC_Del PyObject_GC_Del\r
+\r
+/* GC information is stored BEFORE the object structure. */\r
+typedef union _gc_head {\r
+    struct {\r
+        union _gc_head *gc_next;\r
+        union _gc_head *gc_prev;\r
+        Py_ssize_t gc_refs;\r
+    } gc;\r
+    long double dummy;  /* force worst-case alignment */\r
+} PyGC_Head;\r
+\r
+extern PyGC_Head *_PyGC_generation0;\r
+\r
+#define _Py_AS_GC(o) ((PyGC_Head *)(o)-1)\r
+\r
+#define _PyGC_REFS_UNTRACKED                    (-2)\r
+#define _PyGC_REFS_REACHABLE                    (-3)\r
+#define _PyGC_REFS_TENTATIVELY_UNREACHABLE      (-4)\r
+\r
+/* Tell the GC to track this object.  NB: While the object is tracked the\r
+ * collector it must be safe to call the ob_traverse method. */\r
+#define _PyObject_GC_TRACK(o) do { \\r
+    PyGC_Head *g = _Py_AS_GC(o); \\r
+    if (g->gc.gc_refs != _PyGC_REFS_UNTRACKED) \\r
+        Py_FatalError("GC object already tracked"); \\r
+    g->gc.gc_refs = _PyGC_REFS_REACHABLE; \\r
+    g->gc.gc_next = _PyGC_generation0; \\r
+    g->gc.gc_prev = _PyGC_generation0->gc.gc_prev; \\r
+    g->gc.gc_prev->gc.gc_next = g; \\r
+    _PyGC_generation0->gc.gc_prev = g; \\r
+    } while (0);\r
+\r
+/* Tell the GC to stop tracking this object.\r
+ * gc_next doesn't need to be set to NULL, but doing so is a good\r
+ * way to provoke memory errors if calling code is confused.\r
+ */\r
+#define _PyObject_GC_UNTRACK(o) do { \\r
+    PyGC_Head *g = _Py_AS_GC(o); \\r
+    assert(g->gc.gc_refs != _PyGC_REFS_UNTRACKED); \\r
+    g->gc.gc_refs = _PyGC_REFS_UNTRACKED; \\r
+    g->gc.gc_prev->gc.gc_next = g->gc.gc_next; \\r
+    g->gc.gc_next->gc.gc_prev = g->gc.gc_prev; \\r
+    g->gc.gc_next = NULL; \\r
+    } while (0);\r
+\r
+/* True if the object is currently tracked by the GC. */\r
+#define _PyObject_GC_IS_TRACKED(o) \\r
+    ((_Py_AS_GC(o))->gc.gc_refs != _PyGC_REFS_UNTRACKED)\r
+\r
+/* True if the object may be tracked by the GC in the future, or already is.\r
+   This can be useful to implement some optimizations. */\r
+#define _PyObject_GC_MAY_BE_TRACKED(obj) \\r
+    (PyObject_IS_GC(obj) && \\r
+        (!PyTuple_CheckExact(obj) || _PyObject_GC_IS_TRACKED(obj)))\r
+\r
+\r
+PyAPI_FUNC(PyObject *) _PyObject_GC_Malloc(size_t);\r
+PyAPI_FUNC(PyObject *) _PyObject_GC_New(PyTypeObject *);\r
+PyAPI_FUNC(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t);\r
+PyAPI_FUNC(void) PyObject_GC_Track(void *);\r
+PyAPI_FUNC(void) PyObject_GC_UnTrack(void *);\r
+PyAPI_FUNC(void) PyObject_GC_Del(void *);\r
+\r
+#define PyObject_GC_New(type, typeobj) \\r
+                ( (type *) _PyObject_GC_New(typeobj) )\r
+#define PyObject_GC_NewVar(type, typeobj, n) \\r
+                ( (type *) _PyObject_GC_NewVar((typeobj), (n)) )\r
+\r
+\r
+/* Utility macro to help write tp_traverse functions.\r
+ * To use this macro, the tp_traverse function must name its arguments\r
+ * "visit" and "arg".  This is intended to keep tp_traverse functions\r
+ * looking as much alike as possible.\r
+ */\r
+#define Py_VISIT(op)                                                    \\r
+    do {                                                                \\r
+        if (op) {                                                       \\r
+            int vret = visit((PyObject *)(op), arg);                    \\r
+            if (vret)                                                   \\r
+                return vret;                                            \\r
+        }                                                               \\r
+    } while (0)\r
+\r
+/* This is here for the sake of backwards compatibility.  Extensions that\r
+ * use the old GC API will still compile but the objects will not be\r
+ * tracked by the GC. */\r
+#define PyGC_HEAD_SIZE 0\r
+#define PyObject_GC_Init(op)\r
+#define PyObject_GC_Fini(op)\r
+#define PyObject_AS_GC(op) (op)\r
+#define PyObject_FROM_GC(op) (op)\r
+\r
+\r
+/* Test if a type supports weak references */\r
+#define PyType_SUPPORTS_WEAKREFS(t) \\r
+    (PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) \\r
+     && ((t)->tp_weaklistoffset > 0))\r
+\r
+#define PyObject_GET_WEAKREFS_LISTPTR(o) \\r
+    ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset))\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_OBJIMPL_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/opcode.h b/AppPkg/Applications/Python/Python-2.7.10/Include/opcode.h
new file mode 100644 (file)
index 0000000..fe2a690
--- /dev/null
@@ -0,0 +1,162 @@
+#ifndef Py_OPCODE_H\r
+#define Py_OPCODE_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Instruction opcodes for compiled code */\r
+\r
+#define STOP_CODE      0\r
+#define POP_TOP                1\r
+#define ROT_TWO                2\r
+#define ROT_THREE      3\r
+#define DUP_TOP                4\r
+#define ROT_FOUR       5\r
+#define NOP            9\r
+\r
+#define UNARY_POSITIVE 10\r
+#define UNARY_NEGATIVE 11\r
+#define UNARY_NOT      12\r
+#define UNARY_CONVERT  13\r
+\r
+#define UNARY_INVERT   15\r
+\r
+#define BINARY_POWER   19\r
+\r
+#define BINARY_MULTIPLY        20\r
+#define BINARY_DIVIDE  21\r
+#define BINARY_MODULO  22\r
+#define BINARY_ADD     23\r
+#define BINARY_SUBTRACT        24\r
+#define BINARY_SUBSCR  25\r
+#define BINARY_FLOOR_DIVIDE 26\r
+#define BINARY_TRUE_DIVIDE 27\r
+#define INPLACE_FLOOR_DIVIDE 28\r
+#define INPLACE_TRUE_DIVIDE 29\r
+\r
+#define SLICE          30\r
+/* Also uses 31-33 */\r
+\r
+#define STORE_SLICE    40\r
+/* Also uses 41-43 */\r
+\r
+#define DELETE_SLICE   50\r
+/* Also uses 51-53 */\r
+\r
+#define STORE_MAP      54\r
+#define INPLACE_ADD    55\r
+#define INPLACE_SUBTRACT       56\r
+#define INPLACE_MULTIPLY       57\r
+#define INPLACE_DIVIDE 58\r
+#define INPLACE_MODULO 59\r
+#define STORE_SUBSCR   60\r
+#define DELETE_SUBSCR  61\r
+\r
+#define BINARY_LSHIFT  62\r
+#define BINARY_RSHIFT  63\r
+#define BINARY_AND     64\r
+#define BINARY_XOR     65\r
+#define BINARY_OR      66\r
+#define INPLACE_POWER  67\r
+#define GET_ITER       68\r
+\r
+#define PRINT_EXPR     70\r
+#define PRINT_ITEM     71\r
+#define PRINT_NEWLINE  72\r
+#define PRINT_ITEM_TO   73\r
+#define PRINT_NEWLINE_TO 74\r
+#define INPLACE_LSHIFT 75\r
+#define INPLACE_RSHIFT 76\r
+#define INPLACE_AND    77\r
+#define INPLACE_XOR    78\r
+#define INPLACE_OR     79\r
+#define BREAK_LOOP     80\r
+#define WITH_CLEANUP    81\r
+#define LOAD_LOCALS    82\r
+#define RETURN_VALUE   83\r
+#define IMPORT_STAR    84\r
+#define EXEC_STMT      85\r
+#define YIELD_VALUE    86\r
+#define POP_BLOCK      87\r
+#define END_FINALLY    88\r
+#define BUILD_CLASS    89\r
+\r
+#define HAVE_ARGUMENT  90      /* Opcodes from here have an argument: */\r
+\r
+#define STORE_NAME     90      /* Index in name list */\r
+#define DELETE_NAME    91      /* "" */\r
+#define UNPACK_SEQUENCE        92      /* Number of sequence items */\r
+#define FOR_ITER       93\r
+#define LIST_APPEND    94\r
+\r
+#define STORE_ATTR     95      /* Index in name list */\r
+#define DELETE_ATTR    96      /* "" */\r
+#define STORE_GLOBAL   97      /* "" */\r
+#define DELETE_GLOBAL  98      /* "" */\r
+#define DUP_TOPX       99      /* number of items to duplicate */\r
+#define LOAD_CONST     100     /* Index in const list */\r
+#define LOAD_NAME      101     /* Index in name list */\r
+#define BUILD_TUPLE    102     /* Number of tuple items */\r
+#define BUILD_LIST     103     /* Number of list items */\r
+#define BUILD_SET      104     /* Number of set items */\r
+#define BUILD_MAP      105     /* Always zero for now */\r
+#define LOAD_ATTR      106     /* Index in name list */\r
+#define COMPARE_OP     107     /* Comparison operator */\r
+#define IMPORT_NAME    108     /* Index in name list */\r
+#define IMPORT_FROM    109     /* Index in name list */\r
+#define JUMP_FORWARD   110     /* Number of bytes to skip */\r
+\r
+#define JUMP_IF_FALSE_OR_POP 111 /* Target byte offset from beginning\r
+                                    of code */\r
+#define JUMP_IF_TRUE_OR_POP 112        /* "" */\r
+#define JUMP_ABSOLUTE  113     /* "" */\r
+#define POP_JUMP_IF_FALSE 114  /* "" */\r
+#define POP_JUMP_IF_TRUE 115   /* "" */\r
+\r
+#define LOAD_GLOBAL    116     /* Index in name list */\r
+\r
+#define CONTINUE_LOOP  119     /* Start of loop (absolute) */\r
+#define SETUP_LOOP     120     /* Target address (relative) */\r
+#define SETUP_EXCEPT   121     /* "" */\r
+#define SETUP_FINALLY  122     /* "" */\r
+\r
+#define LOAD_FAST      124     /* Local variable number */\r
+#define STORE_FAST     125     /* Local variable number */\r
+#define DELETE_FAST    126     /* Local variable number */\r
+\r
+#define RAISE_VARARGS  130     /* Number of raise arguments (1, 2 or 3) */\r
+/* CALL_FUNCTION_XXX opcodes defined below depend on this definition */\r
+#define CALL_FUNCTION  131     /* #args + (#kwargs<<8) */\r
+#define MAKE_FUNCTION  132     /* #defaults */\r
+#define BUILD_SLICE    133     /* Number of items */\r
+\r
+#define MAKE_CLOSURE    134     /* #free vars */\r
+#define LOAD_CLOSURE    135     /* Load free variable from closure */\r
+#define LOAD_DEREF      136     /* Load and dereference from closure cell */ \r
+#define STORE_DEREF     137     /* Store into cell */ \r
+\r
+/* The next 3 opcodes must be contiguous and satisfy\r
+   (CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1  */\r
+#define CALL_FUNCTION_VAR          140 /* #args + (#kwargs<<8) */\r
+#define CALL_FUNCTION_KW           141 /* #args + (#kwargs<<8) */\r
+#define CALL_FUNCTION_VAR_KW       142 /* #args + (#kwargs<<8) */\r
+\r
+#define SETUP_WITH 143\r
+\r
+/* Support for opargs more than 16 bits long */\r
+#define EXTENDED_ARG  145\r
+\r
+#define SET_ADD         146\r
+#define MAP_ADD         147\r
+\r
+\r
+enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, PyCmp_GT=Py_GT, PyCmp_GE=Py_GE,\r
+            PyCmp_IN, PyCmp_NOT_IN, PyCmp_IS, PyCmp_IS_NOT, PyCmp_EXC_MATCH, PyCmp_BAD};\r
+\r
+#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_OPCODE_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/osdefs.h b/AppPkg/Applications/Python/Python-2.7.10/Include/osdefs.h
new file mode 100644 (file)
index 0000000..d41ea14
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef Py_OSDEFS_H\r
+#define Py_OSDEFS_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Operating system dependencies */\r
+\r
+/* Mod by chrish: QNX has WATCOM, but isn't DOS */\r
+#if !defined(__QNX__)\r
+#if defined(MS_WINDOWS) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__DJGPP__) || defined(PYOS_OS2)\r
+#if defined(PYOS_OS2) && defined(PYCC_GCC)\r
+#define MAXPATHLEN 260\r
+#define SEP '/'\r
+#define ALTSEP '\\'\r
+#else\r
+#define SEP '\\'\r
+#define ALTSEP '/'\r
+#define MAXPATHLEN 256\r
+#endif\r
+#define DELIM ';'\r
+#endif\r
+#endif\r
+\r
+#ifdef RISCOS\r
+#define SEP '.'\r
+#define MAXPATHLEN 256\r
+#define DELIM ','\r
+#endif\r
+\r
+\r
+/* Filename separator */\r
+#ifndef SEP\r
+#define SEP '/'\r
+#endif\r
+\r
+/* Max pathname length */\r
+#ifdef __hpux\r
+#include <sys/param.h>\r
+#include <limits.h>\r
+#ifndef PATH_MAX\r
+#define PATH_MAX MAXPATHLEN\r
+#endif\r
+#endif\r
+\r
+#ifndef MAXPATHLEN\r
+#if defined(PATH_MAX) && PATH_MAX > 1024\r
+#define MAXPATHLEN PATH_MAX\r
+#else\r
+#define MAXPATHLEN 1024\r
+#endif\r
+#endif\r
+\r
+/* Search path entry delimiter */\r
+#ifndef DELIM\r
+#define DELIM ':'\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_OSDEFS_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/parsetok.h b/AppPkg/Applications/Python/Python-2.7.10/Include/parsetok.h
new file mode 100644 (file)
index 0000000..915bdba
--- /dev/null
@@ -0,0 +1,64 @@
+\r
+/* Parser-tokenizer link interface */\r
+\r
+#ifndef Py_PARSETOK_H\r
+#define Py_PARSETOK_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct {\r
+    int error;\r
+    const char *filename;\r
+    int lineno;\r
+    int offset;\r
+    char *text;\r
+    int token;\r
+    int expected;\r
+} perrdetail;\r
+\r
+#if 0\r
+#define PyPARSE_YIELD_IS_KEYWORD       0x0001\r
+#endif\r
+\r
+#define PyPARSE_DONT_IMPLY_DEDENT      0x0002\r
+\r
+#if 0\r
+#define PyPARSE_WITH_IS_KEYWORD                0x0003\r
+#endif\r
+\r
+#define PyPARSE_PRINT_IS_FUNCTION       0x0004\r
+#define PyPARSE_UNICODE_LITERALS        0x0008\r
+\r
+\r
+\r
+PyAPI_FUNC(node *) PyParser_ParseString(const char *, grammar *, int,\r
+                                              perrdetail *);\r
+PyAPI_FUNC(node *) PyParser_ParseFile (FILE *, const char *, grammar *, int,\r
+                                             char *, char *, perrdetail *);\r
+\r
+PyAPI_FUNC(node *) PyParser_ParseStringFlags(const char *, grammar *, int,\r
+                                              perrdetail *, int);\r
+PyAPI_FUNC(node *) PyParser_ParseFileFlags(FILE *, const char *, grammar *,\r
+                                                int, char *, char *,\r
+                                                perrdetail *, int);\r
+PyAPI_FUNC(node *) PyParser_ParseFileFlagsEx(FILE *, const char *, grammar *,\r
+                                                int, char *, char *,\r
+                                                perrdetail *, int *);\r
+\r
+PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilename(const char *,\r
+                                             const char *,\r
+                                             grammar *, int,\r
+                                              perrdetail *, int);\r
+PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilenameEx(const char *,\r
+                                             const char *,\r
+                                             grammar *, int,\r
+                                              perrdetail *, int *);\r
+\r
+/* Note that he following function is defined in pythonrun.c not parsetok.c. */\r
+PyAPI_FUNC(void) PyParser_SetError(perrdetail *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_PARSETOK_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/patchlevel.h b/AppPkg/Applications/Python/Python-2.7.10/Include/patchlevel.h
new file mode 100644 (file)
index 0000000..6b17d28
--- /dev/null
@@ -0,0 +1,43 @@
+\r
+/* Newfangled version identification scheme.\r
+\r
+   This scheme was added in Python 1.5.2b2; before that time, only PATCHLEVEL\r
+   was available.  To test for presence of the scheme, test for\r
+   defined(PY_MAJOR_VERSION).\r
+\r
+   When the major or minor version changes, the VERSION variable in\r
+   configure.ac must also be changed.\r
+\r
+   There is also (independent) API version information in modsupport.h.\r
+*/\r
+\r
+/* Values for PY_RELEASE_LEVEL */\r
+#define PY_RELEASE_LEVEL_ALPHA 0xA\r
+#define PY_RELEASE_LEVEL_BETA  0xB\r
+#define PY_RELEASE_LEVEL_GAMMA 0xC     /* For release candidates */\r
+#define PY_RELEASE_LEVEL_FINAL 0xF     /* Serial should be 0 here */\r
+                                       /* Higher for patch releases */\r
+\r
+/* Version parsed out into numeric values */\r
+/*--start constants--*/\r
+#define PY_MAJOR_VERSION       2\r
+#define PY_MINOR_VERSION       7\r
+#define PY_MICRO_VERSION       10\r
+#define PY_RELEASE_LEVEL       PY_RELEASE_LEVEL_FINAL\r
+#define PY_RELEASE_SERIAL      0\r
+\r
+/* Version as a string */\r
+#define PY_VERSION             "2.7.10"\r
+/*--end constants--*/\r
+\r
+/* Subversion Revision number of this file (not of the repository). Empty\r
+   since Mercurial migration. */\r
+#define PY_PATCHLEVEL_REVISION  ""\r
+\r
+/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.\r
+   Use this for numeric comparisons, e.g. #if PY_VERSION_HEX >= ... */\r
+#define PY_VERSION_HEX ((PY_MAJOR_VERSION << 24) | \\r
+                       (PY_MINOR_VERSION << 16) | \\r
+                       (PY_MICRO_VERSION <<  8) | \\r
+                       (PY_RELEASE_LEVEL <<  4) | \\r
+                       (PY_RELEASE_SERIAL << 0))\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pgen.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pgen.h
new file mode 100644 (file)
index 0000000..af84852
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef Py_PGEN_H\r
+#define Py_PGEN_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Parser generator interface */\r
+\r
+extern grammar *meta_grammar(void);\r
+\r
+struct _node;\r
+extern grammar *pgen(struct _node *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_PGEN_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pgenheaders.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pgenheaders.h
new file mode 100644 (file)
index 0000000..7aac4e2
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef Py_PGENHEADERS_H\r
+#define Py_PGENHEADERS_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Include files and extern declarations used by most of the parser. */\r
+\r
+#include "Python.h"\r
+\r
+PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)\r
+                       Py_GCC_ATTRIBUTE((format(printf, 1, 2)));\r
+PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...)\r
+                       Py_GCC_ATTRIBUTE((format(printf, 1, 2)));\r
+\r
+#define addarc _Py_addarc\r
+#define addbit _Py_addbit\r
+#define adddfa _Py_adddfa\r
+#define addfirstsets _Py_addfirstsets\r
+#define addlabel _Py_addlabel\r
+#define addstate _Py_addstate\r
+#define delbitset _Py_delbitset\r
+#define dumptree _Py_dumptree\r
+#define findlabel _Py_findlabel\r
+#define mergebitset _Py_mergebitset\r
+#define meta_grammar _Py_meta_grammar\r
+#define newbitset _Py_newbitset\r
+#define newgrammar _Py_newgrammar\r
+#define pgen _Py_pgen\r
+#define printgrammar _Py_printgrammar\r
+#define printnonterminals _Py_printnonterminals\r
+#define printtree _Py_printtree\r
+#define samebitset _Py_samebitset\r
+#define showtree _Py_showtree\r
+#define tok_dump _Py_tok_dump\r
+#define translatelabels _Py_translatelabels\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_PGENHEADERS_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/py_curses.h b/AppPkg/Applications/Python/Python-2.7.10/Include/py_curses.h
new file mode 100644 (file)
index 0000000..2120607
--- /dev/null
@@ -0,0 +1,176 @@
+\r
+#ifndef Py_CURSES_H\r
+#define Py_CURSES_H\r
+\r
+#ifdef __APPLE__\r
+/*\r
+** On Mac OS X 10.2 [n]curses.h and stdlib.h use different guards\r
+** against multiple definition of wchar_t.\r
+*/\r
+#ifdef _BSD_WCHAR_T_DEFINED_\r
+#define _WCHAR_T\r
+#endif\r
+\r
+/* the following define is necessary for OS X 10.6; without it, the\r
+   Apple-supplied ncurses.h sets NCURSES_OPAQUE to 1, and then Python\r
+   can't get at the WINDOW flags field. */\r
+#define NCURSES_OPAQUE 0\r
+#endif /* __APPLE__ */\r
+\r
+#ifdef __FreeBSD__\r
+/*\r
+** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards\r
+** against multiple definition of wchar_t and wint_t.\r
+*/\r
+#ifdef _XOPEN_SOURCE_EXTENDED\r
+#ifndef __FreeBSD_version\r
+#include <osreldate.h>\r
+#endif\r
+#if __FreeBSD_version >= 500000\r
+#ifndef __wchar_t\r
+#define __wchar_t\r
+#endif\r
+#ifndef __wint_t\r
+#define __wint_t\r
+#endif\r
+#else\r
+#ifndef _WCHAR_T\r
+#define _WCHAR_T\r
+#endif\r
+#ifndef _WINT_T\r
+#define _WINT_T\r
+#endif\r
+#endif\r
+#endif\r
+#endif\r
+\r
+#ifdef HAVE_NCURSES_H\r
+#include <ncurses.h>\r
+#else\r
+#include <curses.h>\r
+#ifdef HAVE_TERM_H\r
+/* for tigetstr, which is not declared in SysV curses */\r
+#include <term.h>\r
+#endif\r
+#endif\r
+\r
+#ifdef HAVE_NCURSES_H\r
+/* configure was checking <curses.h>, but we will\r
+   use <ncurses.h>, which has all these features. */\r
+#ifndef WINDOW_HAS_FLAGS\r
+#define WINDOW_HAS_FLAGS 1\r
+#endif\r
+#ifndef MVWDELCH_IS_EXPRESSION\r
+#define MVWDELCH_IS_EXPRESSION 1\r
+#endif\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#define PyCurses_API_pointers 4\r
+\r
+/* Type declarations */\r
+\r
+typedef struct {\r
+       PyObject_HEAD\r
+       WINDOW *win;\r
+} PyCursesWindowObject;\r
+\r
+#define PyCursesWindow_Check(v)         (Py_TYPE(v) == &PyCursesWindow_Type)\r
+\r
+#define PyCurses_CAPSULE_NAME "_curses._C_API"\r
+\r
+\r
+#ifdef CURSES_MODULE\r
+/* This section is used when compiling _cursesmodule.c */\r
+\r
+#else\r
+/* This section is used in modules that use the _cursesmodule API */\r
+\r
+static void **PyCurses_API;\r
+\r
+#define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])\r
+#define PyCursesSetupTermCalled  {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}\r
+#define PyCursesInitialised      {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}\r
+#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}\r
+\r
+#define import_curses() \\r
+    PyCurses_API = (void **)PyCapsule_Import(PyCurses_CAPSULE_NAME, 1);\r
+\r
+#endif\r
+\r
+/* general error messages */\r
+static char *catchall_ERR  = "curses function returned ERR";\r
+static char *catchall_NULL = "curses function returned NULL";\r
+\r
+/* Function Prototype Macros - They are ugly but very, very useful. ;-)\r
+\r
+   X - function name\r
+   TYPE - parameter Type\r
+   ERGSTR - format string for construction of the return value\r
+   PARSESTR - format string for argument parsing\r
+   */\r
+\r
+#define NoArgNoReturnFunction(X) \\r
+static PyObject *PyCurses_ ## X (PyObject *self) \\r
+{ \\r
+  PyCursesInitialised \\r
+  return PyCursesCheckERR(X(), # X); }\r
+\r
+#define NoArgOrFlagNoReturnFunction(X) \\r
+static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \\r
+{ \\r
+  int flag = 0; \\r
+  PyCursesInitialised \\r
+  switch(PyTuple_Size(args)) { \\r
+  case 0: \\r
+    return PyCursesCheckERR(X(), # X); \\r
+  case 1: \\r
+    if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \\r
+    if (flag) return PyCursesCheckERR(X(), # X); \\r
+    else return PyCursesCheckERR(no ## X (), # X); \\r
+  default: \\r
+    PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \\r
+    return NULL; } }\r
+\r
+#define NoArgReturnIntFunction(X) \\r
+static PyObject *PyCurses_ ## X (PyObject *self) \\r
+{ \\r
+ PyCursesInitialised \\r
+ return PyInt_FromLong((long) X()); }\r
+\r
+\r
+#define NoArgReturnStringFunction(X) \\r
+static PyObject *PyCurses_ ## X (PyObject *self) \\r
+{ \\r
+  PyCursesInitialised \\r
+  return PyString_FromString(X()); }\r
+\r
+#define NoArgTrueFalseFunction(X) \\r
+static PyObject *PyCurses_ ## X (PyObject *self) \\r
+{ \\r
+  PyCursesInitialised \\r
+  if (X () == FALSE) { \\r
+    Py_INCREF(Py_False); \\r
+    return Py_False; \\r
+  } \\r
+  Py_INCREF(Py_True); \\r
+  return Py_True; }\r
+\r
+#define NoArgNoReturnVoidFunction(X) \\r
+static PyObject *PyCurses_ ## X (PyObject *self) \\r
+{ \\r
+  PyCursesInitialised \\r
+  X(); \\r
+  Py_INCREF(Py_None); \\r
+  return Py_None; }\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* !defined(Py_CURSES_H) */\r
+\r
+\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pyarena.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pyarena.h
new file mode 100644 (file)
index 0000000..fec1afa
--- /dev/null
@@ -0,0 +1,62 @@
+/* An arena-like memory interface for the compiler.\r
+ */\r
+\r
+#ifndef Py_PYARENA_H\r
+#define Py_PYARENA_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+  typedef struct _arena PyArena;\r
+\r
+  /* PyArena_New() and PyArena_Free() create a new arena and free it,\r
+     respectively.  Once an arena has been created, it can be used\r
+     to allocate memory via PyArena_Malloc().  Pointers to PyObject can\r
+     also be registered with the arena via PyArena_AddPyObject(), and the\r
+     arena will ensure that the PyObjects stay alive at least until\r
+     PyArena_Free() is called.  When an arena is freed, all the memory it\r
+     allocated is freed, the arena releases internal references to registered\r
+     PyObject*, and none of its pointers are valid.\r
+     XXX (tim) What does "none of its pointers are valid" mean?  Does it\r
+     XXX mean that pointers previously obtained via PyArena_Malloc() are\r
+     XXX no longer valid?  (That's clearly true, but not sure that's what\r
+     XXX the text is trying to say.)\r
+\r
+     PyArena_New() returns an arena pointer.  On error, it\r
+     returns a negative number and sets an exception.\r
+     XXX (tim):  Not true.  On error, PyArena_New() actually returns NULL,\r
+     XXX and looks like it may or may not set an exception (e.g., if the\r
+     XXX internal PyList_New(0) returns NULL, PyArena_New() passes that on\r
+     XXX and an exception is set; OTOH, if the internal\r
+     XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but\r
+     XXX an exception is not set in that case).\r
+  */\r
+  PyAPI_FUNC(PyArena *) PyArena_New(void);\r
+  PyAPI_FUNC(void) PyArena_Free(PyArena *);\r
+\r
+  /* Mostly like malloc(), return the address of a block of memory spanning\r
+   * `size` bytes, or return NULL (without setting an exception) if enough\r
+   * new memory can't be obtained.  Unlike malloc(0), PyArena_Malloc() with\r
+   * size=0 does not guarantee to return a unique pointer (the pointer\r
+   * returned may equal one or more other pointers obtained from\r
+   * PyArena_Malloc()).\r
+   * Note that pointers obtained via PyArena_Malloc() must never be passed to\r
+   * the system free() or realloc(), or to any of Python's similar memory-\r
+   * management functions.  PyArena_Malloc()-obtained pointers remain valid\r
+   * until PyArena_Free(ar) is called, at which point all pointers obtained\r
+   * from the arena `ar` become invalid simultaneously.\r
+   */\r
+  PyAPI_FUNC(void *) PyArena_Malloc(PyArena *, size_t size);\r
+\r
+  /* This routine isn't a proper arena allocation routine.  It takes\r
+   * a PyObject* and records it so that it can be DECREFed when the\r
+   * arena is freed.\r
+   */\r
+  PyAPI_FUNC(int) PyArena_AddPyObject(PyArena *, PyObject *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* !Py_PYARENA_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pycapsule.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pycapsule.h
new file mode 100644 (file)
index 0000000..d414435
--- /dev/null
@@ -0,0 +1,56 @@
+\r
+/* Capsule objects let you wrap a C "void *" pointer in a Python\r
+   object.  They're a way of passing data through the Python interpreter\r
+   without creating your own custom type.\r
+\r
+   Capsules are used for communication between extension modules.\r
+   They provide a way for an extension module to export a C interface\r
+   to other extension modules, so that extension modules can use the\r
+   Python import mechanism to link to one another.\r
+\r
+   For more information, please see "c-api/capsule.html" in the\r
+   documentation.\r
+*/\r
+\r
+#ifndef Py_CAPSULE_H\r
+#define Py_CAPSULE_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_DATA(PyTypeObject) PyCapsule_Type;\r
+\r
+typedef void (*PyCapsule_Destructor)(PyObject *);\r
+\r
+#define PyCapsule_CheckExact(op) (Py_TYPE(op) == &PyCapsule_Type)\r
+\r
+\r
+PyAPI_FUNC(PyObject *) PyCapsule_New(\r
+    void *pointer,\r
+    const char *name,\r
+    PyCapsule_Destructor destructor);\r
+\r
+PyAPI_FUNC(void *) PyCapsule_GetPointer(PyObject *capsule, const char *name);\r
+\r
+PyAPI_FUNC(PyCapsule_Destructor) PyCapsule_GetDestructor(PyObject *capsule);\r
+\r
+PyAPI_FUNC(const char *) PyCapsule_GetName(PyObject *capsule);\r
+\r
+PyAPI_FUNC(void *) PyCapsule_GetContext(PyObject *capsule);\r
+\r
+PyAPI_FUNC(int) PyCapsule_IsValid(PyObject *capsule, const char *name);\r
+\r
+PyAPI_FUNC(int) PyCapsule_SetPointer(PyObject *capsule, void *pointer);\r
+\r
+PyAPI_FUNC(int) PyCapsule_SetDestructor(PyObject *capsule, PyCapsule_Destructor destructor);\r
+\r
+PyAPI_FUNC(int) PyCapsule_SetName(PyObject *capsule, const char *name);\r
+\r
+PyAPI_FUNC(int) PyCapsule_SetContext(PyObject *capsule, void *context);\r
+\r
+PyAPI_FUNC(void *) PyCapsule_Import(const char *name, int no_block);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_CAPSULE_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pyctype.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pyctype.h
new file mode 100644 (file)
index 0000000..e28542a
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef PYCTYPE_H\r
+#define PYCTYPE_H\r
+\r
+#define PY_CTF_LOWER  0x01\r
+#define PY_CTF_UPPER  0x02\r
+#define PY_CTF_ALPHA  (PY_CTF_LOWER|PY_CTF_UPPER)\r
+#define PY_CTF_DIGIT  0x04\r
+#define PY_CTF_ALNUM  (PY_CTF_ALPHA|PY_CTF_DIGIT)\r
+#define PY_CTF_SPACE  0x08\r
+#define PY_CTF_XDIGIT 0x10\r
+\r
+PyAPI_DATA(const unsigned int) _Py_ctype_table[256];\r
+\r
+/* Unlike their C counterparts, the following macros are not meant to\r
+ * handle an int with any of the values [EOF, 0-UCHAR_MAX]. The argument\r
+ * must be a signed/unsigned char. */\r
+#define Py_ISLOWER(c)  (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_LOWER)\r
+#define Py_ISUPPER(c)  (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_UPPER)\r
+#define Py_ISALPHA(c)  (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_ALPHA)\r
+#define Py_ISDIGIT(c)  (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_DIGIT)\r
+#define Py_ISXDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_XDIGIT)\r
+#define Py_ISALNUM(c)  (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_ALNUM)\r
+#define Py_ISSPACE(c)  (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_SPACE)\r
+\r
+PyAPI_DATA(const unsigned char) _Py_ctype_tolower[256];\r
+PyAPI_DATA(const unsigned char) _Py_ctype_toupper[256];\r
+\r
+#define Py_TOLOWER(c) (_Py_ctype_tolower[Py_CHARMASK(c)])\r
+#define Py_TOUPPER(c) (_Py_ctype_toupper[Py_CHARMASK(c)])\r
+\r
+#endif /* !PYCTYPE_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pydebug.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pydebug.h
new file mode 100644 (file)
index 0000000..9f719e1
--- /dev/null
@@ -0,0 +1,41 @@
+\r
+#ifndef Py_PYDEBUG_H\r
+#define Py_PYDEBUG_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_DATA(int) Py_DebugFlag;\r
+PyAPI_DATA(int) Py_VerboseFlag;\r
+PyAPI_DATA(int) Py_InteractiveFlag;\r
+PyAPI_DATA(int) Py_InspectFlag;\r
+PyAPI_DATA(int) Py_OptimizeFlag;\r
+PyAPI_DATA(int) Py_NoSiteFlag;\r
+PyAPI_DATA(int) Py_BytesWarningFlag;\r
+PyAPI_DATA(int) Py_UseClassExceptionsFlag;\r
+PyAPI_DATA(int) Py_FrozenFlag;\r
+PyAPI_DATA(int) Py_TabcheckFlag;\r
+PyAPI_DATA(int) Py_UnicodeFlag;\r
+PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;\r
+PyAPI_DATA(int) Py_DivisionWarningFlag;\r
+PyAPI_DATA(int) Py_DontWriteBytecodeFlag;\r
+PyAPI_DATA(int) Py_NoUserSiteDirectory;\r
+/* _XXX Py_QnewFlag should go away in 3.0.  It's true iff -Qnew is passed,\r
+  on the command line, and is used in 2.2 by ceval.c to make all "/" divisions\r
+  true divisions (which they will be in 3.0). */\r
+PyAPI_DATA(int) _Py_QnewFlag;\r
+/* Warn about 3.x issues */\r
+PyAPI_DATA(int) Py_Py3kWarningFlag;\r
+PyAPI_DATA(int) Py_HashRandomizationFlag;\r
+\r
+/* this is a wrapper around getenv() that pays attention to\r
+   Py_IgnoreEnvironmentFlag.  It should be used for getting variables like\r
+   PYTHONPATH and PYTHONHOME from the environment */\r
+#define Py_GETENV(s) (Py_IgnoreEnvironmentFlag ? NULL : getenv(s))\r
+\r
+PyAPI_FUNC(void) Py_FatalError(const char *message);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_PYDEBUG_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pyerrors.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pyerrors.h
new file mode 100644 (file)
index 0000000..a703345
--- /dev/null
@@ -0,0 +1,329 @@
+#ifndef Py_ERRORS_H\r
+#define Py_ERRORS_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* Error objects */\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    PyObject *dict;\r
+    PyObject *args;\r
+    PyObject *message;\r
+} PyBaseExceptionObject;\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    PyObject *dict;\r
+    PyObject *args;\r
+    PyObject *message;\r
+    PyObject *msg;\r
+    PyObject *filename;\r
+    PyObject *lineno;\r
+    PyObject *offset;\r
+    PyObject *text;\r
+    PyObject *print_file_and_line;\r
+} PySyntaxErrorObject;\r
+\r
+#ifdef Py_USING_UNICODE\r
+typedef struct {\r
+    PyObject_HEAD\r
+    PyObject *dict;\r
+    PyObject *args;\r
+    PyObject *message;\r
+    PyObject *encoding;\r
+    PyObject *object;\r
+    Py_ssize_t start;\r
+    Py_ssize_t end;\r
+    PyObject *reason;\r
+} PyUnicodeErrorObject;\r
+#endif\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    PyObject *dict;\r
+    PyObject *args;\r
+    PyObject *message;\r
+    PyObject *code;\r
+} PySystemExitObject;\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    PyObject *dict;\r
+    PyObject *args;\r
+    PyObject *message;\r
+    PyObject *myerrno;\r
+    PyObject *strerror;\r
+    PyObject *filename;\r
+} PyEnvironmentErrorObject;\r
+\r
+#ifdef MS_WINDOWS\r
+typedef struct {\r
+    PyObject_HEAD\r
+    PyObject *dict;\r
+    PyObject *args;\r
+    PyObject *message;\r
+    PyObject *myerrno;\r
+    PyObject *strerror;\r
+    PyObject *filename;\r
+    PyObject *winerror;\r
+} PyWindowsErrorObject;\r
+#endif\r
+\r
+/* Error handling definitions */\r
+\r
+PyAPI_FUNC(void) PyErr_SetNone(PyObject *);\r
+PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *);\r
+PyAPI_FUNC(void) PyErr_SetString(PyObject *, const char *);\r
+PyAPI_FUNC(PyObject *) PyErr_Occurred(void);\r
+PyAPI_FUNC(void) PyErr_Clear(void);\r
+PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);\r
+PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);\r
+\r
+#ifdef Py_DEBUG\r
+#define _PyErr_OCCURRED() PyErr_Occurred()\r
+#else\r
+#define _PyErr_OCCURRED() (_PyThreadState_Current->curexc_type)\r
+#endif\r
+\r
+/* Error testing and normalization */\r
+PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);\r
+PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);\r
+PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);\r
+PyAPI_FUNC(void) _PyErr_ReplaceException(PyObject *, PyObject *, PyObject *);\r
+\r
+/* */\r
+\r
+#define PyExceptionClass_Check(x)                                       \\r
+    (PyClass_Check((x)) || (PyType_Check((x)) &&                        \\r
+      PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)))\r
+\r
+#define PyExceptionInstance_Check(x)                    \\r
+    (PyInstance_Check((x)) ||                           \\r
+     PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS))\r
+\r
+#define PyExceptionClass_Name(x)                                   \\r
+    (PyClass_Check((x))                                            \\r
+     ? PyString_AS_STRING(((PyClassObject*)(x))->cl_name)          \\r
+     : (char *)(((PyTypeObject*)(x))->tp_name))\r
+\r
+#define PyExceptionInstance_Class(x)                                    \\r
+    ((PyInstance_Check((x))                                             \\r
+      ? (PyObject*)((PyInstanceObject*)(x))->in_class                   \\r
+      : (PyObject*)((x)->ob_type)))\r
+\r
+\r
+/* Predefined exceptions */\r
+\r
+PyAPI_DATA(PyObject *) PyExc_BaseException;\r
+PyAPI_DATA(PyObject *) PyExc_Exception;\r
+PyAPI_DATA(PyObject *) PyExc_StopIteration;\r
+PyAPI_DATA(PyObject *) PyExc_GeneratorExit;\r
+PyAPI_DATA(PyObject *) PyExc_StandardError;\r
+PyAPI_DATA(PyObject *) PyExc_ArithmeticError;\r
+PyAPI_DATA(PyObject *) PyExc_LookupError;\r
+\r
+PyAPI_DATA(PyObject *) PyExc_AssertionError;\r
+PyAPI_DATA(PyObject *) PyExc_AttributeError;\r
+PyAPI_DATA(PyObject *) PyExc_EOFError;\r
+PyAPI_DATA(PyObject *) PyExc_FloatingPointError;\r
+PyAPI_DATA(PyObject *) PyExc_EnvironmentError;\r
+PyAPI_DATA(PyObject *) PyExc_IOError;\r
+PyAPI_DATA(PyObject *) PyExc_OSError;\r
+PyAPI_DATA(PyObject *) PyExc_ImportError;\r
+PyAPI_DATA(PyObject *) PyExc_IndexError;\r
+PyAPI_DATA(PyObject *) PyExc_KeyError;\r
+PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt;\r
+PyAPI_DATA(PyObject *) PyExc_MemoryError;\r
+PyAPI_DATA(PyObject *) PyExc_NameError;\r
+PyAPI_DATA(PyObject *) PyExc_OverflowError;\r
+PyAPI_DATA(PyObject *) PyExc_RuntimeError;\r
+PyAPI_DATA(PyObject *) PyExc_NotImplementedError;\r
+PyAPI_DATA(PyObject *) PyExc_SyntaxError;\r
+PyAPI_DATA(PyObject *) PyExc_IndentationError;\r
+PyAPI_DATA(PyObject *) PyExc_TabError;\r
+PyAPI_DATA(PyObject *) PyExc_ReferenceError;\r
+PyAPI_DATA(PyObject *) PyExc_SystemError;\r
+PyAPI_DATA(PyObject *) PyExc_SystemExit;\r
+PyAPI_DATA(PyObject *) PyExc_TypeError;\r
+PyAPI_DATA(PyObject *) PyExc_UnboundLocalError;\r
+PyAPI_DATA(PyObject *) PyExc_UnicodeError;\r
+PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError;\r
+PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError;\r
+PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError;\r
+PyAPI_DATA(PyObject *) PyExc_ValueError;\r
+PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError;\r
+#ifdef MS_WINDOWS\r
+PyAPI_DATA(PyObject *) PyExc_WindowsError;\r
+#endif\r
+#ifdef __VMS\r
+PyAPI_DATA(PyObject *) PyExc_VMSError;\r
+#endif\r
+\r
+PyAPI_DATA(PyObject *) PyExc_BufferError;\r
+\r
+PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst;\r
+PyAPI_DATA(PyObject *) PyExc_RecursionErrorInst;\r
+\r
+/* Predefined warning categories */\r
+PyAPI_DATA(PyObject *) PyExc_Warning;\r
+PyAPI_DATA(PyObject *) PyExc_UserWarning;\r
+PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;\r
+PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;\r
+PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;\r
+PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;\r
+PyAPI_DATA(PyObject *) PyExc_FutureWarning;\r
+PyAPI_DATA(PyObject *) PyExc_ImportWarning;\r
+PyAPI_DATA(PyObject *) PyExc_UnicodeWarning;\r
+PyAPI_DATA(PyObject *) PyExc_BytesWarning;\r
+\r
+\r
+/* Convenience functions */\r
+\r
+PyAPI_FUNC(int) PyErr_BadArgument(void);\r
+PyAPI_FUNC(PyObject *) PyErr_NoMemory(void);\r
+PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject(\r
+    PyObject *, PyObject *);\r
+PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(\r
+    PyObject *, const char *);\r
+#ifdef MS_WINDOWS\r
+PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(\r
+    PyObject *, const Py_UNICODE *);\r
+#endif /* MS_WINDOWS */\r
+\r
+PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *, const char *, ...)\r
+                        Py_GCC_ATTRIBUTE((format(printf, 2, 3)));\r
+\r
+#ifdef MS_WINDOWS\r
+PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilenameObject(\r
+    int, const char *);\r
+PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(\r
+    int, const char *);\r
+PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(\r
+    int, const Py_UNICODE *);\r
+PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);\r
+PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(\r
+    PyObject *,int, PyObject *);\r
+PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(\r
+    PyObject *,int, const char *);\r
+PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(\r
+    PyObject *,int, const Py_UNICODE *);\r
+PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);\r
+#endif /* MS_WINDOWS */\r
+\r
+/* Export the old function so that the existing API remains available: */\r
+PyAPI_FUNC(void) PyErr_BadInternalCall(void);\r
+PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename, int lineno);\r
+/* Mask the old API with a call to the new API for code compiled under\r
+   Python 2.0: */\r
+#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)\r
+\r
+/* Function to create a new exception */\r
+PyAPI_FUNC(PyObject *) PyErr_NewException(\r
+    char *name, PyObject *base, PyObject *dict);\r
+PyAPI_FUNC(PyObject *) PyErr_NewExceptionWithDoc(\r
+    char *name, char *doc, PyObject *base, PyObject *dict);\r
+PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);\r
+\r
+/* In sigcheck.c or signalmodule.c */\r
+PyAPI_FUNC(int) PyErr_CheckSignals(void);\r
+PyAPI_FUNC(void) PyErr_SetInterrupt(void);\r
+\r
+/* In signalmodule.c */\r
+int PySignal_SetWakeupFd(int fd);\r
+\r
+/* Support for adding program text to SyntaxErrors */\r
+PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);\r
+PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int);\r
+\r
+#ifdef Py_USING_UNICODE\r
+/* The following functions are used to create and modify unicode\r
+   exceptions from C */\r
+\r
+/* create a UnicodeDecodeError object */\r
+PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create(\r
+    const char *, const char *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);\r
+\r
+/* create a UnicodeEncodeError object */\r
+PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(\r
+    const char *, const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);\r
+\r
+/* create a UnicodeTranslateError object */\r
+PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(\r
+    const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);\r
+\r
+/* get the encoding attribute */\r
+PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *);\r
+\r
+/* get the object attribute */\r
+PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *);\r
+\r
+/* get the value of the start attribute (the int * may not be NULL)\r
+   return 0 on success, -1 on failure */\r
+PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *);\r
+PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *);\r
+PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *);\r
+\r
+/* assign a new value to the start attribute\r
+   return 0 on success, -1 on failure */\r
+PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t);\r
+PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t);\r
+PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t);\r
+\r
+/* get the value of the end attribute (the int *may not be NULL)\r
+ return 0 on success, -1 on failure */\r
+PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *);\r
+PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *);\r
+PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *);\r
+\r
+/* assign a new value to the end attribute\r
+   return 0 on success, -1 on failure */\r
+PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t);\r
+PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t);\r
+PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t);\r
+\r
+/* get the value of the reason attribute */\r
+PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *);\r
+\r
+/* assign a new value to the reason attribute\r
+   return 0 on success, -1 on failure */\r
+PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason(\r
+    PyObject *, const char *);\r
+PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason(\r
+    PyObject *, const char *);\r
+PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(\r
+    PyObject *, const char *);\r
+#endif\r
+\r
+\r
+/* These APIs aren't really part of the error implementation, but\r
+   often needed to format error messages; the native C lib APIs are\r
+   not available on all platforms, which is why we provide emulations\r
+   for those platforms in Python/mysnprintf.c,\r
+   WARNING:  The return value of snprintf varies across platforms; do\r
+   not rely on any particular behavior; eventually the C99 defn may\r
+   be reliable.\r
+*/\r
+#if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)\r
+# define HAVE_SNPRINTF\r
+# define snprintf _snprintf\r
+# define vsnprintf _vsnprintf\r
+#endif\r
+\r
+#include <stdarg.h>\r
+PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char  *format, ...)\r
+                        Py_GCC_ATTRIBUTE((format(printf, 3, 4)));\r
+PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char  *format, va_list va)\r
+                        Py_GCC_ATTRIBUTE((format(printf, 3, 0)));\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_ERRORS_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pyexpat.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pyexpat.h
new file mode 100644 (file)
index 0000000..fdce988
--- /dev/null
@@ -0,0 +1,48 @@
+/* Stuff to export relevant 'expat' entry points from pyexpat to other\r
+ * parser modules, such as cElementTree. */\r
+\r
+/* note: you must import expat.h before importing this module! */\r
+\r
+#define PyExpat_CAPI_MAGIC  "pyexpat.expat_CAPI 1.0"\r
+#define PyExpat_CAPSULE_NAME "pyexpat.expat_CAPI"\r
+\r
+struct PyExpat_CAPI \r
+{\r
+    char* magic; /* set to PyExpat_CAPI_MAGIC */\r
+    int size; /* set to sizeof(struct PyExpat_CAPI) */\r
+    int MAJOR_VERSION;\r
+    int MINOR_VERSION;\r
+    int MICRO_VERSION;\r
+    /* pointers to selected expat functions.  add new functions at\r
+       the end, if needed */\r
+    const XML_LChar * (*ErrorString)(enum XML_Error code);\r
+    enum XML_Error (*GetErrorCode)(XML_Parser parser);\r
+    XML_Size (*GetErrorColumnNumber)(XML_Parser parser);\r
+    XML_Size (*GetErrorLineNumber)(XML_Parser parser);\r
+    enum XML_Status (*Parse)(\r
+        XML_Parser parser, const char *s, int len, int isFinal);\r
+    XML_Parser (*ParserCreate_MM)(\r
+        const XML_Char *encoding, const XML_Memory_Handling_Suite *memsuite,\r
+        const XML_Char *namespaceSeparator);\r
+    void (*ParserFree)(XML_Parser parser);\r
+    void (*SetCharacterDataHandler)(\r
+        XML_Parser parser, XML_CharacterDataHandler handler);\r
+    void (*SetCommentHandler)(\r
+        XML_Parser parser, XML_CommentHandler handler);\r
+    void (*SetDefaultHandlerExpand)(\r
+        XML_Parser parser, XML_DefaultHandler handler);\r
+    void (*SetElementHandler)(\r
+        XML_Parser parser, XML_StartElementHandler start,\r
+        XML_EndElementHandler end);\r
+    void (*SetNamespaceDeclHandler)(\r
+        XML_Parser parser, XML_StartNamespaceDeclHandler start,\r
+        XML_EndNamespaceDeclHandler end);\r
+    void (*SetProcessingInstructionHandler)(\r
+        XML_Parser parser, XML_ProcessingInstructionHandler handler);\r
+    void (*SetUnknownEncodingHandler)(\r
+        XML_Parser parser, XML_UnknownEncodingHandler handler,\r
+        void *encodingHandlerData);\r
+    void (*SetUserData)(XML_Parser parser, void *userData);\r
+    /* always add new stuff to the end! */\r
+};\r
+\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pyfpe.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pyfpe.h
new file mode 100644 (file)
index 0000000..6671616
--- /dev/null
@@ -0,0 +1,176 @@
+#ifndef Py_PYFPE_H\r
+#define Py_PYFPE_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+/*\r
+     ---------------------------------------------------------------------\r
+    /                       Copyright (c) 1996.                           \\r
+   |          The Regents of the University of California.                 |\r
+   |                        All rights reserved.                           |\r
+   |                                                                       |\r
+   |   Permission to use, copy, modify, and distribute this software for   |\r
+   |   any purpose without fee is hereby granted, provided that this en-   |\r
+   |   tire notice is included in all copies of any software which is or   |\r
+   |   includes  a  copy  or  modification  of  this software and in all   |\r
+   |   copies of the supporting documentation for such software.           |\r
+   |                                                                       |\r
+   |   This  work was produced at the University of California, Lawrence   |\r
+   |   Livermore National Laboratory under  contract  no.  W-7405-ENG-48   |\r
+   |   between  the  U.S.  Department  of  Energy and The Regents of the   |\r
+   |   University of California for the operation of UC LLNL.              |\r
+   |                                                                       |\r
+   |                              DISCLAIMER                               |\r
+   |                                                                       |\r
+   |   This  software was prepared as an account of work sponsored by an   |\r
+   |   agency of the United States Government. Neither the United States   |\r
+   |   Government  nor the University of California nor any of their em-   |\r
+   |   ployees, makes any warranty, express or implied, or  assumes  any   |\r
+   |   liability  or  responsibility  for the accuracy, completeness, or   |\r
+   |   usefulness of any information,  apparatus,  product,  or  process   |\r
+   |   disclosed,   or  represents  that  its  use  would  not  infringe   |\r
+   |   privately-owned rights. Reference herein to any specific  commer-   |\r
+   |   cial  products,  process,  or  service  by trade name, trademark,   |\r
+   |   manufacturer, or otherwise, does not  necessarily  constitute  or   |\r
+   |   imply  its endorsement, recommendation, or favoring by the United   |\r
+   |   States Government or the University of California. The views  and   |\r
+   |   opinions  of authors expressed herein do not necessarily state or   |\r
+   |   reflect those of the United States Government or  the  University   |\r
+   |   of  California,  and shall not be used for advertising or product   |\r
+    \  endorsement purposes.                                              /\r
+     ---------------------------------------------------------------------\r
+*/\r
+\r
+/*\r
+ *       Define macros for handling SIGFPE.\r
+ *       Lee Busby, LLNL, November, 1996\r
+ *       busby1@llnl.gov\r
+ * \r
+ *********************************************\r
+ * Overview of the system for handling SIGFPE:\r
+ * \r
+ * This file (Include/pyfpe.h) defines a couple of "wrapper" macros for\r
+ * insertion into your Python C code of choice. Their proper use is\r
+ * discussed below. The file Python/pyfpe.c defines a pair of global\r
+ * variables PyFPE_jbuf and PyFPE_counter which are used by the signal\r
+ * handler for SIGFPE to decide if a particular exception was protected\r
+ * by the macros. The signal handler itself, and code for enabling the\r
+ * generation of SIGFPE in the first place, is in a (new) Python module\r
+ * named fpectl. This module is standard in every respect. It can be loaded\r
+ * either statically or dynamically as you choose, and like any other\r
+ * Python module, has no effect until you import it.\r
+ * \r
+ * In the general case, there are three steps toward handling SIGFPE in any\r
+ * Python code:\r
+ * \r
+ * 1) Add the *_PROTECT macros to your C code as required to protect\r
+ *    dangerous floating point sections.\r
+ * \r
+ * 2) Turn on the inclusion of the code by adding the ``--with-fpectl''\r
+ *    flag at the time you run configure.  If the fpectl or other modules\r
+ *    which use the *_PROTECT macros are to be dynamically loaded, be\r
+ *    sure they are compiled with WANT_SIGFPE_HANDLER defined.\r
+ * \r
+ * 3) When python is built and running, import fpectl, and execute\r
+ *    fpectl.turnon_sigfpe(). This sets up the signal handler and enables\r
+ *    generation of SIGFPE whenever an exception occurs. From this point\r
+ *    on, any properly trapped SIGFPE should result in the Python\r
+ *    FloatingPointError exception.\r
+ * \r
+ * Step 1 has been done already for the Python kernel code, and should be\r
+ * done soon for the NumPy array package.  Step 2 is usually done once at\r
+ * python install time. Python's behavior with respect to SIGFPE is not\r
+ * changed unless you also do step 3. Thus you can control this new\r
+ * facility at compile time, or run time, or both.\r
+ * \r
+ ******************************** \r
+ * Using the macros in your code:\r
+ * \r
+ * static PyObject *foobar(PyObject *self,PyObject *args)\r
+ * {\r
+ *     ....\r
+ *     PyFPE_START_PROTECT("Error in foobar", return 0)\r
+ *     result = dangerous_op(somearg1, somearg2, ...);\r
+ *     PyFPE_END_PROTECT(result)\r
+ *     ....\r
+ * }\r
+ * \r
+ * If a floating point error occurs in dangerous_op, foobar returns 0 (NULL),\r
+ * after setting the associated value of the FloatingPointError exception to\r
+ * "Error in foobar". ``Dangerous_op'' can be a single operation, or a block\r
+ * of code, function calls, or any combination, so long as no alternate\r
+ * return is possible before the PyFPE_END_PROTECT macro is reached.\r
+ * \r
+ * The macros can only be used in a function context where an error return\r
+ * can be recognized as signaling a Python exception. (Generally, most\r
+ * functions that return a PyObject * will qualify.)\r
+ * \r
+ * Guido's original design suggestion for PyFPE_START_PROTECT and\r
+ * PyFPE_END_PROTECT had them open and close a local block, with a locally\r
+ * defined jmp_buf and jmp_buf pointer. This would allow recursive nesting\r
+ * of the macros. The Ansi C standard makes it clear that such local\r
+ * variables need to be declared with the "volatile" type qualifier to keep\r
+ * setjmp from corrupting their values. Some current implementations seem\r
+ * to be more restrictive. For example, the HPUX man page for setjmp says\r
+ * \r
+ *   Upon the return from a setjmp() call caused by a longjmp(), the\r
+ *   values of any non-static local variables belonging to the routine\r
+ *   from which setjmp() was called are undefined. Code which depends on\r
+ *   such values is not guaranteed to be portable.\r
+ * \r
+ * I therefore decided on a more limited form of nesting, using a counter\r
+ * variable (PyFPE_counter) to keep track of any recursion.  If an exception\r
+ * occurs in an ``inner'' pair of macros, the return will apparently\r
+ * come from the outermost level.\r
+ * \r
+ */\r
+\r
+#ifdef WANT_SIGFPE_HANDLER\r
+#include <signal.h>\r
+#include <setjmp.h>\r
+#include <math.h>\r
+extern jmp_buf PyFPE_jbuf;\r
+extern int PyFPE_counter;\r
+extern double PyFPE_dummy(void *);\r
+\r
+#define PyFPE_START_PROTECT(err_string, leave_stmt) \\r
+if (!PyFPE_counter++ && setjmp(PyFPE_jbuf)) { \\r
+       PyErr_SetString(PyExc_FloatingPointError, err_string); \\r
+       PyFPE_counter = 0; \\r
+       leave_stmt; \\r
+}\r
+\r
+/*\r
+ * This (following) is a heck of a way to decrement a counter. However,\r
+ * unless the macro argument is provided, code optimizers will sometimes move\r
+ * this statement so that it gets executed *before* the unsafe expression\r
+ * which we're trying to protect.  That pretty well messes things up,\r
+ * of course.\r
+ * \r
+ * If the expression(s) you're trying to protect don't happen to return a\r
+ * value, you will need to manufacture a dummy result just to preserve the\r
+ * correct ordering of statements.  Note that the macro passes the address\r
+ * of its argument (so you need to give it something which is addressable).\r
+ * If your expression returns multiple results, pass the last such result\r
+ * to PyFPE_END_PROTECT.\r
+ * \r
+ * Note that PyFPE_dummy returns a double, which is cast to int.\r
+ * This seeming insanity is to tickle the Floating Point Unit (FPU).\r
+ * If an exception has occurred in a preceding floating point operation,\r
+ * some architectures (notably Intel 80x86) will not deliver the interrupt\r
+ * until the *next* floating point operation.  This is painful if you've\r
+ * already decremented PyFPE_counter.\r
+ */\r
+#define PyFPE_END_PROTECT(v) PyFPE_counter -= (int)PyFPE_dummy(&(v));\r
+\r
+#else\r
+\r
+#define PyFPE_START_PROTECT(err_string, leave_stmt)\r
+#define PyFPE_END_PROTECT(v)\r
+\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_PYFPE_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pygetopt.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pygetopt.h
new file mode 100644 (file)
index 0000000..024f173
--- /dev/null
@@ -0,0 +1,18 @@
+\r
+#ifndef Py_PYGETOPT_H\r
+#define Py_PYGETOPT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_DATA(int) _PyOS_opterr;\r
+PyAPI_DATA(int) _PyOS_optind;\r
+PyAPI_DATA(char *) _PyOS_optarg;\r
+\r
+PyAPI_FUNC(void) _PyOS_ResetGetOpt(void);\r
+PyAPI_FUNC(int) _PyOS_GetOpt(int argc, char **argv, char *optstring);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_PYGETOPT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pymacconfig.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pymacconfig.h
new file mode 100644 (file)
index 0000000..f647b47
--- /dev/null
@@ -0,0 +1,102 @@
+#ifndef PYMACCONFIG_H\r
+#define PYMACCONFIG_H\r
+     /*\r
+      * This file moves some of the autoconf magic to compile-time\r
+      * when building on MacOSX. This is needed for building 4-way\r
+      * universal binaries and for 64-bit universal binaries because\r
+      * the values redefined below aren't configure-time constant but\r
+      * only compile-time constant in these scenarios.\r
+      */\r
+\r
+#if defined(__APPLE__)\r
+\r
+# undef SIZEOF_LONG\r
+# undef SIZEOF_PTHREAD_T\r
+# undef SIZEOF_SIZE_T\r
+# undef SIZEOF_TIME_T\r
+# undef SIZEOF_VOID_P\r
+# undef SIZEOF__BOOL\r
+# undef SIZEOF_UINTPTR_T\r
+# undef SIZEOF_PTHREAD_T\r
+# undef WORDS_BIGENDIAN\r
+# undef DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754\r
+# undef DOUBLE_IS_BIG_ENDIAN_IEEE754\r
+# undef DOUBLE_IS_LITTLE_ENDIAN_IEEE754\r
+# undef HAVE_GCC_ASM_FOR_X87\r
+\r
+#    undef VA_LIST_IS_ARRAY\r
+#    if defined(__LP64__) && defined(__x86_64__)\r
+#        define VA_LIST_IS_ARRAY 1\r
+#    endif\r
+\r
+#    undef HAVE_LARGEFILE_SUPPORT\r
+#    ifndef __LP64__\r
+#         define HAVE_LARGEFILE_SUPPORT 1\r
+#    endif\r
+\r
+#    undef SIZEOF_LONG\r
+#    ifdef __LP64__\r
+#        define SIZEOF__BOOL            1\r
+#        define SIZEOF__BOOL            1\r
+#        define SIZEOF_LONG             8\r
+#        define SIZEOF_PTHREAD_T        8\r
+#        define SIZEOF_SIZE_T           8\r
+#        define SIZEOF_TIME_T           8\r
+#        define SIZEOF_VOID_P           8\r
+#        define SIZEOF_UINTPTR_T        8\r
+#        define SIZEOF_PTHREAD_T        8\r
+#    else\r
+#        ifdef __ppc__\r
+#           define SIZEOF__BOOL         4\r
+#        else\r
+#           define SIZEOF__BOOL         1\r
+#        endif\r
+#        define SIZEOF_LONG             4\r
+#        define SIZEOF_PTHREAD_T        4\r
+#        define SIZEOF_SIZE_T           4\r
+#        define SIZEOF_TIME_T           4\r
+#        define SIZEOF_VOID_P           4\r
+#        define SIZEOF_UINTPTR_T        4\r
+#        define SIZEOF_PTHREAD_T        4\r
+#    endif\r
+\r
+#    if defined(__LP64__)\r
+     /* MacOSX 10.4 (the first release to support 64-bit code\r
+      * at all) only supports 64-bit in the UNIX layer.\r
+      * Therefore surpress the toolbox-glue in 64-bit mode.\r
+      */\r
+\r
+    /* In 64-bit mode setpgrp always has no argments, in 32-bit\r
+     * mode that depends on the compilation environment\r
+     */\r
+#       undef SETPGRP_HAVE_ARG\r
+\r
+#    endif\r
+\r
+#ifdef __BIG_ENDIAN__\r
+#define WORDS_BIGENDIAN 1\r
+#define DOUBLE_IS_BIG_ENDIAN_IEEE754\r
+#else\r
+#define DOUBLE_IS_LITTLE_ENDIAN_IEEE754\r
+#endif /* __BIG_ENDIAN */\r
+\r
+#ifdef __i386__\r
+# define HAVE_GCC_ASM_FOR_X87\r
+#endif\r
+\r
+    /*\r
+     * The definition in pyconfig.h is only valid on the OS release\r
+     * where configure ran on and not necessarily for all systems where\r
+     * the executable can be used on.\r
+     *\r
+     * Specifically: OSX 10.4 has limited supported for '%zd', while\r
+     * 10.5 has full support for '%zd'. A binary built on 10.5 won't\r
+     * work properly on 10.4 unless we surpress the definition\r
+     * of PY_FORMAT_SIZE_T\r
+     */\r
+#undef  PY_FORMAT_SIZE_T\r
+\r
+\r
+#endif /* defined(_APPLE__) */\r
+\r
+#endif /* PYMACCONFIG_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pymactoolbox.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pymactoolbox.h
new file mode 100644 (file)
index 0000000..a0ac1c2
--- /dev/null
@@ -0,0 +1,217 @@
+/*\r
+** pymactoolbox.h - globals defined in mactoolboxglue.c\r
+*/\r
+#ifndef Py_PYMACTOOLBOX_H\r
+#define Py_PYMACTOOLBOX_H\r
+#ifdef __cplusplus\r
+       extern "C" {\r
+#endif\r
+\r
+#include <Carbon/Carbon.h>\r
+\r
+#ifndef __LP64__\r
+#include <QuickTime/QuickTime.h>\r
+#endif /* !__LP64__ */\r
+\r
+/*\r
+** Helper routines for error codes and such.\r
+*/\r
+char *PyMac_StrError(int);                     /* strerror with mac errors */\r
+extern PyObject *PyMac_OSErrException;         /* Exception for OSErr */\r
+PyObject *PyMac_GetOSErrException(void);       /* Initialize & return it */\r
+PyObject *PyErr_Mac(PyObject *, int);          /* Exception with a mac error */\r
+PyObject *PyMac_Error(OSErr);                  /* Uses PyMac_GetOSErrException */\r
+#ifndef __LP64__ \r
+extern OSErr PyMac_GetFullPathname(FSSpec *, char *, int); /* convert\r
+                                                             fsspec->path */\r
+#endif /* __LP64__ */\r
+\r
+/*\r
+** These conversion routines are defined in mactoolboxglue.c itself.\r
+*/\r
+int PyMac_GetOSType(PyObject *, OSType *);     /* argument parser for OSType */\r
+PyObject *PyMac_BuildOSType(OSType);           /* Convert OSType to PyObject */\r
+\r
+PyObject *PyMac_BuildNumVersion(NumVersion);/* Convert NumVersion to PyObject */\r
+\r
+int PyMac_GetStr255(PyObject *, Str255);       /* argument parser for Str255 */\r
+PyObject *PyMac_BuildStr255(Str255);           /* Convert Str255 to PyObject */\r
+PyObject *PyMac_BuildOptStr255(Str255);                /* Convert Str255 to PyObject,\r
+                                                  NULL to None */\r
+\r
+int PyMac_GetRect(PyObject *, Rect *);         /* argument parser for Rect */\r
+PyObject *PyMac_BuildRect(Rect *);             /* Convert Rect to PyObject */\r
+\r
+int PyMac_GetPoint(PyObject *, Point *);       /* argument parser for Point */\r
+PyObject *PyMac_BuildPoint(Point);             /* Convert Point to PyObject */\r
+\r
+int PyMac_GetEventRecord(PyObject *, EventRecord *); /* argument parser for\r
+                                                       EventRecord */\r
+PyObject *PyMac_BuildEventRecord(EventRecord *); /* Convert EventRecord to\r
+                                                   PyObject */\r
+\r
+int PyMac_GetFixed(PyObject *, Fixed *);       /* argument parser for Fixed */\r
+PyObject *PyMac_BuildFixed(Fixed);             /* Convert Fixed to PyObject */\r
+int PyMac_Getwide(PyObject *, wide *);         /* argument parser for wide */\r
+PyObject *PyMac_Buildwide(wide *);             /* Convert wide to PyObject */\r
+\r
+/*\r
+** The rest of the routines are implemented by extension modules. If they are\r
+** dynamically loaded mactoolboxglue will contain a stub implementation of the\r
+** routine, which imports the module, whereupon the module's init routine will\r
+** communicate the routine pointer back to the stub.\r
+** If USE_TOOLBOX_OBJECT_GLUE is not defined there is no glue code, and the\r
+** extension modules simply declare the routine. This is the case for static\r
+** builds (and could be the case for MacPython CFM builds, because CFM extension\r
+** modules can reference each other without problems).\r
+*/\r
+\r
+#ifdef USE_TOOLBOX_OBJECT_GLUE\r
+/*\r
+** These macros are used in the module init code. If we use toolbox object glue\r
+** it sets the function pointer to point to the real function.\r
+*/\r
+#define PyMac_INIT_TOOLBOX_OBJECT_NEW(object, rtn) { \\r
+       extern PyObject *(*PyMacGluePtr_##rtn)(object); \\r
+       PyMacGluePtr_##rtn = _##rtn; \\r
+}\r
+#define PyMac_INIT_TOOLBOX_OBJECT_CONVERT(object, rtn) { \\r
+       extern int (*PyMacGluePtr_##rtn)(PyObject *, object *); \\r
+       PyMacGluePtr_##rtn = _##rtn; \\r
+}\r
+#else\r
+/*\r
+** If we don't use toolbox object glue the init macros are empty. Moreover, we define\r
+** _xxx_New to be the same as xxx_New, and the code in mactoolboxglue isn't included.\r
+*/\r
+#define PyMac_INIT_TOOLBOX_OBJECT_NEW(object, rtn)\r
+#define PyMac_INIT_TOOLBOX_OBJECT_CONVERT(object, rtn)\r
+#endif /* USE_TOOLBOX_OBJECT_GLUE */\r
+\r
+/* macfs exports */\r
+#ifndef __LP64__\r
+int PyMac_GetFSSpec(PyObject *, FSSpec *);     /* argument parser for FSSpec */\r
+PyObject *PyMac_BuildFSSpec(FSSpec *);         /* Convert FSSpec to PyObject */\r
+#endif /* !__LP64__ */\r
+\r
+int PyMac_GetFSRef(PyObject *, FSRef *);       /* argument parser for FSRef */\r
+PyObject *PyMac_BuildFSRef(FSRef *);           /* Convert FSRef to PyObject */\r
+\r
+/* AE exports */\r
+extern PyObject *AEDesc_New(AppleEvent *); /* XXXX Why passed by address?? */\r
+extern PyObject *AEDesc_NewBorrowed(AppleEvent *);\r
+extern int AEDesc_Convert(PyObject *, AppleEvent *);\r
+\r
+/* Cm exports */\r
+extern PyObject *CmpObj_New(Component);\r
+extern int CmpObj_Convert(PyObject *, Component *);\r
+extern PyObject *CmpInstObj_New(ComponentInstance);\r
+extern int CmpInstObj_Convert(PyObject *, ComponentInstance *);\r
+\r
+/* Ctl exports */\r
+#ifndef __LP64__\r
+extern PyObject *CtlObj_New(ControlHandle);\r
+extern int CtlObj_Convert(PyObject *, ControlHandle *);\r
+#endif /* !__LP64__ */\r
+\r
+/* Dlg exports */\r
+#ifndef __LP64__\r
+extern PyObject *DlgObj_New(DialogPtr);\r
+extern int DlgObj_Convert(PyObject *, DialogPtr *);\r
+extern PyObject *DlgObj_WhichDialog(DialogPtr);\r
+#endif /* !__LP64__ */\r
+\r
+/* Drag exports */\r
+#ifndef __LP64__\r
+extern PyObject *DragObj_New(DragReference);\r
+extern int DragObj_Convert(PyObject *, DragReference *);\r
+#endif /* !__LP64__ */\r
+\r
+/* List exports */\r
+#ifndef __LP64__\r
+extern PyObject *ListObj_New(ListHandle);\r
+extern int ListObj_Convert(PyObject *, ListHandle *);\r
+#endif /* !__LP64__ */\r
+\r
+/* Menu exports */\r
+#ifndef __LP64__\r
+extern PyObject *MenuObj_New(MenuHandle);\r
+extern int MenuObj_Convert(PyObject *, MenuHandle *);\r
+#endif /* !__LP64__ */\r
+\r
+/* Qd exports */\r
+#ifndef __LP64__\r
+extern PyObject *GrafObj_New(GrafPtr);\r
+extern int GrafObj_Convert(PyObject *, GrafPtr *);\r
+extern PyObject *BMObj_New(BitMapPtr);\r
+extern int BMObj_Convert(PyObject *, BitMapPtr *);\r
+extern PyObject *QdRGB_New(RGBColor *);\r
+extern int QdRGB_Convert(PyObject *, RGBColor *);\r
+#endif /* !__LP64__ */\r
+\r
+/* Qdoffs exports */\r
+#ifndef __LP64__\r
+extern PyObject *GWorldObj_New(GWorldPtr);\r
+extern int GWorldObj_Convert(PyObject *, GWorldPtr *);\r
+#endif /* !__LP64__ */\r
+\r
+/* Qt exports */\r
+#ifndef __LP64__\r
+extern PyObject *TrackObj_New(Track);\r
+extern int TrackObj_Convert(PyObject *, Track *);\r
+extern PyObject *MovieObj_New(Movie);\r
+extern int MovieObj_Convert(PyObject *, Movie *);\r
+extern PyObject *MovieCtlObj_New(MovieController);\r
+extern int MovieCtlObj_Convert(PyObject *, MovieController *);\r
+extern PyObject *TimeBaseObj_New(TimeBase);\r
+extern int TimeBaseObj_Convert(PyObject *, TimeBase *);\r
+extern PyObject *UserDataObj_New(UserData);\r
+extern int UserDataObj_Convert(PyObject *, UserData *);\r
+extern PyObject *MediaObj_New(Media);\r
+extern int MediaObj_Convert(PyObject *, Media *);\r
+#endif /* !__LP64__ */\r
+\r
+/* Res exports */\r
+extern PyObject *ResObj_New(Handle);\r
+extern int ResObj_Convert(PyObject *, Handle *);\r
+extern PyObject *OptResObj_New(Handle);\r
+extern int OptResObj_Convert(PyObject *, Handle *);\r
+\r
+/* TE exports */\r
+#ifndef __LP64__\r
+extern PyObject *TEObj_New(TEHandle);\r
+extern int TEObj_Convert(PyObject *, TEHandle *);\r
+#endif /* !__LP64__ */\r
+\r
+/* Win exports */\r
+#ifndef __LP64__\r
+extern PyObject *WinObj_New(WindowPtr);\r
+extern int WinObj_Convert(PyObject *, WindowPtr *);\r
+extern PyObject *WinObj_WhichWindow(WindowPtr);\r
+#endif /* !__LP64__ */\r
+\r
+/* CF exports */\r
+extern PyObject *CFObj_New(CFTypeRef);\r
+extern int CFObj_Convert(PyObject *, CFTypeRef *);\r
+extern PyObject *CFTypeRefObj_New(CFTypeRef);\r
+extern int CFTypeRefObj_Convert(PyObject *, CFTypeRef *);\r
+extern PyObject *CFStringRefObj_New(CFStringRef);\r
+extern int CFStringRefObj_Convert(PyObject *, CFStringRef *);\r
+extern PyObject *CFMutableStringRefObj_New(CFMutableStringRef);\r
+extern int CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *);\r
+extern PyObject *CFArrayRefObj_New(CFArrayRef);\r
+extern int CFArrayRefObj_Convert(PyObject *, CFArrayRef *);\r
+extern PyObject *CFMutableArrayRefObj_New(CFMutableArrayRef);\r
+extern int CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *);\r
+extern PyObject *CFDictionaryRefObj_New(CFDictionaryRef);\r
+extern int CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *);\r
+extern PyObject *CFMutableDictionaryRefObj_New(CFMutableDictionaryRef);\r
+extern int CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *);\r
+extern PyObject *CFURLRefObj_New(CFURLRef);\r
+extern int CFURLRefObj_Convert(PyObject *, CFURLRef *);\r
+extern int OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *);\r
+\r
+#ifdef __cplusplus\r
+       }\r
+#endif\r
+#endif\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pymath.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pymath.h
new file mode 100644 (file)
index 0000000..f63ddb7
--- /dev/null
@@ -0,0 +1,192 @@
+#ifndef Py_PYMATH_H\r
+#define Py_PYMATH_H\r
+\r
+#include "pyconfig.h" /* include for defines */\r
+\r
+/**************************************************************************\r
+Symbols and macros to supply platform-independent interfaces to mathematical\r
+functions and constants\r
+**************************************************************************/\r
+\r
+/* Python provides implementations for copysign, round and hypot in\r
+ * Python/pymath.c just in case your math library doesn't provide the\r
+ * functions.\r
+ *\r
+ *Note: PC/pyconfig.h defines copysign as _copysign\r
+ */\r
+#ifndef HAVE_COPYSIGN\r
+extern double copysign(double, double);\r
+#endif\r
+\r
+#ifndef HAVE_ROUND\r
+extern double round(double);\r
+#endif\r
+\r
+#ifndef HAVE_HYPOT\r
+extern double hypot(double, double);\r
+#endif\r
+\r
+/* extra declarations */\r
+#ifndef _MSC_VER\r
+#ifndef __STDC__\r
+extern double fmod (double, double);\r
+extern double frexp (double, int *);\r
+extern double ldexp (double, int);\r
+extern double modf (double, double *);\r
+extern double pow(double, double);\r
+#endif /* __STDC__ */\r
+#endif /* _MSC_VER */\r
+\r
+#ifdef _OSF_SOURCE\r
+/* OSF1 5.1 doesn't make these available with XOPEN_SOURCE_EXTENDED defined */\r
+extern int finite(double);\r
+extern double copysign(double, double);\r
+#endif\r
+\r
+/* High precision defintion of pi and e (Euler)\r
+ * The values are taken from libc6's math.h.\r
+ */\r
+#ifndef Py_MATH_PIl\r
+#define Py_MATH_PIl 3.1415926535897932384626433832795029L\r
+#endif\r
+#ifndef Py_MATH_PI\r
+#define Py_MATH_PI 3.14159265358979323846\r
+#endif\r
+\r
+#ifndef Py_MATH_El\r
+#define Py_MATH_El 2.7182818284590452353602874713526625L\r
+#endif\r
+\r
+#ifndef Py_MATH_E\r
+#define Py_MATH_E 2.7182818284590452354\r
+#endif\r
+\r
+/* On x86, Py_FORCE_DOUBLE forces a floating-point number out of an x87 FPU\r
+   register and into a 64-bit memory location, rounding from extended\r
+   precision to double precision in the process.  On other platforms it does\r
+   nothing. */\r
+\r
+/* we take double rounding as evidence of x87 usage */\r
+#ifndef Py_FORCE_DOUBLE\r
+#  ifdef X87_DOUBLE_ROUNDING\r
+PyAPI_FUNC(double) _Py_force_double(double);\r
+#    define Py_FORCE_DOUBLE(X) (_Py_force_double(X))\r
+#  else\r
+#    define Py_FORCE_DOUBLE(X) (X)\r
+#  endif\r
+#endif\r
+\r
+#ifdef HAVE_GCC_ASM_FOR_X87\r
+PyAPI_FUNC(unsigned short) _Py_get_387controlword(void);\r
+PyAPI_FUNC(void) _Py_set_387controlword(unsigned short);\r
+#endif\r
+\r
+/* Py_IS_NAN(X)\r
+ * Return 1 if float or double arg is a NaN, else 0.\r
+ * Caution:\r
+ *     X is evaluated more than once.\r
+ *     This may not work on all platforms.  Each platform has *some*\r
+ *     way to spell this, though -- override in pyconfig.h if you have\r
+ *     a platform where it doesn't work.\r
+ * Note: PC/pyconfig.h defines Py_IS_NAN as _isnan\r
+ */\r
+#ifndef Py_IS_NAN\r
+#if defined HAVE_DECL_ISNAN && HAVE_DECL_ISNAN == 1\r
+#define Py_IS_NAN(X) isnan(X)\r
+#else\r
+#define Py_IS_NAN(X) ((X) != (X))\r
+#endif\r
+#endif\r
+\r
+/* Py_IS_INFINITY(X)\r
+ * Return 1 if float or double arg is an infinity, else 0.\r
+ * Caution:\r
+ *    X is evaluated more than once.\r
+ *    This implementation may set the underflow flag if |X| is very small;\r
+ *    it really can't be implemented correctly (& easily) before C99.\r
+ *    Override in pyconfig.h if you have a better spelling on your platform.\r
+ *  Py_FORCE_DOUBLE is used to avoid getting false negatives from a\r
+ *    non-infinite value v sitting in an 80-bit x87 register such that\r
+ *    v becomes infinite when spilled from the register to 64-bit memory.\r
+ * Note: PC/pyconfig.h defines Py_IS_INFINITY as _isinf\r
+ */\r
+#ifndef Py_IS_INFINITY\r
+#  if defined HAVE_DECL_ISINF && HAVE_DECL_ISINF == 1\r
+#    define Py_IS_INFINITY(X) isinf(X)\r
+#  else\r
+#    define Py_IS_INFINITY(X) ((X) &&                                   \\r
+                               (Py_FORCE_DOUBLE(X)*0.5 == Py_FORCE_DOUBLE(X)))\r
+#  endif\r
+#endif\r
+\r
+/* Py_IS_FINITE(X)\r
+ * Return 1 if float or double arg is neither infinite nor NAN, else 0.\r
+ * Some compilers (e.g. VisualStudio) have intrisics for this, so a special\r
+ * macro for this particular test is useful\r
+ * Note: PC/pyconfig.h defines Py_IS_FINITE as _finite\r
+ */\r
+#ifndef Py_IS_FINITE\r
+#if defined HAVE_DECL_ISFINITE && HAVE_DECL_ISFINITE == 1\r
+#define Py_IS_FINITE(X) isfinite(X)\r
+#elif defined HAVE_FINITE\r
+#define Py_IS_FINITE(X) finite(X)\r
+#else\r
+#define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))\r
+#endif\r
+#endif\r
+\r
+/* HUGE_VAL is supposed to expand to a positive double infinity.  Python\r
+ * uses Py_HUGE_VAL instead because some platforms are broken in this\r
+ * respect.  We used to embed code in pyport.h to try to worm around that,\r
+ * but different platforms are broken in conflicting ways.  If you're on\r
+ * a platform where HUGE_VAL is defined incorrectly, fiddle your Python\r
+ * config to #define Py_HUGE_VAL to something that works on your platform.\r
+ */\r
+#ifndef Py_HUGE_VAL\r
+#define Py_HUGE_VAL HUGE_VAL\r
+#endif\r
+\r
+/* Py_NAN\r
+ * A value that evaluates to a NaN. On IEEE 754 platforms INF*0 or\r
+ * INF/INF works. Define Py_NO_NAN in pyconfig.h if your platform\r
+ * doesn't support NaNs.\r
+ */\r
+#if !defined(Py_NAN) && !defined(Py_NO_NAN)\r
+#define Py_NAN (Py_HUGE_VAL * 0.)\r
+#endif\r
+\r
+/* Py_OVERFLOWED(X)\r
+ * Return 1 iff a libm function overflowed.  Set errno to 0 before calling\r
+ * a libm function, and invoke this macro after, passing the function\r
+ * result.\r
+ * Caution:\r
+ *    This isn't reliable.  C99 no longer requires libm to set errno under\r
+ *       any exceptional condition, but does require +- HUGE_VAL return\r
+ *       values on overflow.  A 754 box *probably* maps HUGE_VAL to a\r
+ *       double infinity, and we're cool if that's so, unless the input\r
+ *       was an infinity and an infinity is the expected result.  A C89\r
+ *       system sets errno to ERANGE, so we check for that too.  We're\r
+ *       out of luck if a C99 754 box doesn't map HUGE_VAL to +Inf, or\r
+ *       if the returned result is a NaN, or if a C89 box returns HUGE_VAL\r
+ *       in non-overflow cases.\r
+ *    X is evaluated more than once.\r
+ * Some platforms have better way to spell this, so expect some #ifdef'ery.\r
+ *\r
+ * OpenBSD uses 'isinf()' because a compiler bug on that platform causes\r
+ * the longer macro version to be mis-compiled. This isn't optimal, and\r
+ * should be removed once a newer compiler is available on that platform.\r
+ * The system that had the failure was running OpenBSD 3.2 on Intel, with\r
+ * gcc 2.95.3.\r
+ *\r
+ * According to Tim's checkin, the FreeBSD systems use isinf() to work\r
+ * around a FPE bug on that platform.\r
+ */\r
+#if defined(__FreeBSD__) || defined(__OpenBSD__)\r
+#define Py_OVERFLOWED(X) isinf(X)\r
+#else\r
+#define Py_OVERFLOWED(X) ((X) != 0.0 && (errno == ERANGE ||    \\r
+                                        (X) == Py_HUGE_VAL || \\r
+                                        (X) == -Py_HUGE_VAL))\r
+#endif\r
+\r
+#endif /* Py_PYMATH_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pymem.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pymem.h
new file mode 100644 (file)
index 0000000..27c72f1
--- /dev/null
@@ -0,0 +1,122 @@
+/* The PyMem_ family:  low-level memory allocation interfaces.\r
+   See objimpl.h for the PyObject_ memory family.\r
+*/\r
+\r
+#ifndef Py_PYMEM_H\r
+#define Py_PYMEM_H\r
+\r
+#include "pyport.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* BEWARE:\r
+\r
+   Each interface exports both functions and macros.  Extension modules should\r
+   use the functions, to ensure binary compatibility across Python versions.\r
+   Because the Python implementation is free to change internal details, and\r
+   the macros may (or may not) expose details for speed, if you do use the\r
+   macros you must recompile your extensions with each Python release.\r
+\r
+   Never mix calls to PyMem_ with calls to the platform malloc/realloc/\r
+   calloc/free.  For example, on Windows different DLLs may end up using\r
+   different heaps, and if you use PyMem_Malloc you'll get the memory from the\r
+   heap used by the Python DLL; it could be a disaster if you free()'ed that\r
+   directly in your own extension.  Using PyMem_Free instead ensures Python\r
+   can return the memory to the proper heap.  As another example, in\r
+   PYMALLOC_DEBUG mode, Python wraps all calls to all PyMem_ and PyObject_\r
+   memory functions in special debugging wrappers that add additional\r
+   debugging info to dynamic memory blocks.  The system routines have no idea\r
+   what to do with that stuff, and the Python wrappers have no idea what to do\r
+   with raw blocks obtained directly by the system routines then.\r
+\r
+   The GIL must be held when using these APIs.\r
+*/\r
+\r
+/*\r
+ * Raw memory interface\r
+ * ====================\r
+ */\r
+\r
+/* Functions\r
+\r
+   Functions supplying platform-independent semantics for malloc/realloc/\r
+   free.  These functions make sure that allocating 0 bytes returns a distinct\r
+   non-NULL pointer (whenever possible -- if we're flat out of memory, NULL\r
+   may be returned), even if the platform malloc and realloc don't.\r
+   Returned pointers must be checked for NULL explicitly.  No action is\r
+   performed on failure (no exception is set, no warning is printed, etc).\r
+*/\r
+\r
+PyAPI_FUNC(void *) PyMem_Malloc(size_t);\r
+PyAPI_FUNC(void *) PyMem_Realloc(void *, size_t);\r
+PyAPI_FUNC(void) PyMem_Free(void *);\r
+\r
+/* Starting from Python 1.6, the wrappers Py_{Malloc,Realloc,Free} are\r
+   no longer supported. They used to call PyErr_NoMemory() on failure. */\r
+\r
+/* Macros. */\r
+#ifdef PYMALLOC_DEBUG\r
+/* Redirect all memory operations to Python's debugging allocator. */\r
+#define PyMem_MALLOC           _PyMem_DebugMalloc\r
+#define PyMem_REALLOC          _PyMem_DebugRealloc\r
+#define PyMem_FREE             _PyMem_DebugFree\r
+\r
+#else  /* ! PYMALLOC_DEBUG */\r
+\r
+/* PyMem_MALLOC(0) means malloc(1). Some systems would return NULL\r
+   for malloc(0), which would be treated as an error. Some platforms\r
+   would return a pointer with no memory behind it, which would break\r
+   pymalloc. To solve these problems, allocate an extra byte. */\r
+/* Returns NULL to indicate error if a negative size or size larger than\r
+   Py_ssize_t can represent is supplied.  Helps prevents security holes. */\r
+#define PyMem_MALLOC(n)                ((size_t)(n) > (size_t)PY_SSIZE_T_MAX ? NULL \\r
+                               : malloc((n) ? (n) : 1))\r
+#define PyMem_REALLOC(p, n)    ((size_t)(n) > (size_t)PY_SSIZE_T_MAX  ? NULL \\r
+                               : realloc((p), (n) ? (n) : 1))\r
+#define PyMem_FREE             free\r
+\r
+#endif /* PYMALLOC_DEBUG */\r
+\r
+/*\r
+ * Type-oriented memory interface\r
+ * ==============================\r
+ *\r
+ * Allocate memory for n objects of the given type.  Returns a new pointer\r
+ * or NULL if the request was too large or memory allocation failed.  Use\r
+ * these macros rather than doing the multiplication yourself so that proper\r
+ * overflow checking is always done.\r
+ */\r
+\r
+#define PyMem_New(type, n) \\r
+  ( ((size_t)(n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL :     \\r
+       ( (type *) PyMem_Malloc((n) * sizeof(type)) ) )\r
+#define PyMem_NEW(type, n) \\r
+  ( ((size_t)(n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL :     \\r
+       ( (type *) PyMem_MALLOC((n) * sizeof(type)) ) )\r
+\r
+/*\r
+ * The value of (p) is always clobbered by this macro regardless of success.\r
+ * The caller MUST check if (p) is NULL afterwards and deal with the memory\r
+ * error if so.  This means the original value of (p) MUST be saved for the\r
+ * caller's memory error handler to not lose track of it.\r
+ */\r
+#define PyMem_Resize(p, type, n) \\r
+  ( (p) = ((size_t)(n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL :       \\r
+       (type *) PyMem_Realloc((p), (n) * sizeof(type)) )\r
+#define PyMem_RESIZE(p, type, n) \\r
+  ( (p) = ((size_t)(n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL :       \\r
+       (type *) PyMem_REALLOC((p), (n) * sizeof(type)) )\r
+\r
+/* PyMem{Del,DEL} are left over from ancient days, and shouldn't be used\r
+ * anymore.  They're just confusing aliases for PyMem_{Free,FREE} now.\r
+ */\r
+#define PyMem_Del              PyMem_Free\r
+#define PyMem_DEL              PyMem_FREE\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* !Py_PYMEM_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pyport.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pyport.h
new file mode 100644 (file)
index 0000000..ff43d6e
--- /dev/null
@@ -0,0 +1,941 @@
+#ifndef Py_PYPORT_H\r
+#define Py_PYPORT_H\r
+\r
+#include "pyconfig.h" /* include for defines */\r
+\r
+/* Some versions of HP-UX & Solaris need inttypes.h for int32_t,\r
+   INT32_MAX, etc. */\r
+#ifdef HAVE_INTTYPES_H\r
+#include <inttypes.h>\r
+#endif\r
+\r
+#ifdef HAVE_STDINT_H\r
+#include <stdint.h>\r
+#endif\r
+\r
+/**************************************************************************\r
+Symbols and macros to supply platform-independent interfaces to basic\r
+C language & library operations whose spellings vary across platforms.\r
+\r
+Please try to make documentation here as clear as possible:  by definition,\r
+the stuff here is trying to illuminate C's darkest corners.\r
+\r
+Config #defines referenced here:\r
+\r
+SIGNED_RIGHT_SHIFT_ZERO_FILLS\r
+Meaning:  To be defined iff i>>j does not extend the sign bit when i is a\r
+          signed integral type and i < 0.\r
+Used in:  Py_ARITHMETIC_RIGHT_SHIFT\r
+\r
+Py_DEBUG\r
+Meaning:  Extra checks compiled in for debug mode.\r
+Used in:  Py_SAFE_DOWNCAST\r
+\r
+HAVE_UINTPTR_T\r
+Meaning:  The C9X type uintptr_t is supported by the compiler\r
+Used in:  Py_uintptr_t\r
+\r
+HAVE_LONG_LONG\r
+Meaning:  The compiler supports the C type "long long"\r
+Used in:  PY_LONG_LONG\r
+\r
+**************************************************************************/\r
+\r
+\r
+/* For backward compatibility only. Obsolete, do not use. */\r
+#ifdef HAVE_PROTOTYPES\r
+#define Py_PROTO(x) x\r
+#else\r
+#define Py_PROTO(x) ()\r
+#endif\r
+#ifndef Py_FPROTO\r
+#define Py_FPROTO(x) Py_PROTO(x)\r
+#endif\r
+\r
+/* typedefs for some C9X-defined synonyms for integral types.\r
+ *\r
+ * The names in Python are exactly the same as the C9X names, except with a\r
+ * Py_ prefix.  Until C9X is universally implemented, this is the only way\r
+ * to ensure that Python gets reliable names that don't conflict with names\r
+ * in non-Python code that are playing their own tricks to define the C9X\r
+ * names.\r
+ *\r
+ * NOTE: don't go nuts here!  Python has no use for *most* of the C9X\r
+ * integral synonyms.  Only define the ones we actually need.\r
+ */\r
+\r
+#ifdef HAVE_LONG_LONG\r
+#ifndef PY_LONG_LONG\r
+#define PY_LONG_LONG long long\r
+#if defined(LLONG_MAX)\r
+/* If LLONG_MAX is defined in limits.h, use that. */\r
+#define PY_LLONG_MIN LLONG_MIN\r
+#define PY_LLONG_MAX LLONG_MAX\r
+#define PY_ULLONG_MAX ULLONG_MAX\r
+#elif defined(__LONG_LONG_MAX__)\r
+/* Otherwise, if GCC has a builtin define, use that. */\r
+#define PY_LLONG_MAX __LONG_LONG_MAX__\r
+#define PY_LLONG_MIN (-PY_LLONG_MAX-1)\r
+#define PY_ULLONG_MAX (__LONG_LONG_MAX__*2ULL + 1ULL)\r
+#else\r
+/* Otherwise, rely on two's complement. */\r
+#define PY_ULLONG_MAX (~0ULL)\r
+#define PY_LLONG_MAX  ((long long)(PY_ULLONG_MAX>>1))\r
+#define PY_LLONG_MIN (-PY_LLONG_MAX-1)\r
+#endif /* LLONG_MAX */\r
+#endif\r
+#endif /* HAVE_LONG_LONG */\r
+\r
+/* a build with 30-bit digits for Python long integers needs an exact-width\r
+ * 32-bit unsigned integer type to store those digits.  (We could just use\r
+ * type 'unsigned long', but that would be wasteful on a system where longs\r
+ * are 64-bits.)  On Unix systems, the autoconf macro AC_TYPE_UINT32_T defines\r
+ * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t.\r
+ * However, it doesn't set HAVE_UINT32_T, so we do that here.\r
+ */\r
+#ifdef uint32_t\r
+#define HAVE_UINT32_T 1\r
+#endif\r
+\r
+#ifdef HAVE_UINT32_T\r
+#ifndef PY_UINT32_T\r
+#define PY_UINT32_T uint32_t\r
+#endif\r
+#endif\r
+\r
+/* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the\r
+ * long integer implementation, when 30-bit digits are enabled.\r
+ */\r
+#ifdef uint64_t\r
+#define HAVE_UINT64_T 1\r
+#endif\r
+\r
+#ifdef HAVE_UINT64_T\r
+#ifndef PY_UINT64_T\r
+#define PY_UINT64_T uint64_t\r
+#endif\r
+#endif\r
+\r
+/* Signed variants of the above */\r
+#ifdef int32_t\r
+#define HAVE_INT32_T 1\r
+#endif\r
+\r
+#ifdef HAVE_INT32_T\r
+#ifndef PY_INT32_T\r
+#define PY_INT32_T int32_t\r
+#endif\r
+#endif\r
+\r
+#ifdef int64_t\r
+#define HAVE_INT64_T 1\r
+#endif\r
+\r
+#ifdef HAVE_INT64_T\r
+#ifndef PY_INT64_T\r
+#define PY_INT64_T int64_t\r
+#endif\r
+#endif\r
+\r
+/* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all\r
+   the necessary integer types are available, and we're on a 64-bit platform\r
+   (as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */\r
+\r
+#ifndef PYLONG_BITS_IN_DIGIT\r
+#if (defined HAVE_UINT64_T && defined HAVE_INT64_T && \\r
+     defined HAVE_UINT32_T && defined HAVE_INT32_T && SIZEOF_VOID_P >= 8)\r
+#define PYLONG_BITS_IN_DIGIT 30\r
+#else\r
+#define PYLONG_BITS_IN_DIGIT 15\r
+#endif\r
+#endif\r
+\r
+/* uintptr_t is the C9X name for an unsigned integral type such that a\r
+ * legitimate void* can be cast to uintptr_t and then back to void* again\r
+ * without loss of information.  Similarly for intptr_t, wrt a signed\r
+ * integral type.\r
+ */\r
+#ifdef HAVE_UINTPTR_T\r
+typedef uintptr_t       Py_uintptr_t;\r
+typedef intptr_t        Py_intptr_t;\r
+\r
+#elif SIZEOF_VOID_P <= SIZEOF_INT\r
+typedef unsigned int    Py_uintptr_t;\r
+typedef int             Py_intptr_t;\r
+\r
+#elif SIZEOF_VOID_P <= SIZEOF_LONG\r
+typedef unsigned long   Py_uintptr_t;\r
+typedef long            Py_intptr_t;\r
+\r
+#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)\r
+typedef unsigned PY_LONG_LONG   Py_uintptr_t;\r
+typedef PY_LONG_LONG            Py_intptr_t;\r
+\r
+#else\r
+#   error "Python needs a typedef for Py_uintptr_t in pyport.h."\r
+#endif /* HAVE_UINTPTR_T */\r
+\r
+/* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==\r
+ * sizeof(size_t).  C99 doesn't define such a thing directly (size_t is an\r
+ * unsigned integral type).  See PEP 353 for details.\r
+ */\r
+#ifdef HAVE_SSIZE_T\r
+typedef ssize_t         Py_ssize_t;\r
+#elif SIZEOF_VOID_P == SIZEOF_SIZE_T\r
+typedef Py_intptr_t     Py_ssize_t;\r
+#else\r
+#   error "Python needs a typedef for Py_ssize_t in pyport.h."\r
+#endif\r
+\r
+/* Largest possible value of size_t.\r
+   SIZE_MAX is part of C99, so it might be defined on some\r
+   platforms. If it is not defined, (size_t)-1 is a portable\r
+   definition for C89, due to the way signed->unsigned\r
+   conversion is defined. */\r
+#ifdef SIZE_MAX\r
+#define PY_SIZE_MAX SIZE_MAX\r
+#else\r
+#define PY_SIZE_MAX ((size_t)-1)\r
+#endif\r
+\r
+/* Largest positive value of type Py_ssize_t. */\r
+#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))\r
+/* Smallest negative value of type Py_ssize_t. */\r
+#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)\r
+\r
+#if SIZEOF_PID_T > SIZEOF_LONG\r
+#   error "Python doesn't support sizeof(pid_t) > sizeof(long)"\r
+#endif\r
+\r
+/* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf\r
+ * format to convert an argument with the width of a size_t or Py_ssize_t.\r
+ * C99 introduced "z" for this purpose, but not all platforms support that;\r
+ * e.g., MS compilers use "I" instead.\r
+ *\r
+ * These "high level" Python format functions interpret "z" correctly on\r
+ * all platforms (Python interprets the format string itself, and does whatever\r
+ * the platform C requires to convert a size_t/Py_ssize_t argument):\r
+ *\r
+ *     PyString_FromFormat\r
+ *     PyErr_Format\r
+ *     PyString_FromFormatV\r
+ *\r
+ * Lower-level uses require that you interpolate the correct format modifier\r
+ * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for\r
+ * example,\r
+ *\r
+ *     Py_ssize_t index;\r
+ *     fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);\r
+ *\r
+ * That will expand to %ld, or %Id, or to something else correct for a\r
+ * Py_ssize_t on the platform.\r
+ */\r
+#ifndef PY_FORMAT_SIZE_T\r
+#   if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)\r
+#       define PY_FORMAT_SIZE_T ""\r
+#   elif SIZEOF_SIZE_T == SIZEOF_LONG\r
+#       define PY_FORMAT_SIZE_T "l"\r
+#   elif defined(MS_WINDOWS)\r
+#       define PY_FORMAT_SIZE_T "I"\r
+#   else\r
+#       error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"\r
+#   endif\r
+#endif\r
+\r
+/* PY_FORMAT_LONG_LONG is analogous to PY_FORMAT_SIZE_T above, but for\r
+ * the long long type instead of the size_t type.  It's only available\r
+ * when HAVE_LONG_LONG is defined. The "high level" Python format\r
+ * functions listed above will interpret "lld" or "llu" correctly on\r
+ * all platforms.\r
+ */\r
+#ifdef HAVE_LONG_LONG\r
+#   ifndef PY_FORMAT_LONG_LONG\r
+#       if defined(MS_WIN64) || defined(MS_WINDOWS)\r
+#           define PY_FORMAT_LONG_LONG "I64"\r
+#       else\r
+#           error "This platform's pyconfig.h needs to define PY_FORMAT_LONG_LONG"\r
+#       endif\r
+#   endif\r
+#endif\r
+\r
+/* Py_LOCAL can be used instead of static to get the fastest possible calling\r
+ * convention for functions that are local to a given module.\r
+ *\r
+ * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,\r
+ * for platforms that support that.\r
+ *\r
+ * If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more\r
+ * "aggressive" inlining/optimizaion is enabled for the entire module.  This\r
+ * may lead to code bloat, and may slow things down for those reasons.  It may\r
+ * also lead to errors, if the code relies on pointer aliasing.  Use with\r
+ * care.\r
+ *\r
+ * NOTE: You can only use this for functions that are entirely local to a\r
+ * module; functions that are exported via method tables, callbacks, etc,\r
+ * should keep using static.\r
+ */\r
+\r
+#undef USE_INLINE /* XXX - set via configure? */\r
+\r
+#if defined(_MSC_VER)\r
+#if defined(PY_LOCAL_AGGRESSIVE)\r
+/* enable more aggressive optimization for visual studio */\r
+#pragma optimize("agtw", on)\r
+#endif\r
+/* ignore warnings if the compiler decides not to inline a function */\r
+#pragma warning(disable: 4710)\r
+/* fastest possible local call under MSVC */\r
+#define Py_LOCAL(type) static type __fastcall\r
+#define Py_LOCAL_INLINE(type) static __inline type __fastcall\r
+#elif defined(USE_INLINE)\r
+#define Py_LOCAL(type) static type\r
+#define Py_LOCAL_INLINE(type) static inline type\r
+#else\r
+#define Py_LOCAL(type) static type\r
+#define Py_LOCAL_INLINE(type) static type\r
+#endif\r
+\r
+/* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks\r
+ * are often very short.  While most platforms have highly optimized code for\r
+ * large transfers, the setup costs for memcpy are often quite high.  MEMCPY\r
+ * solves this by doing short copies "in line".\r
+ */\r
+\r
+#if defined(_MSC_VER)\r
+#define Py_MEMCPY(target, source, length) do {                          \\r
+        size_t i_, n_ = (length);                                       \\r
+        char *t_ = (void*) (target);                                    \\r
+        const char *s_ = (void*) (source);                              \\r
+        if (n_ >= 16)                                                   \\r
+            memcpy(t_, s_, n_);                                         \\r
+        else                                                            \\r
+            for (i_ = 0; i_ < n_; i_++)                                 \\r
+                t_[i_] = s_[i_];                                        \\r
+    } while (0)\r
+#else\r
+#define Py_MEMCPY memcpy\r
+#endif\r
+\r
+#include <stdlib.h>\r
+\r
+#ifdef HAVE_IEEEFP_H\r
+#include <ieeefp.h>  /* needed for 'finite' declaration on some platforms */\r
+#endif\r
+\r
+#include <math.h> /* Moved here from the math section, before extern "C" */\r
+\r
+/********************************************\r
+ * WRAPPER FOR <time.h> and/or <sys/time.h> *\r
+ ********************************************/\r
+\r
+#ifdef TIME_WITH_SYS_TIME\r
+#include <sys/time.h>\r
+#include <time.h>\r
+#else /* !TIME_WITH_SYS_TIME */\r
+#ifdef HAVE_SYS_TIME_H\r
+#include <sys/time.h>\r
+#else /* !HAVE_SYS_TIME_H */\r
+#include <time.h>\r
+#endif /* !HAVE_SYS_TIME_H */\r
+#endif /* !TIME_WITH_SYS_TIME */\r
+\r
+\r
+/******************************\r
+ * WRAPPER FOR <sys/select.h> *\r
+ ******************************/\r
+\r
+/* NB caller must include <sys/types.h> */\r
+\r
+#ifdef HAVE_SYS_SELECT_H\r
+\r
+#include <sys/select.h>\r
+\r
+#endif /* !HAVE_SYS_SELECT_H */\r
+\r
+/*******************************\r
+ * stat() and fstat() fiddling *\r
+ *******************************/\r
+\r
+/* We expect that stat and fstat exist on most systems.\r
+ *  It's confirmed on Unix, Mac and Windows.\r
+ *  If you don't have them, add\r
+ *      #define DONT_HAVE_STAT\r
+ * and/or\r
+ *      #define DONT_HAVE_FSTAT\r
+ * to your pyconfig.h. Python code beyond this should check HAVE_STAT and\r
+ * HAVE_FSTAT instead.\r
+ * Also\r
+ *      #define HAVE_SYS_STAT_H\r
+ * if <sys/stat.h> exists on your platform, and\r
+ *      #define HAVE_STAT_H\r
+ * if <stat.h> does.\r
+ */\r
+#ifndef DONT_HAVE_STAT\r
+#define HAVE_STAT\r
+#endif\r
+\r
+#ifndef DONT_HAVE_FSTAT\r
+#define HAVE_FSTAT\r
+#endif\r
+\r
+#ifdef RISCOS\r
+#include <sys/types.h>\r
+#include "unixstuff.h"\r
+#endif\r
+\r
+#ifdef HAVE_SYS_STAT_H\r
+#if defined(PYOS_OS2) && defined(PYCC_GCC)\r
+#include <sys/types.h>\r
+#endif\r
+#include <sys/stat.h>\r
+#elif defined(HAVE_STAT_H)\r
+#include <stat.h>\r
+#endif\r
+\r
+#if defined(PYCC_VACPP)\r
+/* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */\r
+#define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG)\r
+#endif\r
+\r
+#ifndef S_ISREG\r
+#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)\r
+#endif\r
+\r
+#ifndef S_ISDIR\r
+#define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)\r
+#endif\r
+\r
+\r
+#ifdef __cplusplus\r
+/* Move this down here since some C++ #include's don't like to be included\r
+   inside an extern "C" */\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Py_ARITHMETIC_RIGHT_SHIFT\r
+ * C doesn't define whether a right-shift of a signed integer sign-extends\r
+ * or zero-fills.  Here a macro to force sign extension:\r
+ * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)\r
+ *    Return I >> J, forcing sign extension.  Arithmetically, return the\r
+ *    floor of I/2**J.\r
+ * Requirements:\r
+ *    I should have signed integer type.  In the terminology of C99, this can\r
+ *    be either one of the five standard signed integer types (signed char,\r
+ *    short, int, long, long long) or an extended signed integer type.\r
+ *    J is an integer >= 0 and strictly less than the number of bits in the\r
+ *    type of I (because C doesn't define what happens for J outside that\r
+ *    range either).\r
+ *    TYPE used to specify the type of I, but is now ignored.  It's been left\r
+ *    in for backwards compatibility with versions <= 2.6 or 3.0.\r
+ * Caution:\r
+ *    I may be evaluated more than once.\r
+ */\r
+#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS\r
+#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \\r
+    ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))\r
+#else\r
+#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))\r
+#endif\r
+\r
+/* Py_FORCE_EXPANSION(X)\r
+ * "Simply" returns its argument.  However, macro expansions within the\r
+ * argument are evaluated.  This unfortunate trickery is needed to get\r
+ * token-pasting to work as desired in some cases.\r
+ */\r
+#define Py_FORCE_EXPANSION(X) X\r
+\r
+/* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)\r
+ * Cast VALUE to type NARROW from type WIDE.  In Py_DEBUG mode, this\r
+ * assert-fails if any information is lost.\r
+ * Caution:\r
+ *    VALUE may be evaluated more than once.\r
+ */\r
+#ifdef Py_DEBUG\r
+#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \\r
+    (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))\r
+#else\r
+#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)\r
+#endif\r
+\r
+/* Py_SET_ERRNO_ON_MATH_ERROR(x)\r
+ * If a libm function did not set errno, but it looks like the result\r
+ * overflowed or not-a-number, set errno to ERANGE or EDOM.  Set errno\r
+ * to 0 before calling a libm function, and invoke this macro after,\r
+ * passing the function result.\r
+ * Caution:\r
+ *    This isn't reliable.  See Py_OVERFLOWED comments.\r
+ *    X is evaluated more than once.\r
+ */\r
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))\r
+#define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;\r
+#else\r
+#define _Py_SET_EDOM_FOR_NAN(X) ;\r
+#endif\r
+#define Py_SET_ERRNO_ON_MATH_ERROR(X) \\r
+    do { \\r
+        if (errno == 0) { \\r
+            if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \\r
+                errno = ERANGE; \\r
+            else _Py_SET_EDOM_FOR_NAN(X) \\r
+        } \\r
+    } while(0)\r
+\r
+/* Py_SET_ERANGE_ON_OVERFLOW(x)\r
+ * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.\r
+ */\r
+#define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)\r
+\r
+/* Py_ADJUST_ERANGE1(x)\r
+ * Py_ADJUST_ERANGE2(x, y)\r
+ * Set errno to 0 before calling a libm function, and invoke one of these\r
+ * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful\r
+ * for functions returning complex results).  This makes two kinds of\r
+ * adjustments to errno:  (A) If it looks like the platform libm set\r
+ * errno=ERANGE due to underflow, clear errno. (B) If it looks like the\r
+ * platform libm overflowed but didn't set errno, force errno to ERANGE.  In\r
+ * effect, we're trying to force a useful implementation of C89 errno\r
+ * behavior.\r
+ * Caution:\r
+ *    This isn't reliable.  See Py_OVERFLOWED comments.\r
+ *    X and Y may be evaluated more than once.\r
+ */\r
+#define Py_ADJUST_ERANGE1(X)                                            \\r
+    do {                                                                \\r
+        if (errno == 0) {                                               \\r
+            if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL)              \\r
+                errno = ERANGE;                                         \\r
+        }                                                               \\r
+        else if (errno == ERANGE && (X) == 0.0)                         \\r
+            errno = 0;                                                  \\r
+    } while(0)\r
+\r
+#define Py_ADJUST_ERANGE2(X, Y)                                         \\r
+    do {                                                                \\r
+        if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL ||                \\r
+            (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) {                \\r
+                        if (errno == 0)                                 \\r
+                                errno = ERANGE;                         \\r
+        }                                                               \\r
+        else if (errno == ERANGE)                                       \\r
+            errno = 0;                                                  \\r
+    } while(0)\r
+\r
+/*  The functions _Py_dg_strtod and _Py_dg_dtoa in Python/dtoa.c (which are\r
+ *  required to support the short float repr introduced in Python 3.1) require\r
+ *  that the floating-point unit that's being used for arithmetic operations\r
+ *  on C doubles is set to use 53-bit precision.  It also requires that the\r
+ *  FPU rounding mode is round-half-to-even, but that's less often an issue.\r
+ *\r
+ *  If your FPU isn't already set to 53-bit precision/round-half-to-even, and\r
+ *  you want to make use of _Py_dg_strtod and _Py_dg_dtoa, then you should\r
+ *\r
+ *     #define HAVE_PY_SET_53BIT_PRECISION 1\r
+ *\r
+ *  and also give appropriate definitions for the following three macros:\r
+ *\r
+ *    _PY_SET_53BIT_PRECISION_START : store original FPU settings, and\r
+ *        set FPU to 53-bit precision/round-half-to-even\r
+ *    _PY_SET_53BIT_PRECISION_END : restore original FPU settings\r
+ *    _PY_SET_53BIT_PRECISION_HEADER : any variable declarations needed to\r
+ *        use the two macros above.\r
+ *\r
+ * The macros are designed to be used within a single C function: see\r
+ * Python/pystrtod.c for an example of their use.\r
+ */\r
+\r
+/* get and set x87 control word for gcc/x86 */\r
+#ifdef HAVE_GCC_ASM_FOR_X87\r
+#define HAVE_PY_SET_53BIT_PRECISION 1\r
+/* _Py_get/set_387controlword functions are defined in Python/pymath.c */\r
+#define _Py_SET_53BIT_PRECISION_HEADER                          \\r
+    unsigned short old_387controlword, new_387controlword\r
+#define _Py_SET_53BIT_PRECISION_START                                   \\r
+    do {                                                                \\r
+        old_387controlword = _Py_get_387controlword();                  \\r
+        new_387controlword = (old_387controlword & ~0x0f00) | 0x0200; \\r
+        if (new_387controlword != old_387controlword)                   \\r
+            _Py_set_387controlword(new_387controlword);                 \\r
+    } while (0)\r
+#define _Py_SET_53BIT_PRECISION_END                             \\r
+    if (new_387controlword != old_387controlword)               \\r
+        _Py_set_387controlword(old_387controlword)\r
+#endif\r
+\r
+/* get and set x87 control word for VisualStudio/x86 */\r
+#if defined(_MSC_VER) && !defined(_WIN64) /* x87 not supported in 64-bit */\r
+#define HAVE_PY_SET_53BIT_PRECISION 1\r
+#define _Py_SET_53BIT_PRECISION_HEADER \\r
+    unsigned int old_387controlword, new_387controlword, out_387controlword\r
+/* We use the __control87_2 function to set only the x87 control word.\r
+   The SSE control word is unaffected. */\r
+#define _Py_SET_53BIT_PRECISION_START                                   \\r
+    do {                                                                \\r
+        __control87_2(0, 0, &old_387controlword, NULL);                 \\r
+        new_387controlword =                                            \\r
+          (old_387controlword & ~(_MCW_PC | _MCW_RC)) | (_PC_53 | _RC_NEAR); \\r
+        if (new_387controlword != old_387controlword)                   \\r
+            __control87_2(new_387controlword, _MCW_PC | _MCW_RC,        \\r
+                          &out_387controlword, NULL);                   \\r
+    } while (0)\r
+#define _Py_SET_53BIT_PRECISION_END                                     \\r
+    do {                                                                \\r
+        if (new_387controlword != old_387controlword)                   \\r
+            __control87_2(old_387controlword, _MCW_PC | _MCW_RC,        \\r
+                          &out_387controlword, NULL);                   \\r
+    } while (0)\r
+#endif\r
+\r
+/* default definitions are empty */\r
+#ifndef HAVE_PY_SET_53BIT_PRECISION\r
+#define _Py_SET_53BIT_PRECISION_HEADER\r
+#define _Py_SET_53BIT_PRECISION_START\r
+#define _Py_SET_53BIT_PRECISION_END\r
+#endif\r
+\r
+/* If we can't guarantee 53-bit precision, don't use the code\r
+   in Python/dtoa.c, but fall back to standard code.  This\r
+   means that repr of a float will be long (17 sig digits).\r
+\r
+   Realistically, there are two things that could go wrong:\r
+\r
+   (1) doubles aren't IEEE 754 doubles, or\r
+   (2) we're on x86 with the rounding precision set to 64-bits\r
+       (extended precision), and we don't know how to change\r
+       the rounding precision.\r
+ */\r
+\r
+#if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \\r
+    !defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \\r
+    !defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754)\r
+#define PY_NO_SHORT_FLOAT_REPR\r
+#endif\r
+\r
+/* double rounding is symptomatic of use of extended precision on x86.  If\r
+   we're seeing double rounding, and we don't have any mechanism available for\r
+   changing the FPU rounding precision, then don't use Python/dtoa.c. */\r
+#if defined(X87_DOUBLE_ROUNDING) && !defined(HAVE_PY_SET_53BIT_PRECISION)\r
+#define PY_NO_SHORT_FLOAT_REPR\r
+#endif\r
+\r
+/* Py_DEPRECATED(version)\r
+ * Declare a variable, type, or function deprecated.\r
+ * Usage:\r
+ *    extern int old_var Py_DEPRECATED(2.3);\r
+ *    typedef int T1 Py_DEPRECATED(2.4);\r
+ *    extern int x() Py_DEPRECATED(2.5);\r
+ */\r
+#if defined(__GNUC__) && ((__GNUC__ >= 4) || \\r
+              (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))\r
+#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))\r
+#else\r
+#define Py_DEPRECATED(VERSION_UNUSED)\r
+#endif\r
+\r
+/**************************************************************************\r
+Prototypes that are missing from the standard include files on some systems\r
+(and possibly only some versions of such systems.)\r
+\r
+Please be conservative with adding new ones, document them and enclose them\r
+in platform-specific #ifdefs.\r
+**************************************************************************/\r
+\r
+#ifdef SOLARIS\r
+/* Unchecked */\r
+extern int gethostname(char *, int);\r
+#endif\r
+\r
+#ifdef __BEOS__\r
+/* Unchecked */\r
+/* It's in the libs, but not the headers... - [cjh] */\r
+int shutdown( int, int );\r
+#endif\r
+\r
+#ifdef HAVE__GETPTY\r
+#include <sys/types.h>          /* we need to import mode_t */\r
+extern char * _getpty(int *, int, mode_t, int);\r
+#endif\r
+\r
+/* On QNX 6, struct termio must be declared by including sys/termio.h\r
+   if TCGETA, TCSETA, TCSETAW, or TCSETAF are used.  sys/termio.h must\r
+   be included before termios.h or it will generate an error. */\r
+#if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux)\r
+#include <sys/termio.h>\r
+#endif\r
+\r
+#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)\r
+#if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) && !defined(HAVE_UTIL_H)\r
+/* BSDI does not supply a prototype for the 'openpty' and 'forkpty'\r
+   functions, even though they are included in libutil. */\r
+#include <termios.h>\r
+extern int openpty(int *, int *, char *, struct termios *, struct winsize *);\r
+extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);\r
+#endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */\r
+#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */\r
+\r
+\r
+/* These are pulled from various places. It isn't obvious on what platforms\r
+   they are necessary, nor what the exact prototype should look like (which\r
+   is likely to vary between platforms!) If you find you need one of these\r
+   declarations, please move them to a platform-specific block and include\r
+   proper prototypes. */\r
+#if 0\r
+\r
+/* From Modules/resource.c */\r
+extern int getrusage();\r
+extern int getpagesize();\r
+\r
+/* From Python/sysmodule.c and Modules/posixmodule.c */\r
+extern int fclose(FILE *);\r
+\r
+/* From Modules/posixmodule.c */\r
+extern int fdatasync(int);\r
+#endif /* 0 */\r
+\r
+\r
+/* On 4.4BSD-descendants, ctype functions serves the whole range of\r
+ * wchar_t character set rather than single byte code points only.\r
+ * This characteristic can break some operations of string object\r
+ * including str.upper() and str.split() on UTF-8 locales.  This\r
+ * workaround was provided by Tim Robbins of FreeBSD project.\r
+ */\r
+\r
+#ifdef __FreeBSD__\r
+#include <osreldate.h>\r
+#if __FreeBSD_version > 500039\r
+# define _PY_PORT_CTYPE_UTF8_ISSUE\r
+#endif\r
+#endif\r
+\r
+\r
+#if defined(__APPLE__)\r
+# define _PY_PORT_CTYPE_UTF8_ISSUE\r
+#endif\r
+\r
+#ifdef _PY_PORT_CTYPE_UTF8_ISSUE\r
+#include <ctype.h>\r
+#include <wctype.h>\r
+#undef isalnum\r
+#define isalnum(c) iswalnum(btowc(c))\r
+#undef isalpha\r
+#define isalpha(c) iswalpha(btowc(c))\r
+#undef islower\r
+#define islower(c) iswlower(btowc(c))\r
+#undef isspace\r
+#define isspace(c) iswspace(btowc(c))\r
+#undef isupper\r
+#define isupper(c) iswupper(btowc(c))\r
+#undef tolower\r
+#define tolower(c) towlower(btowc(c))\r
+#undef toupper\r
+#define toupper(c) towupper(btowc(c))\r
+#endif\r
+\r
+\r
+/* Declarations for symbol visibility.\r
+\r
+  PyAPI_FUNC(type): Declares a public Python API function and return type\r
+  PyAPI_DATA(type): Declares public Python data and its type\r
+  PyMODINIT_FUNC:   A Python module init function.  If these functions are\r
+                    inside the Python core, they are private to the core.\r
+                    If in an extension module, it may be declared with\r
+                    external linkage depending on the platform.\r
+\r
+  As a number of platforms support/require "__declspec(dllimport/dllexport)",\r
+  we support a HAVE_DECLSPEC_DLL macro to save duplication.\r
+*/\r
+\r
+/*\r
+  All windows ports, except cygwin, are handled in PC/pyconfig.h.\r
+\r
+  BeOS and cygwin are the only other autoconf platform requiring special\r
+  linkage handling and both of these use __declspec().\r
+*/\r
+#if defined(__CYGWIN__) || defined(__BEOS__)\r
+#       define HAVE_DECLSPEC_DLL\r
+#endif\r
+\r
+/* only get special linkage if built as shared or platform is Cygwin */\r
+#if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)\r
+#       if defined(HAVE_DECLSPEC_DLL)\r
+#               ifdef Py_BUILD_CORE\r
+#                       define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE\r
+#                       define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE\r
+        /* module init functions inside the core need no external linkage */\r
+        /* except for Cygwin to handle embedding (FIXME: BeOS too?) */\r
+#                       if defined(__CYGWIN__)\r
+#                               define PyMODINIT_FUNC __declspec(dllexport) void\r
+#                       else /* __CYGWIN__ */\r
+#                               define PyMODINIT_FUNC void\r
+#                       endif /* __CYGWIN__ */\r
+#               else /* Py_BUILD_CORE */\r
+        /* Building an extension module, or an embedded situation */\r
+        /* public Python functions and data are imported */\r
+        /* Under Cygwin, auto-import functions to prevent compilation */\r
+        /* failures similar to those described at the bottom of 4.1: */\r
+        /* http://docs.python.org/extending/windows.html#a-cookbook-approach */\r
+#                       if !defined(__CYGWIN__)\r
+#                               define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE\r
+#                       endif /* !__CYGWIN__ */\r
+#                       define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE\r
+        /* module init functions outside the core must be exported */\r
+#                       if defined(__cplusplus)\r
+#                               define PyMODINIT_FUNC extern "C" __declspec(dllexport) void\r
+#                       else /* __cplusplus */\r
+#                               define PyMODINIT_FUNC __declspec(dllexport) void\r
+#                       endif /* __cplusplus */\r
+#               endif /* Py_BUILD_CORE */\r
+#       endif /* HAVE_DECLSPEC */\r
+#endif /* Py_ENABLE_SHARED */\r
+\r
+/* If no external linkage macros defined by now, create defaults */\r
+#ifndef PyAPI_FUNC\r
+#       define PyAPI_FUNC(RTYPE) RTYPE\r
+#endif\r
+#ifndef PyAPI_DATA\r
+#       define PyAPI_DATA(RTYPE) extern RTYPE\r
+#endif\r
+#ifndef PyMODINIT_FUNC\r
+#       if defined(__cplusplus)\r
+#               define PyMODINIT_FUNC extern "C" void\r
+#       else /* __cplusplus */\r
+#               define PyMODINIT_FUNC void\r
+#       endif /* __cplusplus */\r
+#endif\r
+\r
+/* Deprecated DL_IMPORT and DL_EXPORT macros */\r
+#if defined(Py_ENABLE_SHARED) && defined (HAVE_DECLSPEC_DLL)\r
+#       if defined(Py_BUILD_CORE)\r
+#               define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE\r
+#               define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE\r
+#       else\r
+#               define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE\r
+#               define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE\r
+#       endif\r
+#endif\r
+#ifndef DL_EXPORT\r
+#       define DL_EXPORT(RTYPE) RTYPE\r
+#endif\r
+#ifndef DL_IMPORT\r
+#       define DL_IMPORT(RTYPE) RTYPE\r
+#endif\r
+/* End of deprecated DL_* macros */\r
+\r
+/* If the fd manipulation macros aren't defined,\r
+   here is a set that should do the job */\r
+\r
+#if 0 /* disabled and probably obsolete */\r
+\r
+#ifndef FD_SETSIZE\r
+#define FD_SETSIZE      256\r
+#endif\r
+\r
+#ifndef FD_SET\r
+\r
+typedef long fd_mask;\r
+\r
+#define NFDBITS (sizeof(fd_mask) * NBBY)        /* bits per mask */\r
+#ifndef howmany\r
+#define howmany(x, y)   (((x)+((y)-1))/(y))\r
+#endif /* howmany */\r
+\r
+typedef struct fd_set {\r
+    fd_mask     fds_bits[howmany(FD_SETSIZE, NFDBITS)];\r
+} fd_set;\r
+\r
+#define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))\r
+#define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))\r
+#define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))\r
+#define FD_ZERO(p)      memset((char *)(p), '\0', sizeof(*(p)))\r
+\r
+#endif /* FD_SET */\r
+\r
+#endif /* fd manipulation macros */\r
+\r
+\r
+/* limits.h constants that may be missing */\r
+\r
+#ifndef INT_MAX\r
+#define INT_MAX 2147483647\r
+#endif\r
+\r
+#ifndef LONG_MAX\r
+#if SIZEOF_LONG == 4\r
+#define LONG_MAX 0X7FFFFFFFL\r
+#elif SIZEOF_LONG == 8\r
+#define LONG_MAX 0X7FFFFFFFFFFFFFFFL\r
+#else\r
+#error "could not set LONG_MAX in pyport.h"\r
+#endif\r
+#endif\r
+\r
+#ifndef LONG_MIN\r
+#define LONG_MIN (-LONG_MAX-1)\r
+#endif\r
+\r
+#ifndef LONG_BIT\r
+#define LONG_BIT (8 * SIZEOF_LONG)\r
+#endif\r
+\r
+#if LONG_BIT != 8 * SIZEOF_LONG\r
+/* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent\r
+ * 32-bit platforms using gcc.  We try to catch that here at compile-time\r
+ * rather than waiting for integer multiplication to trigger bogus\r
+ * overflows.\r
+ */\r
+#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+/*\r
+ * Hide GCC attributes from compilers that don't support them.\r
+ */\r
+#if (!defined(__GNUC__) || __GNUC__ < 2 || \\r
+     (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) && \\r
+    !defined(RISCOS)\r
+#define Py_GCC_ATTRIBUTE(x)\r
+#else\r
+#define Py_GCC_ATTRIBUTE(x) __attribute__(x)\r
+#endif\r
+\r
+/*\r
+ * Add PyArg_ParseTuple format where available.\r
+ */\r
+#ifdef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE\r
+#define Py_FORMAT_PARSETUPLE(func,p1,p2) __attribute__((format(func,p1,p2)))\r
+#else\r
+#define Py_FORMAT_PARSETUPLE(func,p1,p2)\r
+#endif\r
+\r
+/*\r
+ * Specify alignment on compilers that support it.\r
+ */\r
+#if defined(__GNUC__) && __GNUC__ >= 3\r
+#define Py_ALIGNED(x) __attribute__((aligned(x)))\r
+#else\r
+#define Py_ALIGNED(x)\r
+#endif\r
+\r
+/* Eliminate end-of-loop code not reached warnings from SunPro C\r
+ * when using do{...}while(0) macros\r
+ */\r
+#ifdef __SUNPRO_C\r
+#pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)\r
+#endif\r
+\r
+/*\r
+ * Older Microsoft compilers don't support the C99 long long literal suffixes,\r
+ * so these will be defined in PC/pyconfig.h for those compilers.\r
+ */\r
+#ifndef Py_LL\r
+#define Py_LL(x) x##LL\r
+#endif\r
+\r
+#ifndef Py_ULL\r
+#define Py_ULL(x) Py_LL(x##U)\r
+#endif\r
+\r
+#endif /* Py_PYPORT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pystate.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pystate.h
new file mode 100644 (file)
index 0000000..62ada41
--- /dev/null
@@ -0,0 +1,200 @@
+\r
+/* Thread and interpreter state structures and their interfaces */\r
+\r
+\r
+#ifndef Py_PYSTATE_H\r
+#define Py_PYSTATE_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* State shared between threads */\r
+\r
+struct _ts; /* Forward */\r
+struct _is; /* Forward */\r
+\r
+typedef struct _is {\r
+\r
+    struct _is *next;\r
+    struct _ts *tstate_head;\r
+\r
+    PyObject *modules;\r
+    PyObject *sysdict;\r
+    PyObject *builtins;\r
+    PyObject *modules_reloading;\r
+\r
+    PyObject *codec_search_path;\r
+    PyObject *codec_search_cache;\r
+    PyObject *codec_error_registry;\r
+\r
+#ifdef HAVE_DLOPEN\r
+    int dlopenflags;\r
+#endif\r
+#ifdef WITH_TSC\r
+    int tscdump;\r
+#endif\r
+\r
+} PyInterpreterState;\r
+\r
+\r
+/* State unique per thread */\r
+\r
+struct _frame; /* Avoid including frameobject.h */\r
+\r
+/* Py_tracefunc return -1 when raising an exception, or 0 for success. */\r
+typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);\r
+\r
+/* The following values are used for 'what' for tracefunc functions: */\r
+#define PyTrace_CALL 0\r
+#define PyTrace_EXCEPTION 1\r
+#define PyTrace_LINE 2\r
+#define PyTrace_RETURN 3\r
+#define PyTrace_C_CALL 4\r
+#define PyTrace_C_EXCEPTION 5\r
+#define PyTrace_C_RETURN 6\r
+\r
+typedef struct _ts {\r
+    /* See Python/ceval.c for comments explaining most fields */\r
+\r
+    struct _ts *next;\r
+    PyInterpreterState *interp;\r
+\r
+    struct _frame *frame;\r
+    int recursion_depth;\r
+    /* 'tracing' keeps track of the execution depth when tracing/profiling.\r
+       This is to prevent the actual trace/profile code from being recorded in\r
+       the trace/profile. */\r
+    int tracing;\r
+    int use_tracing;\r
+\r
+    Py_tracefunc c_profilefunc;\r
+    Py_tracefunc c_tracefunc;\r
+    PyObject *c_profileobj;\r
+    PyObject *c_traceobj;\r
+\r
+    PyObject *curexc_type;\r
+    PyObject *curexc_value;\r
+    PyObject *curexc_traceback;\r
+\r
+    PyObject *exc_type;\r
+    PyObject *exc_value;\r
+    PyObject *exc_traceback;\r
+\r
+    PyObject *dict;  /* Stores per-thread state */\r
+\r
+    /* tick_counter is incremented whenever the check_interval ticker\r
+     * reaches zero. The purpose is to give a useful measure of the number\r
+     * of interpreted bytecode instructions in a given thread.  This\r
+     * extremely lightweight statistic collector may be of interest to\r
+     * profilers (like psyco.jit()), although nothing in the core uses it.\r
+     */\r
+    int tick_counter;\r
+\r
+    int gilstate_counter;\r
+\r
+    PyObject *async_exc; /* Asynchronous exception to raise */\r
+    long thread_id; /* Thread id where this tstate was created */\r
+\r
+    int trash_delete_nesting;\r
+    PyObject *trash_delete_later;\r
+\r
+    /* XXX signal handlers should also be here */\r
+\r
+} PyThreadState;\r
+\r
+\r
+PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);\r
+PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);\r
+PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);\r
+\r
+PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);\r
+PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);\r
+PyAPI_FUNC(void) _PyThreadState_Init(PyThreadState *);\r
+PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);\r
+PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);\r
+#ifdef WITH_THREAD\r
+PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);\r
+#endif\r
+\r
+PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);\r
+PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);\r
+PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);\r
+PyAPI_FUNC(int) PyThreadState_SetAsyncExc(long, PyObject *);\r
+\r
+\r
+/* Variable and macro for in-line access to current thread state */\r
+\r
+PyAPI_DATA(PyThreadState *) _PyThreadState_Current;\r
+\r
+#ifdef Py_DEBUG\r
+#define PyThreadState_GET() PyThreadState_Get()\r
+#else\r
+#define PyThreadState_GET() (_PyThreadState_Current)\r
+#endif\r
+\r
+typedef\r
+    enum {PyGILState_LOCKED, PyGILState_UNLOCKED}\r
+        PyGILState_STATE;\r
+\r
+/* Ensure that the current thread is ready to call the Python\r
+   C API, regardless of the current state of Python, or of its\r
+   thread lock.  This may be called as many times as desired\r
+   by a thread so long as each call is matched with a call to\r
+   PyGILState_Release().  In general, other thread-state APIs may\r
+   be used between _Ensure() and _Release() calls, so long as the\r
+   thread-state is restored to its previous state before the Release().\r
+   For example, normal use of the Py_BEGIN_ALLOW_THREADS/\r
+   Py_END_ALLOW_THREADS macros are acceptable.\r
+\r
+   The return value is an opaque "handle" to the thread state when\r
+   PyGILState_Ensure() was called, and must be passed to\r
+   PyGILState_Release() to ensure Python is left in the same state. Even\r
+   though recursive calls are allowed, these handles can *not* be shared -\r
+   each unique call to PyGILState_Ensure must save the handle for its\r
+   call to PyGILState_Release.\r
+\r
+   When the function returns, the current thread will hold the GIL.\r
+\r
+   Failure is a fatal error.\r
+*/\r
+PyAPI_FUNC(PyGILState_STATE) PyGILState_Ensure(void);\r
+\r
+/* Release any resources previously acquired.  After this call, Python's\r
+   state will be the same as it was prior to the corresponding\r
+   PyGILState_Ensure() call (but generally this state will be unknown to\r
+   the caller, hence the use of the GILState API.)\r
+\r
+   Every call to PyGILState_Ensure must be matched by a call to\r
+   PyGILState_Release on the same thread.\r
+*/\r
+PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE);\r
+\r
+/* Helper/diagnostic function - get the current thread state for\r
+   this thread.  May return NULL if no GILState API has been used\r
+   on the current thread.  Note that the main thread always has such a\r
+   thread-state, even if no auto-thread-state call has been made\r
+   on the main thread.\r
+*/\r
+PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void);\r
+\r
+/* The implementation of sys._current_frames()  Returns a dict mapping\r
+   thread id to that thread's current frame.\r
+*/\r
+PyAPI_FUNC(PyObject *) _PyThread_CurrentFrames(void);\r
+\r
+/* Routines for advanced debuggers, requested by David Beazley.\r
+   Don't use unless you know what you are doing! */\r
+PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void);\r
+PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);\r
+PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);\r
+PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);\r
+\r
+typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);\r
+\r
+/* hook for PyEval_GetFrame(), requested for Psyco */\r
+PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame;\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_PYSTATE_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pystrcmp.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pystrcmp.h
new file mode 100644 (file)
index 0000000..542399d
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef Py_STRCMP_H\r
+#define Py_STRCMP_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_FUNC(int) PyOS_mystrnicmp(const char *, const char *, Py_ssize_t);\r
+PyAPI_FUNC(int) PyOS_mystricmp(const char *, const char *);\r
+\r
+#if defined(MS_WINDOWS) || defined(PYOS_OS2)\r
+#define PyOS_strnicmp strnicmp\r
+#define PyOS_stricmp stricmp\r
+#else\r
+#define PyOS_strnicmp PyOS_mystrnicmp\r
+#define PyOS_stricmp PyOS_mystricmp\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* !Py_STRCMP_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pystrtod.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pystrtod.h
new file mode 100644 (file)
index 0000000..f2ecc60
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef Py_STRTOD_H\r
+#define Py_STRTOD_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+PyAPI_FUNC(double) PyOS_ascii_strtod(const char *str, char **ptr);\r
+PyAPI_FUNC(double) PyOS_ascii_atof(const char *str);\r
+\r
+/* Deprecated in 2.7 and 3.1. Will disappear in 2.8 (if it exists) and 3.2 */\r
+PyAPI_FUNC(char *) PyOS_ascii_formatd(char *buffer, size_t buf_len,\r
+                                      const char *format, double d);\r
+PyAPI_FUNC(double) PyOS_string_to_double(const char *str,\r
+                                         char **endptr,\r
+                                         PyObject *overflow_exception);\r
+\r
+/* The caller is responsible for calling PyMem_Free to free the buffer\r
+   that's is returned. */\r
+PyAPI_FUNC(char *) PyOS_double_to_string(double val,\r
+                                         char format_code,\r
+                                         int precision,\r
+                                         int flags,\r
+                                         int *type);\r
+\r
+PyAPI_FUNC(double) _Py_parse_inf_or_nan(const char *p, char **endptr);\r
+\r
+\r
+/* PyOS_double_to_string's "flags" parameter can be set to 0 or more of: */\r
+#define Py_DTSF_SIGN      0x01 /* always add the sign */\r
+#define Py_DTSF_ADD_DOT_0 0x02 /* if the result is an integer add ".0" */\r
+#define Py_DTSF_ALT       0x04 /* "alternate" formatting. it's format_code\r
+                                  specific */\r
+\r
+/* PyOS_double_to_string's "type", if non-NULL, will be set to one of: */\r
+#define Py_DTST_FINITE 0\r
+#define Py_DTST_INFINITE 1\r
+#define Py_DTST_NAN 2\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* !Py_STRTOD_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pythonrun.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pythonrun.h
new file mode 100644 (file)
index 0000000..58e1831
--- /dev/null
@@ -0,0 +1,182 @@
+\r
+/* Interfaces to parse and execute pieces of python code */\r
+\r
+#ifndef Py_PYTHONRUN_H\r
+#define Py_PYTHONRUN_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \\r
+                   CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \\r
+                   CO_FUTURE_UNICODE_LITERALS)\r
+#define PyCF_MASK_OBSOLETE (CO_NESTED)\r
+#define PyCF_SOURCE_IS_UTF8  0x0100\r
+#define PyCF_DONT_IMPLY_DEDENT 0x0200\r
+#define PyCF_ONLY_AST 0x0400\r
+\r
+typedef struct {\r
+    int cf_flags;  /* bitmask of CO_xxx flags relevant to future */\r
+} PyCompilerFlags;\r
+\r
+PyAPI_FUNC(void) Py_SetProgramName(char *);\r
+PyAPI_FUNC(char *) Py_GetProgramName(void);\r
+\r
+PyAPI_FUNC(void) Py_SetPythonHome(char *);\r
+PyAPI_FUNC(char *) Py_GetPythonHome(void);\r
+\r
+PyAPI_FUNC(void) Py_Initialize(void);\r
+PyAPI_FUNC(void) Py_InitializeEx(int);\r
+PyAPI_FUNC(void) Py_Finalize(void);\r
+PyAPI_FUNC(int) Py_IsInitialized(void);\r
+PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);\r
+PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);\r
+\r
+PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);\r
+PyAPI_FUNC(int) PyRun_AnyFileExFlags(FILE *, const char *, int, PyCompilerFlags *);\r
+PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);\r
+PyAPI_FUNC(int) PyRun_SimpleFileExFlags(FILE *, const char *, int, PyCompilerFlags *);\r
+PyAPI_FUNC(int) PyRun_InteractiveOneFlags(FILE *, const char *, PyCompilerFlags *);\r
+PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(FILE *, const char *, PyCompilerFlags *);\r
+\r
+PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(const char *, const char *,\r
+                                                 int, PyCompilerFlags *flags,\r
+                                                 PyArena *);\r
+PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(FILE *, const char *, int,\r
+                                               char *, char *,\r
+                                               PyCompilerFlags *, int *,\r
+                                               PyArena *);\r
+#define PyParser_SimpleParseString(S, B) \\r
+    PyParser_SimpleParseStringFlags(S, B, 0)\r
+#define PyParser_SimpleParseFile(FP, S, B) \\r
+    PyParser_SimpleParseFileFlags(FP, S, B, 0)\r
+PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,\r
+                                                          int);\r
+PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,\r
+                                                        int, int);\r
+\r
+PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,\r
+                                         PyObject *, PyCompilerFlags *);\r
+\r
+PyAPI_FUNC(PyObject *) PyRun_FileExFlags(FILE *, const char *, int,\r
+                                         PyObject *, PyObject *, int,\r
+                                         PyCompilerFlags *);\r
+\r
+#define Py_CompileString(str, p, s) Py_CompileStringFlags(str, p, s, NULL)\r
+PyAPI_FUNC(PyObject *) Py_CompileStringFlags(const char *, const char *, int,\r
+                                             PyCompilerFlags *);\r
+PyAPI_FUNC(struct symtable *) Py_SymtableString(const char *, const char *, int);\r
+\r
+PyAPI_FUNC(void) PyErr_Print(void);\r
+PyAPI_FUNC(void) PyErr_PrintEx(int);\r
+PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);\r
+\r
+PyAPI_FUNC(int) Py_AtExit(void (*func)(void));\r
+\r
+PyAPI_FUNC(void) Py_Exit(int);\r
+\r
+PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);\r
+\r
+/* Bootstrap */\r
+PyAPI_FUNC(int) Py_Main(int argc, char **argv);\r
+\r
+/* Use macros for a bunch of old variants */\r
+#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)\r
+#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)\r
+#define PyRun_AnyFileEx(fp, name, closeit) \\r
+    PyRun_AnyFileExFlags(fp, name, closeit, NULL)\r
+#define PyRun_AnyFileFlags(fp, name, flags) \\r
+    PyRun_AnyFileExFlags(fp, name, 0, flags)\r
+#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)\r
+#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)\r
+#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)\r
+#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)\r
+#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)\r
+#define PyRun_File(fp, p, s, g, l) \\r
+    PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)\r
+#define PyRun_FileEx(fp, p, s, g, l, c) \\r
+    PyRun_FileExFlags(fp, p, s, g, l, c, NULL)\r
+#define PyRun_FileFlags(fp, p, s, g, l, flags) \\r
+    PyRun_FileExFlags(fp, p, s, g, l, 0, flags)\r
+\r
+/* In getpath.c */\r
+PyAPI_FUNC(char *) Py_GetProgramFullPath(void);\r
+PyAPI_FUNC(char *) Py_GetPrefix(void);\r
+PyAPI_FUNC(char *) Py_GetExecPrefix(void);\r
+PyAPI_FUNC(char *) Py_GetPath(void);\r
+\r
+/* In their own files */\r
+PyAPI_FUNC(const char *) Py_GetVersion(void);\r
+PyAPI_FUNC(const char *) Py_GetPlatform(void);\r
+PyAPI_FUNC(const char *) Py_GetCopyright(void);\r
+PyAPI_FUNC(const char *) Py_GetCompiler(void);\r
+PyAPI_FUNC(const char *) Py_GetBuildInfo(void);\r
+PyAPI_FUNC(const char *) _Py_svnversion(void);\r
+PyAPI_FUNC(const char *) Py_SubversionRevision(void);\r
+PyAPI_FUNC(const char *) Py_SubversionShortBranch(void);\r
+PyAPI_FUNC(const char *) _Py_hgidentifier(void);\r
+PyAPI_FUNC(const char *) _Py_hgversion(void);\r
+\r
+/* Internal -- various one-time initializations */\r
+PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);\r
+PyAPI_FUNC(PyObject *) _PySys_Init(void);\r
+PyAPI_FUNC(void) _PyImport_Init(void);\r
+PyAPI_FUNC(void) _PyExc_Init(void);\r
+PyAPI_FUNC(void) _PyImportHooks_Init(void);\r
+PyAPI_FUNC(int) _PyFrame_Init(void);\r
+PyAPI_FUNC(int) _PyInt_Init(void);\r
+PyAPI_FUNC(int) _PyLong_Init(void);\r
+PyAPI_FUNC(void) _PyFloat_Init(void);\r
+PyAPI_FUNC(int) PyByteArray_Init(void);\r
+PyAPI_FUNC(void) _PyRandom_Init(void);\r
+\r
+/* Various internal finalizers */\r
+PyAPI_FUNC(void) _PyExc_Fini(void);\r
+PyAPI_FUNC(void) _PyImport_Fini(void);\r
+PyAPI_FUNC(void) PyMethod_Fini(void);\r
+PyAPI_FUNC(void) PyFrame_Fini(void);\r
+PyAPI_FUNC(void) PyCFunction_Fini(void);\r
+PyAPI_FUNC(void) PyDict_Fini(void);\r
+PyAPI_FUNC(void) PyTuple_Fini(void);\r
+PyAPI_FUNC(void) PyList_Fini(void);\r
+PyAPI_FUNC(void) PySet_Fini(void);\r
+PyAPI_FUNC(void) PyString_Fini(void);\r
+PyAPI_FUNC(void) PyInt_Fini(void);\r
+PyAPI_FUNC(void) PyFloat_Fini(void);\r
+PyAPI_FUNC(void) PyOS_FiniInterrupts(void);\r
+PyAPI_FUNC(void) PyByteArray_Fini(void);\r
+PyAPI_FUNC(void) _PyRandom_Fini(void);\r
+\r
+/* Stuff with no proper home (yet) */\r
+PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, char *);\r
+PyAPI_DATA(int) (*PyOS_InputHook)(void);\r
+PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *);\r
+PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;\r
+\r
+/* Stack size, in "pointers" (so we get extra safety margins\r
+   on 64-bit platforms).  On a 32-bit platform, this translates\r
+   to a 8k margin. */\r
+#define PYOS_STACK_MARGIN 2048\r
+\r
+#if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1300\r
+/* Enable stack checking under Microsoft C */\r
+#define USE_STACKCHECK\r
+#endif\r
+\r
+#ifdef USE_STACKCHECK\r
+/* Check that we aren't overflowing our stack */\r
+PyAPI_FUNC(int) PyOS_CheckStack(void);\r
+#endif\r
+\r
+/* Signals */\r
+typedef void (*PyOS_sighandler_t)(int);\r
+PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int);\r
+PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t);\r
+\r
+/* Random */\r
+PyAPI_FUNC(int) _PyOS_URandom (void *buffer, Py_ssize_t size);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_PYTHONRUN_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/pythread.h b/AppPkg/Applications/Python/Python-2.7.10/Include/pythread.h
new file mode 100644 (file)
index 0000000..d3c587b
--- /dev/null
@@ -0,0 +1,41 @@
+\r
+#ifndef Py_PYTHREAD_H\r
+#define Py_PYTHREAD_H\r
+\r
+typedef void *PyThread_type_lock;\r
+typedef void *PyThread_type_sema;\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_FUNC(void) PyThread_init_thread(void);\r
+PyAPI_FUNC(long) PyThread_start_new_thread(void (*)(void *), void *);\r
+PyAPI_FUNC(void) PyThread_exit_thread(void);\r
+PyAPI_FUNC(long) PyThread_get_thread_ident(void);\r
+\r
+PyAPI_FUNC(PyThread_type_lock) PyThread_allocate_lock(void);\r
+PyAPI_FUNC(void) PyThread_free_lock(PyThread_type_lock);\r
+PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int);\r
+#define WAIT_LOCK      1\r
+#define NOWAIT_LOCK    0\r
+PyAPI_FUNC(void) PyThread_release_lock(PyThread_type_lock);\r
+\r
+PyAPI_FUNC(size_t) PyThread_get_stacksize(void);\r
+PyAPI_FUNC(int) PyThread_set_stacksize(size_t);\r
+\r
+/* Thread Local Storage (TLS) API */\r
+PyAPI_FUNC(int) PyThread_create_key(void);\r
+PyAPI_FUNC(void) PyThread_delete_key(int);\r
+PyAPI_FUNC(int) PyThread_set_key_value(int, void *);\r
+PyAPI_FUNC(void *) PyThread_get_key_value(int);\r
+PyAPI_FUNC(void) PyThread_delete_key_value(int key);\r
+\r
+/* Cleanup after a fork */\r
+PyAPI_FUNC(void) PyThread_ReInitTLS(void);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* !Py_PYTHREAD_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/rangeobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/rangeobject.h
new file mode 100644 (file)
index 0000000..b8dcb40
--- /dev/null
@@ -0,0 +1,28 @@
+\r
+/* Range object interface */\r
+\r
+#ifndef Py_RANGEOBJECT_H\r
+#define Py_RANGEOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* This is about the type 'xrange', not the built-in function range(), which\r
+   returns regular lists. */\r
+\r
+/*\r
+A range object represents an integer range.  This is an immutable object;\r
+a range cannot change its value after creation.\r
+\r
+Range objects behave like the corresponding tuple objects except that\r
+they are represented by a start, stop, and step datamembers.\r
+*/\r
+\r
+PyAPI_DATA(PyTypeObject) PyRange_Type;\r
+\r
+#define PyRange_Check(op) (Py_TYPE(op) == &PyRange_Type)\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_RANGEOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/setobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/setobject.h
new file mode 100644 (file)
index 0000000..6ded153
--- /dev/null
@@ -0,0 +1,99 @@
+/* Set object interface */\r
+\r
+#ifndef Py_SETOBJECT_H\r
+#define Py_SETOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/*\r
+There are three kinds of slots in the table:\r
+\r
+1. Unused:  key == NULL\r
+2. Active:  key != NULL and key != dummy\r
+3. Dummy:   key == dummy\r
+\r
+Note: .pop() abuses the hash field of an Unused or Dummy slot to\r
+hold a search finger.  The hash field of Unused or Dummy slots has\r
+no meaning otherwise.\r
+*/\r
+\r
+#define PySet_MINSIZE 8\r
+\r
+typedef struct {\r
+    long hash;      /* cached hash code for the entry key */\r
+    PyObject *key;\r
+} setentry;\r
+\r
+\r
+/*\r
+This data structure is shared by set and frozenset objects.\r
+*/\r
+\r
+typedef struct _setobject PySetObject;\r
+struct _setobject {\r
+    PyObject_HEAD\r
+\r
+    Py_ssize_t fill;  /* # Active + # Dummy */\r
+    Py_ssize_t used;  /* # Active */\r
+\r
+    /* The table contains mask + 1 slots, and that's a power of 2.\r
+     * We store the mask instead of the size because the mask is more\r
+     * frequently needed.\r
+     */\r
+    Py_ssize_t mask;\r
+\r
+    /* table points to smalltable for small tables, else to\r
+     * additional malloc'ed memory.  table is never NULL!  This rule\r
+     * saves repeated runtime null-tests.\r
+     */\r
+    setentry *table;\r
+    setentry *(*lookup)(PySetObject *so, PyObject *key, long hash);\r
+    setentry smalltable[PySet_MINSIZE];\r
+\r
+    long hash;                  /* only used by frozenset objects */\r
+    PyObject *weakreflist;      /* List of weak references */\r
+};\r
+\r
+PyAPI_DATA(PyTypeObject) PySet_Type;\r
+PyAPI_DATA(PyTypeObject) PyFrozenSet_Type;\r
+\r
+/* Invariants for frozensets:\r
+ *     data is immutable.\r
+ *     hash is the hash of the frozenset or -1 if not computed yet.\r
+ * Invariants for sets:\r
+ *     hash is -1\r
+ */\r
+\r
+#define PyFrozenSet_CheckExact(ob) (Py_TYPE(ob) == &PyFrozenSet_Type)\r
+#define PyAnySet_CheckExact(ob) \\r
+    (Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type)\r
+#define PyAnySet_Check(ob) \\r
+    (Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type || \\r
+      PyType_IsSubtype(Py_TYPE(ob), &PySet_Type) || \\r
+      PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type))\r
+#define PySet_Check(ob) \\r
+    (Py_TYPE(ob) == &PySet_Type || \\r
+    PyType_IsSubtype(Py_TYPE(ob), &PySet_Type))\r
+#define   PyFrozenSet_Check(ob) \\r
+    (Py_TYPE(ob) == &PyFrozenSet_Type || \\r
+      PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type))\r
+\r
+PyAPI_FUNC(PyObject *) PySet_New(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *);\r
+PyAPI_FUNC(Py_ssize_t) PySet_Size(PyObject *anyset);\r
+#define PySet_GET_SIZE(so) (((PySetObject *)(so))->used)\r
+PyAPI_FUNC(int) PySet_Clear(PyObject *set);\r
+PyAPI_FUNC(int) PySet_Contains(PyObject *anyset, PyObject *key);\r
+PyAPI_FUNC(int) PySet_Discard(PyObject *set, PyObject *key);\r
+PyAPI_FUNC(int) PySet_Add(PyObject *set, PyObject *key);\r
+PyAPI_FUNC(int) _PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **key);\r
+PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash);\r
+PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set);\r
+PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_SETOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/sliceobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/sliceobject.h
new file mode 100644 (file)
index 0000000..469921a
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef Py_SLICEOBJECT_H\r
+#define Py_SLICEOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* The unique ellipsis object "..." */\r
+\r
+PyAPI_DATA(PyObject) _Py_EllipsisObject; /* Don't use this directly */\r
+\r
+#define Py_Ellipsis (&_Py_EllipsisObject)\r
+\r
+/* Slice object interface */\r
+\r
+/*\r
+\r
+A slice object containing start, stop, and step data members (the\r
+names are from range).  After much talk with Guido, it was decided to\r
+let these be any arbitrary python type.  Py_None stands for omitted values.\r
+*/\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    PyObject *start, *stop, *step;     /* not NULL */\r
+} PySliceObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PySlice_Type;\r
+PyAPI_DATA(PyTypeObject) PyEllipsis_Type;\r
+\r
+#define PySlice_Check(op) (Py_TYPE(op) == &PySlice_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop,\r
+                                  PyObject* step);\r
+PyAPI_FUNC(PyObject *) _PySlice_FromIndices(Py_ssize_t start, Py_ssize_t stop);\r
+PyAPI_FUNC(int) PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,\r
+                                  Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step);\r
+PyAPI_FUNC(int) PySlice_GetIndicesEx(PySliceObject *r, Py_ssize_t length,\r
+                                   Py_ssize_t *start, Py_ssize_t *stop, \r
+                                   Py_ssize_t *step, Py_ssize_t *slicelength);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_SLICEOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/stringobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/stringobject.h
new file mode 100644 (file)
index 0000000..d20d986
--- /dev/null
@@ -0,0 +1,210 @@
+\r
+/* String (str/bytes) object interface */\r
+\r
+#ifndef Py_STRINGOBJECT_H\r
+#define Py_STRINGOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#include <stdarg.h>\r
+\r
+/*\r
+Type PyStringObject represents a character string.  An extra zero byte is\r
+reserved at the end to ensure it is zero-terminated, but a size is\r
+present so strings with null bytes in them can be represented.  This\r
+is an immutable object type.\r
+\r
+There are functions to create new string objects, to test\r
+an object for string-ness, and to get the\r
+string value.  The latter function returns a null pointer\r
+if the object is not of the proper type.\r
+There is a variant that takes an explicit size as well as a\r
+variant that assumes a zero-terminated string.  Note that none of the\r
+functions should be applied to nil objects.\r
+*/\r
+\r
+/* Caching the hash (ob_shash) saves recalculation of a string's hash value.\r
+   Interning strings (ob_sstate) tries to ensure that only one string\r
+   object with a given value exists, so equality tests can be one pointer\r
+   comparison.  This is generally restricted to strings that "look like"\r
+   Python identifiers, although the intern() builtin can be used to force\r
+   interning of any string.\r
+   Together, these sped the interpreter by up to 20%. */\r
+\r
+typedef struct {\r
+    PyObject_VAR_HEAD\r
+    long ob_shash;\r
+    int ob_sstate;\r
+    char ob_sval[1];\r
+\r
+    /* Invariants:\r
+     *     ob_sval contains space for 'ob_size+1' elements.\r
+     *     ob_sval[ob_size] == 0.\r
+     *     ob_shash is the hash of the string or -1 if not computed yet.\r
+     *     ob_sstate != 0 iff the string object is in stringobject.c's\r
+     *       'interned' dictionary; in this case the two references\r
+     *       from 'interned' to this object are *not counted* in ob_refcnt.\r
+     */\r
+} PyStringObject;\r
+\r
+#define SSTATE_NOT_INTERNED 0\r
+#define SSTATE_INTERNED_MORTAL 1\r
+#define SSTATE_INTERNED_IMMORTAL 2\r
+\r
+PyAPI_DATA(PyTypeObject) PyBaseString_Type;\r
+PyAPI_DATA(PyTypeObject) PyString_Type;\r
+\r
+#define PyString_Check(op) \\r
+                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS)\r
+#define PyString_CheckExact(op) (Py_TYPE(op) == &PyString_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);\r
+PyAPI_FUNC(PyObject *) PyString_FromString(const char *);\r
+PyAPI_FUNC(PyObject *) PyString_FromFormatV(const char*, va_list)\r
+                               Py_GCC_ATTRIBUTE((format(printf, 1, 0)));\r
+PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)\r
+                               Py_GCC_ATTRIBUTE((format(printf, 1, 2)));\r
+PyAPI_FUNC(Py_ssize_t) PyString_Size(PyObject *);\r
+PyAPI_FUNC(char *) PyString_AsString(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);\r
+PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);\r
+PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);\r
+PyAPI_FUNC(int) _PyString_Resize(PyObject **, Py_ssize_t);\r
+PyAPI_FUNC(int) _PyString_Eq(PyObject *, PyObject*);\r
+PyAPI_FUNC(PyObject *) PyString_Format(PyObject *, PyObject *);\r
+PyAPI_FUNC(PyObject *) _PyString_FormatLong(PyObject*, int, int,\r
+                                                 int, char**, int*);\r
+PyAPI_FUNC(PyObject *) PyString_DecodeEscape(const char *, Py_ssize_t, \r
+                                                  const char *, Py_ssize_t,\r
+                                                  const char *);\r
+\r
+PyAPI_FUNC(void) PyString_InternInPlace(PyObject **);\r
+PyAPI_FUNC(void) PyString_InternImmortal(PyObject **);\r
+PyAPI_FUNC(PyObject *) PyString_InternFromString(const char *);\r
+PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void);\r
+\r
+/* Use only if you know it's a string */\r
+#define PyString_CHECK_INTERNED(op) (((PyStringObject *)(op))->ob_sstate)\r
+\r
+/* Macro, trading safety for speed */\r
+#define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)\r
+#define PyString_GET_SIZE(op)  Py_SIZE(op)\r
+\r
+/* _PyString_Join(sep, x) is like sep.join(x).  sep must be PyStringObject*,\r
+   x must be an iterable object. */\r
+PyAPI_FUNC(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);\r
+\r
+/* --- Generic Codecs ----------------------------------------------------- */\r
+\r
+/* Create an object by decoding the encoded string s of the\r
+   given size. */\r
+\r
+PyAPI_FUNC(PyObject*) PyString_Decode(\r
+    const char *s,              /* encoded string */\r
+    Py_ssize_t size,            /* size of buffer */\r
+    const char *encoding,       /* encoding */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+/* Encodes a char buffer of the given size and returns a \r
+   Python object. */\r
+\r
+PyAPI_FUNC(PyObject*) PyString_Encode(\r
+    const char *s,              /* string char buffer */\r
+    Py_ssize_t size,            /* number of chars to encode */\r
+    const char *encoding,       /* encoding */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+/* Encodes a string object and returns the result as Python \r
+   object. */\r
+\r
+PyAPI_FUNC(PyObject*) PyString_AsEncodedObject(\r
+    PyObject *str,             /* string object */\r
+    const char *encoding,      /* encoding */\r
+    const char *errors         /* error handling */\r
+    );\r
+\r
+/* Encodes a string object and returns the result as Python string\r
+   object.   \r
+   \r
+   If the codec returns an Unicode object, the object is converted\r
+   back to a string using the default encoding.\r
+\r
+   DEPRECATED - use PyString_AsEncodedObject() instead. */\r
+\r
+PyAPI_FUNC(PyObject*) PyString_AsEncodedString(\r
+    PyObject *str,             /* string object */\r
+    const char *encoding,      /* encoding */\r
+    const char *errors         /* error handling */\r
+    );\r
+\r
+/* Decodes a string object and returns the result as Python \r
+   object. */\r
+\r
+PyAPI_FUNC(PyObject*) PyString_AsDecodedObject(\r
+    PyObject *str,             /* string object */\r
+    const char *encoding,      /* encoding */\r
+    const char *errors         /* error handling */\r
+    );\r
+\r
+/* Decodes a string object and returns the result as Python string\r
+   object.  \r
+   \r
+   If the codec returns an Unicode object, the object is converted\r
+   back to a string using the default encoding.\r
+\r
+   DEPRECATED - use PyString_AsDecodedObject() instead. */\r
+\r
+PyAPI_FUNC(PyObject*) PyString_AsDecodedString(\r
+    PyObject *str,             /* string object */\r
+    const char *encoding,      /* encoding */\r
+    const char *errors         /* error handling */\r
+    );\r
+\r
+/* Provides access to the internal data buffer and size of a string\r
+   object or the default encoded version of an Unicode object. Passing\r
+   NULL as *len parameter will force the string buffer to be\r
+   0-terminated (passing a string with embedded NULL characters will\r
+   cause an exception).  */\r
+\r
+PyAPI_FUNC(int) PyString_AsStringAndSize(\r
+    register PyObject *obj,    /* string or Unicode object */\r
+    register char **s,         /* pointer to buffer variable */\r
+    register Py_ssize_t *len   /* pointer to length variable or NULL\r
+                                  (only possible for 0-terminated\r
+                                  strings) */\r
+    );\r
+\r
+\r
+/* Using the current locale, insert the thousands grouping\r
+   into the string pointed to by buffer.  For the argument descriptions,\r
+   see Objects/stringlib/localeutil.h */\r
+PyAPI_FUNC(Py_ssize_t) _PyString_InsertThousandsGroupingLocale(char *buffer,\r
+                                  Py_ssize_t n_buffer,\r
+                                  char *digits,\r
+                                  Py_ssize_t n_digits,\r
+                                  Py_ssize_t min_width);\r
+\r
+/* Using explicit passed-in values, insert the thousands grouping\r
+   into the string pointed to by buffer.  For the argument descriptions,\r
+   see Objects/stringlib/localeutil.h */\r
+PyAPI_FUNC(Py_ssize_t) _PyString_InsertThousandsGrouping(char *buffer,\r
+                                  Py_ssize_t n_buffer,\r
+                                  char *digits,\r
+                                  Py_ssize_t n_digits,\r
+                                  Py_ssize_t min_width,\r
+                                  const char *grouping,\r
+                                  const char *thousands_sep);\r
+\r
+/* Format the object based on the format_spec, as defined in PEP 3101\r
+   (Advanced String Formatting). */\r
+PyAPI_FUNC(PyObject *) _PyBytes_FormatAdvanced(PyObject *obj,\r
+                                              char *format_spec,\r
+                                              Py_ssize_t format_spec_len);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_STRINGOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/structmember.h b/AppPkg/Applications/Python/Python-2.7.10/Include/structmember.h
new file mode 100644 (file)
index 0000000..8e2425b
--- /dev/null
@@ -0,0 +1,99 @@
+#ifndef Py_STRUCTMEMBER_H\r
+#define Py_STRUCTMEMBER_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Interface to map C struct members to Python object attributes */\r
+\r
+#include <stddef.h> /* For offsetof */\r
+\r
+/* The offsetof() macro calculates the offset of a structure member\r
+   in its structure.  Unfortunately this cannot be written down\r
+   portably, hence it is provided by a Standard C header file.\r
+   For pre-Standard C compilers, here is a version that usually works\r
+   (but watch out!): */\r
+\r
+#ifndef offsetof\r
+#define offsetof(type, member) ( (int) & ((type*)0) -> member )\r
+#endif\r
+\r
+/* An array of memberlist structures defines the name, type and offset\r
+   of selected members of a C structure.  These can be read by\r
+   PyMember_Get() and set by PyMember_Set() (except if their READONLY flag\r
+   is set).  The array must be terminated with an entry whose name\r
+   pointer is NULL. */\r
+\r
+struct memberlist {\r
+    /* Obsolete version, for binary backwards compatibility */\r
+    char *name;\r
+    int type;\r
+    int offset;\r
+    int flags;\r
+};\r
+\r
+typedef struct PyMemberDef {\r
+    /* Current version, use this */\r
+    char *name;\r
+    int type;\r
+    Py_ssize_t offset;\r
+    int flags;\r
+    char *doc;\r
+} PyMemberDef;\r
+\r
+/* Types */\r
+#define T_SHORT         0\r
+#define T_INT           1\r
+#define T_LONG          2\r
+#define T_FLOAT         3\r
+#define T_DOUBLE        4\r
+#define T_STRING        5\r
+#define T_OBJECT        6\r
+/* XXX the ordering here is weird for binary compatibility */\r
+#define T_CHAR          7       /* 1-character string */\r
+#define T_BYTE          8       /* 8-bit signed int */\r
+/* unsigned variants: */\r
+#define T_UBYTE         9\r
+#define T_USHORT        10\r
+#define T_UINT          11\r
+#define T_ULONG         12\r
+\r
+/* Added by Jack: strings contained in the structure */\r
+#define T_STRING_INPLACE        13\r
+\r
+/* Added by Lillo: bools contained in the structure (assumed char) */\r
+#define T_BOOL          14\r
+\r
+#define T_OBJECT_EX     16      /* Like T_OBJECT, but raises AttributeError\r
+                   when the value is NULL, instead of\r
+                   converting to None. */\r
+#ifdef HAVE_LONG_LONG\r
+#define T_LONGLONG      17\r
+#define T_ULONGLONG      18\r
+#endif /* HAVE_LONG_LONG */\r
+\r
+#define T_PYSSIZET       19 /* Py_ssize_t */\r
+\r
+\r
+/* Flags */\r
+#define READONLY        1\r
+#define RO              READONLY                /* Shorthand */\r
+#define READ_RESTRICTED 2\r
+#define PY_WRITE_RESTRICTED 4\r
+#define RESTRICTED      (READ_RESTRICTED | PY_WRITE_RESTRICTED)\r
+\r
+\r
+/* Obsolete API, for binary backwards compatibility */\r
+PyAPI_FUNC(PyObject *) PyMember_Get(const char *, struct memberlist *, const char *);\r
+PyAPI_FUNC(int) PyMember_Set(char *, struct memberlist *, const char *, PyObject *);\r
+\r
+/* Current API, use this */\r
+PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);\r
+PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_STRUCTMEMBER_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/structseq.h b/AppPkg/Applications/Python/Python-2.7.10/Include/structseq.h
new file mode 100644 (file)
index 0000000..74b1a88
--- /dev/null
@@ -0,0 +1,41 @@
+\r
+/* Tuple object interface */\r
+\r
+#ifndef Py_STRUCTSEQ_H\r
+#define Py_STRUCTSEQ_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct PyStructSequence_Field {\r
+       char *name;\r
+       char *doc;\r
+} PyStructSequence_Field;\r
+\r
+typedef struct PyStructSequence_Desc {\r
+       char *name;\r
+       char *doc;\r
+       struct PyStructSequence_Field *fields;\r
+       int n_in_sequence;\r
+} PyStructSequence_Desc;\r
+\r
+extern char* PyStructSequence_UnnamedField;\r
+\r
+PyAPI_FUNC(void) PyStructSequence_InitType(PyTypeObject *type,\r
+                                          PyStructSequence_Desc *desc);\r
+\r
+PyAPI_FUNC(PyObject *) PyStructSequence_New(PyTypeObject* type);\r
+\r
+typedef struct {\r
+       PyObject_VAR_HEAD\r
+       PyObject *ob_item[1];\r
+} PyStructSequence;\r
+\r
+/* Macro, *only* to be used to fill in brand new objects */\r
+#define PyStructSequence_SET_ITEM(op, i, v) \\r
+       (((PyStructSequence *)(op))->ob_item[i] = v)\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_STRUCTSEQ_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/symtable.h b/AppPkg/Applications/Python/Python-2.7.10/Include/symtable.h
new file mode 100644 (file)
index 0000000..dd3e360
--- /dev/null
@@ -0,0 +1,98 @@
+#ifndef Py_SYMTABLE_H\r
+#define Py_SYMTABLE_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef enum _block_type { FunctionBlock, ClassBlock, ModuleBlock }\r
+    _Py_block_ty;\r
+\r
+struct _symtable_entry;\r
+\r
+struct symtable {\r
+    const char *st_filename; /* name of file being compiled */\r
+    struct _symtable_entry *st_cur; /* current symbol table entry */\r
+    struct _symtable_entry *st_top; /* module entry */\r
+    PyObject *st_symbols;    /* dictionary of symbol table entries */\r
+    PyObject *st_stack;      /* stack of namespace info */\r
+    PyObject *st_global;     /* borrowed ref to MODULE in st_symbols */\r
+    int st_nblocks;          /* number of blocks */\r
+    PyObject *st_private;        /* name of current class or NULL */\r
+    PyFutureFeatures *st_future; /* module's future features */\r
+};\r
+\r
+typedef struct _symtable_entry {\r
+    PyObject_HEAD\r
+    PyObject *ste_id;        /* int: key in st_symbols */\r
+    PyObject *ste_symbols;   /* dict: name to flags */\r
+    PyObject *ste_name;      /* string: name of block */\r
+    PyObject *ste_varnames;  /* list of variable names */\r
+    PyObject *ste_children;  /* list of child ids */\r
+    _Py_block_ty ste_type;   /* module, class, or function */\r
+    int ste_unoptimized;     /* false if namespace is optimized */\r
+    int ste_nested;      /* true if block is nested */\r
+    unsigned ste_free : 1;        /* true if block has free variables */\r
+    unsigned ste_child_free : 1;  /* true if a child block has free vars,\r
+                                     including free refs to globals */\r
+    unsigned ste_generator : 1;   /* true if namespace is a generator */\r
+    unsigned ste_varargs : 1;     /* true if block has varargs */\r
+    unsigned ste_varkeywords : 1; /* true if block has varkeywords */\r
+    unsigned ste_returns_value : 1;  /* true if namespace uses return with\r
+                                        an argument */\r
+    int ste_lineno;          /* first line of block */\r
+    int ste_opt_lineno;      /* lineno of last exec or import * */\r
+    int ste_tmpname;         /* counter for listcomp temp vars */\r
+    struct symtable *ste_table;\r
+} PySTEntryObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PySTEntry_Type;\r
+\r
+#define PySTEntry_Check(op) (Py_TYPE(op) == &PySTEntry_Type)\r
+\r
+PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *);\r
+\r
+PyAPI_FUNC(struct symtable *) PySymtable_Build(mod_ty, const char *,\r
+                                              PyFutureFeatures *);\r
+PyAPI_FUNC(PySTEntryObject *) PySymtable_Lookup(struct symtable *, void *);\r
+\r
+PyAPI_FUNC(void) PySymtable_Free(struct symtable *);\r
+\r
+/* Flags for def-use information */\r
+\r
+#define DEF_GLOBAL 1           /* global stmt */\r
+#define DEF_LOCAL 2            /* assignment in code block */\r
+#define DEF_PARAM 2<<1         /* formal parameter */\r
+#define USE 2<<2               /* name is used */\r
+#define DEF_FREE 2<<3         /* name used but not defined in nested block */\r
+#define DEF_FREE_CLASS 2<<4    /* free variable from class's method */\r
+#define DEF_IMPORT 2<<5        /* assignment occurred via import */\r
+\r
+#define DEF_BOUND (DEF_LOCAL | DEF_PARAM | DEF_IMPORT)\r
+\r
+/* GLOBAL_EXPLICIT and GLOBAL_IMPLICIT are used internally by the symbol\r
+   table.  GLOBAL is returned from PyST_GetScope() for either of them.\r
+   It is stored in ste_symbols at bits 12-14.\r
+*/\r
+#define SCOPE_OFF 11\r
+#define SCOPE_MASK 7\r
+\r
+#define LOCAL 1\r
+#define GLOBAL_EXPLICIT 2\r
+#define GLOBAL_IMPLICIT 3\r
+#define FREE 4\r
+#define CELL 5\r
+\r
+/* The following three names are used for the ste_unoptimized bit field */\r
+#define OPT_IMPORT_STAR 1\r
+#define OPT_EXEC 2\r
+#define OPT_BARE_EXEC 4\r
+#define OPT_TOPLEVEL 8  /* top-level names, including eval and exec */\r
+\r
+#define GENERATOR 1\r
+#define GENERATOR_EXPRESSION 2\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_SYMTABLE_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/sysmodule.h b/AppPkg/Applications/Python/Python-2.7.10/Include/sysmodule.h
new file mode 100644 (file)
index 0000000..5a8bee7
--- /dev/null
@@ -0,0 +1,31 @@
+\r
+/* System module interface */\r
+\r
+#ifndef Py_SYSMODULE_H\r
+#define Py_SYSMODULE_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_FUNC(PyObject *) PySys_GetObject(char *);\r
+PyAPI_FUNC(int) PySys_SetObject(char *, PyObject *);\r
+PyAPI_FUNC(FILE *) PySys_GetFile(char *, FILE *);\r
+PyAPI_FUNC(void) PySys_SetArgv(int, char **);\r
+PyAPI_FUNC(void) PySys_SetArgvEx(int, char **, int);\r
+PyAPI_FUNC(void) PySys_SetPath(char *);\r
+\r
+PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)\r
+                       Py_GCC_ATTRIBUTE((format(printf, 1, 2)));\r
+PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...)\r
+                       Py_GCC_ATTRIBUTE((format(printf, 1, 2)));\r
+\r
+PyAPI_FUNC(void) PySys_ResetWarnOptions(void);\r
+PyAPI_FUNC(void) PySys_AddWarnOption(char *);\r
+PyAPI_FUNC(int) PySys_HasWarnOptions(void);\r
+\r
+PyAPI_FUNC(size_t) _PySys_GetSizeOf(PyObject *);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_SYSMODULE_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/timefuncs.h b/AppPkg/Applications/Python/Python-2.7.10/Include/timefuncs.h
new file mode 100644 (file)
index 0000000..ae5acf7
--- /dev/null
@@ -0,0 +1,26 @@
+/*  timefuncs.h\r
+ */\r
+\r
+/* Utility function related to timemodule.c. */\r
+\r
+#ifndef TIMEFUNCS_H\r
+#define TIMEFUNCS_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Cast double x to time_t, but raise ValueError if x is too large\r
+ * to fit in a time_t.  ValueError is set on return iff the return\r
+ * value is (time_t)-1 and PyErr_Occurred().\r
+ */\r
+PyAPI_FUNC(time_t) _PyTime_DoubleToTimet(double x);\r
+\r
+/* Get the current time since the epoch in seconds */\r
+PyAPI_FUNC(double) _PyTime_FloatTime(void);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif  /* TIMEFUNCS_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/token.h b/AppPkg/Applications/Python/Python-2.7.10/Include/token.h
new file mode 100644 (file)
index 0000000..438f04b
--- /dev/null
@@ -0,0 +1,85 @@
+\r
+/* Token types */\r
+\r
+#ifndef Py_TOKEN_H\r
+#define Py_TOKEN_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#undef TILDE   /* Prevent clash of our definition with system macro. Ex AIX, ioctl.h */\r
+\r
+#define ENDMARKER      0\r
+#define NAME           1\r
+#define NUMBER         2\r
+#define STRING         3\r
+#define NEWLINE                4\r
+#define INDENT         5\r
+#define DEDENT         6\r
+#define LPAR           7\r
+#define RPAR           8\r
+#define LSQB           9\r
+#define RSQB           10\r
+#define COLON          11\r
+#define COMMA          12\r
+#define SEMI           13\r
+#define PLUS           14\r
+#define MINUS          15\r
+#define STAR           16\r
+#define SLASH          17\r
+#define VBAR           18\r
+#define AMPER          19\r
+#define LESS           20\r
+#define GREATER                21\r
+#define EQUAL          22\r
+#define DOT            23\r
+#define PERCENT                24\r
+#define BACKQUOTE      25\r
+#define LBRACE         26\r
+#define RBRACE         27\r
+#define EQEQUAL                28\r
+#define NOTEQUAL       29\r
+#define LESSEQUAL      30\r
+#define GREATEREQUAL   31\r
+#define TILDE          32\r
+#define CIRCUMFLEX     33\r
+#define LEFTSHIFT      34\r
+#define RIGHTSHIFT     35\r
+#define DOUBLESTAR     36\r
+#define PLUSEQUAL      37\r
+#define MINEQUAL       38\r
+#define STAREQUAL      39\r
+#define SLASHEQUAL     40\r
+#define PERCENTEQUAL   41\r
+#define AMPEREQUAL     42\r
+#define VBAREQUAL      43\r
+#define CIRCUMFLEXEQUAL        44\r
+#define LEFTSHIFTEQUAL 45\r
+#define RIGHTSHIFTEQUAL        46\r
+#define DOUBLESTAREQUAL        47\r
+#define DOUBLESLASH    48\r
+#define DOUBLESLASHEQUAL 49\r
+#define AT              50     \r
+/* Don't forget to update the table _PyParser_TokenNames in tokenizer.c! */\r
+#define OP             51\r
+#define ERRORTOKEN     52\r
+#define N_TOKENS       53\r
+\r
+/* Special definitions for cooperation with parser */\r
+\r
+#define NT_OFFSET              256\r
+\r
+#define ISTERMINAL(x)          ((x) < NT_OFFSET)\r
+#define ISNONTERMINAL(x)       ((x) >= NT_OFFSET)\r
+#define ISEOF(x)               ((x) == ENDMARKER)\r
+\r
+\r
+PyAPI_DATA(char *) _PyParser_TokenNames[]; /* Token names */\r
+PyAPI_FUNC(int) PyToken_OneChar(int);\r
+PyAPI_FUNC(int) PyToken_TwoChars(int, int);\r
+PyAPI_FUNC(int) PyToken_ThreeChars(int, int, int);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_TOKEN_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/traceback.h b/AppPkg/Applications/Python/Python-2.7.10/Include/traceback.h
new file mode 100644 (file)
index 0000000..fce0607
--- /dev/null
@@ -0,0 +1,31 @@
+\r
+#ifndef Py_TRACEBACK_H\r
+#define Py_TRACEBACK_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+struct _frame;\r
+\r
+/* Traceback interface */\r
+\r
+typedef struct _traceback {\r
+       PyObject_HEAD\r
+       struct _traceback *tb_next;\r
+       struct _frame *tb_frame;\r
+       int tb_lasti;\r
+       int tb_lineno;\r
+} PyTracebackObject;\r
+\r
+PyAPI_FUNC(int) PyTraceBack_Here(struct _frame *);\r
+PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *);\r
+PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, const char *, int, int);\r
+\r
+/* Reveal traceback type so we can typecheck traceback objects */\r
+PyAPI_DATA(PyTypeObject) PyTraceBack_Type;\r
+#define PyTraceBack_Check(v) (Py_TYPE(v) == &PyTraceBack_Type)\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_TRACEBACK_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/tupleobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/tupleobject.h
new file mode 100644 (file)
index 0000000..8fdfd59
--- /dev/null
@@ -0,0 +1,61 @@
+\r
+/* Tuple object interface */\r
+\r
+#ifndef Py_TUPLEOBJECT_H\r
+#define Py_TUPLEOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/*\r
+Another generally useful object type is a tuple of object pointers.\r
+For Python, this is an immutable type.  C code can change the tuple items\r
+(but not their number), and even use tuples are general-purpose arrays of\r
+object references, but in general only brand new tuples should be mutated,\r
+not ones that might already have been exposed to Python code.\r
+\r
+*** WARNING *** PyTuple_SetItem does not increment the new item's reference\r
+count, but does decrement the reference count of the item it replaces,\r
+if not nil.  It does *decrement* the reference count if it is *not*\r
+inserted in the tuple.  Similarly, PyTuple_GetItem does not increment the\r
+returned item's reference count.\r
+*/\r
+\r
+typedef struct {\r
+    PyObject_VAR_HEAD\r
+    PyObject *ob_item[1];\r
+\r
+    /* ob_item contains space for 'ob_size' elements.\r
+     * Items must normally not be NULL, except during construction when\r
+     * the tuple is not yet visible outside the function that builds it.\r
+     */\r
+} PyTupleObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PyTuple_Type;\r
+\r
+#define PyTuple_Check(op) \\r
+                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)\r
+#define PyTuple_CheckExact(op) (Py_TYPE(op) == &PyTuple_Type)\r
+\r
+PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size);\r
+PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *);\r
+PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, Py_ssize_t);\r
+PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *);\r
+PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);\r
+PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, Py_ssize_t);\r
+PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...);\r
+PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);\r
+\r
+/* Macro, trading safety for speed */\r
+#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])\r
+#define PyTuple_GET_SIZE(op)    Py_SIZE(op)\r
+\r
+/* Macro, *only* to be used to fill in brand new tuples */\r
+#define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)\r
+\r
+PyAPI_FUNC(int) PyTuple_ClearFreeList(void);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_TUPLEOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/ucnhash.h b/AppPkg/Applications/Python/Python-2.7.10/Include/ucnhash.h
new file mode 100644 (file)
index 0000000..8158730
--- /dev/null
@@ -0,0 +1,33 @@
+/* Unicode name database interface */\r
+\r
+#ifndef Py_UCNHASH_H\r
+#define Py_UCNHASH_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* revised ucnhash CAPI interface (exported through a "wrapper") */\r
+\r
+#define PyUnicodeData_CAPSULE_NAME "unicodedata.ucnhash_CAPI"\r
+\r
+typedef struct {\r
+\r
+    /* Size of this struct */\r
+    int size;\r
+\r
+    /* Get name for a given character code.  Returns non-zero if\r
+       success, zero if not.  Does not set Python exceptions. \r
+       If self is NULL, data come from the default version of the database.\r
+       If it is not NULL, it should be a unicodedata.ucd_X_Y_Z object */\r
+    int (*getname)(PyObject *self, Py_UCS4 code, char* buffer, int buflen);\r
+\r
+    /* Get character code for a given name.  Same error handling\r
+       as for getname. */\r
+    int (*getcode)(PyObject *self, const char* name, int namelen, Py_UCS4* code);\r
+\r
+} _PyUnicode_Name_CAPI;\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_UCNHASH_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/unicodeobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/unicodeobject.h
new file mode 100644 (file)
index 0000000..de52416
--- /dev/null
@@ -0,0 +1,1413 @@
+#ifndef Py_UNICODEOBJECT_H\r
+#define Py_UNICODEOBJECT_H\r
+\r
+#include <stdarg.h>\r
+\r
+/*\r
+\r
+Unicode implementation based on original code by Fredrik Lundh,\r
+modified by Marc-Andre Lemburg (mal@lemburg.com) according to the\r
+Unicode Integration Proposal (see file Misc/unicode.txt).\r
+\r
+Copyright (c) Corporation for National Research Initiatives.\r
+\r
+\r
+ Original header:\r
+ --------------------------------------------------------------------\r
+\r
+ * Yet another Unicode string type for Python.  This type supports the\r
+ * 16-bit Basic Multilingual Plane (BMP) only.\r
+ *\r
+ * Written by Fredrik Lundh, January 1999.\r
+ *\r
+ * Copyright (c) 1999 by Secret Labs AB.\r
+ * Copyright (c) 1999 by Fredrik Lundh.\r
+ *\r
+ * fredrik@pythonware.com\r
+ * http://www.pythonware.com\r
+ *\r
+ * --------------------------------------------------------------------\r
+ * This Unicode String Type is\r
+ *\r
+ * Copyright (c) 1999 by Secret Labs AB\r
+ * Copyright (c) 1999 by Fredrik Lundh\r
+ *\r
+ * By obtaining, using, and/or copying this software and/or its\r
+ * associated documentation, you agree that you have read, understood,\r
+ * and will comply with the following terms and conditions:\r
+ *\r
+ * Permission to use, copy, modify, and distribute this software and its\r
+ * associated documentation for any purpose and without fee is hereby\r
+ * granted, provided that the above copyright notice appears in all\r
+ * copies, and that both that copyright notice and this permission notice\r
+ * appear in supporting documentation, and that the name of Secret Labs\r
+ * AB or the author not be used in advertising or publicity pertaining to\r
+ * distribution of the software without specific, written prior\r
+ * permission.\r
+ *\r
+ * SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO\r
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\r
+ * FITNESS.  IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR\r
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\r
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT\r
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\r
+ * -------------------------------------------------------------------- */\r
+\r
+#include <ctype.h>\r
+\r
+/* === Internal API ======================================================= */\r
+\r
+/* --- Internal Unicode Format -------------------------------------------- */\r
+\r
+#ifndef Py_USING_UNICODE\r
+\r
+#define PyUnicode_Check(op)                 0\r
+#define PyUnicode_CheckExact(op)            0\r
+\r
+#else\r
+\r
+/* FIXME: MvL's new implementation assumes that Py_UNICODE_SIZE is\r
+   properly set, but the default rules below doesn't set it.  I'll\r
+   sort this out some other day -- fredrik@pythonware.com */\r
+\r
+#ifndef Py_UNICODE_SIZE\r
+#error Must define Py_UNICODE_SIZE\r
+#endif\r
+\r
+/* Setting Py_UNICODE_WIDE enables UCS-4 storage.  Otherwise, Unicode\r
+   strings are stored as UCS-2 (with limited support for UTF-16) */\r
+\r
+#if Py_UNICODE_SIZE >= 4\r
+#define Py_UNICODE_WIDE\r
+#endif\r
+\r
+/* Set these flags if the platform has "wchar.h", "wctype.h" and the\r
+   wchar_t type is a 16-bit unsigned type */\r
+/* #define HAVE_WCHAR_H */\r
+/* #define HAVE_USABLE_WCHAR_T */\r
+\r
+/* Defaults for various platforms */\r
+#ifndef PY_UNICODE_TYPE\r
+\r
+/* Windows has a usable wchar_t type (unless we're using UCS-4) */\r
+# if defined(MS_WIN32) && Py_UNICODE_SIZE == 2\r
+#  define HAVE_USABLE_WCHAR_T\r
+#  define PY_UNICODE_TYPE wchar_t\r
+# endif\r
+\r
+# if defined(Py_UNICODE_WIDE)\r
+#  define PY_UNICODE_TYPE Py_UCS4\r
+# endif\r
+\r
+#endif\r
+\r
+/* If the compiler provides a wchar_t type we try to support it\r
+   through the interface functions PyUnicode_FromWideChar() and\r
+   PyUnicode_AsWideChar(). */\r
+\r
+#ifdef HAVE_USABLE_WCHAR_T\r
+# ifndef HAVE_WCHAR_H\r
+#  define HAVE_WCHAR_H\r
+# endif\r
+#endif\r
+\r
+#ifdef HAVE_WCHAR_H\r
+/* Work around a cosmetic bug in BSDI 4.x wchar.h; thanks to Thomas Wouters */\r
+# ifdef _HAVE_BSDI\r
+#  include <time.h>\r
+# endif\r
+#  include <wchar.h>\r
+#endif\r
+\r
+/*\r
+ * Use this typedef when you need to represent a UTF-16 surrogate pair\r
+ * as single unsigned integer.\r
+ */\r
+#if SIZEOF_INT >= 4\r
+typedef unsigned int Py_UCS4;\r
+#elif SIZEOF_LONG >= 4\r
+typedef unsigned long Py_UCS4;\r
+#endif\r
+\r
+/* Py_UNICODE is the native Unicode storage format (code unit) used by\r
+   Python and represents a single Unicode element in the Unicode\r
+   type. */\r
+\r
+typedef PY_UNICODE_TYPE Py_UNICODE;\r
+\r
+/* --- UCS-2/UCS-4 Name Mangling ------------------------------------------ */\r
+\r
+/* Unicode API names are mangled to assure that UCS-2 and UCS-4 builds\r
+   produce different external names and thus cause import errors in\r
+   case Python interpreters and extensions with mixed compiled in\r
+   Unicode width assumptions are combined. */\r
+\r
+#ifndef Py_UNICODE_WIDE\r
+\r
+# define PyUnicode_AsASCIIString PyUnicodeUCS2_AsASCIIString\r
+# define PyUnicode_AsCharmapString PyUnicodeUCS2_AsCharmapString\r
+# define PyUnicode_AsEncodedObject PyUnicodeUCS2_AsEncodedObject\r
+# define PyUnicode_AsEncodedString PyUnicodeUCS2_AsEncodedString\r
+# define PyUnicode_AsLatin1String PyUnicodeUCS2_AsLatin1String\r
+# define PyUnicode_AsRawUnicodeEscapeString PyUnicodeUCS2_AsRawUnicodeEscapeString\r
+# define PyUnicode_AsUTF32String PyUnicodeUCS2_AsUTF32String\r
+# define PyUnicode_AsUTF16String PyUnicodeUCS2_AsUTF16String\r
+# define PyUnicode_AsUTF8String PyUnicodeUCS2_AsUTF8String\r
+# define PyUnicode_AsUnicode PyUnicodeUCS2_AsUnicode\r
+# define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS2_AsUnicodeEscapeString\r
+# define PyUnicode_AsWideChar PyUnicodeUCS2_AsWideChar\r
+# define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist\r
+# define PyUnicode_Compare PyUnicodeUCS2_Compare\r
+# define PyUnicode_Concat PyUnicodeUCS2_Concat\r
+# define PyUnicode_Contains PyUnicodeUCS2_Contains\r
+# define PyUnicode_Count PyUnicodeUCS2_Count\r
+# define PyUnicode_Decode PyUnicodeUCS2_Decode\r
+# define PyUnicode_DecodeASCII PyUnicodeUCS2_DecodeASCII\r
+# define PyUnicode_DecodeCharmap PyUnicodeUCS2_DecodeCharmap\r
+# define PyUnicode_DecodeLatin1 PyUnicodeUCS2_DecodeLatin1\r
+# define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS2_DecodeRawUnicodeEscape\r
+# define PyUnicode_DecodeUTF32 PyUnicodeUCS2_DecodeUTF32\r
+# define PyUnicode_DecodeUTF32Stateful PyUnicodeUCS2_DecodeUTF32Stateful\r
+# define PyUnicode_DecodeUTF16 PyUnicodeUCS2_DecodeUTF16\r
+# define PyUnicode_DecodeUTF16Stateful PyUnicodeUCS2_DecodeUTF16Stateful\r
+# define PyUnicode_DecodeUTF8 PyUnicodeUCS2_DecodeUTF8\r
+# define PyUnicode_DecodeUTF8Stateful PyUnicodeUCS2_DecodeUTF8Stateful\r
+# define PyUnicode_DecodeUnicodeEscape PyUnicodeUCS2_DecodeUnicodeEscape\r
+# define PyUnicode_Encode PyUnicodeUCS2_Encode\r
+# define PyUnicode_EncodeASCII PyUnicodeUCS2_EncodeASCII\r
+# define PyUnicode_EncodeCharmap PyUnicodeUCS2_EncodeCharmap\r
+# define PyUnicode_EncodeDecimal PyUnicodeUCS2_EncodeDecimal\r
+# define PyUnicode_EncodeLatin1 PyUnicodeUCS2_EncodeLatin1\r
+# define PyUnicode_EncodeRawUnicodeEscape PyUnicodeUCS2_EncodeRawUnicodeEscape\r
+# define PyUnicode_EncodeUTF32 PyUnicodeUCS2_EncodeUTF32\r
+# define PyUnicode_EncodeUTF16 PyUnicodeUCS2_EncodeUTF16\r
+# define PyUnicode_EncodeUTF8 PyUnicodeUCS2_EncodeUTF8\r
+# define PyUnicode_EncodeUnicodeEscape PyUnicodeUCS2_EncodeUnicodeEscape\r
+# define PyUnicode_Find PyUnicodeUCS2_Find\r
+# define PyUnicode_Format PyUnicodeUCS2_Format\r
+# define PyUnicode_FromEncodedObject PyUnicodeUCS2_FromEncodedObject\r
+# define PyUnicode_FromFormat PyUnicodeUCS2_FromFormat\r
+# define PyUnicode_FromFormatV PyUnicodeUCS2_FromFormatV\r
+# define PyUnicode_FromObject PyUnicodeUCS2_FromObject\r
+# define PyUnicode_FromOrdinal PyUnicodeUCS2_FromOrdinal\r
+# define PyUnicode_FromString PyUnicodeUCS2_FromString\r
+# define PyUnicode_FromStringAndSize PyUnicodeUCS2_FromStringAndSize\r
+# define PyUnicode_FromUnicode PyUnicodeUCS2_FromUnicode\r
+# define PyUnicode_FromWideChar PyUnicodeUCS2_FromWideChar\r
+# define PyUnicode_GetDefaultEncoding PyUnicodeUCS2_GetDefaultEncoding\r
+# define PyUnicode_GetMax PyUnicodeUCS2_GetMax\r
+# define PyUnicode_GetSize PyUnicodeUCS2_GetSize\r
+# define PyUnicode_Join PyUnicodeUCS2_Join\r
+# define PyUnicode_Partition PyUnicodeUCS2_Partition\r
+# define PyUnicode_RPartition PyUnicodeUCS2_RPartition\r
+# define PyUnicode_RSplit PyUnicodeUCS2_RSplit\r
+# define PyUnicode_Replace PyUnicodeUCS2_Replace\r
+# define PyUnicode_Resize PyUnicodeUCS2_Resize\r
+# define PyUnicode_RichCompare PyUnicodeUCS2_RichCompare\r
+# define PyUnicode_SetDefaultEncoding PyUnicodeUCS2_SetDefaultEncoding\r
+# define PyUnicode_Split PyUnicodeUCS2_Split\r
+# define PyUnicode_Splitlines PyUnicodeUCS2_Splitlines\r
+# define PyUnicode_Tailmatch PyUnicodeUCS2_Tailmatch\r
+# define PyUnicode_Translate PyUnicodeUCS2_Translate\r
+# define PyUnicode_TranslateCharmap PyUnicodeUCS2_TranslateCharmap\r
+# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS2_AsDefaultEncodedString\r
+# define _PyUnicode_Fini _PyUnicodeUCS2_Fini\r
+# define _PyUnicode_Init _PyUnicodeUCS2_Init\r
+# define _PyUnicode_IsAlpha _PyUnicodeUCS2_IsAlpha\r
+# define _PyUnicode_IsDecimalDigit _PyUnicodeUCS2_IsDecimalDigit\r
+# define _PyUnicode_IsDigit _PyUnicodeUCS2_IsDigit\r
+# define _PyUnicode_IsLinebreak _PyUnicodeUCS2_IsLinebreak\r
+# define _PyUnicode_IsLowercase _PyUnicodeUCS2_IsLowercase\r
+# define _PyUnicode_IsNumeric _PyUnicodeUCS2_IsNumeric\r
+# define _PyUnicode_IsTitlecase _PyUnicodeUCS2_IsTitlecase\r
+# define _PyUnicode_IsUppercase _PyUnicodeUCS2_IsUppercase\r
+# define _PyUnicode_IsWhitespace _PyUnicodeUCS2_IsWhitespace\r
+# define _PyUnicode_ToDecimalDigit _PyUnicodeUCS2_ToDecimalDigit\r
+# define _PyUnicode_ToDigit _PyUnicodeUCS2_ToDigit\r
+# define _PyUnicode_ToLowercase _PyUnicodeUCS2_ToLowercase\r
+# define _PyUnicode_ToNumeric _PyUnicodeUCS2_ToNumeric\r
+# define _PyUnicode_ToTitlecase _PyUnicodeUCS2_ToTitlecase\r
+# define _PyUnicode_ToUppercase _PyUnicodeUCS2_ToUppercase\r
+\r
+#else\r
+\r
+# define PyUnicode_AsASCIIString PyUnicodeUCS4_AsASCIIString\r
+# define PyUnicode_AsCharmapString PyUnicodeUCS4_AsCharmapString\r
+# define PyUnicode_AsEncodedObject PyUnicodeUCS4_AsEncodedObject\r
+# define PyUnicode_AsEncodedString PyUnicodeUCS4_AsEncodedString\r
+# define PyUnicode_AsLatin1String PyUnicodeUCS4_AsLatin1String\r
+# define PyUnicode_AsRawUnicodeEscapeString PyUnicodeUCS4_AsRawUnicodeEscapeString\r
+# define PyUnicode_AsUTF32String PyUnicodeUCS4_AsUTF32String\r
+# define PyUnicode_AsUTF16String PyUnicodeUCS4_AsUTF16String\r
+# define PyUnicode_AsUTF8String PyUnicodeUCS4_AsUTF8String\r
+# define PyUnicode_AsUnicode PyUnicodeUCS4_AsUnicode\r
+# define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS4_AsUnicodeEscapeString\r
+# define PyUnicode_AsWideChar PyUnicodeUCS4_AsWideChar\r
+# define PyUnicode_ClearFreeList PyUnicodeUCS4_ClearFreelist\r
+# define PyUnicode_Compare PyUnicodeUCS4_Compare\r
+# define PyUnicode_Concat PyUnicodeUCS4_Concat\r
+# define PyUnicode_Contains PyUnicodeUCS4_Contains\r
+# define PyUnicode_Count PyUnicodeUCS4_Count\r
+# define PyUnicode_Decode PyUnicodeUCS4_Decode\r
+# define PyUnicode_DecodeASCII PyUnicodeUCS4_DecodeASCII\r
+# define PyUnicode_DecodeCharmap PyUnicodeUCS4_DecodeCharmap\r
+# define PyUnicode_DecodeLatin1 PyUnicodeUCS4_DecodeLatin1\r
+# define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS4_DecodeRawUnicodeEscape\r
+# define PyUnicode_DecodeUTF32 PyUnicodeUCS4_DecodeUTF32\r
+# define PyUnicode_DecodeUTF32Stateful PyUnicodeUCS4_DecodeUTF32Stateful\r
+# define PyUnicode_DecodeUTF16 PyUnicodeUCS4_DecodeUTF16\r
+# define PyUnicode_DecodeUTF16Stateful PyUnicodeUCS4_DecodeUTF16Stateful\r
+# define PyUnicode_DecodeUTF8 PyUnicodeUCS4_DecodeUTF8\r
+# define PyUnicode_DecodeUTF8Stateful PyUnicodeUCS4_DecodeUTF8Stateful\r
+# define PyUnicode_DecodeUnicodeEscape PyUnicodeUCS4_DecodeUnicodeEscape\r
+# define PyUnicode_Encode PyUnicodeUCS4_Encode\r
+# define PyUnicode_EncodeASCII PyUnicodeUCS4_EncodeASCII\r
+# define PyUnicode_EncodeCharmap PyUnicodeUCS4_EncodeCharmap\r
+# define PyUnicode_EncodeDecimal PyUnicodeUCS4_EncodeDecimal\r
+# define PyUnicode_EncodeLatin1 PyUnicodeUCS4_EncodeLatin1\r
+# define PyUnicode_EncodeRawUnicodeEscape PyUnicodeUCS4_EncodeRawUnicodeEscape\r
+# define PyUnicode_EncodeUTF32 PyUnicodeUCS4_EncodeUTF32\r
+# define PyUnicode_EncodeUTF16 PyUnicodeUCS4_EncodeUTF16\r
+# define PyUnicode_EncodeUTF8 PyUnicodeUCS4_EncodeUTF8\r
+# define PyUnicode_EncodeUnicodeEscape PyUnicodeUCS4_EncodeUnicodeEscape\r
+# define PyUnicode_Find PyUnicodeUCS4_Find\r
+# define PyUnicode_Format PyUnicodeUCS4_Format\r
+# define PyUnicode_FromEncodedObject PyUnicodeUCS4_FromEncodedObject\r
+# define PyUnicode_FromFormat PyUnicodeUCS4_FromFormat\r
+# define PyUnicode_FromFormatV PyUnicodeUCS4_FromFormatV\r
+# define PyUnicode_FromObject PyUnicodeUCS4_FromObject\r
+# define PyUnicode_FromOrdinal PyUnicodeUCS4_FromOrdinal\r
+# define PyUnicode_FromString PyUnicodeUCS4_FromString\r
+# define PyUnicode_FromStringAndSize PyUnicodeUCS4_FromStringAndSize\r
+# define PyUnicode_FromUnicode PyUnicodeUCS4_FromUnicode\r
+# define PyUnicode_FromWideChar PyUnicodeUCS4_FromWideChar\r
+# define PyUnicode_GetDefaultEncoding PyUnicodeUCS4_GetDefaultEncoding\r
+# define PyUnicode_GetMax PyUnicodeUCS4_GetMax\r
+# define PyUnicode_GetSize PyUnicodeUCS4_GetSize\r
+# define PyUnicode_Join PyUnicodeUCS4_Join\r
+# define PyUnicode_Partition PyUnicodeUCS4_Partition\r
+# define PyUnicode_RPartition PyUnicodeUCS4_RPartition\r
+# define PyUnicode_RSplit PyUnicodeUCS4_RSplit\r
+# define PyUnicode_Replace PyUnicodeUCS4_Replace\r
+# define PyUnicode_Resize PyUnicodeUCS4_Resize\r
+# define PyUnicode_RichCompare PyUnicodeUCS4_RichCompare\r
+# define PyUnicode_SetDefaultEncoding PyUnicodeUCS4_SetDefaultEncoding\r
+# define PyUnicode_Split PyUnicodeUCS4_Split\r
+# define PyUnicode_Splitlines PyUnicodeUCS4_Splitlines\r
+# define PyUnicode_Tailmatch PyUnicodeUCS4_Tailmatch\r
+# define PyUnicode_Translate PyUnicodeUCS4_Translate\r
+# define PyUnicode_TranslateCharmap PyUnicodeUCS4_TranslateCharmap\r
+# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS4_AsDefaultEncodedString\r
+# define _PyUnicode_Fini _PyUnicodeUCS4_Fini\r
+# define _PyUnicode_Init _PyUnicodeUCS4_Init\r
+# define _PyUnicode_IsAlpha _PyUnicodeUCS4_IsAlpha\r
+# define _PyUnicode_IsDecimalDigit _PyUnicodeUCS4_IsDecimalDigit\r
+# define _PyUnicode_IsDigit _PyUnicodeUCS4_IsDigit\r
+# define _PyUnicode_IsLinebreak _PyUnicodeUCS4_IsLinebreak\r
+# define _PyUnicode_IsLowercase _PyUnicodeUCS4_IsLowercase\r
+# define _PyUnicode_IsNumeric _PyUnicodeUCS4_IsNumeric\r
+# define _PyUnicode_IsTitlecase _PyUnicodeUCS4_IsTitlecase\r
+# define _PyUnicode_IsUppercase _PyUnicodeUCS4_IsUppercase\r
+# define _PyUnicode_IsWhitespace _PyUnicodeUCS4_IsWhitespace\r
+# define _PyUnicode_ToDecimalDigit _PyUnicodeUCS4_ToDecimalDigit\r
+# define _PyUnicode_ToDigit _PyUnicodeUCS4_ToDigit\r
+# define _PyUnicode_ToLowercase _PyUnicodeUCS4_ToLowercase\r
+# define _PyUnicode_ToNumeric _PyUnicodeUCS4_ToNumeric\r
+# define _PyUnicode_ToTitlecase _PyUnicodeUCS4_ToTitlecase\r
+# define _PyUnicode_ToUppercase _PyUnicodeUCS4_ToUppercase\r
+\r
+\r
+#endif\r
+\r
+/* --- Internal Unicode Operations ---------------------------------------- */\r
+\r
+/* If you want Python to use the compiler's wctype.h functions instead\r
+   of the ones supplied with Python, define WANT_WCTYPE_FUNCTIONS or\r
+   configure Python using --with-wctype-functions.  This reduces the\r
+   interpreter's code size. */\r
+\r
+#if defined(HAVE_USABLE_WCHAR_T) && defined(WANT_WCTYPE_FUNCTIONS)\r
+\r
+#include <wctype.h>\r
+\r
+#define Py_UNICODE_ISSPACE(ch) iswspace(ch)\r
+\r
+#define Py_UNICODE_ISLOWER(ch) iswlower(ch)\r
+#define Py_UNICODE_ISUPPER(ch) iswupper(ch)\r
+#define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch)\r
+#define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch)\r
+\r
+#define Py_UNICODE_TOLOWER(ch) towlower(ch)\r
+#define Py_UNICODE_TOUPPER(ch) towupper(ch)\r
+#define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch)\r
+\r
+#define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)\r
+#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)\r
+#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)\r
+\r
+#define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)\r
+#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)\r
+#define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch)\r
+\r
+#define Py_UNICODE_ISALPHA(ch) iswalpha(ch)\r
+\r
+#else\r
+\r
+/* Since splitting on whitespace is an important use case, and\r
+   whitespace in most situations is solely ASCII whitespace, we\r
+   optimize for the common case by using a quick look-up table\r
+   _Py_ascii_whitespace (see below) with an inlined check.\r
+\r
+ */\r
+#define Py_UNICODE_ISSPACE(ch) \\r
+    ((ch) < 128U ? _Py_ascii_whitespace[(ch)] : _PyUnicode_IsWhitespace(ch))\r
+\r
+#define Py_UNICODE_ISLOWER(ch) _PyUnicode_IsLowercase(ch)\r
+#define Py_UNICODE_ISUPPER(ch) _PyUnicode_IsUppercase(ch)\r
+#define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch)\r
+#define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch)\r
+\r
+#define Py_UNICODE_TOLOWER(ch) _PyUnicode_ToLowercase(ch)\r
+#define Py_UNICODE_TOUPPER(ch) _PyUnicode_ToUppercase(ch)\r
+#define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch)\r
+\r
+#define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)\r
+#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)\r
+#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)\r
+\r
+#define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)\r
+#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)\r
+#define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch)\r
+\r
+#define Py_UNICODE_ISALPHA(ch) _PyUnicode_IsAlpha(ch)\r
+\r
+#endif\r
+\r
+#define Py_UNICODE_ISALNUM(ch) \\r
+       (Py_UNICODE_ISALPHA(ch) || \\r
+    Py_UNICODE_ISDECIMAL(ch) || \\r
+    Py_UNICODE_ISDIGIT(ch) || \\r
+    Py_UNICODE_ISNUMERIC(ch))\r
+\r
+#define Py_UNICODE_COPY(target, source, length)                         \\r
+    Py_MEMCPY((target), (source), (length)*sizeof(Py_UNICODE))\r
+\r
+#define Py_UNICODE_FILL(target, value, length) \\r
+    do {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\\r
+    for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\\r
+    } while (0)\r
+\r
+/* Check if substring matches at given offset.  the offset must be\r
+   valid, and the substring must not be empty */\r
+\r
+#define Py_UNICODE_MATCH(string, offset, substring) \\r
+    ((*((string)->str + (offset)) == *((substring)->str)) && \\r
+    ((*((string)->str + (offset) + (substring)->length-1) == *((substring)->str + (substring)->length-1))) && \\r
+     !memcmp((string)->str + (offset), (substring)->str, (substring)->length*sizeof(Py_UNICODE)))\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* --- Unicode Type ------------------------------------------------------- */\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+    Py_ssize_t length;          /* Length of raw Unicode data in buffer */\r
+    Py_UNICODE *str;            /* Raw Unicode buffer */\r
+    long hash;                  /* Hash value; -1 if not set */\r
+    PyObject *defenc;           /* (Default) Encoded version as Python\r
+                                   string, or NULL; this is used for\r
+                                   implementing the buffer protocol */\r
+} PyUnicodeObject;\r
+\r
+PyAPI_DATA(PyTypeObject) PyUnicode_Type;\r
+\r
+#define PyUnicode_Check(op) \\r
+                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)\r
+#define PyUnicode_CheckExact(op) (Py_TYPE(op) == &PyUnicode_Type)\r
+\r
+/* Fast access macros */\r
+#define PyUnicode_GET_SIZE(op) \\r
+    (((PyUnicodeObject *)(op))->length)\r
+#define PyUnicode_GET_DATA_SIZE(op) \\r
+    (((PyUnicodeObject *)(op))->length * sizeof(Py_UNICODE))\r
+#define PyUnicode_AS_UNICODE(op) \\r
+    (((PyUnicodeObject *)(op))->str)\r
+#define PyUnicode_AS_DATA(op) \\r
+    ((const char *)((PyUnicodeObject *)(op))->str)\r
+\r
+/* --- Constants ---------------------------------------------------------- */\r
+\r
+/* This Unicode character will be used as replacement character during\r
+   decoding if the errors argument is set to "replace". Note: the\r
+   Unicode character U+FFFD is the official REPLACEMENT CHARACTER in\r
+   Unicode 3.0. */\r
+\r
+#define Py_UNICODE_REPLACEMENT_CHARACTER ((Py_UNICODE) 0xFFFD)\r
+\r
+/* === Public API ========================================================= */\r
+\r
+/* --- Plain Py_UNICODE --------------------------------------------------- */\r
+\r
+/* Create a Unicode Object from the Py_UNICODE buffer u of the given\r
+   size.\r
+\r
+   u may be NULL which causes the contents to be undefined. It is the\r
+   user's responsibility to fill in the needed data afterwards. Note\r
+   that modifying the Unicode object contents after construction is\r
+   only allowed if u was set to NULL.\r
+\r
+   The buffer is copied into the new object. */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(\r
+    const Py_UNICODE *u,        /* Unicode buffer */\r
+    Py_ssize_t size             /* size of buffer */\r
+    );\r
+\r
+/* Similar to PyUnicode_FromUnicode(), but u points to Latin-1 encoded bytes */\r
+PyAPI_FUNC(PyObject*) PyUnicode_FromStringAndSize(\r
+    const char *u,        /* char buffer */\r
+    Py_ssize_t size       /* size of buffer */\r
+    );\r
+\r
+/* Similar to PyUnicode_FromUnicode(), but u points to null-terminated\r
+   Latin-1 encoded bytes */\r
+PyAPI_FUNC(PyObject*) PyUnicode_FromString(\r
+    const char *u        /* string */\r
+    );\r
+\r
+/* Return a read-only pointer to the Unicode object's internal\r
+   Py_UNICODE buffer. */\r
+\r
+PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(\r
+    PyObject *unicode           /* Unicode object */\r
+    );\r
+\r
+/* Get the length of the Unicode object. */\r
+\r
+PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(\r
+    PyObject *unicode           /* Unicode object */\r
+    );\r
+\r
+/* Get the maximum ordinal for a Unicode character. */\r
+PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void);\r
+\r
+/* Resize an already allocated Unicode object to the new size length.\r
+\r
+   *unicode is modified to point to the new (resized) object and 0\r
+   returned on success.\r
+\r
+   This API may only be called by the function which also called the\r
+   Unicode constructor. The refcount on the object must be 1. Otherwise,\r
+   an error is returned.\r
+\r
+   Error handling is implemented as follows: an exception is set, -1\r
+   is returned and *unicode left untouched.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(int) PyUnicode_Resize(\r
+    PyObject **unicode,         /* Pointer to the Unicode object */\r
+    Py_ssize_t length           /* New length */\r
+    );\r
+\r
+/* Coerce obj to an Unicode object and return a reference with\r
+   *incremented* refcount.\r
+\r
+   Coercion is done in the following way:\r
+\r
+   1. String and other char buffer compatible objects are decoded\r
+      under the assumptions that they contain data using the current\r
+      default encoding. Decoding is done in "strict" mode.\r
+\r
+   2. All other objects (including Unicode objects) raise an\r
+      exception.\r
+\r
+   The API returns NULL in case of an error. The caller is responsible\r
+   for decref'ing the returned objects.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_FromEncodedObject(\r
+    register PyObject *obj,     /* Object */\r
+    const char *encoding,       /* encoding */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+/* Coerce obj to an Unicode object and return a reference with\r
+   *incremented* refcount.\r
+\r
+   Unicode objects are passed back as-is (subclasses are converted to\r
+   true Unicode objects), all other objects are delegated to\r
+   PyUnicode_FromEncodedObject(obj, NULL, "strict") which results in\r
+   using the default encoding as basis for decoding the object.\r
+\r
+   The API returns NULL in case of an error. The caller is responsible\r
+   for decref'ing the returned objects.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_FromObject(\r
+    register PyObject *obj      /* Object */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject *) PyUnicode_FromFormatV(const char*, va_list);\r
+PyAPI_FUNC(PyObject *) PyUnicode_FromFormat(const char*, ...);\r
+\r
+/* Format the object based on the format_spec, as defined in PEP 3101\r
+   (Advanced String Formatting). */\r
+PyAPI_FUNC(PyObject *) _PyUnicode_FormatAdvanced(PyObject *obj,\r
+                                                 Py_UNICODE *format_spec,\r
+                                                 Py_ssize_t format_spec_len);\r
+\r
+/* --- wchar_t support for platforms which support it --------------------- */\r
+\r
+#ifdef HAVE_WCHAR_H\r
+\r
+/* Create a Unicode Object from the whcar_t buffer w of the given\r
+   size.\r
+\r
+   The buffer is copied into the new object. */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_FromWideChar(\r
+    register const wchar_t *w,  /* wchar_t buffer */\r
+    Py_ssize_t size             /* size of buffer */\r
+    );\r
+\r
+/* Copies the Unicode Object contents into the wchar_t buffer w.  At\r
+   most size wchar_t characters are copied.\r
+\r
+   Note that the resulting wchar_t string may or may not be\r
+   0-terminated.  It is the responsibility of the caller to make sure\r
+   that the wchar_t string is 0-terminated in case this is required by\r
+   the application.\r
+\r
+   Returns the number of wchar_t characters copied (excluding a\r
+   possibly trailing 0-termination character) or -1 in case of an\r
+   error. */\r
+\r
+PyAPI_FUNC(Py_ssize_t) PyUnicode_AsWideChar(\r
+    PyUnicodeObject *unicode,   /* Unicode object */\r
+    register wchar_t *w,        /* wchar_t buffer */\r
+    Py_ssize_t size             /* size of buffer */\r
+    );\r
+\r
+#endif\r
+\r
+/* --- Unicode ordinals --------------------------------------------------- */\r
+\r
+/* Create a Unicode Object from the given Unicode code point ordinal.\r
+\r
+   The ordinal must be in range(0x10000) on narrow Python builds\r
+   (UCS2), and range(0x110000) on wide builds (UCS4). A ValueError is\r
+   raised in case it is not.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_FromOrdinal(int ordinal);\r
+\r
+/* --- Free-list management ----------------------------------------------- */\r
+\r
+/* Clear the free list used by the Unicode implementation.\r
+\r
+   This can be used to release memory used for objects on the free\r
+   list back to the Python memory allocator.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(int) PyUnicode_ClearFreeList(void);\r
+\r
+/* === Builtin Codecs =====================================================\r
+\r
+   Many of these APIs take two arguments encoding and errors. These\r
+   parameters encoding and errors have the same semantics as the ones\r
+   of the builtin unicode() API.\r
+\r
+   Setting encoding to NULL causes the default encoding to be used.\r
+\r
+   Error handling is set by errors which may also be set to NULL\r
+   meaning to use the default handling defined for the codec. Default\r
+   error handling for all builtin codecs is "strict" (ValueErrors are\r
+   raised).\r
+\r
+   The codecs all use a similar interface. Only deviation from the\r
+   generic ones are documented.\r
+\r
+*/\r
+\r
+/* --- Manage the default encoding ---------------------------------------- */\r
+\r
+/* Return a Python string holding the default encoded value of the\r
+   Unicode object.\r
+\r
+   The resulting string is cached in the Unicode object for subsequent\r
+   usage by this function. The cached version is needed to implement\r
+   the character buffer interface and will live (at least) as long as\r
+   the Unicode object itself.\r
+\r
+   The refcount of the string is *not* incremented.\r
+\r
+   *** Exported for internal use by the interpreter only !!! ***\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject *) _PyUnicode_AsDefaultEncodedString(\r
+    PyObject *, const char *);\r
+\r
+/* Returns the currently active default encoding.\r
+\r
+   The default encoding is currently implemented as run-time settable\r
+   process global.  This may change in future versions of the\r
+   interpreter to become a parameter which is managed on a per-thread\r
+   basis.\r
+\r
+ */\r
+\r
+PyAPI_FUNC(const char*) PyUnicode_GetDefaultEncoding(void);\r
+\r
+/* Sets the currently active default encoding.\r
+\r
+   Returns 0 on success, -1 in case of an error.\r
+\r
+ */\r
+\r
+PyAPI_FUNC(int) PyUnicode_SetDefaultEncoding(\r
+    const char *encoding        /* Encoding name in standard form */\r
+    );\r
+\r
+/* --- Generic Codecs ----------------------------------------------------- */\r
+\r
+/* Create a Unicode object by decoding the encoded string s of the\r
+   given size. */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_Decode(\r
+    const char *s,              /* encoded string */\r
+    Py_ssize_t size,            /* size of buffer */\r
+    const char *encoding,       /* encoding */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+/* Encodes a Py_UNICODE buffer of the given size and returns a\r
+   Python string object. */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_Encode(\r
+    const Py_UNICODE *s,        /* Unicode char buffer */\r
+    Py_ssize_t size,            /* number of Py_UNICODE chars to encode */\r
+    const char *encoding,       /* encoding */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+/* Encodes a Unicode object and returns the result as Python\r
+   object. */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedObject(\r
+    PyObject *unicode,          /* Unicode object */\r
+    const char *encoding,       /* encoding */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+/* Encodes a Unicode object and returns the result as Python string\r
+   object. */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedString(\r
+    PyObject *unicode,          /* Unicode object */\r
+    const char *encoding,       /* encoding */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_BuildEncodingMap(\r
+    PyObject* string            /* 256 character map */\r
+   );\r
+\r
+\r
+/* --- UTF-7 Codecs ------------------------------------------------------- */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7(\r
+    const char *string,         /* UTF-7 encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7Stateful(\r
+    const char *string,         /* UTF-7 encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    const char *errors,         /* error handling */\r
+    Py_ssize_t *consumed        /* bytes consumed */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7(\r
+    const Py_UNICODE *data,     /* Unicode char buffer */\r
+    Py_ssize_t length,                  /* number of Py_UNICODE chars to encode */\r
+    int base64SetO,             /* Encode RFC2152 Set O characters in base64 */\r
+    int base64WhiteSpace,       /* Encode whitespace (sp, ht, nl, cr) in base64 */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+/* --- UTF-8 Codecs ------------------------------------------------------- */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8(\r
+    const char *string,         /* UTF-8 encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8Stateful(\r
+    const char *string,         /* UTF-8 encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    const char *errors,         /* error handling */\r
+    Py_ssize_t *consumed                /* bytes consumed */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_AsUTF8String(\r
+    PyObject *unicode           /* Unicode object */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF8(\r
+    const Py_UNICODE *data,     /* Unicode char buffer */\r
+    Py_ssize_t length,                  /* number of Py_UNICODE chars to encode */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+/* --- UTF-32 Codecs ------------------------------------------------------ */\r
+\r
+/* Decodes length bytes from a UTF-32 encoded buffer string and returns\r
+   the corresponding Unicode object.\r
+\r
+   errors (if non-NULL) defines the error handling. It defaults\r
+   to "strict".\r
+\r
+   If byteorder is non-NULL, the decoder starts decoding using the\r
+   given byte order:\r
+\r
+    *byteorder == -1: little endian\r
+    *byteorder == 0:  native order\r
+    *byteorder == 1:  big endian\r
+\r
+   In native mode, the first four bytes of the stream are checked for a\r
+   BOM mark. If found, the BOM mark is analysed, the byte order\r
+   adjusted and the BOM skipped.  In the other modes, no BOM mark\r
+   interpretation is done. After completion, *byteorder is set to the\r
+   current byte order at the end of input data.\r
+\r
+   If byteorder is NULL, the codec starts in native order mode.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF32(\r
+    const char *string,         /* UTF-32 encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    const char *errors,         /* error handling */\r
+    int *byteorder              /* pointer to byteorder to use\r
+                                   0=native;-1=LE,1=BE; updated on\r
+                                   exit */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF32Stateful(\r
+    const char *string,         /* UTF-32 encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    const char *errors,         /* error handling */\r
+    int *byteorder,             /* pointer to byteorder to use\r
+                                   0=native;-1=LE,1=BE; updated on\r
+                                   exit */\r
+    Py_ssize_t *consumed        /* bytes consumed */\r
+    );\r
+\r
+/* Returns a Python string using the UTF-32 encoding in native byte\r
+   order. The string always starts with a BOM mark.  */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_AsUTF32String(\r
+    PyObject *unicode           /* Unicode object */\r
+    );\r
+\r
+/* Returns a Python string object holding the UTF-32 encoded value of\r
+   the Unicode data.\r
+\r
+   If byteorder is not 0, output is written according to the following\r
+   byte order:\r
+\r
+   byteorder == -1: little endian\r
+   byteorder == 0:  native byte order (writes a BOM mark)\r
+   byteorder == 1:  big endian\r
+\r
+   If byteorder is 0, the output string will always start with the\r
+   Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is\r
+   prepended.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF32(\r
+    const Py_UNICODE *data,     /* Unicode char buffer */\r
+    Py_ssize_t length,          /* number of Py_UNICODE chars to encode */\r
+    const char *errors,         /* error handling */\r
+    int byteorder               /* byteorder to use 0=BOM+native;-1=LE,1=BE */\r
+    );\r
+\r
+/* --- UTF-16 Codecs ------------------------------------------------------ */\r
+\r
+/* Decodes length bytes from a UTF-16 encoded buffer string and returns\r
+   the corresponding Unicode object.\r
+\r
+   errors (if non-NULL) defines the error handling. It defaults\r
+   to "strict".\r
+\r
+   If byteorder is non-NULL, the decoder starts decoding using the\r
+   given byte order:\r
+\r
+    *byteorder == -1: little endian\r
+    *byteorder == 0:  native order\r
+    *byteorder == 1:  big endian\r
+\r
+   In native mode, the first two bytes of the stream are checked for a\r
+   BOM mark. If found, the BOM mark is analysed, the byte order\r
+   adjusted and the BOM skipped.  In the other modes, no BOM mark\r
+   interpretation is done. After completion, *byteorder is set to the\r
+   current byte order at the end of input data.\r
+\r
+   If byteorder is NULL, the codec starts in native order mode.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16(\r
+    const char *string,         /* UTF-16 encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    const char *errors,         /* error handling */\r
+    int *byteorder              /* pointer to byteorder to use\r
+                                   0=native;-1=LE,1=BE; updated on\r
+                                   exit */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16Stateful(\r
+    const char *string,         /* UTF-16 encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    const char *errors,         /* error handling */\r
+    int *byteorder,             /* pointer to byteorder to use\r
+                                   0=native;-1=LE,1=BE; updated on\r
+                                   exit */\r
+    Py_ssize_t *consumed                /* bytes consumed */\r
+    );\r
+\r
+/* Returns a Python string using the UTF-16 encoding in native byte\r
+   order. The string always starts with a BOM mark.  */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_AsUTF16String(\r
+    PyObject *unicode           /* Unicode object */\r
+    );\r
+\r
+/* Returns a Python string object holding the UTF-16 encoded value of\r
+   the Unicode data.\r
+\r
+   If byteorder is not 0, output is written according to the following\r
+   byte order:\r
+\r
+   byteorder == -1: little endian\r
+   byteorder == 0:  native byte order (writes a BOM mark)\r
+   byteorder == 1:  big endian\r
+\r
+   If byteorder is 0, the output string will always start with the\r
+   Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is\r
+   prepended.\r
+\r
+   Note that Py_UNICODE data is being interpreted as UTF-16 reduced to\r
+   UCS-2. This trick makes it possible to add full UTF-16 capabilities\r
+   at a later point without compromising the APIs.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF16(\r
+    const Py_UNICODE *data,     /* Unicode char buffer */\r
+    Py_ssize_t length,                  /* number of Py_UNICODE chars to encode */\r
+    const char *errors,         /* error handling */\r
+    int byteorder               /* byteorder to use 0=BOM+native;-1=LE,1=BE */\r
+    );\r
+\r
+/* --- Unicode-Escape Codecs ---------------------------------------------- */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeUnicodeEscape(\r
+    const char *string,         /* Unicode-Escape encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_AsUnicodeEscapeString(\r
+    PyObject *unicode           /* Unicode object */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_EncodeUnicodeEscape(\r
+    const Py_UNICODE *data,     /* Unicode char buffer */\r
+    Py_ssize_t length                   /* Number of Py_UNICODE chars to encode */\r
+    );\r
+\r
+/* --- Raw-Unicode-Escape Codecs ------------------------------------------ */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeRawUnicodeEscape(\r
+    const char *string,         /* Raw-Unicode-Escape encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_AsRawUnicodeEscapeString(\r
+    PyObject *unicode           /* Unicode object */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_EncodeRawUnicodeEscape(\r
+    const Py_UNICODE *data,     /* Unicode char buffer */\r
+    Py_ssize_t length                   /* Number of Py_UNICODE chars to encode */\r
+    );\r
+\r
+/* --- Unicode Internal Codec ---------------------------------------------\r
+\r
+    Only for internal use in _codecsmodule.c */\r
+\r
+PyObject *_PyUnicode_DecodeUnicodeInternal(\r
+    const char *string,\r
+    Py_ssize_t length,\r
+    const char *errors\r
+    );\r
+\r
+/* --- Latin-1 Codecs -----------------------------------------------------\r
+\r
+   Note: Latin-1 corresponds to the first 256 Unicode ordinals.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeLatin1(\r
+    const char *string,         /* Latin-1 encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_AsLatin1String(\r
+    PyObject *unicode           /* Unicode object */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_EncodeLatin1(\r
+    const Py_UNICODE *data,     /* Unicode char buffer */\r
+    Py_ssize_t length,                  /* Number of Py_UNICODE chars to encode */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+/* --- ASCII Codecs -------------------------------------------------------\r
+\r
+   Only 7-bit ASCII data is excepted. All other codes generate errors.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeASCII(\r
+    const char *string,         /* ASCII encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_AsASCIIString(\r
+    PyObject *unicode           /* Unicode object */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_EncodeASCII(\r
+    const Py_UNICODE *data,     /* Unicode char buffer */\r
+    Py_ssize_t length,                  /* Number of Py_UNICODE chars to encode */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+/* --- Character Map Codecs -----------------------------------------------\r
+\r
+   This codec uses mappings to encode and decode characters.\r
+\r
+   Decoding mappings must map single string characters to single\r
+   Unicode characters, integers (which are then interpreted as Unicode\r
+   ordinals) or None (meaning "undefined mapping" and causing an\r
+   error).\r
+\r
+   Encoding mappings must map single Unicode characters to single\r
+   string characters, integers (which are then interpreted as Latin-1\r
+   ordinals) or None (meaning "undefined mapping" and causing an\r
+   error).\r
+\r
+   If a character lookup fails with a LookupError, the character is\r
+   copied as-is meaning that its ordinal value will be interpreted as\r
+   Unicode or Latin-1 ordinal resp. Because of this mappings only need\r
+   to contain those mappings which map characters to different code\r
+   points.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeCharmap(\r
+    const char *string,         /* Encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    PyObject *mapping,          /* character mapping\r
+                                   (char ordinal -> unicode ordinal) */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_AsCharmapString(\r
+    PyObject *unicode,          /* Unicode object */\r
+    PyObject *mapping           /* character mapping\r
+                                   (unicode ordinal -> char ordinal) */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_EncodeCharmap(\r
+    const Py_UNICODE *data,     /* Unicode char buffer */\r
+    Py_ssize_t length,          /* Number of Py_UNICODE chars to encode */\r
+    PyObject *mapping,          /* character mapping\r
+                                   (unicode ordinal -> char ordinal) */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+/* Translate a Py_UNICODE buffer of the given length by applying a\r
+   character mapping table to it and return the resulting Unicode\r
+   object.\r
+\r
+   The mapping table must map Unicode ordinal integers to Unicode\r
+   ordinal integers or None (causing deletion of the character).\r
+\r
+   Mapping tables may be dictionaries or sequences. Unmapped character\r
+   ordinals (ones which cause a LookupError) are left untouched and\r
+   are copied as-is.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject *) PyUnicode_TranslateCharmap(\r
+    const Py_UNICODE *data,     /* Unicode char buffer */\r
+    Py_ssize_t length,                  /* Number of Py_UNICODE chars to encode */\r
+    PyObject *table,            /* Translate table */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+#ifdef MS_WIN32\r
+\r
+/* --- MBCS codecs for Windows -------------------------------------------- */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCS(\r
+    const char *string,         /* MBCS encoded string */\r
+    Py_ssize_t length,              /* size of string */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCSStateful(\r
+    const char *string,         /* MBCS encoded string */\r
+    Py_ssize_t length,          /* size of string */\r
+    const char *errors,         /* error handling */\r
+    Py_ssize_t *consumed        /* bytes consumed */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_AsMBCSString(\r
+    PyObject *unicode           /* Unicode object */\r
+    );\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS(\r
+    const Py_UNICODE *data,     /* Unicode char buffer */\r
+    Py_ssize_t length,              /* Number of Py_UNICODE chars to encode */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+#endif /* MS_WIN32 */\r
+\r
+/* --- Decimal Encoder ---------------------------------------------------- */\r
+\r
+/* Takes a Unicode string holding a decimal value and writes it into\r
+   an output buffer using standard ASCII digit codes.\r
+\r
+   The output buffer has to provide at least length+1 bytes of storage\r
+   area. The output string is 0-terminated.\r
+\r
+   The encoder converts whitespace to ' ', decimal characters to their\r
+   corresponding ASCII digit and all other Latin-1 characters except\r
+   \0 as-is. Characters outside this range (Unicode ordinals 1-256)\r
+   are treated as errors. This includes embedded NULL bytes.\r
+\r
+   Error handling is defined by the errors argument:\r
+\r
+      NULL or "strict": raise a ValueError\r
+      "ignore": ignore the wrong characters (these are not copied to the\r
+                output buffer)\r
+      "replace": replaces illegal characters with '?'\r
+\r
+   Returns 0 on success, -1 on failure.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(int) PyUnicode_EncodeDecimal(\r
+    Py_UNICODE *s,              /* Unicode buffer */\r
+    Py_ssize_t length,                  /* Number of Py_UNICODE chars to encode */\r
+    char *output,               /* Output buffer; must have size >= length */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+/* --- Methods & Slots ----------------------------------------------------\r
+\r
+   These are capable of handling Unicode objects and strings on input\r
+   (we refer to them as strings in the descriptions) and return\r
+   Unicode objects or integers as apporpriate. */\r
+\r
+/* Concat two strings giving a new Unicode string. */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_Concat(\r
+    PyObject *left,             /* Left string */\r
+    PyObject *right             /* Right string */\r
+    );\r
+\r
+/* Split a string giving a list of Unicode strings.\r
+\r
+   If sep is NULL, splitting will be done at all whitespace\r
+   substrings. Otherwise, splits occur at the given separator.\r
+\r
+   At most maxsplit splits will be done. If negative, no limit is set.\r
+\r
+   Separators are not included in the resulting list.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_Split(\r
+    PyObject *s,                /* String to split */\r
+    PyObject *sep,              /* String separator */\r
+    Py_ssize_t maxsplit         /* Maxsplit count */\r
+    );\r
+\r
+/* Dito, but split at line breaks.\r
+\r
+   CRLF is considered to be one line break. Line breaks are not\r
+   included in the resulting list. */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_Splitlines(\r
+    PyObject *s,                /* String to split */\r
+    int keepends                /* If true, line end markers are included */\r
+    );\r
+\r
+/* Partition a string using a given separator. */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_Partition(\r
+    PyObject *s,                /* String to partition */\r
+    PyObject *sep               /* String separator */\r
+    );\r
+\r
+/* Partition a string using a given separator, searching from the end of the\r
+   string. */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_RPartition(\r
+    PyObject *s,                /* String to partition */\r
+    PyObject *sep               /* String separator */\r
+    );\r
+\r
+/* Split a string giving a list of Unicode strings.\r
+\r
+   If sep is NULL, splitting will be done at all whitespace\r
+   substrings. Otherwise, splits occur at the given separator.\r
+\r
+   At most maxsplit splits will be done. But unlike PyUnicode_Split\r
+   PyUnicode_RSplit splits from the end of the string. If negative,\r
+   no limit is set.\r
+\r
+   Separators are not included in the resulting list.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_RSplit(\r
+    PyObject *s,                /* String to split */\r
+    PyObject *sep,              /* String separator */\r
+    Py_ssize_t maxsplit         /* Maxsplit count */\r
+    );\r
+\r
+/* Translate a string by applying a character mapping table to it and\r
+   return the resulting Unicode object.\r
+\r
+   The mapping table must map Unicode ordinal integers to Unicode\r
+   ordinal integers or None (causing deletion of the character).\r
+\r
+   Mapping tables may be dictionaries or sequences. Unmapped character\r
+   ordinals (ones which cause a LookupError) are left untouched and\r
+   are copied as-is.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject *) PyUnicode_Translate(\r
+    PyObject *str,              /* String */\r
+    PyObject *table,            /* Translate table */\r
+    const char *errors          /* error handling */\r
+    );\r
+\r
+/* Join a sequence of strings using the given separator and return\r
+   the resulting Unicode string. */\r
+\r
+PyAPI_FUNC(PyObject*) PyUnicode_Join(\r
+    PyObject *separator,        /* Separator string */\r
+    PyObject *seq               /* Sequence object */\r
+    );\r
+\r
+/* Return 1 if substr matches str[start:end] at the given tail end, 0\r
+   otherwise. */\r
+\r
+PyAPI_FUNC(Py_ssize_t) PyUnicode_Tailmatch(\r
+    PyObject *str,              /* String */\r
+    PyObject *substr,           /* Prefix or Suffix string */\r
+    Py_ssize_t start,           /* Start index */\r
+    Py_ssize_t end,             /* Stop index */\r
+    int direction               /* Tail end: -1 prefix, +1 suffix */\r
+    );\r
+\r
+/* Return the first position of substr in str[start:end] using the\r
+   given search direction or -1 if not found. -2 is returned in case\r
+   an error occurred and an exception is set. */\r
+\r
+PyAPI_FUNC(Py_ssize_t) PyUnicode_Find(\r
+    PyObject *str,              /* String */\r
+    PyObject *substr,           /* Substring to find */\r
+    Py_ssize_t start,           /* Start index */\r
+    Py_ssize_t end,             /* Stop index */\r
+    int direction               /* Find direction: +1 forward, -1 backward */\r
+    );\r
+\r
+/* Count the number of occurrences of substr in str[start:end]. */\r
+\r
+PyAPI_FUNC(Py_ssize_t) PyUnicode_Count(\r
+    PyObject *str,              /* String */\r
+    PyObject *substr,           /* Substring to count */\r
+    Py_ssize_t start,           /* Start index */\r
+    Py_ssize_t end              /* Stop index */\r
+    );\r
+\r
+/* Replace at most maxcount occurrences of substr in str with replstr\r
+   and return the resulting Unicode object. */\r
+\r
+PyAPI_FUNC(PyObject *) PyUnicode_Replace(\r
+    PyObject *str,              /* String */\r
+    PyObject *substr,           /* Substring to find */\r
+    PyObject *replstr,          /* Substring to replace */\r
+    Py_ssize_t maxcount         /* Max. number of replacements to apply;\r
+                                   -1 = all */\r
+    );\r
+\r
+/* Compare two strings and return -1, 0, 1 for less than, equal,\r
+   greater than resp. */\r
+\r
+PyAPI_FUNC(int) PyUnicode_Compare(\r
+    PyObject *left,             /* Left string */\r
+    PyObject *right             /* Right string */\r
+    );\r
+\r
+/* Rich compare two strings and return one of the following:\r
+\r
+   - NULL in case an exception was raised\r
+   - Py_True or Py_False for successfuly comparisons\r
+   - Py_NotImplemented in case the type combination is unknown\r
+\r
+   Note that Py_EQ and Py_NE comparisons can cause a UnicodeWarning in\r
+   case the conversion of the arguments to Unicode fails with a\r
+   UnicodeDecodeError.\r
+\r
+   Possible values for op:\r
+\r
+     Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE\r
+\r
+*/\r
+\r
+PyAPI_FUNC(PyObject *) PyUnicode_RichCompare(\r
+    PyObject *left,             /* Left string */\r
+    PyObject *right,            /* Right string */\r
+    int op                      /* Operation: Py_EQ, Py_NE, Py_GT, etc. */\r
+    );\r
+\r
+/* Apply a argument tuple or dictionary to a format string and return\r
+   the resulting Unicode string. */\r
+\r
+PyAPI_FUNC(PyObject *) PyUnicode_Format(\r
+    PyObject *format,           /* Format string */\r
+    PyObject *args              /* Argument tuple or dictionary */\r
+    );\r
+\r
+/* Checks whether element is contained in container and return 1/0\r
+   accordingly.\r
+\r
+   element has to coerce to an one element Unicode string. -1 is\r
+   returned in case of an error. */\r
+\r
+PyAPI_FUNC(int) PyUnicode_Contains(\r
+    PyObject *container,        /* Container string */\r
+    PyObject *element           /* Element string */\r
+    );\r
+\r
+/* Externally visible for str.strip(unicode) */\r
+PyAPI_FUNC(PyObject *) _PyUnicode_XStrip(\r
+    PyUnicodeObject *self,\r
+    int striptype,\r
+    PyObject *sepobj\r
+    );\r
+\r
+/* === Characters Type APIs =============================================== */\r
+\r
+/* Helper array used by Py_UNICODE_ISSPACE(). */\r
+\r
+PyAPI_DATA(const unsigned char) _Py_ascii_whitespace[];\r
+\r
+/* These should not be used directly. Use the Py_UNICODE_IS* and\r
+   Py_UNICODE_TO* macros instead.\r
+\r
+   These APIs are implemented in Objects/unicodectype.c.\r
+\r
+*/\r
+\r
+PyAPI_FUNC(int) _PyUnicode_IsLowercase(\r
+    Py_UNICODE ch       /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(int) _PyUnicode_IsUppercase(\r
+    Py_UNICODE ch       /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(int) _PyUnicode_IsTitlecase(\r
+    Py_UNICODE ch       /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(int) _PyUnicode_IsWhitespace(\r
+    const Py_UNICODE ch         /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(int) _PyUnicode_IsLinebreak(\r
+    const Py_UNICODE ch         /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToLowercase(\r
+    Py_UNICODE ch       /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToUppercase(\r
+    Py_UNICODE ch       /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToTitlecase(\r
+    Py_UNICODE ch       /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(int) _PyUnicode_ToDecimalDigit(\r
+    Py_UNICODE ch       /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(int) _PyUnicode_ToDigit(\r
+    Py_UNICODE ch       /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(double) _PyUnicode_ToNumeric(\r
+    Py_UNICODE ch       /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(int) _PyUnicode_IsDecimalDigit(\r
+    Py_UNICODE ch       /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(int) _PyUnicode_IsDigit(\r
+    Py_UNICODE ch       /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(int) _PyUnicode_IsNumeric(\r
+    Py_UNICODE ch       /* Unicode character */\r
+    );\r
+\r
+PyAPI_FUNC(int) _PyUnicode_IsAlpha(\r
+    Py_UNICODE ch       /* Unicode character */\r
+    );\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* Py_USING_UNICODE */\r
+#endif /* !Py_UNICODEOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/warnings.h b/AppPkg/Applications/Python/Python-2.7.10/Include/warnings.h
new file mode 100644 (file)
index 0000000..bf8f963
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef Py_WARNINGS_H\r
+#define Py_WARNINGS_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+PyAPI_FUNC(void) _PyWarnings_Init(void);\r
+\r
+PyAPI_FUNC(int) PyErr_WarnEx(PyObject *, const char *, Py_ssize_t);\r
+PyAPI_FUNC(int) PyErr_WarnExplicit(PyObject *, const char *, const char *, int,\r
+                                    const char *, PyObject *);\r
+\r
+#define PyErr_WarnPy3k(msg, stacklevel) \\r
+  (Py_Py3kWarningFlag ? PyErr_WarnEx(PyExc_DeprecationWarning, msg, stacklevel) : 0)\r
+\r
+/* DEPRECATED: Use PyErr_WarnEx() instead. */\r
+#define PyErr_Warn(category, msg) PyErr_WarnEx(category, msg, 1)\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_WARNINGS_H */\r
+\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Include/weakrefobject.h b/AppPkg/Applications/Python/Python-2.7.10/Include/weakrefobject.h
new file mode 100644 (file)
index 0000000..49c23b1
--- /dev/null
@@ -0,0 +1,82 @@
+/* Weak references objects for Python. */\r
+\r
+#ifndef Py_WEAKREFOBJECT_H\r
+#define Py_WEAKREFOBJECT_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+typedef struct _PyWeakReference PyWeakReference;\r
+\r
+/* PyWeakReference is the base struct for the Python ReferenceType, ProxyType,\r
+ * and CallableProxyType.\r
+ */\r
+struct _PyWeakReference {\r
+    PyObject_HEAD\r
+\r
+    /* The object to which this is a weak reference, or Py_None if none.\r
+     * Note that this is a stealth reference:  wr_object's refcount is\r
+     * not incremented to reflect this pointer.\r
+     */\r
+    PyObject *wr_object;\r
+\r
+    /* A callable to invoke when wr_object dies, or NULL if none. */\r
+    PyObject *wr_callback;\r
+\r
+    /* A cache for wr_object's hash code.  As usual for hashes, this is -1\r
+     * if the hash code isn't known yet.\r
+     */\r
+    long hash;\r
+\r
+    /* If wr_object is weakly referenced, wr_object has a doubly-linked NULL-\r
+     * terminated list of weak references to it.  These are the list pointers.\r
+     * If wr_object goes away, wr_object is set to Py_None, and these pointers\r
+     * have no meaning then.\r
+     */\r
+    PyWeakReference *wr_prev;\r
+    PyWeakReference *wr_next;\r
+};\r
+\r
+PyAPI_DATA(PyTypeObject) _PyWeakref_RefType;\r
+PyAPI_DATA(PyTypeObject) _PyWeakref_ProxyType;\r
+PyAPI_DATA(PyTypeObject) _PyWeakref_CallableProxyType;\r
+\r
+#define PyWeakref_CheckRef(op) PyObject_TypeCheck(op, &_PyWeakref_RefType)\r
+#define PyWeakref_CheckRefExact(op) \\r
+        (Py_TYPE(op) == &_PyWeakref_RefType)\r
+#define PyWeakref_CheckProxy(op) \\r
+        ((Py_TYPE(op) == &_PyWeakref_ProxyType) || \\r
+         (Py_TYPE(op) == &_PyWeakref_CallableProxyType))\r
+\r
+#define PyWeakref_Check(op) \\r
+        (PyWeakref_CheckRef(op) || PyWeakref_CheckProxy(op))\r
+\r
+\r
+PyAPI_FUNC(PyObject *) PyWeakref_NewRef(PyObject *ob,\r
+                                              PyObject *callback);\r
+PyAPI_FUNC(PyObject *) PyWeakref_NewProxy(PyObject *ob,\r
+                                                PyObject *callback);\r
+PyAPI_FUNC(PyObject *) PyWeakref_GetObject(PyObject *ref);\r
+\r
+PyAPI_FUNC(Py_ssize_t) _PyWeakref_GetWeakrefCount(PyWeakReference *head);\r
+\r
+PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);\r
+\r
+/* Explanation for the Py_REFCNT() check: when a weakref's target is part\r
+   of a long chain of deallocations which triggers the trashcan mechanism,\r
+   clearing the weakrefs can be delayed long after the target's refcount\r
+   has dropped to zero.  In the meantime, code accessing the weakref will\r
+   be able to "see" the target object even though it is supposed to be\r
+   unreachable.  See issue #16602. */\r
+\r
+#define PyWeakref_GET_OBJECT(ref)                           \\r
+    (Py_REFCNT(((PyWeakReference *)(ref))->wr_object) > 0   \\r
+     ? ((PyWeakReference *)(ref))->wr_object                \\r
+     : Py_None)\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_WEAKREFOBJECT_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/acceler.c b/AppPkg/Applications/Python/Python-2.7.10/Parser/acceler.c
new file mode 100644 (file)
index 0000000..f6036d9
--- /dev/null
@@ -0,0 +1,125 @@
+\r
+/* Parser accelerator module */\r
+\r
+/* The parser as originally conceived had disappointing performance.\r
+   This module does some precomputation that speeds up the selection\r
+   of a DFA based upon a token, turning a search through an array\r
+   into a simple indexing operation.  The parser now cannot work\r
+   without the accelerators installed.  Note that the accelerators\r
+   are installed dynamically when the parser is initialized, they\r
+   are not part of the static data structure written on graminit.[ch]\r
+   by the parser generator. */\r
+\r
+#include "pgenheaders.h"\r
+#include "grammar.h"\r
+#include "node.h"\r
+#include "token.h"\r
+#include "parser.h"\r
+\r
+/* Forward references */\r
+static void fixdfa(grammar *, dfa *);\r
+static void fixstate(grammar *, state *);\r
+\r
+void\r
+PyGrammar_AddAccelerators(grammar *g)\r
+{\r
+    dfa *d;\r
+    int i;\r
+    d = g->g_dfa;\r
+    for (i = g->g_ndfas; --i >= 0; d++)\r
+        fixdfa(g, d);\r
+    g->g_accel = 1;\r
+}\r
+\r
+void\r
+PyGrammar_RemoveAccelerators(grammar *g)\r
+{\r
+    dfa *d;\r
+    int i;\r
+    g->g_accel = 0;\r
+    d = g->g_dfa;\r
+    for (i = g->g_ndfas; --i >= 0; d++) {\r
+        state *s;\r
+        int j;\r
+        s = d->d_state;\r
+        for (j = 0; j < d->d_nstates; j++, s++) {\r
+            if (s->s_accel)\r
+                PyObject_FREE(s->s_accel);\r
+            s->s_accel = NULL;\r
+        }\r
+    }\r
+}\r
+\r
+static void\r
+fixdfa(grammar *g, dfa *d)\r
+{\r
+    state *s;\r
+    int j;\r
+    s = d->d_state;\r
+    for (j = 0; j < d->d_nstates; j++, s++)\r
+        fixstate(g, s);\r
+}\r
+\r
+static void\r
+fixstate(grammar *g, state *s)\r
+{\r
+    arc *a;\r
+    int k;\r
+    int *accel;\r
+    int nl = g->g_ll.ll_nlabels;\r
+    s->s_accept = 0;\r
+    accel = (int *) PyObject_MALLOC(nl * sizeof(int));\r
+    if (accel == NULL) {\r
+        fprintf(stderr, "no mem to build parser accelerators\n");\r
+        exit(1);\r
+    }\r
+    for (k = 0; k < nl; k++)\r
+        accel[k] = -1;\r
+    a = s->s_arc;\r
+    for (k = s->s_narcs; --k >= 0; a++) {\r
+        int lbl = a->a_lbl;\r
+        label *l = &g->g_ll.ll_label[lbl];\r
+        int type = l->lb_type;\r
+        if (a->a_arrow >= (1 << 7)) {\r
+            printf("XXX too many states!\n");\r
+            continue;\r
+        }\r
+        if (ISNONTERMINAL(type)) {\r
+            dfa *d1 = PyGrammar_FindDFA(g, type);\r
+            int ibit;\r
+            if (type - NT_OFFSET >= (1 << 7)) {\r
+                printf("XXX too high nonterminal number!\n");\r
+                continue;\r
+            }\r
+            for (ibit = 0; ibit < g->g_ll.ll_nlabels; ibit++) {\r
+                if (testbit(d1->d_first, ibit)) {\r
+                    if (accel[ibit] != -1)\r
+                        printf("XXX ambiguity!\n");\r
+                    accel[ibit] = a->a_arrow | (1 << 7) |\r
+                        ((type - NT_OFFSET) << 8);\r
+                }\r
+            }\r
+        }\r
+        else if (lbl == EMPTY)\r
+            s->s_accept = 1;\r
+        else if (lbl >= 0 && lbl < nl)\r
+            accel[lbl] = a->a_arrow;\r
+    }\r
+    while (nl > 0 && accel[nl-1] == -1)\r
+        nl--;\r
+    for (k = 0; k < nl && accel[k] == -1;)\r
+        k++;\r
+    if (k < nl) {\r
+        int i;\r
+        s->s_accel = (int *) PyObject_MALLOC((nl-k) * sizeof(int));\r
+        if (s->s_accel == NULL) {\r
+            fprintf(stderr, "no mem to add parser accelerators\n");\r
+            exit(1);\r
+        }\r
+        s->s_lower = k;\r
+        s->s_upper = nl;\r
+        for (i = 0; k < nl; i++, k++)\r
+            s->s_accel[i] = accel[k];\r
+    }\r
+    PyObject_FREE(accel);\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/bitset.c b/AppPkg/Applications/Python/Python-2.7.10/Parser/bitset.c
new file mode 100644 (file)
index 0000000..3bf5da1
--- /dev/null
@@ -0,0 +1,66 @@
+\r
+/* Bitset primitives used by the parser generator */\r
+\r
+#include "pgenheaders.h"\r
+#include "bitset.h"\r
+\r
+bitset\r
+newbitset(int nbits)\r
+{\r
+    int nbytes = NBYTES(nbits);\r
+    bitset ss = (char *)PyObject_MALLOC(sizeof(BYTE) *  nbytes);\r
+\r
+    if (ss == NULL)\r
+        Py_FatalError("no mem for bitset");\r
+\r
+    ss += nbytes;\r
+    while (--nbytes >= 0)\r
+        *--ss = 0;\r
+    return ss;\r
+}\r
+\r
+void\r
+delbitset(bitset ss)\r
+{\r
+    PyObject_FREE(ss);\r
+}\r
+\r
+int\r
+addbit(bitset ss, int ibit)\r
+{\r
+    int ibyte = BIT2BYTE(ibit);\r
+    BYTE mask = BIT2MASK(ibit);\r
+\r
+    if (ss[ibyte] & mask)\r
+        return 0; /* Bit already set */\r
+    ss[ibyte] |= mask;\r
+    return 1;\r
+}\r
+\r
+#if 0 /* Now a macro */\r
+int\r
+testbit(bitset ss, int ibit)\r
+{\r
+    return (ss[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0;\r
+}\r
+#endif\r
+\r
+int\r
+samebitset(bitset ss1, bitset ss2, int nbits)\r
+{\r
+    int i;\r
+\r
+    for (i = NBYTES(nbits); --i >= 0; )\r
+        if (*ss1++ != *ss2++)\r
+            return 0;\r
+    return 1;\r
+}\r
+\r
+void\r
+mergebitset(bitset ss1, bitset ss2, int nbits)\r
+{\r
+    int i;\r
+\r
+    for (i = NBYTES(nbits); --i >= 0; )\r
+        *ss1++ |= *ss2++;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/firstsets.c b/AppPkg/Applications/Python/Python-2.7.10/Parser/firstsets.c
new file mode 100644 (file)
index 0000000..69faf8f
--- /dev/null
@@ -0,0 +1,113 @@
+\r
+/* Computation of FIRST stets */\r
+\r
+#include "pgenheaders.h"\r
+#include "grammar.h"\r
+#include "token.h"\r
+\r
+extern int Py_DebugFlag;\r
+\r
+/* Forward */\r
+static void calcfirstset(grammar *, dfa *);\r
+\r
+void\r
+addfirstsets(grammar *g)\r
+{\r
+    int i;\r
+    dfa *d;\r
+\r
+    if (Py_DebugFlag)\r
+        printf("Adding FIRST sets ...\n");\r
+    for (i = 0; i < g->g_ndfas; i++) {\r
+        d = &g->g_dfa[i];\r
+        if (d->d_first == NULL)\r
+            calcfirstset(g, d);\r
+    }\r
+}\r
+\r
+static void\r
+calcfirstset(grammar *g, dfa *d)\r
+{\r
+    int i, j;\r
+    state *s;\r
+    arc *a;\r
+    int nsyms;\r
+    int *sym;\r
+    int nbits;\r
+    static bitset dummy;\r
+    bitset result;\r
+    int type;\r
+    dfa *d1;\r
+    label *l0;\r
+\r
+    if (Py_DebugFlag)\r
+        printf("Calculate FIRST set for '%s'\n", d->d_name);\r
+\r
+    if (dummy == NULL)\r
+        dummy = newbitset(1);\r
+    if (d->d_first == dummy) {\r
+        fprintf(stderr, "Left-recursion for '%s'\n", d->d_name);\r
+        return;\r
+    }\r
+    if (d->d_first != NULL) {\r
+        fprintf(stderr, "Re-calculating FIRST set for '%s' ???\n",\r
+            d->d_name);\r
+    }\r
+    d->d_first = dummy;\r
+\r
+    l0 = g->g_ll.ll_label;\r
+    nbits = g->g_ll.ll_nlabels;\r
+    result = newbitset(nbits);\r
+\r
+    sym = (int *)PyObject_MALLOC(sizeof(int));\r
+    if (sym == NULL)\r
+        Py_FatalError("no mem for new sym in calcfirstset");\r
+    nsyms = 1;\r
+    sym[0] = findlabel(&g->g_ll, d->d_type, (char *)NULL);\r
+\r
+    s = &d->d_state[d->d_initial];\r
+    for (i = 0; i < s->s_narcs; i++) {\r
+        a = &s->s_arc[i];\r
+        for (j = 0; j < nsyms; j++) {\r
+            if (sym[j] == a->a_lbl)\r
+                break;\r
+        }\r
+        if (j >= nsyms) { /* New label */\r
+            sym = (int *)PyObject_REALLOC(sym,\r
+                                    sizeof(int) * (nsyms + 1));\r
+            if (sym == NULL)\r
+                Py_FatalError(\r
+                    "no mem to resize sym in calcfirstset");\r
+            sym[nsyms++] = a->a_lbl;\r
+            type = l0[a->a_lbl].lb_type;\r
+            if (ISNONTERMINAL(type)) {\r
+                d1 = PyGrammar_FindDFA(g, type);\r
+                if (d1->d_first == dummy) {\r
+                    fprintf(stderr,\r
+                        "Left-recursion below '%s'\n",\r
+                        d->d_name);\r
+                }\r
+                else {\r
+                    if (d1->d_first == NULL)\r
+                        calcfirstset(g, d1);\r
+                    mergebitset(result,\r
+                                d1->d_first, nbits);\r
+                }\r
+            }\r
+            else if (ISTERMINAL(type)) {\r
+                addbit(result, a->a_lbl);\r
+            }\r
+        }\r
+    }\r
+    d->d_first = result;\r
+    if (Py_DebugFlag) {\r
+        printf("FIRST set for '%s': {", d->d_name);\r
+        for (i = 0; i < nbits; i++) {\r
+            if (testbit(result, i))\r
+                printf(" %s", PyGrammar_LabelRepr(&l0[i]));\r
+        }\r
+        printf(" }\n");\r
+    }\r
+\r
+    PyObject_FREE(sym);\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/grammar.c b/AppPkg/Applications/Python/Python-2.7.10/Parser/grammar.c
new file mode 100644 (file)
index 0000000..4cce422
--- /dev/null
@@ -0,0 +1,254 @@
+\r
+/* Grammar implementation */\r
+\r
+#include "Python.h"\r
+#include "pgenheaders.h"\r
+\r
+#include <ctype.h>\r
+\r
+#include "token.h"\r
+#include "grammar.h"\r
+\r
+#ifdef RISCOS\r
+#include <unixlib.h>\r
+#endif\r
+\r
+extern int Py_DebugFlag;\r
+\r
+grammar *\r
+newgrammar(int start)\r
+{\r
+    grammar *g;\r
+\r
+    g = (grammar *)PyObject_MALLOC(sizeof(grammar));\r
+    if (g == NULL)\r
+        Py_FatalError("no mem for new grammar");\r
+    g->g_ndfas = 0;\r
+    g->g_dfa = NULL;\r
+    g->g_start = start;\r
+    g->g_ll.ll_nlabels = 0;\r
+    g->g_ll.ll_label = NULL;\r
+    g->g_accel = 0;\r
+    return g;\r
+}\r
+\r
+dfa *\r
+adddfa(grammar *g, int type, char *name)\r
+{\r
+    dfa *d;\r
+\r
+    g->g_dfa = (dfa *)PyObject_REALLOC(g->g_dfa,\r
+                                        sizeof(dfa) * (g->g_ndfas + 1));\r
+    if (g->g_dfa == NULL)\r
+        Py_FatalError("no mem to resize dfa in adddfa");\r
+    d = &g->g_dfa[g->g_ndfas++];\r
+    d->d_type = type;\r
+    d->d_name = strdup(name);\r
+    d->d_nstates = 0;\r
+    d->d_state = NULL;\r
+    d->d_initial = -1;\r
+    d->d_first = NULL;\r
+    return d; /* Only use while fresh! */\r
+}\r
+\r
+int\r
+addstate(dfa *d)\r
+{\r
+    state *s;\r
+\r
+    d->d_state = (state *)PyObject_REALLOC(d->d_state,\r
+                                  sizeof(state) * (d->d_nstates + 1));\r
+    if (d->d_state == NULL)\r
+        Py_FatalError("no mem to resize state in addstate");\r
+    s = &d->d_state[d->d_nstates++];\r
+    s->s_narcs = 0;\r
+    s->s_arc = NULL;\r
+    s->s_lower = 0;\r
+    s->s_upper = 0;\r
+    s->s_accel = NULL;\r
+    s->s_accept = 0;\r
+    return s - d->d_state;\r
+}\r
+\r
+void\r
+addarc(dfa *d, int from, int to, int lbl)\r
+{\r
+    state *s;\r
+    arc *a;\r
+\r
+    assert(0 <= from && from < d->d_nstates);\r
+    assert(0 <= to && to < d->d_nstates);\r
+\r
+    s = &d->d_state[from];\r
+    s->s_arc = (arc *)PyObject_REALLOC(s->s_arc, sizeof(arc) * (s->s_narcs + 1));\r
+    if (s->s_arc == NULL)\r
+        Py_FatalError("no mem to resize arc list in addarc");\r
+    a = &s->s_arc[s->s_narcs++];\r
+    a->a_lbl = lbl;\r
+    a->a_arrow = to;\r
+}\r
+\r
+int\r
+addlabel(labellist *ll, int type, char *str)\r
+{\r
+    int i;\r
+    label *lb;\r
+\r
+    for (i = 0; i < ll->ll_nlabels; i++) {\r
+        if (ll->ll_label[i].lb_type == type &&\r
+            strcmp(ll->ll_label[i].lb_str, str) == 0)\r
+            return i;\r
+    }\r
+    ll->ll_label = (label *)PyObject_REALLOC(ll->ll_label,\r
+                                    sizeof(label) * (ll->ll_nlabels + 1));\r
+    if (ll->ll_label == NULL)\r
+        Py_FatalError("no mem to resize labellist in addlabel");\r
+    lb = &ll->ll_label[ll->ll_nlabels++];\r
+    lb->lb_type = type;\r
+    lb->lb_str = strdup(str);\r
+    if (Py_DebugFlag)\r
+        printf("Label @ %8p, %d: %s\n", ll, ll->ll_nlabels,\r
+               PyGrammar_LabelRepr(lb));\r
+    return lb - ll->ll_label;\r
+}\r
+\r
+/* Same, but rather dies than adds */\r
+\r
+int\r
+findlabel(labellist *ll, int type, char *str)\r
+{\r
+    int i;\r
+\r
+    for (i = 0; i < ll->ll_nlabels; i++) {\r
+        if (ll->ll_label[i].lb_type == type /*&&\r
+            strcmp(ll->ll_label[i].lb_str, str) == 0*/)\r
+            return i;\r
+    }\r
+    fprintf(stderr, "Label %d/'%s' not found\n", type, str);\r
+    Py_FatalError("grammar.c:findlabel()");\r
+    return 0; /* Make gcc -Wall happy */\r
+}\r
+\r
+/* Forward */\r
+static void translabel(grammar *, label *);\r
+\r
+void\r
+translatelabels(grammar *g)\r
+{\r
+    int i;\r
+\r
+#ifdef Py_DEBUG\r
+    printf("Translating labels ...\n");\r
+#endif\r
+    /* Don't translate EMPTY */\r
+    for (i = EMPTY+1; i < g->g_ll.ll_nlabels; i++)\r
+        translabel(g, &g->g_ll.ll_label[i]);\r
+}\r
+\r
+static void\r
+translabel(grammar *g, label *lb)\r
+{\r
+    int i;\r
+\r
+    if (Py_DebugFlag)\r
+        printf("Translating label %s ...\n", PyGrammar_LabelRepr(lb));\r
+\r
+    if (lb->lb_type == NAME) {\r
+        for (i = 0; i < g->g_ndfas; i++) {\r
+            if (strcmp(lb->lb_str, g->g_dfa[i].d_name) == 0) {\r
+                if (Py_DebugFlag)\r
+                    printf(\r
+                        "Label %s is non-terminal %d.\n",\r
+                        lb->lb_str,\r
+                        g->g_dfa[i].d_type);\r
+                lb->lb_type = g->g_dfa[i].d_type;\r
+                free(lb->lb_str);\r
+                lb->lb_str = NULL;\r
+                return;\r
+            }\r
+        }\r
+        for (i = 0; i < (int)N_TOKENS; i++) {\r
+            if (strcmp(lb->lb_str, _PyParser_TokenNames[i]) == 0) {\r
+                if (Py_DebugFlag)\r
+                    printf("Label %s is terminal %d.\n",\r
+                        lb->lb_str, i);\r
+                lb->lb_type = i;\r
+                free(lb->lb_str);\r
+                lb->lb_str = NULL;\r
+                return;\r
+            }\r
+        }\r
+        printf("Can't translate NAME label '%s'\n", lb->lb_str);\r
+        return;\r
+    }\r
+\r
+    if (lb->lb_type == STRING) {\r
+        if (isalpha(Py_CHARMASK(lb->lb_str[1])) ||\r
+            lb->lb_str[1] == '_') {\r
+            char *p;\r
+            char *src;\r
+            char *dest;\r
+            size_t name_len;\r
+            if (Py_DebugFlag)\r
+                printf("Label %s is a keyword\n", lb->lb_str);\r
+            lb->lb_type = NAME;\r
+            src = lb->lb_str + 1;\r
+            p = strchr(src, '\'');\r
+            if (p)\r
+                name_len = p - src;\r
+            else\r
+                name_len = strlen(src);\r
+            dest = (char *)malloc(name_len + 1);\r
+            if (!dest) {\r
+                printf("Can't alloc dest '%s'\n", src);\r
+                return;\r
+            }\r
+            strncpy(dest, src, name_len);\r
+            dest[name_len] = '\0';\r
+            free(lb->lb_str);\r
+            lb->lb_str = dest;\r
+        }\r
+        else if (lb->lb_str[2] == lb->lb_str[0]) {\r
+            int type = (int) PyToken_OneChar(lb->lb_str[1]);\r
+            if (type != OP) {\r
+                lb->lb_type = type;\r
+                free(lb->lb_str);\r
+                lb->lb_str = NULL;\r
+            }\r
+            else\r
+                printf("Unknown OP label %s\n",\r
+                    lb->lb_str);\r
+        }\r
+        else if (lb->lb_str[2] && lb->lb_str[3] == lb->lb_str[0]) {\r
+            int type = (int) PyToken_TwoChars(lb->lb_str[1],\r
+                                       lb->lb_str[2]);\r
+            if (type != OP) {\r
+                lb->lb_type = type;\r
+                free(lb->lb_str);\r
+                lb->lb_str = NULL;\r
+            }\r
+            else\r
+                printf("Unknown OP label %s\n",\r
+                    lb->lb_str);\r
+        }\r
+        else if (lb->lb_str[2] && lb->lb_str[3] && lb->lb_str[4] == lb->lb_str[0]) {\r
+            int type = (int) PyToken_ThreeChars(lb->lb_str[1],\r
+                                                lb->lb_str[2],\r
+                                                lb->lb_str[3]);\r
+            if (type != OP) {\r
+                lb->lb_type = type;\r
+                free(lb->lb_str);\r
+                lb->lb_str = NULL;\r
+            }\r
+            else\r
+                printf("Unknown OP label %s\n",\r
+                    lb->lb_str);\r
+        }\r
+        else\r
+            printf("Can't translate STRING label %s\n",\r
+                lb->lb_str);\r
+    }\r
+    else\r
+        printf("Can't translate label '%s'\n",\r
+               PyGrammar_LabelRepr(lb));\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/grammar1.c b/AppPkg/Applications/Python/Python-2.7.10/Parser/grammar1.c
new file mode 100644 (file)
index 0000000..27db22f
--- /dev/null
@@ -0,0 +1,57 @@
+\r
+/* Grammar subroutines needed by parser */\r
+\r
+#include "Python.h"\r
+#include "pgenheaders.h"\r
+#include "grammar.h"\r
+#include "token.h"\r
+\r
+/* Return the DFA for the given type */\r
+\r
+dfa *\r
+PyGrammar_FindDFA(grammar *g, register int type)\r
+{\r
+    register dfa *d;\r
+#if 1\r
+    /* Massive speed-up */\r
+    d = &g->g_dfa[type - NT_OFFSET];\r
+    assert(d->d_type == type);\r
+    return d;\r
+#else\r
+    /* Old, slow version */\r
+    register int i;\r
+\r
+    for (i = g->g_ndfas, d = g->g_dfa; --i >= 0; d++) {\r
+        if (d->d_type == type)\r
+            return d;\r
+    }\r
+    assert(0);\r
+    /* NOTREACHED */\r
+#endif\r
+}\r
+\r
+char *\r
+PyGrammar_LabelRepr(label *lb)\r
+{\r
+    static char buf[100];\r
+\r
+    if (lb->lb_type == ENDMARKER)\r
+        return "EMPTY";\r
+    else if (ISNONTERMINAL(lb->lb_type)) {\r
+        if (lb->lb_str == NULL) {\r
+            PyOS_snprintf(buf, sizeof(buf), "NT%d", lb->lb_type);\r
+            return buf;\r
+        }\r
+        else\r
+            return lb->lb_str;\r
+    }\r
+    else {\r
+        if (lb->lb_str == NULL)\r
+            return _PyParser_TokenNames[lb->lb_type];\r
+        else {\r
+            PyOS_snprintf(buf, sizeof(buf), "%.32s(%.32s)",\r
+                _PyParser_TokenNames[lb->lb_type], lb->lb_str);\r
+            return buf;\r
+        }\r
+    }\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/listnode.c b/AppPkg/Applications/Python/Python-2.7.10/Parser/listnode.c
new file mode 100644 (file)
index 0000000..8d59233
--- /dev/null
@@ -0,0 +1,66 @@
+\r
+/* List a node on a file */\r
+\r
+#include "pgenheaders.h"\r
+#include "token.h"\r
+#include "node.h"\r
+\r
+/* Forward */\r
+static void list1node(FILE *, node *);\r
+static void listnode(FILE *, node *);\r
+\r
+void\r
+PyNode_ListTree(node *n)\r
+{\r
+    listnode(stdout, n);\r
+}\r
+\r
+static int level, atbol;\r
+\r
+static void\r
+listnode(FILE *fp, node *n)\r
+{\r
+    level = 0;\r
+    atbol = 1;\r
+    list1node(fp, n);\r
+}\r
+\r
+static void\r
+list1node(FILE *fp, node *n)\r
+{\r
+    if (n == 0)\r
+        return;\r
+    if (ISNONTERMINAL(TYPE(n))) {\r
+        int i;\r
+        for (i = 0; i < NCH(n); i++)\r
+            list1node(fp, CHILD(n, i));\r
+    }\r
+    else if (ISTERMINAL(TYPE(n))) {\r
+        switch (TYPE(n)) {\r
+        case INDENT:\r
+            ++level;\r
+            break;\r
+        case DEDENT:\r
+            --level;\r
+            break;\r
+        default:\r
+            if (atbol) {\r
+                int i;\r
+                for (i = 0; i < level; ++i)\r
+                    fprintf(fp, "\t");\r
+                atbol = 0;\r
+            }\r
+            if (TYPE(n) == NEWLINE) {\r
+                if (STR(n) != NULL)\r
+                    fprintf(fp, "%s", STR(n));\r
+                fprintf(fp, "\n");\r
+                atbol = 1;\r
+            }\r
+            else\r
+                fprintf(fp, "%s ", STR(n));\r
+            break;\r
+        }\r
+    }\r
+    else\r
+        fprintf(fp, "? ");\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/metagrammar.c b/AppPkg/Applications/Python/Python-2.7.10/Parser/metagrammar.c
new file mode 100644 (file)
index 0000000..299ccaa
--- /dev/null
@@ -0,0 +1,159 @@
+\r
+#include "pgenheaders.h"\r
+#include "metagrammar.h"\r
+#include "grammar.h"\r
+#include "pgen.h"\r
+static arc arcs_0_0[3] = {\r
+    {2, 0},\r
+    {3, 0},\r
+    {4, 1},\r
+};\r
+static arc arcs_0_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_0[2] = {\r
+    {3, arcs_0_0},\r
+    {1, arcs_0_1},\r
+};\r
+static arc arcs_1_0[1] = {\r
+    {5, 1},\r
+};\r
+static arc arcs_1_1[1] = {\r
+    {6, 2},\r
+};\r
+static arc arcs_1_2[1] = {\r
+    {7, 3},\r
+};\r
+static arc arcs_1_3[1] = {\r
+    {3, 4},\r
+};\r
+static arc arcs_1_4[1] = {\r
+    {0, 4},\r
+};\r
+static state states_1[5] = {\r
+    {1, arcs_1_0},\r
+    {1, arcs_1_1},\r
+    {1, arcs_1_2},\r
+    {1, arcs_1_3},\r
+    {1, arcs_1_4},\r
+};\r
+static arc arcs_2_0[1] = {\r
+    {8, 1},\r
+};\r
+static arc arcs_2_1[2] = {\r
+    {9, 0},\r
+    {0, 1},\r
+};\r
+static state states_2[2] = {\r
+    {1, arcs_2_0},\r
+    {2, arcs_2_1},\r
+};\r
+static arc arcs_3_0[1] = {\r
+    {10, 1},\r
+};\r
+static arc arcs_3_1[2] = {\r
+    {10, 1},\r
+    {0, 1},\r
+};\r
+static state states_3[2] = {\r
+    {1, arcs_3_0},\r
+    {2, arcs_3_1},\r
+};\r
+static arc arcs_4_0[2] = {\r
+    {11, 1},\r
+    {13, 2},\r
+};\r
+static arc arcs_4_1[1] = {\r
+    {7, 3},\r
+};\r
+static arc arcs_4_2[3] = {\r
+    {14, 4},\r
+    {15, 4},\r
+    {0, 2},\r
+};\r
+static arc arcs_4_3[1] = {\r
+    {12, 4},\r
+};\r
+static arc arcs_4_4[1] = {\r
+    {0, 4},\r
+};\r
+static state states_4[5] = {\r
+    {2, arcs_4_0},\r
+    {1, arcs_4_1},\r
+    {3, arcs_4_2},\r
+    {1, arcs_4_3},\r
+    {1, arcs_4_4},\r
+};\r
+static arc arcs_5_0[3] = {\r
+    {5, 1},\r
+    {16, 1},\r
+    {17, 2},\r
+};\r
+static arc arcs_5_1[1] = {\r
+    {0, 1},\r
+};\r
+static arc arcs_5_2[1] = {\r
+    {7, 3},\r
+};\r
+static arc arcs_5_3[1] = {\r
+    {18, 1},\r
+};\r
+static state states_5[4] = {\r
+    {3, arcs_5_0},\r
+    {1, arcs_5_1},\r
+    {1, arcs_5_2},\r
+    {1, arcs_5_3},\r
+};\r
+static dfa dfas[6] = {\r
+    {256, "MSTART", 0, 2, states_0,\r
+     "\070\000\000"},\r
+    {257, "RULE", 0, 5, states_1,\r
+     "\040\000\000"},\r
+    {258, "RHS", 0, 2, states_2,\r
+     "\040\010\003"},\r
+    {259, "ALT", 0, 2, states_3,\r
+     "\040\010\003"},\r
+    {260, "ITEM", 0, 5, states_4,\r
+     "\040\010\003"},\r
+    {261, "ATOM", 0, 4, states_5,\r
+     "\040\000\003"},\r
+};\r
+static label labels[19] = {\r
+    {0, "EMPTY"},\r
+    {256, 0},\r
+    {257, 0},\r
+    {4, 0},\r
+    {0, 0},\r
+    {1, 0},\r
+    {11, 0},\r
+    {258, 0},\r
+    {259, 0},\r
+    {18, 0},\r
+    {260, 0},\r
+    {9, 0},\r
+    {10, 0},\r
+    {261, 0},\r
+    {16, 0},\r
+    {14, 0},\r
+    {3, 0},\r
+    {7, 0},\r
+    {8, 0},\r
+};\r
+static grammar _PyParser_Grammar = {\r
+    6,\r
+    dfas,\r
+    {19, labels},\r
+    256\r
+};\r
+\r
+grammar *\r
+meta_grammar(void)\r
+{\r
+    return &_PyParser_Grammar;\r
+}\r
+\r
+grammar *\r
+Py_meta_grammar(void)\r
+{\r
+  return meta_grammar();\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/myreadline.c b/AppPkg/Applications/Python/Python-2.7.10/Parser/myreadline.c
new file mode 100644 (file)
index 0000000..ca99e35
--- /dev/null
@@ -0,0 +1,218 @@
+\r
+/* Readline interface for tokenizer.c and [raw_]input() in bltinmodule.c.\r
+   By default, or when stdin is not a tty device, we have a super\r
+   simple my_readline function using fgets.\r
+   Optionally, we can use the GNU readline library.\r
+   my_readline() has a different return value from GNU readline():\r
+   - NULL if an interrupt occurred or if an error occurred\r
+   - a malloc'ed empty string if EOF was read\r
+   - a malloc'ed string ending in \n normally\r
+*/\r
+\r
+#include "Python.h"\r
+#ifdef MS_WINDOWS\r
+#define WIN32_LEAN_AND_MEAN\r
+#include "windows.h"\r
+#endif /* MS_WINDOWS */\r
+\r
+#ifdef __VMS\r
+extern char* vms__StdioReadline(FILE *sys_stdin, FILE *sys_stdout, char *prompt);\r
+#endif\r
+\r
+\r
+PyThreadState* _PyOS_ReadlineTState;\r
+\r
+#ifdef WITH_THREAD\r
+#include "pythread.h"\r
+static PyThread_type_lock _PyOS_ReadlineLock = NULL;\r
+#endif\r
+\r
+int (*PyOS_InputHook)(void) = NULL;\r
+\r
+#ifdef RISCOS\r
+int Py_RISCOSWimpFlag;\r
+#endif\r
+\r
+/* This function restarts a fgets() after an EINTR error occurred\r
+   except if PyOS_InterruptOccurred() returns true. */\r
+\r
+static int\r
+my_fgets(char *buf, int len, FILE *fp)\r
+{\r
+    char *p;\r
+#ifdef MS_WINDOWS\r
+    int i;\r
+#endif\r
+\r
+    while (1) {\r
+        if (PyOS_InputHook != NULL)\r
+            (void)(PyOS_InputHook)();\r
+        errno = 0;\r
+        clearerr(fp);\r
+        p = fgets(buf, len, fp);\r
+        if (p != NULL)\r
+            return 0; /* No error */\r
+#ifdef MS_WINDOWS\r
+        /* Ctrl-C anywhere on the line or Ctrl-Z if the only character\r
+           on a line will set ERROR_OPERATION_ABORTED. Under normal\r
+           circumstances Ctrl-C will also have caused the SIGINT handler\r
+           to fire. This signal fires in another thread and is not\r
+           guaranteed to have occurred before this point in the code.\r
+\r
+           Therefore: check in a small loop to see if the trigger has\r
+           fired, in which case assume this is a Ctrl-C event. If it\r
+           hasn't fired within 10ms assume that this is a Ctrl-Z on its\r
+           own or that the signal isn't going to fire for some other\r
+           reason and drop through to check for EOF.\r
+        */\r
+        if (GetLastError()==ERROR_OPERATION_ABORTED) {\r
+            for (i = 0; i < 10; i++) {\r
+                if (PyOS_InterruptOccurred())\r
+                    return 1;\r
+                Sleep(1);\r
+            }\r
+        }\r
+#endif /* MS_WINDOWS */\r
+        if (feof(fp)) {\r
+            clearerr(fp);\r
+            return -1; /* EOF */\r
+        }\r
+#ifdef EINTR\r
+        if (errno == EINTR) {\r
+            int s;\r
+#ifdef WITH_THREAD\r
+            PyEval_RestoreThread(_PyOS_ReadlineTState);\r
+#endif\r
+            s = PyErr_CheckSignals();\r
+#ifdef WITH_THREAD\r
+            PyEval_SaveThread();\r
+#endif\r
+            if (s < 0)\r
+                    return 1;\r
+           /* try again */\r
+            continue;\r
+        }\r
+#endif\r
+        if (PyOS_InterruptOccurred()) {\r
+            return 1; /* Interrupt */\r
+        }\r
+        return -2; /* Error */\r
+    }\r
+    /* NOTREACHED */\r
+}\r
+\r
+\r
+/* Readline implementation using fgets() */\r
+\r
+char *\r
+PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)\r
+{\r
+    size_t n;\r
+    char *p;\r
+    n = 100;\r
+    if ((p = (char *)PyMem_MALLOC(n)) == NULL)\r
+        return NULL;\r
+    fflush(sys_stdout);\r
+#ifndef RISCOS\r
+    if (prompt)\r
+        fprintf(stderr, "%s", prompt);\r
+#else\r
+    if (prompt) {\r
+        if(Py_RISCOSWimpFlag)\r
+            fprintf(stderr, "\x0cr%s\x0c", prompt);\r
+        else\r
+            fprintf(stderr, "%s", prompt);\r
+    }\r
+#endif\r
+    fflush(stderr);\r
+    switch (my_fgets(p, (int)n, sys_stdin)) {\r
+    case 0: /* Normal case */\r
+        break;\r
+    case 1: /* Interrupt */\r
+        PyMem_FREE(p);\r
+        return NULL;\r
+    case -1: /* EOF */\r
+    case -2: /* Error */\r
+    default: /* Shouldn't happen */\r
+        *p = '\0';\r
+        break;\r
+    }\r
+    n = strlen(p);\r
+    while (n > 0 && p[n-1] != '\n') {\r
+        size_t incr = n+2;\r
+        p = (char *)PyMem_REALLOC(p, n + incr);\r
+        if (p == NULL)\r
+            return NULL;\r
+        if (incr > INT_MAX) {\r
+            PyErr_SetString(PyExc_OverflowError, "input line too long");\r
+        }\r
+        if (my_fgets(p+n, (int)incr, sys_stdin) != 0)\r
+            break;\r
+        n += strlen(p+n);\r
+    }\r
+    return (char *)PyMem_REALLOC(p, n+1);\r
+}\r
+\r
+\r
+/* By initializing this function pointer, systems embedding Python can\r
+   override the readline function.\r
+\r
+   Note: Python expects in return a buffer allocated with PyMem_Malloc. */\r
+\r
+char *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *);\r
+\r
+\r
+/* Interface used by tokenizer.c and bltinmodule.c */\r
+\r
+char *\r
+PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)\r
+{\r
+    char *rv;\r
+\r
+    if (_PyOS_ReadlineTState == PyThreadState_GET()) {\r
+        PyErr_SetString(PyExc_RuntimeError,\r
+                        "can't re-enter readline");\r
+        return NULL;\r
+    }\r
+\r
+\r
+    if (PyOS_ReadlineFunctionPointer == NULL) {\r
+#ifdef __VMS\r
+        PyOS_ReadlineFunctionPointer = vms__StdioReadline;\r
+#else\r
+        PyOS_ReadlineFunctionPointer = PyOS_StdioReadline;\r
+#endif\r
+    }\r
+\r
+#ifdef WITH_THREAD\r
+    if (_PyOS_ReadlineLock == NULL) {\r
+        _PyOS_ReadlineLock = PyThread_allocate_lock();\r
+    }\r
+#endif\r
+\r
+    _PyOS_ReadlineTState = PyThreadState_GET();\r
+    Py_BEGIN_ALLOW_THREADS\r
+#ifdef WITH_THREAD\r
+    PyThread_acquire_lock(_PyOS_ReadlineLock, 1);\r
+#endif\r
+\r
+    /* This is needed to handle the unlikely case that the\r
+     * interpreter is in interactive mode *and* stdin/out are not\r
+     * a tty.  This can happen, for example if python is run like\r
+     * this: python -i < test1.py\r
+     */\r
+    if (!isatty (fileno (sys_stdin)) || !isatty (fileno (sys_stdout)))\r
+        rv = PyOS_StdioReadline (sys_stdin, sys_stdout, prompt);\r
+    else\r
+        rv = (*PyOS_ReadlineFunctionPointer)(sys_stdin, sys_stdout,\r
+                                             prompt);\r
+    Py_END_ALLOW_THREADS\r
+\r
+#ifdef WITH_THREAD\r
+    PyThread_release_lock(_PyOS_ReadlineLock);\r
+#endif\r
+\r
+    _PyOS_ReadlineTState = NULL;\r
+\r
+    return rv;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/node.c b/AppPkg/Applications/Python/Python-2.7.10/Parser/node.c
new file mode 100644 (file)
index 0000000..4f1fbf8
--- /dev/null
@@ -0,0 +1,164 @@
+/* Parse tree node implementation */\r
+\r
+#include "Python.h"\r
+#include "node.h"\r
+#include "errcode.h"\r
+\r
+node *\r
+PyNode_New(int type)\r
+{\r
+    node *n = (node *) PyObject_MALLOC(1 * sizeof(node));\r
+    if (n == NULL)\r
+        return NULL;\r
+    n->n_type = type;\r
+    n->n_str = NULL;\r
+    n->n_lineno = 0;\r
+    n->n_nchildren = 0;\r
+    n->n_child = NULL;\r
+    return n;\r
+}\r
+\r
+/* See comments at XXXROUNDUP below.  Returns -1 on overflow. */\r
+static int\r
+fancy_roundup(int n)\r
+{\r
+    /* Round up to the closest power of 2 >= n. */\r
+    int result = 256;\r
+    assert(n > 128);\r
+    while (result < n) {\r
+        result <<= 1;\r
+        if (result <= 0)\r
+            return -1;\r
+    }\r
+    return result;\r
+}\r
+\r
+/* A gimmick to make massive numbers of reallocs quicker.  The result is\r
+ * a number >= the input.  In PyNode_AddChild, it's used like so, when\r
+ * we're about to add child number current_size + 1:\r
+ *\r
+ *     if XXXROUNDUP(current_size) < XXXROUNDUP(current_size + 1):\r
+ *         allocate space for XXXROUNDUP(current_size + 1) total children\r
+ *     else:\r
+ *         we already have enough space\r
+ *\r
+ * Since a node starts out empty, we must have\r
+ *\r
+ *     XXXROUNDUP(0) < XXXROUNDUP(1)\r
+ *\r
+ * so that we allocate space for the first child.  One-child nodes are very\r
+ * common (presumably that would change if we used a more abstract form\r
+ * of syntax tree), so to avoid wasting memory it's desirable that\r
+ * XXXROUNDUP(1) == 1.  That in turn forces XXXROUNDUP(0) == 0.\r
+ *\r
+ * Else for 2 <= n <= 128, we round up to the closest multiple of 4.  Why 4?\r
+ * Rounding up to a multiple of an exact power of 2 is very efficient, and\r
+ * most nodes with more than one child have <= 4 kids.\r
+ *\r
+ * Else we call fancy_roundup() to grow proportionately to n.  We've got an\r
+ * extreme case then (like test_longexp.py), and on many platforms doing\r
+ * anything less than proportional growth leads to exorbitant runtime\r
+ * (e.g., MacPython), or extreme fragmentation of user address space (e.g.,\r
+ * Win98).\r
+ *\r
+ * In a run of compileall across the 2.3a0 Lib directory, Andrew MacIntyre\r
+ * reported that, with this scheme, 89% of PyObject_REALLOC calls in\r
+ * PyNode_AddChild passed 1 for the size, and 9% passed 4.  So this usually\r
+ * wastes very little memory, but is very effective at sidestepping\r
+ * platform-realloc disasters on vulnerable platforms.\r
+ *\r
+ * Note that this would be straightforward if a node stored its current\r
+ * capacity.  The code is tricky to avoid that.\r
+ */\r
+#define XXXROUNDUP(n) ((n) <= 1 ? (n) :                 \\r
+               (n) <= 128 ? (((n) + 3) & ~3) :          \\r
+               fancy_roundup(n))\r
+\r
+\r
+int\r
+PyNode_AddChild(register node *n1, int type, char *str, int lineno, int col_offset)\r
+{\r
+    const int nch = n1->n_nchildren;\r
+    int current_capacity;\r
+    int required_capacity;\r
+    node *n;\r
+\r
+    if (nch == INT_MAX || nch < 0)\r
+        return E_OVERFLOW;\r
+\r
+    current_capacity = XXXROUNDUP(nch);\r
+    required_capacity = XXXROUNDUP(nch + 1);\r
+    if (current_capacity < 0 || required_capacity < 0)\r
+        return E_OVERFLOW;\r
+    if (current_capacity < required_capacity) {\r
+        if (required_capacity > PY_SIZE_MAX / sizeof(node)) {\r
+            return E_NOMEM;\r
+        }\r
+        n = n1->n_child;\r
+        n = (node *) PyObject_REALLOC(n,\r
+                                      required_capacity * sizeof(node));\r
+        if (n == NULL)\r
+            return E_NOMEM;\r
+        n1->n_child = n;\r
+    }\r
+\r
+    n = &n1->n_child[n1->n_nchildren++];\r
+    n->n_type = type;\r
+    n->n_str = str;\r
+    n->n_lineno = lineno;\r
+    n->n_col_offset = col_offset;\r
+    n->n_nchildren = 0;\r
+    n->n_child = NULL;\r
+    return 0;\r
+}\r
+\r
+/* Forward */\r
+static void freechildren(node *);\r
+static Py_ssize_t sizeofchildren(node *n);\r
+\r
+\r
+void\r
+PyNode_Free(node *n)\r
+{\r
+    if (n != NULL) {\r
+        freechildren(n);\r
+        PyObject_FREE(n);\r
+    }\r
+}\r
+\r
+Py_ssize_t\r
+_PyNode_SizeOf(node *n)\r
+{\r
+    Py_ssize_t res = 0;\r
+\r
+    if (n != NULL)\r
+        res = sizeof(node) + sizeofchildren(n);\r
+    return res;\r
+}\r
+\r
+static void\r
+freechildren(node *n)\r
+{\r
+    int i;\r
+    for (i = NCH(n); --i >= 0; )\r
+        freechildren(CHILD(n, i));\r
+    if (n->n_child != NULL)\r
+        PyObject_FREE(n->n_child);\r
+    if (STR(n) != NULL)\r
+        PyObject_FREE(STR(n));\r
+}\r
+\r
+static Py_ssize_t\r
+sizeofchildren(node *n)\r
+{\r
+    Py_ssize_t res = 0;\r
+    int i;\r
+    for (i = NCH(n); --i >= 0; )\r
+        res += sizeofchildren(CHILD(n, i));\r
+    if (n->n_child != NULL)\r
+        /* allocated size of n->n_child array */\r
+        res += XXXROUNDUP(NCH(n)) * sizeof(node);\r
+    if (STR(n) != NULL)\r
+        res += strlen(STR(n)) + 1;\r
+    return res;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/parser.c b/AppPkg/Applications/Python/Python-2.7.10/Parser/parser.c
new file mode 100644 (file)
index 0000000..d98dfaa
--- /dev/null
@@ -0,0 +1,436 @@
+\r
+/* Parser implementation */\r
+\r
+/* For a description, see the comments at end of this file */\r
+\r
+/* XXX To do: error recovery */\r
+\r
+#include "Python.h"\r
+#include "pgenheaders.h"\r
+#include "token.h"\r
+#include "grammar.h"\r
+#include "node.h"\r
+#include "parser.h"\r
+#include "errcode.h"\r
+\r
+\r
+#ifdef Py_DEBUG\r
+extern int Py_DebugFlag;\r
+#define D(x) if (!Py_DebugFlag); else x\r
+#else\r
+#define D(x)\r
+#endif\r
+\r
+\r
+/* STACK DATA TYPE */\r
+\r
+static void s_reset(stack *);\r
+\r
+static void\r
+s_reset(stack *s)\r
+{\r
+    s->s_top = &s->s_base[MAXSTACK];\r
+}\r
+\r
+#define s_empty(s) ((s)->s_top == &(s)->s_base[MAXSTACK])\r
+\r
+static int\r
+s_push(register stack *s, dfa *d, node *parent)\r
+{\r
+    register stackentry *top;\r
+    if (s->s_top == s->s_base) {\r
+        fprintf(stderr, "s_push: parser stack overflow\n");\r
+        return E_NOMEM;\r
+    }\r
+    top = --s->s_top;\r
+    top->s_dfa = d;\r
+    top->s_parent = parent;\r
+    top->s_state = 0;\r
+    return 0;\r
+}\r
+\r
+#ifdef Py_DEBUG\r
+\r
+static void\r
+s_pop(register stack *s)\r
+{\r
+    if (s_empty(s))\r
+        Py_FatalError("s_pop: parser stack underflow -- FATAL");\r
+    s->s_top++;\r
+}\r
+\r
+#else /* !Py_DEBUG */\r
+\r
+#define s_pop(s) (s)->s_top++\r
+\r
+#endif\r
+\r
+\r
+/* PARSER CREATION */\r
+\r
+parser_state *\r
+PyParser_New(grammar *g, int start)\r
+{\r
+    parser_state *ps;\r
+\r
+    if (!g->g_accel)\r
+        PyGrammar_AddAccelerators(g);\r
+    ps = (parser_state *)PyMem_MALLOC(sizeof(parser_state));\r
+    if (ps == NULL)\r
+        return NULL;\r
+    ps->p_grammar = g;\r
+#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD\r
+    ps->p_flags = 0;\r
+#endif\r
+    ps->p_tree = PyNode_New(start);\r
+    if (ps->p_tree == NULL) {\r
+        PyMem_FREE(ps);\r
+        return NULL;\r
+    }\r
+    s_reset(&ps->p_stack);\r
+    (void) s_push(&ps->p_stack, PyGrammar_FindDFA(g, start), ps->p_tree);\r
+    return ps;\r
+}\r
+\r
+void\r
+PyParser_Delete(parser_state *ps)\r
+{\r
+    /* NB If you want to save the parse tree,\r
+       you must set p_tree to NULL before calling delparser! */\r
+    PyNode_Free(ps->p_tree);\r
+    PyMem_FREE(ps);\r
+}\r
+\r
+\r
+/* PARSER STACK OPERATIONS */\r
+\r
+static int\r
+shift(register stack *s, int type, char *str, int newstate, int lineno, int col_offset)\r
+{\r
+    int err;\r
+    assert(!s_empty(s));\r
+    err = PyNode_AddChild(s->s_top->s_parent, type, str, lineno, col_offset);\r
+    if (err)\r
+        return err;\r
+    s->s_top->s_state = newstate;\r
+    return 0;\r
+}\r
+\r
+static int\r
+push(register stack *s, int type, dfa *d, int newstate, int lineno, int col_offset)\r
+{\r
+    int err;\r
+    register node *n;\r
+    n = s->s_top->s_parent;\r
+    assert(!s_empty(s));\r
+    err = PyNode_AddChild(n, type, (char *)NULL, lineno, col_offset);\r
+    if (err)\r
+        return err;\r
+    s->s_top->s_state = newstate;\r
+    return s_push(s, d, CHILD(n, NCH(n)-1));\r
+}\r
+\r
+\r
+/* PARSER PROPER */\r
+\r
+static int\r
+classify(parser_state *ps, int type, char *str)\r
+{\r
+    grammar *g = ps->p_grammar;\r
+    register int n = g->g_ll.ll_nlabels;\r
+\r
+    if (type == NAME) {\r
+        register char *s = str;\r
+        register label *l = g->g_ll.ll_label;\r
+        register int i;\r
+        for (i = n; i > 0; i--, l++) {\r
+            if (l->lb_type != NAME || l->lb_str == NULL ||\r
+                l->lb_str[0] != s[0] ||\r
+                strcmp(l->lb_str, s) != 0)\r
+                continue;\r
+#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD\r
+            if (ps->p_flags & CO_FUTURE_PRINT_FUNCTION &&\r
+                s[0] == 'p' && strcmp(s, "print") == 0) {\r
+                break; /* no longer a keyword */\r
+            }\r
+#endif\r
+            D(printf("It's a keyword\n"));\r
+            return n - i;\r
+        }\r
+    }\r
+\r
+    {\r
+        register label *l = g->g_ll.ll_label;\r
+        register int i;\r
+        for (i = n; i > 0; i--, l++) {\r
+            if (l->lb_type == type && l->lb_str == NULL) {\r
+                D(printf("It's a token we know\n"));\r
+                return n - i;\r
+            }\r
+        }\r
+    }\r
+\r
+    D(printf("Illegal token\n"));\r
+    return -1;\r
+}\r
+\r
+#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD\r
+static void\r
+future_hack(parser_state *ps)\r
+{\r
+    node *n = ps->p_stack.s_top->s_parent;\r
+    node *ch, *cch;\r
+    int i;\r
+\r
+    /* from __future__ import ..., must have at least 4 children */\r
+    n = CHILD(n, 0);\r
+    if (NCH(n) < 4)\r
+        return;\r
+    ch = CHILD(n, 0);\r
+    if (STR(ch) == NULL || strcmp(STR(ch), "from") != 0)\r
+        return;\r
+    ch = CHILD(n, 1);\r
+    if (NCH(ch) == 1 && STR(CHILD(ch, 0)) &&\r
+        strcmp(STR(CHILD(ch, 0)), "__future__") != 0)\r
+        return;\r
+    ch = CHILD(n, 3);\r
+    /* ch can be a star, a parenthesis or import_as_names */\r
+    if (TYPE(ch) == STAR)\r
+        return;\r
+    if (TYPE(ch) == LPAR)\r
+        ch = CHILD(n, 4);\r
+\r
+    for (i = 0; i < NCH(ch); i += 2) {\r
+        cch = CHILD(ch, i);\r
+        if (NCH(cch) >= 1 && TYPE(CHILD(cch, 0)) == NAME) {\r
+            char *str_ch = STR(CHILD(cch, 0));\r
+            if (strcmp(str_ch, FUTURE_WITH_STATEMENT) == 0) {\r
+                ps->p_flags |= CO_FUTURE_WITH_STATEMENT;\r
+            } else if (strcmp(str_ch, FUTURE_PRINT_FUNCTION) == 0) {\r
+                ps->p_flags |= CO_FUTURE_PRINT_FUNCTION;\r
+            } else if (strcmp(str_ch, FUTURE_UNICODE_LITERALS) == 0) {\r
+                ps->p_flags |= CO_FUTURE_UNICODE_LITERALS;\r
+            }\r
+        }\r
+    }\r
+}\r
+#endif /* future keyword */\r
+\r
+int\r
+PyParser_AddToken(register parser_state *ps, register int type, char *str,\r
+                  int lineno, int col_offset, int *expected_ret)\r
+{\r
+    register int ilabel;\r
+    int err;\r
+\r
+    D(printf("Token %s/'%s' ... ", _PyParser_TokenNames[type], str));\r
+\r
+    /* Find out which label this token is */\r
+    ilabel = classify(ps, type, str);\r
+    if (ilabel < 0)\r
+        return E_SYNTAX;\r
+\r
+    /* Loop until the token is shifted or an error occurred */\r
+    for (;;) {\r
+        /* Fetch the current dfa and state */\r
+        register dfa *d = ps->p_stack.s_top->s_dfa;\r
+        register state *s = &d->d_state[ps->p_stack.s_top->s_state];\r
+\r
+        D(printf(" DFA '%s', state %d:",\r
+            d->d_name, ps->p_stack.s_top->s_state));\r
+\r
+        /* Check accelerator */\r
+        if (s->s_lower <= ilabel && ilabel < s->s_upper) {\r
+            register int x = s->s_accel[ilabel - s->s_lower];\r
+            if (x != -1) {\r
+                if (x & (1<<7)) {\r
+                    /* Push non-terminal */\r
+                    int nt = (x >> 8) + NT_OFFSET;\r
+                    int arrow = x & ((1<<7)-1);\r
+                    dfa *d1 = PyGrammar_FindDFA(\r
+                        ps->p_grammar, nt);\r
+                    if ((err = push(&ps->p_stack, nt, d1,\r
+                        arrow, lineno, col_offset)) > 0) {\r
+                        D(printf(" MemError: push\n"));\r
+                        return err;\r
+                    }\r
+                    D(printf(" Push ...\n"));\r
+                    continue;\r
+                }\r
+\r
+                /* Shift the token */\r
+                if ((err = shift(&ps->p_stack, type, str,\r
+                                x, lineno, col_offset)) > 0) {\r
+                    D(printf(" MemError: shift.\n"));\r
+                    return err;\r
+                }\r
+                D(printf(" Shift.\n"));\r
+                /* Pop while we are in an accept-only state */\r
+                while (s = &d->d_state\r
+                                [ps->p_stack.s_top->s_state],\r
+                    s->s_accept && s->s_narcs == 1) {\r
+                    D(printf("  DFA '%s', state %d: "\r
+                             "Direct pop.\n",\r
+                             d->d_name,\r
+                             ps->p_stack.s_top->s_state));\r
+#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD\r
+                    if (d->d_name[0] == 'i' &&\r
+                        strcmp(d->d_name,\r
+                           "import_stmt") == 0)\r
+                        future_hack(ps);\r
+#endif\r
+                    s_pop(&ps->p_stack);\r
+                    if (s_empty(&ps->p_stack)) {\r
+                        D(printf("  ACCEPT.\n"));\r
+                        return E_DONE;\r
+                    }\r
+                    d = ps->p_stack.s_top->s_dfa;\r
+                }\r
+                return E_OK;\r
+            }\r
+        }\r
+\r
+        if (s->s_accept) {\r
+#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD\r
+            if (d->d_name[0] == 'i' &&\r
+                strcmp(d->d_name, "import_stmt") == 0)\r
+                future_hack(ps);\r
+#endif\r
+            /* Pop this dfa and try again */\r
+            s_pop(&ps->p_stack);\r
+            D(printf(" Pop ...\n"));\r
+            if (s_empty(&ps->p_stack)) {\r
+                D(printf(" Error: bottom of stack.\n"));\r
+                return E_SYNTAX;\r
+            }\r
+            continue;\r
+        }\r
+\r
+        /* Stuck, report syntax error */\r
+        D(printf(" Error.\n"));\r
+        if (expected_ret) {\r
+            if (s->s_lower == s->s_upper - 1) {\r
+                /* Only one possible expected token */\r
+                *expected_ret = ps->p_grammar->\r
+                    g_ll.ll_label[s->s_lower].lb_type;\r
+            }\r
+            else\r
+                *expected_ret = -1;\r
+        }\r
+        return E_SYNTAX;\r
+    }\r
+}\r
+\r
+\r
+#ifdef Py_DEBUG\r
+\r
+/* DEBUG OUTPUT */\r
+\r
+void\r
+dumptree(grammar *g, node *n)\r
+{\r
+    int i;\r
+\r
+    if (n == NULL)\r
+        printf("NIL");\r
+    else {\r
+        label l;\r
+        l.lb_type = TYPE(n);\r
+        l.lb_str = STR(n);\r
+        printf("%s", PyGrammar_LabelRepr(&l));\r
+        if (ISNONTERMINAL(TYPE(n))) {\r
+            printf("(");\r
+            for (i = 0; i < NCH(n); i++) {\r
+                if (i > 0)\r
+                    printf(",");\r
+                dumptree(g, CHILD(n, i));\r
+            }\r
+            printf(")");\r
+        }\r
+    }\r
+}\r
+\r
+void\r
+showtree(grammar *g, node *n)\r
+{\r
+    int i;\r
+\r
+    if (n == NULL)\r
+        return;\r
+    if (ISNONTERMINAL(TYPE(n))) {\r
+        for (i = 0; i < NCH(n); i++)\r
+            showtree(g, CHILD(n, i));\r
+    }\r
+    else if (ISTERMINAL(TYPE(n))) {\r
+        printf("%s", _PyParser_TokenNames[TYPE(n)]);\r
+        if (TYPE(n) == NUMBER || TYPE(n) == NAME)\r
+            printf("(%s)", STR(n));\r
+        printf(" ");\r
+    }\r
+    else\r
+        printf("? ");\r
+}\r
+\r
+void\r
+printtree(parser_state *ps)\r
+{\r
+    if (Py_DebugFlag) {\r
+        printf("Parse tree:\n");\r
+        dumptree(ps->p_grammar, ps->p_tree);\r
+        printf("\n");\r
+        printf("Tokens:\n");\r
+        showtree(ps->p_grammar, ps->p_tree);\r
+        printf("\n");\r
+    }\r
+    printf("Listing:\n");\r
+    PyNode_ListTree(ps->p_tree);\r
+    printf("\n");\r
+}\r
+\r
+#endif /* Py_DEBUG */\r
+\r
+/*\r
+\r
+Description\r
+-----------\r
+\r
+The parser's interface is different than usual: the function addtoken()\r
+must be called for each token in the input.  This makes it possible to\r
+turn it into an incremental parsing system later.  The parsing system\r
+constructs a parse tree as it goes.\r
+\r
+A parsing rule is represented as a Deterministic Finite-state Automaton\r
+(DFA).  A node in a DFA represents a state of the parser; an arc represents\r
+a transition.  Transitions are either labeled with terminal symbols or\r
+with non-terminals.  When the parser decides to follow an arc labeled\r
+with a non-terminal, it is invoked recursively with the DFA representing\r
+the parsing rule for that as its initial state; when that DFA accepts,\r
+the parser that invoked it continues.  The parse tree constructed by the\r
+recursively called parser is inserted as a child in the current parse tree.\r
+\r
+The DFA's can be constructed automatically from a more conventional\r
+language description.  An extended LL(1) grammar (ELL(1)) is suitable.\r
+Certain restrictions make the parser's life easier: rules that can produce\r
+the empty string should be outlawed (there are other ways to put loops\r
+or optional parts in the language).  To avoid the need to construct\r
+FIRST sets, we can require that all but the last alternative of a rule\r
+(really: arc going out of a DFA's state) must begin with a terminal\r
+symbol.\r
+\r
+As an example, consider this grammar:\r
+\r
+expr:   term (OP term)*\r
+term:   CONSTANT | '(' expr ')'\r
+\r
+The DFA corresponding to the rule for expr is:\r
+\r
+------->.---term-->.------->\r
+    ^          |\r
+    |          |\r
+    \----OP----/\r
+\r
+The parse tree generated for the input a+b is:\r
+\r
+(expr: (term: (NAME: a)), (OP: +), (term: (NAME: b)))\r
+\r
+*/\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/parser.h b/AppPkg/Applications/Python/Python-2.7.10/Parser/parser.h
new file mode 100644 (file)
index 0000000..bc09396
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef Py_PARSER_H\r
+#define Py_PARSER_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Parser interface */\r
+\r
+#define MAXSTACK 1500\r
+\r
+typedef struct {\r
+       int              s_state;       /* State in current DFA */\r
+       dfa             *s_dfa;         /* Current DFA */\r
+       struct _node    *s_parent;      /* Where to add next node */\r
+} stackentry;\r
+\r
+typedef struct {\r
+       stackentry      *s_top;         /* Top entry */\r
+       stackentry       s_base[MAXSTACK];/* Array of stack entries */\r
+                                       /* NB The stack grows down */\r
+} stack;\r
+\r
+typedef struct {\r
+       stack           p_stack;        /* Stack of parser states */\r
+       grammar         *p_grammar;     /* Grammar to use */\r
+       node            *p_tree;        /* Top of parse tree */\r
+#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD\r
+       unsigned long   p_flags;        /* see co_flags in Include/code.h */\r
+#endif\r
+} parser_state;\r
+\r
+parser_state *PyParser_New(grammar *g, int start);\r
+void PyParser_Delete(parser_state *ps);\r
+int PyParser_AddToken(parser_state *ps, int type, char *str, int lineno, int col_offset,\r
+                      int *expected_ret);\r
+void PyGrammar_AddAccelerators(grammar *g);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_PARSER_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/parsetok.c b/AppPkg/Applications/Python/Python-2.7.10/Parser/parsetok.c
new file mode 100644 (file)
index 0000000..ac1eeb6
--- /dev/null
@@ -0,0 +1,282 @@
+\r
+/* Parser-tokenizer link implementation */\r
+\r
+#include "pgenheaders.h"\r
+#include "tokenizer.h"\r
+#include "node.h"\r
+#include "grammar.h"\r
+#include "parser.h"\r
+#include "parsetok.h"\r
+#include "errcode.h"\r
+#include "graminit.h"\r
+\r
+int Py_TabcheckFlag;\r
+\r
+\r
+/* Forward */\r
+static node *parsetok(struct tok_state *, grammar *, int, perrdetail *, int *);\r
+static void initerr(perrdetail *err_ret, const char* filename);\r
+\r
+/* Parse input coming from a string.  Return error code, print some errors. */\r
+node *\r
+PyParser_ParseString(const char *s, grammar *g, int start, perrdetail *err_ret)\r
+{\r
+    return PyParser_ParseStringFlagsFilename(s, NULL, g, start, err_ret, 0);\r
+}\r
+\r
+node *\r
+PyParser_ParseStringFlags(const char *s, grammar *g, int start,\r
+                          perrdetail *err_ret, int flags)\r
+{\r
+    return PyParser_ParseStringFlagsFilename(s, NULL,\r
+                                             g, start, err_ret, flags);\r
+}\r
+\r
+node *\r
+PyParser_ParseStringFlagsFilename(const char *s, const char *filename,\r
+                          grammar *g, int start,\r
+                          perrdetail *err_ret, int flags)\r
+{\r
+    int iflags = flags;\r
+    return PyParser_ParseStringFlagsFilenameEx(s, filename, g, start,\r
+                                               err_ret, &iflags);\r
+}\r
+\r
+node *\r
+PyParser_ParseStringFlagsFilenameEx(const char *s, const char *filename,\r
+                          grammar *g, int start,\r
+                          perrdetail *err_ret, int *flags)\r
+{\r
+    struct tok_state *tok;\r
+\r
+    initerr(err_ret, filename);\r
+\r
+    if ((tok = PyTokenizer_FromString(s, start == file_input)) == NULL) {\r
+        err_ret->error = PyErr_Occurred() ? E_DECODE : E_NOMEM;\r
+        return NULL;\r
+    }\r
+\r
+    tok->filename = filename ? filename : "<string>";\r
+    if (Py_TabcheckFlag || Py_VerboseFlag) {\r
+        tok->altwarning = (tok->filename != NULL);\r
+        if (Py_TabcheckFlag >= 2)\r
+            tok->alterror++;\r
+    }\r
+\r
+    return parsetok(tok, g, start, err_ret, flags);\r
+}\r
+\r
+/* Parse input coming from a file.  Return error code, print some errors. */\r
+\r
+node *\r
+PyParser_ParseFile(FILE *fp, const char *filename, grammar *g, int start,\r
+                   char *ps1, char *ps2, perrdetail *err_ret)\r
+{\r
+    return PyParser_ParseFileFlags(fp, filename, g, start, ps1, ps2,\r
+                                   err_ret, 0);\r
+}\r
+\r
+node *\r
+PyParser_ParseFileFlags(FILE *fp, const char *filename, grammar *g, int start,\r
+                        char *ps1, char *ps2, perrdetail *err_ret, int flags)\r
+{\r
+    int iflags = flags;\r
+    return PyParser_ParseFileFlagsEx(fp, filename, g, start, ps1, ps2, err_ret, &iflags);\r
+}\r
+\r
+node *\r
+PyParser_ParseFileFlagsEx(FILE *fp, const char *filename, grammar *g, int start,\r
+                          char *ps1, char *ps2, perrdetail *err_ret, int *flags)\r
+{\r
+    struct tok_state *tok;\r
+\r
+    initerr(err_ret, filename);\r
+\r
+    if ((tok = PyTokenizer_FromFile(fp, ps1, ps2)) == NULL) {\r
+        err_ret->error = E_NOMEM;\r
+        return NULL;\r
+    }\r
+    tok->filename = filename;\r
+    if (Py_TabcheckFlag || Py_VerboseFlag) {\r
+        tok->altwarning = (filename != NULL);\r
+        if (Py_TabcheckFlag >= 2)\r
+            tok->alterror++;\r
+    }\r
+\r
+    return parsetok(tok, g, start, err_ret, flags);\r
+}\r
+\r
+#if 0\r
+static char with_msg[] =\r
+"%s:%d: Warning: 'with' will become a reserved keyword in Python 2.6\n";\r
+\r
+static char as_msg[] =\r
+"%s:%d: Warning: 'as' will become a reserved keyword in Python 2.6\n";\r
+\r
+static void\r
+warn(const char *msg, const char *filename, int lineno)\r
+{\r
+    if (filename == NULL)\r
+        filename = "<string>";\r
+    PySys_WriteStderr(msg, filename, lineno);\r
+}\r
+#endif\r
+\r
+/* Parse input coming from the given tokenizer structure.\r
+   Return error code. */\r
+\r
+static node *\r
+parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,\r
+         int *flags)\r
+{\r
+    parser_state *ps;\r
+    node *n;\r
+    int started = 0;\r
+\r
+    if ((ps = PyParser_New(g, start)) == NULL) {\r
+        fprintf(stderr, "no mem for new parser\n");\r
+        err_ret->error = E_NOMEM;\r
+        PyTokenizer_Free(tok);\r
+        return NULL;\r
+    }\r
+#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD\r
+    if (*flags & PyPARSE_PRINT_IS_FUNCTION) {\r
+        ps->p_flags |= CO_FUTURE_PRINT_FUNCTION;\r
+    }\r
+    if (*flags & PyPARSE_UNICODE_LITERALS) {\r
+        ps->p_flags |= CO_FUTURE_UNICODE_LITERALS;\r
+    }\r
+\r
+#endif\r
+\r
+    for (;;) {\r
+        char *a, *b;\r
+        int type;\r
+        size_t len;\r
+        char *str;\r
+        int col_offset;\r
+\r
+        type = PyTokenizer_Get(tok, &a, &b);\r
+        if (type == ERRORTOKEN) {\r
+            err_ret->error = tok->done;\r
+            break;\r
+        }\r
+        if (type == ENDMARKER && started) {\r
+            type = NEWLINE; /* Add an extra newline */\r
+            started = 0;\r
+            /* Add the right number of dedent tokens,\r
+               except if a certain flag is given --\r
+               codeop.py uses this. */\r
+            if (tok->indent &&\r
+                !(*flags & PyPARSE_DONT_IMPLY_DEDENT))\r
+            {\r
+                tok->pendin = -tok->indent;\r
+                tok->indent = 0;\r
+            }\r
+        }\r
+        else\r
+            started = 1;\r
+        len = b - a; /* XXX this may compute NULL - NULL */\r
+        str = (char *) PyObject_MALLOC(len + 1);\r
+        if (str == NULL) {\r
+            fprintf(stderr, "no mem for next token\n");\r
+            err_ret->error = E_NOMEM;\r
+            break;\r
+        }\r
+        if (len > 0)\r
+            strncpy(str, a, len);\r
+        str[len] = '\0';\r
+\r
+#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD\r
+#endif\r
+        if (a >= tok->line_start)\r
+            col_offset = a - tok->line_start;\r
+        else\r
+            col_offset = -1;\r
+\r
+        if ((err_ret->error =\r
+             PyParser_AddToken(ps, (int)type, str, tok->lineno, col_offset,\r
+                               &(err_ret->expected))) != E_OK) {\r
+            if (err_ret->error != E_DONE) {\r
+                PyObject_FREE(str);\r
+                err_ret->token = type;\r
+            }\r
+            break;\r
+        }\r
+    }\r
+\r
+    if (err_ret->error == E_DONE) {\r
+        n = ps->p_tree;\r
+        ps->p_tree = NULL;\r
+    }\r
+    else\r
+        n = NULL;\r
+\r
+#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD\r
+    *flags = ps->p_flags;\r
+#endif\r
+    PyParser_Delete(ps);\r
+\r
+    if (n == NULL) {\r
+        if (tok->lineno <= 1 && tok->done == E_EOF)\r
+            err_ret->error = E_EOF;\r
+        err_ret->lineno = tok->lineno;\r
+        if (tok->buf != NULL) {\r
+            char *text = NULL;\r
+            size_t len;\r
+            assert(tok->cur - tok->buf < INT_MAX);\r
+            err_ret->offset = (int)(tok->cur - tok->buf);\r
+            len = tok->inp - tok->buf;\r
+#ifdef Py_USING_UNICODE\r
+            text = PyTokenizer_RestoreEncoding(tok, len, &err_ret->offset);\r
+\r
+#endif\r
+            if (text == NULL) {\r
+                text = (char *) PyObject_MALLOC(len + 1);\r
+                if (text != NULL) {\r
+                    if (len > 0)\r
+                        strncpy(text, tok->buf, len);\r
+                    text[len] = '\0';\r
+                }\r
+            }\r
+            err_ret->text = text;\r
+        }\r
+    } else if (tok->encoding != NULL) {\r
+        /* 'nodes->n_str' uses PyObject_*, while 'tok->encoding' was\r
+         * allocated using PyMem_\r
+         */\r
+        node* r = PyNode_New(encoding_decl);\r
+        if (r)\r
+            r->n_str = PyObject_MALLOC(strlen(tok->encoding)+1);\r
+        if (!r || !r->n_str) {\r
+            err_ret->error = E_NOMEM;\r
+            if (r)\r
+                PyObject_FREE(r);\r
+            n = NULL;\r
+            goto done;\r
+        }\r
+        strcpy(r->n_str, tok->encoding);\r
+        PyMem_FREE(tok->encoding);\r
+        tok->encoding = NULL;\r
+        r->n_nchildren = 1;\r
+        r->n_child = n;\r
+        n = r;\r
+    }\r
+\r
+done:\r
+    PyTokenizer_Free(tok);\r
+\r
+    return n;\r
+}\r
+\r
+static void\r
+initerr(perrdetail *err_ret, const char *filename)\r
+{\r
+    err_ret->error = E_OK;\r
+    err_ret->filename = filename;\r
+    err_ret->lineno = 0;\r
+    err_ret->offset = 0;\r
+    err_ret->text = NULL;\r
+    err_ret->token = -1;\r
+    err_ret->expected = -1;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/tokenizer.c b/AppPkg/Applications/Python/Python-2.7.10/Parser/tokenizer.c
new file mode 100644 (file)
index 0000000..086dc56
--- /dev/null
@@ -0,0 +1,1755 @@
+\r
+/* Tokenizer implementation */\r
+\r
+#include "Python.h"\r
+#include "pgenheaders.h"\r
+\r
+#include <ctype.h>\r
+#include <assert.h>\r
+\r
+#include "tokenizer.h"\r
+#include "errcode.h"\r
+\r
+#ifndef PGEN\r
+#include "unicodeobject.h"\r
+#include "stringobject.h"\r
+#include "fileobject.h"\r
+#include "codecs.h"\r
+#include "abstract.h"\r
+#include "pydebug.h"\r
+#endif /* PGEN */\r
+\r
+extern char *PyOS_Readline(FILE *, FILE *, char *);\r
+/* Return malloc'ed string including trailing \n;\r
+   empty malloc'ed string for EOF;\r
+   NULL if interrupted */\r
+\r
+/* Don't ever change this -- it would break the portability of Python code */\r
+#define TABSIZE 8\r
+\r
+/* Forward */\r
+static struct tok_state *tok_new(void);\r
+static int tok_nextc(struct tok_state *tok);\r
+static void tok_backup(struct tok_state *tok, int c);\r
+\r
+/* Token names */\r
+\r
+char *_PyParser_TokenNames[] = {\r
+    "ENDMARKER",\r
+    "NAME",\r
+    "NUMBER",\r
+    "STRING",\r
+    "NEWLINE",\r
+    "INDENT",\r
+    "DEDENT",\r
+    "LPAR",\r
+    "RPAR",\r
+    "LSQB",\r
+    "RSQB",\r
+    "COLON",\r
+    "COMMA",\r
+    "SEMI",\r
+    "PLUS",\r
+    "MINUS",\r
+    "STAR",\r
+    "SLASH",\r
+    "VBAR",\r
+    "AMPER",\r
+    "LESS",\r
+    "GREATER",\r
+    "EQUAL",\r
+    "DOT",\r
+    "PERCENT",\r
+    "BACKQUOTE",\r
+    "LBRACE",\r
+    "RBRACE",\r
+    "EQEQUAL",\r
+    "NOTEQUAL",\r
+    "LESSEQUAL",\r
+    "GREATEREQUAL",\r
+    "TILDE",\r
+    "CIRCUMFLEX",\r
+    "LEFTSHIFT",\r
+    "RIGHTSHIFT",\r
+    "DOUBLESTAR",\r
+    "PLUSEQUAL",\r
+    "MINEQUAL",\r
+    "STAREQUAL",\r
+    "SLASHEQUAL",\r
+    "PERCENTEQUAL",\r
+    "AMPEREQUAL",\r
+    "VBAREQUAL",\r
+    "CIRCUMFLEXEQUAL",\r
+    "LEFTSHIFTEQUAL",\r
+    "RIGHTSHIFTEQUAL",\r
+    "DOUBLESTAREQUAL",\r
+    "DOUBLESLASH",\r
+    "DOUBLESLASHEQUAL",\r
+    "AT",\r
+    /* This table must match the #defines in token.h! */\r
+    "OP",\r
+    "<ERRORTOKEN>",\r
+    "<N_TOKENS>"\r
+};\r
+\r
+/* Create and initialize a new tok_state structure */\r
+\r
+static struct tok_state *\r
+tok_new(void)\r
+{\r
+    struct tok_state *tok = (struct tok_state *)PyMem_MALLOC(\r
+                                            sizeof(struct tok_state));\r
+    if (tok == NULL)\r
+        return NULL;\r
+    tok->buf = tok->cur = tok->end = tok->inp = tok->start = NULL;\r
+    tok->done = E_OK;\r
+    tok->fp = NULL;\r
+    tok->input = NULL;\r
+    tok->tabsize = TABSIZE;\r
+    tok->indent = 0;\r
+    tok->indstack[0] = 0;\r
+    tok->atbol = 1;\r
+    tok->pendin = 0;\r
+    tok->prompt = tok->nextprompt = NULL;\r
+    tok->lineno = 0;\r
+    tok->level = 0;\r
+    tok->filename = NULL;\r
+    tok->altwarning = 0;\r
+    tok->alterror = 0;\r
+    tok->alttabsize = 1;\r
+    tok->altindstack[0] = 0;\r
+    tok->decoding_state = 0;\r
+    tok->decoding_erred = 0;\r
+    tok->read_coding_spec = 0;\r
+    tok->encoding = NULL;\r
+    tok->cont_line = 0;\r
+#ifndef PGEN\r
+    tok->decoding_readline = NULL;\r
+    tok->decoding_buffer = NULL;\r
+#endif\r
+    return tok;\r
+}\r
+\r
+static char *\r
+new_string(const char *s, Py_ssize_t len)\r
+{\r
+    char* result = (char *)PyMem_MALLOC(len + 1);\r
+    if (result != NULL) {\r
+        memcpy(result, s, len);\r
+        result[len] = '\0';\r
+    }\r
+    return result;\r
+}\r
+\r
+#ifdef PGEN\r
+\r
+static char *\r
+decoding_fgets(char *s, int size, struct tok_state *tok)\r
+{\r
+    return fgets(s, size, tok->fp);\r
+}\r
+\r
+static int\r
+decoding_feof(struct tok_state *tok)\r
+{\r
+    return feof(tok->fp);\r
+}\r
+\r
+static char *\r
+decode_str(const char *str, int exec_input, struct tok_state *tok)\r
+{\r
+    return new_string(str, strlen(str));\r
+}\r
+\r
+#else /* PGEN */\r
+\r
+static char *\r
+error_ret(struct tok_state *tok) /* XXX */\r
+{\r
+    tok->decoding_erred = 1;\r
+    if (tok->fp != NULL && tok->buf != NULL) /* see PyTokenizer_Free */\r
+        PyMem_FREE(tok->buf);\r
+    tok->buf = NULL;\r
+    return NULL;                /* as if it were EOF */\r
+}\r
+\r
+\r
+static char *\r
+get_normal_name(char *s)        /* for utf-8 and latin-1 */\r
+{\r
+    char buf[13];\r
+    int i;\r
+    for (i = 0; i < 12; i++) {\r
+        int c = s[i];\r
+        if (c == '\0')\r
+            break;\r
+        else if (c == '_')\r
+            buf[i] = '-';\r
+        else\r
+            buf[i] = tolower(c);\r
+    }\r
+    buf[i] = '\0';\r
+    if (strcmp(buf, "utf-8") == 0 ||\r
+        strncmp(buf, "utf-8-", 6) == 0)\r
+        return "utf-8";\r
+    else if (strcmp(buf, "latin-1") == 0 ||\r
+             strcmp(buf, "iso-8859-1") == 0 ||\r
+             strcmp(buf, "iso-latin-1") == 0 ||\r
+             strncmp(buf, "latin-1-", 8) == 0 ||\r
+             strncmp(buf, "iso-8859-1-", 11) == 0 ||\r
+             strncmp(buf, "iso-latin-1-", 12) == 0)\r
+        return "iso-8859-1";\r
+    else\r
+        return s;\r
+}\r
+\r
+/* Return the coding spec in S, or NULL if none is found.  */\r
+\r
+static char *\r
+get_coding_spec(const char *s, Py_ssize_t size)\r
+{\r
+    Py_ssize_t i;\r
+    /* Coding spec must be in a comment, and that comment must be\r
+     * the only statement on the source code line. */\r
+    for (i = 0; i < size - 6; i++) {\r
+        if (s[i] == '#')\r
+            break;\r
+        if (s[i] != ' ' && s[i] != '\t' && s[i] != '\014')\r
+            return NULL;\r
+    }\r
+    for (; i < size - 6; i++) { /* XXX inefficient search */\r
+        const char* t = s + i;\r
+        if (strncmp(t, "coding", 6) == 0) {\r
+            const char* begin = NULL;\r
+            t += 6;\r
+            if (t[0] != ':' && t[0] != '=')\r
+                continue;\r
+            do {\r
+                t++;\r
+            } while (t[0] == '\x20' || t[0] == '\t');\r
+\r
+            begin = t;\r
+            while (Py_ISALNUM(t[0]) ||\r
+                   t[0] == '-' || t[0] == '_' || t[0] == '.')\r
+                t++;\r
+\r
+            if (begin < t) {\r
+                char* r = new_string(begin, t - begin);\r
+                char* q = get_normal_name(r);\r
+                if (r != q) {\r
+                    PyMem_FREE(r);\r
+                    r = new_string(q, strlen(q));\r
+                }\r
+                return r;\r
+            }\r
+        }\r
+    }\r
+    return NULL;\r
+}\r
+\r
+/* Check whether the line contains a coding spec. If it does,\r
+   invoke the set_readline function for the new encoding.\r
+   This function receives the tok_state and the new encoding.\r
+   Return 1 on success, 0 on failure.  */\r
+\r
+static int\r
+check_coding_spec(const char* line, Py_ssize_t size, struct tok_state *tok,\r
+                  int set_readline(struct tok_state *, const char *))\r
+{\r
+    char * cs;\r
+    int r = 1;\r
+\r
+    if (tok->cont_line) {\r
+        /* It's a continuation line, so it can't be a coding spec. */\r
+        tok->read_coding_spec = 1;\r
+        return 1;\r
+    }\r
+    cs = get_coding_spec(line, size);\r
+    if (!cs) {\r
+        Py_ssize_t i;\r
+        for (i = 0; i < size; i++) {\r
+            if (line[i] == '#' || line[i] == '\n' || line[i] == '\r')\r
+                break;\r
+            if (line[i] != ' ' && line[i] != '\t' && line[i] != '\014') {\r
+                /* Stop checking coding spec after a line containing\r
+                 * anything except a comment. */\r
+                tok->read_coding_spec = 1;\r
+                break;\r
+            }\r
+        }\r
+    } else {\r
+        tok->read_coding_spec = 1;\r
+        if (tok->encoding == NULL) {\r
+            assert(tok->decoding_state == 1); /* raw */\r
+            if (strcmp(cs, "utf-8") == 0 ||\r
+                strcmp(cs, "iso-8859-1") == 0) {\r
+                tok->encoding = cs;\r
+            } else {\r
+#ifdef Py_USING_UNICODE\r
+                r = set_readline(tok, cs);\r
+                if (r) {\r
+                    tok->encoding = cs;\r
+                    tok->decoding_state = -1;\r
+                }\r
+                else {\r
+                    PyErr_Format(PyExc_SyntaxError,\r
+                                 "encoding problem: %s", cs);\r
+                    PyMem_FREE(cs);\r
+                }\r
+#else\r
+                /* Without Unicode support, we cannot\r
+                   process the coding spec. Since there\r
+                   won't be any Unicode literals, that\r
+                   won't matter. */\r
+                PyMem_FREE(cs);\r
+#endif\r
+            }\r
+        } else {                /* then, compare cs with BOM */\r
+            r = (strcmp(tok->encoding, cs) == 0);\r
+            if (!r)\r
+                PyErr_Format(PyExc_SyntaxError,\r
+                             "encoding problem: %s with BOM", cs);\r
+            PyMem_FREE(cs);\r
+        }\r
+    }\r
+    return r;\r
+}\r
+\r
+/* See whether the file starts with a BOM. If it does,\r
+   invoke the set_readline function with the new encoding.\r
+   Return 1 on success, 0 on failure.  */\r
+\r
+static int\r
+check_bom(int get_char(struct tok_state *),\r
+          void unget_char(int, struct tok_state *),\r
+          int set_readline(struct tok_state *, const char *),\r
+          struct tok_state *tok)\r
+{\r
+    int ch1, ch2, ch3;\r
+    ch1 = get_char(tok);\r
+    tok->decoding_state = 1;\r
+    if (ch1 == EOF) {\r
+        return 1;\r
+    } else if (ch1 == 0xEF) {\r
+        ch2 = get_char(tok);\r
+        if (ch2 != 0xBB) {\r
+            unget_char(ch2, tok);\r
+            unget_char(ch1, tok);\r
+            return 1;\r
+        }\r
+        ch3 = get_char(tok);\r
+        if (ch3 != 0xBF) {\r
+            unget_char(ch3, tok);\r
+            unget_char(ch2, tok);\r
+            unget_char(ch1, tok);\r
+            return 1;\r
+        }\r
+#if 0\r
+    /* Disable support for UTF-16 BOMs until a decision\r
+       is made whether this needs to be supported.  */\r
+    } else if (ch1 == 0xFE) {\r
+        ch2 = get_char(tok);\r
+        if (ch2 != 0xFF) {\r
+            unget_char(ch2, tok);\r
+            unget_char(ch1, tok);\r
+            return 1;\r
+        }\r
+        if (!set_readline(tok, "utf-16-be"))\r
+            return 0;\r
+        tok->decoding_state = -1;\r
+    } else if (ch1 == 0xFF) {\r
+        ch2 = get_char(tok);\r
+        if (ch2 != 0xFE) {\r
+            unget_char(ch2, tok);\r
+            unget_char(ch1, tok);\r
+            return 1;\r
+        }\r
+        if (!set_readline(tok, "utf-16-le"))\r
+            return 0;\r
+        tok->decoding_state = -1;\r
+#endif\r
+    } else {\r
+        unget_char(ch1, tok);\r
+        return 1;\r
+    }\r
+    if (tok->encoding != NULL)\r
+        PyMem_FREE(tok->encoding);\r
+    tok->encoding = new_string("utf-8", 5);     /* resulting is in utf-8 */\r
+    return 1;\r
+}\r
+\r
+/* Read a line of text from TOK into S, using the stream in TOK.\r
+   Return NULL on failure, else S.\r
+\r
+   On entry, tok->decoding_buffer will be one of:\r
+     1) NULL: need to call tok->decoding_readline to get a new line\r
+     2) PyUnicodeObject *: decoding_feof has called tok->decoding_readline and\r
+       stored the result in tok->decoding_buffer\r
+     3) PyStringObject *: previous call to fp_readl did not have enough room\r
+       (in the s buffer) to copy entire contents of the line read\r
+       by tok->decoding_readline.  tok->decoding_buffer has the overflow.\r
+       In this case, fp_readl is called in a loop (with an expanded buffer)\r
+       until the buffer ends with a '\n' (or until the end of the file is\r
+       reached): see tok_nextc and its calls to decoding_fgets.\r
+*/\r
+\r
+static char *\r
+fp_readl(char *s, int size, struct tok_state *tok)\r
+{\r
+#ifndef Py_USING_UNICODE\r
+    /* In a non-Unicode built, this should never be called. */\r
+    Py_FatalError("fp_readl should not be called in this build.");\r
+    return NULL; /* Keep compiler happy (not reachable) */\r
+#else\r
+    PyObject* utf8 = NULL;\r
+    PyObject* buf = tok->decoding_buffer;\r
+    char *str;\r
+    Py_ssize_t utf8len;\r
+\r
+    /* Ask for one less byte so we can terminate it */\r
+    assert(size > 0);\r
+    size--;\r
+\r
+    if (buf == NULL) {\r
+        buf = PyObject_CallObject(tok->decoding_readline, NULL);\r
+        if (buf == NULL)\r
+            return error_ret(tok);\r
+        if (!PyUnicode_Check(buf)) {\r
+            Py_DECREF(buf);\r
+            PyErr_SetString(PyExc_SyntaxError,\r
+                            "codec did not return a unicode object");\r
+            return error_ret(tok);\r
+        }\r
+    } else {\r
+        tok->decoding_buffer = NULL;\r
+        if (PyString_CheckExact(buf))\r
+            utf8 = buf;\r
+    }\r
+    if (utf8 == NULL) {\r
+        utf8 = PyUnicode_AsUTF8String(buf);\r
+        Py_DECREF(buf);\r
+        if (utf8 == NULL)\r
+            return error_ret(tok);\r
+    }\r
+    str = PyString_AsString(utf8);\r
+    utf8len = PyString_GET_SIZE(utf8);\r
+    if (utf8len > size) {\r
+        tok->decoding_buffer = PyString_FromStringAndSize(str+size, utf8len-size);\r
+        if (tok->decoding_buffer == NULL) {\r
+            Py_DECREF(utf8);\r
+            return error_ret(tok);\r
+        }\r
+        utf8len = size;\r
+    }\r
+    memcpy(s, str, utf8len);\r
+    s[utf8len] = '\0';\r
+    Py_DECREF(utf8);\r
+    if (utf8len == 0)\r
+        return NULL; /* EOF */\r
+    return s;\r
+#endif\r
+}\r
+\r
+/* Set the readline function for TOK to a StreamReader's\r
+   readline function. The StreamReader is named ENC.\r
+\r
+   This function is called from check_bom and check_coding_spec.\r
+\r
+   ENC is usually identical to the future value of tok->encoding,\r
+   except for the (currently unsupported) case of UTF-16.\r
+\r
+   Return 1 on success, 0 on failure. */\r
+\r
+static int\r
+fp_setreadl(struct tok_state *tok, const char* enc)\r
+{\r
+    PyObject *reader, *stream, *readline;\r
+\r
+    /* XXX: constify filename argument. */\r
+    stream = PyFile_FromFile(tok->fp, (char*)tok->filename, "rb", NULL);\r
+    if (stream == NULL)\r
+        return 0;\r
+\r
+    reader = PyCodec_StreamReader(enc, stream, NULL);\r
+    Py_DECREF(stream);\r
+    if (reader == NULL)\r
+        return 0;\r
+\r
+    readline = PyObject_GetAttrString(reader, "readline");\r
+    Py_DECREF(reader);\r
+    if (readline == NULL)\r
+        return 0;\r
+\r
+    tok->decoding_readline = readline;\r
+    return 1;\r
+}\r
+\r
+/* Fetch the next byte from TOK. */\r
+\r
+static int fp_getc(struct tok_state *tok) {\r
+    return getc(tok->fp);\r
+}\r
+\r
+/* Unfetch the last byte back into TOK.  */\r
+\r
+static void fp_ungetc(int c, struct tok_state *tok) {\r
+    ungetc(c, tok->fp);\r
+}\r
+\r
+/* Read a line of input from TOK. Determine encoding\r
+   if necessary.  */\r
+\r
+static char *\r
+decoding_fgets(char *s, int size, struct tok_state *tok)\r
+{\r
+    char *line = NULL;\r
+    int badchar = 0;\r
+    for (;;) {\r
+        if (tok->decoding_state < 0) {\r
+            /* We already have a codec associated with\r
+               this input. */\r
+            line = fp_readl(s, size, tok);\r
+            break;\r
+        } else if (tok->decoding_state > 0) {\r
+            /* We want a 'raw' read. */\r
+            line = Py_UniversalNewlineFgets(s, size,\r
+                                            tok->fp, NULL);\r
+            break;\r
+        } else {\r
+            /* We have not yet determined the encoding.\r
+               If an encoding is found, use the file-pointer\r
+               reader functions from now on. */\r
+            if (!check_bom(fp_getc, fp_ungetc, fp_setreadl, tok))\r
+                return error_ret(tok);\r
+            assert(tok->decoding_state != 0);\r
+        }\r
+    }\r
+    if (line != NULL && tok->lineno < 2 && !tok->read_coding_spec) {\r
+        if (!check_coding_spec(line, strlen(line), tok, fp_setreadl)) {\r
+            return error_ret(tok);\r
+        }\r
+    }\r
+#ifndef PGEN\r
+    /* The default encoding is ASCII, so make sure we don't have any\r
+       non-ASCII bytes in it. */\r
+    if (line && !tok->encoding) {\r
+        unsigned char *c;\r
+        for (c = (unsigned char *)line; *c; c++)\r
+            if (*c > 127) {\r
+                badchar = *c;\r
+                break;\r
+            }\r
+    }\r
+    if (badchar) {\r
+        char buf[500];\r
+        /* Need to add 1 to the line number, since this line\r
+           has not been counted, yet.  */\r
+        sprintf(buf,\r
+            "Non-ASCII character '\\x%.2x' "\r
+            "in file %.200s on line %i, "\r
+            "but no encoding declared; "\r
+            "see http://python.org/dev/peps/pep-0263/ for details",\r
+            badchar, tok->filename, tok->lineno + 1);\r
+        PyErr_SetString(PyExc_SyntaxError, buf);\r
+        return error_ret(tok);\r
+    }\r
+#endif\r
+    return line;\r
+}\r
+\r
+static int\r
+decoding_feof(struct tok_state *tok)\r
+{\r
+    if (tok->decoding_state >= 0) {\r
+        return feof(tok->fp);\r
+    } else {\r
+        PyObject* buf = tok->decoding_buffer;\r
+        if (buf == NULL) {\r
+            buf = PyObject_CallObject(tok->decoding_readline, NULL);\r
+            if (buf == NULL) {\r
+                error_ret(tok);\r
+                return 1;\r
+            } else {\r
+                tok->decoding_buffer = buf;\r
+            }\r
+        }\r
+        return PyObject_Length(buf) == 0;\r
+    }\r
+}\r
+\r
+/* Fetch a byte from TOK, using the string buffer. */\r
+\r
+static int\r
+buf_getc(struct tok_state *tok) {\r
+    return Py_CHARMASK(*tok->str++);\r
+}\r
+\r
+/* Unfetch a byte from TOK, using the string buffer. */\r
+\r
+static void\r
+buf_ungetc(int c, struct tok_state *tok) {\r
+    tok->str--;\r
+    assert(Py_CHARMASK(*tok->str) == c);        /* tok->cur may point to read-only segment */\r
+}\r
+\r
+/* Set the readline function for TOK to ENC. For the string-based\r
+   tokenizer, this means to just record the encoding. */\r
+\r
+static int\r
+buf_setreadl(struct tok_state *tok, const char* enc) {\r
+    tok->enc = enc;\r
+    return 1;\r
+}\r
+\r
+/* Return a UTF-8 encoding Python string object from the\r
+   C byte string STR, which is encoded with ENC. */\r
+\r
+#ifdef Py_USING_UNICODE\r
+static PyObject *\r
+translate_into_utf8(const char* str, const char* enc) {\r
+    PyObject *utf8;\r
+    PyObject* buf = PyUnicode_Decode(str, strlen(str), enc, NULL);\r
+    if (buf == NULL)\r
+        return NULL;\r
+    utf8 = PyUnicode_AsUTF8String(buf);\r
+    Py_DECREF(buf);\r
+    return utf8;\r
+}\r
+#endif\r
+\r
+\r
+static char *\r
+translate_newlines(const char *s, int exec_input, struct tok_state *tok) {\r
+    int skip_next_lf = 0, needed_length = strlen(s) + 2, final_length;\r
+    char *buf, *current;\r
+    char c = '\0';\r
+    buf = PyMem_MALLOC(needed_length);\r
+    if (buf == NULL) {\r
+        tok->done = E_NOMEM;\r
+        return NULL;\r
+    }\r
+    for (current = buf; *s; s++, current++) {\r
+        c = *s;\r
+        if (skip_next_lf) {\r
+            skip_next_lf = 0;\r
+            if (c == '\n') {\r
+                c = *++s;\r
+                if (!c)\r
+                    break;\r
+            }\r
+        }\r
+        if (c == '\r') {\r
+            skip_next_lf = 1;\r
+            c = '\n';\r
+        }\r
+        *current = c;\r
+    }\r
+    /* If this is exec input, add a newline to the end of the string if\r
+       there isn't one already. */\r
+    if (exec_input && c != '\n') {\r
+        *current = '\n';\r
+        current++;\r
+    }\r
+    *current = '\0';\r
+    final_length = current - buf + 1;\r
+    if (final_length < needed_length && final_length)\r
+        /* should never fail */\r
+        buf = PyMem_REALLOC(buf, final_length);\r
+    return buf;\r
+}\r
+\r
+/* Decode a byte string STR for use as the buffer of TOK.\r
+   Look for encoding declarations inside STR, and record them\r
+   inside TOK.  */\r
+\r
+static const char *\r
+decode_str(const char *input, int single, struct tok_state *tok)\r
+{\r
+    PyObject* utf8 = NULL;\r
+    const char *str;\r
+    const char *s;\r
+    const char *newl[2] = {NULL, NULL};\r
+    int lineno = 0;\r
+    tok->input = str = translate_newlines(input, single, tok);\r
+    if (str == NULL)\r
+        return NULL;\r
+    tok->enc = NULL;\r
+    tok->str = str;\r
+    if (!check_bom(buf_getc, buf_ungetc, buf_setreadl, tok))\r
+        return error_ret(tok);\r
+    str = tok->str;             /* string after BOM if any */\r
+    assert(str);\r
+#ifdef Py_USING_UNICODE\r
+    if (tok->enc != NULL) {\r
+        utf8 = translate_into_utf8(str, tok->enc);\r
+        if (utf8 == NULL)\r
+            return error_ret(tok);\r
+        str = PyString_AsString(utf8);\r
+    }\r
+#endif\r
+    for (s = str;; s++) {\r
+        if (*s == '\0') break;\r
+        else if (*s == '\n') {\r
+            assert(lineno < 2);\r
+            newl[lineno] = s;\r
+            lineno++;\r
+            if (lineno == 2) break;\r
+        }\r
+    }\r
+    tok->enc = NULL;\r
+    /* need to check line 1 and 2 separately since check_coding_spec\r
+       assumes a single line as input */\r
+    if (newl[0]) {\r
+        if (!check_coding_spec(str, newl[0] - str, tok, buf_setreadl))\r
+            return error_ret(tok);\r
+        if (tok->enc == NULL && !tok->read_coding_spec && newl[1]) {\r
+            if (!check_coding_spec(newl[0]+1, newl[1] - newl[0],\r
+                                   tok, buf_setreadl))\r
+                return error_ret(tok);\r
+        }\r
+    }\r
+#ifdef Py_USING_UNICODE\r
+    if (tok->enc != NULL) {\r
+        assert(utf8 == NULL);\r
+        utf8 = translate_into_utf8(str, tok->enc);\r
+        if (utf8 == NULL)\r
+            return error_ret(tok);\r
+        str = PyString_AsString(utf8);\r
+    }\r
+#endif\r
+    assert(tok->decoding_buffer == NULL);\r
+    tok->decoding_buffer = utf8; /* CAUTION */\r
+    return str;\r
+}\r
+\r
+#endif /* PGEN */\r
+\r
+/* Set up tokenizer for string */\r
+\r
+struct tok_state *\r
+PyTokenizer_FromString(const char *str, int exec_input)\r
+{\r
+    struct tok_state *tok = tok_new();\r
+    if (tok == NULL)\r
+        return NULL;\r
+    str = (char *)decode_str(str, exec_input, tok);\r
+    if (str == NULL) {\r
+        PyTokenizer_Free(tok);\r
+        return NULL;\r
+    }\r
+\r
+    /* XXX: constify members. */\r
+    tok->buf = tok->cur = tok->end = tok->inp = (char*)str;\r
+    return tok;\r
+}\r
+\r
+\r
+/* Set up tokenizer for file */\r
+\r
+struct tok_state *\r
+PyTokenizer_FromFile(FILE *fp, char *ps1, char *ps2)\r
+{\r
+    struct tok_state *tok = tok_new();\r
+    if (tok == NULL)\r
+        return NULL;\r
+    if ((tok->buf = (char *)PyMem_MALLOC(BUFSIZ)) == NULL) {\r
+        PyTokenizer_Free(tok);\r
+        return NULL;\r
+    }\r
+    tok->cur = tok->inp = tok->buf;\r
+    tok->end = tok->buf + BUFSIZ;\r
+    tok->fp = fp;\r
+    tok->prompt = ps1;\r
+    tok->nextprompt = ps2;\r
+    return tok;\r
+}\r
+\r
+\r
+/* Free a tok_state structure */\r
+\r
+void\r
+PyTokenizer_Free(struct tok_state *tok)\r
+{\r
+    if (tok->encoding != NULL)\r
+        PyMem_FREE(tok->encoding);\r
+#ifndef PGEN\r
+    Py_XDECREF(tok->decoding_readline);\r
+    Py_XDECREF(tok->decoding_buffer);\r
+#endif\r
+    if (tok->fp != NULL && tok->buf != NULL)\r
+        PyMem_FREE(tok->buf);\r
+    if (tok->input)\r
+        PyMem_FREE((char *)tok->input);\r
+    PyMem_FREE(tok);\r
+}\r
+\r
+#if !defined(PGEN) && defined(Py_USING_UNICODE)\r
+static int\r
+tok_stdin_decode(struct tok_state *tok, char **inp)\r
+{\r
+    PyObject *enc, *sysstdin, *decoded, *utf8;\r
+    const char *encoding;\r
+    char *converted;\r
+\r
+    if (PySys_GetFile((char *)"stdin", NULL) != stdin)\r
+        return 0;\r
+    sysstdin = PySys_GetObject("stdin");\r
+    if (sysstdin == NULL || !PyFile_Check(sysstdin))\r
+        return 0;\r
+\r
+    enc = ((PyFileObject *)sysstdin)->f_encoding;\r
+    if (enc == NULL || !PyString_Check(enc))\r
+        return 0;\r
+    Py_INCREF(enc);\r
+\r
+    encoding = PyString_AsString(enc);\r
+    decoded = PyUnicode_Decode(*inp, strlen(*inp), encoding, NULL);\r
+    if (decoded == NULL)\r
+        goto error_clear;\r
+\r
+    utf8 = PyUnicode_AsEncodedString(decoded, "utf-8", NULL);\r
+    Py_DECREF(decoded);\r
+    if (utf8 == NULL)\r
+        goto error_clear;\r
+\r
+    assert(PyString_Check(utf8));\r
+    converted = new_string(PyString_AS_STRING(utf8),\r
+                           PyString_GET_SIZE(utf8));\r
+    Py_DECREF(utf8);\r
+    if (converted == NULL)\r
+        goto error_nomem;\r
+\r
+    PyMem_FREE(*inp);\r
+    *inp = converted;\r
+    if (tok->encoding != NULL)\r
+        PyMem_FREE(tok->encoding);\r
+    tok->encoding = new_string(encoding, strlen(encoding));\r
+    if (tok->encoding == NULL)\r
+        goto error_nomem;\r
+\r
+    Py_DECREF(enc);\r
+    return 0;\r
+\r
+error_nomem:\r
+    Py_DECREF(enc);\r
+    tok->done = E_NOMEM;\r
+    return -1;\r
+\r
+error_clear:\r
+    Py_DECREF(enc);\r
+    if (!PyErr_ExceptionMatches(PyExc_UnicodeDecodeError)) {\r
+        tok->done = E_ERROR;\r
+        return -1;\r
+    }\r
+    /* Fallback to iso-8859-1: for backward compatibility */\r
+    PyErr_Clear();\r
+    return 0;\r
+}\r
+#endif\r
+\r
+/* Get next char, updating state; error code goes into tok->done */\r
+\r
+static int\r
+tok_nextc(register struct tok_state *tok)\r
+{\r
+    for (;;) {\r
+        if (tok->cur != tok->inp) {\r
+            return Py_CHARMASK(*tok->cur++); /* Fast path */\r
+        }\r
+        if (tok->done != E_OK)\r
+            return EOF;\r
+        if (tok->fp == NULL) {\r
+            char *end = strchr(tok->inp, '\n');\r
+            if (end != NULL)\r
+                end++;\r
+            else {\r
+                end = strchr(tok->inp, '\0');\r
+                if (end == tok->inp) {\r
+                    tok->done = E_EOF;\r
+                    return EOF;\r
+                }\r
+            }\r
+            if (tok->start == NULL)\r
+                tok->buf = tok->cur;\r
+            tok->line_start = tok->cur;\r
+            tok->lineno++;\r
+            tok->inp = end;\r
+            return Py_CHARMASK(*tok->cur++);\r
+        }\r
+        if (tok->prompt != NULL) {\r
+            char *newtok = PyOS_Readline(stdin, stdout, tok->prompt);\r
+            if (tok->nextprompt != NULL)\r
+                tok->prompt = tok->nextprompt;\r
+            if (newtok == NULL)\r
+                tok->done = E_INTR;\r
+            else if (*newtok == '\0') {\r
+                PyMem_FREE(newtok);\r
+                tok->done = E_EOF;\r
+            }\r
+#if !defined(PGEN) && defined(Py_USING_UNICODE)\r
+            else if (tok_stdin_decode(tok, &newtok) != 0)\r
+                PyMem_FREE(newtok);\r
+#endif\r
+            else if (tok->start != NULL) {\r
+                size_t start = tok->start - tok->buf;\r
+                size_t oldlen = tok->cur - tok->buf;\r
+                size_t newlen = oldlen + strlen(newtok);\r
+                char *buf = tok->buf;\r
+                buf = (char *)PyMem_REALLOC(buf, newlen+1);\r
+                tok->lineno++;\r
+                if (buf == NULL) {\r
+                    PyMem_FREE(tok->buf);\r
+                    tok->buf = NULL;\r
+                    PyMem_FREE(newtok);\r
+                    tok->done = E_NOMEM;\r
+                    return EOF;\r
+                }\r
+                tok->buf = buf;\r
+                tok->cur = tok->buf + oldlen;\r
+                tok->line_start = tok->cur;\r
+                strcpy(tok->buf + oldlen, newtok);\r
+                PyMem_FREE(newtok);\r
+                tok->inp = tok->buf + newlen;\r
+                tok->end = tok->inp + 1;\r
+                tok->start = tok->buf + start;\r
+            }\r
+            else {\r
+                tok->lineno++;\r
+                if (tok->buf != NULL)\r
+                    PyMem_FREE(tok->buf);\r
+                tok->buf = newtok;\r
+                tok->line_start = tok->buf;\r
+                tok->cur = tok->buf;\r
+                tok->line_start = tok->buf;\r
+                tok->inp = strchr(tok->buf, '\0');\r
+                tok->end = tok->inp + 1;\r
+            }\r
+        }\r
+        else {\r
+            int done = 0;\r
+            Py_ssize_t cur = 0;\r
+            char *pt;\r
+            if (tok->start == NULL) {\r
+                if (tok->buf == NULL) {\r
+                    tok->buf = (char *)\r
+                        PyMem_MALLOC(BUFSIZ);\r
+                    if (tok->buf == NULL) {\r
+                        tok->done = E_NOMEM;\r
+                        return EOF;\r
+                    }\r
+                    tok->end = tok->buf + BUFSIZ;\r
+                }\r
+                if (decoding_fgets(tok->buf, (int)(tok->end - tok->buf),\r
+                          tok) == NULL) {\r
+                    tok->done = E_EOF;\r
+                    done = 1;\r
+                }\r
+                else {\r
+                    tok->done = E_OK;\r
+                    tok->inp = strchr(tok->buf, '\0');\r
+                    done = tok->inp[-1] == '\n';\r
+                }\r
+            }\r
+            else {\r
+                cur = tok->cur - tok->buf;\r
+                if (decoding_feof(tok)) {\r
+                    tok->done = E_EOF;\r
+                    done = 1;\r
+                }\r
+                else\r
+                    tok->done = E_OK;\r
+            }\r
+            tok->lineno++;\r
+            /* Read until '\n' or EOF */\r
+            while (!done) {\r
+                Py_ssize_t curstart = tok->start == NULL ? -1 :\r
+                          tok->start - tok->buf;\r
+                Py_ssize_t curvalid = tok->inp - tok->buf;\r
+                Py_ssize_t newsize = curvalid + BUFSIZ;\r
+                char *newbuf = tok->buf;\r
+                newbuf = (char *)PyMem_REALLOC(newbuf,\r
+                                               newsize);\r
+                if (newbuf == NULL) {\r
+                    tok->done = E_NOMEM;\r
+                    tok->cur = tok->inp;\r
+                    return EOF;\r
+                }\r
+                tok->buf = newbuf;\r
+                tok->inp = tok->buf + curvalid;\r
+                tok->end = tok->buf + newsize;\r
+                tok->start = curstart < 0 ? NULL :\r
+                         tok->buf + curstart;\r
+                if (decoding_fgets(tok->inp,\r
+                               (int)(tok->end - tok->inp),\r
+                               tok) == NULL) {\r
+                    /* Break out early on decoding\r
+                       errors, as tok->buf will be NULL\r
+                     */\r
+                    if (tok->decoding_erred)\r
+                        return EOF;\r
+                    /* Last line does not end in \n,\r
+                       fake one */\r
+                    strcpy(tok->inp, "\n");\r
+                }\r
+                tok->inp = strchr(tok->inp, '\0');\r
+                done = tok->inp[-1] == '\n';\r
+            }\r
+            if (tok->buf != NULL) {\r
+                tok->cur = tok->buf + cur;\r
+                tok->line_start = tok->cur;\r
+                /* replace "\r\n" with "\n" */\r
+                /* For Mac leave the \r, giving a syntax error */\r
+                pt = tok->inp - 2;\r
+                if (pt >= tok->buf && *pt == '\r') {\r
+                    *pt++ = '\n';\r
+                    *pt = '\0';\r
+                    tok->inp = pt;\r
+                }\r
+            }\r
+        }\r
+        if (tok->done != E_OK) {\r
+            if (tok->prompt != NULL)\r
+                PySys_WriteStderr("\n");\r
+            tok->cur = tok->inp;\r
+            return EOF;\r
+        }\r
+    }\r
+    /*NOTREACHED*/\r
+}\r
+\r
+\r
+/* Back-up one character */\r
+\r
+static void\r
+tok_backup(register struct tok_state *tok, register int c)\r
+{\r
+    if (c != EOF) {\r
+        if (--tok->cur < tok->buf)\r
+            Py_FatalError("tok_backup: beginning of buffer");\r
+        if (*tok->cur != c)\r
+            *tok->cur = c;\r
+    }\r
+}\r
+\r
+\r
+/* Return the token corresponding to a single character */\r
+\r
+int\r
+PyToken_OneChar(int c)\r
+{\r
+    switch (c) {\r
+    case '(':           return LPAR;\r
+    case ')':           return RPAR;\r
+    case '[':           return LSQB;\r
+    case ']':           return RSQB;\r
+    case ':':           return COLON;\r
+    case ',':           return COMMA;\r
+    case ';':           return SEMI;\r
+    case '+':           return PLUS;\r
+    case '-':           return MINUS;\r
+    case '*':           return STAR;\r
+    case '/':           return SLASH;\r
+    case '|':           return VBAR;\r
+    case '&':           return AMPER;\r
+    case '<':           return LESS;\r
+    case '>':           return GREATER;\r
+    case '=':           return EQUAL;\r
+    case '.':           return DOT;\r
+    case '%':           return PERCENT;\r
+    case '`':           return BACKQUOTE;\r
+    case '{':           return LBRACE;\r
+    case '}':           return RBRACE;\r
+    case '^':           return CIRCUMFLEX;\r
+    case '~':           return TILDE;\r
+    case '@':       return AT;\r
+    default:            return OP;\r
+    }\r
+}\r
+\r
+\r
+int\r
+PyToken_TwoChars(int c1, int c2)\r
+{\r
+    switch (c1) {\r
+    case '=':\r
+        switch (c2) {\r
+        case '=':               return EQEQUAL;\r
+        }\r
+        break;\r
+    case '!':\r
+        switch (c2) {\r
+        case '=':               return NOTEQUAL;\r
+        }\r
+        break;\r
+    case '<':\r
+        switch (c2) {\r
+        case '>':               return NOTEQUAL;\r
+        case '=':               return LESSEQUAL;\r
+        case '<':               return LEFTSHIFT;\r
+        }\r
+        break;\r
+    case '>':\r
+        switch (c2) {\r
+        case '=':               return GREATEREQUAL;\r
+        case '>':               return RIGHTSHIFT;\r
+        }\r
+        break;\r
+    case '+':\r
+        switch (c2) {\r
+        case '=':               return PLUSEQUAL;\r
+        }\r
+        break;\r
+    case '-':\r
+        switch (c2) {\r
+        case '=':               return MINEQUAL;\r
+        }\r
+        break;\r
+    case '*':\r
+        switch (c2) {\r
+        case '*':               return DOUBLESTAR;\r
+        case '=':               return STAREQUAL;\r
+        }\r
+        break;\r
+    case '/':\r
+        switch (c2) {\r
+        case '/':               return DOUBLESLASH;\r
+        case '=':               return SLASHEQUAL;\r
+        }\r
+        break;\r
+    case '|':\r
+        switch (c2) {\r
+        case '=':               return VBAREQUAL;\r
+        }\r
+        break;\r
+    case '%':\r
+        switch (c2) {\r
+        case '=':               return PERCENTEQUAL;\r
+        }\r
+        break;\r
+    case '&':\r
+        switch (c2) {\r
+        case '=':               return AMPEREQUAL;\r
+        }\r
+        break;\r
+    case '^':\r
+        switch (c2) {\r
+        case '=':               return CIRCUMFLEXEQUAL;\r
+        }\r
+        break;\r
+    }\r
+    return OP;\r
+}\r
+\r
+int\r
+PyToken_ThreeChars(int c1, int c2, int c3)\r
+{\r
+    switch (c1) {\r
+    case '<':\r
+        switch (c2) {\r
+        case '<':\r
+            switch (c3) {\r
+            case '=':\r
+                return LEFTSHIFTEQUAL;\r
+            }\r
+            break;\r
+        }\r
+        break;\r
+    case '>':\r
+        switch (c2) {\r
+        case '>':\r
+            switch (c3) {\r
+            case '=':\r
+                return RIGHTSHIFTEQUAL;\r
+            }\r
+            break;\r
+        }\r
+        break;\r
+    case '*':\r
+        switch (c2) {\r
+        case '*':\r
+            switch (c3) {\r
+            case '=':\r
+                return DOUBLESTAREQUAL;\r
+            }\r
+            break;\r
+        }\r
+        break;\r
+    case '/':\r
+        switch (c2) {\r
+        case '/':\r
+            switch (c3) {\r
+            case '=':\r
+                return DOUBLESLASHEQUAL;\r
+            }\r
+            break;\r
+        }\r
+        break;\r
+    }\r
+    return OP;\r
+}\r
+\r
+static int\r
+indenterror(struct tok_state *tok)\r
+{\r
+    if (tok->alterror) {\r
+        tok->done = E_TABSPACE;\r
+        tok->cur = tok->inp;\r
+        return 1;\r
+    }\r
+    if (tok->altwarning) {\r
+        PySys_WriteStderr("%s: inconsistent use of tabs and spaces "\r
+                          "in indentation\n", tok->filename);\r
+        tok->altwarning = 0;\r
+    }\r
+    return 0;\r
+}\r
+\r
+/* Get next token, after space stripping etc. */\r
+\r
+static int\r
+tok_get(register struct tok_state *tok, char **p_start, char **p_end)\r
+{\r
+    register int c;\r
+    int blankline;\r
+\r
+    *p_start = *p_end = NULL;\r
+  nextline:\r
+    tok->start = NULL;\r
+    blankline = 0;\r
+\r
+    /* Get indentation level */\r
+    if (tok->atbol) {\r
+        register int col = 0;\r
+        register int altcol = 0;\r
+        tok->atbol = 0;\r
+        for (;;) {\r
+            c = tok_nextc(tok);\r
+            if (c == ' ')\r
+                col++, altcol++;\r
+            else if (c == '\t') {\r
+                col = (col/tok->tabsize + 1) * tok->tabsize;\r
+                altcol = (altcol/tok->alttabsize + 1)\r
+                    * tok->alttabsize;\r
+            }\r
+            else if (c == '\014') /* Control-L (formfeed) */\r
+                col = altcol = 0; /* For Emacs users */\r
+            else\r
+                break;\r
+        }\r
+        tok_backup(tok, c);\r
+        if (c == '#' || c == '\n') {\r
+            /* Lines with only whitespace and/or comments\r
+               shouldn't affect the indentation and are\r
+               not passed to the parser as NEWLINE tokens,\r
+               except *totally* empty lines in interactive\r
+               mode, which signal the end of a command group. */\r
+            if (col == 0 && c == '\n' && tok->prompt != NULL)\r
+                blankline = 0; /* Let it through */\r
+            else\r
+                blankline = 1; /* Ignore completely */\r
+            /* We can't jump back right here since we still\r
+               may need to skip to the end of a comment */\r
+        }\r
+        if (!blankline && tok->level == 0) {\r
+            if (col == tok->indstack[tok->indent]) {\r
+                /* No change */\r
+                if (altcol != tok->altindstack[tok->indent]) {\r
+                    if (indenterror(tok))\r
+                        return ERRORTOKEN;\r
+                }\r
+            }\r
+            else if (col > tok->indstack[tok->indent]) {\r
+                /* Indent -- always one */\r
+                if (tok->indent+1 >= MAXINDENT) {\r
+                    tok->done = E_TOODEEP;\r
+                    tok->cur = tok->inp;\r
+                    return ERRORTOKEN;\r
+                }\r
+                if (altcol <= tok->altindstack[tok->indent]) {\r
+                    if (indenterror(tok))\r
+                        return ERRORTOKEN;\r
+                }\r
+                tok->pendin++;\r
+                tok->indstack[++tok->indent] = col;\r
+                tok->altindstack[tok->indent] = altcol;\r
+            }\r
+            else /* col < tok->indstack[tok->indent] */ {\r
+                /* Dedent -- any number, must be consistent */\r
+                while (tok->indent > 0 &&\r
+                    col < tok->indstack[tok->indent]) {\r
+                    tok->pendin--;\r
+                    tok->indent--;\r
+                }\r
+                if (col != tok->indstack[tok->indent]) {\r
+                    tok->done = E_DEDENT;\r
+                    tok->cur = tok->inp;\r
+                    return ERRORTOKEN;\r
+                }\r
+                if (altcol != tok->altindstack[tok->indent]) {\r
+                    if (indenterror(tok))\r
+                        return ERRORTOKEN;\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    tok->start = tok->cur;\r
+\r
+    /* Return pending indents/dedents */\r
+    if (tok->pendin != 0) {\r
+        if (tok->pendin < 0) {\r
+            tok->pendin++;\r
+            return DEDENT;\r
+        }\r
+        else {\r
+            tok->pendin--;\r
+            return INDENT;\r
+        }\r
+    }\r
+\r
+ again:\r
+    tok->start = NULL;\r
+    /* Skip spaces */\r
+    do {\r
+        c = tok_nextc(tok);\r
+    } while (c == ' ' || c == '\t' || c == '\014');\r
+\r
+    /* Set start of current token */\r
+    tok->start = tok->cur - 1;\r
+\r
+    /* Skip comment, while looking for tab-setting magic */\r
+    if (c == '#') {\r
+        static char *tabforms[] = {\r
+            "tab-width:",                       /* Emacs */\r
+            ":tabstop=",                        /* vim, full form */\r
+            ":ts=",                             /* vim, abbreviated form */\r
+            "set tabsize=",                     /* will vi never die? */\r
+        /* more templates can be added here to support other editors */\r
+        };\r
+        char cbuf[80];\r
+        char *tp, **cp;\r
+        tp = cbuf;\r
+        do {\r
+            *tp++ = c = tok_nextc(tok);\r
+        } while (c != EOF && c != '\n' &&\r
+                 (size_t)(tp - cbuf + 1) < sizeof(cbuf));\r
+        *tp = '\0';\r
+        for (cp = tabforms;\r
+             cp < tabforms + sizeof(tabforms)/sizeof(tabforms[0]);\r
+             cp++) {\r
+            if ((tp = strstr(cbuf, *cp))) {\r
+                int newsize = atoi(tp + strlen(*cp));\r
+\r
+                if (newsize >= 1 && newsize <= 40) {\r
+                    tok->tabsize = newsize;\r
+                    if (Py_VerboseFlag)\r
+                        PySys_WriteStderr(\r
+                        "Tab size set to %d\n",\r
+                        newsize);\r
+                }\r
+            }\r
+        }\r
+        while (c != EOF && c != '\n')\r
+            c = tok_nextc(tok);\r
+    }\r
+\r
+    /* Check for EOF and errors now */\r
+    if (c == EOF) {\r
+        return tok->done == E_EOF ? ENDMARKER : ERRORTOKEN;\r
+    }\r
+\r
+    /* Identifier (most frequent token!) */\r
+    if (Py_ISALPHA(c) || c == '_') {\r
+        /* Process r"", u"" and ur"" */\r
+        switch (c) {\r
+        case 'b':\r
+        case 'B':\r
+            c = tok_nextc(tok);\r
+            if (c == 'r' || c == 'R')\r
+                c = tok_nextc(tok);\r
+            if (c == '"' || c == '\'')\r
+                goto letter_quote;\r
+            break;\r
+        case 'r':\r
+        case 'R':\r
+            c = tok_nextc(tok);\r
+            if (c == '"' || c == '\'')\r
+                goto letter_quote;\r
+            break;\r
+        case 'u':\r
+        case 'U':\r
+            c = tok_nextc(tok);\r
+            if (c == 'r' || c == 'R')\r
+                c = tok_nextc(tok);\r
+            if (c == '"' || c == '\'')\r
+                goto letter_quote;\r
+            break;\r
+        }\r
+        while (c != EOF && (Py_ISALNUM(c) || c == '_')) {\r
+            c = tok_nextc(tok);\r
+        }\r
+        tok_backup(tok, c);\r
+        *p_start = tok->start;\r
+        *p_end = tok->cur;\r
+        return NAME;\r
+    }\r
+\r
+    /* Newline */\r
+    if (c == '\n') {\r
+        tok->atbol = 1;\r
+        if (blankline || tok->level > 0)\r
+            goto nextline;\r
+        *p_start = tok->start;\r
+        *p_end = tok->cur - 1; /* Leave '\n' out of the string */\r
+        tok->cont_line = 0;\r
+        return NEWLINE;\r
+    }\r
+\r
+    /* Period or number starting with period? */\r
+    if (c == '.') {\r
+        c = tok_nextc(tok);\r
+        if (isdigit(c)) {\r
+            goto fraction;\r
+        }\r
+        else {\r
+            tok_backup(tok, c);\r
+            *p_start = tok->start;\r
+            *p_end = tok->cur;\r
+            return DOT;\r
+        }\r
+    }\r
+\r
+    /* Number */\r
+    if (isdigit(c)) {\r
+        if (c == '0') {\r
+            /* Hex, octal or binary -- maybe. */\r
+            c = tok_nextc(tok);\r
+            if (c == '.')\r
+                goto fraction;\r
+#ifndef WITHOUT_COMPLEX\r
+            if (c == 'j' || c == 'J')\r
+                goto imaginary;\r
+#endif\r
+            if (c == 'x' || c == 'X') {\r
+\r
+                /* Hex */\r
+                c = tok_nextc(tok);\r
+                if (!isxdigit(c)) {\r
+                    tok->done = E_TOKEN;\r
+                    tok_backup(tok, c);\r
+                    return ERRORTOKEN;\r
+                }\r
+                do {\r
+                    c = tok_nextc(tok);\r
+                } while (isxdigit(c));\r
+            }\r
+            else if (c == 'o' || c == 'O') {\r
+                /* Octal */\r
+                c = tok_nextc(tok);\r
+                if (c < '0' || c >= '8') {\r
+                    tok->done = E_TOKEN;\r
+                    tok_backup(tok, c);\r
+                    return ERRORTOKEN;\r
+                }\r
+                do {\r
+                    c = tok_nextc(tok);\r
+                } while ('0' <= c && c < '8');\r
+            }\r
+            else if (c == 'b' || c == 'B') {\r
+                /* Binary */\r
+                c = tok_nextc(tok);\r
+                if (c != '0' && c != '1') {\r
+                    tok->done = E_TOKEN;\r
+                    tok_backup(tok, c);\r
+                    return ERRORTOKEN;\r
+                }\r
+                do {\r
+                    c = tok_nextc(tok);\r
+                } while (c == '0' || c == '1');\r
+            }\r
+            else {\r
+                int found_decimal = 0;\r
+                /* Octal; c is first char of it */\r
+                /* There's no 'isoctdigit' macro, sigh */\r
+                while ('0' <= c && c < '8') {\r
+                    c = tok_nextc(tok);\r
+                }\r
+                if (isdigit(c)) {\r
+                    found_decimal = 1;\r
+                    do {\r
+                        c = tok_nextc(tok);\r
+                    } while (isdigit(c));\r
+                }\r
+                if (c == '.')\r
+                    goto fraction;\r
+                else if (c == 'e' || c == 'E')\r
+                    goto exponent;\r
+#ifndef WITHOUT_COMPLEX\r
+                else if (c == 'j' || c == 'J')\r
+                    goto imaginary;\r
+#endif\r
+                else if (found_decimal) {\r
+                    tok->done = E_TOKEN;\r
+                    tok_backup(tok, c);\r
+                    return ERRORTOKEN;\r
+                }\r
+            }\r
+            if (c == 'l' || c == 'L')\r
+                c = tok_nextc(tok);\r
+        }\r
+        else {\r
+            /* Decimal */\r
+            do {\r
+                c = tok_nextc(tok);\r
+            } while (isdigit(c));\r
+            if (c == 'l' || c == 'L')\r
+                c = tok_nextc(tok);\r
+            else {\r
+                /* Accept floating point numbers. */\r
+                if (c == '.') {\r
+        fraction:\r
+                    /* Fraction */\r
+                    do {\r
+                        c = tok_nextc(tok);\r
+                    } while (isdigit(c));\r
+                }\r
+                if (c == 'e' || c == 'E') {\r
+                    int e;\r
+                  exponent:\r
+                    e = c;\r
+                    /* Exponent part */\r
+                    c = tok_nextc(tok);\r
+                    if (c == '+' || c == '-') {\r
+                        c = tok_nextc(tok);\r
+                        if (!isdigit(c)) {\r
+                            tok->done = E_TOKEN;\r
+                            tok_backup(tok, c);\r
+                            return ERRORTOKEN;\r
+                        }\r
+                    } else if (!isdigit(c)) {\r
+                        tok_backup(tok, c);\r
+                        tok_backup(tok, e);\r
+                        *p_start = tok->start;\r
+                        *p_end = tok->cur;\r
+                        return NUMBER;\r
+                    }\r
+                    do {\r
+                        c = tok_nextc(tok);\r
+                    } while (isdigit(c));\r
+                }\r
+#ifndef WITHOUT_COMPLEX\r
+                if (c == 'j' || c == 'J')\r
+                    /* Imaginary part */\r
+        imaginary:\r
+                    c = tok_nextc(tok);\r
+#endif\r
+            }\r
+        }\r
+        tok_backup(tok, c);\r
+        *p_start = tok->start;\r
+        *p_end = tok->cur;\r
+        return NUMBER;\r
+    }\r
+\r
+  letter_quote:\r
+    /* String */\r
+    if (c == '\'' || c == '"') {\r
+        Py_ssize_t quote2 = tok->cur - tok->start + 1;\r
+        int quote = c;\r
+        int triple = 0;\r
+        int tripcount = 0;\r
+        for (;;) {\r
+            c = tok_nextc(tok);\r
+            if (c == '\n') {\r
+                if (!triple) {\r
+                    tok->done = E_EOLS;\r
+                    tok_backup(tok, c);\r
+                    return ERRORTOKEN;\r
+                }\r
+                tripcount = 0;\r
+                tok->cont_line = 1; /* multiline string. */\r
+            }\r
+            else if (c == EOF) {\r
+                if (triple)\r
+                    tok->done = E_EOFS;\r
+                else\r
+                    tok->done = E_EOLS;\r
+                tok->cur = tok->inp;\r
+                return ERRORTOKEN;\r
+            }\r
+            else if (c == quote) {\r
+                tripcount++;\r
+                if (tok->cur - tok->start == quote2) {\r
+                    c = tok_nextc(tok);\r
+                    if (c == quote) {\r
+                        triple = 1;\r
+                        tripcount = 0;\r
+                        continue;\r
+                    }\r
+                    tok_backup(tok, c);\r
+                }\r
+                if (!triple || tripcount == 3)\r
+                    break;\r
+            }\r
+            else if (c == '\\') {\r
+                tripcount = 0;\r
+                c = tok_nextc(tok);\r
+                if (c == EOF) {\r
+                    tok->done = E_EOLS;\r
+                    tok->cur = tok->inp;\r
+                    return ERRORTOKEN;\r
+                }\r
+            }\r
+            else\r
+                tripcount = 0;\r
+        }\r
+        *p_start = tok->start;\r
+        *p_end = tok->cur;\r
+        return STRING;\r
+    }\r
+\r
+    /* Line continuation */\r
+    if (c == '\\') {\r
+        c = tok_nextc(tok);\r
+        if (c != '\n') {\r
+            tok->done = E_LINECONT;\r
+            tok->cur = tok->inp;\r
+            return ERRORTOKEN;\r
+        }\r
+        tok->cont_line = 1;\r
+        goto again; /* Read next line */\r
+    }\r
+\r
+    /* Check for two-character token */\r
+    {\r
+        int c2 = tok_nextc(tok);\r
+        int token = PyToken_TwoChars(c, c2);\r
+#ifndef PGEN\r
+        if (Py_Py3kWarningFlag && token == NOTEQUAL && c == '<') {\r
+            if (PyErr_WarnExplicit(PyExc_DeprecationWarning,\r
+                                   "<> not supported in 3.x; use !=",\r
+                                   tok->filename, tok->lineno,\r
+                                   NULL, NULL)) {\r
+                return ERRORTOKEN;\r
+            }\r
+        }\r
+#endif\r
+        if (token != OP) {\r
+            int c3 = tok_nextc(tok);\r
+            int token3 = PyToken_ThreeChars(c, c2, c3);\r
+            if (token3 != OP) {\r
+                token = token3;\r
+            } else {\r
+                tok_backup(tok, c3);\r
+            }\r
+            *p_start = tok->start;\r
+            *p_end = tok->cur;\r
+            return token;\r
+        }\r
+        tok_backup(tok, c2);\r
+    }\r
+\r
+    /* Keep track of parentheses nesting level */\r
+    switch (c) {\r
+    case '(':\r
+    case '[':\r
+    case '{':\r
+        tok->level++;\r
+        break;\r
+    case ')':\r
+    case ']':\r
+    case '}':\r
+        tok->level--;\r
+        break;\r
+    }\r
+\r
+    /* Punctuation character */\r
+    *p_start = tok->start;\r
+    *p_end = tok->cur;\r
+    return PyToken_OneChar(c);\r
+}\r
+\r
+int\r
+PyTokenizer_Get(struct tok_state *tok, char **p_start, char **p_end)\r
+{\r
+    int result = tok_get(tok, p_start, p_end);\r
+    if (tok->decoding_erred) {\r
+        result = ERRORTOKEN;\r
+        tok->done = E_DECODE;\r
+    }\r
+    return result;\r
+}\r
+\r
+/* This function is only called from parsetok. However, it cannot live\r
+   there, as it must be empty for PGEN, and we can check for PGEN only\r
+   in this file. */\r
+\r
+#if defined(PGEN) || !defined(Py_USING_UNICODE)\r
+char*\r
+PyTokenizer_RestoreEncoding(struct tok_state* tok, int len, int* offset)\r
+{\r
+    return NULL;\r
+}\r
+#else\r
+#ifdef Py_USING_UNICODE\r
+static PyObject *\r
+dec_utf8(const char *enc, const char *text, size_t len) {\r
+    PyObject *ret = NULL;\r
+    PyObject *unicode_text = PyUnicode_DecodeUTF8(text, len, "replace");\r
+    if (unicode_text) {\r
+        ret = PyUnicode_AsEncodedString(unicode_text, enc, "replace");\r
+        Py_DECREF(unicode_text);\r
+    }\r
+    if (!ret) {\r
+        PyErr_Clear();\r
+    }\r
+    return ret;\r
+}\r
+char *\r
+PyTokenizer_RestoreEncoding(struct tok_state* tok, int len, int *offset)\r
+{\r
+    char *text = NULL;\r
+    if (tok->encoding) {\r
+        /* convert source to original encondig */\r
+        PyObject *lineobj = dec_utf8(tok->encoding, tok->buf, len);\r
+        if (lineobj != NULL) {\r
+            int linelen = PyString_Size(lineobj);\r
+            const char *line = PyString_AsString(lineobj);\r
+            text = PyObject_MALLOC(linelen + 1);\r
+            if (text != NULL && line != NULL) {\r
+                if (linelen)\r
+                    strncpy(text, line, linelen);\r
+                text[linelen] = '\0';\r
+            }\r
+            Py_DECREF(lineobj);\r
+\r
+            /* adjust error offset */\r
+            if (*offset > 1) {\r
+                PyObject *offsetobj = dec_utf8(tok->encoding,\r
+                                               tok->buf, *offset-1);\r
+                if (offsetobj) {\r
+                    *offset = PyString_Size(offsetobj) + 1;\r
+                    Py_DECREF(offsetobj);\r
+                }\r
+            }\r
+\r
+        }\r
+    }\r
+    return text;\r
+\r
+}\r
+#endif /* defined(Py_USING_UNICODE) */\r
+#endif\r
+\r
+\r
+#ifdef Py_DEBUG\r
+\r
+void\r
+tok_dump(int type, char *start, char *end)\r
+{\r
+    printf("%s", _PyParser_TokenNames[type]);\r
+    if (type == NAME || type == NUMBER || type == STRING || type == OP)\r
+        printf("(%.*s)", (int)(end - start), start);\r
+}\r
+\r
+#endif\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Parser/tokenizer.h b/AppPkg/Applications/Python/Python-2.7.10/Parser/tokenizer.h
new file mode 100644 (file)
index 0000000..3de3280
--- /dev/null
@@ -0,0 +1,70 @@
+#ifndef Py_TOKENIZER_H\r
+#define Py_TOKENIZER_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#include "object.h"\r
+\r
+/* Tokenizer interface */\r
+\r
+#include "token.h"      /* For token types */\r
+\r
+#define MAXINDENT 100   /* Max indentation level */\r
+\r
+/* Tokenizer state */\r
+struct tok_state {\r
+    /* Input state; buf <= cur <= inp <= end */\r
+    /* NB an entire line is held in the buffer */\r
+    char *buf;          /* Input buffer, or NULL; malloc'ed if fp != NULL */\r
+    char *cur;          /* Next character in buffer */\r
+    char *inp;          /* End of data in buffer */\r
+    char *end;          /* End of input buffer if buf != NULL */\r
+    char *start;        /* Start of current token if not NULL */\r
+    int done;           /* E_OK normally, E_EOF at EOF, otherwise error code */\r
+    /* NB If done != E_OK, cur must be == inp!!! */\r
+    FILE *fp;           /* Rest of input; NULL if tokenizing a string */\r
+    int tabsize;        /* Tab spacing */\r
+    int indent;         /* Current indentation index */\r
+    int indstack[MAXINDENT];            /* Stack of indents */\r
+    int atbol;          /* Nonzero if at begin of new line */\r
+    int pendin;         /* Pending indents (if > 0) or dedents (if < 0) */\r
+    char *prompt, *nextprompt;          /* For interactive prompting */\r
+    int lineno;         /* Current line number */\r
+    int level;          /* () [] {} Parentheses nesting level */\r
+            /* Used to allow free continuations inside them */\r
+    /* Stuff for checking on different tab sizes */\r
+    const char *filename;       /* For error messages */\r
+    int altwarning;     /* Issue warning if alternate tabs don't match */\r
+    int alterror;       /* Issue error if alternate tabs don't match */\r
+    int alttabsize;     /* Alternate tab spacing */\r
+    int altindstack[MAXINDENT];         /* Stack of alternate indents */\r
+    /* Stuff for PEP 0263 */\r
+    int decoding_state;         /* -1:decoding, 0:init, 1:raw */\r
+    int decoding_erred;         /* whether erred in decoding  */\r
+    int read_coding_spec;       /* whether 'coding:...' has been read  */\r
+    char *encoding;\r
+    int cont_line;          /* whether we are in a continuation line. */\r
+    const char* line_start;     /* pointer to start of current line */\r
+#ifndef PGEN\r
+    PyObject *decoding_readline; /* codecs.open(...).readline */\r
+    PyObject *decoding_buffer;\r
+#endif\r
+    const char* enc;\r
+    const char* str;\r
+    const char* input; /* Tokenizer's newline translated copy of the string. */\r
+};\r
+\r
+extern struct tok_state *PyTokenizer_FromString(const char *, int);\r
+extern struct tok_state *PyTokenizer_FromFile(FILE *, char *, char *);\r
+extern void PyTokenizer_Free(struct tok_state *);\r
+extern int PyTokenizer_Get(struct tok_state *, char **, char **);\r
+#if defined(PGEN) || defined(Py_USING_UNICODE)\r
+extern char * PyTokenizer_RestoreEncoding(struct tok_state* tok,\r
+                                          int len, int *offset);\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_TOKENIZER_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/Python-ast.c b/AppPkg/Applications/Python/Python-2.7.10/Python/Python-ast.c
new file mode 100644 (file)
index 0000000..ab4009a
--- /dev/null
@@ -0,0 +1,6788 @@
+/* File automatically generated by Parser/asdl_c.py. */\r
+\r
+\r
+/*\r
+   __version__ 82160.\r
+\r
+   This module must be committed separately after each AST grammar change;\r
+   The __version__ number is set to the revision number of the commit\r
+   containing the grammar change.\r
+*/\r
+\r
+#include "Python.h"\r
+#include "Python-ast.h"\r
+\r
+static PyTypeObject AST_type;\r
+static PyTypeObject *mod_type;\r
+static PyObject* ast2obj_mod(void*);\r
+static PyTypeObject *Module_type;\r
+static char *Module_fields[]={\r
+        "body",\r
+};\r
+static PyTypeObject *Interactive_type;\r
+static char *Interactive_fields[]={\r
+        "body",\r
+};\r
+static PyTypeObject *Expression_type;\r
+static char *Expression_fields[]={\r
+        "body",\r
+};\r
+static PyTypeObject *Suite_type;\r
+static char *Suite_fields[]={\r
+        "body",\r
+};\r
+static PyTypeObject *stmt_type;\r
+static char *stmt_attributes[] = {\r
+        "lineno",\r
+        "col_offset",\r
+};\r
+static PyObject* ast2obj_stmt(void*);\r
+static PyTypeObject *FunctionDef_type;\r
+static char *FunctionDef_fields[]={\r
+        "name",\r
+        "args",\r
+        "body",\r
+        "decorator_list",\r
+};\r
+static PyTypeObject *ClassDef_type;\r
+static char *ClassDef_fields[]={\r
+        "name",\r
+        "bases",\r
+        "body",\r
+        "decorator_list",\r
+};\r
+static PyTypeObject *Return_type;\r
+static char *Return_fields[]={\r
+        "value",\r
+};\r
+static PyTypeObject *Delete_type;\r
+static char *Delete_fields[]={\r
+        "targets",\r
+};\r
+static PyTypeObject *Assign_type;\r
+static char *Assign_fields[]={\r
+        "targets",\r
+        "value",\r
+};\r
+static PyTypeObject *AugAssign_type;\r
+static char *AugAssign_fields[]={\r
+        "target",\r
+        "op",\r
+        "value",\r
+};\r
+static PyTypeObject *Print_type;\r
+static char *Print_fields[]={\r
+        "dest",\r
+        "values",\r
+        "nl",\r
+};\r
+static PyTypeObject *For_type;\r
+static char *For_fields[]={\r
+        "target",\r
+        "iter",\r
+        "body",\r
+        "orelse",\r
+};\r
+static PyTypeObject *While_type;\r
+static char *While_fields[]={\r
+        "test",\r
+        "body",\r
+        "orelse",\r
+};\r
+static PyTypeObject *If_type;\r
+static char *If_fields[]={\r
+        "test",\r
+        "body",\r
+        "orelse",\r
+};\r
+static PyTypeObject *With_type;\r
+static char *With_fields[]={\r
+        "context_expr",\r
+        "optional_vars",\r
+        "body",\r
+};\r
+static PyTypeObject *Raise_type;\r
+static char *Raise_fields[]={\r
+        "type",\r
+        "inst",\r
+        "tback",\r
+};\r
+static PyTypeObject *TryExcept_type;\r
+static char *TryExcept_fields[]={\r
+        "body",\r
+        "handlers",\r
+        "orelse",\r
+};\r
+static PyTypeObject *TryFinally_type;\r
+static char *TryFinally_fields[]={\r
+        "body",\r
+        "finalbody",\r
+};\r
+static PyTypeObject *Assert_type;\r
+static char *Assert_fields[]={\r
+        "test",\r
+        "msg",\r
+};\r
+static PyTypeObject *Import_type;\r
+static char *Import_fields[]={\r
+        "names",\r
+};\r
+static PyTypeObject *ImportFrom_type;\r
+static char *ImportFrom_fields[]={\r
+        "module",\r
+        "names",\r
+        "level",\r
+};\r
+static PyTypeObject *Exec_type;\r
+static char *Exec_fields[]={\r
+        "body",\r
+        "globals",\r
+        "locals",\r
+};\r
+static PyTypeObject *Global_type;\r
+static char *Global_fields[]={\r
+        "names",\r
+};\r
+static PyTypeObject *Expr_type;\r
+static char *Expr_fields[]={\r
+        "value",\r
+};\r
+static PyTypeObject *Pass_type;\r
+static PyTypeObject *Break_type;\r
+static PyTypeObject *Continue_type;\r
+static PyTypeObject *expr_type;\r
+static char *expr_attributes[] = {\r
+        "lineno",\r
+        "col_offset",\r
+};\r
+static PyObject* ast2obj_expr(void*);\r
+static PyTypeObject *BoolOp_type;\r
+static char *BoolOp_fields[]={\r
+        "op",\r
+        "values",\r
+};\r
+static PyTypeObject *BinOp_type;\r
+static char *BinOp_fields[]={\r
+        "left",\r
+        "op",\r
+        "right",\r
+};\r
+static PyTypeObject *UnaryOp_type;\r
+static char *UnaryOp_fields[]={\r
+        "op",\r
+        "operand",\r
+};\r
+static PyTypeObject *Lambda_type;\r
+static char *Lambda_fields[]={\r
+        "args",\r
+        "body",\r
+};\r
+static PyTypeObject *IfExp_type;\r
+static char *IfExp_fields[]={\r
+        "test",\r
+        "body",\r
+        "orelse",\r
+};\r
+static PyTypeObject *Dict_type;\r
+static char *Dict_fields[]={\r
+        "keys",\r
+        "values",\r
+};\r
+static PyTypeObject *Set_type;\r
+static char *Set_fields[]={\r
+        "elts",\r
+};\r
+static PyTypeObject *ListComp_type;\r
+static char *ListComp_fields[]={\r
+        "elt",\r
+        "generators",\r
+};\r
+static PyTypeObject *SetComp_type;\r
+static char *SetComp_fields[]={\r
+        "elt",\r
+        "generators",\r
+};\r
+static PyTypeObject *DictComp_type;\r
+static char *DictComp_fields[]={\r
+        "key",\r
+        "value",\r
+        "generators",\r
+};\r
+static PyTypeObject *GeneratorExp_type;\r
+static char *GeneratorExp_fields[]={\r
+        "elt",\r
+        "generators",\r
+};\r
+static PyTypeObject *Yield_type;\r
+static char *Yield_fields[]={\r
+        "value",\r
+};\r
+static PyTypeObject *Compare_type;\r
+static char *Compare_fields[]={\r
+        "left",\r
+        "ops",\r
+        "comparators",\r
+};\r
+static PyTypeObject *Call_type;\r
+static char *Call_fields[]={\r
+        "func",\r
+        "args",\r
+        "keywords",\r
+        "starargs",\r
+        "kwargs",\r
+};\r
+static PyTypeObject *Repr_type;\r
+static char *Repr_fields[]={\r
+        "value",\r
+};\r
+static PyTypeObject *Num_type;\r
+static char *Num_fields[]={\r
+        "n",\r
+};\r
+static PyTypeObject *Str_type;\r
+static char *Str_fields[]={\r
+        "s",\r
+};\r
+static PyTypeObject *Attribute_type;\r
+static char *Attribute_fields[]={\r
+        "value",\r
+        "attr",\r
+        "ctx",\r
+};\r
+static PyTypeObject *Subscript_type;\r
+static char *Subscript_fields[]={\r
+        "value",\r
+        "slice",\r
+        "ctx",\r
+};\r
+static PyTypeObject *Name_type;\r
+static char *Name_fields[]={\r
+        "id",\r
+        "ctx",\r
+};\r
+static PyTypeObject *List_type;\r
+static char *List_fields[]={\r
+        "elts",\r
+        "ctx",\r
+};\r
+static PyTypeObject *Tuple_type;\r
+static char *Tuple_fields[]={\r
+        "elts",\r
+        "ctx",\r
+};\r
+static PyTypeObject *expr_context_type;\r
+static PyObject *Load_singleton, *Store_singleton, *Del_singleton,\r
+*AugLoad_singleton, *AugStore_singleton, *Param_singleton;\r
+static PyObject* ast2obj_expr_context(expr_context_ty);\r
+static PyTypeObject *Load_type;\r
+static PyTypeObject *Store_type;\r
+static PyTypeObject *Del_type;\r
+static PyTypeObject *AugLoad_type;\r
+static PyTypeObject *AugStore_type;\r
+static PyTypeObject *Param_type;\r
+static PyTypeObject *slice_type;\r
+static PyObject* ast2obj_slice(void*);\r
+static PyTypeObject *Ellipsis_type;\r
+static PyTypeObject *Slice_type;\r
+static char *Slice_fields[]={\r
+        "lower",\r
+        "upper",\r
+        "step",\r
+};\r
+static PyTypeObject *ExtSlice_type;\r
+static char *ExtSlice_fields[]={\r
+        "dims",\r
+};\r
+static PyTypeObject *Index_type;\r
+static char *Index_fields[]={\r
+        "value",\r
+};\r
+static PyTypeObject *boolop_type;\r
+static PyObject *And_singleton, *Or_singleton;\r
+static PyObject* ast2obj_boolop(boolop_ty);\r
+static PyTypeObject *And_type;\r
+static PyTypeObject *Or_type;\r
+static PyTypeObject *operator_type;\r
+static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton,\r
+*Div_singleton, *Mod_singleton, *Pow_singleton, *LShift_singleton,\r
+*RShift_singleton, *BitOr_singleton, *BitXor_singleton, *BitAnd_singleton,\r
+*FloorDiv_singleton;\r
+static PyObject* ast2obj_operator(operator_ty);\r
+static PyTypeObject *Add_type;\r
+static PyTypeObject *Sub_type;\r
+static PyTypeObject *Mult_type;\r
+static PyTypeObject *Div_type;\r
+static PyTypeObject *Mod_type;\r
+static PyTypeObject *Pow_type;\r
+static PyTypeObject *LShift_type;\r
+static PyTypeObject *RShift_type;\r
+static PyTypeObject *BitOr_type;\r
+static PyTypeObject *BitXor_type;\r
+static PyTypeObject *BitAnd_type;\r
+static PyTypeObject *FloorDiv_type;\r
+static PyTypeObject *unaryop_type;\r
+static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton,\r
+*USub_singleton;\r
+static PyObject* ast2obj_unaryop(unaryop_ty);\r
+static PyTypeObject *Invert_type;\r
+static PyTypeObject *Not_type;\r
+static PyTypeObject *UAdd_type;\r
+static PyTypeObject *USub_type;\r
+static PyTypeObject *cmpop_type;\r
+static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton,\r
+*Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton,\r
+*NotIn_singleton;\r
+static PyObject* ast2obj_cmpop(cmpop_ty);\r
+static PyTypeObject *Eq_type;\r
+static PyTypeObject *NotEq_type;\r
+static PyTypeObject *Lt_type;\r
+static PyTypeObject *LtE_type;\r
+static PyTypeObject *Gt_type;\r
+static PyTypeObject *GtE_type;\r
+static PyTypeObject *Is_type;\r
+static PyTypeObject *IsNot_type;\r
+static PyTypeObject *In_type;\r
+static PyTypeObject *NotIn_type;\r
+static PyTypeObject *comprehension_type;\r
+static PyObject* ast2obj_comprehension(void*);\r
+static char *comprehension_fields[]={\r
+        "target",\r
+        "iter",\r
+        "ifs",\r
+};\r
+static PyTypeObject *excepthandler_type;\r
+static char *excepthandler_attributes[] = {\r
+        "lineno",\r
+        "col_offset",\r
+};\r
+static PyObject* ast2obj_excepthandler(void*);\r
+static PyTypeObject *ExceptHandler_type;\r
+static char *ExceptHandler_fields[]={\r
+        "type",\r
+        "name",\r
+        "body",\r
+};\r
+static PyTypeObject *arguments_type;\r
+static PyObject* ast2obj_arguments(void*);\r
+static char *arguments_fields[]={\r
+        "args",\r
+        "vararg",\r
+        "kwarg",\r
+        "defaults",\r
+};\r
+static PyTypeObject *keyword_type;\r
+static PyObject* ast2obj_keyword(void*);\r
+static char *keyword_fields[]={\r
+        "arg",\r
+        "value",\r
+};\r
+static PyTypeObject *alias_type;\r
+static PyObject* ast2obj_alias(void*);\r
+static char *alias_fields[]={\r
+        "name",\r
+        "asname",\r
+};\r
+\r
+\r
+static int\r
+ast_type_init(PyObject *self, PyObject *args, PyObject *kw)\r
+{\r
+    Py_ssize_t i, numfields = 0;\r
+    int res = -1;\r
+    PyObject *key, *value, *fields;\r
+    fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields");\r
+    if (!fields)\r
+        PyErr_Clear();\r
+    if (fields) {\r
+        numfields = PySequence_Size(fields);\r
+        if (numfields == -1)\r
+            goto cleanup;\r
+    }\r
+    res = 0; /* if no error occurs, this stays 0 to the end */\r
+    if (PyTuple_GET_SIZE(args) > 0) {\r
+        if (numfields != PyTuple_GET_SIZE(args)) {\r
+            PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"\r
+                         "%zd positional argument%s",\r
+                         Py_TYPE(self)->tp_name,\r
+                         numfields == 0 ? "" : "either 0 or ",\r
+                         numfields, numfields == 1 ? "" : "s");\r
+            res = -1;\r
+            goto cleanup;\r
+        }\r
+        for (i = 0; i < PyTuple_GET_SIZE(args); i++) {\r
+            /* cannot be reached when fields is NULL */\r
+            PyObject *name = PySequence_GetItem(fields, i);\r
+            if (!name) {\r
+                res = -1;\r
+                goto cleanup;\r
+            }\r
+            res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));\r
+            Py_DECREF(name);\r
+            if (res < 0)\r
+                goto cleanup;\r
+        }\r
+    }\r
+    if (kw) {\r
+        i = 0;  /* needed by PyDict_Next */\r
+        while (PyDict_Next(kw, &i, &key, &value)) {\r
+            res = PyObject_SetAttr(self, key, value);\r
+            if (res < 0)\r
+                goto cleanup;\r
+        }\r
+    }\r
+  cleanup:\r
+    Py_XDECREF(fields);\r
+    return res;\r
+}\r
+\r
+/* Pickling support */\r
+static PyObject *\r
+ast_type_reduce(PyObject *self, PyObject *unused)\r
+{\r
+    PyObject *res;\r
+    PyObject *dict = PyObject_GetAttrString(self, "__dict__");\r
+    if (dict == NULL) {\r
+        if (PyErr_ExceptionMatches(PyExc_AttributeError))\r
+            PyErr_Clear();\r
+        else\r
+            return NULL;\r
+    }\r
+    if (dict) {\r
+        res = Py_BuildValue("O()O", Py_TYPE(self), dict);\r
+        Py_DECREF(dict);\r
+        return res;\r
+    }\r
+    return Py_BuildValue("O()", Py_TYPE(self));\r
+}\r
+\r
+static PyMethodDef ast_type_methods[] = {\r
+    {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},\r
+    {NULL}\r
+};\r
+\r
+static PyTypeObject AST_type = {\r
+    PyVarObject_HEAD_INIT(&PyType_Type, 0)\r
+    "_ast.AST",\r
+    sizeof(PyObject),\r
+    0,\r
+    0,                       /* tp_dealloc */\r
+    0,                       /* tp_print */\r
+    0,                       /* tp_getattr */\r
+    0,                       /* tp_setattr */\r
+    0,                       /* tp_compare */\r
+    0,                       /* tp_repr */\r
+    0,                       /* tp_as_number */\r
+    0,                       /* tp_as_sequence */\r
+    0,                       /* tp_as_mapping */\r
+    0,                       /* tp_hash */\r
+    0,                       /* tp_call */\r
+    0,                       /* tp_str */\r
+    PyObject_GenericGetAttr, /* tp_getattro */\r
+    PyObject_GenericSetAttr, /* tp_setattro */\r
+    0,                       /* tp_as_buffer */\r
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */\r
+    0,                       /* tp_doc */\r
+    0,                       /* tp_traverse */\r
+    0,                       /* tp_clear */\r
+    0,                       /* tp_richcompare */\r
+    0,                       /* tp_weaklistoffset */\r
+    0,                       /* tp_iter */\r
+    0,                       /* tp_iternext */\r
+    ast_type_methods,        /* tp_methods */\r
+    0,                       /* tp_members */\r
+    0,                       /* tp_getset */\r
+    0,                       /* tp_base */\r
+    0,                       /* tp_dict */\r
+    0,                       /* tp_descr_get */\r
+    0,                       /* tp_descr_set */\r
+    0,                       /* tp_dictoffset */\r
+    (initproc)ast_type_init, /* tp_init */\r
+    PyType_GenericAlloc,     /* tp_alloc */\r
+    PyType_GenericNew,       /* tp_new */\r
+    PyObject_Del,            /* tp_free */\r
+};\r
+\r
+\r
+static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)\r
+{\r
+    PyObject *fnames, *result;\r
+    int i;\r
+    fnames = PyTuple_New(num_fields);\r
+    if (!fnames) return NULL;\r
+    for (i = 0; i < num_fields; i++) {\r
+        PyObject *field = PyString_FromString(fields[i]);\r
+        if (!field) {\r
+            Py_DECREF(fnames);\r
+            return NULL;\r
+        }\r
+        PyTuple_SET_ITEM(fnames, i, field);\r
+    }\r
+    result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",\r
+                    type, base, "_fields", fnames, "__module__", "_ast");\r
+    Py_DECREF(fnames);\r
+    return (PyTypeObject*)result;\r
+}\r
+\r
+static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)\r
+{\r
+    int i, result;\r
+    PyObject *s, *l = PyTuple_New(num_fields);\r
+    if (!l)\r
+        return 0;\r
+    for (i = 0; i < num_fields; i++) {\r
+        s = PyString_FromString(attrs[i]);\r
+        if (!s) {\r
+            Py_DECREF(l);\r
+            return 0;\r
+        }\r
+        PyTuple_SET_ITEM(l, i, s);\r
+    }\r
+    result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;\r
+    Py_DECREF(l);\r
+    return result;\r
+}\r
+\r
+/* Conversion AST -> Python */\r
+\r
+static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))\r
+{\r
+    int i, n = asdl_seq_LEN(seq);\r
+    PyObject *result = PyList_New(n);\r
+    PyObject *value;\r
+    if (!result)\r
+        return NULL;\r
+    for (i = 0; i < n; i++) {\r
+        value = func(asdl_seq_GET(seq, i));\r
+        if (!value) {\r
+            Py_DECREF(result);\r
+            return NULL;\r
+        }\r
+        PyList_SET_ITEM(result, i, value);\r
+    }\r
+    return result;\r
+}\r
+\r
+static PyObject* ast2obj_object(void *o)\r
+{\r
+    if (!o)\r
+        o = Py_None;\r
+    Py_INCREF((PyObject*)o);\r
+    return (PyObject*)o;\r
+}\r
+#define ast2obj_identifier ast2obj_object\r
+#define ast2obj_string ast2obj_object\r
+static PyObject* ast2obj_bool(bool b)\r
+{\r
+    return PyBool_FromLong(b);\r
+}\r
+\r
+static PyObject* ast2obj_int(long b)\r
+{\r
+    return PyInt_FromLong(b);\r
+}\r
+\r
+/* Conversion Python -> AST */\r
+\r
+static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)\r
+{\r
+    if (obj == Py_None)\r
+        obj = NULL;\r
+    if (obj)\r
+        PyArena_AddPyObject(arena, obj);\r
+    Py_XINCREF(obj);\r
+    *out = obj;\r
+    return 0;\r
+}\r
+\r
+static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)\r
+{\r
+    if (!PyString_CheckExact(obj) && obj != Py_None) {\r
+        PyErr_Format(PyExc_TypeError,\r
+                    "AST identifier must be of type str");\r
+        return 1;\r
+    }\r
+    return obj2ast_object(obj, out, arena);\r
+}\r
+\r
+static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)\r
+{\r
+    if (!PyString_CheckExact(obj) && !PyUnicode_CheckExact(obj)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                       "AST string must be of type str or unicode");\r
+        return 1;\r
+    }\r
+    return obj2ast_object(obj, out, arena);\r
+}\r
+\r
+static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)\r
+{\r
+    int i;\r
+    if (!PyInt_Check(obj) && !PyLong_Check(obj)) {\r
+        PyObject *s = PyObject_Repr(obj);\r
+        if (s == NULL) return 1;\r
+        PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",\r
+                     PyString_AS_STRING(s));\r
+        Py_DECREF(s);\r
+        return 1;\r
+    }\r
+\r
+    i = (int)PyLong_AsLong(obj);\r
+    if (i == -1 && PyErr_Occurred())\r
+        return 1;\r
+    *out = i;\r
+    return 0;\r
+}\r
+\r
+static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)\r
+{\r
+    if (!PyBool_Check(obj)) {\r
+        PyObject *s = PyObject_Repr(obj);\r
+        if (s == NULL) return 1;\r
+        PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s",\r
+                     PyString_AS_STRING(s));\r
+        Py_DECREF(s);\r
+        return 1;\r
+    }\r
+\r
+    *out = (obj == Py_True);\r
+    return 0;\r
+}\r
+\r
+static int add_ast_fields(void)\r
+{\r
+    PyObject *empty_tuple, *d;\r
+    if (PyType_Ready(&AST_type) < 0)\r
+        return -1;\r
+    d = AST_type.tp_dict;\r
+    empty_tuple = PyTuple_New(0);\r
+    if (!empty_tuple ||\r
+        PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||\r
+        PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {\r
+        Py_XDECREF(empty_tuple);\r
+        return -1;\r
+    }\r
+    Py_DECREF(empty_tuple);\r
+    return 0;\r
+}\r
+\r
+\r
+static int init_types(void)\r
+{\r
+        static int initialized;\r
+        if (initialized) return 1;\r
+        if (add_ast_fields() < 0) return 0;\r
+        mod_type = make_type("mod", &AST_type, NULL, 0);\r
+        if (!mod_type) return 0;\r
+        if (!add_attributes(mod_type, NULL, 0)) return 0;\r
+        Module_type = make_type("Module", mod_type, Module_fields, 1);\r
+        if (!Module_type) return 0;\r
+        Interactive_type = make_type("Interactive", mod_type,\r
+                                     Interactive_fields, 1);\r
+        if (!Interactive_type) return 0;\r
+        Expression_type = make_type("Expression", mod_type, Expression_fields,\r
+                                    1);\r
+        if (!Expression_type) return 0;\r
+        Suite_type = make_type("Suite", mod_type, Suite_fields, 1);\r
+        if (!Suite_type) return 0;\r
+        stmt_type = make_type("stmt", &AST_type, NULL, 0);\r
+        if (!stmt_type) return 0;\r
+        if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;\r
+        FunctionDef_type = make_type("FunctionDef", stmt_type,\r
+                                     FunctionDef_fields, 4);\r
+        if (!FunctionDef_type) return 0;\r
+        ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4);\r
+        if (!ClassDef_type) return 0;\r
+        Return_type = make_type("Return", stmt_type, Return_fields, 1);\r
+        if (!Return_type) return 0;\r
+        Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);\r
+        if (!Delete_type) return 0;\r
+        Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);\r
+        if (!Assign_type) return 0;\r
+        AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);\r
+        if (!AugAssign_type) return 0;\r
+        Print_type = make_type("Print", stmt_type, Print_fields, 3);\r
+        if (!Print_type) return 0;\r
+        For_type = make_type("For", stmt_type, For_fields, 4);\r
+        if (!For_type) return 0;\r
+        While_type = make_type("While", stmt_type, While_fields, 3);\r
+        if (!While_type) return 0;\r
+        If_type = make_type("If", stmt_type, If_fields, 3);\r
+        if (!If_type) return 0;\r
+        With_type = make_type("With", stmt_type, With_fields, 3);\r
+        if (!With_type) return 0;\r
+        Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);\r
+        if (!Raise_type) return 0;\r
+        TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);\r
+        if (!TryExcept_type) return 0;\r
+        TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,\r
+                                    2);\r
+        if (!TryFinally_type) return 0;\r
+        Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);\r
+        if (!Assert_type) return 0;\r
+        Import_type = make_type("Import", stmt_type, Import_fields, 1);\r
+        if (!Import_type) return 0;\r
+        ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,\r
+                                    3);\r
+        if (!ImportFrom_type) return 0;\r
+        Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);\r
+        if (!Exec_type) return 0;\r
+        Global_type = make_type("Global", stmt_type, Global_fields, 1);\r
+        if (!Global_type) return 0;\r
+        Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);\r
+        if (!Expr_type) return 0;\r
+        Pass_type = make_type("Pass", stmt_type, NULL, 0);\r
+        if (!Pass_type) return 0;\r
+        Break_type = make_type("Break", stmt_type, NULL, 0);\r
+        if (!Break_type) return 0;\r
+        Continue_type = make_type("Continue", stmt_type, NULL, 0);\r
+        if (!Continue_type) return 0;\r
+        expr_type = make_type("expr", &AST_type, NULL, 0);\r
+        if (!expr_type) return 0;\r
+        if (!add_attributes(expr_type, expr_attributes, 2)) return 0;\r
+        BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2);\r
+        if (!BoolOp_type) return 0;\r
+        BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3);\r
+        if (!BinOp_type) return 0;\r
+        UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2);\r
+        if (!UnaryOp_type) return 0;\r
+        Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2);\r
+        if (!Lambda_type) return 0;\r
+        IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3);\r
+        if (!IfExp_type) return 0;\r
+        Dict_type = make_type("Dict", expr_type, Dict_fields, 2);\r
+        if (!Dict_type) return 0;\r
+        Set_type = make_type("Set", expr_type, Set_fields, 1);\r
+        if (!Set_type) return 0;\r
+        ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);\r
+        if (!ListComp_type) return 0;\r
+        SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);\r
+        if (!SetComp_type) return 0;\r
+        DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);\r
+        if (!DictComp_type) return 0;\r
+        GeneratorExp_type = make_type("GeneratorExp", expr_type,\r
+                                      GeneratorExp_fields, 2);\r
+        if (!GeneratorExp_type) return 0;\r
+        Yield_type = make_type("Yield", expr_type, Yield_fields, 1);\r
+        if (!Yield_type) return 0;\r
+        Compare_type = make_type("Compare", expr_type, Compare_fields, 3);\r
+        if (!Compare_type) return 0;\r
+        Call_type = make_type("Call", expr_type, Call_fields, 5);\r
+        if (!Call_type) return 0;\r
+        Repr_type = make_type("Repr", expr_type, Repr_fields, 1);\r
+        if (!Repr_type) return 0;\r
+        Num_type = make_type("Num", expr_type, Num_fields, 1);\r
+        if (!Num_type) return 0;\r
+        Str_type = make_type("Str", expr_type, Str_fields, 1);\r
+        if (!Str_type) return 0;\r
+        Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);\r
+        if (!Attribute_type) return 0;\r
+        Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);\r
+        if (!Subscript_type) return 0;\r
+        Name_type = make_type("Name", expr_type, Name_fields, 2);\r
+        if (!Name_type) return 0;\r
+        List_type = make_type("List", expr_type, List_fields, 2);\r
+        if (!List_type) return 0;\r
+        Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2);\r
+        if (!Tuple_type) return 0;\r
+        expr_context_type = make_type("expr_context", &AST_type, NULL, 0);\r
+        if (!expr_context_type) return 0;\r
+        if (!add_attributes(expr_context_type, NULL, 0)) return 0;\r
+        Load_type = make_type("Load", expr_context_type, NULL, 0);\r
+        if (!Load_type) return 0;\r
+        Load_singleton = PyType_GenericNew(Load_type, NULL, NULL);\r
+        if (!Load_singleton) return 0;\r
+        Store_type = make_type("Store", expr_context_type, NULL, 0);\r
+        if (!Store_type) return 0;\r
+        Store_singleton = PyType_GenericNew(Store_type, NULL, NULL);\r
+        if (!Store_singleton) return 0;\r
+        Del_type = make_type("Del", expr_context_type, NULL, 0);\r
+        if (!Del_type) return 0;\r
+        Del_singleton = PyType_GenericNew(Del_type, NULL, NULL);\r
+        if (!Del_singleton) return 0;\r
+        AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0);\r
+        if (!AugLoad_type) return 0;\r
+        AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL);\r
+        if (!AugLoad_singleton) return 0;\r
+        AugStore_type = make_type("AugStore", expr_context_type, NULL, 0);\r
+        if (!AugStore_type) return 0;\r
+        AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL);\r
+        if (!AugStore_singleton) return 0;\r
+        Param_type = make_type("Param", expr_context_type, NULL, 0);\r
+        if (!Param_type) return 0;\r
+        Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);\r
+        if (!Param_singleton) return 0;\r
+        slice_type = make_type("slice", &AST_type, NULL, 0);\r
+        if (!slice_type) return 0;\r
+        if (!add_attributes(slice_type, NULL, 0)) return 0;\r
+        Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);\r
+        if (!Ellipsis_type) return 0;\r
+        Slice_type = make_type("Slice", slice_type, Slice_fields, 3);\r
+        if (!Slice_type) return 0;\r
+        ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);\r
+        if (!ExtSlice_type) return 0;\r
+        Index_type = make_type("Index", slice_type, Index_fields, 1);\r
+        if (!Index_type) return 0;\r
+        boolop_type = make_type("boolop", &AST_type, NULL, 0);\r
+        if (!boolop_type) return 0;\r
+        if (!add_attributes(boolop_type, NULL, 0)) return 0;\r
+        And_type = make_type("And", boolop_type, NULL, 0);\r
+        if (!And_type) return 0;\r
+        And_singleton = PyType_GenericNew(And_type, NULL, NULL);\r
+        if (!And_singleton) return 0;\r
+        Or_type = make_type("Or", boolop_type, NULL, 0);\r
+        if (!Or_type) return 0;\r
+        Or_singleton = PyType_GenericNew(Or_type, NULL, NULL);\r
+        if (!Or_singleton) return 0;\r
+        operator_type = make_type("operator", &AST_type, NULL, 0);\r
+        if (!operator_type) return 0;\r
+        if (!add_attributes(operator_type, NULL, 0)) return 0;\r
+        Add_type = make_type("Add", operator_type, NULL, 0);\r
+        if (!Add_type) return 0;\r
+        Add_singleton = PyType_GenericNew(Add_type, NULL, NULL);\r
+        if (!Add_singleton) return 0;\r
+        Sub_type = make_type("Sub", operator_type, NULL, 0);\r
+        if (!Sub_type) return 0;\r
+        Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL);\r
+        if (!Sub_singleton) return 0;\r
+        Mult_type = make_type("Mult", operator_type, NULL, 0);\r
+        if (!Mult_type) return 0;\r
+        Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL);\r
+        if (!Mult_singleton) return 0;\r
+        Div_type = make_type("Div", operator_type, NULL, 0);\r
+        if (!Div_type) return 0;\r
+        Div_singleton = PyType_GenericNew(Div_type, NULL, NULL);\r
+        if (!Div_singleton) return 0;\r
+        Mod_type = make_type("Mod", operator_type, NULL, 0);\r
+        if (!Mod_type) return 0;\r
+        Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL);\r
+        if (!Mod_singleton) return 0;\r
+        Pow_type = make_type("Pow", operator_type, NULL, 0);\r
+        if (!Pow_type) return 0;\r
+        Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL);\r
+        if (!Pow_singleton) return 0;\r
+        LShift_type = make_type("LShift", operator_type, NULL, 0);\r
+        if (!LShift_type) return 0;\r
+        LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL);\r
+        if (!LShift_singleton) return 0;\r
+        RShift_type = make_type("RShift", operator_type, NULL, 0);\r
+        if (!RShift_type) return 0;\r
+        RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL);\r
+        if (!RShift_singleton) return 0;\r
+        BitOr_type = make_type("BitOr", operator_type, NULL, 0);\r
+        if (!BitOr_type) return 0;\r
+        BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL);\r
+        if (!BitOr_singleton) return 0;\r
+        BitXor_type = make_type("BitXor", operator_type, NULL, 0);\r
+        if (!BitXor_type) return 0;\r
+        BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL);\r
+        if (!BitXor_singleton) return 0;\r
+        BitAnd_type = make_type("BitAnd", operator_type, NULL, 0);\r
+        if (!BitAnd_type) return 0;\r
+        BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL);\r
+        if (!BitAnd_singleton) return 0;\r
+        FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0);\r
+        if (!FloorDiv_type) return 0;\r
+        FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL);\r
+        if (!FloorDiv_singleton) return 0;\r
+        unaryop_type = make_type("unaryop", &AST_type, NULL, 0);\r
+        if (!unaryop_type) return 0;\r
+        if (!add_attributes(unaryop_type, NULL, 0)) return 0;\r
+        Invert_type = make_type("Invert", unaryop_type, NULL, 0);\r
+        if (!Invert_type) return 0;\r
+        Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL);\r
+        if (!Invert_singleton) return 0;\r
+        Not_type = make_type("Not", unaryop_type, NULL, 0);\r
+        if (!Not_type) return 0;\r
+        Not_singleton = PyType_GenericNew(Not_type, NULL, NULL);\r
+        if (!Not_singleton) return 0;\r
+        UAdd_type = make_type("UAdd", unaryop_type, NULL, 0);\r
+        if (!UAdd_type) return 0;\r
+        UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL);\r
+        if (!UAdd_singleton) return 0;\r
+        USub_type = make_type("USub", unaryop_type, NULL, 0);\r
+        if (!USub_type) return 0;\r
+        USub_singleton = PyType_GenericNew(USub_type, NULL, NULL);\r
+        if (!USub_singleton) return 0;\r
+        cmpop_type = make_type("cmpop", &AST_type, NULL, 0);\r
+        if (!cmpop_type) return 0;\r
+        if (!add_attributes(cmpop_type, NULL, 0)) return 0;\r
+        Eq_type = make_type("Eq", cmpop_type, NULL, 0);\r
+        if (!Eq_type) return 0;\r
+        Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL);\r
+        if (!Eq_singleton) return 0;\r
+        NotEq_type = make_type("NotEq", cmpop_type, NULL, 0);\r
+        if (!NotEq_type) return 0;\r
+        NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL);\r
+        if (!NotEq_singleton) return 0;\r
+        Lt_type = make_type("Lt", cmpop_type, NULL, 0);\r
+        if (!Lt_type) return 0;\r
+        Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL);\r
+        if (!Lt_singleton) return 0;\r
+        LtE_type = make_type("LtE", cmpop_type, NULL, 0);\r
+        if (!LtE_type) return 0;\r
+        LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL);\r
+        if (!LtE_singleton) return 0;\r
+        Gt_type = make_type("Gt", cmpop_type, NULL, 0);\r
+        if (!Gt_type) return 0;\r
+        Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL);\r
+        if (!Gt_singleton) return 0;\r
+        GtE_type = make_type("GtE", cmpop_type, NULL, 0);\r
+        if (!GtE_type) return 0;\r
+        GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL);\r
+        if (!GtE_singleton) return 0;\r
+        Is_type = make_type("Is", cmpop_type, NULL, 0);\r
+        if (!Is_type) return 0;\r
+        Is_singleton = PyType_GenericNew(Is_type, NULL, NULL);\r
+        if (!Is_singleton) return 0;\r
+        IsNot_type = make_type("IsNot", cmpop_type, NULL, 0);\r
+        if (!IsNot_type) return 0;\r
+        IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL);\r
+        if (!IsNot_singleton) return 0;\r
+        In_type = make_type("In", cmpop_type, NULL, 0);\r
+        if (!In_type) return 0;\r
+        In_singleton = PyType_GenericNew(In_type, NULL, NULL);\r
+        if (!In_singleton) return 0;\r
+        NotIn_type = make_type("NotIn", cmpop_type, NULL, 0);\r
+        if (!NotIn_type) return 0;\r
+        NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);\r
+        if (!NotIn_singleton) return 0;\r
+        comprehension_type = make_type("comprehension", &AST_type,\r
+                                       comprehension_fields, 3);\r
+        if (!comprehension_type) return 0;\r
+        excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);\r
+        if (!excepthandler_type) return 0;\r
+        if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))\r
+            return 0;\r
+        ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,\r
+                                       ExceptHandler_fields, 3);\r
+        if (!ExceptHandler_type) return 0;\r
+        arguments_type = make_type("arguments", &AST_type, arguments_fields, 4);\r
+        if (!arguments_type) return 0;\r
+        keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);\r
+        if (!keyword_type) return 0;\r
+        alias_type = make_type("alias", &AST_type, alias_fields, 2);\r
+        if (!alias_type) return 0;\r
+        initialized = 1;\r
+        return 1;\r
+}\r
+\r
+static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);\r
+static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);\r
+static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);\r
+static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*\r
+                                arena);\r
+static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);\r
+static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);\r
+static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);\r
+static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);\r
+static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);\r
+static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*\r
+                                 arena);\r
+static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*\r
+                                 arena);\r
+static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);\r
+static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);\r
+static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);\r
+\r
+mod_ty\r
+Module(asdl_seq * body, PyArena *arena)\r
+{\r
+        mod_ty p;\r
+        p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Module_kind;\r
+        p->v.Module.body = body;\r
+        return p;\r
+}\r
+\r
+mod_ty\r
+Interactive(asdl_seq * body, PyArena *arena)\r
+{\r
+        mod_ty p;\r
+        p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Interactive_kind;\r
+        p->v.Interactive.body = body;\r
+        return p;\r
+}\r
+\r
+mod_ty\r
+Expression(expr_ty body, PyArena *arena)\r
+{\r
+        mod_ty p;\r
+        if (!body) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field body is required for Expression");\r
+                return NULL;\r
+        }\r
+        p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Expression_kind;\r
+        p->v.Expression.body = body;\r
+        return p;\r
+}\r
+\r
+mod_ty\r
+Suite(asdl_seq * body, PyArena *arena)\r
+{\r
+        mod_ty p;\r
+        p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Suite_kind;\r
+        p->v.Suite.body = body;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *\r
+            decorator_list, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        if (!name) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field name is required for FunctionDef");\r
+                return NULL;\r
+        }\r
+        if (!args) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field args is required for FunctionDef");\r
+                return NULL;\r
+        }\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = FunctionDef_kind;\r
+        p->v.FunctionDef.name = name;\r
+        p->v.FunctionDef.args = args;\r
+        p->v.FunctionDef.body = body;\r
+        p->v.FunctionDef.decorator_list = decorator_list;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq *\r
+         decorator_list, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        if (!name) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field name is required for ClassDef");\r
+                return NULL;\r
+        }\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = ClassDef_kind;\r
+        p->v.ClassDef.name = name;\r
+        p->v.ClassDef.bases = bases;\r
+        p->v.ClassDef.body = body;\r
+        p->v.ClassDef.decorator_list = decorator_list;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+Return(expr_ty value, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Return_kind;\r
+        p->v.Return.value = value;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Delete_kind;\r
+        p->v.Delete.targets = targets;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena\r
+       *arena)\r
+{\r
+        stmt_ty p;\r
+        if (!value) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field value is required for Assign");\r
+                return NULL;\r
+        }\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Assign_kind;\r
+        p->v.Assign.targets = targets;\r
+        p->v.Assign.value = value;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int\r
+          col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        if (!target) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field target is required for AugAssign");\r
+                return NULL;\r
+        }\r
+        if (!op) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field op is required for AugAssign");\r
+                return NULL;\r
+        }\r
+        if (!value) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field value is required for AugAssign");\r
+                return NULL;\r
+        }\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = AugAssign_kind;\r
+        p->v.AugAssign.target = target;\r
+        p->v.AugAssign.op = op;\r
+        p->v.AugAssign.value = value;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,\r
+      PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Print_kind;\r
+        p->v.Print.dest = dest;\r
+        p->v.Print.values = values;\r
+        p->v.Print.nl = nl;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int\r
+    lineno, int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        if (!target) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field target is required for For");\r
+                return NULL;\r
+        }\r
+        if (!iter) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field iter is required for For");\r
+                return NULL;\r
+        }\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = For_kind;\r
+        p->v.For.target = target;\r
+        p->v.For.iter = iter;\r
+        p->v.For.body = body;\r
+        p->v.For.orelse = orelse;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int\r
+      col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        if (!test) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field test is required for While");\r
+                return NULL;\r
+        }\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = While_kind;\r
+        p->v.While.test = test;\r
+        p->v.While.body = body;\r
+        p->v.While.orelse = orelse;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int\r
+   col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        if (!test) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field test is required for If");\r
+                return NULL;\r
+        }\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = If_kind;\r
+        p->v.If.test = test;\r
+        p->v.If.body = body;\r
+        p->v.If.orelse = orelse;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,\r
+     int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        if (!context_expr) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field context_expr is required for With");\r
+                return NULL;\r
+        }\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = With_kind;\r
+        p->v.With.context_expr = context_expr;\r
+        p->v.With.optional_vars = optional_vars;\r
+        p->v.With.body = body;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,\r
+      PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Raise_kind;\r
+        p->v.Raise.type = type;\r
+        p->v.Raise.inst = inst;\r
+        p->v.Raise.tback = tback;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,\r
+          int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = TryExcept_kind;\r
+        p->v.TryExcept.body = body;\r
+        p->v.TryExcept.handlers = handlers;\r
+        p->v.TryExcept.orelse = orelse;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,\r
+           PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = TryFinally_kind;\r
+        p->v.TryFinally.body = body;\r
+        p->v.TryFinally.finalbody = finalbody;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        if (!test) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field test is required for Assert");\r
+                return NULL;\r
+        }\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Assert_kind;\r
+        p->v.Assert.test = test;\r
+        p->v.Assert.msg = msg;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Import_kind;\r
+        p->v.Import.names = names;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int\r
+           col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = ImportFrom_kind;\r
+        p->v.ImportFrom.module = module;\r
+        p->v.ImportFrom.names = names;\r
+        p->v.ImportFrom.level = level;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,\r
+     PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        if (!body) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field body is required for Exec");\r
+                return NULL;\r
+        }\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Exec_kind;\r
+        p->v.Exec.body = body;\r
+        p->v.Exec.globals = globals;\r
+        p->v.Exec.locals = locals;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Global_kind;\r
+        p->v.Global.names = names;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+Expr(expr_ty value, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        if (!value) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field value is required for Expr");\r
+                return NULL;\r
+        }\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Expr_kind;\r
+        p->v.Expr.value = value;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+Pass(int lineno, int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Pass_kind;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+Break(int lineno, int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Break_kind;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+stmt_ty\r
+Continue(int lineno, int col_offset, PyArena *arena)\r
+{\r
+        stmt_ty p;\r
+        p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Continue_kind;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena\r
+       *arena)\r
+{\r
+        expr_ty p;\r
+        if (!op) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field op is required for BoolOp");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = BoolOp_kind;\r
+        p->v.BoolOp.op = op;\r
+        p->v.BoolOp.values = values;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,\r
+      PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        if (!left) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field left is required for BinOp");\r
+                return NULL;\r
+        }\r
+        if (!op) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field op is required for BinOp");\r
+                return NULL;\r
+        }\r
+        if (!right) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field right is required for BinOp");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = BinOp_kind;\r
+        p->v.BinOp.left = left;\r
+        p->v.BinOp.op = op;\r
+        p->v.BinOp.right = right;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena\r
+        *arena)\r
+{\r
+        expr_ty p;\r
+        if (!op) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field op is required for UnaryOp");\r
+                return NULL;\r
+        }\r
+        if (!operand) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field operand is required for UnaryOp");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = UnaryOp_kind;\r
+        p->v.UnaryOp.op = op;\r
+        p->v.UnaryOp.operand = operand;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena\r
+       *arena)\r
+{\r
+        expr_ty p;\r
+        if (!args) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field args is required for Lambda");\r
+                return NULL;\r
+        }\r
+        if (!body) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field body is required for Lambda");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Lambda_kind;\r
+        p->v.Lambda.args = args;\r
+        p->v.Lambda.body = body;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,\r
+      PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        if (!test) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field test is required for IfExp");\r
+                return NULL;\r
+        }\r
+        if (!body) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field body is required for IfExp");\r
+                return NULL;\r
+        }\r
+        if (!orelse) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field orelse is required for IfExp");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = IfExp_kind;\r
+        p->v.IfExp.test = test;\r
+        p->v.IfExp.body = body;\r
+        p->v.IfExp.orelse = orelse;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena\r
+     *arena)\r
+{\r
+        expr_ty p;\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Dict_kind;\r
+        p->v.Dict.keys = keys;\r
+        p->v.Dict.values = values;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Set_kind;\r
+        p->v.Set.elts = elts;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,\r
+         PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        if (!elt) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field elt is required for ListComp");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = ListComp_kind;\r
+        p->v.ListComp.elt = elt;\r
+        p->v.ListComp.generators = generators;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena\r
+        *arena)\r
+{\r
+        expr_ty p;\r
+        if (!elt) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field elt is required for SetComp");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = SetComp_kind;\r
+        p->v.SetComp.elt = elt;\r
+        p->v.SetComp.generators = generators;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int\r
+         col_offset, PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        if (!key) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field key is required for DictComp");\r
+                return NULL;\r
+        }\r
+        if (!value) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field value is required for DictComp");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = DictComp_kind;\r
+        p->v.DictComp.key = key;\r
+        p->v.DictComp.value = value;\r
+        p->v.DictComp.generators = generators;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,\r
+             PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        if (!elt) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field elt is required for GeneratorExp");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = GeneratorExp_kind;\r
+        p->v.GeneratorExp.elt = elt;\r
+        p->v.GeneratorExp.generators = generators;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Yield_kind;\r
+        p->v.Yield.value = value;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,\r
+        int col_offset, PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        if (!left) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field left is required for Compare");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Compare_kind;\r
+        p->v.Compare.left = left;\r
+        p->v.Compare.ops = ops;\r
+        p->v.Compare.comparators = comparators;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,\r
+     expr_ty kwargs, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        if (!func) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field func is required for Call");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Call_kind;\r
+        p->v.Call.func = func;\r
+        p->v.Call.args = args;\r
+        p->v.Call.keywords = keywords;\r
+        p->v.Call.starargs = starargs;\r
+        p->v.Call.kwargs = kwargs;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        if (!value) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field value is required for Repr");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Repr_kind;\r
+        p->v.Repr.value = value;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+Num(object n, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        if (!n) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field n is required for Num");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Num_kind;\r
+        p->v.Num.n = n;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+Str(string s, int lineno, int col_offset, PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        if (!s) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field s is required for Str");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Str_kind;\r
+        p->v.Str.s = s;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int\r
+          col_offset, PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        if (!value) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field value is required for Attribute");\r
+                return NULL;\r
+        }\r
+        if (!attr) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field attr is required for Attribute");\r
+                return NULL;\r
+        }\r
+        if (!ctx) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field ctx is required for Attribute");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Attribute_kind;\r
+        p->v.Attribute.value = value;\r
+        p->v.Attribute.attr = attr;\r
+        p->v.Attribute.ctx = ctx;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int\r
+          col_offset, PyArena *arena)\r
+{\r
+        expr_ty p;\r
+        if (!value) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field value is required for Subscript");\r
+                return NULL;\r
+        }\r
+        if (!slice) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field slice is required for Subscript");\r
+                return NULL;\r
+        }\r
+        if (!ctx) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field ctx is required for Subscript");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Subscript_kind;\r
+        p->v.Subscript.value = value;\r
+        p->v.Subscript.slice = slice;\r
+        p->v.Subscript.ctx = ctx;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena\r
+     *arena)\r
+{\r
+        expr_ty p;\r
+        if (!id) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field id is required for Name");\r
+                return NULL;\r
+        }\r
+        if (!ctx) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field ctx is required for Name");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Name_kind;\r
+        p->v.Name.id = id;\r
+        p->v.Name.ctx = ctx;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena\r
+     *arena)\r
+{\r
+        expr_ty p;\r
+        if (!ctx) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field ctx is required for List");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = List_kind;\r
+        p->v.List.elts = elts;\r
+        p->v.List.ctx = ctx;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+expr_ty\r
+Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena\r
+      *arena)\r
+{\r
+        expr_ty p;\r
+        if (!ctx) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field ctx is required for Tuple");\r
+                return NULL;\r
+        }\r
+        p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Tuple_kind;\r
+        p->v.Tuple.elts = elts;\r
+        p->v.Tuple.ctx = ctx;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+slice_ty\r
+Ellipsis(PyArena *arena)\r
+{\r
+        slice_ty p;\r
+        p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Ellipsis_kind;\r
+        return p;\r
+}\r
+\r
+slice_ty\r
+Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)\r
+{\r
+        slice_ty p;\r
+        p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Slice_kind;\r
+        p->v.Slice.lower = lower;\r
+        p->v.Slice.upper = upper;\r
+        p->v.Slice.step = step;\r
+        return p;\r
+}\r
+\r
+slice_ty\r
+ExtSlice(asdl_seq * dims, PyArena *arena)\r
+{\r
+        slice_ty p;\r
+        p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = ExtSlice_kind;\r
+        p->v.ExtSlice.dims = dims;\r
+        return p;\r
+}\r
+\r
+slice_ty\r
+Index(expr_ty value, PyArena *arena)\r
+{\r
+        slice_ty p;\r
+        if (!value) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field value is required for Index");\r
+                return NULL;\r
+        }\r
+        p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = Index_kind;\r
+        p->v.Index.value = value;\r
+        return p;\r
+}\r
+\r
+comprehension_ty\r
+comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)\r
+{\r
+        comprehension_ty p;\r
+        if (!target) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field target is required for comprehension");\r
+                return NULL;\r
+        }\r
+        if (!iter) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field iter is required for comprehension");\r
+                return NULL;\r
+        }\r
+        p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->target = target;\r
+        p->iter = iter;\r
+        p->ifs = ifs;\r
+        return p;\r
+}\r
+\r
+excepthandler_ty\r
+ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int\r
+              col_offset, PyArena *arena)\r
+{\r
+        excepthandler_ty p;\r
+        p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->kind = ExceptHandler_kind;\r
+        p->v.ExceptHandler.type = type;\r
+        p->v.ExceptHandler.name = name;\r
+        p->v.ExceptHandler.body = body;\r
+        p->lineno = lineno;\r
+        p->col_offset = col_offset;\r
+        return p;\r
+}\r
+\r
+arguments_ty\r
+arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *\r
+          defaults, PyArena *arena)\r
+{\r
+        arguments_ty p;\r
+        p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->args = args;\r
+        p->vararg = vararg;\r
+        p->kwarg = kwarg;\r
+        p->defaults = defaults;\r
+        return p;\r
+}\r
+\r
+keyword_ty\r
+keyword(identifier arg, expr_ty value, PyArena *arena)\r
+{\r
+        keyword_ty p;\r
+        if (!arg) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field arg is required for keyword");\r
+                return NULL;\r
+        }\r
+        if (!value) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field value is required for keyword");\r
+                return NULL;\r
+        }\r
+        p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->arg = arg;\r
+        p->value = value;\r
+        return p;\r
+}\r
+\r
+alias_ty\r
+alias(identifier name, identifier asname, PyArena *arena)\r
+{\r
+        alias_ty p;\r
+        if (!name) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "field name is required for alias");\r
+                return NULL;\r
+        }\r
+        p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));\r
+        if (!p)\r
+                return NULL;\r
+        p->name = name;\r
+        p->asname = asname;\r
+        return p;\r
+}\r
+\r
+\r
+PyObject*\r
+ast2obj_mod(void* _o)\r
+{\r
+        mod_ty o = (mod_ty)_o;\r
+        PyObject *result = NULL, *value = NULL;\r
+        if (!o) {\r
+                Py_INCREF(Py_None);\r
+                return Py_None;\r
+        }\r
+\r
+        switch (o->kind) {\r
+        case Module_kind:\r
+                result = PyType_GenericNew(Module_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.Module.body, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Interactive_kind:\r
+                result = PyType_GenericNew(Interactive_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Expression_kind:\r
+                result = PyType_GenericNew(Expression_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Expression.body);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Suite_kind:\r
+                result = PyType_GenericNew(Suite_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        }\r
+        return result;\r
+failed:\r
+        Py_XDECREF(value);\r
+        Py_XDECREF(result);\r
+        return NULL;\r
+}\r
+\r
+PyObject*\r
+ast2obj_stmt(void* _o)\r
+{\r
+        stmt_ty o = (stmt_ty)_o;\r
+        PyObject *result = NULL, *value = NULL;\r
+        if (!o) {\r
+                Py_INCREF(Py_None);\r
+                return Py_None;\r
+        }\r
+\r
+        switch (o->kind) {\r
+        case FunctionDef_kind:\r
+                result = PyType_GenericNew(FunctionDef_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_identifier(o->v.FunctionDef.name);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "name", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_arguments(o->v.FunctionDef.args);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "args", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.FunctionDef.decorator_list,\r
+                                     ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "decorator_list", value) ==\r
+                    -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case ClassDef_kind:\r
+                result = PyType_GenericNew(ClassDef_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_identifier(o->v.ClassDef.name);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "name", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "bases", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.ClassDef.decorator_list,\r
+                                     ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "decorator_list", value) ==\r
+                    -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Return_kind:\r
+                result = PyType_GenericNew(Return_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Return.value);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "value", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Delete_kind:\r
+                result = PyType_GenericNew(Delete_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "targets", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Assign_kind:\r
+                result = PyType_GenericNew(Assign_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "targets", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.Assign.value);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "value", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case AugAssign_kind:\r
+                result = PyType_GenericNew(AugAssign_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.AugAssign.target);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "target", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_operator(o->v.AugAssign.op);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "op", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.AugAssign.value);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "value", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Print_kind:\r
+                result = PyType_GenericNew(Print_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Print.dest);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "dest", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.Print.values, ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "values", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_bool(o->v.Print.nl);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "nl", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case For_kind:\r
+                result = PyType_GenericNew(For_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.For.target);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "target", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.For.iter);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "iter", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.For.body, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "orelse", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case While_kind:\r
+                result = PyType_GenericNew(While_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.While.test);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "test", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.While.body, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "orelse", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case If_kind:\r
+                result = PyType_GenericNew(If_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.If.test);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "test", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.If.body, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "orelse", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case With_kind:\r
+                result = PyType_GenericNew(With_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.With.context_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "context_expr", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.With.optional_vars);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "optional_vars", value) ==\r
+                    -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.With.body, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Raise_kind:\r
+                result = PyType_GenericNew(Raise_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Raise.type);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "type", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.Raise.inst);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "inst", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.Raise.tback);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "tback", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case TryExcept_kind:\r
+                result = PyType_GenericNew(TryExcept_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.TryExcept.handlers,\r
+                                     ast2obj_excepthandler);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "handlers", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "orelse", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case TryFinally_kind:\r
+                result = PyType_GenericNew(TryFinally_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "finalbody", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Assert_kind:\r
+                result = PyType_GenericNew(Assert_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Assert.test);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "test", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.Assert.msg);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "msg", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Import_kind:\r
+                result = PyType_GenericNew(Import_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.Import.names, ast2obj_alias);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "names", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case ImportFrom_kind:\r
+                result = PyType_GenericNew(ImportFrom_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_identifier(o->v.ImportFrom.module);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "module", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "names", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_int(o->v.ImportFrom.level);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "level", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Exec_kind:\r
+                result = PyType_GenericNew(Exec_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Exec.body);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.Exec.globals);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "globals", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.Exec.locals);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "locals", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Global_kind:\r
+                result = PyType_GenericNew(Global_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.Global.names, ast2obj_identifier);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "names", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Expr_kind:\r
+                result = PyType_GenericNew(Expr_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Expr.value);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "value", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Pass_kind:\r
+                result = PyType_GenericNew(Pass_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                break;\r
+        case Break_kind:\r
+                result = PyType_GenericNew(Break_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                break;\r
+        case Continue_kind:\r
+                result = PyType_GenericNew(Continue_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                break;\r
+        }\r
+        value = ast2obj_int(o->lineno);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "lineno", value) < 0)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        value = ast2obj_int(o->col_offset);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "col_offset", value) < 0)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        return result;\r
+failed:\r
+        Py_XDECREF(value);\r
+        Py_XDECREF(result);\r
+        return NULL;\r
+}\r
+\r
+PyObject*\r
+ast2obj_expr(void* _o)\r
+{\r
+        expr_ty o = (expr_ty)_o;\r
+        PyObject *result = NULL, *value = NULL;\r
+        if (!o) {\r
+                Py_INCREF(Py_None);\r
+                return Py_None;\r
+        }\r
+\r
+        switch (o->kind) {\r
+        case BoolOp_kind:\r
+                result = PyType_GenericNew(BoolOp_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_boolop(o->v.BoolOp.op);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "op", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "values", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case BinOp_kind:\r
+                result = PyType_GenericNew(BinOp_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.BinOp.left);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "left", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_operator(o->v.BinOp.op);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "op", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.BinOp.right);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "right", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case UnaryOp_kind:\r
+                result = PyType_GenericNew(UnaryOp_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_unaryop(o->v.UnaryOp.op);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "op", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.UnaryOp.operand);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "operand", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Lambda_kind:\r
+                result = PyType_GenericNew(Lambda_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_arguments(o->v.Lambda.args);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "args", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.Lambda.body);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case IfExp_kind:\r
+                result = PyType_GenericNew(IfExp_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.IfExp.test);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "test", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.IfExp.body);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.IfExp.orelse);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "orelse", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Dict_kind:\r
+                result = PyType_GenericNew(Dict_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "keys", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.Dict.values, ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "values", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Set_kind:\r
+                result = PyType_GenericNew(Set_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.Set.elts, ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "elts", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case ListComp_kind:\r
+                result = PyType_GenericNew(ListComp_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.ListComp.elt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "elt", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.ListComp.generators,\r
+                                     ast2obj_comprehension);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "generators", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case SetComp_kind:\r
+                result = PyType_GenericNew(SetComp_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.SetComp.elt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "elt", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.SetComp.generators,\r
+                                     ast2obj_comprehension);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "generators", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case DictComp_kind:\r
+                result = PyType_GenericNew(DictComp_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.DictComp.key);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "key", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.DictComp.value);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "value", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.DictComp.generators,\r
+                                     ast2obj_comprehension);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "generators", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case GeneratorExp_kind:\r
+                result = PyType_GenericNew(GeneratorExp_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.GeneratorExp.elt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "elt", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.GeneratorExp.generators,\r
+                                     ast2obj_comprehension);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "generators", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Yield_kind:\r
+                result = PyType_GenericNew(Yield_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Yield.value);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "value", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Compare_kind:\r
+                result = PyType_GenericNew(Compare_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Compare.left);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "left", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                {\r
+                        int i, n = asdl_seq_LEN(o->v.Compare.ops);\r
+                        value = PyList_New(n);\r
+                        if (!value) goto failed;\r
+                        for(i = 0; i < n; i++)\r
+                                PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));\r
+                }\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "ops", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "comparators", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Call_kind:\r
+                result = PyType_GenericNew(Call_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Call.func);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "func", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.Call.args, ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "args", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "keywords", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.Call.starargs);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "starargs", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.Call.kwargs);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "kwargs", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Repr_kind:\r
+                result = PyType_GenericNew(Repr_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Repr.value);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "value", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Num_kind:\r
+                result = PyType_GenericNew(Num_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_object(o->v.Num.n);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "n", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Str_kind:\r
+                result = PyType_GenericNew(Str_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_string(o->v.Str.s);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "s", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Attribute_kind:\r
+                result = PyType_GenericNew(Attribute_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Attribute.value);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "value", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_identifier(o->v.Attribute.attr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "attr", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr_context(o->v.Attribute.ctx);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "ctx", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Subscript_kind:\r
+                result = PyType_GenericNew(Subscript_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Subscript.value);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "value", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_slice(o->v.Subscript.slice);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "slice", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr_context(o->v.Subscript.ctx);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "ctx", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Name_kind:\r
+                result = PyType_GenericNew(Name_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_identifier(o->v.Name.id);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "id", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr_context(o->v.Name.ctx);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "ctx", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case List_kind:\r
+                result = PyType_GenericNew(List_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.List.elts, ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "elts", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr_context(o->v.List.ctx);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "ctx", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Tuple_kind:\r
+                result = PyType_GenericNew(Tuple_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "elts", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr_context(o->v.Tuple.ctx);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "ctx", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        }\r
+        value = ast2obj_int(o->lineno);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "lineno", value) < 0)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        value = ast2obj_int(o->col_offset);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "col_offset", value) < 0)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        return result;\r
+failed:\r
+        Py_XDECREF(value);\r
+        Py_XDECREF(result);\r
+        return NULL;\r
+}\r
+\r
+PyObject* ast2obj_expr_context(expr_context_ty o)\r
+{\r
+        switch(o) {\r
+                case Load:\r
+                        Py_INCREF(Load_singleton);\r
+                        return Load_singleton;\r
+                case Store:\r
+                        Py_INCREF(Store_singleton);\r
+                        return Store_singleton;\r
+                case Del:\r
+                        Py_INCREF(Del_singleton);\r
+                        return Del_singleton;\r
+                case AugLoad:\r
+                        Py_INCREF(AugLoad_singleton);\r
+                        return AugLoad_singleton;\r
+                case AugStore:\r
+                        Py_INCREF(AugStore_singleton);\r
+                        return AugStore_singleton;\r
+                case Param:\r
+                        Py_INCREF(Param_singleton);\r
+                        return Param_singleton;\r
+                default:\r
+                        /* should never happen, but just in case ... */\r
+                        PyErr_Format(PyExc_SystemError, "unknown expr_context found");\r
+                        return NULL;\r
+        }\r
+}\r
+PyObject*\r
+ast2obj_slice(void* _o)\r
+{\r
+        slice_ty o = (slice_ty)_o;\r
+        PyObject *result = NULL, *value = NULL;\r
+        if (!o) {\r
+                Py_INCREF(Py_None);\r
+                return Py_None;\r
+        }\r
+\r
+        switch (o->kind) {\r
+        case Ellipsis_kind:\r
+                result = PyType_GenericNew(Ellipsis_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                break;\r
+        case Slice_kind:\r
+                result = PyType_GenericNew(Slice_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Slice.lower);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "lower", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.Slice.upper);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "upper", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.Slice.step);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "step", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case ExtSlice_kind:\r
+                result = PyType_GenericNew(ExtSlice_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "dims", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        case Index_kind:\r
+                result = PyType_GenericNew(Index_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.Index.value);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "value", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        }\r
+        return result;\r
+failed:\r
+        Py_XDECREF(value);\r
+        Py_XDECREF(result);\r
+        return NULL;\r
+}\r
+\r
+PyObject* ast2obj_boolop(boolop_ty o)\r
+{\r
+        switch(o) {\r
+                case And:\r
+                        Py_INCREF(And_singleton);\r
+                        return And_singleton;\r
+                case Or:\r
+                        Py_INCREF(Or_singleton);\r
+                        return Or_singleton;\r
+                default:\r
+                        /* should never happen, but just in case ... */\r
+                        PyErr_Format(PyExc_SystemError, "unknown boolop found");\r
+                        return NULL;\r
+        }\r
+}\r
+PyObject* ast2obj_operator(operator_ty o)\r
+{\r
+        switch(o) {\r
+                case Add:\r
+                        Py_INCREF(Add_singleton);\r
+                        return Add_singleton;\r
+                case Sub:\r
+                        Py_INCREF(Sub_singleton);\r
+                        return Sub_singleton;\r
+                case Mult:\r
+                        Py_INCREF(Mult_singleton);\r
+                        return Mult_singleton;\r
+                case Div:\r
+                        Py_INCREF(Div_singleton);\r
+                        return Div_singleton;\r
+                case Mod:\r
+                        Py_INCREF(Mod_singleton);\r
+                        return Mod_singleton;\r
+                case Pow:\r
+                        Py_INCREF(Pow_singleton);\r
+                        return Pow_singleton;\r
+                case LShift:\r
+                        Py_INCREF(LShift_singleton);\r
+                        return LShift_singleton;\r
+                case RShift:\r
+                        Py_INCREF(RShift_singleton);\r
+                        return RShift_singleton;\r
+                case BitOr:\r
+                        Py_INCREF(BitOr_singleton);\r
+                        return BitOr_singleton;\r
+                case BitXor:\r
+                        Py_INCREF(BitXor_singleton);\r
+                        return BitXor_singleton;\r
+                case BitAnd:\r
+                        Py_INCREF(BitAnd_singleton);\r
+                        return BitAnd_singleton;\r
+                case FloorDiv:\r
+                        Py_INCREF(FloorDiv_singleton);\r
+                        return FloorDiv_singleton;\r
+                default:\r
+                        /* should never happen, but just in case ... */\r
+                        PyErr_Format(PyExc_SystemError, "unknown operator found");\r
+                        return NULL;\r
+        }\r
+}\r
+PyObject* ast2obj_unaryop(unaryop_ty o)\r
+{\r
+        switch(o) {\r
+                case Invert:\r
+                        Py_INCREF(Invert_singleton);\r
+                        return Invert_singleton;\r
+                case Not:\r
+                        Py_INCREF(Not_singleton);\r
+                        return Not_singleton;\r
+                case UAdd:\r
+                        Py_INCREF(UAdd_singleton);\r
+                        return UAdd_singleton;\r
+                case USub:\r
+                        Py_INCREF(USub_singleton);\r
+                        return USub_singleton;\r
+                default:\r
+                        /* should never happen, but just in case ... */\r
+                        PyErr_Format(PyExc_SystemError, "unknown unaryop found");\r
+                        return NULL;\r
+        }\r
+}\r
+PyObject* ast2obj_cmpop(cmpop_ty o)\r
+{\r
+        switch(o) {\r
+                case Eq:\r
+                        Py_INCREF(Eq_singleton);\r
+                        return Eq_singleton;\r
+                case NotEq:\r
+                        Py_INCREF(NotEq_singleton);\r
+                        return NotEq_singleton;\r
+                case Lt:\r
+                        Py_INCREF(Lt_singleton);\r
+                        return Lt_singleton;\r
+                case LtE:\r
+                        Py_INCREF(LtE_singleton);\r
+                        return LtE_singleton;\r
+                case Gt:\r
+                        Py_INCREF(Gt_singleton);\r
+                        return Gt_singleton;\r
+                case GtE:\r
+                        Py_INCREF(GtE_singleton);\r
+                        return GtE_singleton;\r
+                case Is:\r
+                        Py_INCREF(Is_singleton);\r
+                        return Is_singleton;\r
+                case IsNot:\r
+                        Py_INCREF(IsNot_singleton);\r
+                        return IsNot_singleton;\r
+                case In:\r
+                        Py_INCREF(In_singleton);\r
+                        return In_singleton;\r
+                case NotIn:\r
+                        Py_INCREF(NotIn_singleton);\r
+                        return NotIn_singleton;\r
+                default:\r
+                        /* should never happen, but just in case ... */\r
+                        PyErr_Format(PyExc_SystemError, "unknown cmpop found");\r
+                        return NULL;\r
+        }\r
+}\r
+PyObject*\r
+ast2obj_comprehension(void* _o)\r
+{\r
+        comprehension_ty o = (comprehension_ty)_o;\r
+        PyObject *result = NULL, *value = NULL;\r
+        if (!o) {\r
+                Py_INCREF(Py_None);\r
+                return Py_None;\r
+        }\r
+\r
+        result = PyType_GenericNew(comprehension_type, NULL, NULL);\r
+        if (!result) return NULL;\r
+        value = ast2obj_expr(o->target);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "target", value) == -1)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        value = ast2obj_expr(o->iter);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "iter", value) == -1)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        value = ast2obj_list(o->ifs, ast2obj_expr);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "ifs", value) == -1)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        return result;\r
+failed:\r
+        Py_XDECREF(value);\r
+        Py_XDECREF(result);\r
+        return NULL;\r
+}\r
+\r
+PyObject*\r
+ast2obj_excepthandler(void* _o)\r
+{\r
+        excepthandler_ty o = (excepthandler_ty)_o;\r
+        PyObject *result = NULL, *value = NULL;\r
+        if (!o) {\r
+                Py_INCREF(Py_None);\r
+                return Py_None;\r
+        }\r
+\r
+        switch (o->kind) {\r
+        case ExceptHandler_kind:\r
+                result = PyType_GenericNew(ExceptHandler_type, NULL, NULL);\r
+                if (!result) goto failed;\r
+                value = ast2obj_expr(o->v.ExceptHandler.type);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "type", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_expr(o->v.ExceptHandler.name);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "name", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);\r
+                if (!value) goto failed;\r
+                if (PyObject_SetAttrString(result, "body", value) == -1)\r
+                        goto failed;\r
+                Py_DECREF(value);\r
+                break;\r
+        }\r
+        value = ast2obj_int(o->lineno);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "lineno", value) < 0)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        value = ast2obj_int(o->col_offset);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "col_offset", value) < 0)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        return result;\r
+failed:\r
+        Py_XDECREF(value);\r
+        Py_XDECREF(result);\r
+        return NULL;\r
+}\r
+\r
+PyObject*\r
+ast2obj_arguments(void* _o)\r
+{\r
+        arguments_ty o = (arguments_ty)_o;\r
+        PyObject *result = NULL, *value = NULL;\r
+        if (!o) {\r
+                Py_INCREF(Py_None);\r
+                return Py_None;\r
+        }\r
+\r
+        result = PyType_GenericNew(arguments_type, NULL, NULL);\r
+        if (!result) return NULL;\r
+        value = ast2obj_list(o->args, ast2obj_expr);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "args", value) == -1)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        value = ast2obj_identifier(o->vararg);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "vararg", value) == -1)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        value = ast2obj_identifier(o->kwarg);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "kwarg", value) == -1)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        value = ast2obj_list(o->defaults, ast2obj_expr);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "defaults", value) == -1)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        return result;\r
+failed:\r
+        Py_XDECREF(value);\r
+        Py_XDECREF(result);\r
+        return NULL;\r
+}\r
+\r
+PyObject*\r
+ast2obj_keyword(void* _o)\r
+{\r
+        keyword_ty o = (keyword_ty)_o;\r
+        PyObject *result = NULL, *value = NULL;\r
+        if (!o) {\r
+                Py_INCREF(Py_None);\r
+                return Py_None;\r
+        }\r
+\r
+        result = PyType_GenericNew(keyword_type, NULL, NULL);\r
+        if (!result) return NULL;\r
+        value = ast2obj_identifier(o->arg);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "arg", value) == -1)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        value = ast2obj_expr(o->value);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "value", value) == -1)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        return result;\r
+failed:\r
+        Py_XDECREF(value);\r
+        Py_XDECREF(result);\r
+        return NULL;\r
+}\r
+\r
+PyObject*\r
+ast2obj_alias(void* _o)\r
+{\r
+        alias_ty o = (alias_ty)_o;\r
+        PyObject *result = NULL, *value = NULL;\r
+        if (!o) {\r
+                Py_INCREF(Py_None);\r
+                return Py_None;\r
+        }\r
+\r
+        result = PyType_GenericNew(alias_type, NULL, NULL);\r
+        if (!result) return NULL;\r
+        value = ast2obj_identifier(o->name);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "name", value) == -1)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        value = ast2obj_identifier(o->asname);\r
+        if (!value) goto failed;\r
+        if (PyObject_SetAttrString(result, "asname", value) == -1)\r
+                goto failed;\r
+        Py_DECREF(value);\r
+        return result;\r
+failed:\r
+        Py_XDECREF(value);\r
+        Py_XDECREF(result);\r
+        return NULL;\r
+}\r
+\r
+\r
+int\r
+obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        int isinstance;\r
+\r
+\r
+        if (obj == Py_None) {\r
+                *out = NULL;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* body;\r
+\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        body = asdl_seq_new(len, arena);\r
+                        if (body == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(body, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");\r
+                        return 1;\r
+                }\r
+                *out = Module(body, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* body;\r
+\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        body = asdl_seq_new(len, arena);\r
+                        if (body == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(body, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");\r
+                        return 1;\r
+                }\r
+                *out = Interactive(body, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty body;\r
+\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &body, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");\r
+                        return 1;\r
+                }\r
+                *out = Expression(body, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* body;\r
+\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        body = asdl_seq_new(len, arena);\r
+                        if (body == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(body, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");\r
+                        return 1;\r
+                }\r
+                *out = Suite(body, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+\r
+        tmp = PyObject_Repr(obj);\r
+        if (tmp == NULL) goto failed;\r
+        PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+int\r
+obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        int isinstance;\r
+\r
+        int lineno;\r
+        int col_offset;\r
+\r
+        if (obj == Py_None) {\r
+                *out = NULL;\r
+                return 0;\r
+        }\r
+        if (PyObject_HasAttrString(obj, "lineno")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "lineno");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_int(tmp, &lineno, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");\r
+                return 1;\r
+        }\r
+        if (PyObject_HasAttrString(obj, "col_offset")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "col_offset");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_int(tmp, &col_offset, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");\r
+                return 1;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                identifier name;\r
+                arguments_ty args;\r
+                asdl_seq* body;\r
+                asdl_seq* decorator_list;\r
+\r
+                if (PyObject_HasAttrString(obj, "name")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "name");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_identifier(tmp, &name, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "args")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "args");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_arguments(tmp, &args, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        body = asdl_seq_new(len, arena);\r
+                        if (body == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(body, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "decorator_list")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "decorator_list");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        decorator_list = asdl_seq_new(len, arena);\r
+                        if (decorator_list == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(decorator_list, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");\r
+                        return 1;\r
+                }\r
+                *out = FunctionDef(name, args, body, decorator_list, lineno,\r
+                                   col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                identifier name;\r
+                asdl_seq* bases;\r
+                asdl_seq* body;\r
+                asdl_seq* decorator_list;\r
+\r
+                if (PyObject_HasAttrString(obj, "name")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "name");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_identifier(tmp, &name, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "bases")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "bases");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        bases = asdl_seq_new(len, arena);\r
+                        if (bases == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(bases, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        body = asdl_seq_new(len, arena);\r
+                        if (body == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(body, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "decorator_list")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "decorator_list");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        decorator_list = asdl_seq_new(len, arena);\r
+                        if (decorator_list == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(decorator_list, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");\r
+                        return 1;\r
+                }\r
+                *out = ClassDef(name, bases, body, decorator_list, lineno,\r
+                                col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty value;\r
+\r
+                if (PyObject_HasAttrString(obj, "value")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "value");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &value, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        value = NULL;\r
+                }\r
+                *out = Return(value, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* targets;\r
+\r
+                if (PyObject_HasAttrString(obj, "targets")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "targets");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        targets = asdl_seq_new(len, arena);\r
+                        if (targets == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(targets, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");\r
+                        return 1;\r
+                }\r
+                *out = Delete(targets, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* targets;\r
+                expr_ty value;\r
+\r
+                if (PyObject_HasAttrString(obj, "targets")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "targets");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        targets = asdl_seq_new(len, arena);\r
+                        if (targets == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(targets, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "value")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "value");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &value, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");\r
+                        return 1;\r
+                }\r
+                *out = Assign(targets, value, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty target;\r
+                operator_ty op;\r
+                expr_ty value;\r
+\r
+                if (PyObject_HasAttrString(obj, "target")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "target");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &target, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "op")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "op");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_operator(tmp, &op, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "value")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "value");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &value, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");\r
+                        return 1;\r
+                }\r
+                *out = AugAssign(target, op, value, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Print_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty dest;\r
+                asdl_seq* values;\r
+                bool nl;\r
+\r
+                if (PyObject_HasAttrString(obj, "dest")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "dest");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &dest, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        dest = NULL;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "values")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "values");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Print field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        values = asdl_seq_new(len, arena);\r
+                        if (values == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(values, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Print");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "nl")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "nl");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_bool(tmp, &nl, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"nl\" missing from Print");\r
+                        return 1;\r
+                }\r
+                *out = Print(dest, values, nl, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)For_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty target;\r
+                expr_ty iter;\r
+                asdl_seq* body;\r
+                asdl_seq* orelse;\r
+\r
+                if (PyObject_HasAttrString(obj, "target")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "target");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &target, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "iter")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "iter");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &iter, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        body = asdl_seq_new(len, arena);\r
+                        if (body == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(body, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "orelse")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "orelse");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        orelse = asdl_seq_new(len, arena);\r
+                        if (orelse == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(orelse, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");\r
+                        return 1;\r
+                }\r
+                *out = For(target, iter, body, orelse, lineno, col_offset,\r
+                           arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)While_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty test;\r
+                asdl_seq* body;\r
+                asdl_seq* orelse;\r
+\r
+                if (PyObject_HasAttrString(obj, "test")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "test");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &test, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        body = asdl_seq_new(len, arena);\r
+                        if (body == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(body, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "orelse")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "orelse");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        orelse = asdl_seq_new(len, arena);\r
+                        if (orelse == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(orelse, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");\r
+                        return 1;\r
+                }\r
+                *out = While(test, body, orelse, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)If_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty test;\r
+                asdl_seq* body;\r
+                asdl_seq* orelse;\r
+\r
+                if (PyObject_HasAttrString(obj, "test")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "test");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &test, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        body = asdl_seq_new(len, arena);\r
+                        if (body == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(body, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "orelse")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "orelse");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        orelse = asdl_seq_new(len, arena);\r
+                        if (orelse == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(orelse, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");\r
+                        return 1;\r
+                }\r
+                *out = If(test, body, orelse, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)With_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty context_expr;\r
+                expr_ty optional_vars;\r
+                asdl_seq* body;\r
+\r
+                if (PyObject_HasAttrString(obj, "context_expr")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "context_expr");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &context_expr, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "optional_vars")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "optional_vars");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &optional_vars, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        optional_vars = NULL;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        body = asdl_seq_new(len, arena);\r
+                        if (body == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(body, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");\r
+                        return 1;\r
+                }\r
+                *out = With(context_expr, optional_vars, body, lineno,\r
+                            col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty type;\r
+                expr_ty inst;\r
+                expr_ty tback;\r
+\r
+                if (PyObject_HasAttrString(obj, "type")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "type");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &type, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        type = NULL;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "inst")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "inst");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &inst, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        inst = NULL;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "tback")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "tback");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &tback, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        tback = NULL;\r
+                }\r
+                *out = Raise(type, inst, tback, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* body;\r
+                asdl_seq* handlers;\r
+                asdl_seq* orelse;\r
+\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        body = asdl_seq_new(len, arena);\r
+                        if (body == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(body, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "handlers")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "handlers");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        handlers = asdl_seq_new(len, arena);\r
+                        if (handlers == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                excepthandler_ty value;\r
+                                res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(handlers, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "orelse")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "orelse");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        orelse = asdl_seq_new(len, arena);\r
+                        if (orelse == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(orelse, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept");\r
+                        return 1;\r
+                }\r
+                *out = TryExcept(body, handlers, orelse, lineno, col_offset,\r
+                                 arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* body;\r
+                asdl_seq* finalbody;\r
+\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        body = asdl_seq_new(len, arena);\r
+                        if (body == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(body, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "finalbody")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "finalbody");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        finalbody = asdl_seq_new(len, arena);\r
+                        if (finalbody == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(finalbody, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally");\r
+                        return 1;\r
+                }\r
+                *out = TryFinally(body, finalbody, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty test;\r
+                expr_ty msg;\r
+\r
+                if (PyObject_HasAttrString(obj, "test")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "test");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &test, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "msg")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "msg");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &msg, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        msg = NULL;\r
+                }\r
+                *out = Assert(test, msg, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* names;\r
+\r
+                if (PyObject_HasAttrString(obj, "names")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "names");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        names = asdl_seq_new(len, arena);\r
+                        if (names == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                alias_ty value;\r
+                                res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(names, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");\r
+                        return 1;\r
+                }\r
+                *out = Import(names, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                identifier module;\r
+                asdl_seq* names;\r
+                int level;\r
+\r
+                if (PyObject_HasAttrString(obj, "module")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "module");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_identifier(tmp, &module, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        module = NULL;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "names")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "names");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        names = asdl_seq_new(len, arena);\r
+                        if (names == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                alias_ty value;\r
+                                res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(names, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "level")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "level");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_int(tmp, &level, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        level = 0;\r
+                }\r
+                *out = ImportFrom(module, names, level, lineno, col_offset,\r
+                                  arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Exec_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty body;\r
+                expr_ty globals;\r
+                expr_ty locals;\r
+\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &body, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Exec");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "globals")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "globals");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &globals, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        globals = NULL;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "locals")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "locals");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &locals, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        locals = NULL;\r
+                }\r
+                *out = Exec(body, globals, locals, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* names;\r
+\r
+                if (PyObject_HasAttrString(obj, "names")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "names");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        names = asdl_seq_new(len, arena);\r
+                        if (names == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                identifier value;\r
+                                res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(names, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");\r
+                        return 1;\r
+                }\r
+                *out = Global(names, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty value;\r
+\r
+                if (PyObject_HasAttrString(obj, "value")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "value");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &value, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");\r
+                        return 1;\r
+                }\r
+                *out = Expr(value, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+\r
+                *out = Pass(lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+\r
+                *out = Break(lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+\r
+                *out = Continue(lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+\r
+        tmp = PyObject_Repr(obj);\r
+        if (tmp == NULL) goto failed;\r
+        PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+int\r
+obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        int isinstance;\r
+\r
+        int lineno;\r
+        int col_offset;\r
+\r
+        if (obj == Py_None) {\r
+                *out = NULL;\r
+                return 0;\r
+        }\r
+        if (PyObject_HasAttrString(obj, "lineno")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "lineno");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_int(tmp, &lineno, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");\r
+                return 1;\r
+        }\r
+        if (PyObject_HasAttrString(obj, "col_offset")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "col_offset");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_int(tmp, &col_offset, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");\r
+                return 1;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                boolop_ty op;\r
+                asdl_seq* values;\r
+\r
+                if (PyObject_HasAttrString(obj, "op")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "op");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_boolop(tmp, &op, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "values")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "values");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        values = asdl_seq_new(len, arena);\r
+                        if (values == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(values, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");\r
+                        return 1;\r
+                }\r
+                *out = BoolOp(op, values, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty left;\r
+                operator_ty op;\r
+                expr_ty right;\r
+\r
+                if (PyObject_HasAttrString(obj, "left")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "left");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &left, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "op")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "op");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_operator(tmp, &op, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "right")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "right");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &right, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");\r
+                        return 1;\r
+                }\r
+                *out = BinOp(left, op, right, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                unaryop_ty op;\r
+                expr_ty operand;\r
+\r
+                if (PyObject_HasAttrString(obj, "op")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "op");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_unaryop(tmp, &op, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "operand")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "operand");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &operand, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");\r
+                        return 1;\r
+                }\r
+                *out = UnaryOp(op, operand, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                arguments_ty args;\r
+                expr_ty body;\r
+\r
+                if (PyObject_HasAttrString(obj, "args")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "args");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_arguments(tmp, &args, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &body, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");\r
+                        return 1;\r
+                }\r
+                *out = Lambda(args, body, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty test;\r
+                expr_ty body;\r
+                expr_ty orelse;\r
+\r
+                if (PyObject_HasAttrString(obj, "test")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "test");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &test, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &body, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "orelse")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "orelse");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &orelse, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");\r
+                        return 1;\r
+                }\r
+                *out = IfExp(test, body, orelse, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* keys;\r
+                asdl_seq* values;\r
+\r
+                if (PyObject_HasAttrString(obj, "keys")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "keys");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        keys = asdl_seq_new(len, arena);\r
+                        if (keys == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(keys, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "values")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "values");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        values = asdl_seq_new(len, arena);\r
+                        if (values == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(values, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");\r
+                        return 1;\r
+                }\r
+                *out = Dict(keys, values, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* elts;\r
+\r
+                if (PyObject_HasAttrString(obj, "elts")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "elts");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        elts = asdl_seq_new(len, arena);\r
+                        if (elts == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(elts, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");\r
+                        return 1;\r
+                }\r
+                *out = Set(elts, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty elt;\r
+                asdl_seq* generators;\r
+\r
+                if (PyObject_HasAttrString(obj, "elt")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "elt");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &elt, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "generators")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "generators");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        generators = asdl_seq_new(len, arena);\r
+                        if (generators == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                comprehension_ty value;\r
+                                res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(generators, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");\r
+                        return 1;\r
+                }\r
+                *out = ListComp(elt, generators, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty elt;\r
+                asdl_seq* generators;\r
+\r
+                if (PyObject_HasAttrString(obj, "elt")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "elt");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &elt, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "generators")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "generators");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        generators = asdl_seq_new(len, arena);\r
+                        if (generators == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                comprehension_ty value;\r
+                                res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(generators, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");\r
+                        return 1;\r
+                }\r
+                *out = SetComp(elt, generators, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty key;\r
+                expr_ty value;\r
+                asdl_seq* generators;\r
+\r
+                if (PyObject_HasAttrString(obj, "key")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "key");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &key, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "value")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "value");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &value, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "generators")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "generators");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        generators = asdl_seq_new(len, arena);\r
+                        if (generators == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                comprehension_ty value;\r
+                                res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(generators, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");\r
+                        return 1;\r
+                }\r
+                *out = DictComp(key, value, generators, lineno, col_offset,\r
+                                arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty elt;\r
+                asdl_seq* generators;\r
+\r
+                if (PyObject_HasAttrString(obj, "elt")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "elt");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &elt, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "generators")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "generators");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        generators = asdl_seq_new(len, arena);\r
+                        if (generators == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                comprehension_ty value;\r
+                                res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(generators, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");\r
+                        return 1;\r
+                }\r
+                *out = GeneratorExp(elt, generators, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty value;\r
+\r
+                if (PyObject_HasAttrString(obj, "value")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "value");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &value, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        value = NULL;\r
+                }\r
+                *out = Yield(value, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty left;\r
+                asdl_int_seq* ops;\r
+                asdl_seq* comparators;\r
+\r
+                if (PyObject_HasAttrString(obj, "left")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "left");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &left, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "ops")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "ops");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        ops = asdl_int_seq_new(len, arena);\r
+                        if (ops == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                cmpop_ty value;\r
+                                res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(ops, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "comparators")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "comparators");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        comparators = asdl_seq_new(len, arena);\r
+                        if (comparators == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(comparators, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");\r
+                        return 1;\r
+                }\r
+                *out = Compare(left, ops, comparators, lineno, col_offset,\r
+                               arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty func;\r
+                asdl_seq* args;\r
+                asdl_seq* keywords;\r
+                expr_ty starargs;\r
+                expr_ty kwargs;\r
+\r
+                if (PyObject_HasAttrString(obj, "func")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "func");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &func, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "args")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "args");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        args = asdl_seq_new(len, arena);\r
+                        if (args == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(args, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "keywords")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "keywords");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        keywords = asdl_seq_new(len, arena);\r
+                        if (keywords == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                keyword_ty value;\r
+                                res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(keywords, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "starargs")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "starargs");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &starargs, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        starargs = NULL;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "kwargs")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "kwargs");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &kwargs, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        kwargs = NULL;\r
+                }\r
+                *out = Call(func, args, keywords, starargs, kwargs, lineno,\r
+                            col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Repr_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty value;\r
+\r
+                if (PyObject_HasAttrString(obj, "value")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "value");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &value, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Repr");\r
+                        return 1;\r
+                }\r
+                *out = Repr(value, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                object n;\r
+\r
+                if (PyObject_HasAttrString(obj, "n")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "n");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_object(tmp, &n, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num");\r
+                        return 1;\r
+                }\r
+                *out = Num(n, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                string s;\r
+\r
+                if (PyObject_HasAttrString(obj, "s")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "s");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_string(tmp, &s, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str");\r
+                        return 1;\r
+                }\r
+                *out = Str(s, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty value;\r
+                identifier attr;\r
+                expr_context_ty ctx;\r
+\r
+                if (PyObject_HasAttrString(obj, "value")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "value");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &value, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "attr")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "attr");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_identifier(tmp, &attr, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "ctx")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "ctx");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr_context(tmp, &ctx, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");\r
+                        return 1;\r
+                }\r
+                *out = Attribute(value, attr, ctx, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty value;\r
+                slice_ty slice;\r
+                expr_context_ty ctx;\r
+\r
+                if (PyObject_HasAttrString(obj, "value")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "value");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &value, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "slice")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "slice");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_slice(tmp, &slice, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "ctx")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "ctx");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr_context(tmp, &ctx, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");\r
+                        return 1;\r
+                }\r
+                *out = Subscript(value, slice, ctx, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                identifier id;\r
+                expr_context_ty ctx;\r
+\r
+                if (PyObject_HasAttrString(obj, "id")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "id");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_identifier(tmp, &id, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "ctx")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "ctx");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr_context(tmp, &ctx, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");\r
+                        return 1;\r
+                }\r
+                *out = Name(id, ctx, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)List_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* elts;\r
+                expr_context_ty ctx;\r
+\r
+                if (PyObject_HasAttrString(obj, "elts")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "elts");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        elts = asdl_seq_new(len, arena);\r
+                        if (elts == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(elts, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "ctx")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "ctx");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr_context(tmp, &ctx, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");\r
+                        return 1;\r
+                }\r
+                *out = List(elts, ctx, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* elts;\r
+                expr_context_ty ctx;\r
+\r
+                if (PyObject_HasAttrString(obj, "elts")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "elts");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        elts = asdl_seq_new(len, arena);\r
+                        if (elts == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                expr_ty value;\r
+                                res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(elts, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");\r
+                        return 1;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "ctx")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "ctx");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr_context(tmp, &ctx, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");\r
+                        return 1;\r
+                }\r
+                *out = Tuple(elts, ctx, lineno, col_offset, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+\r
+        tmp = PyObject_Repr(obj);\r
+        if (tmp == NULL) goto failed;\r
+        PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+int\r
+obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        int isinstance;\r
+\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Load;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Store;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Del;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = AugLoad;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = AugStore;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Param;\r
+                return 0;\r
+        }\r
+\r
+        tmp = PyObject_Repr(obj);\r
+        if (tmp == NULL) goto failed;\r
+        PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+int\r
+obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        int isinstance;\r
+\r
+\r
+        if (obj == Py_None) {\r
+                *out = NULL;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+\r
+                *out = Ellipsis(arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty lower;\r
+                expr_ty upper;\r
+                expr_ty step;\r
+\r
+                if (PyObject_HasAttrString(obj, "lower")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "lower");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &lower, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        lower = NULL;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "upper")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "upper");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &upper, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        upper = NULL;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "step")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "step");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &step, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        step = NULL;\r
+                }\r
+                *out = Slice(lower, upper, step, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                asdl_seq* dims;\r
+\r
+                if (PyObject_HasAttrString(obj, "dims")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "dims");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        dims = asdl_seq_new(len, arena);\r
+                        if (dims == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                slice_ty value;\r
+                                res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(dims, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");\r
+                        return 1;\r
+                }\r
+                *out = ExtSlice(dims, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty value;\r
+\r
+                if (PyObject_HasAttrString(obj, "value")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "value");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &value, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");\r
+                        return 1;\r
+                }\r
+                *out = Index(value, arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+\r
+        tmp = PyObject_Repr(obj);\r
+        if (tmp == NULL) goto failed;\r
+        PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+int\r
+obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        int isinstance;\r
+\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = And;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Or;\r
+                return 0;\r
+        }\r
+\r
+        tmp = PyObject_Repr(obj);\r
+        if (tmp == NULL) goto failed;\r
+        PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+int\r
+obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        int isinstance;\r
+\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Add;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Sub;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Mult;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Div;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Mod;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Pow;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = LShift;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = RShift;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = BitOr;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = BitXor;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = BitAnd;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = FloorDiv;\r
+                return 0;\r
+        }\r
+\r
+        tmp = PyObject_Repr(obj);\r
+        if (tmp == NULL) goto failed;\r
+        PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+int\r
+obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        int isinstance;\r
+\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Invert;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Not;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = UAdd;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = USub;\r
+                return 0;\r
+        }\r
+\r
+        tmp = PyObject_Repr(obj);\r
+        if (tmp == NULL) goto failed;\r
+        PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+int\r
+obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        int isinstance;\r
+\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Eq;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = NotEq;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Lt;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = LtE;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Gt;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = GtE;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = Is;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = IsNot;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)In_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = In;\r
+                return 0;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                *out = NotIn;\r
+                return 0;\r
+        }\r
+\r
+        tmp = PyObject_Repr(obj);\r
+        if (tmp == NULL) goto failed;\r
+        PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+int\r
+obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        expr_ty target;\r
+        expr_ty iter;\r
+        asdl_seq* ifs;\r
+\r
+        if (PyObject_HasAttrString(obj, "target")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "target");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_expr(tmp, &target, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");\r
+                return 1;\r
+        }\r
+        if (PyObject_HasAttrString(obj, "iter")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "iter");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_expr(tmp, &iter, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");\r
+                return 1;\r
+        }\r
+        if (PyObject_HasAttrString(obj, "ifs")) {\r
+                int res;\r
+                Py_ssize_t len;\r
+                Py_ssize_t i;\r
+                tmp = PyObject_GetAttrString(obj, "ifs");\r
+                if (tmp == NULL) goto failed;\r
+                if (!PyList_Check(tmp)) {\r
+                        PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                        goto failed;\r
+                }\r
+                len = PyList_GET_SIZE(tmp);\r
+                ifs = asdl_seq_new(len, arena);\r
+                if (ifs == NULL) goto failed;\r
+                for (i = 0; i < len; i++) {\r
+                        expr_ty value;\r
+                        res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                        if (res != 0) goto failed;\r
+                        asdl_seq_SET(ifs, i, value);\r
+                }\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");\r
+                return 1;\r
+        }\r
+        *out = comprehension(target, iter, ifs, arena);\r
+        return 0;\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+int\r
+obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        int isinstance;\r
+\r
+        int lineno;\r
+        int col_offset;\r
+\r
+        if (obj == Py_None) {\r
+                *out = NULL;\r
+                return 0;\r
+        }\r
+        if (PyObject_HasAttrString(obj, "lineno")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "lineno");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_int(tmp, &lineno, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");\r
+                return 1;\r
+        }\r
+        if (PyObject_HasAttrString(obj, "col_offset")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "col_offset");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_int(tmp, &col_offset, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");\r
+                return 1;\r
+        }\r
+        isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type);\r
+        if (isinstance == -1) {\r
+                return 1;\r
+        }\r
+        if (isinstance) {\r
+                expr_ty type;\r
+                expr_ty name;\r
+                asdl_seq* body;\r
+\r
+                if (PyObject_HasAttrString(obj, "type")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "type");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &type, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        type = NULL;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "name")) {\r
+                        int res;\r
+                        tmp = PyObject_GetAttrString(obj, "name");\r
+                        if (tmp == NULL) goto failed;\r
+                        res = obj2ast_expr(tmp, &name, arena);\r
+                        if (res != 0) goto failed;\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        name = NULL;\r
+                }\r
+                if (PyObject_HasAttrString(obj, "body")) {\r
+                        int res;\r
+                        Py_ssize_t len;\r
+                        Py_ssize_t i;\r
+                        tmp = PyObject_GetAttrString(obj, "body");\r
+                        if (tmp == NULL) goto failed;\r
+                        if (!PyList_Check(tmp)) {\r
+                                PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                                goto failed;\r
+                        }\r
+                        len = PyList_GET_SIZE(tmp);\r
+                        body = asdl_seq_new(len, arena);\r
+                        if (body == NULL) goto failed;\r
+                        for (i = 0; i < len; i++) {\r
+                                stmt_ty value;\r
+                                res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                                if (res != 0) goto failed;\r
+                                asdl_seq_SET(body, i, value);\r
+                        }\r
+                        Py_XDECREF(tmp);\r
+                        tmp = NULL;\r
+                } else {\r
+                        PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");\r
+                        return 1;\r
+                }\r
+                *out = ExceptHandler(type, name, body, lineno, col_offset,\r
+                                     arena);\r
+                if (*out == NULL) goto failed;\r
+                return 0;\r
+        }\r
+\r
+        tmp = PyObject_Repr(obj);\r
+        if (tmp == NULL) goto failed;\r
+        PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp));\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+int\r
+obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        asdl_seq* args;\r
+        identifier vararg;\r
+        identifier kwarg;\r
+        asdl_seq* defaults;\r
+\r
+        if (PyObject_HasAttrString(obj, "args")) {\r
+                int res;\r
+                Py_ssize_t len;\r
+                Py_ssize_t i;\r
+                tmp = PyObject_GetAttrString(obj, "args");\r
+                if (tmp == NULL) goto failed;\r
+                if (!PyList_Check(tmp)) {\r
+                        PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                        goto failed;\r
+                }\r
+                len = PyList_GET_SIZE(tmp);\r
+                args = asdl_seq_new(len, arena);\r
+                if (args == NULL) goto failed;\r
+                for (i = 0; i < len; i++) {\r
+                        expr_ty value;\r
+                        res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                        if (res != 0) goto failed;\r
+                        asdl_seq_SET(args, i, value);\r
+                }\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");\r
+                return 1;\r
+        }\r
+        if (PyObject_HasAttrString(obj, "vararg")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "vararg");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_identifier(tmp, &vararg, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                vararg = NULL;\r
+        }\r
+        if (PyObject_HasAttrString(obj, "kwarg")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "kwarg");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_identifier(tmp, &kwarg, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                kwarg = NULL;\r
+        }\r
+        if (PyObject_HasAttrString(obj, "defaults")) {\r
+                int res;\r
+                Py_ssize_t len;\r
+                Py_ssize_t i;\r
+                tmp = PyObject_GetAttrString(obj, "defaults");\r
+                if (tmp == NULL) goto failed;\r
+                if (!PyList_Check(tmp)) {\r
+                        PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);\r
+                        goto failed;\r
+                }\r
+                len = PyList_GET_SIZE(tmp);\r
+                defaults = asdl_seq_new(len, arena);\r
+                if (defaults == NULL) goto failed;\r
+                for (i = 0; i < len; i++) {\r
+                        expr_ty value;\r
+                        res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);\r
+                        if (res != 0) goto failed;\r
+                        asdl_seq_SET(defaults, i, value);\r
+                }\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");\r
+                return 1;\r
+        }\r
+        *out = arguments(args, vararg, kwarg, defaults, arena);\r
+        return 0;\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+int\r
+obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        identifier arg;\r
+        expr_ty value;\r
+\r
+        if (PyObject_HasAttrString(obj, "arg")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "arg");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_identifier(tmp, &arg, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword");\r
+                return 1;\r
+        }\r
+        if (PyObject_HasAttrString(obj, "value")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "value");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_expr(tmp, &value, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");\r
+                return 1;\r
+        }\r
+        *out = keyword(arg, value, arena);\r
+        return 0;\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+int\r
+obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)\r
+{\r
+        PyObject* tmp = NULL;\r
+        identifier name;\r
+        identifier asname;\r
+\r
+        if (PyObject_HasAttrString(obj, "name")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "name");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_identifier(tmp, &name, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");\r
+                return 1;\r
+        }\r
+        if (PyObject_HasAttrString(obj, "asname")) {\r
+                int res;\r
+                tmp = PyObject_GetAttrString(obj, "asname");\r
+                if (tmp == NULL) goto failed;\r
+                res = obj2ast_identifier(tmp, &asname, arena);\r
+                if (res != 0) goto failed;\r
+                Py_XDECREF(tmp);\r
+                tmp = NULL;\r
+        } else {\r
+                asname = NULL;\r
+        }\r
+        *out = alias(name, asname, arena);\r
+        return 0;\r
+failed:\r
+        Py_XDECREF(tmp);\r
+        return 1;\r
+}\r
+\r
+\r
+PyMODINIT_FUNC\r
+init_ast(void)\r
+{\r
+        PyObject *m, *d;\r
+        if (!init_types()) return;\r
+        m = Py_InitModule3("_ast", NULL, NULL);\r
+        if (!m) return;\r
+        d = PyModule_GetDict(m);\r
+        if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return;\r
+        if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)\r
+                return;\r
+        if (PyModule_AddStringConstant(m, "__version__", "82160") < 0)\r
+                return;\r
+        if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)\r
+            < 0) return;\r
+        if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <\r
+            0) return;\r
+        if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)\r
+            < 0) return;\r
+        if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <\r
+            0) return;\r
+        if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <\r
+            0) return;\r
+        if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <\r
+            0) return;\r
+        if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <\r
+            0) return;\r
+        if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "GeneratorExp",\r
+            (PyObject*)GeneratorExp_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <\r
+            0) return;\r
+        if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <\r
+            0) return;\r
+        if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "expr_context",\r
+            (PyObject*)expr_context_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "comprehension",\r
+            (PyObject*)comprehension_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "excepthandler",\r
+            (PyObject*)excepthandler_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "ExceptHandler",\r
+            (PyObject*)ExceptHandler_type) < 0) return;\r
+        if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <\r
+            0) return;\r
+        if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)\r
+            return;\r
+        if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;\r
+}\r
+\r
+\r
+PyObject* PyAST_mod2obj(mod_ty t)\r
+{\r
+    init_types();\r
+    return ast2obj_mod(t);\r
+}\r
+\r
+/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */\r
+mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)\r
+{\r
+    mod_ty res;\r
+    PyObject *req_type[3];\r
+    char *req_name[3];\r
+    int isinstance;\r
+\r
+    req_type[0] = (PyObject*)Module_type;\r
+    req_type[1] = (PyObject*)Expression_type;\r
+    req_type[2] = (PyObject*)Interactive_type;\r
+\r
+    req_name[0] = "Module";\r
+    req_name[1] = "Expression";\r
+    req_name[2] = "Interactive";\r
+\r
+    assert(0 <= mode && mode <= 2);\r
+\r
+    init_types();\r
+\r
+    isinstance = PyObject_IsInstance(ast, req_type[mode]);\r
+    if (isinstance == -1)\r
+        return NULL;\r
+    if (!isinstance) {\r
+        PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",\r
+                     req_name[mode], Py_TYPE(ast)->tp_name);\r
+        return NULL;\r
+    }\r
+    if (obj2ast_mod(ast, &res, arena) != 0)\r
+        return NULL;\r
+    else\r
+        return res;\r
+}\r
+\r
+int PyAST_Check(PyObject* obj)\r
+{\r
+    init_types();\r
+    return PyObject_IsInstance(obj, (PyObject*)&AST_type);\r
+}\r
+\r
+\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/_warnings.c b/AppPkg/Applications/Python/Python-2.7.10/Python/_warnings.c
new file mode 100644 (file)
index 0000000..c880e33
--- /dev/null
@@ -0,0 +1,911 @@
+#include "Python.h"\r
+#include "frameobject.h"\r
+\r
+#define MODULE_NAME "_warnings"\r
+\r
+PyDoc_STRVAR(warnings__doc__,\r
+MODULE_NAME " provides basic warning filtering support.\n"\r
+"It is a helper module to speed up interpreter start-up.");\r
+\r
+/* Both 'filters' and 'onceregistry' can be set in warnings.py;\r
+   get_warnings_attr() will reset these variables accordingly. */\r
+static PyObject *_filters;  /* List */\r
+static PyObject *_once_registry;  /* Dict */\r
+static PyObject *_default_action; /* String */\r
+\r
+\r
+static int\r
+check_matched(PyObject *obj, PyObject *arg)\r
+{\r
+    PyObject *result;\r
+    int rc;\r
+\r
+    if (obj == Py_None)\r
+        return 1;\r
+    result = PyObject_CallMethod(obj, "match", "O", arg);\r
+    if (result == NULL)\r
+        return -1;\r
+\r
+    rc = PyObject_IsTrue(result);\r
+    Py_DECREF(result);\r
+    return rc;\r
+}\r
+\r
+/*\r
+   Returns a new reference.\r
+   A NULL return value can mean false or an error.\r
+*/\r
+static PyObject *\r
+get_warnings_attr(const char *attr)\r
+{\r
+    static PyObject *warnings_str = NULL;\r
+    PyObject *all_modules;\r
+    PyObject *warnings_module;\r
+    int result;\r
+\r
+    if (warnings_str == NULL) {\r
+        warnings_str = PyString_InternFromString("warnings");\r
+        if (warnings_str == NULL)\r
+            return NULL;\r
+    }\r
+\r
+    all_modules = PyImport_GetModuleDict();\r
+    result = PyDict_Contains(all_modules, warnings_str);\r
+    if (result == -1 || result == 0)\r
+        return NULL;\r
+\r
+    warnings_module = PyDict_GetItem(all_modules, warnings_str);\r
+    if (!PyObject_HasAttrString(warnings_module, attr))\r
+            return NULL;\r
+    return PyObject_GetAttrString(warnings_module, attr);\r
+}\r
+\r
+\r
+static PyObject *\r
+get_once_registry(void)\r
+{\r
+    PyObject *registry;\r
+\r
+    registry = get_warnings_attr("onceregistry");\r
+    if (registry == NULL) {\r
+        if (PyErr_Occurred())\r
+            return NULL;\r
+        return _once_registry;\r
+    }\r
+    Py_DECREF(_once_registry);\r
+    _once_registry = registry;\r
+    return registry;\r
+}\r
+\r
+\r
+static PyObject *\r
+get_default_action(void)\r
+{\r
+    PyObject *default_action;\r
+\r
+    default_action = get_warnings_attr("defaultaction");\r
+    if (default_action == NULL) {\r
+        if (PyErr_Occurred()) {\r
+            return NULL;\r
+        }\r
+        return _default_action;\r
+    }\r
+\r
+    Py_DECREF(_default_action);\r
+    _default_action = default_action;\r
+    return default_action;\r
+}\r
+\r
+\r
+/* The item is a borrowed reference. */\r
+static const char *\r
+get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,\r
+           PyObject *module, PyObject **item)\r
+{\r
+    PyObject *action;\r
+    Py_ssize_t i;\r
+    PyObject *warnings_filters;\r
+\r
+    warnings_filters = get_warnings_attr("filters");\r
+    if (warnings_filters == NULL) {\r
+        if (PyErr_Occurred())\r
+            return NULL;\r
+    }\r
+    else {\r
+        Py_DECREF(_filters);\r
+        _filters = warnings_filters;\r
+    }\r
+\r
+    if (!PyList_Check(_filters)) {\r
+        PyErr_SetString(PyExc_ValueError,\r
+                        MODULE_NAME ".filters must be a list");\r
+        return NULL;\r
+    }\r
+\r
+    /* _filters could change while we are iterating over it. */\r
+    for (i = 0; i < PyList_GET_SIZE(_filters); i++) {\r
+        PyObject *tmp_item, *action, *msg, *cat, *mod, *ln_obj;\r
+        Py_ssize_t ln;\r
+        int is_subclass, good_msg, good_mod;\r
+\r
+        tmp_item = *item = PyList_GET_ITEM(_filters, i);\r
+        if (PyTuple_Size(tmp_item) != 5) {\r
+            PyErr_Format(PyExc_ValueError,\r
+                         MODULE_NAME ".filters item %zd isn't a 5-tuple", i);\r
+            return NULL;\r
+        }\r
+\r
+        /* Python code: action, msg, cat, mod, ln = item */\r
+        action = PyTuple_GET_ITEM(tmp_item, 0);\r
+        msg = PyTuple_GET_ITEM(tmp_item, 1);\r
+        cat = PyTuple_GET_ITEM(tmp_item, 2);\r
+        mod = PyTuple_GET_ITEM(tmp_item, 3);\r
+        ln_obj = PyTuple_GET_ITEM(tmp_item, 4);\r
+\r
+        good_msg = check_matched(msg, text);\r
+        good_mod = check_matched(mod, module);\r
+        is_subclass = PyObject_IsSubclass(category, cat);\r
+        ln = PyInt_AsSsize_t(ln_obj);\r
+        if (good_msg == -1 || good_mod == -1 || is_subclass == -1 ||\r
+            (ln == -1 && PyErr_Occurred()))\r
+            return NULL;\r
+\r
+        if (good_msg && is_subclass && good_mod && (ln == 0 || lineno == ln))\r
+            return PyString_AsString(action);\r
+    }\r
+\r
+    action = get_default_action();\r
+    if (action != NULL) {\r
+        return PyString_AsString(action);\r
+    }\r
+\r
+    PyErr_SetString(PyExc_ValueError,\r
+                    MODULE_NAME ".defaultaction not found");\r
+    return NULL;\r
+}\r
+\r
+\r
+static int\r
+already_warned(PyObject *registry, PyObject *key, int should_set)\r
+{\r
+    PyObject *already_warned;\r
+\r
+    if (key == NULL)\r
+        return -1;\r
+\r
+    already_warned = PyDict_GetItem(registry, key);\r
+    if (already_warned != NULL) {\r
+        int rc = PyObject_IsTrue(already_warned);\r
+        if (rc != 0)\r
+            return rc;\r
+    }\r
+\r
+    /* This warning wasn't found in the registry, set it. */\r
+    if (should_set)\r
+        return PyDict_SetItem(registry, key, Py_True);\r
+    return 0;\r
+}\r
+\r
+/* New reference. */\r
+static PyObject *\r
+normalize_module(PyObject *filename)\r
+{\r
+    PyObject *module;\r
+    const char *mod_str;\r
+    Py_ssize_t len;\r
+\r
+    int rc = PyObject_IsTrue(filename);\r
+    if (rc == -1)\r
+        return NULL;\r
+    else if (rc == 0)\r
+        return PyString_FromString("<unknown>");\r
+\r
+    mod_str = PyString_AsString(filename);\r
+    if (mod_str == NULL)\r
+        return NULL;\r
+    len = PyString_Size(filename);\r
+    if (len < 0)\r
+        return NULL;\r
+    if (len >= 3 &&\r
+            strncmp(mod_str + (len - 3), ".py", 3) == 0) {\r
+        module = PyString_FromStringAndSize(mod_str, len-3);\r
+    }\r
+    else {\r
+        module = filename;\r
+        Py_INCREF(module);\r
+    }\r
+    return module;\r
+}\r
+\r
+static int\r
+update_registry(PyObject *registry, PyObject *text, PyObject *category,\r
+                int add_zero)\r
+{\r
+    PyObject *altkey, *zero = NULL;\r
+    int rc;\r
+\r
+    if (add_zero) {\r
+        zero = PyInt_FromLong(0);\r
+        if (zero == NULL)\r
+            return -1;\r
+        altkey = PyTuple_Pack(3, text, category, zero);\r
+    }\r
+    else\r
+        altkey = PyTuple_Pack(2, text, category);\r
+\r
+    rc = already_warned(registry, altkey, 1);\r
+    Py_XDECREF(zero);\r
+    Py_XDECREF(altkey);\r
+    return rc;\r
+}\r
+\r
+static void\r
+show_warning(PyObject *filename, int lineno, PyObject *text, PyObject\r
+                *category, PyObject *sourceline)\r
+{\r
+    PyObject *f_stderr;\r
+    PyObject *name;\r
+    char lineno_str[128];\r
+\r
+    PyOS_snprintf(lineno_str, sizeof(lineno_str), ":%d: ", lineno);\r
+\r
+    name = PyObject_GetAttrString(category, "__name__");\r
+    if (name == NULL)  /* XXX Can an object lack a '__name__' attribute? */\r
+        return;\r
+\r
+    f_stderr = PySys_GetObject("stderr");\r
+    if (f_stderr == NULL) {\r
+        fprintf(stderr, "lost sys.stderr\n");\r
+        Py_DECREF(name);\r
+        return;\r
+    }\r
+\r
+    /* Print "filename:lineno: category: text\n" */\r
+    PyFile_WriteObject(filename, f_stderr, Py_PRINT_RAW);\r
+    PyFile_WriteString(lineno_str, f_stderr);\r
+    PyFile_WriteObject(name, f_stderr, Py_PRINT_RAW);\r
+    PyFile_WriteString(": ", f_stderr);\r
+    PyFile_WriteObject(text, f_stderr, Py_PRINT_RAW);\r
+    PyFile_WriteString("\n", f_stderr);\r
+    Py_XDECREF(name);\r
+\r
+    /* Print "  source_line\n" */\r
+    if (sourceline) {\r
+        char *source_line_str = PyString_AS_STRING(sourceline);\r
+        while (*source_line_str == ' ' || *source_line_str == '\t' ||\r
+                *source_line_str == '\014')\r
+            source_line_str++;\r
+\r
+        PyFile_WriteString(source_line_str, f_stderr);\r
+        PyFile_WriteString("\n", f_stderr);\r
+    }\r
+    else\r
+        _Py_DisplaySourceLine(f_stderr, PyString_AS_STRING(filename),\r
+                              lineno, 2);\r
+    PyErr_Clear();\r
+}\r
+\r
+static PyObject *\r
+warn_explicit(PyObject *category, PyObject *message,\r
+              PyObject *filename, int lineno,\r
+              PyObject *module, PyObject *registry, PyObject *sourceline)\r
+{\r
+    PyObject *key = NULL, *text = NULL, *result = NULL, *lineno_obj = NULL;\r
+    PyObject *item = Py_None;\r
+    const char *action;\r
+    int rc;\r
+\r
+    if (registry && !PyDict_Check(registry) && (registry != Py_None)) {\r
+        PyErr_SetString(PyExc_TypeError, "'registry' must be a dict");\r
+        return NULL;\r
+    }\r
+\r
+    /* Normalize module. */\r
+    if (module == NULL) {\r
+        module = normalize_module(filename);\r
+        if (module == NULL)\r
+            return NULL;\r
+    }\r
+    else\r
+        Py_INCREF(module);\r
+\r
+    /* Normalize message. */\r
+    Py_INCREF(message);  /* DECREF'ed in cleanup. */\r
+    rc = PyObject_IsInstance(message, PyExc_Warning);\r
+    if (rc == -1) {\r
+        goto cleanup;\r
+    }\r
+    if (rc == 1) {\r
+        text = PyObject_Str(message);\r
+        if (text == NULL)\r
+            goto cleanup;\r
+        category = (PyObject*)message->ob_type;\r
+    }\r
+    else {\r
+        text = message;\r
+        message = PyObject_CallFunction(category, "O", message);\r
+        if (message == NULL)\r
+            goto cleanup;\r
+    }\r
+\r
+    lineno_obj = PyInt_FromLong(lineno);\r
+    if (lineno_obj == NULL)\r
+        goto cleanup;\r
+\r
+    /* Create key. */\r
+    key = PyTuple_Pack(3, text, category, lineno_obj);\r
+    if (key == NULL)\r
+        goto cleanup;\r
+\r
+    if ((registry != NULL) && (registry != Py_None)) {\r
+        rc = already_warned(registry, key, 0);\r
+        if (rc == -1)\r
+            goto cleanup;\r
+        else if (rc == 1)\r
+            goto return_none;\r
+        /* Else this warning hasn't been generated before. */\r
+    }\r
+\r
+    action = get_filter(category, text, lineno, module, &item);\r
+    if (action == NULL)\r
+        goto cleanup;\r
+\r
+    if (strcmp(action, "error") == 0) {\r
+        PyErr_SetObject(category, message);\r
+        goto cleanup;\r
+    }\r
+\r
+    /* Store in the registry that we've been here, *except* when the action\r
+       is "always". */\r
+    rc = 0;\r
+    if (strcmp(action, "always") != 0) {\r
+        if (registry != NULL && registry != Py_None &&\r
+                PyDict_SetItem(registry, key, Py_True) < 0)\r
+            goto cleanup;\r
+        else if (strcmp(action, "ignore") == 0)\r
+            goto return_none;\r
+        else if (strcmp(action, "once") == 0) {\r
+            if (registry == NULL || registry == Py_None) {\r
+                registry = get_once_registry();\r
+                if (registry == NULL)\r
+                    goto cleanup;\r
+            }\r
+            /* _once_registry[(text, category)] = 1 */\r
+            rc = update_registry(registry, text, category, 0);\r
+        }\r
+        else if (strcmp(action, "module") == 0) {\r
+            /* registry[(text, category, 0)] = 1 */\r
+            if (registry != NULL && registry != Py_None)\r
+                rc = update_registry(registry, text, category, 0);\r
+        }\r
+        else if (strcmp(action, "default") != 0) {\r
+            PyObject *to_str = PyObject_Str(item);\r
+            const char *err_str = "???";\r
+\r
+            if (to_str != NULL)\r
+                err_str = PyString_AS_STRING(to_str);\r
+            PyErr_Format(PyExc_RuntimeError,\r
+                        "Unrecognized action (%s) in warnings.filters:\n %s",\r
+                        action, err_str);\r
+            Py_XDECREF(to_str);\r
+            goto cleanup;\r
+        }\r
+    }\r
+\r
+    if (rc == 1)  /* Already warned for this module. */\r
+        goto return_none;\r
+    if (rc == 0) {\r
+        PyObject *show_fxn = get_warnings_attr("showwarning");\r
+        if (show_fxn == NULL) {\r
+            if (PyErr_Occurred())\r
+                goto cleanup;\r
+            show_warning(filename, lineno, text, category, sourceline);\r
+        }\r
+        else {\r
+              PyObject *res;\r
+\r
+              if (!PyMethod_Check(show_fxn) && !PyFunction_Check(show_fxn)) {\r
+                  PyErr_SetString(PyExc_TypeError,\r
+                                  "warnings.showwarning() must be set to a "\r
+                                  "function or method");\r
+                  Py_DECREF(show_fxn);\r
+                  goto cleanup;\r
+              }\r
+\r
+              res = PyObject_CallFunctionObjArgs(show_fxn, message, category,\r
+                                                  filename, lineno_obj,\r
+                                                  NULL);\r
+              Py_DECREF(show_fxn);\r
+              Py_XDECREF(res);\r
+              if (res == NULL)\r
+                  goto cleanup;\r
+        }\r
+    }\r
+    else /* if (rc == -1) */\r
+        goto cleanup;\r
+\r
+ return_none:\r
+    result = Py_None;\r
+    Py_INCREF(result);\r
+\r
+ cleanup:\r
+    Py_XDECREF(key);\r
+    Py_XDECREF(text);\r
+    Py_XDECREF(lineno_obj);\r
+    Py_DECREF(module);\r
+    Py_XDECREF(message);\r
+    return result;  /* Py_None or NULL. */\r
+}\r
+\r
+/* filename, module, and registry are new refs, globals is borrowed */\r
+/* Returns 0 on error (no new refs), 1 on success */\r
+static int\r
+setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,\r
+              PyObject **module, PyObject **registry)\r
+{\r
+    PyObject *globals;\r
+\r
+    /* Setup globals and lineno. */\r
+    PyFrameObject *f = PyThreadState_GET()->frame;\r
+    while (--stack_level > 0 && f != NULL)\r
+        f = f->f_back;\r
+\r
+    if (f == NULL) {\r
+        globals = PyThreadState_Get()->interp->sysdict;\r
+        *lineno = 1;\r
+    }\r
+    else {\r
+        globals = f->f_globals;\r
+        *lineno = PyFrame_GetLineNumber(f);\r
+    }\r
+\r
+    *module = NULL;\r
+\r
+    /* Setup registry. */\r
+    assert(globals != NULL);\r
+    assert(PyDict_Check(globals));\r
+    *registry = PyDict_GetItemString(globals, "__warningregistry__");\r
+    if (*registry == NULL) {\r
+        int rc;\r
+\r
+        *registry = PyDict_New();\r
+        if (*registry == NULL)\r
+            return 0;\r
+\r
+         rc = PyDict_SetItemString(globals, "__warningregistry__", *registry);\r
+         if (rc < 0)\r
+            goto handle_error;\r
+    }\r
+    else\r
+        Py_INCREF(*registry);\r
+\r
+    /* Setup module. */\r
+    *module = PyDict_GetItemString(globals, "__name__");\r
+    if (*module == NULL) {\r
+        *module = PyString_FromString("<string>");\r
+        if (*module == NULL)\r
+            goto handle_error;\r
+    }\r
+    else\r
+        Py_INCREF(*module);\r
+\r
+    /* Setup filename. */\r
+    *filename = PyDict_GetItemString(globals, "__file__");\r
+    if (*filename != NULL && PyString_Check(*filename)) {\r
+            Py_ssize_t len = PyString_Size(*filename);\r
+        const char *file_str = PyString_AsString(*filename);\r
+            if (file_str == NULL || (len < 0 && PyErr_Occurred()))\r
+            goto handle_error;\r
+\r
+        /* if filename.lower().endswith((".pyc", ".pyo")): */\r
+        if (len >= 4 &&\r
+            file_str[len-4] == '.' &&\r
+            tolower(file_str[len-3]) == 'p' &&\r
+            tolower(file_str[len-2]) == 'y' &&\r
+            (tolower(file_str[len-1]) == 'c' ||\r
+                tolower(file_str[len-1]) == 'o'))\r
+        {\r
+            *filename = PyString_FromStringAndSize(file_str, len-1);\r
+            if (*filename == NULL)\r
+                goto handle_error;\r
+        }\r
+        else\r
+            Py_INCREF(*filename);\r
+    }\r
+    else {\r
+        const char *module_str = PyString_AsString(*module);\r
+        *filename = NULL;\r
+        if (module_str && strcmp(module_str, "__main__") == 0) {\r
+            PyObject *argv = PySys_GetObject("argv");\r
+            if (argv != NULL && PyList_Size(argv) > 0) {\r
+                int is_true;\r
+                *filename = PyList_GetItem(argv, 0);\r
+                Py_INCREF(*filename);\r
+                /* If sys.argv[0] is false, then use '__main__'. */\r
+                is_true = PyObject_IsTrue(*filename);\r
+                if (is_true < 0) {\r
+                    Py_DECREF(*filename);\r
+                    goto handle_error;\r
+                }\r
+                else if (!is_true) {\r
+                    Py_DECREF(*filename);\r
+                    *filename = PyString_FromString("__main__");\r
+                    if (*filename == NULL)\r
+                        goto handle_error;\r
+                }\r
+            }\r
+            else {\r
+                /* embedded interpreters don't have sys.argv, see bug #839151 */\r
+                *filename = PyString_FromString("__main__");\r
+                if (*filename == NULL)\r
+                    goto handle_error;\r
+            }\r
+        }\r
+        if (*filename == NULL) {\r
+            *filename = *module;\r
+            Py_INCREF(*filename);\r
+        }\r
+    }\r
+\r
+    return 1;\r
+\r
+ handle_error:\r
+    /* filename not XDECREF'ed here as there is no way to jump here with a\r
+       dangling reference. */\r
+    Py_XDECREF(*registry);\r
+    Py_XDECREF(*module);\r
+    return 0;\r
+}\r
+\r
+static PyObject *\r
+get_category(PyObject *message, PyObject *category)\r
+{\r
+    int rc;\r
+\r
+    /* Get category. */\r
+    rc = PyObject_IsInstance(message, PyExc_Warning);\r
+    if (rc == -1)\r
+        return NULL;\r
+\r
+    if (rc == 1)\r
+        category = (PyObject*)message->ob_type;\r
+    else if (category == NULL)\r
+        category = PyExc_UserWarning;\r
+\r
+    /* Validate category. */\r
+    rc = PyObject_IsSubclass(category, PyExc_Warning);\r
+    if (rc == -1)\r
+        return NULL;\r
+    if (rc == 0) {\r
+        PyErr_SetString(PyExc_ValueError,\r
+                        "category is not a subclass of Warning");\r
+        return NULL;\r
+    }\r
+\r
+    return category;\r
+}\r
+\r
+static PyObject *\r
+do_warn(PyObject *message, PyObject *category, Py_ssize_t stack_level)\r
+{\r
+    PyObject *filename, *module, *registry, *res;\r
+    int lineno;\r
+\r
+    if (!setup_context(stack_level, &filename, &lineno, &module, &registry))\r
+        return NULL;\r
+\r
+    res = warn_explicit(category, message, filename, lineno, module, registry,\r
+                        NULL);\r
+    Py_DECREF(filename);\r
+    Py_DECREF(registry);\r
+    Py_DECREF(module);\r
+    return res;\r
+}\r
+\r
+static PyObject *\r
+warnings_warn(PyObject *self, PyObject *args, PyObject *kwds)\r
+{\r
+    static char *kw_list[] = { "message", "category", "stacklevel", 0 };\r
+    PyObject *message, *category = NULL;\r
+    Py_ssize_t stack_level = 1;\r
+\r
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|On:warn", kw_list,\r
+                                     &message, &category, &stack_level))\r
+        return NULL;\r
+\r
+    category = get_category(message, category);\r
+    if (category == NULL)\r
+        return NULL;\r
+    return do_warn(message, category, stack_level);\r
+}\r
+\r
+static PyObject *\r
+warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)\r
+{\r
+    static char *kwd_list[] = {"message", "category", "filename", "lineno",\r
+                                "module", "registry", "module_globals", 0};\r
+    PyObject *message;\r
+    PyObject *category;\r
+    PyObject *filename;\r
+    int lineno;\r
+    PyObject *module = NULL;\r
+    PyObject *registry = NULL;\r
+    PyObject *module_globals = NULL;\r
+\r
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOi|OOO:warn_explicit",\r
+                kwd_list, &message, &category, &filename, &lineno, &module,\r
+                &registry, &module_globals))\r
+        return NULL;\r
+\r
+    if (module_globals) {\r
+        static PyObject *get_source_name = NULL;\r
+        static PyObject *splitlines_name = NULL;\r
+        PyObject *loader;\r
+        PyObject *module_name;\r
+        PyObject *source;\r
+        PyObject *source_list;\r
+        PyObject *source_line;\r
+        PyObject *returned;\r
+\r
+        if (get_source_name == NULL) {\r
+            get_source_name = PyString_InternFromString("get_source");\r
+            if (!get_source_name)\r
+                return NULL;\r
+        }\r
+        if (splitlines_name == NULL) {\r
+            splitlines_name = PyString_InternFromString("splitlines");\r
+            if (!splitlines_name)\r
+                return NULL;\r
+        }\r
+\r
+        /* Check/get the requisite pieces needed for the loader. */\r
+        loader = PyDict_GetItemString(module_globals, "__loader__");\r
+        module_name = PyDict_GetItemString(module_globals, "__name__");\r
+\r
+        if (loader == NULL || module_name == NULL)\r
+            goto standard_call;\r
+\r
+        /* Make sure the loader implements the optional get_source() method. */\r
+        if (!PyObject_HasAttrString(loader, "get_source"))\r
+                goto standard_call;\r
+        /* Call get_source() to get the source code. */\r
+        source = PyObject_CallMethodObjArgs(loader, get_source_name,\r
+                                                module_name, NULL);\r
+        if (!source)\r
+            return NULL;\r
+        else if (source == Py_None) {\r
+            Py_DECREF(Py_None);\r
+            goto standard_call;\r
+        }\r
+\r
+        /* Split the source into lines. */\r
+        source_list = PyObject_CallMethodObjArgs(source, splitlines_name,\r
+                                                    NULL);\r
+        Py_DECREF(source);\r
+        if (!source_list)\r
+            return NULL;\r
+\r
+        /* Get the source line. */\r
+        source_line = PyList_GetItem(source_list, lineno-1);\r
+        if (!source_line) {\r
+            Py_DECREF(source_list);\r
+            return NULL;\r
+        }\r
+\r
+        /* Handle the warning. */\r
+        returned = warn_explicit(category, message, filename, lineno, module,\r
+                            registry, source_line);\r
+        Py_DECREF(source_list);\r
+        return returned;\r
+    }\r
+\r
+ standard_call:\r
+    return warn_explicit(category, message, filename, lineno, module,\r
+                                registry, NULL);\r
+}\r
+\r
+\r
+/* Function to issue a warning message; may raise an exception. */\r
+int\r
+PyErr_WarnEx(PyObject *category, const char *text, Py_ssize_t stack_level)\r
+{\r
+    PyObject *res;\r
+    PyObject *message = PyString_FromString(text);\r
+    if (message == NULL)\r
+        return -1;\r
+\r
+    if (category == NULL)\r
+        category = PyExc_RuntimeWarning;\r
+\r
+    res = do_warn(message, category, stack_level);\r
+    Py_DECREF(message);\r
+    if (res == NULL)\r
+        return -1;\r
+    Py_DECREF(res);\r
+\r
+    return 0;\r
+}\r
+\r
+/* PyErr_Warn is only for backwards compatibility and will be removed.\r
+   Use PyErr_WarnEx instead. */\r
+\r
+#undef PyErr_Warn\r
+\r
+PyAPI_FUNC(int)\r
+PyErr_Warn(PyObject *category, char *text)\r
+{\r
+    return PyErr_WarnEx(category, text, 1);\r
+}\r
+\r
+/* Warning with explicit origin */\r
+int\r
+PyErr_WarnExplicit(PyObject *category, const char *text,\r
+                   const char *filename_str, int lineno,\r
+                   const char *module_str, PyObject *registry)\r
+{\r
+    PyObject *res;\r
+    PyObject *message = PyString_FromString(text);\r
+    PyObject *filename = PyString_FromString(filename_str);\r
+    PyObject *module = NULL;\r
+    int ret = -1;\r
+\r
+    if (message == NULL || filename == NULL)\r
+        goto exit;\r
+    if (module_str != NULL) {\r
+        module = PyString_FromString(module_str);\r
+            if (module == NULL)\r
+                goto exit;\r
+    }\r
+\r
+    if (category == NULL)\r
+        category = PyExc_RuntimeWarning;\r
+    res = warn_explicit(category, message, filename, lineno, module, registry,\r
+                        NULL);\r
+    if (res == NULL)\r
+        goto exit;\r
+    Py_DECREF(res);\r
+    ret = 0;\r
+\r
+ exit:\r
+    Py_XDECREF(message);\r
+    Py_XDECREF(module);\r
+    Py_XDECREF(filename);\r
+    return ret;\r
+}\r
+\r
+\r
+PyDoc_STRVAR(warn_doc,\r
+"Issue a warning, or maybe ignore it or raise an exception.");\r
+\r
+PyDoc_STRVAR(warn_explicit_doc,\r
+"Low-level inferface to warnings functionality.");\r
+\r
+static PyMethodDef warnings_functions[] = {\r
+    {"warn", (PyCFunction)warnings_warn, METH_VARARGS | METH_KEYWORDS,\r
+        warn_doc},\r
+    {"warn_explicit", (PyCFunction)warnings_warn_explicit,\r
+        METH_VARARGS | METH_KEYWORDS, warn_explicit_doc},\r
+    /* XXX(brett.cannon): add showwarning? */\r
+    /* XXX(brett.cannon): Reasonable to add formatwarning? */\r
+    {NULL, NULL}               /* sentinel */\r
+};\r
+\r
+\r
+static PyObject *\r
+create_filter(PyObject *category, const char *action)\r
+{\r
+    static PyObject *ignore_str = NULL;\r
+    static PyObject *error_str = NULL;\r
+    static PyObject *default_str = NULL;\r
+    PyObject *action_obj = NULL;\r
+    PyObject *lineno, *result;\r
+\r
+    if (!strcmp(action, "ignore")) {\r
+        if (ignore_str == NULL) {\r
+            ignore_str = PyString_InternFromString("ignore");\r
+            if (ignore_str == NULL)\r
+                return NULL;\r
+        }\r
+        action_obj = ignore_str;\r
+    }\r
+    else if (!strcmp(action, "error")) {\r
+        if (error_str == NULL) {\r
+            error_str = PyString_InternFromString("error");\r
+            if (error_str == NULL)\r
+                return NULL;\r
+        }\r
+        action_obj = error_str;\r
+    }\r
+    else if (!strcmp(action, "default")) {\r
+        if (default_str == NULL) {\r
+            default_str = PyString_InternFromString("default");\r
+            if (default_str == NULL)\r
+                return NULL;\r
+        }\r
+        action_obj = default_str;\r
+    }\r
+    else {\r
+        Py_FatalError("unknown action");\r
+    }\r
+\r
+    /* This assumes the line number is zero for now. */\r
+    lineno = PyInt_FromLong(0);\r
+    if (lineno == NULL)\r
+        return NULL;\r
+    result = PyTuple_Pack(5, action_obj, Py_None, category, Py_None, lineno);\r
+    Py_DECREF(lineno);\r
+    return result;\r
+}\r
+\r
+static PyObject *\r
+init_filters(void)\r
+{\r
+    /* Don't silence DeprecationWarning if -3 or -Q were used. */\r
+    PyObject *filters = PyList_New(Py_Py3kWarningFlag ||\r
+                                    Py_DivisionWarningFlag ? 3 : 4);\r
+    unsigned int pos = 0;  /* Post-incremented in each use. */\r
+    unsigned int x;\r
+    const char *bytes_action;\r
+\r
+    if (filters == NULL)\r
+        return NULL;\r
+\r
+    /* If guard changes, make sure to update 'filters' initialization above. */\r
+    if (!Py_Py3kWarningFlag && !Py_DivisionWarningFlag) {\r
+        PyList_SET_ITEM(filters, pos++,\r
+                        create_filter(PyExc_DeprecationWarning, "ignore"));\r
+    }\r
+    PyList_SET_ITEM(filters, pos++,\r
+                    create_filter(PyExc_PendingDeprecationWarning, "ignore"));\r
+    PyList_SET_ITEM(filters, pos++,\r
+                    create_filter(PyExc_ImportWarning, "ignore"));\r
+    if (Py_BytesWarningFlag > 1)\r
+        bytes_action = "error";\r
+    else if (Py_BytesWarningFlag)\r
+        bytes_action = "default";\r
+    else\r
+        bytes_action = "ignore";\r
+    PyList_SET_ITEM(filters, pos++, create_filter(PyExc_BytesWarning,\r
+                    bytes_action));\r
+\r
+    for (x = 0; x < pos; x += 1) {\r
+        if (PyList_GET_ITEM(filters, x) == NULL) {\r
+            Py_DECREF(filters);\r
+            return NULL;\r
+        }\r
+    }\r
+\r
+    return filters;\r
+}\r
+\r
+\r
+PyMODINIT_FUNC\r
+_PyWarnings_Init(void)\r
+{\r
+    PyObject *m;\r
+\r
+    m = Py_InitModule3(MODULE_NAME, warnings_functions, warnings__doc__);\r
+    if (m == NULL)\r
+        return;\r
+\r
+    _filters = init_filters();\r
+    if (_filters == NULL)\r
+        return;\r
+    Py_INCREF(_filters);\r
+    if (PyModule_AddObject(m, "filters", _filters) < 0)\r
+        return;\r
+\r
+    _once_registry = PyDict_New();\r
+    if (_once_registry == NULL)\r
+        return;\r
+    Py_INCREF(_once_registry);\r
+    if (PyModule_AddObject(m, "once_registry", _once_registry) < 0)\r
+        return;\r
+\r
+    _default_action = PyString_FromString("default");\r
+    if (_default_action == NULL)\r
+        return;\r
+    Py_INCREF(_default_action);\r
+    if (PyModule_AddObject(m, "default_action", _default_action) < 0)\r
+        return;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/asdl.c b/AppPkg/Applications/Python/Python-2.7.10/Python/asdl.c
new file mode 100644 (file)
index 0000000..5705758
--- /dev/null
@@ -0,0 +1,64 @@
+#include "Python.h"\r
+#include "asdl.h"\r
+\r
+asdl_seq *\r
+asdl_seq_new(int size, PyArena *arena)\r
+{\r
+    asdl_seq *seq = NULL;\r
+    size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);\r
+\r
+    /* check size is sane */\r
+    if (size < 0 || size == INT_MIN ||\r
+        (size && ((size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {\r
+        PyErr_NoMemory();\r
+        return NULL;\r
+    }\r
+\r
+    /* check if size can be added safely */\r
+    if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {\r
+        PyErr_NoMemory();\r
+        return NULL;\r
+    }\r
+\r
+    n += sizeof(asdl_seq);\r
+\r
+    seq = (asdl_seq *)PyArena_Malloc(arena, n);\r
+    if (!seq) {\r
+        PyErr_NoMemory();\r
+        return NULL;\r
+    }\r
+    memset(seq, 0, n);\r
+    seq->size = size;\r
+    return seq;\r
+}\r
+\r
+asdl_int_seq *\r
+asdl_int_seq_new(int size, PyArena *arena)\r
+{\r
+    asdl_int_seq *seq = NULL;\r
+    size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);\r
+\r
+    /* check size is sane */\r
+    if (size < 0 || size == INT_MIN ||\r
+        (size && ((size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {\r
+            PyErr_NoMemory();\r
+            return NULL;\r
+    }\r
+\r
+    /* check if size can be added safely */\r
+    if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {\r
+        PyErr_NoMemory();\r
+        return NULL;\r
+    }\r
+\r
+    n += sizeof(asdl_seq);\r
+\r
+    seq = (asdl_int_seq *)PyArena_Malloc(arena, n);\r
+    if (!seq) {\r
+        PyErr_NoMemory();\r
+        return NULL;\r
+    }\r
+    memset(seq, 0, n);\r
+    seq->size = size;\r
+    return seq;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/ast.c b/AppPkg/Applications/Python/Python-2.7.10/Python/ast.c
new file mode 100644 (file)
index 0000000..2ec1514
--- /dev/null
@@ -0,0 +1,3587 @@
+/*\r
+ * This file includes functions to transform a concrete syntax tree (CST) to\r
+ * an abstract syntax tree (AST).  The main function is PyAST_FromNode().\r
+ *\r
+ */\r
+#include "Python.h"\r
+#include "Python-ast.h"\r
+#include "grammar.h"\r
+#include "node.h"\r
+#include "pyarena.h"\r
+#include "ast.h"\r
+#include "token.h"\r
+#include "parsetok.h"\r
+#include "graminit.h"\r
+\r
+#include <assert.h>\r
+\r
+/* Data structure used internally */\r
+struct compiling {\r
+    char *c_encoding; /* source encoding */\r
+    int c_future_unicode; /* __future__ unicode literals flag */\r
+    PyArena *c_arena; /* arena for allocating memeory */\r
+    const char *c_filename; /* filename */\r
+};\r
+\r
+static asdl_seq *seq_for_testlist(struct compiling *, const node *);\r
+static expr_ty ast_for_expr(struct compiling *, const node *);\r
+static stmt_ty ast_for_stmt(struct compiling *, const node *);\r
+static asdl_seq *ast_for_suite(struct compiling *, const node *);\r
+static asdl_seq *ast_for_exprlist(struct compiling *, const node *,\r
+                                  expr_context_ty);\r
+static expr_ty ast_for_testlist(struct compiling *, const node *);\r
+static stmt_ty ast_for_classdef(struct compiling *, const node *, asdl_seq *);\r
+static expr_ty ast_for_testlist_comp(struct compiling *, const node *);\r
+\r
+/* Note different signature for ast_for_call */\r
+static expr_ty ast_for_call(struct compiling *, const node *, expr_ty);\r
+\r
+static PyObject *parsenumber(struct compiling *, const char *);\r
+static PyObject *parsestr(struct compiling *, const node *n, const char *);\r
+static PyObject *parsestrplus(struct compiling *, const node *n);\r
+\r
+#ifndef LINENO\r
+#define LINENO(n)       ((n)->n_lineno)\r
+#endif\r
+\r
+#define COMP_GENEXP 0\r
+#define COMP_SETCOMP  1\r
+\r
+static identifier\r
+new_identifier(const char* n, PyArena *arena) {\r
+    PyObject* id = PyString_InternFromString(n);\r
+    if (id != NULL)\r
+        PyArena_AddPyObject(arena, id);\r
+    return id;\r
+}\r
+\r
+#define NEW_IDENTIFIER(n) new_identifier(STR(n), c->c_arena)\r
+\r
+/* This routine provides an invalid object for the syntax error.\r
+   The outermost routine must unpack this error and create the\r
+   proper object.  We do this so that we don't have to pass\r
+   the filename to everything function.\r
+\r
+   XXX Maybe we should just pass the filename...\r
+*/\r
+\r
+static int\r
+ast_error(const node *n, const char *errstr)\r
+{\r
+    PyObject *u = Py_BuildValue("zi", errstr, LINENO(n));\r
+    if (!u)\r
+        return 0;\r
+    PyErr_SetObject(PyExc_SyntaxError, u);\r
+    Py_DECREF(u);\r
+    return 0;\r
+}\r
+\r
+static void\r
+ast_error_finish(const char *filename)\r
+{\r
+    PyObject *type, *value, *tback, *errstr, *loc, *tmp;\r
+    long lineno;\r
+\r
+    assert(PyErr_Occurred());\r
+    if (!PyErr_ExceptionMatches(PyExc_SyntaxError))\r
+        return;\r
+\r
+    PyErr_Fetch(&type, &value, &tback);\r
+    errstr = PyTuple_GetItem(value, 0);\r
+    if (!errstr)\r
+        return;\r
+    Py_INCREF(errstr);\r
+    lineno = PyInt_AsLong(PyTuple_GetItem(value, 1));\r
+    if (lineno == -1) {\r
+        Py_DECREF(errstr);\r
+        return;\r
+    }\r
+    Py_DECREF(value);\r
+\r
+    loc = PyErr_ProgramText(filename, lineno);\r
+    if (!loc) {\r
+        Py_INCREF(Py_None);\r
+        loc = Py_None;\r
+    }\r
+    tmp = Py_BuildValue("(zlOO)", filename, lineno, Py_None, loc);\r
+    Py_DECREF(loc);\r
+    if (!tmp) {\r
+        Py_DECREF(errstr);\r
+        return;\r
+    }\r
+    value = PyTuple_Pack(2, errstr, tmp);\r
+    Py_DECREF(errstr);\r
+    Py_DECREF(tmp);\r
+    if (!value)\r
+        return;\r
+    PyErr_Restore(type, value, tback);\r
+}\r
+\r
+static int\r
+ast_warn(struct compiling *c, const node *n, char *msg)\r
+{\r
+    if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, c->c_filename, LINENO(n),\r
+                           NULL, NULL) < 0) {\r
+        /* if -Werr, change it to a SyntaxError */\r
+        if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SyntaxWarning))\r
+            ast_error(n, msg);\r
+        return 0;\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+forbidden_check(struct compiling *c, const node *n, const char *x)\r
+{\r
+    if (!strcmp(x, "None"))\r
+        return ast_error(n, "cannot assign to None");\r
+    if (!strcmp(x, "__debug__"))\r
+        return ast_error(n, "cannot assign to __debug__");\r
+    if (Py_Py3kWarningFlag) {\r
+        if (!(strcmp(x, "True") && strcmp(x, "False")) &&\r
+            !ast_warn(c, n, "assignment to True or False is forbidden in 3.x"))\r
+            return 0;\r
+        if (!strcmp(x, "nonlocal") &&\r
+            !ast_warn(c, n, "nonlocal is a keyword in 3.x"))\r
+            return 0;\r
+    }\r
+    return 1;\r
+}\r
+\r
+/* num_stmts() returns number of contained statements.\r
+\r
+   Use this routine to determine how big a sequence is needed for\r
+   the statements in a parse tree.  Its raison d'etre is this bit of\r
+   grammar:\r
+\r
+   stmt: simple_stmt | compound_stmt\r
+   simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE\r
+\r
+   A simple_stmt can contain multiple small_stmt elements joined\r
+   by semicolons.  If the arg is a simple_stmt, the number of\r
+   small_stmt elements is returned.\r
+*/\r
+\r
+static int\r
+num_stmts(const node *n)\r
+{\r
+    int i, l;\r
+    node *ch;\r
+\r
+    switch (TYPE(n)) {\r
+        case single_input:\r
+            if (TYPE(CHILD(n, 0)) == NEWLINE)\r
+                return 0;\r
+            else\r
+                return num_stmts(CHILD(n, 0));\r
+        case file_input:\r
+            l = 0;\r
+            for (i = 0; i < NCH(n); i++) {\r
+                ch = CHILD(n, i);\r
+                if (TYPE(ch) == stmt)\r
+                    l += num_stmts(ch);\r
+            }\r
+            return l;\r
+        case stmt:\r
+            return num_stmts(CHILD(n, 0));\r
+        case compound_stmt:\r
+            return 1;\r
+        case simple_stmt:\r
+            return NCH(n) / 2; /* Divide by 2 to remove count of semi-colons */\r
+        case suite:\r
+            if (NCH(n) == 1)\r
+                return num_stmts(CHILD(n, 0));\r
+            else {\r
+                l = 0;\r
+                for (i = 2; i < (NCH(n) - 1); i++)\r
+                    l += num_stmts(CHILD(n, i));\r
+                return l;\r
+            }\r
+        default: {\r
+            char buf[128];\r
+\r
+            sprintf(buf, "Non-statement found: %d %d",\r
+                    TYPE(n), NCH(n));\r
+            Py_FatalError(buf);\r
+        }\r
+    }\r
+    assert(0);\r
+    return 0;\r
+}\r
+\r
+/* Transform the CST rooted at node * to the appropriate AST\r
+*/\r
+\r
+mod_ty\r
+PyAST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename,\r
+               PyArena *arena)\r
+{\r
+    int i, j, k, num;\r
+    asdl_seq *stmts = NULL;\r
+    stmt_ty s;\r
+    node *ch;\r
+    struct compiling c;\r
+\r
+    if (flags && flags->cf_flags & PyCF_SOURCE_IS_UTF8) {\r
+        c.c_encoding = "utf-8";\r
+        if (TYPE(n) == encoding_decl) {\r
+            ast_error(n, "encoding declaration in Unicode string");\r
+            goto error;\r
+        }\r
+    } else if (TYPE(n) == encoding_decl) {\r
+        c.c_encoding = STR(n);\r
+        n = CHILD(n, 0);\r
+    } else {\r
+        c.c_encoding = NULL;\r
+    }\r
+    c.c_future_unicode = flags && flags->cf_flags & CO_FUTURE_UNICODE_LITERALS;\r
+    c.c_arena = arena;\r
+    c.c_filename = filename;\r
+\r
+    k = 0;\r
+    switch (TYPE(n)) {\r
+        case file_input:\r
+            stmts = asdl_seq_new(num_stmts(n), arena);\r
+            if (!stmts)\r
+                return NULL;\r
+            for (i = 0; i < NCH(n) - 1; i++) {\r
+                ch = CHILD(n, i);\r
+                if (TYPE(ch) == NEWLINE)\r
+                    continue;\r
+                REQ(ch, stmt);\r
+                num = num_stmts(ch);\r
+                if (num == 1) {\r
+                    s = ast_for_stmt(&c, ch);\r
+                    if (!s)\r
+                        goto error;\r
+                    asdl_seq_SET(stmts, k++, s);\r
+                }\r
+                else {\r
+                    ch = CHILD(ch, 0);\r
+                    REQ(ch, simple_stmt);\r
+                    for (j = 0; j < num; j++) {\r
+                        s = ast_for_stmt(&c, CHILD(ch, j * 2));\r
+                        if (!s)\r
+                            goto error;\r
+                        asdl_seq_SET(stmts, k++, s);\r
+                    }\r
+                }\r
+            }\r
+            return Module(stmts, arena);\r
+        case eval_input: {\r
+            expr_ty testlist_ast;\r
+\r
+            /* XXX Why not comp_for here? */\r
+            testlist_ast = ast_for_testlist(&c, CHILD(n, 0));\r
+            if (!testlist_ast)\r
+                goto error;\r
+            return Expression(testlist_ast, arena);\r
+        }\r
+        case single_input:\r
+            if (TYPE(CHILD(n, 0)) == NEWLINE) {\r
+                stmts = asdl_seq_new(1, arena);\r
+                if (!stmts)\r
+                    goto error;\r
+                asdl_seq_SET(stmts, 0, Pass(n->n_lineno, n->n_col_offset,\r
+                                            arena));\r
+                if (!asdl_seq_GET(stmts, 0))\r
+                    goto error;\r
+                return Interactive(stmts, arena);\r
+            }\r
+            else {\r
+                n = CHILD(n, 0);\r
+                num = num_stmts(n);\r
+                stmts = asdl_seq_new(num, arena);\r
+                if (!stmts)\r
+                    goto error;\r
+                if (num == 1) {\r
+                    s = ast_for_stmt(&c, n);\r
+                    if (!s)\r
+                        goto error;\r
+                    asdl_seq_SET(stmts, 0, s);\r
+                }\r
+                else {\r
+                    /* Only a simple_stmt can contain multiple statements. */\r
+                    REQ(n, simple_stmt);\r
+                    for (i = 0; i < NCH(n); i += 2) {\r
+                        if (TYPE(CHILD(n, i)) == NEWLINE)\r
+                            break;\r
+                        s = ast_for_stmt(&c, CHILD(n, i));\r
+                        if (!s)\r
+                            goto error;\r
+                        asdl_seq_SET(stmts, i / 2, s);\r
+                    }\r
+                }\r
+\r
+                return Interactive(stmts, arena);\r
+            }\r
+        default:\r
+            PyErr_Format(PyExc_SystemError,\r
+                         "invalid node %d for PyAST_FromNode", TYPE(n));\r
+            goto error;\r
+    }\r
+ error:\r
+    ast_error_finish(filename);\r
+    return NULL;\r
+}\r
+\r
+/* Return the AST repr. of the operator represented as syntax (|, ^, etc.)\r
+*/\r
+\r
+static operator_ty\r
+get_operator(const node *n)\r
+{\r
+    switch (TYPE(n)) {\r
+        case VBAR:\r
+            return BitOr;\r
+        case CIRCUMFLEX:\r
+            return BitXor;\r
+        case AMPER:\r
+            return BitAnd;\r
+        case LEFTSHIFT:\r
+            return LShift;\r
+        case RIGHTSHIFT:\r
+            return RShift;\r
+        case PLUS:\r
+            return Add;\r
+        case MINUS:\r
+            return Sub;\r
+        case STAR:\r
+            return Mult;\r
+        case SLASH:\r
+            return Div;\r
+        case DOUBLESLASH:\r
+            return FloorDiv;\r
+        case PERCENT:\r
+            return Mod;\r
+        default:\r
+            return (operator_ty)0;\r
+    }\r
+}\r
+\r
+/* Set the context ctx for expr_ty e, recursively traversing e.\r
+\r
+   Only sets context for expr kinds that "can appear in assignment context"\r
+   (according to ../Parser/Python.asdl).  For other expr kinds, it sets\r
+   an appropriate syntax error and returns false.\r
+*/\r
+\r
+static int\r
+set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)\r
+{\r
+    asdl_seq *s = NULL;\r
+    /* If a particular expression type can't be used for assign / delete,\r
+       set expr_name to its name and an error message will be generated.\r
+    */\r
+    const char* expr_name = NULL;\r
+\r
+    /* The ast defines augmented store and load contexts, but the\r
+       implementation here doesn't actually use them.  The code may be\r
+       a little more complex than necessary as a result.  It also means\r
+       that expressions in an augmented assignment have a Store context.\r
+       Consider restructuring so that augmented assignment uses\r
+       set_context(), too.\r
+    */\r
+    assert(ctx != AugStore && ctx != AugLoad);\r
+\r
+    switch (e->kind) {\r
+        case Attribute_kind:\r
+            if (ctx == Store && !forbidden_check(c, n,\r
+                                PyBytes_AS_STRING(e->v.Attribute.attr)))\r
+                    return 0;\r
+            e->v.Attribute.ctx = ctx;\r
+            break;\r
+        case Subscript_kind:\r
+            e->v.Subscript.ctx = ctx;\r
+            break;\r
+        case Name_kind:\r
+            if (ctx == Store && !forbidden_check(c, n,\r
+                                PyBytes_AS_STRING(e->v.Name.id)))\r
+                    return 0;\r
+            e->v.Name.ctx = ctx;\r
+            break;\r
+        case List_kind:\r
+            e->v.List.ctx = ctx;\r
+            s = e->v.List.elts;\r
+            break;\r
+        case Tuple_kind:\r
+            if (asdl_seq_LEN(e->v.Tuple.elts))  {\r
+                e->v.Tuple.ctx = ctx;\r
+                s = e->v.Tuple.elts;\r
+            }\r
+            else {\r
+                expr_name = "()";\r
+            }\r
+            break;\r
+        case Lambda_kind:\r
+            expr_name = "lambda";\r
+            break;\r
+        case Call_kind:\r
+            expr_name = "function call";\r
+            break;\r
+        case BoolOp_kind:\r
+        case BinOp_kind:\r
+        case UnaryOp_kind:\r
+            expr_name = "operator";\r
+            break;\r
+        case GeneratorExp_kind:\r
+            expr_name = "generator expression";\r
+            break;\r
+        case Yield_kind:\r
+            expr_name = "yield expression";\r
+            break;\r
+        case ListComp_kind:\r
+            expr_name = "list comprehension";\r
+            break;\r
+        case SetComp_kind:\r
+            expr_name = "set comprehension";\r
+            break;\r
+        case DictComp_kind:\r
+            expr_name = "dict comprehension";\r
+            break;\r
+        case Dict_kind:\r
+        case Set_kind:\r
+        case Num_kind:\r
+        case Str_kind:\r
+            expr_name = "literal";\r
+            break;\r
+        case Compare_kind:\r
+            expr_name = "comparison";\r
+            break;\r
+        case Repr_kind:\r
+            expr_name = "repr";\r
+            break;\r
+        case IfExp_kind:\r
+            expr_name = "conditional expression";\r
+            break;\r
+        default:\r
+            PyErr_Format(PyExc_SystemError,\r
+                         "unexpected expression in assignment %d (line %d)",\r
+                         e->kind, e->lineno);\r
+            return 0;\r
+    }\r
+    /* Check for error string set by switch */\r
+    if (expr_name) {\r
+        char buf[300];\r
+        PyOS_snprintf(buf, sizeof(buf),\r
+                      "can't %s %s",\r
+                      ctx == Store ? "assign to" : "delete",\r
+                      expr_name);\r
+        return ast_error(n, buf);\r
+    }\r
+\r
+    /* If the LHS is a list or tuple, we need to set the assignment\r
+       context for all the contained elements.\r
+    */\r
+    if (s) {\r
+        int i;\r
+\r
+        for (i = 0; i < asdl_seq_LEN(s); i++) {\r
+            if (!set_context(c, (expr_ty)asdl_seq_GET(s, i), ctx, n))\r
+                return 0;\r
+        }\r
+    }\r
+    return 1;\r
+}\r
+\r
+static operator_ty\r
+ast_for_augassign(struct compiling *c, const node *n)\r
+{\r
+    REQ(n, augassign);\r
+    n = CHILD(n, 0);\r
+    switch (STR(n)[0]) {\r
+        case '+':\r
+            return Add;\r
+        case '-':\r
+            return Sub;\r
+        case '/':\r
+            if (STR(n)[1] == '/')\r
+                return FloorDiv;\r
+            else\r
+                return Div;\r
+        case '%':\r
+            return Mod;\r
+        case '<':\r
+            return LShift;\r
+        case '>':\r
+            return RShift;\r
+        case '&':\r
+            return BitAnd;\r
+        case '^':\r
+            return BitXor;\r
+        case '|':\r
+            return BitOr;\r
+        case '*':\r
+            if (STR(n)[1] == '*')\r
+                return Pow;\r
+            else\r
+                return Mult;\r
+        default:\r
+            PyErr_Format(PyExc_SystemError, "invalid augassign: %s", STR(n));\r
+            return (operator_ty)0;\r
+    }\r
+}\r
+\r
+static cmpop_ty\r
+ast_for_comp_op(struct compiling *c, const node *n)\r
+{\r
+    /* comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'\r
+               |'is' 'not'\r
+    */\r
+    REQ(n, comp_op);\r
+    if (NCH(n) == 1) {\r
+        n = CHILD(n, 0);\r
+        switch (TYPE(n)) {\r
+            case LESS:\r
+                return Lt;\r
+            case GREATER:\r
+                return Gt;\r
+            case EQEQUAL:                       /* == */\r
+                return Eq;\r
+            case LESSEQUAL:\r
+                return LtE;\r
+            case GREATEREQUAL:\r
+                return GtE;\r
+            case NOTEQUAL:\r
+                return NotEq;\r
+            case NAME:\r
+                if (strcmp(STR(n), "in") == 0)\r
+                    return In;\r
+                if (strcmp(STR(n), "is") == 0)\r
+                    return Is;\r
+            default:\r
+                PyErr_Format(PyExc_SystemError, "invalid comp_op: %s",\r
+                             STR(n));\r
+                return (cmpop_ty)0;\r
+        }\r
+    }\r
+    else if (NCH(n) == 2) {\r
+        /* handle "not in" and "is not" */\r
+        switch (TYPE(CHILD(n, 0))) {\r
+            case NAME:\r
+                if (strcmp(STR(CHILD(n, 1)), "in") == 0)\r
+                    return NotIn;\r
+                if (strcmp(STR(CHILD(n, 0)), "is") == 0)\r
+                    return IsNot;\r
+            default:\r
+                PyErr_Format(PyExc_SystemError, "invalid comp_op: %s %s",\r
+                             STR(CHILD(n, 0)), STR(CHILD(n, 1)));\r
+                return (cmpop_ty)0;\r
+        }\r
+    }\r
+    PyErr_Format(PyExc_SystemError, "invalid comp_op: has %d children",\r
+                 NCH(n));\r
+    return (cmpop_ty)0;\r
+}\r
+\r
+static asdl_seq *\r
+seq_for_testlist(struct compiling *c, const node *n)\r
+{\r
+    /* testlist: test (',' test)* [','] */\r
+    asdl_seq *seq;\r
+    expr_ty expression;\r
+    int i;\r
+    assert(TYPE(n) == testlist ||\r
+           TYPE(n) == listmaker ||\r
+           TYPE(n) == testlist_comp ||\r
+           TYPE(n) == testlist_safe ||\r
+           TYPE(n) == testlist1);\r
+\r
+    seq = asdl_seq_new((NCH(n) + 1) / 2, c->c_arena);\r
+    if (!seq)\r
+        return NULL;\r
+\r
+    for (i = 0; i < NCH(n); i += 2) {\r
+        assert(TYPE(CHILD(n, i)) == test || TYPE(CHILD(n, i)) == old_test);\r
+\r
+        expression = ast_for_expr(c, CHILD(n, i));\r
+        if (!expression)\r
+            return NULL;\r
+\r
+        assert(i / 2 < seq->size);\r
+        asdl_seq_SET(seq, i / 2, expression);\r
+    }\r
+    return seq;\r
+}\r
+\r
+static expr_ty\r
+compiler_complex_args(struct compiling *c, const node *n)\r
+{\r
+    int i, len = (NCH(n) + 1) / 2;\r
+    expr_ty result;\r
+    asdl_seq *args = asdl_seq_new(len, c->c_arena);\r
+    if (!args)\r
+        return NULL;\r
+\r
+    /* fpdef: NAME | '(' fplist ')'\r
+       fplist: fpdef (',' fpdef)* [',']\r
+    */\r
+    REQ(n, fplist);\r
+    for (i = 0; i < len; i++) {\r
+        PyObject *arg_id;\r
+        const node *fpdef_node = CHILD(n, 2*i);\r
+        const node *child;\r
+        expr_ty arg;\r
+set_name:\r
+        /* fpdef_node is either a NAME or an fplist */\r
+        child = CHILD(fpdef_node, 0);\r
+        if (TYPE(child) == NAME) {\r
+            if (!forbidden_check(c, n, STR(child)))\r
+                return NULL;\r
+            arg_id = NEW_IDENTIFIER(child);\r
+            if (!arg_id)\r
+                return NULL;\r
+            arg = Name(arg_id, Store, LINENO(child), child->n_col_offset,\r
+                       c->c_arena);\r
+        }\r
+        else {\r
+            assert(TYPE(fpdef_node) == fpdef);\r
+            /* fpdef_node[0] is not a name, so it must be '(', get CHILD[1] */\r
+            child = CHILD(fpdef_node, 1);\r
+            assert(TYPE(child) == fplist);\r
+            /* NCH == 1 means we have (x), we need to elide the extra parens */\r
+            if (NCH(child) == 1) {\r
+                fpdef_node = CHILD(child, 0);\r
+                assert(TYPE(fpdef_node) == fpdef);\r
+                goto set_name;\r
+            }\r
+            arg = compiler_complex_args(c, child);\r
+        }\r
+        asdl_seq_SET(args, i, arg);\r
+    }\r
+\r
+    result = Tuple(args, Store, LINENO(n), n->n_col_offset, c->c_arena);\r
+    if (!set_context(c, result, Store, n))\r
+        return NULL;\r
+    return result;\r
+}\r
+\r
+\r
+/* Create AST for argument list. */\r
+\r
+static arguments_ty\r
+ast_for_arguments(struct compiling *c, const node *n)\r
+{\r
+    /* parameters: '(' [varargslist] ')'\r
+       varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME]\r
+            | '**' NAME) | fpdef ['=' test] (',' fpdef ['=' test])* [',']\r
+    */\r
+    int i, j, k, n_args = 0, n_defaults = 0, found_default = 0;\r
+    asdl_seq *args, *defaults;\r
+    identifier vararg = NULL, kwarg = NULL;\r
+    node *ch;\r
+\r
+    if (TYPE(n) == parameters) {\r
+        if (NCH(n) == 2) /* () as argument list */\r
+            return arguments(NULL, NULL, NULL, NULL, c->c_arena);\r
+        n = CHILD(n, 1);\r
+    }\r
+    REQ(n, varargslist);\r
+\r
+    /* first count the number of normal args & defaults */\r
+    for (i = 0; i < NCH(n); i++) {\r
+        ch = CHILD(n, i);\r
+        if (TYPE(ch) == fpdef)\r
+            n_args++;\r
+        if (TYPE(ch) == EQUAL)\r
+            n_defaults++;\r
+    }\r
+    args = (n_args ? asdl_seq_new(n_args, c->c_arena) : NULL);\r
+    if (!args && n_args)\r
+        return NULL;\r
+    defaults = (n_defaults ? asdl_seq_new(n_defaults, c->c_arena) : NULL);\r
+    if (!defaults && n_defaults)\r
+        return NULL;\r
+\r
+    /* fpdef: NAME | '(' fplist ')'\r
+       fplist: fpdef (',' fpdef)* [',']\r
+    */\r
+    i = 0;\r
+    j = 0;  /* index for defaults */\r
+    k = 0;  /* index for args */\r
+    while (i < NCH(n)) {\r
+        ch = CHILD(n, i);\r
+        switch (TYPE(ch)) {\r
+            case fpdef: {\r
+                int complex_args = 0, parenthesized = 0;\r
+            handle_fpdef:\r
+                /* XXX Need to worry about checking if TYPE(CHILD(n, i+1)) is\r
+                   anything other than EQUAL or a comma? */\r
+                /* XXX Should NCH(n) check be made a separate check? */\r
+                if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) {\r
+                    expr_ty expression = ast_for_expr(c, CHILD(n, i + 2));\r
+                    if (!expression)\r
+                        return NULL;\r
+                    assert(defaults != NULL);\r
+                    asdl_seq_SET(defaults, j++, expression);\r
+                    i += 2;\r
+                    found_default = 1;\r
+                }\r
+                else if (found_default) {\r
+                    /* def f((x)=4): pass should raise an error.\r
+                       def f((x, (y))): pass will just incur the tuple unpacking warning. */\r
+                    if (parenthesized && !complex_args) {\r
+                        ast_error(n, "parenthesized arg with default");\r
+                        return NULL;\r
+                    }\r
+                    ast_error(n,\r
+                             "non-default argument follows default argument");\r
+                    return NULL;\r
+                }\r
+                if (NCH(ch) == 3) {\r
+                    ch = CHILD(ch, 1);\r
+                    /* def foo((x)): is not complex, special case. */\r
+                    if (NCH(ch) != 1) {\r
+                        /* We have complex arguments, setup for unpacking. */\r
+                        if (Py_Py3kWarningFlag && !ast_warn(c, ch,\r
+                            "tuple parameter unpacking has been removed in 3.x"))\r
+                            return NULL;\r
+                        complex_args = 1;\r
+                        asdl_seq_SET(args, k++, compiler_complex_args(c, ch));\r
+                        if (!asdl_seq_GET(args, k-1))\r
+                                return NULL;\r
+                    } else {\r
+                        /* def foo((x)): setup for checking NAME below. */\r
+                        /* Loop because there can be many parens and tuple\r
+                           unpacking mixed in. */\r
+                        parenthesized = 1;\r
+                        ch = CHILD(ch, 0);\r
+                        assert(TYPE(ch) == fpdef);\r
+                        goto handle_fpdef;\r
+                    }\r
+                }\r
+                if (TYPE(CHILD(ch, 0)) == NAME) {\r
+                    PyObject *id;\r
+                    expr_ty name;\r
+                    if (!forbidden_check(c, n, STR(CHILD(ch, 0))))\r
+                        return NULL;\r
+                    id = NEW_IDENTIFIER(CHILD(ch, 0));\r
+                    if (!id)\r
+                        return NULL;\r
+                    name = Name(id, Param, LINENO(ch), ch->n_col_offset,\r
+                                c->c_arena);\r
+                    if (!name)\r
+                        return NULL;\r
+                    asdl_seq_SET(args, k++, name);\r
+\r
+                }\r
+                i += 2; /* the name and the comma */\r
+                if (parenthesized && Py_Py3kWarningFlag &&\r
+                    !ast_warn(c, ch, "parenthesized argument names "\r
+                              "are invalid in 3.x"))\r
+                    return NULL;\r
+\r
+                break;\r
+            }\r
+            case STAR:\r
+                if (!forbidden_check(c, CHILD(n, i+1), STR(CHILD(n, i+1))))\r
+                    return NULL;\r
+                vararg = NEW_IDENTIFIER(CHILD(n, i+1));\r
+                if (!vararg)\r
+                    return NULL;\r
+                i += 3;\r
+                break;\r
+            case DOUBLESTAR:\r
+                if (!forbidden_check(c, CHILD(n, i+1), STR(CHILD(n, i+1))))\r
+                    return NULL;\r
+                kwarg = NEW_IDENTIFIER(CHILD(n, i+1));\r
+                if (!kwarg)\r
+                    return NULL;\r
+                i += 3;\r
+                break;\r
+            default:\r
+                PyErr_Format(PyExc_SystemError,\r
+                             "unexpected node in varargslist: %d @ %d",\r
+                             TYPE(ch), i);\r
+                return NULL;\r
+        }\r
+    }\r
+\r
+    return arguments(args, vararg, kwarg, defaults, c->c_arena);\r
+}\r
+\r
+static expr_ty\r
+ast_for_dotted_name(struct compiling *c, const node *n)\r
+{\r
+    expr_ty e;\r
+    identifier id;\r
+    int lineno, col_offset;\r
+    int i;\r
+\r
+    REQ(n, dotted_name);\r
+\r
+    lineno = LINENO(n);\r
+    col_offset = n->n_col_offset;\r
+\r
+    id = NEW_IDENTIFIER(CHILD(n, 0));\r
+    if (!id)\r
+        return NULL;\r
+    e = Name(id, Load, lineno, col_offset, c->c_arena);\r
+    if (!e)\r
+        return NULL;\r
+\r
+    for (i = 2; i < NCH(n); i+=2) {\r
+        id = NEW_IDENTIFIER(CHILD(n, i));\r
+        if (!id)\r
+            return NULL;\r
+        e = Attribute(e, id, Load, lineno, col_offset, c->c_arena);\r
+        if (!e)\r
+            return NULL;\r
+    }\r
+\r
+    return e;\r
+}\r
+\r
+static expr_ty\r
+ast_for_decorator(struct compiling *c, const node *n)\r
+{\r
+    /* decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE */\r
+    expr_ty d = NULL;\r
+    expr_ty name_expr;\r
+\r
+    REQ(n, decorator);\r
+    REQ(CHILD(n, 0), AT);\r
+    REQ(RCHILD(n, -1), NEWLINE);\r
+\r
+    name_expr = ast_for_dotted_name(c, CHILD(n, 1));\r
+    if (!name_expr)\r
+        return NULL;\r
+\r
+    if (NCH(n) == 3) { /* No arguments */\r
+        d = name_expr;\r
+        name_expr = NULL;\r
+    }\r
+    else if (NCH(n) == 5) { /* Call with no arguments */\r
+        d = Call(name_expr, NULL, NULL, NULL, NULL, LINENO(n),\r
+                 n->n_col_offset, c->c_arena);\r
+        if (!d)\r
+            return NULL;\r
+        name_expr = NULL;\r
+    }\r
+    else {\r
+        d = ast_for_call(c, CHILD(n, 3), name_expr);\r
+        if (!d)\r
+            return NULL;\r
+        name_expr = NULL;\r
+    }\r
+\r
+    return d;\r
+}\r
+\r
+static asdl_seq*\r
+ast_for_decorators(struct compiling *c, const node *n)\r
+{\r
+    asdl_seq* decorator_seq;\r
+    expr_ty d;\r
+    int i;\r
+\r
+    REQ(n, decorators);\r
+    decorator_seq = asdl_seq_new(NCH(n), c->c_arena);\r
+    if (!decorator_seq)\r
+        return NULL;\r
+\r
+    for (i = 0; i < NCH(n); i++) {\r
+        d = ast_for_decorator(c, CHILD(n, i));\r
+        if (!d)\r
+            return NULL;\r
+        asdl_seq_SET(decorator_seq, i, d);\r
+    }\r
+    return decorator_seq;\r
+}\r
+\r
+static stmt_ty\r
+ast_for_funcdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)\r
+{\r
+    /* funcdef: 'def' NAME parameters ':' suite */\r
+    identifier name;\r
+    arguments_ty args;\r
+    asdl_seq *body;\r
+    int name_i = 1;\r
+\r
+    REQ(n, funcdef);\r
+\r
+    name = NEW_IDENTIFIER(CHILD(n, name_i));\r
+    if (!name)\r
+        return NULL;\r
+    else if (!forbidden_check(c, CHILD(n, name_i), STR(CHILD(n, name_i))))\r
+        return NULL;\r
+    args = ast_for_arguments(c, CHILD(n, name_i + 1));\r
+    if (!args)\r
+        return NULL;\r
+    body = ast_for_suite(c, CHILD(n, name_i + 3));\r
+    if (!body)\r
+        return NULL;\r
+\r
+    return FunctionDef(name, args, body, decorator_seq, LINENO(n),\r
+                       n->n_col_offset, c->c_arena);\r
+}\r
+\r
+static stmt_ty\r
+ast_for_decorated(struct compiling *c, const node *n)\r
+{\r
+    /* decorated: decorators (classdef | funcdef) */\r
+    stmt_ty thing = NULL;\r
+    asdl_seq *decorator_seq = NULL;\r
+\r
+    REQ(n, decorated);\r
+\r
+    decorator_seq = ast_for_decorators(c, CHILD(n, 0));\r
+    if (!decorator_seq)\r
+      return NULL;\r
+\r
+    assert(TYPE(CHILD(n, 1)) == funcdef ||\r
+           TYPE(CHILD(n, 1)) == classdef);\r
+\r
+    if (TYPE(CHILD(n, 1)) == funcdef) {\r
+      thing = ast_for_funcdef(c, CHILD(n, 1), decorator_seq);\r
+    } else if (TYPE(CHILD(n, 1)) == classdef) {\r
+      thing = ast_for_classdef(c, CHILD(n, 1), decorator_seq);\r
+    }\r
+    /* we count the decorators in when talking about the class' or\r
+       function's line number */\r
+    if (thing) {\r
+        thing->lineno = LINENO(n);\r
+        thing->col_offset = n->n_col_offset;\r
+    }\r
+    return thing;\r
+}\r
+\r
+static expr_ty\r
+ast_for_lambdef(struct compiling *c, const node *n)\r
+{\r
+    /* lambdef: 'lambda' [varargslist] ':' test */\r
+    arguments_ty args;\r
+    expr_ty expression;\r
+\r
+    if (NCH(n) == 3) {\r
+        args = arguments(NULL, NULL, NULL, NULL, c->c_arena);\r
+        if (!args)\r
+            return NULL;\r
+        expression = ast_for_expr(c, CHILD(n, 2));\r
+        if (!expression)\r
+            return NULL;\r
+    }\r
+    else {\r
+        args = ast_for_arguments(c, CHILD(n, 1));\r
+        if (!args)\r
+            return NULL;\r
+        expression = ast_for_expr(c, CHILD(n, 3));\r
+        if (!expression)\r
+            return NULL;\r
+    }\r
+\r
+    return Lambda(args, expression, LINENO(n), n->n_col_offset, c->c_arena);\r
+}\r
+\r
+static expr_ty\r
+ast_for_ifexpr(struct compiling *c, const node *n)\r
+{\r
+    /* test: or_test 'if' or_test 'else' test */\r
+    expr_ty expression, body, orelse;\r
+\r
+    assert(NCH(n) == 5);\r
+    body = ast_for_expr(c, CHILD(n, 0));\r
+    if (!body)\r
+        return NULL;\r
+    expression = ast_for_expr(c, CHILD(n, 2));\r
+    if (!expression)\r
+        return NULL;\r
+    orelse = ast_for_expr(c, CHILD(n, 4));\r
+    if (!orelse)\r
+        return NULL;\r
+    return IfExp(expression, body, orelse, LINENO(n), n->n_col_offset,\r
+                 c->c_arena);\r
+}\r
+\r
+/* XXX(nnorwitz): the listcomp and genexpr code should be refactored\r
+   so there is only a single version.  Possibly for loops can also re-use\r
+   the code.\r
+*/\r
+\r
+/* Count the number of 'for' loop in a list comprehension.\r
+\r
+   Helper for ast_for_listcomp().\r
+*/\r
+\r
+static int\r
+count_list_fors(struct compiling *c, const node *n)\r
+{\r
+    int n_fors = 0;\r
+    node *ch = CHILD(n, 1);\r
+\r
+ count_list_for:\r
+    n_fors++;\r
+    REQ(ch, list_for);\r
+    if (NCH(ch) == 5)\r
+        ch = CHILD(ch, 4);\r
+    else\r
+        return n_fors;\r
+ count_list_iter:\r
+    REQ(ch, list_iter);\r
+    ch = CHILD(ch, 0);\r
+    if (TYPE(ch) == list_for)\r
+        goto count_list_for;\r
+    else if (TYPE(ch) == list_if) {\r
+        if (NCH(ch) == 3) {\r
+            ch = CHILD(ch, 2);\r
+            goto count_list_iter;\r
+        }\r
+        else\r
+            return n_fors;\r
+    }\r
+\r
+    /* Should never be reached */\r
+    PyErr_SetString(PyExc_SystemError, "logic error in count_list_fors");\r
+    return -1;\r
+}\r
+\r
+/* Count the number of 'if' statements in a list comprehension.\r
+\r
+   Helper for ast_for_listcomp().\r
+*/\r
+\r
+static int\r
+count_list_ifs(struct compiling *c, const node *n)\r
+{\r
+    int n_ifs = 0;\r
+\r
+ count_list_iter:\r
+    REQ(n, list_iter);\r
+    if (TYPE(CHILD(n, 0)) == list_for)\r
+        return n_ifs;\r
+    n = CHILD(n, 0);\r
+    REQ(n, list_if);\r
+    n_ifs++;\r
+    if (NCH(n) == 2)\r
+        return n_ifs;\r
+    n = CHILD(n, 2);\r
+    goto count_list_iter;\r
+}\r
+\r
+static expr_ty\r
+ast_for_listcomp(struct compiling *c, const node *n)\r
+{\r
+    /* listmaker: test ( list_for | (',' test)* [','] )\r
+       list_for: 'for' exprlist 'in' testlist_safe [list_iter]\r
+       list_iter: list_for | list_if\r
+       list_if: 'if' test [list_iter]\r
+       testlist_safe: test [(',' test)+ [',']]\r
+    */\r
+    expr_ty elt, first;\r
+    asdl_seq *listcomps;\r
+    int i, n_fors;\r
+    node *ch;\r
+\r
+    REQ(n, listmaker);\r
+    assert(NCH(n) > 1);\r
+\r
+    elt = ast_for_expr(c, CHILD(n, 0));\r
+    if (!elt)\r
+        return NULL;\r
+\r
+    n_fors = count_list_fors(c, n);\r
+    if (n_fors == -1)\r
+        return NULL;\r
+\r
+    listcomps = asdl_seq_new(n_fors, c->c_arena);\r
+    if (!listcomps)\r
+        return NULL;\r
+\r
+    ch = CHILD(n, 1);\r
+    for (i = 0; i < n_fors; i++) {\r
+        comprehension_ty lc;\r
+        asdl_seq *t;\r
+        expr_ty expression;\r
+        node *for_ch;\r
+\r
+        REQ(ch, list_for);\r
+\r
+        for_ch = CHILD(ch, 1);\r
+        t = ast_for_exprlist(c, for_ch, Store);\r
+        if (!t)\r
+            return NULL;\r
+        expression = ast_for_testlist(c, CHILD(ch, 3));\r
+        if (!expression)\r
+            return NULL;\r
+\r
+        /* Check the # of children rather than the length of t, since\r
+           [x for x, in ... ] has 1 element in t, but still requires a Tuple.\r
+        */\r
+        first = (expr_ty)asdl_seq_GET(t, 0);\r
+        if (NCH(for_ch) == 1)\r
+            lc = comprehension(first, expression, NULL, c->c_arena);\r
+        else\r
+            lc = comprehension(Tuple(t, Store, first->lineno, first->col_offset,\r
+                                     c->c_arena),\r
+                               expression, NULL, c->c_arena);\r
+        if (!lc)\r
+            return NULL;\r
+\r
+        if (NCH(ch) == 5) {\r
+            int j, n_ifs;\r
+            asdl_seq *ifs;\r
+            expr_ty list_for_expr;\r
+\r
+            ch = CHILD(ch, 4);\r
+            n_ifs = count_list_ifs(c, ch);\r
+            if (n_ifs == -1)\r
+                return NULL;\r
+\r
+            ifs = asdl_seq_new(n_ifs, c->c_arena);\r
+            if (!ifs)\r
+                return NULL;\r
+\r
+            for (j = 0; j < n_ifs; j++) {\r
+                REQ(ch, list_iter);\r
+                ch = CHILD(ch, 0);\r
+                REQ(ch, list_if);\r
+\r
+                list_for_expr = ast_for_expr(c, CHILD(ch, 1));\r
+                if (!list_for_expr)\r
+                    return NULL;\r
+\r
+                asdl_seq_SET(ifs, j, list_for_expr);\r
+                if (NCH(ch) == 3)\r
+                    ch = CHILD(ch, 2);\r
+            }\r
+            /* on exit, must guarantee that ch is a list_for */\r
+            if (TYPE(ch) == list_iter)\r
+                ch = CHILD(ch, 0);\r
+            lc->ifs = ifs;\r
+        }\r
+        asdl_seq_SET(listcomps, i, lc);\r
+    }\r
+\r
+    return ListComp(elt, listcomps, LINENO(n), n->n_col_offset, c->c_arena);\r
+}\r
+\r
+/*\r
+   Count the number of 'for' loops in a comprehension.\r
+\r
+   Helper for ast_for_comprehension().\r
+*/\r
+\r
+static int\r
+count_comp_fors(struct compiling *c, const node *n)\r
+{\r
+    int n_fors = 0;\r
+\r
+  count_comp_for:\r
+    n_fors++;\r
+    REQ(n, comp_for);\r
+    if (NCH(n) == 5)\r
+        n = CHILD(n, 4);\r
+    else\r
+        return n_fors;\r
+  count_comp_iter:\r
+    REQ(n, comp_iter);\r
+    n = CHILD(n, 0);\r
+    if (TYPE(n) == comp_for)\r
+        goto count_comp_for;\r
+    else if (TYPE(n) == comp_if) {\r
+        if (NCH(n) == 3) {\r
+            n = CHILD(n, 2);\r
+            goto count_comp_iter;\r
+        }\r
+        else\r
+            return n_fors;\r
+    }\r
+\r
+    /* Should never be reached */\r
+    PyErr_SetString(PyExc_SystemError,\r
+                    "logic error in count_comp_fors");\r
+    return -1;\r
+}\r
+\r
+/* Count the number of 'if' statements in a comprehension.\r
+\r
+   Helper for ast_for_comprehension().\r
+*/\r
+\r
+static int\r
+count_comp_ifs(struct compiling *c, const node *n)\r
+{\r
+    int n_ifs = 0;\r
+\r
+    while (1) {\r
+        REQ(n, comp_iter);\r
+        if (TYPE(CHILD(n, 0)) == comp_for)\r
+            return n_ifs;\r
+        n = CHILD(n, 0);\r
+        REQ(n, comp_if);\r
+        n_ifs++;\r
+        if (NCH(n) == 2)\r
+            return n_ifs;\r
+        n = CHILD(n, 2);\r
+    }\r
+}\r
+\r
+static asdl_seq *\r
+ast_for_comprehension(struct compiling *c, const node *n)\r
+{\r
+    int i, n_fors;\r
+    asdl_seq *comps;\r
+\r
+    n_fors = count_comp_fors(c, n);\r
+    if (n_fors == -1)\r
+        return NULL;\r
+\r
+    comps = asdl_seq_new(n_fors, c->c_arena);\r
+    if (!comps)\r
+        return NULL;\r
+\r
+    for (i = 0; i < n_fors; i++) {\r
+        comprehension_ty comp;\r
+        asdl_seq *t;\r
+        expr_ty expression, first;\r
+        node *for_ch;\r
+\r
+        REQ(n, comp_for);\r
+\r
+        for_ch = CHILD(n, 1);\r
+        t = ast_for_exprlist(c, for_ch, Store);\r
+        if (!t)\r
+            return NULL;\r
+        expression = ast_for_expr(c, CHILD(n, 3));\r
+        if (!expression)\r
+            return NULL;\r
+\r
+        /* Check the # of children rather than the length of t, since\r
+           (x for x, in ...) has 1 element in t, but still requires a Tuple. */\r
+        first = (expr_ty)asdl_seq_GET(t, 0);\r
+        if (NCH(for_ch) == 1)\r
+            comp = comprehension(first, expression, NULL, c->c_arena);\r
+        else\r
+            comp = comprehension(Tuple(t, Store, first->lineno, first->col_offset,\r
+                                     c->c_arena),\r
+                               expression, NULL, c->c_arena);\r
+        if (!comp)\r
+            return NULL;\r
+\r
+        if (NCH(n) == 5) {\r
+            int j, n_ifs;\r
+            asdl_seq *ifs;\r
+\r
+            n = CHILD(n, 4);\r
+            n_ifs = count_comp_ifs(c, n);\r
+            if (n_ifs == -1)\r
+                return NULL;\r
+\r
+            ifs = asdl_seq_new(n_ifs, c->c_arena);\r
+            if (!ifs)\r
+                return NULL;\r
+\r
+            for (j = 0; j < n_ifs; j++) {\r
+                REQ(n, comp_iter);\r
+                n = CHILD(n, 0);\r
+                REQ(n, comp_if);\r
+\r
+                expression = ast_for_expr(c, CHILD(n, 1));\r
+                if (!expression)\r
+                    return NULL;\r
+                asdl_seq_SET(ifs, j, expression);\r
+                if (NCH(n) == 3)\r
+                    n = CHILD(n, 2);\r
+            }\r
+            /* on exit, must guarantee that n is a comp_for */\r
+            if (TYPE(n) == comp_iter)\r
+                n = CHILD(n, 0);\r
+            comp->ifs = ifs;\r
+        }\r
+        asdl_seq_SET(comps, i, comp);\r
+    }\r
+    return comps;\r
+}\r
+\r
+static expr_ty\r
+ast_for_itercomp(struct compiling *c, const node *n, int type)\r
+{\r
+    expr_ty elt;\r
+    asdl_seq *comps;\r
+\r
+    assert(NCH(n) > 1);\r
+\r
+    elt = ast_for_expr(c, CHILD(n, 0));\r
+    if (!elt)\r
+        return NULL;\r
+\r
+    comps = ast_for_comprehension(c, CHILD(n, 1));\r
+    if (!comps)\r
+        return NULL;\r
+\r
+    if (type == COMP_GENEXP)\r
+        return GeneratorExp(elt, comps, LINENO(n), n->n_col_offset, c->c_arena);\r
+    else if (type == COMP_SETCOMP)\r
+        return SetComp(elt, comps, LINENO(n), n->n_col_offset, c->c_arena);\r
+    else\r
+        /* Should never happen */\r
+        return NULL;\r
+}\r
+\r
+static expr_ty\r
+ast_for_dictcomp(struct compiling *c, const node *n)\r
+{\r
+    expr_ty key, value;\r
+    asdl_seq *comps;\r
+\r
+    assert(NCH(n) > 3);\r
+    REQ(CHILD(n, 1), COLON);\r
+\r
+    key = ast_for_expr(c, CHILD(n, 0));\r
+    if (!key)\r
+        return NULL;\r
+\r
+    value = ast_for_expr(c, CHILD(n, 2));\r
+    if (!value)\r
+        return NULL;\r
+\r
+    comps = ast_for_comprehension(c, CHILD(n, 3));\r
+    if (!comps)\r
+        return NULL;\r
+\r
+    return DictComp(key, value, comps, LINENO(n), n->n_col_offset, c->c_arena);\r
+}\r
+\r
+static expr_ty\r
+ast_for_genexp(struct compiling *c, const node *n)\r
+{\r
+    assert(TYPE(n) == (testlist_comp) || TYPE(n) == (argument));\r
+    return ast_for_itercomp(c, n, COMP_GENEXP);\r
+}\r
+\r
+static expr_ty\r
+ast_for_setcomp(struct compiling *c, const node *n)\r
+{\r
+    assert(TYPE(n) == (dictorsetmaker));\r
+    return ast_for_itercomp(c, n, COMP_SETCOMP);\r
+}\r
+\r
+static expr_ty\r
+ast_for_atom(struct compiling *c, const node *n)\r
+{\r
+    /* atom: '(' [yield_expr|testlist_comp] ')' | '[' [listmaker] ']'\r
+       | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING+\r
+    */\r
+    node *ch = CHILD(n, 0);\r
+\r
+    switch (TYPE(ch)) {\r
+    case NAME: {\r
+        /* All names start in Load context, but may later be\r
+           changed. */\r
+        PyObject *name = NEW_IDENTIFIER(ch);\r
+        if (!name)\r
+            return NULL;\r
+        return Name(name, Load, LINENO(n), n->n_col_offset, c->c_arena);\r
+    }\r
+    case STRING: {\r
+        PyObject *str = parsestrplus(c, n);\r
+        if (!str) {\r
+#ifdef Py_USING_UNICODE\r
+            if (PyErr_ExceptionMatches(PyExc_UnicodeError)){\r
+                PyObject *type, *value, *tback, *errstr;\r
+                PyErr_Fetch(&type, &value, &tback);\r
+                errstr = PyObject_Str(value);\r
+                if (errstr) {\r
+                    char *s = "";\r
+                    char buf[128];\r
+                    s = PyString_AsString(errstr);\r
+                    PyOS_snprintf(buf, sizeof(buf), "(unicode error) %s", s);\r
+                    ast_error(n, buf);\r
+                    Py_DECREF(errstr);\r
+                } else {\r
+                    ast_error(n, "(unicode error) unknown error");\r
+                }\r
+                Py_DECREF(type);\r
+                Py_DECREF(value);\r
+                Py_XDECREF(tback);\r
+            }\r
+#endif\r
+            return NULL;\r
+        }\r
+        PyArena_AddPyObject(c->c_arena, str);\r
+        return Str(str, LINENO(n), n->n_col_offset, c->c_arena);\r
+    }\r
+    case NUMBER: {\r
+        PyObject *pynum = parsenumber(c, STR(ch));\r
+        if (!pynum)\r
+            return NULL;\r
+\r
+        PyArena_AddPyObject(c->c_arena, pynum);\r
+        return Num(pynum, LINENO(n), n->n_col_offset, c->c_arena);\r
+    }\r
+    case LPAR: /* some parenthesized expressions */\r
+        ch = CHILD(n, 1);\r
+\r
+        if (TYPE(ch) == RPAR)\r
+            return Tuple(NULL, Load, LINENO(n), n->n_col_offset, c->c_arena);\r
+\r
+        if (TYPE(ch) == yield_expr)\r
+            return ast_for_expr(c, ch);\r
+\r
+        return ast_for_testlist_comp(c, ch);\r
+    case LSQB: /* list (or list comprehension) */\r
+        ch = CHILD(n, 1);\r
+\r
+        if (TYPE(ch) == RSQB)\r
+            return List(NULL, Load, LINENO(n), n->n_col_offset, c->c_arena);\r
+\r
+        REQ(ch, listmaker);\r
+        if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) {\r
+            asdl_seq *elts = seq_for_testlist(c, ch);\r
+            if (!elts)\r
+                return NULL;\r
+\r
+            return List(elts, Load, LINENO(n), n->n_col_offset, c->c_arena);\r
+        }\r
+        else\r
+            return ast_for_listcomp(c, ch);\r
+    case LBRACE: {\r
+        /* dictorsetmaker:\r
+         *    (test ':' test (comp_for | (',' test ':' test)* [','])) |\r
+         *    (test (comp_for | (',' test)* [',']))\r
+         */\r
+        int i, size;\r
+        asdl_seq *keys, *values;\r
+\r
+        ch = CHILD(n, 1);\r
+        if (TYPE(ch) == RBRACE) {\r
+            /* it's an empty dict */\r
+            return Dict(NULL, NULL, LINENO(n), n->n_col_offset, c->c_arena);\r
+        } else if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) {\r
+            /* it's a simple set */\r
+            asdl_seq *elts;\r
+            size = (NCH(ch) + 1) / 2; /* +1 in case no trailing comma */\r
+            elts = asdl_seq_new(size, c->c_arena);\r
+            if (!elts)\r
+                return NULL;\r
+            for (i = 0; i < NCH(ch); i += 2) {\r
+                expr_ty expression;\r
+                expression = ast_for_expr(c, CHILD(ch, i));\r
+                if (!expression)\r
+                    return NULL;\r
+                asdl_seq_SET(elts, i / 2, expression);\r
+            }\r
+            return Set(elts, LINENO(n), n->n_col_offset, c->c_arena);\r
+        } else if (TYPE(CHILD(ch, 1)) == comp_for) {\r
+            /* it's a set comprehension */\r
+            return ast_for_setcomp(c, ch);\r
+        } else if (NCH(ch) > 3 && TYPE(CHILD(ch, 3)) == comp_for) {\r
+            return ast_for_dictcomp(c, ch);\r
+        } else {\r
+            /* it's a dict */\r
+            size = (NCH(ch) + 1) / 4; /* +1 in case no trailing comma */\r
+            keys = asdl_seq_new(size, c->c_arena);\r
+            if (!keys)\r
+                return NULL;\r
+\r
+            values = asdl_seq_new(size, c->c_arena);\r
+            if (!values)\r
+                return NULL;\r
+\r
+            for (i = 0; i < NCH(ch); i += 4) {\r
+                expr_ty expression;\r
+\r
+                expression = ast_for_expr(c, CHILD(ch, i));\r
+                if (!expression)\r
+                    return NULL;\r
+\r
+                asdl_seq_SET(keys, i / 4, expression);\r
+\r
+                expression = ast_for_expr(c, CHILD(ch, i + 2));\r
+                if (!expression)\r
+                    return NULL;\r
+\r
+                asdl_seq_SET(values, i / 4, expression);\r
+            }\r
+            return Dict(keys, values, LINENO(n), n->n_col_offset, c->c_arena);\r
+        }\r
+    }\r
+    case BACKQUOTE: { /* repr */\r
+        expr_ty expression;\r
+        if (Py_Py3kWarningFlag &&\r
+            !ast_warn(c, n, "backquote not supported in 3.x; use repr()"))\r
+            return NULL;\r
+        expression = ast_for_testlist(c, CHILD(n, 1));\r
+        if (!expression)\r
+            return NULL;\r
+\r
+        return Repr(expression, LINENO(n), n->n_col_offset, c->c_arena);\r
+    }\r
+    default:\r
+        PyErr_Format(PyExc_SystemError, "unhandled atom %d", TYPE(ch));\r
+        return NULL;\r
+    }\r
+}\r
+\r
+static slice_ty\r
+ast_for_slice(struct compiling *c, const node *n)\r
+{\r
+    node *ch;\r
+    expr_ty lower = NULL, upper = NULL, step = NULL;\r
+\r
+    REQ(n, subscript);\r
+\r
+    /*\r
+       subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]\r
+       sliceop: ':' [test]\r
+    */\r
+    ch = CHILD(n, 0);\r
+    if (TYPE(ch) == DOT)\r
+        return Ellipsis(c->c_arena);\r
+\r
+    if (NCH(n) == 1 && TYPE(ch) == test) {\r
+        /* 'step' variable hold no significance in terms of being used over\r
+           other vars */\r
+        step = ast_for_expr(c, ch);\r
+        if (!step)\r
+            return NULL;\r
+\r
+        return Index(step, c->c_arena);\r
+    }\r
+\r
+    if (TYPE(ch) == test) {\r
+        lower = ast_for_expr(c, ch);\r
+        if (!lower)\r
+            return NULL;\r
+    }\r
+\r
+    /* If there's an upper bound it's in the second or third position. */\r
+    if (TYPE(ch) == COLON) {\r
+        if (NCH(n) > 1) {\r
+            node *n2 = CHILD(n, 1);\r
+\r
+            if (TYPE(n2) == test) {\r
+                upper = ast_for_expr(c, n2);\r
+                if (!upper)\r
+                    return NULL;\r
+            }\r
+        }\r
+    } else if (NCH(n) > 2) {\r
+        node *n2 = CHILD(n, 2);\r
+\r
+        if (TYPE(n2) == test) {\r
+            upper = ast_for_expr(c, n2);\r
+            if (!upper)\r
+                return NULL;\r
+        }\r
+    }\r
+\r
+    ch = CHILD(n, NCH(n) - 1);\r
+    if (TYPE(ch) == sliceop) {\r
+        if (NCH(ch) == 1) {\r
+            /*\r
+              This is an extended slice (ie "x[::]") with no expression in the\r
+              step field. We set this literally to "None" in order to\r
+              disambiguate it from x[:]. (The interpreter might have to call\r
+              __getslice__ for x[:], but it must call __getitem__ for x[::].)\r
+            */\r
+            identifier none = new_identifier("None", c->c_arena);\r
+            if (!none)\r
+                return NULL;\r
+            ch = CHILD(ch, 0);\r
+            step = Name(none, Load, LINENO(ch), ch->n_col_offset, c->c_arena);\r
+            if (!step)\r
+                return NULL;\r
+        } else {\r
+            ch = CHILD(ch, 1);\r
+            if (TYPE(ch) == test) {\r
+                step = ast_for_expr(c, ch);\r
+                if (!step)\r
+                    return NULL;\r
+            }\r
+        }\r
+    }\r
+\r
+    return Slice(lower, upper, step, c->c_arena);\r
+}\r
+\r
+static expr_ty\r
+ast_for_binop(struct compiling *c, const node *n)\r
+{\r
+        /* Must account for a sequence of expressions.\r
+           How should A op B op C by represented?\r
+           BinOp(BinOp(A, op, B), op, C).\r
+        */\r
+\r
+        int i, nops;\r
+        expr_ty expr1, expr2, result;\r
+        operator_ty newoperator;\r
+\r
+        expr1 = ast_for_expr(c, CHILD(n, 0));\r
+        if (!expr1)\r
+            return NULL;\r
+\r
+        expr2 = ast_for_expr(c, CHILD(n, 2));\r
+        if (!expr2)\r
+            return NULL;\r
+\r
+        newoperator = get_operator(CHILD(n, 1));\r
+        if (!newoperator)\r
+            return NULL;\r
+\r
+        result = BinOp(expr1, newoperator, expr2, LINENO(n), n->n_col_offset,\r
+                       c->c_arena);\r
+        if (!result)\r
+            return NULL;\r
+\r
+        nops = (NCH(n) - 1) / 2;\r
+        for (i = 1; i < nops; i++) {\r
+                expr_ty tmp_result, tmp;\r
+                const node* next_oper = CHILD(n, i * 2 + 1);\r
+\r
+                newoperator = get_operator(next_oper);\r
+                if (!newoperator)\r
+                    return NULL;\r
+\r
+                tmp = ast_for_expr(c, CHILD(n, i * 2 + 2));\r
+                if (!tmp)\r
+                    return NULL;\r
+\r
+                tmp_result = BinOp(result, newoperator, tmp,\r
+                                   LINENO(next_oper), next_oper->n_col_offset,\r
+                                   c->c_arena);\r
+                if (!tmp_result)\r
+                        return NULL;\r
+                result = tmp_result;\r
+        }\r
+        return result;\r
+}\r
+\r
+static expr_ty\r
+ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr)\r
+{\r
+    /* trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME\r
+       subscriptlist: subscript (',' subscript)* [',']\r
+       subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]\r
+     */\r
+    REQ(n, trailer);\r
+    if (TYPE(CHILD(n, 0)) == LPAR) {\r
+        if (NCH(n) == 2)\r
+            return Call(left_expr, NULL, NULL, NULL, NULL, LINENO(n),\r
+                        n->n_col_offset, c->c_arena);\r
+        else\r
+            return ast_for_call(c, CHILD(n, 1), left_expr);\r
+    }\r
+    else if (TYPE(CHILD(n, 0)) == DOT ) {\r
+        PyObject *attr_id = NEW_IDENTIFIER(CHILD(n, 1));\r
+        if (!attr_id)\r
+            return NULL;\r
+        return Attribute(left_expr, attr_id, Load,\r
+                         LINENO(n), n->n_col_offset, c->c_arena);\r
+    }\r
+    else {\r
+        REQ(CHILD(n, 0), LSQB);\r
+        REQ(CHILD(n, 2), RSQB);\r
+        n = CHILD(n, 1);\r
+        if (NCH(n) == 1) {\r
+            slice_ty slc = ast_for_slice(c, CHILD(n, 0));\r
+            if (!slc)\r
+                return NULL;\r
+            return Subscript(left_expr, slc, Load, LINENO(n), n->n_col_offset,\r
+                             c->c_arena);\r
+        }\r
+        else {\r
+            /* The grammar is ambiguous here. The ambiguity is resolved\r
+               by treating the sequence as a tuple literal if there are\r
+               no slice features.\r
+            */\r
+            int j;\r
+            slice_ty slc;\r
+            expr_ty e;\r
+            bool simple = true;\r
+            asdl_seq *slices, *elts;\r
+            slices = asdl_seq_new((NCH(n) + 1) / 2, c->c_arena);\r
+            if (!slices)\r
+                return NULL;\r
+            for (j = 0; j < NCH(n); j += 2) {\r
+                slc = ast_for_slice(c, CHILD(n, j));\r
+                if (!slc)\r
+                    return NULL;\r
+                if (slc->kind != Index_kind)\r
+                    simple = false;\r
+                asdl_seq_SET(slices, j / 2, slc);\r
+            }\r
+            if (!simple) {\r
+                return Subscript(left_expr, ExtSlice(slices, c->c_arena),\r
+                                 Load, LINENO(n), n->n_col_offset, c->c_arena);\r
+            }\r
+            /* extract Index values and put them in a Tuple */\r
+            elts = asdl_seq_new(asdl_seq_LEN(slices), c->c_arena);\r
+            if (!elts)\r
+                return NULL;\r
+            for (j = 0; j < asdl_seq_LEN(slices); ++j) {\r
+                slc = (slice_ty)asdl_seq_GET(slices, j);\r
+                assert(slc->kind == Index_kind  && slc->v.Index.value);\r
+                asdl_seq_SET(elts, j, slc->v.Index.value);\r
+            }\r
+            e = Tuple(elts, Load, LINENO(n), n->n_col_offset, c->c_arena);\r
+            if (!e)\r
+                return NULL;\r
+            return Subscript(left_expr, Index(e, c->c_arena),\r
+                             Load, LINENO(n), n->n_col_offset, c->c_arena);\r
+        }\r
+    }\r
+}\r
+\r
+static expr_ty\r
+ast_for_factor(struct compiling *c, const node *n)\r
+{\r
+    node *pfactor, *ppower, *patom, *pnum;\r
+    expr_ty expression;\r
+\r
+    /* If the unary - operator is applied to a constant, don't generate\r
+       a UNARY_NEGATIVE opcode.  Just store the approriate value as a\r
+       constant.  The peephole optimizer already does something like\r
+       this but it doesn't handle the case where the constant is\r
+       (sys.maxint - 1).  In that case, we want a PyIntObject, not a\r
+       PyLongObject.\r
+    */\r
+    if (TYPE(CHILD(n, 0)) == MINUS &&\r
+        NCH(n) == 2 &&\r
+        TYPE((pfactor = CHILD(n, 1))) == factor &&\r
+        NCH(pfactor) == 1 &&\r
+        TYPE((ppower = CHILD(pfactor, 0))) == power &&\r
+        NCH(ppower) == 1 &&\r
+        TYPE((patom = CHILD(ppower, 0))) == atom &&\r
+        TYPE((pnum = CHILD(patom, 0))) == NUMBER) {\r
+        PyObject *pynum;\r
+        char *s = PyObject_MALLOC(strlen(STR(pnum)) + 2);\r
+        if (s == NULL)\r
+            return NULL;\r
+        s[0] = '-';\r
+        strcpy(s + 1, STR(pnum));\r
+        pynum = parsenumber(c, s);\r
+        PyObject_FREE(s);\r
+        if (!pynum)\r
+            return NULL;\r
+\r
+        PyArena_AddPyObject(c->c_arena, pynum);\r
+        return Num(pynum, LINENO(n), n->n_col_offset, c->c_arena);\r
+    }\r
+\r
+    expression = ast_for_expr(c, CHILD(n, 1));\r
+    if (!expression)\r
+        return NULL;\r
+\r
+    switch (TYPE(CHILD(n, 0))) {\r
+        case PLUS:\r
+            return UnaryOp(UAdd, expression, LINENO(n), n->n_col_offset,\r
+                           c->c_arena);\r
+        case MINUS:\r
+            return UnaryOp(USub, expression, LINENO(n), n->n_col_offset,\r
+                           c->c_arena);\r
+        case TILDE:\r
+            return UnaryOp(Invert, expression, LINENO(n),\r
+                           n->n_col_offset, c->c_arena);\r
+    }\r
+    PyErr_Format(PyExc_SystemError, "unhandled factor: %d",\r
+                 TYPE(CHILD(n, 0)));\r
+    return NULL;\r
+}\r
+\r
+static expr_ty\r
+ast_for_power(struct compiling *c, const node *n)\r
+{\r
+    /* power: atom trailer* ('**' factor)*\r
+     */\r
+    int i;\r
+    expr_ty e, tmp;\r
+    REQ(n, power);\r
+    e = ast_for_atom(c, CHILD(n, 0));\r
+    if (!e)\r
+        return NULL;\r
+    if (NCH(n) == 1)\r
+        return e;\r
+    for (i = 1; i < NCH(n); i++) {\r
+        node *ch = CHILD(n, i);\r
+        if (TYPE(ch) != trailer)\r
+            break;\r
+        tmp = ast_for_trailer(c, ch, e);\r
+        if (!tmp)\r
+            return NULL;\r
+        tmp->lineno = e->lineno;\r
+        tmp->col_offset = e->col_offset;\r
+        e = tmp;\r
+    }\r
+    if (TYPE(CHILD(n, NCH(n) - 1)) == factor) {\r
+        expr_ty f = ast_for_expr(c, CHILD(n, NCH(n) - 1));\r
+        if (!f)\r
+            return NULL;\r
+        tmp = BinOp(e, Pow, f, LINENO(n), n->n_col_offset, c->c_arena);\r
+        if (!tmp)\r
+            return NULL;\r
+        e = tmp;\r
+    }\r
+    return e;\r
+}\r
+\r
+/* Do not name a variable 'expr'!  Will cause a compile error.\r
+*/\r
+\r
+static expr_ty\r
+ast_for_expr(struct compiling *c, const node *n)\r
+{\r
+    /* handle the full range of simple expressions\r
+       test: or_test ['if' or_test 'else' test] | lambdef\r
+       or_test: and_test ('or' and_test)*\r
+       and_test: not_test ('and' not_test)*\r
+       not_test: 'not' not_test | comparison\r
+       comparison: expr (comp_op expr)*\r
+       expr: xor_expr ('|' xor_expr)*\r
+       xor_expr: and_expr ('^' and_expr)*\r
+       and_expr: shift_expr ('&' shift_expr)*\r
+       shift_expr: arith_expr (('<<'|'>>') arith_expr)*\r
+       arith_expr: term (('+'|'-') term)*\r
+       term: factor (('*'|'/'|'%'|'//') factor)*\r
+       factor: ('+'|'-'|'~') factor | power\r
+       power: atom trailer* ('**' factor)*\r
+\r
+       As well as modified versions that exist for backward compatibility,\r
+       to explicitly allow:\r
+       [ x for x in lambda: 0, lambda: 1 ]\r
+       (which would be ambiguous without these extra rules)\r
+\r
+       old_test: or_test | old_lambdef\r
+       old_lambdef: 'lambda' [vararglist] ':' old_test\r
+\r
+    */\r
+\r
+    asdl_seq *seq;\r
+    int i;\r
+\r
+ loop:\r
+    switch (TYPE(n)) {\r
+        case test:\r
+        case old_test:\r
+            if (TYPE(CHILD(n, 0)) == lambdef ||\r
+                TYPE(CHILD(n, 0)) == old_lambdef)\r
+                return ast_for_lambdef(c, CHILD(n, 0));\r
+            else if (NCH(n) > 1)\r
+                return ast_for_ifexpr(c, n);\r
+            /* Fallthrough */\r
+        case or_test:\r
+        case and_test:\r
+            if (NCH(n) == 1) {\r
+                n = CHILD(n, 0);\r
+                goto loop;\r
+            }\r
+            seq = asdl_seq_new((NCH(n) + 1) / 2, c->c_arena);\r
+            if (!seq)\r
+                return NULL;\r
+            for (i = 0; i < NCH(n); i += 2) {\r
+                expr_ty e = ast_for_expr(c, CHILD(n, i));\r
+                if (!e)\r
+                    return NULL;\r
+                asdl_seq_SET(seq, i / 2, e);\r
+            }\r
+            if (!strcmp(STR(CHILD(n, 1)), "and"))\r
+                return BoolOp(And, seq, LINENO(n), n->n_col_offset,\r
+                              c->c_arena);\r
+            assert(!strcmp(STR(CHILD(n, 1)), "or"));\r
+            return BoolOp(Or, seq, LINENO(n), n->n_col_offset, c->c_arena);\r
+        case not_test:\r
+            if (NCH(n) == 1) {\r
+                n = CHILD(n, 0);\r
+                goto loop;\r
+            }\r
+            else {\r
+                expr_ty expression = ast_for_expr(c, CHILD(n, 1));\r
+                if (!expression)\r
+                    return NULL;\r
+\r
+                return UnaryOp(Not, expression, LINENO(n), n->n_col_offset,\r
+                               c->c_arena);\r
+            }\r
+        case comparison:\r
+            if (NCH(n) == 1) {\r
+                n = CHILD(n, 0);\r
+                goto loop;\r
+            }\r
+            else {\r
+                expr_ty expression;\r
+                asdl_int_seq *ops;\r
+                asdl_seq *cmps;\r
+                ops = asdl_int_seq_new(NCH(n) / 2, c->c_arena);\r
+                if (!ops)\r
+                    return NULL;\r
+                cmps = asdl_seq_new(NCH(n) / 2, c->c_arena);\r
+                if (!cmps) {\r
+                    return NULL;\r
+                }\r
+                for (i = 1; i < NCH(n); i += 2) {\r
+                    cmpop_ty newoperator;\r
+\r
+                    newoperator = ast_for_comp_op(c, CHILD(n, i));\r
+                    if (!newoperator) {\r
+                        return NULL;\r
+                    }\r
+\r
+                    expression = ast_for_expr(c, CHILD(n, i + 1));\r
+                    if (!expression) {\r
+                        return NULL;\r
+                    }\r
+\r
+                    asdl_seq_SET(ops, i / 2, newoperator);\r
+                    asdl_seq_SET(cmps, i / 2, expression);\r
+                }\r
+                expression = ast_for_expr(c, CHILD(n, 0));\r
+                if (!expression) {\r
+                    return NULL;\r
+                }\r
+\r
+                return Compare(expression, ops, cmps, LINENO(n),\r
+                               n->n_col_offset, c->c_arena);\r
+            }\r
+            break;\r
+\r
+        /* The next five cases all handle BinOps.  The main body of code\r
+           is the same in each case, but the switch turned inside out to\r
+           reuse the code for each type of operator.\r
+         */\r
+        case expr:\r
+        case xor_expr:\r
+        case and_expr:\r
+        case shift_expr:\r
+        case arith_expr:\r
+        case term:\r
+            if (NCH(n) == 1) {\r
+                n = CHILD(n, 0);\r
+                goto loop;\r
+            }\r
+            return ast_for_binop(c, n);\r
+        case yield_expr: {\r
+            expr_ty exp = NULL;\r
+            if (NCH(n) == 2) {\r
+                exp = ast_for_testlist(c, CHILD(n, 1));\r
+                if (!exp)\r
+                    return NULL;\r
+            }\r
+            return Yield(exp, LINENO(n), n->n_col_offset, c->c_arena);\r
+        }\r
+        case factor:\r
+            if (NCH(n) == 1) {\r
+                n = CHILD(n, 0);\r
+                goto loop;\r
+            }\r
+            return ast_for_factor(c, n);\r
+        case power:\r
+            return ast_for_power(c, n);\r
+        default:\r
+            PyErr_Format(PyExc_SystemError, "unhandled expr: %d", TYPE(n));\r
+            return NULL;\r
+    }\r
+    /* should never get here unless if error is set */\r
+    return NULL;\r
+}\r
+\r
+static expr_ty\r
+ast_for_call(struct compiling *c, const node *n, expr_ty func)\r
+{\r
+    /*\r
+      arglist: (argument ',')* (argument [',']| '*' test [',' '**' test]\r
+               | '**' test)\r
+      argument: [test '='] test [comp_for]        # Really [keyword '='] test\r
+    */\r
+\r
+    int i, nargs, nkeywords, ngens;\r
+    asdl_seq *args;\r
+    asdl_seq *keywords;\r
+    expr_ty vararg = NULL, kwarg = NULL;\r
+\r
+    REQ(n, arglist);\r
+\r
+    nargs = 0;\r
+    nkeywords = 0;\r
+    ngens = 0;\r
+    for (i = 0; i < NCH(n); i++) {\r
+        node *ch = CHILD(n, i);\r
+        if (TYPE(ch) == argument) {\r
+            if (NCH(ch) == 1)\r
+                nargs++;\r
+            else if (TYPE(CHILD(ch, 1)) == comp_for)\r
+                ngens++;\r
+            else\r
+                nkeywords++;\r
+        }\r
+    }\r
+    if (ngens > 1 || (ngens && (nargs || nkeywords))) {\r
+        ast_error(n, "Generator expression must be parenthesized "\r
+                  "if not sole argument");\r
+        return NULL;\r
+    }\r
+\r
+    if (nargs + nkeywords + ngens > 255) {\r
+      ast_error(n, "more than 255 arguments");\r
+      return NULL;\r
+    }\r
+\r
+    args = asdl_seq_new(nargs + ngens, c->c_arena);\r
+    if (!args)\r
+        return NULL;\r
+    keywords = asdl_seq_new(nkeywords, c->c_arena);\r
+    if (!keywords)\r
+        return NULL;\r
+    nargs = 0;\r
+    nkeywords = 0;\r
+    for (i = 0; i < NCH(n); i++) {\r
+        node *ch = CHILD(n, i);\r
+        if (TYPE(ch) == argument) {\r
+            expr_ty e;\r
+            if (NCH(ch) == 1) {\r
+                if (nkeywords) {\r
+                    ast_error(CHILD(ch, 0),\r
+                              "non-keyword arg after keyword arg");\r
+                    return NULL;\r
+                }\r
+                if (vararg) {\r
+                    ast_error(CHILD(ch, 0),\r
+                              "only named arguments may follow *expression");\r
+                    return NULL;\r
+                }\r
+                e = ast_for_expr(c, CHILD(ch, 0));\r
+                if (!e)\r
+                    return NULL;\r
+                asdl_seq_SET(args, nargs++, e);\r
+            }\r
+            else if (TYPE(CHILD(ch, 1)) == comp_for) {\r
+                e = ast_for_genexp(c, ch);\r
+                if (!e)\r
+                    return NULL;\r
+                asdl_seq_SET(args, nargs++, e);\r
+            }\r
+            else {\r
+                keyword_ty kw;\r
+                identifier key;\r
+                int k;\r
+                char *tmp;\r
+\r
+                /* CHILD(ch, 0) is test, but must be an identifier? */\r
+                e = ast_for_expr(c, CHILD(ch, 0));\r
+                if (!e)\r
+                    return NULL;\r
+                /* f(lambda x: x[0] = 3) ends up getting parsed with\r
+                 * LHS test = lambda x: x[0], and RHS test = 3.\r
+                 * SF bug 132313 points out that complaining about a keyword\r
+                 * then is very confusing.\r
+                 */\r
+                if (e->kind == Lambda_kind) {\r
+                    ast_error(CHILD(ch, 0),\r
+                              "lambda cannot contain assignment");\r
+                    return NULL;\r
+                } else if (e->kind != Name_kind) {\r
+                    ast_error(CHILD(ch, 0), "keyword can't be an expression");\r
+                    return NULL;\r
+                }\r
+                key = e->v.Name.id;\r
+                if (!forbidden_check(c, CHILD(ch, 0), PyBytes_AS_STRING(key)))\r
+                    return NULL;\r
+                for (k = 0; k < nkeywords; k++) {\r
+                    tmp = PyString_AS_STRING(\r
+                        ((keyword_ty)asdl_seq_GET(keywords, k))->arg);\r
+                    if (!strcmp(tmp, PyString_AS_STRING(key))) {\r
+                        ast_error(CHILD(ch, 0), "keyword argument repeated");\r
+                        return NULL;\r
+                    }\r
+                }\r
+                e = ast_for_expr(c, CHILD(ch, 2));\r
+                if (!e)\r
+                    return NULL;\r
+                kw = keyword(key, e, c->c_arena);\r
+                if (!kw)\r
+                    return NULL;\r
+                asdl_seq_SET(keywords, nkeywords++, kw);\r
+            }\r
+        }\r
+        else if (TYPE(ch) == STAR) {\r
+            vararg = ast_for_expr(c, CHILD(n, i+1));\r
+            if (!vararg)\r
+                return NULL;\r
+            i++;\r
+        }\r
+        else if (TYPE(ch) == DOUBLESTAR) {\r
+            kwarg = ast_for_expr(c, CHILD(n, i+1));\r
+            if (!kwarg)\r
+                return NULL;\r
+            i++;\r
+        }\r
+    }\r
+\r
+    return Call(func, args, keywords, vararg, kwarg, func->lineno,\r
+                func->col_offset, c->c_arena);\r
+}\r
+\r
+static expr_ty\r
+ast_for_testlist(struct compiling *c, const node* n)\r
+{\r
+    /* testlist_comp: test (',' test)* [','] */\r
+    /* testlist: test (',' test)* [','] */\r
+    /* testlist_safe: test (',' test)+ [','] */\r
+    /* testlist1: test (',' test)* */\r
+    assert(NCH(n) > 0);\r
+    if (TYPE(n) == testlist_comp) {\r
+        if (NCH(n) > 1)\r
+            assert(TYPE(CHILD(n, 1)) != comp_for);\r
+    }\r
+    else {\r
+        assert(TYPE(n) == testlist ||\r
+               TYPE(n) == testlist_safe ||\r
+               TYPE(n) == testlist1);\r
+    }\r
+    if (NCH(n) == 1)\r
+        return ast_for_expr(c, CHILD(n, 0));\r
+    else {\r
+        asdl_seq *tmp = seq_for_testlist(c, n);\r
+        if (!tmp)\r
+            return NULL;\r
+        return Tuple(tmp, Load, LINENO(n), n->n_col_offset, c->c_arena);\r
+    }\r
+}\r
+\r
+static expr_ty\r
+ast_for_testlist_comp(struct compiling *c, const node* n)\r
+{\r
+    /* testlist_comp: test ( comp_for | (',' test)* [','] ) */\r
+    /* argument: test [ comp_for ] */\r
+    assert(TYPE(n) == testlist_comp || TYPE(n) == argument);\r
+    if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == comp_for)\r
+        return ast_for_genexp(c, n);\r
+    return ast_for_testlist(c, n);\r
+}\r
+\r
+/* like ast_for_testlist() but returns a sequence */\r
+static asdl_seq*\r
+ast_for_class_bases(struct compiling *c, const node* n)\r
+{\r
+    /* testlist: test (',' test)* [','] */\r
+    assert(NCH(n) > 0);\r
+    REQ(n, testlist);\r
+    if (NCH(n) == 1) {\r
+        expr_ty base;\r
+        asdl_seq *bases = asdl_seq_new(1, c->c_arena);\r
+        if (!bases)\r
+            return NULL;\r
+        base = ast_for_expr(c, CHILD(n, 0));\r
+        if (!base)\r
+            return NULL;\r
+        asdl_seq_SET(bases, 0, base);\r
+        return bases;\r
+    }\r
+\r
+    return seq_for_testlist(c, n);\r
+}\r
+\r
+static stmt_ty\r
+ast_for_expr_stmt(struct compiling *c, const node *n)\r
+{\r
+    REQ(n, expr_stmt);\r
+    /* expr_stmt: testlist (augassign (yield_expr|testlist)\r
+                | ('=' (yield_expr|testlist))*)\r
+       testlist: test (',' test)* [',']\r
+       augassign: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^='\r
+                | '<<=' | '>>=' | '**=' | '//='\r
+       test: ... here starts the operator precendence dance\r
+     */\r
+\r
+    if (NCH(n) == 1) {\r
+        expr_ty e = ast_for_testlist(c, CHILD(n, 0));\r
+        if (!e)\r
+            return NULL;\r
+\r
+        return Expr(e, LINENO(n), n->n_col_offset, c->c_arena);\r
+    }\r
+    else if (TYPE(CHILD(n, 1)) == augassign) {\r
+        expr_ty expr1, expr2;\r
+        operator_ty newoperator;\r
+        node *ch = CHILD(n, 0);\r
+\r
+        expr1 = ast_for_testlist(c, ch);\r
+        if (!expr1)\r
+            return NULL;\r
+        if(!set_context(c, expr1, Store, ch))\r
+            return NULL;\r
+        /* set_context checks that most expressions are not the left side.\r
+          Augmented assignments can only have a name, a subscript, or an\r
+          attribute on the left, though, so we have to explicitly check for\r
+          those. */\r
+        switch (expr1->kind) {\r
+            case Name_kind:\r
+            case Attribute_kind:\r
+            case Subscript_kind:\r
+                break;\r
+            default:\r
+                ast_error(ch, "illegal expression for augmented assignment");\r
+                return NULL;\r
+        }\r
+\r
+        ch = CHILD(n, 2);\r
+        if (TYPE(ch) == testlist)\r
+            expr2 = ast_for_testlist(c, ch);\r
+        else\r
+            expr2 = ast_for_expr(c, ch);\r
+        if (!expr2)\r
+            return NULL;\r
+\r
+        newoperator = ast_for_augassign(c, CHILD(n, 1));\r
+        if (!newoperator)\r
+            return NULL;\r
+\r
+        return AugAssign(expr1, newoperator, expr2, LINENO(n), n->n_col_offset,\r
+                         c->c_arena);\r
+    }\r
+    else {\r
+        int i;\r
+        asdl_seq *targets;\r
+        node *value;\r
+        expr_ty expression;\r
+\r
+        /* a normal assignment */\r
+        REQ(CHILD(n, 1), EQUAL);\r
+        targets = asdl_seq_new(NCH(n) / 2, c->c_arena);\r
+        if (!targets)\r
+            return NULL;\r
+        for (i = 0; i < NCH(n) - 2; i += 2) {\r
+            expr_ty e;\r
+            node *ch = CHILD(n, i);\r
+            if (TYPE(ch) == yield_expr) {\r
+                ast_error(ch, "assignment to yield expression not possible");\r
+                return NULL;\r
+            }\r
+            e = ast_for_testlist(c, ch);\r
+            if (!e)\r
+                return NULL;\r
+\r
+            /* set context to assign */\r
+            if (!set_context(c, e, Store, CHILD(n, i)))\r
+                return NULL;\r
+\r
+            asdl_seq_SET(targets, i / 2, e);\r
+        }\r
+        value = CHILD(n, NCH(n) - 1);\r
+        if (TYPE(value) == testlist)\r
+            expression = ast_for_testlist(c, value);\r
+        else\r
+            expression = ast_for_expr(c, value);\r
+        if (!expression)\r
+            return NULL;\r
+        return Assign(targets, expression, LINENO(n), n->n_col_offset,\r
+                      c->c_arena);\r
+    }\r
+}\r
+\r
+static stmt_ty\r
+ast_for_print_stmt(struct compiling *c, const node *n)\r
+{\r
+    /* print_stmt: 'print' ( [ test (',' test)* [','] ]\r
+                             | '>>' test [ (',' test)+ [','] ] )\r
+     */\r
+    expr_ty dest = NULL, expression;\r
+    asdl_seq *seq = NULL;\r
+    bool nl;\r
+    int i, j, values_count, start = 1;\r
+\r
+    REQ(n, print_stmt);\r
+    if (NCH(n) >= 2 && TYPE(CHILD(n, 1)) == RIGHTSHIFT) {\r
+        dest = ast_for_expr(c, CHILD(n, 2));\r
+        if (!dest)\r
+            return NULL;\r
+            start = 4;\r
+    }\r
+    values_count = (NCH(n) + 1 - start) / 2;\r
+    if (values_count) {\r
+        seq = asdl_seq_new(values_count, c->c_arena);\r
+        if (!seq)\r
+            return NULL;\r
+        for (i = start, j = 0; i < NCH(n); i += 2, ++j) {\r
+            expression = ast_for_expr(c, CHILD(n, i));\r
+            if (!expression)\r
+                return NULL;\r
+            asdl_seq_SET(seq, j, expression);\r
+        }\r
+    }\r
+    nl = (TYPE(CHILD(n, NCH(n) - 1)) == COMMA) ? false : true;\r
+    return Print(dest, seq, nl, LINENO(n), n->n_col_offset, c->c_arena);\r
+}\r
+\r
+static asdl_seq *\r
+ast_for_exprlist(struct compiling *c, const node *n, expr_context_ty context)\r
+{\r
+    asdl_seq *seq;\r
+    int i;\r
+    expr_ty e;\r
+\r
+    REQ(n, exprlist);\r
+\r
+    seq = asdl_seq_new((NCH(n) + 1) / 2, c->c_arena);\r
+    if (!seq)\r
+        return NULL;\r
+    for (i = 0; i < NCH(n); i += 2) {\r
+        e = ast_for_expr(c, CHILD(n, i));\r
+        if (!e)\r
+            return NULL;\r
+        asdl_seq_SET(seq, i / 2, e);\r
+        if (context && !set_context(c, e, context, CHILD(n, i)))\r
+            return NULL;\r
+    }\r
+    return seq;\r
+}\r
+\r
+static stmt_ty\r
+ast_for_del_stmt(struct compiling *c, const node *n)\r
+{\r
+    asdl_seq *expr_list;\r
+\r
+    /* del_stmt: 'del' exprlist */\r
+    REQ(n, del_stmt);\r
+\r
+    expr_list = ast_for_exprlist(c, CHILD(n, 1), Del);\r
+    if (!expr_list)\r
+        return NULL;\r
+    return Delete(expr_list, LINENO(n), n->n_col_offset, c->c_arena);\r
+}\r
+\r
+static stmt_ty\r
+ast_for_flow_stmt(struct compiling *c, const node *n)\r
+{\r
+    /*\r
+      flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt\r
+                 | yield_stmt\r
+      break_stmt: 'break'\r
+      continue_stmt: 'continue'\r
+      return_stmt: 'return' [testlist]\r
+      yield_stmt: yield_expr\r
+      yield_expr: 'yield' testlist\r
+      raise_stmt: 'raise' [test [',' test [',' test]]]\r
+    */\r
+    node *ch;\r
+\r
+    REQ(n, flow_stmt);\r
+    ch = CHILD(n, 0);\r
+    switch (TYPE(ch)) {\r
+        case break_stmt:\r
+            return Break(LINENO(n), n->n_col_offset, c->c_arena);\r
+        case continue_stmt:\r
+            return Continue(LINENO(n), n->n_col_offset, c->c_arena);\r
+        case yield_stmt: { /* will reduce to yield_expr */\r
+            expr_ty exp = ast_for_expr(c, CHILD(ch, 0));\r
+            if (!exp)\r
+                return NULL;\r
+            return Expr(exp, LINENO(n), n->n_col_offset, c->c_arena);\r
+        }\r
+        case return_stmt:\r
+            if (NCH(ch) == 1)\r
+                return Return(NULL, LINENO(n), n->n_col_offset, c->c_arena);\r
+            else {\r
+                expr_ty expression = ast_for_testlist(c, CHILD(ch, 1));\r
+                if (!expression)\r
+                    return NULL;\r
+                return Return(expression, LINENO(n), n->n_col_offset,\r
+                              c->c_arena);\r
+            }\r
+        case raise_stmt:\r
+            if (NCH(ch) == 1)\r
+                return Raise(NULL, NULL, NULL, LINENO(n), n->n_col_offset,\r
+                             c->c_arena);\r
+            else if (NCH(ch) == 2) {\r
+                expr_ty expression = ast_for_expr(c, CHILD(ch, 1));\r
+                if (!expression)\r
+                    return NULL;\r
+                return Raise(expression, NULL, NULL, LINENO(n),\r
+                             n->n_col_offset, c->c_arena);\r
+            }\r
+            else if (NCH(ch) == 4) {\r
+                expr_ty expr1, expr2;\r
+\r
+                expr1 = ast_for_expr(c, CHILD(ch, 1));\r
+                if (!expr1)\r
+                    return NULL;\r
+                expr2 = ast_for_expr(c, CHILD(ch, 3));\r
+                if (!expr2)\r
+                    return NULL;\r
+\r
+                return Raise(expr1, expr2, NULL, LINENO(n), n->n_col_offset,\r
+                             c->c_arena);\r
+            }\r
+            else if (NCH(ch) == 6) {\r
+                expr_ty expr1, expr2, expr3;\r
+\r
+                expr1 = ast_for_expr(c, CHILD(ch, 1));\r
+                if (!expr1)\r
+                    return NULL;\r
+                expr2 = ast_for_expr(c, CHILD(ch, 3));\r
+                if (!expr2)\r
+                    return NULL;\r
+                expr3 = ast_for_expr(c, CHILD(ch, 5));\r
+                if (!expr3)\r
+                    return NULL;\r
+\r
+                return Raise(expr1, expr2, expr3, LINENO(n), n->n_col_offset,\r
+                             c->c_arena);\r
+            }\r
+        default:\r
+            PyErr_Format(PyExc_SystemError,\r
+                         "unexpected flow_stmt: %d", TYPE(ch));\r
+            return NULL;\r
+    }\r
+\r
+    PyErr_SetString(PyExc_SystemError, "unhandled flow statement");\r
+    return NULL;\r
+}\r
+\r
+static alias_ty\r
+alias_for_import_name(struct compiling *c, const node *n, int store)\r
+{\r
+    /*\r
+      import_as_name: NAME ['as' NAME]\r
+      dotted_as_name: dotted_name ['as' NAME]\r
+      dotted_name: NAME ('.' NAME)*\r
+    */\r
+    PyObject *str, *name;\r
+\r
+ loop:\r
+    switch (TYPE(n)) {\r
+         case import_as_name: {\r
+            node *name_node = CHILD(n, 0);\r
+            str = NULL;\r
+            if (NCH(n) == 3) {\r
+                node *str_node = CHILD(n, 2);\r
+                if (store && !forbidden_check(c, str_node, STR(str_node)))\r
+                    return NULL;\r
+                str = NEW_IDENTIFIER(str_node);\r
+                if (!str)\r
+                    return NULL;\r
+            }\r
+            else {\r
+                if (!forbidden_check(c, name_node, STR(name_node)))\r
+                    return NULL;\r
+            }\r
+            name = NEW_IDENTIFIER(name_node);\r
+            if (!name)\r
+                return NULL;\r
+            return alias(name, str, c->c_arena);\r
+        }\r
+        case dotted_as_name:\r
+            if (NCH(n) == 1) {\r
+                n = CHILD(n, 0);\r
+                goto loop;\r
+            }\r
+            else {\r
+                node *asname_node = CHILD(n, 2);\r
+                alias_ty a = alias_for_import_name(c, CHILD(n, 0), 0);\r
+                if (!a)\r
+                    return NULL;\r
+                assert(!a->asname);\r
+                if (!forbidden_check(c, asname_node, STR(asname_node)))\r
+                    return NULL;\r
+                a->asname = NEW_IDENTIFIER(asname_node);\r
+                if (!a->asname)\r
+                    return NULL;\r
+                return a;\r
+            }\r
+            break;\r
+        case dotted_name:\r
+            if (NCH(n) == 1) {\r
+                node *name_node = CHILD(n, 0);\r
+                if (store && !forbidden_check(c, name_node, STR(name_node)))\r
+                    return NULL;\r
+                name = NEW_IDENTIFIER(name_node);\r
+                if (!name)\r
+                    return NULL;\r
+                return alias(name, NULL, c->c_arena);\r
+            }\r
+            else {\r
+                /* Create a string of the form "a.b.c" */\r
+                int i;\r
+                size_t len;\r
+                char *s;\r
+\r
+                len = 0;\r
+                for (i = 0; i < NCH(n); i += 2)\r
+                    /* length of string plus one for the dot */\r
+                    len += strlen(STR(CHILD(n, i))) + 1;\r
+                len--; /* the last name doesn't have a dot */\r
+                str = PyString_FromStringAndSize(NULL, len);\r
+                if (!str)\r
+                    return NULL;\r
+                s = PyString_AS_STRING(str);\r
+                if (!s)\r
+                    return NULL;\r
+                for (i = 0; i < NCH(n); i += 2) {\r
+                    char *sch = STR(CHILD(n, i));\r
+                    strcpy(s, STR(CHILD(n, i)));\r
+                    s += strlen(sch);\r
+                    *s++ = '.';\r
+                }\r
+                --s;\r
+                *s = '\0';\r
+                PyString_InternInPlace(&str);\r
+                PyArena_AddPyObject(c->c_arena, str);\r
+                return alias(str, NULL, c->c_arena);\r
+            }\r
+            break;\r
+        case STAR:\r
+            str = PyString_InternFromString("*");\r
+            PyArena_AddPyObject(c->c_arena, str);\r
+            return alias(str, NULL, c->c_arena);\r
+        default:\r
+            PyErr_Format(PyExc_SystemError,\r
+                         "unexpected import name: %d", TYPE(n));\r
+            return NULL;\r
+    }\r
+\r
+    PyErr_SetString(PyExc_SystemError, "unhandled import name condition");\r
+    return NULL;\r
+}\r
+\r
+static stmt_ty\r
+ast_for_import_stmt(struct compiling *c, const node *n)\r
+{\r
+    /*\r
+      import_stmt: import_name | import_from\r
+      import_name: 'import' dotted_as_names\r
+      import_from: 'from' ('.'* dotted_name | '.') 'import'\r
+                          ('*' | '(' import_as_names ')' | import_as_names)\r
+    */\r
+    int lineno;\r
+    int col_offset;\r
+    int i;\r
+    asdl_seq *aliases;\r
+\r
+    REQ(n, import_stmt);\r
+    lineno = LINENO(n);\r
+    col_offset = n->n_col_offset;\r
+    n = CHILD(n, 0);\r
+    if (TYPE(n) == import_name) {\r
+        n = CHILD(n, 1);\r
+        REQ(n, dotted_as_names);\r
+        aliases = asdl_seq_new((NCH(n) + 1) / 2, c->c_arena);\r
+        if (!aliases)\r
+            return NULL;\r
+        for (i = 0; i < NCH(n); i += 2) {\r
+            alias_ty import_alias = alias_for_import_name(c, CHILD(n, i), 1);\r
+            if (!import_alias)\r
+                return NULL;\r
+            asdl_seq_SET(aliases, i / 2, import_alias);\r
+        }\r
+        return Import(aliases, lineno, col_offset, c->c_arena);\r
+    }\r
+    else if (TYPE(n) == import_from) {\r
+        int n_children;\r
+        int idx, ndots = 0;\r
+        alias_ty mod = NULL;\r
+        identifier modname = NULL;\r
+\r
+       /* Count the number of dots (for relative imports) and check for the\r
+          optional module name */\r
+        for (idx = 1; idx < NCH(n); idx++) {\r
+            if (TYPE(CHILD(n, idx)) == dotted_name) {\r
+                mod = alias_for_import_name(c, CHILD(n, idx), 0);\r
+                if (!mod)\r
+                    return NULL;\r
+                idx++;\r
+                break;\r
+            } else if (TYPE(CHILD(n, idx)) != DOT) {\r
+                break;\r
+            }\r
+            ndots++;\r
+        }\r
+        idx++; /* skip over the 'import' keyword */\r
+        switch (TYPE(CHILD(n, idx))) {\r
+        case STAR:\r
+            /* from ... import * */\r
+            n = CHILD(n, idx);\r
+            n_children = 1;\r
+            break;\r
+        case LPAR:\r
+            /* from ... import (x, y, z) */\r
+            n = CHILD(n, idx + 1);\r
+            n_children = NCH(n);\r
+            break;\r
+        case import_as_names:\r
+            /* from ... import x, y, z */\r
+            n = CHILD(n, idx);\r
+            n_children = NCH(n);\r
+            if (n_children % 2 == 0) {\r
+                ast_error(n, "trailing comma not allowed without"\r
+                             " surrounding parentheses");\r
+                return NULL;\r
+            }\r
+            break;\r
+        default:\r
+            ast_error(n, "Unexpected node-type in from-import");\r
+            return NULL;\r
+        }\r
+\r
+        aliases = asdl_seq_new((n_children + 1) / 2, c->c_arena);\r
+        if (!aliases)\r
+            return NULL;\r
+\r
+        /* handle "from ... import *" special b/c there's no children */\r
+        if (TYPE(n) == STAR) {\r
+            alias_ty import_alias = alias_for_import_name(c, n, 1);\r
+            if (!import_alias)\r
+                return NULL;\r
+                asdl_seq_SET(aliases, 0, import_alias);\r
+        }\r
+        else {\r
+            for (i = 0; i < NCH(n); i += 2) {\r
+                alias_ty import_alias = alias_for_import_name(c, CHILD(n, i), 1);\r
+                if (!import_alias)\r
+                    return NULL;\r
+                    asdl_seq_SET(aliases, i / 2, import_alias);\r
+            }\r
+        }\r
+        if (mod != NULL)\r
+            modname = mod->name;\r
+        return ImportFrom(modname, aliases, ndots, lineno, col_offset,\r
+                          c->c_arena);\r
+    }\r
+    PyErr_Format(PyExc_SystemError,\r
+                 "unknown import statement: starts with command '%s'",\r
+                 STR(CHILD(n, 0)));\r
+    return NULL;\r
+}\r
+\r
+static stmt_ty\r
+ast_for_global_stmt(struct compiling *c, const node *n)\r
+{\r
+    /* global_stmt: 'global' NAME (',' NAME)* */\r
+    identifier name;\r
+    asdl_seq *s;\r
+    int i;\r
+\r
+    REQ(n, global_stmt);\r
+    s = asdl_seq_new(NCH(n) / 2, c->c_arena);\r
+    if (!s)\r
+        return NULL;\r
+    for (i = 1; i < NCH(n); i += 2) {\r
+        name = NEW_IDENTIFIER(CHILD(n, i));\r
+        if (!name)\r
+            return NULL;\r
+        asdl_seq_SET(s, i / 2, name);\r
+    }\r
+    return Global(s, LINENO(n), n->n_col_offset, c->c_arena);\r
+}\r
+\r
+static stmt_ty\r
+ast_for_exec_stmt(struct compiling *c, const node *n)\r
+{\r
+    expr_ty expr1, globals = NULL, locals = NULL;\r
+    int n_children = NCH(n);\r
+    if (n_children != 2 && n_children != 4 && n_children != 6) {\r
+        PyErr_Format(PyExc_SystemError,\r
+                     "poorly formed 'exec' statement: %d parts to statement",\r
+                     n_children);\r
+        return NULL;\r
+    }\r
+\r
+    /* exec_stmt: 'exec' expr ['in' test [',' test]] */\r
+    REQ(n, exec_stmt);\r
+    expr1 = ast_for_expr(c, CHILD(n, 1));\r
+    if (!expr1)\r
+        return NULL;\r
+\r
+    if (expr1->kind == Tuple_kind && n_children < 4 &&\r
+        (asdl_seq_LEN(expr1->v.Tuple.elts) == 2 ||\r
+         asdl_seq_LEN(expr1->v.Tuple.elts) == 3)) {\r
+        /* Backwards compatibility: passing exec args as a tuple */\r
+        globals = asdl_seq_GET(expr1->v.Tuple.elts, 1);\r
+        if (asdl_seq_LEN(expr1->v.Tuple.elts) == 3) {\r
+            locals = asdl_seq_GET(expr1->v.Tuple.elts, 2);\r
+        }\r
+        expr1 = asdl_seq_GET(expr1->v.Tuple.elts, 0);\r
+    }\r
+\r
+    if (n_children >= 4) {\r
+        globals = ast_for_expr(c, CHILD(n, 3));\r
+        if (!globals)\r
+            return NULL;\r
+    }\r
+    if (n_children == 6) {\r
+        locals = ast_for_expr(c, CHILD(n, 5));\r
+        if (!locals)\r
+            return NULL;\r
+    }\r
+\r
+    return Exec(expr1, globals, locals, LINENO(n), n->n_col_offset,\r
+                c->c_arena);\r
+}\r
+\r
+static stmt_ty\r
+ast_for_assert_stmt(struct compiling *c, const node *n)\r
+{\r
+    /* assert_stmt: 'assert' test [',' test] */\r
+    REQ(n, assert_stmt);\r
+    if (NCH(n) == 2) {\r
+        expr_ty expression = ast_for_expr(c, CHILD(n, 1));\r
+        if (!expression)\r
+            return NULL;\r
+        return Assert(expression, NULL, LINENO(n), n->n_col_offset,\r
+                      c->c_arena);\r
+    }\r
+    else if (NCH(n) == 4) {\r
+        expr_ty expr1, expr2;\r
+\r
+        expr1 = ast_for_expr(c, CHILD(n, 1));\r
+        if (!expr1)\r
+            return NULL;\r
+        expr2 = ast_for_expr(c, CHILD(n, 3));\r
+        if (!expr2)\r
+            return NULL;\r
+\r
+        return Assert(expr1, expr2, LINENO(n), n->n_col_offset, c->c_arena);\r
+    }\r
+    PyErr_Format(PyExc_SystemError,\r
+                 "improper number of parts to 'assert' statement: %d",\r
+                 NCH(n));\r
+    return NULL;\r
+}\r
+\r
+static asdl_seq *\r
+ast_for_suite(struct compiling *c, const node *n)\r
+{\r
+    /* suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT */\r
+    asdl_seq *seq;\r
+    stmt_ty s;\r
+    int i, total, num, end, pos = 0;\r
+    node *ch;\r
+\r
+    REQ(n, suite);\r
+\r
+    total = num_stmts(n);\r
+    seq = asdl_seq_new(total, c->c_arena);\r
+    if (!seq)\r
+        return NULL;\r
+    if (TYPE(CHILD(n, 0)) == simple_stmt) {\r
+        n = CHILD(n, 0);\r
+        /* simple_stmt always ends with a NEWLINE,\r
+           and may have a trailing SEMI\r
+        */\r
+        end = NCH(n) - 1;\r
+        if (TYPE(CHILD(n, end - 1)) == SEMI)\r
+            end--;\r
+        /* loop by 2 to skip semi-colons */\r
+        for (i = 0; i < end; i += 2) {\r
+            ch = CHILD(n, i);\r
+            s = ast_for_stmt(c, ch);\r
+            if (!s)\r
+                return NULL;\r
+            asdl_seq_SET(seq, pos++, s);\r
+        }\r
+    }\r
+    else {\r
+        for (i = 2; i < (NCH(n) - 1); i++) {\r
+            ch = CHILD(n, i);\r
+            REQ(ch, stmt);\r
+            num = num_stmts(ch);\r
+            if (num == 1) {\r
+                /* small_stmt or compound_stmt with only one child */\r
+                s = ast_for_stmt(c, ch);\r
+                if (!s)\r
+                    return NULL;\r
+                asdl_seq_SET(seq, pos++, s);\r
+            }\r
+            else {\r
+                int j;\r
+                ch = CHILD(ch, 0);\r
+                REQ(ch, simple_stmt);\r
+                for (j = 0; j < NCH(ch); j += 2) {\r
+                    /* statement terminates with a semi-colon ';' */\r
+                    if (NCH(CHILD(ch, j)) == 0) {\r
+                        assert((j + 1) == NCH(ch));\r
+                        break;\r
+                    }\r
+                    s = ast_for_stmt(c, CHILD(ch, j));\r
+                    if (!s)\r
+                        return NULL;\r
+                    asdl_seq_SET(seq, pos++, s);\r
+                }\r
+            }\r
+        }\r
+    }\r
+    assert(pos == seq->size);\r
+    return seq;\r
+}\r
+\r
+static stmt_ty\r
+ast_for_if_stmt(struct compiling *c, const node *n)\r
+{\r
+    /* if_stmt: 'if' test ':' suite ('elif' test ':' suite)*\r
+       ['else' ':' suite]\r
+    */\r
+    char *s;\r
+\r
+    REQ(n, if_stmt);\r
+\r
+    if (NCH(n) == 4) {\r
+        expr_ty expression;\r
+        asdl_seq *suite_seq;\r
+\r
+        expression = ast_for_expr(c, CHILD(n, 1));\r
+        if (!expression)\r
+            return NULL;\r
+        suite_seq = ast_for_suite(c, CHILD(n, 3));\r
+        if (!suite_seq)\r
+            return NULL;\r
+\r
+        return If(expression, suite_seq, NULL, LINENO(n), n->n_col_offset,\r
+                  c->c_arena);\r
+    }\r
+\r
+    s = STR(CHILD(n, 4));\r
+    /* s[2], the third character in the string, will be\r
+       's' for el_s_e, or\r
+       'i' for el_i_f\r
+    */\r
+    if (s[2] == 's') {\r
+        expr_ty expression;\r
+        asdl_seq *seq1, *seq2;\r
+\r
+        expression = ast_for_expr(c, CHILD(n, 1));\r
+        if (!expression)\r
+            return NULL;\r
+        seq1 = ast_for_suite(c, CHILD(n, 3));\r
+        if (!seq1)\r
+            return NULL;\r
+        seq2 = ast_for_suite(c, CHILD(n, 6));\r
+        if (!seq2)\r
+            return NULL;\r
+\r
+        return If(expression, seq1, seq2, LINENO(n), n->n_col_offset,\r
+                  c->c_arena);\r
+    }\r
+    else if (s[2] == 'i') {\r
+        int i, n_elif, has_else = 0;\r
+        expr_ty expression;\r
+        asdl_seq *suite_seq;\r
+        asdl_seq *orelse = NULL;\r
+        n_elif = NCH(n) - 4;\r
+        /* must reference the child n_elif+1 since 'else' token is third,\r
+           not fourth, child from the end. */\r
+        if (TYPE(CHILD(n, (n_elif + 1))) == NAME\r
+            && STR(CHILD(n, (n_elif + 1)))[2] == 's') {\r
+            has_else = 1;\r
+            n_elif -= 3;\r
+        }\r
+        n_elif /= 4;\r
+\r
+        if (has_else) {\r
+            asdl_seq *suite_seq2;\r
+\r
+            orelse = asdl_seq_new(1, c->c_arena);\r
+            if (!orelse)\r
+                return NULL;\r
+            expression = ast_for_expr(c, CHILD(n, NCH(n) - 6));\r
+            if (!expression)\r
+                return NULL;\r
+            suite_seq = ast_for_suite(c, CHILD(n, NCH(n) - 4));\r
+            if (!suite_seq)\r
+                return NULL;\r
+            suite_seq2 = ast_for_suite(c, CHILD(n, NCH(n) - 1));\r
+            if (!suite_seq2)\r
+                return NULL;\r
+\r
+            asdl_seq_SET(orelse, 0,\r
+                         If(expression, suite_seq, suite_seq2,\r
+                            LINENO(CHILD(n, NCH(n) - 6)),\r
+                            CHILD(n, NCH(n) - 6)->n_col_offset,\r
+                            c->c_arena));\r
+            /* the just-created orelse handled the last elif */\r
+            n_elif--;\r
+        }\r
+\r
+        for (i = 0; i < n_elif; i++) {\r
+            int off = 5 + (n_elif - i - 1) * 4;\r
+            asdl_seq *newobj = asdl_seq_new(1, c->c_arena);\r
+            if (!newobj)\r
+                return NULL;\r
+            expression = ast_for_expr(c, CHILD(n, off));\r
+            if (!expression)\r
+                return NULL;\r
+            suite_seq = ast_for_suite(c, CHILD(n, off + 2));\r
+            if (!suite_seq)\r
+                return NULL;\r
+\r
+            asdl_seq_SET(newobj, 0,\r
+                         If(expression, suite_seq, orelse,\r
+                            LINENO(CHILD(n, off)),\r
+                            CHILD(n, off)->n_col_offset, c->c_arena));\r
+            orelse = newobj;\r
+        }\r
+        expression = ast_for_expr(c, CHILD(n, 1));\r
+        if (!expression)\r
+            return NULL;\r
+        suite_seq = ast_for_suite(c, CHILD(n, 3));\r
+        if (!suite_seq)\r
+            return NULL;\r
+        return If(expression, suite_seq, orelse,\r
+                  LINENO(n), n->n_col_offset, c->c_arena);\r
+    }\r
+\r
+    PyErr_Format(PyExc_SystemError,\r
+                 "unexpected token in 'if' statement: %s", s);\r
+    return NULL;\r
+}\r
+\r
+static stmt_ty\r
+ast_for_while_stmt(struct compiling *c, const node *n)\r
+{\r
+    /* while_stmt: 'while' test ':' suite ['else' ':' suite] */\r
+    REQ(n, while_stmt);\r
+\r
+    if (NCH(n) == 4) {\r
+        expr_ty expression;\r
+        asdl_seq *suite_seq;\r
+\r
+        expression = ast_for_expr(c, CHILD(n, 1));\r
+        if (!expression)\r
+            return NULL;\r
+        suite_seq = ast_for_suite(c, CHILD(n, 3));\r
+        if (!suite_seq)\r
+            return NULL;\r
+        return While(expression, suite_seq, NULL, LINENO(n), n->n_col_offset,\r
+                     c->c_arena);\r
+    }\r
+    else if (NCH(n) == 7) {\r
+        expr_ty expression;\r
+        asdl_seq *seq1, *seq2;\r
+\r
+        expression = ast_for_expr(c, CHILD(n, 1));\r
+        if (!expression)\r
+            return NULL;\r
+        seq1 = ast_for_suite(c, CHILD(n, 3));\r
+        if (!seq1)\r
+            return NULL;\r
+        seq2 = ast_for_suite(c, CHILD(n, 6));\r
+        if (!seq2)\r
+            return NULL;\r
+\r
+        return While(expression, seq1, seq2, LINENO(n), n->n_col_offset,\r
+                     c->c_arena);\r
+    }\r
+\r
+    PyErr_Format(PyExc_SystemError,\r
+                 "wrong number of tokens for 'while' statement: %d",\r
+                 NCH(n));\r
+    return NULL;\r
+}\r
+\r
+static stmt_ty\r
+ast_for_for_stmt(struct compiling *c, const node *n)\r
+{\r
+    asdl_seq *_target, *seq = NULL, *suite_seq;\r
+    expr_ty expression;\r
+    expr_ty target, first;\r
+    const node *node_target;\r
+    /* for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] */\r
+    REQ(n, for_stmt);\r
+\r
+    if (NCH(n) == 9) {\r
+        seq = ast_for_suite(c, CHILD(n, 8));\r
+        if (!seq)\r
+            return NULL;\r
+    }\r
+\r
+    node_target = CHILD(n, 1);\r
+    _target = ast_for_exprlist(c, node_target, Store);\r
+    if (!_target)\r
+        return NULL;\r
+    /* Check the # of children rather than the length of _target, since\r
+       for x, in ... has 1 element in _target, but still requires a Tuple. */\r
+    first = (expr_ty)asdl_seq_GET(_target, 0);\r
+    if (NCH(node_target) == 1)\r
+        target = first;\r
+    else\r
+        target = Tuple(_target, Store, first->lineno, first->col_offset, c->c_arena);\r
+\r
+    expression = ast_for_testlist(c, CHILD(n, 3));\r
+    if (!expression)\r
+        return NULL;\r
+    suite_seq = ast_for_suite(c, CHILD(n, 5));\r
+    if (!suite_seq)\r
+        return NULL;\r
+\r
+    return For(target, expression, suite_seq, seq, LINENO(n), n->n_col_offset,\r
+               c->c_arena);\r
+}\r
+\r
+static excepthandler_ty\r
+ast_for_except_clause(struct compiling *c, const node *exc, node *body)\r
+{\r
+    /* except_clause: 'except' [test [(',' | 'as') test]] */\r
+    REQ(exc, except_clause);\r
+    REQ(body, suite);\r
+\r
+    if (NCH(exc) == 1) {\r
+        asdl_seq *suite_seq = ast_for_suite(c, body);\r
+        if (!suite_seq)\r
+            return NULL;\r
+\r
+        return ExceptHandler(NULL, NULL, suite_seq, LINENO(exc),\r
+                             exc->n_col_offset, c->c_arena);\r
+    }\r
+    else if (NCH(exc) == 2) {\r
+        expr_ty expression;\r
+        asdl_seq *suite_seq;\r
+\r
+        expression = ast_for_expr(c, CHILD(exc, 1));\r
+        if (!expression)\r
+            return NULL;\r
+        suite_seq = ast_for_suite(c, body);\r
+        if (!suite_seq)\r
+            return NULL;\r
+\r
+        return ExceptHandler(expression, NULL, suite_seq, LINENO(exc),\r
+                             exc->n_col_offset, c->c_arena);\r
+    }\r
+    else if (NCH(exc) == 4) {\r
+        asdl_seq *suite_seq;\r
+        expr_ty expression;\r
+        expr_ty e = ast_for_expr(c, CHILD(exc, 3));\r
+        if (!e)\r
+            return NULL;\r
+        if (!set_context(c, e, Store, CHILD(exc, 3)))\r
+            return NULL;\r
+        expression = ast_for_expr(c, CHILD(exc, 1));\r
+        if (!expression)\r
+            return NULL;\r
+        suite_seq = ast_for_suite(c, body);\r
+        if (!suite_seq)\r
+            return NULL;\r
+\r
+        return ExceptHandler(expression, e, suite_seq, LINENO(exc),\r
+                             exc->n_col_offset, c->c_arena);\r
+    }\r
+\r
+    PyErr_Format(PyExc_SystemError,\r
+                 "wrong number of children for 'except' clause: %d",\r
+                 NCH(exc));\r
+    return NULL;\r
+}\r
+\r
+static stmt_ty\r
+ast_for_try_stmt(struct compiling *c, const node *n)\r
+{\r
+    const int nch = NCH(n);\r
+    int n_except = (nch - 3)/3;\r
+    asdl_seq *body, *orelse = NULL, *finally = NULL;\r
+\r
+    REQ(n, try_stmt);\r
+\r
+    body = ast_for_suite(c, CHILD(n, 2));\r
+    if (body == NULL)\r
+        return NULL;\r
+\r
+    if (TYPE(CHILD(n, nch - 3)) == NAME) {\r
+        if (strcmp(STR(CHILD(n, nch - 3)), "finally") == 0) {\r
+            if (nch >= 9 && TYPE(CHILD(n, nch - 6)) == NAME) {\r
+                /* we can assume it's an "else",\r
+                   because nch >= 9 for try-else-finally and\r
+                   it would otherwise have a type of except_clause */\r
+                orelse = ast_for_suite(c, CHILD(n, nch - 4));\r
+                if (orelse == NULL)\r
+                    return NULL;\r
+                n_except--;\r
+            }\r
+\r
+            finally = ast_for_suite(c, CHILD(n, nch - 1));\r
+            if (finally == NULL)\r
+                return NULL;\r
+            n_except--;\r
+        }\r
+        else {\r
+            /* we can assume it's an "else",\r
+               otherwise it would have a type of except_clause */\r
+            orelse = ast_for_suite(c, CHILD(n, nch - 1));\r
+            if (orelse == NULL)\r
+                return NULL;\r
+            n_except--;\r
+        }\r
+    }\r
+    else if (TYPE(CHILD(n, nch - 3)) != except_clause) {\r
+        ast_error(n, "malformed 'try' statement");\r
+        return NULL;\r
+    }\r
+\r
+    if (n_except > 0) {\r
+        int i;\r
+        stmt_ty except_st;\r
+        /* process except statements to create a try ... except */\r
+        asdl_seq *handlers = asdl_seq_new(n_except, c->c_arena);\r
+        if (handlers == NULL)\r
+            return NULL;\r
+\r
+        for (i = 0; i < n_except; i++) {\r
+            excepthandler_ty e = ast_for_except_clause(c, CHILD(n, 3 + i * 3),\r
+                                                       CHILD(n, 5 + i * 3));\r
+            if (!e)\r
+                return NULL;\r
+            asdl_seq_SET(handlers, i, e);\r
+        }\r
+\r
+        except_st = TryExcept(body, handlers, orelse, LINENO(n),\r
+                              n->n_col_offset, c->c_arena);\r
+        if (!finally)\r
+            return except_st;\r
+\r
+        /* if a 'finally' is present too, we nest the TryExcept within a\r
+           TryFinally to emulate try ... except ... finally */\r
+        body = asdl_seq_new(1, c->c_arena);\r
+        if (body == NULL)\r
+            return NULL;\r
+        asdl_seq_SET(body, 0, except_st);\r
+    }\r
+\r
+    /* must be a try ... finally (except clauses are in body, if any exist) */\r
+    assert(finally != NULL);\r
+    return TryFinally(body, finally, LINENO(n), n->n_col_offset, c->c_arena);\r
+}\r
+\r
+/* with_item: test ['as' expr] */\r
+static stmt_ty\r
+ast_for_with_item(struct compiling *c, const node *n, asdl_seq *content)\r
+{\r
+    expr_ty context_expr, optional_vars = NULL;\r
+\r
+    REQ(n, with_item);\r
+    context_expr = ast_for_expr(c, CHILD(n, 0));\r
+    if (!context_expr)\r
+        return NULL;\r
+    if (NCH(n) == 3) {\r
+        optional_vars = ast_for_expr(c, CHILD(n, 2));\r
+\r
+        if (!optional_vars) {\r
+            return NULL;\r
+        }\r
+        if (!set_context(c, optional_vars, Store, n)) {\r
+            return NULL;\r
+        }\r
+    }\r
+\r
+    return With(context_expr, optional_vars, content, LINENO(n),\r
+                n->n_col_offset, c->c_arena);\r
+}\r
+\r
+/* with_stmt: 'with' with_item (',' with_item)* ':' suite */\r
+static stmt_ty\r
+ast_for_with_stmt(struct compiling *c, const node *n)\r
+{\r
+    int i;\r
+    stmt_ty ret;\r
+    asdl_seq *inner;\r
+\r
+    REQ(n, with_stmt);\r
+\r
+    /* process the with items inside-out */\r
+    i = NCH(n) - 1;\r
+    /* the suite of the innermost with item is the suite of the with stmt */\r
+    inner = ast_for_suite(c, CHILD(n, i));\r
+    if (!inner)\r
+        return NULL;\r
+\r
+    for (;;) {\r
+        i -= 2;\r
+        ret = ast_for_with_item(c, CHILD(n, i), inner);\r
+        if (!ret)\r
+            return NULL;\r
+        /* was this the last item? */\r
+        if (i == 1)\r
+            break;\r
+        /* if not, wrap the result so far in a new sequence */\r
+        inner = asdl_seq_new(1, c->c_arena);\r
+        if (!inner)\r
+            return NULL;\r
+        asdl_seq_SET(inner, 0, ret);\r
+    }\r
+\r
+    return ret;\r
+}\r
+\r
+static stmt_ty\r
+ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)\r
+{\r
+    /* classdef: 'class' NAME ['(' testlist ')'] ':' suite */\r
+    PyObject *classname;\r
+    asdl_seq *bases, *s;\r
+\r
+    REQ(n, classdef);\r
+\r
+    if (!forbidden_check(c, n, STR(CHILD(n, 1))))\r
+            return NULL;\r
+\r
+    if (NCH(n) == 4) {\r
+        s = ast_for_suite(c, CHILD(n, 3));\r
+        if (!s)\r
+            return NULL;\r
+        classname = NEW_IDENTIFIER(CHILD(n, 1));\r
+        if (!classname)\r
+            return NULL;\r
+        return ClassDef(classname, NULL, s, decorator_seq, LINENO(n),\r
+                        n->n_col_offset, c->c_arena);\r
+    }\r
+    /* check for empty base list */\r
+    if (TYPE(CHILD(n,3)) == RPAR) {\r
+        s = ast_for_suite(c, CHILD(n,5));\r
+        if (!s)\r
+            return NULL;\r
+        classname = NEW_IDENTIFIER(CHILD(n, 1));\r
+        if (!classname)\r
+            return NULL;\r
+        return ClassDef(classname, NULL, s, decorator_seq, LINENO(n),\r
+                        n->n_col_offset, c->c_arena);\r
+    }\r
+\r
+    /* else handle the base class list */\r
+    bases = ast_for_class_bases(c, CHILD(n, 3));\r
+    if (!bases)\r
+        return NULL;\r
+\r
+    s = ast_for_suite(c, CHILD(n, 6));\r
+    if (!s)\r
+        return NULL;\r
+    classname = NEW_IDENTIFIER(CHILD(n, 1));\r
+    if (!classname)\r
+        return NULL;\r
+    return ClassDef(classname, bases, s, decorator_seq,\r
+                    LINENO(n), n->n_col_offset, c->c_arena);\r
+}\r
+\r
+static stmt_ty\r
+ast_for_stmt(struct compiling *c, const node *n)\r
+{\r
+    if (TYPE(n) == stmt) {\r
+        assert(NCH(n) == 1);\r
+        n = CHILD(n, 0);\r
+    }\r
+    if (TYPE(n) == simple_stmt) {\r
+        assert(num_stmts(n) == 1);\r
+        n = CHILD(n, 0);\r
+    }\r
+    if (TYPE(n) == small_stmt) {\r
+        n = CHILD(n, 0);\r
+        /* small_stmt: expr_stmt | print_stmt  | del_stmt | pass_stmt\r
+                     | flow_stmt | import_stmt | global_stmt | exec_stmt\r
+                     | assert_stmt\r
+        */\r
+        switch (TYPE(n)) {\r
+            case expr_stmt:\r
+                return ast_for_expr_stmt(c, n);\r
+            case print_stmt:\r
+                return ast_for_print_stmt(c, n);\r
+            case del_stmt:\r
+                return ast_for_del_stmt(c, n);\r
+            case pass_stmt:\r
+                return Pass(LINENO(n), n->n_col_offset, c->c_arena);\r
+            case flow_stmt:\r
+                return ast_for_flow_stmt(c, n);\r
+            case import_stmt:\r
+                return ast_for_import_stmt(c, n);\r
+            case global_stmt:\r
+                return ast_for_global_stmt(c, n);\r
+            case exec_stmt:\r
+                return ast_for_exec_stmt(c, n);\r
+            case assert_stmt:\r
+                return ast_for_assert_stmt(c, n);\r
+            default:\r
+                PyErr_Format(PyExc_SystemError,\r
+                             "unhandled small_stmt: TYPE=%d NCH=%d\n",\r
+                             TYPE(n), NCH(n));\r
+                return NULL;\r
+        }\r
+    }\r
+    else {\r
+        /* compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt\r
+                        | funcdef | classdef | decorated\r
+        */\r
+        node *ch = CHILD(n, 0);\r
+        REQ(n, compound_stmt);\r
+        switch (TYPE(ch)) {\r
+            case if_stmt:\r
+                return ast_for_if_stmt(c, ch);\r
+            case while_stmt:\r
+                return ast_for_while_stmt(c, ch);\r
+            case for_stmt:\r
+                return ast_for_for_stmt(c, ch);\r
+            case try_stmt:\r
+                return ast_for_try_stmt(c, ch);\r
+            case with_stmt:\r
+                return ast_for_with_stmt(c, ch);\r
+            case funcdef:\r
+                return ast_for_funcdef(c, ch, NULL);\r
+            case classdef:\r
+                return ast_for_classdef(c, ch, NULL);\r
+            case decorated:\r
+                return ast_for_decorated(c, ch);\r
+            default:\r
+                PyErr_Format(PyExc_SystemError,\r
+                             "unhandled small_stmt: TYPE=%d NCH=%d\n",\r
+                             TYPE(n), NCH(n));\r
+                return NULL;\r
+        }\r
+    }\r
+}\r
+\r
+static PyObject *\r
+parsenumber(struct compiling *c, const char *s)\r
+{\r
+        const char *end;\r
+        long x;\r
+        double dx;\r
+#ifndef WITHOUT_COMPLEX\r
+        Py_complex complex;\r
+        int imflag;\r
+#endif\r
+\r
+        assert(s != NULL);\r
+        errno = 0;\r
+        end = s + strlen(s) - 1;\r
+#ifndef WITHOUT_COMPLEX\r
+        imflag = *end == 'j' || *end == 'J';\r
+#endif\r
+        if (*end == 'l' || *end == 'L')\r
+                return PyLong_FromString((char *)s, (char **)0, 0);\r
+        x = PyOS_strtol((char *)s, (char **)&end, 0);\r
+        if (*end == '\0') {\r
+                if (errno != 0)\r
+                        return PyLong_FromString((char *)s, (char **)0, 0);\r
+                return PyInt_FromLong(x);\r
+        }\r
+        /* XXX Huge floats may silently fail */\r
+#ifndef WITHOUT_COMPLEX\r
+        if (imflag) {\r
+                complex.real = 0.;\r
+                complex.imag = PyOS_string_to_double(s, (char **)&end, NULL);\r
+                if (complex.imag == -1.0 && PyErr_Occurred())\r
+                        return NULL;\r
+                return PyComplex_FromCComplex(complex);\r
+        }\r
+        else\r
+#endif\r
+        {\r
+                dx = PyOS_string_to_double(s, NULL, NULL);\r
+                if (dx == -1.0 && PyErr_Occurred())\r
+                        return NULL;\r
+                return PyFloat_FromDouble(dx);\r
+        }\r
+}\r
+\r
+static PyObject *\r
+decode_utf8(struct compiling *c, const char **sPtr, const char *end, char* encoding)\r
+{\r
+#ifndef Py_USING_UNICODE\r
+        Py_FatalError("decode_utf8 should not be called in this build.");\r
+        return NULL;\r
+#else\r
+        PyObject *u, *v;\r
+        char *s, *t;\r
+        t = s = (char *)*sPtr;\r
+        /* while (s < end && *s != '\\') s++; */ /* inefficient for u".." */\r
+        while (s < end && (*s & 0x80)) s++;\r
+        *sPtr = s;\r
+        u = PyUnicode_DecodeUTF8(t, s - t, NULL);\r
+        if (u == NULL)\r
+                return NULL;\r
+        v = PyUnicode_AsEncodedString(u, encoding, NULL);\r
+        Py_DECREF(u);\r
+        return v;\r
+#endif\r
+}\r
+\r
+#ifdef Py_USING_UNICODE\r
+static PyObject *\r
+decode_unicode(struct compiling *c, const char *s, size_t len, int rawmode, const char *encoding)\r
+{\r
+        PyObject *v;\r
+        PyObject *u = NULL;\r
+        char *buf;\r
+        char *p;\r
+        const char *end;\r
+        if (encoding != NULL && strcmp(encoding, "iso-8859-1")) {\r
+                /* check for integer overflow */\r
+                if (len > PY_SIZE_MAX / 6)\r
+                        return NULL;\r
+                /* "<C3><A4>" (2 bytes) may become "\U000000E4" (10 bytes), or 1:5\r
+                   "\ä" (3 bytes) may become "\u005c\U000000E4" (16 bytes), or ~1:6 */\r
+                u = PyString_FromStringAndSize((char *)NULL, len * 6);\r
+                if (u == NULL)\r
+                        return NULL;\r
+                p = buf = PyString_AsString(u);\r
+                end = s + len;\r
+                while (s < end) {\r
+                        if (*s == '\\') {\r
+                                *p++ = *s++;\r
+                                if (*s & 0x80) {\r
+                                        strcpy(p, "u005c");\r
+                                        p += 5;\r
+                                }\r
+                        }\r
+                        if (*s & 0x80) { /* XXX inefficient */\r
+                                PyObject *w;\r
+                                char *r;\r
+                                Py_ssize_t rn, i;\r
+                                w = decode_utf8(c, &s, end, "utf-32-be");\r
+                                if (w == NULL) {\r
+                                        Py_DECREF(u);\r
+                                        return NULL;\r
+                                }\r
+                                r = PyString_AsString(w);\r
+                                rn = PyString_Size(w);\r
+                                assert(rn % 4 == 0);\r
+                                for (i = 0; i < rn; i += 4) {\r
+                                        sprintf(p, "\\U%02x%02x%02x%02x",\r
+                                                r[i + 0] & 0xFF,\r
+                                                r[i + 1] & 0xFF,\r
+                                                r[i + 2] & 0xFF,\r
+                                                r[i + 3] & 0xFF);\r
+                                        p += 10;\r
+                                }\r
+                                Py_DECREF(w);\r
+                        } else {\r
+                                *p++ = *s++;\r
+                        }\r
+                }\r
+                len = p - buf;\r
+                s = buf;\r
+        }\r
+        if (rawmode)\r
+                v = PyUnicode_DecodeRawUnicodeEscape(s, len, NULL);\r
+        else\r
+                v = PyUnicode_DecodeUnicodeEscape(s, len, NULL);\r
+        Py_XDECREF(u);\r
+        return v;\r
+}\r
+#endif\r
+\r
+/* s is a Python string literal, including the bracketing quote characters,\r
+ * and r &/or u prefixes (if any), and embedded escape sequences (if any).\r
+ * parsestr parses it, and returns the decoded Python string object.\r
+ */\r
+static PyObject *\r
+parsestr(struct compiling *c, const node *n, const char *s)\r
+{\r
+        size_t len, i;\r
+        int quote = Py_CHARMASK(*s);\r
+        int rawmode = 0;\r
+        int need_encoding;\r
+        int unicode = c->c_future_unicode;\r
+        int bytes = 0;\r
+\r
+        if (isalpha(quote) || quote == '_') {\r
+                if (quote == 'u' || quote == 'U') {\r
+                        quote = *++s;\r
+                        unicode = 1;\r
+                }\r
+                if (quote == 'b' || quote == 'B') {\r
+                        quote = *++s;\r
+                        unicode = 0;\r
+                        bytes = 1;\r
+                }\r
+                if (quote == 'r' || quote == 'R') {\r
+                        quote = *++s;\r
+                        rawmode = 1;\r
+                }\r
+        }\r
+        if (quote != '\'' && quote != '\"') {\r
+                PyErr_BadInternalCall();\r
+                return NULL;\r
+        }\r
+        s++;\r
+        len = strlen(s);\r
+        if (len > INT_MAX) {\r
+                PyErr_SetString(PyExc_OverflowError,\r
+                                "string to parse is too long");\r
+                return NULL;\r
+        }\r
+        if (s[--len] != quote) {\r
+                PyErr_BadInternalCall();\r
+                return NULL;\r
+        }\r
+        if (len >= 4 && s[0] == quote && s[1] == quote) {\r
+                s += 2;\r
+                len -= 2;\r
+                if (s[--len] != quote || s[--len] != quote) {\r
+                        PyErr_BadInternalCall();\r
+                        return NULL;\r
+                }\r
+        }\r
+        if (Py_Py3kWarningFlag && bytes) {\r
+            for (i = 0; i < len; i++) {\r
+                if ((unsigned char)s[i] > 127) {\r
+                    if (!ast_warn(c, n,\r
+                        "non-ascii bytes literals not supported in 3.x"))\r
+                        return NULL;\r
+                    break;\r
+                }\r
+            }\r
+        }\r
+#ifdef Py_USING_UNICODE\r
+        if (unicode || Py_UnicodeFlag) {\r
+                return decode_unicode(c, s, len, rawmode, c->c_encoding);\r
+        }\r
+#endif\r
+        need_encoding = (c->c_encoding != NULL &&\r
+                         strcmp(c->c_encoding, "utf-8") != 0 &&\r
+                         strcmp(c->c_encoding, "iso-8859-1") != 0);\r
+        if (rawmode || strchr(s, '\\') == NULL) {\r
+                if (need_encoding) {\r
+#ifndef Py_USING_UNICODE\r
+                        /* This should not happen - we never see any other\r
+                           encoding. */\r
+                        Py_FatalError(\r
+                            "cannot deal with encodings in this build.");\r
+#else\r
+                        PyObject *v, *u = PyUnicode_DecodeUTF8(s, len, NULL);\r
+                        if (u == NULL)\r
+                                return NULL;\r
+                        v = PyUnicode_AsEncodedString(u, c->c_encoding, NULL);\r
+                        Py_DECREF(u);\r
+                        return v;\r
+#endif\r
+                } else {\r
+                        return PyString_FromStringAndSize(s, len);\r
+                }\r
+        }\r
+\r
+        return PyString_DecodeEscape(s, len, NULL, unicode,\r
+                                     need_encoding ? c->c_encoding : NULL);\r
+}\r
+\r
+/* Build a Python string object out of a STRING atom.  This takes care of\r
+ * compile-time literal catenation, calling parsestr() on each piece, and\r
+ * pasting the intermediate results together.\r
+ */\r
+static PyObject *\r
+parsestrplus(struct compiling *c, const node *n)\r
+{\r
+        PyObject *v;\r
+        int i;\r
+        REQ(CHILD(n, 0), STRING);\r
+        if ((v = parsestr(c, n, STR(CHILD(n, 0)))) != NULL) {\r
+                /* String literal concatenation */\r
+                for (i = 1; i < NCH(n); i++) {\r
+                        PyObject *s;\r
+                        s = parsestr(c, n, STR(CHILD(n, i)));\r
+                        if (s == NULL)\r
+                                goto onError;\r
+                        if (PyString_Check(v) && PyString_Check(s)) {\r
+                                PyString_ConcatAndDel(&v, s);\r
+                                if (v == NULL)\r
+                                    goto onError;\r
+                        }\r
+#ifdef Py_USING_UNICODE\r
+                        else {\r
+                                PyObject *temp = PyUnicode_Concat(v, s);\r
+                                Py_DECREF(s);\r
+                                Py_DECREF(v);\r
+                                v = temp;\r
+                                if (v == NULL)\r
+                                    goto onError;\r
+                        }\r
+#endif\r
+                }\r
+        }\r
+        return v;\r
+\r
+ onError:\r
+        Py_XDECREF(v);\r
+        return NULL;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/bltinmodule.c b/AppPkg/Applications/Python/Python-2.7.10/Python/bltinmodule.c
new file mode 100644 (file)
index 0000000..188d688
--- /dev/null
@@ -0,0 +1,3061 @@
+/* Built-in functions */\r
+\r
+#include "Python.h"\r
+#include "Python-ast.h"\r
+\r
+#include "node.h"\r
+#include "code.h"\r
+#include "eval.h"\r
+\r
+#include <ctype.h>\r
+#include <float.h> /* for DBL_MANT_DIG and friends */\r
+\r
+#ifdef RISCOS\r
+#include "unixstuff.h"\r
+#endif\r
+\r
+/* The default encoding used by the platform file system APIs\r
+   Can remain NULL for all platforms that don't have such a concept\r
+*/\r
+#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)\r
+const char *Py_FileSystemDefaultEncoding = "mbcs";\r
+#elif defined(__APPLE__)\r
+const char *Py_FileSystemDefaultEncoding = "utf-8";\r
+#else\r
+const char *Py_FileSystemDefaultEncoding = NULL; /* use default */\r
+#endif\r
+\r
+/* Forward */\r
+static PyObject *filterstring(PyObject *, PyObject *);\r
+#ifdef Py_USING_UNICODE\r
+static PyObject *filterunicode(PyObject *, PyObject *);\r
+#endif\r
+static PyObject *filtertuple (PyObject *, PyObject *);\r
+\r
+static PyObject *\r
+builtin___import__(PyObject *self, PyObject *args, PyObject *kwds)\r
+{\r
+    static char *kwlist[] = {"name", "globals", "locals", "fromlist",\r
+                             "level", 0};\r
+    char *name;\r
+    PyObject *globals = NULL;\r
+    PyObject *locals = NULL;\r
+    PyObject *fromlist = NULL;\r
+    int level = -1;\r
+\r
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|OOOi:__import__",\r
+                    kwlist, &name, &globals, &locals, &fromlist, &level))\r
+        return NULL;\r
+    return PyImport_ImportModuleLevel(name, globals, locals,\r
+                                      fromlist, level);\r
+}\r
+\r
+PyDoc_STRVAR(import_doc,\r
+"__import__(name, globals={}, locals={}, fromlist=[], level=-1) -> module\n\\r
+\n\\r
+Import a module. Because this function is meant for use by the Python\n\\r
+interpreter and not for general use it is better to use\n\\r
+importlib.import_module() to programmatically import a module.\n\\r
+\n\\r
+The globals argument is only used to determine the context;\n\\r
+they are not modified.  The locals argument is unused.  The fromlist\n\\r
+should be a list of names to emulate ``from name import ...'', or an\n\\r
+empty list to emulate ``import name''.\n\\r
+When importing a module from a package, note that __import__('A.B', ...)\n\\r
+returns package A when fromlist is empty, but its submodule B when\n\\r
+fromlist is not empty.  Level is used to determine whether to perform \n\\r
+absolute or relative imports.  -1 is the original strategy of attempting\n\\r
+both absolute and relative imports, 0 is absolute, a positive number\n\\r
+is the number of parent directories to search relative to the current module.");\r
+\r
+\r
+static PyObject *\r
+builtin_abs(PyObject *self, PyObject *v)\r
+{\r
+    return PyNumber_Absolute(v);\r
+}\r
+\r
+PyDoc_STRVAR(abs_doc,\r
+"abs(number) -> number\n\\r
+\n\\r
+Return the absolute value of the argument.");\r
+\r
+static PyObject *\r
+builtin_all(PyObject *self, PyObject *v)\r
+{\r
+    PyObject *it, *item;\r
+    PyObject *(*iternext)(PyObject *);\r
+    int cmp;\r
+\r
+    it = PyObject_GetIter(v);\r
+    if (it == NULL)\r
+        return NULL;\r
+    iternext = *Py_TYPE(it)->tp_iternext;\r
+\r
+    for (;;) {\r
+        item = iternext(it);\r
+        if (item == NULL)\r
+            break;\r
+        cmp = PyObject_IsTrue(item);\r
+        Py_DECREF(item);\r
+        if (cmp < 0) {\r
+            Py_DECREF(it);\r
+            return NULL;\r
+        }\r
+        if (cmp == 0) {\r
+            Py_DECREF(it);\r
+            Py_RETURN_FALSE;\r
+        }\r
+    }\r
+    Py_DECREF(it);\r
+    if (PyErr_Occurred()) {\r
+        if (PyErr_ExceptionMatches(PyExc_StopIteration))\r
+            PyErr_Clear();\r
+        else\r
+            return NULL;\r
+    }\r
+    Py_RETURN_TRUE;\r
+}\r
+\r
+PyDoc_STRVAR(all_doc,\r
+"all(iterable) -> bool\n\\r
+\n\\r
+Return True if bool(x) is True for all values x in the iterable.\n\\r
+If the iterable is empty, return True.");\r
+\r
+static PyObject *\r
+builtin_any(PyObject *self, PyObject *v)\r
+{\r
+    PyObject *it, *item;\r
+    PyObject *(*iternext)(PyObject *);\r
+    int cmp;\r
+\r
+    it = PyObject_GetIter(v);\r
+    if (it == NULL)\r
+        return NULL;\r
+    iternext = *Py_TYPE(it)->tp_iternext;\r
+\r
+    for (;;) {\r
+        item = iternext(it);\r
+        if (item == NULL)\r
+            break;\r
+        cmp = PyObject_IsTrue(item);\r
+        Py_DECREF(item);\r
+        if (cmp < 0) {\r
+            Py_DECREF(it);\r
+            return NULL;\r
+        }\r
+        if (cmp == 1) {\r
+            Py_DECREF(it);\r
+            Py_RETURN_TRUE;\r
+        }\r
+    }\r
+    Py_DECREF(it);\r
+    if (PyErr_Occurred()) {\r
+        if (PyErr_ExceptionMatches(PyExc_StopIteration))\r
+            PyErr_Clear();\r
+        else\r
+            return NULL;\r
+    }\r
+    Py_RETURN_FALSE;\r
+}\r
+\r
+PyDoc_STRVAR(any_doc,\r
+"any(iterable) -> bool\n\\r
+\n\\r
+Return True if bool(x) is True for any x in the iterable.\n\\r
+If the iterable is empty, return False.");\r
+\r
+static PyObject *\r
+builtin_apply(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *func, *alist = NULL, *kwdict = NULL;\r
+    PyObject *t = NULL, *retval = NULL;\r
+\r
+    if (PyErr_WarnPy3k("apply() not supported in 3.x; "\r
+                       "use func(*args, **kwargs)", 1) < 0)\r
+        return NULL;\r
+\r
+    if (!PyArg_UnpackTuple(args, "apply", 1, 3, &func, &alist, &kwdict))\r
+        return NULL;\r
+    if (alist != NULL) {\r
+        if (!PyTuple_Check(alist)) {\r
+            if (!PySequence_Check(alist)) {\r
+                PyErr_Format(PyExc_TypeError,\r
+                     "apply() arg 2 expected sequence, found %s",\r
+                         alist->ob_type->tp_name);\r
+                return NULL;\r
+            }\r
+            t = PySequence_Tuple(alist);\r
+            if (t == NULL)\r
+                return NULL;\r
+            alist = t;\r
+        }\r
+    }\r
+    if (kwdict != NULL && !PyDict_Check(kwdict)) {\r
+        PyErr_Format(PyExc_TypeError,\r
+                     "apply() arg 3 expected dictionary, found %s",\r
+                     kwdict->ob_type->tp_name);\r
+        goto finally;\r
+    }\r
+    retval = PyEval_CallObjectWithKeywords(func, alist, kwdict);\r
+  finally:\r
+    Py_XDECREF(t);\r
+    return retval;\r
+}\r
+\r
+PyDoc_STRVAR(apply_doc,\r
+"apply(object[, args[, kwargs]]) -> value\n\\r
+\n\\r
+Call a callable object with positional arguments taken from the tuple args,\n\\r
+and keyword arguments taken from the optional dictionary kwargs.\n\\r
+Note that classes are callable, as are instances with a __call__() method.\n\\r
+\n\\r
+Deprecated since release 2.3. Instead, use the extended call syntax:\n\\r
+    function(*args, **keywords).");\r
+\r
+\r
+static PyObject *\r
+builtin_bin(PyObject *self, PyObject *v)\r
+{\r
+    return PyNumber_ToBase(v, 2);\r
+}\r
+\r
+PyDoc_STRVAR(bin_doc,\r
+"bin(number) -> string\n\\r
+\n\\r
+Return the binary representation of an integer or long integer.");\r
+\r
+\r
+static PyObject *\r
+builtin_callable(PyObject *self, PyObject *v)\r
+{\r
+    return PyBool_FromLong((long)PyCallable_Check(v));\r
+}\r
+\r
+PyDoc_STRVAR(callable_doc,\r
+"callable(object) -> bool\n\\r
+\n\\r
+Return whether the object is callable (i.e., some kind of function).\n\\r
+Note that classes are callable, as are instances with a __call__() method.");\r
+\r
+\r
+static PyObject *\r
+builtin_filter(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *func, *seq, *result, *it, *arg;\r
+    Py_ssize_t len;   /* guess for result list size */\r
+    register Py_ssize_t j;\r
+\r
+    if (!PyArg_UnpackTuple(args, "filter", 2, 2, &func, &seq))\r
+        return NULL;\r
+\r
+    /* Strings and tuples return a result of the same type. */\r
+    if (PyString_Check(seq))\r
+        return filterstring(func, seq);\r
+#ifdef Py_USING_UNICODE\r
+    if (PyUnicode_Check(seq))\r
+        return filterunicode(func, seq);\r
+#endif\r
+    if (PyTuple_Check(seq))\r
+        return filtertuple(func, seq);\r
+\r
+    /* Pre-allocate argument list tuple. */\r
+    arg = PyTuple_New(1);\r
+    if (arg == NULL)\r
+        return NULL;\r
+\r
+    /* Get iterator. */\r
+    it = PyObject_GetIter(seq);\r
+    if (it == NULL)\r
+        goto Fail_arg;\r
+\r
+    /* Guess a result list size. */\r
+    len = _PyObject_LengthHint(seq, 8);\r
+    if (len == -1)\r
+        goto Fail_it;\r
+\r
+    /* Get a result list. */\r
+    if (PyList_Check(seq) && seq->ob_refcnt == 1) {\r
+        /* Eww - can modify the list in-place. */\r
+        Py_INCREF(seq);\r
+        result = seq;\r
+    }\r
+    else {\r
+        result = PyList_New(len);\r
+        if (result == NULL)\r
+            goto Fail_it;\r
+    }\r
+\r
+    /* Build the result list. */\r
+    j = 0;\r
+    for (;;) {\r
+        PyObject *item;\r
+        int ok;\r
+\r
+        item = PyIter_Next(it);\r
+        if (item == NULL) {\r
+            if (PyErr_Occurred())\r
+                goto Fail_result_it;\r
+            break;\r
+        }\r
+\r
+        if (func == (PyObject *)&PyBool_Type || func == Py_None) {\r
+            ok = PyObject_IsTrue(item);\r
+        }\r
+        else {\r
+            PyObject *good;\r
+            PyTuple_SET_ITEM(arg, 0, item);\r
+            good = PyObject_Call(func, arg, NULL);\r
+            PyTuple_SET_ITEM(arg, 0, NULL);\r
+            if (good == NULL) {\r
+                Py_DECREF(item);\r
+                goto Fail_result_it;\r
+            }\r
+            ok = PyObject_IsTrue(good);\r
+            Py_DECREF(good);\r
+        }\r
+        if (ok > 0) {\r
+            if (j < len)\r
+                PyList_SET_ITEM(result, j, item);\r
+            else {\r
+                int status = PyList_Append(result, item);\r
+                Py_DECREF(item);\r
+                if (status < 0)\r
+                    goto Fail_result_it;\r
+            }\r
+            ++j;\r
+        }\r
+        else {\r
+            Py_DECREF(item);\r
+            if (ok < 0)\r
+                goto Fail_result_it;\r
+        }\r
+    }\r
+\r
+\r
+    /* Cut back result list if len is too big. */\r
+    if (j < len && PyList_SetSlice(result, j, len, NULL) < 0)\r
+        goto Fail_result_it;\r
+\r
+    Py_DECREF(it);\r
+    Py_DECREF(arg);\r
+    return result;\r
+\r
+Fail_result_it:\r
+    Py_DECREF(result);\r
+Fail_it:\r
+    Py_DECREF(it);\r
+Fail_arg:\r
+    Py_DECREF(arg);\r
+    return NULL;\r
+}\r
+\r
+PyDoc_STRVAR(filter_doc,\r
+"filter(function or None, sequence) -> list, tuple, or string\n"\r
+"\n"\r
+"Return those items of sequence for which function(item) is true.  If\n"\r
+"function is None, return the items that are true.  If sequence is a tuple\n"\r
+"or string, return the same type, else return a list.");\r
+\r
+static PyObject *\r
+builtin_format(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *value;\r
+    PyObject *format_spec = NULL;\r
+\r
+    if (!PyArg_ParseTuple(args, "O|O:format", &value, &format_spec))\r
+        return NULL;\r
+\r
+    return PyObject_Format(value, format_spec);\r
+}\r
+\r
+PyDoc_STRVAR(format_doc,\r
+"format(value[, format_spec]) -> string\n\\r
+\n\\r
+Returns value.__format__(format_spec)\n\\r
+format_spec defaults to \"\"");\r
+\r
+static PyObject *\r
+builtin_chr(PyObject *self, PyObject *args)\r
+{\r
+    long x;\r
+    char s[1];\r
+\r
+    if (!PyArg_ParseTuple(args, "l:chr", &x))\r
+        return NULL;\r
+    if (x < 0 || x >= 256) {\r
+        PyErr_SetString(PyExc_ValueError,\r
+                        "chr() arg not in range(256)");\r
+        return NULL;\r
+    }\r
+    s[0] = (char)x;\r
+    return PyString_FromStringAndSize(s, 1);\r
+}\r
+\r
+PyDoc_STRVAR(chr_doc,\r
+"chr(i) -> character\n\\r
+\n\\r
+Return a string of one character with ordinal i; 0 <= i < 256.");\r
+\r
+\r
+#ifdef Py_USING_UNICODE\r
+static PyObject *\r
+builtin_unichr(PyObject *self, PyObject *args)\r
+{\r
+    int x;\r
+\r
+    if (!PyArg_ParseTuple(args, "i:unichr", &x))\r
+        return NULL;\r
+\r
+    return PyUnicode_FromOrdinal(x);\r
+}\r
+\r
+PyDoc_STRVAR(unichr_doc,\r
+"unichr(i) -> Unicode character\n\\r
+\n\\r
+Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.");\r
+#endif\r
+\r
+\r
+static PyObject *\r
+builtin_cmp(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *a, *b;\r
+    int c;\r
+\r
+    if (!PyArg_UnpackTuple(args, "cmp", 2, 2, &a, &b))\r
+        return NULL;\r
+    if (PyObject_Cmp(a, b, &c) < 0)\r
+        return NULL;\r
+    return PyInt_FromLong((long)c);\r
+}\r
+\r
+PyDoc_STRVAR(cmp_doc,\r
+"cmp(x, y) -> integer\n\\r
+\n\\r
+Return negative if x<y, zero if x==y, positive if x>y.");\r
+\r
+\r
+static PyObject *\r
+builtin_coerce(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *v, *w;\r
+    PyObject *res;\r
+\r
+    if (PyErr_WarnPy3k("coerce() not supported in 3.x", 1) < 0)\r
+        return NULL;\r
+\r
+    if (!PyArg_UnpackTuple(args, "coerce", 2, 2, &v, &w))\r
+        return NULL;\r
+    if (PyNumber_Coerce(&v, &w) < 0)\r
+        return NULL;\r
+    res = PyTuple_Pack(2, v, w);\r
+    Py_DECREF(v);\r
+    Py_DECREF(w);\r
+    return res;\r
+}\r
+\r
+PyDoc_STRVAR(coerce_doc,\r
+"coerce(x, y) -> (x1, y1)\n\\r
+\n\\r
+Return a tuple consisting of the two numeric arguments converted to\n\\r
+a common type, using the same rules as used by arithmetic operations.\n\\r
+If coercion is not possible, raise TypeError.");\r
+\r
+static PyObject *\r
+builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)\r
+{\r
+    char *str;\r
+    char *filename;\r
+    char *startstr;\r
+    int mode = -1;\r
+    int dont_inherit = 0;\r
+    int supplied_flags = 0;\r
+    int is_ast;\r
+    PyCompilerFlags cf;\r
+    PyObject *result = NULL, *cmd, *tmp = NULL;\r
+    Py_ssize_t length;\r
+    static char *kwlist[] = {"source", "filename", "mode", "flags",\r
+                             "dont_inherit", NULL};\r
+    int start[] = {Py_file_input, Py_eval_input, Py_single_input};\r
+\r
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "Oss|ii:compile",\r
+                                     kwlist, &cmd, &filename, &startstr,\r
+                                     &supplied_flags, &dont_inherit))\r
+        return NULL;\r
+\r
+    cf.cf_flags = supplied_flags;\r
+\r
+    if (supplied_flags &\r
+        ~(PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_DONT_IMPLY_DEDENT | PyCF_ONLY_AST))\r
+    {\r
+        PyErr_SetString(PyExc_ValueError,\r
+                        "compile(): unrecognised flags");\r
+        return NULL;\r
+    }\r
+    /* XXX Warn if (supplied_flags & PyCF_MASK_OBSOLETE) != 0? */\r
+\r
+    if (!dont_inherit) {\r
+        PyEval_MergeCompilerFlags(&cf);\r
+    }\r
+\r
+    if (strcmp(startstr, "exec") == 0)\r
+        mode = 0;\r
+    else if (strcmp(startstr, "eval") == 0)\r
+        mode = 1;\r
+    else if (strcmp(startstr, "single") == 0)\r
+        mode = 2;\r
+    else {\r
+        PyErr_SetString(PyExc_ValueError,\r
+                        "compile() arg 3 must be 'exec', 'eval' or 'single'");\r
+        return NULL;\r
+    }\r
+\r
+    is_ast = PyAST_Check(cmd);\r
+    if (is_ast == -1)\r
+        return NULL;\r
+    if (is_ast) {\r
+        if (supplied_flags & PyCF_ONLY_AST) {\r
+            Py_INCREF(cmd);\r
+            result = cmd;\r
+        }\r
+        else {\r
+            PyArena *arena;\r
+            mod_ty mod;\r
+\r
+            arena = PyArena_New();\r
+            if (arena == NULL)\r
+                return NULL;\r
+            mod = PyAST_obj2mod(cmd, arena, mode);\r
+            if (mod == NULL) {\r
+                PyArena_Free(arena);\r
+                return NULL;\r
+            }\r
+            result = (PyObject*)PyAST_Compile(mod, filename,\r
+                                              &cf, arena);\r
+            PyArena_Free(arena);\r
+        }\r
+        return result;\r
+    }\r
+\r
+#ifdef Py_USING_UNICODE\r
+    if (PyUnicode_Check(cmd)) {\r
+        tmp = PyUnicode_AsUTF8String(cmd);\r
+        if (tmp == NULL)\r
+            return NULL;\r
+        cmd = tmp;\r
+        cf.cf_flags |= PyCF_SOURCE_IS_UTF8;\r
+    }\r
+#endif\r
+\r
+    if (PyObject_AsReadBuffer(cmd, (const void **)&str, &length))\r
+        goto cleanup;\r
+    if ((size_t)length != strlen(str)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                        "compile() expected string without null bytes");\r
+        goto cleanup;\r
+    }\r
+    result = Py_CompileStringFlags(str, filename, start[mode], &cf);\r
+cleanup:\r
+    Py_XDECREF(tmp);\r
+    return result;\r
+}\r
+\r
+PyDoc_STRVAR(compile_doc,\r
+"compile(source, filename, mode[, flags[, dont_inherit]]) -> code object\n\\r
+\n\\r
+Compile the source string (a Python module, statement or expression)\n\\r
+into a code object that can be executed by the exec statement or eval().\n\\r
+The filename will be used for run-time error messages.\n\\r
+The mode must be 'exec' to compile a module, 'single' to compile a\n\\r
+single (interactive) statement, or 'eval' to compile an expression.\n\\r
+The flags argument, if present, controls which future statements influence\n\\r
+the compilation of the code.\n\\r
+The dont_inherit argument, if non-zero, stops the compilation inheriting\n\\r
+the effects of any future statements in effect in the code calling\n\\r
+compile; if absent or zero these statements do influence the compilation,\n\\r
+in addition to any features explicitly specified.");\r
+\r
+static PyObject *\r
+builtin_dir(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *arg = NULL;\r
+\r
+    if (!PyArg_UnpackTuple(args, "dir", 0, 1, &arg))\r
+        return NULL;\r
+    return PyObject_Dir(arg);\r
+}\r
+\r
+PyDoc_STRVAR(dir_doc,\r
+"dir([object]) -> list of strings\n"\r
+"\n"\r
+"If called without an argument, return the names in the current scope.\n"\r
+"Else, return an alphabetized list of names comprising (some of) the attributes\n"\r
+"of the given object, and of attributes reachable from it.\n"\r
+"If the object supplies a method named __dir__, it will be used; otherwise\n"\r
+"the default dir() logic is used and returns:\n"\r
+"  for a module object: the module's attributes.\n"\r
+"  for a class object:  its attributes, and recursively the attributes\n"\r
+"    of its bases.\n"\r
+"  for any other object: its attributes, its class's attributes, and\n"\r
+"    recursively the attributes of its class's base classes.");\r
+\r
+static PyObject *\r
+builtin_divmod(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *v, *w;\r
+\r
+    if (!PyArg_UnpackTuple(args, "divmod", 2, 2, &v, &w))\r
+        return NULL;\r
+    return PyNumber_Divmod(v, w);\r
+}\r
+\r
+PyDoc_STRVAR(divmod_doc,\r
+"divmod(x, y) -> (quotient, remainder)\n\\r
+\n\\r
+Return the tuple ((x-x%y)/y, x%y).  Invariant: div*y + mod == x.");\r
+\r
+\r
+static PyObject *\r
+builtin_eval(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *cmd, *result, *tmp = NULL;\r
+    PyObject *globals = Py_None, *locals = Py_None;\r
+    char *str;\r
+    PyCompilerFlags cf;\r
+\r
+    if (!PyArg_UnpackTuple(args, "eval", 1, 3, &cmd, &globals, &locals))\r
+        return NULL;\r
+    if (locals != Py_None && !PyMapping_Check(locals)) {\r
+        PyErr_SetString(PyExc_TypeError, "locals must be a mapping");\r
+        return NULL;\r
+    }\r
+    if (globals != Py_None && !PyDict_Check(globals)) {\r
+        PyErr_SetString(PyExc_TypeError, PyMapping_Check(globals) ?\r
+            "globals must be a real dict; try eval(expr, {}, mapping)"\r
+            : "globals must be a dict");\r
+        return NULL;\r
+    }\r
+    if (globals == Py_None) {\r
+        globals = PyEval_GetGlobals();\r
+        if (locals == Py_None)\r
+            locals = PyEval_GetLocals();\r
+    }\r
+    else if (locals == Py_None)\r
+        locals = globals;\r
+\r
+    if (globals == NULL || locals == NULL) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+            "eval must be given globals and locals "\r
+            "when called without a frame");\r
+        return NULL;\r
+    }\r
+\r
+    if (PyDict_GetItemString(globals, "__builtins__") == NULL) {\r
+        if (PyDict_SetItemString(globals, "__builtins__",\r
+                                 PyEval_GetBuiltins()) != 0)\r
+            return NULL;\r
+    }\r
+\r
+    if (PyCode_Check(cmd)) {\r
+        if (PyCode_GetNumFree((PyCodeObject *)cmd) > 0) {\r
+            PyErr_SetString(PyExc_TypeError,\r
+        "code object passed to eval() may not contain free variables");\r
+            return NULL;\r
+        }\r
+        return PyEval_EvalCode((PyCodeObject *) cmd, globals, locals);\r
+    }\r
+\r
+    if (!PyString_Check(cmd) &&\r
+        !PyUnicode_Check(cmd)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                   "eval() arg 1 must be a string or code object");\r
+        return NULL;\r
+    }\r
+    cf.cf_flags = 0;\r
+\r
+#ifdef Py_USING_UNICODE\r
+    if (PyUnicode_Check(cmd)) {\r
+        tmp = PyUnicode_AsUTF8String(cmd);\r
+        if (tmp == NULL)\r
+            return NULL;\r
+        cmd = tmp;\r
+        cf.cf_flags |= PyCF_SOURCE_IS_UTF8;\r
+    }\r
+#endif\r
+    if (PyString_AsStringAndSize(cmd, &str, NULL)) {\r
+        Py_XDECREF(tmp);\r
+        return NULL;\r
+    }\r
+    while (*str == ' ' || *str == '\t')\r
+        str++;\r
+\r
+    (void)PyEval_MergeCompilerFlags(&cf);\r
+    result = PyRun_StringFlags(str, Py_eval_input, globals, locals, &cf);\r
+    Py_XDECREF(tmp);\r
+    return result;\r
+}\r
+\r
+PyDoc_STRVAR(eval_doc,\r
+"eval(source[, globals[, locals]]) -> value\n\\r
+\n\\r
+Evaluate the source in the context of globals and locals.\n\\r
+The source may be a string representing a Python expression\n\\r
+or a code object as returned by compile().\n\\r
+The globals must be a dictionary and locals can be any mapping,\n\\r
+defaulting to the current globals and locals.\n\\r
+If only globals is given, locals defaults to it.\n");\r
+\r
+\r
+static PyObject *\r
+builtin_execfile(PyObject *self, PyObject *args)\r
+{\r
+    char *filename;\r
+    PyObject *globals = Py_None, *locals = Py_None;\r
+    PyObject *res;\r
+    FILE* fp = NULL;\r
+    PyCompilerFlags cf;\r
+    int exists;\r
+\r
+    if (PyErr_WarnPy3k("execfile() not supported in 3.x; use exec()",\r
+                       1) < 0)\r
+        return NULL;\r
+\r
+    if (!PyArg_ParseTuple(args, "s|O!O:execfile",\r
+                    &filename,\r
+                    &PyDict_Type, &globals,\r
+                    &locals))\r
+        return NULL;\r
+    if (locals != Py_None && !PyMapping_Check(locals)) {\r
+        PyErr_SetString(PyExc_TypeError, "locals must be a mapping");\r
+        return NULL;\r
+    }\r
+    if (globals == Py_None) {\r
+        globals = PyEval_GetGlobals();\r
+        if (locals == Py_None)\r
+            locals = PyEval_GetLocals();\r
+    }\r
+    else if (locals == Py_None)\r
+        locals = globals;\r
+    if (PyDict_GetItemString(globals, "__builtins__") == NULL) {\r
+        if (PyDict_SetItemString(globals, "__builtins__",\r
+                                 PyEval_GetBuiltins()) != 0)\r
+            return NULL;\r
+    }\r
+\r
+    exists = 0;\r
+    /* Test for existence or directory. */\r
+#if defined(PLAN9)\r
+    {\r
+        Dir *d;\r
+\r
+        if ((d = dirstat(filename))!=nil) {\r
+            if(d->mode & DMDIR)\r
+                werrstr("is a directory");\r
+            else\r
+                exists = 1;\r
+            free(d);\r
+        }\r
+    }\r
+#elif defined(RISCOS)\r
+    if (object_exists(filename)) {\r
+        if (isdir(filename))\r
+            errno = EISDIR;\r
+        else\r
+            exists = 1;\r
+    }\r
+#else   /* standard Posix */\r
+    {\r
+        struct stat s;\r
+        if (stat(filename, &s) == 0) {\r
+            if (S_ISDIR(s.st_mode))\r
+#                               if defined(PYOS_OS2) && defined(PYCC_VACPP)\r
+                            errno = EOS2ERR;\r
+#                               else\r
+                            errno = EISDIR;\r
+#                               endif\r
+            else\r
+                exists = 1;\r
+        }\r
+    }\r
+#endif\r
+\r
+    if (exists) {\r
+        Py_BEGIN_ALLOW_THREADS\r
+        fp = fopen(filename, "r" PY_STDIOTEXTMODE);\r
+        Py_END_ALLOW_THREADS\r
+\r
+        if (fp == NULL) {\r
+            exists = 0;\r
+        }\r
+    }\r
+\r
+    if (!exists) {\r
+        PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename);\r
+        return NULL;\r
+    }\r
+    cf.cf_flags = 0;\r
+    if (PyEval_MergeCompilerFlags(&cf))\r
+        res = PyRun_FileExFlags(fp, filename, Py_file_input, globals,\r
+                           locals, 1, &cf);\r
+    else\r
+        res = PyRun_FileEx(fp, filename, Py_file_input, globals,\r
+                           locals, 1);\r
+    return res;\r
+}\r
+\r
+PyDoc_STRVAR(execfile_doc,\r
+"execfile(filename[, globals[, locals]])\n\\r
+\n\\r
+Read and execute a Python script from a file.\n\\r
+The globals and locals are dictionaries, defaulting to the current\n\\r
+globals and locals.  If only globals is given, locals defaults to it.");\r
+\r
+\r
+static PyObject *\r
+builtin_getattr(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *v, *result, *dflt = NULL;\r
+    PyObject *name;\r
+\r
+    if (!PyArg_UnpackTuple(args, "getattr", 2, 3, &v, &name, &dflt))\r
+        return NULL;\r
+#ifdef Py_USING_UNICODE\r
+    if (PyUnicode_Check(name)) {\r
+        name = _PyUnicode_AsDefaultEncodedString(name, NULL);\r
+        if (name == NULL)\r
+            return NULL;\r
+    }\r
+#endif\r
+\r
+    if (!PyString_Check(name)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                        "getattr(): attribute name must be string");\r
+        return NULL;\r
+    }\r
+    result = PyObject_GetAttr(v, name);\r
+    if (result == NULL && dflt != NULL &&\r
+        PyErr_ExceptionMatches(PyExc_AttributeError))\r
+    {\r
+        PyErr_Clear();\r
+        Py_INCREF(dflt);\r
+        result = dflt;\r
+    }\r
+    return result;\r
+}\r
+\r
+PyDoc_STRVAR(getattr_doc,\r
+"getattr(object, name[, default]) -> value\n\\r
+\n\\r
+Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.\n\\r
+When a default argument is given, it is returned when the attribute doesn't\n\\r
+exist; without it, an exception is raised in that case.");\r
+\r
+\r
+static PyObject *\r
+builtin_globals(PyObject *self)\r
+{\r
+    PyObject *d;\r
+\r
+    d = PyEval_GetGlobals();\r
+    Py_XINCREF(d);\r
+    return d;\r
+}\r
+\r
+PyDoc_STRVAR(globals_doc,\r
+"globals() -> dictionary\n\\r
+\n\\r
+Return the dictionary containing the current scope's global variables.");\r
+\r
+\r
+static PyObject *\r
+builtin_hasattr(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *v;\r
+    PyObject *name;\r
+\r
+    if (!PyArg_UnpackTuple(args, "hasattr", 2, 2, &v, &name))\r
+        return NULL;\r
+#ifdef Py_USING_UNICODE\r
+    if (PyUnicode_Check(name)) {\r
+        name = _PyUnicode_AsDefaultEncodedString(name, NULL);\r
+        if (name == NULL)\r
+            return NULL;\r
+    }\r
+#endif\r
+\r
+    if (!PyString_Check(name)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                        "hasattr(): attribute name must be string");\r
+        return NULL;\r
+    }\r
+    v = PyObject_GetAttr(v, name);\r
+    if (v == NULL) {\r
+        if (!PyErr_ExceptionMatches(PyExc_Exception))\r
+            return NULL;\r
+        else {\r
+            PyErr_Clear();\r
+            Py_INCREF(Py_False);\r
+            return Py_False;\r
+        }\r
+    }\r
+    Py_DECREF(v);\r
+    Py_INCREF(Py_True);\r
+    return Py_True;\r
+}\r
+\r
+PyDoc_STRVAR(hasattr_doc,\r
+"hasattr(object, name) -> bool\n\\r
+\n\\r
+Return whether the object has an attribute with the given name.\n\\r
+(This is done by calling getattr(object, name) and catching exceptions.)");\r
+\r
+\r
+static PyObject *\r
+builtin_id(PyObject *self, PyObject *v)\r
+{\r
+    return PyLong_FromVoidPtr(v);\r
+}\r
+\r
+PyDoc_STRVAR(id_doc,\r
+"id(object) -> integer\n\\r
+\n\\r
+Return the identity of an object.  This is guaranteed to be unique among\n\\r
+simultaneously existing objects.  (Hint: it's the object's memory address.)");\r
+\r
+\r
+static PyObject *\r
+builtin_map(PyObject *self, PyObject *args)\r
+{\r
+    typedef struct {\r
+        PyObject *it;           /* the iterator object */\r
+        int saw_StopIteration;  /* bool:  did the iterator end? */\r
+    } sequence;\r
+\r
+    PyObject *func, *result;\r
+    sequence *seqs = NULL, *sqp;\r
+    Py_ssize_t n, len;\r
+    register int i, j;\r
+\r
+    n = PyTuple_Size(args);\r
+    if (n < 2) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                        "map() requires at least two args");\r
+        return NULL;\r
+    }\r
+\r
+    func = PyTuple_GetItem(args, 0);\r
+    n--;\r
+\r
+    if (func == Py_None) {\r
+        if (PyErr_WarnPy3k("map(None, ...) not supported in 3.x; "\r
+                           "use list(...)", 1) < 0)\r
+            return NULL;\r
+        if (n == 1) {\r
+            /* map(None, S) is the same as list(S). */\r
+            return PySequence_List(PyTuple_GetItem(args, 1));\r
+        }\r
+    }\r
+\r
+    /* Get space for sequence descriptors.  Must NULL out the iterator\r
+     * pointers so that jumping to Fail_2 later doesn't see trash.\r
+     */\r
+    if ((seqs = PyMem_NEW(sequence, n)) == NULL) {\r
+        PyErr_NoMemory();\r
+        return NULL;\r
+    }\r
+    for (i = 0; i < n; ++i) {\r
+        seqs[i].it = (PyObject*)NULL;\r
+        seqs[i].saw_StopIteration = 0;\r
+    }\r
+\r
+    /* Do a first pass to obtain iterators for the arguments, and set len\r
+     * to the largest of their lengths.\r
+     */\r
+    len = 0;\r
+    for (i = 0, sqp = seqs; i < n; ++i, ++sqp) {\r
+        PyObject *curseq;\r
+        Py_ssize_t curlen;\r
+\r
+        /* Get iterator. */\r
+        curseq = PyTuple_GetItem(args, i+1);\r
+        sqp->it = PyObject_GetIter(curseq);\r
+        if (sqp->it == NULL) {\r
+            static char errmsg[] =\r
+                "argument %d to map() must support iteration";\r
+            char errbuf[sizeof(errmsg) + 25];\r
+            PyOS_snprintf(errbuf, sizeof(errbuf), errmsg, i+2);\r
+            PyErr_SetString(PyExc_TypeError, errbuf);\r
+            goto Fail_2;\r
+        }\r
+\r
+        /* Update len. */\r
+        curlen = _PyObject_LengthHint(curseq, 8);\r
+        if (curlen > len)\r
+            len = curlen;\r
+    }\r
+\r
+    /* Get space for the result list. */\r
+    if ((result = (PyObject *) PyList_New(len)) == NULL)\r
+        goto Fail_2;\r
+\r
+    /* Iterate over the sequences until all have stopped. */\r
+    for (i = 0; ; ++i) {\r
+        PyObject *alist, *item=NULL, *value;\r
+        int numactive = 0;\r
+\r
+        if (func == Py_None && n == 1)\r
+            alist = NULL;\r
+        else if ((alist = PyTuple_New(n)) == NULL)\r
+            goto Fail_1;\r
+\r
+        for (j = 0, sqp = seqs; j < n; ++j, ++sqp) {\r
+            if (sqp->saw_StopIteration) {\r
+                Py_INCREF(Py_None);\r
+                item = Py_None;\r
+            }\r
+            else {\r
+                item = PyIter_Next(sqp->it);\r
+                if (item)\r
+                    ++numactive;\r
+                else {\r
+                    if (PyErr_Occurred()) {\r
+                        Py_XDECREF(alist);\r
+                        goto Fail_1;\r
+                    }\r
+                    Py_INCREF(Py_None);\r
+                    item = Py_None;\r
+                    sqp->saw_StopIteration = 1;\r
+                }\r
+            }\r
+            if (alist)\r
+                PyTuple_SET_ITEM(alist, j, item);\r
+            else\r
+                break;\r
+        }\r
+\r
+        if (!alist)\r
+            alist = item;\r
+\r
+        if (numactive == 0) {\r
+            Py_DECREF(alist);\r
+            break;\r
+        }\r
+\r
+        if (func == Py_None)\r
+            value = alist;\r
+        else {\r
+            value = PyEval_CallObject(func, alist);\r
+            Py_DECREF(alist);\r
+            if (value == NULL)\r
+                goto Fail_1;\r
+        }\r
+        if (i >= len) {\r
+            int status = PyList_Append(result, value);\r
+            Py_DECREF(value);\r
+            if (status < 0)\r
+                goto Fail_1;\r
+        }\r
+        else if (PyList_SetItem(result, i, value) < 0)\r
+            goto Fail_1;\r
+    }\r
+\r
+    if (i < len && PyList_SetSlice(result, i, len, NULL) < 0)\r
+        goto Fail_1;\r
+\r
+    goto Succeed;\r
+\r
+Fail_1:\r
+    Py_DECREF(result);\r
+Fail_2:\r
+    result = NULL;\r
+Succeed:\r
+    assert(seqs);\r
+    for (i = 0; i < n; ++i)\r
+        Py_XDECREF(seqs[i].it);\r
+    PyMem_DEL(seqs);\r
+    return result;\r
+}\r
+\r
+PyDoc_STRVAR(map_doc,\r
+"map(function, sequence[, sequence, ...]) -> list\n\\r
+\n\\r
+Return a list of the results of applying the function to the items of\n\\r
+the argument sequence(s).  If more than one sequence is given, the\n\\r
+function is called with an argument list consisting of the corresponding\n\\r
+item of each sequence, substituting None for missing values when not all\n\\r
+sequences have the same length.  If the function is None, return a list of\n\\r
+the items of the sequence (or a list of tuples if more than one sequence).");\r
+\r
+\r
+static PyObject *\r
+builtin_next(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *it, *res;\r
+    PyObject *def = NULL;\r
+\r
+    if (!PyArg_UnpackTuple(args, "next", 1, 2, &it, &def))\r
+        return NULL;\r
+    if (!PyIter_Check(it)) {\r
+        PyErr_Format(PyExc_TypeError,\r
+            "%.200s object is not an iterator",\r
+            it->ob_type->tp_name);\r
+        return NULL;\r
+    }\r
+\r
+    res = (*it->ob_type->tp_iternext)(it);\r
+    if (res != NULL) {\r
+        return res;\r
+    } else if (def != NULL) {\r
+        if (PyErr_Occurred()) {\r
+            if (!PyErr_ExceptionMatches(PyExc_StopIteration))\r
+                return NULL;\r
+            PyErr_Clear();\r
+        }\r
+        Py_INCREF(def);\r
+        return def;\r
+    } else if (PyErr_Occurred()) {\r
+        return NULL;\r
+    } else {\r
+        PyErr_SetNone(PyExc_StopIteration);\r
+        return NULL;\r
+    }\r
+}\r
+\r
+PyDoc_STRVAR(next_doc,\r
+"next(iterator[, default])\n\\r
+\n\\r
+Return the next item from the iterator. If default is given and the iterator\n\\r
+is exhausted, it is returned instead of raising StopIteration.");\r
+\r
+\r
+static PyObject *\r
+builtin_setattr(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *v;\r
+    PyObject *name;\r
+    PyObject *value;\r
+\r
+    if (!PyArg_UnpackTuple(args, "setattr", 3, 3, &v, &name, &value))\r
+        return NULL;\r
+    if (PyObject_SetAttr(v, name, value) != 0)\r
+        return NULL;\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+PyDoc_STRVAR(setattr_doc,\r
+"setattr(object, name, value)\n\\r
+\n\\r
+Set a named attribute on an object; setattr(x, 'y', v) is equivalent to\n\\r
+``x.y = v''.");\r
+\r
+\r
+static PyObject *\r
+builtin_delattr(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *v;\r
+    PyObject *name;\r
+\r
+    if (!PyArg_UnpackTuple(args, "delattr", 2, 2, &v, &name))\r
+        return NULL;\r
+    if (PyObject_SetAttr(v, name, (PyObject *)NULL) != 0)\r
+        return NULL;\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+PyDoc_STRVAR(delattr_doc,\r
+"delattr(object, name)\n\\r
+\n\\r
+Delete a named attribute on an object; delattr(x, 'y') is equivalent to\n\\r
+``del x.y''.");\r
+\r
+\r
+static PyObject *\r
+builtin_hash(PyObject *self, PyObject *v)\r
+{\r
+    long x;\r
+\r
+    x = PyObject_Hash(v);\r
+    if (x == -1)\r
+        return NULL;\r
+    return PyInt_FromLong(x);\r
+}\r
+\r
+PyDoc_STRVAR(hash_doc,\r
+"hash(object) -> integer\n\\r
+\n\\r
+Return a hash value for the object.  Two objects with the same value have\n\\r
+the same hash value.  The reverse is not necessarily true, but likely.");\r
+\r
+\r
+static PyObject *\r
+builtin_hex(PyObject *self, PyObject *v)\r
+{\r
+    PyNumberMethods *nb;\r
+    PyObject *res;\r
+\r
+    if ((nb = v->ob_type->tp_as_number) == NULL ||\r
+        nb->nb_hex == NULL) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                   "hex() argument can't be converted to hex");\r
+        return NULL;\r
+    }\r
+    res = (*nb->nb_hex)(v);\r
+    if (res && !PyString_Check(res)) {\r
+        PyErr_Format(PyExc_TypeError,\r
+                     "__hex__ returned non-string (type %.200s)",\r
+                     res->ob_type->tp_name);\r
+        Py_DECREF(res);\r
+        return NULL;\r
+    }\r
+    return res;\r
+}\r
+\r
+PyDoc_STRVAR(hex_doc,\r
+"hex(number) -> string\n\\r
+\n\\r
+Return the hexadecimal representation of an integer or long integer.");\r
+\r
+\r
+static PyObject *builtin_raw_input(PyObject *, PyObject *);\r
+\r
+static PyObject *\r
+builtin_input(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *line;\r
+    char *str;\r
+    PyObject *res;\r
+    PyObject *globals, *locals;\r
+    PyCompilerFlags cf;\r
+\r
+    line = builtin_raw_input(self, args);\r
+    if (line == NULL)\r
+        return line;\r
+    if (!PyArg_Parse(line, "s;embedded '\\0' in input line", &str))\r
+        return NULL;\r
+    while (*str == ' ' || *str == '\t')\r
+                    str++;\r
+    globals = PyEval_GetGlobals();\r
+    locals = PyEval_GetLocals();\r
+    if (PyDict_GetItemString(globals, "__builtins__") == NULL) {\r
+        if (PyDict_SetItemString(globals, "__builtins__",\r
+                                 PyEval_GetBuiltins()) != 0)\r
+            return NULL;\r
+    }\r
+    cf.cf_flags = 0;\r
+    PyEval_MergeCompilerFlags(&cf);\r
+    res = PyRun_StringFlags(str, Py_eval_input, globals, locals, &cf);\r
+    Py_DECREF(line);\r
+    return res;\r
+}\r
+\r
+PyDoc_STRVAR(input_doc,\r
+"input([prompt]) -> value\n\\r
+\n\\r
+Equivalent to eval(raw_input(prompt)).");\r
+\r
+\r
+static PyObject *\r
+builtin_intern(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *s;\r
+    if (!PyArg_ParseTuple(args, "S:intern", &s))\r
+        return NULL;\r
+    if (!PyString_CheckExact(s)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                        "can't intern subclass of string");\r
+        return NULL;\r
+    }\r
+    Py_INCREF(s);\r
+    PyString_InternInPlace(&s);\r
+    return s;\r
+}\r
+\r
+PyDoc_STRVAR(intern_doc,\r
+"intern(string) -> string\n\\r
+\n\\r
+``Intern'' the given string.  This enters the string in the (global)\n\\r
+table of interned strings whose purpose is to speed up dictionary lookups.\n\\r
+Return the string itself or the previously interned string object with the\n\\r
+same value.");\r
+\r
+\r
+static PyObject *\r
+builtin_iter(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *v, *w = NULL;\r
+\r
+    if (!PyArg_UnpackTuple(args, "iter", 1, 2, &v, &w))\r
+        return NULL;\r
+    if (w == NULL)\r
+        return PyObject_GetIter(v);\r
+    if (!PyCallable_Check(v)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                        "iter(v, w): v must be callable");\r
+        return NULL;\r
+    }\r
+    return PyCallIter_New(v, w);\r
+}\r
+\r
+PyDoc_STRVAR(iter_doc,\r
+"iter(collection) -> iterator\n\\r
+iter(callable, sentinel) -> iterator\n\\r
+\n\\r
+Get an iterator from an object.  In the first form, the argument must\n\\r
+supply its own iterator, or be a sequence.\n\\r
+In the second form, the callable is called until it returns the sentinel.");\r
+\r
+\r
+static PyObject *\r
+builtin_len(PyObject *self, PyObject *v)\r
+{\r
+    Py_ssize_t res;\r
+\r
+    res = PyObject_Size(v);\r
+    if (res < 0 && PyErr_Occurred())\r
+        return NULL;\r
+    return PyInt_FromSsize_t(res);\r
+}\r
+\r
+PyDoc_STRVAR(len_doc,\r
+"len(object) -> integer\n\\r
+\n\\r
+Return the number of items of a sequence or collection.");\r
+\r
+\r
+static PyObject *\r
+builtin_locals(PyObject *self)\r
+{\r
+    PyObject *d;\r
+\r
+    d = PyEval_GetLocals();\r
+    Py_XINCREF(d);\r
+    return d;\r
+}\r
+\r
+PyDoc_STRVAR(locals_doc,\r
+"locals() -> dictionary\n\\r
+\n\\r
+Update and return a dictionary containing the current scope's local variables.");\r
+\r
+\r
+static PyObject *\r
+min_max(PyObject *args, PyObject *kwds, int op)\r
+{\r
+    PyObject *v, *it, *item, *val, *maxitem, *maxval, *keyfunc=NULL;\r
+    const char *name = op == Py_LT ? "min" : "max";\r
+\r
+    if (PyTuple_Size(args) > 1)\r
+        v = args;\r
+    else if (!PyArg_UnpackTuple(args, (char *)name, 1, 1, &v))\r
+        return NULL;\r
+\r
+    if (kwds != NULL && PyDict_Check(kwds) && PyDict_Size(kwds)) {\r
+        keyfunc = PyDict_GetItemString(kwds, "key");\r
+        if (PyDict_Size(kwds)!=1  ||  keyfunc == NULL) {\r
+            PyErr_Format(PyExc_TypeError,\r
+                "%s() got an unexpected keyword argument", name);\r
+            return NULL;\r
+        }\r
+        Py_INCREF(keyfunc);\r
+    }\r
+\r
+    it = PyObject_GetIter(v);\r
+    if (it == NULL) {\r
+        Py_XDECREF(keyfunc);\r
+        return NULL;\r
+    }\r
+\r
+    maxitem = NULL; /* the result */\r
+    maxval = NULL;  /* the value associated with the result */\r
+    while (( item = PyIter_Next(it) )) {\r
+        /* get the value from the key function */\r
+        if (keyfunc != NULL) {\r
+            val = PyObject_CallFunctionObjArgs(keyfunc, item, NULL);\r
+            if (val == NULL)\r
+                goto Fail_it_item;\r
+        }\r
+        /* no key function; the value is the item */\r
+        else {\r
+            val = item;\r
+            Py_INCREF(val);\r
+        }\r
+\r
+        /* maximum value and item are unset; set them */\r
+        if (maxval == NULL) {\r
+            maxitem = item;\r
+            maxval = val;\r
+        }\r
+        /* maximum value and item are set; update them as necessary */\r
+        else {\r
+            int cmp = PyObject_RichCompareBool(val, maxval, op);\r
+            if (cmp < 0)\r
+                goto Fail_it_item_and_val;\r
+            else if (cmp > 0) {\r
+                Py_DECREF(maxval);\r
+                Py_DECREF(maxitem);\r
+                maxval = val;\r
+                maxitem = item;\r
+            }\r
+            else {\r
+                Py_DECREF(item);\r
+                Py_DECREF(val);\r
+            }\r
+        }\r
+    }\r
+    if (PyErr_Occurred())\r
+        goto Fail_it;\r
+    if (maxval == NULL) {\r
+        PyErr_Format(PyExc_ValueError,\r
+                     "%s() arg is an empty sequence", name);\r
+        assert(maxitem == NULL);\r
+    }\r
+    else\r
+        Py_DECREF(maxval);\r
+    Py_DECREF(it);\r
+    Py_XDECREF(keyfunc);\r
+    return maxitem;\r
+\r
+Fail_it_item_and_val:\r
+    Py_DECREF(val);\r
+Fail_it_item:\r
+    Py_DECREF(item);\r
+Fail_it:\r
+    Py_XDECREF(maxval);\r
+    Py_XDECREF(maxitem);\r
+    Py_DECREF(it);\r
+    Py_XDECREF(keyfunc);\r
+    return NULL;\r
+}\r
+\r
+static PyObject *\r
+builtin_min(PyObject *self, PyObject *args, PyObject *kwds)\r
+{\r
+    return min_max(args, kwds, Py_LT);\r
+}\r
+\r
+PyDoc_STRVAR(min_doc,\r
+"min(iterable[, key=func]) -> value\n\\r
+min(a, b, c, ...[, key=func]) -> value\n\\r
+\n\\r
+With a single iterable argument, return its smallest item.\n\\r
+With two or more arguments, return the smallest argument.");\r
+\r
+\r
+static PyObject *\r
+builtin_max(PyObject *self, PyObject *args, PyObject *kwds)\r
+{\r
+    return min_max(args, kwds, Py_GT);\r
+}\r
+\r
+PyDoc_STRVAR(max_doc,\r
+"max(iterable[, key=func]) -> value\n\\r
+max(a, b, c, ...[, key=func]) -> value\n\\r
+\n\\r
+With a single iterable argument, return its largest item.\n\\r
+With two or more arguments, return the largest argument.");\r
+\r
+\r
+static PyObject *\r
+builtin_oct(PyObject *self, PyObject *v)\r
+{\r
+    PyNumberMethods *nb;\r
+    PyObject *res;\r
+\r
+    if (v == NULL || (nb = v->ob_type->tp_as_number) == NULL ||\r
+        nb->nb_oct == NULL) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                   "oct() argument can't be converted to oct");\r
+        return NULL;\r
+    }\r
+    res = (*nb->nb_oct)(v);\r
+    if (res && !PyString_Check(res)) {\r
+        PyErr_Format(PyExc_TypeError,\r
+                     "__oct__ returned non-string (type %.200s)",\r
+                     res->ob_type->tp_name);\r
+        Py_DECREF(res);\r
+        return NULL;\r
+    }\r
+    return res;\r
+}\r
+\r
+PyDoc_STRVAR(oct_doc,\r
+"oct(number) -> string\n\\r
+\n\\r
+Return the octal representation of an integer or long integer.");\r
+\r
+\r
+static PyObject *\r
+builtin_open(PyObject *self, PyObject *args, PyObject *kwds)\r
+{\r
+    return PyObject_Call((PyObject*)&PyFile_Type, args, kwds);\r
+}\r
+\r
+PyDoc_STRVAR(open_doc,\r
+"open(name[, mode[, buffering]]) -> file object\n\\r
+\n\\r
+Open a file using the file() type, returns a file object.  This is the\n\\r
+preferred way to open a file.  See file.__doc__ for further information.");\r
+\r
+\r
+static PyObject *\r
+builtin_ord(PyObject *self, PyObject* obj)\r
+{\r
+    long ord;\r
+    Py_ssize_t size;\r
+\r
+    if (PyString_Check(obj)) {\r
+        size = PyString_GET_SIZE(obj);\r
+        if (size == 1) {\r
+            ord = (long)((unsigned char)*PyString_AS_STRING(obj));\r
+            return PyInt_FromLong(ord);\r
+        }\r
+    } else if (PyByteArray_Check(obj)) {\r
+        size = PyByteArray_GET_SIZE(obj);\r
+        if (size == 1) {\r
+            ord = (long)((unsigned char)*PyByteArray_AS_STRING(obj));\r
+            return PyInt_FromLong(ord);\r
+        }\r
+\r
+#ifdef Py_USING_UNICODE\r
+    } else if (PyUnicode_Check(obj)) {\r
+        size = PyUnicode_GET_SIZE(obj);\r
+        if (size == 1) {\r
+            ord = (long)*PyUnicode_AS_UNICODE(obj);\r
+            return PyInt_FromLong(ord);\r
+        }\r
+#endif\r
+    } else {\r
+        PyErr_Format(PyExc_TypeError,\r
+                     "ord() expected string of length 1, but " \\r
+                     "%.200s found", obj->ob_type->tp_name);\r
+        return NULL;\r
+    }\r
+\r
+    PyErr_Format(PyExc_TypeError,\r
+                 "ord() expected a character, "\r
+                 "but string of length %zd found",\r
+                 size);\r
+    return NULL;\r
+}\r
+\r
+PyDoc_STRVAR(ord_doc,\r
+"ord(c) -> integer\n\\r
+\n\\r
+Return the integer ordinal of a one-character string.");\r
+\r
+\r
+static PyObject *\r
+builtin_pow(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *v, *w, *z = Py_None;\r
+\r
+    if (!PyArg_UnpackTuple(args, "pow", 2, 3, &v, &w, &z))\r
+        return NULL;\r
+    return PyNumber_Power(v, w, z);\r
+}\r
+\r
+PyDoc_STRVAR(pow_doc,\r
+"pow(x, y[, z]) -> number\n\\r
+\n\\r
+With two arguments, equivalent to x**y.  With three arguments,\n\\r
+equivalent to (x**y) % z, but may be more efficient (e.g. for longs).");\r
+\r
+\r
+static PyObject *\r
+builtin_print(PyObject *self, PyObject *args, PyObject *kwds)\r
+{\r
+    static char *kwlist[] = {"sep", "end", "file", 0};\r
+    static PyObject *dummy_args = NULL;\r
+    static PyObject *unicode_newline = NULL, *unicode_space = NULL;\r
+    static PyObject *str_newline = NULL, *str_space = NULL;\r
+    PyObject *newline, *space;\r
+    PyObject *sep = NULL, *end = NULL, *file = NULL;\r
+    int i, err, use_unicode = 0;\r
+\r
+    if (dummy_args == NULL) {\r
+        if (!(dummy_args = PyTuple_New(0)))\r
+            return NULL;\r
+    }\r
+    if (str_newline == NULL) {\r
+        str_newline = PyString_FromString("\n");\r
+        if (str_newline == NULL)\r
+            return NULL;\r
+        str_space = PyString_FromString(" ");\r
+        if (str_space == NULL) {\r
+            Py_CLEAR(str_newline);\r
+            return NULL;\r
+        }\r
+#ifdef Py_USING_UNICODE\r
+        unicode_newline = PyUnicode_FromString("\n");\r
+        if (unicode_newline == NULL) {\r
+            Py_CLEAR(str_newline);\r
+            Py_CLEAR(str_space);\r
+            return NULL;\r
+        }\r
+        unicode_space = PyUnicode_FromString(" ");\r
+        if (unicode_space == NULL) {\r
+            Py_CLEAR(str_newline);\r
+            Py_CLEAR(str_space);\r
+            Py_CLEAR(unicode_space);\r
+            return NULL;\r
+        }\r
+#endif\r
+    }\r
+    if (!PyArg_ParseTupleAndKeywords(dummy_args, kwds, "|OOO:print",\r
+                                     kwlist, &sep, &end, &file))\r
+        return NULL;\r
+    if (file == NULL || file == Py_None) {\r
+        file = PySys_GetObject("stdout");\r
+        /* sys.stdout may be None when FILE* stdout isn't connected */\r
+        if (file == Py_None)\r
+            Py_RETURN_NONE;\r
+    }\r
+    if (sep == Py_None) {\r
+        sep = NULL;\r
+    }\r
+    else if (sep) {\r
+        if (PyUnicode_Check(sep)) {\r
+            use_unicode = 1;\r
+        }\r
+        else if (!PyString_Check(sep)) {\r
+            PyErr_Format(PyExc_TypeError,\r
+                         "sep must be None, str or unicode, not %.200s",\r
+                         sep->ob_type->tp_name);\r
+            return NULL;\r
+        }\r
+    }\r
+    if (end == Py_None)\r
+        end = NULL;\r
+    else if (end) {\r
+        if (PyUnicode_Check(end)) {\r
+            use_unicode = 1;\r
+        }\r
+        else if (!PyString_Check(end)) {\r
+            PyErr_Format(PyExc_TypeError,\r
+                         "end must be None, str or unicode, not %.200s",\r
+                         end->ob_type->tp_name);\r
+            return NULL;\r
+        }\r
+    }\r
+\r
+    if (!use_unicode) {\r
+        for (i = 0; i < PyTuple_Size(args); i++) {\r
+            if (PyUnicode_Check(PyTuple_GET_ITEM(args, i))) {\r
+                use_unicode = 1;\r
+                break;\r
+            }\r
+        }\r
+    }\r
+    if (use_unicode) {\r
+        newline = unicode_newline;\r
+        space = unicode_space;\r
+    }\r
+    else {\r
+        newline = str_newline;\r
+        space = str_space;\r
+    }\r
+\r
+    for (i = 0; i < PyTuple_Size(args); i++) {\r
+        if (i > 0) {\r
+            if (sep == NULL)\r
+                err = PyFile_WriteObject(space, file,\r
+                                         Py_PRINT_RAW);\r
+            else\r
+                err = PyFile_WriteObject(sep, file,\r
+                                         Py_PRINT_RAW);\r
+            if (err)\r
+                return NULL;\r
+        }\r
+        err = PyFile_WriteObject(PyTuple_GetItem(args, i), file,\r
+                                 Py_PRINT_RAW);\r
+        if (err)\r
+            return NULL;\r
+    }\r
+\r
+    if (end == NULL)\r
+        err = PyFile_WriteObject(newline, file, Py_PRINT_RAW);\r
+    else\r
+        err = PyFile_WriteObject(end, file, Py_PRINT_RAW);\r
+    if (err)\r
+        return NULL;\r
+\r
+    Py_RETURN_NONE;\r
+}\r
+\r
+PyDoc_STRVAR(print_doc,\r
+"print(value, ..., sep=' ', end='\\n', file=sys.stdout)\n\\r
+\n\\r
+Prints the values to a stream, or to sys.stdout by default.\n\\r
+Optional keyword arguments:\n\\r
+file: a file-like object (stream); defaults to the current sys.stdout.\n\\r
+sep:  string inserted between values, default a space.\n\\r
+end:  string appended after the last value, default a newline.");\r
+\r
+\r
+/* Return number of items in range (lo, hi, step), when arguments are\r
+ * PyInt or PyLong objects.  step > 0 required.  Return a value < 0 if\r
+ * & only if the true value is too large to fit in a signed long.\r
+ * Arguments MUST return 1 with either PyInt_Check() or\r
+ * PyLong_Check().  Return -1 when there is an error.\r
+ */\r
+static long\r
+get_len_of_range_longs(PyObject *lo, PyObject *hi, PyObject *step)\r
+{\r
+    /* -------------------------------------------------------------\r
+    Algorithm is equal to that of get_len_of_range(), but it operates\r
+    on PyObjects (which are assumed to be PyLong or PyInt objects).\r
+    ---------------------------------------------------------------*/\r
+    long n;\r
+    PyObject *diff = NULL;\r
+    PyObject *one = NULL;\r
+    PyObject *tmp1 = NULL, *tmp2 = NULL, *tmp3 = NULL;\r
+        /* holds sub-expression evaluations */\r
+\r
+    /* if (lo >= hi), return length of 0. */\r
+    if (PyObject_Compare(lo, hi) >= 0)\r
+        return 0;\r
+\r
+    if ((one = PyLong_FromLong(1L)) == NULL)\r
+        goto Fail;\r
+\r
+    if ((tmp1 = PyNumber_Subtract(hi, lo)) == NULL)\r
+        goto Fail;\r
+\r
+    if ((diff = PyNumber_Subtract(tmp1, one)) == NULL)\r
+        goto Fail;\r
+\r
+    if ((tmp2 = PyNumber_FloorDivide(diff, step)) == NULL)\r
+        goto Fail;\r
+\r
+    if ((tmp3 = PyNumber_Add(tmp2, one)) == NULL)\r
+        goto Fail;\r
+\r
+    n = PyLong_AsLong(tmp3);\r
+    if (PyErr_Occurred()) {  /* Check for Overflow */\r
+        PyErr_Clear();\r
+        goto Fail;\r
+    }\r
+\r
+    Py_DECREF(tmp3);\r
+    Py_DECREF(tmp2);\r
+    Py_DECREF(diff);\r
+    Py_DECREF(tmp1);\r
+    Py_DECREF(one);\r
+    return n;\r
+\r
+  Fail:\r
+    Py_XDECREF(tmp3);\r
+    Py_XDECREF(tmp2);\r
+    Py_XDECREF(diff);\r
+    Py_XDECREF(tmp1);\r
+    Py_XDECREF(one);\r
+    return -1;\r
+}\r
+\r
+/* Helper function for handle_range_longs.  If arg is int or long\r
+   object, returns it with incremented reference count.  If arg is\r
+   float, raises type error. As a last resort, creates a new int by\r
+   calling arg type's nb_int method if it is defined.  Returns NULL\r
+   and sets exception on error.\r
+\r
+   Returns a new reference to an int object. */\r
+static PyObject *\r
+get_range_long_argument(PyObject *arg, const char *name)\r
+{\r
+    PyObject *v;\r
+    PyNumberMethods *nb;\r
+    if (PyInt_Check(arg) || PyLong_Check(arg)) {\r
+        Py_INCREF(arg);\r
+        return arg;\r
+    }\r
+    if (PyFloat_Check(arg) ||\r
+        (nb = Py_TYPE(arg)->tp_as_number) == NULL ||\r
+        nb->nb_int == NULL) {\r
+        PyErr_Format(PyExc_TypeError,\r
+                     "range() integer %s argument expected, got %s.",\r
+                     name, arg->ob_type->tp_name);\r
+        return NULL;\r
+    }\r
+    v = nb->nb_int(arg);\r
+    if (v == NULL)\r
+        return NULL;\r
+    if (PyInt_Check(v) || PyLong_Check(v))\r
+        return v;\r
+    Py_DECREF(v);\r
+    PyErr_SetString(PyExc_TypeError,\r
+                    "__int__ should return int object");\r
+    return NULL;\r
+}\r
+\r
+/* An extension of builtin_range() that handles the case when PyLong\r
+ * arguments are given. */\r
+static PyObject *\r
+handle_range_longs(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *ilow = NULL;\r
+    PyObject *ihigh = NULL;\r
+    PyObject *istep = NULL;\r
+\r
+    PyObject *low = NULL;\r
+    PyObject *high = NULL;\r
+    PyObject *step = NULL;\r
+\r
+    PyObject *curnum = NULL;\r
+    PyObject *v = NULL;\r
+    long bign;\r
+    Py_ssize_t i, n;\r
+    int cmp_result;\r
+\r
+    PyObject *zero = PyLong_FromLong(0);\r
+\r
+    if (zero == NULL)\r
+        return NULL;\r
+\r
+    if (!PyArg_UnpackTuple(args, "range", 1, 3, &ilow, &ihigh, &istep)) {\r
+        Py_DECREF(zero);\r
+        return NULL;\r
+    }\r
+\r
+    /* Figure out which way we were called, supply defaults, and be\r
+     * sure to incref everything so that the decrefs at the end\r
+     * are correct. NB: ilow, ihigh and istep are borrowed references.\r
+     */\r
+    assert(ilow != NULL);\r
+    if (ihigh == NULL) {\r
+        /* only 1 arg -- it's the upper limit */\r
+        ihigh = ilow;\r
+        ilow = NULL;\r
+    }\r
+\r
+    /* convert ihigh if necessary */\r
+    assert(ihigh != NULL);\r
+    high = get_range_long_argument(ihigh, "end");\r
+    if (high == NULL)\r
+        goto Fail;\r
+\r
+    /* ihigh correct now; do ilow */\r
+    if (ilow == NULL) {\r
+        Py_INCREF(zero);\r
+        low = zero;\r
+    }\r
+    else {\r
+        low = get_range_long_argument(ilow, "start");\r
+        if (low == NULL)\r
+            goto Fail;\r
+    }\r
+\r
+    /* ilow and ihigh correct now; do istep */\r
+    if (istep == NULL)\r
+        step = PyLong_FromLong(1);\r
+    else\r
+        step = get_range_long_argument(istep, "step");\r
+    if (step == NULL)\r
+        goto Fail;\r
+\r
+    if (PyObject_Cmp(step, zero, &cmp_result) == -1)\r
+        goto Fail;\r
+\r
+    if (cmp_result == 0) {\r
+        PyErr_SetString(PyExc_ValueError,\r
+                        "range() step argument must not be zero");\r
+        goto Fail;\r
+    }\r
+\r
+    if (cmp_result > 0)\r
+        bign = get_len_of_range_longs(low, high, step);\r
+    else {\r
+        PyObject *neg_step = PyNumber_Negative(step);\r
+        if (neg_step == NULL)\r
+            goto Fail;\r
+        bign = get_len_of_range_longs(high, low, neg_step);\r
+        Py_DECREF(neg_step);\r
+    }\r
+\r
+    n = (Py_ssize_t)bign;\r
+    if (bign < 0 || (long)n != bign) {\r
+        PyErr_SetString(PyExc_OverflowError,\r
+                        "range() result has too many items");\r
+        goto Fail;\r
+    }\r
+\r
+    v = PyList_New(n);\r
+    if (v == NULL)\r
+        goto Fail;\r
+\r
+    curnum = low;\r
+    Py_INCREF(curnum);\r
+\r
+    for (i = 0; i < n; i++) {\r
+        PyObject *w = PyNumber_Long(curnum);\r
+        PyObject *tmp_num;\r
+        if (w == NULL)\r
+            goto Fail;\r
+\r
+        PyList_SET_ITEM(v, i, w);\r
+\r
+        tmp_num = PyNumber_Add(curnum, step);\r
+        if (tmp_num == NULL)\r
+            goto Fail;\r
+\r
+        Py_DECREF(curnum);\r
+        curnum = tmp_num;\r
+    }\r
+    Py_DECREF(low);\r
+    Py_DECREF(high);\r
+    Py_DECREF(step);\r
+    Py_DECREF(zero);\r
+    Py_DECREF(curnum);\r
+    return v;\r
+\r
+  Fail:\r
+    Py_XDECREF(low);\r
+    Py_XDECREF(high);\r
+    Py_XDECREF(step);\r
+    Py_DECREF(zero);\r
+    Py_XDECREF(curnum);\r
+    Py_XDECREF(v);\r
+    return NULL;\r
+}\r
+\r
+/* Return number of items in range/xrange (lo, hi, step).  step > 0\r
+ * required.  Return a value < 0 if & only if the true value is too\r
+ * large to fit in a signed long.\r
+ */\r
+static long\r
+get_len_of_range(long lo, long hi, long step)\r
+{\r
+    /* -------------------------------------------------------------\r
+    If lo >= hi, the range is empty.\r
+    Else if n values are in the range, the last one is\r
+    lo + (n-1)*step, which must be <= hi-1.  Rearranging,\r
+    n <= (hi - lo - 1)/step + 1, so taking the floor of the RHS gives\r
+    the proper value.  Since lo < hi in this case, hi-lo-1 >= 0, so\r
+    the RHS is non-negative and so truncation is the same as the\r
+    floor.  Letting M be the largest positive long, the worst case\r
+    for the RHS numerator is hi=M, lo=-M-1, and then\r
+    hi-lo-1 = M-(-M-1)-1 = 2*M.  Therefore unsigned long has enough\r
+    precision to compute the RHS exactly.\r
+    ---------------------------------------------------------------*/\r
+    long n = 0;\r
+    if (lo < hi) {\r
+        unsigned long uhi = (unsigned long)hi;\r
+        unsigned long ulo = (unsigned long)lo;\r
+        unsigned long diff = uhi - ulo - 1;\r
+        n = (long)(diff / (unsigned long)step + 1);\r
+    }\r
+    return n;\r
+}\r
+\r
+static PyObject *\r
+builtin_range(PyObject *self, PyObject *args)\r
+{\r
+    long ilow = 0, ihigh = 0, istep = 1;\r
+    long bign;\r
+    Py_ssize_t i, n;\r
+\r
+    PyObject *v;\r
+\r
+    if (PyTuple_Size(args) <= 1) {\r
+        if (!PyArg_ParseTuple(args,\r
+                        "l;range() requires 1-3 int arguments",\r
+                        &ihigh)) {\r
+            PyErr_Clear();\r
+            return handle_range_longs(self, args);\r
+        }\r
+    }\r
+    else {\r
+        if (!PyArg_ParseTuple(args,\r
+                        "ll|l;range() requires 1-3 int arguments",\r
+                        &ilow, &ihigh, &istep)) {\r
+            PyErr_Clear();\r
+            return handle_range_longs(self, args);\r
+        }\r
+    }\r
+    if (istep == 0) {\r
+        PyErr_SetString(PyExc_ValueError,\r
+                        "range() step argument must not be zero");\r
+        return NULL;\r
+    }\r
+    if (istep > 0)\r
+        bign = get_len_of_range(ilow, ihigh, istep);\r
+    else\r
+        bign = get_len_of_range(ihigh, ilow, -istep);\r
+    n = (Py_ssize_t)bign;\r
+    if (bign < 0 || (long)n != bign) {\r
+        PyErr_SetString(PyExc_OverflowError,\r
+                        "range() result has too many items");\r
+        return NULL;\r
+    }\r
+    v = PyList_New(n);\r
+    if (v == NULL)\r
+        return NULL;\r
+    for (i = 0; i < n; i++) {\r
+        PyObject *w = PyInt_FromLong(ilow);\r
+        if (w == NULL) {\r
+            Py_DECREF(v);\r
+            return NULL;\r
+        }\r
+        PyList_SET_ITEM(v, i, w);\r
+        ilow += istep;\r
+    }\r
+    return v;\r
+}\r
+\r
+PyDoc_STRVAR(range_doc,\r
+"range(stop) -> list of integers\n\\r
+range(start, stop[, step]) -> list of integers\n\\r
+\n\\r
+Return a list containing an arithmetic progression of integers.\n\\r
+range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.\n\\r
+When step is given, it specifies the increment (or decrement).\n\\r
+For example, range(4) returns [0, 1, 2, 3].  The end point is omitted!\n\\r
+These are exactly the valid indices for a list of 4 elements.");\r
+\r
+\r
+static PyObject *\r
+builtin_raw_input(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *v = NULL;\r
+    PyObject *fin = PySys_GetObject("stdin");\r
+    PyObject *fout = PySys_GetObject("stdout");\r
+\r
+    if (!PyArg_UnpackTuple(args, "[raw_]input", 0, 1, &v))\r
+        return NULL;\r
+\r
+    if (fin == NULL) {\r
+        PyErr_SetString(PyExc_RuntimeError, "[raw_]input: lost sys.stdin");\r
+        return NULL;\r
+    }\r
+    if (fout == NULL) {\r
+        PyErr_SetString(PyExc_RuntimeError, "[raw_]input: lost sys.stdout");\r
+        return NULL;\r
+    }\r
+    if (PyFile_SoftSpace(fout, 0)) {\r
+        if (PyFile_WriteString(" ", fout) != 0)\r
+            return NULL;\r
+    }\r
+    if (PyFile_AsFile(fin) && PyFile_AsFile(fout)\r
+        && isatty(fileno(PyFile_AsFile(fin)))\r
+        && isatty(fileno(PyFile_AsFile(fout)))) {\r
+        PyObject *po;\r
+        char *prompt;\r
+        char *s;\r
+        PyObject *result;\r
+        if (v != NULL) {\r
+            po = PyObject_Str(v);\r
+            if (po == NULL)\r
+                return NULL;\r
+            prompt = PyString_AsString(po);\r
+            if (prompt == NULL)\r
+                return NULL;\r
+        }\r
+        else {\r
+            po = NULL;\r
+            prompt = "";\r
+        }\r
+        s = PyOS_Readline(PyFile_AsFile(fin), PyFile_AsFile(fout),\r
+                          prompt);\r
+        Py_XDECREF(po);\r
+        if (s == NULL) {\r
+            if (!PyErr_Occurred())\r
+                PyErr_SetNone(PyExc_KeyboardInterrupt);\r
+            return NULL;\r
+        }\r
+        if (*s == '\0') {\r
+            PyErr_SetNone(PyExc_EOFError);\r
+            result = NULL;\r
+        }\r
+        else { /* strip trailing '\n' */\r
+            size_t len = strlen(s);\r
+            if (len > PY_SSIZE_T_MAX) {\r
+                PyErr_SetString(PyExc_OverflowError,\r
+                                "[raw_]input: input too long");\r
+                result = NULL;\r
+            }\r
+            else {\r
+                result = PyString_FromStringAndSize(s, len-1);\r
+            }\r
+        }\r
+        PyMem_FREE(s);\r
+        return result;\r
+    }\r
+    if (v != NULL) {\r
+        if (PyFile_WriteObject(v, fout, Py_PRINT_RAW) != 0)\r
+            return NULL;\r
+    }\r
+    return PyFile_GetLine(fin, -1);\r
+}\r
+\r
+PyDoc_STRVAR(raw_input_doc,\r
+"raw_input([prompt]) -> string\n\\r
+\n\\r
+Read a string from standard input.  The trailing newline is stripped.\n\\r
+If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.\n\\r
+On Unix, GNU readline is used if enabled.  The prompt string, if given,\n\\r
+is printed without a trailing newline before reading.");\r
+\r
+\r
+static PyObject *\r
+builtin_reduce(PyObject *self, PyObject *args)\r
+{\r
+    static PyObject *functools_reduce = NULL;\r
+\r
+    if (PyErr_WarnPy3k("reduce() not supported in 3.x; "\r
+                       "use functools.reduce()", 1) < 0)\r
+        return NULL;\r
+\r
+    if (functools_reduce == NULL) {\r
+        PyObject *functools = PyImport_ImportModule("functools");\r
+        if (functools == NULL)\r
+            return NULL;\r
+        functools_reduce = PyObject_GetAttrString(functools, "reduce");\r
+        Py_DECREF(functools);\r
+        if (functools_reduce == NULL)\r
+            return NULL;\r
+    }\r
+    return PyObject_Call(functools_reduce, args, NULL);\r
+}\r
+\r
+PyDoc_STRVAR(reduce_doc,\r
+"reduce(function, sequence[, initial]) -> value\n\\r
+\n\\r
+Apply a function of two arguments cumulatively to the items of a sequence,\n\\r
+from left to right, so as to reduce the sequence to a single value.\n\\r
+For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\\r
+((((1+2)+3)+4)+5).  If initial is present, it is placed before the items\n\\r
+of the sequence in the calculation, and serves as a default when the\n\\r
+sequence is empty.");\r
+\r
+\r
+static PyObject *\r
+builtin_reload(PyObject *self, PyObject *v)\r
+{\r
+    if (PyErr_WarnPy3k("In 3.x, reload() is renamed to imp.reload()",\r
+                       1) < 0)\r
+        return NULL;\r
+\r
+    return PyImport_ReloadModule(v);\r
+}\r
+\r
+PyDoc_STRVAR(reload_doc,\r
+"reload(module) -> module\n\\r
+\n\\r
+Reload the module.  The module must have been successfully imported before.");\r
+\r
+\r
+static PyObject *\r
+builtin_repr(PyObject *self, PyObject *v)\r
+{\r
+    return PyObject_Repr(v);\r
+}\r
+\r
+PyDoc_STRVAR(repr_doc,\r
+"repr(object) -> string\n\\r
+\n\\r
+Return the canonical string representation of the object.\n\\r
+For most object types, eval(repr(object)) == object.");\r
+\r
+\r
+static PyObject *\r
+builtin_round(PyObject *self, PyObject *args, PyObject *kwds)\r
+{\r
+    double x;\r
+    PyObject *o_ndigits = NULL;\r
+    Py_ssize_t ndigits;\r
+    static char *kwlist[] = {"number", "ndigits", 0};\r
+\r
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "d|O:round",\r
+        kwlist, &x, &o_ndigits))\r
+        return NULL;\r
+\r
+    if (o_ndigits == NULL) {\r
+        /* second argument defaults to 0 */\r
+        ndigits = 0;\r
+    }\r
+    else {\r
+        /* interpret 2nd argument as a Py_ssize_t; clip on overflow */\r
+        ndigits = PyNumber_AsSsize_t(o_ndigits, NULL);\r
+        if (ndigits == -1 && PyErr_Occurred())\r
+            return NULL;\r
+    }\r
+\r
+    /* nans, infinities and zeros round to themselves */\r
+    if (!Py_IS_FINITE(x) || x == 0.0)\r
+        return PyFloat_FromDouble(x);\r
+\r
+    /* Deal with extreme values for ndigits. For ndigits > NDIGITS_MAX, x\r
+       always rounds to itself.  For ndigits < NDIGITS_MIN, x always\r
+       rounds to +-0.0.  Here 0.30103 is an upper bound for log10(2). */\r
+#define NDIGITS_MAX ((int)((DBL_MANT_DIG-DBL_MIN_EXP) * 0.30103))\r
+#define NDIGITS_MIN (-(int)((DBL_MAX_EXP + 1) * 0.30103))\r
+    if (ndigits > NDIGITS_MAX)\r
+        /* return x */\r
+        return PyFloat_FromDouble(x);\r
+    else if (ndigits < NDIGITS_MIN)\r
+        /* return 0.0, but with sign of x */\r
+        return PyFloat_FromDouble(0.0*x);\r
+    else\r
+        /* finite x, and ndigits is not unreasonably large */\r
+        /* _Py_double_round is defined in floatobject.c */\r
+        return _Py_double_round(x, (int)ndigits);\r
+#undef NDIGITS_MAX\r
+#undef NDIGITS_MIN\r
+}\r
+\r
+PyDoc_STRVAR(round_doc,\r
+"round(number[, ndigits]) -> floating point number\n\\r
+\n\\r
+Round a number to a given precision in decimal digits (default 0 digits).\n\\r
+This always returns a floating point number.  Precision may be negative.");\r
+\r
+static PyObject *\r
+builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)\r
+{\r
+    PyObject *newlist, *v, *seq, *compare=NULL, *keyfunc=NULL, *newargs;\r
+    PyObject *callable;\r
+    static char *kwlist[] = {"iterable", "cmp", "key", "reverse", 0};\r
+    int reverse;\r
+\r
+    /* args 1-4 should match listsort in Objects/listobject.c */\r
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OOi:sorted",\r
+        kwlist, &seq, &compare, &keyfunc, &reverse))\r
+        return NULL;\r
+\r
+    newlist = PySequence_List(seq);\r
+    if (newlist == NULL)\r
+        return NULL;\r
+\r
+    callable = PyObject_GetAttrString(newlist, "sort");\r
+    if (callable == NULL) {\r
+        Py_DECREF(newlist);\r
+        return NULL;\r
+    }\r
+\r
+    newargs = PyTuple_GetSlice(args, 1, 4);\r
+    if (newargs == NULL) {\r
+        Py_DECREF(newlist);\r
+        Py_DECREF(callable);\r
+        return NULL;\r
+    }\r
+\r
+    v = PyObject_Call(callable, newargs, kwds);\r
+    Py_DECREF(newargs);\r
+    Py_DECREF(callable);\r
+    if (v == NULL) {\r
+        Py_DECREF(newlist);\r
+        return NULL;\r
+    }\r
+    Py_DECREF(v);\r
+    return newlist;\r
+}\r
+\r
+PyDoc_STRVAR(sorted_doc,\r
+"sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list");\r
+\r
+static PyObject *\r
+builtin_vars(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *v = NULL;\r
+    PyObject *d;\r
+\r
+    if (!PyArg_UnpackTuple(args, "vars", 0, 1, &v))\r
+        return NULL;\r
+    if (v == NULL) {\r
+        d = PyEval_GetLocals();\r
+        if (d == NULL) {\r
+            if (!PyErr_Occurred())\r
+                PyErr_SetString(PyExc_SystemError,\r
+                                "vars(): no locals!?");\r
+        }\r
+        else\r
+            Py_INCREF(d);\r
+    }\r
+    else {\r
+        d = PyObject_GetAttrString(v, "__dict__");\r
+        if (d == NULL) {\r
+            PyErr_SetString(PyExc_TypeError,\r
+                "vars() argument must have __dict__ attribute");\r
+            return NULL;\r
+        }\r
+    }\r
+    return d;\r
+}\r
+\r
+PyDoc_STRVAR(vars_doc,\r
+"vars([object]) -> dictionary\n\\r
+\n\\r
+Without arguments, equivalent to locals().\n\\r
+With an argument, equivalent to object.__dict__.");\r
+\r
+\r
+static PyObject*\r
+builtin_sum(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *seq;\r
+    PyObject *result = NULL;\r
+    PyObject *temp, *item, *iter;\r
+\r
+    if (!PyArg_UnpackTuple(args, "sum", 1, 2, &seq, &result))\r
+        return NULL;\r
+\r
+    iter = PyObject_GetIter(seq);\r
+    if (iter == NULL)\r
+        return NULL;\r
+\r
+    if (result == NULL) {\r
+        result = PyInt_FromLong(0);\r
+        if (result == NULL) {\r
+            Py_DECREF(iter);\r
+            return NULL;\r
+        }\r
+    } else {\r
+        /* reject string values for 'start' parameter */\r
+        if (PyObject_TypeCheck(result, &PyBaseString_Type)) {\r
+            PyErr_SetString(PyExc_TypeError,\r
+                "sum() can't sum strings [use ''.join(seq) instead]");\r
+            Py_DECREF(iter);\r
+            return NULL;\r
+        }\r
+        Py_INCREF(result);\r
+    }\r
+\r
+#ifndef SLOW_SUM\r
+    /* Fast addition by keeping temporary sums in C instead of new Python objects.\r
+       Assumes all inputs are the same type.  If the assumption fails, default\r
+       to the more general routine.\r
+    */\r
+    if (PyInt_CheckExact(result)) {\r
+        long i_result = PyInt_AS_LONG(result);\r
+        Py_DECREF(result);\r
+        result = NULL;\r
+        while(result == NULL) {\r
+            item = PyIter_Next(iter);\r
+            if (item == NULL) {\r
+                Py_DECREF(iter);\r
+                if (PyErr_Occurred())\r
+                    return NULL;\r
+                return PyInt_FromLong(i_result);\r
+            }\r
+            if (PyInt_CheckExact(item)) {\r
+                long b = PyInt_AS_LONG(item);\r
+                long x = i_result + b;\r
+                if ((x^i_result) >= 0 || (x^b) >= 0) {\r
+                    i_result = x;\r
+                    Py_DECREF(item);\r
+                    continue;\r
+                }\r
+            }\r
+            /* Either overflowed or is not an int. Restore real objects and process normally */\r
+            result = PyInt_FromLong(i_result);\r
+            temp = PyNumber_Add(result, item);\r
+            Py_DECREF(result);\r
+            Py_DECREF(item);\r
+            result = temp;\r
+            if (result == NULL) {\r
+                Py_DECREF(iter);\r
+                return NULL;\r
+            }\r
+        }\r
+    }\r
+\r
+    if (PyFloat_CheckExact(result)) {\r
+        double f_result = PyFloat_AS_DOUBLE(result);\r
+        Py_DECREF(result);\r
+        result = NULL;\r
+        while(result == NULL) {\r
+            item = PyIter_Next(iter);\r
+            if (item == NULL) {\r
+                Py_DECREF(iter);\r
+                if (PyErr_Occurred())\r
+                    return NULL;\r
+                return PyFloat_FromDouble(f_result);\r
+            }\r
+            if (PyFloat_CheckExact(item)) {\r
+                PyFPE_START_PROTECT("add", Py_DECREF(item); Py_DECREF(iter); return 0)\r
+                f_result += PyFloat_AS_DOUBLE(item);\r
+                PyFPE_END_PROTECT(f_result)\r
+                Py_DECREF(item);\r
+                continue;\r
+            }\r
+            if (PyInt_CheckExact(item)) {\r
+                PyFPE_START_PROTECT("add", Py_DECREF(item); Py_DECREF(iter); return 0)\r
+                f_result += (double)PyInt_AS_LONG(item);\r
+                PyFPE_END_PROTECT(f_result)\r
+                Py_DECREF(item);\r
+                continue;\r
+            }\r
+            result = PyFloat_FromDouble(f_result);\r
+            temp = PyNumber_Add(result, item);\r
+            Py_DECREF(result);\r
+            Py_DECREF(item);\r
+            result = temp;\r
+            if (result == NULL) {\r
+                Py_DECREF(iter);\r
+                return NULL;\r
+            }\r
+        }\r
+    }\r
+#endif\r
+\r
+    for(;;) {\r
+        item = PyIter_Next(iter);\r
+        if (item == NULL) {\r
+            /* error, or end-of-sequence */\r
+            if (PyErr_Occurred()) {\r
+                Py_DECREF(result);\r
+                result = NULL;\r
+            }\r
+            break;\r
+        }\r
+        /* It's tempting to use PyNumber_InPlaceAdd instead of\r
+           PyNumber_Add here, to avoid quadratic running time\r
+           when doing 'sum(list_of_lists, [])'.  However, this\r
+           would produce a change in behaviour: a snippet like\r
+\r
+             empty = []\r
+             sum([[x] for x in range(10)], empty)\r
+\r
+           would change the value of empty. */\r
+        temp = PyNumber_Add(result, item);\r
+        Py_DECREF(result);\r
+        Py_DECREF(item);\r
+        result = temp;\r
+        if (result == NULL)\r
+            break;\r
+    }\r
+    Py_DECREF(iter);\r
+    return result;\r
+}\r
+\r
+PyDoc_STRVAR(sum_doc,\r
+"sum(sequence[, start]) -> value\n\\r
+\n\\r
+Return the sum of a sequence of numbers (NOT strings) plus the value\n\\r
+of parameter 'start' (which defaults to 0).  When the sequence is\n\\r
+empty, return start.");\r
+\r
+\r
+static PyObject *\r
+builtin_isinstance(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *inst;\r
+    PyObject *cls;\r
+    int retval;\r
+\r
+    if (!PyArg_UnpackTuple(args, "isinstance", 2, 2, &inst, &cls))\r
+        return NULL;\r
+\r
+    retval = PyObject_IsInstance(inst, cls);\r
+    if (retval < 0)\r
+        return NULL;\r
+    return PyBool_FromLong(retval);\r
+}\r
+\r
+PyDoc_STRVAR(isinstance_doc,\r
+"isinstance(object, class-or-type-or-tuple) -> bool\n\\r
+\n\\r
+Return whether an object is an instance of a class or of a subclass thereof.\n\\r
+With a type as second argument, return whether that is the object's type.\n\\r
+The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for\n\\r
+isinstance(x, A) or isinstance(x, B) or ... (etc.).");\r
+\r
+\r
+static PyObject *\r
+builtin_issubclass(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *derived;\r
+    PyObject *cls;\r
+    int retval;\r
+\r
+    if (!PyArg_UnpackTuple(args, "issubclass", 2, 2, &derived, &cls))\r
+        return NULL;\r
+\r
+    retval = PyObject_IsSubclass(derived, cls);\r
+    if (retval < 0)\r
+        return NULL;\r
+    return PyBool_FromLong(retval);\r
+}\r
+\r
+PyDoc_STRVAR(issubclass_doc,\r
+"issubclass(C, B) -> bool\n\\r
+\n\\r
+Return whether class C is a subclass (i.e., a derived class) of class B.\n\\r
+When using a tuple as the second argument issubclass(X, (A, B, ...)),\n\\r
+is a shortcut for issubclass(X, A) or issubclass(X, B) or ... (etc.).");\r
+\r
+\r
+static PyObject*\r
+builtin_zip(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *ret;\r
+    const Py_ssize_t itemsize = PySequence_Length(args);\r
+    Py_ssize_t i;\r
+    PyObject *itlist;  /* tuple of iterators */\r
+    Py_ssize_t len;        /* guess at result length */\r
+\r
+    if (itemsize == 0)\r
+        return PyList_New(0);\r
+\r
+    /* args must be a tuple */\r
+    assert(PyTuple_Check(args));\r
+\r
+    /* Guess at result length:  the shortest of the input lengths.\r
+       If some argument refuses to say, we refuse to guess too, lest\r
+       an argument like xrange(sys.maxint) lead us astray.*/\r
+    len = -1;           /* unknown */\r
+    for (i = 0; i < itemsize; ++i) {\r
+        PyObject *item = PyTuple_GET_ITEM(args, i);\r
+        Py_ssize_t thislen = _PyObject_LengthHint(item, -2);\r
+        if (thislen < 0) {\r
+            if (thislen == -1)\r
+                return NULL;\r
+            len = -1;\r
+            break;\r
+        }\r
+        else if (len < 0 || thislen < len)\r
+            len = thislen;\r
+    }\r
+\r
+    /* allocate result list */\r
+    if (len < 0)\r
+        len = 10;               /* arbitrary */\r
+    if ((ret = PyList_New(len)) == NULL)\r
+        return NULL;\r
+\r
+    /* obtain iterators */\r
+    itlist = PyTuple_New(itemsize);\r
+    if (itlist == NULL)\r
+        goto Fail_ret;\r
+    for (i = 0; i < itemsize; ++i) {\r
+        PyObject *item = PyTuple_GET_ITEM(args, i);\r
+        PyObject *it = PyObject_GetIter(item);\r
+        if (it == NULL) {\r
+            if (PyErr_ExceptionMatches(PyExc_TypeError))\r
+                PyErr_Format(PyExc_TypeError,\r
+                    "zip argument #%zd must support iteration",\r
+                    i+1);\r
+            goto Fail_ret_itlist;\r
+        }\r
+        PyTuple_SET_ITEM(itlist, i, it);\r
+    }\r
+\r
+    /* build result into ret list */\r
+    for (i = 0; ; ++i) {\r
+        int j;\r
+        PyObject *next = PyTuple_New(itemsize);\r
+        if (!next)\r
+            goto Fail_ret_itlist;\r
+\r
+        for (j = 0; j < itemsize; j++) {\r
+            PyObject *it = PyTuple_GET_ITEM(itlist, j);\r
+            PyObject *item = PyIter_Next(it);\r
+            if (!item) {\r
+                if (PyErr_Occurred()) {\r
+                    Py_DECREF(ret);\r
+                    ret = NULL;\r
+                }\r
+                Py_DECREF(next);\r
+                Py_DECREF(itlist);\r
+                goto Done;\r
+            }\r
+            PyTuple_SET_ITEM(next, j, item);\r
+        }\r
+\r
+        if (i < len)\r
+            PyList_SET_ITEM(ret, i, next);\r
+        else {\r
+            int status = PyList_Append(ret, next);\r
+            Py_DECREF(next);\r
+            ++len;\r
+            if (status < 0)\r
+                goto Fail_ret_itlist;\r
+        }\r
+    }\r
+\r
+Done:\r
+    if (ret != NULL && i < len) {\r
+        /* The list is too big. */\r
+        if (PyList_SetSlice(ret, i, len, NULL) < 0)\r
+            return NULL;\r
+    }\r
+    return ret;\r
+\r
+Fail_ret_itlist:\r
+    Py_DECREF(itlist);\r
+Fail_ret:\r
+    Py_DECREF(ret);\r
+    return NULL;\r
+}\r
+\r
+\r
+PyDoc_STRVAR(zip_doc,\r
+"zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)]\n\\r
+\n\\r
+Return a list of tuples, where each tuple contains the i-th element\n\\r
+from each of the argument sequences.  The returned list is truncated\n\\r
+in length to the length of the shortest argument sequence.");\r
+\r
+\r
+static PyMethodDef builtin_methods[] = {\r
+    {"__import__",      (PyCFunction)builtin___import__, METH_VARARGS | METH_KEYWORDS, import_doc},\r
+    {"abs",             builtin_abs,        METH_O, abs_doc},\r
+    {"all",             builtin_all,        METH_O, all_doc},\r
+    {"any",             builtin_any,        METH_O, any_doc},\r
+    {"apply",           builtin_apply,      METH_VARARGS, apply_doc},\r
+    {"bin",             builtin_bin,        METH_O, bin_doc},\r
+    {"callable",        builtin_callable,   METH_O, callable_doc},\r
+    {"chr",             builtin_chr,        METH_VARARGS, chr_doc},\r
+    {"cmp",             builtin_cmp,        METH_VARARGS, cmp_doc},\r
+    {"coerce",          builtin_coerce,     METH_VARARGS, coerce_doc},\r
+    {"compile",         (PyCFunction)builtin_compile,    METH_VARARGS | METH_KEYWORDS, compile_doc},\r
+    {"delattr",         builtin_delattr,    METH_VARARGS, delattr_doc},\r
+    {"dir",             builtin_dir,        METH_VARARGS, dir_doc},\r
+    {"divmod",          builtin_divmod,     METH_VARARGS, divmod_doc},\r
+    {"eval",            builtin_eval,       METH_VARARGS, eval_doc},\r
+    {"execfile",        builtin_execfile,   METH_VARARGS, execfile_doc},\r
+    {"filter",          builtin_filter,     METH_VARARGS, filter_doc},\r
+    {"format",          builtin_format,     METH_VARARGS, format_doc},\r
+    {"getattr",         builtin_getattr,    METH_VARARGS, getattr_doc},\r
+    {"globals",         (PyCFunction)builtin_globals,    METH_NOARGS, globals_doc},\r
+    {"hasattr",         builtin_hasattr,    METH_VARARGS, hasattr_doc},\r
+    {"hash",            builtin_hash,       METH_O, hash_doc},\r
+    {"hex",             builtin_hex,        METH_O, hex_doc},\r
+    {"id",              builtin_id,         METH_O, id_doc},\r
+    {"input",           builtin_input,      METH_VARARGS, input_doc},\r
+    {"intern",          builtin_intern,     METH_VARARGS, intern_doc},\r
+    {"isinstance",  builtin_isinstance, METH_VARARGS, isinstance_doc},\r
+    {"issubclass",  builtin_issubclass, METH_VARARGS, issubclass_doc},\r
+    {"iter",            builtin_iter,       METH_VARARGS, iter_doc},\r
+    {"len",             builtin_len,        METH_O, len_doc},\r
+    {"locals",          (PyCFunction)builtin_locals,     METH_NOARGS, locals_doc},\r
+    {"map",             builtin_map,        METH_VARARGS, map_doc},\r
+    {"max",             (PyCFunction)builtin_max,        METH_VARARGS | METH_KEYWORDS, max_doc},\r
+    {"min",             (PyCFunction)builtin_min,        METH_VARARGS | METH_KEYWORDS, min_doc},\r
+    {"next",            builtin_next,       METH_VARARGS, next_doc},\r
+    {"oct",             builtin_oct,        METH_O, oct_doc},\r
+    {"open",            (PyCFunction)builtin_open,       METH_VARARGS | METH_KEYWORDS, open_doc},\r
+    {"ord",             builtin_ord,        METH_O, ord_doc},\r
+    {"pow",             builtin_pow,        METH_VARARGS, pow_doc},\r
+    {"print",           (PyCFunction)builtin_print,      METH_VARARGS | METH_KEYWORDS, print_doc},\r
+    {"range",           builtin_range,      METH_VARARGS, range_doc},\r
+    {"raw_input",       builtin_raw_input,  METH_VARARGS, raw_input_doc},\r
+    {"reduce",          builtin_reduce,     METH_VARARGS, reduce_doc},\r
+    {"reload",          builtin_reload,     METH_O, reload_doc},\r
+    {"repr",            builtin_repr,       METH_O, repr_doc},\r
+    {"round",           (PyCFunction)builtin_round,      METH_VARARGS | METH_KEYWORDS, round_doc},\r
+    {"setattr",         builtin_setattr,    METH_VARARGS, setattr_doc},\r
+    {"sorted",          (PyCFunction)builtin_sorted,     METH_VARARGS | METH_KEYWORDS, sorted_doc},\r
+    {"sum",             builtin_sum,        METH_VARARGS, sum_doc},\r
+#ifdef Py_USING_UNICODE\r
+    {"unichr",          builtin_unichr,     METH_VARARGS, unichr_doc},\r
+#endif\r
+    {"vars",            builtin_vars,       METH_VARARGS, vars_doc},\r
+    {"zip",         builtin_zip,        METH_VARARGS, zip_doc},\r
+    {NULL,              NULL},\r
+};\r
+\r
+PyDoc_STRVAR(builtin_doc,\r
+"Built-in functions, exceptions, and other objects.\n\\r
+\n\\r
+Noteworthy: None is the `nil' object; Ellipsis represents `...' in slices.");\r
+\r
+PyObject *\r
+_PyBuiltin_Init(void)\r
+{\r
+    PyObject *mod, *dict, *debug;\r
+    mod = Py_InitModule4("__builtin__", builtin_methods,\r
+                         builtin_doc, (PyObject *)NULL,\r
+                         PYTHON_API_VERSION);\r
+    if (mod == NULL)\r
+        return NULL;\r
+    dict = PyModule_GetDict(mod);\r
+\r
+#ifdef Py_TRACE_REFS\r
+    /* __builtin__ exposes a number of statically allocated objects\r
+     * that, before this code was added in 2.3, never showed up in\r
+     * the list of "all objects" maintained by Py_TRACE_REFS.  As a\r
+     * result, programs leaking references to None and False (etc)\r
+     * couldn't be diagnosed by examining sys.getobjects(0).\r
+     */\r
+#define ADD_TO_ALL(OBJECT) _Py_AddToAllObjects((PyObject *)(OBJECT), 0)\r
+#else\r
+#define ADD_TO_ALL(OBJECT) (void)0\r
+#endif\r
+\r
+#define SETBUILTIN(NAME, OBJECT) \\r
+    if (PyDict_SetItemString(dict, NAME, (PyObject *)OBJECT) < 0)       \\r
+        return NULL;                                                    \\r
+    ADD_TO_ALL(OBJECT)\r
+\r
+    SETBUILTIN("None",                  Py_None);\r
+    SETBUILTIN("Ellipsis",              Py_Ellipsis);\r
+    SETBUILTIN("NotImplemented",        Py_NotImplemented);\r
+    SETBUILTIN("False",                 Py_False);\r
+    SETBUILTIN("True",                  Py_True);\r
+    SETBUILTIN("basestring",            &PyBaseString_Type);\r
+    SETBUILTIN("bool",                  &PyBool_Type);\r
+    SETBUILTIN("memoryview",        &PyMemoryView_Type);\r
+    SETBUILTIN("bytearray",             &PyByteArray_Type);\r
+    SETBUILTIN("bytes",                 &PyString_Type);\r
+    SETBUILTIN("buffer",                &PyBuffer_Type);\r
+    SETBUILTIN("classmethod",           &PyClassMethod_Type);\r
+#ifndef WITHOUT_COMPLEX\r
+    SETBUILTIN("complex",               &PyComplex_Type);\r
+#endif\r
+    SETBUILTIN("dict",                  &PyDict_Type);\r
+    SETBUILTIN("enumerate",             &PyEnum_Type);\r
+    SETBUILTIN("file",                  &PyFile_Type);\r
+    SETBUILTIN("float",                 &PyFloat_Type);\r
+    SETBUILTIN("frozenset",             &PyFrozenSet_Type);\r
+    SETBUILTIN("property",              &PyProperty_Type);\r
+    SETBUILTIN("int",                   &PyInt_Type);\r
+    SETBUILTIN("list",                  &PyList_Type);\r
+    SETBUILTIN("long",                  &PyLong_Type);\r
+    SETBUILTIN("object",                &PyBaseObject_Type);\r
+    SETBUILTIN("reversed",              &PyReversed_Type);\r
+    SETBUILTIN("set",                   &PySet_Type);\r
+    SETBUILTIN("slice",                 &PySlice_Type);\r
+    SETBUILTIN("staticmethod",          &PyStaticMethod_Type);\r
+    SETBUILTIN("str",                   &PyString_Type);\r
+    SETBUILTIN("super",                 &PySuper_Type);\r
+    SETBUILTIN("tuple",                 &PyTuple_Type);\r
+    SETBUILTIN("type",                  &PyType_Type);\r
+    SETBUILTIN("xrange",                &PyRange_Type);\r
+#ifdef Py_USING_UNICODE\r
+    SETBUILTIN("unicode",               &PyUnicode_Type);\r
+#endif\r
+    debug = PyBool_FromLong(Py_OptimizeFlag == 0);\r
+    if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {\r
+        Py_XDECREF(debug);\r
+        return NULL;\r
+    }\r
+    Py_XDECREF(debug);\r
+\r
+    return mod;\r
+#undef ADD_TO_ALL\r
+#undef SETBUILTIN\r
+}\r
+\r
+/* Helper for filter(): filter a tuple through a function */\r
+\r
+static PyObject *\r
+filtertuple(PyObject *func, PyObject *tuple)\r
+{\r
+    PyObject *result;\r
+    Py_ssize_t i, j;\r
+    Py_ssize_t len = PyTuple_Size(tuple);\r
+\r
+    if (len == 0) {\r
+        if (PyTuple_CheckExact(tuple))\r
+            Py_INCREF(tuple);\r
+        else\r
+            tuple = PyTuple_New(0);\r
+        return tuple;\r
+    }\r
+\r
+    if ((result = PyTuple_New(len)) == NULL)\r
+        return NULL;\r
+\r
+    for (i = j = 0; i < len; ++i) {\r
+        PyObject *item, *good;\r
+        int ok;\r
+\r
+        if (tuple->ob_type->tp_as_sequence &&\r
+            tuple->ob_type->tp_as_sequence->sq_item) {\r
+            item = tuple->ob_type->tp_as_sequence->sq_item(tuple, i);\r
+            if (item == NULL)\r
+                goto Fail_1;\r
+        } else {\r
+            PyErr_SetString(PyExc_TypeError, "filter(): unsubscriptable tuple");\r
+            goto Fail_1;\r
+        }\r
+        if (func == Py_None) {\r
+            Py_INCREF(item);\r
+            good = item;\r
+        }\r
+        else {\r
+            PyObject *arg = PyTuple_Pack(1, item);\r
+            if (arg == NULL) {\r
+                Py_DECREF(item);\r
+                goto Fail_1;\r
+            }\r
+            good = PyEval_CallObject(func, arg);\r
+            Py_DECREF(arg);\r
+            if (good == NULL) {\r
+                Py_DECREF(item);\r
+                goto Fail_1;\r
+            }\r
+        }\r
+        ok = PyObject_IsTrue(good);\r
+        Py_DECREF(good);\r
+        if (ok > 0) {\r
+            if (PyTuple_SetItem(result, j++, item) < 0)\r
+                goto Fail_1;\r
+        }\r
+        else {\r
+            Py_DECREF(item);\r
+            if (ok < 0)\r
+                goto Fail_1;\r
+        }\r
+    }\r
+\r
+    if (_PyTuple_Resize(&result, j) < 0)\r
+        return NULL;\r
+\r
+    return result;\r
+\r
+Fail_1:\r
+    Py_DECREF(result);\r
+    return NULL;\r
+}\r
+\r
+\r
+/* Helper for filter(): filter a string through a function */\r
+\r
+static PyObject *\r
+filterstring(PyObject *func, PyObject *strobj)\r
+{\r
+    PyObject *result;\r
+    Py_ssize_t i, j;\r
+    Py_ssize_t len = PyString_Size(strobj);\r
+    Py_ssize_t outlen = len;\r
+\r
+    if (func == Py_None) {\r
+        /* If it's a real string we can return the original,\r
+         * as no character is ever false and __getitem__\r
+         * does return this character. If it's a subclass\r
+         * we must go through the __getitem__ loop */\r
+        if (PyString_CheckExact(strobj)) {\r
+            Py_INCREF(strobj);\r
+            return strobj;\r
+        }\r
+    }\r
+    if ((result = PyString_FromStringAndSize(NULL, len)) == NULL)\r
+        return NULL;\r
+\r
+    for (i = j = 0; i < len; ++i) {\r
+        PyObject *item;\r
+        int ok;\r
+\r
+        item = (*strobj->ob_type->tp_as_sequence->sq_item)(strobj, i);\r
+        if (item == NULL)\r
+            goto Fail_1;\r
+        if (func==Py_None) {\r
+            ok = 1;\r
+        } else {\r
+            PyObject *arg, *good;\r
+            arg = PyTuple_Pack(1, item);\r
+            if (arg == NULL) {\r
+                Py_DECREF(item);\r
+                goto Fail_1;\r
+            }\r
+            good = PyEval_CallObject(func, arg);\r
+            Py_DECREF(arg);\r
+            if (good == NULL) {\r
+                Py_DECREF(item);\r
+                goto Fail_1;\r
+            }\r
+            ok = PyObject_IsTrue(good);\r
+            Py_DECREF(good);\r
+        }\r
+        if (ok > 0) {\r
+            Py_ssize_t reslen;\r
+            if (!PyString_Check(item)) {\r
+                PyErr_SetString(PyExc_TypeError, "can't filter str to str:"\r
+                    " __getitem__ returned different type");\r
+                Py_DECREF(item);\r
+                goto Fail_1;\r
+            }\r
+            reslen = PyString_GET_SIZE(item);\r
+            if (reslen == 1) {\r
+                PyString_AS_STRING(result)[j++] =\r
+                    PyString_AS_STRING(item)[0];\r
+            } else {\r
+                /* do we need more space? */\r
+                Py_ssize_t need = j;\r
+\r
+                /* calculate space requirements while checking for overflow */\r
+                if (need > PY_SSIZE_T_MAX - reslen) {\r
+                    Py_DECREF(item);\r
+                    goto Fail_1;\r
+                }\r
+\r
+                need += reslen;\r
+\r
+                if (need > PY_SSIZE_T_MAX - len) {\r
+                    Py_DECREF(item);\r
+                    goto Fail_1;\r
+                }\r
+\r
+                need += len;\r
+\r
+                if (need <= i) {\r
+                    Py_DECREF(item);\r
+                    goto Fail_1;\r
+                }\r
+\r
+                need = need - i - 1;\r
+\r
+                assert(need >= 0);\r
+                assert(outlen >= 0);\r
+\r
+                if (need > outlen) {\r
+                    /* overallocate, to avoid reallocations */\r
+                    if (outlen > PY_SSIZE_T_MAX / 2) {\r
+                        Py_DECREF(item);\r
+                        return NULL;\r
+                    }\r
+\r
+                    if (need<2*outlen) {\r
+                        need = 2*outlen;\r
+      }\r
+                                    if (_PyString_Resize(&result, need)) {\r
+                                            Py_DECREF(item);\r
+                                            return NULL;\r
+                                    }\r
+                                    outlen = need;\r
+                            }\r
+                            memcpy(\r
+                                    PyString_AS_STRING(result) + j,\r
+                                    PyString_AS_STRING(item),\r
+                                    reslen\r
+                            );\r
+                            j += reslen;\r
+                    }\r
+        }\r
+        Py_DECREF(item);\r
+        if (ok < 0)\r
+            goto Fail_1;\r
+    }\r
+\r
+    if (j < outlen)\r
+        _PyString_Resize(&result, j);\r
+\r
+    return result;\r
+\r
+Fail_1:\r
+    Py_DECREF(result);\r
+    return NULL;\r
+}\r
+\r
+#ifdef Py_USING_UNICODE\r
+/* Helper for filter(): filter a Unicode object through a function */\r
+\r
+static PyObject *\r
+filterunicode(PyObject *func, PyObject *strobj)\r
+{\r
+    PyObject *result;\r
+    register Py_ssize_t i, j;\r
+    Py_ssize_t len = PyUnicode_GetSize(strobj);\r
+    Py_ssize_t outlen = len;\r
+\r
+    if (func == Py_None) {\r
+        /* If it's a real string we can return the original,\r
+         * as no character is ever false and __getitem__\r
+         * does return this character. If it's a subclass\r
+         * we must go through the __getitem__ loop */\r
+        if (PyUnicode_CheckExact(strobj)) {\r
+            Py_INCREF(strobj);\r
+            return strobj;\r
+        }\r
+    }\r
+    if ((result = PyUnicode_FromUnicode(NULL, len)) == NULL)\r
+        return NULL;\r
+\r
+    for (i = j = 0; i < len; ++i) {\r
+        PyObject *item, *arg, *good;\r
+        int ok;\r
+\r
+        item = (*strobj->ob_type->tp_as_sequence->sq_item)(strobj, i);\r
+        if (item == NULL)\r
+            goto Fail_1;\r
+        if (func == Py_None) {\r
+            ok = 1;\r
+        } else {\r
+            arg = PyTuple_Pack(1, item);\r
+            if (arg == NULL) {\r
+                Py_DECREF(item);\r
+                goto Fail_1;\r
+            }\r
+            good = PyEval_CallObject(func, arg);\r
+            Py_DECREF(arg);\r
+            if (good == NULL) {\r
+                Py_DECREF(item);\r
+                goto Fail_1;\r
+            }\r
+            ok = PyObject_IsTrue(good);\r
+            Py_DECREF(good);\r
+        }\r
+        if (ok > 0) {\r
+            Py_ssize_t reslen;\r
+            if (!PyUnicode_Check(item)) {\r
+                PyErr_SetString(PyExc_TypeError,\r
+                "can't filter unicode to unicode:"\r
+                " __getitem__ returned different type");\r
+                Py_DECREF(item);\r
+                goto Fail_1;\r
+            }\r
+            reslen = PyUnicode_GET_SIZE(item);\r
+            if (reslen == 1)\r
+                PyUnicode_AS_UNICODE(result)[j++] =\r
+                    PyUnicode_AS_UNICODE(item)[0];\r
+            else {\r
+                /* do we need more space? */\r
+                Py_ssize_t need = j + reslen + len - i - 1;\r
+\r
+                /* check that didnt overflow */\r
+                if ((j > PY_SSIZE_T_MAX - reslen) ||\r
+                    ((j + reslen) > PY_SSIZE_T_MAX - len) ||\r
+                        ((j + reslen + len) < i) ||\r
+                            ((j + reslen + len - i) <= 0)) {\r
+                    Py_DECREF(item);\r
+                    return NULL;\r
+                }\r
+\r
+                assert(need >= 0);\r
+                assert(outlen >= 0);\r
+\r
+                if (need > outlen) {\r
+                    /* overallocate,\r
+                       to avoid reallocations */\r
+                    if (need < 2 * outlen) {\r
+        if (outlen > PY_SSIZE_T_MAX / 2) {\r
+          Py_DECREF(item);\r
+          return NULL;\r
+                                            } else {\r
+                                                    need = 2 * outlen;\r
+                                }\r
+      }\r
+\r
+                                    if (PyUnicode_Resize(\r
+                                            &result, need) < 0) {\r
+                                            Py_DECREF(item);\r
+                                            goto Fail_1;\r
+                                    }\r
+                                    outlen = need;\r
+                            }\r
+                            memcpy(PyUnicode_AS_UNICODE(result) + j,\r
+                                   PyUnicode_AS_UNICODE(item),\r
+                                   reslen*sizeof(Py_UNICODE));\r
+                            j += reslen;\r
+                    }\r
+        }\r
+        Py_DECREF(item);\r
+        if (ok < 0)\r
+            goto Fail_1;\r
+    }\r
+\r
+    if (j < outlen)\r
+        PyUnicode_Resize(&result, j);\r
+\r
+    return result;\r
+\r
+Fail_1:\r
+    Py_DECREF(result);\r
+    return NULL;\r
+}\r
+#endif\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/ceval.c b/AppPkg/Applications/Python/Python-2.7.10/Python/ceval.c
new file mode 100644 (file)
index 0000000..7e12374
--- /dev/null
@@ -0,0 +1,4917 @@
+\r
+/* Execute compiled code */\r
+\r
+/* XXX TO DO:\r
+   XXX speed up searching for keywords by using a dictionary\r
+   XXX document it!\r
+   */\r
+\r
+/* enable more aggressive intra-module optimizations, where available */\r
+#define PY_LOCAL_AGGRESSIVE\r
+\r
+#include "Python.h"\r
+\r
+#include "code.h"\r
+#include "frameobject.h"\r
+#include "eval.h"\r
+#include "opcode.h"\r
+#include "structmember.h"\r
+\r
+#include <ctype.h>\r
+\r
+#ifndef WITH_TSC\r
+\r
+#define READ_TIMESTAMP(var)\r
+\r
+#else\r
+\r
+typedef unsigned long long uint64;\r
+\r
+/* PowerPC support.\r
+   "__ppc__" appears to be the preprocessor definition to detect on OS X, whereas\r
+   "__powerpc__" appears to be the correct one for Linux with GCC\r
+*/\r
+#if defined(__ppc__) || defined (__powerpc__)\r
+\r
+#define READ_TIMESTAMP(var) ppc_getcounter(&var)\r
+\r
+static void\r
+ppc_getcounter(uint64 *v)\r
+{\r
+    register unsigned long tbu, tb, tbu2;\r
+\r
+  loop:\r
+    asm volatile ("mftbu %0" : "=r" (tbu) );\r
+    asm volatile ("mftb  %0" : "=r" (tb)  );\r
+    asm volatile ("mftbu %0" : "=r" (tbu2));\r
+    if (__builtin_expect(tbu != tbu2, 0)) goto loop;\r
+\r
+    /* The slightly peculiar way of writing the next lines is\r
+       compiled better by GCC than any other way I tried. */\r
+    ((long*)(v))[0] = tbu;\r
+    ((long*)(v))[1] = tb;\r
+}\r
+\r
+#elif defined(__i386__)\r
+\r
+/* this is for linux/x86 (and probably any other GCC/x86 combo) */\r
+\r
+#define READ_TIMESTAMP(val) \\r
+     __asm__ __volatile__("rdtsc" : "=A" (val))\r
+\r
+#elif defined(__x86_64__)\r
+\r
+/* for gcc/x86_64, the "A" constraint in DI mode means *either* rax *or* rdx;\r
+   not edx:eax as it does for i386.  Since rdtsc puts its result in edx:eax\r
+   even in 64-bit mode, we need to use "a" and "d" for the lower and upper\r
+   32-bit pieces of the result. */\r
+\r
+#define READ_TIMESTAMP(val) do {                        \\r
+    unsigned int h, l;                                  \\r
+    __asm__ __volatile__("rdtsc" : "=a" (l), "=d" (h)); \\r
+    (val) = ((uint64)l) | (((uint64)h) << 32);          \\r
+    } while(0)\r
+\r
+\r
+#else\r
+\r
+#error "Don't know how to implement timestamp counter for this architecture"\r
+\r
+#endif\r
+\r
+void dump_tsc(int opcode, int ticked, uint64 inst0, uint64 inst1,\r
+              uint64 loop0, uint64 loop1, uint64 intr0, uint64 intr1)\r
+{\r
+    uint64 intr, inst, loop;\r
+    PyThreadState *tstate = PyThreadState_Get();\r
+    if (!tstate->interp->tscdump)\r
+        return;\r
+    intr = intr1 - intr0;\r
+    inst = inst1 - inst0 - intr;\r
+    loop = loop1 - loop0 - intr;\r
+    fprintf(stderr, "opcode=%03d t=%d inst=%06lld loop=%06lld\n",\r
+            opcode, ticked, inst, loop);\r
+}\r
+\r
+#endif\r
+\r
+/* Turn this on if your compiler chokes on the big switch: */\r
+/* #define CASE_TOO_BIG 1 */\r
+\r
+#ifdef Py_DEBUG\r
+/* For debugging the interpreter: */\r
+#define LLTRACE  1      /* Low-level trace feature */\r
+#define CHECKEXC 1      /* Double-check exception checking */\r
+#endif\r
+\r
+typedef PyObject *(*callproc)(PyObject *, PyObject *, PyObject *);\r
+\r
+/* Forward declarations */\r
+#ifdef WITH_TSC\r
+static PyObject * call_function(PyObject ***, int, uint64*, uint64*);\r
+#else\r
+static PyObject * call_function(PyObject ***, int);\r
+#endif\r
+static PyObject * fast_function(PyObject *, PyObject ***, int, int, int);\r
+static PyObject * do_call(PyObject *, PyObject ***, int, int);\r
+static PyObject * ext_do_call(PyObject *, PyObject ***, int, int, int);\r
+static PyObject * update_keyword_args(PyObject *, int, PyObject ***,\r
+                                      PyObject *);\r
+static PyObject * update_star_args(int, int, PyObject *, PyObject ***);\r
+static PyObject * load_args(PyObject ***, int);\r
+#define CALL_FLAG_VAR 1\r
+#define CALL_FLAG_KW 2\r
+\r
+#ifdef LLTRACE\r
+static int lltrace;\r
+static int prtrace(PyObject *, char *);\r
+#endif\r
+static int call_trace(Py_tracefunc, PyObject *, PyFrameObject *,\r
+                      int, PyObject *);\r
+static int call_trace_protected(Py_tracefunc, PyObject *,\r
+                                PyFrameObject *, int, PyObject *);\r
+static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *);\r
+static int maybe_call_line_trace(Py_tracefunc, PyObject *,\r
+                                 PyFrameObject *, int *, int *, int *);\r
+\r
+static PyObject * apply_slice(PyObject *, PyObject *, PyObject *);\r
+static int assign_slice(PyObject *, PyObject *,\r
+                        PyObject *, PyObject *);\r
+static PyObject * cmp_outcome(int, PyObject *, PyObject *);\r
+static PyObject * import_from(PyObject *, PyObject *);\r
+static int import_all_from(PyObject *, PyObject *);\r
+static PyObject * build_class(PyObject *, PyObject *, PyObject *);\r
+static int exec_statement(PyFrameObject *,\r
+                          PyObject *, PyObject *, PyObject *);\r
+static void set_exc_info(PyThreadState *, PyObject *, PyObject *, PyObject *);\r
+static void reset_exc_info(PyThreadState *);\r
+static void format_exc_check_arg(PyObject *, char *, PyObject *);\r
+static PyObject * string_concatenate(PyObject *, PyObject *,\r
+                                     PyFrameObject *, unsigned char *);\r
+static PyObject * kwd_as_string(PyObject *);\r
+static PyObject * special_lookup(PyObject *, char *, PyObject **);\r
+\r
+#define NAME_ERROR_MSG \\r
+    "name '%.200s' is not defined"\r
+#define GLOBAL_NAME_ERROR_MSG \\r
+    "global name '%.200s' is not defined"\r
+#define UNBOUNDLOCAL_ERROR_MSG \\r
+    "local variable '%.200s' referenced before assignment"\r
+#define UNBOUNDFREE_ERROR_MSG \\r
+    "free variable '%.200s' referenced before assignment" \\r
+    " in enclosing scope"\r
+\r
+/* Dynamic execution profile */\r
+#ifdef DYNAMIC_EXECUTION_PROFILE\r
+#ifdef DXPAIRS\r
+static long dxpairs[257][256];\r
+#define dxp dxpairs[256]\r
+#else\r
+static long dxp[256];\r
+#endif\r
+#endif\r
+\r
+/* Function call profile */\r
+#ifdef CALL_PROFILE\r
+#define PCALL_NUM 11\r
+static int pcall[PCALL_NUM];\r
+\r
+#define PCALL_ALL 0\r
+#define PCALL_FUNCTION 1\r
+#define PCALL_FAST_FUNCTION 2\r
+#define PCALL_FASTER_FUNCTION 3\r
+#define PCALL_METHOD 4\r
+#define PCALL_BOUND_METHOD 5\r
+#define PCALL_CFUNCTION 6\r
+#define PCALL_TYPE 7\r
+#define PCALL_GENERATOR 8\r
+#define PCALL_OTHER 9\r
+#define PCALL_POP 10\r
+\r
+/* Notes about the statistics\r
+\r
+   PCALL_FAST stats\r
+\r
+   FAST_FUNCTION means no argument tuple needs to be created.\r
+   FASTER_FUNCTION means that the fast-path frame setup code is used.\r
+\r
+   If there is a method call where the call can be optimized by changing\r
+   the argument tuple and calling the function directly, it gets recorded\r
+   twice.\r
+\r
+   As a result, the relationship among the statistics appears to be\r
+   PCALL_ALL == PCALL_FUNCTION + PCALL_METHOD - PCALL_BOUND_METHOD +\r
+                PCALL_CFUNCTION + PCALL_TYPE + PCALL_GENERATOR + PCALL_OTHER\r
+   PCALL_FUNCTION > PCALL_FAST_FUNCTION > PCALL_FASTER_FUNCTION\r
+   PCALL_METHOD > PCALL_BOUND_METHOD\r
+*/\r
+\r
+#define PCALL(POS) pcall[POS]++\r
+\r
+PyObject *\r
+PyEval_GetCallStats(PyObject *self)\r
+{\r
+    return Py_BuildValue("iiiiiiiiiii",\r
+                         pcall[0], pcall[1], pcall[2], pcall[3],\r
+                         pcall[4], pcall[5], pcall[6], pcall[7],\r
+                         pcall[8], pcall[9], pcall[10]);\r
+}\r
+#else\r
+#define PCALL(O)\r
+\r
+PyObject *\r
+PyEval_GetCallStats(PyObject *self)\r
+{\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+#endif\r
+\r
+\r
+#ifdef WITH_THREAD\r
+\r
+#ifdef HAVE_ERRNO_H\r
+#include <errno.h>\r
+#endif\r
+#include "pythread.h"\r
+\r
+static PyThread_type_lock interpreter_lock = 0; /* This is the GIL */\r
+static PyThread_type_lock pending_lock = 0; /* for pending calls */\r
+static long main_thread = 0;\r
+\r
+int\r
+PyEval_ThreadsInitialized(void)\r
+{\r
+    return interpreter_lock != 0;\r
+}\r
+\r
+void\r
+PyEval_InitThreads(void)\r
+{\r
+    if (interpreter_lock)\r
+        return;\r
+    interpreter_lock = PyThread_allocate_lock();\r
+    PyThread_acquire_lock(interpreter_lock, 1);\r
+    main_thread = PyThread_get_thread_ident();\r
+}\r
+\r
+void\r
+PyEval_AcquireLock(void)\r
+{\r
+    PyThread_acquire_lock(interpreter_lock, 1);\r
+}\r
+\r
+void\r
+PyEval_ReleaseLock(void)\r
+{\r
+    PyThread_release_lock(interpreter_lock);\r
+}\r
+\r
+void\r
+PyEval_AcquireThread(PyThreadState *tstate)\r
+{\r
+    if (tstate == NULL)\r
+        Py_FatalError("PyEval_AcquireThread: NULL new thread state");\r
+    /* Check someone has called PyEval_InitThreads() to create the lock */\r
+    assert(interpreter_lock);\r
+    PyThread_acquire_lock(interpreter_lock, 1);\r
+    if (PyThreadState_Swap(tstate) != NULL)\r
+        Py_FatalError(\r
+            "PyEval_AcquireThread: non-NULL old thread state");\r
+}\r
+\r
+void\r
+PyEval_ReleaseThread(PyThreadState *tstate)\r
+{\r
+    if (tstate == NULL)\r
+        Py_FatalError("PyEval_ReleaseThread: NULL thread state");\r
+    if (PyThreadState_Swap(NULL) != tstate)\r
+        Py_FatalError("PyEval_ReleaseThread: wrong thread state");\r
+    PyThread_release_lock(interpreter_lock);\r
+}\r
+\r
+/* This function is called from PyOS_AfterFork to ensure that newly\r
+   created child processes don't hold locks referring to threads which\r
+   are not running in the child process.  (This could also be done using\r
+   pthread_atfork mechanism, at least for the pthreads implementation.) */\r
+\r
+void\r
+PyEval_ReInitThreads(void)\r
+{\r
+    PyObject *threading, *result;\r
+    PyThreadState *tstate;\r
+\r
+    if (!interpreter_lock)\r
+        return;\r
+    /*XXX Can't use PyThread_free_lock here because it does too\r
+      much error-checking.  Doing this cleanly would require\r
+      adding a new function to each thread_*.h.  Instead, just\r
+      create a new lock and waste a little bit of memory */\r
+    interpreter_lock = PyThread_allocate_lock();\r
+    pending_lock = PyThread_allocate_lock();\r
+    PyThread_acquire_lock(interpreter_lock, 1);\r
+    main_thread = PyThread_get_thread_ident();\r
+\r
+    /* Update the threading module with the new state.\r
+     */\r
+    tstate = PyThreadState_GET();\r
+    threading = PyMapping_GetItemString(tstate->interp->modules,\r
+                                        "threading");\r
+    if (threading == NULL) {\r
+        /* threading not imported */\r
+        PyErr_Clear();\r
+        return;\r
+    }\r
+    result = PyObject_CallMethod(threading, "_after_fork", NULL);\r
+    if (result == NULL)\r
+        PyErr_WriteUnraisable(threading);\r
+    else\r
+        Py_DECREF(result);\r
+    Py_DECREF(threading);\r
+}\r
+#endif\r
+\r
+/* Functions save_thread and restore_thread are always defined so\r
+   dynamically loaded modules needn't be compiled separately for use\r
+   with and without threads: */\r
+\r
+PyThreadState *\r
+PyEval_SaveThread(void)\r
+{\r
+    PyThreadState *tstate = PyThreadState_Swap(NULL);\r
+    if (tstate == NULL)\r
+        Py_FatalError("PyEval_SaveThread: NULL tstate");\r
+#ifdef WITH_THREAD\r
+    if (interpreter_lock)\r
+        PyThread_release_lock(interpreter_lock);\r
+#endif\r
+    return tstate;\r
+}\r
+\r
+void\r
+PyEval_RestoreThread(PyThreadState *tstate)\r
+{\r
+    if (tstate == NULL)\r
+        Py_FatalError("PyEval_RestoreThread: NULL tstate");\r
+#ifdef WITH_THREAD\r
+    if (interpreter_lock) {\r
+        int err = errno;\r
+        PyThread_acquire_lock(interpreter_lock, 1);\r
+        errno = err;\r
+    }\r
+#endif\r
+    PyThreadState_Swap(tstate);\r
+}\r
+\r
+\r
+/* Mechanism whereby asynchronously executing callbacks (e.g. UNIX\r
+   signal handlers or Mac I/O completion routines) can schedule calls\r
+   to a function to be called synchronously.\r
+   The synchronous function is called with one void* argument.\r
+   It should return 0 for success or -1 for failure -- failure should\r
+   be accompanied by an exception.\r
+\r
+   If registry succeeds, the registry function returns 0; if it fails\r
+   (e.g. due to too many pending calls) it returns -1 (without setting\r
+   an exception condition).\r
+\r
+   Note that because registry may occur from within signal handlers,\r
+   or other asynchronous events, calling malloc() is unsafe!\r
+\r
+#ifdef WITH_THREAD\r
+   Any thread can schedule pending calls, but only the main thread\r
+   will execute them.\r
+   There is no facility to schedule calls to a particular thread, but\r
+   that should be easy to change, should that ever be required.  In\r
+   that case, the static variables here should go into the python\r
+   threadstate.\r
+#endif\r
+*/\r
+\r
+#ifdef WITH_THREAD\r
+\r
+/* The WITH_THREAD implementation is thread-safe.  It allows\r
+   scheduling to be made from any thread, and even from an executing\r
+   callback.\r
+ */\r
+\r
+#define NPENDINGCALLS 32\r
+static struct {\r
+    int (*func)(void *);\r
+    void *arg;\r
+} pendingcalls[NPENDINGCALLS];\r
+static int pendingfirst = 0;\r
+static int pendinglast = 0;\r
+static volatile int pendingcalls_to_do = 1; /* trigger initialization of lock */\r
+static char pendingbusy = 0;\r
+\r
+int\r
+Py_AddPendingCall(int (*func)(void *), void *arg)\r
+{\r
+    int i, j, result=0;\r
+    PyThread_type_lock lock = pending_lock;\r
+\r
+    /* try a few times for the lock.  Since this mechanism is used\r
+     * for signal handling (on the main thread), there is a (slim)\r
+     * chance that a signal is delivered on the same thread while we\r
+     * hold the lock during the Py_MakePendingCalls() function.\r
+     * This avoids a deadlock in that case.\r
+     * Note that signals can be delivered on any thread.  In particular,\r
+     * on Windows, a SIGINT is delivered on a system-created worker\r
+     * thread.\r
+     * We also check for lock being NULL, in the unlikely case that\r
+     * this function is called before any bytecode evaluation takes place.\r
+     */\r
+    if (lock != NULL) {\r
+        for (i = 0; i<100; i++) {\r
+            if (PyThread_acquire_lock(lock, NOWAIT_LOCK))\r
+                break;\r
+        }\r
+        if (i == 100)\r
+            return -1;\r
+    }\r
+\r
+    i = pendinglast;\r
+    j = (i + 1) % NPENDINGCALLS;\r
+    if (j == pendingfirst) {\r
+        result = -1; /* Queue full */\r
+    } else {\r
+        pendingcalls[i].func = func;\r
+        pendingcalls[i].arg = arg;\r
+        pendinglast = j;\r
+    }\r
+    /* signal main loop */\r
+    _Py_Ticker = 0;\r
+    pendingcalls_to_do = 1;\r
+    if (lock != NULL)\r
+        PyThread_release_lock(lock);\r
+    return result;\r
+}\r
+\r
+int\r
+Py_MakePendingCalls(void)\r
+{\r
+    int i;\r
+    int r = 0;\r
+\r
+    if (!pending_lock) {\r
+        /* initial allocation of the lock */\r
+        pending_lock = PyThread_allocate_lock();\r
+        if (pending_lock == NULL)\r
+            return -1;\r
+    }\r
+\r
+    /* only service pending calls on main thread */\r
+    if (main_thread && PyThread_get_thread_ident() != main_thread)\r
+        return 0;\r
+    /* don't perform recursive pending calls */\r
+    if (pendingbusy)\r
+        return 0;\r
+    pendingbusy = 1;\r
+    /* perform a bounded number of calls, in case of recursion */\r
+    for (i=0; i<NPENDINGCALLS; i++) {\r
+        int j;\r
+        int (*func)(void *);\r
+        void *arg = NULL;\r
+\r
+        /* pop one item off the queue while holding the lock */\r
+        PyThread_acquire_lock(pending_lock, WAIT_LOCK);\r
+        j = pendingfirst;\r
+        if (j == pendinglast) {\r
+            func = NULL; /* Queue empty */\r
+        } else {\r
+            func = pendingcalls[j].func;\r
+            arg = pendingcalls[j].arg;\r
+            pendingfirst = (j + 1) % NPENDINGCALLS;\r
+        }\r
+        pendingcalls_to_do = pendingfirst != pendinglast;\r
+        PyThread_release_lock(pending_lock);\r
+        /* having released the lock, perform the callback */\r
+        if (func == NULL)\r
+            break;\r
+        r = func(arg);\r
+        if (r)\r
+            break;\r
+    }\r
+    pendingbusy = 0;\r
+    return r;\r
+}\r
+\r
+#else /* if ! defined WITH_THREAD */\r
+\r
+/*\r
+   WARNING!  ASYNCHRONOUSLY EXECUTING CODE!\r
+   This code is used for signal handling in python that isn't built\r
+   with WITH_THREAD.\r
+   Don't use this implementation when Py_AddPendingCalls() can happen\r
+   on a different thread!\r
+\r
+   There are two possible race conditions:\r
+   (1) nested asynchronous calls to Py_AddPendingCall()\r
+   (2) AddPendingCall() calls made while pending calls are being processed.\r
+\r
+   (1) is very unlikely because typically signal delivery\r
+   is blocked during signal handling.  So it should be impossible.\r
+   (2) is a real possibility.\r
+   The current code is safe against (2), but not against (1).\r
+   The safety against (2) is derived from the fact that only one\r
+   thread is present, interrupted by signals, and that the critical\r
+   section is protected with the "busy" variable.  On Windows, which\r
+   delivers SIGINT on a system thread, this does not hold and therefore\r
+   Windows really shouldn't use this version.\r
+   The two threads could theoretically wiggle around the "busy" variable.\r
+*/\r
+\r
+#define NPENDINGCALLS 32\r
+static struct {\r
+    int (*func)(void *);\r
+    void *arg;\r
+} pendingcalls[NPENDINGCALLS];\r
+static volatile int pendingfirst = 0;\r
+static volatile int pendinglast = 0;\r
+static volatile int pendingcalls_to_do = 0;\r
+\r
+int\r
+Py_AddPendingCall(int (*func)(void *), void *arg)\r
+{\r
+    static volatile int busy = 0;\r
+    int i, j;\r
+    /* XXX Begin critical section */\r
+    if (busy)\r
+        return -1;\r
+    busy = 1;\r
+    i = pendinglast;\r
+    j = (i + 1) % NPENDINGCALLS;\r
+    if (j == pendingfirst) {\r
+        busy = 0;\r
+        return -1; /* Queue full */\r
+    }\r
+    pendingcalls[i].func = func;\r
+    pendingcalls[i].arg = arg;\r
+    pendinglast = j;\r
+\r
+    _Py_Ticker = 0;\r
+    pendingcalls_to_do = 1; /* Signal main loop */\r
+    busy = 0;\r
+    /* XXX End critical section */\r
+    return 0;\r
+}\r
+\r
+int\r
+Py_MakePendingCalls(void)\r
+{\r
+    static int busy = 0;\r
+    if (busy)\r
+        return 0;\r
+    busy = 1;\r
+    pendingcalls_to_do = 0;\r
+    for (;;) {\r
+        int i;\r
+        int (*func)(void *);\r
+        void *arg;\r
+        i = pendingfirst;\r
+        if (i == pendinglast)\r
+            break; /* Queue empty */\r
+        func = pendingcalls[i].func;\r
+        arg = pendingcalls[i].arg;\r
+        pendingfirst = (i + 1) % NPENDINGCALLS;\r
+        if (func(arg) < 0) {\r
+            busy = 0;\r
+            pendingcalls_to_do = 1; /* We're not done yet */\r
+            return -1;\r
+        }\r
+    }\r
+    busy = 0;\r
+    return 0;\r
+}\r
+\r
+#endif /* WITH_THREAD */\r
+\r
+\r
+/* The interpreter's recursion limit */\r
+\r
+#ifndef Py_DEFAULT_RECURSION_LIMIT\r
+#define Py_DEFAULT_RECURSION_LIMIT 1000\r
+#endif\r
+static int recursion_limit = Py_DEFAULT_RECURSION_LIMIT;\r
+int _Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT;\r
+\r
+int\r
+Py_GetRecursionLimit(void)\r
+{\r
+    return recursion_limit;\r
+}\r
+\r
+void\r
+Py_SetRecursionLimit(int new_limit)\r
+{\r
+    recursion_limit = new_limit;\r
+    _Py_CheckRecursionLimit = recursion_limit;\r
+}\r
+\r
+/* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()\r
+   if the recursion_depth reaches _Py_CheckRecursionLimit.\r
+   If USE_STACKCHECK, the macro decrements _Py_CheckRecursionLimit\r
+   to guarantee that _Py_CheckRecursiveCall() is regularly called.\r
+   Without USE_STACKCHECK, there is no need for this. */\r
+int\r
+_Py_CheckRecursiveCall(char *where)\r
+{\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+\r
+#ifdef USE_STACKCHECK\r
+    if (PyOS_CheckStack()) {\r
+        --tstate->recursion_depth;\r
+        PyErr_SetString(PyExc_MemoryError, "Stack overflow");\r
+        return -1;\r
+    }\r
+#endif\r
+    if (tstate->recursion_depth > recursion_limit) {\r
+        --tstate->recursion_depth;\r
+        PyErr_Format(PyExc_RuntimeError,\r
+                     "maximum recursion depth exceeded%s",\r
+                     where);\r
+        return -1;\r
+    }\r
+    _Py_CheckRecursionLimit = recursion_limit;\r
+    return 0;\r
+}\r
+\r
+/* Status code for main loop (reason for stack unwind) */\r
+enum why_code {\r
+        WHY_NOT =       0x0001, /* No error */\r
+        WHY_EXCEPTION = 0x0002, /* Exception occurred */\r
+        WHY_RERAISE =   0x0004, /* Exception re-raised by 'finally' */\r
+        WHY_RETURN =    0x0008, /* 'return' statement */\r
+        WHY_BREAK =     0x0010, /* 'break' statement */\r
+        WHY_CONTINUE =  0x0020, /* 'continue' statement */\r
+        WHY_YIELD =     0x0040  /* 'yield' operator */\r
+};\r
+\r
+static enum why_code do_raise(PyObject *, PyObject *, PyObject *);\r
+static int unpack_iterable(PyObject *, int, PyObject **);\r
+\r
+/* Records whether tracing is on for any thread.  Counts the number of\r
+   threads for which tstate->c_tracefunc is non-NULL, so if the value\r
+   is 0, we know we don't have to check this thread's c_tracefunc.\r
+   This speeds up the if statement in PyEval_EvalFrameEx() after\r
+   fast_next_opcode*/\r
+static int _Py_TracingPossible = 0;\r
+\r
+/* for manipulating the thread switch and periodic "stuff" - used to be\r
+   per thread, now just a pair o' globals */\r
+int _Py_CheckInterval = 100;\r
+volatile int _Py_Ticker = 0; /* so that we hit a "tick" first thing */\r
+\r
+PyObject *\r
+PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals)\r
+{\r
+    return PyEval_EvalCodeEx(co,\r
+                      globals, locals,\r
+                      (PyObject **)NULL, 0,\r
+                      (PyObject **)NULL, 0,\r
+                      (PyObject **)NULL, 0,\r
+                      NULL);\r
+}\r
+\r
+\r
+/* Interpreter main loop */\r
+\r
+PyObject *\r
+PyEval_EvalFrame(PyFrameObject *f) {\r
+    /* This is for backward compatibility with extension modules that\r
+       used this API; core interpreter code should call\r
+       PyEval_EvalFrameEx() */\r
+    return PyEval_EvalFrameEx(f, 0);\r
+}\r
+\r
+PyObject *\r
+PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)\r
+{\r
+#ifdef DXPAIRS\r
+    int lastopcode = 0;\r
+#endif\r
+    register PyObject **stack_pointer;  /* Next free slot in value stack */\r
+    register unsigned char *next_instr;\r
+    register int opcode;        /* Current opcode */\r
+    register int oparg;         /* Current opcode argument, if any */\r
+    register enum why_code why; /* Reason for block stack unwind */\r
+    register int err;           /* Error status -- nonzero if error */\r
+    register PyObject *x;       /* Result object -- NULL if error */\r
+    register PyObject *v;       /* Temporary objects popped off stack */\r
+    register PyObject *w;\r
+    register PyObject *u;\r
+    register PyObject *t;\r
+    register PyObject *stream = NULL;    /* for PRINT opcodes */\r
+    register PyObject **fastlocals, **freevars;\r
+    PyObject *retval = NULL;            /* Return value */\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    PyCodeObject *co;\r
+\r
+    /* when tracing we set things up so that\r
+\r
+           not (instr_lb <= current_bytecode_offset < instr_ub)\r
+\r
+       is true when the line being executed has changed.  The\r
+       initial values are such as to make this false the first\r
+       time it is tested. */\r
+    int instr_ub = -1, instr_lb = 0, instr_prev = -1;\r
+\r
+    unsigned char *first_instr;\r
+    PyObject *names;\r
+    PyObject *consts;\r
+#if defined(Py_DEBUG) || defined(LLTRACE)\r
+    /* Make it easier to find out where we are with a debugger */\r
+    char *filename;\r
+#endif\r
+\r
+/* Tuple access macros */\r
+\r
+#ifndef Py_DEBUG\r
+#define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i))\r
+#else\r
+#define GETITEM(v, i) PyTuple_GetItem((v), (i))\r
+#endif\r
+\r
+#ifdef WITH_TSC\r
+/* Use Pentium timestamp counter to mark certain events:\r
+   inst0 -- beginning of switch statement for opcode dispatch\r
+   inst1 -- end of switch statement (may be skipped)\r
+   loop0 -- the top of the mainloop\r
+   loop1 -- place where control returns again to top of mainloop\r
+            (may be skipped)\r
+   intr1 -- beginning of long interruption\r
+   intr2 -- end of long interruption\r
+\r
+   Many opcodes call out to helper C functions.  In some cases, the\r
+   time in those functions should be counted towards the time for the\r
+   opcode, but not in all cases.  For example, a CALL_FUNCTION opcode\r
+   calls another Python function; there's no point in charge all the\r
+   bytecode executed by the called function to the caller.\r
+\r
+   It's hard to make a useful judgement statically.  In the presence\r
+   of operator overloading, it's impossible to tell if a call will\r
+   execute new Python code or not.\r
+\r
+   It's a case-by-case judgement.  I'll use intr1 for the following\r
+   cases:\r
+\r
+   EXEC_STMT\r
+   IMPORT_STAR\r
+   IMPORT_FROM\r
+   CALL_FUNCTION (and friends)\r
+\r
+ */\r
+    uint64 inst0, inst1, loop0, loop1, intr0 = 0, intr1 = 0;\r
+    int ticked = 0;\r
+\r
+    READ_TIMESTAMP(inst0);\r
+    READ_TIMESTAMP(inst1);\r
+    READ_TIMESTAMP(loop0);\r
+    READ_TIMESTAMP(loop1);\r
+\r
+    /* shut up the compiler */\r
+    opcode = 0;\r
+#endif\r
+\r
+/* Code access macros */\r
+\r
+#define INSTR_OFFSET()  ((int)(next_instr - first_instr))\r
+#define NEXTOP()        (*next_instr++)\r
+#define NEXTARG()       (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2])\r
+#define PEEKARG()       ((next_instr[2]<<8) + next_instr[1])\r
+#define JUMPTO(x)       (next_instr = first_instr + (x))\r
+#define JUMPBY(x)       (next_instr += (x))\r
+\r
+/* OpCode prediction macros\r
+    Some opcodes tend to come in pairs thus making it possible to\r
+    predict the second code when the first is run.  For example,\r
+    GET_ITER is often followed by FOR_ITER. And FOR_ITER is often\r
+    followed by STORE_FAST or UNPACK_SEQUENCE.\r
+\r
+    Verifying the prediction costs a single high-speed test of a register\r
+    variable against a constant.  If the pairing was good, then the\r
+    processor's own internal branch predication has a high likelihood of\r
+    success, resulting in a nearly zero-overhead transition to the\r
+    next opcode.  A successful prediction saves a trip through the eval-loop\r
+    including its two unpredictable branches, the HAS_ARG test and the\r
+    switch-case.  Combined with the processor's internal branch prediction,\r
+    a successful PREDICT has the effect of making the two opcodes run as if\r
+    they were a single new opcode with the bodies combined.\r
+\r
+    If collecting opcode statistics, your choices are to either keep the\r
+    predictions turned-on and interpret the results as if some opcodes\r
+    had been combined or turn-off predictions so that the opcode frequency\r
+    counter updates for both opcodes.\r
+*/\r
+\r
+#ifdef DYNAMIC_EXECUTION_PROFILE\r
+#define PREDICT(op)             if (0) goto PRED_##op\r
+#else\r
+#define PREDICT(op)             if (*next_instr == op) goto PRED_##op\r
+#endif\r
+\r
+#define PREDICTED(op)           PRED_##op: next_instr++\r
+#define PREDICTED_WITH_ARG(op)  PRED_##op: oparg = PEEKARG(); next_instr += 3\r
+\r
+/* Stack manipulation macros */\r
+\r
+/* The stack can grow at most MAXINT deep, as co_nlocals and\r
+   co_stacksize are ints. */\r
+#define STACK_LEVEL()     ((int)(stack_pointer - f->f_valuestack))\r
+#define EMPTY()           (STACK_LEVEL() == 0)\r
+#define TOP()             (stack_pointer[-1])\r
+#define SECOND()          (stack_pointer[-2])\r
+#define THIRD()           (stack_pointer[-3])\r
+#define FOURTH()          (stack_pointer[-4])\r
+#define PEEK(n)           (stack_pointer[-(n)])\r
+#define SET_TOP(v)        (stack_pointer[-1] = (v))\r
+#define SET_SECOND(v)     (stack_pointer[-2] = (v))\r
+#define SET_THIRD(v)      (stack_pointer[-3] = (v))\r
+#define SET_FOURTH(v)     (stack_pointer[-4] = (v))\r
+#define SET_VALUE(n, v)   (stack_pointer[-(n)] = (v))\r
+#define BASIC_STACKADJ(n) (stack_pointer += n)\r
+#define BASIC_PUSH(v)     (*stack_pointer++ = (v))\r
+#define BASIC_POP()       (*--stack_pointer)\r
+\r
+#ifdef LLTRACE\r
+#define PUSH(v)         { (void)(BASIC_PUSH(v), \\r
+                          lltrace && prtrace(TOP(), "push")); \\r
+                          assert(STACK_LEVEL() <= co->co_stacksize); }\r
+#define POP()           ((void)(lltrace && prtrace(TOP(), "pop")), \\r
+                         BASIC_POP())\r
+#define STACKADJ(n)     { (void)(BASIC_STACKADJ(n), \\r
+                          lltrace && prtrace(TOP(), "stackadj")); \\r
+                          assert(STACK_LEVEL() <= co->co_stacksize); }\r
+#define EXT_POP(STACK_POINTER) ((void)(lltrace && \\r
+                                prtrace((STACK_POINTER)[-1], "ext_pop")), \\r
+                                *--(STACK_POINTER))\r
+#else\r
+#define PUSH(v)                BASIC_PUSH(v)\r
+#define POP()                  BASIC_POP()\r
+#define STACKADJ(n)            BASIC_STACKADJ(n)\r
+#define EXT_POP(STACK_POINTER) (*--(STACK_POINTER))\r
+#endif\r
+\r
+/* Local variable macros */\r
+\r
+#define GETLOCAL(i)     (fastlocals[i])\r
+\r
+/* The SETLOCAL() macro must not DECREF the local variable in-place and\r
+   then store the new value; it must copy the old value to a temporary\r
+   value, then store the new value, and then DECREF the temporary value.\r
+   This is because it is possible that during the DECREF the frame is\r
+   accessed by other code (e.g. a __del__ method or gc.collect()) and the\r
+   variable would be pointing to already-freed memory. */\r
+#define SETLOCAL(i, value)      do { PyObject *tmp = GETLOCAL(i); \\r
+                                     GETLOCAL(i) = value; \\r
+                                     Py_XDECREF(tmp); } while (0)\r
+\r
+/* Start of code */\r
+\r
+    if (f == NULL)\r
+        return NULL;\r
+\r
+    /* push frame */\r
+    if (Py_EnterRecursiveCall(""))\r
+        return NULL;\r
+\r
+    tstate->frame = f;\r
+\r
+    if (tstate->use_tracing) {\r
+        if (tstate->c_tracefunc != NULL) {\r
+            /* tstate->c_tracefunc, if defined, is a\r
+               function that will be called on *every* entry\r
+               to a code block.  Its return value, if not\r
+               None, is a function that will be called at\r
+               the start of each executed line of code.\r
+               (Actually, the function must return itself\r
+               in order to continue tracing.)  The trace\r
+               functions are called with three arguments:\r
+               a pointer to the current frame, a string\r
+               indicating why the function is called, and\r
+               an argument which depends on the situation.\r
+               The global trace function is also called\r
+               whenever an exception is detected. */\r
+            if (call_trace_protected(tstate->c_tracefunc,\r
+                                     tstate->c_traceobj,\r
+                                     f, PyTrace_CALL, Py_None)) {\r
+                /* Trace function raised an error */\r
+                goto exit_eval_frame;\r
+            }\r
+        }\r
+        if (tstate->c_profilefunc != NULL) {\r
+            /* Similar for c_profilefunc, except it needn't\r
+               return itself and isn't called for "line" events */\r
+            if (call_trace_protected(tstate->c_profilefunc,\r
+                                     tstate->c_profileobj,\r
+                                     f, PyTrace_CALL, Py_None)) {\r
+                /* Profile function raised an error */\r
+                goto exit_eval_frame;\r
+            }\r
+        }\r
+    }\r
+\r
+    co = f->f_code;\r
+    names = co->co_names;\r
+    consts = co->co_consts;\r
+    fastlocals = f->f_localsplus;\r
+    freevars = f->f_localsplus + co->co_nlocals;\r
+    first_instr = (unsigned char*) PyString_AS_STRING(co->co_code);\r
+    /* An explanation is in order for the next line.\r
+\r
+       f->f_lasti now refers to the index of the last instruction\r
+       executed.  You might think this was obvious from the name, but\r
+       this wasn't always true before 2.3!  PyFrame_New now sets\r
+       f->f_lasti to -1 (i.e. the index *before* the first instruction)\r
+       and YIELD_VALUE doesn't fiddle with f_lasti any more.  So this\r
+       does work.  Promise.\r
+\r
+       When the PREDICT() macros are enabled, some opcode pairs follow in\r
+       direct succession without updating f->f_lasti.  A successful\r
+       prediction effectively links the two codes together as if they\r
+       were a single new opcode; accordingly,f->f_lasti will point to\r
+       the first code in the pair (for instance, GET_ITER followed by\r
+       FOR_ITER is effectively a single opcode and f->f_lasti will point\r
+       at to the beginning of the combined pair.)\r
+    */\r
+    next_instr = first_instr + f->f_lasti + 1;\r
+    stack_pointer = f->f_stacktop;\r
+    assert(stack_pointer != NULL);\r
+    f->f_stacktop = NULL;       /* remains NULL unless yield suspends frame */\r
+\r
+#ifdef LLTRACE\r
+    lltrace = PyDict_GetItemString(f->f_globals, "__lltrace__") != NULL;\r
+#endif\r
+#if defined(Py_DEBUG) || defined(LLTRACE)\r
+    filename = PyString_AsString(co->co_filename);\r
+#endif\r
+\r
+    why = WHY_NOT;\r
+    err = 0;\r
+    x = Py_None;        /* Not a reference, just anything non-NULL */\r
+    w = NULL;\r
+\r
+    if (throwflag) { /* support for generator.throw() */\r
+        why = WHY_EXCEPTION;\r
+        goto on_error;\r
+    }\r
+\r
+    for (;;) {\r
+#ifdef WITH_TSC\r
+        if (inst1 == 0) {\r
+            /* Almost surely, the opcode executed a break\r
+               or a continue, preventing inst1 from being set\r
+               on the way out of the loop.\r
+            */\r
+            READ_TIMESTAMP(inst1);\r
+            loop1 = inst1;\r
+        }\r
+        dump_tsc(opcode, ticked, inst0, inst1, loop0, loop1,\r
+                 intr0, intr1);\r
+        ticked = 0;\r
+        inst1 = 0;\r
+        intr0 = 0;\r
+        intr1 = 0;\r
+        READ_TIMESTAMP(loop0);\r
+#endif\r
+        assert(stack_pointer >= f->f_valuestack); /* else underflow */\r
+        assert(STACK_LEVEL() <= co->co_stacksize);  /* else overflow */\r
+\r
+        /* Do periodic things.  Doing this every time through\r
+           the loop would add too much overhead, so we do it\r
+           only every Nth instruction.  We also do it if\r
+           ``pendingcalls_to_do'' is set, i.e. when an asynchronous\r
+           event needs attention (e.g. a signal handler or\r
+           async I/O handler); see Py_AddPendingCall() and\r
+           Py_MakePendingCalls() above. */\r
+\r
+        if (--_Py_Ticker < 0) {\r
+            if (*next_instr == SETUP_FINALLY) {\r
+                /* Make the last opcode before\r
+                   a try: finally: block uninterruptible. */\r
+                goto fast_next_opcode;\r
+            }\r
+            _Py_Ticker = _Py_CheckInterval;\r
+            tstate->tick_counter++;\r
+#ifdef WITH_TSC\r
+            ticked = 1;\r
+#endif\r
+            if (pendingcalls_to_do) {\r
+                if (Py_MakePendingCalls() < 0) {\r
+                    why = WHY_EXCEPTION;\r
+                    goto on_error;\r
+                }\r
+                if (pendingcalls_to_do)\r
+                    /* MakePendingCalls() didn't succeed.\r
+                       Force early re-execution of this\r
+                       "periodic" code, possibly after\r
+                       a thread switch */\r
+                    _Py_Ticker = 0;\r
+            }\r
+#ifdef WITH_THREAD\r
+            if (interpreter_lock) {\r
+                /* Give another thread a chance */\r
+\r
+                if (PyThreadState_Swap(NULL) != tstate)\r
+                    Py_FatalError("ceval: tstate mix-up");\r
+                PyThread_release_lock(interpreter_lock);\r
+\r
+                /* Other threads may run now */\r
+\r
+                PyThread_acquire_lock(interpreter_lock, 1);\r
+\r
+                if (PyThreadState_Swap(tstate) != NULL)\r
+                    Py_FatalError("ceval: orphan tstate");\r
+\r
+                /* Check for thread interrupts */\r
+\r
+                if (tstate->async_exc != NULL) {\r
+                    x = tstate->async_exc;\r
+                    tstate->async_exc = NULL;\r
+                    PyErr_SetNone(x);\r
+                    Py_DECREF(x);\r
+                    why = WHY_EXCEPTION;\r
+                    goto on_error;\r
+                }\r
+            }\r
+#endif\r
+        }\r
+\r
+    fast_next_opcode:\r
+        f->f_lasti = INSTR_OFFSET();\r
+\r
+        /* line-by-line tracing support */\r
+\r
+        if (_Py_TracingPossible &&\r
+            tstate->c_tracefunc != NULL && !tstate->tracing) {\r
+            /* see maybe_call_line_trace\r
+               for expository comments */\r
+            f->f_stacktop = stack_pointer;\r
+\r
+            err = maybe_call_line_trace(tstate->c_tracefunc,\r
+                                        tstate->c_traceobj,\r
+                                        f, &instr_lb, &instr_ub,\r
+                                        &instr_prev);\r
+            /* Reload possibly changed frame fields */\r
+            JUMPTO(f->f_lasti);\r
+            if (f->f_stacktop != NULL) {\r
+                stack_pointer = f->f_stacktop;\r
+                f->f_stacktop = NULL;\r
+            }\r
+            if (err) {\r
+                /* trace function raised an exception */\r
+                goto on_error;\r
+            }\r
+        }\r
+\r
+        /* Extract opcode and argument */\r
+\r
+        opcode = NEXTOP();\r
+        oparg = 0;   /* allows oparg to be stored in a register because\r
+            it doesn't have to be remembered across a full loop */\r
+        if (HAS_ARG(opcode))\r
+            oparg = NEXTARG();\r
+    dispatch_opcode:\r
+#ifdef DYNAMIC_EXECUTION_PROFILE\r
+#ifdef DXPAIRS\r
+        dxpairs[lastopcode][opcode]++;\r
+        lastopcode = opcode;\r
+#endif\r
+        dxp[opcode]++;\r
+#endif\r
+\r
+#ifdef LLTRACE\r
+        /* Instruction tracing */\r
+\r
+        if (lltrace) {\r
+            if (HAS_ARG(opcode)) {\r
+                printf("%d: %d, %d\n",\r
+                       f->f_lasti, opcode, oparg);\r
+            }\r
+            else {\r
+                printf("%d: %d\n",\r
+                       f->f_lasti, opcode);\r
+            }\r
+        }\r
+#endif\r
+\r
+        /* Main switch on opcode */\r
+        READ_TIMESTAMP(inst0);\r
+\r
+        switch (opcode) {\r
+\r
+        /* BEWARE!\r
+           It is essential that any operation that fails sets either\r
+           x to NULL, err to nonzero, or why to anything but WHY_NOT,\r
+           and that no operation that succeeds does this! */\r
+\r
+        /* case STOP_CODE: this is an error! */\r
+\r
+        case NOP:\r
+            goto fast_next_opcode;\r
+\r
+        case LOAD_FAST:\r
+            x = GETLOCAL(oparg);\r
+            if (x != NULL) {\r
+                Py_INCREF(x);\r
+                PUSH(x);\r
+                goto fast_next_opcode;\r
+            }\r
+            format_exc_check_arg(PyExc_UnboundLocalError,\r
+                UNBOUNDLOCAL_ERROR_MSG,\r
+                PyTuple_GetItem(co->co_varnames, oparg));\r
+            break;\r
+\r
+        case LOAD_CONST:\r
+            x = GETITEM(consts, oparg);\r
+            Py_INCREF(x);\r
+            PUSH(x);\r
+            goto fast_next_opcode;\r
+\r
+        PREDICTED_WITH_ARG(STORE_FAST);\r
+        case STORE_FAST:\r
+            v = POP();\r
+            SETLOCAL(oparg, v);\r
+            goto fast_next_opcode;\r
+\r
+        case POP_TOP:\r
+            v = POP();\r
+            Py_DECREF(v);\r
+            goto fast_next_opcode;\r
+\r
+        case ROT_TWO:\r
+            v = TOP();\r
+            w = SECOND();\r
+            SET_TOP(w);\r
+            SET_SECOND(v);\r
+            goto fast_next_opcode;\r
+\r
+        case ROT_THREE:\r
+            v = TOP();\r
+            w = SECOND();\r
+            x = THIRD();\r
+            SET_TOP(w);\r
+            SET_SECOND(x);\r
+            SET_THIRD(v);\r
+            goto fast_next_opcode;\r
+\r
+        case ROT_FOUR:\r
+            u = TOP();\r
+            v = SECOND();\r
+            w = THIRD();\r
+            x = FOURTH();\r
+            SET_TOP(v);\r
+            SET_SECOND(w);\r
+            SET_THIRD(x);\r
+            SET_FOURTH(u);\r
+            goto fast_next_opcode;\r
+\r
+        case DUP_TOP:\r
+            v = TOP();\r
+            Py_INCREF(v);\r
+            PUSH(v);\r
+            goto fast_next_opcode;\r
+\r
+        case DUP_TOPX:\r
+            if (oparg == 2) {\r
+                x = TOP();\r
+                Py_INCREF(x);\r
+                w = SECOND();\r
+                Py_INCREF(w);\r
+                STACKADJ(2);\r
+                SET_TOP(x);\r
+                SET_SECOND(w);\r
+                goto fast_next_opcode;\r
+            } else if (oparg == 3) {\r
+                x = TOP();\r
+                Py_INCREF(x);\r
+                w = SECOND();\r
+                Py_INCREF(w);\r
+                v = THIRD();\r
+                Py_INCREF(v);\r
+                STACKADJ(3);\r
+                SET_TOP(x);\r
+                SET_SECOND(w);\r
+                SET_THIRD(v);\r
+                goto fast_next_opcode;\r
+            }\r
+            Py_FatalError("invalid argument to DUP_TOPX"\r
+                          " (bytecode corruption?)");\r
+            /* Never returns, so don't bother to set why. */\r
+            break;\r
+\r
+        case UNARY_POSITIVE:\r
+            v = TOP();\r
+            x = PyNumber_Positive(v);\r
+            Py_DECREF(v);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case UNARY_NEGATIVE:\r
+            v = TOP();\r
+            x = PyNumber_Negative(v);\r
+            Py_DECREF(v);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case UNARY_NOT:\r
+            v = TOP();\r
+            err = PyObject_IsTrue(v);\r
+            Py_DECREF(v);\r
+            if (err == 0) {\r
+                Py_INCREF(Py_True);\r
+                SET_TOP(Py_True);\r
+                continue;\r
+            }\r
+            else if (err > 0) {\r
+                Py_INCREF(Py_False);\r
+                SET_TOP(Py_False);\r
+                err = 0;\r
+                continue;\r
+            }\r
+            STACKADJ(-1);\r
+            break;\r
+\r
+        case UNARY_CONVERT:\r
+            v = TOP();\r
+            x = PyObject_Repr(v);\r
+            Py_DECREF(v);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case UNARY_INVERT:\r
+            v = TOP();\r
+            x = PyNumber_Invert(v);\r
+            Py_DECREF(v);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case BINARY_POWER:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_Power(v, w, Py_None);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case BINARY_MULTIPLY:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_Multiply(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case BINARY_DIVIDE:\r
+            if (!_Py_QnewFlag) {\r
+                w = POP();\r
+                v = TOP();\r
+                x = PyNumber_Divide(v, w);\r
+                Py_DECREF(v);\r
+                Py_DECREF(w);\r
+                SET_TOP(x);\r
+                if (x != NULL) continue;\r
+                break;\r
+            }\r
+            /* -Qnew is in effect:  fall through to\r
+               BINARY_TRUE_DIVIDE */\r
+        case BINARY_TRUE_DIVIDE:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_TrueDivide(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case BINARY_FLOOR_DIVIDE:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_FloorDivide(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case BINARY_MODULO:\r
+            w = POP();\r
+            v = TOP();\r
+            if (PyString_CheckExact(v))\r
+                x = PyString_Format(v, w);\r
+            else\r
+                x = PyNumber_Remainder(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case BINARY_ADD:\r
+            w = POP();\r
+            v = TOP();\r
+            if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {\r
+                /* INLINE: int + int */\r
+                register long a, b, i;\r
+                a = PyInt_AS_LONG(v);\r
+                b = PyInt_AS_LONG(w);\r
+                /* cast to avoid undefined behaviour\r
+                   on overflow */\r
+                i = (long)((unsigned long)a + b);\r
+                if ((i^a) < 0 && (i^b) < 0)\r
+                    goto slow_add;\r
+                x = PyInt_FromLong(i);\r
+            }\r
+            else if (PyString_CheckExact(v) &&\r
+                     PyString_CheckExact(w)) {\r
+                x = string_concatenate(v, w, f, next_instr);\r
+                /* string_concatenate consumed the ref to v */\r
+                goto skip_decref_vx;\r
+            }\r
+            else {\r
+              slow_add:\r
+                x = PyNumber_Add(v, w);\r
+            }\r
+            Py_DECREF(v);\r
+          skip_decref_vx:\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case BINARY_SUBTRACT:\r
+            w = POP();\r
+            v = TOP();\r
+            if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {\r
+                /* INLINE: int - int */\r
+                register long a, b, i;\r
+                a = PyInt_AS_LONG(v);\r
+                b = PyInt_AS_LONG(w);\r
+                /* cast to avoid undefined behaviour\r
+                   on overflow */\r
+                i = (long)((unsigned long)a - b);\r
+                if ((i^a) < 0 && (i^~b) < 0)\r
+                    goto slow_sub;\r
+                x = PyInt_FromLong(i);\r
+            }\r
+            else {\r
+              slow_sub:\r
+                x = PyNumber_Subtract(v, w);\r
+            }\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case BINARY_SUBSCR:\r
+            w = POP();\r
+            v = TOP();\r
+            if (PyList_CheckExact(v) && PyInt_CheckExact(w)) {\r
+                /* INLINE: list[int] */\r
+                Py_ssize_t i = PyInt_AsSsize_t(w);\r
+                if (i < 0)\r
+                    i += PyList_GET_SIZE(v);\r
+                if (i >= 0 && i < PyList_GET_SIZE(v)) {\r
+                    x = PyList_GET_ITEM(v, i);\r
+                    Py_INCREF(x);\r
+                }\r
+                else\r
+                    goto slow_get;\r
+            }\r
+            else\r
+              slow_get:\r
+                x = PyObject_GetItem(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case BINARY_LSHIFT:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_Lshift(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case BINARY_RSHIFT:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_Rshift(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case BINARY_AND:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_And(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case BINARY_XOR:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_Xor(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case BINARY_OR:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_Or(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case LIST_APPEND:\r
+            w = POP();\r
+            v = PEEK(oparg);\r
+            err = PyList_Append(v, w);\r
+            Py_DECREF(w);\r
+            if (err == 0) {\r
+                PREDICT(JUMP_ABSOLUTE);\r
+                continue;\r
+            }\r
+            break;\r
+\r
+        case SET_ADD:\r
+            w = POP();\r
+            v = stack_pointer[-oparg];\r
+            err = PySet_Add(v, w);\r
+            Py_DECREF(w);\r
+            if (err == 0) {\r
+                PREDICT(JUMP_ABSOLUTE);\r
+                continue;\r
+            }\r
+            break;\r
+\r
+        case INPLACE_POWER:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_InPlacePower(v, w, Py_None);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case INPLACE_MULTIPLY:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_InPlaceMultiply(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case INPLACE_DIVIDE:\r
+            if (!_Py_QnewFlag) {\r
+                w = POP();\r
+                v = TOP();\r
+                x = PyNumber_InPlaceDivide(v, w);\r
+                Py_DECREF(v);\r
+                Py_DECREF(w);\r
+                SET_TOP(x);\r
+                if (x != NULL) continue;\r
+                break;\r
+            }\r
+            /* -Qnew is in effect:  fall through to\r
+               INPLACE_TRUE_DIVIDE */\r
+        case INPLACE_TRUE_DIVIDE:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_InPlaceTrueDivide(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case INPLACE_FLOOR_DIVIDE:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_InPlaceFloorDivide(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case INPLACE_MODULO:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_InPlaceRemainder(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case INPLACE_ADD:\r
+            w = POP();\r
+            v = TOP();\r
+            if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {\r
+                /* INLINE: int + int */\r
+                register long a, b, i;\r
+                a = PyInt_AS_LONG(v);\r
+                b = PyInt_AS_LONG(w);\r
+                i = a + b;\r
+                if ((i^a) < 0 && (i^b) < 0)\r
+                    goto slow_iadd;\r
+                x = PyInt_FromLong(i);\r
+            }\r
+            else if (PyString_CheckExact(v) &&\r
+                     PyString_CheckExact(w)) {\r
+                x = string_concatenate(v, w, f, next_instr);\r
+                /* string_concatenate consumed the ref to v */\r
+                goto skip_decref_v;\r
+            }\r
+            else {\r
+              slow_iadd:\r
+                x = PyNumber_InPlaceAdd(v, w);\r
+            }\r
+            Py_DECREF(v);\r
+          skip_decref_v:\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case INPLACE_SUBTRACT:\r
+            w = POP();\r
+            v = TOP();\r
+            if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {\r
+                /* INLINE: int - int */\r
+                register long a, b, i;\r
+                a = PyInt_AS_LONG(v);\r
+                b = PyInt_AS_LONG(w);\r
+                i = a - b;\r
+                if ((i^a) < 0 && (i^~b) < 0)\r
+                    goto slow_isub;\r
+                x = PyInt_FromLong(i);\r
+            }\r
+            else {\r
+              slow_isub:\r
+                x = PyNumber_InPlaceSubtract(v, w);\r
+            }\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case INPLACE_LSHIFT:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_InPlaceLshift(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case INPLACE_RSHIFT:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_InPlaceRshift(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case INPLACE_AND:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_InPlaceAnd(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case INPLACE_XOR:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_InPlaceXor(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case INPLACE_OR:\r
+            w = POP();\r
+            v = TOP();\r
+            x = PyNumber_InPlaceOr(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case SLICE+0:\r
+        case SLICE+1:\r
+        case SLICE+2:\r
+        case SLICE+3:\r
+            if ((opcode-SLICE) & 2)\r
+                w = POP();\r
+            else\r
+                w = NULL;\r
+            if ((opcode-SLICE) & 1)\r
+                v = POP();\r
+            else\r
+                v = NULL;\r
+            u = TOP();\r
+            x = apply_slice(u, v, w);\r
+            Py_DECREF(u);\r
+            Py_XDECREF(v);\r
+            Py_XDECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case STORE_SLICE+0:\r
+        case STORE_SLICE+1:\r
+        case STORE_SLICE+2:\r
+        case STORE_SLICE+3:\r
+            if ((opcode-STORE_SLICE) & 2)\r
+                w = POP();\r
+            else\r
+                w = NULL;\r
+            if ((opcode-STORE_SLICE) & 1)\r
+                v = POP();\r
+            else\r
+                v = NULL;\r
+            u = POP();\r
+            t = POP();\r
+            err = assign_slice(u, v, w, t); /* u[v:w] = t */\r
+            Py_DECREF(t);\r
+            Py_DECREF(u);\r
+            Py_XDECREF(v);\r
+            Py_XDECREF(w);\r
+            if (err == 0) continue;\r
+            break;\r
+\r
+        case DELETE_SLICE+0:\r
+        case DELETE_SLICE+1:\r
+        case DELETE_SLICE+2:\r
+        case DELETE_SLICE+3:\r
+            if ((opcode-DELETE_SLICE) & 2)\r
+                w = POP();\r
+            else\r
+                w = NULL;\r
+            if ((opcode-DELETE_SLICE) & 1)\r
+                v = POP();\r
+            else\r
+                v = NULL;\r
+            u = POP();\r
+            err = assign_slice(u, v, w, (PyObject *)NULL);\r
+                                            /* del u[v:w] */\r
+            Py_DECREF(u);\r
+            Py_XDECREF(v);\r
+            Py_XDECREF(w);\r
+            if (err == 0) continue;\r
+            break;\r
+\r
+        case STORE_SUBSCR:\r
+            w = TOP();\r
+            v = SECOND();\r
+            u = THIRD();\r
+            STACKADJ(-3);\r
+            /* v[w] = u */\r
+            err = PyObject_SetItem(v, w, u);\r
+            Py_DECREF(u);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            if (err == 0) continue;\r
+            break;\r
+\r
+        case DELETE_SUBSCR:\r
+            w = TOP();\r
+            v = SECOND();\r
+            STACKADJ(-2);\r
+            /* del v[w] */\r
+            err = PyObject_DelItem(v, w);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            if (err == 0) continue;\r
+            break;\r
+\r
+        case PRINT_EXPR:\r
+            v = POP();\r
+            w = PySys_GetObject("displayhook");\r
+            if (w == NULL) {\r
+                PyErr_SetString(PyExc_RuntimeError,\r
+                                "lost sys.displayhook");\r
+                err = -1;\r
+                x = NULL;\r
+            }\r
+            if (err == 0) {\r
+                x = PyTuple_Pack(1, v);\r
+                if (x == NULL)\r
+                    err = -1;\r
+            }\r
+            if (err == 0) {\r
+                w = PyEval_CallObject(w, x);\r
+                Py_XDECREF(w);\r
+                if (w == NULL)\r
+                    err = -1;\r
+            }\r
+            Py_DECREF(v);\r
+            Py_XDECREF(x);\r
+            break;\r
+\r
+        case PRINT_ITEM_TO:\r
+            w = stream = POP();\r
+            /* fall through to PRINT_ITEM */\r
+\r
+        case PRINT_ITEM:\r
+            v = POP();\r
+            if (stream == NULL || stream == Py_None) {\r
+                w = PySys_GetObject("stdout");\r
+                if (w == NULL) {\r
+                    PyErr_SetString(PyExc_RuntimeError,\r
+                                    "lost sys.stdout");\r
+                    err = -1;\r
+                }\r
+            }\r
+            /* PyFile_SoftSpace() can exececute arbitrary code\r
+               if sys.stdout is an instance with a __getattr__.\r
+               If __getattr__ raises an exception, w will\r
+               be freed, so we need to prevent that temporarily. */\r
+            Py_XINCREF(w);\r
+            if (w != NULL && PyFile_SoftSpace(w, 0))\r
+                err = PyFile_WriteString(" ", w);\r
+            if (err == 0)\r
+                err = PyFile_WriteObject(v, w, Py_PRINT_RAW);\r
+            if (err == 0) {\r
+                /* XXX move into writeobject() ? */\r
+                if (PyString_Check(v)) {\r
+                    char *s = PyString_AS_STRING(v);\r
+                    Py_ssize_t len = PyString_GET_SIZE(v);\r
+                    if (len == 0 ||\r
+                        !isspace(Py_CHARMASK(s[len-1])) ||\r
+                        s[len-1] == ' ')\r
+                        PyFile_SoftSpace(w, 1);\r
+                }\r
+#ifdef Py_USING_UNICODE\r
+                else if (PyUnicode_Check(v)) {\r
+                    Py_UNICODE *s = PyUnicode_AS_UNICODE(v);\r
+                    Py_ssize_t len = PyUnicode_GET_SIZE(v);\r
+                    if (len == 0 ||\r
+                        !Py_UNICODE_ISSPACE(s[len-1]) ||\r
+                        s[len-1] == ' ')\r
+                        PyFile_SoftSpace(w, 1);\r
+                }\r
+#endif\r
+                else\r
+                    PyFile_SoftSpace(w, 1);\r
+            }\r
+            Py_XDECREF(w);\r
+            Py_DECREF(v);\r
+            Py_XDECREF(stream);\r
+            stream = NULL;\r
+            if (err == 0)\r
+                continue;\r
+            break;\r
+\r
+        case PRINT_NEWLINE_TO:\r
+            w = stream = POP();\r
+            /* fall through to PRINT_NEWLINE */\r
+\r
+        case PRINT_NEWLINE:\r
+            if (stream == NULL || stream == Py_None) {\r
+                w = PySys_GetObject("stdout");\r
+                if (w == NULL) {\r
+                    PyErr_SetString(PyExc_RuntimeError,\r
+                                    "lost sys.stdout");\r
+                    why = WHY_EXCEPTION;\r
+                }\r
+            }\r
+            if (w != NULL) {\r
+                /* w.write() may replace sys.stdout, so we\r
+                 * have to keep our reference to it */\r
+                Py_INCREF(w);\r
+                err = PyFile_WriteString("\n", w);\r
+                if (err == 0)\r
+                    PyFile_SoftSpace(w, 0);\r
+                Py_DECREF(w);\r
+            }\r
+            Py_XDECREF(stream);\r
+            stream = NULL;\r
+            break;\r
+\r
+\r
+#ifdef CASE_TOO_BIG\r
+        default: switch (opcode) {\r
+#endif\r
+        case RAISE_VARARGS:\r
+            u = v = w = NULL;\r
+            switch (oparg) {\r
+            case 3:\r
+                u = POP(); /* traceback */\r
+                /* Fallthrough */\r
+            case 2:\r
+                v = POP(); /* value */\r
+                /* Fallthrough */\r
+            case 1:\r
+                w = POP(); /* exc */\r
+            case 0: /* Fallthrough */\r
+                why = do_raise(w, v, u);\r
+                break;\r
+            default:\r
+                PyErr_SetString(PyExc_SystemError,\r
+                           "bad RAISE_VARARGS oparg");\r
+                why = WHY_EXCEPTION;\r
+                break;\r
+            }\r
+            break;\r
+\r
+        case LOAD_LOCALS:\r
+            if ((x = f->f_locals) != NULL) {\r
+                Py_INCREF(x);\r
+                PUSH(x);\r
+                continue;\r
+            }\r
+            PyErr_SetString(PyExc_SystemError, "no locals");\r
+            break;\r
+\r
+        case RETURN_VALUE:\r
+            retval = POP();\r
+            why = WHY_RETURN;\r
+            goto fast_block_end;\r
+\r
+        case YIELD_VALUE:\r
+            retval = POP();\r
+            f->f_stacktop = stack_pointer;\r
+            why = WHY_YIELD;\r
+            goto fast_yield;\r
+\r
+        case EXEC_STMT:\r
+            w = TOP();\r
+            v = SECOND();\r
+            u = THIRD();\r
+            STACKADJ(-3);\r
+            READ_TIMESTAMP(intr0);\r
+            err = exec_statement(f, u, v, w);\r
+            READ_TIMESTAMP(intr1);\r
+            Py_DECREF(u);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            break;\r
+\r
+        case POP_BLOCK:\r
+            {\r
+                PyTryBlock *b = PyFrame_BlockPop(f);\r
+                while (STACK_LEVEL() > b->b_level) {\r
+                    v = POP();\r
+                    Py_DECREF(v);\r
+                }\r
+            }\r
+            continue;\r
+\r
+        PREDICTED(END_FINALLY);\r
+        case END_FINALLY:\r
+            v = POP();\r
+            if (PyInt_Check(v)) {\r
+                why = (enum why_code) PyInt_AS_LONG(v);\r
+                assert(why != WHY_YIELD);\r
+                if (why == WHY_RETURN ||\r
+                    why == WHY_CONTINUE)\r
+                    retval = POP();\r
+            }\r
+            else if (PyExceptionClass_Check(v) ||\r
+                     PyString_Check(v)) {\r
+                w = POP();\r
+                u = POP();\r
+                PyErr_Restore(v, w, u);\r
+                why = WHY_RERAISE;\r
+                break;\r
+            }\r
+            else if (v != Py_None) {\r
+                PyErr_SetString(PyExc_SystemError,\r
+                    "'finally' pops bad exception");\r
+                why = WHY_EXCEPTION;\r
+            }\r
+            Py_DECREF(v);\r
+            break;\r
+\r
+        case BUILD_CLASS:\r
+            u = TOP();\r
+            v = SECOND();\r
+            w = THIRD();\r
+            STACKADJ(-2);\r
+            x = build_class(u, v, w);\r
+            SET_TOP(x);\r
+            Py_DECREF(u);\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            break;\r
+\r
+        case STORE_NAME:\r
+            w = GETITEM(names, oparg);\r
+            v = POP();\r
+            if ((x = f->f_locals) != NULL) {\r
+                if (PyDict_CheckExact(x))\r
+                    err = PyDict_SetItem(x, w, v);\r
+                else\r
+                    err = PyObject_SetItem(x, w, v);\r
+                Py_DECREF(v);\r
+                if (err == 0) continue;\r
+                break;\r
+            }\r
+            t = PyObject_Repr(w);\r
+            if (t == NULL)\r
+                break;\r
+            PyErr_Format(PyExc_SystemError,\r
+                         "no locals found when storing %s",\r
+                         PyString_AS_STRING(t));\r
+            Py_DECREF(t);\r
+            break;\r
+\r
+        case DELETE_NAME:\r
+            w = GETITEM(names, oparg);\r
+            if ((x = f->f_locals) != NULL) {\r
+                if ((err = PyObject_DelItem(x, w)) != 0)\r
+                    format_exc_check_arg(PyExc_NameError,\r
+                                         NAME_ERROR_MSG,\r
+                                         w);\r
+                break;\r
+            }\r
+            t = PyObject_Repr(w);\r
+            if (t == NULL)\r
+                break;\r
+            PyErr_Format(PyExc_SystemError,\r
+                         "no locals when deleting %s",\r
+                         PyString_AS_STRING(w));\r
+            Py_DECREF(t);\r
+            break;\r
+\r
+        PREDICTED_WITH_ARG(UNPACK_SEQUENCE);\r
+        case UNPACK_SEQUENCE:\r
+            v = POP();\r
+            if (PyTuple_CheckExact(v) &&\r
+                PyTuple_GET_SIZE(v) == oparg) {\r
+                PyObject **items = \\r
+                    ((PyTupleObject *)v)->ob_item;\r
+                while (oparg--) {\r
+                    w = items[oparg];\r
+                    Py_INCREF(w);\r
+                    PUSH(w);\r
+                }\r
+                Py_DECREF(v);\r
+                continue;\r
+            } else if (PyList_CheckExact(v) &&\r
+                       PyList_GET_SIZE(v) == oparg) {\r
+                PyObject **items = \\r
+                    ((PyListObject *)v)->ob_item;\r
+                while (oparg--) {\r
+                    w = items[oparg];\r
+                    Py_INCREF(w);\r
+                    PUSH(w);\r
+                }\r
+            } else if (unpack_iterable(v, oparg,\r
+                                       stack_pointer + oparg)) {\r
+                STACKADJ(oparg);\r
+            } else {\r
+                /* unpack_iterable() raised an exception */\r
+                why = WHY_EXCEPTION;\r
+            }\r
+            Py_DECREF(v);\r
+            break;\r
+\r
+        case STORE_ATTR:\r
+            w = GETITEM(names, oparg);\r
+            v = TOP();\r
+            u = SECOND();\r
+            STACKADJ(-2);\r
+            err = PyObject_SetAttr(v, w, u); /* v.w = u */\r
+            Py_DECREF(v);\r
+            Py_DECREF(u);\r
+            if (err == 0) continue;\r
+            break;\r
+\r
+        case DELETE_ATTR:\r
+            w = GETITEM(names, oparg);\r
+            v = POP();\r
+            err = PyObject_SetAttr(v, w, (PyObject *)NULL);\r
+                                            /* del v.w */\r
+            Py_DECREF(v);\r
+            break;\r
+\r
+        case STORE_GLOBAL:\r
+            w = GETITEM(names, oparg);\r
+            v = POP();\r
+            err = PyDict_SetItem(f->f_globals, w, v);\r
+            Py_DECREF(v);\r
+            if (err == 0) continue;\r
+            break;\r
+\r
+        case DELETE_GLOBAL:\r
+            w = GETITEM(names, oparg);\r
+            if ((err = PyDict_DelItem(f->f_globals, w)) != 0)\r
+                format_exc_check_arg(\r
+                    PyExc_NameError, GLOBAL_NAME_ERROR_MSG, w);\r
+            break;\r
+\r
+        case LOAD_NAME:\r
+            w = GETITEM(names, oparg);\r
+            if ((v = f->f_locals) == NULL) {\r
+                why = WHY_EXCEPTION;\r
+                t = PyObject_Repr(w);\r
+                if (t == NULL)\r
+                    break;\r
+                PyErr_Format(PyExc_SystemError,\r
+                             "no locals when loading %s",\r
+                             PyString_AS_STRING(w));\r
+                Py_DECREF(t);\r
+                break;\r
+            }\r
+            if (PyDict_CheckExact(v)) {\r
+                x = PyDict_GetItem(v, w);\r
+                Py_XINCREF(x);\r
+            }\r
+            else {\r
+                x = PyObject_GetItem(v, w);\r
+                if (x == NULL && PyErr_Occurred()) {\r
+                    if (!PyErr_ExceptionMatches(\r
+                                    PyExc_KeyError))\r
+                        break;\r
+                    PyErr_Clear();\r
+                }\r
+            }\r
+            if (x == NULL) {\r
+                x = PyDict_GetItem(f->f_globals, w);\r
+                if (x == NULL) {\r
+                    x = PyDict_GetItem(f->f_builtins, w);\r
+                    if (x == NULL) {\r
+                        format_exc_check_arg(\r
+                                    PyExc_NameError,\r
+                                    NAME_ERROR_MSG, w);\r
+                        break;\r
+                    }\r
+                }\r
+                Py_INCREF(x);\r
+            }\r
+            PUSH(x);\r
+            continue;\r
+\r
+        case LOAD_GLOBAL:\r
+            w = GETITEM(names, oparg);\r
+            if (PyString_CheckExact(w)) {\r
+                /* Inline the PyDict_GetItem() calls.\r
+                   WARNING: this is an extreme speed hack.\r
+                   Do not try this at home. */\r
+                long hash = ((PyStringObject *)w)->ob_shash;\r
+                if (hash != -1) {\r
+                    PyDictObject *d;\r
+                    PyDictEntry *e;\r
+                    d = (PyDictObject *)(f->f_globals);\r
+                    e = d->ma_lookup(d, w, hash);\r
+                    if (e == NULL) {\r
+                        x = NULL;\r
+                        break;\r
+                    }\r
+                    x = e->me_value;\r
+                    if (x != NULL) {\r
+                        Py_INCREF(x);\r
+                        PUSH(x);\r
+                        continue;\r
+                    }\r
+                    d = (PyDictObject *)(f->f_builtins);\r
+                    e = d->ma_lookup(d, w, hash);\r
+                    if (e == NULL) {\r
+                        x = NULL;\r
+                        break;\r
+                    }\r
+                    x = e->me_value;\r
+                    if (x != NULL) {\r
+                        Py_INCREF(x);\r
+                        PUSH(x);\r
+                        continue;\r
+                    }\r
+                    goto load_global_error;\r
+                }\r
+            }\r
+            /* This is the un-inlined version of the code above */\r
+            x = PyDict_GetItem(f->f_globals, w);\r
+            if (x == NULL) {\r
+                x = PyDict_GetItem(f->f_builtins, w);\r
+                if (x == NULL) {\r
+                  load_global_error:\r
+                    format_exc_check_arg(\r
+                                PyExc_NameError,\r
+                                GLOBAL_NAME_ERROR_MSG, w);\r
+                    break;\r
+                }\r
+            }\r
+            Py_INCREF(x);\r
+            PUSH(x);\r
+            continue;\r
+\r
+        case DELETE_FAST:\r
+            x = GETLOCAL(oparg);\r
+            if (x != NULL) {\r
+                SETLOCAL(oparg, NULL);\r
+                continue;\r
+            }\r
+            format_exc_check_arg(\r
+                PyExc_UnboundLocalError,\r
+                UNBOUNDLOCAL_ERROR_MSG,\r
+                PyTuple_GetItem(co->co_varnames, oparg)\r
+                );\r
+            break;\r
+\r
+        case LOAD_CLOSURE:\r
+            x = freevars[oparg];\r
+            Py_INCREF(x);\r
+            PUSH(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case LOAD_DEREF:\r
+            x = freevars[oparg];\r
+            w = PyCell_Get(x);\r
+            if (w != NULL) {\r
+                PUSH(w);\r
+                continue;\r
+            }\r
+            err = -1;\r
+            /* Don't stomp existing exception */\r
+            if (PyErr_Occurred())\r
+                break;\r
+            if (oparg < PyTuple_GET_SIZE(co->co_cellvars)) {\r
+                v = PyTuple_GET_ITEM(co->co_cellvars,\r
+                                     oparg);\r
+                format_exc_check_arg(\r
+                       PyExc_UnboundLocalError,\r
+                       UNBOUNDLOCAL_ERROR_MSG,\r
+                       v);\r
+            } else {\r
+                v = PyTuple_GET_ITEM(co->co_freevars, oparg -\r
+                    PyTuple_GET_SIZE(co->co_cellvars));\r
+                format_exc_check_arg(PyExc_NameError,\r
+                                     UNBOUNDFREE_ERROR_MSG, v);\r
+            }\r
+            break;\r
+\r
+        case STORE_DEREF:\r
+            w = POP();\r
+            x = freevars[oparg];\r
+            PyCell_Set(x, w);\r
+            Py_DECREF(w);\r
+            continue;\r
+\r
+        case BUILD_TUPLE:\r
+            x = PyTuple_New(oparg);\r
+            if (x != NULL) {\r
+                for (; --oparg >= 0;) {\r
+                    w = POP();\r
+                    PyTuple_SET_ITEM(x, oparg, w);\r
+                }\r
+                PUSH(x);\r
+                continue;\r
+            }\r
+            break;\r
+\r
+        case BUILD_LIST:\r
+            x =  PyList_New(oparg);\r
+            if (x != NULL) {\r
+                for (; --oparg >= 0;) {\r
+                    w = POP();\r
+                    PyList_SET_ITEM(x, oparg, w);\r
+                }\r
+                PUSH(x);\r
+                continue;\r
+            }\r
+            break;\r
+\r
+        case BUILD_SET:\r
+            x = PySet_New(NULL);\r
+            if (x != NULL) {\r
+                for (; --oparg >= 0;) {\r
+                    w = POP();\r
+                    if (err == 0)\r
+                        err = PySet_Add(x, w);\r
+                    Py_DECREF(w);\r
+                }\r
+                if (err != 0) {\r
+                    Py_DECREF(x);\r
+                    break;\r
+                }\r
+                PUSH(x);\r
+                continue;\r
+            }\r
+            break;\r
+\r
+\r
+        case BUILD_MAP:\r
+            x = _PyDict_NewPresized((Py_ssize_t)oparg);\r
+            PUSH(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case STORE_MAP:\r
+            w = TOP();     /* key */\r
+            u = SECOND();  /* value */\r
+            v = THIRD();   /* dict */\r
+            STACKADJ(-2);\r
+            assert (PyDict_CheckExact(v));\r
+            err = PyDict_SetItem(v, w, u);  /* v[w] = u */\r
+            Py_DECREF(u);\r
+            Py_DECREF(w);\r
+            if (err == 0) continue;\r
+            break;\r
+\r
+        case MAP_ADD:\r
+            w = TOP();     /* key */\r
+            u = SECOND();  /* value */\r
+            STACKADJ(-2);\r
+            v = stack_pointer[-oparg];  /* dict */\r
+            assert (PyDict_CheckExact(v));\r
+            err = PyDict_SetItem(v, w, u);  /* v[w] = u */\r
+            Py_DECREF(u);\r
+            Py_DECREF(w);\r
+            if (err == 0) {\r
+                PREDICT(JUMP_ABSOLUTE);\r
+                continue;\r
+            }\r
+            break;\r
+\r
+        case LOAD_ATTR:\r
+            w = GETITEM(names, oparg);\r
+            v = TOP();\r
+            x = PyObject_GetAttr(v, w);\r
+            Py_DECREF(v);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case COMPARE_OP:\r
+            w = POP();\r
+            v = TOP();\r
+            if (PyInt_CheckExact(w) && PyInt_CheckExact(v)) {\r
+                /* INLINE: cmp(int, int) */\r
+                register long a, b;\r
+                register int res;\r
+                a = PyInt_AS_LONG(v);\r
+                b = PyInt_AS_LONG(w);\r
+                switch (oparg) {\r
+                case PyCmp_LT: res = a <  b; break;\r
+                case PyCmp_LE: res = a <= b; break;\r
+                case PyCmp_EQ: res = a == b; break;\r
+                case PyCmp_NE: res = a != b; break;\r
+                case PyCmp_GT: res = a >  b; break;\r
+                case PyCmp_GE: res = a >= b; break;\r
+                case PyCmp_IS: res = v == w; break;\r
+                case PyCmp_IS_NOT: res = v != w; break;\r
+                default: goto slow_compare;\r
+                }\r
+                x = res ? Py_True : Py_False;\r
+                Py_INCREF(x);\r
+            }\r
+            else {\r
+              slow_compare:\r
+                x = cmp_outcome(oparg, v, w);\r
+            }\r
+            Py_DECREF(v);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x == NULL) break;\r
+            PREDICT(POP_JUMP_IF_FALSE);\r
+            PREDICT(POP_JUMP_IF_TRUE);\r
+            continue;\r
+\r
+        case IMPORT_NAME:\r
+            w = GETITEM(names, oparg);\r
+            x = PyDict_GetItemString(f->f_builtins, "__import__");\r
+            if (x == NULL) {\r
+                PyErr_SetString(PyExc_ImportError,\r
+                                "__import__ not found");\r
+                break;\r
+            }\r
+            Py_INCREF(x);\r
+            v = POP();\r
+            u = TOP();\r
+            if (PyInt_AsLong(u) != -1 || PyErr_Occurred())\r
+                w = PyTuple_Pack(5,\r
+                            w,\r
+                            f->f_globals,\r
+                            f->f_locals == NULL ?\r
+                                  Py_None : f->f_locals,\r
+                            v,\r
+                            u);\r
+            else\r
+                w = PyTuple_Pack(4,\r
+                            w,\r
+                            f->f_globals,\r
+                            f->f_locals == NULL ?\r
+                                  Py_None : f->f_locals,\r
+                            v);\r
+            Py_DECREF(v);\r
+            Py_DECREF(u);\r
+            if (w == NULL) {\r
+                u = POP();\r
+                Py_DECREF(x);\r
+                x = NULL;\r
+                break;\r
+            }\r
+            READ_TIMESTAMP(intr0);\r
+            v = x;\r
+            x = PyEval_CallObject(v, w);\r
+            Py_DECREF(v);\r
+            READ_TIMESTAMP(intr1);\r
+            Py_DECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case IMPORT_STAR:\r
+            v = POP();\r
+            PyFrame_FastToLocals(f);\r
+            if ((x = f->f_locals) == NULL) {\r
+                PyErr_SetString(PyExc_SystemError,\r
+                    "no locals found during 'import *'");\r
+                break;\r
+            }\r
+            READ_TIMESTAMP(intr0);\r
+            err = import_all_from(x, v);\r
+            READ_TIMESTAMP(intr1);\r
+            PyFrame_LocalsToFast(f, 0);\r
+            Py_DECREF(v);\r
+            if (err == 0) continue;\r
+            break;\r
+\r
+        case IMPORT_FROM:\r
+            w = GETITEM(names, oparg);\r
+            v = TOP();\r
+            READ_TIMESTAMP(intr0);\r
+            x = import_from(v, w);\r
+            READ_TIMESTAMP(intr1);\r
+            PUSH(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case JUMP_FORWARD:\r
+            JUMPBY(oparg);\r
+            goto fast_next_opcode;\r
+\r
+        PREDICTED_WITH_ARG(POP_JUMP_IF_FALSE);\r
+        case POP_JUMP_IF_FALSE:\r
+            w = POP();\r
+            if (w == Py_True) {\r
+                Py_DECREF(w);\r
+                goto fast_next_opcode;\r
+            }\r
+            if (w == Py_False) {\r
+                Py_DECREF(w);\r
+                JUMPTO(oparg);\r
+                goto fast_next_opcode;\r
+            }\r
+            err = PyObject_IsTrue(w);\r
+            Py_DECREF(w);\r
+            if (err > 0)\r
+                err = 0;\r
+            else if (err == 0)\r
+                JUMPTO(oparg);\r
+            else\r
+                break;\r
+            continue;\r
+\r
+        PREDICTED_WITH_ARG(POP_JUMP_IF_TRUE);\r
+        case POP_JUMP_IF_TRUE:\r
+            w = POP();\r
+            if (w == Py_False) {\r
+                Py_DECREF(w);\r
+                goto fast_next_opcode;\r
+            }\r
+            if (w == Py_True) {\r
+                Py_DECREF(w);\r
+                JUMPTO(oparg);\r
+                goto fast_next_opcode;\r
+            }\r
+            err = PyObject_IsTrue(w);\r
+            Py_DECREF(w);\r
+            if (err > 0) {\r
+                err = 0;\r
+                JUMPTO(oparg);\r
+            }\r
+            else if (err == 0)\r
+                ;\r
+            else\r
+                break;\r
+            continue;\r
+\r
+        case JUMP_IF_FALSE_OR_POP:\r
+            w = TOP();\r
+            if (w == Py_True) {\r
+                STACKADJ(-1);\r
+                Py_DECREF(w);\r
+                goto fast_next_opcode;\r
+            }\r
+            if (w == Py_False) {\r
+                JUMPTO(oparg);\r
+                goto fast_next_opcode;\r
+            }\r
+            err = PyObject_IsTrue(w);\r
+            if (err > 0) {\r
+                STACKADJ(-1);\r
+                Py_DECREF(w);\r
+                err = 0;\r
+            }\r
+            else if (err == 0)\r
+                JUMPTO(oparg);\r
+            else\r
+                break;\r
+            continue;\r
+\r
+        case JUMP_IF_TRUE_OR_POP:\r
+            w = TOP();\r
+            if (w == Py_False) {\r
+                STACKADJ(-1);\r
+                Py_DECREF(w);\r
+                goto fast_next_opcode;\r
+            }\r
+            if (w == Py_True) {\r
+                JUMPTO(oparg);\r
+                goto fast_next_opcode;\r
+            }\r
+            err = PyObject_IsTrue(w);\r
+            if (err > 0) {\r
+                err = 0;\r
+                JUMPTO(oparg);\r
+            }\r
+            else if (err == 0) {\r
+                STACKADJ(-1);\r
+                Py_DECREF(w);\r
+            }\r
+            else\r
+                break;\r
+            continue;\r
+\r
+        PREDICTED_WITH_ARG(JUMP_ABSOLUTE);\r
+        case JUMP_ABSOLUTE:\r
+            JUMPTO(oparg);\r
+#if FAST_LOOPS\r
+            /* Enabling this path speeds-up all while and for-loops by bypassing\r
+               the per-loop checks for signals.  By default, this should be turned-off\r
+               because it prevents detection of a control-break in tight loops like\r
+               "while 1: pass".  Compile with this option turned-on when you need\r
+               the speed-up and do not need break checking inside tight loops (ones\r
+               that contain only instructions ending with goto fast_next_opcode).\r
+            */\r
+            goto fast_next_opcode;\r
+#else\r
+            continue;\r
+#endif\r
+\r
+        case GET_ITER:\r
+            /* before: [obj]; after [getiter(obj)] */\r
+            v = TOP();\r
+            x = PyObject_GetIter(v);\r
+            Py_DECREF(v);\r
+            if (x != NULL) {\r
+                SET_TOP(x);\r
+                PREDICT(FOR_ITER);\r
+                continue;\r
+            }\r
+            STACKADJ(-1);\r
+            break;\r
+\r
+        PREDICTED_WITH_ARG(FOR_ITER);\r
+        case FOR_ITER:\r
+            /* before: [iter]; after: [iter, iter()] *or* [] */\r
+            v = TOP();\r
+            x = (*v->ob_type->tp_iternext)(v);\r
+            if (x != NULL) {\r
+                PUSH(x);\r
+                PREDICT(STORE_FAST);\r
+                PREDICT(UNPACK_SEQUENCE);\r
+                continue;\r
+            }\r
+            if (PyErr_Occurred()) {\r
+                if (!PyErr_ExceptionMatches(\r
+                                PyExc_StopIteration))\r
+                    break;\r
+                PyErr_Clear();\r
+            }\r
+            /* iterator ended normally */\r
+            x = v = POP();\r
+            Py_DECREF(v);\r
+            JUMPBY(oparg);\r
+            continue;\r
+\r
+        case BREAK_LOOP:\r
+            why = WHY_BREAK;\r
+            goto fast_block_end;\r
+\r
+        case CONTINUE_LOOP:\r
+            retval = PyInt_FromLong(oparg);\r
+            if (!retval) {\r
+                x = NULL;\r
+                break;\r
+            }\r
+            why = WHY_CONTINUE;\r
+            goto fast_block_end;\r
+\r
+        case SETUP_LOOP:\r
+        case SETUP_EXCEPT:\r
+        case SETUP_FINALLY:\r
+            /* NOTE: If you add any new block-setup opcodes that\r
+               are not try/except/finally handlers, you may need\r
+               to update the PyGen_NeedsFinalizing() function.\r
+               */\r
+\r
+            PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg,\r
+                               STACK_LEVEL());\r
+            continue;\r
+\r
+        case SETUP_WITH:\r
+        {\r
+            static PyObject *exit, *enter;\r
+            w = TOP();\r
+            x = special_lookup(w, "__exit__", &exit);\r
+            if (!x)\r
+                break;\r
+            SET_TOP(x);\r
+            u = special_lookup(w, "__enter__", &enter);\r
+            Py_DECREF(w);\r
+            if (!u) {\r
+                x = NULL;\r
+                break;\r
+            }\r
+            x = PyObject_CallFunctionObjArgs(u, NULL);\r
+            Py_DECREF(u);\r
+            if (!x)\r
+                break;\r
+            /* Setup a finally block (SETUP_WITH as a block is\r
+               equivalent to SETUP_FINALLY except it normalizes\r
+               the exception) before pushing the result of\r
+               __enter__ on the stack. */\r
+            PyFrame_BlockSetup(f, SETUP_WITH, INSTR_OFFSET() + oparg,\r
+                               STACK_LEVEL());\r
+\r
+            PUSH(x);\r
+            continue;\r
+        }\r
+\r
+        case WITH_CLEANUP:\r
+        {\r
+            /* At the top of the stack are 1-3 values indicating\r
+               how/why we entered the finally clause:\r
+               - TOP = None\r
+               - (TOP, SECOND) = (WHY_{RETURN,CONTINUE}), retval\r
+               - TOP = WHY_*; no retval below it\r
+               - (TOP, SECOND, THIRD) = exc_info()\r
+               Below them is EXIT, the context.__exit__ bound method.\r
+               In the last case, we must call\r
+                 EXIT(TOP, SECOND, THIRD)\r
+               otherwise we must call\r
+                 EXIT(None, None, None)\r
+\r
+               In all cases, we remove EXIT from the stack, leaving\r
+               the rest in the same order.\r
+\r
+               In addition, if the stack represents an exception,\r
+               *and* the function call returns a 'true' value, we\r
+               "zap" this information, to prevent END_FINALLY from\r
+               re-raising the exception.  (But non-local gotos\r
+               should still be resumed.)\r
+            */\r
+\r
+            PyObject *exit_func;\r
+\r
+            u = POP();\r
+            if (u == Py_None) {\r
+                exit_func = TOP();\r
+                SET_TOP(u);\r
+                v = w = Py_None;\r
+            }\r
+            else if (PyInt_Check(u)) {\r
+                switch(PyInt_AS_LONG(u)) {\r
+                case WHY_RETURN:\r
+                case WHY_CONTINUE:\r
+                    /* Retval in TOP. */\r
+                    exit_func = SECOND();\r
+                    SET_SECOND(TOP());\r
+                    SET_TOP(u);\r
+                    break;\r
+                default:\r
+                    exit_func = TOP();\r
+                    SET_TOP(u);\r
+                    break;\r
+                }\r
+                u = v = w = Py_None;\r
+            }\r
+            else {\r
+                v = TOP();\r
+                w = SECOND();\r
+                exit_func = THIRD();\r
+                SET_TOP(u);\r
+                SET_SECOND(v);\r
+                SET_THIRD(w);\r
+            }\r
+            /* XXX Not the fastest way to call it... */\r
+            x = PyObject_CallFunctionObjArgs(exit_func, u, v, w,\r
+                                             NULL);\r
+            Py_DECREF(exit_func);\r
+            if (x == NULL)\r
+                break; /* Go to error exit */\r
+\r
+            if (u != Py_None)\r
+                err = PyObject_IsTrue(x);\r
+            else\r
+                err = 0;\r
+            Py_DECREF(x);\r
+\r
+            if (err < 0)\r
+                break; /* Go to error exit */\r
+            else if (err > 0) {\r
+                err = 0;\r
+                /* There was an exception and a true return */\r
+                STACKADJ(-2);\r
+                Py_INCREF(Py_None);\r
+                SET_TOP(Py_None);\r
+                Py_DECREF(u);\r
+                Py_DECREF(v);\r
+                Py_DECREF(w);\r
+            } else {\r
+                /* The stack was rearranged to remove EXIT\r
+                   above. Let END_FINALLY do its thing */\r
+            }\r
+            PREDICT(END_FINALLY);\r
+            break;\r
+        }\r
+\r
+        case CALL_FUNCTION:\r
+        {\r
+            PyObject **sp;\r
+            PCALL(PCALL_ALL);\r
+            sp = stack_pointer;\r
+#ifdef WITH_TSC\r
+            x = call_function(&sp, oparg, &intr0, &intr1);\r
+#else\r
+            x = call_function(&sp, oparg);\r
+#endif\r
+            stack_pointer = sp;\r
+            PUSH(x);\r
+            if (x != NULL)\r
+                continue;\r
+            break;\r
+        }\r
+\r
+        case CALL_FUNCTION_VAR:\r
+        case CALL_FUNCTION_KW:\r
+        case CALL_FUNCTION_VAR_KW:\r
+        {\r
+            int na = oparg & 0xff;\r
+            int nk = (oparg>>8) & 0xff;\r
+            int flags = (opcode - CALL_FUNCTION) & 3;\r
+            int n = na + 2 * nk;\r
+            PyObject **pfunc, *func, **sp;\r
+            PCALL(PCALL_ALL);\r
+            if (flags & CALL_FLAG_VAR)\r
+                n++;\r
+            if (flags & CALL_FLAG_KW)\r
+                n++;\r
+            pfunc = stack_pointer - n - 1;\r
+            func = *pfunc;\r
+\r
+            if (PyMethod_Check(func)\r
+                && PyMethod_GET_SELF(func) != NULL) {\r
+                PyObject *self = PyMethod_GET_SELF(func);\r
+                Py_INCREF(self);\r
+                func = PyMethod_GET_FUNCTION(func);\r
+                Py_INCREF(func);\r
+                Py_DECREF(*pfunc);\r
+                *pfunc = self;\r
+                na++;\r
+            } else\r
+                Py_INCREF(func);\r
+            sp = stack_pointer;\r
+            READ_TIMESTAMP(intr0);\r
+            x = ext_do_call(func, &sp, flags, na, nk);\r
+            READ_TIMESTAMP(intr1);\r
+            stack_pointer = sp;\r
+            Py_DECREF(func);\r
+\r
+            while (stack_pointer > pfunc) {\r
+                w = POP();\r
+                Py_DECREF(w);\r
+            }\r
+            PUSH(x);\r
+            if (x != NULL)\r
+                continue;\r
+            break;\r
+        }\r
+\r
+        case MAKE_FUNCTION:\r
+            v = POP(); /* code object */\r
+            x = PyFunction_New(v, f->f_globals);\r
+            Py_DECREF(v);\r
+            /* XXX Maybe this should be a separate opcode? */\r
+            if (x != NULL && oparg > 0) {\r
+                v = PyTuple_New(oparg);\r
+                if (v == NULL) {\r
+                    Py_DECREF(x);\r
+                    x = NULL;\r
+                    break;\r
+                }\r
+                while (--oparg >= 0) {\r
+                    w = POP();\r
+                    PyTuple_SET_ITEM(v, oparg, w);\r
+                }\r
+                err = PyFunction_SetDefaults(x, v);\r
+                Py_DECREF(v);\r
+            }\r
+            PUSH(x);\r
+            break;\r
+\r
+        case MAKE_CLOSURE:\r
+        {\r
+            v = POP(); /* code object */\r
+            x = PyFunction_New(v, f->f_globals);\r
+            Py_DECREF(v);\r
+            if (x != NULL) {\r
+                v = POP();\r
+                if (PyFunction_SetClosure(x, v) != 0) {\r
+                    /* Can't happen unless bytecode is corrupt. */\r
+                    why = WHY_EXCEPTION;\r
+                }\r
+                Py_DECREF(v);\r
+            }\r
+            if (x != NULL && oparg > 0) {\r
+                v = PyTuple_New(oparg);\r
+                if (v == NULL) {\r
+                    Py_DECREF(x);\r
+                    x = NULL;\r
+                    break;\r
+                }\r
+                while (--oparg >= 0) {\r
+                    w = POP();\r
+                    PyTuple_SET_ITEM(v, oparg, w);\r
+                }\r
+                if (PyFunction_SetDefaults(x, v) != 0) {\r
+                    /* Can't happen unless\r
+                       PyFunction_SetDefaults changes. */\r
+                    why = WHY_EXCEPTION;\r
+                }\r
+                Py_DECREF(v);\r
+            }\r
+            PUSH(x);\r
+            break;\r
+        }\r
+\r
+        case BUILD_SLICE:\r
+            if (oparg == 3)\r
+                w = POP();\r
+            else\r
+                w = NULL;\r
+            v = POP();\r
+            u = TOP();\r
+            x = PySlice_New(u, v, w);\r
+            Py_DECREF(u);\r
+            Py_DECREF(v);\r
+            Py_XDECREF(w);\r
+            SET_TOP(x);\r
+            if (x != NULL) continue;\r
+            break;\r
+\r
+        case EXTENDED_ARG:\r
+            opcode = NEXTOP();\r
+            oparg = oparg<<16 | NEXTARG();\r
+            goto dispatch_opcode;\r
+\r
+        default:\r
+            fprintf(stderr,\r
+                "XXX lineno: %d, opcode: %d\n",\r
+                PyFrame_GetLineNumber(f),\r
+                opcode);\r
+            PyErr_SetString(PyExc_SystemError, "unknown opcode");\r
+            why = WHY_EXCEPTION;\r
+            break;\r
+\r
+#ifdef CASE_TOO_BIG\r
+        }\r
+#endif\r
+\r
+        } /* switch */\r
+\r
+        on_error:\r
+\r
+        READ_TIMESTAMP(inst1);\r
+\r
+        /* Quickly continue if no error occurred */\r
+\r
+        if (why == WHY_NOT) {\r
+            if (err == 0 && x != NULL) {\r
+#ifdef CHECKEXC\r
+                /* This check is expensive! */\r
+                if (PyErr_Occurred())\r
+                    fprintf(stderr,\r
+                        "XXX undetected error\n");\r
+                else {\r
+#endif\r
+                    READ_TIMESTAMP(loop1);\r
+                    continue; /* Normal, fast path */\r
+#ifdef CHECKEXC\r
+                }\r
+#endif\r
+            }\r
+            why = WHY_EXCEPTION;\r
+            x = Py_None;\r
+            err = 0;\r
+        }\r
+\r
+        /* Double-check exception status */\r
+\r
+        if (why == WHY_EXCEPTION || why == WHY_RERAISE) {\r
+            if (!PyErr_Occurred()) {\r
+                PyErr_SetString(PyExc_SystemError,\r
+                    "error return without exception set");\r
+                why = WHY_EXCEPTION;\r
+            }\r
+        }\r
+#ifdef CHECKEXC\r
+        else {\r
+            /* This check is expensive! */\r
+            if (PyErr_Occurred()) {\r
+                char buf[128];\r
+                sprintf(buf, "Stack unwind with exception "\r
+                    "set and why=%d", why);\r
+                Py_FatalError(buf);\r
+            }\r
+        }\r
+#endif\r
+\r
+        /* Log traceback info if this is a real exception */\r
+\r
+        if (why == WHY_EXCEPTION) {\r
+            PyTraceBack_Here(f);\r
+\r
+            if (tstate->c_tracefunc != NULL)\r
+                call_exc_trace(tstate->c_tracefunc,\r
+                               tstate->c_traceobj, f);\r
+        }\r
+\r
+        /* For the rest, treat WHY_RERAISE as WHY_EXCEPTION */\r
+\r
+        if (why == WHY_RERAISE)\r
+            why = WHY_EXCEPTION;\r
+\r
+        /* Unwind stacks if a (pseudo) exception occurred */\r
+\r
+fast_block_end:\r
+        while (why != WHY_NOT && f->f_iblock > 0) {\r
+            /* Peek at the current block. */\r
+            PyTryBlock *b = &f->f_blockstack[f->f_iblock - 1];\r
+\r
+            assert(why != WHY_YIELD);\r
+            if (b->b_type == SETUP_LOOP && why == WHY_CONTINUE) {\r
+                why = WHY_NOT;\r
+                JUMPTO(PyInt_AS_LONG(retval));\r
+                Py_DECREF(retval);\r
+                break;\r
+            }\r
+\r
+            /* Now we have to pop the block. */\r
+            f->f_iblock--;\r
+\r
+            while (STACK_LEVEL() > b->b_level) {\r
+                v = POP();\r
+                Py_XDECREF(v);\r
+            }\r
+            if (b->b_type == SETUP_LOOP && why == WHY_BREAK) {\r
+                why = WHY_NOT;\r
+                JUMPTO(b->b_handler);\r
+                break;\r
+            }\r
+            if (b->b_type == SETUP_FINALLY ||\r
+                (b->b_type == SETUP_EXCEPT &&\r
+                 why == WHY_EXCEPTION) ||\r
+                b->b_type == SETUP_WITH) {\r
+                if (why == WHY_EXCEPTION) {\r
+                    PyObject *exc, *val, *tb;\r
+                    PyErr_Fetch(&exc, &val, &tb);\r
+                    if (val == NULL) {\r
+                        val = Py_None;\r
+                        Py_INCREF(val);\r
+                    }\r
+                    /* Make the raw exception data\r
+                       available to the handler,\r
+                       so a program can emulate the\r
+                       Python main loop.  Don't do\r
+                       this for 'finally'. */\r
+                    if (b->b_type == SETUP_EXCEPT ||\r
+                        b->b_type == SETUP_WITH) {\r
+                        PyErr_NormalizeException(\r
+                            &exc, &val, &tb);\r
+                        set_exc_info(tstate,\r
+                                     exc, val, tb);\r
+                    }\r
+                    if (tb == NULL) {\r
+                        Py_INCREF(Py_None);\r
+                        PUSH(Py_None);\r
+                    } else\r
+                        PUSH(tb);\r
+                    PUSH(val);\r
+                    PUSH(exc);\r
+                }\r
+                else {\r
+                    if (why & (WHY_RETURN | WHY_CONTINUE))\r
+                        PUSH(retval);\r
+                    v = PyInt_FromLong((long)why);\r
+                    PUSH(v);\r
+                }\r
+                why = WHY_NOT;\r
+                JUMPTO(b->b_handler);\r
+                break;\r
+            }\r
+        } /* unwind stack */\r
+\r
+        /* End the loop if we still have an error (or return) */\r
+\r
+        if (why != WHY_NOT)\r
+            break;\r
+        READ_TIMESTAMP(loop1);\r
+\r
+    } /* main loop */\r
+\r
+    assert(why != WHY_YIELD);\r
+    /* Pop remaining stack entries. */\r
+    while (!EMPTY()) {\r
+        v = POP();\r
+        Py_XDECREF(v);\r
+    }\r
+\r
+    if (why != WHY_RETURN)\r
+        retval = NULL;\r
+\r
+fast_yield:\r
+    if (tstate->use_tracing) {\r
+        if (tstate->c_tracefunc) {\r
+            if (why == WHY_RETURN || why == WHY_YIELD) {\r
+                if (call_trace(tstate->c_tracefunc,\r
+                               tstate->c_traceobj, f,\r
+                               PyTrace_RETURN, retval)) {\r
+                    Py_XDECREF(retval);\r
+                    retval = NULL;\r
+                    why = WHY_EXCEPTION;\r
+                }\r
+            }\r
+            else if (why == WHY_EXCEPTION) {\r
+                call_trace_protected(tstate->c_tracefunc,\r
+                                     tstate->c_traceobj, f,\r
+                                     PyTrace_RETURN, NULL);\r
+            }\r
+        }\r
+        if (tstate->c_profilefunc) {\r
+            if (why == WHY_EXCEPTION)\r
+                call_trace_protected(tstate->c_profilefunc,\r
+                                     tstate->c_profileobj, f,\r
+                                     PyTrace_RETURN, NULL);\r
+            else if (call_trace(tstate->c_profilefunc,\r
+                                tstate->c_profileobj, f,\r
+                                PyTrace_RETURN, retval)) {\r
+                Py_XDECREF(retval);\r
+                retval = NULL;\r
+                why = WHY_EXCEPTION;\r
+            }\r
+        }\r
+    }\r
+\r
+    if (tstate->frame->f_exc_type != NULL)\r
+        reset_exc_info(tstate);\r
+    else {\r
+        assert(tstate->frame->f_exc_value == NULL);\r
+        assert(tstate->frame->f_exc_traceback == NULL);\r
+    }\r
+\r
+    /* pop frame */\r
+exit_eval_frame:\r
+    Py_LeaveRecursiveCall();\r
+    tstate->frame = f->f_back;\r
+\r
+    return retval;\r
+}\r
+\r
+/* This is gonna seem *real weird*, but if you put some other code between\r
+   PyEval_EvalFrame() and PyEval_EvalCodeEx() you will need to adjust\r
+   the test in the if statements in Misc/gdbinit (pystack and pystackv). */\r
+\r
+PyObject *\r
+PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,\r
+           PyObject **args, int argcount, PyObject **kws, int kwcount,\r
+           PyObject **defs, int defcount, PyObject *closure)\r
+{\r
+    register PyFrameObject *f;\r
+    register PyObject *retval = NULL;\r
+    register PyObject **fastlocals, **freevars;\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    PyObject *x, *u;\r
+\r
+    if (globals == NULL) {\r
+        PyErr_SetString(PyExc_SystemError,\r
+                        "PyEval_EvalCodeEx: NULL globals");\r
+        return NULL;\r
+    }\r
+\r
+    assert(tstate != NULL);\r
+    assert(globals != NULL);\r
+    f = PyFrame_New(tstate, co, globals, locals);\r
+    if (f == NULL)\r
+        return NULL;\r
+\r
+    fastlocals = f->f_localsplus;\r
+    freevars = f->f_localsplus + co->co_nlocals;\r
+\r
+    if (co->co_argcount > 0 ||\r
+        co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) {\r
+        int i;\r
+        int n = argcount;\r
+        PyObject *kwdict = NULL;\r
+        if (co->co_flags & CO_VARKEYWORDS) {\r
+            kwdict = PyDict_New();\r
+            if (kwdict == NULL)\r
+                goto fail;\r
+            i = co->co_argcount;\r
+            if (co->co_flags & CO_VARARGS)\r
+                i++;\r
+            SETLOCAL(i, kwdict);\r
+        }\r
+        if (argcount > co->co_argcount) {\r
+            if (!(co->co_flags & CO_VARARGS)) {\r
+                PyErr_Format(PyExc_TypeError,\r
+                    "%.200s() takes %s %d "\r
+                    "argument%s (%d given)",\r
+                    PyString_AsString(co->co_name),\r
+                    defcount ? "at most" : "exactly",\r
+                    co->co_argcount,\r
+                    co->co_argcount == 1 ? "" : "s",\r
+                    argcount + kwcount);\r
+                goto fail;\r
+            }\r
+            n = co->co_argcount;\r
+        }\r
+        for (i = 0; i < n; i++) {\r
+            x = args[i];\r
+            Py_INCREF(x);\r
+            SETLOCAL(i, x);\r
+        }\r
+        if (co->co_flags & CO_VARARGS) {\r
+            u = PyTuple_New(argcount - n);\r
+            if (u == NULL)\r
+                goto fail;\r
+            SETLOCAL(co->co_argcount, u);\r
+            for (i = n; i < argcount; i++) {\r
+                x = args[i];\r
+                Py_INCREF(x);\r
+                PyTuple_SET_ITEM(u, i-n, x);\r
+            }\r
+        }\r
+        for (i = 0; i < kwcount; i++) {\r
+            PyObject **co_varnames;\r
+            PyObject *keyword = kws[2*i];\r
+            PyObject *value = kws[2*i + 1];\r
+            int j;\r
+            if (keyword == NULL || !(PyString_Check(keyword)\r
+#ifdef Py_USING_UNICODE\r
+                                     || PyUnicode_Check(keyword)\r
+#endif\r
+                        )) {\r
+                PyErr_Format(PyExc_TypeError,\r
+                    "%.200s() keywords must be strings",\r
+                    PyString_AsString(co->co_name));\r
+                goto fail;\r
+            }\r
+            /* Speed hack: do raw pointer compares. As names are\r
+               normally interned this should almost always hit. */\r
+            co_varnames = ((PyTupleObject *)(co->co_varnames))->ob_item;\r
+            for (j = 0; j < co->co_argcount; j++) {\r
+                PyObject *nm = co_varnames[j];\r
+                if (nm == keyword)\r
+                    goto kw_found;\r
+            }\r
+            /* Slow fallback, just in case */\r
+            for (j = 0; j < co->co_argcount; j++) {\r
+                PyObject *nm = co_varnames[j];\r
+                int cmp = PyObject_RichCompareBool(\r
+                    keyword, nm, Py_EQ);\r
+                if (cmp > 0)\r
+                    goto kw_found;\r
+                else if (cmp < 0)\r
+                    goto fail;\r
+            }\r
+            if (kwdict == NULL) {\r
+                PyObject *kwd_str = kwd_as_string(keyword);\r
+                if (kwd_str) {\r
+                    PyErr_Format(PyExc_TypeError,\r
+                                 "%.200s() got an unexpected "\r
+                                 "keyword argument '%.400s'",\r
+                                 PyString_AsString(co->co_name),\r
+                                 PyString_AsString(kwd_str));\r
+                    Py_DECREF(kwd_str);\r
+                }\r
+                goto fail;\r
+            }\r
+            PyDict_SetItem(kwdict, keyword, value);\r
+            continue;\r
+          kw_found:\r
+            if (GETLOCAL(j) != NULL) {\r
+                PyObject *kwd_str = kwd_as_string(keyword);\r
+                if (kwd_str) {\r
+                    PyErr_Format(PyExc_TypeError,\r
+                                 "%.200s() got multiple "\r
+                                 "values for keyword "\r
+                                 "argument '%.400s'",\r
+                                 PyString_AsString(co->co_name),\r
+                                 PyString_AsString(kwd_str));\r
+                    Py_DECREF(kwd_str);\r
+                }\r
+                goto fail;\r
+            }\r
+            Py_INCREF(value);\r
+            SETLOCAL(j, value);\r
+        }\r
+        if (argcount < co->co_argcount) {\r
+            int m = co->co_argcount - defcount;\r
+            for (i = argcount; i < m; i++) {\r
+                if (GETLOCAL(i) == NULL) {\r
+                    int j, given = 0;\r
+                    for (j = 0; j < co->co_argcount; j++)\r
+                        if (GETLOCAL(j))\r
+                            given++;\r
+                    PyErr_Format(PyExc_TypeError,\r
+                        "%.200s() takes %s %d "\r
+                        "argument%s (%d given)",\r
+                        PyString_AsString(co->co_name),\r
+                        ((co->co_flags & CO_VARARGS) ||\r
+                         defcount) ? "at least"\r
+                                   : "exactly",\r
+                        m, m == 1 ? "" : "s", given);\r
+                    goto fail;\r
+                }\r
+            }\r
+            if (n > m)\r
+                i = n - m;\r
+            else\r
+                i = 0;\r
+            for (; i < defcount; i++) {\r
+                if (GETLOCAL(m+i) == NULL) {\r
+                    PyObject *def = defs[i];\r
+                    Py_INCREF(def);\r
+                    SETLOCAL(m+i, def);\r
+                }\r
+            }\r
+        }\r
+    }\r
+    else if (argcount > 0 || kwcount > 0) {\r
+        PyErr_Format(PyExc_TypeError,\r
+                     "%.200s() takes no arguments (%d given)",\r
+                     PyString_AsString(co->co_name),\r
+                     argcount + kwcount);\r
+        goto fail;\r
+    }\r
+    /* Allocate and initialize storage for cell vars, and copy free\r
+       vars into frame.  This isn't too efficient right now. */\r
+    if (PyTuple_GET_SIZE(co->co_cellvars)) {\r
+        int i, j, nargs, found;\r
+        char *cellname, *argname;\r
+        PyObject *c;\r
+\r
+        nargs = co->co_argcount;\r
+        if (co->co_flags & CO_VARARGS)\r
+            nargs++;\r
+        if (co->co_flags & CO_VARKEYWORDS)\r
+            nargs++;\r
+\r
+        /* Initialize each cell var, taking into account\r
+           cell vars that are initialized from arguments.\r
+\r
+           Should arrange for the compiler to put cellvars\r
+           that are arguments at the beginning of the cellvars\r
+           list so that we can march over it more efficiently?\r
+        */\r
+        for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) {\r
+            cellname = PyString_AS_STRING(\r
+                PyTuple_GET_ITEM(co->co_cellvars, i));\r
+            found = 0;\r
+            for (j = 0; j < nargs; j++) {\r
+                argname = PyString_AS_STRING(\r
+                    PyTuple_GET_ITEM(co->co_varnames, j));\r
+                if (strcmp(cellname, argname) == 0) {\r
+                    c = PyCell_New(GETLOCAL(j));\r
+                    if (c == NULL)\r
+                        goto fail;\r
+                    GETLOCAL(co->co_nlocals + i) = c;\r
+                    found = 1;\r
+                    break;\r
+                }\r
+            }\r
+            if (found == 0) {\r
+                c = PyCell_New(NULL);\r
+                if (c == NULL)\r
+                    goto fail;\r
+                SETLOCAL(co->co_nlocals + i, c);\r
+            }\r
+        }\r
+    }\r
+    if (PyTuple_GET_SIZE(co->co_freevars)) {\r
+        int i;\r
+        for (i = 0; i < PyTuple_GET_SIZE(co->co_freevars); ++i) {\r
+            PyObject *o = PyTuple_GET_ITEM(closure, i);\r
+            Py_INCREF(o);\r
+            freevars[PyTuple_GET_SIZE(co->co_cellvars) + i] = o;\r
+        }\r
+    }\r
+\r
+    if (co->co_flags & CO_GENERATOR) {\r
+        /* Don't need to keep the reference to f_back, it will be set\r
+         * when the generator is resumed. */\r
+        Py_CLEAR(f->f_back);\r
+\r
+        PCALL(PCALL_GENERATOR);\r
+\r
+        /* Create a new generator that owns the ready to run frame\r
+         * and return that as the value. */\r
+        return PyGen_New(f);\r
+    }\r
+\r
+    retval = PyEval_EvalFrameEx(f,0);\r
+\r
+fail: /* Jump here from prelude on failure */\r
+\r
+    /* decref'ing the frame can cause __del__ methods to get invoked,\r
+       which can call back into Python.  While we're done with the\r
+       current Python frame (f), the associated C stack is still in use,\r
+       so recursion_depth must be boosted for the duration.\r
+    */\r
+    assert(tstate != NULL);\r
+    ++tstate->recursion_depth;\r
+    Py_DECREF(f);\r
+    --tstate->recursion_depth;\r
+    return retval;\r
+}\r
+\r
+\r
+static PyObject *\r
+special_lookup(PyObject *o, char *meth, PyObject **cache)\r
+{\r
+    PyObject *res;\r
+    if (PyInstance_Check(o)) {\r
+        if (!*cache)\r
+            return PyObject_GetAttrString(o, meth);\r
+        else\r
+            return PyObject_GetAttr(o, *cache);\r
+    }\r
+    res = _PyObject_LookupSpecial(o, meth, cache);\r
+    if (res == NULL && !PyErr_Occurred()) {\r
+        PyErr_SetObject(PyExc_AttributeError, *cache);\r
+        return NULL;\r
+    }\r
+    return res;\r
+}\r
+\r
+\r
+static PyObject *\r
+kwd_as_string(PyObject *kwd) {\r
+#ifdef Py_USING_UNICODE\r
+    if (PyString_Check(kwd)) {\r
+#else\r
+        assert(PyString_Check(kwd));\r
+#endif\r
+        Py_INCREF(kwd);\r
+        return kwd;\r
+#ifdef Py_USING_UNICODE\r
+    }\r
+    return _PyUnicode_AsDefaultEncodedString(kwd, "replace");\r
+#endif\r
+}\r
+\r
+\r
+/* Implementation notes for set_exc_info() and reset_exc_info():\r
+\r
+- Below, 'exc_ZZZ' stands for 'exc_type', 'exc_value' and\r
+  'exc_traceback'.  These always travel together.\r
+\r
+- tstate->curexc_ZZZ is the "hot" exception that is set by\r
+  PyErr_SetString(), cleared by PyErr_Clear(), and so on.\r
+\r
+- Once an exception is caught by an except clause, it is transferred\r
+  from tstate->curexc_ZZZ to tstate->exc_ZZZ, from which sys.exc_info()\r
+  can pick it up.  This is the primary task of set_exc_info().\r
+  XXX That can't be right:  set_exc_info() doesn't look at tstate->curexc_ZZZ.\r
+\r
+- Now let me explain the complicated dance with frame->f_exc_ZZZ.\r
+\r
+  Long ago, when none of this existed, there were just a few globals:\r
+  one set corresponding to the "hot" exception, and one set\r
+  corresponding to sys.exc_ZZZ.  (Actually, the latter weren't C\r
+  globals; they were simply stored as sys.exc_ZZZ.  For backwards\r
+  compatibility, they still are!)  The problem was that in code like\r
+  this:\r
+\r
+     try:\r
+    "something that may fail"\r
+     except "some exception":\r
+    "do something else first"\r
+    "print the exception from sys.exc_ZZZ."\r
+\r
+  if "do something else first" invoked something that raised and caught\r
+  an exception, sys.exc_ZZZ were overwritten.  That was a frequent\r
+  cause of subtle bugs.  I fixed this by changing the semantics as\r
+  follows:\r
+\r
+    - Within one frame, sys.exc_ZZZ will hold the last exception caught\r
+      *in that frame*.\r
+\r
+    - But initially, and as long as no exception is caught in a given\r
+      frame, sys.exc_ZZZ will hold the last exception caught in the\r
+      previous frame (or the frame before that, etc.).\r
+\r
+  The first bullet fixed the bug in the above example.  The second\r
+  bullet was for backwards compatibility: it was (and is) common to\r
+  have a function that is called when an exception is caught, and to\r
+  have that function access the caught exception via sys.exc_ZZZ.\r
+  (Example: traceback.print_exc()).\r
+\r
+  At the same time I fixed the problem that sys.exc_ZZZ weren't\r
+  thread-safe, by introducing sys.exc_info() which gets it from tstate;\r
+  but that's really a separate improvement.\r
+\r
+  The reset_exc_info() function in ceval.c restores the tstate->exc_ZZZ\r
+  variables to what they were before the current frame was called.  The\r
+  set_exc_info() function saves them on the frame so that\r
+  reset_exc_info() can restore them.  The invariant is that\r
+  frame->f_exc_ZZZ is NULL iff the current frame never caught an\r
+  exception (where "catching" an exception applies only to successful\r
+  except clauses); and if the current frame ever caught an exception,\r
+  frame->f_exc_ZZZ is the exception that was stored in tstate->exc_ZZZ\r
+  at the start of the current frame.\r
+\r
+*/\r
+\r
+static void\r
+set_exc_info(PyThreadState *tstate,\r
+             PyObject *type, PyObject *value, PyObject *tb)\r
+{\r
+    PyFrameObject *frame = tstate->frame;\r
+    PyObject *tmp_type, *tmp_value, *tmp_tb;\r
+\r
+    assert(type != NULL);\r
+    assert(frame != NULL);\r
+    if (frame->f_exc_type == NULL) {\r
+        assert(frame->f_exc_value == NULL);\r
+        assert(frame->f_exc_traceback == NULL);\r
+        /* This frame didn't catch an exception before. */\r
+        /* Save previous exception of this thread in this frame. */\r
+        if (tstate->exc_type == NULL) {\r
+            /* XXX Why is this set to Py_None? */\r
+            Py_INCREF(Py_None);\r
+            tstate->exc_type = Py_None;\r
+        }\r
+        Py_INCREF(tstate->exc_type);\r
+        Py_XINCREF(tstate->exc_value);\r
+        Py_XINCREF(tstate->exc_traceback);\r
+        frame->f_exc_type = tstate->exc_type;\r
+        frame->f_exc_value = tstate->exc_value;\r
+        frame->f_exc_traceback = tstate->exc_traceback;\r
+    }\r
+    /* Set new exception for this thread. */\r
+    tmp_type = tstate->exc_type;\r
+    tmp_value = tstate->exc_value;\r
+    tmp_tb = tstate->exc_traceback;\r
+    Py_INCREF(type);\r
+    Py_XINCREF(value);\r
+    Py_XINCREF(tb);\r
+    tstate->exc_type = type;\r
+    tstate->exc_value = value;\r
+    tstate->exc_traceback = tb;\r
+    Py_XDECREF(tmp_type);\r
+    Py_XDECREF(tmp_value);\r
+    Py_XDECREF(tmp_tb);\r
+    /* For b/w compatibility */\r
+    PySys_SetObject("exc_type", type);\r
+    PySys_SetObject("exc_value", value);\r
+    PySys_SetObject("exc_traceback", tb);\r
+}\r
+\r
+static void\r
+reset_exc_info(PyThreadState *tstate)\r
+{\r
+    PyFrameObject *frame;\r
+    PyObject *tmp_type, *tmp_value, *tmp_tb;\r
+\r
+    /* It's a precondition that the thread state's frame caught an\r
+     * exception -- verify in a debug build.\r
+     */\r
+    assert(tstate != NULL);\r
+    frame = tstate->frame;\r
+    assert(frame != NULL);\r
+    assert(frame->f_exc_type != NULL);\r
+\r
+    /* Copy the frame's exception info back to the thread state. */\r
+    tmp_type = tstate->exc_type;\r
+    tmp_value = tstate->exc_value;\r
+    tmp_tb = tstate->exc_traceback;\r
+    Py_INCREF(frame->f_exc_type);\r
+    Py_XINCREF(frame->f_exc_value);\r
+    Py_XINCREF(frame->f_exc_traceback);\r
+    tstate->exc_type = frame->f_exc_type;\r
+    tstate->exc_value = frame->f_exc_value;\r
+    tstate->exc_traceback = frame->f_exc_traceback;\r
+    Py_XDECREF(tmp_type);\r
+    Py_XDECREF(tmp_value);\r
+    Py_XDECREF(tmp_tb);\r
+\r
+    /* For b/w compatibility */\r
+    PySys_SetObject("exc_type", frame->f_exc_type);\r
+    PySys_SetObject("exc_value", frame->f_exc_value);\r
+    PySys_SetObject("exc_traceback", frame->f_exc_traceback);\r
+\r
+    /* Clear the frame's exception info. */\r
+    tmp_type = frame->f_exc_type;\r
+    tmp_value = frame->f_exc_value;\r
+    tmp_tb = frame->f_exc_traceback;\r
+    frame->f_exc_type = NULL;\r
+    frame->f_exc_value = NULL;\r
+    frame->f_exc_traceback = NULL;\r
+    Py_DECREF(tmp_type);\r
+    Py_XDECREF(tmp_value);\r
+    Py_XDECREF(tmp_tb);\r
+}\r
+\r
+/* Logic for the raise statement (too complicated for inlining).\r
+   This *consumes* a reference count to each of its arguments. */\r
+static enum why_code\r
+do_raise(PyObject *type, PyObject *value, PyObject *tb)\r
+{\r
+    if (type == NULL) {\r
+        /* Reraise */\r
+        PyThreadState *tstate = PyThreadState_GET();\r
+        type = tstate->exc_type == NULL ? Py_None : tstate->exc_type;\r
+        value = tstate->exc_value;\r
+        tb = tstate->exc_traceback;\r
+        Py_XINCREF(type);\r
+        Py_XINCREF(value);\r
+        Py_XINCREF(tb);\r
+    }\r
+\r
+    /* We support the following forms of raise:\r
+       raise <class>, <classinstance>\r
+       raise <class>, <argument tuple>\r
+       raise <class>, None\r
+       raise <class>, <argument>\r
+       raise <classinstance>, None\r
+       raise <string>, <object>\r
+       raise <string>, None\r
+\r
+       An omitted second argument is the same as None.\r
+\r
+       In addition, raise <tuple>, <anything> is the same as\r
+       raising the tuple's first item (and it better have one!);\r
+       this rule is applied recursively.\r
+\r
+       Finally, an optional third argument can be supplied, which\r
+       gives the traceback to be substituted (useful when\r
+       re-raising an exception after examining it).  */\r
+\r
+    /* First, check the traceback argument, replacing None with\r
+       NULL. */\r
+    if (tb == Py_None) {\r
+        Py_DECREF(tb);\r
+        tb = NULL;\r
+    }\r
+    else if (tb != NULL && !PyTraceBack_Check(tb)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                   "raise: arg 3 must be a traceback or None");\r
+        goto raise_error;\r
+    }\r
+\r
+    /* Next, replace a missing value with None */\r
+    if (value == NULL) {\r
+        value = Py_None;\r
+        Py_INCREF(value);\r
+    }\r
+\r
+    /* Next, repeatedly, replace a tuple exception with its first item */\r
+    while (PyTuple_Check(type) && PyTuple_Size(type) > 0) {\r
+        PyObject *tmp = type;\r
+        type = PyTuple_GET_ITEM(type, 0);\r
+        Py_INCREF(type);\r
+        Py_DECREF(tmp);\r
+    }\r
+\r
+    if (PyExceptionClass_Check(type)) {\r
+        PyErr_NormalizeException(&type, &value, &tb);\r
+        if (!PyExceptionInstance_Check(value)) {\r
+            PyErr_Format(PyExc_TypeError,\r
+                         "calling %s() should have returned an instance of "\r
+                         "BaseException, not '%s'",\r
+                         ((PyTypeObject *)type)->tp_name,\r
+                         Py_TYPE(value)->tp_name);\r
+            goto raise_error;\r
+        }\r
+    }\r
+    else if (PyExceptionInstance_Check(type)) {\r
+        /* Raising an instance.  The value should be a dummy. */\r
+        if (value != Py_None) {\r
+            PyErr_SetString(PyExc_TypeError,\r
+              "instance exception may not have a separate value");\r
+            goto raise_error;\r
+        }\r
+        else {\r
+            /* Normalize to raise <class>, <instance> */\r
+            Py_DECREF(value);\r
+            value = type;\r
+            type = PyExceptionInstance_Class(type);\r
+            Py_INCREF(type);\r
+        }\r
+    }\r
+    else {\r
+        /* Not something you can raise.  You get an exception\r
+           anyway, just not what you specified :-) */\r
+        PyErr_Format(PyExc_TypeError,\r
+                     "exceptions must be old-style classes or "\r
+                     "derived from BaseException, not %s",\r
+                     type->ob_type->tp_name);\r
+        goto raise_error;\r
+    }\r
+\r
+    assert(PyExceptionClass_Check(type));\r
+    if (Py_Py3kWarningFlag && PyClass_Check(type)) {\r
+        if (PyErr_WarnEx(PyExc_DeprecationWarning,\r
+                        "exceptions must derive from BaseException "\r
+                        "in 3.x", 1) < 0)\r
+            goto raise_error;\r
+    }\r
+\r
+    PyErr_Restore(type, value, tb);\r
+    if (tb == NULL)\r
+        return WHY_EXCEPTION;\r
+    else\r
+        return WHY_RERAISE;\r
+ raise_error:\r
+    Py_XDECREF(value);\r
+    Py_XDECREF(type);\r
+    Py_XDECREF(tb);\r
+    return WHY_EXCEPTION;\r
+}\r
+\r
+/* Iterate v argcnt times and store the results on the stack (via decreasing\r
+   sp).  Return 1 for success, 0 if error. */\r
+\r
+static int\r
+unpack_iterable(PyObject *v, int argcnt, PyObject **sp)\r
+{\r
+    int i = 0;\r
+    PyObject *it;  /* iter(v) */\r
+    PyObject *w;\r
+\r
+    assert(v != NULL);\r
+\r
+    it = PyObject_GetIter(v);\r
+    if (it == NULL)\r
+        goto Error;\r
+\r
+    for (; i < argcnt; i++) {\r
+        w = PyIter_Next(it);\r
+        if (w == NULL) {\r
+            /* Iterator done, via error or exhaustion. */\r
+            if (!PyErr_Occurred()) {\r
+                PyErr_Format(PyExc_ValueError,\r
+                    "need more than %d value%s to unpack",\r
+                    i, i == 1 ? "" : "s");\r
+            }\r
+            goto Error;\r
+        }\r
+        *--sp = w;\r
+    }\r
+\r
+    /* We better have exhausted the iterator now. */\r
+    w = PyIter_Next(it);\r
+    if (w == NULL) {\r
+        if (PyErr_Occurred())\r
+            goto Error;\r
+        Py_DECREF(it);\r
+        return 1;\r
+    }\r
+    Py_DECREF(w);\r
+    PyErr_SetString(PyExc_ValueError, "too many values to unpack");\r
+    /* fall through */\r
+Error:\r
+    for (; i > 0; i--, sp++)\r
+        Py_DECREF(*sp);\r
+    Py_XDECREF(it);\r
+    return 0;\r
+}\r
+\r
+\r
+#ifdef LLTRACE\r
+static int\r
+prtrace(PyObject *v, char *str)\r
+{\r
+    printf("%s ", str);\r
+    if (PyObject_Print(v, stdout, 0) != 0)\r
+        PyErr_Clear(); /* Don't know what else to do */\r
+    printf("\n");\r
+    return 1;\r
+}\r
+#endif\r
+\r
+static void\r
+call_exc_trace(Py_tracefunc func, PyObject *self, PyFrameObject *f)\r
+{\r
+    PyObject *type, *value, *traceback, *arg;\r
+    int err;\r
+    PyErr_Fetch(&type, &value, &traceback);\r
+    if (value == NULL) {\r
+        value = Py_None;\r
+        Py_INCREF(value);\r
+    }\r
+    arg = PyTuple_Pack(3, type, value, traceback);\r
+    if (arg == NULL) {\r
+        PyErr_Restore(type, value, traceback);\r
+        return;\r
+    }\r
+    err = call_trace(func, self, f, PyTrace_EXCEPTION, arg);\r
+    Py_DECREF(arg);\r
+    if (err == 0)\r
+        PyErr_Restore(type, value, traceback);\r
+    else {\r
+        Py_XDECREF(type);\r
+        Py_XDECREF(value);\r
+        Py_XDECREF(traceback);\r
+    }\r
+}\r
+\r
+static int\r
+call_trace_protected(Py_tracefunc func, PyObject *obj, PyFrameObject *frame,\r
+                     int what, PyObject *arg)\r
+{\r
+    PyObject *type, *value, *traceback;\r
+    int err;\r
+    PyErr_Fetch(&type, &value, &traceback);\r
+    err = call_trace(func, obj, frame, what, arg);\r
+    if (err == 0)\r
+    {\r
+        PyErr_Restore(type, value, traceback);\r
+        return 0;\r
+    }\r
+    else {\r
+        Py_XDECREF(type);\r
+        Py_XDECREF(value);\r
+        Py_XDECREF(traceback);\r
+        return -1;\r
+    }\r
+}\r
+\r
+static int\r
+call_trace(Py_tracefunc func, PyObject *obj, PyFrameObject *frame,\r
+           int what, PyObject *arg)\r
+{\r
+    register PyThreadState *tstate = frame->f_tstate;\r
+    int result;\r
+    if (tstate->tracing)\r
+        return 0;\r
+    tstate->tracing++;\r
+    tstate->use_tracing = 0;\r
+    result = func(obj, frame, what, arg);\r
+    tstate->use_tracing = ((tstate->c_tracefunc != NULL)\r
+                           || (tstate->c_profilefunc != NULL));\r
+    tstate->tracing--;\r
+    return result;\r
+}\r
+\r
+PyObject *\r
+_PyEval_CallTracing(PyObject *func, PyObject *args)\r
+{\r
+    PyFrameObject *frame = PyEval_GetFrame();\r
+    PyThreadState *tstate = frame->f_tstate;\r
+    int save_tracing = tstate->tracing;\r
+    int save_use_tracing = tstate->use_tracing;\r
+    PyObject *result;\r
+\r
+    tstate->tracing = 0;\r
+    tstate->use_tracing = ((tstate->c_tracefunc != NULL)\r
+                           || (tstate->c_profilefunc != NULL));\r
+    result = PyObject_Call(func, args, NULL);\r
+    tstate->tracing = save_tracing;\r
+    tstate->use_tracing = save_use_tracing;\r
+    return result;\r
+}\r
+\r
+/* See Objects/lnotab_notes.txt for a description of how tracing works. */\r
+static int\r
+maybe_call_line_trace(Py_tracefunc func, PyObject *obj,\r
+                      PyFrameObject *frame, int *instr_lb, int *instr_ub,\r
+                      int *instr_prev)\r
+{\r
+    int result = 0;\r
+    int line = frame->f_lineno;\r
+\r
+    /* If the last instruction executed isn't in the current\r
+       instruction window, reset the window.\r
+    */\r
+    if (frame->f_lasti < *instr_lb || frame->f_lasti >= *instr_ub) {\r
+        PyAddrPair bounds;\r
+        line = _PyCode_CheckLineNumber(frame->f_code, frame->f_lasti,\r
+                                       &bounds);\r
+        *instr_lb = bounds.ap_lower;\r
+        *instr_ub = bounds.ap_upper;\r
+    }\r
+    /* If the last instruction falls at the start of a line or if\r
+       it represents a jump backwards, update the frame's line\r
+       number and call the trace function. */\r
+    if (frame->f_lasti == *instr_lb || frame->f_lasti < *instr_prev) {\r
+        frame->f_lineno = line;\r
+        result = call_trace(func, obj, frame, PyTrace_LINE, Py_None);\r
+    }\r
+    *instr_prev = frame->f_lasti;\r
+    return result;\r
+}\r
+\r
+void\r
+PyEval_SetProfile(Py_tracefunc func, PyObject *arg)\r
+{\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    PyObject *temp = tstate->c_profileobj;\r
+    Py_XINCREF(arg);\r
+    tstate->c_profilefunc = NULL;\r
+    tstate->c_profileobj = NULL;\r
+    /* Must make sure that tracing is not ignored if 'temp' is freed */\r
+    tstate->use_tracing = tstate->c_tracefunc != NULL;\r
+    Py_XDECREF(temp);\r
+    tstate->c_profilefunc = func;\r
+    tstate->c_profileobj = arg;\r
+    /* Flag that tracing or profiling is turned on */\r
+    tstate->use_tracing = (func != NULL) || (tstate->c_tracefunc != NULL);\r
+}\r
+\r
+void\r
+PyEval_SetTrace(Py_tracefunc func, PyObject *arg)\r
+{\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    PyObject *temp = tstate->c_traceobj;\r
+    _Py_TracingPossible += (func != NULL) - (tstate->c_tracefunc != NULL);\r
+    Py_XINCREF(arg);\r
+    tstate->c_tracefunc = NULL;\r
+    tstate->c_traceobj = NULL;\r
+    /* Must make sure that profiling is not ignored if 'temp' is freed */\r
+    tstate->use_tracing = tstate->c_profilefunc != NULL;\r
+    Py_XDECREF(temp);\r
+    tstate->c_tracefunc = func;\r
+    tstate->c_traceobj = arg;\r
+    /* Flag that tracing or profiling is turned on */\r
+    tstate->use_tracing = ((func != NULL)\r
+                           || (tstate->c_profilefunc != NULL));\r
+}\r
+\r
+PyObject *\r
+PyEval_GetBuiltins(void)\r
+{\r
+    PyFrameObject *current_frame = PyEval_GetFrame();\r
+    if (current_frame == NULL)\r
+        return PyThreadState_GET()->interp->builtins;\r
+    else\r
+        return current_frame->f_builtins;\r
+}\r
+\r
+PyObject *\r
+PyEval_GetLocals(void)\r
+{\r
+    PyFrameObject *current_frame = PyEval_GetFrame();\r
+    if (current_frame == NULL)\r
+        return NULL;\r
+    PyFrame_FastToLocals(current_frame);\r
+    return current_frame->f_locals;\r
+}\r
+\r
+PyObject *\r
+PyEval_GetGlobals(void)\r
+{\r
+    PyFrameObject *current_frame = PyEval_GetFrame();\r
+    if (current_frame == NULL)\r
+        return NULL;\r
+    else\r
+        return current_frame->f_globals;\r
+}\r
+\r
+PyFrameObject *\r
+PyEval_GetFrame(void)\r
+{\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    return _PyThreadState_GetFrame(tstate);\r
+}\r
+\r
+int\r
+PyEval_GetRestricted(void)\r
+{\r
+    PyFrameObject *current_frame = PyEval_GetFrame();\r
+    return current_frame == NULL ? 0 : PyFrame_IsRestricted(current_frame);\r
+}\r
+\r
+int\r
+PyEval_MergeCompilerFlags(PyCompilerFlags *cf)\r
+{\r
+    PyFrameObject *current_frame = PyEval_GetFrame();\r
+    int result = cf->cf_flags != 0;\r
+\r
+    if (current_frame != NULL) {\r
+        const int codeflags = current_frame->f_code->co_flags;\r
+        const int compilerflags = codeflags & PyCF_MASK;\r
+        if (compilerflags) {\r
+            result = 1;\r
+            cf->cf_flags |= compilerflags;\r
+        }\r
+#if 0 /* future keyword */\r
+        if (codeflags & CO_GENERATOR_ALLOWED) {\r
+            result = 1;\r
+            cf->cf_flags |= CO_GENERATOR_ALLOWED;\r
+        }\r
+#endif\r
+    }\r
+    return result;\r
+}\r
+\r
+int\r
+Py_FlushLine(void)\r
+{\r
+    PyObject *f = PySys_GetObject("stdout");\r
+    if (f == NULL)\r
+        return 0;\r
+    if (!PyFile_SoftSpace(f, 0))\r
+        return 0;\r
+    return PyFile_WriteString("\n", f);\r
+}\r
+\r
+\r
+/* External interface to call any callable object.\r
+   The arg must be a tuple or NULL.  The kw must be a dict or NULL. */\r
+\r
+PyObject *\r
+PyEval_CallObjectWithKeywords(PyObject *func, PyObject *arg, PyObject *kw)\r
+{\r
+    PyObject *result;\r
+\r
+    if (arg == NULL) {\r
+        arg = PyTuple_New(0);\r
+        if (arg == NULL)\r
+            return NULL;\r
+    }\r
+    else if (!PyTuple_Check(arg)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                        "argument list must be a tuple");\r
+        return NULL;\r
+    }\r
+    else\r
+        Py_INCREF(arg);\r
+\r
+    if (kw != NULL && !PyDict_Check(kw)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                        "keyword list must be a dictionary");\r
+        Py_DECREF(arg);\r
+        return NULL;\r
+    }\r
+\r
+    result = PyObject_Call(func, arg, kw);\r
+    Py_DECREF(arg);\r
+    return result;\r
+}\r
+\r
+const char *\r
+PyEval_GetFuncName(PyObject *func)\r
+{\r
+    if (PyMethod_Check(func))\r
+        return PyEval_GetFuncName(PyMethod_GET_FUNCTION(func));\r
+    else if (PyFunction_Check(func))\r
+        return PyString_AsString(((PyFunctionObject*)func)->func_name);\r
+    else if (PyCFunction_Check(func))\r
+        return ((PyCFunctionObject*)func)->m_ml->ml_name;\r
+    else if (PyClass_Check(func))\r
+        return PyString_AsString(((PyClassObject*)func)->cl_name);\r
+    else if (PyInstance_Check(func)) {\r
+        return PyString_AsString(\r
+            ((PyInstanceObject*)func)->in_class->cl_name);\r
+    } else {\r
+        return func->ob_type->tp_name;\r
+    }\r
+}\r
+\r
+const char *\r
+PyEval_GetFuncDesc(PyObject *func)\r
+{\r
+    if (PyMethod_Check(func))\r
+        return "()";\r
+    else if (PyFunction_Check(func))\r
+        return "()";\r
+    else if (PyCFunction_Check(func))\r
+        return "()";\r
+    else if (PyClass_Check(func))\r
+        return " constructor";\r
+    else if (PyInstance_Check(func)) {\r
+        return " instance";\r
+    } else {\r
+        return " object";\r
+    }\r
+}\r
+\r
+static void\r
+err_args(PyObject *func, int flags, int nargs)\r
+{\r
+    if (flags & METH_NOARGS)\r
+        PyErr_Format(PyExc_TypeError,\r
+                     "%.200s() takes no arguments (%d given)",\r
+                     ((PyCFunctionObject *)func)->m_ml->ml_name,\r
+                     nargs);\r
+    else\r
+        PyErr_Format(PyExc_TypeError,\r
+                     "%.200s() takes exactly one argument (%d given)",\r
+                     ((PyCFunctionObject *)func)->m_ml->ml_name,\r
+                     nargs);\r
+}\r
+\r
+#define C_TRACE(x, call) \\r
+if (tstate->use_tracing && tstate->c_profilefunc) { \\r
+    if (call_trace(tstate->c_profilefunc, \\r
+        tstate->c_profileobj, \\r
+        tstate->frame, PyTrace_C_CALL, \\r
+        func)) { \\r
+        x = NULL; \\r
+    } \\r
+    else { \\r
+        x = call; \\r
+        if (tstate->c_profilefunc != NULL) { \\r
+            if (x == NULL) { \\r
+                call_trace_protected(tstate->c_profilefunc, \\r
+                    tstate->c_profileobj, \\r
+                    tstate->frame, PyTrace_C_EXCEPTION, \\r
+                    func); \\r
+                /* XXX should pass (type, value, tb) */ \\r
+            } else { \\r
+                if (call_trace(tstate->c_profilefunc, \\r
+                    tstate->c_profileobj, \\r
+                    tstate->frame, PyTrace_C_RETURN, \\r
+                    func)) { \\r
+                    Py_DECREF(x); \\r
+                    x = NULL; \\r
+                } \\r
+            } \\r
+        } \\r
+    } \\r
+} else { \\r
+    x = call; \\r
+    }\r
+\r
+static PyObject *\r
+call_function(PyObject ***pp_stack, int oparg\r
+#ifdef WITH_TSC\r
+                , uint64* pintr0, uint64* pintr1\r
+#endif\r
+                )\r
+{\r
+    int na = oparg & 0xff;\r
+    int nk = (oparg>>8) & 0xff;\r
+    int n = na + 2 * nk;\r
+    PyObject **pfunc = (*pp_stack) - n - 1;\r
+    PyObject *func = *pfunc;\r
+    PyObject *x, *w;\r
+\r
+    /* Always dispatch PyCFunction first, because these are\r
+       presumed to be the most frequent callable object.\r
+    */\r
+    if (PyCFunction_Check(func) && nk == 0) {\r
+        int flags = PyCFunction_GET_FLAGS(func);\r
+        PyThreadState *tstate = PyThreadState_GET();\r
+\r
+        PCALL(PCALL_CFUNCTION);\r
+        if (flags & (METH_NOARGS | METH_O)) {\r
+            PyCFunction meth = PyCFunction_GET_FUNCTION(func);\r
+            PyObject *self = PyCFunction_GET_SELF(func);\r
+            if (flags & METH_NOARGS && na == 0) {\r
+                C_TRACE(x, (*meth)(self,NULL));\r
+            }\r
+            else if (flags & METH_O && na == 1) {\r
+                PyObject *arg = EXT_POP(*pp_stack);\r
+                C_TRACE(x, (*meth)(self,arg));\r
+                Py_DECREF(arg);\r
+            }\r
+            else {\r
+                err_args(func, flags, na);\r
+                x = NULL;\r
+            }\r
+        }\r
+        else {\r
+            PyObject *callargs;\r
+            callargs = load_args(pp_stack, na);\r
+            READ_TIMESTAMP(*pintr0);\r
+            C_TRACE(x, PyCFunction_Call(func,callargs,NULL));\r
+            READ_TIMESTAMP(*pintr1);\r
+            Py_XDECREF(callargs);\r
+        }\r
+    } else {\r
+        if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) {\r
+            /* optimize access to bound methods */\r
+            PyObject *self = PyMethod_GET_SELF(func);\r
+            PCALL(PCALL_METHOD);\r
+            PCALL(PCALL_BOUND_METHOD);\r
+            Py_INCREF(self);\r
+            func = PyMethod_GET_FUNCTION(func);\r
+            Py_INCREF(func);\r
+            Py_DECREF(*pfunc);\r
+            *pfunc = self;\r
+            na++;\r
+            n++;\r
+        } else\r
+            Py_INCREF(func);\r
+        READ_TIMESTAMP(*pintr0);\r
+        if (PyFunction_Check(func))\r
+            x = fast_function(func, pp_stack, n, na, nk);\r
+        else\r
+            x = do_call(func, pp_stack, na, nk);\r
+        READ_TIMESTAMP(*pintr1);\r
+        Py_DECREF(func);\r
+    }\r
+\r
+    /* Clear the stack of the function object.  Also removes\r
+       the arguments in case they weren't consumed already\r
+       (fast_function() and err_args() leave them on the stack).\r
+     */\r
+    while ((*pp_stack) > pfunc) {\r
+        w = EXT_POP(*pp_stack);\r
+        Py_DECREF(w);\r
+        PCALL(PCALL_POP);\r
+    }\r
+    return x;\r
+}\r
+\r
+/* The fast_function() function optimize calls for which no argument\r
+   tuple is necessary; the objects are passed directly from the stack.\r
+   For the simplest case -- a function that takes only positional\r
+   arguments and is called with only positional arguments -- it\r
+   inlines the most primitive frame setup code from\r
+   PyEval_EvalCodeEx(), which vastly reduces the checks that must be\r
+   done before evaluating the frame.\r
+*/\r
+\r
+static PyObject *\r
+fast_function(PyObject *func, PyObject ***pp_stack, int n, int na, int nk)\r
+{\r
+    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);\r
+    PyObject *globals = PyFunction_GET_GLOBALS(func);\r
+    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);\r
+    PyObject **d = NULL;\r
+    int nd = 0;\r
+\r
+    PCALL(PCALL_FUNCTION);\r
+    PCALL(PCALL_FAST_FUNCTION);\r
+    if (argdefs == NULL && co->co_argcount == n && nk==0 &&\r
+        co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {\r
+        PyFrameObject *f;\r
+        PyObject *retval = NULL;\r
+        PyThreadState *tstate = PyThreadState_GET();\r
+        PyObject **fastlocals, **stack;\r
+        int i;\r
+\r
+        PCALL(PCALL_FASTER_FUNCTION);\r
+        assert(globals != NULL);\r
+        /* XXX Perhaps we should create a specialized\r
+           PyFrame_New() that doesn't take locals, but does\r
+           take builtins without sanity checking them.\r
+        */\r
+        assert(tstate != NULL);\r
+        f = PyFrame_New(tstate, co, globals, NULL);\r
+        if (f == NULL)\r
+            return NULL;\r
+\r
+        fastlocals = f->f_localsplus;\r
+        stack = (*pp_stack) - n;\r
+\r
+        for (i = 0; i < n; i++) {\r
+            Py_INCREF(*stack);\r
+            fastlocals[i] = *stack++;\r
+        }\r
+        retval = PyEval_EvalFrameEx(f,0);\r
+        ++tstate->recursion_depth;\r
+        Py_DECREF(f);\r
+        --tstate->recursion_depth;\r
+        return retval;\r
+    }\r
+    if (argdefs != NULL) {\r
+        d = &PyTuple_GET_ITEM(argdefs, 0);\r
+        nd = Py_SIZE(argdefs);\r
+    }\r
+    return PyEval_EvalCodeEx(co, globals,\r
+                             (PyObject *)NULL, (*pp_stack)-n, na,\r
+                             (*pp_stack)-2*nk, nk, d, nd,\r
+                             PyFunction_GET_CLOSURE(func));\r
+}\r
+\r
+static PyObject *\r
+update_keyword_args(PyObject *orig_kwdict, int nk, PyObject ***pp_stack,\r
+                    PyObject *func)\r
+{\r
+    PyObject *kwdict = NULL;\r
+    if (orig_kwdict == NULL)\r
+        kwdict = PyDict_New();\r
+    else {\r
+        kwdict = PyDict_Copy(orig_kwdict);\r
+        Py_DECREF(orig_kwdict);\r
+    }\r
+    if (kwdict == NULL)\r
+        return NULL;\r
+    while (--nk >= 0) {\r
+        int err;\r
+        PyObject *value = EXT_POP(*pp_stack);\r
+        PyObject *key = EXT_POP(*pp_stack);\r
+        if (PyDict_GetItem(kwdict, key) != NULL) {\r
+            PyErr_Format(PyExc_TypeError,\r
+                         "%.200s%s got multiple values "\r
+                         "for keyword argument '%.200s'",\r
+                         PyEval_GetFuncName(func),\r
+                         PyEval_GetFuncDesc(func),\r
+                         PyString_AsString(key));\r
+            Py_DECREF(key);\r
+            Py_DECREF(value);\r
+            Py_DECREF(kwdict);\r
+            return NULL;\r
+        }\r
+        err = PyDict_SetItem(kwdict, key, value);\r
+        Py_DECREF(key);\r
+        Py_DECREF(value);\r
+        if (err) {\r
+            Py_DECREF(kwdict);\r
+            return NULL;\r
+        }\r
+    }\r
+    return kwdict;\r
+}\r
+\r
+static PyObject *\r
+update_star_args(int nstack, int nstar, PyObject *stararg,\r
+                 PyObject ***pp_stack)\r
+{\r
+    PyObject *callargs, *w;\r
+\r
+    callargs = PyTuple_New(nstack + nstar);\r
+    if (callargs == NULL) {\r
+        return NULL;\r
+    }\r
+    if (nstar) {\r
+        int i;\r
+        for (i = 0; i < nstar; i++) {\r
+            PyObject *a = PyTuple_GET_ITEM(stararg, i);\r
+            Py_INCREF(a);\r
+            PyTuple_SET_ITEM(callargs, nstack + i, a);\r
+        }\r
+    }\r
+    while (--nstack >= 0) {\r
+        w = EXT_POP(*pp_stack);\r
+        PyTuple_SET_ITEM(callargs, nstack, w);\r
+    }\r
+    return callargs;\r
+}\r
+\r
+static PyObject *\r
+load_args(PyObject ***pp_stack, int na)\r
+{\r
+    PyObject *args = PyTuple_New(na);\r
+    PyObject *w;\r
+\r
+    if (args == NULL)\r
+        return NULL;\r
+    while (--na >= 0) {\r
+        w = EXT_POP(*pp_stack);\r
+        PyTuple_SET_ITEM(args, na, w);\r
+    }\r
+    return args;\r
+}\r
+\r
+static PyObject *\r
+do_call(PyObject *func, PyObject ***pp_stack, int na, int nk)\r
+{\r
+    PyObject *callargs = NULL;\r
+    PyObject *kwdict = NULL;\r
+    PyObject *result = NULL;\r
+\r
+    if (nk > 0) {\r
+        kwdict = update_keyword_args(NULL, nk, pp_stack, func);\r
+        if (kwdict == NULL)\r
+            goto call_fail;\r
+    }\r
+    callargs = load_args(pp_stack, na);\r
+    if (callargs == NULL)\r
+        goto call_fail;\r
+#ifdef CALL_PROFILE\r
+    /* At this point, we have to look at the type of func to\r
+       update the call stats properly.  Do it here so as to avoid\r
+       exposing the call stats machinery outside ceval.c\r
+    */\r
+    if (PyFunction_Check(func))\r
+        PCALL(PCALL_FUNCTION);\r
+    else if (PyMethod_Check(func))\r
+        PCALL(PCALL_METHOD);\r
+    else if (PyType_Check(func))\r
+        PCALL(PCALL_TYPE);\r
+    else if (PyCFunction_Check(func))\r
+        PCALL(PCALL_CFUNCTION);\r
+    else\r
+        PCALL(PCALL_OTHER);\r
+#endif\r
+    if (PyCFunction_Check(func)) {\r
+        PyThreadState *tstate = PyThreadState_GET();\r
+        C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));\r
+    }\r
+    else\r
+        result = PyObject_Call(func, callargs, kwdict);\r
+ call_fail:\r
+    Py_XDECREF(callargs);\r
+    Py_XDECREF(kwdict);\r
+    return result;\r
+}\r
+\r
+static PyObject *\r
+ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)\r
+{\r
+    int nstar = 0;\r
+    PyObject *callargs = NULL;\r
+    PyObject *stararg = NULL;\r
+    PyObject *kwdict = NULL;\r
+    PyObject *result = NULL;\r
+\r
+    if (flags & CALL_FLAG_KW) {\r
+        kwdict = EXT_POP(*pp_stack);\r
+        if (!PyDict_Check(kwdict)) {\r
+            PyObject *d;\r
+            d = PyDict_New();\r
+            if (d == NULL)\r
+                goto ext_call_fail;\r
+            if (PyDict_Update(d, kwdict) != 0) {\r
+                Py_DECREF(d);\r
+                /* PyDict_Update raises attribute\r
+                 * error (percolated from an attempt\r
+                 * to get 'keys' attribute) instead of\r
+                 * a type error if its second argument\r
+                 * is not a mapping.\r
+                 */\r
+                if (PyErr_ExceptionMatches(PyExc_AttributeError)) {\r
+                    PyErr_Format(PyExc_TypeError,\r
+                                 "%.200s%.200s argument after ** "\r
+                                 "must be a mapping, not %.200s",\r
+                                 PyEval_GetFuncName(func),\r
+                                 PyEval_GetFuncDesc(func),\r
+                                 kwdict->ob_type->tp_name);\r
+                }\r
+                goto ext_call_fail;\r
+            }\r
+            Py_DECREF(kwdict);\r
+            kwdict = d;\r
+        }\r
+    }\r
+    if (flags & CALL_FLAG_VAR) {\r
+        stararg = EXT_POP(*pp_stack);\r
+        if (!PyTuple_Check(stararg)) {\r
+            PyObject *t = NULL;\r
+            t = PySequence_Tuple(stararg);\r
+            if (t == NULL) {\r
+                if (PyErr_ExceptionMatches(PyExc_TypeError)) {\r
+                    PyErr_Format(PyExc_TypeError,\r
+                                 "%.200s%.200s argument after * "\r
+                                 "must be a sequence, not %200s",\r
+                                 PyEval_GetFuncName(func),\r
+                                 PyEval_GetFuncDesc(func),\r
+                                 stararg->ob_type->tp_name);\r
+                }\r
+                goto ext_call_fail;\r
+            }\r
+            Py_DECREF(stararg);\r
+            stararg = t;\r
+        }\r
+        nstar = PyTuple_GET_SIZE(stararg);\r
+    }\r
+    if (nk > 0) {\r
+        kwdict = update_keyword_args(kwdict, nk, pp_stack, func);\r
+        if (kwdict == NULL)\r
+            goto ext_call_fail;\r
+    }\r
+    callargs = update_star_args(na, nstar, stararg, pp_stack);\r
+    if (callargs == NULL)\r
+        goto ext_call_fail;\r
+#ifdef CALL_PROFILE\r
+    /* At this point, we have to look at the type of func to\r
+       update the call stats properly.  Do it here so as to avoid\r
+       exposing the call stats machinery outside ceval.c\r
+    */\r
+    if (PyFunction_Check(func))\r
+        PCALL(PCALL_FUNCTION);\r
+    else if (PyMethod_Check(func))\r
+        PCALL(PCALL_METHOD);\r
+    else if (PyType_Check(func))\r
+        PCALL(PCALL_TYPE);\r
+    else if (PyCFunction_Check(func))\r
+        PCALL(PCALL_CFUNCTION);\r
+    else\r
+        PCALL(PCALL_OTHER);\r
+#endif\r
+    if (PyCFunction_Check(func)) {\r
+        PyThreadState *tstate = PyThreadState_GET();\r
+        C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));\r
+    }\r
+    else\r
+        result = PyObject_Call(func, callargs, kwdict);\r
+ext_call_fail:\r
+    Py_XDECREF(callargs);\r
+    Py_XDECREF(kwdict);\r
+    Py_XDECREF(stararg);\r
+    return result;\r
+}\r
+\r
+/* Extract a slice index from a PyInt or PyLong or an object with the\r
+   nb_index slot defined, and store in *pi.\r
+   Silently reduce values larger than PY_SSIZE_T_MAX to PY_SSIZE_T_MAX,\r
+   and silently boost values less than -PY_SSIZE_T_MAX-1 to -PY_SSIZE_T_MAX-1.\r
+   Return 0 on error, 1 on success.\r
+*/\r
+/* Note:  If v is NULL, return success without storing into *pi.  This\r
+   is because_PyEval_SliceIndex() is called by apply_slice(), which can be\r
+   called by the SLICE opcode with v and/or w equal to NULL.\r
+*/\r
+int\r
+_PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)\r
+{\r
+    if (v != NULL) {\r
+        Py_ssize_t x;\r
+        if (PyInt_Check(v)) {\r
+            /* XXX(nnorwitz): I think PyInt_AS_LONG is correct,\r
+               however, it looks like it should be AsSsize_t.\r
+               There should be a comment here explaining why.\r
+            */\r
+            x = PyInt_AS_LONG(v);\r
+        }\r
+        else if (PyIndex_Check(v)) {\r
+            x = PyNumber_AsSsize_t(v, NULL);\r
+            if (x == -1 && PyErr_Occurred())\r
+                return 0;\r
+        }\r
+        else {\r
+            PyErr_SetString(PyExc_TypeError,\r
+                            "slice indices must be integers or "\r
+                            "None or have an __index__ method");\r
+            return 0;\r
+        }\r
+        *pi = x;\r
+    }\r
+    return 1;\r
+}\r
+\r
+#undef ISINDEX\r
+#define ISINDEX(x) ((x) == NULL || \\r
+                    PyInt_Check(x) || PyLong_Check(x) || PyIndex_Check(x))\r
+\r
+static PyObject *\r
+apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */\r
+{\r
+    PyTypeObject *tp = u->ob_type;\r
+    PySequenceMethods *sq = tp->tp_as_sequence;\r
+\r
+    if (sq && sq->sq_slice && ISINDEX(v) && ISINDEX(w)) {\r
+        Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX;\r
+        if (!_PyEval_SliceIndex(v, &ilow))\r
+            return NULL;\r
+        if (!_PyEval_SliceIndex(w, &ihigh))\r
+            return NULL;\r
+        return PySequence_GetSlice(u, ilow, ihigh);\r
+    }\r
+    else {\r
+        PyObject *slice = PySlice_New(v, w, NULL);\r
+        if (slice != NULL) {\r
+            PyObject *res = PyObject_GetItem(u, slice);\r
+            Py_DECREF(slice);\r
+            return res;\r
+        }\r
+        else\r
+            return NULL;\r
+    }\r
+}\r
+\r
+static int\r
+assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)\r
+    /* u[v:w] = x */\r
+{\r
+    PyTypeObject *tp = u->ob_type;\r
+    PySequenceMethods *sq = tp->tp_as_sequence;\r
+\r
+    if (sq && sq->sq_ass_slice && ISINDEX(v) && ISINDEX(w)) {\r
+        Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX;\r
+        if (!_PyEval_SliceIndex(v, &ilow))\r
+            return -1;\r
+        if (!_PyEval_SliceIndex(w, &ihigh))\r
+            return -1;\r
+        if (x == NULL)\r
+            return PySequence_DelSlice(u, ilow, ihigh);\r
+        else\r
+            return PySequence_SetSlice(u, ilow, ihigh, x);\r
+    }\r
+    else {\r
+        PyObject *slice = PySlice_New(v, w, NULL);\r
+        if (slice != NULL) {\r
+            int res;\r
+            if (x != NULL)\r
+                res = PyObject_SetItem(u, slice, x);\r
+            else\r
+                res = PyObject_DelItem(u, slice);\r
+            Py_DECREF(slice);\r
+            return res;\r
+        }\r
+        else\r
+            return -1;\r
+    }\r
+}\r
+\r
+#define Py3kExceptionClass_Check(x)     \\r
+    (PyType_Check((x)) &&               \\r
+     PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))\r
+\r
+#define CANNOT_CATCH_MSG "catching classes that don't inherit from " \\r
+                         "BaseException is not allowed in 3.x"\r
+\r
+static PyObject *\r
+cmp_outcome(int op, register PyObject *v, register PyObject *w)\r
+{\r
+    int res = 0;\r
+    switch (op) {\r
+    case PyCmp_IS:\r
+        res = (v == w);\r
+        break;\r
+    case PyCmp_IS_NOT:\r
+        res = (v != w);\r
+        break;\r
+    case PyCmp_IN:\r
+        res = PySequence_Contains(w, v);\r
+        if (res < 0)\r
+            return NULL;\r
+        break;\r
+    case PyCmp_NOT_IN:\r
+        res = PySequence_Contains(w, v);\r
+        if (res < 0)\r
+            return NULL;\r
+        res = !res;\r
+        break;\r
+    case PyCmp_EXC_MATCH:\r
+        if (PyTuple_Check(w)) {\r
+            Py_ssize_t i, length;\r
+            length = PyTuple_Size(w);\r
+            for (i = 0; i < length; i += 1) {\r
+                PyObject *exc = PyTuple_GET_ITEM(w, i);\r
+                if (PyString_Check(exc)) {\r
+                    int ret_val;\r
+                    ret_val = PyErr_WarnEx(\r
+                        PyExc_DeprecationWarning,\r
+                        "catching of string "\r
+                        "exceptions is deprecated", 1);\r
+                    if (ret_val < 0)\r
+                        return NULL;\r
+                }\r
+                else if (Py_Py3kWarningFlag  &&\r
+                         !PyTuple_Check(exc) &&\r
+                         !Py3kExceptionClass_Check(exc))\r
+                {\r
+                    int ret_val;\r
+                    ret_val = PyErr_WarnEx(\r
+                        PyExc_DeprecationWarning,\r
+                        CANNOT_CATCH_MSG, 1);\r
+                    if (ret_val < 0)\r
+                        return NULL;\r
+                }\r
+            }\r
+        }\r
+        else {\r
+            if (PyString_Check(w)) {\r
+                int ret_val;\r
+                ret_val = PyErr_WarnEx(\r
+                                PyExc_DeprecationWarning,\r
+                                "catching of string "\r
+                                "exceptions is deprecated", 1);\r
+                if (ret_val < 0)\r
+                    return NULL;\r
+            }\r
+            else if (Py_Py3kWarningFlag  &&\r
+                     !PyTuple_Check(w) &&\r
+                     !Py3kExceptionClass_Check(w))\r
+            {\r
+                int ret_val;\r
+                ret_val = PyErr_WarnEx(\r
+                    PyExc_DeprecationWarning,\r
+                    CANNOT_CATCH_MSG, 1);\r
+                if (ret_val < 0)\r
+                    return NULL;\r
+            }\r
+        }\r
+        res = PyErr_GivenExceptionMatches(v, w);\r
+        break;\r
+    default:\r
+        return PyObject_RichCompare(v, w, op);\r
+    }\r
+    v = res ? Py_True : Py_False;\r
+    Py_INCREF(v);\r
+    return v;\r
+}\r
+\r
+static PyObject *\r
+import_from(PyObject *v, PyObject *name)\r
+{\r
+    PyObject *x;\r
+\r
+    x = PyObject_GetAttr(v, name);\r
+    if (x == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {\r
+        PyErr_Format(PyExc_ImportError,\r
+                     "cannot import name %.230s",\r
+                     PyString_AsString(name));\r
+    }\r
+    return x;\r
+}\r
+\r
+static int\r
+import_all_from(PyObject *locals, PyObject *v)\r
+{\r
+    PyObject *all = PyObject_GetAttrString(v, "__all__");\r
+    PyObject *dict, *name, *value;\r
+    int skip_leading_underscores = 0;\r
+    int pos, err;\r
+\r
+    if (all == NULL) {\r
+        if (!PyErr_ExceptionMatches(PyExc_AttributeError))\r
+            return -1; /* Unexpected error */\r
+        PyErr_Clear();\r
+        dict = PyObject_GetAttrString(v, "__dict__");\r
+        if (dict == NULL) {\r
+            if (!PyErr_ExceptionMatches(PyExc_AttributeError))\r
+                return -1;\r
+            PyErr_SetString(PyExc_ImportError,\r
+            "from-import-* object has no __dict__ and no __all__");\r
+            return -1;\r
+        }\r
+        all = PyMapping_Keys(dict);\r
+        Py_DECREF(dict);\r
+        if (all == NULL)\r
+            return -1;\r
+        skip_leading_underscores = 1;\r
+    }\r
+\r
+    for (pos = 0, err = 0; ; pos++) {\r
+        name = PySequence_GetItem(all, pos);\r
+        if (name == NULL) {\r
+            if (!PyErr_ExceptionMatches(PyExc_IndexError))\r
+                err = -1;\r
+            else\r
+                PyErr_Clear();\r
+            break;\r
+        }\r
+        if (skip_leading_underscores &&\r
+            PyString_Check(name) &&\r
+            PyString_AS_STRING(name)[0] == '_')\r
+        {\r
+            Py_DECREF(name);\r
+            continue;\r
+        }\r
+        value = PyObject_GetAttr(v, name);\r
+        if (value == NULL)\r
+            err = -1;\r
+        else if (PyDict_CheckExact(locals))\r
+            err = PyDict_SetItem(locals, name, value);\r
+        else\r
+            err = PyObject_SetItem(locals, name, value);\r
+        Py_DECREF(name);\r
+        Py_XDECREF(value);\r
+        if (err != 0)\r
+            break;\r
+    }\r
+    Py_DECREF(all);\r
+    return err;\r
+}\r
+\r
+static PyObject *\r
+build_class(PyObject *methods, PyObject *bases, PyObject *name)\r
+{\r
+    PyObject *metaclass = NULL, *result, *base;\r
+\r
+    if (PyDict_Check(methods))\r
+        metaclass = PyDict_GetItemString(methods, "__metaclass__");\r
+    if (metaclass != NULL)\r
+        Py_INCREF(metaclass);\r
+    else if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {\r
+        base = PyTuple_GET_ITEM(bases, 0);\r
+        metaclass = PyObject_GetAttrString(base, "__class__");\r
+        if (metaclass == NULL) {\r
+            PyErr_Clear();\r
+            metaclass = (PyObject *)base->ob_type;\r
+            Py_INCREF(metaclass);\r
+        }\r
+    }\r
+    else {\r
+        PyObject *g = PyEval_GetGlobals();\r
+        if (g != NULL && PyDict_Check(g))\r
+            metaclass = PyDict_GetItemString(g, "__metaclass__");\r
+        if (metaclass == NULL)\r
+            metaclass = (PyObject *) &PyClass_Type;\r
+        Py_INCREF(metaclass);\r
+    }\r
+    result = PyObject_CallFunctionObjArgs(metaclass, name, bases, methods,\r
+                                          NULL);\r
+    Py_DECREF(metaclass);\r
+    if (result == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\r
+        /* A type error here likely means that the user passed\r
+           in a base that was not a class (such the random module\r
+           instead of the random.random type).  Help them out with\r
+           by augmenting the error message with more information.*/\r
+\r
+        PyObject *ptype, *pvalue, *ptraceback;\r
+\r
+        PyErr_Fetch(&ptype, &pvalue, &ptraceback);\r
+        if (PyString_Check(pvalue)) {\r
+            PyObject *newmsg;\r
+            newmsg = PyString_FromFormat(\r
+                "Error when calling the metaclass bases\n"\r
+                "    %s",\r
+                PyString_AS_STRING(pvalue));\r
+            if (newmsg != NULL) {\r
+                Py_DECREF(pvalue);\r
+                pvalue = newmsg;\r
+            }\r
+        }\r
+        PyErr_Restore(ptype, pvalue, ptraceback);\r
+    }\r
+    return result;\r
+}\r
+\r
+static int\r
+exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals,\r
+               PyObject *locals)\r
+{\r
+    int n;\r
+    PyObject *v;\r
+    int plain = 0;\r
+\r
+    if (PyTuple_Check(prog) && globals == Py_None && locals == Py_None &&\r
+        ((n = PyTuple_Size(prog)) == 2 || n == 3)) {\r
+        /* Backward compatibility hack */\r
+        globals = PyTuple_GetItem(prog, 1);\r
+        if (n == 3)\r
+            locals = PyTuple_GetItem(prog, 2);\r
+        prog = PyTuple_GetItem(prog, 0);\r
+    }\r
+    if (globals == Py_None) {\r
+        globals = PyEval_GetGlobals();\r
+        if (locals == Py_None) {\r
+            locals = PyEval_GetLocals();\r
+            plain = 1;\r
+        }\r
+        if (!globals || !locals) {\r
+            PyErr_SetString(PyExc_SystemError,\r
+                            "globals and locals cannot be NULL");\r
+            return -1;\r
+        }\r
+    }\r
+    else if (locals == Py_None)\r
+        locals = globals;\r
+    if (!PyString_Check(prog) &&\r
+#ifdef Py_USING_UNICODE\r
+        !PyUnicode_Check(prog) &&\r
+#endif\r
+        !PyCode_Check(prog) &&\r
+        !PyFile_Check(prog)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+            "exec: arg 1 must be a string, file, or code object");\r
+        return -1;\r
+    }\r
+    if (!PyDict_Check(globals)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+            "exec: arg 2 must be a dictionary or None");\r
+        return -1;\r
+    }\r
+    if (!PyMapping_Check(locals)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+            "exec: arg 3 must be a mapping or None");\r
+        return -1;\r
+    }\r
+    if (PyDict_GetItemString(globals, "__builtins__") == NULL)\r
+        PyDict_SetItemString(globals, "__builtins__", f->f_builtins);\r
+    if (PyCode_Check(prog)) {\r
+        if (PyCode_GetNumFree((PyCodeObject *)prog) > 0) {\r
+            PyErr_SetString(PyExc_TypeError,\r
+        "code object passed to exec may not contain free variables");\r
+            return -1;\r
+        }\r
+        v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals);\r
+    }\r
+    else if (PyFile_Check(prog)) {\r
+        FILE *fp = PyFile_AsFile(prog);\r
+        char *name = PyString_AsString(PyFile_Name(prog));\r
+        PyCompilerFlags cf;\r
+        if (name == NULL)\r
+            return -1;\r
+        cf.cf_flags = 0;\r
+        if (PyEval_MergeCompilerFlags(&cf))\r
+            v = PyRun_FileFlags(fp, name, Py_file_input, globals,\r
+                                locals, &cf);\r
+        else\r
+            v = PyRun_File(fp, name, Py_file_input, globals,\r
+                           locals);\r
+    }\r
+    else {\r
+        PyObject *tmp = NULL;\r
+        char *str;\r
+        PyCompilerFlags cf;\r
+        cf.cf_flags = 0;\r
+#ifdef Py_USING_UNICODE\r
+        if (PyUnicode_Check(prog)) {\r
+            tmp = PyUnicode_AsUTF8String(prog);\r
+            if (tmp == NULL)\r
+                return -1;\r
+            prog = tmp;\r
+            cf.cf_flags |= PyCF_SOURCE_IS_UTF8;\r
+        }\r
+#endif\r
+        if (PyString_AsStringAndSize(prog, &str, NULL))\r
+            return -1;\r
+        if (PyEval_MergeCompilerFlags(&cf))\r
+            v = PyRun_StringFlags(str, Py_file_input, globals,\r
+                                  locals, &cf);\r
+        else\r
+            v = PyRun_String(str, Py_file_input, globals, locals);\r
+        Py_XDECREF(tmp);\r
+    }\r
+    if (plain)\r
+        PyFrame_LocalsToFast(f, 0);\r
+    if (v == NULL)\r
+        return -1;\r
+    Py_DECREF(v);\r
+    return 0;\r
+}\r
+\r
+static void\r
+format_exc_check_arg(PyObject *exc, char *format_str, PyObject *obj)\r
+{\r
+    char *obj_str;\r
+\r
+    if (!obj)\r
+        return;\r
+\r
+    obj_str = PyString_AsString(obj);\r
+    if (!obj_str)\r
+        return;\r
+\r
+    PyErr_Format(exc, format_str, obj_str);\r
+}\r
+\r
+static PyObject *\r
+string_concatenate(PyObject *v, PyObject *w,\r
+                   PyFrameObject *f, unsigned char *next_instr)\r
+{\r
+    /* This function implements 'variable += expr' when both arguments\r
+       are strings. */\r
+    Py_ssize_t v_len = PyString_GET_SIZE(v);\r
+    Py_ssize_t w_len = PyString_GET_SIZE(w);\r
+    Py_ssize_t new_len = v_len + w_len;\r
+    if (new_len < 0) {\r
+        PyErr_SetString(PyExc_OverflowError,\r
+                        "strings are too large to concat");\r
+        return NULL;\r
+    }\r
+\r
+    if (v->ob_refcnt == 2) {\r
+        /* In the common case, there are 2 references to the value\r
+         * stored in 'variable' when the += is performed: one on the\r
+         * value stack (in 'v') and one still stored in the\r
+         * 'variable'.  We try to delete the variable now to reduce\r
+         * the refcnt to 1.\r
+         */\r
+        switch (*next_instr) {\r
+        case STORE_FAST:\r
+        {\r
+            int oparg = PEEKARG();\r
+            PyObject **fastlocals = f->f_localsplus;\r
+            if (GETLOCAL(oparg) == v)\r
+                SETLOCAL(oparg, NULL);\r
+            break;\r
+        }\r
+        case STORE_DEREF:\r
+        {\r
+            PyObject **freevars = (f->f_localsplus +\r
+                                   f->f_code->co_nlocals);\r
+            PyObject *c = freevars[PEEKARG()];\r
+            if (PyCell_GET(c) == v)\r
+                PyCell_Set(c, NULL);\r
+            break;\r
+        }\r
+        case STORE_NAME:\r
+        {\r
+            PyObject *names = f->f_code->co_names;\r
+            PyObject *name = GETITEM(names, PEEKARG());\r
+            PyObject *locals = f->f_locals;\r
+            if (PyDict_CheckExact(locals) &&\r
+                PyDict_GetItem(locals, name) == v) {\r
+                if (PyDict_DelItem(locals, name) != 0) {\r
+                    PyErr_Clear();\r
+                }\r
+            }\r
+            break;\r
+        }\r
+        }\r
+    }\r
+\r
+    if (v->ob_refcnt == 1 && !PyString_CHECK_INTERNED(v)) {\r
+        /* Now we own the last reference to 'v', so we can resize it\r
+         * in-place.\r
+         */\r
+        if (_PyString_Resize(&v, new_len) != 0) {\r
+            /* XXX if _PyString_Resize() fails, 'v' has been\r
+             * deallocated so it cannot be put back into\r
+             * 'variable'.  The MemoryError is raised when there\r
+             * is no value in 'variable', which might (very\r
+             * remotely) be a cause of incompatibilities.\r
+             */\r
+            return NULL;\r
+        }\r
+        /* copy 'w' into the newly allocated area of 'v' */\r
+        memcpy(PyString_AS_STRING(v) + v_len,\r
+               PyString_AS_STRING(w), w_len);\r
+        return v;\r
+    }\r
+    else {\r
+        /* When in-place resizing is not an option. */\r
+        PyString_Concat(&v, w);\r
+        return v;\r
+    }\r
+}\r
+\r
+#ifdef DYNAMIC_EXECUTION_PROFILE\r
+\r
+static PyObject *\r
+getarray(long a[256])\r
+{\r
+    int i;\r
+    PyObject *l = PyList_New(256);\r
+    if (l == NULL) return NULL;\r
+    for (i = 0; i < 256; i++) {\r
+        PyObject *x = PyInt_FromLong(a[i]);\r
+        if (x == NULL) {\r
+            Py_DECREF(l);\r
+            return NULL;\r
+        }\r
+        PyList_SetItem(l, i, x);\r
+    }\r
+    for (i = 0; i < 256; i++)\r
+        a[i] = 0;\r
+    return l;\r
+}\r
+\r
+PyObject *\r
+_Py_GetDXProfile(PyObject *self, PyObject *args)\r
+{\r
+#ifndef DXPAIRS\r
+    return getarray(dxp);\r
+#else\r
+    int i;\r
+    PyObject *l = PyList_New(257);\r
+    if (l == NULL) return NULL;\r
+    for (i = 0; i < 257; i++) {\r
+        PyObject *x = getarray(dxpairs[i]);\r
+        if (x == NULL) {\r
+            Py_DECREF(l);\r
+            return NULL;\r
+        }\r
+        PyList_SetItem(l, i, x);\r
+    }\r
+    return l;\r
+#endif\r
+}\r
+\r
+#endif\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/codecs.c b/AppPkg/Applications/Python/Python-2.7.10/Python/codecs.c
new file mode 100644 (file)
index 0000000..8de5129
--- /dev/null
@@ -0,0 +1,889 @@
+/* ------------------------------------------------------------------------\r
+\r
+   Python Codec Registry and support functions\r
+\r
+Written by Marc-Andre Lemburg (mal@lemburg.com).\r
+\r
+Copyright (c) Corporation for National Research Initiatives.\r
+\r
+   ------------------------------------------------------------------------ */\r
+\r
+#include "Python.h"\r
+#include <ctype.h>\r
+\r
+/* --- Codec Registry ----------------------------------------------------- */\r
+\r
+/* Import the standard encodings package which will register the first\r
+   codec search function.\r
+\r
+   This is done in a lazy way so that the Unicode implementation does\r
+   not downgrade startup time of scripts not needing it.\r
+\r
+   ImportErrors are silently ignored by this function. Only one try is\r
+   made.\r
+\r
+*/\r
+\r
+static int _PyCodecRegistry_Init(void); /* Forward */\r
+\r
+int PyCodec_Register(PyObject *search_function)\r
+{\r
+    PyInterpreterState *interp = PyThreadState_GET()->interp;\r
+    if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())\r
+        goto onError;\r
+    if (search_function == NULL) {\r
+        PyErr_BadArgument();\r
+        goto onError;\r
+    }\r
+    if (!PyCallable_Check(search_function)) {\r
+        PyErr_SetString(PyExc_TypeError, "argument must be callable");\r
+        goto onError;\r
+    }\r
+    return PyList_Append(interp->codec_search_path, search_function);\r
+\r
+ onError:\r
+    return -1;\r
+}\r
+\r
+/* Convert a string to a normalized Python string: all characters are\r
+   converted to lower case, spaces are replaced with underscores. */\r
+\r
+static\r
+PyObject *normalizestring(const char *string)\r
+{\r
+    register size_t i;\r
+    size_t len = strlen(string);\r
+    char *p;\r
+    PyObject *v;\r
+\r
+    if (len > PY_SSIZE_T_MAX) {\r
+        PyErr_SetString(PyExc_OverflowError, "string is too large");\r
+        return NULL;\r
+    }\r
+\r
+    v = PyString_FromStringAndSize(NULL, len);\r
+    if (v == NULL)\r
+        return NULL;\r
+    p = PyString_AS_STRING(v);\r
+    for (i = 0; i < len; i++) {\r
+        register char ch = string[i];\r
+        if (ch == ' ')\r
+            ch = '-';\r
+        else\r
+            ch = Py_TOLOWER(Py_CHARMASK(ch));\r
+        p[i] = ch;\r
+    }\r
+    return v;\r
+}\r
+\r
+/* Lookup the given encoding and return a tuple providing the codec\r
+   facilities.\r
+\r
+   The encoding string is looked up converted to all lower-case\r
+   characters. This makes encodings looked up through this mechanism\r
+   effectively case-insensitive.\r
+\r
+   If no codec is found, a LookupError is set and NULL returned.\r
+\r
+   As side effect, this tries to load the encodings package, if not\r
+   yet done. This is part of the lazy load strategy for the encodings\r
+   package.\r
+\r
+*/\r
+\r
+PyObject *_PyCodec_Lookup(const char *encoding)\r
+{\r
+    PyInterpreterState *interp;\r
+    PyObject *result, *args = NULL, *v;\r
+    Py_ssize_t i, len;\r
+\r
+    if (encoding == NULL) {\r
+        PyErr_BadArgument();\r
+        goto onError;\r
+    }\r
+\r
+    interp = PyThreadState_GET()->interp;\r
+    if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())\r
+        goto onError;\r
+\r
+    /* Convert the encoding to a normalized Python string: all\r
+       characters are converted to lower case, spaces and hyphens are\r
+       replaced with underscores. */\r
+    v = normalizestring(encoding);\r
+    if (v == NULL)\r
+        goto onError;\r
+    PyString_InternInPlace(&v);\r
+\r
+    /* First, try to lookup the name in the registry dictionary */\r
+    result = PyDict_GetItem(interp->codec_search_cache, v);\r
+    if (result != NULL) {\r
+        Py_INCREF(result);\r
+        Py_DECREF(v);\r
+        return result;\r
+    }\r
+\r
+    /* Next, scan the search functions in order of registration */\r
+    args = PyTuple_New(1);\r
+    if (args == NULL)\r
+        goto onError;\r
+    PyTuple_SET_ITEM(args,0,v);\r
+\r
+    len = PyList_Size(interp->codec_search_path);\r
+    if (len < 0)\r
+        goto onError;\r
+    if (len == 0) {\r
+        PyErr_SetString(PyExc_LookupError,\r
+                        "no codec search functions registered: "\r
+                        "can't find encoding");\r
+        goto onError;\r
+    }\r
+\r
+    for (i = 0; i < len; i++) {\r
+        PyObject *func;\r
+\r
+        func = PyList_GetItem(interp->codec_search_path, i);\r
+        if (func == NULL)\r
+            goto onError;\r
+        result = PyEval_CallObject(func, args);\r
+        if (result == NULL)\r
+            goto onError;\r
+        if (result == Py_None) {\r
+            Py_DECREF(result);\r
+            continue;\r
+        }\r
+        if (!PyTuple_Check(result) || PyTuple_GET_SIZE(result) != 4) {\r
+            PyErr_SetString(PyExc_TypeError,\r
+                            "codec search functions must return 4-tuples");\r
+            Py_DECREF(result);\r
+            goto onError;\r
+        }\r
+        break;\r
+    }\r
+    if (i == len) {\r
+        /* XXX Perhaps we should cache misses too ? */\r
+        PyErr_Format(PyExc_LookupError,\r
+                     "unknown encoding: %s", encoding);\r
+        goto onError;\r
+    }\r
+\r
+    /* Cache and return the result */\r
+    PyDict_SetItem(interp->codec_search_cache, v, result);\r
+    Py_DECREF(args);\r
+    return result;\r
+\r
+ onError:\r
+    Py_XDECREF(args);\r
+    return NULL;\r
+}\r
+\r
+static\r
+PyObject *args_tuple(PyObject *object,\r
+                     const char *errors)\r
+{\r
+    PyObject *args;\r
+\r
+    args = PyTuple_New(1 + (errors != NULL));\r
+    if (args == NULL)\r
+        return NULL;\r
+    Py_INCREF(object);\r
+    PyTuple_SET_ITEM(args,0,object);\r
+    if (errors) {\r
+        PyObject *v;\r
+\r
+        v = PyString_FromString(errors);\r
+        if (v == NULL) {\r
+            Py_DECREF(args);\r
+            return NULL;\r
+        }\r
+        PyTuple_SET_ITEM(args, 1, v);\r
+    }\r
+    return args;\r
+}\r
+\r
+/* Helper function to get a codec item */\r
+\r
+static\r
+PyObject *codec_getitem(const char *encoding, int index)\r
+{\r
+    PyObject *codecs;\r
+    PyObject *v;\r
+\r
+    codecs = _PyCodec_Lookup(encoding);\r
+    if (codecs == NULL)\r
+        return NULL;\r
+    v = PyTuple_GET_ITEM(codecs, index);\r
+    Py_DECREF(codecs);\r
+    Py_INCREF(v);\r
+    return v;\r
+}\r
+\r
+/* Helper function to create an incremental codec. */\r
+\r
+static\r
+PyObject *codec_getincrementalcodec(const char *encoding,\r
+                                    const char *errors,\r
+                                    const char *attrname)\r
+{\r
+    PyObject *codecs, *ret, *inccodec;\r
+\r
+    codecs = _PyCodec_Lookup(encoding);\r
+    if (codecs == NULL)\r
+        return NULL;\r
+    inccodec = PyObject_GetAttrString(codecs, attrname);\r
+    Py_DECREF(codecs);\r
+    if (inccodec == NULL)\r
+        return NULL;\r
+    if (errors)\r
+        ret = PyObject_CallFunction(inccodec, "s", errors);\r
+    else\r
+        ret = PyObject_CallFunction(inccodec, NULL);\r
+    Py_DECREF(inccodec);\r
+    return ret;\r
+}\r
+\r
+/* Helper function to create a stream codec. */\r
+\r
+static\r
+PyObject *codec_getstreamcodec(const char *encoding,\r
+                               PyObject *stream,\r
+                               const char *errors,\r
+                               const int index)\r
+{\r
+    PyObject *codecs, *streamcodec, *codeccls;\r
+\r
+    codecs = _PyCodec_Lookup(encoding);\r
+    if (codecs == NULL)\r
+        return NULL;\r
+\r
+    codeccls = PyTuple_GET_ITEM(codecs, index);\r
+    if (errors != NULL)\r
+        streamcodec = PyObject_CallFunction(codeccls, "Os", stream, errors);\r
+    else\r
+        streamcodec = PyObject_CallFunction(codeccls, "O", stream);\r
+    Py_DECREF(codecs);\r
+    return streamcodec;\r
+}\r
+\r
+/* Convenience APIs to query the Codec registry.\r
+\r
+   All APIs return a codec object with incremented refcount.\r
+\r
+ */\r
+\r
+PyObject *PyCodec_Encoder(const char *encoding)\r
+{\r
+    return codec_getitem(encoding, 0);\r
+}\r
+\r
+PyObject *PyCodec_Decoder(const char *encoding)\r
+{\r
+    return codec_getitem(encoding, 1);\r
+}\r
+\r
+PyObject *PyCodec_IncrementalEncoder(const char *encoding,\r
+                                     const char *errors)\r
+{\r
+    return codec_getincrementalcodec(encoding, errors, "incrementalencoder");\r
+}\r
+\r
+PyObject *PyCodec_IncrementalDecoder(const char *encoding,\r
+                                     const char *errors)\r
+{\r
+    return codec_getincrementalcodec(encoding, errors, "incrementaldecoder");\r
+}\r
+\r
+PyObject *PyCodec_StreamReader(const char *encoding,\r
+                               PyObject *stream,\r
+                               const char *errors)\r
+{\r
+    return codec_getstreamcodec(encoding, stream, errors, 2);\r
+}\r
+\r
+PyObject *PyCodec_StreamWriter(const char *encoding,\r
+                               PyObject *stream,\r
+                               const char *errors)\r
+{\r
+    return codec_getstreamcodec(encoding, stream, errors, 3);\r
+}\r
+\r
+/* Encode an object (e.g. an Unicode object) using the given encoding\r
+   and return the resulting encoded object (usually a Python string).\r
+\r
+   errors is passed to the encoder factory as argument if non-NULL. */\r
+\r
+PyObject *PyCodec_Encode(PyObject *object,\r
+                         const char *encoding,\r
+                         const char *errors)\r
+{\r
+    PyObject *encoder = NULL;\r
+    PyObject *args = NULL, *result = NULL;\r
+    PyObject *v;\r
+\r
+    encoder = PyCodec_Encoder(encoding);\r
+    if (encoder == NULL)\r
+        goto onError;\r
+\r
+    args = args_tuple(object, errors);\r
+    if (args == NULL)\r
+        goto onError;\r
+\r
+    result = PyEval_CallObject(encoder,args);\r
+    if (result == NULL)\r
+        goto onError;\r
+\r
+    if (!PyTuple_Check(result) ||\r
+        PyTuple_GET_SIZE(result) != 2) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                        "encoder must return a tuple (object,integer)");\r
+        goto onError;\r
+    }\r
+    v = PyTuple_GET_ITEM(result,0);\r
+    Py_INCREF(v);\r
+    /* We don't check or use the second (integer) entry. */\r
+\r
+    Py_DECREF(args);\r
+    Py_DECREF(encoder);\r
+    Py_DECREF(result);\r
+    return v;\r
+\r
+ onError:\r
+    Py_XDECREF(result);\r
+    Py_XDECREF(args);\r
+    Py_XDECREF(encoder);\r
+    return NULL;\r
+}\r
+\r
+/* Decode an object (usually a Python string) using the given encoding\r
+   and return an equivalent object (e.g. an Unicode object).\r
+\r
+   errors is passed to the decoder factory as argument if non-NULL. */\r
+\r
+PyObject *PyCodec_Decode(PyObject *object,\r
+                         const char *encoding,\r
+                         const char *errors)\r
+{\r
+    PyObject *decoder = NULL;\r
+    PyObject *args = NULL, *result = NULL;\r
+    PyObject *v;\r
+\r
+    decoder = PyCodec_Decoder(encoding);\r
+    if (decoder == NULL)\r
+        goto onError;\r
+\r
+    args = args_tuple(object, errors);\r
+    if (args == NULL)\r
+        goto onError;\r
+\r
+    result = PyEval_CallObject(decoder,args);\r
+    if (result == NULL)\r
+        goto onError;\r
+    if (!PyTuple_Check(result) ||\r
+        PyTuple_GET_SIZE(result) != 2) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                        "decoder must return a tuple (object,integer)");\r
+        goto onError;\r
+    }\r
+    v = PyTuple_GET_ITEM(result,0);\r
+    Py_INCREF(v);\r
+    /* We don't check or use the second (integer) entry. */\r
+\r
+    Py_DECREF(args);\r
+    Py_DECREF(decoder);\r
+    Py_DECREF(result);\r
+    return v;\r
+\r
+ onError:\r
+    Py_XDECREF(args);\r
+    Py_XDECREF(decoder);\r
+    Py_XDECREF(result);\r
+    return NULL;\r
+}\r
+\r
+/* Register the error handling callback function error under the name\r
+   name. This function will be called by the codec when it encounters\r
+   an unencodable characters/undecodable bytes and doesn't know the\r
+   callback name, when name is specified as the error parameter\r
+   in the call to the encode/decode function.\r
+   Return 0 on success, -1 on error */\r
+int PyCodec_RegisterError(const char *name, PyObject *error)\r
+{\r
+    PyInterpreterState *interp = PyThreadState_GET()->interp;\r
+    if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())\r
+        return -1;\r
+    if (!PyCallable_Check(error)) {\r
+        PyErr_SetString(PyExc_TypeError, "handler must be callable");\r
+        return -1;\r
+    }\r
+    return PyDict_SetItemString(interp->codec_error_registry,\r
+                                (char *)name, error);\r
+}\r
+\r
+/* Lookup the error handling callback function registered under the\r
+   name error. As a special case NULL can be passed, in which case\r
+   the error handling callback for strict encoding will be returned. */\r
+PyObject *PyCodec_LookupError(const char *name)\r
+{\r
+    PyObject *handler = NULL;\r
+\r
+    PyInterpreterState *interp = PyThreadState_GET()->interp;\r
+    if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())\r
+        return NULL;\r
+\r
+    if (name==NULL)\r
+        name = "strict";\r
+    handler = PyDict_GetItemString(interp->codec_error_registry, (char *)name);\r
+    if (!handler)\r
+        PyErr_Format(PyExc_LookupError, "unknown error handler name '%.400s'", name);\r
+    else\r
+        Py_INCREF(handler);\r
+    return handler;\r
+}\r
+\r
+static void wrong_exception_type(PyObject *exc)\r
+{\r
+    PyObject *type = PyObject_GetAttrString(exc, "__class__");\r
+    if (type != NULL) {\r
+        PyObject *name = PyObject_GetAttrString(type, "__name__");\r
+        Py_DECREF(type);\r
+        if (name != NULL) {\r
+            PyObject *string = PyObject_Str(name);\r
+            Py_DECREF(name);\r
+            if (string != NULL) {\r
+                PyErr_Format(PyExc_TypeError,\r
+                    "don't know how to handle %.400s in error callback",\r
+                    PyString_AS_STRING(string));\r
+                Py_DECREF(string);\r
+            }\r
+        }\r
+    }\r
+}\r
+\r
+PyObject *PyCodec_StrictErrors(PyObject *exc)\r
+{\r
+    if (PyExceptionInstance_Check(exc))\r
+        PyErr_SetObject(PyExceptionInstance_Class(exc), exc);\r
+    else\r
+        PyErr_SetString(PyExc_TypeError, "codec must pass exception instance");\r
+    return NULL;\r
+}\r
+\r
+\r
+#ifdef Py_USING_UNICODE\r
+PyObject *PyCodec_IgnoreErrors(PyObject *exc)\r
+{\r
+    Py_ssize_t end;\r
+    if (PyObject_IsInstance(exc, PyExc_UnicodeEncodeError)) {\r
+        if (PyUnicodeEncodeError_GetEnd(exc, &end))\r
+            return NULL;\r
+    }\r
+    else if (PyObject_IsInstance(exc, PyExc_UnicodeDecodeError)) {\r
+        if (PyUnicodeDecodeError_GetEnd(exc, &end))\r
+            return NULL;\r
+    }\r
+    else if (PyObject_IsInstance(exc, PyExc_UnicodeTranslateError)) {\r
+        if (PyUnicodeTranslateError_GetEnd(exc, &end))\r
+            return NULL;\r
+    }\r
+    else {\r
+        wrong_exception_type(exc);\r
+        return NULL;\r
+    }\r
+    /* ouch: passing NULL, 0, pos gives None instead of u'' */\r
+    return Py_BuildValue("(u#n)", &end, 0, end);\r
+}\r
+\r
+\r
+PyObject *PyCodec_ReplaceErrors(PyObject *exc)\r
+{\r
+    PyObject *restuple;\r
+    Py_ssize_t start;\r
+    Py_ssize_t end;\r
+    Py_ssize_t i;\r
+\r
+    if (PyObject_IsInstance(exc, PyExc_UnicodeEncodeError)) {\r
+        PyObject *res;\r
+        Py_UNICODE *p;\r
+        if (PyUnicodeEncodeError_GetStart(exc, &start))\r
+            return NULL;\r
+        if (PyUnicodeEncodeError_GetEnd(exc, &end))\r
+            return NULL;\r
+        res = PyUnicode_FromUnicode(NULL, end-start);\r
+        if (res == NULL)\r
+            return NULL;\r
+        for (p = PyUnicode_AS_UNICODE(res), i = start;\r
+            i<end; ++p, ++i)\r
+            *p = '?';\r
+        restuple = Py_BuildValue("(On)", res, end);\r
+        Py_DECREF(res);\r
+        return restuple;\r
+    }\r
+    else if (PyObject_IsInstance(exc, PyExc_UnicodeDecodeError)) {\r
+        Py_UNICODE res = Py_UNICODE_REPLACEMENT_CHARACTER;\r
+        if (PyUnicodeDecodeError_GetEnd(exc, &end))\r
+            return NULL;\r
+        return Py_BuildValue("(u#n)", &res, (Py_ssize_t)1, end);\r
+    }\r
+    else if (PyObject_IsInstance(exc, PyExc_UnicodeTranslateError)) {\r
+        PyObject *res;\r
+        Py_UNICODE *p;\r
+        if (PyUnicodeTranslateError_GetStart(exc, &start))\r
+            return NULL;\r
+        if (PyUnicodeTranslateError_GetEnd(exc, &end))\r
+            return NULL;\r
+        res = PyUnicode_FromUnicode(NULL, end-start);\r
+        if (res == NULL)\r
+            return NULL;\r
+        for (p = PyUnicode_AS_UNICODE(res), i = start;\r
+            i<end; ++p, ++i)\r
+            *p = Py_UNICODE_REPLACEMENT_CHARACTER;\r
+        restuple = Py_BuildValue("(On)", res, end);\r
+        Py_DECREF(res);\r
+        return restuple;\r
+    }\r
+    else {\r
+        wrong_exception_type(exc);\r
+        return NULL;\r
+    }\r
+}\r
+\r
+PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc)\r
+{\r
+    if (PyObject_IsInstance(exc, PyExc_UnicodeEncodeError)) {\r
+        PyObject *restuple;\r
+        PyObject *object;\r
+        Py_ssize_t start;\r
+        Py_ssize_t end;\r
+        PyObject *res;\r
+        Py_UNICODE *p;\r
+        Py_UNICODE *startp;\r
+        Py_UNICODE *e;\r
+        Py_UNICODE *outp;\r
+        Py_ssize_t ressize;\r
+        if (PyUnicodeEncodeError_GetStart(exc, &start))\r
+            return NULL;\r
+        if (PyUnicodeEncodeError_GetEnd(exc, &end))\r
+            return NULL;\r
+        if (!(object = PyUnicodeEncodeError_GetObject(exc)))\r
+            return NULL;\r
+        startp = PyUnicode_AS_UNICODE(object);\r
+        if (end - start > PY_SSIZE_T_MAX / (2+7+1)) {\r
+            end = start + PY_SSIZE_T_MAX / (2+7+1);\r
+#ifndef Py_UNICODE_WIDE\r
+            if (0xD800 <= startp[end - 1] && startp[end - 1] <= 0xDBFF)\r
+                end--;\r
+#endif\r
+        }\r
+        e = startp + end;\r
+        for (p = startp+start, ressize = 0; p < e;) {\r
+            Py_UCS4 ch = *p++;\r
+#ifndef Py_UNICODE_WIDE\r
+            if ((0xD800 <= ch && ch <= 0xDBFF) &&\r
+                (p < e) &&\r
+                (0xDC00 <= *p && *p <= 0xDFFF)) {\r
+                ch = ((((ch & 0x03FF) << 10) |\r
+                       ((Py_UCS4)*p++ & 0x03FF)) + 0x10000);\r
+            }\r
+#endif\r
+            if (ch < 10)\r
+                ressize += 2+1+1;\r
+            else if (ch < 100)\r
+                ressize += 2+2+1;\r
+            else if (ch < 1000)\r
+                ressize += 2+3+1;\r
+            else if (ch < 10000)\r
+                ressize += 2+4+1;\r
+            else if (ch < 100000)\r
+                ressize += 2+5+1;\r
+            else if (ch < 1000000)\r
+                ressize += 2+6+1;\r
+            else\r
+                ressize += 2+7+1;\r
+        }\r
+        /* allocate replacement */\r
+        res = PyUnicode_FromUnicode(NULL, ressize);\r
+        if (res == NULL) {\r
+            Py_DECREF(object);\r
+            return NULL;\r
+        }\r
+        /* generate replacement */\r
+        for (p = startp+start, outp = PyUnicode_AS_UNICODE(res); p < e;) {\r
+            int digits;\r
+            int base;\r
+            Py_UCS4 ch = *p++;\r
+#ifndef Py_UNICODE_WIDE\r
+            if ((0xD800 <= ch && ch <= 0xDBFF) &&\r
+                (p < startp+end) &&\r
+                (0xDC00 <= *p && *p <= 0xDFFF)) {\r
+                ch = ((((ch & 0x03FF) << 10) |\r
+                       ((Py_UCS4)*p++ & 0x03FF)) + 0x10000);\r
+            }\r
+#endif\r
+            *outp++ = '&';\r
+            *outp++ = '#';\r
+            if (ch < 10) {\r
+                digits = 1;\r
+                base = 1;\r
+            }\r
+            else if (ch < 100) {\r
+                digits = 2;\r
+                base = 10;\r
+            }\r
+            else if (ch < 1000) {\r
+                digits = 3;\r
+                base = 100;\r
+            }\r
+            else if (ch < 10000) {\r
+                digits = 4;\r
+                base = 1000;\r
+            }\r
+            else if (ch < 100000) {\r
+                digits = 5;\r
+                base = 10000;\r
+            }\r
+            else if (ch < 1000000) {\r
+                digits = 6;\r
+                base = 100000;\r
+            }\r
+            else {\r
+                digits = 7;\r
+                base = 1000000;\r
+            }\r
+            while (digits-->0) {\r
+                *outp++ = '0' + ch/base;\r
+                ch %= base;\r
+                base /= 10;\r
+            }\r
+            *outp++ = ';';\r
+        }\r
+        restuple = Py_BuildValue("(On)", res, end);\r
+        Py_DECREF(res);\r
+        Py_DECREF(object);\r
+        return restuple;\r
+    }\r
+    else {\r
+        wrong_exception_type(exc);\r
+        return NULL;\r
+    }\r
+}\r
+\r
+static Py_UNICODE hexdigits[] = {\r
+    '0', '1', '2', '3', '4', '5', '6', '7',\r
+    '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'\r
+};\r
+\r
+PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)\r
+{\r
+    if (PyObject_IsInstance(exc, PyExc_UnicodeEncodeError)) {\r
+        PyObject *restuple;\r
+        PyObject *object;\r
+        Py_ssize_t start;\r
+        Py_ssize_t end;\r
+        PyObject *res;\r
+        Py_UNICODE *p;\r
+        Py_UNICODE *startp;\r
+        Py_UNICODE *outp;\r
+        Py_ssize_t ressize;\r
+        if (PyUnicodeEncodeError_GetStart(exc, &start))\r
+            return NULL;\r
+        if (PyUnicodeEncodeError_GetEnd(exc, &end))\r
+            return NULL;\r
+        if (!(object = PyUnicodeEncodeError_GetObject(exc)))\r
+            return NULL;\r
+        if (end - start > PY_SSIZE_T_MAX / (1+1+8))\r
+            end = start + PY_SSIZE_T_MAX / (1+1+8);\r
+        startp = PyUnicode_AS_UNICODE(object);\r
+        for (p = startp+start, ressize = 0; p < startp+end; ++p) {\r
+#ifdef Py_UNICODE_WIDE\r
+            if (*p >= 0x00010000)\r
+                ressize += 1+1+8;\r
+            else\r
+#endif\r
+            if (*p >= 0x100) {\r
+                ressize += 1+1+4;\r
+            }\r
+            else\r
+                ressize += 1+1+2;\r
+        }\r
+        res = PyUnicode_FromUnicode(NULL, ressize);\r
+        if (res == NULL) {\r
+            Py_DECREF(object);\r
+            return NULL;\r
+        }\r
+        for (p = startp+start, outp = PyUnicode_AS_UNICODE(res);\r
+            p < startp+end; ++p) {\r
+            Py_UNICODE c = *p;\r
+            *outp++ = '\\';\r
+#ifdef Py_UNICODE_WIDE\r
+            if (c >= 0x00010000) {\r
+                *outp++ = 'U';\r
+                *outp++ = hexdigits[(c>>28)&0xf];\r
+                *outp++ = hexdigits[(c>>24)&0xf];\r
+                *outp++ = hexdigits[(c>>20)&0xf];\r
+                *outp++ = hexdigits[(c>>16)&0xf];\r
+                *outp++ = hexdigits[(c>>12)&0xf];\r
+                *outp++ = hexdigits[(c>>8)&0xf];\r
+            }\r
+            else\r
+#endif\r
+            if (c >= 0x100) {\r
+                *outp++ = 'u';\r
+                *outp++ = hexdigits[(c>>12)&0xf];\r
+                *outp++ = hexdigits[(c>>8)&0xf];\r
+            }\r
+            else\r
+                *outp++ = 'x';\r
+            *outp++ = hexdigits[(c>>4)&0xf];\r
+            *outp++ = hexdigits[c&0xf];\r
+        }\r
+\r
+        restuple = Py_BuildValue("(On)", res, end);\r
+        Py_DECREF(res);\r
+        Py_DECREF(object);\r
+        return restuple;\r
+    }\r
+    else {\r
+        wrong_exception_type(exc);\r
+        return NULL;\r
+    }\r
+}\r
+#endif\r
+\r
+static PyObject *strict_errors(PyObject *self, PyObject *exc)\r
+{\r
+    return PyCodec_StrictErrors(exc);\r
+}\r
+\r
+\r
+#ifdef Py_USING_UNICODE\r
+static PyObject *ignore_errors(PyObject *self, PyObject *exc)\r
+{\r
+    return PyCodec_IgnoreErrors(exc);\r
+}\r
+\r
+\r
+static PyObject *replace_errors(PyObject *self, PyObject *exc)\r
+{\r
+    return PyCodec_ReplaceErrors(exc);\r
+}\r
+\r
+\r
+static PyObject *xmlcharrefreplace_errors(PyObject *self, PyObject *exc)\r
+{\r
+    return PyCodec_XMLCharRefReplaceErrors(exc);\r
+}\r
+\r
+\r
+static PyObject *backslashreplace_errors(PyObject *self, PyObject *exc)\r
+{\r
+    return PyCodec_BackslashReplaceErrors(exc);\r
+}\r
+#endif\r
+\r
+static int _PyCodecRegistry_Init(void)\r
+{\r
+    static struct {\r
+        char *name;\r
+        PyMethodDef def;\r
+    } methods[] =\r
+    {\r
+        {\r
+            "strict",\r
+            {\r
+                "strict_errors",\r
+                strict_errors,\r
+                METH_O,\r
+                PyDoc_STR("Implements the 'strict' error handling, which "\r
+                          "raises a UnicodeError on coding errors.")\r
+            }\r
+        },\r
+#ifdef Py_USING_UNICODE\r
+        {\r
+            "ignore",\r
+            {\r
+                "ignore_errors",\r
+                ignore_errors,\r
+                METH_O,\r
+                PyDoc_STR("Implements the 'ignore' error handling, which "\r
+                          "ignores malformed data and continues.")\r
+            }\r
+        },\r
+        {\r
+            "replace",\r
+            {\r
+                "replace_errors",\r
+                replace_errors,\r
+                METH_O,\r
+                PyDoc_STR("Implements the 'replace' error handling, which "\r
+                          "replaces malformed data with a replacement marker.")\r
+            }\r
+        },\r
+        {\r
+            "xmlcharrefreplace",\r
+            {\r
+                "xmlcharrefreplace_errors",\r
+                xmlcharrefreplace_errors,\r
+                METH_O,\r
+                PyDoc_STR("Implements the 'xmlcharrefreplace' error handling, "\r
+                          "which replaces an unencodable character with the "\r
+                          "appropriate XML character reference.")\r
+            }\r
+        },\r
+        {\r
+            "backslashreplace",\r
+            {\r
+                "backslashreplace_errors",\r
+                backslashreplace_errors,\r
+                METH_O,\r
+                PyDoc_STR("Implements the 'backslashreplace' error handling, "\r
+                          "which replaces an unencodable character with a "\r
+                          "backslashed escape sequence.")\r
+            }\r
+        }\r
+#endif\r
+    };\r
+\r
+    PyInterpreterState *interp = PyThreadState_GET()->interp;\r
+    PyObject *mod;\r
+    unsigned i;\r
+\r
+    if (interp->codec_search_path != NULL)\r
+        return 0;\r
+\r
+    interp->codec_search_path = PyList_New(0);\r
+    interp->codec_search_cache = PyDict_New();\r
+    interp->codec_error_registry = PyDict_New();\r
+\r
+    if (interp->codec_error_registry) {\r
+        for (i = 0; i < sizeof(methods)/sizeof(methods[0]); ++i) {\r
+            PyObject *func = PyCFunction_New(&methods[i].def, NULL);\r
+            int res;\r
+            if (!func)\r
+                Py_FatalError("can't initialize codec error registry");\r
+            res = PyCodec_RegisterError(methods[i].name, func);\r
+            Py_DECREF(func);\r
+            if (res)\r
+                Py_FatalError("can't initialize codec error registry");\r
+        }\r
+    }\r
+\r
+    if (interp->codec_search_path == NULL ||\r
+        interp->codec_search_cache == NULL ||\r
+        interp->codec_error_registry == NULL)\r
+        Py_FatalError("can't initialize codec registry");\r
+\r
+    mod = PyImport_ImportModuleLevel("encodings", NULL, NULL, NULL, 0);\r
+    if (mod == NULL) {\r
+        if (PyErr_ExceptionMatches(PyExc_ImportError)) {\r
+            /* Ignore ImportErrors... this is done so that\r
+               distributions can disable the encodings package. Note\r
+               that other errors are not masked, e.g. SystemErrors\r
+               raised to inform the user of an error in the Python\r
+               configuration are still reported back to the user. */\r
+            PyErr_Clear();\r
+            return 0;\r
+        }\r
+        return -1;\r
+    }\r
+    Py_DECREF(mod);\r
+    return 0;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/compile.c b/AppPkg/Applications/Python/Python-2.7.10/Python/compile.c
new file mode 100644 (file)
index 0000000..205f044
--- /dev/null
@@ -0,0 +1,4003 @@
+/*\r
+ * This file compiles an abstract syntax tree (AST) into Python bytecode.\r
+ *\r
+ * The primary entry point is PyAST_Compile(), which returns a\r
+ * PyCodeObject.  The compiler makes several passes to build the code\r
+ * object:\r
+ *   1. Checks for future statements.  See future.c\r
+ *   2. Builds a symbol table.  See symtable.c.\r
+ *   3. Generate code for basic blocks.  See compiler_mod() in this file.\r
+ *   4. Assemble the basic blocks into final code.  See assemble() in\r
+ *      this file.\r
+ *   5. Optimize the byte code (peephole optimizations).  See peephole.c\r
+ *\r
+ * Note that compiler_mod() suggests module, but the module ast type\r
+ * (mod_ty) has cases for expressions and interactive statements.\r
+ *\r
+ * CAUTION: The VISIT_* macros abort the current function when they\r
+ * encounter a problem. So don't invoke them when there is memory\r
+ * which needs to be released. Code blocks are OK, as the compiler\r
+ * structure takes care of releasing those.  Use the arena to manage\r
+ * objects.\r
+ */\r
+\r
+#include "Python.h"\r
+\r
+#include "Python-ast.h"\r
+#include "node.h"\r
+#include "pyarena.h"\r
+#include "ast.h"\r
+#include "code.h"\r
+#include "compile.h"\r
+#include "symtable.h"\r
+#include "opcode.h"\r
+\r
+int Py_OptimizeFlag = 0;\r
+\r
+#define DEFAULT_BLOCK_SIZE 16\r
+#define DEFAULT_BLOCKS 8\r
+#define DEFAULT_CODE_SIZE 128\r
+#define DEFAULT_LNOTAB_SIZE 16\r
+\r
+#define COMP_GENEXP   0\r
+#define COMP_SETCOMP  1\r
+#define COMP_DICTCOMP 2\r
+\r
+struct instr {\r
+    unsigned i_jabs : 1;\r
+    unsigned i_jrel : 1;\r
+    unsigned i_hasarg : 1;\r
+    unsigned char i_opcode;\r
+    int i_oparg;\r
+    struct basicblock_ *i_target; /* target block (if jump instruction) */\r
+    int i_lineno;\r
+};\r
+\r
+typedef struct basicblock_ {\r
+    /* Each basicblock in a compilation unit is linked via b_list in the\r
+       reverse order that the block are allocated.  b_list points to the next\r
+       block, not to be confused with b_next, which is next by control flow. */\r
+    struct basicblock_ *b_list;\r
+    /* number of instructions used */\r
+    int b_iused;\r
+    /* length of instruction array (b_instr) */\r
+    int b_ialloc;\r
+    /* pointer to an array of instructions, initially NULL */\r
+    struct instr *b_instr;\r
+    /* If b_next is non-NULL, it is a pointer to the next\r
+       block reached by normal control flow. */\r
+    struct basicblock_ *b_next;\r
+    /* b_seen is used to perform a DFS of basicblocks. */\r
+    unsigned b_seen : 1;\r
+    /* b_return is true if a RETURN_VALUE opcode is inserted. */\r
+    unsigned b_return : 1;\r
+    /* depth of stack upon entry of block, computed by stackdepth() */\r
+    int b_startdepth;\r
+    /* instruction offset for block, computed by assemble_jump_offsets() */\r
+    int b_offset;\r
+} basicblock;\r
+\r
+/* fblockinfo tracks the current frame block.\r
+\r
+A frame block is used to handle loops, try/except, and try/finally.\r
+It's called a frame block to distinguish it from a basic block in the\r
+compiler IR.\r
+*/\r
+\r
+enum fblocktype { LOOP, EXCEPT, FINALLY_TRY, FINALLY_END };\r
+\r
+struct fblockinfo {\r
+    enum fblocktype fb_type;\r
+    basicblock *fb_block;\r
+};\r
+\r
+/* The following items change on entry and exit of code blocks.\r
+   They must be saved and restored when returning to a block.\r
+*/\r
+struct compiler_unit {\r
+    PySTEntryObject *u_ste;\r
+\r
+    PyObject *u_name;\r
+    /* The following fields are dicts that map objects to\r
+       the index of them in co_XXX.      The index is used as\r
+       the argument for opcodes that refer to those collections.\r
+    */\r
+    PyObject *u_consts;    /* all constants */\r
+    PyObject *u_names;     /* all names */\r
+    PyObject *u_varnames;  /* local variables */\r
+    PyObject *u_cellvars;  /* cell variables */\r
+    PyObject *u_freevars;  /* free variables */\r
+\r
+    PyObject *u_private;        /* for private name mangling */\r
+\r
+    int u_argcount;        /* number of arguments for block */\r
+    /* Pointer to the most recently allocated block.  By following b_list\r
+       members, you can reach all early allocated blocks. */\r
+    basicblock *u_blocks;\r
+    basicblock *u_curblock; /* pointer to current block */\r
+\r
+    int u_nfblocks;\r
+    struct fblockinfo u_fblock[CO_MAXBLOCKS];\r
+\r
+    int u_firstlineno; /* the first lineno of the block */\r
+    int u_lineno;          /* the lineno for the current stmt */\r
+    bool u_lineno_set; /* boolean to indicate whether instr\r
+                          has been generated with current lineno */\r
+};\r
+\r
+/* This struct captures the global state of a compilation.\r
+\r
+The u pointer points to the current compilation unit, while units\r
+for enclosing blocks are stored in c_stack.     The u and c_stack are\r
+managed by compiler_enter_scope() and compiler_exit_scope().\r
+*/\r
+\r
+struct compiler {\r
+    const char *c_filename;\r
+    struct symtable *c_st;\r
+    PyFutureFeatures *c_future; /* pointer to module's __future__ */\r
+    PyCompilerFlags *c_flags;\r
+\r
+    int c_interactive;           /* true if in interactive mode */\r
+    int c_nestlevel;\r
+\r
+    struct compiler_unit *u; /* compiler state for current block */\r
+    PyObject *c_stack;           /* Python list holding compiler_unit ptrs */\r
+    PyArena *c_arena;            /* pointer to memory allocation arena */\r
+};\r
+\r
+static int compiler_enter_scope(struct compiler *, identifier, void *, int);\r
+static void compiler_free(struct compiler *);\r
+static basicblock *compiler_new_block(struct compiler *);\r
+static int compiler_next_instr(struct compiler *, basicblock *);\r
+static int compiler_addop(struct compiler *, int);\r
+static int compiler_addop_o(struct compiler *, int, PyObject *, PyObject *);\r
+static int compiler_addop_i(struct compiler *, int, int);\r
+static int compiler_addop_j(struct compiler *, int, basicblock *, int);\r
+static basicblock *compiler_use_new_block(struct compiler *);\r
+static int compiler_error(struct compiler *, const char *);\r
+static int compiler_nameop(struct compiler *, identifier, expr_context_ty);\r
+\r
+static PyCodeObject *compiler_mod(struct compiler *, mod_ty);\r
+static int compiler_visit_stmt(struct compiler *, stmt_ty);\r
+static int compiler_visit_keyword(struct compiler *, keyword_ty);\r
+static int compiler_visit_expr(struct compiler *, expr_ty);\r
+static int compiler_augassign(struct compiler *, stmt_ty);\r
+static int compiler_visit_slice(struct compiler *, slice_ty,\r
+                                expr_context_ty);\r
+\r
+static int compiler_push_fblock(struct compiler *, enum fblocktype,\r
+                                basicblock *);\r
+static void compiler_pop_fblock(struct compiler *, enum fblocktype,\r
+                                basicblock *);\r
+/* Returns true if there is a loop on the fblock stack. */\r
+static int compiler_in_loop(struct compiler *);\r
+\r
+static int inplace_binop(struct compiler *, operator_ty);\r
+static int expr_constant(expr_ty e);\r
+\r
+static int compiler_with(struct compiler *, stmt_ty);\r
+\r
+static PyCodeObject *assemble(struct compiler *, int addNone);\r
+static PyObject *__doc__;\r
+\r
+#define COMPILER_CAPSULE_NAME_COMPILER_UNIT "compile.c compiler unit"\r
+\r
+PyObject *\r
+_Py_Mangle(PyObject *privateobj, PyObject *ident)\r
+{\r
+    /* Name mangling: __private becomes _classname__private.\r
+       This is independent from how the name is used. */\r
+    const char *p, *name = PyString_AsString(ident);\r
+    char *buffer;\r
+    size_t nlen, plen;\r
+    if (privateobj == NULL || !PyString_Check(privateobj) ||\r
+        name == NULL || name[0] != '_' || name[1] != '_') {\r
+        Py_INCREF(ident);\r
+        return ident;\r
+    }\r
+    p = PyString_AsString(privateobj);\r
+    nlen = strlen(name);\r
+    /* Don't mangle __id__ or names with dots.\r
+\r
+       The only time a name with a dot can occur is when\r
+       we are compiling an import statement that has a\r
+       package name.\r
+\r
+       TODO(jhylton): Decide whether we want to support\r
+       mangling of the module name, e.g. __M.X.\r
+    */\r
+    if ((name[nlen-1] == '_' && name[nlen-2] == '_')\r
+        || strchr(name, '.')) {\r
+        Py_INCREF(ident);\r
+        return ident; /* Don't mangle __whatever__ */\r
+    }\r
+    /* Strip leading underscores from class name */\r
+    while (*p == '_')\r
+        p++;\r
+    if (*p == '\0') {\r
+        Py_INCREF(ident);\r
+        return ident; /* Don't mangle if class is just underscores */\r
+    }\r
+    plen = strlen(p);\r
+\r
+    if (plen + nlen >= PY_SSIZE_T_MAX - 1) {\r
+        PyErr_SetString(PyExc_OverflowError,\r
+                        "private identifier too large to be mangled");\r
+        return NULL;\r
+    }\r
+\r
+    ident = PyString_FromStringAndSize(NULL, 1 + nlen + plen);\r
+    if (!ident)\r
+        return 0;\r
+    /* ident = "_" + p[:plen] + name # i.e. 1+plen+nlen bytes */\r
+    buffer = PyString_AS_STRING(ident);\r
+    buffer[0] = '_';\r
+    strncpy(buffer+1, p, plen);\r
+    strcpy(buffer+1+plen, name);\r
+    return ident;\r
+}\r
+\r
+static int\r
+compiler_init(struct compiler *c)\r
+{\r
+    memset(c, 0, sizeof(struct compiler));\r
+\r
+    c->c_stack = PyList_New(0);\r
+    if (!c->c_stack)\r
+        return 0;\r
+\r
+    return 1;\r
+}\r
+\r
+PyCodeObject *\r
+PyAST_Compile(mod_ty mod, const char *filename, PyCompilerFlags *flags,\r
+              PyArena *arena)\r
+{\r
+    struct compiler c;\r
+    PyCodeObject *co = NULL;\r
+    PyCompilerFlags local_flags;\r
+    int merged;\r
+\r
+    if (!__doc__) {\r
+        __doc__ = PyString_InternFromString("__doc__");\r
+        if (!__doc__)\r
+            return NULL;\r
+    }\r
+\r
+    if (!compiler_init(&c))\r
+        return NULL;\r
+    c.c_filename = filename;\r
+    c.c_arena = arena;\r
+    c.c_future = PyFuture_FromAST(mod, filename);\r
+    if (c.c_future == NULL)\r
+        goto finally;\r
+    if (!flags) {\r
+        local_flags.cf_flags = 0;\r
+        flags = &local_flags;\r
+    }\r
+    merged = c.c_future->ff_features | flags->cf_flags;\r
+    c.c_future->ff_features = merged;\r
+    flags->cf_flags = merged;\r
+    c.c_flags = flags;\r
+    c.c_nestlevel = 0;\r
+\r
+    c.c_st = PySymtable_Build(mod, filename, c.c_future);\r
+    if (c.c_st == NULL) {\r
+        if (!PyErr_Occurred())\r
+            PyErr_SetString(PyExc_SystemError, "no symtable");\r
+        goto finally;\r
+    }\r
+\r
+    co = compiler_mod(&c, mod);\r
+\r
+ finally:\r
+    compiler_free(&c);\r
+    assert(co || PyErr_Occurred());\r
+    return co;\r
+}\r
+\r
+PyCodeObject *\r
+PyNode_Compile(struct _node *n, const char *filename)\r
+{\r
+    PyCodeObject *co = NULL;\r
+    mod_ty mod;\r
+    PyArena *arena = PyArena_New();\r
+    if (!arena)\r
+        return NULL;\r
+    mod = PyAST_FromNode(n, NULL, filename, arena);\r
+    if (mod)\r
+        co = PyAST_Compile(mod, filename, NULL, arena);\r
+    PyArena_Free(arena);\r
+    return co;\r
+}\r
+\r
+static void\r
+compiler_free(struct compiler *c)\r
+{\r
+    if (c->c_st)\r
+        PySymtable_Free(c->c_st);\r
+    if (c->c_future)\r
+        PyObject_Free(c->c_future);\r
+    Py_DECREF(c->c_stack);\r
+}\r
+\r
+static PyObject *\r
+list2dict(PyObject *list)\r
+{\r
+    Py_ssize_t i, n;\r
+    PyObject *v, *k;\r
+    PyObject *dict = PyDict_New();\r
+    if (!dict) return NULL;\r
+\r
+    n = PyList_Size(list);\r
+    for (i = 0; i < n; i++) {\r
+        v = PyInt_FromLong(i);\r
+        if (!v) {\r
+            Py_DECREF(dict);\r
+            return NULL;\r
+        }\r
+        k = PyList_GET_ITEM(list, i);\r
+        k = PyTuple_Pack(2, k, k->ob_type);\r
+        if (k == NULL || PyDict_SetItem(dict, k, v) < 0) {\r
+            Py_XDECREF(k);\r
+            Py_DECREF(v);\r
+            Py_DECREF(dict);\r
+            return NULL;\r
+        }\r
+        Py_DECREF(k);\r
+        Py_DECREF(v);\r
+    }\r
+    return dict;\r
+}\r
+\r
+/* Return new dict containing names from src that match scope(s).\r
+\r
+src is a symbol table dictionary.  If the scope of a name matches\r
+either scope_type or flag is set, insert it into the new dict.  The\r
+values are integers, starting at offset and increasing by one for\r
+each key.\r
+*/\r
+\r
+static PyObject *\r
+dictbytype(PyObject *src, int scope_type, int flag, int offset)\r
+{\r
+    Py_ssize_t i = offset, scope, num_keys, key_i;\r
+    PyObject *k, *v, *dest = PyDict_New();\r
+    PyObject *sorted_keys;\r
+\r
+    assert(offset >= 0);\r
+    if (dest == NULL)\r
+        return NULL;\r
+\r
+    /* Sort the keys so that we have a deterministic order on the indexes\r
+       saved in the returned dictionary.  These indexes are used as indexes\r
+       into the free and cell var storage.  Therefore if they aren't\r
+       deterministic, then the generated bytecode is not deterministic.\r
+    */\r
+    sorted_keys = PyDict_Keys(src);\r
+    if (sorted_keys == NULL)\r
+        return NULL;\r
+    if (PyList_Sort(sorted_keys) != 0) {\r
+        Py_DECREF(sorted_keys);\r
+        return NULL;\r
+    }\r
+    num_keys = PyList_GET_SIZE(sorted_keys);\r
+\r
+    for (key_i = 0; key_i < num_keys; key_i++) {\r
+        k = PyList_GET_ITEM(sorted_keys, key_i);\r
+        v = PyDict_GetItem(src, k);\r
+        /* XXX this should probably be a macro in symtable.h */\r
+        assert(PyInt_Check(v));\r
+        scope = (PyInt_AS_LONG(v) >> SCOPE_OFF) & SCOPE_MASK;\r
+\r
+        if (scope == scope_type || PyInt_AS_LONG(v) & flag) {\r
+            PyObject *tuple, *item = PyInt_FromLong(i);\r
+            if (item == NULL) {\r
+                Py_DECREF(sorted_keys);\r
+                Py_DECREF(dest);\r
+                return NULL;\r
+            }\r
+            i++;\r
+            tuple = PyTuple_Pack(2, k, k->ob_type);\r
+            if (!tuple || PyDict_SetItem(dest, tuple, item) < 0) {\r
+                Py_DECREF(sorted_keys);\r
+                Py_DECREF(item);\r
+                Py_DECREF(dest);\r
+                Py_XDECREF(tuple);\r
+                return NULL;\r
+            }\r
+            Py_DECREF(item);\r
+            Py_DECREF(tuple);\r
+        }\r
+    }\r
+    Py_DECREF(sorted_keys);\r
+    return dest;\r
+}\r
+\r
+static void\r
+compiler_unit_check(struct compiler_unit *u)\r
+{\r
+    basicblock *block;\r
+    for (block = u->u_blocks; block != NULL; block = block->b_list) {\r
+        assert((void *)block != (void *)0xcbcbcbcb);\r
+        assert((void *)block != (void *)0xfbfbfbfb);\r
+        assert((void *)block != (void *)0xdbdbdbdb);\r
+        if (block->b_instr != NULL) {\r
+            assert(block->b_ialloc > 0);\r
+            assert(block->b_iused > 0);\r
+            assert(block->b_ialloc >= block->b_iused);\r
+        }\r
+        else {\r
+            assert (block->b_iused == 0);\r
+            assert (block->b_ialloc == 0);\r
+        }\r
+    }\r
+}\r
+\r
+static void\r
+compiler_unit_free(struct compiler_unit *u)\r
+{\r
+    basicblock *b, *next;\r
+\r
+    compiler_unit_check(u);\r
+    b = u->u_blocks;\r
+    while (b != NULL) {\r
+        if (b->b_instr)\r
+            PyObject_Free((void *)b->b_instr);\r
+        next = b->b_list;\r
+        PyObject_Free((void *)b);\r
+        b = next;\r
+    }\r
+    Py_CLEAR(u->u_ste);\r
+    Py_CLEAR(u->u_name);\r
+    Py_CLEAR(u->u_consts);\r
+    Py_CLEAR(u->u_names);\r
+    Py_CLEAR(u->u_varnames);\r
+    Py_CLEAR(u->u_freevars);\r
+    Py_CLEAR(u->u_cellvars);\r
+    Py_CLEAR(u->u_private);\r
+    PyObject_Free(u);\r
+}\r
+\r
+static int\r
+compiler_enter_scope(struct compiler *c, identifier name, void *key,\r
+                     int lineno)\r
+{\r
+    struct compiler_unit *u;\r
+\r
+    u = (struct compiler_unit *)PyObject_Malloc(sizeof(\r
+                                            struct compiler_unit));\r
+    if (!u) {\r
+        PyErr_NoMemory();\r
+        return 0;\r
+    }\r
+    memset(u, 0, sizeof(struct compiler_unit));\r
+    u->u_argcount = 0;\r
+    u->u_ste = PySymtable_Lookup(c->c_st, key);\r
+    if (!u->u_ste) {\r
+        compiler_unit_free(u);\r
+        return 0;\r
+    }\r
+    Py_INCREF(name);\r
+    u->u_name = name;\r
+    u->u_varnames = list2dict(u->u_ste->ste_varnames);\r
+    u->u_cellvars = dictbytype(u->u_ste->ste_symbols, CELL, 0, 0);\r
+    if (!u->u_varnames || !u->u_cellvars) {\r
+        compiler_unit_free(u);\r
+        return 0;\r
+    }\r
+\r
+    u->u_freevars = dictbytype(u->u_ste->ste_symbols, FREE, DEF_FREE_CLASS,\r
+                               PyDict_Size(u->u_cellvars));\r
+    if (!u->u_freevars) {\r
+        compiler_unit_free(u);\r
+        return 0;\r
+    }\r
+\r
+    u->u_blocks = NULL;\r
+    u->u_nfblocks = 0;\r
+    u->u_firstlineno = lineno;\r
+    u->u_lineno = 0;\r
+    u->u_lineno_set = false;\r
+    u->u_consts = PyDict_New();\r
+    if (!u->u_consts) {\r
+        compiler_unit_free(u);\r
+        return 0;\r
+    }\r
+    u->u_names = PyDict_New();\r
+    if (!u->u_names) {\r
+        compiler_unit_free(u);\r
+        return 0;\r
+    }\r
+\r
+    u->u_private = NULL;\r
+\r
+    /* Push the old compiler_unit on the stack. */\r
+    if (c->u) {\r
+        PyObject *capsule = PyCapsule_New(c->u, COMPILER_CAPSULE_NAME_COMPILER_UNIT, NULL);\r
+        if (!capsule || PyList_Append(c->c_stack, capsule) < 0) {\r
+            Py_XDECREF(capsule);\r
+            compiler_unit_free(u);\r
+            return 0;\r
+        }\r
+        Py_DECREF(capsule);\r
+        u->u_private = c->u->u_private;\r
+        Py_XINCREF(u->u_private);\r
+    }\r
+    c->u = u;\r
+\r
+    c->c_nestlevel++;\r
+    if (compiler_use_new_block(c) == NULL)\r
+        return 0;\r
+\r
+    return 1;\r
+}\r
+\r
+static void\r
+compiler_exit_scope(struct compiler *c)\r
+{\r
+    int n;\r
+    PyObject *capsule;\r
+\r
+    c->c_nestlevel--;\r
+    compiler_unit_free(c->u);\r
+    /* Restore c->u to the parent unit. */\r
+    n = PyList_GET_SIZE(c->c_stack) - 1;\r
+    if (n >= 0) {\r
+        capsule = PyList_GET_ITEM(c->c_stack, n);\r
+        c->u = (struct compiler_unit *)PyCapsule_GetPointer(capsule, COMPILER_CAPSULE_NAME_COMPILER_UNIT);\r
+        assert(c->u);\r
+        /* we are deleting from a list so this really shouldn't fail */\r
+        if (PySequence_DelItem(c->c_stack, n) < 0)\r
+            Py_FatalError("compiler_exit_scope()");\r
+        compiler_unit_check(c->u);\r
+    }\r
+    else\r
+        c->u = NULL;\r
+\r
+}\r
+\r
+/* Allocate a new block and return a pointer to it.\r
+   Returns NULL on error.\r
+*/\r
+\r
+static basicblock *\r
+compiler_new_block(struct compiler *c)\r
+{\r
+    basicblock *b;\r
+    struct compiler_unit *u;\r
+\r
+    u = c->u;\r
+    b = (basicblock *)PyObject_Malloc(sizeof(basicblock));\r
+    if (b == NULL) {\r
+        PyErr_NoMemory();\r
+        return NULL;\r
+    }\r
+    memset((void *)b, 0, sizeof(basicblock));\r
+    /* Extend the singly linked list of blocks with new block. */\r
+    b->b_list = u->u_blocks;\r
+    u->u_blocks = b;\r
+    return b;\r
+}\r
+\r
+static basicblock *\r
+compiler_use_new_block(struct compiler *c)\r
+{\r
+    basicblock *block = compiler_new_block(c);\r
+    if (block == NULL)\r
+        return NULL;\r
+    c->u->u_curblock = block;\r
+    return block;\r
+}\r
+\r
+static basicblock *\r
+compiler_next_block(struct compiler *c)\r
+{\r
+    basicblock *block = compiler_new_block(c);\r
+    if (block == NULL)\r
+        return NULL;\r
+    c->u->u_curblock->b_next = block;\r
+    c->u->u_curblock = block;\r
+    return block;\r
+}\r
+\r
+static basicblock *\r
+compiler_use_next_block(struct compiler *c, basicblock *block)\r
+{\r
+    assert(block != NULL);\r
+    c->u->u_curblock->b_next = block;\r
+    c->u->u_curblock = block;\r
+    return block;\r
+}\r
+\r
+/* Returns the offset of the next instruction in the current block's\r
+   b_instr array.  Resizes the b_instr as necessary.\r
+   Returns -1 on failure.\r
+*/\r
+\r
+static int\r
+compiler_next_instr(struct compiler *c, basicblock *b)\r
+{\r
+    assert(b != NULL);\r
+    if (b->b_instr == NULL) {\r
+        b->b_instr = (struct instr *)PyObject_Malloc(\r
+                         sizeof(struct instr) * DEFAULT_BLOCK_SIZE);\r
+        if (b->b_instr == NULL) {\r
+            PyErr_NoMemory();\r
+            return -1;\r
+        }\r
+        b->b_ialloc = DEFAULT_BLOCK_SIZE;\r
+        memset((char *)b->b_instr, 0,\r
+               sizeof(struct instr) * DEFAULT_BLOCK_SIZE);\r
+    }\r
+    else if (b->b_iused == b->b_ialloc) {\r
+        struct instr *tmp;\r
+        size_t oldsize, newsize;\r
+        oldsize = b->b_ialloc * sizeof(struct instr);\r
+        newsize = oldsize << 1;\r
+\r
+        if (oldsize > (PY_SIZE_MAX >> 1)) {\r
+            PyErr_NoMemory();\r
+            return -1;\r
+        }\r
+\r
+        if (newsize == 0) {\r
+            PyErr_NoMemory();\r
+            return -1;\r
+        }\r
+        b->b_ialloc <<= 1;\r
+        tmp = (struct instr *)PyObject_Realloc(\r
+                                        (void *)b->b_instr, newsize);\r
+        if (tmp == NULL) {\r
+            PyErr_NoMemory();\r
+            return -1;\r
+        }\r
+        b->b_instr = tmp;\r
+        memset((char *)b->b_instr + oldsize, 0, newsize - oldsize);\r
+    }\r
+    return b->b_iused++;\r
+}\r
+\r
+/* Set the i_lineno member of the instruction at offset off if the\r
+   line number for the current expression/statement has not\r
+   already been set.  If it has been set, the call has no effect.\r
+\r
+   The line number is reset in the following cases:\r
+   - when entering a new scope\r
+   - on each statement\r
+   - on each expression that start a new line\r
+   - before the "except" clause\r
+   - before the "for" and "while" expressions\r
+*/\r
+\r
+static void\r
+compiler_set_lineno(struct compiler *c, int off)\r
+{\r
+    basicblock *b;\r
+    if (c->u->u_lineno_set)\r
+        return;\r
+    c->u->u_lineno_set = true;\r
+    b = c->u->u_curblock;\r
+    b->b_instr[off].i_lineno = c->u->u_lineno;\r
+}\r
+\r
+static int\r
+opcode_stack_effect(int opcode, int oparg)\r
+{\r
+    switch (opcode) {\r
+        case POP_TOP:\r
+            return -1;\r
+        case ROT_TWO:\r
+        case ROT_THREE:\r
+            return 0;\r
+        case DUP_TOP:\r
+            return 1;\r
+        case ROT_FOUR:\r
+            return 0;\r
+\r
+        case UNARY_POSITIVE:\r
+        case UNARY_NEGATIVE:\r
+        case UNARY_NOT:\r
+        case UNARY_CONVERT:\r
+        case UNARY_INVERT:\r
+            return 0;\r
+\r
+        case SET_ADD:\r
+        case LIST_APPEND:\r
+            return -1;\r
+\r
+        case MAP_ADD:\r
+            return -2;\r
+\r
+        case BINARY_POWER:\r
+        case BINARY_MULTIPLY:\r
+        case BINARY_DIVIDE:\r
+        case BINARY_MODULO:\r
+        case BINARY_ADD:\r
+        case BINARY_SUBTRACT:\r
+        case BINARY_SUBSCR:\r
+        case BINARY_FLOOR_DIVIDE:\r
+        case BINARY_TRUE_DIVIDE:\r
+            return -1;\r
+        case INPLACE_FLOOR_DIVIDE:\r
+        case INPLACE_TRUE_DIVIDE:\r
+            return -1;\r
+\r
+        case SLICE+0:\r
+            return 0;\r
+        case SLICE+1:\r
+            return -1;\r
+        case SLICE+2:\r
+            return -1;\r
+        case SLICE+3:\r
+            return -2;\r
+\r
+        case STORE_SLICE+0:\r
+            return -2;\r
+        case STORE_SLICE+1:\r
+            return -3;\r
+        case STORE_SLICE+2:\r
+            return -3;\r
+        case STORE_SLICE+3:\r
+            return -4;\r
+\r
+        case DELETE_SLICE+0:\r
+            return -1;\r
+        case DELETE_SLICE+1:\r
+            return -2;\r
+        case DELETE_SLICE+2:\r
+            return -2;\r
+        case DELETE_SLICE+3:\r
+            return -3;\r
+\r
+        case INPLACE_ADD:\r
+        case INPLACE_SUBTRACT:\r
+        case INPLACE_MULTIPLY:\r
+        case INPLACE_DIVIDE:\r
+        case INPLACE_MODULO:\r
+            return -1;\r
+        case STORE_SUBSCR:\r
+            return -3;\r
+        case STORE_MAP:\r
+            return -2;\r
+        case DELETE_SUBSCR:\r
+            return -2;\r
+\r
+        case BINARY_LSHIFT:\r
+        case BINARY_RSHIFT:\r
+        case BINARY_AND:\r
+        case BINARY_XOR:\r
+        case BINARY_OR:\r
+            return -1;\r
+        case INPLACE_POWER:\r
+            return -1;\r
+        case GET_ITER:\r
+            return 0;\r
+\r
+        case PRINT_EXPR:\r
+            return -1;\r
+        case PRINT_ITEM:\r
+            return -1;\r
+        case PRINT_NEWLINE:\r
+            return 0;\r
+        case PRINT_ITEM_TO:\r
+            return -2;\r
+        case PRINT_NEWLINE_TO:\r
+            return -1;\r
+        case INPLACE_LSHIFT:\r
+        case INPLACE_RSHIFT:\r
+        case INPLACE_AND:\r
+        case INPLACE_XOR:\r
+        case INPLACE_OR:\r
+            return -1;\r
+        case BREAK_LOOP:\r
+            return 0;\r
+        case SETUP_WITH:\r
+            return 4;\r
+        case WITH_CLEANUP:\r
+            return -1; /* XXX Sometimes more */\r
+        case LOAD_LOCALS:\r
+            return 1;\r
+        case RETURN_VALUE:\r
+            return -1;\r
+        case IMPORT_STAR:\r
+            return -1;\r
+        case EXEC_STMT:\r
+            return -3;\r
+        case YIELD_VALUE:\r
+            return 0;\r
+\r
+        case POP_BLOCK:\r
+            return 0;\r
+        case END_FINALLY:\r
+            return -3; /* or -1 or -2 if no exception occurred or\r
+                          return/break/continue */\r
+        case BUILD_CLASS:\r
+            return -2;\r
+\r
+        case STORE_NAME:\r
+            return -1;\r
+        case DELETE_NAME:\r
+            return 0;\r
+        case UNPACK_SEQUENCE:\r
+            return oparg-1;\r
+        case FOR_ITER:\r
+            return 1; /* or -1, at end of iterator */\r
+\r
+        case STORE_ATTR:\r
+            return -2;\r
+        case DELETE_ATTR:\r
+            return -1;\r
+        case STORE_GLOBAL:\r
+            return -1;\r
+        case DELETE_GLOBAL:\r
+            return 0;\r
+        case DUP_TOPX:\r
+            return oparg;\r
+        case LOAD_CONST:\r
+            return 1;\r
+        case LOAD_NAME:\r
+            return 1;\r
+        case BUILD_TUPLE:\r
+        case BUILD_LIST:\r
+        case BUILD_SET:\r
+            return 1-oparg;\r
+        case BUILD_MAP:\r
+            return 1;\r
+        case LOAD_ATTR:\r
+            return 0;\r
+        case COMPARE_OP:\r
+            return -1;\r
+        case IMPORT_NAME:\r
+            return -1;\r
+        case IMPORT_FROM:\r
+            return 1;\r
+\r
+        case JUMP_FORWARD:\r
+        case JUMP_IF_TRUE_OR_POP:  /* -1 if jump not taken */\r
+        case JUMP_IF_FALSE_OR_POP:  /*  "" */\r
+        case JUMP_ABSOLUTE:\r
+            return 0;\r
+\r
+        case POP_JUMP_IF_FALSE:\r
+        case POP_JUMP_IF_TRUE:\r
+            return -1;\r
+\r
+        case LOAD_GLOBAL:\r
+            return 1;\r
+\r
+        case CONTINUE_LOOP:\r
+            return 0;\r
+        case SETUP_LOOP:\r
+        case SETUP_EXCEPT:\r
+        case SETUP_FINALLY:\r
+            return 0;\r
+\r
+        case LOAD_FAST:\r
+            return 1;\r
+        case STORE_FAST:\r
+            return -1;\r
+        case DELETE_FAST:\r
+            return 0;\r
+\r
+        case RAISE_VARARGS:\r
+            return -oparg;\r
+#define NARGS(o) (((o) % 256) + 2*((o) / 256))\r
+        case CALL_FUNCTION:\r
+            return -NARGS(oparg);\r
+        case CALL_FUNCTION_VAR:\r
+        case CALL_FUNCTION_KW:\r
+            return -NARGS(oparg)-1;\r
+        case CALL_FUNCTION_VAR_KW:\r
+            return -NARGS(oparg)-2;\r
+#undef NARGS\r
+        case MAKE_FUNCTION:\r
+            return -oparg;\r
+        case BUILD_SLICE:\r
+            if (oparg == 3)\r
+                return -2;\r
+            else\r
+                return -1;\r
+\r
+        case MAKE_CLOSURE:\r
+            return -oparg-1;\r
+        case LOAD_CLOSURE:\r
+            return 1;\r
+        case LOAD_DEREF:\r
+            return 1;\r
+        case STORE_DEREF:\r
+            return -1;\r
+        default:\r
+            fprintf(stderr, "opcode = %d\n", opcode);\r
+            Py_FatalError("opcode_stack_effect()");\r
+\r
+    }\r
+    return 0; /* not reachable */\r
+}\r
+\r
+/* Add an opcode with no argument.\r
+   Returns 0 on failure, 1 on success.\r
+*/\r
+\r
+static int\r
+compiler_addop(struct compiler *c, int opcode)\r
+{\r
+    basicblock *b;\r
+    struct instr *i;\r
+    int off;\r
+    off = compiler_next_instr(c, c->u->u_curblock);\r
+    if (off < 0)\r
+        return 0;\r
+    b = c->u->u_curblock;\r
+    i = &b->b_instr[off];\r
+    i->i_opcode = opcode;\r
+    i->i_hasarg = 0;\r
+    if (opcode == RETURN_VALUE)\r
+        b->b_return = 1;\r
+    compiler_set_lineno(c, off);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_add_o(struct compiler *c, PyObject *dict, PyObject *o)\r
+{\r
+    PyObject *t, *v;\r
+    Py_ssize_t arg;\r
+    double d;\r
+\r
+    /* necessary to make sure types aren't coerced (e.g., int and long) */\r
+    /* _and_ to distinguish 0.0 from -0.0 e.g. on IEEE platforms */\r
+    if (PyFloat_Check(o)) {\r
+        d = PyFloat_AS_DOUBLE(o);\r
+        /* all we need is to make the tuple different in either the 0.0\r
+         * or -0.0 case from all others, just to avoid the "coercion".\r
+         */\r
+        if (d == 0.0 && copysign(1.0, d) < 0.0)\r
+            t = PyTuple_Pack(3, o, o->ob_type, Py_None);\r
+        else\r
+            t = PyTuple_Pack(2, o, o->ob_type);\r
+    }\r
+#ifndef WITHOUT_COMPLEX\r
+    else if (PyComplex_Check(o)) {\r
+        Py_complex z;\r
+        int real_negzero, imag_negzero;\r
+        /* For the complex case we must make complex(x, 0.)\r
+           different from complex(x, -0.) and complex(0., y)\r
+           different from complex(-0., y), for any x and y.\r
+           All four complex zeros must be distinguished.*/\r
+        z = PyComplex_AsCComplex(o);\r
+        real_negzero = z.real == 0.0 && copysign(1.0, z.real) < 0.0;\r
+        imag_negzero = z.imag == 0.0 && copysign(1.0, z.imag) < 0.0;\r
+        if (real_negzero && imag_negzero) {\r
+            t = PyTuple_Pack(5, o, o->ob_type,\r
+                             Py_None, Py_None, Py_None);\r
+        }\r
+        else if (imag_negzero) {\r
+            t = PyTuple_Pack(4, o, o->ob_type, Py_None, Py_None);\r
+        }\r
+        else if (real_negzero) {\r
+            t = PyTuple_Pack(3, o, o->ob_type, Py_None);\r
+        }\r
+        else {\r
+            t = PyTuple_Pack(2, o, o->ob_type);\r
+        }\r
+    }\r
+#endif /* WITHOUT_COMPLEX */\r
+    else {\r
+        t = PyTuple_Pack(2, o, o->ob_type);\r
+    }\r
+    if (t == NULL)\r
+        return -1;\r
+\r
+    v = PyDict_GetItem(dict, t);\r
+    if (!v) {\r
+        arg = PyDict_Size(dict);\r
+        v = PyInt_FromLong(arg);\r
+        if (!v) {\r
+            Py_DECREF(t);\r
+            return -1;\r
+        }\r
+        if (PyDict_SetItem(dict, t, v) < 0) {\r
+            Py_DECREF(t);\r
+            Py_DECREF(v);\r
+            return -1;\r
+        }\r
+        Py_DECREF(v);\r
+    }\r
+    else\r
+        arg = PyInt_AsLong(v);\r
+    Py_DECREF(t);\r
+    return arg;\r
+}\r
+\r
+static int\r
+compiler_addop_o(struct compiler *c, int opcode, PyObject *dict,\r
+                     PyObject *o)\r
+{\r
+    int arg = compiler_add_o(c, dict, o);\r
+    if (arg < 0)\r
+        return 0;\r
+    return compiler_addop_i(c, opcode, arg);\r
+}\r
+\r
+static int\r
+compiler_addop_name(struct compiler *c, int opcode, PyObject *dict,\r
+                    PyObject *o)\r
+{\r
+    int arg;\r
+    PyObject *mangled = _Py_Mangle(c->u->u_private, o);\r
+    if (!mangled)\r
+        return 0;\r
+    arg = compiler_add_o(c, dict, mangled);\r
+    Py_DECREF(mangled);\r
+    if (arg < 0)\r
+        return 0;\r
+    return compiler_addop_i(c, opcode, arg);\r
+}\r
+\r
+/* Add an opcode with an integer argument.\r
+   Returns 0 on failure, 1 on success.\r
+*/\r
+\r
+static int\r
+compiler_addop_i(struct compiler *c, int opcode, int oparg)\r
+{\r
+    struct instr *i;\r
+    int off;\r
+    off = compiler_next_instr(c, c->u->u_curblock);\r
+    if (off < 0)\r
+        return 0;\r
+    i = &c->u->u_curblock->b_instr[off];\r
+    i->i_opcode = opcode;\r
+    i->i_oparg = oparg;\r
+    i->i_hasarg = 1;\r
+    compiler_set_lineno(c, off);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_addop_j(struct compiler *c, int opcode, basicblock *b, int absolute)\r
+{\r
+    struct instr *i;\r
+    int off;\r
+\r
+    assert(b != NULL);\r
+    off = compiler_next_instr(c, c->u->u_curblock);\r
+    if (off < 0)\r
+        return 0;\r
+    i = &c->u->u_curblock->b_instr[off];\r
+    i->i_opcode = opcode;\r
+    i->i_target = b;\r
+    i->i_hasarg = 1;\r
+    if (absolute)\r
+        i->i_jabs = 1;\r
+    else\r
+        i->i_jrel = 1;\r
+    compiler_set_lineno(c, off);\r
+    return 1;\r
+}\r
+\r
+/* The distinction between NEW_BLOCK and NEXT_BLOCK is subtle.  (I'd\r
+   like to find better names.)  NEW_BLOCK() creates a new block and sets\r
+   it as the current block.  NEXT_BLOCK() also creates an implicit jump\r
+   from the current block to the new block.\r
+*/\r
+\r
+/* The returns inside these macros make it impossible to decref objects\r
+   created in the local function.  Local objects should use the arena.\r
+*/\r
+\r
+\r
+#define NEW_BLOCK(C) { \\r
+    if (compiler_use_new_block((C)) == NULL) \\r
+        return 0; \\r
+}\r
+\r
+#define NEXT_BLOCK(C) { \\r
+    if (compiler_next_block((C)) == NULL) \\r
+        return 0; \\r
+}\r
+\r
+#define ADDOP(C, OP) { \\r
+    if (!compiler_addop((C), (OP))) \\r
+        return 0; \\r
+}\r
+\r
+#define ADDOP_IN_SCOPE(C, OP) { \\r
+    if (!compiler_addop((C), (OP))) { \\r
+        compiler_exit_scope(c); \\r
+        return 0; \\r
+    } \\r
+}\r
+\r
+#define ADDOP_O(C, OP, O, TYPE) { \\r
+    if (!compiler_addop_o((C), (OP), (C)->u->u_ ## TYPE, (O))) \\r
+        return 0; \\r
+}\r
+\r
+#define ADDOP_NAME(C, OP, O, TYPE) { \\r
+    if (!compiler_addop_name((C), (OP), (C)->u->u_ ## TYPE, (O))) \\r
+        return 0; \\r
+}\r
+\r
+#define ADDOP_I(C, OP, O) { \\r
+    if (!compiler_addop_i((C), (OP), (O))) \\r
+        return 0; \\r
+}\r
+\r
+#define ADDOP_JABS(C, OP, O) { \\r
+    if (!compiler_addop_j((C), (OP), (O), 1)) \\r
+        return 0; \\r
+}\r
+\r
+#define ADDOP_JREL(C, OP, O) { \\r
+    if (!compiler_addop_j((C), (OP), (O), 0)) \\r
+        return 0; \\r
+}\r
+\r
+/* VISIT and VISIT_SEQ takes an ASDL type as their second argument.  They use\r
+   the ASDL name to synthesize the name of the C type and the visit function.\r
+*/\r
+\r
+#define VISIT(C, TYPE, V) {\\r
+    if (!compiler_visit_ ## TYPE((C), (V))) \\r
+        return 0; \\r
+}\r
+\r
+#define VISIT_IN_SCOPE(C, TYPE, V) {\\r
+    if (!compiler_visit_ ## TYPE((C), (V))) { \\r
+        compiler_exit_scope(c); \\r
+        return 0; \\r
+    } \\r
+}\r
+\r
+#define VISIT_SLICE(C, V, CTX) {\\r
+    if (!compiler_visit_slice((C), (V), (CTX))) \\r
+        return 0; \\r
+}\r
+\r
+#define VISIT_SEQ(C, TYPE, SEQ) { \\r
+    int _i; \\r
+    asdl_seq *seq = (SEQ); /* avoid variable capture */ \\r
+    for (_i = 0; _i < asdl_seq_LEN(seq); _i++) { \\r
+        TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \\r
+        if (!compiler_visit_ ## TYPE((C), elt)) \\r
+            return 0; \\r
+    } \\r
+}\r
+\r
+#define VISIT_SEQ_IN_SCOPE(C, TYPE, SEQ) { \\r
+    int _i; \\r
+    asdl_seq *seq = (SEQ); /* avoid variable capture */ \\r
+    for (_i = 0; _i < asdl_seq_LEN(seq); _i++) { \\r
+        TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, _i); \\r
+        if (!compiler_visit_ ## TYPE((C), elt)) { \\r
+            compiler_exit_scope(c); \\r
+            return 0; \\r
+        } \\r
+    } \\r
+}\r
+\r
+static int\r
+compiler_isdocstring(stmt_ty s)\r
+{\r
+    if (s->kind != Expr_kind)\r
+        return 0;\r
+    return s->v.Expr.value->kind == Str_kind;\r
+}\r
+\r
+/* Compile a sequence of statements, checking for a docstring. */\r
+\r
+static int\r
+compiler_body(struct compiler *c, asdl_seq *stmts)\r
+{\r
+    int i = 0;\r
+    stmt_ty st;\r
+\r
+    if (!asdl_seq_LEN(stmts))\r
+        return 1;\r
+    st = (stmt_ty)asdl_seq_GET(stmts, 0);\r
+    if (compiler_isdocstring(st) && Py_OptimizeFlag < 2) {\r
+        /* don't generate docstrings if -OO */\r
+        i = 1;\r
+        VISIT(c, expr, st->v.Expr.value);\r
+        if (!compiler_nameop(c, __doc__, Store))\r
+            return 0;\r
+    }\r
+    for (; i < asdl_seq_LEN(stmts); i++)\r
+        VISIT(c, stmt, (stmt_ty)asdl_seq_GET(stmts, i));\r
+    return 1;\r
+}\r
+\r
+static PyCodeObject *\r
+compiler_mod(struct compiler *c, mod_ty mod)\r
+{\r
+    PyCodeObject *co;\r
+    int addNone = 1;\r
+    static PyObject *module;\r
+    if (!module) {\r
+        module = PyString_InternFromString("<module>");\r
+        if (!module)\r
+            return NULL;\r
+    }\r
+    /* Use 0 for firstlineno initially, will fixup in assemble(). */\r
+    if (!compiler_enter_scope(c, module, mod, 0))\r
+        return NULL;\r
+    switch (mod->kind) {\r
+    case Module_kind:\r
+        if (!compiler_body(c, mod->v.Module.body)) {\r
+            compiler_exit_scope(c);\r
+            return 0;\r
+        }\r
+        break;\r
+    case Interactive_kind:\r
+        c->c_interactive = 1;\r
+        VISIT_SEQ_IN_SCOPE(c, stmt,\r
+                                mod->v.Interactive.body);\r
+        break;\r
+    case Expression_kind:\r
+        VISIT_IN_SCOPE(c, expr, mod->v.Expression.body);\r
+        addNone = 0;\r
+        break;\r
+    case Suite_kind:\r
+        PyErr_SetString(PyExc_SystemError,\r
+                        "suite should not be possible");\r
+        return 0;\r
+    default:\r
+        PyErr_Format(PyExc_SystemError,\r
+                     "module kind %d should not be possible",\r
+                     mod->kind);\r
+        return 0;\r
+    }\r
+    co = assemble(c, addNone);\r
+    compiler_exit_scope(c);\r
+    return co;\r
+}\r
+\r
+/* The test for LOCAL must come before the test for FREE in order to\r
+   handle classes where name is both local and free.  The local var is\r
+   a method and the free var is a free var referenced within a method.\r
+*/\r
+\r
+static int\r
+get_ref_type(struct compiler *c, PyObject *name)\r
+{\r
+    int scope = PyST_GetScope(c->u->u_ste, name);\r
+    if (scope == 0) {\r
+        char buf[350];\r
+        PyOS_snprintf(buf, sizeof(buf),\r
+                      "unknown scope for %.100s in %.100s(%s) in %s\n"\r
+                      "symbols: %s\nlocals: %s\nglobals: %s",\r
+                      PyString_AS_STRING(name),\r
+                      PyString_AS_STRING(c->u->u_name),\r
+                      PyString_AS_STRING(PyObject_Repr(c->u->u_ste->ste_id)),\r
+                      c->c_filename,\r
+                      PyString_AS_STRING(PyObject_Repr(c->u->u_ste->ste_symbols)),\r
+                      PyString_AS_STRING(PyObject_Repr(c->u->u_varnames)),\r
+                      PyString_AS_STRING(PyObject_Repr(c->u->u_names))\r
+        );\r
+        Py_FatalError(buf);\r
+    }\r
+\r
+    return scope;\r
+}\r
+\r
+static int\r
+compiler_lookup_arg(PyObject *dict, PyObject *name)\r
+{\r
+    PyObject *k, *v;\r
+    k = PyTuple_Pack(2, name, name->ob_type);\r
+    if (k == NULL)\r
+        return -1;\r
+    v = PyDict_GetItem(dict, k);\r
+    Py_DECREF(k);\r
+    if (v == NULL)\r
+        return -1;\r
+    return PyInt_AS_LONG(v);\r
+}\r
+\r
+static int\r
+compiler_make_closure(struct compiler *c, PyCodeObject *co, int args)\r
+{\r
+    int i, free = PyCode_GetNumFree(co);\r
+    if (free == 0) {\r
+        ADDOP_O(c, LOAD_CONST, (PyObject*)co, consts);\r
+        ADDOP_I(c, MAKE_FUNCTION, args);\r
+        return 1;\r
+    }\r
+    for (i = 0; i < free; ++i) {\r
+        /* Bypass com_addop_varname because it will generate\r
+           LOAD_DEREF but LOAD_CLOSURE is needed.\r
+        */\r
+        PyObject *name = PyTuple_GET_ITEM(co->co_freevars, i);\r
+        int arg, reftype;\r
+\r
+        /* Special case: If a class contains a method with a\r
+           free variable that has the same name as a method,\r
+           the name will be considered free *and* local in the\r
+           class.  It should be handled by the closure, as\r
+           well as by the normal name loookup logic.\r
+        */\r
+        reftype = get_ref_type(c, name);\r
+        if (reftype == CELL)\r
+            arg = compiler_lookup_arg(c->u->u_cellvars, name);\r
+        else /* (reftype == FREE) */\r
+            arg = compiler_lookup_arg(c->u->u_freevars, name);\r
+        if (arg == -1) {\r
+            printf("lookup %s in %s %d %d\n"\r
+                "freevars of %s: %s\n",\r
+                PyString_AS_STRING(PyObject_Repr(name)),\r
+                PyString_AS_STRING(c->u->u_name),\r
+                reftype, arg,\r
+                PyString_AS_STRING(co->co_name),\r
+                PyString_AS_STRING(PyObject_Repr(co->co_freevars)));\r
+            Py_FatalError("compiler_make_closure()");\r
+        }\r
+        ADDOP_I(c, LOAD_CLOSURE, arg);\r
+    }\r
+    ADDOP_I(c, BUILD_TUPLE, free);\r
+    ADDOP_O(c, LOAD_CONST, (PyObject*)co, consts);\r
+    ADDOP_I(c, MAKE_CLOSURE, args);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_decorators(struct compiler *c, asdl_seq* decos)\r
+{\r
+    int i;\r
+\r
+    if (!decos)\r
+        return 1;\r
+\r
+    for (i = 0; i < asdl_seq_LEN(decos); i++) {\r
+        VISIT(c, expr, (expr_ty)asdl_seq_GET(decos, i));\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_arguments(struct compiler *c, arguments_ty args)\r
+{\r
+    int i;\r
+    int n = asdl_seq_LEN(args->args);\r
+    /* Correctly handle nested argument lists */\r
+    for (i = 0; i < n; i++) {\r
+        expr_ty arg = (expr_ty)asdl_seq_GET(args->args, i);\r
+        if (arg->kind == Tuple_kind) {\r
+            PyObject *id = PyString_FromFormat(".%d", i);\r
+            if (id == NULL) {\r
+                return 0;\r
+            }\r
+            if (!compiler_nameop(c, id, Load)) {\r
+                Py_DECREF(id);\r
+                return 0;\r
+            }\r
+            Py_DECREF(id);\r
+            VISIT(c, expr, arg);\r
+        }\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_function(struct compiler *c, stmt_ty s)\r
+{\r
+    PyCodeObject *co;\r
+    PyObject *first_const = Py_None;\r
+    arguments_ty args = s->v.FunctionDef.args;\r
+    asdl_seq* decos = s->v.FunctionDef.decorator_list;\r
+    stmt_ty st;\r
+    int i, n, docstring;\r
+\r
+    assert(s->kind == FunctionDef_kind);\r
+\r
+    if (!compiler_decorators(c, decos))\r
+        return 0;\r
+    if (args->defaults)\r
+        VISIT_SEQ(c, expr, args->defaults);\r
+    if (!compiler_enter_scope(c, s->v.FunctionDef.name, (void *)s,\r
+                              s->lineno))\r
+        return 0;\r
+\r
+    st = (stmt_ty)asdl_seq_GET(s->v.FunctionDef.body, 0);\r
+    docstring = compiler_isdocstring(st);\r
+    if (docstring && Py_OptimizeFlag < 2)\r
+        first_const = st->v.Expr.value->v.Str.s;\r
+    if (compiler_add_o(c, c->u->u_consts, first_const) < 0)      {\r
+        compiler_exit_scope(c);\r
+        return 0;\r
+    }\r
+\r
+    /* unpack nested arguments */\r
+    compiler_arguments(c, args);\r
+\r
+    c->u->u_argcount = asdl_seq_LEN(args->args);\r
+    n = asdl_seq_LEN(s->v.FunctionDef.body);\r
+    /* if there was a docstring, we need to skip the first statement */\r
+    for (i = docstring; i < n; i++) {\r
+        st = (stmt_ty)asdl_seq_GET(s->v.FunctionDef.body, i);\r
+        VISIT_IN_SCOPE(c, stmt, st);\r
+    }\r
+    co = assemble(c, 1);\r
+    compiler_exit_scope(c);\r
+    if (co == NULL)\r
+        return 0;\r
+\r
+    compiler_make_closure(c, co, asdl_seq_LEN(args->defaults));\r
+    Py_DECREF(co);\r
+\r
+    for (i = 0; i < asdl_seq_LEN(decos); i++) {\r
+        ADDOP_I(c, CALL_FUNCTION, 1);\r
+    }\r
+\r
+    return compiler_nameop(c, s->v.FunctionDef.name, Store);\r
+}\r
+\r
+static int\r
+compiler_class(struct compiler *c, stmt_ty s)\r
+{\r
+    int n, i;\r
+    PyCodeObject *co;\r
+    PyObject *str;\r
+    asdl_seq* decos = s->v.ClassDef.decorator_list;\r
+\r
+    if (!compiler_decorators(c, decos))\r
+        return 0;\r
+\r
+    /* push class name on stack, needed by BUILD_CLASS */\r
+    ADDOP_O(c, LOAD_CONST, s->v.ClassDef.name, consts);\r
+    /* push the tuple of base classes on the stack */\r
+    n = asdl_seq_LEN(s->v.ClassDef.bases);\r
+    if (n > 0)\r
+        VISIT_SEQ(c, expr, s->v.ClassDef.bases);\r
+    ADDOP_I(c, BUILD_TUPLE, n);\r
+    if (!compiler_enter_scope(c, s->v.ClassDef.name, (void *)s,\r
+                              s->lineno))\r
+        return 0;\r
+    Py_XDECREF(c->u->u_private);\r
+    c->u->u_private = s->v.ClassDef.name;\r
+    Py_INCREF(c->u->u_private);\r
+    str = PyString_InternFromString("__name__");\r
+    if (!str || !compiler_nameop(c, str, Load)) {\r
+        Py_XDECREF(str);\r
+        compiler_exit_scope(c);\r
+        return 0;\r
+    }\r
+\r
+    Py_DECREF(str);\r
+    str = PyString_InternFromString("__module__");\r
+    if (!str || !compiler_nameop(c, str, Store)) {\r
+        Py_XDECREF(str);\r
+        compiler_exit_scope(c);\r
+        return 0;\r
+    }\r
+    Py_DECREF(str);\r
+\r
+    if (!compiler_body(c, s->v.ClassDef.body)) {\r
+        compiler_exit_scope(c);\r
+        return 0;\r
+    }\r
+\r
+    ADDOP_IN_SCOPE(c, LOAD_LOCALS);\r
+    ADDOP_IN_SCOPE(c, RETURN_VALUE);\r
+    co = assemble(c, 1);\r
+    compiler_exit_scope(c);\r
+    if (co == NULL)\r
+        return 0;\r
+\r
+    compiler_make_closure(c, co, 0);\r
+    Py_DECREF(co);\r
+\r
+    ADDOP_I(c, CALL_FUNCTION, 0);\r
+    ADDOP(c, BUILD_CLASS);\r
+    /* apply decorators */\r
+    for (i = 0; i < asdl_seq_LEN(decos); i++) {\r
+        ADDOP_I(c, CALL_FUNCTION, 1);\r
+    }\r
+    if (!compiler_nameop(c, s->v.ClassDef.name, Store))\r
+        return 0;\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_ifexp(struct compiler *c, expr_ty e)\r
+{\r
+    basicblock *end, *next;\r
+\r
+    assert(e->kind == IfExp_kind);\r
+    end = compiler_new_block(c);\r
+    if (end == NULL)\r
+        return 0;\r
+    next = compiler_new_block(c);\r
+    if (next == NULL)\r
+        return 0;\r
+    VISIT(c, expr, e->v.IfExp.test);\r
+    ADDOP_JABS(c, POP_JUMP_IF_FALSE, next);\r
+    VISIT(c, expr, e->v.IfExp.body);\r
+    ADDOP_JREL(c, JUMP_FORWARD, end);\r
+    compiler_use_next_block(c, next);\r
+    VISIT(c, expr, e->v.IfExp.orelse);\r
+    compiler_use_next_block(c, end);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_lambda(struct compiler *c, expr_ty e)\r
+{\r
+    PyCodeObject *co;\r
+    static identifier name;\r
+    arguments_ty args = e->v.Lambda.args;\r
+    assert(e->kind == Lambda_kind);\r
+\r
+    if (!name) {\r
+        name = PyString_InternFromString("<lambda>");\r
+        if (!name)\r
+            return 0;\r
+    }\r
+\r
+    if (args->defaults)\r
+        VISIT_SEQ(c, expr, args->defaults);\r
+    if (!compiler_enter_scope(c, name, (void *)e, e->lineno))\r
+        return 0;\r
+\r
+    /* unpack nested arguments */\r
+    compiler_arguments(c, args);\r
+\r
+    /* Make None the first constant, so the lambda can't have a\r
+       docstring. */\r
+    if (compiler_add_o(c, c->u->u_consts, Py_None) < 0)\r
+        return 0;\r
+\r
+    c->u->u_argcount = asdl_seq_LEN(args->args);\r
+    VISIT_IN_SCOPE(c, expr, e->v.Lambda.body);\r
+    if (c->u->u_ste->ste_generator) {\r
+        ADDOP_IN_SCOPE(c, POP_TOP);\r
+    }\r
+    else {\r
+        ADDOP_IN_SCOPE(c, RETURN_VALUE);\r
+    }\r
+    co = assemble(c, 1);\r
+    compiler_exit_scope(c);\r
+    if (co == NULL)\r
+        return 0;\r
+\r
+    compiler_make_closure(c, co, asdl_seq_LEN(args->defaults));\r
+    Py_DECREF(co);\r
+\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_print(struct compiler *c, stmt_ty s)\r
+{\r
+    int i, n;\r
+    bool dest;\r
+\r
+    assert(s->kind == Print_kind);\r
+    n = asdl_seq_LEN(s->v.Print.values);\r
+    dest = false;\r
+    if (s->v.Print.dest) {\r
+        VISIT(c, expr, s->v.Print.dest);\r
+        dest = true;\r
+    }\r
+    for (i = 0; i < n; i++) {\r
+        expr_ty e = (expr_ty)asdl_seq_GET(s->v.Print.values, i);\r
+        if (dest) {\r
+            ADDOP(c, DUP_TOP);\r
+            VISIT(c, expr, e);\r
+            ADDOP(c, ROT_TWO);\r
+            ADDOP(c, PRINT_ITEM_TO);\r
+        }\r
+        else {\r
+            VISIT(c, expr, e);\r
+            ADDOP(c, PRINT_ITEM);\r
+        }\r
+    }\r
+    if (s->v.Print.nl) {\r
+        if (dest)\r
+            ADDOP(c, PRINT_NEWLINE_TO)\r
+        else\r
+            ADDOP(c, PRINT_NEWLINE)\r
+    }\r
+    else if (dest)\r
+        ADDOP(c, POP_TOP);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_if(struct compiler *c, stmt_ty s)\r
+{\r
+    basicblock *end, *next;\r
+    int constant;\r
+    assert(s->kind == If_kind);\r
+    end = compiler_new_block(c);\r
+    if (end == NULL)\r
+        return 0;\r
+\r
+    constant = expr_constant(s->v.If.test);\r
+    /* constant = 0: "if 0"\r
+     * constant = 1: "if 1", "if 2", ...\r
+     * constant = -1: rest */\r
+    if (constant == 0) {\r
+        if (s->v.If.orelse)\r
+            VISIT_SEQ(c, stmt, s->v.If.orelse);\r
+    } else if (constant == 1) {\r
+        VISIT_SEQ(c, stmt, s->v.If.body);\r
+    } else {\r
+        if (s->v.If.orelse) {\r
+            next = compiler_new_block(c);\r
+            if (next == NULL)\r
+                return 0;\r
+        }\r
+        else\r
+            next = end;\r
+        VISIT(c, expr, s->v.If.test);\r
+        ADDOP_JABS(c, POP_JUMP_IF_FALSE, next);\r
+        VISIT_SEQ(c, stmt, s->v.If.body);\r
+        ADDOP_JREL(c, JUMP_FORWARD, end);\r
+        if (s->v.If.orelse) {\r
+            compiler_use_next_block(c, next);\r
+            VISIT_SEQ(c, stmt, s->v.If.orelse);\r
+        }\r
+    }\r
+    compiler_use_next_block(c, end);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_for(struct compiler *c, stmt_ty s)\r
+{\r
+    basicblock *start, *cleanup, *end;\r
+\r
+    start = compiler_new_block(c);\r
+    cleanup = compiler_new_block(c);\r
+    end = compiler_new_block(c);\r
+    if (start == NULL || end == NULL || cleanup == NULL)\r
+        return 0;\r
+    ADDOP_JREL(c, SETUP_LOOP, end);\r
+    if (!compiler_push_fblock(c, LOOP, start))\r
+        return 0;\r
+    VISIT(c, expr, s->v.For.iter);\r
+    ADDOP(c, GET_ITER);\r
+    compiler_use_next_block(c, start);\r
+    ADDOP_JREL(c, FOR_ITER, cleanup);\r
+    VISIT(c, expr, s->v.For.target);\r
+    VISIT_SEQ(c, stmt, s->v.For.body);\r
+    ADDOP_JABS(c, JUMP_ABSOLUTE, start);\r
+    compiler_use_next_block(c, cleanup);\r
+    ADDOP(c, POP_BLOCK);\r
+    compiler_pop_fblock(c, LOOP, start);\r
+    VISIT_SEQ(c, stmt, s->v.For.orelse);\r
+    compiler_use_next_block(c, end);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_while(struct compiler *c, stmt_ty s)\r
+{\r
+    basicblock *loop, *orelse, *end, *anchor = NULL;\r
+    int constant = expr_constant(s->v.While.test);\r
+\r
+    if (constant == 0) {\r
+        if (s->v.While.orelse)\r
+            VISIT_SEQ(c, stmt, s->v.While.orelse);\r
+        return 1;\r
+    }\r
+    loop = compiler_new_block(c);\r
+    end = compiler_new_block(c);\r
+    if (constant == -1) {\r
+        anchor = compiler_new_block(c);\r
+        if (anchor == NULL)\r
+            return 0;\r
+    }\r
+    if (loop == NULL || end == NULL)\r
+        return 0;\r
+    if (s->v.While.orelse) {\r
+        orelse = compiler_new_block(c);\r
+        if (orelse == NULL)\r
+            return 0;\r
+    }\r
+    else\r
+        orelse = NULL;\r
+\r
+    ADDOP_JREL(c, SETUP_LOOP, end);\r
+    compiler_use_next_block(c, loop);\r
+    if (!compiler_push_fblock(c, LOOP, loop))\r
+        return 0;\r
+    if (constant == -1) {\r
+        VISIT(c, expr, s->v.While.test);\r
+        ADDOP_JABS(c, POP_JUMP_IF_FALSE, anchor);\r
+    }\r
+    VISIT_SEQ(c, stmt, s->v.While.body);\r
+    ADDOP_JABS(c, JUMP_ABSOLUTE, loop);\r
+\r
+    /* XXX should the two POP instructions be in a separate block\r
+       if there is no else clause ?\r
+    */\r
+\r
+    if (constant == -1)\r
+        compiler_use_next_block(c, anchor);\r
+    ADDOP(c, POP_BLOCK);\r
+    compiler_pop_fblock(c, LOOP, loop);\r
+    if (orelse != NULL) /* what if orelse is just pass? */\r
+        VISIT_SEQ(c, stmt, s->v.While.orelse);\r
+    compiler_use_next_block(c, end);\r
+\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_continue(struct compiler *c)\r
+{\r
+    static const char LOOP_ERROR_MSG[] = "'continue' not properly in loop";\r
+    static const char IN_FINALLY_ERROR_MSG[] =\r
+                    "'continue' not supported inside 'finally' clause";\r
+    int i;\r
+\r
+    if (!c->u->u_nfblocks)\r
+        return compiler_error(c, LOOP_ERROR_MSG);\r
+    i = c->u->u_nfblocks - 1;\r
+    switch (c->u->u_fblock[i].fb_type) {\r
+    case LOOP:\r
+        ADDOP_JABS(c, JUMP_ABSOLUTE, c->u->u_fblock[i].fb_block);\r
+        break;\r
+    case EXCEPT:\r
+    case FINALLY_TRY:\r
+        while (--i >= 0 && c->u->u_fblock[i].fb_type != LOOP) {\r
+            /* Prevent continue anywhere under a finally\r
+                  even if hidden in a sub-try or except. */\r
+            if (c->u->u_fblock[i].fb_type == FINALLY_END)\r
+                return compiler_error(c, IN_FINALLY_ERROR_MSG);\r
+        }\r
+        if (i == -1)\r
+            return compiler_error(c, LOOP_ERROR_MSG);\r
+        ADDOP_JABS(c, CONTINUE_LOOP, c->u->u_fblock[i].fb_block);\r
+        break;\r
+    case FINALLY_END:\r
+        return compiler_error(c, IN_FINALLY_ERROR_MSG);\r
+    }\r
+\r
+    return 1;\r
+}\r
+\r
+/* Code generated for "try: <body> finally: <finalbody>" is as follows:\r
+\r
+        SETUP_FINALLY           L\r
+        <code for body>\r
+        POP_BLOCK\r
+        LOAD_CONST              <None>\r
+    L:          <code for finalbody>\r
+        END_FINALLY\r
+\r
+   The special instructions use the block stack.  Each block\r
+   stack entry contains the instruction that created it (here\r
+   SETUP_FINALLY), the level of the value stack at the time the\r
+   block stack entry was created, and a label (here L).\r
+\r
+   SETUP_FINALLY:\r
+    Pushes the current value stack level and the label\r
+    onto the block stack.\r
+   POP_BLOCK:\r
+    Pops en entry from the block stack, and pops the value\r
+    stack until its level is the same as indicated on the\r
+    block stack.  (The label is ignored.)\r
+   END_FINALLY:\r
+    Pops a variable number of entries from the *value* stack\r
+    and re-raises the exception they specify.  The number of\r
+    entries popped depends on the (pseudo) exception type.\r
+\r
+   The block stack is unwound when an exception is raised:\r
+   when a SETUP_FINALLY entry is found, the exception is pushed\r
+   onto the value stack (and the exception condition is cleared),\r
+   and the interpreter jumps to the label gotten from the block\r
+   stack.\r
+*/\r
+\r
+static int\r
+compiler_try_finally(struct compiler *c, stmt_ty s)\r
+{\r
+    basicblock *body, *end;\r
+    body = compiler_new_block(c);\r
+    end = compiler_new_block(c);\r
+    if (body == NULL || end == NULL)\r
+        return 0;\r
+\r
+    ADDOP_JREL(c, SETUP_FINALLY, end);\r
+    compiler_use_next_block(c, body);\r
+    if (!compiler_push_fblock(c, FINALLY_TRY, body))\r
+        return 0;\r
+    VISIT_SEQ(c, stmt, s->v.TryFinally.body);\r
+    ADDOP(c, POP_BLOCK);\r
+    compiler_pop_fblock(c, FINALLY_TRY, body);\r
+\r
+    ADDOP_O(c, LOAD_CONST, Py_None, consts);\r
+    compiler_use_next_block(c, end);\r
+    if (!compiler_push_fblock(c, FINALLY_END, end))\r
+        return 0;\r
+    VISIT_SEQ(c, stmt, s->v.TryFinally.finalbody);\r
+    ADDOP(c, END_FINALLY);\r
+    compiler_pop_fblock(c, FINALLY_END, end);\r
+\r
+    return 1;\r
+}\r
+\r
+/*\r
+   Code generated for "try: S except E1, V1: S1 except E2, V2: S2 ...":\r
+   (The contents of the value stack is shown in [], with the top\r
+   at the right; 'tb' is trace-back info, 'val' the exception's\r
+   associated value, and 'exc' the exception.)\r
+\r
+   Value stack          Label   Instruction     Argument\r
+   []                           SETUP_EXCEPT    L1\r
+   []                           <code for S>\r
+   []                           POP_BLOCK\r
+   []                           JUMP_FORWARD    L0\r
+\r
+   [tb, val, exc]       L1:     DUP                             )\r
+   [tb, val, exc, exc]          <evaluate E1>                   )\r
+   [tb, val, exc, exc, E1]      COMPARE_OP      EXC_MATCH       ) only if E1\r
+   [tb, val, exc, 1-or-0]       POP_JUMP_IF_FALSE       L2      )\r
+   [tb, val, exc]               POP\r
+   [tb, val]                    <assign to V1>  (or POP if no V1)\r
+   [tb]                         POP\r
+   []                           <code for S1>\r
+                                JUMP_FORWARD    L0\r
+\r
+   [tb, val, exc]       L2:     DUP\r
+   .............................etc.......................\r
+\r
+   [tb, val, exc]       Ln+1:   END_FINALLY     # re-raise exception\r
+\r
+   []                   L0:     <next statement>\r
+\r
+   Of course, parts are not generated if Vi or Ei is not present.\r
+*/\r
+static int\r
+compiler_try_except(struct compiler *c, stmt_ty s)\r
+{\r
+    basicblock *body, *orelse, *except, *end;\r
+    int i, n;\r
+\r
+    body = compiler_new_block(c);\r
+    except = compiler_new_block(c);\r
+    orelse = compiler_new_block(c);\r
+    end = compiler_new_block(c);\r
+    if (body == NULL || except == NULL || orelse == NULL || end == NULL)\r
+        return 0;\r
+    ADDOP_JREL(c, SETUP_EXCEPT, except);\r
+    compiler_use_next_block(c, body);\r
+    if (!compiler_push_fblock(c, EXCEPT, body))\r
+        return 0;\r
+    VISIT_SEQ(c, stmt, s->v.TryExcept.body);\r
+    ADDOP(c, POP_BLOCK);\r
+    compiler_pop_fblock(c, EXCEPT, body);\r
+    ADDOP_JREL(c, JUMP_FORWARD, orelse);\r
+    n = asdl_seq_LEN(s->v.TryExcept.handlers);\r
+    compiler_use_next_block(c, except);\r
+    for (i = 0; i < n; i++) {\r
+        excepthandler_ty handler = (excepthandler_ty)asdl_seq_GET(\r
+                                        s->v.TryExcept.handlers, i);\r
+        if (!handler->v.ExceptHandler.type && i < n-1)\r
+            return compiler_error(c, "default 'except:' must be last");\r
+        c->u->u_lineno_set = false;\r
+        c->u->u_lineno = handler->lineno;\r
+        except = compiler_new_block(c);\r
+        if (except == NULL)\r
+            return 0;\r
+        if (handler->v.ExceptHandler.type) {\r
+            ADDOP(c, DUP_TOP);\r
+            VISIT(c, expr, handler->v.ExceptHandler.type);\r
+            ADDOP_I(c, COMPARE_OP, PyCmp_EXC_MATCH);\r
+            ADDOP_JABS(c, POP_JUMP_IF_FALSE, except);\r
+        }\r
+        ADDOP(c, POP_TOP);\r
+        if (handler->v.ExceptHandler.name) {\r
+            VISIT(c, expr, handler->v.ExceptHandler.name);\r
+        }\r
+        else {\r
+            ADDOP(c, POP_TOP);\r
+        }\r
+        ADDOP(c, POP_TOP);\r
+        VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body);\r
+        ADDOP_JREL(c, JUMP_FORWARD, end);\r
+        compiler_use_next_block(c, except);\r
+    }\r
+    ADDOP(c, END_FINALLY);\r
+    compiler_use_next_block(c, orelse);\r
+    VISIT_SEQ(c, stmt, s->v.TryExcept.orelse);\r
+    compiler_use_next_block(c, end);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_import_as(struct compiler *c, identifier name, identifier asname)\r
+{\r
+    /* The IMPORT_NAME opcode was already generated.  This function\r
+       merely needs to bind the result to a name.\r
+\r
+       If there is a dot in name, we need to split it and emit a\r
+       LOAD_ATTR for each name.\r
+    */\r
+    const char *src = PyString_AS_STRING(name);\r
+    const char *dot = strchr(src, '.');\r
+    if (dot) {\r
+        /* Consume the base module name to get the first attribute */\r
+        src = dot + 1;\r
+        while (dot) {\r
+            /* NB src is only defined when dot != NULL */\r
+            PyObject *attr;\r
+            dot = strchr(src, '.');\r
+            attr = PyString_FromStringAndSize(src,\r
+                                dot ? dot - src : strlen(src));\r
+            if (!attr)\r
+                return -1;\r
+            ADDOP_O(c, LOAD_ATTR, attr, names);\r
+            Py_DECREF(attr);\r
+            src = dot + 1;\r
+        }\r
+    }\r
+    return compiler_nameop(c, asname, Store);\r
+}\r
+\r
+static int\r
+compiler_import(struct compiler *c, stmt_ty s)\r
+{\r
+    /* The Import node stores a module name like a.b.c as a single\r
+       string.  This is convenient for all cases except\r
+         import a.b.c as d\r
+       where we need to parse that string to extract the individual\r
+       module names.\r
+       XXX Perhaps change the representation to make this case simpler?\r
+     */\r
+    int i, n = asdl_seq_LEN(s->v.Import.names);\r
+\r
+    for (i = 0; i < n; i++) {\r
+        alias_ty alias = (alias_ty)asdl_seq_GET(s->v.Import.names, i);\r
+        int r;\r
+        PyObject *level;\r
+\r
+        if (c->c_flags && (c->c_flags->cf_flags & CO_FUTURE_ABSOLUTE_IMPORT))\r
+            level = PyInt_FromLong(0);\r
+        else\r
+            level = PyInt_FromLong(-1);\r
+\r
+        if (level == NULL)\r
+            return 0;\r
+\r
+        ADDOP_O(c, LOAD_CONST, level, consts);\r
+        Py_DECREF(level);\r
+        ADDOP_O(c, LOAD_CONST, Py_None, consts);\r
+        ADDOP_NAME(c, IMPORT_NAME, alias->name, names);\r
+\r
+        if (alias->asname) {\r
+            r = compiler_import_as(c, alias->name, alias->asname);\r
+            if (!r)\r
+                return r;\r
+        }\r
+        else {\r
+            identifier tmp = alias->name;\r
+            const char *base = PyString_AS_STRING(alias->name);\r
+            char *dot = strchr(base, '.');\r
+            if (dot)\r
+                tmp = PyString_FromStringAndSize(base,\r
+                                                 dot - base);\r
+            r = compiler_nameop(c, tmp, Store);\r
+            if (dot) {\r
+                Py_DECREF(tmp);\r
+            }\r
+            if (!r)\r
+                return r;\r
+        }\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_from_import(struct compiler *c, stmt_ty s)\r
+{\r
+    int i, n = asdl_seq_LEN(s->v.ImportFrom.names);\r
+\r
+    PyObject *names = PyTuple_New(n);\r
+    PyObject *level;\r
+    static PyObject *empty_string;\r
+\r
+    if (!empty_string) {\r
+        empty_string = PyString_FromString("");\r
+        if (!empty_string)\r
+            return 0;\r
+    }\r
+\r
+    if (!names)\r
+        return 0;\r
+\r
+    if (s->v.ImportFrom.level == 0 && c->c_flags &&\r
+        !(c->c_flags->cf_flags & CO_FUTURE_ABSOLUTE_IMPORT))\r
+        level = PyInt_FromLong(-1);\r
+    else\r
+        level = PyInt_FromLong(s->v.ImportFrom.level);\r
+\r
+    if (!level) {\r
+        Py_DECREF(names);\r
+        return 0;\r
+    }\r
+\r
+    /* build up the names */\r
+    for (i = 0; i < n; i++) {\r
+        alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i);\r
+        Py_INCREF(alias->name);\r
+        PyTuple_SET_ITEM(names, i, alias->name);\r
+    }\r
+\r
+    if (s->lineno > c->c_future->ff_lineno && s->v.ImportFrom.module &&\r
+        !strcmp(PyString_AS_STRING(s->v.ImportFrom.module), "__future__")) {\r
+        Py_DECREF(level);\r
+        Py_DECREF(names);\r
+        return compiler_error(c, "from __future__ imports must occur "\r
+                              "at the beginning of the file");\r
+    }\r
+\r
+    ADDOP_O(c, LOAD_CONST, level, consts);\r
+    Py_DECREF(level);\r
+    ADDOP_O(c, LOAD_CONST, names, consts);\r
+    Py_DECREF(names);\r
+    if (s->v.ImportFrom.module) {\r
+        ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names);\r
+    }\r
+    else {\r
+        ADDOP_NAME(c, IMPORT_NAME, empty_string, names);\r
+    }\r
+    for (i = 0; i < n; i++) {\r
+        alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i);\r
+        identifier store_name;\r
+\r
+        if (i == 0 && *PyString_AS_STRING(alias->name) == '*') {\r
+            assert(n == 1);\r
+            ADDOP(c, IMPORT_STAR);\r
+            return 1;\r
+        }\r
+\r
+        ADDOP_NAME(c, IMPORT_FROM, alias->name, names);\r
+        store_name = alias->name;\r
+        if (alias->asname)\r
+            store_name = alias->asname;\r
+\r
+        if (!compiler_nameop(c, store_name, Store)) {\r
+            Py_DECREF(names);\r
+            return 0;\r
+        }\r
+    }\r
+    /* remove imported module */\r
+    ADDOP(c, POP_TOP);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_assert(struct compiler *c, stmt_ty s)\r
+{\r
+    static PyObject *assertion_error = NULL;\r
+    basicblock *end;\r
+\r
+    if (Py_OptimizeFlag)\r
+        return 1;\r
+    if (assertion_error == NULL) {\r
+        assertion_error = PyString_InternFromString("AssertionError");\r
+        if (assertion_error == NULL)\r
+            return 0;\r
+    }\r
+    if (s->v.Assert.test->kind == Tuple_kind &&\r
+        asdl_seq_LEN(s->v.Assert.test->v.Tuple.elts) > 0) {\r
+        const char* msg =\r
+            "assertion is always true, perhaps remove parentheses?";\r
+        if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, c->c_filename,\r
+                               c->u->u_lineno, NULL, NULL) == -1)\r
+            return 0;\r
+    }\r
+    VISIT(c, expr, s->v.Assert.test);\r
+    end = compiler_new_block(c);\r
+    if (end == NULL)\r
+        return 0;\r
+    ADDOP_JABS(c, POP_JUMP_IF_TRUE, end);\r
+    ADDOP_O(c, LOAD_GLOBAL, assertion_error, names);\r
+    if (s->v.Assert.msg) {\r
+        VISIT(c, expr, s->v.Assert.msg);\r
+        ADDOP_I(c, CALL_FUNCTION, 1);\r
+    }\r
+    ADDOP_I(c, RAISE_VARARGS, 1);\r
+    compiler_use_next_block(c, end);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_visit_stmt(struct compiler *c, stmt_ty s)\r
+{\r
+    int i, n;\r
+\r
+    /* Always assign a lineno to the next instruction for a stmt. */\r
+    c->u->u_lineno = s->lineno;\r
+    c->u->u_lineno_set = false;\r
+\r
+    switch (s->kind) {\r
+    case FunctionDef_kind:\r
+        return compiler_function(c, s);\r
+    case ClassDef_kind:\r
+        return compiler_class(c, s);\r
+    case Return_kind:\r
+        if (c->u->u_ste->ste_type != FunctionBlock)\r
+            return compiler_error(c, "'return' outside function");\r
+        if (s->v.Return.value) {\r
+            VISIT(c, expr, s->v.Return.value);\r
+        }\r
+        else\r
+            ADDOP_O(c, LOAD_CONST, Py_None, consts);\r
+        ADDOP(c, RETURN_VALUE);\r
+        break;\r
+    case Delete_kind:\r
+        VISIT_SEQ(c, expr, s->v.Delete.targets)\r
+        break;\r
+    case Assign_kind:\r
+        n = asdl_seq_LEN(s->v.Assign.targets);\r
+        VISIT(c, expr, s->v.Assign.value);\r
+        for (i = 0; i < n; i++) {\r
+            if (i < n - 1)\r
+                ADDOP(c, DUP_TOP);\r
+            VISIT(c, expr,\r
+                  (expr_ty)asdl_seq_GET(s->v.Assign.targets, i));\r
+        }\r
+        break;\r
+    case AugAssign_kind:\r
+        return compiler_augassign(c, s);\r
+    case Print_kind:\r
+        return compiler_print(c, s);\r
+    case For_kind:\r
+        return compiler_for(c, s);\r
+    case While_kind:\r
+        return compiler_while(c, s);\r
+    case If_kind:\r
+        return compiler_if(c, s);\r
+    case Raise_kind:\r
+        n = 0;\r
+        if (s->v.Raise.type) {\r
+            VISIT(c, expr, s->v.Raise.type);\r
+            n++;\r
+            if (s->v.Raise.inst) {\r
+                VISIT(c, expr, s->v.Raise.inst);\r
+                n++;\r
+                if (s->v.Raise.tback) {\r
+                    VISIT(c, expr, s->v.Raise.tback);\r
+                    n++;\r
+                }\r
+            }\r
+        }\r
+        ADDOP_I(c, RAISE_VARARGS, n);\r
+        break;\r
+    case TryExcept_kind:\r
+        return compiler_try_except(c, s);\r
+    case TryFinally_kind:\r
+        return compiler_try_finally(c, s);\r
+    case Assert_kind:\r
+        return compiler_assert(c, s);\r
+    case Import_kind:\r
+        return compiler_import(c, s);\r
+    case ImportFrom_kind:\r
+        return compiler_from_import(c, s);\r
+    case Exec_kind:\r
+        VISIT(c, expr, s->v.Exec.body);\r
+        if (s->v.Exec.globals) {\r
+            VISIT(c, expr, s->v.Exec.globals);\r
+            if (s->v.Exec.locals) {\r
+                VISIT(c, expr, s->v.Exec.locals);\r
+            } else {\r
+                ADDOP(c, DUP_TOP);\r
+            }\r
+        } else {\r
+            ADDOP_O(c, LOAD_CONST, Py_None, consts);\r
+            ADDOP(c, DUP_TOP);\r
+        }\r
+        ADDOP(c, EXEC_STMT);\r
+        break;\r
+    case Global_kind:\r
+        break;\r
+    case Expr_kind:\r
+        if (c->c_interactive && c->c_nestlevel <= 1) {\r
+            VISIT(c, expr, s->v.Expr.value);\r
+            ADDOP(c, PRINT_EXPR);\r
+        }\r
+        else if (s->v.Expr.value->kind != Str_kind &&\r
+                 s->v.Expr.value->kind != Num_kind) {\r
+            VISIT(c, expr, s->v.Expr.value);\r
+            ADDOP(c, POP_TOP);\r
+        }\r
+        break;\r
+    case Pass_kind:\r
+        break;\r
+    case Break_kind:\r
+        if (!compiler_in_loop(c))\r
+            return compiler_error(c, "'break' outside loop");\r
+        ADDOP(c, BREAK_LOOP);\r
+        break;\r
+    case Continue_kind:\r
+        return compiler_continue(c);\r
+    case With_kind:\r
+        return compiler_with(c, s);\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+unaryop(unaryop_ty op)\r
+{\r
+    switch (op) {\r
+    case Invert:\r
+        return UNARY_INVERT;\r
+    case Not:\r
+        return UNARY_NOT;\r
+    case UAdd:\r
+        return UNARY_POSITIVE;\r
+    case USub:\r
+        return UNARY_NEGATIVE;\r
+    default:\r
+        PyErr_Format(PyExc_SystemError,\r
+            "unary op %d should not be possible", op);\r
+        return 0;\r
+    }\r
+}\r
+\r
+static int\r
+binop(struct compiler *c, operator_ty op)\r
+{\r
+    switch (op) {\r
+    case Add:\r
+        return BINARY_ADD;\r
+    case Sub:\r
+        return BINARY_SUBTRACT;\r
+    case Mult:\r
+        return BINARY_MULTIPLY;\r
+    case Div:\r
+        if (c->c_flags && c->c_flags->cf_flags & CO_FUTURE_DIVISION)\r
+            return BINARY_TRUE_DIVIDE;\r
+        else\r
+            return BINARY_DIVIDE;\r
+    case Mod:\r
+        return BINARY_MODULO;\r
+    case Pow:\r
+        return BINARY_POWER;\r
+    case LShift:\r
+        return BINARY_LSHIFT;\r
+    case RShift:\r
+        return BINARY_RSHIFT;\r
+    case BitOr:\r
+        return BINARY_OR;\r
+    case BitXor:\r
+        return BINARY_XOR;\r
+    case BitAnd:\r
+        return BINARY_AND;\r
+    case FloorDiv:\r
+        return BINARY_FLOOR_DIVIDE;\r
+    default:\r
+        PyErr_Format(PyExc_SystemError,\r
+            "binary op %d should not be possible", op);\r
+        return 0;\r
+    }\r
+}\r
+\r
+static int\r
+cmpop(cmpop_ty op)\r
+{\r
+    switch (op) {\r
+    case Eq:\r
+        return PyCmp_EQ;\r
+    case NotEq:\r
+        return PyCmp_NE;\r
+    case Lt:\r
+        return PyCmp_LT;\r
+    case LtE:\r
+        return PyCmp_LE;\r
+    case Gt:\r
+        return PyCmp_GT;\r
+    case GtE:\r
+        return PyCmp_GE;\r
+    case Is:\r
+        return PyCmp_IS;\r
+    case IsNot:\r
+        return PyCmp_IS_NOT;\r
+    case In:\r
+        return PyCmp_IN;\r
+    case NotIn:\r
+        return PyCmp_NOT_IN;\r
+    default:\r
+        return PyCmp_BAD;\r
+    }\r
+}\r
+\r
+static int\r
+inplace_binop(struct compiler *c, operator_ty op)\r
+{\r
+    switch (op) {\r
+    case Add:\r
+        return INPLACE_ADD;\r
+    case Sub:\r
+        return INPLACE_SUBTRACT;\r
+    case Mult:\r
+        return INPLACE_MULTIPLY;\r
+    case Div:\r
+        if (c->c_flags && c->c_flags->cf_flags & CO_FUTURE_DIVISION)\r
+            return INPLACE_TRUE_DIVIDE;\r
+        else\r
+            return INPLACE_DIVIDE;\r
+    case Mod:\r
+        return INPLACE_MODULO;\r
+    case Pow:\r
+        return INPLACE_POWER;\r
+    case LShift:\r
+        return INPLACE_LSHIFT;\r
+    case RShift:\r
+        return INPLACE_RSHIFT;\r
+    case BitOr:\r
+        return INPLACE_OR;\r
+    case BitXor:\r
+        return INPLACE_XOR;\r
+    case BitAnd:\r
+        return INPLACE_AND;\r
+    case FloorDiv:\r
+        return INPLACE_FLOOR_DIVIDE;\r
+    default:\r
+        PyErr_Format(PyExc_SystemError,\r
+            "inplace binary op %d should not be possible", op);\r
+        return 0;\r
+    }\r
+}\r
+\r
+static int\r
+compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)\r
+{\r
+    int op, scope, arg;\r
+    enum { OP_FAST, OP_GLOBAL, OP_DEREF, OP_NAME } optype;\r
+\r
+    PyObject *dict = c->u->u_names;\r
+    PyObject *mangled;\r
+    /* XXX AugStore isn't used anywhere! */\r
+\r
+    mangled = _Py_Mangle(c->u->u_private, name);\r
+    if (!mangled)\r
+        return 0;\r
+\r
+    op = 0;\r
+    optype = OP_NAME;\r
+    scope = PyST_GetScope(c->u->u_ste, mangled);\r
+    switch (scope) {\r
+    case FREE:\r
+        dict = c->u->u_freevars;\r
+        optype = OP_DEREF;\r
+        break;\r
+    case CELL:\r
+        dict = c->u->u_cellvars;\r
+        optype = OP_DEREF;\r
+        break;\r
+    case LOCAL:\r
+        if (c->u->u_ste->ste_type == FunctionBlock)\r
+            optype = OP_FAST;\r
+        break;\r
+    case GLOBAL_IMPLICIT:\r
+        if (c->u->u_ste->ste_type == FunctionBlock &&\r
+            !c->u->u_ste->ste_unoptimized)\r
+            optype = OP_GLOBAL;\r
+        break;\r
+    case GLOBAL_EXPLICIT:\r
+        optype = OP_GLOBAL;\r
+        break;\r
+    default:\r
+        /* scope can be 0 */\r
+        break;\r
+    }\r
+\r
+    /* XXX Leave assert here, but handle __doc__ and the like better */\r
+    assert(scope || PyString_AS_STRING(name)[0] == '_');\r
+\r
+    switch (optype) {\r
+    case OP_DEREF:\r
+        switch (ctx) {\r
+        case Load: op = LOAD_DEREF; break;\r
+        case Store: op = STORE_DEREF; break;\r
+        case AugLoad:\r
+        case AugStore:\r
+            break;\r
+        case Del:\r
+            PyErr_Format(PyExc_SyntaxError,\r
+                         "can not delete variable '%s' referenced "\r
+                         "in nested scope",\r
+                         PyString_AS_STRING(name));\r
+            Py_DECREF(mangled);\r
+            return 0;\r
+        case Param:\r
+        default:\r
+            PyErr_SetString(PyExc_SystemError,\r
+                            "param invalid for deref variable");\r
+            return 0;\r
+        }\r
+        break;\r
+    case OP_FAST:\r
+        switch (ctx) {\r
+        case Load: op = LOAD_FAST; break;\r
+        case Store: op = STORE_FAST; break;\r
+        case Del: op = DELETE_FAST; break;\r
+        case AugLoad:\r
+        case AugStore:\r
+            break;\r
+        case Param:\r
+        default:\r
+            PyErr_SetString(PyExc_SystemError,\r
+                            "param invalid for local variable");\r
+            return 0;\r
+        }\r
+        ADDOP_O(c, op, mangled, varnames);\r
+        Py_DECREF(mangled);\r
+        return 1;\r
+    case OP_GLOBAL:\r
+        switch (ctx) {\r
+        case Load: op = LOAD_GLOBAL; break;\r
+        case Store: op = STORE_GLOBAL; break;\r
+        case Del: op = DELETE_GLOBAL; break;\r
+        case AugLoad:\r
+        case AugStore:\r
+            break;\r
+        case Param:\r
+        default:\r
+            PyErr_SetString(PyExc_SystemError,\r
+                            "param invalid for global variable");\r
+            return 0;\r
+        }\r
+        break;\r
+    case OP_NAME:\r
+        switch (ctx) {\r
+        case Load: op = LOAD_NAME; break;\r
+        case Store: op = STORE_NAME; break;\r
+        case Del: op = DELETE_NAME; break;\r
+        case AugLoad:\r
+        case AugStore:\r
+            break;\r
+        case Param:\r
+        default:\r
+            PyErr_SetString(PyExc_SystemError,\r
+                            "param invalid for name variable");\r
+            return 0;\r
+        }\r
+        break;\r
+    }\r
+\r
+    assert(op);\r
+    arg = compiler_add_o(c, dict, mangled);\r
+    Py_DECREF(mangled);\r
+    if (arg < 0)\r
+        return 0;\r
+    return compiler_addop_i(c, op, arg);\r
+}\r
+\r
+static int\r
+compiler_boolop(struct compiler *c, expr_ty e)\r
+{\r
+    basicblock *end;\r
+    int jumpi, i, n;\r
+    asdl_seq *s;\r
+\r
+    assert(e->kind == BoolOp_kind);\r
+    if (e->v.BoolOp.op == And)\r
+        jumpi = JUMP_IF_FALSE_OR_POP;\r
+    else\r
+        jumpi = JUMP_IF_TRUE_OR_POP;\r
+    end = compiler_new_block(c);\r
+    if (end == NULL)\r
+        return 0;\r
+    s = e->v.BoolOp.values;\r
+    n = asdl_seq_LEN(s) - 1;\r
+    assert(n >= 0);\r
+    for (i = 0; i < n; ++i) {\r
+        VISIT(c, expr, (expr_ty)asdl_seq_GET(s, i));\r
+        ADDOP_JABS(c, jumpi, end);\r
+    }\r
+    VISIT(c, expr, (expr_ty)asdl_seq_GET(s, n));\r
+    compiler_use_next_block(c, end);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_list(struct compiler *c, expr_ty e)\r
+{\r
+    int n = asdl_seq_LEN(e->v.List.elts);\r
+    if (e->v.List.ctx == Store) {\r
+        ADDOP_I(c, UNPACK_SEQUENCE, n);\r
+    }\r
+    VISIT_SEQ(c, expr, e->v.List.elts);\r
+    if (e->v.List.ctx == Load) {\r
+        ADDOP_I(c, BUILD_LIST, n);\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_tuple(struct compiler *c, expr_ty e)\r
+{\r
+    int n = asdl_seq_LEN(e->v.Tuple.elts);\r
+    if (e->v.Tuple.ctx == Store) {\r
+        ADDOP_I(c, UNPACK_SEQUENCE, n);\r
+    }\r
+    VISIT_SEQ(c, expr, e->v.Tuple.elts);\r
+    if (e->v.Tuple.ctx == Load) {\r
+        ADDOP_I(c, BUILD_TUPLE, n);\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_compare(struct compiler *c, expr_ty e)\r
+{\r
+    int i, n;\r
+    basicblock *cleanup = NULL;\r
+\r
+    /* XXX the logic can be cleaned up for 1 or multiple comparisons */\r
+    VISIT(c, expr, e->v.Compare.left);\r
+    n = asdl_seq_LEN(e->v.Compare.ops);\r
+    assert(n > 0);\r
+    if (n > 1) {\r
+        cleanup = compiler_new_block(c);\r
+        if (cleanup == NULL)\r
+            return 0;\r
+        VISIT(c, expr,\r
+            (expr_ty)asdl_seq_GET(e->v.Compare.comparators, 0));\r
+    }\r
+    for (i = 1; i < n; i++) {\r
+        ADDOP(c, DUP_TOP);\r
+        ADDOP(c, ROT_THREE);\r
+        ADDOP_I(c, COMPARE_OP,\r
+            cmpop((cmpop_ty)(asdl_seq_GET(\r
+                                      e->v.Compare.ops, i - 1))));\r
+        ADDOP_JABS(c, JUMP_IF_FALSE_OR_POP, cleanup);\r
+        NEXT_BLOCK(c);\r
+        if (i < (n - 1))\r
+            VISIT(c, expr,\r
+                (expr_ty)asdl_seq_GET(e->v.Compare.comparators, i));\r
+    }\r
+    VISIT(c, expr, (expr_ty)asdl_seq_GET(e->v.Compare.comparators, n - 1));\r
+    ADDOP_I(c, COMPARE_OP,\r
+           cmpop((cmpop_ty)(asdl_seq_GET(e->v.Compare.ops, n - 1))));\r
+    if (n > 1) {\r
+        basicblock *end = compiler_new_block(c);\r
+        if (end == NULL)\r
+            return 0;\r
+        ADDOP_JREL(c, JUMP_FORWARD, end);\r
+        compiler_use_next_block(c, cleanup);\r
+        ADDOP(c, ROT_TWO);\r
+        ADDOP(c, POP_TOP);\r
+        compiler_use_next_block(c, end);\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_call(struct compiler *c, expr_ty e)\r
+{\r
+    int n, code = 0;\r
+\r
+    VISIT(c, expr, e->v.Call.func);\r
+    n = asdl_seq_LEN(e->v.Call.args);\r
+    VISIT_SEQ(c, expr, e->v.Call.args);\r
+    if (e->v.Call.keywords) {\r
+        VISIT_SEQ(c, keyword, e->v.Call.keywords);\r
+        n |= asdl_seq_LEN(e->v.Call.keywords) << 8;\r
+    }\r
+    if (e->v.Call.starargs) {\r
+        VISIT(c, expr, e->v.Call.starargs);\r
+        code |= 1;\r
+    }\r
+    if (e->v.Call.kwargs) {\r
+        VISIT(c, expr, e->v.Call.kwargs);\r
+        code |= 2;\r
+    }\r
+    switch (code) {\r
+    case 0:\r
+        ADDOP_I(c, CALL_FUNCTION, n);\r
+        break;\r
+    case 1:\r
+        ADDOP_I(c, CALL_FUNCTION_VAR, n);\r
+        break;\r
+    case 2:\r
+        ADDOP_I(c, CALL_FUNCTION_KW, n);\r
+        break;\r
+    case 3:\r
+        ADDOP_I(c, CALL_FUNCTION_VAR_KW, n);\r
+        break;\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_listcomp_generator(struct compiler *c, asdl_seq *generators,\r
+                            int gen_index, expr_ty elt)\r
+{\r
+    /* generate code for the iterator, then each of the ifs,\r
+       and then write to the element */\r
+\r
+    comprehension_ty l;\r
+    basicblock *start, *anchor, *skip, *if_cleanup;\r
+    int i, n;\r
+\r
+    start = compiler_new_block(c);\r
+    skip = compiler_new_block(c);\r
+    if_cleanup = compiler_new_block(c);\r
+    anchor = compiler_new_block(c);\r
+\r
+    if (start == NULL || skip == NULL || if_cleanup == NULL ||\r
+        anchor == NULL)\r
+        return 0;\r
+\r
+    l = (comprehension_ty)asdl_seq_GET(generators, gen_index);\r
+    VISIT(c, expr, l->iter);\r
+    ADDOP(c, GET_ITER);\r
+    compiler_use_next_block(c, start);\r
+    ADDOP_JREL(c, FOR_ITER, anchor);\r
+    NEXT_BLOCK(c);\r
+    VISIT(c, expr, l->target);\r
+\r
+    /* XXX this needs to be cleaned up...a lot! */\r
+    n = asdl_seq_LEN(l->ifs);\r
+    for (i = 0; i < n; i++) {\r
+        expr_ty e = (expr_ty)asdl_seq_GET(l->ifs, i);\r
+        VISIT(c, expr, e);\r
+        ADDOP_JABS(c, POP_JUMP_IF_FALSE, if_cleanup);\r
+        NEXT_BLOCK(c);\r
+    }\r
+\r
+    if (++gen_index < asdl_seq_LEN(generators))\r
+        if (!compiler_listcomp_generator(c, generators, gen_index, elt))\r
+        return 0;\r
+\r
+    /* only append after the last for generator */\r
+    if (gen_index >= asdl_seq_LEN(generators)) {\r
+        VISIT(c, expr, elt);\r
+        ADDOP_I(c, LIST_APPEND, gen_index+1);\r
+\r
+        compiler_use_next_block(c, skip);\r
+    }\r
+    compiler_use_next_block(c, if_cleanup);\r
+    ADDOP_JABS(c, JUMP_ABSOLUTE, start);\r
+    compiler_use_next_block(c, anchor);\r
+\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_listcomp(struct compiler *c, expr_ty e)\r
+{\r
+    assert(e->kind == ListComp_kind);\r
+    ADDOP_I(c, BUILD_LIST, 0);\r
+    return compiler_listcomp_generator(c, e->v.ListComp.generators, 0,\r
+                                       e->v.ListComp.elt);\r
+}\r
+\r
+/* Dict and set comprehensions and generator expressions work by creating a\r
+   nested function to perform the actual iteration. This means that the\r
+   iteration variables don't leak into the current scope.\r
+   The defined function is called immediately following its definition, with the\r
+   result of that call being the result of the expression.\r
+   The LC/SC version returns the populated container, while the GE version is\r
+   flagged in symtable.c as a generator, so it returns the generator object\r
+   when the function is called.\r
+   This code *knows* that the loop cannot contain break, continue, or return,\r
+   so it cheats and skips the SETUP_LOOP/POP_BLOCK steps used in normal loops.\r
+\r
+   Possible cleanups:\r
+    - iterate over the generator sequence instead of using recursion\r
+*/\r
+\r
+static int\r
+compiler_comprehension_generator(struct compiler *c,\r
+                                 asdl_seq *generators, int gen_index,\r
+                                 expr_ty elt, expr_ty val, int type)\r
+{\r
+    /* generate code for the iterator, then each of the ifs,\r
+       and then write to the element */\r
+\r
+    comprehension_ty gen;\r
+    basicblock *start, *anchor, *skip, *if_cleanup;\r
+    int i, n;\r
+\r
+    start = compiler_new_block(c);\r
+    skip = compiler_new_block(c);\r
+    if_cleanup = compiler_new_block(c);\r
+    anchor = compiler_new_block(c);\r
+\r
+    if (start == NULL || skip == NULL || if_cleanup == NULL ||\r
+        anchor == NULL)\r
+        return 0;\r
+\r
+    gen = (comprehension_ty)asdl_seq_GET(generators, gen_index);\r
+\r
+    if (gen_index == 0) {\r
+        /* Receive outermost iter as an implicit argument */\r
+        c->u->u_argcount = 1;\r
+        ADDOP_I(c, LOAD_FAST, 0);\r
+    }\r
+    else {\r
+        /* Sub-iter - calculate on the fly */\r
+        VISIT(c, expr, gen->iter);\r
+        ADDOP(c, GET_ITER);\r
+    }\r
+    compiler_use_next_block(c, start);\r
+    ADDOP_JREL(c, FOR_ITER, anchor);\r
+    NEXT_BLOCK(c);\r
+    VISIT(c, expr, gen->target);\r
+\r
+    /* XXX this needs to be cleaned up...a lot! */\r
+    n = asdl_seq_LEN(gen->ifs);\r
+    for (i = 0; i < n; i++) {\r
+        expr_ty e = (expr_ty)asdl_seq_GET(gen->ifs, i);\r
+        VISIT(c, expr, e);\r
+        ADDOP_JABS(c, POP_JUMP_IF_FALSE, if_cleanup);\r
+        NEXT_BLOCK(c);\r
+    }\r
+\r
+    if (++gen_index < asdl_seq_LEN(generators))\r
+        if (!compiler_comprehension_generator(c,\r
+                                              generators, gen_index,\r
+                                              elt, val, type))\r
+        return 0;\r
+\r
+    /* only append after the last for generator */\r
+    if (gen_index >= asdl_seq_LEN(generators)) {\r
+        /* comprehension specific code */\r
+        switch (type) {\r
+        case COMP_GENEXP:\r
+            VISIT(c, expr, elt);\r
+            ADDOP(c, YIELD_VALUE);\r
+            ADDOP(c, POP_TOP);\r
+            break;\r
+        case COMP_SETCOMP:\r
+            VISIT(c, expr, elt);\r
+            ADDOP_I(c, SET_ADD, gen_index + 1);\r
+            break;\r
+        case COMP_DICTCOMP:\r
+            /* With 'd[k] = v', v is evaluated before k, so we do\r
+               the same. */\r
+            VISIT(c, expr, val);\r
+            VISIT(c, expr, elt);\r
+            ADDOP_I(c, MAP_ADD, gen_index + 1);\r
+            break;\r
+        default:\r
+            return 0;\r
+        }\r
+\r
+        compiler_use_next_block(c, skip);\r
+    }\r
+    compiler_use_next_block(c, if_cleanup);\r
+    ADDOP_JABS(c, JUMP_ABSOLUTE, start);\r
+    compiler_use_next_block(c, anchor);\r
+\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_comprehension(struct compiler *c, expr_ty e, int type, identifier name,\r
+                       asdl_seq *generators, expr_ty elt, expr_ty val)\r
+{\r
+    PyCodeObject *co = NULL;\r
+    expr_ty outermost_iter;\r
+\r
+    outermost_iter = ((comprehension_ty)\r
+                      asdl_seq_GET(generators, 0))->iter;\r
+\r
+    if (!compiler_enter_scope(c, name, (void *)e, e->lineno))\r
+        goto error;\r
+\r
+    if (type != COMP_GENEXP) {\r
+        int op;\r
+        switch (type) {\r
+        case COMP_SETCOMP:\r
+            op = BUILD_SET;\r
+            break;\r
+        case COMP_DICTCOMP:\r
+            op = BUILD_MAP;\r
+            break;\r
+        default:\r
+            PyErr_Format(PyExc_SystemError,\r
+                         "unknown comprehension type %d", type);\r
+            goto error_in_scope;\r
+        }\r
+\r
+        ADDOP_I(c, op, 0);\r
+    }\r
+\r
+    if (!compiler_comprehension_generator(c, generators, 0, elt,\r
+                                          val, type))\r
+        goto error_in_scope;\r
+\r
+    if (type != COMP_GENEXP) {\r
+        ADDOP(c, RETURN_VALUE);\r
+    }\r
+\r
+    co = assemble(c, 1);\r
+    compiler_exit_scope(c);\r
+    if (co == NULL)\r
+        goto error;\r
+\r
+    if (!compiler_make_closure(c, co, 0))\r
+        goto error;\r
+    Py_DECREF(co);\r
+\r
+    VISIT(c, expr, outermost_iter);\r
+    ADDOP(c, GET_ITER);\r
+    ADDOP_I(c, CALL_FUNCTION, 1);\r
+    return 1;\r
+error_in_scope:\r
+    compiler_exit_scope(c);\r
+error:\r
+    Py_XDECREF(co);\r
+    return 0;\r
+}\r
+\r
+static int\r
+compiler_genexp(struct compiler *c, expr_ty e)\r
+{\r
+    static identifier name;\r
+    if (!name) {\r
+        name = PyString_FromString("<genexpr>");\r
+        if (!name)\r
+            return 0;\r
+    }\r
+    assert(e->kind == GeneratorExp_kind);\r
+    return compiler_comprehension(c, e, COMP_GENEXP, name,\r
+                                  e->v.GeneratorExp.generators,\r
+                                  e->v.GeneratorExp.elt, NULL);\r
+}\r
+\r
+static int\r
+compiler_setcomp(struct compiler *c, expr_ty e)\r
+{\r
+    static identifier name;\r
+    if (!name) {\r
+        name = PyString_FromString("<setcomp>");\r
+        if (!name)\r
+            return 0;\r
+    }\r
+    assert(e->kind == SetComp_kind);\r
+    return compiler_comprehension(c, e, COMP_SETCOMP, name,\r
+                                  e->v.SetComp.generators,\r
+                                  e->v.SetComp.elt, NULL);\r
+}\r
+\r
+static int\r
+compiler_dictcomp(struct compiler *c, expr_ty e)\r
+{\r
+    static identifier name;\r
+    if (!name) {\r
+        name = PyString_FromString("<dictcomp>");\r
+        if (!name)\r
+            return 0;\r
+    }\r
+    assert(e->kind == DictComp_kind);\r
+    return compiler_comprehension(c, e, COMP_DICTCOMP, name,\r
+                                  e->v.DictComp.generators,\r
+                                  e->v.DictComp.key, e->v.DictComp.value);\r
+}\r
+\r
+static int\r
+compiler_visit_keyword(struct compiler *c, keyword_ty k)\r
+{\r
+    ADDOP_O(c, LOAD_CONST, k->arg, consts);\r
+    VISIT(c, expr, k->value);\r
+    return 1;\r
+}\r
+\r
+/* Test whether expression is constant.  For constants, report\r
+   whether they are true or false.\r
+\r
+   Return values: 1 for true, 0 for false, -1 for non-constant.\r
+ */\r
+\r
+static int\r
+expr_constant(expr_ty e)\r
+{\r
+    switch (e->kind) {\r
+    case Num_kind:\r
+        return PyObject_IsTrue(e->v.Num.n);\r
+    case Str_kind:\r
+        return PyObject_IsTrue(e->v.Str.s);\r
+    case Name_kind:\r
+        /* __debug__ is not assignable, so we can optimize\r
+         * it away in if and while statements */\r
+        if (strcmp(PyString_AS_STRING(e->v.Name.id),\r
+                   "__debug__") == 0)\r
+                   return ! Py_OptimizeFlag;\r
+        /* fall through */\r
+    default:\r
+        return -1;\r
+    }\r
+}\r
+\r
+/*\r
+   Implements the with statement from PEP 343.\r
+\r
+   The semantics outlined in that PEP are as follows:\r
+\r
+   with EXPR as VAR:\r
+       BLOCK\r
+\r
+   It is implemented roughly as:\r
+\r
+   context = EXPR\r
+   exit = context.__exit__  # not calling it\r
+   value = context.__enter__()\r
+   try:\r
+       VAR = value  # if VAR present in the syntax\r
+       BLOCK\r
+   finally:\r
+       if an exception was raised:\r
+       exc = copy of (exception, instance, traceback)\r
+       else:\r
+       exc = (None, None, None)\r
+       exit(*exc)\r
+ */\r
+static int\r
+compiler_with(struct compiler *c, stmt_ty s)\r
+{\r
+    basicblock *block, *finally;\r
+\r
+    assert(s->kind == With_kind);\r
+\r
+    block = compiler_new_block(c);\r
+    finally = compiler_new_block(c);\r
+    if (!block || !finally)\r
+        return 0;\r
+\r
+    /* Evaluate EXPR */\r
+    VISIT(c, expr, s->v.With.context_expr);\r
+    ADDOP_JREL(c, SETUP_WITH, finally);\r
+\r
+    /* SETUP_WITH pushes a finally block. */\r
+    compiler_use_next_block(c, block);\r
+    /* Note that the block is actually called SETUP_WITH in ceval.c, but\r
+       functions the same as SETUP_FINALLY except that exceptions are\r
+       normalized. */\r
+    if (!compiler_push_fblock(c, FINALLY_TRY, block)) {\r
+        return 0;\r
+    }\r
+\r
+    if (s->v.With.optional_vars) {\r
+        VISIT(c, expr, s->v.With.optional_vars);\r
+    }\r
+    else {\r
+    /* Discard result from context.__enter__() */\r
+        ADDOP(c, POP_TOP);\r
+    }\r
+\r
+    /* BLOCK code */\r
+    VISIT_SEQ(c, stmt, s->v.With.body);\r
+\r
+    /* End of try block; start the finally block */\r
+    ADDOP(c, POP_BLOCK);\r
+    compiler_pop_fblock(c, FINALLY_TRY, block);\r
+\r
+    ADDOP_O(c, LOAD_CONST, Py_None, consts);\r
+    compiler_use_next_block(c, finally);\r
+    if (!compiler_push_fblock(c, FINALLY_END, finally))\r
+        return 0;\r
+\r
+    /* Finally block starts; context.__exit__ is on the stack under\r
+       the exception or return information. Just issue our magic\r
+       opcode. */\r
+    ADDOP(c, WITH_CLEANUP);\r
+\r
+    /* Finally block ends. */\r
+    ADDOP(c, END_FINALLY);\r
+    compiler_pop_fblock(c, FINALLY_END, finally);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_visit_expr(struct compiler *c, expr_ty e)\r
+{\r
+    int i, n;\r
+\r
+    /* If expr e has a different line number than the last expr/stmt,\r
+       set a new line number for the next instruction.\r
+    */\r
+    if (e->lineno > c->u->u_lineno) {\r
+        c->u->u_lineno = e->lineno;\r
+        c->u->u_lineno_set = false;\r
+    }\r
+    switch (e->kind) {\r
+    case BoolOp_kind:\r
+        return compiler_boolop(c, e);\r
+    case BinOp_kind:\r
+        VISIT(c, expr, e->v.BinOp.left);\r
+        VISIT(c, expr, e->v.BinOp.right);\r
+        ADDOP(c, binop(c, e->v.BinOp.op));\r
+        break;\r
+    case UnaryOp_kind:\r
+        VISIT(c, expr, e->v.UnaryOp.operand);\r
+        ADDOP(c, unaryop(e->v.UnaryOp.op));\r
+        break;\r
+    case Lambda_kind:\r
+        return compiler_lambda(c, e);\r
+    case IfExp_kind:\r
+        return compiler_ifexp(c, e);\r
+    case Dict_kind:\r
+        n = asdl_seq_LEN(e->v.Dict.values);\r
+        ADDOP_I(c, BUILD_MAP, (n>0xFFFF ? 0xFFFF : n));\r
+        for (i = 0; i < n; i++) {\r
+            VISIT(c, expr,\r
+                (expr_ty)asdl_seq_GET(e->v.Dict.values, i));\r
+            VISIT(c, expr,\r
+                (expr_ty)asdl_seq_GET(e->v.Dict.keys, i));\r
+            ADDOP(c, STORE_MAP);\r
+        }\r
+        break;\r
+    case Set_kind:\r
+        n = asdl_seq_LEN(e->v.Set.elts);\r
+        VISIT_SEQ(c, expr, e->v.Set.elts);\r
+        ADDOP_I(c, BUILD_SET, n);\r
+        break;\r
+    case ListComp_kind:\r
+        return compiler_listcomp(c, e);\r
+    case SetComp_kind:\r
+        return compiler_setcomp(c, e);\r
+    case DictComp_kind:\r
+        return compiler_dictcomp(c, e);\r
+    case GeneratorExp_kind:\r
+        return compiler_genexp(c, e);\r
+    case Yield_kind:\r
+        if (c->u->u_ste->ste_type != FunctionBlock)\r
+            return compiler_error(c, "'yield' outside function");\r
+        if (e->v.Yield.value) {\r
+            VISIT(c, expr, e->v.Yield.value);\r
+        }\r
+        else {\r
+            ADDOP_O(c, LOAD_CONST, Py_None, consts);\r
+        }\r
+        ADDOP(c, YIELD_VALUE);\r
+        break;\r
+    case Compare_kind:\r
+        return compiler_compare(c, e);\r
+    case Call_kind:\r
+        return compiler_call(c, e);\r
+    case Repr_kind:\r
+        VISIT(c, expr, e->v.Repr.value);\r
+        ADDOP(c, UNARY_CONVERT);\r
+        break;\r
+    case Num_kind:\r
+        ADDOP_O(c, LOAD_CONST, e->v.Num.n, consts);\r
+        break;\r
+    case Str_kind:\r
+        ADDOP_O(c, LOAD_CONST, e->v.Str.s, consts);\r
+        break;\r
+    /* The following exprs can be assignment targets. */\r
+    case Attribute_kind:\r
+        if (e->v.Attribute.ctx != AugStore)\r
+            VISIT(c, expr, e->v.Attribute.value);\r
+        switch (e->v.Attribute.ctx) {\r
+        case AugLoad:\r
+            ADDOP(c, DUP_TOP);\r
+            /* Fall through to load */\r
+        case Load:\r
+            ADDOP_NAME(c, LOAD_ATTR, e->v.Attribute.attr, names);\r
+            break;\r
+        case AugStore:\r
+            ADDOP(c, ROT_TWO);\r
+            /* Fall through to save */\r
+        case Store:\r
+            ADDOP_NAME(c, STORE_ATTR, e->v.Attribute.attr, names);\r
+            break;\r
+        case Del:\r
+            ADDOP_NAME(c, DELETE_ATTR, e->v.Attribute.attr, names);\r
+            break;\r
+        case Param:\r
+        default:\r
+            PyErr_SetString(PyExc_SystemError,\r
+                            "param invalid in attribute expression");\r
+            return 0;\r
+        }\r
+        break;\r
+    case Subscript_kind:\r
+        switch (e->v.Subscript.ctx) {\r
+        case AugLoad:\r
+            VISIT(c, expr, e->v.Subscript.value);\r
+            VISIT_SLICE(c, e->v.Subscript.slice, AugLoad);\r
+            break;\r
+        case Load:\r
+            VISIT(c, expr, e->v.Subscript.value);\r
+            VISIT_SLICE(c, e->v.Subscript.slice, Load);\r
+            break;\r
+        case AugStore:\r
+            VISIT_SLICE(c, e->v.Subscript.slice, AugStore);\r
+            break;\r
+        case Store:\r
+            VISIT(c, expr, e->v.Subscript.value);\r
+            VISIT_SLICE(c, e->v.Subscript.slice, Store);\r
+            break;\r
+        case Del:\r
+            VISIT(c, expr, e->v.Subscript.value);\r
+            VISIT_SLICE(c, e->v.Subscript.slice, Del);\r
+            break;\r
+        case Param:\r
+        default:\r
+            PyErr_SetString(PyExc_SystemError,\r
+                "param invalid in subscript expression");\r
+            return 0;\r
+        }\r
+        break;\r
+    case Name_kind:\r
+        return compiler_nameop(c, e->v.Name.id, e->v.Name.ctx);\r
+    /* child nodes of List and Tuple will have expr_context set */\r
+    case List_kind:\r
+        return compiler_list(c, e);\r
+    case Tuple_kind:\r
+        return compiler_tuple(c, e);\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_augassign(struct compiler *c, stmt_ty s)\r
+{\r
+    expr_ty e = s->v.AugAssign.target;\r
+    expr_ty auge;\r
+\r
+    assert(s->kind == AugAssign_kind);\r
+\r
+    switch (e->kind) {\r
+    case Attribute_kind:\r
+        auge = Attribute(e->v.Attribute.value, e->v.Attribute.attr,\r
+                         AugLoad, e->lineno, e->col_offset, c->c_arena);\r
+        if (auge == NULL)\r
+            return 0;\r
+        VISIT(c, expr, auge);\r
+        VISIT(c, expr, s->v.AugAssign.value);\r
+        ADDOP(c, inplace_binop(c, s->v.AugAssign.op));\r
+        auge->v.Attribute.ctx = AugStore;\r
+        VISIT(c, expr, auge);\r
+        break;\r
+    case Subscript_kind:\r
+        auge = Subscript(e->v.Subscript.value, e->v.Subscript.slice,\r
+                         AugLoad, e->lineno, e->col_offset, c->c_arena);\r
+        if (auge == NULL)\r
+            return 0;\r
+        VISIT(c, expr, auge);\r
+        VISIT(c, expr, s->v.AugAssign.value);\r
+        ADDOP(c, inplace_binop(c, s->v.AugAssign.op));\r
+        auge->v.Subscript.ctx = AugStore;\r
+        VISIT(c, expr, auge);\r
+        break;\r
+    case Name_kind:\r
+        if (!compiler_nameop(c, e->v.Name.id, Load))\r
+            return 0;\r
+        VISIT(c, expr, s->v.AugAssign.value);\r
+        ADDOP(c, inplace_binop(c, s->v.AugAssign.op));\r
+        return compiler_nameop(c, e->v.Name.id, Store);\r
+    default:\r
+        PyErr_Format(PyExc_SystemError,\r
+            "invalid node type (%d) for augmented assignment",\r
+            e->kind);\r
+        return 0;\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_push_fblock(struct compiler *c, enum fblocktype t, basicblock *b)\r
+{\r
+    struct fblockinfo *f;\r
+    if (c->u->u_nfblocks >= CO_MAXBLOCKS) {\r
+        PyErr_SetString(PyExc_SystemError,\r
+                        "too many statically nested blocks");\r
+        return 0;\r
+    }\r
+    f = &c->u->u_fblock[c->u->u_nfblocks++];\r
+    f->fb_type = t;\r
+    f->fb_block = b;\r
+    return 1;\r
+}\r
+\r
+static void\r
+compiler_pop_fblock(struct compiler *c, enum fblocktype t, basicblock *b)\r
+{\r
+    struct compiler_unit *u = c->u;\r
+    assert(u->u_nfblocks > 0);\r
+    u->u_nfblocks--;\r
+    assert(u->u_fblock[u->u_nfblocks].fb_type == t);\r
+    assert(u->u_fblock[u->u_nfblocks].fb_block == b);\r
+}\r
+\r
+static int\r
+compiler_in_loop(struct compiler *c) {\r
+    int i;\r
+    struct compiler_unit *u = c->u;\r
+    for (i = 0; i < u->u_nfblocks; ++i) {\r
+        if (u->u_fblock[i].fb_type == LOOP)\r
+            return 1;\r
+    }\r
+    return 0;\r
+}\r
+/* Raises a SyntaxError and returns 0.\r
+   If something goes wrong, a different exception may be raised.\r
+*/\r
+\r
+static int\r
+compiler_error(struct compiler *c, const char *errstr)\r
+{\r
+    PyObject *loc;\r
+    PyObject *u = NULL, *v = NULL;\r
+\r
+    loc = PyErr_ProgramText(c->c_filename, c->u->u_lineno);\r
+    if (!loc) {\r
+        Py_INCREF(Py_None);\r
+        loc = Py_None;\r
+    }\r
+    u = Py_BuildValue("(ziOO)", c->c_filename, c->u->u_lineno,\r
+                      Py_None, loc);\r
+    if (!u)\r
+        goto exit;\r
+    v = Py_BuildValue("(zO)", errstr, u);\r
+    if (!v)\r
+        goto exit;\r
+    PyErr_SetObject(PyExc_SyntaxError, v);\r
+ exit:\r
+    Py_DECREF(loc);\r
+    Py_XDECREF(u);\r
+    Py_XDECREF(v);\r
+    return 0;\r
+}\r
+\r
+static int\r
+compiler_handle_subscr(struct compiler *c, const char *kind,\r
+                       expr_context_ty ctx)\r
+{\r
+    int op = 0;\r
+\r
+    /* XXX this code is duplicated */\r
+    switch (ctx) {\r
+        case AugLoad: /* fall through to Load */\r
+        case Load:    op = BINARY_SUBSCR; break;\r
+        case AugStore:/* fall through to Store */\r
+        case Store:   op = STORE_SUBSCR; break;\r
+        case Del:     op = DELETE_SUBSCR; break;\r
+        case Param:\r
+            PyErr_Format(PyExc_SystemError,\r
+                         "invalid %s kind %d in subscript\n",\r
+                         kind, ctx);\r
+            return 0;\r
+    }\r
+    if (ctx == AugLoad) {\r
+        ADDOP_I(c, DUP_TOPX, 2);\r
+    }\r
+    else if (ctx == AugStore) {\r
+        ADDOP(c, ROT_THREE);\r
+    }\r
+    ADDOP(c, op);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)\r
+{\r
+    int n = 2;\r
+    assert(s->kind == Slice_kind);\r
+\r
+    /* only handles the cases where BUILD_SLICE is emitted */\r
+    if (s->v.Slice.lower) {\r
+        VISIT(c, expr, s->v.Slice.lower);\r
+    }\r
+    else {\r
+        ADDOP_O(c, LOAD_CONST, Py_None, consts);\r
+    }\r
+\r
+    if (s->v.Slice.upper) {\r
+        VISIT(c, expr, s->v.Slice.upper);\r
+    }\r
+    else {\r
+        ADDOP_O(c, LOAD_CONST, Py_None, consts);\r
+    }\r
+\r
+    if (s->v.Slice.step) {\r
+        n++;\r
+        VISIT(c, expr, s->v.Slice.step);\r
+    }\r
+    ADDOP_I(c, BUILD_SLICE, n);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_simple_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)\r
+{\r
+    int op = 0, slice_offset = 0, stack_count = 0;\r
+\r
+    assert(s->v.Slice.step == NULL);\r
+    if (s->v.Slice.lower) {\r
+        slice_offset++;\r
+        stack_count++;\r
+        if (ctx != AugStore)\r
+            VISIT(c, expr, s->v.Slice.lower);\r
+    }\r
+    if (s->v.Slice.upper) {\r
+        slice_offset += 2;\r
+        stack_count++;\r
+        if (ctx != AugStore)\r
+            VISIT(c, expr, s->v.Slice.upper);\r
+    }\r
+\r
+    if (ctx == AugLoad) {\r
+        switch (stack_count) {\r
+        case 0: ADDOP(c, DUP_TOP); break;\r
+        case 1: ADDOP_I(c, DUP_TOPX, 2); break;\r
+        case 2: ADDOP_I(c, DUP_TOPX, 3); break;\r
+        }\r
+    }\r
+    else if (ctx == AugStore) {\r
+        switch (stack_count) {\r
+        case 0: ADDOP(c, ROT_TWO); break;\r
+        case 1: ADDOP(c, ROT_THREE); break;\r
+        case 2: ADDOP(c, ROT_FOUR); break;\r
+        }\r
+    }\r
+\r
+    switch (ctx) {\r
+    case AugLoad: /* fall through to Load */\r
+    case Load: op = SLICE; break;\r
+    case AugStore:/* fall through to Store */\r
+    case Store: op = STORE_SLICE; break;\r
+    case Del: op = DELETE_SLICE; break;\r
+    case Param:\r
+    default:\r
+        PyErr_SetString(PyExc_SystemError,\r
+                        "param invalid in simple slice");\r
+        return 0;\r
+    }\r
+\r
+    ADDOP(c, op + slice_offset);\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_visit_nested_slice(struct compiler *c, slice_ty s,\r
+                            expr_context_ty ctx)\r
+{\r
+    switch (s->kind) {\r
+    case Ellipsis_kind:\r
+        ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts);\r
+        break;\r
+    case Slice_kind:\r
+        return compiler_slice(c, s, ctx);\r
+    case Index_kind:\r
+        VISIT(c, expr, s->v.Index.value);\r
+        break;\r
+    case ExtSlice_kind:\r
+    default:\r
+        PyErr_SetString(PyExc_SystemError,\r
+                        "extended slice invalid in nested slice");\r
+        return 0;\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+compiler_visit_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)\r
+{\r
+    char * kindname = NULL;\r
+    switch (s->kind) {\r
+    case Index_kind:\r
+        kindname = "index";\r
+        if (ctx != AugStore) {\r
+            VISIT(c, expr, s->v.Index.value);\r
+        }\r
+        break;\r
+    case Ellipsis_kind:\r
+        kindname = "ellipsis";\r
+        if (ctx != AugStore) {\r
+            ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts);\r
+        }\r
+        break;\r
+    case Slice_kind:\r
+        kindname = "slice";\r
+        if (!s->v.Slice.step)\r
+            return compiler_simple_slice(c, s, ctx);\r
+        if (ctx != AugStore) {\r
+            if (!compiler_slice(c, s, ctx))\r
+                return 0;\r
+        }\r
+        break;\r
+    case ExtSlice_kind:\r
+        kindname = "extended slice";\r
+        if (ctx != AugStore) {\r
+            int i, n = asdl_seq_LEN(s->v.ExtSlice.dims);\r
+            for (i = 0; i < n; i++) {\r
+                slice_ty sub = (slice_ty)asdl_seq_GET(\r
+                    s->v.ExtSlice.dims, i);\r
+                if (!compiler_visit_nested_slice(c, sub, ctx))\r
+                    return 0;\r
+            }\r
+            ADDOP_I(c, BUILD_TUPLE, n);\r
+        }\r
+        break;\r
+    default:\r
+        PyErr_Format(PyExc_SystemError,\r
+                     "invalid subscript kind %d", s->kind);\r
+        return 0;\r
+    }\r
+    return compiler_handle_subscr(c, kindname, ctx);\r
+}\r
+\r
+\r
+/* End of the compiler section, beginning of the assembler section */\r
+\r
+/* do depth-first search of basic block graph, starting with block.\r
+   post records the block indices in post-order.\r
+\r
+   XXX must handle implicit jumps from one block to next\r
+*/\r
+\r
+struct assembler {\r
+    PyObject *a_bytecode;  /* string containing bytecode */\r
+    int a_offset;              /* offset into bytecode */\r
+    int a_nblocks;             /* number of reachable blocks */\r
+    basicblock **a_postorder; /* list of blocks in dfs postorder */\r
+    PyObject *a_lnotab;    /* string containing lnotab */\r
+    int a_lnotab_off;      /* offset into lnotab */\r
+    int a_lineno;              /* last lineno of emitted instruction */\r
+    int a_lineno_off;      /* bytecode offset of last lineno */\r
+};\r
+\r
+static void\r
+dfs(struct compiler *c, basicblock *b, struct assembler *a)\r
+{\r
+    int i;\r
+    struct instr *instr = NULL;\r
+\r
+    if (b->b_seen)\r
+        return;\r
+    b->b_seen = 1;\r
+    if (b->b_next != NULL)\r
+        dfs(c, b->b_next, a);\r
+    for (i = 0; i < b->b_iused; i++) {\r
+        instr = &b->b_instr[i];\r
+        if (instr->i_jrel || instr->i_jabs)\r
+            dfs(c, instr->i_target, a);\r
+    }\r
+    a->a_postorder[a->a_nblocks++] = b;\r
+}\r
+\r
+static int\r
+stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth)\r
+{\r
+    int i, target_depth;\r
+    struct instr *instr;\r
+    if (b->b_seen || b->b_startdepth >= depth)\r
+        return maxdepth;\r
+    b->b_seen = 1;\r
+    b->b_startdepth = depth;\r
+    for (i = 0; i < b->b_iused; i++) {\r
+        instr = &b->b_instr[i];\r
+        depth += opcode_stack_effect(instr->i_opcode, instr->i_oparg);\r
+        if (depth > maxdepth)\r
+            maxdepth = depth;\r
+        assert(depth >= 0); /* invalid code or bug in stackdepth() */\r
+        if (instr->i_jrel || instr->i_jabs) {\r
+            target_depth = depth;\r
+            if (instr->i_opcode == FOR_ITER) {\r
+                target_depth = depth-2;\r
+            }\r
+            else if (instr->i_opcode == SETUP_FINALLY ||\r
+                     instr->i_opcode == SETUP_EXCEPT) {\r
+                target_depth = depth+3;\r
+                if (target_depth > maxdepth)\r
+                    maxdepth = target_depth;\r
+            }\r
+            else if (instr->i_opcode == JUMP_IF_TRUE_OR_POP ||\r
+                     instr->i_opcode == JUMP_IF_FALSE_OR_POP)\r
+                depth = depth - 1;\r
+            maxdepth = stackdepth_walk(c, instr->i_target,\r
+                                       target_depth, maxdepth);\r
+            if (instr->i_opcode == JUMP_ABSOLUTE ||\r
+                instr->i_opcode == JUMP_FORWARD) {\r
+                goto out; /* remaining code is dead */\r
+            }\r
+        }\r
+    }\r
+    if (b->b_next)\r
+        maxdepth = stackdepth_walk(c, b->b_next, depth, maxdepth);\r
+out:\r
+    b->b_seen = 0;\r
+    return maxdepth;\r
+}\r
+\r
+/* Find the flow path that needs the largest stack.  We assume that\r
+ * cycles in the flow graph have no net effect on the stack depth.\r
+ */\r
+static int\r
+stackdepth(struct compiler *c)\r
+{\r
+    basicblock *b, *entryblock;\r
+    entryblock = NULL;\r
+    for (b = c->u->u_blocks; b != NULL; b = b->b_list) {\r
+        b->b_seen = 0;\r
+        b->b_startdepth = INT_MIN;\r
+        entryblock = b;\r
+    }\r
+    if (!entryblock)\r
+        return 0;\r
+    return stackdepth_walk(c, entryblock, 0, 0);\r
+}\r
+\r
+static int\r
+assemble_init(struct assembler *a, int nblocks, int firstlineno)\r
+{\r
+    memset(a, 0, sizeof(struct assembler));\r
+    a->a_lineno = firstlineno;\r
+    a->a_bytecode = PyString_FromStringAndSize(NULL, DEFAULT_CODE_SIZE);\r
+    if (!a->a_bytecode)\r
+        return 0;\r
+    a->a_lnotab = PyString_FromStringAndSize(NULL, DEFAULT_LNOTAB_SIZE);\r
+    if (!a->a_lnotab)\r
+        return 0;\r
+    if (nblocks > PY_SIZE_MAX / sizeof(basicblock *)) {\r
+        PyErr_NoMemory();\r
+        return 0;\r
+    }\r
+    a->a_postorder = (basicblock **)PyObject_Malloc(\r
+                                        sizeof(basicblock *) * nblocks);\r
+    if (!a->a_postorder) {\r
+        PyErr_NoMemory();\r
+        return 0;\r
+    }\r
+    return 1;\r
+}\r
+\r
+static void\r
+assemble_free(struct assembler *a)\r
+{\r
+    Py_XDECREF(a->a_bytecode);\r
+    Py_XDECREF(a->a_lnotab);\r
+    if (a->a_postorder)\r
+        PyObject_Free(a->a_postorder);\r
+}\r
+\r
+/* Return the size of a basic block in bytes. */\r
+\r
+static int\r
+instrsize(struct instr *instr)\r
+{\r
+    if (!instr->i_hasarg)\r
+        return 1;               /* 1 byte for the opcode*/\r
+    if (instr->i_oparg > 0xffff)\r
+        return 6;               /* 1 (opcode) + 1 (EXTENDED_ARG opcode) + 2 (oparg) + 2(oparg extended) */\r
+    return 3;                   /* 1 (opcode) + 2 (oparg) */\r
+}\r
+\r
+static int\r
+blocksize(basicblock *b)\r
+{\r
+    int i;\r
+    int size = 0;\r
+\r
+    for (i = 0; i < b->b_iused; i++)\r
+        size += instrsize(&b->b_instr[i]);\r
+    return size;\r
+}\r
+\r
+/* Appends a pair to the end of the line number table, a_lnotab, representing\r
+   the instruction's bytecode offset and line number.  See\r
+   Objects/lnotab_notes.txt for the description of the line number table. */\r
+\r
+static int\r
+assemble_lnotab(struct assembler *a, struct instr *i)\r
+{\r
+    int d_bytecode, d_lineno;\r
+    int len;\r
+    unsigned char *lnotab;\r
+\r
+    d_bytecode = a->a_offset - a->a_lineno_off;\r
+    d_lineno = i->i_lineno - a->a_lineno;\r
+\r
+    assert(d_bytecode >= 0);\r
+    assert(d_lineno >= 0);\r
+\r
+    if(d_bytecode == 0 && d_lineno == 0)\r
+        return 1;\r
+\r
+    if (d_bytecode > 255) {\r
+        int j, nbytes, ncodes = d_bytecode / 255;\r
+        nbytes = a->a_lnotab_off + 2 * ncodes;\r
+        len = PyString_GET_SIZE(a->a_lnotab);\r
+        if (nbytes >= len) {\r
+            if ((len <= INT_MAX / 2) && (len * 2 < nbytes))\r
+                len = nbytes;\r
+            else if (len <= INT_MAX / 2)\r
+                len *= 2;\r
+            else {\r
+                PyErr_NoMemory();\r
+                return 0;\r
+            }\r
+            if (_PyString_Resize(&a->a_lnotab, len) < 0)\r
+                return 0;\r
+        }\r
+        lnotab = (unsigned char *)\r
+                   PyString_AS_STRING(a->a_lnotab) + a->a_lnotab_off;\r
+        for (j = 0; j < ncodes; j++) {\r
+            *lnotab++ = 255;\r
+            *lnotab++ = 0;\r
+        }\r
+        d_bytecode -= ncodes * 255;\r
+        a->a_lnotab_off += ncodes * 2;\r
+    }\r
+    assert(d_bytecode <= 255);\r
+    if (d_lineno > 255) {\r
+        int j, nbytes, ncodes = d_lineno / 255;\r
+        nbytes = a->a_lnotab_off + 2 * ncodes;\r
+        len = PyString_GET_SIZE(a->a_lnotab);\r
+        if (nbytes >= len) {\r
+            if ((len <= INT_MAX / 2) && len * 2 < nbytes)\r
+                len = nbytes;\r
+            else if (len <= INT_MAX / 2)\r
+                len *= 2;\r
+            else {\r
+                PyErr_NoMemory();\r
+                return 0;\r
+            }\r
+            if (_PyString_Resize(&a->a_lnotab, len) < 0)\r
+                return 0;\r
+        }\r
+        lnotab = (unsigned char *)\r
+                   PyString_AS_STRING(a->a_lnotab) + a->a_lnotab_off;\r
+        *lnotab++ = d_bytecode;\r
+        *lnotab++ = 255;\r
+        d_bytecode = 0;\r
+        for (j = 1; j < ncodes; j++) {\r
+            *lnotab++ = 0;\r
+            *lnotab++ = 255;\r
+        }\r
+        d_lineno -= ncodes * 255;\r
+        a->a_lnotab_off += ncodes * 2;\r
+    }\r
+\r
+    len = PyString_GET_SIZE(a->a_lnotab);\r
+    if (a->a_lnotab_off + 2 >= len) {\r
+        if (_PyString_Resize(&a->a_lnotab, len * 2) < 0)\r
+            return 0;\r
+    }\r
+    lnotab = (unsigned char *)\r
+                    PyString_AS_STRING(a->a_lnotab) + a->a_lnotab_off;\r
+\r
+    a->a_lnotab_off += 2;\r
+    if (d_bytecode) {\r
+        *lnotab++ = d_bytecode;\r
+        *lnotab++ = d_lineno;\r
+    }\r
+    else {      /* First line of a block; def stmt, etc. */\r
+        *lnotab++ = 0;\r
+        *lnotab++ = d_lineno;\r
+    }\r
+    a->a_lineno = i->i_lineno;\r
+    a->a_lineno_off = a->a_offset;\r
+    return 1;\r
+}\r
+\r
+/* assemble_emit()\r
+   Extend the bytecode with a new instruction.\r
+   Update lnotab if necessary.\r
+*/\r
+\r
+static int\r
+assemble_emit(struct assembler *a, struct instr *i)\r
+{\r
+    int size, arg = 0, ext = 0;\r
+    Py_ssize_t len = PyString_GET_SIZE(a->a_bytecode);\r
+    char *code;\r
+\r
+    size = instrsize(i);\r
+    if (i->i_hasarg) {\r
+        arg = i->i_oparg;\r
+        ext = arg >> 16;\r
+    }\r
+    if (i->i_lineno && !assemble_lnotab(a, i))\r
+        return 0;\r
+    if (a->a_offset + size >= len) {\r
+        if (len > PY_SSIZE_T_MAX / 2)\r
+            return 0;\r
+        if (_PyString_Resize(&a->a_bytecode, len * 2) < 0)\r
+            return 0;\r
+    }\r
+    code = PyString_AS_STRING(a->a_bytecode) + a->a_offset;\r
+    a->a_offset += size;\r
+    if (size == 6) {\r
+        assert(i->i_hasarg);\r
+        *code++ = (char)EXTENDED_ARG;\r
+        *code++ = ext & 0xff;\r
+        *code++ = ext >> 8;\r
+        arg &= 0xffff;\r
+    }\r
+    *code++ = i->i_opcode;\r
+    if (i->i_hasarg) {\r
+        assert(size == 3 || size == 6);\r
+        *code++ = arg & 0xff;\r
+        *code++ = arg >> 8;\r
+    }\r
+    return 1;\r
+}\r
+\r
+static void\r
+assemble_jump_offsets(struct assembler *a, struct compiler *c)\r
+{\r
+    basicblock *b;\r
+    int bsize, totsize, extended_arg_count = 0, last_extended_arg_count;\r
+    int i;\r
+\r
+    /* Compute the size of each block and fixup jump args.\r
+       Replace block pointer with position in bytecode. */\r
+    do {\r
+        totsize = 0;\r
+        for (i = a->a_nblocks - 1; i >= 0; i--) {\r
+            b = a->a_postorder[i];\r
+            bsize = blocksize(b);\r
+            b->b_offset = totsize;\r
+            totsize += bsize;\r
+        }\r
+        last_extended_arg_count = extended_arg_count;\r
+        extended_arg_count = 0;\r
+        for (b = c->u->u_blocks; b != NULL; b = b->b_list) {\r
+            bsize = b->b_offset;\r
+            for (i = 0; i < b->b_iused; i++) {\r
+                struct instr *instr = &b->b_instr[i];\r
+                /* Relative jumps are computed relative to\r
+                   the instruction pointer after fetching\r
+                   the jump instruction.\r
+                */\r
+                bsize += instrsize(instr);\r
+                if (instr->i_jabs)\r
+                    instr->i_oparg = instr->i_target->b_offset;\r
+                else if (instr->i_jrel) {\r
+                    int delta = instr->i_target->b_offset - bsize;\r
+                    instr->i_oparg = delta;\r
+                }\r
+                else\r
+                    continue;\r
+                if (instr->i_oparg > 0xffff)\r
+                    extended_arg_count++;\r
+            }\r
+        }\r
+\r
+    /* XXX: This is an awful hack that could hurt performance, but\r
+        on the bright side it should work until we come up\r
+        with a better solution.\r
+\r
+        The issue is that in the first loop blocksize() is called\r
+        which calls instrsize() which requires i_oparg be set\r
+        appropriately.          There is a bootstrap problem because\r
+        i_oparg is calculated in the second loop above.\r
+\r
+        So we loop until we stop seeing new EXTENDED_ARGs.\r
+        The only EXTENDED_ARGs that could be popping up are\r
+        ones in jump instructions.  So this should converge\r
+        fairly quickly.\r
+    */\r
+    } while (last_extended_arg_count != extended_arg_count);\r
+}\r
+\r
+static PyObject *\r
+dict_keys_inorder(PyObject *dict, int offset)\r
+{\r
+    PyObject *tuple, *k, *v;\r
+    Py_ssize_t i, pos = 0, size = PyDict_Size(dict);\r
+\r
+    tuple = PyTuple_New(size);\r
+    if (tuple == NULL)\r
+        return NULL;\r
+    while (PyDict_Next(dict, &pos, &k, &v)) {\r
+        i = PyInt_AS_LONG(v);\r
+        /* The keys of the dictionary are tuples. (see compiler_add_o)\r
+           The object we want is always first, though. */\r
+        k = PyTuple_GET_ITEM(k, 0);\r
+        Py_INCREF(k);\r
+        assert((i - offset) < size);\r
+        assert((i - offset) >= 0);\r
+        PyTuple_SET_ITEM(tuple, i - offset, k);\r
+    }\r
+    return tuple;\r
+}\r
+\r
+static int\r
+compute_code_flags(struct compiler *c)\r
+{\r
+    PySTEntryObject *ste = c->u->u_ste;\r
+    int flags = 0, n;\r
+    if (ste->ste_type != ModuleBlock)\r
+        flags |= CO_NEWLOCALS;\r
+    if (ste->ste_type == FunctionBlock) {\r
+        if (!ste->ste_unoptimized)\r
+            flags |= CO_OPTIMIZED;\r
+        if (ste->ste_nested)\r
+            flags |= CO_NESTED;\r
+        if (ste->ste_generator)\r
+            flags |= CO_GENERATOR;\r
+        if (ste->ste_varargs)\r
+            flags |= CO_VARARGS;\r
+        if (ste->ste_varkeywords)\r
+            flags |= CO_VARKEYWORDS;\r
+    }\r
+\r
+    /* (Only) inherit compilerflags in PyCF_MASK */\r
+    flags |= (c->c_flags->cf_flags & PyCF_MASK);\r
+\r
+    n = PyDict_Size(c->u->u_freevars);\r
+    if (n < 0)\r
+        return -1;\r
+    if (n == 0) {\r
+        n = PyDict_Size(c->u->u_cellvars);\r
+        if (n < 0)\r
+        return -1;\r
+        if (n == 0) {\r
+        flags |= CO_NOFREE;\r
+        }\r
+    }\r
+\r
+    return flags;\r
+}\r
+\r
+static PyCodeObject *\r
+makecode(struct compiler *c, struct assembler *a)\r
+{\r
+    PyObject *tmp;\r
+    PyCodeObject *co = NULL;\r
+    PyObject *consts = NULL;\r
+    PyObject *names = NULL;\r
+    PyObject *varnames = NULL;\r
+    PyObject *filename = NULL;\r
+    PyObject *name = NULL;\r
+    PyObject *freevars = NULL;\r
+    PyObject *cellvars = NULL;\r
+    PyObject *bytecode = NULL;\r
+    int nlocals, flags;\r
+\r
+    tmp = dict_keys_inorder(c->u->u_consts, 0);\r
+    if (!tmp)\r
+        goto error;\r
+    consts = PySequence_List(tmp); /* optimize_code requires a list */\r
+    Py_DECREF(tmp);\r
+\r
+    names = dict_keys_inorder(c->u->u_names, 0);\r
+    varnames = dict_keys_inorder(c->u->u_varnames, 0);\r
+    if (!consts || !names || !varnames)\r
+        goto error;\r
+\r
+    cellvars = dict_keys_inorder(c->u->u_cellvars, 0);\r
+    if (!cellvars)\r
+        goto error;\r
+    freevars = dict_keys_inorder(c->u->u_freevars, PyTuple_Size(cellvars));\r
+    if (!freevars)\r
+        goto error;\r
+    filename = PyString_FromString(c->c_filename);\r
+    if (!filename)\r
+        goto error;\r
+\r
+    nlocals = PyDict_Size(c->u->u_varnames);\r
+    flags = compute_code_flags(c);\r
+    if (flags < 0)\r
+        goto error;\r
+\r
+    bytecode = PyCode_Optimize(a->a_bytecode, consts, names, a->a_lnotab);\r
+    if (!bytecode)\r
+        goto error;\r
+\r
+    tmp = PyList_AsTuple(consts); /* PyCode_New requires a tuple */\r
+    if (!tmp)\r
+        goto error;\r
+    Py_DECREF(consts);\r
+    consts = tmp;\r
+\r
+    co = PyCode_New(c->u->u_argcount, nlocals, stackdepth(c), flags,\r
+                    bytecode, consts, names, varnames,\r
+                    freevars, cellvars,\r
+                    filename, c->u->u_name,\r
+                    c->u->u_firstlineno,\r
+                    a->a_lnotab);\r
+ error:\r
+    Py_XDECREF(consts);\r
+    Py_XDECREF(names);\r
+    Py_XDECREF(varnames);\r
+    Py_XDECREF(filename);\r
+    Py_XDECREF(name);\r
+    Py_XDECREF(freevars);\r
+    Py_XDECREF(cellvars);\r
+    Py_XDECREF(bytecode);\r
+    return co;\r
+}\r
+\r
+\r
+/* For debugging purposes only */\r
+#if 0\r
+static void\r
+dump_instr(const struct instr *i)\r
+{\r
+    const char *jrel = i->i_jrel ? "jrel " : "";\r
+    const char *jabs = i->i_jabs ? "jabs " : "";\r
+    char arg[128];\r
+\r
+    *arg = '\0';\r
+    if (i->i_hasarg)\r
+        sprintf(arg, "arg: %d ", i->i_oparg);\r
+\r
+    fprintf(stderr, "line: %d, opcode: %d %s%s%s\n",\r
+                    i->i_lineno, i->i_opcode, arg, jabs, jrel);\r
+}\r
+\r
+static void\r
+dump_basicblock(const basicblock *b)\r
+{\r
+    const char *seen = b->b_seen ? "seen " : "";\r
+    const char *b_return = b->b_return ? "return " : "";\r
+    fprintf(stderr, "used: %d, depth: %d, offset: %d %s%s\n",\r
+        b->b_iused, b->b_startdepth, b->b_offset, seen, b_return);\r
+    if (b->b_instr) {\r
+        int i;\r
+        for (i = 0; i < b->b_iused; i++) {\r
+            fprintf(stderr, "  [%02d] ", i);\r
+            dump_instr(b->b_instr + i);\r
+        }\r
+    }\r
+}\r
+#endif\r
+\r
+static PyCodeObject *\r
+assemble(struct compiler *c, int addNone)\r
+{\r
+    basicblock *b, *entryblock;\r
+    struct assembler a;\r
+    int i, j, nblocks;\r
+    PyCodeObject *co = NULL;\r
+\r
+    /* Make sure every block that falls off the end returns None.\r
+       XXX NEXT_BLOCK() isn't quite right, because if the last\r
+       block ends with a jump or return b_next shouldn't set.\r
+     */\r
+    if (!c->u->u_curblock->b_return) {\r
+        NEXT_BLOCK(c);\r
+        if (addNone)\r
+            ADDOP_O(c, LOAD_CONST, Py_None, consts);\r
+        ADDOP(c, RETURN_VALUE);\r
+    }\r
+\r
+    nblocks = 0;\r
+    entryblock = NULL;\r
+    for (b = c->u->u_blocks; b != NULL; b = b->b_list) {\r
+        nblocks++;\r
+        entryblock = b;\r
+    }\r
+\r
+    /* Set firstlineno if it wasn't explicitly set. */\r
+    if (!c->u->u_firstlineno) {\r
+        if (entryblock && entryblock->b_instr)\r
+            c->u->u_firstlineno = entryblock->b_instr->i_lineno;\r
+        else\r
+            c->u->u_firstlineno = 1;\r
+    }\r
+    if (!assemble_init(&a, nblocks, c->u->u_firstlineno))\r
+        goto error;\r
+    dfs(c, entryblock, &a);\r
+\r
+    /* Can't modify the bytecode after computing jump offsets. */\r
+    assemble_jump_offsets(&a, c);\r
+\r
+    /* Emit code in reverse postorder from dfs. */\r
+    for (i = a.a_nblocks - 1; i >= 0; i--) {\r
+        b = a.a_postorder[i];\r
+        for (j = 0; j < b->b_iused; j++)\r
+            if (!assemble_emit(&a, &b->b_instr[j]))\r
+                goto error;\r
+    }\r
+\r
+    if (_PyString_Resize(&a.a_lnotab, a.a_lnotab_off) < 0)\r
+        goto error;\r
+    if (_PyString_Resize(&a.a_bytecode, a.a_offset) < 0)\r
+        goto error;\r
+\r
+    co = makecode(c, &a);\r
+ error:\r
+    assemble_free(&a);\r
+    return co;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/dtoa.c b/AppPkg/Applications/Python/Python-2.7.10/Python/dtoa.c
new file mode 100644 (file)
index 0000000..655e366
--- /dev/null
@@ -0,0 +1,2949 @@
+/****************************************************************\r
+ *\r
+ * The author of this software is David M. Gay.\r
+ *\r
+ * Copyright (c) 1991, 2000, 2001 by Lucent Technologies.\r
+ *\r
+ * Permission to use, copy, modify, and distribute this software for any\r
+ * purpose without fee is hereby granted, provided that this entire notice\r
+ * is included in all copies of any software which is or includes a copy\r
+ * or modification of this software and in all copies of the supporting\r
+ * documentation for such software.\r
+ *\r
+ * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED\r
+ * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY\r
+ * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY\r
+ * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.\r
+ *\r
+ ***************************************************************/\r
+\r
+/****************************************************************\r
+ * This is dtoa.c by David M. Gay, downloaded from\r
+ * http://www.netlib.org/fp/dtoa.c on April 15, 2009 and modified for\r
+ * inclusion into the Python core by Mark E. T. Dickinson and Eric V. Smith.\r
+ *\r
+ * Please remember to check http://www.netlib.org/fp regularly (and especially\r
+ * before any Python release) for bugfixes and updates.\r
+ *\r
+ * The major modifications from Gay's original code are as follows:\r
+ *\r
+ *  0. The original code has been specialized to Python's needs by removing\r
+ *     many of the #ifdef'd sections.  In particular, code to support VAX and\r
+ *     IBM floating-point formats, hex NaNs, hex floats, locale-aware\r
+ *     treatment of the decimal point, and setting of the inexact flag have\r
+ *     been removed.\r
+ *\r
+ *  1. We use PyMem_Malloc and PyMem_Free in place of malloc and free.\r
+ *\r
+ *  2. The public functions strtod, dtoa and freedtoa all now have\r
+ *     a _Py_dg_ prefix.\r
+ *\r
+ *  3. Instead of assuming that PyMem_Malloc always succeeds, we thread\r
+ *     PyMem_Malloc failures through the code.  The functions\r
+ *\r
+ *       Balloc, multadd, s2b, i2b, mult, pow5mult, lshift, diff, d2b\r
+ *\r
+ *     of return type *Bigint all return NULL to indicate a malloc failure.\r
+ *     Similarly, rv_alloc and nrv_alloc (return type char *) return NULL on\r
+ *     failure.  bigcomp now has return type int (it used to be void) and\r
+ *     returns -1 on failure and 0 otherwise.  _Py_dg_dtoa returns NULL\r
+ *     on failure.  _Py_dg_strtod indicates failure due to malloc failure\r
+ *     by returning -1.0, setting errno=ENOMEM and *se to s00.\r
+ *\r
+ *  4. The static variable dtoa_result has been removed.  Callers of\r
+ *     _Py_dg_dtoa are expected to call _Py_dg_freedtoa to free\r
+ *     the memory allocated by _Py_dg_dtoa.\r
+ *\r
+ *  5. The code has been reformatted to better fit with Python's\r
+ *     C style guide (PEP 7).\r
+ *\r
+ *  6. A bug in the memory allocation has been fixed: to avoid FREEing memory\r
+ *     that hasn't been MALLOC'ed, private_mem should only be used when k <=\r
+ *     Kmax.\r
+ *\r
+ *  7. _Py_dg_strtod has been modified so that it doesn't accept strings with\r
+ *     leading whitespace.\r
+ *\r
+ ***************************************************************/\r
+\r
+/* Please send bug reports for the original dtoa.c code to David M. Gay (dmg\r
+ * at acm dot org, with " at " changed at "@" and " dot " changed to ".").\r
+ * Please report bugs for this modified version using the Python issue tracker\r
+ * (http://bugs.python.org). */\r
+\r
+/* On a machine with IEEE extended-precision registers, it is\r
+ * necessary to specify double-precision (53-bit) rounding precision\r
+ * before invoking strtod or dtoa.  If the machine uses (the equivalent\r
+ * of) Intel 80x87 arithmetic, the call\r
+ *      _control87(PC_53, MCW_PC);\r
+ * does this with many compilers.  Whether this or another call is\r
+ * appropriate depends on the compiler; for this to work, it may be\r
+ * necessary to #include "float.h" or another system-dependent header\r
+ * file.\r
+ */\r
+\r
+/* strtod for IEEE-, VAX-, and IBM-arithmetic machines.\r
+ *\r
+ * This strtod returns a nearest machine number to the input decimal\r
+ * string (or sets errno to ERANGE).  With IEEE arithmetic, ties are\r
+ * broken by the IEEE round-even rule.  Otherwise ties are broken by\r
+ * biased rounding (add half and chop).\r
+ *\r
+ * Inspired loosely by William D. Clinger's paper "How to Read Floating\r
+ * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 92-101].\r
+ *\r
+ * Modifications:\r
+ *\r
+ *      1. We only require IEEE, IBM, or VAX double-precision\r
+ *              arithmetic (not IEEE double-extended).\r
+ *      2. We get by with floating-point arithmetic in a case that\r
+ *              Clinger missed -- when we're computing d * 10^n\r
+ *              for a small integer d and the integer n is not too\r
+ *              much larger than 22 (the maximum integer k for which\r
+ *              we can represent 10^k exactly), we may be able to\r
+ *              compute (d*10^k) * 10^(e-k) with just one roundoff.\r
+ *      3. Rather than a bit-at-a-time adjustment of the binary\r
+ *              result in the hard case, we use floating-point\r
+ *              arithmetic to determine the adjustment to within\r
+ *              one bit; only in really hard cases do we need to\r
+ *              compute a second residual.\r
+ *      4. Because of 3., we don't need a large table of powers of 10\r
+ *              for ten-to-e (just some small tables, e.g. of 10^k\r
+ *              for 0 <= k <= 22).\r
+ */\r
+\r
+/* Linking of Python's #defines to Gay's #defines starts here. */\r
+\r
+#include "Python.h"\r
+\r
+/* if PY_NO_SHORT_FLOAT_REPR is defined, then don't even try to compile\r
+   the following code */\r
+#ifndef PY_NO_SHORT_FLOAT_REPR\r
+\r
+#include "float.h"\r
+\r
+#define MALLOC PyMem_Malloc\r
+#define FREE PyMem_Free\r
+\r
+/* This code should also work for ARM mixed-endian format on little-endian\r
+   machines, where doubles have byte order 45670123 (in increasing address\r
+   order, 0 being the least significant byte). */\r
+#ifdef DOUBLE_IS_LITTLE_ENDIAN_IEEE754\r
+#  define IEEE_8087\r
+#endif\r
+#if defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) ||  \\r
+  defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754)\r
+#  define IEEE_MC68k\r
+#endif\r
+#if defined(IEEE_8087) + defined(IEEE_MC68k) != 1\r
+#error "Exactly one of IEEE_8087 or IEEE_MC68k should be defined."\r
+#endif\r
+\r
+/* The code below assumes that the endianness of integers matches the\r
+   endianness of the two 32-bit words of a double.  Check this. */\r
+#if defined(WORDS_BIGENDIAN) && (defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) || \\r
+                                 defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754))\r
+#error "doubles and ints have incompatible endianness"\r
+#endif\r
+\r
+#if !defined(WORDS_BIGENDIAN) && defined(DOUBLE_IS_BIG_ENDIAN_IEEE754)\r
+#error "doubles and ints have incompatible endianness"\r
+#endif\r
+\r
+\r
+#if defined(HAVE_UINT32_T) && defined(HAVE_INT32_T)\r
+typedef PY_UINT32_T ULong;\r
+typedef PY_INT32_T Long;\r
+#else\r
+#error "Failed to find an exact-width 32-bit integer type"\r
+#endif\r
+\r
+#if defined(HAVE_UINT64_T)\r
+#define ULLong PY_UINT64_T\r
+#else\r
+#undef ULLong\r
+#endif\r
+\r
+#undef DEBUG\r
+#ifdef Py_DEBUG\r
+#define DEBUG\r
+#endif\r
+\r
+/* End Python #define linking */\r
+\r
+#ifdef DEBUG\r
+#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}\r
+#endif\r
+\r
+#ifndef PRIVATE_MEM\r
+#define PRIVATE_MEM 2304\r
+#endif\r
+#define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))\r
+static double private_mem[PRIVATE_mem], *pmem_next = private_mem;\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef union { double d; ULong L[2]; } U;\r
+\r
+#ifdef IEEE_8087\r
+#define word0(x) (x)->L[1]\r
+#define word1(x) (x)->L[0]\r
+#else\r
+#define word0(x) (x)->L[0]\r
+#define word1(x) (x)->L[1]\r
+#endif\r
+#define dval(x) (x)->d\r
+\r
+#ifndef STRTOD_DIGLIM\r
+#define STRTOD_DIGLIM 40\r
+#endif\r
+\r
+/* maximum permitted exponent value for strtod; exponents larger than\r
+   MAX_ABS_EXP in absolute value get truncated to +-MAX_ABS_EXP.  MAX_ABS_EXP\r
+   should fit into an int. */\r
+#ifndef MAX_ABS_EXP\r
+#define MAX_ABS_EXP 1100000000U\r
+#endif\r
+/* Bound on length of pieces of input strings in _Py_dg_strtod; specifically,\r
+   this is used to bound the total number of digits ignoring leading zeros and\r
+   the number of digits that follow the decimal point.  Ideally, MAX_DIGITS\r
+   should satisfy MAX_DIGITS + 400 < MAX_ABS_EXP; that ensures that the\r
+   exponent clipping in _Py_dg_strtod can't affect the value of the output. */\r
+#ifndef MAX_DIGITS\r
+#define MAX_DIGITS 1000000000U\r
+#endif\r
+\r
+/* Guard against trying to use the above values on unusual platforms with ints\r
+ * of width less than 32 bits. */\r
+#if MAX_ABS_EXP > INT_MAX\r
+#error "MAX_ABS_EXP should fit in an int"\r
+#endif\r
+#if MAX_DIGITS > INT_MAX\r
+#error "MAX_DIGITS should fit in an int"\r
+#endif\r
+\r
+/* The following definition of Storeinc is appropriate for MIPS processors.\r
+ * An alternative that might be better on some machines is\r
+ * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)\r
+ */\r
+#if defined(IEEE_8087)\r
+#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b,  \\r
+                         ((unsigned short *)a)[0] = (unsigned short)c, a++)\r
+#else\r
+#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b,  \\r
+                         ((unsigned short *)a)[1] = (unsigned short)c, a++)\r
+#endif\r
+\r
+/* #define P DBL_MANT_DIG */\r
+/* Ten_pmax = floor(P*log(2)/log(5)) */\r
+/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */\r
+/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */\r
+/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */\r
+\r
+#define Exp_shift  20\r
+#define Exp_shift1 20\r
+#define Exp_msk1    0x100000\r
+#define Exp_msk11   0x100000\r
+#define Exp_mask  0x7ff00000\r
+#define P 53\r
+#define Nbits 53\r
+#define Bias 1023\r
+#define Emax 1023\r
+#define Emin (-1022)\r
+#define Etiny (-1074)  /* smallest denormal is 2**Etiny */\r
+#define Exp_1  0x3ff00000\r
+#define Exp_11 0x3ff00000\r
+#define Ebits 11\r
+#define Frac_mask  0xfffff\r
+#define Frac_mask1 0xfffff\r
+#define Ten_pmax 22\r
+#define Bletch 0x10\r
+#define Bndry_mask  0xfffff\r
+#define Bndry_mask1 0xfffff\r
+#define Sign_bit 0x80000000\r
+#define Log2P 1\r
+#define Tiny0 0\r
+#define Tiny1 1\r
+#define Quick_max 14\r
+#define Int_max 14\r
+\r
+#ifndef Flt_Rounds\r
+#ifdef FLT_ROUNDS\r
+#define Flt_Rounds FLT_ROUNDS\r
+#else\r
+#define Flt_Rounds 1\r
+#endif\r
+#endif /*Flt_Rounds*/\r
+\r
+#define Rounding Flt_Rounds\r
+\r
+#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))\r
+#define Big1 0xffffffff\r
+\r
+/* struct BCinfo is used to pass information from _Py_dg_strtod to bigcomp */\r
+\r
+typedef struct BCinfo BCinfo;\r
+struct\r
+BCinfo {\r
+    int e0, nd, nd0, scale;\r
+};\r
+\r
+#define FFFFFFFF 0xffffffffUL\r
+\r
+#define Kmax 7\r
+\r
+/* struct Bigint is used to represent arbitrary-precision integers.  These\r
+   integers are stored in sign-magnitude format, with the magnitude stored as\r
+   an array of base 2**32 digits.  Bigints are always normalized: if x is a\r
+   Bigint then x->wds >= 1, and either x->wds == 1 or x[wds-1] is nonzero.\r
+\r
+   The Bigint fields are as follows:\r
+\r
+     - next is a header used by Balloc and Bfree to keep track of lists\r
+         of freed Bigints;  it's also used for the linked list of\r
+         powers of 5 of the form 5**2**i used by pow5mult.\r
+     - k indicates which pool this Bigint was allocated from\r
+     - maxwds is the maximum number of words space was allocated for\r
+       (usually maxwds == 2**k)\r
+     - sign is 1 for negative Bigints, 0 for positive.  The sign is unused\r
+       (ignored on inputs, set to 0 on outputs) in almost all operations\r
+       involving Bigints: a notable exception is the diff function, which\r
+       ignores signs on inputs but sets the sign of the output correctly.\r
+     - wds is the actual number of significant words\r
+     - x contains the vector of words (digits) for this Bigint, from least\r
+       significant (x[0]) to most significant (x[wds-1]).\r
+*/\r
+\r
+struct\r
+Bigint {\r
+    struct Bigint *next;\r
+    int k, maxwds, sign, wds;\r
+    ULong x[1];\r
+};\r
+\r
+typedef struct Bigint Bigint;\r
+\r
+#ifndef Py_USING_MEMORY_DEBUGGER\r
+\r
+/* Memory management: memory is allocated from, and returned to, Kmax+1 pools\r
+   of memory, where pool k (0 <= k <= Kmax) is for Bigints b with b->maxwds ==\r
+   1 << k.  These pools are maintained as linked lists, with freelist[k]\r
+   pointing to the head of the list for pool k.\r
+\r
+   On allocation, if there's no free slot in the appropriate pool, MALLOC is\r
+   called to get more memory.  This memory is not returned to the system until\r
+   Python quits.  There's also a private memory pool that's allocated from\r
+   in preference to using MALLOC.\r
+\r
+   For Bigints with more than (1 << Kmax) digits (which implies at least 1233\r
+   decimal digits), memory is directly allocated using MALLOC, and freed using\r
+   FREE.\r
+\r
+   XXX: it would be easy to bypass this memory-management system and\r
+   translate each call to Balloc into a call to PyMem_Malloc, and each\r
+   Bfree to PyMem_Free.  Investigate whether this has any significant\r
+   performance on impact. */\r
+\r
+static Bigint *freelist[Kmax+1];\r
+\r
+/* Allocate space for a Bigint with up to 1<<k digits */\r
+\r
+static Bigint *\r
+Balloc(int k)\r
+{\r
+    int x;\r
+    Bigint *rv;\r
+    unsigned int len;\r
+\r
+    if (k <= Kmax && (rv = freelist[k]))\r
+        freelist[k] = rv->next;\r
+    else {\r
+        x = 1 << k;\r
+        len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)\r
+            /sizeof(double);\r
+        if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) {\r
+            rv = (Bigint*)pmem_next;\r
+            pmem_next += len;\r
+        }\r
+        else {\r
+            rv = (Bigint*)MALLOC(len*sizeof(double));\r
+            if (rv == NULL)\r
+                return NULL;\r
+        }\r
+        rv->k = k;\r
+        rv->maxwds = x;\r
+    }\r
+    rv->sign = rv->wds = 0;\r
+    return rv;\r
+}\r
+\r
+/* Free a Bigint allocated with Balloc */\r
+\r
+static void\r
+Bfree(Bigint *v)\r
+{\r
+    if (v) {\r
+        if (v->k > Kmax)\r
+            FREE((void*)v);\r
+        else {\r
+            v->next = freelist[v->k];\r
+            freelist[v->k] = v;\r
+        }\r
+    }\r
+}\r
+\r
+#else\r
+\r
+/* Alternative versions of Balloc and Bfree that use PyMem_Malloc and\r
+   PyMem_Free directly in place of the custom memory allocation scheme above.\r
+   These are provided for the benefit of memory debugging tools like\r
+   Valgrind. */\r
+\r
+/* Allocate space for a Bigint with up to 1<<k digits */\r
+\r
+static Bigint *\r
+Balloc(int k)\r
+{\r
+    int x;\r
+    Bigint *rv;\r
+    unsigned int len;\r
+\r
+    x = 1 << k;\r
+    len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)\r
+        /sizeof(double);\r
+\r
+    rv = (Bigint*)MALLOC(len*sizeof(double));\r
+    if (rv == NULL)\r
+        return NULL;\r
+\r
+    rv->k = k;\r
+    rv->maxwds = x;\r
+    rv->sign = rv->wds = 0;\r
+    return rv;\r
+}\r
+\r
+/* Free a Bigint allocated with Balloc */\r
+\r
+static void\r
+Bfree(Bigint *v)\r
+{\r
+    if (v) {\r
+        FREE((void*)v);\r
+    }\r
+}\r
+\r
+#endif /* Py_USING_MEMORY_DEBUGGER */\r
+\r
+#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign,   \\r
+                          y->wds*sizeof(Long) + 2*sizeof(int))\r
+\r
+/* Multiply a Bigint b by m and add a.  Either modifies b in place and returns\r
+   a pointer to the modified b, or Bfrees b and returns a pointer to a copy.\r
+   On failure, return NULL.  In this case, b will have been already freed. */\r
+\r
+static Bigint *\r
+multadd(Bigint *b, int m, int a)       /* multiply by m and add a */\r
+{\r
+    int i, wds;\r
+#ifdef ULLong\r
+    ULong *x;\r
+    ULLong carry, y;\r
+#else\r
+    ULong carry, *x, y;\r
+    ULong xi, z;\r
+#endif\r
+    Bigint *b1;\r
+\r
+    wds = b->wds;\r
+    x = b->x;\r
+    i = 0;\r
+    carry = a;\r
+    do {\r
+#ifdef ULLong\r
+        y = *x * (ULLong)m + carry;\r
+        carry = y >> 32;\r
+        *x++ = (ULong)(y & FFFFFFFF);\r
+#else\r
+        xi = *x;\r
+        y = (xi & 0xffff) * m + carry;\r
+        z = (xi >> 16) * m + (y >> 16);\r
+        carry = z >> 16;\r
+        *x++ = (z << 16) + (y & 0xffff);\r
+#endif\r
+    }\r
+    while(++i < wds);\r
+    if (carry) {\r
+        if (wds >= b->maxwds) {\r
+            b1 = Balloc(b->k+1);\r
+            if (b1 == NULL){\r
+                Bfree(b);\r
+                return NULL;\r
+            }\r
+            Bcopy(b1, b);\r
+            Bfree(b);\r
+            b = b1;\r
+        }\r
+        b->x[wds++] = (ULong)carry;\r
+        b->wds = wds;\r
+    }\r
+    return b;\r
+}\r
+\r
+/* convert a string s containing nd decimal digits (possibly containing a\r
+   decimal separator at position nd0, which is ignored) to a Bigint.  This\r
+   function carries on where the parsing code in _Py_dg_strtod leaves off: on\r
+   entry, y9 contains the result of converting the first 9 digits.  Returns\r
+   NULL on failure. */\r
+\r
+static Bigint *\r
+s2b(const char *s, int nd0, int nd, ULong y9)\r
+{\r
+    Bigint *b;\r
+    int i, k;\r
+    Long x, y;\r
+\r
+    x = (nd + 8) / 9;\r
+    for(k = 0, y = 1; x > y; y <<= 1, k++) ;\r
+    b = Balloc(k);\r
+    if (b == NULL)\r
+        return NULL;\r
+    b->x[0] = y9;\r
+    b->wds = 1;\r
+\r
+    if (nd <= 9)\r
+      return b;\r
+\r
+    s += 9;\r
+    for (i = 9; i < nd0; i++) {\r
+        b = multadd(b, 10, *s++ - '0');\r
+        if (b == NULL)\r
+            return NULL;\r
+    }\r
+    s++;\r
+    for(; i < nd; i++) {\r
+        b = multadd(b, 10, *s++ - '0');\r
+        if (b == NULL)\r
+            return NULL;\r
+    }\r
+    return b;\r
+}\r
+\r
+/* count leading 0 bits in the 32-bit integer x. */\r
+\r
+static int\r
+hi0bits(ULong x)\r
+{\r
+    int k = 0;\r
+\r
+    if (!(x & 0xffff0000)) {\r
+        k = 16;\r
+        x <<= 16;\r
+    }\r
+    if (!(x & 0xff000000)) {\r
+        k += 8;\r
+        x <<= 8;\r
+    }\r
+    if (!(x & 0xf0000000)) {\r
+        k += 4;\r
+        x <<= 4;\r
+    }\r
+    if (!(x & 0xc0000000)) {\r
+        k += 2;\r
+        x <<= 2;\r
+    }\r
+    if (!(x & 0x80000000)) {\r
+        k++;\r
+        if (!(x & 0x40000000))\r
+            return 32;\r
+    }\r
+    return k;\r
+}\r
+\r
+/* count trailing 0 bits in the 32-bit integer y, and shift y right by that\r
+   number of bits. */\r
+\r
+static int\r
+lo0bits(ULong *y)\r
+{\r
+    int k;\r
+    ULong x = *y;\r
+\r
+    if (x & 7) {\r
+        if (x & 1)\r
+            return 0;\r
+        if (x & 2) {\r
+            *y = x >> 1;\r
+            return 1;\r
+        }\r
+        *y = x >> 2;\r
+        return 2;\r
+    }\r
+    k = 0;\r
+    if (!(x & 0xffff)) {\r
+        k = 16;\r
+        x >>= 16;\r
+    }\r
+    if (!(x & 0xff)) {\r
+        k += 8;\r
+        x >>= 8;\r
+    }\r
+    if (!(x & 0xf)) {\r
+        k += 4;\r
+        x >>= 4;\r
+    }\r
+    if (!(x & 0x3)) {\r
+        k += 2;\r
+        x >>= 2;\r
+    }\r
+    if (!(x & 1)) {\r
+        k++;\r
+        x >>= 1;\r
+        if (!x)\r
+            return 32;\r
+    }\r
+    *y = x;\r
+    return k;\r
+}\r
+\r
+/* convert a small nonnegative integer to a Bigint */\r
+\r
+static Bigint *\r
+i2b(int i)\r
+{\r
+    Bigint *b;\r
+\r
+    b = Balloc(1);\r
+    if (b == NULL)\r
+        return NULL;\r
+    b->x[0] = i;\r
+    b->wds = 1;\r
+    return b;\r
+}\r
+\r
+/* multiply two Bigints.  Returns a new Bigint, or NULL on failure.  Ignores\r
+   the signs of a and b. */\r
+\r
+static Bigint *\r
+mult(Bigint *a, Bigint *b)\r
+{\r
+    Bigint *c;\r
+    int k, wa, wb, wc;\r
+    ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0;\r
+    ULong y;\r
+#ifdef ULLong\r
+    ULLong carry, z;\r
+#else\r
+    ULong carry, z;\r
+    ULong z2;\r
+#endif\r
+\r
+    if ((!a->x[0] && a->wds == 1) || (!b->x[0] && b->wds == 1)) {\r
+        c = Balloc(0);\r
+        if (c == NULL)\r
+            return NULL;\r
+        c->wds = 1;\r
+        c->x[0] = 0;\r
+        return c;\r
+    }\r
+\r
+    if (a->wds < b->wds) {\r
+        c = a;\r
+        a = b;\r
+        b = c;\r
+    }\r
+    k = a->k;\r
+    wa = a->wds;\r
+    wb = b->wds;\r
+    wc = wa + wb;\r
+    if (wc > a->maxwds)\r
+        k++;\r
+    c = Balloc(k);\r
+    if (c == NULL)\r
+        return NULL;\r
+    for(x = c->x, xa = x + wc; x < xa; x++)\r
+        *x = 0;\r
+    xa = a->x;\r
+    xae = xa + wa;\r
+    xb = b->x;\r
+    xbe = xb + wb;\r
+    xc0 = c->x;\r
+#ifdef ULLong\r
+    for(; xb < xbe; xc0++) {\r
+        if ((y = *xb++)) {\r
+            x = xa;\r
+            xc = xc0;\r
+            carry = 0;\r
+            do {\r
+                z = *x++ * (ULLong)y + *xc + carry;\r
+                carry = z >> 32;\r
+                *xc++ = (ULong)(z & FFFFFFFF);\r
+            }\r
+            while(x < xae);\r
+            *xc = (ULong)carry;\r
+        }\r
+    }\r
+#else\r
+    for(; xb < xbe; xb++, xc0++) {\r
+        if (y = *xb & 0xffff) {\r
+            x = xa;\r
+            xc = xc0;\r
+            carry = 0;\r
+            do {\r
+                z = (*x & 0xffff) * y + (*xc & 0xffff) + carry;\r
+                carry = z >> 16;\r
+                z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;\r
+                carry = z2 >> 16;\r
+                Storeinc(xc, z2, z);\r
+            }\r
+            while(x < xae);\r
+            *xc = carry;\r
+        }\r
+        if (y = *xb >> 16) {\r
+            x = xa;\r
+            xc = xc0;\r
+            carry = 0;\r
+            z2 = *xc;\r
+            do {\r
+                z = (*x & 0xffff) * y + (*xc >> 16) + carry;\r
+                carry = z >> 16;\r
+                Storeinc(xc, z, z2);\r
+                z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;\r
+                carry = z2 >> 16;\r
+            }\r
+            while(x < xae);\r
+            *xc = z2;\r
+        }\r
+    }\r
+#endif\r
+    for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ;\r
+    c->wds = wc;\r
+    return c;\r
+}\r
+\r
+#ifndef Py_USING_MEMORY_DEBUGGER\r
+\r
+/* p5s is a linked list of powers of 5 of the form 5**(2**i), i >= 2 */\r
+\r
+static Bigint *p5s;\r
+\r
+/* multiply the Bigint b by 5**k.  Returns a pointer to the result, or NULL on\r
+   failure; if the returned pointer is distinct from b then the original\r
+   Bigint b will have been Bfree'd.   Ignores the sign of b. */\r
+\r
+static Bigint *\r
+pow5mult(Bigint *b, int k)\r
+{\r
+    Bigint *b1, *p5, *p51;\r
+    int i;\r
+    static int p05[3] = { 5, 25, 125 };\r
+\r
+    if ((i = k & 3)) {\r
+        b = multadd(b, p05[i-1], 0);\r
+        if (b == NULL)\r
+            return NULL;\r
+    }\r
+\r
+    if (!(k >>= 2))\r
+        return b;\r
+    p5 = p5s;\r
+    if (!p5) {\r
+        /* first time */\r
+        p5 = i2b(625);\r
+        if (p5 == NULL) {\r
+            Bfree(b);\r
+            return NULL;\r
+        }\r
+        p5s = p5;\r
+        p5->next = 0;\r
+    }\r
+    for(;;) {\r
+        if (k & 1) {\r
+            b1 = mult(b, p5);\r
+            Bfree(b);\r
+            b = b1;\r
+            if (b == NULL)\r
+                return NULL;\r
+        }\r
+        if (!(k >>= 1))\r
+            break;\r
+        p51 = p5->next;\r
+        if (!p51) {\r
+            p51 = mult(p5,p5);\r
+            if (p51 == NULL) {\r
+                Bfree(b);\r
+                return NULL;\r
+            }\r
+            p51->next = 0;\r
+            p5->next = p51;\r
+        }\r
+        p5 = p51;\r
+    }\r
+    return b;\r
+}\r
+\r
+#else\r
+\r
+/* Version of pow5mult that doesn't cache powers of 5. Provided for\r
+   the benefit of memory debugging tools like Valgrind. */\r
+\r
+static Bigint *\r
+pow5mult(Bigint *b, int k)\r
+{\r
+    Bigint *b1, *p5, *p51;\r
+    int i;\r
+    static int p05[3] = { 5, 25, 125 };\r
+\r
+    if ((i = k & 3)) {\r
+        b = multadd(b, p05[i-1], 0);\r
+        if (b == NULL)\r
+            return NULL;\r
+    }\r
+\r
+    if (!(k >>= 2))\r
+        return b;\r
+    p5 = i2b(625);\r
+    if (p5 == NULL) {\r
+        Bfree(b);\r
+        return NULL;\r
+    }\r
+\r
+    for(;;) {\r
+        if (k & 1) {\r
+            b1 = mult(b, p5);\r
+            Bfree(b);\r
+            b = b1;\r
+            if (b == NULL) {\r
+                Bfree(p5);\r
+                return NULL;\r
+            }\r
+        }\r
+        if (!(k >>= 1))\r
+            break;\r
+        p51 = mult(p5, p5);\r
+        Bfree(p5);\r
+        p5 = p51;\r
+        if (p5 == NULL) {\r
+            Bfree(b);\r
+            return NULL;\r
+        }\r
+    }\r
+    Bfree(p5);\r
+    return b;\r
+}\r
+\r
+#endif /* Py_USING_MEMORY_DEBUGGER */\r
+\r
+/* shift a Bigint b left by k bits.  Return a pointer to the shifted result,\r
+   or NULL on failure.  If the returned pointer is distinct from b then the\r
+   original b will have been Bfree'd.   Ignores the sign of b. */\r
+\r
+static Bigint *\r
+lshift(Bigint *b, int k)\r
+{\r
+    int i, k1, n, n1;\r
+    Bigint *b1;\r
+    ULong *x, *x1, *xe, z;\r
+\r
+    if (!k || (!b->x[0] && b->wds == 1))\r
+        return b;\r
+\r
+    n = k >> 5;\r
+    k1 = b->k;\r
+    n1 = n + b->wds + 1;\r
+    for(i = b->maxwds; n1 > i; i <<= 1)\r
+        k1++;\r
+    b1 = Balloc(k1);\r
+    if (b1 == NULL) {\r
+        Bfree(b);\r
+        return NULL;\r
+    }\r
+    x1 = b1->x;\r
+    for(i = 0; i < n; i++)\r
+        *x1++ = 0;\r
+    x = b->x;\r
+    xe = x + b->wds;\r
+    if (k &= 0x1f) {\r
+        k1 = 32 - k;\r
+        z = 0;\r
+        do {\r
+            *x1++ = *x << k | z;\r
+            z = *x++ >> k1;\r
+        }\r
+        while(x < xe);\r
+        if ((*x1 = z))\r
+            ++n1;\r
+    }\r
+    else do\r
+             *x1++ = *x++;\r
+        while(x < xe);\r
+    b1->wds = n1 - 1;\r
+    Bfree(b);\r
+    return b1;\r
+}\r
+\r
+/* Do a three-way compare of a and b, returning -1 if a < b, 0 if a == b and\r
+   1 if a > b.  Ignores signs of a and b. */\r
+\r
+static int\r
+cmp(Bigint *a, Bigint *b)\r
+{\r
+    ULong *xa, *xa0, *xb, *xb0;\r
+    int i, j;\r
+\r
+    i = a->wds;\r
+    j = b->wds;\r
+#ifdef DEBUG\r
+    if (i > 1 && !a->x[i-1])\r
+        Bug("cmp called with a->x[a->wds-1] == 0");\r
+    if (j > 1 && !b->x[j-1])\r
+        Bug("cmp called with b->x[b->wds-1] == 0");\r
+#endif\r
+    if (i -= j)\r
+        return i;\r
+    xa0 = a->x;\r
+    xa = xa0 + j;\r
+    xb0 = b->x;\r
+    xb = xb0 + j;\r
+    for(;;) {\r
+        if (*--xa != *--xb)\r
+            return *xa < *xb ? -1 : 1;\r
+        if (xa <= xa0)\r
+            break;\r
+    }\r
+    return 0;\r
+}\r
+\r
+/* Take the difference of Bigints a and b, returning a new Bigint.  Returns\r
+   NULL on failure.  The signs of a and b are ignored, but the sign of the\r
+   result is set appropriately. */\r
+\r
+static Bigint *\r
+diff(Bigint *a, Bigint *b)\r
+{\r
+    Bigint *c;\r
+    int i, wa, wb;\r
+    ULong *xa, *xae, *xb, *xbe, *xc;\r
+#ifdef ULLong\r
+    ULLong borrow, y;\r
+#else\r
+    ULong borrow, y;\r
+    ULong z;\r
+#endif\r
+\r
+    i = cmp(a,b);\r
+    if (!i) {\r
+        c = Balloc(0);\r
+        if (c == NULL)\r
+            return NULL;\r
+        c->wds = 1;\r
+        c->x[0] = 0;\r
+        return c;\r
+    }\r
+    if (i < 0) {\r
+        c = a;\r
+        a = b;\r
+        b = c;\r
+        i = 1;\r
+    }\r
+    else\r
+        i = 0;\r
+    c = Balloc(a->k);\r
+    if (c == NULL)\r
+        return NULL;\r
+    c->sign = i;\r
+    wa = a->wds;\r
+    xa = a->x;\r
+    xae = xa + wa;\r
+    wb = b->wds;\r
+    xb = b->x;\r
+    xbe = xb + wb;\r
+    xc = c->x;\r
+    borrow = 0;\r
+#ifdef ULLong\r
+    do {\r
+        y = (ULLong)*xa++ - *xb++ - borrow;\r
+        borrow = y >> 32 & (ULong)1;\r
+        *xc++ = (ULong)(y & FFFFFFFF);\r
+    }\r
+    while(xb < xbe);\r
+    while(xa < xae) {\r
+        y = *xa++ - borrow;\r
+        borrow = y >> 32 & (ULong)1;\r
+        *xc++ = (ULong)(y & FFFFFFFF);\r
+    }\r
+#else\r
+    do {\r
+        y = (*xa & 0xffff) - (*xb & 0xffff) - borrow;\r
+        borrow = (y & 0x10000) >> 16;\r
+        z = (*xa++ >> 16) - (*xb++ >> 16) - borrow;\r
+        borrow = (z & 0x10000) >> 16;\r
+        Storeinc(xc, z, y);\r
+    }\r
+    while(xb < xbe);\r
+    while(xa < xae) {\r
+        y = (*xa & 0xffff) - borrow;\r
+        borrow = (y & 0x10000) >> 16;\r
+        z = (*xa++ >> 16) - borrow;\r
+        borrow = (z & 0x10000) >> 16;\r
+        Storeinc(xc, z, y);\r
+    }\r
+#endif\r
+    while(!*--xc)\r
+        wa--;\r
+    c->wds = wa;\r
+    return c;\r
+}\r
+\r
+/* Given a positive normal double x, return the difference between x and the\r
+   next double up.  Doesn't give correct results for subnormals. */\r
+\r
+static double\r
+ulp(U *x)\r
+{\r
+    Long L;\r
+    U u;\r
+\r
+    L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;\r
+    word0(&u) = L;\r
+    word1(&u) = 0;\r
+    return dval(&u);\r
+}\r
+\r
+/* Convert a Bigint to a double plus an exponent */\r
+\r
+static double\r
+b2d(Bigint *a, int *e)\r
+{\r
+    ULong *xa, *xa0, w, y, z;\r
+    int k;\r
+    U d;\r
+\r
+    xa0 = a->x;\r
+    xa = xa0 + a->wds;\r
+    y = *--xa;\r
+#ifdef DEBUG\r
+    if (!y) Bug("zero y in b2d");\r
+#endif\r
+    k = hi0bits(y);\r
+    *e = 32 - k;\r
+    if (k < Ebits) {\r
+        word0(&d) = Exp_1 | y >> (Ebits - k);\r
+        w = xa > xa0 ? *--xa : 0;\r
+        word1(&d) = y << ((32-Ebits) + k) | w >> (Ebits - k);\r
+        goto ret_d;\r
+    }\r
+    z = xa > xa0 ? *--xa : 0;\r
+    if (k -= Ebits) {\r
+        word0(&d) = Exp_1 | y << k | z >> (32 - k);\r
+        y = xa > xa0 ? *--xa : 0;\r
+        word1(&d) = z << k | y >> (32 - k);\r
+    }\r
+    else {\r
+        word0(&d) = Exp_1 | y;\r
+        word1(&d) = z;\r
+    }\r
+  ret_d:\r
+    return dval(&d);\r
+}\r
+\r
+/* Convert a scaled double to a Bigint plus an exponent.  Similar to d2b,\r
+   except that it accepts the scale parameter used in _Py_dg_strtod (which\r
+   should be either 0 or 2*P), and the normalization for the return value is\r
+   different (see below).  On input, d should be finite and nonnegative, and d\r
+   / 2**scale should be exactly representable as an IEEE 754 double.\r
+\r
+   Returns a Bigint b and an integer e such that\r
+\r
+     dval(d) / 2**scale = b * 2**e.\r
+\r
+   Unlike d2b, b is not necessarily odd: b and e are normalized so\r
+   that either 2**(P-1) <= b < 2**P and e >= Etiny, or b < 2**P\r
+   and e == Etiny.  This applies equally to an input of 0.0: in that\r
+   case the return values are b = 0 and e = Etiny.\r
+\r
+   The above normalization ensures that for all possible inputs d,\r
+   2**e gives ulp(d/2**scale).\r
+\r
+   Returns NULL on failure.\r
+*/\r
+\r
+static Bigint *\r
+sd2b(U *d, int scale, int *e)\r
+{\r
+    Bigint *b;\r
+\r
+    b = Balloc(1);\r
+    if (b == NULL)\r
+        return NULL;\r
+    \r
+    /* First construct b and e assuming that scale == 0. */\r
+    b->wds = 2;\r
+    b->x[0] = word1(d);\r
+    b->x[1] = word0(d) & Frac_mask;\r
+    *e = Etiny - 1 + (int)((word0(d) & Exp_mask) >> Exp_shift);\r
+    if (*e < Etiny)\r
+        *e = Etiny;\r
+    else\r
+        b->x[1] |= Exp_msk1;\r
+\r
+    /* Now adjust for scale, provided that b != 0. */\r
+    if (scale && (b->x[0] || b->x[1])) {\r
+        *e -= scale;\r
+        if (*e < Etiny) {\r
+            scale = Etiny - *e;\r
+            *e = Etiny;\r
+            /* We can't shift more than P-1 bits without shifting out a 1. */\r
+            assert(0 < scale && scale <= P - 1);\r
+            if (scale >= 32) {\r
+                /* The bits shifted out should all be zero. */\r
+                assert(b->x[0] == 0);\r
+                b->x[0] = b->x[1];\r
+                b->x[1] = 0;\r
+                scale -= 32;\r
+            }\r
+            if (scale) {\r
+                /* The bits shifted out should all be zero. */\r
+                assert(b->x[0] << (32 - scale) == 0);\r
+                b->x[0] = (b->x[0] >> scale) | (b->x[1] << (32 - scale));\r
+                b->x[1] >>= scale;\r
+            }\r
+        }\r
+    }\r
+    /* Ensure b is normalized. */\r
+    if (!b->x[1])\r
+        b->wds = 1;\r
+\r
+    return b;\r
+}\r
+\r
+/* Convert a double to a Bigint plus an exponent.  Return NULL on failure.\r
+\r
+   Given a finite nonzero double d, return an odd Bigint b and exponent *e\r
+   such that fabs(d) = b * 2**e.  On return, *bbits gives the number of\r
+   significant bits of b; that is, 2**(*bbits-1) <= b < 2**(*bbits).\r
+\r
+   If d is zero, then b == 0, *e == -1010, *bbits = 0.\r
+ */\r
+\r
+static Bigint *\r
+d2b(U *d, int *e, int *bits)\r
+{\r
+    Bigint *b;\r
+    int de, k;\r
+    ULong *x, y, z;\r
+    int i;\r
+\r
+    b = Balloc(1);\r
+    if (b == NULL)\r
+        return NULL;\r
+    x = b->x;\r
+\r
+    z = word0(d) & Frac_mask;\r
+    word0(d) &= 0x7fffffff;   /* clear sign bit, which we ignore */\r
+    if ((de = (int)(word0(d) >> Exp_shift)))\r
+        z |= Exp_msk1;\r
+    if ((y = word1(d))) {\r
+        if ((k = lo0bits(&y))) {\r
+            x[0] = y | z << (32 - k);\r
+            z >>= k;\r
+        }\r
+        else\r
+            x[0] = y;\r
+        i =\r
+            b->wds = (x[1] = z) ? 2 : 1;\r
+    }\r
+    else {\r
+        k = lo0bits(&z);\r
+        x[0] = z;\r
+        i =\r
+            b->wds = 1;\r
+        k += 32;\r
+    }\r
+    if (de) {\r
+        *e = de - Bias - (P-1) + k;\r
+        *bits = P - k;\r
+    }\r
+    else {\r
+        *e = de - Bias - (P-1) + 1 + k;\r
+        *bits = 32*i - hi0bits(x[i-1]);\r
+    }\r
+    return b;\r
+}\r
+\r
+/* Compute the ratio of two Bigints, as a double.  The result may have an\r
+   error of up to 2.5 ulps. */\r
+\r
+static double\r
+ratio(Bigint *a, Bigint *b)\r
+{\r
+    U da, db;\r
+    int k, ka, kb;\r
+\r
+    dval(&da) = b2d(a, &ka);\r
+    dval(&db) = b2d(b, &kb);\r
+    k = ka - kb + 32*(a->wds - b->wds);\r
+    if (k > 0)\r
+        word0(&da) += k*Exp_msk1;\r
+    else {\r
+        k = -k;\r
+        word0(&db) += k*Exp_msk1;\r
+    }\r
+    return dval(&da) / dval(&db);\r
+}\r
+\r
+static const double\r
+tens[] = {\r
+    1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,\r
+    1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,\r
+    1e20, 1e21, 1e22\r
+};\r
+\r
+static const double\r
+bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };\r
+static const double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128,\r
+                                   9007199254740992.*9007199254740992.e-256\r
+                                   /* = 2^106 * 1e-256 */\r
+};\r
+/* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */\r
+/* flag unnecessarily.  It leads to a song and dance at the end of strtod. */\r
+#define Scale_Bit 0x10\r
+#define n_bigtens 5\r
+\r
+#define ULbits 32\r
+#define kshift 5\r
+#define kmask 31\r
+\r
+\r
+static int\r
+dshift(Bigint *b, int p2)\r
+{\r
+    int rv = hi0bits(b->x[b->wds-1]) - 4;\r
+    if (p2 > 0)\r
+        rv -= p2;\r
+    return rv & kmask;\r
+}\r
+\r
+/* special case of Bigint division.  The quotient is always in the range 0 <=\r
+   quotient < 10, and on entry the divisor S is normalized so that its top 4\r
+   bits (28--31) are zero and bit 27 is set. */\r
+\r
+static int\r
+quorem(Bigint *b, Bigint *S)\r
+{\r
+    int n;\r
+    ULong *bx, *bxe, q, *sx, *sxe;\r
+#ifdef ULLong\r
+    ULLong borrow, carry, y, ys;\r
+#else\r
+    ULong borrow, carry, y, ys;\r
+    ULong si, z, zs;\r
+#endif\r
+\r
+    n = S->wds;\r
+#ifdef DEBUG\r
+    /*debug*/ if (b->wds > n)\r
+        /*debug*/       Bug("oversize b in quorem");\r
+#endif\r
+    if (b->wds < n)\r
+        return 0;\r
+    sx = S->x;\r
+    sxe = sx + --n;\r
+    bx = b->x;\r
+    bxe = bx + n;\r
+    q = *bxe / (*sxe + 1);      /* ensure q <= true quotient */\r
+#ifdef DEBUG\r
+    /*debug*/ if (q > 9)\r
+        /*debug*/       Bug("oversized quotient in quorem");\r
+#endif\r
+    if (q) {\r
+        borrow = 0;\r
+        carry = 0;\r
+        do {\r
+#ifdef ULLong\r
+            ys = *sx++ * (ULLong)q + carry;\r
+            carry = ys >> 32;\r
+            y = *bx - (ys & FFFFFFFF) - borrow;\r
+            borrow = y >> 32 & (ULong)1;\r
+            *bx++ = (ULong)(y & FFFFFFFF);\r
+#else\r
+            si = *sx++;\r
+            ys = (si & 0xffff) * q + carry;\r
+            zs = (si >> 16) * q + (ys >> 16);\r
+            carry = zs >> 16;\r
+            y = (*bx & 0xffff) - (ys & 0xffff) - borrow;\r
+            borrow = (y & 0x10000) >> 16;\r
+            z = (*bx >> 16) - (zs & 0xffff) - borrow;\r
+            borrow = (z & 0x10000) >> 16;\r
+            Storeinc(bx, z, y);\r
+#endif\r
+        }\r
+        while(sx <= sxe);\r
+        if (!*bxe) {\r
+            bx = b->x;\r
+            while(--bxe > bx && !*bxe)\r
+                --n;\r
+            b->wds = n;\r
+        }\r
+    }\r
+    if (cmp(b, S) >= 0) {\r
+        q++;\r
+        borrow = 0;\r
+        carry = 0;\r
+        bx = b->x;\r
+        sx = S->x;\r
+        do {\r
+#ifdef ULLong\r
+            ys = *sx++ + carry;\r
+            carry = ys >> 32;\r
+            y = *bx - (ys & FFFFFFFF) - borrow;\r
+            borrow = y >> 32 & (ULong)1;\r
+            *bx++ = (ULong)(y & FFFFFFFF);\r
+#else\r
+            si = *sx++;\r
+            ys = (si & 0xffff) + carry;\r
+            zs = (si >> 16) + (ys >> 16);\r
+            carry = zs >> 16;\r
+            y = (*bx & 0xffff) - (ys & 0xffff) - borrow;\r
+            borrow = (y & 0x10000) >> 16;\r
+            z = (*bx >> 16) - (zs & 0xffff) - borrow;\r
+            borrow = (z & 0x10000) >> 16;\r
+            Storeinc(bx, z, y);\r
+#endif\r
+        }\r
+        while(sx <= sxe);\r
+        bx = b->x;\r
+        bxe = bx + n;\r
+        if (!*bxe) {\r
+            while(--bxe > bx && !*bxe)\r
+                --n;\r
+            b->wds = n;\r
+        }\r
+    }\r
+    return q;\r
+}\r
+\r
+/* sulp(x) is a version of ulp(x) that takes bc.scale into account.\r
+\r
+   Assuming that x is finite and nonnegative (positive zero is fine\r
+   here) and x / 2^bc.scale is exactly representable as a double,\r
+   sulp(x) is equivalent to 2^bc.scale * ulp(x / 2^bc.scale). */\r
+\r
+static double\r
+sulp(U *x, BCinfo *bc)\r
+{\r
+    U u;\r
+\r
+    if (bc->scale && 2*P + 1 > (int)((word0(x) & Exp_mask) >> Exp_shift)) {\r
+        /* rv/2^bc->scale is subnormal */\r
+        word0(&u) = (P+2)*Exp_msk1;\r
+        word1(&u) = 0;\r
+        return u.d;\r
+    }\r
+    else {\r
+        assert(word0(x) || word1(x)); /* x != 0.0 */\r
+        return ulp(x);\r
+    }\r
+}\r
+\r
+/* The bigcomp function handles some hard cases for strtod, for inputs\r
+   with more than STRTOD_DIGLIM digits.  It's called once an initial\r
+   estimate for the double corresponding to the input string has\r
+   already been obtained by the code in _Py_dg_strtod.\r
+\r
+   The bigcomp function is only called after _Py_dg_strtod has found a\r
+   double value rv such that either rv or rv + 1ulp represents the\r
+   correctly rounded value corresponding to the original string.  It\r
+   determines which of these two values is the correct one by\r
+   computing the decimal digits of rv + 0.5ulp and comparing them with\r
+   the corresponding digits of s0.\r
+\r
+   In the following, write dv for the absolute value of the number represented\r
+   by the input string.\r
+\r
+   Inputs:\r
+\r
+     s0 points to the first significant digit of the input string.\r
+\r
+     rv is a (possibly scaled) estimate for the closest double value to the\r
+        value represented by the original input to _Py_dg_strtod.  If\r
+        bc->scale is nonzero, then rv/2^(bc->scale) is the approximation to\r
+        the input value.\r
+\r
+     bc is a struct containing information gathered during the parsing and\r
+        estimation steps of _Py_dg_strtod.  Description of fields follows:\r
+\r
+        bc->e0 gives the exponent of the input value, such that dv = (integer\r
+           given by the bd->nd digits of s0) * 10**e0\r
+\r
+        bc->nd gives the total number of significant digits of s0.  It will\r
+           be at least 1.\r
+\r
+        bc->nd0 gives the number of significant digits of s0 before the\r
+           decimal separator.  If there's no decimal separator, bc->nd0 ==\r
+           bc->nd.\r
+\r
+        bc->scale is the value used to scale rv to avoid doing arithmetic with\r
+           subnormal values.  It's either 0 or 2*P (=106).\r
+\r
+   Outputs:\r
+\r
+     On successful exit, rv/2^(bc->scale) is the closest double to dv.\r
+\r
+     Returns 0 on success, -1 on failure (e.g., due to a failed malloc call). */\r
+\r
+static int\r
+bigcomp(U *rv, const char *s0, BCinfo *bc)\r
+{\r
+    Bigint *b, *d;\r
+    int b2, d2, dd, i, nd, nd0, odd, p2, p5;\r
+\r
+    nd = bc->nd;\r
+    nd0 = bc->nd0;\r
+    p5 = nd + bc->e0;\r
+    b = sd2b(rv, bc->scale, &p2);\r
+    if (b == NULL)\r
+        return -1;\r
+\r
+    /* record whether the lsb of rv/2^(bc->scale) is odd:  in the exact halfway\r
+       case, this is used for round to even. */\r
+    odd = b->x[0] & 1;\r
+\r
+    /* left shift b by 1 bit and or a 1 into the least significant bit;\r
+       this gives us b * 2**p2 = rv/2^(bc->scale) + 0.5 ulp. */\r
+    b = lshift(b, 1);\r
+    if (b == NULL)\r
+        return -1;\r
+    b->x[0] |= 1;\r
+    p2--;\r
+\r
+    p2 -= p5;\r
+    d = i2b(1);\r
+    if (d == NULL) {\r
+        Bfree(b);\r
+        return -1;\r
+    }\r
+    /* Arrange for convenient computation of quotients:\r
+     * shift left if necessary so divisor has 4 leading 0 bits.\r
+     */\r
+    if (p5 > 0) {\r
+        d = pow5mult(d, p5);\r
+        if (d == NULL) {\r
+            Bfree(b);\r
+            return -1;\r
+        }\r
+    }\r
+    else if (p5 < 0) {\r
+        b = pow5mult(b, -p5);\r
+        if (b == NULL) {\r
+            Bfree(d);\r
+            return -1;\r
+        }\r
+    }\r
+    if (p2 > 0) {\r
+        b2 = p2;\r
+        d2 = 0;\r
+    }\r
+    else {\r
+        b2 = 0;\r
+        d2 = -p2;\r
+    }\r
+    i = dshift(d, d2);\r
+    if ((b2 += i) > 0) {\r
+        b = lshift(b, b2);\r
+        if (b == NULL) {\r
+            Bfree(d);\r
+            return -1;\r
+        }\r
+    }\r
+    if ((d2 += i) > 0) {\r
+        d = lshift(d, d2);\r
+        if (d == NULL) {\r
+            Bfree(b);\r
+            return -1;\r
+        }\r
+    }\r
+\r
+    /* Compare s0 with b/d: set dd to -1, 0, or 1 according as s0 < b/d, s0 ==\r
+     * b/d, or s0 > b/d.  Here the digits of s0 are thought of as representing\r
+     * a number in the range [0.1, 1). */\r
+    if (cmp(b, d) >= 0)\r
+        /* b/d >= 1 */\r
+        dd = -1;\r
+    else {\r
+        i = 0;\r
+        for(;;) {\r
+            b = multadd(b, 10, 0);\r
+            if (b == NULL) {\r
+                Bfree(d);\r
+                return -1;\r
+            }\r
+            dd = s0[i < nd0 ? i : i+1] - '0' - quorem(b, d);\r
+            i++;\r
+\r
+            if (dd)\r
+                break;\r
+            if (!b->x[0] && b->wds == 1) {\r
+                /* b/d == 0 */\r
+                dd = i < nd;\r
+                break;\r
+            }\r
+            if (!(i < nd)) {\r
+                /* b/d != 0, but digits of s0 exhausted */\r
+                dd = -1;\r
+                break;\r
+            }\r
+        }\r
+    }\r
+    Bfree(b);\r
+    Bfree(d);\r
+    if (dd > 0 || (dd == 0 && odd))\r
+        dval(rv) += sulp(rv, bc);\r
+    return 0;\r
+}\r
+\r
+double\r
+_Py_dg_strtod(const char *s00, char **se)\r
+{\r
+    int bb2, bb5, bbe, bd2, bd5, bs2, c, dsign, e, e1, error;\r
+    int esign, i, j, k, lz, nd, nd0, odd, sign;\r
+    const char *s, *s0, *s1;\r
+    double aadj, aadj1;\r
+    U aadj2, adj, rv, rv0;\r
+    ULong y, z, abs_exp;\r
+    Long L;\r
+    BCinfo bc;\r
+    Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;\r
+    size_t ndigits, fraclen;\r
+\r
+    dval(&rv) = 0.;\r
+\r
+    /* Start parsing. */\r
+    c = *(s = s00);\r
+\r
+    /* Parse optional sign, if present. */\r
+    sign = 0;\r
+    switch (c) {\r
+    case '-':\r
+        sign = 1;\r
+        /* no break */\r
+    case '+':\r
+        c = *++s;\r
+    }\r
+\r
+    /* Skip leading zeros: lz is true iff there were leading zeros. */\r
+    s1 = s;\r
+    while (c == '0')\r
+        c = *++s;\r
+    lz = s != s1;\r
+\r
+    /* Point s0 at the first nonzero digit (if any).  fraclen will be the\r
+       number of digits between the decimal point and the end of the\r
+       digit string.  ndigits will be the total number of digits ignoring\r
+       leading zeros. */\r
+    s0 = s1 = s;\r
+    while ('0' <= c && c <= '9')\r
+        c = *++s;\r
+    ndigits = s - s1;\r
+    fraclen = 0;\r
+\r
+    /* Parse decimal point and following digits. */\r
+    if (c == '.') {\r
+        c = *++s;\r
+        if (!ndigits) {\r
+            s1 = s;\r
+            while (c == '0')\r
+                c = *++s;\r
+            lz = lz || s != s1;\r
+            fraclen += (s - s1);\r
+            s0 = s;\r
+        }\r
+        s1 = s;\r
+        while ('0' <= c && c <= '9')\r
+            c = *++s;\r
+        ndigits += s - s1;\r
+        fraclen += s - s1;\r
+    }\r
+\r
+    /* Now lz is true if and only if there were leading zero digits, and\r
+       ndigits gives the total number of digits ignoring leading zeros.  A\r
+       valid input must have at least one digit. */\r
+    if (!ndigits && !lz) {\r
+        if (se)\r
+            *se = (char *)s00;\r
+        goto parse_error;\r
+    }\r
+\r
+    /* Range check ndigits and fraclen to make sure that they, and values\r
+       computed with them, can safely fit in an int. */\r
+    if (ndigits > MAX_DIGITS || fraclen > MAX_DIGITS) {\r
+        if (se)\r
+            *se = (char *)s00;\r
+        goto parse_error;\r
+    }\r
+    nd = (int)ndigits;\r
+    nd0 = (int)ndigits - (int)fraclen;\r
+\r
+    /* Parse exponent. */\r
+    e = 0;\r
+    if (c == 'e' || c == 'E') {\r
+        s00 = s;\r
+        c = *++s;\r
+\r
+        /* Exponent sign. */\r
+        esign = 0;\r
+        switch (c) {\r
+        case '-':\r
+            esign = 1;\r
+            /* no break */\r
+        case '+':\r
+            c = *++s;\r
+        }\r
+\r
+        /* Skip zeros.  lz is true iff there are leading zeros. */\r
+        s1 = s;\r
+        while (c == '0')\r
+            c = *++s;\r
+        lz = s != s1;\r
+\r
+        /* Get absolute value of the exponent. */\r
+        s1 = s;\r
+        abs_exp = 0;\r
+        while ('0' <= c && c <= '9') {\r
+            abs_exp = 10*abs_exp + (c - '0');\r
+            c = *++s;\r
+        }\r
+\r
+        /* abs_exp will be correct modulo 2**32.  But 10**9 < 2**32, so if\r
+           there are at most 9 significant exponent digits then overflow is\r
+           impossible. */\r
+        if (s - s1 > 9 || abs_exp > MAX_ABS_EXP)\r
+            e = (int)MAX_ABS_EXP;\r
+        else\r
+            e = (int)abs_exp;\r
+        if (esign)\r
+            e = -e;\r
+\r
+        /* A valid exponent must have at least one digit. */\r
+        if (s == s1 && !lz)\r
+            s = s00;\r
+    }\r
+\r
+    /* Adjust exponent to take into account position of the point. */\r
+    e -= nd - nd0;\r
+    if (nd0 <= 0)\r
+        nd0 = nd;\r
+\r
+    /* Finished parsing.  Set se to indicate how far we parsed */\r
+    if (se)\r
+        *se = (char *)s;\r
+\r
+    /* If all digits were zero, exit with return value +-0.0.  Otherwise,\r
+       strip trailing zeros: scan back until we hit a nonzero digit. */\r
+    if (!nd)\r
+        goto ret;\r
+    for (i = nd; i > 0; ) {\r
+        --i;\r
+        if (s0[i < nd0 ? i : i+1] != '0') {\r
+            ++i;\r
+            break;\r
+        }\r
+    }\r
+    e += nd - i;\r
+    nd = i;\r
+    if (nd0 > nd)\r
+        nd0 = nd;\r
+\r
+    /* Summary of parsing results.  After parsing, and dealing with zero\r
+     * inputs, we have values s0, nd0, nd, e, sign, where:\r
+     *\r
+     *  - s0 points to the first significant digit of the input string\r
+     *\r
+     *  - nd is the total number of significant digits (here, and\r
+     *    below, 'significant digits' means the set of digits of the\r
+     *    significand of the input that remain after ignoring leading\r
+     *    and trailing zeros).\r
+     *\r
+     *  - nd0 indicates the position of the decimal point, if present; it\r
+     *    satisfies 1 <= nd0 <= nd.  The nd significant digits are in\r
+     *    s0[0:nd0] and s0[nd0+1:nd+1] using the usual Python half-open slice\r
+     *    notation.  (If nd0 < nd, then s0[nd0] contains a '.'  character; if\r
+     *    nd0 == nd, then s0[nd0] could be any non-digit character.)\r
+     *\r
+     *  - e is the adjusted exponent: the absolute value of the number\r
+     *    represented by the original input string is n * 10**e, where\r
+     *    n is the integer represented by the concatenation of\r
+     *    s0[0:nd0] and s0[nd0+1:nd+1]\r
+     *\r
+     *  - sign gives the sign of the input:  1 for negative, 0 for positive\r
+     *\r
+     *  - the first and last significant digits are nonzero\r
+     */\r
+\r
+    /* put first DBL_DIG+1 digits into integer y and z.\r
+     *\r
+     *  - y contains the value represented by the first min(9, nd)\r
+     *    significant digits\r
+     *\r
+     *  - if nd > 9, z contains the value represented by significant digits\r
+     *    with indices in [9, min(16, nd)).  So y * 10**(min(16, nd) - 9) + z\r
+     *    gives the value represented by the first min(16, nd) sig. digits.\r
+     */\r
+\r
+    bc.e0 = e1 = e;\r
+    y = z = 0;\r
+    for (i = 0; i < nd; i++) {\r
+        if (i < 9)\r
+            y = 10*y + s0[i < nd0 ? i : i+1] - '0';\r
+        else if (i < DBL_DIG+1)\r
+            z = 10*z + s0[i < nd0 ? i : i+1] - '0';\r
+        else\r
+            break;\r
+    }\r
+\r
+    k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;\r
+    dval(&rv) = y;\r
+    if (k > 9) {\r
+        dval(&rv) = tens[k - 9] * dval(&rv) + z;\r
+    }\r
+    bd0 = 0;\r
+    if (nd <= DBL_DIG\r
+        && Flt_Rounds == 1\r
+        ) {\r
+        if (!e)\r
+            goto ret;\r
+        if (e > 0) {\r
+            if (e <= Ten_pmax) {\r
+                dval(&rv) *= tens[e];\r
+                goto ret;\r
+            }\r
+            i = DBL_DIG - nd;\r
+            if (e <= Ten_pmax + i) {\r
+                /* A fancier test would sometimes let us do\r
+                 * this for larger i values.\r
+                 */\r
+                e -= i;\r
+                dval(&rv) *= tens[i];\r
+                dval(&rv) *= tens[e];\r
+                goto ret;\r
+            }\r
+        }\r
+        else if (e >= -Ten_pmax) {\r
+            dval(&rv) /= tens[-e];\r
+            goto ret;\r
+        }\r
+    }\r
+    e1 += nd - k;\r
+\r
+    bc.scale = 0;\r
+\r
+    /* Get starting approximation = rv * 10**e1 */\r
+\r
+    if (e1 > 0) {\r
+        if ((i = e1 & 15))\r
+            dval(&rv) *= tens[i];\r
+        if (e1 &= ~15) {\r
+            if (e1 > DBL_MAX_10_EXP)\r
+                goto ovfl;\r
+            e1 >>= 4;\r
+            for(j = 0; e1 > 1; j++, e1 >>= 1)\r
+                if (e1 & 1)\r
+                    dval(&rv) *= bigtens[j];\r
+            /* The last multiplication could overflow. */\r
+            word0(&rv) -= P*Exp_msk1;\r
+            dval(&rv) *= bigtens[j];\r
+            if ((z = word0(&rv) & Exp_mask)\r
+                > Exp_msk1*(DBL_MAX_EXP+Bias-P))\r
+                goto ovfl;\r
+            if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {\r
+                /* set to largest number */\r
+                /* (Can't trust DBL_MAX) */\r
+                word0(&rv) = Big0;\r
+                word1(&rv) = Big1;\r
+            }\r
+            else\r
+                word0(&rv) += P*Exp_msk1;\r
+        }\r
+    }\r
+    else if (e1 < 0) {\r
+        /* The input decimal value lies in [10**e1, 10**(e1+16)).\r
+\r
+           If e1 <= -512, underflow immediately.\r
+           If e1 <= -256, set bc.scale to 2*P.\r
+\r
+           So for input value < 1e-256, bc.scale is always set;\r
+           for input value >= 1e-240, bc.scale is never set.\r
+           For input values in [1e-256, 1e-240), bc.scale may or may\r
+           not be set. */\r
+\r
+        e1 = -e1;\r
+        if ((i = e1 & 15))\r
+            dval(&rv) /= tens[i];\r
+        if (e1 >>= 4) {\r
+            if (e1 >= 1 << n_bigtens)\r
+                goto undfl;\r
+            if (e1 & Scale_Bit)\r
+                bc.scale = 2*P;\r
+            for(j = 0; e1 > 0; j++, e1 >>= 1)\r
+                if (e1 & 1)\r
+                    dval(&rv) *= tinytens[j];\r
+            if (bc.scale && (j = 2*P + 1 - ((word0(&rv) & Exp_mask)\r
+                                            >> Exp_shift)) > 0) {\r
+                /* scaled rv is denormal; clear j low bits */\r
+                if (j >= 32) {\r
+                    word1(&rv) = 0;\r
+                    if (j >= 53)\r
+                        word0(&rv) = (P+2)*Exp_msk1;\r
+                    else\r
+                        word0(&rv) &= 0xffffffff << (j-32);\r
+                }\r
+                else\r
+                    word1(&rv) &= 0xffffffff << j;\r
+            }\r
+            if (!dval(&rv))\r
+                goto undfl;\r
+        }\r
+    }\r
+\r
+    /* Now the hard part -- adjusting rv to the correct value.*/\r
+\r
+    /* Put digits into bd: true value = bd * 10^e */\r
+\r
+    bc.nd = nd;\r
+    bc.nd0 = nd0;       /* Only needed if nd > STRTOD_DIGLIM, but done here */\r
+                        /* to silence an erroneous warning about bc.nd0 */\r
+                        /* possibly not being initialized. */\r
+    if (nd > STRTOD_DIGLIM) {\r
+        /* ASSERT(STRTOD_DIGLIM >= 18); 18 == one more than the */\r
+        /* minimum number of decimal digits to distinguish double values */\r
+        /* in IEEE arithmetic. */\r
+\r
+        /* Truncate input to 18 significant digits, then discard any trailing\r
+           zeros on the result by updating nd, nd0, e and y suitably. (There's\r
+           no need to update z; it's not reused beyond this point.) */\r
+        for (i = 18; i > 0; ) {\r
+            /* scan back until we hit a nonzero digit.  significant digit 'i'\r
+            is s0[i] if i < nd0, s0[i+1] if i >= nd0. */\r
+            --i;\r
+            if (s0[i < nd0 ? i : i+1] != '0') {\r
+                ++i;\r
+                break;\r
+            }\r
+        }\r
+        e += nd - i;\r
+        nd = i;\r
+        if (nd0 > nd)\r
+            nd0 = nd;\r
+        if (nd < 9) { /* must recompute y */\r
+            y = 0;\r
+            for(i = 0; i < nd0; ++i)\r
+                y = 10*y + s0[i] - '0';\r
+            for(; i < nd; ++i)\r
+                y = 10*y + s0[i+1] - '0';\r
+        }\r
+    }\r
+    bd0 = s2b(s0, nd0, nd, y);\r
+    if (bd0 == NULL)\r
+        goto failed_malloc;\r
+\r
+    /* Notation for the comments below.  Write:\r
+\r
+         - dv for the absolute value of the number represented by the original\r
+           decimal input string.\r
+\r
+         - if we've truncated dv, write tdv for the truncated value.\r
+           Otherwise, set tdv == dv.\r
+\r
+         - srv for the quantity rv/2^bc.scale; so srv is the current binary\r
+           approximation to tdv (and dv).  It should be exactly representable\r
+           in an IEEE 754 double.\r
+    */\r
+\r
+    for(;;) {\r
+\r
+        /* This is the main correction loop for _Py_dg_strtod.\r
+\r
+           We've got a decimal value tdv, and a floating-point approximation\r
+           srv=rv/2^bc.scale to tdv.  The aim is to determine whether srv is\r
+           close enough (i.e., within 0.5 ulps) to tdv, and to compute a new\r
+           approximation if not.\r
+\r
+           To determine whether srv is close enough to tdv, compute integers\r
+           bd, bb and bs proportional to tdv, srv and 0.5 ulp(srv)\r
+           respectively, and then use integer arithmetic to determine whether\r
+           |tdv - srv| is less than, equal to, or greater than 0.5 ulp(srv).\r
+        */\r
+\r
+        bd = Balloc(bd0->k);\r
+        if (bd == NULL) {\r
+            Bfree(bd0);\r
+            goto failed_malloc;\r
+        }\r
+        Bcopy(bd, bd0);\r
+        bb = sd2b(&rv, bc.scale, &bbe);   /* srv = bb * 2^bbe */\r
+        if (bb == NULL) {\r
+            Bfree(bd);\r
+            Bfree(bd0);\r
+            goto failed_malloc;\r
+        }\r
+        /* Record whether lsb of bb is odd, in case we need this\r
+           for the round-to-even step later. */\r
+        odd = bb->x[0] & 1;\r
+\r
+        /* tdv = bd * 10**e;  srv = bb * 2**bbe */\r
+        bs = i2b(1);\r
+        if (bs == NULL) {\r
+            Bfree(bb);\r
+            Bfree(bd);\r
+            Bfree(bd0);\r
+            goto failed_malloc;\r
+        }\r
+\r
+        if (e >= 0) {\r
+            bb2 = bb5 = 0;\r
+            bd2 = bd5 = e;\r
+        }\r
+        else {\r
+            bb2 = bb5 = -e;\r
+            bd2 = bd5 = 0;\r
+        }\r
+        if (bbe >= 0)\r
+            bb2 += bbe;\r
+        else\r
+            bd2 -= bbe;\r
+        bs2 = bb2;\r
+        bb2++;\r
+        bd2++;\r
+\r
+        /* At this stage bd5 - bb5 == e == bd2 - bb2 + bbe, bb2 - bs2 == 1,\r
+           and bs == 1, so:\r
+\r
+              tdv == bd * 10**e = bd * 2**(bbe - bb2 + bd2) * 5**(bd5 - bb5)\r
+              srv == bb * 2**bbe = bb * 2**(bbe - bb2 + bb2)\r
+              0.5 ulp(srv) == 2**(bbe-1) = bs * 2**(bbe - bb2 + bs2)\r
+\r
+           It follows that:\r
+\r
+              M * tdv = bd * 2**bd2 * 5**bd5\r
+              M * srv = bb * 2**bb2 * 5**bb5\r
+              M * 0.5 ulp(srv) = bs * 2**bs2 * 5**bb5\r
+\r
+           for some constant M.  (Actually, M == 2**(bb2 - bbe) * 5**bb5, but\r
+           this fact is not needed below.)\r
+        */\r
+\r
+        /* Remove factor of 2**i, where i = min(bb2, bd2, bs2). */\r
+        i = bb2 < bd2 ? bb2 : bd2;\r
+        if (i > bs2)\r
+            i = bs2;\r
+        if (i > 0) {\r
+            bb2 -= i;\r
+            bd2 -= i;\r
+            bs2 -= i;\r
+        }\r
+\r
+        /* Scale bb, bd, bs by the appropriate powers of 2 and 5. */\r
+        if (bb5 > 0) {\r
+            bs = pow5mult(bs, bb5);\r
+            if (bs == NULL) {\r
+                Bfree(bb);\r
+                Bfree(bd);\r
+                Bfree(bd0);\r
+                goto failed_malloc;\r
+            }\r
+            bb1 = mult(bs, bb);\r
+            Bfree(bb);\r
+            bb = bb1;\r
+            if (bb == NULL) {\r
+                Bfree(bs);\r
+                Bfree(bd);\r
+                Bfree(bd0);\r
+                goto failed_malloc;\r
+            }\r
+        }\r
+        if (bb2 > 0) {\r
+            bb = lshift(bb, bb2);\r
+            if (bb == NULL) {\r
+                Bfree(bs);\r
+                Bfree(bd);\r
+                Bfree(bd0);\r
+                goto failed_malloc;\r
+            }\r
+        }\r
+        if (bd5 > 0) {\r
+            bd = pow5mult(bd, bd5);\r
+            if (bd == NULL) {\r
+                Bfree(bb);\r
+                Bfree(bs);\r
+                Bfree(bd0);\r
+                goto failed_malloc;\r
+            }\r
+        }\r
+        if (bd2 > 0) {\r
+            bd = lshift(bd, bd2);\r
+            if (bd == NULL) {\r
+                Bfree(bb);\r
+                Bfree(bs);\r
+                Bfree(bd0);\r
+                goto failed_malloc;\r
+            }\r
+        }\r
+        if (bs2 > 0) {\r
+            bs = lshift(bs, bs2);\r
+            if (bs == NULL) {\r
+                Bfree(bb);\r
+                Bfree(bd);\r
+                Bfree(bd0);\r
+                goto failed_malloc;\r
+            }\r
+        }\r
+\r
+        /* Now bd, bb and bs are scaled versions of tdv, srv and 0.5 ulp(srv),\r
+           respectively.  Compute the difference |tdv - srv|, and compare\r
+           with 0.5 ulp(srv). */\r
+\r
+        delta = diff(bb, bd);\r
+        if (delta == NULL) {\r
+            Bfree(bb);\r
+            Bfree(bs);\r
+            Bfree(bd);\r
+            Bfree(bd0);\r
+            goto failed_malloc;\r
+        }\r
+        dsign = delta->sign;\r
+        delta->sign = 0;\r
+        i = cmp(delta, bs);\r
+        if (bc.nd > nd && i <= 0) {\r
+            if (dsign)\r
+                break;  /* Must use bigcomp(). */\r
+\r
+            /* Here rv overestimates the truncated decimal value by at most\r
+               0.5 ulp(rv).  Hence rv either overestimates the true decimal\r
+               value by <= 0.5 ulp(rv), or underestimates it by some small\r
+               amount (< 0.1 ulp(rv)); either way, rv is within 0.5 ulps of\r
+               the true decimal value, so it's possible to exit.\r
+\r
+               Exception: if scaled rv is a normal exact power of 2, but not\r
+               DBL_MIN, then rv - 0.5 ulp(rv) takes us all the way down to the\r
+               next double, so the correctly rounded result is either rv - 0.5\r
+               ulp(rv) or rv; in this case, use bigcomp to distinguish. */\r
+\r
+            if (!word1(&rv) && !(word0(&rv) & Bndry_mask)) {\r
+                /* rv can't be 0, since it's an overestimate for some\r
+                   nonzero value.  So rv is a normal power of 2. */\r
+                j = (int)(word0(&rv) & Exp_mask) >> Exp_shift;\r
+                /* rv / 2^bc.scale = 2^(j - 1023 - bc.scale); use bigcomp if\r
+                   rv / 2^bc.scale >= 2^-1021. */\r
+                if (j - bc.scale >= 2) {\r
+                    dval(&rv) -= 0.5 * sulp(&rv, &bc);\r
+                    break; /* Use bigcomp. */\r
+                }\r
+            }\r
+\r
+            {\r
+                bc.nd = nd;\r
+                i = -1; /* Discarded digits make delta smaller. */\r
+            }\r
+        }\r
+\r
+        if (i < 0) {\r
+            /* Error is less than half an ulp -- check for\r
+             * special case of mantissa a power of two.\r
+             */\r
+            if (dsign || word1(&rv) || word0(&rv) & Bndry_mask\r
+                || (word0(&rv) & Exp_mask) <= (2*P+1)*Exp_msk1\r
+                ) {\r
+                break;\r
+            }\r
+            if (!delta->x[0] && delta->wds <= 1) {\r
+                /* exact result */\r
+                break;\r
+            }\r
+            delta = lshift(delta,Log2P);\r
+            if (delta == NULL) {\r
+                Bfree(bb);\r
+                Bfree(bs);\r
+                Bfree(bd);\r
+                Bfree(bd0);\r
+                goto failed_malloc;\r
+            }\r
+            if (cmp(delta, bs) > 0)\r
+                goto drop_down;\r
+            break;\r
+        }\r
+        if (i == 0) {\r
+            /* exactly half-way between */\r
+            if (dsign) {\r
+                if ((word0(&rv) & Bndry_mask1) == Bndry_mask1\r
+                    &&  word1(&rv) == (\r
+                        (bc.scale &&\r
+                         (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1) ?\r
+                        (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) :\r
+                        0xffffffff)) {\r
+                    /*boundary case -- increment exponent*/\r
+                    word0(&rv) = (word0(&rv) & Exp_mask)\r
+                        + Exp_msk1\r
+                        ;\r
+                    word1(&rv) = 0;\r
+                    dsign = 0;\r
+                    break;\r
+                }\r
+            }\r
+            else if (!(word0(&rv) & Bndry_mask) && !word1(&rv)) {\r
+              drop_down:\r
+                /* boundary case -- decrement exponent */\r
+                if (bc.scale) {\r
+                    L = word0(&rv) & Exp_mask;\r
+                    if (L <= (2*P+1)*Exp_msk1) {\r
+                        if (L > (P+2)*Exp_msk1)\r
+                            /* round even ==> */\r
+                            /* accept rv */\r
+                            break;\r
+                        /* rv = smallest denormal */\r
+                        if (bc.nd > nd)\r
+                            break;\r
+                        goto undfl;\r
+                    }\r
+                }\r
+                L = (word0(&rv) & Exp_mask) - Exp_msk1;\r
+                word0(&rv) = L | Bndry_mask1;\r
+                word1(&rv) = 0xffffffff;\r
+                break;\r
+            }\r
+            if (!odd)\r
+                break;\r
+            if (dsign)\r
+                dval(&rv) += sulp(&rv, &bc);\r
+            else {\r
+                dval(&rv) -= sulp(&rv, &bc);\r
+                if (!dval(&rv)) {\r
+                    if (bc.nd >nd)\r
+                        break;\r
+                    goto undfl;\r
+                }\r
+            }\r
+            dsign = 1 - dsign;\r
+            break;\r
+        }\r
+        if ((aadj = ratio(delta, bs)) <= 2.) {\r
+            if (dsign)\r
+                aadj = aadj1 = 1.;\r
+            else if (word1(&rv) || word0(&rv) & Bndry_mask) {\r
+                if (word1(&rv) == Tiny1 && !word0(&rv)) {\r
+                    if (bc.nd >nd)\r
+                        break;\r
+                    goto undfl;\r
+                }\r
+                aadj = 1.;\r
+                aadj1 = -1.;\r
+            }\r
+            else {\r
+                /* special case -- power of FLT_RADIX to be */\r
+                /* rounded down... */\r
+\r
+                if (aadj < 2./FLT_RADIX)\r
+                    aadj = 1./FLT_RADIX;\r
+                else\r
+                    aadj *= 0.5;\r
+                aadj1 = -aadj;\r
+            }\r
+        }\r
+        else {\r
+            aadj *= 0.5;\r
+            aadj1 = dsign ? aadj : -aadj;\r
+            if (Flt_Rounds == 0)\r
+                aadj1 += 0.5;\r
+        }\r
+        y = word0(&rv) & Exp_mask;\r
+\r
+        /* Check for overflow */\r
+\r
+        if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {\r
+            dval(&rv0) = dval(&rv);\r
+            word0(&rv) -= P*Exp_msk1;\r
+            adj.d = aadj1 * ulp(&rv);\r
+            dval(&rv) += adj.d;\r
+            if ((word0(&rv) & Exp_mask) >=\r
+                Exp_msk1*(DBL_MAX_EXP+Bias-P)) {\r
+                if (word0(&rv0) == Big0 && word1(&rv0) == Big1) {\r
+                    Bfree(bb);\r
+                    Bfree(bd);\r
+                    Bfree(bs);\r
+                    Bfree(bd0);\r
+                    Bfree(delta);\r
+                    goto ovfl;\r
+                }\r
+                word0(&rv) = Big0;\r
+                word1(&rv) = Big1;\r
+                goto cont;\r
+            }\r
+            else\r
+                word0(&rv) += P*Exp_msk1;\r
+        }\r
+        else {\r
+            if (bc.scale && y <= 2*P*Exp_msk1) {\r
+                if (aadj <= 0x7fffffff) {\r
+                    if ((z = (ULong)aadj) <= 0)\r
+                        z = 1;\r
+                    aadj = z;\r
+                    aadj1 = dsign ? aadj : -aadj;\r
+                }\r
+                dval(&aadj2) = aadj1;\r
+                word0(&aadj2) += (2*P+1)*Exp_msk1 - y;\r
+                aadj1 = dval(&aadj2);\r
+            }\r
+            adj.d = aadj1 * ulp(&rv);\r
+            dval(&rv) += adj.d;\r
+        }\r
+        z = word0(&rv) & Exp_mask;\r
+        if (bc.nd == nd) {\r
+            if (!bc.scale)\r
+                if (y == z) {\r
+                    /* Can we stop now? */\r
+                    L = (Long)aadj;\r
+                    aadj -= L;\r
+                    /* The tolerances below are conservative. */\r
+                    if (dsign || word1(&rv) || word0(&rv) & Bndry_mask) {\r
+                        if (aadj < .4999999 || aadj > .5000001)\r
+                            break;\r
+                    }\r
+                    else if (aadj < .4999999/FLT_RADIX)\r
+                        break;\r
+                }\r
+        }\r
+      cont:\r
+        Bfree(bb);\r
+        Bfree(bd);\r
+        Bfree(bs);\r
+        Bfree(delta);\r
+    }\r
+    Bfree(bb);\r
+    Bfree(bd);\r
+    Bfree(bs);\r
+    Bfree(bd0);\r
+    Bfree(delta);\r
+    if (bc.nd > nd) {\r
+        error = bigcomp(&rv, s0, &bc);\r
+        if (error)\r
+            goto failed_malloc;\r
+    }\r
+\r
+    if (bc.scale) {\r
+        word0(&rv0) = Exp_1 - 2*P*Exp_msk1;\r
+        word1(&rv0) = 0;\r
+        dval(&rv) *= dval(&rv0);\r
+    }\r
+\r
+  ret:\r
+    return sign ? -dval(&rv) : dval(&rv);\r
+\r
+  parse_error:\r
+    return 0.0;\r
+\r
+  failed_malloc:\r
+    errno = ENOMEM;\r
+    return -1.0;\r
+\r
+  undfl:\r
+    return sign ? -0.0 : 0.0;\r
+\r
+  ovfl:\r
+    errno = ERANGE;\r
+    /* Can't trust HUGE_VAL */\r
+    word0(&rv) = Exp_mask;\r
+    word1(&rv) = 0;\r
+    return sign ? -dval(&rv) : dval(&rv);\r
+\r
+}\r
+\r
+static char *\r
+rv_alloc(int i)\r
+{\r
+    int j, k, *r;\r
+\r
+    j = sizeof(ULong);\r
+    for(k = 0;\r
+        sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= (unsigned)i;\r
+        j <<= 1)\r
+        k++;\r
+    r = (int*)Balloc(k);\r
+    if (r == NULL)\r
+        return NULL;\r
+    *r = k;\r
+    return (char *)(r+1);\r
+}\r
+\r
+static char *\r
+nrv_alloc(char *s, char **rve, int n)\r
+{\r
+    char *rv, *t;\r
+\r
+    rv = rv_alloc(n);\r
+    if (rv == NULL)\r
+        return NULL;\r
+    t = rv;\r
+    while((*t = *s++)) t++;\r
+    if (rve)\r
+        *rve = t;\r
+    return rv;\r
+}\r
+\r
+/* freedtoa(s) must be used to free values s returned by dtoa\r
+ * when MULTIPLE_THREADS is #defined.  It should be used in all cases,\r
+ * but for consistency with earlier versions of dtoa, it is optional\r
+ * when MULTIPLE_THREADS is not defined.\r
+ */\r
+\r
+void\r
+_Py_dg_freedtoa(char *s)\r
+{\r
+    Bigint *b = (Bigint *)((int *)s - 1);\r
+    b->maxwds = 1 << (b->k = *(int*)b);\r
+    Bfree(b);\r
+}\r
+\r
+/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.\r
+ *\r
+ * Inspired by "How to Print Floating-Point Numbers Accurately" by\r
+ * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126].\r
+ *\r
+ * Modifications:\r
+ *      1. Rather than iterating, we use a simple numeric overestimate\r
+ *         to determine k = floor(log10(d)).  We scale relevant\r
+ *         quantities using O(log2(k)) rather than O(k) multiplications.\r
+ *      2. For some modes > 2 (corresponding to ecvt and fcvt), we don't\r
+ *         try to generate digits strictly left to right.  Instead, we\r
+ *         compute with fewer bits and propagate the carry if necessary\r
+ *         when rounding the final digit up.  This is often faster.\r
+ *      3. Under the assumption that input will be rounded nearest,\r
+ *         mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.\r
+ *         That is, we allow equality in stopping tests when the\r
+ *         round-nearest rule will give the same floating-point value\r
+ *         as would satisfaction of the stopping test with strict\r
+ *         inequality.\r
+ *      4. We remove common factors of powers of 2 from relevant\r
+ *         quantities.\r
+ *      5. When converting floating-point integers less than 1e16,\r
+ *         we use floating-point arithmetic rather than resorting\r
+ *         to multiple-precision integers.\r
+ *      6. When asked to produce fewer than 15 digits, we first try\r
+ *         to get by with floating-point arithmetic; we resort to\r
+ *         multiple-precision integer arithmetic only if we cannot\r
+ *         guarantee that the floating-point calculation has given\r
+ *         the correctly rounded result.  For k requested digits and\r
+ *         "uniformly" distributed input, the probability is\r
+ *         something like 10^(k-15) that we must resort to the Long\r
+ *         calculation.\r
+ */\r
+\r
+/* Additional notes (METD): (1) returns NULL on failure.  (2) to avoid memory\r
+   leakage, a successful call to _Py_dg_dtoa should always be matched by a\r
+   call to _Py_dg_freedtoa. */\r
+\r
+char *\r
+_Py_dg_dtoa(double dd, int mode, int ndigits,\r
+            int *decpt, int *sign, char **rve)\r
+{\r
+    /*  Arguments ndigits, decpt, sign are similar to those\r
+        of ecvt and fcvt; trailing zeros are suppressed from\r
+        the returned string.  If not null, *rve is set to point\r
+        to the end of the return value.  If d is +-Infinity or NaN,\r
+        then *decpt is set to 9999.\r
+\r
+        mode:\r
+        0 ==> shortest string that yields d when read in\r
+        and rounded to nearest.\r
+        1 ==> like 0, but with Steele & White stopping rule;\r
+        e.g. with IEEE P754 arithmetic , mode 0 gives\r
+        1e23 whereas mode 1 gives 9.999999999999999e22.\r
+        2 ==> max(1,ndigits) significant digits.  This gives a\r
+        return value similar to that of ecvt, except\r
+        that trailing zeros are suppressed.\r
+        3 ==> through ndigits past the decimal point.  This\r
+        gives a return value similar to that from fcvt,\r
+        except that trailing zeros are suppressed, and\r
+        ndigits can be negative.\r
+        4,5 ==> similar to 2 and 3, respectively, but (in\r
+        round-nearest mode) with the tests of mode 0 to\r
+        possibly return a shorter string that rounds to d.\r
+        With IEEE arithmetic and compilation with\r
+        -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same\r
+        as modes 2 and 3 when FLT_ROUNDS != 1.\r
+        6-9 ==> Debugging modes similar to mode - 4:  don't try\r
+        fast floating-point estimate (if applicable).\r
+\r
+        Values of mode other than 0-9 are treated as mode 0.\r
+\r
+        Sufficient space is allocated to the return value\r
+        to hold the suppressed trailing zeros.\r
+    */\r
+\r
+    int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1,\r
+        j, j1, k, k0, k_check, leftright, m2, m5, s2, s5,\r
+        spec_case, try_quick;\r
+    Long L;\r
+    int denorm;\r
+    ULong x;\r
+    Bigint *b, *b1, *delta, *mlo, *mhi, *S;\r
+    U d2, eps, u;\r
+    double ds;\r
+    char *s, *s0;\r
+\r
+    /* set pointers to NULL, to silence gcc compiler warnings and make\r
+       cleanup easier on error */\r
+    mlo = mhi = S = 0;\r
+    s0 = 0;\r
+\r
+    u.d = dd;\r
+    if (word0(&u) & Sign_bit) {\r
+        /* set sign for everything, including 0's and NaNs */\r
+        *sign = 1;\r
+        word0(&u) &= ~Sign_bit; /* clear sign bit */\r
+    }\r
+    else\r
+        *sign = 0;\r
+\r
+    /* quick return for Infinities, NaNs and zeros */\r
+    if ((word0(&u) & Exp_mask) == Exp_mask)\r
+    {\r
+        /* Infinity or NaN */\r
+        *decpt = 9999;\r
+        if (!word1(&u) && !(word0(&u) & 0xfffff))\r
+            return nrv_alloc("Infinity", rve, 8);\r
+        return nrv_alloc("NaN", rve, 3);\r
+    }\r
+    if (!dval(&u)) {\r
+        *decpt = 1;\r
+        return nrv_alloc("0", rve, 1);\r
+    }\r
+\r
+    /* compute k = floor(log10(d)).  The computation may leave k\r
+       one too large, but should never leave k too small. */\r
+    b = d2b(&u, &be, &bbits);\r
+    if (b == NULL)\r
+        goto failed_malloc;\r
+    if ((i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask>>Exp_shift1)))) {\r
+        dval(&d2) = dval(&u);\r
+        word0(&d2) &= Frac_mask1;\r
+        word0(&d2) |= Exp_11;\r
+\r
+        /* log(x)       ~=~ log(1.5) + (x-1.5)/1.5\r
+         * log10(x)      =  log(x) / log(10)\r
+         *              ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))\r
+         * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2)\r
+         *\r
+         * This suggests computing an approximation k to log10(d) by\r
+         *\r
+         * k = (i - Bias)*0.301029995663981\r
+         *      + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );\r
+         *\r
+         * We want k to be too large rather than too small.\r
+         * The error in the first-order Taylor series approximation\r
+         * is in our favor, so we just round up the constant enough\r
+         * to compensate for any error in the multiplication of\r
+         * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,\r
+         * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,\r
+         * adding 1e-13 to the constant term more than suffices.\r
+         * Hence we adjust the constant term to 0.1760912590558.\r
+         * (We could get a more accurate k by invoking log10,\r
+         *  but this is probably not worthwhile.)\r
+         */\r
+\r
+        i -= Bias;\r
+        denorm = 0;\r
+    }\r
+    else {\r
+        /* d is denormalized */\r
+\r
+        i = bbits + be + (Bias + (P-1) - 1);\r
+        x = i > 32  ? word0(&u) << (64 - i) | word1(&u) >> (i - 32)\r
+            : word1(&u) << (32 - i);\r
+        dval(&d2) = x;\r
+        word0(&d2) -= 31*Exp_msk1; /* adjust exponent */\r
+        i -= (Bias + (P-1) - 1) + 1;\r
+        denorm = 1;\r
+    }\r
+    ds = (dval(&d2)-1.5)*0.289529654602168 + 0.1760912590558 +\r
+        i*0.301029995663981;\r
+    k = (int)ds;\r
+    if (ds < 0. && ds != k)\r
+        k--;    /* want k = floor(ds) */\r
+    k_check = 1;\r
+    if (k >= 0 && k <= Ten_pmax) {\r
+        if (dval(&u) < tens[k])\r
+            k--;\r
+        k_check = 0;\r
+    }\r
+    j = bbits - i - 1;\r
+    if (j >= 0) {\r
+        b2 = 0;\r
+        s2 = j;\r
+    }\r
+    else {\r
+        b2 = -j;\r
+        s2 = 0;\r
+    }\r
+    if (k >= 0) {\r
+        b5 = 0;\r
+        s5 = k;\r
+        s2 += k;\r
+    }\r
+    else {\r
+        b2 -= k;\r
+        b5 = -k;\r
+        s5 = 0;\r
+    }\r
+    if (mode < 0 || mode > 9)\r
+        mode = 0;\r
+\r
+    try_quick = 1;\r
+\r
+    if (mode > 5) {\r
+        mode -= 4;\r
+        try_quick = 0;\r
+    }\r
+    leftright = 1;\r
+    ilim = ilim1 = -1;  /* Values for cases 0 and 1; done here to */\r
+    /* silence erroneous "gcc -Wall" warning. */\r
+    switch(mode) {\r
+    case 0:\r
+    case 1:\r
+        i = 18;\r
+        ndigits = 0;\r
+        break;\r
+    case 2:\r
+        leftright = 0;\r
+        /* no break */\r
+    case 4:\r
+        if (ndigits <= 0)\r
+            ndigits = 1;\r
+        ilim = ilim1 = i = ndigits;\r
+        break;\r
+    case 3:\r
+        leftright = 0;\r
+        /* no break */\r
+    case 5:\r
+        i = ndigits + k + 1;\r
+        ilim = i;\r
+        ilim1 = i - 1;\r
+        if (i <= 0)\r
+            i = 1;\r
+    }\r
+    s0 = rv_alloc(i);\r
+    if (s0 == NULL)\r
+        goto failed_malloc;\r
+    s = s0;\r
+\r
+\r
+    if (ilim >= 0 && ilim <= Quick_max && try_quick) {\r
+\r
+        /* Try to get by with floating-point arithmetic. */\r
+\r
+        i = 0;\r
+        dval(&d2) = dval(&u);\r
+        k0 = k;\r
+        ilim0 = ilim;\r
+        ieps = 2; /* conservative */\r
+        if (k > 0) {\r
+            ds = tens[k&0xf];\r
+            j = k >> 4;\r
+            if (j & Bletch) {\r
+                /* prevent overflows */\r
+                j &= Bletch - 1;\r
+                dval(&u) /= bigtens[n_bigtens-1];\r
+                ieps++;\r
+            }\r
+            for(; j; j >>= 1, i++)\r
+                if (j & 1) {\r
+                    ieps++;\r
+                    ds *= bigtens[i];\r
+                }\r
+            dval(&u) /= ds;\r
+        }\r
+        else if ((j1 = -k)) {\r
+            dval(&u) *= tens[j1 & 0xf];\r
+            for(j = j1 >> 4; j; j >>= 1, i++)\r
+                if (j & 1) {\r
+                    ieps++;\r
+                    dval(&u) *= bigtens[i];\r
+                }\r
+        }\r
+        if (k_check && dval(&u) < 1. && ilim > 0) {\r
+            if (ilim1 <= 0)\r
+                goto fast_failed;\r
+            ilim = ilim1;\r
+            k--;\r
+            dval(&u) *= 10.;\r
+            ieps++;\r
+        }\r
+        dval(&eps) = ieps*dval(&u) + 7.;\r
+        word0(&eps) -= (P-1)*Exp_msk1;\r
+        if (ilim == 0) {\r
+            S = mhi = 0;\r
+            dval(&u) -= 5.;\r
+            if (dval(&u) > dval(&eps))\r
+                goto one_digit;\r
+            if (dval(&u) < -dval(&eps))\r
+                goto no_digits;\r
+            goto fast_failed;\r
+        }\r
+        if (leftright) {\r
+            /* Use Steele & White method of only\r
+             * generating digits needed.\r
+             */\r
+            dval(&eps) = 0.5/tens[ilim-1] - dval(&eps);\r
+            for(i = 0;;) {\r
+                L = (Long)dval(&u);\r
+                dval(&u) -= L;\r
+                *s++ = '0' + (int)L;\r
+                if (dval(&u) < dval(&eps))\r
+                    goto ret1;\r
+                if (1. - dval(&u) < dval(&eps))\r
+                    goto bump_up;\r
+                if (++i >= ilim)\r
+                    break;\r
+                dval(&eps) *= 10.;\r
+                dval(&u) *= 10.;\r
+            }\r
+        }\r
+        else {\r
+            /* Generate ilim digits, then fix them up. */\r
+            dval(&eps) *= tens[ilim-1];\r
+            for(i = 1;; i++, dval(&u) *= 10.) {\r
+                L = (Long)(dval(&u));\r
+                if (!(dval(&u) -= L))\r
+                    ilim = i;\r
+                *s++ = '0' + (int)L;\r
+                if (i == ilim) {\r
+                    if (dval(&u) > 0.5 + dval(&eps))\r
+                        goto bump_up;\r
+                    else if (dval(&u) < 0.5 - dval(&eps)) {\r
+                        while(*--s == '0');\r
+                        s++;\r
+                        goto ret1;\r
+                    }\r
+                    break;\r
+                }\r
+            }\r
+        }\r
+      fast_failed:\r
+        s = s0;\r
+        dval(&u) = dval(&d2);\r
+        k = k0;\r
+        ilim = ilim0;\r
+    }\r
+\r
+    /* Do we have a "small" integer? */\r
+\r
+    if (be >= 0 && k <= Int_max) {\r
+        /* Yes. */\r
+        ds = tens[k];\r
+        if (ndigits < 0 && ilim <= 0) {\r
+            S = mhi = 0;\r
+            if (ilim < 0 || dval(&u) <= 5*ds)\r
+                goto no_digits;\r
+            goto one_digit;\r
+        }\r
+        for(i = 1;; i++, dval(&u) *= 10.) {\r
+            L = (Long)(dval(&u) / ds);\r
+            dval(&u) -= L*ds;\r
+            *s++ = '0' + (int)L;\r
+            if (!dval(&u)) {\r
+                break;\r
+            }\r
+            if (i == ilim) {\r
+                dval(&u) += dval(&u);\r
+                if (dval(&u) > ds || (dval(&u) == ds && L & 1)) {\r
+                  bump_up:\r
+                    while(*--s == '9')\r
+                        if (s == s0) {\r
+                            k++;\r
+                            *s = '0';\r
+                            break;\r
+                        }\r
+                    ++*s++;\r
+                }\r
+                break;\r
+            }\r
+        }\r
+        goto ret1;\r
+    }\r
+\r
+    m2 = b2;\r
+    m5 = b5;\r
+    if (leftright) {\r
+        i =\r
+            denorm ? be + (Bias + (P-1) - 1 + 1) :\r
+            1 + P - bbits;\r
+        b2 += i;\r
+        s2 += i;\r
+        mhi = i2b(1);\r
+        if (mhi == NULL)\r
+            goto failed_malloc;\r
+    }\r
+    if (m2 > 0 && s2 > 0) {\r
+        i = m2 < s2 ? m2 : s2;\r
+        b2 -= i;\r
+        m2 -= i;\r
+        s2 -= i;\r
+    }\r
+    if (b5 > 0) {\r
+        if (leftright) {\r
+            if (m5 > 0) {\r
+                mhi = pow5mult(mhi, m5);\r
+                if (mhi == NULL)\r
+                    goto failed_malloc;\r
+                b1 = mult(mhi, b);\r
+                Bfree(b);\r
+                b = b1;\r
+                if (b == NULL)\r
+                    goto failed_malloc;\r
+            }\r
+            if ((j = b5 - m5)) {\r
+                b = pow5mult(b, j);\r
+                if (b == NULL)\r
+                    goto failed_malloc;\r
+            }\r
+        }\r
+        else {\r
+            b = pow5mult(b, b5);\r
+            if (b == NULL)\r
+                goto failed_malloc;\r
+        }\r
+    }\r
+    S = i2b(1);\r
+    if (S == NULL)\r
+        goto failed_malloc;\r
+    if (s5 > 0) {\r
+        S = pow5mult(S, s5);\r
+        if (S == NULL)\r
+            goto failed_malloc;\r
+    }\r
+\r
+    /* Check for special case that d is a normalized power of 2. */\r
+\r
+    spec_case = 0;\r
+    if ((mode < 2 || leftright)\r
+        ) {\r
+        if (!word1(&u) && !(word0(&u) & Bndry_mask)\r
+            && word0(&u) & (Exp_mask & ~Exp_msk1)\r
+            ) {\r
+            /* The special case */\r
+            b2 += Log2P;\r
+            s2 += Log2P;\r
+            spec_case = 1;\r
+        }\r
+    }\r
+\r
+    /* Arrange for convenient computation of quotients:\r
+     * shift left if necessary so divisor has 4 leading 0 bits.\r
+     *\r
+     * Perhaps we should just compute leading 28 bits of S once\r
+     * and for all and pass them and a shift to quorem, so it\r
+     * can do shifts and ors to compute the numerator for q.\r
+     */\r
+#define iInc 28\r
+    i = dshift(S, s2);\r
+    b2 += i;\r
+    m2 += i;\r
+    s2 += i;\r
+    if (b2 > 0) {\r
+        b = lshift(b, b2);\r
+        if (b == NULL)\r
+            goto failed_malloc;\r
+    }\r
+    if (s2 > 0) {\r
+        S = lshift(S, s2);\r
+        if (S == NULL)\r
+            goto failed_malloc;\r
+    }\r
+    if (k_check) {\r
+        if (cmp(b,S) < 0) {\r
+            k--;\r
+            b = multadd(b, 10, 0);      /* we botched the k estimate */\r
+            if (b == NULL)\r
+                goto failed_malloc;\r
+            if (leftright) {\r
+                mhi = multadd(mhi, 10, 0);\r
+                if (mhi == NULL)\r
+                    goto failed_malloc;\r
+            }\r
+            ilim = ilim1;\r
+        }\r
+    }\r
+    if (ilim <= 0 && (mode == 3 || mode == 5)) {\r
+        if (ilim < 0) {\r
+            /* no digits, fcvt style */\r
+          no_digits:\r
+            k = -1 - ndigits;\r
+            goto ret;\r
+        }\r
+        else {\r
+            S = multadd(S, 5, 0);\r
+            if (S == NULL)\r
+                goto failed_malloc;\r
+            if (cmp(b, S) <= 0)\r
+                goto no_digits;\r
+        }\r
+      one_digit:\r
+        *s++ = '1';\r
+        k++;\r
+        goto ret;\r
+    }\r
+    if (leftright) {\r
+        if (m2 > 0) {\r
+            mhi = lshift(mhi, m2);\r
+            if (mhi == NULL)\r
+                goto failed_malloc;\r
+        }\r
+\r
+        /* Compute mlo -- check for special case\r
+         * that d is a normalized power of 2.\r
+         */\r
+\r
+        mlo = mhi;\r
+        if (spec_case) {\r
+            mhi = Balloc(mhi->k);\r
+            if (mhi == NULL)\r
+                goto failed_malloc;\r
+            Bcopy(mhi, mlo);\r
+            mhi = lshift(mhi, Log2P);\r
+            if (mhi == NULL)\r
+                goto failed_malloc;\r
+        }\r
+\r
+        for(i = 1;;i++) {\r
+            dig = quorem(b,S) + '0';\r
+            /* Do we yet have the shortest decimal string\r
+             * that will round to d?\r
+             */\r
+            j = cmp(b, mlo);\r
+            delta = diff(S, mhi);\r
+            if (delta == NULL)\r
+                goto failed_malloc;\r
+            j1 = delta->sign ? 1 : cmp(b, delta);\r
+            Bfree(delta);\r
+            if (j1 == 0 && mode != 1 && !(word1(&u) & 1)\r
+                ) {\r
+                if (dig == '9')\r
+                    goto round_9_up;\r
+                if (j > 0)\r
+                    dig++;\r
+                *s++ = dig;\r
+                goto ret;\r
+            }\r
+            if (j < 0 || (j == 0 && mode != 1\r
+                          && !(word1(&u) & 1)\r
+                    )) {\r
+                if (!b->x[0] && b->wds <= 1) {\r
+                    goto accept_dig;\r
+                }\r
+                if (j1 > 0) {\r
+                    b = lshift(b, 1);\r
+                    if (b == NULL)\r
+                        goto failed_malloc;\r
+                    j1 = cmp(b, S);\r
+                    if ((j1 > 0 || (j1 == 0 && dig & 1))\r
+                        && dig++ == '9')\r
+                        goto round_9_up;\r
+                }\r
+              accept_dig:\r
+                *s++ = dig;\r
+                goto ret;\r
+            }\r
+            if (j1 > 0) {\r
+                if (dig == '9') { /* possible if i == 1 */\r
+                  round_9_up:\r
+                    *s++ = '9';\r
+                    goto roundoff;\r
+                }\r
+                *s++ = dig + 1;\r
+                goto ret;\r
+            }\r
+            *s++ = dig;\r
+            if (i == ilim)\r
+                break;\r
+            b = multadd(b, 10, 0);\r
+            if (b == NULL)\r
+                goto failed_malloc;\r
+            if (mlo == mhi) {\r
+                mlo = mhi = multadd(mhi, 10, 0);\r
+                if (mlo == NULL)\r
+                    goto failed_malloc;\r
+            }\r
+            else {\r
+                mlo = multadd(mlo, 10, 0);\r
+                if (mlo == NULL)\r
+                    goto failed_malloc;\r
+                mhi = multadd(mhi, 10, 0);\r
+                if (mhi == NULL)\r
+                    goto failed_malloc;\r
+            }\r
+        }\r
+    }\r
+    else\r
+        for(i = 1;; i++) {\r
+            *s++ = dig = quorem(b,S) + '0';\r
+            if (!b->x[0] && b->wds <= 1) {\r
+                goto ret;\r
+            }\r
+            if (i >= ilim)\r
+                break;\r
+            b = multadd(b, 10, 0);\r
+            if (b == NULL)\r
+                goto failed_malloc;\r
+        }\r
+\r
+    /* Round off last digit */\r
+\r
+    b = lshift(b, 1);\r
+    if (b == NULL)\r
+        goto failed_malloc;\r
+    j = cmp(b, S);\r
+    if (j > 0 || (j == 0 && dig & 1)) {\r
+      roundoff:\r
+        while(*--s == '9')\r
+            if (s == s0) {\r
+                k++;\r
+                *s++ = '1';\r
+                goto ret;\r
+            }\r
+        ++*s++;\r
+    }\r
+    else {\r
+        while(*--s == '0');\r
+        s++;\r
+    }\r
+  ret:\r
+    Bfree(S);\r
+    if (mhi) {\r
+        if (mlo && mlo != mhi)\r
+            Bfree(mlo);\r
+        Bfree(mhi);\r
+    }\r
+  ret1:\r
+    Bfree(b);\r
+    *s = 0;\r
+    *decpt = k + 1;\r
+    if (rve)\r
+        *rve = s;\r
+    return s0;\r
+  failed_malloc:\r
+    if (S)\r
+        Bfree(S);\r
+    if (mlo && mlo != mhi)\r
+        Bfree(mlo);\r
+    if (mhi)\r
+        Bfree(mhi);\r
+    if (b)\r
+        Bfree(b);\r
+    if (s0)\r
+        _Py_dg_freedtoa(s0);\r
+    return NULL;\r
+}\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif  /* PY_NO_SHORT_FLOAT_REPR */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/dynload_stub.c b/AppPkg/Applications/Python/Python-2.7.10/Python/dynload_stub.c
new file mode 100644 (file)
index 0000000..80f4abf
--- /dev/null
@@ -0,0 +1,11 @@
+\r
+/* This module provides the necessary stubs for when dynamic loading is\r
+   not present. */\r
+\r
+#include "Python.h"\r
+#include "importdl.h"\r
+\r
+\r
+const struct filedescr _PyImport_DynLoadFiletab[] = {\r
+       {0, 0}\r
+};\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/errors.c b/AppPkg/Applications/Python/Python-2.7.10/Python/errors.c
new file mode 100644 (file)
index 0000000..8e9b5da
--- /dev/null
@@ -0,0 +1,827 @@
+\r
+/* Error handling */\r
+\r
+#include "Python.h"\r
+\r
+#ifndef __STDC__\r
+#ifndef MS_WINDOWS\r
+extern char *strerror(int);\r
+#endif\r
+#endif\r
+\r
+#ifdef MS_WINDOWS\r
+#include "windows.h"\r
+#include "winbase.h"\r
+#endif\r
+\r
+#include <ctype.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+void\r
+PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)\r
+{\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    PyObject *oldtype, *oldvalue, *oldtraceback;\r
+\r
+    if (traceback != NULL && !PyTraceBack_Check(traceback)) {\r
+        /* XXX Should never happen -- fatal error instead? */\r
+        /* Well, it could be None. */\r
+        Py_DECREF(traceback);\r
+        traceback = NULL;\r
+    }\r
+\r
+    /* Save these in locals to safeguard against recursive\r
+       invocation through Py_XDECREF */\r
+    oldtype = tstate->curexc_type;\r
+    oldvalue = tstate->curexc_value;\r
+    oldtraceback = tstate->curexc_traceback;\r
+\r
+    tstate->curexc_type = type;\r
+    tstate->curexc_value = value;\r
+    tstate->curexc_traceback = traceback;\r
+\r
+    Py_XDECREF(oldtype);\r
+    Py_XDECREF(oldvalue);\r
+    Py_XDECREF(oldtraceback);\r
+}\r
+\r
+void\r
+PyErr_SetObject(PyObject *exception, PyObject *value)\r
+{\r
+    Py_XINCREF(exception);\r
+    Py_XINCREF(value);\r
+    PyErr_Restore(exception, value, (PyObject *)NULL);\r
+}\r
+\r
+void\r
+PyErr_SetNone(PyObject *exception)\r
+{\r
+    PyErr_SetObject(exception, (PyObject *)NULL);\r
+}\r
+\r
+void\r
+PyErr_SetString(PyObject *exception, const char *string)\r
+{\r
+    PyObject *value = PyString_FromString(string);\r
+    PyErr_SetObject(exception, value);\r
+    Py_XDECREF(value);\r
+}\r
+\r
+\r
+PyObject *\r
+PyErr_Occurred(void)\r
+{\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+\r
+    return tstate->curexc_type;\r
+}\r
+\r
+\r
+int\r
+PyErr_GivenExceptionMatches(PyObject *err, PyObject *exc)\r
+{\r
+    if (err == NULL || exc == NULL) {\r
+        /* maybe caused by "import exceptions" that failed early on */\r
+        return 0;\r
+    }\r
+    if (PyTuple_Check(exc)) {\r
+        Py_ssize_t i, n;\r
+        n = PyTuple_Size(exc);\r
+        for (i = 0; i < n; i++) {\r
+            /* Test recursively */\r
+             if (PyErr_GivenExceptionMatches(\r
+                 err, PyTuple_GET_ITEM(exc, i)))\r
+             {\r
+                 return 1;\r
+             }\r
+        }\r
+        return 0;\r
+    }\r
+    /* err might be an instance, so check its class. */\r
+    if (PyExceptionInstance_Check(err))\r
+        err = PyExceptionInstance_Class(err);\r
+\r
+    if (PyExceptionClass_Check(err) && PyExceptionClass_Check(exc)) {\r
+        int res = 0, reclimit;\r
+        PyObject *exception, *value, *tb;\r
+        PyErr_Fetch(&exception, &value, &tb);\r
+        /* Temporarily bump the recursion limit, so that in the most\r
+           common case PyObject_IsSubclass will not raise a recursion\r
+           error we have to ignore anyway.  Don't do it when the limit\r
+           is already insanely high, to avoid overflow */\r
+        reclimit = Py_GetRecursionLimit();\r
+        if (reclimit < (1 << 30))\r
+            Py_SetRecursionLimit(reclimit + 5);\r
+        res = PyObject_IsSubclass(err, exc);\r
+        Py_SetRecursionLimit(reclimit);\r
+        /* This function must not fail, so print the error here */\r
+        if (res == -1) {\r
+            PyErr_WriteUnraisable(err);\r
+            res = 0;\r
+        }\r
+        PyErr_Restore(exception, value, tb);\r
+        return res;\r
+    }\r
+\r
+    return err == exc;\r
+}\r
+\r
+\r
+int\r
+PyErr_ExceptionMatches(PyObject *exc)\r
+{\r
+    return PyErr_GivenExceptionMatches(PyErr_Occurred(), exc);\r
+}\r
+\r
+\r
+/* Used in many places to normalize a raised exception, including in\r
+   eval_code2(), do_raise(), and PyErr_Print()\r
+*/\r
+void\r
+PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)\r
+{\r
+    PyObject *type = *exc;\r
+    PyObject *value = *val;\r
+    PyObject *inclass = NULL;\r
+    PyObject *initial_tb = NULL;\r
+    PyThreadState *tstate = NULL;\r
+\r
+    if (type == NULL) {\r
+        /* There was no exception, so nothing to do. */\r
+        return;\r
+    }\r
+\r
+    /* If PyErr_SetNone() was used, the value will have been actually\r
+       set to NULL.\r
+    */\r
+    if (!value) {\r
+        value = Py_None;\r
+        Py_INCREF(value);\r
+    }\r
+\r
+    if (PyExceptionInstance_Check(value))\r
+        inclass = PyExceptionInstance_Class(value);\r
+\r
+    /* Normalize the exception so that if the type is a class, the\r
+       value will be an instance.\r
+    */\r
+    if (PyExceptionClass_Check(type)) {\r
+        /* if the value was not an instance, or is not an instance\r
+           whose class is (or is derived from) type, then use the\r
+           value as an argument to instantiation of the type\r
+           class.\r
+        */\r
+        if (!inclass || !PyObject_IsSubclass(inclass, type)) {\r
+            PyObject *args, *res;\r
+\r
+            if (value == Py_None)\r
+                args = PyTuple_New(0);\r
+            else if (PyTuple_Check(value)) {\r
+                Py_INCREF(value);\r
+                args = value;\r
+            }\r
+            else\r
+                args = PyTuple_Pack(1, value);\r
+\r
+            if (args == NULL)\r
+                goto finally;\r
+            res = PyEval_CallObject(type, args);\r
+            Py_DECREF(args);\r
+            if (res == NULL)\r
+                goto finally;\r
+            Py_DECREF(value);\r
+            value = res;\r
+        }\r
+        /* if the class of the instance doesn't exactly match the\r
+           class of the type, believe the instance\r
+        */\r
+        else if (inclass != type) {\r
+            Py_DECREF(type);\r
+            type = inclass;\r
+            Py_INCREF(type);\r
+        }\r
+    }\r
+    *exc = type;\r
+    *val = value;\r
+    return;\r
+finally:\r
+    Py_DECREF(type);\r
+    Py_DECREF(value);\r
+    /* If the new exception doesn't set a traceback and the old\r
+       exception had a traceback, use the old traceback for the\r
+       new exception.  It's better than nothing.\r
+    */\r
+    initial_tb = *tb;\r
+    PyErr_Fetch(exc, val, tb);\r
+    if (initial_tb != NULL) {\r
+        if (*tb == NULL)\r
+            *tb = initial_tb;\r
+        else\r
+            Py_DECREF(initial_tb);\r
+    }\r
+    /* normalize recursively */\r
+    tstate = PyThreadState_GET();\r
+    if (++tstate->recursion_depth > Py_GetRecursionLimit()) {\r
+        --tstate->recursion_depth;\r
+        /* throw away the old exception... */\r
+        Py_DECREF(*exc);\r
+        Py_DECREF(*val);\r
+        /* ... and use the recursion error instead */\r
+        *exc = PyExc_RuntimeError;\r
+        *val = PyExc_RecursionErrorInst;\r
+        Py_INCREF(*exc);\r
+        Py_INCREF(*val);\r
+        /* just keeping the old traceback */\r
+        return;\r
+    }\r
+    PyErr_NormalizeException(exc, val, tb);\r
+    --tstate->recursion_depth;\r
+}\r
+\r
+\r
+void\r
+PyErr_Fetch(PyObject **p_type, PyObject **p_value, PyObject **p_traceback)\r
+{\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+\r
+    *p_type = tstate->curexc_type;\r
+    *p_value = tstate->curexc_value;\r
+    *p_traceback = tstate->curexc_traceback;\r
+\r
+    tstate->curexc_type = NULL;\r
+    tstate->curexc_value = NULL;\r
+    tstate->curexc_traceback = NULL;\r
+}\r
+\r
+void\r
+PyErr_Clear(void)\r
+{\r
+    PyErr_Restore(NULL, NULL, NULL);\r
+}\r
+\r
+/* Restore previously fetched exception if an exception is not set,\r
+   otherwise drop previously fetched exception.\r
+   Like _PyErr_ChainExceptions() in Python 3, but doesn't set the context.\r
+ */\r
+void\r
+_PyErr_ReplaceException(PyObject *exc, PyObject *val, PyObject *tb)\r
+{\r
+    if (exc == NULL)\r
+        return;\r
+\r
+    if (PyErr_Occurred()) {\r
+        Py_DECREF(exc);\r
+        Py_XDECREF(val);\r
+        Py_XDECREF(tb);\r
+    }\r
+    else {\r
+        PyErr_Restore(exc, val, tb);\r
+    }\r
+}\r
+\r
+/* Convenience functions to set a type error exception and return 0 */\r
+\r
+int\r
+PyErr_BadArgument(void)\r
+{\r
+    PyErr_SetString(PyExc_TypeError,\r
+                    "bad argument type for built-in operation");\r
+    return 0;\r
+}\r
+\r
+PyObject *\r
+PyErr_NoMemory(void)\r
+{\r
+    if (PyErr_ExceptionMatches(PyExc_MemoryError))\r
+        /* already current */\r
+        return NULL;\r
+\r
+    /* raise the pre-allocated instance if it still exists */\r
+    if (PyExc_MemoryErrorInst)\r
+        PyErr_SetObject(PyExc_MemoryError, PyExc_MemoryErrorInst);\r
+    else\r
+        /* this will probably fail since there's no memory and hee,\r
+           hee, we have to instantiate this class\r
+        */\r
+        PyErr_SetNone(PyExc_MemoryError);\r
+\r
+    return NULL;\r
+}\r
+\r
+PyObject *\r
+PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject)\r
+{\r
+    PyObject *v;\r
+    char *s;\r
+    int i = errno;\r
+#ifdef PLAN9\r
+    char errbuf[ERRMAX];\r
+#endif\r
+#ifdef MS_WINDOWS\r
+    char *s_buf = NULL;\r
+    char s_small_buf[28]; /* Room for "Windows Error 0xFFFFFFFF" */\r
+#endif\r
+#ifdef EINTR\r
+    if (i == EINTR && PyErr_CheckSignals())\r
+        return NULL;\r
+#endif\r
+#ifdef PLAN9\r
+    rerrstr(errbuf, sizeof errbuf);\r
+    s = errbuf;\r
+#else\r
+    if (i == 0)\r
+        s = "Error"; /* Sometimes errno didn't get set */\r
+    else\r
+#ifndef MS_WINDOWS\r
+        s = strerror(i);\r
+#else\r
+    {\r
+        /* Note that the Win32 errors do not lineup with the\r
+           errno error.  So if the error is in the MSVC error\r
+           table, we use it, otherwise we assume it really _is_\r
+           a Win32 error code\r
+        */\r
+        if (i > 0 && i < _sys_nerr) {\r
+            s = _sys_errlist[i];\r
+        }\r
+        else {\r
+            int len = FormatMessage(\r
+                FORMAT_MESSAGE_ALLOCATE_BUFFER |\r
+                FORMAT_MESSAGE_FROM_SYSTEM |\r
+                FORMAT_MESSAGE_IGNORE_INSERTS,\r
+                NULL,                   /* no message source */\r
+                i,\r
+                MAKELANGID(LANG_NEUTRAL,\r
+                           SUBLANG_DEFAULT),\r
+                           /* Default language */\r
+                (LPTSTR) &s_buf,\r
+                0,                      /* size not used */\r
+                NULL);                  /* no args */\r
+            if (len==0) {\r
+                /* Only ever seen this in out-of-mem\r
+                   situations */\r
+                sprintf(s_small_buf, "Windows Error 0x%X", i);\r
+                s = s_small_buf;\r
+                s_buf = NULL;\r
+            } else {\r
+                s = s_buf;\r
+                /* remove trailing cr/lf and dots */\r
+                while (len > 0 && (s[len-1] <= ' ' || s[len-1] == '.'))\r
+                    s[--len] = '\0';\r
+            }\r
+        }\r
+    }\r
+#endif /* Unix/Windows */\r
+#endif /* PLAN 9*/\r
+    if (filenameObject != NULL)\r
+        v = Py_BuildValue("(isO)", i, s, filenameObject);\r
+    else\r
+        v = Py_BuildValue("(is)", i, s);\r
+    if (v != NULL) {\r
+        PyErr_SetObject(exc, v);\r
+        Py_DECREF(v);\r
+    }\r
+#ifdef MS_WINDOWS\r
+    LocalFree(s_buf);\r
+#endif\r
+    return NULL;\r
+}\r
+\r
+\r
+PyObject *\r
+PyErr_SetFromErrnoWithFilename(PyObject *exc, const char *filename)\r
+{\r
+    PyObject *name = filename ? PyString_FromString(filename) : NULL;\r
+    PyObject *result = PyErr_SetFromErrnoWithFilenameObject(exc, name);\r
+    Py_XDECREF(name);\r
+    return result;\r
+}\r
+\r
+#ifdef MS_WINDOWS\r
+PyObject *\r
+PyErr_SetFromErrnoWithUnicodeFilename(PyObject *exc, const Py_UNICODE *filename)\r
+{\r
+    PyObject *name = filename ?\r
+                     PyUnicode_FromUnicode(filename, wcslen(filename)) :\r
+             NULL;\r
+    PyObject *result = PyErr_SetFromErrnoWithFilenameObject(exc, name);\r
+    Py_XDECREF(name);\r
+    return result;\r
+}\r
+#endif /* MS_WINDOWS */\r
+\r
+PyObject *\r
+PyErr_SetFromErrno(PyObject *exc)\r
+{\r
+    return PyErr_SetFromErrnoWithFilenameObject(exc, NULL);\r
+}\r
+\r
+#ifdef MS_WINDOWS\r
+/* Windows specific error code handling */\r
+PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject(\r
+    PyObject *exc,\r
+    int ierr,\r
+    PyObject *filenameObject)\r
+{\r
+    int len;\r
+    char *s;\r
+    char *s_buf = NULL; /* Free via LocalFree */\r
+    char s_small_buf[28]; /* Room for "Windows Error 0xFFFFFFFF" */\r
+    PyObject *v;\r
+    DWORD err = (DWORD)ierr;\r
+    if (err==0) err = GetLastError();\r
+    len = FormatMessage(\r
+        /* Error API error */\r
+        FORMAT_MESSAGE_ALLOCATE_BUFFER |\r
+        FORMAT_MESSAGE_FROM_SYSTEM |\r
+        FORMAT_MESSAGE_IGNORE_INSERTS,\r
+        NULL,           /* no message source */\r
+        err,\r
+        MAKELANGID(LANG_NEUTRAL,\r
+        SUBLANG_DEFAULT), /* Default language */\r
+        (LPTSTR) &s_buf,\r
+        0,              /* size not used */\r
+        NULL);          /* no args */\r
+    if (len==0) {\r
+        /* Only seen this in out of mem situations */\r
+        sprintf(s_small_buf, "Windows Error 0x%X", err);\r
+        s = s_small_buf;\r
+        s_buf = NULL;\r
+    } else {\r
+        s = s_buf;\r
+        /* remove trailing cr/lf and dots */\r
+        while (len > 0 && (s[len-1] <= ' ' || s[len-1] == '.'))\r
+            s[--len] = '\0';\r
+    }\r
+    if (filenameObject != NULL)\r
+        v = Py_BuildValue("(isO)", err, s, filenameObject);\r
+    else\r
+        v = Py_BuildValue("(is)", err, s);\r
+    if (v != NULL) {\r
+        PyErr_SetObject(exc, v);\r
+        Py_DECREF(v);\r
+    }\r
+    LocalFree(s_buf);\r
+    return NULL;\r
+}\r
+\r
+PyObject *PyErr_SetExcFromWindowsErrWithFilename(\r
+    PyObject *exc,\r
+    int ierr,\r
+    const char *filename)\r
+{\r
+    PyObject *name = filename ? PyString_FromString(filename) : NULL;\r
+    PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObject(exc,\r
+                                                                 ierr,\r
+                                                                 name);\r
+    Py_XDECREF(name);\r
+    return ret;\r
+}\r
+\r
+PyObject *PyErr_SetExcFromWindowsErrWithUnicodeFilename(\r
+    PyObject *exc,\r
+    int ierr,\r
+    const Py_UNICODE *filename)\r
+{\r
+    PyObject *name = filename ?\r
+                     PyUnicode_FromUnicode(filename, wcslen(filename)) :\r
+             NULL;\r
+    PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObject(exc,\r
+                                                                 ierr,\r
+                                                                 name);\r
+    Py_XDECREF(name);\r
+    return ret;\r
+}\r
+\r
+PyObject *PyErr_SetExcFromWindowsErr(PyObject *exc, int ierr)\r
+{\r
+    return PyErr_SetExcFromWindowsErrWithFilename(exc, ierr, NULL);\r
+}\r
+\r
+PyObject *PyErr_SetFromWindowsErr(int ierr)\r
+{\r
+    return PyErr_SetExcFromWindowsErrWithFilename(PyExc_WindowsError,\r
+                                                  ierr, NULL);\r
+}\r
+PyObject *PyErr_SetFromWindowsErrWithFilename(\r
+    int ierr,\r
+    const char *filename)\r
+{\r
+    PyObject *name = filename ? PyString_FromString(filename) : NULL;\r
+    PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObject(\r
+                                                  PyExc_WindowsError,\r
+                                                  ierr, name);\r
+    Py_XDECREF(name);\r
+    return result;\r
+}\r
+\r
+PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename(\r
+    int ierr,\r
+    const Py_UNICODE *filename)\r
+{\r
+    PyObject *name = filename ?\r
+                     PyUnicode_FromUnicode(filename, wcslen(filename)) :\r
+             NULL;\r
+    PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObject(\r
+                                                  PyExc_WindowsError,\r
+                                                  ierr, name);\r
+    Py_XDECREF(name);\r
+    return result;\r
+}\r
+#endif /* MS_WINDOWS */\r
+\r
+void\r
+_PyErr_BadInternalCall(char *filename, int lineno)\r
+{\r
+    PyErr_Format(PyExc_SystemError,\r
+                 "%s:%d: bad argument to internal function",\r
+                 filename, lineno);\r
+}\r
+\r
+/* Remove the preprocessor macro for PyErr_BadInternalCall() so that we can\r
+   export the entry point for existing object code: */\r
+#undef PyErr_BadInternalCall\r
+void\r
+PyErr_BadInternalCall(void)\r
+{\r
+    PyErr_Format(PyExc_SystemError,\r
+                 "bad argument to internal function");\r
+}\r
+#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)\r
+\r
+\r
+\r
+PyObject *\r
+PyErr_Format(PyObject *exception, const char *format, ...)\r
+{\r
+    va_list vargs;\r
+    PyObject* string;\r
+\r
+#ifdef HAVE_STDARG_PROTOTYPES\r
+    va_start(vargs, format);\r
+#else\r
+    va_start(vargs);\r
+#endif\r
+\r
+    string = PyString_FromFormatV(format, vargs);\r
+    PyErr_SetObject(exception, string);\r
+    Py_XDECREF(string);\r
+    va_end(vargs);\r
+    return NULL;\r
+}\r
+\r
+\r
+\r
+PyObject *\r
+PyErr_NewException(char *name, PyObject *base, PyObject *dict)\r
+{\r
+    char *dot;\r
+    PyObject *modulename = NULL;\r
+    PyObject *classname = NULL;\r
+    PyObject *mydict = NULL;\r
+    PyObject *bases = NULL;\r
+    PyObject *result = NULL;\r
+    dot = strrchr(name, '.');\r
+    if (dot == NULL) {\r
+        PyErr_SetString(PyExc_SystemError,\r
+            "PyErr_NewException: name must be module.class");\r
+        return NULL;\r
+    }\r
+    if (base == NULL)\r
+        base = PyExc_Exception;\r
+    if (dict == NULL) {\r
+        dict = mydict = PyDict_New();\r
+        if (dict == NULL)\r
+            goto failure;\r
+    }\r
+    if (PyDict_GetItemString(dict, "__module__") == NULL) {\r
+        modulename = PyString_FromStringAndSize(name,\r
+                                             (Py_ssize_t)(dot-name));\r
+        if (modulename == NULL)\r
+            goto failure;\r
+        if (PyDict_SetItemString(dict, "__module__", modulename) != 0)\r
+            goto failure;\r
+    }\r
+    if (PyTuple_Check(base)) {\r
+        bases = base;\r
+        /* INCREF as we create a new ref in the else branch */\r
+        Py_INCREF(bases);\r
+    } else {\r
+        bases = PyTuple_Pack(1, base);\r
+        if (bases == NULL)\r
+            goto failure;\r
+    }\r
+    /* Create a real new-style class. */\r
+    result = PyObject_CallFunction((PyObject *)&PyType_Type, "sOO",\r
+                                   dot+1, bases, dict);\r
+  failure:\r
+    Py_XDECREF(bases);\r
+    Py_XDECREF(mydict);\r
+    Py_XDECREF(classname);\r
+    Py_XDECREF(modulename);\r
+    return result;\r
+}\r
+\r
+\r
+/* Create an exception with docstring */\r
+PyObject *\r
+PyErr_NewExceptionWithDoc(char *name, char *doc, PyObject *base, PyObject *dict)\r
+{\r
+    int result;\r
+    PyObject *ret = NULL;\r
+    PyObject *mydict = NULL; /* points to the dict only if we create it */\r
+    PyObject *docobj;\r
+\r
+    if (dict == NULL) {\r
+        dict = mydict = PyDict_New();\r
+        if (dict == NULL) {\r
+            return NULL;\r
+        }\r
+    }\r
+\r
+    if (doc != NULL) {\r
+        docobj = PyString_FromString(doc);\r
+        if (docobj == NULL)\r
+            goto failure;\r
+        result = PyDict_SetItemString(dict, "__doc__", docobj);\r
+        Py_DECREF(docobj);\r
+        if (result < 0)\r
+            goto failure;\r
+    }\r
+\r
+    ret = PyErr_NewException(name, base, dict);\r
+  failure:\r
+    Py_XDECREF(mydict);\r
+    return ret;\r
+}\r
+\r
+\r
+/* Call when an exception has occurred but there is no way for Python\r
+   to handle it.  Examples: exception in __del__ or during GC. */\r
+void\r
+PyErr_WriteUnraisable(PyObject *obj)\r
+{\r
+    PyObject *f, *t, *v, *tb;\r
+    PyErr_Fetch(&t, &v, &tb);\r
+    f = PySys_GetObject("stderr");\r
+    if (f != NULL) {\r
+        PyFile_WriteString("Exception ", f);\r
+        if (t) {\r
+            PyObject* moduleName;\r
+            char* className;\r
+            assert(PyExceptionClass_Check(t));\r
+            className = PyExceptionClass_Name(t);\r
+            if (className != NULL) {\r
+                char *dot = strrchr(className, '.');\r
+                if (dot != NULL)\r
+                    className = dot+1;\r
+            }\r
+\r
+            moduleName = PyObject_GetAttrString(t, "__module__");\r
+            if (moduleName == NULL)\r
+                PyFile_WriteString("<unknown>", f);\r
+            else {\r
+                char* modstr = PyString_AsString(moduleName);\r
+                if (modstr &&\r
+                    strcmp(modstr, "exceptions") != 0)\r
+                {\r
+                    PyFile_WriteString(modstr, f);\r
+                    PyFile_WriteString(".", f);\r
+                }\r
+            }\r
+            if (className == NULL)\r
+                PyFile_WriteString("<unknown>", f);\r
+            else\r
+                PyFile_WriteString(className, f);\r
+            if (v && v != Py_None) {\r
+                PyFile_WriteString(": ", f);\r
+                PyFile_WriteObject(v, f, 0);\r
+            }\r
+            Py_XDECREF(moduleName);\r
+        }\r
+        PyFile_WriteString(" in ", f);\r
+        PyFile_WriteObject(obj, f, 0);\r
+        PyFile_WriteString(" ignored\n", f);\r
+        PyErr_Clear(); /* Just in case */\r
+    }\r
+    Py_XDECREF(t);\r
+    Py_XDECREF(v);\r
+    Py_XDECREF(tb);\r
+}\r
+\r
+extern PyObject *PyModule_GetWarningsModule(void);\r
+\r
+\r
+/* Set file and line information for the current exception.\r
+   If the exception is not a SyntaxError, also sets additional attributes\r
+   to make printing of exceptions believe it is a syntax error. */\r
+\r
+void\r
+PyErr_SyntaxLocation(const char *filename, int lineno)\r
+{\r
+    PyObject *exc, *v, *tb, *tmp;\r
+\r
+    /* add attributes for the line number and filename for the error */\r
+    PyErr_Fetch(&exc, &v, &tb);\r
+    PyErr_NormalizeException(&exc, &v, &tb);\r
+    /* XXX check that it is, indeed, a syntax error. It might not\r
+     * be, though. */\r
+    tmp = PyInt_FromLong(lineno);\r
+    if (tmp == NULL)\r
+        PyErr_Clear();\r
+    else {\r
+        if (PyObject_SetAttrString(v, "lineno", tmp))\r
+            PyErr_Clear();\r
+        Py_DECREF(tmp);\r
+    }\r
+    if (filename != NULL) {\r
+        tmp = PyString_FromString(filename);\r
+        if (tmp == NULL)\r
+            PyErr_Clear();\r
+        else {\r
+            if (PyObject_SetAttrString(v, "filename", tmp))\r
+                PyErr_Clear();\r
+            Py_DECREF(tmp);\r
+        }\r
+\r
+        tmp = PyErr_ProgramText(filename, lineno);\r
+        if (tmp) {\r
+            if (PyObject_SetAttrString(v, "text", tmp))\r
+                PyErr_Clear();\r
+            Py_DECREF(tmp);\r
+        }\r
+    }\r
+    if (PyObject_SetAttrString(v, "offset", Py_None)) {\r
+        PyErr_Clear();\r
+    }\r
+    if (exc != PyExc_SyntaxError) {\r
+        if (!PyObject_HasAttrString(v, "msg")) {\r
+            tmp = PyObject_Str(v);\r
+            if (tmp) {\r
+                if (PyObject_SetAttrString(v, "msg", tmp))\r
+                    PyErr_Clear();\r
+                Py_DECREF(tmp);\r
+            } else {\r
+                PyErr_Clear();\r
+            }\r
+        }\r
+        if (!PyObject_HasAttrString(v, "print_file_and_line")) {\r
+            if (PyObject_SetAttrString(v, "print_file_and_line",\r
+                                       Py_None))\r
+                PyErr_Clear();\r
+        }\r
+    }\r
+    PyErr_Restore(exc, v, tb);\r
+}\r
+\r
+/* com_fetch_program_text will attempt to load the line of text that\r
+   the exception refers to.  If it fails, it will return NULL but will\r
+   not set an exception.\r
+\r
+   XXX The functionality of this function is quite similar to the\r
+   functionality in tb_displayline() in traceback.c.\r
+*/\r
+\r
+PyObject *\r
+PyErr_ProgramText(const char *filename, int lineno)\r
+{\r
+    FILE *fp;\r
+    int i;\r
+    char linebuf[1000];\r
+\r
+    if (filename == NULL || *filename == '\0' || lineno <= 0)\r
+        return NULL;\r
+    fp = fopen(filename, "r" PY_STDIOTEXTMODE);\r
+    if (fp == NULL)\r
+        return NULL;\r
+    for (i = 0; i < lineno; i++) {\r
+        char *pLastChar = &linebuf[sizeof(linebuf) - 2];\r
+        do {\r
+            *pLastChar = '\0';\r
+            if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, fp, NULL) == NULL)\r
+                break;\r
+            /* fgets read *something*; if it didn't get as\r
+               far as pLastChar, it must have found a newline\r
+               or hit the end of the file; if pLastChar is \n,\r
+               it obviously found a newline; else we haven't\r
+               yet seen a newline, so must continue */\r
+        } while (*pLastChar != '\0' && *pLastChar != '\n');\r
+    }\r
+    fclose(fp);\r
+    if (i == lineno) {\r
+        char *p = linebuf;\r
+        while (*p == ' ' || *p == '\t' || *p == '\014')\r
+            p++;\r
+        return PyString_FromString(p);\r
+    }\r
+    return NULL;\r
+}\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/formatter_string.c b/AppPkg/Applications/Python/Python-2.7.10/Python/formatter_string.c
new file mode 100644 (file)
index 0000000..1ab52e7
--- /dev/null
@@ -0,0 +1,17 @@
+/***********************************************************************/\r
+/* Implements the string (as opposed to unicode) version of the\r
+   built-in formatters for string, int, float.  That is, the versions\r
+   of int.__format__, etc., that take and return string objects */\r
+\r
+#include "Python.h"\r
+#include "../Objects/stringlib/stringdefs.h"\r
+\r
+#define FORMAT_STRING  _PyBytes_FormatAdvanced\r
+#define FORMAT_LONG    _PyLong_FormatAdvanced\r
+#define FORMAT_INT     _PyInt_FormatAdvanced\r
+#define FORMAT_FLOAT   _PyFloat_FormatAdvanced\r
+#ifndef WITHOUT_COMPLEX\r
+#define FORMAT_COMPLEX _PyComplex_FormatAdvanced\r
+#endif\r
+\r
+#include "../Objects/stringlib/formatter.h"\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/formatter_unicode.c b/AppPkg/Applications/Python/Python-2.7.10/Python/formatter_unicode.c
new file mode 100644 (file)
index 0000000..c431639
--- /dev/null
@@ -0,0 +1,18 @@
+/* Implements the unicode (as opposed to string) version of the\r
+   built-in formatter for unicode.  That is, unicode.__format__(). */\r
+\r
+#include "Python.h"\r
+\r
+#ifdef Py_USING_UNICODE\r
+\r
+#include "../Objects/stringlib/unicodedefs.h"\r
+\r
+#define FORMAT_STRING _PyUnicode_FormatAdvanced\r
+\r
+/* don't define FORMAT_LONG, FORMAT_FLOAT, and FORMAT_COMPLEX, since\r
+   we can live with only the string versions of those.  The builtin\r
+   format() will convert them to unicode. */\r
+\r
+#include "../Objects/stringlib/formatter.h"\r
+\r
+#endif\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/frozen.c b/AppPkg/Applications/Python/Python-2.7.10/Python/frozen.c
new file mode 100644 (file)
index 0000000..1ec3603
--- /dev/null
@@ -0,0 +1,38 @@
+\r
+/* Dummy frozen modules initializer */\r
+\r
+#include "Python.h"\r
+\r
+/* In order to test the support for frozen modules, by default we\r
+   define a single frozen module, __hello__.  Loading it will print\r
+   some famous words... */\r
+\r
+/* To regenerate this data after the bytecode or marshal format has changed,\r
+   go to ../Tools/freeze/ and freeze the hello.py file; then copy and paste\r
+   the appropriate bytes from M___main__.c. */\r
+\r
+static unsigned char M___hello__[] = {\r
+    99,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,\r
+    0,115,9,0,0,0,100,0,0,71,72,100,1,0,83,40,\r
+    2,0,0,0,115,14,0,0,0,72,101,108,108,111,32,119,\r
+    111,114,108,100,46,46,46,78,40,0,0,0,0,40,0,0,\r
+    0,0,40,0,0,0,0,40,0,0,0,0,115,8,0,0,\r
+    0,104,101,108,108,111,46,112,121,115,1,0,0,0,63,1,\r
+    0,0,0,115,0,0,0,0,\r
+};\r
+\r
+#define SIZE (int)sizeof(M___hello__)\r
+\r
+static struct _frozen _PyImport_FrozenModules[] = {\r
+    /* Test module */\r
+    {"__hello__", M___hello__, SIZE},\r
+    /* Test package (negative size indicates package-ness) */\r
+    {"__phello__", M___hello__, -SIZE},\r
+    {"__phello__.spam", M___hello__, SIZE},\r
+    {0, 0, 0} /* sentinel */\r
+};\r
+\r
+/* Embedding apps may change this pointer to point to their favorite\r
+   collection of frozen modules: */\r
+\r
+struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules;\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/future.c b/AppPkg/Applications/Python/Python-2.7.10/Python/future.c
new file mode 100644 (file)
index 0000000..740678d
--- /dev/null
@@ -0,0 +1,137 @@
+#include "Python.h"\r
+#include "Python-ast.h"\r
+#include "node.h"\r
+#include "token.h"\r
+#include "graminit.h"\r
+#include "code.h"\r
+#include "compile.h"\r
+#include "symtable.h"\r
+\r
+#define UNDEFINED_FUTURE_FEATURE "future feature %.100s is not defined"\r
+#define ERR_LATE_FUTURE \\r
+"from __future__ imports must occur at the beginning of the file"\r
+\r
+static int\r
+future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename)\r
+{\r
+    int i;\r
+    asdl_seq *names;\r
+\r
+    assert(s->kind == ImportFrom_kind);\r
+\r
+    names = s->v.ImportFrom.names;\r
+    for (i = 0; i < asdl_seq_LEN(names); i++) {\r
+        alias_ty name = (alias_ty)asdl_seq_GET(names, i);\r
+        const char *feature = PyString_AsString(name->name);\r
+        if (!feature)\r
+            return 0;\r
+        if (strcmp(feature, FUTURE_NESTED_SCOPES) == 0) {\r
+            continue;\r
+        } else if (strcmp(feature, FUTURE_GENERATORS) == 0) {\r
+            continue;\r
+        } else if (strcmp(feature, FUTURE_DIVISION) == 0) {\r
+            ff->ff_features |= CO_FUTURE_DIVISION;\r
+        } else if (strcmp(feature, FUTURE_ABSOLUTE_IMPORT) == 0) {\r
+            ff->ff_features |= CO_FUTURE_ABSOLUTE_IMPORT;\r
+        } else if (strcmp(feature, FUTURE_WITH_STATEMENT) == 0) {\r
+            ff->ff_features |= CO_FUTURE_WITH_STATEMENT;\r
+        } else if (strcmp(feature, FUTURE_PRINT_FUNCTION) == 0) {\r
+            ff->ff_features |= CO_FUTURE_PRINT_FUNCTION;\r
+        } else if (strcmp(feature, FUTURE_UNICODE_LITERALS) == 0) {\r
+            ff->ff_features |= CO_FUTURE_UNICODE_LITERALS;\r
+        } else if (strcmp(feature, "braces") == 0) {\r
+            PyErr_SetString(PyExc_SyntaxError,\r
+                            "not a chance");\r
+            PyErr_SyntaxLocation(filename, s->lineno);\r
+            return 0;\r
+        } else {\r
+            PyErr_Format(PyExc_SyntaxError,\r
+                         UNDEFINED_FUTURE_FEATURE, feature);\r
+            PyErr_SyntaxLocation(filename, s->lineno);\r
+            return 0;\r
+        }\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename)\r
+{\r
+    int i, found_docstring = 0, done = 0, prev_line = 0;\r
+\r
+    if (!(mod->kind == Module_kind || mod->kind == Interactive_kind))\r
+        return 1;\r
+\r
+    /* A subsequent pass will detect future imports that don't\r
+       appear at the beginning of the file.  There's one case,\r
+       however, that is easier to handle here: A series of imports\r
+       joined by semi-colons, where the first import is a future\r
+       statement but some subsequent import has the future form\r
+       but is preceded by a regular import.\r
+    */\r
+\r
+\r
+    for (i = 0; i < asdl_seq_LEN(mod->v.Module.body); i++) {\r
+        stmt_ty s = (stmt_ty)asdl_seq_GET(mod->v.Module.body, i);\r
+\r
+        if (done && s->lineno > prev_line)\r
+            return 1;\r
+        prev_line = s->lineno;\r
+\r
+        /* The tests below will return from this function unless it is\r
+           still possible to find a future statement.  The only things\r
+           that can precede a future statement are another future\r
+           statement and a doc string.\r
+        */\r
+\r
+        if (s->kind == ImportFrom_kind) {\r
+            identifier modname = s->v.ImportFrom.module;\r
+            if (modname && PyString_GET_SIZE(modname) == 10 &&\r
+                !strcmp(PyString_AS_STRING(modname), "__future__")) {\r
+                if (done) {\r
+                    PyErr_SetString(PyExc_SyntaxError,\r
+                                    ERR_LATE_FUTURE);\r
+                    PyErr_SyntaxLocation(filename,\r
+                                         s->lineno);\r
+                    return 0;\r
+                }\r
+                if (!future_check_features(ff, s, filename))\r
+                    return 0;\r
+                ff->ff_lineno = s->lineno;\r
+            }\r
+            else\r
+                done = 1;\r
+        }\r
+        else if (s->kind == Expr_kind && !found_docstring) {\r
+            expr_ty e = s->v.Expr.value;\r
+            if (e->kind != Str_kind)\r
+                done = 1;\r
+            else\r
+                found_docstring = 1;\r
+        }\r
+        else\r
+            done = 1;\r
+    }\r
+    return 1;\r
+}\r
+\r
+\r
+PyFutureFeatures *\r
+PyFuture_FromAST(mod_ty mod, const char *filename)\r
+{\r
+    PyFutureFeatures *ff;\r
+\r
+    ff = (PyFutureFeatures *)PyObject_Malloc(sizeof(PyFutureFeatures));\r
+    if (ff == NULL) {\r
+        PyErr_NoMemory();\r
+        return NULL;\r
+    }\r
+    ff->ff_features = 0;\r
+    ff->ff_lineno = -1;\r
+\r
+    if (!future_parse(ff, mod, filename)) {\r
+        PyObject_Free(ff);\r
+        return NULL;\r
+    }\r
+    return ff;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/getargs.c b/AppPkg/Applications/Python/Python-2.7.10/Python/getargs.c
new file mode 100644 (file)
index 0000000..debec57
--- /dev/null
@@ -0,0 +1,1908 @@
+\r
+/* New getargs implementation */\r
+\r
+#include "Python.h"\r
+\r
+#include <ctype.h>\r
+\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+int PyArg_Parse(PyObject *, const char *, ...);\r
+int PyArg_ParseTuple(PyObject *, const char *, ...);\r
+int PyArg_VaParse(PyObject *, const char *, va_list);\r
+\r
+int PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,\r
+                                const char *, char **, ...);\r
+int PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,\r
+                                const char *, char **, va_list);\r
+\r
+#ifdef HAVE_DECLSPEC_DLL\r
+/* Export functions */\r
+PyAPI_FUNC(int) _PyArg_Parse_SizeT(PyObject *, char *, ...);\r
+PyAPI_FUNC(int) _PyArg_ParseTuple_SizeT(PyObject *, char *, ...);\r
+PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywords_SizeT(PyObject *, PyObject *,\r
+                                                  const char *, char **, ...);\r
+PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...);\r
+PyAPI_FUNC(int) _PyArg_VaParse_SizeT(PyObject *, char *, va_list);\r
+PyAPI_FUNC(int) _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *, PyObject *,\r
+                                              const char *, char **, va_list);\r
+#endif\r
+\r
+#define FLAG_COMPAT 1\r
+#define FLAG_SIZE_T 2\r
+\r
+\r
+/* Forward */\r
+static int vgetargs1(PyObject *, const char *, va_list *, int);\r
+static void seterror(int, const char *, int *, const char *, const char *);\r
+static char *convertitem(PyObject *, const char **, va_list *, int, int *,\r
+                         char *, size_t, PyObject **);\r
+static char *converttuple(PyObject *, const char **, va_list *, int,\r
+                          int *, char *, size_t, int, PyObject **);\r
+static char *convertsimple(PyObject *, const char **, va_list *, int, char *,\r
+                           size_t, PyObject **);\r
+static Py_ssize_t convertbuffer(PyObject *, void **p, char **);\r
+static int getbuffer(PyObject *, Py_buffer *, char**);\r
+\r
+static int vgetargskeywords(PyObject *, PyObject *,\r
+                            const char *, char **, va_list *, int);\r
+static char *skipitem(const char **, va_list *, int);\r
+\r
+int\r
+PyArg_Parse(PyObject *args, const char *format, ...)\r
+{\r
+    int retval;\r
+    va_list va;\r
+\r
+    va_start(va, format);\r
+    retval = vgetargs1(args, format, &va, FLAG_COMPAT);\r
+    va_end(va);\r
+    return retval;\r
+}\r
+\r
+int\r
+_PyArg_Parse_SizeT(PyObject *args, char *format, ...)\r
+{\r
+    int retval;\r
+    va_list va;\r
+\r
+    va_start(va, format);\r
+    retval = vgetargs1(args, format, &va, FLAG_COMPAT|FLAG_SIZE_T);\r
+    va_end(va);\r
+    return retval;\r
+}\r
+\r
+\r
+int\r
+PyArg_ParseTuple(PyObject *args, const char *format, ...)\r
+{\r
+    int retval;\r
+    va_list va;\r
+\r
+    va_start(va, format);\r
+    retval = vgetargs1(args, format, &va, 0);\r
+    va_end(va);\r
+    return retval;\r
+}\r
+\r
+int\r
+_PyArg_ParseTuple_SizeT(PyObject *args, char *format, ...)\r
+{\r
+    int retval;\r
+    va_list va;\r
+\r
+    va_start(va, format);\r
+    retval = vgetargs1(args, format, &va, FLAG_SIZE_T);\r
+    va_end(va);\r
+    return retval;\r
+}\r
+\r
+\r
+int\r
+PyArg_VaParse(PyObject *args, const char *format, va_list va)\r
+{\r
+    va_list lva;\r
+\r
+#ifdef VA_LIST_IS_ARRAY\r
+    memcpy(lva, va, sizeof(va_list));\r
+#else\r
+#ifdef __va_copy\r
+    __va_copy(lva, va);\r
+#else\r
+    lva = va;\r
+#endif\r
+#endif\r
+\r
+    return vgetargs1(args, format, &lva, 0);\r
+}\r
+\r
+int\r
+_PyArg_VaParse_SizeT(PyObject *args, char *format, va_list va)\r
+{\r
+    va_list lva;\r
+\r
+#ifdef VA_LIST_IS_ARRAY\r
+    memcpy(lva, va, sizeof(va_list));\r
+#else\r
+#ifdef __va_copy\r
+    __va_copy(lva, va);\r
+#else\r
+    lva = va;\r
+#endif\r
+#endif\r
+\r
+    return vgetargs1(args, format, &lva, FLAG_SIZE_T);\r
+}\r
+\r
+\r
+/* Handle cleanup of allocated memory in case of exception */\r
+\r
+#define GETARGS_CAPSULE_NAME_CLEANUP_PTR "getargs.cleanup_ptr"\r
+#define GETARGS_CAPSULE_NAME_CLEANUP_BUFFER "getargs.cleanup_buffer"\r
+\r
+static void\r
+cleanup_ptr(PyObject *self)\r
+{\r
+    void *ptr = PyCapsule_GetPointer(self, GETARGS_CAPSULE_NAME_CLEANUP_PTR);\r
+    if (ptr) {\r
+      PyMem_FREE(ptr);\r
+    }\r
+}\r
+\r
+static void\r
+cleanup_buffer(PyObject *self)\r
+{\r
+    Py_buffer *ptr = (Py_buffer *)PyCapsule_GetPointer(self, GETARGS_CAPSULE_NAME_CLEANUP_BUFFER);\r
+    if (ptr) {\r
+        PyBuffer_Release(ptr);\r
+    }\r
+}\r
+\r
+static int\r
+addcleanup(void *ptr, PyObject **freelist, PyCapsule_Destructor destr)\r
+{\r
+    PyObject *cobj;\r
+    const char *name;\r
+\r
+    if (!*freelist) {\r
+        *freelist = PyList_New(0);\r
+        if (!*freelist) {\r
+            destr(ptr);\r
+            return -1;\r
+        }\r
+    }\r
+\r
+    if (destr == cleanup_ptr) {\r
+        name = GETARGS_CAPSULE_NAME_CLEANUP_PTR;\r
+    } else if (destr == cleanup_buffer) {\r
+        name = GETARGS_CAPSULE_NAME_CLEANUP_BUFFER;\r
+    } else {\r
+        return -1;\r
+    }\r
+    cobj = PyCapsule_New(ptr, name, destr);\r
+    if (!cobj) {\r
+        destr(ptr);\r
+        return -1;\r
+    }\r
+    if (PyList_Append(*freelist, cobj)) {\r
+        Py_DECREF(cobj);\r
+        return -1;\r
+    }\r
+    Py_DECREF(cobj);\r
+    return 0;\r
+}\r
+\r
+static int\r
+cleanreturn(int retval, PyObject *freelist)\r
+{\r
+    if (freelist && retval != 0) {\r
+        /* We were successful, reset the destructors so that they\r
+           don't get called. */\r
+        Py_ssize_t len = PyList_GET_SIZE(freelist), i;\r
+        for (i = 0; i < len; i++)\r
+            PyCapsule_SetDestructor(PyList_GET_ITEM(freelist, i), NULL);\r
+    }\r
+    Py_XDECREF(freelist);\r
+    return retval;\r
+}\r
+\r
+\r
+static int\r
+vgetargs1(PyObject *args, const char *format, va_list *p_va, int flags)\r
+{\r
+    char msgbuf[256];\r
+    int levels[32];\r
+    const char *fname = NULL;\r
+    const char *message = NULL;\r
+    int min = -1;\r
+    int max = 0;\r
+    int level = 0;\r
+    int endfmt = 0;\r
+    const char *formatsave = format;\r
+    Py_ssize_t i, len;\r
+    char *msg;\r
+    PyObject *freelist = NULL;\r
+    int compat = flags & FLAG_COMPAT;\r
+\r
+    assert(compat || (args != (PyObject*)NULL));\r
+    flags = flags & ~FLAG_COMPAT;\r
+\r
+    while (endfmt == 0) {\r
+        int c = *format++;\r
+        switch (c) {\r
+        case '(':\r
+            if (level == 0)\r
+                max++;\r
+            level++;\r
+            if (level >= 30)\r
+                Py_FatalError("too many tuple nesting levels "\r
+                              "in argument format string");\r
+            break;\r
+        case ')':\r
+            if (level == 0)\r
+                Py_FatalError("excess ')' in getargs format");\r
+            else\r
+                level--;\r
+            break;\r
+        case '\0':\r
+            endfmt = 1;\r
+            break;\r
+        case ':':\r
+            fname = format;\r
+            endfmt = 1;\r
+            break;\r
+        case ';':\r
+            message = format;\r
+            endfmt = 1;\r
+            break;\r
+        default:\r
+            if (level == 0) {\r
+                if (c == 'O')\r
+                    max++;\r
+                else if (isalpha(Py_CHARMASK(c))) {\r
+                    if (c != 'e') /* skip encoded */\r
+                        max++;\r
+                } else if (c == '|')\r
+                    min = max;\r
+            }\r
+            break;\r
+        }\r
+    }\r
+\r
+    if (level != 0)\r
+        Py_FatalError(/* '(' */ "missing ')' in getargs format");\r
+\r
+    if (min < 0)\r
+        min = max;\r
+\r
+    format = formatsave;\r
+\r
+    if (compat) {\r
+        if (max == 0) {\r
+            if (args == NULL)\r
+                return 1;\r
+            PyOS_snprintf(msgbuf, sizeof(msgbuf),\r
+                          "%.200s%s takes no arguments",\r
+                          fname==NULL ? "function" : fname,\r
+                          fname==NULL ? "" : "()");\r
+            PyErr_SetString(PyExc_TypeError, msgbuf);\r
+            return 0;\r
+        }\r
+        else if (min == 1 && max == 1) {\r
+            if (args == NULL) {\r
+                PyOS_snprintf(msgbuf, sizeof(msgbuf),\r
+                      "%.200s%s takes at least one argument",\r
+                          fname==NULL ? "function" : fname,\r
+                          fname==NULL ? "" : "()");\r
+                PyErr_SetString(PyExc_TypeError, msgbuf);\r
+                return 0;\r
+            }\r
+            msg = convertitem(args, &format, p_va, flags, levels,\r
+                              msgbuf, sizeof(msgbuf), &freelist);\r
+            if (msg == NULL)\r
+                return cleanreturn(1, freelist);\r
+            seterror(levels[0], msg, levels+1, fname, message);\r
+            return cleanreturn(0, freelist);\r
+        }\r
+        else {\r
+            PyErr_SetString(PyExc_SystemError,\r
+                "old style getargs format uses new features");\r
+            return 0;\r
+        }\r
+    }\r
+\r
+    if (!PyTuple_Check(args)) {\r
+        PyErr_SetString(PyExc_SystemError,\r
+            "new style getargs format but argument is not a tuple");\r
+        return 0;\r
+    }\r
+\r
+    len = PyTuple_GET_SIZE(args);\r
+\r
+    if (len < min || max < len) {\r
+        if (message == NULL) {\r
+            PyOS_snprintf(msgbuf, sizeof(msgbuf),\r
+                          "%.150s%s takes %s %d argument%s "\r
+                          "(%ld given)",\r
+                          fname==NULL ? "function" : fname,\r
+                          fname==NULL ? "" : "()",\r
+                          min==max ? "exactly"\r
+                          : len < min ? "at least" : "at most",\r
+                          len < min ? min : max,\r
+                          (len < min ? min : max) == 1 ? "" : "s",\r
+                          Py_SAFE_DOWNCAST(len, Py_ssize_t, long));\r
+            message = msgbuf;\r
+        }\r
+        PyErr_SetString(PyExc_TypeError, message);\r
+        return 0;\r
+    }\r
+\r
+    for (i = 0; i < len; i++) {\r
+        if (*format == '|')\r
+            format++;\r
+        msg = convertitem(PyTuple_GET_ITEM(args, i), &format, p_va,\r
+                          flags, levels, msgbuf,\r
+                          sizeof(msgbuf), &freelist);\r
+        if (msg) {\r
+            seterror(i+1, msg, levels, fname, msg);\r
+            return cleanreturn(0, freelist);\r
+        }\r
+    }\r
+\r
+    if (*format != '\0' && !isalpha(Py_CHARMASK(*format)) &&\r
+        *format != '(' &&\r
+        *format != '|' && *format != ':' && *format != ';') {\r
+        PyErr_Format(PyExc_SystemError,\r
+                     "bad format string: %.200s", formatsave);\r
+        return cleanreturn(0, freelist);\r
+    }\r
+\r
+    return cleanreturn(1, freelist);\r
+}\r
+\r
+\r
+\r
+static void\r
+seterror(int iarg, const char *msg, int *levels, const char *fname,\r
+         const char *message)\r
+{\r
+    char buf[512];\r
+    int i;\r
+    char *p = buf;\r
+\r
+    if (PyErr_Occurred())\r
+        return;\r
+    else if (message == NULL) {\r
+        if (fname != NULL) {\r
+            PyOS_snprintf(p, sizeof(buf), "%.200s() ", fname);\r
+            p += strlen(p);\r
+        }\r
+        if (iarg != 0) {\r
+            PyOS_snprintf(p, sizeof(buf) - (p - buf),\r
+                          "argument %d", iarg);\r
+            i = 0;\r
+            p += strlen(p);\r
+            while (levels[i] > 0 && i < 32 && (int)(p-buf) < 220) {\r
+                PyOS_snprintf(p, sizeof(buf) - (p - buf),\r
+                              ", item %d", levels[i]-1);\r
+                p += strlen(p);\r
+                i++;\r
+            }\r
+        }\r
+        else {\r
+            PyOS_snprintf(p, sizeof(buf) - (p - buf), "argument");\r
+            p += strlen(p);\r
+        }\r
+        PyOS_snprintf(p, sizeof(buf) - (p - buf), " %.256s", msg);\r
+        message = buf;\r
+    }\r
+    PyErr_SetString(PyExc_TypeError, message);\r
+}\r
+\r
+\r
+/* Convert a tuple argument.\r
+   On entry, *p_format points to the character _after_ the opening '('.\r
+   On successful exit, *p_format points to the closing ')'.\r
+   If successful:\r
+      *p_format and *p_va are updated,\r
+      *levels and *msgbuf are untouched,\r
+      and NULL is returned.\r
+   If the argument is invalid:\r
+      *p_format is unchanged,\r
+      *p_va is undefined,\r
+      *levels is a 0-terminated list of item numbers,\r
+      *msgbuf contains an error message, whose format is:\r
+     "must be <typename1>, not <typename2>", where:\r
+        <typename1> is the name of the expected type, and\r
+        <typename2> is the name of the actual type,\r
+      and msgbuf is returned.\r
+*/\r
+\r
+static char *\r
+converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,\r
+             int *levels, char *msgbuf, size_t bufsize, int toplevel,\r
+             PyObject **freelist)\r
+{\r
+    int level = 0;\r
+    int n = 0;\r
+    const char *format = *p_format;\r
+    int i;\r
+\r
+    for (;;) {\r
+        int c = *format++;\r
+        if (c == '(') {\r
+            if (level == 0)\r
+                n++;\r
+            level++;\r
+        }\r
+        else if (c == ')') {\r
+            if (level == 0)\r
+                break;\r
+            level--;\r
+        }\r
+        else if (c == ':' || c == ';' || c == '\0')\r
+            break;\r
+        else if (level == 0 && isalpha(Py_CHARMASK(c)))\r
+            n++;\r
+    }\r
+\r
+    if (!PySequence_Check(arg) || PyString_Check(arg)) {\r
+        levels[0] = 0;\r
+        PyOS_snprintf(msgbuf, bufsize,\r
+                      toplevel ? "expected %d arguments, not %.50s" :\r
+                      "must be %d-item sequence, not %.50s",\r
+                  n,\r
+                  arg == Py_None ? "None" : arg->ob_type->tp_name);\r
+        return msgbuf;\r
+    }\r
+\r
+    if ((i = PySequence_Size(arg)) != n) {\r
+        levels[0] = 0;\r
+        PyOS_snprintf(msgbuf, bufsize,\r
+                      toplevel ? "expected %d arguments, not %d" :\r
+                     "must be sequence of length %d, not %d",\r
+                  n, i);\r
+        return msgbuf;\r
+    }\r
+\r
+    format = *p_format;\r
+    for (i = 0; i < n; i++) {\r
+        char *msg;\r
+        PyObject *item;\r
+        item = PySequence_GetItem(arg, i);\r
+        if (item == NULL) {\r
+            PyErr_Clear();\r
+            levels[0] = i+1;\r
+            levels[1] = 0;\r
+            strncpy(msgbuf, "is not retrievable", bufsize);\r
+            return msgbuf;\r
+        }\r
+        msg = convertitem(item, &format, p_va, flags, levels+1,\r
+                          msgbuf, bufsize, freelist);\r
+        /* PySequence_GetItem calls tp->sq_item, which INCREFs */\r
+        Py_XDECREF(item);\r
+        if (msg != NULL) {\r
+            levels[0] = i+1;\r
+            return msg;\r
+        }\r
+    }\r
+\r
+    *p_format = format;\r
+    return NULL;\r
+}\r
+\r
+\r
+/* Convert a single item. */\r
+\r
+static char *\r
+convertitem(PyObject *arg, const char **p_format, va_list *p_va, int flags,\r
+            int *levels, char *msgbuf, size_t bufsize, PyObject **freelist)\r
+{\r
+    char *msg;\r
+    const char *format = *p_format;\r
+\r
+    if (*format == '(' /* ')' */) {\r
+        format++;\r
+        msg = converttuple(arg, &format, p_va, flags, levels, msgbuf,\r
+                           bufsize, 0, freelist);\r
+        if (msg == NULL)\r
+            format++;\r
+    }\r
+    else {\r
+        msg = convertsimple(arg, &format, p_va, flags,\r
+                            msgbuf, bufsize, freelist);\r
+        if (msg != NULL)\r
+            levels[0] = 0;\r
+    }\r
+    if (msg == NULL)\r
+        *p_format = format;\r
+    return msg;\r
+}\r
+\r
+\r
+\r
+#define UNICODE_DEFAULT_ENCODING(arg) \\r
+    _PyUnicode_AsDefaultEncodedString(arg, NULL)\r
+\r
+/* Format an error message generated by convertsimple(). */\r
+\r
+static char *\r
+converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)\r
+{\r
+    assert(expected != NULL);\r
+    assert(arg != NULL);\r
+    PyOS_snprintf(msgbuf, bufsize,\r
+                  "must be %.50s, not %.50s", expected,\r
+                  arg == Py_None ? "None" : arg->ob_type->tp_name);\r
+    return msgbuf;\r
+}\r
+\r
+#define CONV_UNICODE "(unicode conversion error)"\r
+\r
+/* explicitly check for float arguments when integers are expected.  For now\r
+ * signal a warning.  Returns true if an exception was raised. */\r
+static int\r
+float_argument_warning(PyObject *arg)\r
+{\r
+    if (PyFloat_Check(arg) &&\r
+        PyErr_Warn(PyExc_DeprecationWarning,\r
+                   "integer argument expected, got float" ))\r
+        return 1;\r
+    else\r
+        return 0;\r
+}\r
+\r
+/* explicitly check for float arguments when integers are expected.  Raises\r
+   TypeError and returns true for float arguments. */\r
+static int\r
+float_argument_error(PyObject *arg)\r
+{\r
+    if (PyFloat_Check(arg)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                        "integer argument expected, got float");\r
+        return 1;\r
+    }\r
+    else\r
+        return 0;\r
+}\r
+\r
+/* Convert a non-tuple argument.  Return NULL if conversion went OK,\r
+   or a string with a message describing the failure.  The message is\r
+   formatted as "must be <desired type>, not <actual type>".\r
+   When failing, an exception may or may not have been raised.\r
+   Don't call if a tuple is expected.\r
+\r
+   When you add new format codes, please don't forget poor skipitem() below.\r
+*/\r
+\r
+static char *\r
+convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,\r
+              char *msgbuf, size_t bufsize, PyObject **freelist)\r
+{\r
+    /* For # codes */\r
+#define FETCH_SIZE      int *q=NULL;Py_ssize_t *q2=NULL;\\r
+    if (flags & FLAG_SIZE_T) q2=va_arg(*p_va, Py_ssize_t*); \\r
+    else q=va_arg(*p_va, int*);\r
+#define STORE_SIZE(s)   \\r
+    if (flags & FLAG_SIZE_T) \\r
+        *q2=s; \\r
+    else { \\r
+        if (INT_MAX < s) { \\r
+            PyErr_SetString(PyExc_OverflowError, \\r
+                "size does not fit in an int"); \\r
+            return converterr("", arg, msgbuf, bufsize); \\r
+        } \\r
+        *q=s; \\r
+    }\r
+#define BUFFER_LEN      ((flags & FLAG_SIZE_T) ? *q2:*q)\r
+\r
+    const char *format = *p_format;\r
+    char c = *format++;\r
+#ifdef Py_USING_UNICODE\r
+    PyObject *uarg;\r
+#endif\r
+\r
+    switch (c) {\r
+\r
+    case 'b': { /* unsigned byte -- very short int */\r
+        char *p = va_arg(*p_va, char *);\r
+        long ival;\r
+        if (float_argument_error(arg))\r
+            return converterr("integer<b>", arg, msgbuf, bufsize);\r
+        ival = PyInt_AsLong(arg);\r
+        if (ival == -1 && PyErr_Occurred())\r
+            return converterr("integer<b>", arg, msgbuf, bufsize);\r
+        else if (ival < 0) {\r
+            PyErr_SetString(PyExc_OverflowError,\r
+            "unsigned byte integer is less than minimum");\r
+            return converterr("integer<b>", arg, msgbuf, bufsize);\r
+        }\r
+        else if (ival > UCHAR_MAX) {\r
+            PyErr_SetString(PyExc_OverflowError,\r
+            "unsigned byte integer is greater than maximum");\r
+            return converterr("integer<b>", arg, msgbuf, bufsize);\r
+        }\r
+        else\r
+            *p = (unsigned char) ival;\r
+        break;\r
+    }\r
+\r
+    case 'B': {/* byte sized bitfield - both signed and unsigned\r
+                  values allowed */\r
+        char *p = va_arg(*p_va, char *);\r
+        long ival;\r
+        if (float_argument_error(arg))\r
+            return converterr("integer<B>", arg, msgbuf, bufsize);\r
+        ival = PyInt_AsUnsignedLongMask(arg);\r
+        if (ival == -1 && PyErr_Occurred())\r
+            return converterr("integer<B>", arg, msgbuf, bufsize);\r
+        else\r
+            *p = (unsigned char) ival;\r
+        break;\r
+    }\r
+\r
+    case 'h': {/* signed short int */\r
+        short *p = va_arg(*p_va, short *);\r
+        long ival;\r
+        if (float_argument_error(arg))\r
+            return converterr("integer<h>", arg, msgbuf, bufsize);\r
+        ival = PyInt_AsLong(arg);\r
+        if (ival == -1 && PyErr_Occurred())\r
+            return converterr("integer<h>", arg, msgbuf, bufsize);\r
+        else if (ival < SHRT_MIN) {\r
+            PyErr_SetString(PyExc_OverflowError,\r
+            "signed short integer is less than minimum");\r
+            return converterr("integer<h>", arg, msgbuf, bufsize);\r
+        }\r
+        else if (ival > SHRT_MAX) {\r
+            PyErr_SetString(PyExc_OverflowError,\r
+            "signed short integer is greater than maximum");\r
+            return converterr("integer<h>", arg, msgbuf, bufsize);\r
+        }\r
+        else\r
+            *p = (short) ival;\r
+        break;\r
+    }\r
+\r
+    case 'H': { /* short int sized bitfield, both signed and\r
+                   unsigned allowed */\r
+        unsigned short *p = va_arg(*p_va, unsigned short *);\r
+        long ival;\r
+        if (float_argument_error(arg))\r
+            return converterr("integer<H>", arg, msgbuf, bufsize);\r
+        ival = PyInt_AsUnsignedLongMask(arg);\r
+        if (ival == -1 && PyErr_Occurred())\r
+            return converterr("integer<H>", arg, msgbuf, bufsize);\r
+        else\r
+            *p = (unsigned short) ival;\r
+        break;\r
+    }\r
+\r
+    case 'i': {/* signed int */\r
+        int *p = va_arg(*p_va, int *);\r
+        long ival;\r
+        if (float_argument_error(arg))\r
+            return converterr("integer<i>", arg, msgbuf, bufsize);\r
+        ival = PyInt_AsLong(arg);\r
+        if (ival == -1 && PyErr_Occurred())\r
+            return converterr("integer<i>", arg, msgbuf, bufsize);\r
+        else if (ival > INT_MAX) {\r
+            PyErr_SetString(PyExc_OverflowError,\r
+                "signed integer is greater than maximum");\r
+            return converterr("integer<i>", arg, msgbuf, bufsize);\r
+        }\r
+        else if (ival < INT_MIN) {\r
+            PyErr_SetString(PyExc_OverflowError,\r
+                "signed integer is less than minimum");\r
+            return converterr("integer<i>", arg, msgbuf, bufsize);\r
+        }\r
+        else\r
+            *p = ival;\r
+        break;\r
+    }\r
+\r
+    case 'I': { /* int sized bitfield, both signed and\r
+                   unsigned allowed */\r
+        unsigned int *p = va_arg(*p_va, unsigned int *);\r
+        unsigned int ival;\r
+        if (float_argument_error(arg))\r
+            return converterr("integer<I>", arg, msgbuf, bufsize);\r
+        ival = (unsigned int)PyInt_AsUnsignedLongMask(arg);\r
+        if (ival == (unsigned int)-1 && PyErr_Occurred())\r
+            return converterr("integer<I>", arg, msgbuf, bufsize);\r
+        else\r
+            *p = ival;\r
+        break;\r
+    }\r
+\r
+    case 'n': /* Py_ssize_t */\r
+#if SIZEOF_SIZE_T != SIZEOF_LONG\r
+    {\r
+        Py_ssize_t *p = va_arg(*p_va, Py_ssize_t *);\r
+        Py_ssize_t ival;\r
+        if (float_argument_error(arg))\r
+            return converterr("integer<n>", arg, msgbuf, bufsize);\r
+        ival = PyInt_AsSsize_t(arg);\r
+        if (ival == -1 && PyErr_Occurred())\r
+            return converterr("integer<n>", arg, msgbuf, bufsize);\r
+        *p = ival;\r
+        break;\r
+    }\r
+#endif\r
+    /* Fall through from 'n' to 'l' if Py_ssize_t is int */\r
+    case 'l': {/* long int */\r
+        long *p = va_arg(*p_va, long *);\r
+        long ival;\r
+        if (float_argument_error(arg))\r
+            return converterr("integer<l>", arg, msgbuf, bufsize);\r
+        ival = PyInt_AsLong(arg);\r
+        if (ival == -1 && PyErr_Occurred())\r
+            return converterr("integer<l>", arg, msgbuf, bufsize);\r
+        else\r
+            *p = ival;\r
+        break;\r
+    }\r
+\r
+    case 'k': { /* long sized bitfield */\r
+        unsigned long *p = va_arg(*p_va, unsigned long *);\r
+        unsigned long ival;\r
+        if (PyInt_Check(arg))\r
+            ival = PyInt_AsUnsignedLongMask(arg);\r
+        else if (PyLong_Check(arg))\r
+            ival = PyLong_AsUnsignedLongMask(arg);\r
+        else\r
+            return converterr("integer<k>", arg, msgbuf, bufsize);\r
+        *p = ival;\r
+        break;\r
+    }\r
+\r
+#ifdef HAVE_LONG_LONG\r
+    case 'L': {/* PY_LONG_LONG */\r
+        PY_LONG_LONG *p = va_arg( *p_va, PY_LONG_LONG * );\r
+        PY_LONG_LONG ival;\r
+        if (float_argument_warning(arg))\r
+            return converterr("long<L>", arg, msgbuf, bufsize);\r
+        ival = PyLong_AsLongLong(arg);\r
+        if (ival == (PY_LONG_LONG)-1 && PyErr_Occurred() ) {\r
+            return converterr("long<L>", arg, msgbuf, bufsize);\r
+        } else {\r
+            *p = ival;\r
+        }\r
+        break;\r
+    }\r
+\r
+    case 'K': { /* long long sized bitfield */\r
+        unsigned PY_LONG_LONG *p = va_arg(*p_va, unsigned PY_LONG_LONG *);\r
+        unsigned PY_LONG_LONG ival;\r
+        if (PyInt_Check(arg))\r
+            ival = PyInt_AsUnsignedLongMask(arg);\r
+        else if (PyLong_Check(arg))\r
+            ival = PyLong_AsUnsignedLongLongMask(arg);\r
+        else\r
+            return converterr("integer<K>", arg, msgbuf, bufsize);\r
+        *p = ival;\r
+        break;\r
+    }\r
+#endif\r
+\r
+    case 'f': {/* float */\r
+        float *p = va_arg(*p_va, float *);\r
+        double dval = PyFloat_AsDouble(arg);\r
+        if (PyErr_Occurred())\r
+            return converterr("float<f>", arg, msgbuf, bufsize);\r
+        else\r
+            *p = (float) dval;\r
+        break;\r
+    }\r
+\r
+    case 'd': {/* double */\r
+        double *p = va_arg(*p_va, double *);\r
+        double dval = PyFloat_AsDouble(arg);\r
+        if (PyErr_Occurred())\r
+            return converterr("float<d>", arg, msgbuf, bufsize);\r
+        else\r
+            *p = dval;\r
+        break;\r
+    }\r
+\r
+#ifndef WITHOUT_COMPLEX\r
+    case 'D': {/* complex double */\r
+        Py_complex *p = va_arg(*p_va, Py_complex *);\r
+        Py_complex cval;\r
+        cval = PyComplex_AsCComplex(arg);\r
+        if (PyErr_Occurred())\r
+            return converterr("complex<D>", arg, msgbuf, bufsize);\r
+        else\r
+            *p = cval;\r
+        break;\r
+    }\r
+#endif /* WITHOUT_COMPLEX */\r
+\r
+    case 'c': {/* char */\r
+        char *p = va_arg(*p_va, char *);\r
+        if (PyString_Check(arg) && PyString_Size(arg) == 1)\r
+            *p = PyString_AS_STRING(arg)[0];\r
+        else\r
+            return converterr("char", arg, msgbuf, bufsize);\r
+        break;\r
+    }\r
+\r
+    case 's': {/* string */\r
+        if (*format == '*') {\r
+            Py_buffer *p = (Py_buffer *)va_arg(*p_va, Py_buffer *);\r
+\r
+            if (PyString_Check(arg)) {\r
+                PyBuffer_FillInfo(p, arg,\r
+                                  PyString_AS_STRING(arg), PyString_GET_SIZE(arg),\r
+                                  1, 0);\r
+            }\r
+#ifdef Py_USING_UNICODE\r
+            else if (PyUnicode_Check(arg)) {\r
+                uarg = UNICODE_DEFAULT_ENCODING(arg);\r
+                if (uarg == NULL)\r
+                    return converterr(CONV_UNICODE,\r
+                                      arg, msgbuf, bufsize);\r
+                PyBuffer_FillInfo(p, arg,\r
+                                  PyString_AS_STRING(uarg), PyString_GET_SIZE(uarg),\r
+                                  1, 0);\r
+            }\r
+#endif\r
+            else { /* any buffer-like object */\r
+                char *buf;\r
+                if (getbuffer(arg, p, &buf) < 0)\r
+                    return converterr(buf, arg, msgbuf, bufsize);\r
+            }\r
+            if (addcleanup(p, freelist, cleanup_buffer)) {\r
+                return converterr(\r
+                    "(cleanup problem)",\r
+                    arg, msgbuf, bufsize);\r
+            }\r
+            format++;\r
+        } else if (*format == '#') {\r
+            void **p = (void **)va_arg(*p_va, char **);\r
+            FETCH_SIZE;\r
+\r
+            if (PyString_Check(arg)) {\r
+                *p = PyString_AS_STRING(arg);\r
+                STORE_SIZE(PyString_GET_SIZE(arg));\r
+            }\r
+#ifdef Py_USING_UNICODE\r
+            else if (PyUnicode_Check(arg)) {\r
+                uarg = UNICODE_DEFAULT_ENCODING(arg);\r
+                if (uarg == NULL)\r
+                    return converterr(CONV_UNICODE,\r
+                                      arg, msgbuf, bufsize);\r
+                *p = PyString_AS_STRING(uarg);\r
+                STORE_SIZE(PyString_GET_SIZE(uarg));\r
+            }\r
+#endif\r
+            else { /* any buffer-like object */\r
+                char *buf;\r
+                Py_ssize_t count = convertbuffer(arg, p, &buf);\r
+                if (count < 0)\r
+                    return converterr(buf, arg, msgbuf, bufsize);\r
+                STORE_SIZE(count);\r
+            }\r
+            format++;\r
+        } else {\r
+            char **p = va_arg(*p_va, char **);\r
+\r
+            if (PyString_Check(arg))\r
+                *p = PyString_AS_STRING(arg);\r
+#ifdef Py_USING_UNICODE\r
+            else if (PyUnicode_Check(arg)) {\r
+                uarg = UNICODE_DEFAULT_ENCODING(arg);\r
+                if (uarg == NULL)\r
+                    return converterr(CONV_UNICODE,\r
+                                      arg, msgbuf, bufsize);\r
+                *p = PyString_AS_STRING(uarg);\r
+            }\r
+#endif\r
+            else\r
+                return converterr("string", arg, msgbuf, bufsize);\r
+            if ((Py_ssize_t)strlen(*p) != PyString_Size(arg))\r
+                return converterr("string without null bytes",\r
+                                  arg, msgbuf, bufsize);\r
+        }\r
+        break;\r
+    }\r
+\r
+    case 'z': {/* string, may be NULL (None) */\r
+        if (*format == '*') {\r
+            Py_buffer *p = (Py_buffer *)va_arg(*p_va, Py_buffer *);\r
+\r
+            if (arg == Py_None)\r
+                PyBuffer_FillInfo(p, NULL, NULL, 0, 1, 0);\r
+            else if (PyString_Check(arg)) {\r
+                PyBuffer_FillInfo(p, arg,\r
+                                  PyString_AS_STRING(arg), PyString_GET_SIZE(arg),\r
+                                  1, 0);\r
+            }\r
+#ifdef Py_USING_UNICODE\r
+            else if (PyUnicode_Check(arg)) {\r
+                uarg = UNICODE_DEFAULT_ENCODING(arg);\r
+                if (uarg == NULL)\r
+                    return converterr(CONV_UNICODE,\r
+                                      arg, msgbuf, bufsize);\r
+                PyBuffer_FillInfo(p, arg,\r
+                                  PyString_AS_STRING(uarg), PyString_GET_SIZE(uarg),\r
+                                  1, 0);\r
+            }\r
+#endif\r
+            else { /* any buffer-like object */\r
+                char *buf;\r
+                if (getbuffer(arg, p, &buf) < 0)\r
+                    return converterr(buf, arg, msgbuf, bufsize);\r
+            }\r
+            if (addcleanup(p, freelist, cleanup_buffer)) {\r
+                return converterr(\r
+                    "(cleanup problem)",\r
+                    arg, msgbuf, bufsize);\r
+            }\r
+            format++;\r
+        } else if (*format == '#') { /* any buffer-like object */\r
+            void **p = (void **)va_arg(*p_va, char **);\r
+            FETCH_SIZE;\r
+\r
+            if (arg == Py_None) {\r
+                *p = 0;\r
+                STORE_SIZE(0);\r
+            }\r
+            else if (PyString_Check(arg)) {\r
+                *p = PyString_AS_STRING(arg);\r
+                STORE_SIZE(PyString_GET_SIZE(arg));\r
+            }\r
+#ifdef Py_USING_UNICODE\r
+            else if (PyUnicode_Check(arg)) {\r
+                uarg = UNICODE_DEFAULT_ENCODING(arg);\r
+                if (uarg == NULL)\r
+                    return converterr(CONV_UNICODE,\r
+                                      arg, msgbuf, bufsize);\r
+                *p = PyString_AS_STRING(uarg);\r
+                STORE_SIZE(PyString_GET_SIZE(uarg));\r
+            }\r
+#endif\r
+            else { /* any buffer-like object */\r
+                char *buf;\r
+                Py_ssize_t count = convertbuffer(arg, p, &buf);\r
+                if (count < 0)\r
+                    return converterr(buf, arg, msgbuf, bufsize);\r
+                STORE_SIZE(count);\r
+            }\r
+            format++;\r
+        } else {\r
+            char **p = va_arg(*p_va, char **);\r
+\r
+            if (arg == Py_None)\r
+                *p = 0;\r
+            else if (PyString_Check(arg))\r
+                *p = PyString_AS_STRING(arg);\r
+#ifdef Py_USING_UNICODE\r
+            else if (PyUnicode_Check(arg)) {\r
+                uarg = UNICODE_DEFAULT_ENCODING(arg);\r
+                if (uarg == NULL)\r
+                    return converterr(CONV_UNICODE,\r
+                                      arg, msgbuf, bufsize);\r
+                *p = PyString_AS_STRING(uarg);\r
+            }\r
+#endif\r
+            else\r
+                return converterr("string or None",\r
+                                  arg, msgbuf, bufsize);\r
+            if (*format == '#') {\r
+                FETCH_SIZE;\r
+                assert(0); /* XXX redundant with if-case */\r
+                if (arg == Py_None) {\r
+                    STORE_SIZE(0);\r
+                } else {\r
+                    STORE_SIZE(PyString_Size(arg));\r
+                }\r
+                format++;\r
+            }\r
+            else if (*p != NULL &&\r
+                     (Py_ssize_t)strlen(*p) != PyString_Size(arg))\r
+                return converterr(\r
+                    "string without null bytes or None",\r
+                    arg, msgbuf, bufsize);\r
+        }\r
+        break;\r
+    }\r
+\r
+    case 'e': {/* encoded string */\r
+        char **buffer;\r
+        const char *encoding;\r
+        PyObject *s;\r
+        Py_ssize_t size;\r
+        int recode_strings;\r
+\r
+        /* Get 'e' parameter: the encoding name */\r
+        encoding = (const char *)va_arg(*p_va, const char *);\r
+#ifdef Py_USING_UNICODE\r
+        if (encoding == NULL)\r
+            encoding = PyUnicode_GetDefaultEncoding();\r
+#endif\r
+\r
+        /* Get output buffer parameter:\r
+           's' (recode all objects via Unicode) or\r
+           't' (only recode non-string objects)\r
+        */\r
+        if (*format == 's')\r
+            recode_strings = 1;\r
+        else if (*format == 't')\r
+            recode_strings = 0;\r
+        else\r
+            return converterr(\r
+                "(unknown parser marker combination)",\r
+                arg, msgbuf, bufsize);\r
+        buffer = (char **)va_arg(*p_va, char **);\r
+        format++;\r
+        if (buffer == NULL)\r
+            return converterr("(buffer is NULL)",\r
+                              arg, msgbuf, bufsize);\r
+\r
+        /* Encode object */\r
+        if (!recode_strings && PyString_Check(arg)) {\r
+            s = arg;\r
+            Py_INCREF(s);\r
+        }\r
+        else {\r
+#ifdef Py_USING_UNICODE\r
+            PyObject *u;\r
+\r
+            /* Convert object to Unicode */\r
+            u = PyUnicode_FromObject(arg);\r
+            if (u == NULL)\r
+                return converterr(\r
+                    "string or unicode or text buffer",\r
+                    arg, msgbuf, bufsize);\r
+\r
+            /* Encode object; use default error handling */\r
+            s = PyUnicode_AsEncodedString(u,\r
+                                          encoding,\r
+                                          NULL);\r
+            Py_DECREF(u);\r
+            if (s == NULL)\r
+                return converterr("(encoding failed)",\r
+                                  arg, msgbuf, bufsize);\r
+            if (!PyString_Check(s)) {\r
+                Py_DECREF(s);\r
+                return converterr(\r
+                    "(encoder failed to return a string)",\r
+                    arg, msgbuf, bufsize);\r
+            }\r
+#else\r
+            return converterr("string<e>", arg, msgbuf, bufsize);\r
+#endif\r
+        }\r
+        size = PyString_GET_SIZE(s);\r
+\r
+        /* Write output; output is guaranteed to be 0-terminated */\r
+        if (*format == '#') {\r
+            /* Using buffer length parameter '#':\r
+\r
+               - if *buffer is NULL, a new buffer of the\r
+               needed size is allocated and the data\r
+               copied into it; *buffer is updated to point\r
+               to the new buffer; the caller is\r
+               responsible for PyMem_Free()ing it after\r
+               usage\r
+\r
+               - if *buffer is not NULL, the data is\r
+               copied to *buffer; *buffer_len has to be\r
+               set to the size of the buffer on input;\r
+               buffer overflow is signalled with an error;\r
+               buffer has to provide enough room for the\r
+               encoded string plus the trailing 0-byte\r
+\r
+               - in both cases, *buffer_len is updated to\r
+               the size of the buffer /excluding/ the\r
+               trailing 0-byte\r
+\r
+            */\r
+            FETCH_SIZE;\r
+\r
+            format++;\r
+            if (q == NULL && q2 == NULL) {\r
+                Py_DECREF(s);\r
+                return converterr(\r
+                    "(buffer_len is NULL)",\r
+                    arg, msgbuf, bufsize);\r
+            }\r
+            if (*buffer == NULL) {\r
+                *buffer = PyMem_NEW(char, size + 1);\r
+                if (*buffer == NULL) {\r
+                    Py_DECREF(s);\r
+                    return converterr(\r
+                        "(memory error)",\r
+                        arg, msgbuf, bufsize);\r
+                }\r
+                if (addcleanup(*buffer, freelist, cleanup_ptr)) {\r
+                    Py_DECREF(s);\r
+                    return converterr(\r
+                        "(cleanup problem)",\r
+                        arg, msgbuf, bufsize);\r
+                }\r
+            } else {\r
+                if (size + 1 > BUFFER_LEN) {\r
+                    Py_DECREF(s);\r
+                    return converterr(\r
+                        "(buffer overflow)",\r
+                        arg, msgbuf, bufsize);\r
+                }\r
+            }\r
+            memcpy(*buffer,\r
+                   PyString_AS_STRING(s),\r
+                   size + 1);\r
+            STORE_SIZE(size);\r
+        } else {\r
+            /* Using a 0-terminated buffer:\r
+\r
+               - the encoded string has to be 0-terminated\r
+               for this variant to work; if it is not, an\r
+               error raised\r
+\r
+               - a new buffer of the needed size is\r
+               allocated and the data copied into it;\r
+               *buffer is updated to point to the new\r
+               buffer; the caller is responsible for\r
+               PyMem_Free()ing it after usage\r
+\r
+            */\r
+            if ((Py_ssize_t)strlen(PyString_AS_STRING(s))\r
+                                                    != size) {\r
+                Py_DECREF(s);\r
+                return converterr(\r
+                    "encoded string without NULL bytes",\r
+                    arg, msgbuf, bufsize);\r
+            }\r
+            *buffer = PyMem_NEW(char, size + 1);\r
+            if (*buffer == NULL) {\r
+                Py_DECREF(s);\r
+                return converterr("(memory error)",\r
+                                  arg, msgbuf, bufsize);\r
+            }\r
+            if (addcleanup(*buffer, freelist, cleanup_ptr)) {\r
+                Py_DECREF(s);\r
+                return converterr("(cleanup problem)",\r
+                                arg, msgbuf, bufsize);\r
+            }\r
+            memcpy(*buffer,\r
+                   PyString_AS_STRING(s),\r
+                   size + 1);\r
+        }\r
+        Py_DECREF(s);\r
+        break;\r
+    }\r
+\r
+#ifdef Py_USING_UNICODE\r
+    case 'u': {/* raw unicode buffer (Py_UNICODE *) */\r
+        if (*format == '#') { /* any buffer-like object */\r
+            void **p = (void **)va_arg(*p_va, char **);\r
+            FETCH_SIZE;\r
+            if (PyUnicode_Check(arg)) {\r
+                *p = PyUnicode_AS_UNICODE(arg);\r
+                STORE_SIZE(PyUnicode_GET_SIZE(arg));\r
+            }\r
+            else {\r
+                return converterr("cannot convert raw buffers",\r
+                                  arg, msgbuf, bufsize);\r
+            }\r
+            format++;\r
+        } else {\r
+            Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);\r
+            if (PyUnicode_Check(arg))\r
+                *p = PyUnicode_AS_UNICODE(arg);\r
+            else\r
+                return converterr("unicode", arg, msgbuf, bufsize);\r
+        }\r
+        break;\r
+    }\r
+#endif\r
+\r
+    case 'S': { /* string object */\r
+        PyObject **p = va_arg(*p_va, PyObject **);\r
+        if (PyString_Check(arg))\r
+            *p = arg;\r
+        else\r
+            return converterr("string", arg, msgbuf, bufsize);\r
+        break;\r
+    }\r
+\r
+#ifdef Py_USING_UNICODE\r
+    case 'U': { /* Unicode object */\r
+        PyObject **p = va_arg(*p_va, PyObject **);\r
+        if (PyUnicode_Check(arg))\r
+            *p = arg;\r
+        else\r
+            return converterr("unicode", arg, msgbuf, bufsize);\r
+        break;\r
+    }\r
+#endif\r
+\r
+    case 'O': { /* object */\r
+        PyTypeObject *type;\r
+        PyObject **p;\r
+        if (*format == '!') {\r
+            type = va_arg(*p_va, PyTypeObject*);\r
+            p = va_arg(*p_va, PyObject **);\r
+            format++;\r
+            if (PyType_IsSubtype(arg->ob_type, type))\r
+                *p = arg;\r
+            else\r
+                return converterr(type->tp_name, arg, msgbuf, bufsize);\r
+\r
+        }\r
+        else if (*format == '?') {\r
+            inquiry pred = va_arg(*p_va, inquiry);\r
+            p = va_arg(*p_va, PyObject **);\r
+            format++;\r
+            if ((*pred)(arg))\r
+                *p = arg;\r
+            else\r
+                return converterr("(unspecified)",\r
+                                  arg, msgbuf, bufsize);\r
+\r
+        }\r
+        else if (*format == '&') {\r
+            typedef int (*converter)(PyObject *, void *);\r
+            converter convert = va_arg(*p_va, converter);\r
+            void *addr = va_arg(*p_va, void *);\r
+            format++;\r
+            if (! (*convert)(arg, addr))\r
+                return converterr("(unspecified)",\r
+                                  arg, msgbuf, bufsize);\r
+        }\r
+        else {\r
+            p = va_arg(*p_va, PyObject **);\r
+            *p = arg;\r
+        }\r
+        break;\r
+    }\r
+\r
+\r
+    case 'w': { /* memory buffer, read-write access */\r
+        void **p = va_arg(*p_va, void **);\r
+        void *res;\r
+        PyBufferProcs *pb = arg->ob_type->tp_as_buffer;\r
+        Py_ssize_t count;\r
+\r
+        if (pb && pb->bf_releasebuffer && *format != '*')\r
+            /* Buffer must be released, yet caller does not use\r
+               the Py_buffer protocol. */\r
+            return converterr("pinned buffer", arg, msgbuf, bufsize);\r
+\r
+        if (pb && pb->bf_getbuffer && *format == '*') {\r
+            /* Caller is interested in Py_buffer, and the object\r
+               supports it directly. */\r
+            format++;\r
+            if (pb->bf_getbuffer(arg, (Py_buffer*)p, PyBUF_WRITABLE) < 0) {\r
+                PyErr_Clear();\r
+                return converterr("read-write buffer", arg, msgbuf, bufsize);\r
+            }\r
+            if (addcleanup(p, freelist, cleanup_buffer)) {\r
+                return converterr(\r
+                    "(cleanup problem)",\r
+                    arg, msgbuf, bufsize);\r
+            }\r
+            if (!PyBuffer_IsContiguous((Py_buffer*)p, 'C'))\r
+                return converterr("contiguous buffer", arg, msgbuf, bufsize);\r
+            break;\r
+        }\r
+\r
+        if (pb == NULL ||\r
+            pb->bf_getwritebuffer == NULL ||\r
+            pb->bf_getsegcount == NULL)\r
+            return converterr("read-write buffer", arg, msgbuf, bufsize);\r
+        if ((*pb->bf_getsegcount)(arg, NULL) != 1)\r
+            return converterr("single-segment read-write buffer",\r
+                              arg, msgbuf, bufsize);\r
+        if ((count = pb->bf_getwritebuffer(arg, 0, &res)) < 0)\r
+            return converterr("(unspecified)", arg, msgbuf, bufsize);\r
+        if (*format == '*') {\r
+            PyBuffer_FillInfo((Py_buffer*)p, arg, res, count, 1, 0);\r
+            format++;\r
+        }\r
+        else {\r
+            *p = res;\r
+            if (*format == '#') {\r
+                FETCH_SIZE;\r
+                STORE_SIZE(count);\r
+                format++;\r
+            }\r
+        }\r
+        break;\r
+    }\r
+\r
+    case 't': { /* 8-bit character buffer, read-only access */\r
+        char **p = va_arg(*p_va, char **);\r
+        PyBufferProcs *pb = arg->ob_type->tp_as_buffer;\r
+        Py_ssize_t count;\r
+\r
+        if (*format++ != '#')\r
+            return converterr(\r
+                "invalid use of 't' format character",\r
+                arg, msgbuf, bufsize);\r
+        if (!PyType_HasFeature(arg->ob_type,\r
+                               Py_TPFLAGS_HAVE_GETCHARBUFFER) ||\r
+            pb == NULL || pb->bf_getcharbuffer == NULL ||\r
+            pb->bf_getsegcount == NULL)\r
+            return converterr(\r
+                "string or read-only character buffer",\r
+                arg, msgbuf, bufsize);\r
+\r
+        if (pb->bf_getsegcount(arg, NULL) != 1)\r
+            return converterr(\r
+                "string or single-segment read-only buffer",\r
+                arg, msgbuf, bufsize);\r
+\r
+        if (pb->bf_releasebuffer)\r
+            return converterr(\r
+                "string or pinned buffer",\r
+                arg, msgbuf, bufsize);\r
+\r
+        count = pb->bf_getcharbuffer(arg, 0, p);\r
+        if (count < 0)\r
+            return converterr("(unspecified)", arg, msgbuf, bufsize);\r
+        {\r
+            FETCH_SIZE;\r
+            STORE_SIZE(count);\r
+        }\r
+        break;\r
+    }\r
+\r
+    default:\r
+        return converterr("impossible<bad format char>", arg, msgbuf, bufsize);\r
+\r
+    }\r
+\r
+    *p_format = format;\r
+    return NULL;\r
+}\r
+\r
+static Py_ssize_t\r
+convertbuffer(PyObject *arg, void **p, char **errmsg)\r
+{\r
+    PyBufferProcs *pb = arg->ob_type->tp_as_buffer;\r
+    Py_ssize_t count;\r
+    if (pb == NULL ||\r
+        pb->bf_getreadbuffer == NULL ||\r
+        pb->bf_getsegcount == NULL ||\r
+        pb->bf_releasebuffer != NULL) {\r
+        *errmsg = "string or read-only buffer";\r
+        return -1;\r
+    }\r
+    if ((*pb->bf_getsegcount)(arg, NULL) != 1) {\r
+        *errmsg = "string or single-segment read-only buffer";\r
+        return -1;\r
+    }\r
+    if ((count = (*pb->bf_getreadbuffer)(arg, 0, p)) < 0) {\r
+        *errmsg = "(unspecified)";\r
+    }\r
+    return count;\r
+}\r
+\r
+static int\r
+getbuffer(PyObject *arg, Py_buffer *view, char **errmsg)\r
+{\r
+    void *buf;\r
+    Py_ssize_t count;\r
+    PyBufferProcs *pb = arg->ob_type->tp_as_buffer;\r
+    if (pb == NULL) {\r
+        *errmsg = "string or buffer";\r
+        return -1;\r
+    }\r
+    if (pb->bf_getbuffer) {\r
+        if (pb->bf_getbuffer(arg, view, 0) < 0) {\r
+            *errmsg = "convertible to a buffer";\r
+            return -1;\r
+        }\r
+        if (!PyBuffer_IsContiguous(view, 'C')) {\r
+            *errmsg = "contiguous buffer";\r
+            return -1;\r
+        }\r
+        return 0;\r
+    }\r
+\r
+    count = convertbuffer(arg, &buf, errmsg);\r
+    if (count < 0) {\r
+        *errmsg = "convertible to a buffer";\r
+        return count;\r
+    }\r
+    PyBuffer_FillInfo(view, arg, buf, count, 1, 0);\r
+    return 0;\r
+}\r
+\r
+/* Support for keyword arguments donated by\r
+   Geoff Philbrick <philbric@delphi.hks.com> */\r
+\r
+/* Return false (0) for error, else true. */\r
+int\r
+PyArg_ParseTupleAndKeywords(PyObject *args,\r
+                            PyObject *keywords,\r
+                            const char *format,\r
+                            char **kwlist, ...)\r
+{\r
+    int retval;\r
+    va_list va;\r
+\r
+    if ((args == NULL || !PyTuple_Check(args)) ||\r
+        (keywords != NULL && !PyDict_Check(keywords)) ||\r
+        format == NULL ||\r
+        kwlist == NULL)\r
+    {\r
+        PyErr_BadInternalCall();\r
+        return 0;\r
+    }\r
+\r
+    va_start(va, kwlist);\r
+    retval = vgetargskeywords(args, keywords, format, kwlist, &va, 0);\r
+    va_end(va);\r
+    return retval;\r
+}\r
+\r
+int\r
+_PyArg_ParseTupleAndKeywords_SizeT(PyObject *args,\r
+                                  PyObject *keywords,\r
+                                  const char *format,\r
+                                  char **kwlist, ...)\r
+{\r
+    int retval;\r
+    va_list va;\r
+\r
+    if ((args == NULL || !PyTuple_Check(args)) ||\r
+        (keywords != NULL && !PyDict_Check(keywords)) ||\r
+        format == NULL ||\r
+        kwlist == NULL)\r
+    {\r
+        PyErr_BadInternalCall();\r
+        return 0;\r
+    }\r
+\r
+    va_start(va, kwlist);\r
+    retval = vgetargskeywords(args, keywords, format,\r
+                              kwlist, &va, FLAG_SIZE_T);\r
+    va_end(va);\r
+    return retval;\r
+}\r
+\r
+\r
+int\r
+PyArg_VaParseTupleAndKeywords(PyObject *args,\r
+                              PyObject *keywords,\r
+                              const char *format,\r
+                              char **kwlist, va_list va)\r
+{\r
+    int retval;\r
+    va_list lva;\r
+\r
+    if ((args == NULL || !PyTuple_Check(args)) ||\r
+        (keywords != NULL && !PyDict_Check(keywords)) ||\r
+        format == NULL ||\r
+        kwlist == NULL)\r
+    {\r
+        PyErr_BadInternalCall();\r
+        return 0;\r
+    }\r
+\r
+#ifdef VA_LIST_IS_ARRAY\r
+    memcpy(lva, va, sizeof(va_list));\r
+#else\r
+#ifdef __va_copy\r
+    __va_copy(lva, va);\r
+#else\r
+    lva = va;\r
+#endif\r
+#endif\r
+\r
+    retval = vgetargskeywords(args, keywords, format, kwlist, &lva, 0);\r
+    return retval;\r
+}\r
+\r
+int\r
+_PyArg_VaParseTupleAndKeywords_SizeT(PyObject *args,\r
+                                    PyObject *keywords,\r
+                                    const char *format,\r
+                                    char **kwlist, va_list va)\r
+{\r
+    int retval;\r
+    va_list lva;\r
+\r
+    if ((args == NULL || !PyTuple_Check(args)) ||\r
+        (keywords != NULL && !PyDict_Check(keywords)) ||\r
+        format == NULL ||\r
+        kwlist == NULL)\r
+    {\r
+        PyErr_BadInternalCall();\r
+        return 0;\r
+    }\r
+\r
+#ifdef VA_LIST_IS_ARRAY\r
+    memcpy(lva, va, sizeof(va_list));\r
+#else\r
+#ifdef __va_copy\r
+    __va_copy(lva, va);\r
+#else\r
+    lva = va;\r
+#endif\r
+#endif\r
+\r
+    retval = vgetargskeywords(args, keywords, format,\r
+                              kwlist, &lva, FLAG_SIZE_T);\r
+    return retval;\r
+}\r
+\r
+#define IS_END_OF_FORMAT(c) (c == '\0' || c == ';' || c == ':')\r
+\r
+static int\r
+vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,\r
+                 char **kwlist, va_list *p_va, int flags)\r
+{\r
+    char msgbuf[512];\r
+    int levels[32];\r
+    const char *fname, *msg, *custom_msg, *keyword;\r
+    int min = INT_MAX;\r
+    int i, len, nargs, nkeywords;\r
+    PyObject *freelist = NULL, *current_arg;\r
+\r
+    assert(args != NULL && PyTuple_Check(args));\r
+    assert(keywords == NULL || PyDict_Check(keywords));\r
+    assert(format != NULL);\r
+    assert(kwlist != NULL);\r
+    assert(p_va != NULL);\r
+\r
+    /* grab the function name or custom error msg first (mutually exclusive) */\r
+    fname = strchr(format, ':');\r
+    if (fname) {\r
+        fname++;\r
+        custom_msg = NULL;\r
+    }\r
+    else {\r
+        custom_msg = strchr(format,';');\r
+        if (custom_msg)\r
+            custom_msg++;\r
+    }\r
+\r
+    /* scan kwlist and get greatest possible nbr of args */\r
+    for (len=0; kwlist[len]; len++)\r
+        continue;\r
+\r
+    nargs = PyTuple_GET_SIZE(args);\r
+    nkeywords = (keywords == NULL) ? 0 : PyDict_Size(keywords);\r
+    if (nargs + nkeywords > len) {\r
+        PyErr_Format(PyExc_TypeError, "%s%s takes at most %d "\r
+                     "argument%s (%d given)",\r
+                     (fname == NULL) ? "function" : fname,\r
+                     (fname == NULL) ? "" : "()",\r
+                     len,\r
+                     (len == 1) ? "" : "s",\r
+                     nargs + nkeywords);\r
+        return 0;\r
+    }\r
+\r
+    /* convert tuple args and keyword args in same loop, using kwlist to drive process */\r
+    for (i = 0; i < len; i++) {\r
+        keyword = kwlist[i];\r
+        if (*format == '|') {\r
+            min = i;\r
+            format++;\r
+        }\r
+        if (IS_END_OF_FORMAT(*format)) {\r
+            PyErr_Format(PyExc_RuntimeError,\r
+                         "More keyword list entries (%d) than "\r
+                         "format specifiers (%d)", len, i);\r
+            return cleanreturn(0, freelist);\r
+        }\r
+        current_arg = NULL;\r
+        if (nkeywords) {\r
+            current_arg = PyDict_GetItemString(keywords, keyword);\r
+        }\r
+        if (current_arg) {\r
+            --nkeywords;\r
+            if (i < nargs) {\r
+                /* arg present in tuple and in dict */\r
+                PyErr_Format(PyExc_TypeError,\r
+                             "Argument given by name ('%s') "\r
+                             "and position (%d)",\r
+                             keyword, i+1);\r
+                return cleanreturn(0, freelist);\r
+            }\r
+        }\r
+        else if (nkeywords && PyErr_Occurred())\r
+            return cleanreturn(0, freelist);\r
+        else if (i < nargs)\r
+            current_arg = PyTuple_GET_ITEM(args, i);\r
+\r
+        if (current_arg) {\r
+            msg = convertitem(current_arg, &format, p_va, flags,\r
+                levels, msgbuf, sizeof(msgbuf), &freelist);\r
+            if (msg) {\r
+                seterror(i+1, msg, levels, fname, custom_msg);\r
+                return cleanreturn(0, freelist);\r
+            }\r
+            continue;\r
+        }\r
+\r
+        if (i < min) {\r
+            PyErr_Format(PyExc_TypeError, "Required argument "\r
+                         "'%s' (pos %d) not found",\r
+                         keyword, i+1);\r
+            return cleanreturn(0, freelist);\r
+        }\r
+        /* current code reports success when all required args\r
+         * fulfilled and no keyword args left, with no further\r
+         * validation. XXX Maybe skip this in debug build ?\r
+         */\r
+        if (!nkeywords)\r
+            return cleanreturn(1, freelist);\r
+\r
+        /* We are into optional args, skip thru to any remaining\r
+         * keyword args */\r
+        msg = skipitem(&format, p_va, flags);\r
+        if (msg) {\r
+            PyErr_Format(PyExc_RuntimeError, "%s: '%s'", msg,\r
+                         format);\r
+            return cleanreturn(0, freelist);\r
+        }\r
+    }\r
+\r
+    if (!IS_END_OF_FORMAT(*format) && *format != '|') {\r
+        PyErr_Format(PyExc_RuntimeError,\r
+            "more argument specifiers than keyword list entries "\r
+            "(remaining format:'%s')", format);\r
+        return cleanreturn(0, freelist);\r
+    }\r
+\r
+    /* make sure there are no extraneous keyword arguments */\r
+    if (nkeywords > 0) {\r
+        PyObject *key, *value;\r
+        Py_ssize_t pos = 0;\r
+        while (PyDict_Next(keywords, &pos, &key, &value)) {\r
+            int match = 0;\r
+            char *ks;\r
+            if (!PyString_Check(key)) {\r
+                PyErr_SetString(PyExc_TypeError,\r
+                                "keywords must be strings");\r
+                return cleanreturn(0, freelist);\r
+            }\r
+            ks = PyString_AsString(key);\r
+            for (i = 0; i < len; i++) {\r
+                if (!strcmp(ks, kwlist[i])) {\r
+                    match = 1;\r
+                    break;\r
+                }\r
+            }\r
+            if (!match) {\r
+                PyErr_Format(PyExc_TypeError,\r
+                             "'%s' is an invalid keyword "\r
+                             "argument for this function",\r
+                             ks);\r
+                return cleanreturn(0, freelist);\r
+            }\r
+        }\r
+    }\r
+\r
+    return cleanreturn(1, freelist);\r
+}\r
+\r
+\r
+static char *\r
+skipitem(const char **p_format, va_list *p_va, int flags)\r
+{\r
+    const char *format = *p_format;\r
+    char c = *format++;\r
+\r
+    switch (c) {\r
+\r
+    /* simple codes\r
+     * The individual types (second arg of va_arg) are irrelevant */\r
+\r
+    case 'b': /* byte -- very short int */\r
+    case 'B': /* byte as bitfield */\r
+    case 'h': /* short int */\r
+    case 'H': /* short int as bitfield */\r
+    case 'i': /* int */\r
+    case 'I': /* int sized bitfield */\r
+    case 'l': /* long int */\r
+    case 'k': /* long int sized bitfield */\r
+#ifdef HAVE_LONG_LONG\r
+    case 'L': /* PY_LONG_LONG */\r
+    case 'K': /* PY_LONG_LONG sized bitfield */\r
+#endif\r
+    case 'f': /* float */\r
+    case 'd': /* double */\r
+#ifndef WITHOUT_COMPLEX\r
+    case 'D': /* complex double */\r
+#endif\r
+    case 'c': /* char */\r
+        {\r
+            (void) va_arg(*p_va, void *);\r
+            break;\r
+        }\r
+\r
+    case 'n': /* Py_ssize_t */\r
+        {\r
+            (void) va_arg(*p_va, Py_ssize_t *);\r
+            break;\r
+        }\r
+\r
+    /* string codes */\r
+\r
+    case 'e': /* string with encoding */\r
+        {\r
+            (void) va_arg(*p_va, const char *);\r
+            if (!(*format == 's' || *format == 't'))\r
+                /* after 'e', only 's' and 't' is allowed */\r
+                goto err;\r
+            format++;\r
+            /* explicit fallthrough to string cases */\r
+        }\r
+\r
+    case 's': /* string */\r
+    case 'z': /* string or None */\r
+#ifdef Py_USING_UNICODE\r
+    case 'u': /* unicode string */\r
+#endif\r
+    case 't': /* buffer, read-only */\r
+    case 'w': /* buffer, read-write */\r
+        {\r
+            (void) va_arg(*p_va, char **);\r
+            if (*format == '#') {\r
+                if (flags & FLAG_SIZE_T)\r
+                    (void) va_arg(*p_va, Py_ssize_t *);\r
+                else\r
+                    (void) va_arg(*p_va, int *);\r
+                format++;\r
+            } else if ((c == 's' || c == 'z') && *format == '*') {\r
+                format++;\r
+            }\r
+            break;\r
+        }\r
+\r
+    /* object codes */\r
+\r
+    case 'S': /* string object */\r
+#ifdef Py_USING_UNICODE\r
+    case 'U': /* unicode string object */\r
+#endif\r
+        {\r
+            (void) va_arg(*p_va, PyObject **);\r
+            break;\r
+        }\r
+\r
+    case 'O': /* object */\r
+        {\r
+            if (*format == '!') {\r
+                format++;\r
+                (void) va_arg(*p_va, PyTypeObject*);\r
+                (void) va_arg(*p_va, PyObject **);\r
+            }\r
+            else if (*format == '&') {\r
+                typedef int (*converter)(PyObject *, void *);\r
+                (void) va_arg(*p_va, converter);\r
+                (void) va_arg(*p_va, void *);\r
+                format++;\r
+            }\r
+            else {\r
+                (void) va_arg(*p_va, PyObject **);\r
+            }\r
+            break;\r
+        }\r
+\r
+    case '(':           /* bypass tuple, not handled at all previously */\r
+        {\r
+            char *msg;\r
+            for (;;) {\r
+                if (*format==')')\r
+                    break;\r
+                if (IS_END_OF_FORMAT(*format))\r
+                    return "Unmatched left paren in format "\r
+                           "string";\r
+                msg = skipitem(&format, p_va, flags);\r
+                if (msg)\r
+                    return msg;\r
+            }\r
+            format++;\r
+            break;\r
+        }\r
+\r
+    case ')':\r
+        return "Unmatched right paren in format string";\r
+\r
+    default:\r
+err:\r
+        return "impossible<bad format char>";\r
+\r
+    }\r
+\r
+    *p_format = format;\r
+    return NULL;\r
+}\r
+\r
+\r
+int\r
+PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, ...)\r
+{\r
+    Py_ssize_t i, l;\r
+    PyObject **o;\r
+    va_list vargs;\r
+\r
+#ifdef HAVE_STDARG_PROTOTYPES\r
+    va_start(vargs, max);\r
+#else\r
+    va_start(vargs);\r
+#endif\r
+\r
+    assert(min >= 0);\r
+    assert(min <= max);\r
+    if (!PyTuple_Check(args)) {\r
+        va_end(vargs);\r
+        PyErr_SetString(PyExc_SystemError,\r
+            "PyArg_UnpackTuple() argument list is not a tuple");\r
+        return 0;\r
+    }\r
+    l = PyTuple_GET_SIZE(args);\r
+    if (l < min) {\r
+        if (name != NULL)\r
+            PyErr_Format(\r
+                PyExc_TypeError,\r
+                "%s expected %s%zd arguments, got %zd",\r
+                name, (min == max ? "" : "at least "), min, l);\r
+        else\r
+            PyErr_Format(\r
+                PyExc_TypeError,\r
+                "unpacked tuple should have %s%zd elements,"\r
+                " but has %zd",\r
+                (min == max ? "" : "at least "), min, l);\r
+        va_end(vargs);\r
+        return 0;\r
+    }\r
+    if (l > max) {\r
+        if (name != NULL)\r
+            PyErr_Format(\r
+                PyExc_TypeError,\r
+                "%s expected %s%zd arguments, got %zd",\r
+                name, (min == max ? "" : "at most "), max, l);\r
+        else\r
+            PyErr_Format(\r
+                PyExc_TypeError,\r
+                "unpacked tuple should have %s%zd elements,"\r
+                " but has %zd",\r
+                (min == max ? "" : "at most "), max, l);\r
+        va_end(vargs);\r
+        return 0;\r
+    }\r
+    for (i = 0; i < l; i++) {\r
+        o = va_arg(vargs, PyObject **);\r
+        *o = PyTuple_GET_ITEM(args, i);\r
+    }\r
+    va_end(vargs);\r
+    return 1;\r
+}\r
+\r
+\r
+/* For type constructors that don't take keyword args\r
+ *\r
+ * Sets a TypeError and returns 0 if the kwds dict is\r
+ * not empty, returns 1 otherwise\r
+ */\r
+int\r
+_PyArg_NoKeywords(const char *funcname, PyObject *kw)\r
+{\r
+    if (kw == NULL)\r
+        return 1;\r
+    if (!PyDict_CheckExact(kw)) {\r
+        PyErr_BadInternalCall();\r
+        return 0;\r
+    }\r
+    if (PyDict_Size(kw) == 0)\r
+        return 1;\r
+\r
+    PyErr_Format(PyExc_TypeError, "%s does not take keyword arguments",\r
+                    funcname);\r
+    return 0;\r
+}\r
+#ifdef __cplusplus\r
+};\r
+#endif\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/getcompiler.c b/AppPkg/Applications/Python/Python-2.7.10/Python/getcompiler.c
new file mode 100644 (file)
index 0000000..33a7639
--- /dev/null
@@ -0,0 +1,28 @@
+\r
+/* Return the compiler identification, if possible. */\r
+\r
+#include "Python.h"\r
+\r
+#ifndef COMPILER\r
+\r
+#ifdef __GNUC__\r
+#define COMPILER "\n[GCC " __VERSION__ "]"\r
+#endif\r
+\r
+#endif /* !COMPILER */\r
+\r
+#ifndef COMPILER\r
+\r
+#ifdef __cplusplus\r
+#define COMPILER "[C++]"\r
+#else\r
+#define COMPILER "[C]"\r
+#endif\r
+\r
+#endif /* !COMPILER */\r
+\r
+const char *\r
+Py_GetCompiler(void)\r
+{\r
+       return COMPILER;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/getopt.c b/AppPkg/Applications/Python/Python-2.7.10/Python/getopt.c
new file mode 100644 (file)
index 0000000..af6f5dc
--- /dev/null
@@ -0,0 +1,136 @@
+/*---------------------------------------------------------------------------*\r
+ * <RCS keywords>\r
+ *\r
+ * C++ Library\r
+ *\r
+ * Copyright 1992-1994, David Gottner\r
+ *\r
+ *                    All Rights Reserved\r
+ *\r
+ * Permission to use, copy, modify, and distribute this software and its\r
+ * documentation for any purpose and without fee is hereby granted,\r
+ * provided that the above copyright notice, this permission notice and\r
+ * the following disclaimer notice appear unmodified in all copies.\r
+ *\r
+ * I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL I\r
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY\r
+ * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER\r
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT\r
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\r
+ *\r
+ * Nevertheless, I would like to know about bugs in this library or\r
+ * suggestions for improvment.  Send bug reports and feedback to\r
+ * davegottner@delphi.com.\r
+ *---------------------------------------------------------------------------*/\r
+\r
+/* Modified to support --help and --version, as well as /? on Windows\r
+ * by Georg Brandl. */\r
+\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+int _PyOS_opterr = 1;          /* generate error messages */\r
+int _PyOS_optind = 1;          /* index into argv array   */\r
+char *_PyOS_optarg = NULL;     /* optional argument       */\r
+static char *opt_ptr = "";\r
+\r
+void _PyOS_ResetGetOpt(void)\r
+{\r
+    _PyOS_opterr = 1;\r
+    _PyOS_optind = 1;\r
+    _PyOS_optarg = NULL;\r
+    opt_ptr = "";\r
+}\r
+\r
+int _PyOS_GetOpt(int argc, char **argv, char *optstring)\r
+{\r
+    char *ptr;\r
+    int option;\r
+\r
+    if (*opt_ptr == '\0') {\r
+\r
+        if (_PyOS_optind >= argc)\r
+            return -1;\r
+#ifdef MS_WINDOWS\r
+        else if (strcmp(argv[_PyOS_optind], "/?") == 0) {\r
+            ++_PyOS_optind;\r
+            return 'h';\r
+        }\r
+#endif\r
+\r
+        else if (argv[_PyOS_optind][0] != '-' ||\r
+                 argv[_PyOS_optind][1] == '\0' /* lone dash */ )\r
+            return -1;\r
+\r
+        else if (strcmp(argv[_PyOS_optind], "--") == 0) {\r
+            ++_PyOS_optind;\r
+            return -1;\r
+        }\r
+\r
+        else if (strcmp(argv[_PyOS_optind], "--help") == 0) {\r
+            ++_PyOS_optind;\r
+            return 'h';\r
+        }\r
+\r
+        else if (strcmp(argv[_PyOS_optind], "--version") == 0) {\r
+            ++_PyOS_optind;\r
+            return 'V';\r
+        }\r
+\r
+\r
+        opt_ptr = &argv[_PyOS_optind++][1];\r
+    }\r
+\r
+    if ((option = *opt_ptr++) == '\0')\r
+        return -1;\r
+\r
+    if (option == 'J') {\r
+        if (_PyOS_opterr)\r
+            fprintf(stderr, "-J is reserved for Jython\n");\r
+        return '_';\r
+    }\r
+\r
+    if (option == 'X') {\r
+        if (_PyOS_opterr)\r
+            fprintf(stderr,\r
+                "-X is reserved for implementation-specific arguments\n");\r
+        return '_';\r
+    }\r
+\r
+    if ((ptr = strchr(optstring, option)) == NULL) {\r
+        if (_PyOS_opterr)\r
+            fprintf(stderr, "Unknown option: -%c\n", option);\r
+\r
+        return '_';\r
+    }\r
+\r
+    if (*(ptr + 1) == ':') {\r
+        if (*opt_ptr != '\0') {\r
+            _PyOS_optarg  = opt_ptr;\r
+            opt_ptr = "";\r
+        }\r
+\r
+        else {\r
+            if (_PyOS_optind >= argc) {\r
+                if (_PyOS_opterr)\r
+                    fprintf(stderr,\r
+                        "Argument expected for the -%c option\n", option);\r
+                return '_';\r
+            }\r
+\r
+            _PyOS_optarg = argv[_PyOS_optind++];\r
+        }\r
+    }\r
+\r
+    return option;\r
+}\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/getplatform.c b/AppPkg/Applications/Python/Python-2.7.10/Python/getplatform.c
new file mode 100644 (file)
index 0000000..ce79ffe
--- /dev/null
@@ -0,0 +1,12 @@
+\r
+#include "Python.h"\r
+\r
+#ifndef PLATFORM\r
+#define PLATFORM "unknown"\r
+#endif\r
+\r
+const char *\r
+Py_GetPlatform(void)\r
+{\r
+       return PLATFORM;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/getversion.c b/AppPkg/Applications/Python/Python-2.7.10/Python/getversion.c
new file mode 100644 (file)
index 0000000..7c75348
--- /dev/null
@@ -0,0 +1,15 @@
+\r
+/* Return the full version string. */\r
+\r
+#include "Python.h"\r
+\r
+#include "patchlevel.h"\r
+\r
+const char *\r
+Py_GetVersion(void)\r
+{\r
+       static char version[250];\r
+       PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",\r
+                     PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());\r
+       return version;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/graminit.c b/AppPkg/Applications/Python/Python-2.7.10/Python/graminit.c
new file mode 100644 (file)
index 0000000..db2e9a7
--- /dev/null
@@ -0,0 +1,2177 @@
+/* Generated by Parser/pgen */\r
+\r
+#include "pgenheaders.h"\r
+#include "grammar.h"\r
+PyAPI_DATA(grammar) _PyParser_Grammar;\r
+static arc arcs_0_0[3] = {\r
+    {2, 1},\r
+    {3, 1},\r
+    {4, 2},\r
+};\r
+static arc arcs_0_1[1] = {\r
+    {0, 1},\r
+};\r
+static arc arcs_0_2[1] = {\r
+    {2, 1},\r
+};\r
+static state states_0[3] = {\r
+    {3, arcs_0_0},\r
+    {1, arcs_0_1},\r
+    {1, arcs_0_2},\r
+};\r
+static arc arcs_1_0[3] = {\r
+    {2, 0},\r
+    {6, 0},\r
+    {7, 1},\r
+};\r
+static arc arcs_1_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_1[2] = {\r
+    {3, arcs_1_0},\r
+    {1, arcs_1_1},\r
+};\r
+static arc arcs_2_0[1] = {\r
+    {9, 1},\r
+};\r
+static arc arcs_2_1[2] = {\r
+    {2, 1},\r
+    {7, 2},\r
+};\r
+static arc arcs_2_2[1] = {\r
+    {0, 2},\r
+};\r
+static state states_2[3] = {\r
+    {1, arcs_2_0},\r
+    {2, arcs_2_1},\r
+    {1, arcs_2_2},\r
+};\r
+static arc arcs_3_0[1] = {\r
+    {11, 1},\r
+};\r
+static arc arcs_3_1[1] = {\r
+    {12, 2},\r
+};\r
+static arc arcs_3_2[2] = {\r
+    {13, 3},\r
+    {2, 4},\r
+};\r
+static arc arcs_3_3[2] = {\r
+    {14, 5},\r
+    {15, 6},\r
+};\r
+static arc arcs_3_4[1] = {\r
+    {0, 4},\r
+};\r
+static arc arcs_3_5[1] = {\r
+    {15, 6},\r
+};\r
+static arc arcs_3_6[1] = {\r
+    {2, 4},\r
+};\r
+static state states_3[7] = {\r
+    {1, arcs_3_0},\r
+    {1, arcs_3_1},\r
+    {2, arcs_3_2},\r
+    {2, arcs_3_3},\r
+    {1, arcs_3_4},\r
+    {1, arcs_3_5},\r
+    {1, arcs_3_6},\r
+};\r
+static arc arcs_4_0[1] = {\r
+    {10, 1},\r
+};\r
+static arc arcs_4_1[2] = {\r
+    {10, 1},\r
+    {0, 1},\r
+};\r
+static state states_4[2] = {\r
+    {1, arcs_4_0},\r
+    {2, arcs_4_1},\r
+};\r
+static arc arcs_5_0[1] = {\r
+    {16, 1},\r
+};\r
+static arc arcs_5_1[2] = {\r
+    {18, 2},\r
+    {19, 2},\r
+};\r
+static arc arcs_5_2[1] = {\r
+    {0, 2},\r
+};\r
+static state states_5[3] = {\r
+    {1, arcs_5_0},\r
+    {2, arcs_5_1},\r
+    {1, arcs_5_2},\r
+};\r
+static arc arcs_6_0[1] = {\r
+    {20, 1},\r
+};\r
+static arc arcs_6_1[1] = {\r
+    {21, 2},\r
+};\r
+static arc arcs_6_2[1] = {\r
+    {22, 3},\r
+};\r
+static arc arcs_6_3[1] = {\r
+    {23, 4},\r
+};\r
+static arc arcs_6_4[1] = {\r
+    {24, 5},\r
+};\r
+static arc arcs_6_5[1] = {\r
+    {0, 5},\r
+};\r
+static state states_6[6] = {\r
+    {1, arcs_6_0},\r
+    {1, arcs_6_1},\r
+    {1, arcs_6_2},\r
+    {1, arcs_6_3},\r
+    {1, arcs_6_4},\r
+    {1, arcs_6_5},\r
+};\r
+static arc arcs_7_0[1] = {\r
+    {13, 1},\r
+};\r
+static arc arcs_7_1[2] = {\r
+    {25, 2},\r
+    {15, 3},\r
+};\r
+static arc arcs_7_2[1] = {\r
+    {15, 3},\r
+};\r
+static arc arcs_7_3[1] = {\r
+    {0, 3},\r
+};\r
+static state states_7[4] = {\r
+    {1, arcs_7_0},\r
+    {2, arcs_7_1},\r
+    {1, arcs_7_2},\r
+    {1, arcs_7_3},\r
+};\r
+static arc arcs_8_0[3] = {\r
+    {26, 1},\r
+    {30, 2},\r
+    {31, 3},\r
+};\r
+static arc arcs_8_1[3] = {\r
+    {27, 4},\r
+    {29, 5},\r
+    {0, 1},\r
+};\r
+static arc arcs_8_2[1] = {\r
+    {21, 6},\r
+};\r
+static arc arcs_8_3[1] = {\r
+    {21, 7},\r
+};\r
+static arc arcs_8_4[1] = {\r
+    {28, 8},\r
+};\r
+static arc arcs_8_5[4] = {\r
+    {26, 1},\r
+    {30, 2},\r
+    {31, 3},\r
+    {0, 5},\r
+};\r
+static arc arcs_8_6[2] = {\r
+    {29, 9},\r
+    {0, 6},\r
+};\r
+static arc arcs_8_7[1] = {\r
+    {0, 7},\r
+};\r
+static arc arcs_8_8[2] = {\r
+    {29, 5},\r
+    {0, 8},\r
+};\r
+static arc arcs_8_9[1] = {\r
+    {31, 3},\r
+};\r
+static state states_8[10] = {\r
+    {3, arcs_8_0},\r
+    {3, arcs_8_1},\r
+    {1, arcs_8_2},\r
+    {1, arcs_8_3},\r
+    {1, arcs_8_4},\r
+    {4, arcs_8_5},\r
+    {2, arcs_8_6},\r
+    {1, arcs_8_7},\r
+    {2, arcs_8_8},\r
+    {1, arcs_8_9},\r
+};\r
+static arc arcs_9_0[2] = {\r
+    {21, 1},\r
+    {13, 2},\r
+};\r
+static arc arcs_9_1[1] = {\r
+    {0, 1},\r
+};\r
+static arc arcs_9_2[1] = {\r
+    {32, 3},\r
+};\r
+static arc arcs_9_3[1] = {\r
+    {15, 1},\r
+};\r
+static state states_9[4] = {\r
+    {2, arcs_9_0},\r
+    {1, arcs_9_1},\r
+    {1, arcs_9_2},\r
+    {1, arcs_9_3},\r
+};\r
+static arc arcs_10_0[1] = {\r
+    {26, 1},\r
+};\r
+static arc arcs_10_1[2] = {\r
+    {29, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_10_2[2] = {\r
+    {26, 1},\r
+    {0, 2},\r
+};\r
+static state states_10[3] = {\r
+    {1, arcs_10_0},\r
+    {2, arcs_10_1},\r
+    {2, arcs_10_2},\r
+};\r
+static arc arcs_11_0[2] = {\r
+    {3, 1},\r
+    {4, 1},\r
+};\r
+static arc arcs_11_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_11[2] = {\r
+    {2, arcs_11_0},\r
+    {1, arcs_11_1},\r
+};\r
+static arc arcs_12_0[1] = {\r
+    {33, 1},\r
+};\r
+static arc arcs_12_1[2] = {\r
+    {34, 2},\r
+    {2, 3},\r
+};\r
+static arc arcs_12_2[2] = {\r
+    {33, 1},\r
+    {2, 3},\r
+};\r
+static arc arcs_12_3[1] = {\r
+    {0, 3},\r
+};\r
+static state states_12[4] = {\r
+    {1, arcs_12_0},\r
+    {2, arcs_12_1},\r
+    {2, arcs_12_2},\r
+    {1, arcs_12_3},\r
+};\r
+static arc arcs_13_0[9] = {\r
+    {35, 1},\r
+    {36, 1},\r
+    {37, 1},\r
+    {38, 1},\r
+    {39, 1},\r
+    {40, 1},\r
+    {41, 1},\r
+    {42, 1},\r
+    {43, 1},\r
+};\r
+static arc arcs_13_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_13[2] = {\r
+    {9, arcs_13_0},\r
+    {1, arcs_13_1},\r
+};\r
+static arc arcs_14_0[1] = {\r
+    {9, 1},\r
+};\r
+static arc arcs_14_1[3] = {\r
+    {44, 2},\r
+    {27, 3},\r
+    {0, 1},\r
+};\r
+static arc arcs_14_2[2] = {\r
+    {45, 4},\r
+    {9, 4},\r
+};\r
+static arc arcs_14_3[2] = {\r
+    {45, 5},\r
+    {9, 5},\r
+};\r
+static arc arcs_14_4[1] = {\r
+    {0, 4},\r
+};\r
+static arc arcs_14_5[2] = {\r
+    {27, 3},\r
+    {0, 5},\r
+};\r
+static state states_14[6] = {\r
+    {1, arcs_14_0},\r
+    {3, arcs_14_1},\r
+    {2, arcs_14_2},\r
+    {2, arcs_14_3},\r
+    {1, arcs_14_4},\r
+    {2, arcs_14_5},\r
+};\r
+static arc arcs_15_0[12] = {\r
+    {46, 1},\r
+    {47, 1},\r
+    {48, 1},\r
+    {49, 1},\r
+    {50, 1},\r
+    {51, 1},\r
+    {52, 1},\r
+    {53, 1},\r
+    {54, 1},\r
+    {55, 1},\r
+    {56, 1},\r
+    {57, 1},\r
+};\r
+static arc arcs_15_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_15[2] = {\r
+    {12, arcs_15_0},\r
+    {1, arcs_15_1},\r
+};\r
+static arc arcs_16_0[1] = {\r
+    {58, 1},\r
+};\r
+static arc arcs_16_1[3] = {\r
+    {28, 2},\r
+    {59, 3},\r
+    {0, 1},\r
+};\r
+static arc arcs_16_2[2] = {\r
+    {29, 4},\r
+    {0, 2},\r
+};\r
+static arc arcs_16_3[1] = {\r
+    {28, 5},\r
+};\r
+static arc arcs_16_4[2] = {\r
+    {28, 2},\r
+    {0, 4},\r
+};\r
+static arc arcs_16_5[2] = {\r
+    {29, 6},\r
+    {0, 5},\r
+};\r
+static arc arcs_16_6[1] = {\r
+    {28, 7},\r
+};\r
+static arc arcs_16_7[2] = {\r
+    {29, 8},\r
+    {0, 7},\r
+};\r
+static arc arcs_16_8[2] = {\r
+    {28, 7},\r
+    {0, 8},\r
+};\r
+static state states_16[9] = {\r
+    {1, arcs_16_0},\r
+    {3, arcs_16_1},\r
+    {2, arcs_16_2},\r
+    {1, arcs_16_3},\r
+    {2, arcs_16_4},\r
+    {2, arcs_16_5},\r
+    {1, arcs_16_6},\r
+    {2, arcs_16_7},\r
+    {2, arcs_16_8},\r
+};\r
+static arc arcs_17_0[1] = {\r
+    {60, 1},\r
+};\r
+static arc arcs_17_1[1] = {\r
+    {61, 2},\r
+};\r
+static arc arcs_17_2[1] = {\r
+    {0, 2},\r
+};\r
+static state states_17[3] = {\r
+    {1, arcs_17_0},\r
+    {1, arcs_17_1},\r
+    {1, arcs_17_2},\r
+};\r
+static arc arcs_18_0[1] = {\r
+    {62, 1},\r
+};\r
+static arc arcs_18_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_18[2] = {\r
+    {1, arcs_18_0},\r
+    {1, arcs_18_1},\r
+};\r
+static arc arcs_19_0[5] = {\r
+    {63, 1},\r
+    {64, 1},\r
+    {65, 1},\r
+    {66, 1},\r
+    {67, 1},\r
+};\r
+static arc arcs_19_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_19[2] = {\r
+    {5, arcs_19_0},\r
+    {1, arcs_19_1},\r
+};\r
+static arc arcs_20_0[1] = {\r
+    {68, 1},\r
+};\r
+static arc arcs_20_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_20[2] = {\r
+    {1, arcs_20_0},\r
+    {1, arcs_20_1},\r
+};\r
+static arc arcs_21_0[1] = {\r
+    {69, 1},\r
+};\r
+static arc arcs_21_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_21[2] = {\r
+    {1, arcs_21_0},\r
+    {1, arcs_21_1},\r
+};\r
+static arc arcs_22_0[1] = {\r
+    {70, 1},\r
+};\r
+static arc arcs_22_1[2] = {\r
+    {9, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_22_2[1] = {\r
+    {0, 2},\r
+};\r
+static state states_22[3] = {\r
+    {1, arcs_22_0},\r
+    {2, arcs_22_1},\r
+    {1, arcs_22_2},\r
+};\r
+static arc arcs_23_0[1] = {\r
+    {45, 1},\r
+};\r
+static arc arcs_23_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_23[2] = {\r
+    {1, arcs_23_0},\r
+    {1, arcs_23_1},\r
+};\r
+static arc arcs_24_0[1] = {\r
+    {71, 1},\r
+};\r
+static arc arcs_24_1[2] = {\r
+    {28, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_24_2[2] = {\r
+    {29, 3},\r
+    {0, 2},\r
+};\r
+static arc arcs_24_3[1] = {\r
+    {28, 4},\r
+};\r
+static arc arcs_24_4[2] = {\r
+    {29, 5},\r
+    {0, 4},\r
+};\r
+static arc arcs_24_5[1] = {\r
+    {28, 6},\r
+};\r
+static arc arcs_24_6[1] = {\r
+    {0, 6},\r
+};\r
+static state states_24[7] = {\r
+    {1, arcs_24_0},\r
+    {2, arcs_24_1},\r
+    {2, arcs_24_2},\r
+    {1, arcs_24_3},\r
+    {2, arcs_24_4},\r
+    {1, arcs_24_5},\r
+    {1, arcs_24_6},\r
+};\r
+static arc arcs_25_0[2] = {\r
+    {72, 1},\r
+    {73, 1},\r
+};\r
+static arc arcs_25_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_25[2] = {\r
+    {2, arcs_25_0},\r
+    {1, arcs_25_1},\r
+};\r
+static arc arcs_26_0[1] = {\r
+    {74, 1},\r
+};\r
+static arc arcs_26_1[1] = {\r
+    {75, 2},\r
+};\r
+static arc arcs_26_2[1] = {\r
+    {0, 2},\r
+};\r
+static state states_26[3] = {\r
+    {1, arcs_26_0},\r
+    {1, arcs_26_1},\r
+    {1, arcs_26_2},\r
+};\r
+static arc arcs_27_0[1] = {\r
+    {76, 1},\r
+};\r
+static arc arcs_27_1[2] = {\r
+    {77, 2},\r
+    {12, 3},\r
+};\r
+static arc arcs_27_2[3] = {\r
+    {77, 2},\r
+    {12, 3},\r
+    {74, 4},\r
+};\r
+static arc arcs_27_3[1] = {\r
+    {74, 4},\r
+};\r
+static arc arcs_27_4[3] = {\r
+    {30, 5},\r
+    {13, 6},\r
+    {78, 5},\r
+};\r
+static arc arcs_27_5[1] = {\r
+    {0, 5},\r
+};\r
+static arc arcs_27_6[1] = {\r
+    {78, 7},\r
+};\r
+static arc arcs_27_7[1] = {\r
+    {15, 5},\r
+};\r
+static state states_27[8] = {\r
+    {1, arcs_27_0},\r
+    {2, arcs_27_1},\r
+    {3, arcs_27_2},\r
+    {1, arcs_27_3},\r
+    {3, arcs_27_4},\r
+    {1, arcs_27_5},\r
+    {1, arcs_27_6},\r
+    {1, arcs_27_7},\r
+};\r
+static arc arcs_28_0[1] = {\r
+    {21, 1},\r
+};\r
+static arc arcs_28_1[2] = {\r
+    {80, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_28_2[1] = {\r
+    {21, 3},\r
+};\r
+static arc arcs_28_3[1] = {\r
+    {0, 3},\r
+};\r
+static state states_28[4] = {\r
+    {1, arcs_28_0},\r
+    {2, arcs_28_1},\r
+    {1, arcs_28_2},\r
+    {1, arcs_28_3},\r
+};\r
+static arc arcs_29_0[1] = {\r
+    {12, 1},\r
+};\r
+static arc arcs_29_1[2] = {\r
+    {80, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_29_2[1] = {\r
+    {21, 3},\r
+};\r
+static arc arcs_29_3[1] = {\r
+    {0, 3},\r
+};\r
+static state states_29[4] = {\r
+    {1, arcs_29_0},\r
+    {2, arcs_29_1},\r
+    {1, arcs_29_2},\r
+    {1, arcs_29_3},\r
+};\r
+static arc arcs_30_0[1] = {\r
+    {79, 1},\r
+};\r
+static arc arcs_30_1[2] = {\r
+    {29, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_30_2[2] = {\r
+    {79, 1},\r
+    {0, 2},\r
+};\r
+static state states_30[3] = {\r
+    {1, arcs_30_0},\r
+    {2, arcs_30_1},\r
+    {2, arcs_30_2},\r
+};\r
+static arc arcs_31_0[1] = {\r
+    {81, 1},\r
+};\r
+static arc arcs_31_1[2] = {\r
+    {29, 0},\r
+    {0, 1},\r
+};\r
+static state states_31[2] = {\r
+    {1, arcs_31_0},\r
+    {2, arcs_31_1},\r
+};\r
+static arc arcs_32_0[1] = {\r
+    {21, 1},\r
+};\r
+static arc arcs_32_1[2] = {\r
+    {77, 0},\r
+    {0, 1},\r
+};\r
+static state states_32[2] = {\r
+    {1, arcs_32_0},\r
+    {2, arcs_32_1},\r
+};\r
+static arc arcs_33_0[1] = {\r
+    {82, 1},\r
+};\r
+static arc arcs_33_1[1] = {\r
+    {21, 2},\r
+};\r
+static arc arcs_33_2[2] = {\r
+    {29, 1},\r
+    {0, 2},\r
+};\r
+static state states_33[3] = {\r
+    {1, arcs_33_0},\r
+    {1, arcs_33_1},\r
+    {2, arcs_33_2},\r
+};\r
+static arc arcs_34_0[1] = {\r
+    {83, 1},\r
+};\r
+static arc arcs_34_1[1] = {\r
+    {84, 2},\r
+};\r
+static arc arcs_34_2[2] = {\r
+    {85, 3},\r
+    {0, 2},\r
+};\r
+static arc arcs_34_3[1] = {\r
+    {28, 4},\r
+};\r
+static arc arcs_34_4[2] = {\r
+    {29, 5},\r
+    {0, 4},\r
+};\r
+static arc arcs_34_5[1] = {\r
+    {28, 6},\r
+};\r
+static arc arcs_34_6[1] = {\r
+    {0, 6},\r
+};\r
+static state states_34[7] = {\r
+    {1, arcs_34_0},\r
+    {1, arcs_34_1},\r
+    {2, arcs_34_2},\r
+    {1, arcs_34_3},\r
+    {2, arcs_34_4},\r
+    {1, arcs_34_5},\r
+    {1, arcs_34_6},\r
+};\r
+static arc arcs_35_0[1] = {\r
+    {86, 1},\r
+};\r
+static arc arcs_35_1[1] = {\r
+    {28, 2},\r
+};\r
+static arc arcs_35_2[2] = {\r
+    {29, 3},\r
+    {0, 2},\r
+};\r
+static arc arcs_35_3[1] = {\r
+    {28, 4},\r
+};\r
+static arc arcs_35_4[1] = {\r
+    {0, 4},\r
+};\r
+static state states_35[5] = {\r
+    {1, arcs_35_0},\r
+    {1, arcs_35_1},\r
+    {2, arcs_35_2},\r
+    {1, arcs_35_3},\r
+    {1, arcs_35_4},\r
+};\r
+static arc arcs_36_0[8] = {\r
+    {87, 1},\r
+    {88, 1},\r
+    {89, 1},\r
+    {90, 1},\r
+    {91, 1},\r
+    {19, 1},\r
+    {18, 1},\r
+    {17, 1},\r
+};\r
+static arc arcs_36_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_36[2] = {\r
+    {8, arcs_36_0},\r
+    {1, arcs_36_1},\r
+};\r
+static arc arcs_37_0[1] = {\r
+    {92, 1},\r
+};\r
+static arc arcs_37_1[1] = {\r
+    {28, 2},\r
+};\r
+static arc arcs_37_2[1] = {\r
+    {23, 3},\r
+};\r
+static arc arcs_37_3[1] = {\r
+    {24, 4},\r
+};\r
+static arc arcs_37_4[3] = {\r
+    {93, 1},\r
+    {94, 5},\r
+    {0, 4},\r
+};\r
+static arc arcs_37_5[1] = {\r
+    {23, 6},\r
+};\r
+static arc arcs_37_6[1] = {\r
+    {24, 7},\r
+};\r
+static arc arcs_37_7[1] = {\r
+    {0, 7},\r
+};\r
+static state states_37[8] = {\r
+    {1, arcs_37_0},\r
+    {1, arcs_37_1},\r
+    {1, arcs_37_2},\r
+    {1, arcs_37_3},\r
+    {3, arcs_37_4},\r
+    {1, arcs_37_5},\r
+    {1, arcs_37_6},\r
+    {1, arcs_37_7},\r
+};\r
+static arc arcs_38_0[1] = {\r
+    {95, 1},\r
+};\r
+static arc arcs_38_1[1] = {\r
+    {28, 2},\r
+};\r
+static arc arcs_38_2[1] = {\r
+    {23, 3},\r
+};\r
+static arc arcs_38_3[1] = {\r
+    {24, 4},\r
+};\r
+static arc arcs_38_4[2] = {\r
+    {94, 5},\r
+    {0, 4},\r
+};\r
+static arc arcs_38_5[1] = {\r
+    {23, 6},\r
+};\r
+static arc arcs_38_6[1] = {\r
+    {24, 7},\r
+};\r
+static arc arcs_38_7[1] = {\r
+    {0, 7},\r
+};\r
+static state states_38[8] = {\r
+    {1, arcs_38_0},\r
+    {1, arcs_38_1},\r
+    {1, arcs_38_2},\r
+    {1, arcs_38_3},\r
+    {2, arcs_38_4},\r
+    {1, arcs_38_5},\r
+    {1, arcs_38_6},\r
+    {1, arcs_38_7},\r
+};\r
+static arc arcs_39_0[1] = {\r
+    {96, 1},\r
+};\r
+static arc arcs_39_1[1] = {\r
+    {61, 2},\r
+};\r
+static arc arcs_39_2[1] = {\r
+    {85, 3},\r
+};\r
+static arc arcs_39_3[1] = {\r
+    {9, 4},\r
+};\r
+static arc arcs_39_4[1] = {\r
+    {23, 5},\r
+};\r
+static arc arcs_39_5[1] = {\r
+    {24, 6},\r
+};\r
+static arc arcs_39_6[2] = {\r
+    {94, 7},\r
+    {0, 6},\r
+};\r
+static arc arcs_39_7[1] = {\r
+    {23, 8},\r
+};\r
+static arc arcs_39_8[1] = {\r
+    {24, 9},\r
+};\r
+static arc arcs_39_9[1] = {\r
+    {0, 9},\r
+};\r
+static state states_39[10] = {\r
+    {1, arcs_39_0},\r
+    {1, arcs_39_1},\r
+    {1, arcs_39_2},\r
+    {1, arcs_39_3},\r
+    {1, arcs_39_4},\r
+    {1, arcs_39_5},\r
+    {2, arcs_39_6},\r
+    {1, arcs_39_7},\r
+    {1, arcs_39_8},\r
+    {1, arcs_39_9},\r
+};\r
+static arc arcs_40_0[1] = {\r
+    {97, 1},\r
+};\r
+static arc arcs_40_1[1] = {\r
+    {23, 2},\r
+};\r
+static arc arcs_40_2[1] = {\r
+    {24, 3},\r
+};\r
+static arc arcs_40_3[2] = {\r
+    {98, 4},\r
+    {99, 5},\r
+};\r
+static arc arcs_40_4[1] = {\r
+    {23, 6},\r
+};\r
+static arc arcs_40_5[1] = {\r
+    {23, 7},\r
+};\r
+static arc arcs_40_6[1] = {\r
+    {24, 8},\r
+};\r
+static arc arcs_40_7[1] = {\r
+    {24, 9},\r
+};\r
+static arc arcs_40_8[4] = {\r
+    {98, 4},\r
+    {94, 10},\r
+    {99, 5},\r
+    {0, 8},\r
+};\r
+static arc arcs_40_9[1] = {\r
+    {0, 9},\r
+};\r
+static arc arcs_40_10[1] = {\r
+    {23, 11},\r
+};\r
+static arc arcs_40_11[1] = {\r
+    {24, 12},\r
+};\r
+static arc arcs_40_12[2] = {\r
+    {99, 5},\r
+    {0, 12},\r
+};\r
+static state states_40[13] = {\r
+    {1, arcs_40_0},\r
+    {1, arcs_40_1},\r
+    {1, arcs_40_2},\r
+    {2, arcs_40_3},\r
+    {1, arcs_40_4},\r
+    {1, arcs_40_5},\r
+    {1, arcs_40_6},\r
+    {1, arcs_40_7},\r
+    {4, arcs_40_8},\r
+    {1, arcs_40_9},\r
+    {1, arcs_40_10},\r
+    {1, arcs_40_11},\r
+    {2, arcs_40_12},\r
+};\r
+static arc arcs_41_0[1] = {\r
+    {100, 1},\r
+};\r
+static arc arcs_41_1[1] = {\r
+    {101, 2},\r
+};\r
+static arc arcs_41_2[2] = {\r
+    {29, 1},\r
+    {23, 3},\r
+};\r
+static arc arcs_41_3[1] = {\r
+    {24, 4},\r
+};\r
+static arc arcs_41_4[1] = {\r
+    {0, 4},\r
+};\r
+static state states_41[5] = {\r
+    {1, arcs_41_0},\r
+    {1, arcs_41_1},\r
+    {2, arcs_41_2},\r
+    {1, arcs_41_3},\r
+    {1, arcs_41_4},\r
+};\r
+static arc arcs_42_0[1] = {\r
+    {28, 1},\r
+};\r
+static arc arcs_42_1[2] = {\r
+    {80, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_42_2[1] = {\r
+    {84, 3},\r
+};\r
+static arc arcs_42_3[1] = {\r
+    {0, 3},\r
+};\r
+static state states_42[4] = {\r
+    {1, arcs_42_0},\r
+    {2, arcs_42_1},\r
+    {1, arcs_42_2},\r
+    {1, arcs_42_3},\r
+};\r
+static arc arcs_43_0[1] = {\r
+    {102, 1},\r
+};\r
+static arc arcs_43_1[2] = {\r
+    {28, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_43_2[3] = {\r
+    {80, 3},\r
+    {29, 3},\r
+    {0, 2},\r
+};\r
+static arc arcs_43_3[1] = {\r
+    {28, 4},\r
+};\r
+static arc arcs_43_4[1] = {\r
+    {0, 4},\r
+};\r
+static state states_43[5] = {\r
+    {1, arcs_43_0},\r
+    {2, arcs_43_1},\r
+    {3, arcs_43_2},\r
+    {1, arcs_43_3},\r
+    {1, arcs_43_4},\r
+};\r
+static arc arcs_44_0[2] = {\r
+    {3, 1},\r
+    {2, 2},\r
+};\r
+static arc arcs_44_1[1] = {\r
+    {0, 1},\r
+};\r
+static arc arcs_44_2[1] = {\r
+    {103, 3},\r
+};\r
+static arc arcs_44_3[1] = {\r
+    {6, 4},\r
+};\r
+static arc arcs_44_4[2] = {\r
+    {6, 4},\r
+    {104, 1},\r
+};\r
+static state states_44[5] = {\r
+    {2, arcs_44_0},\r
+    {1, arcs_44_1},\r
+    {1, arcs_44_2},\r
+    {1, arcs_44_3},\r
+    {2, arcs_44_4},\r
+};\r
+static arc arcs_45_0[1] = {\r
+    {106, 1},\r
+};\r
+static arc arcs_45_1[2] = {\r
+    {29, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_45_2[1] = {\r
+    {106, 3},\r
+};\r
+static arc arcs_45_3[2] = {\r
+    {29, 4},\r
+    {0, 3},\r
+};\r
+static arc arcs_45_4[2] = {\r
+    {106, 3},\r
+    {0, 4},\r
+};\r
+static state states_45[5] = {\r
+    {1, arcs_45_0},\r
+    {2, arcs_45_1},\r
+    {1, arcs_45_2},\r
+    {2, arcs_45_3},\r
+    {2, arcs_45_4},\r
+};\r
+static arc arcs_46_0[2] = {\r
+    {107, 1},\r
+    {108, 1},\r
+};\r
+static arc arcs_46_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_46[2] = {\r
+    {2, arcs_46_0},\r
+    {1, arcs_46_1},\r
+};\r
+static arc arcs_47_0[1] = {\r
+    {109, 1},\r
+};\r
+static arc arcs_47_1[2] = {\r
+    {25, 2},\r
+    {23, 3},\r
+};\r
+static arc arcs_47_2[1] = {\r
+    {23, 3},\r
+};\r
+static arc arcs_47_3[1] = {\r
+    {106, 4},\r
+};\r
+static arc arcs_47_4[1] = {\r
+    {0, 4},\r
+};\r
+static state states_47[5] = {\r
+    {1, arcs_47_0},\r
+    {2, arcs_47_1},\r
+    {1, arcs_47_2},\r
+    {1, arcs_47_3},\r
+    {1, arcs_47_4},\r
+};\r
+static arc arcs_48_0[2] = {\r
+    {107, 1},\r
+    {110, 2},\r
+};\r
+static arc arcs_48_1[2] = {\r
+    {92, 3},\r
+    {0, 1},\r
+};\r
+static arc arcs_48_2[1] = {\r
+    {0, 2},\r
+};\r
+static arc arcs_48_3[1] = {\r
+    {107, 4},\r
+};\r
+static arc arcs_48_4[1] = {\r
+    {94, 5},\r
+};\r
+static arc arcs_48_5[1] = {\r
+    {28, 2},\r
+};\r
+static state states_48[6] = {\r
+    {2, arcs_48_0},\r
+    {2, arcs_48_1},\r
+    {1, arcs_48_2},\r
+    {1, arcs_48_3},\r
+    {1, arcs_48_4},\r
+    {1, arcs_48_5},\r
+};\r
+static arc arcs_49_0[1] = {\r
+    {111, 1},\r
+};\r
+static arc arcs_49_1[2] = {\r
+    {112, 0},\r
+    {0, 1},\r
+};\r
+static state states_49[2] = {\r
+    {1, arcs_49_0},\r
+    {2, arcs_49_1},\r
+};\r
+static arc arcs_50_0[1] = {\r
+    {113, 1},\r
+};\r
+static arc arcs_50_1[2] = {\r
+    {114, 0},\r
+    {0, 1},\r
+};\r
+static state states_50[2] = {\r
+    {1, arcs_50_0},\r
+    {2, arcs_50_1},\r
+};\r
+static arc arcs_51_0[2] = {\r
+    {115, 1},\r
+    {116, 2},\r
+};\r
+static arc arcs_51_1[1] = {\r
+    {113, 2},\r
+};\r
+static arc arcs_51_2[1] = {\r
+    {0, 2},\r
+};\r
+static state states_51[3] = {\r
+    {2, arcs_51_0},\r
+    {1, arcs_51_1},\r
+    {1, arcs_51_2},\r
+};\r
+static arc arcs_52_0[1] = {\r
+    {84, 1},\r
+};\r
+static arc arcs_52_1[2] = {\r
+    {117, 0},\r
+    {0, 1},\r
+};\r
+static state states_52[2] = {\r
+    {1, arcs_52_0},\r
+    {2, arcs_52_1},\r
+};\r
+static arc arcs_53_0[10] = {\r
+    {118, 1},\r
+    {119, 1},\r
+    {120, 1},\r
+    {121, 1},\r
+    {122, 1},\r
+    {123, 1},\r
+    {124, 1},\r
+    {85, 1},\r
+    {115, 2},\r
+    {125, 3},\r
+};\r
+static arc arcs_53_1[1] = {\r
+    {0, 1},\r
+};\r
+static arc arcs_53_2[1] = {\r
+    {85, 1},\r
+};\r
+static arc arcs_53_3[2] = {\r
+    {115, 1},\r
+    {0, 3},\r
+};\r
+static state states_53[4] = {\r
+    {10, arcs_53_0},\r
+    {1, arcs_53_1},\r
+    {1, arcs_53_2},\r
+    {2, arcs_53_3},\r
+};\r
+static arc arcs_54_0[1] = {\r
+    {126, 1},\r
+};\r
+static arc arcs_54_1[2] = {\r
+    {127, 0},\r
+    {0, 1},\r
+};\r
+static state states_54[2] = {\r
+    {1, arcs_54_0},\r
+    {2, arcs_54_1},\r
+};\r
+static arc arcs_55_0[1] = {\r
+    {128, 1},\r
+};\r
+static arc arcs_55_1[2] = {\r
+    {129, 0},\r
+    {0, 1},\r
+};\r
+static state states_55[2] = {\r
+    {1, arcs_55_0},\r
+    {2, arcs_55_1},\r
+};\r
+static arc arcs_56_0[1] = {\r
+    {130, 1},\r
+};\r
+static arc arcs_56_1[2] = {\r
+    {131, 0},\r
+    {0, 1},\r
+};\r
+static state states_56[2] = {\r
+    {1, arcs_56_0},\r
+    {2, arcs_56_1},\r
+};\r
+static arc arcs_57_0[1] = {\r
+    {132, 1},\r
+};\r
+static arc arcs_57_1[3] = {\r
+    {133, 0},\r
+    {59, 0},\r
+    {0, 1},\r
+};\r
+static state states_57[2] = {\r
+    {1, arcs_57_0},\r
+    {3, arcs_57_1},\r
+};\r
+static arc arcs_58_0[1] = {\r
+    {134, 1},\r
+};\r
+static arc arcs_58_1[3] = {\r
+    {135, 0},\r
+    {136, 0},\r
+    {0, 1},\r
+};\r
+static state states_58[2] = {\r
+    {1, arcs_58_0},\r
+    {3, arcs_58_1},\r
+};\r
+static arc arcs_59_0[1] = {\r
+    {137, 1},\r
+};\r
+static arc arcs_59_1[5] = {\r
+    {30, 0},\r
+    {138, 0},\r
+    {139, 0},\r
+    {140, 0},\r
+    {0, 1},\r
+};\r
+static state states_59[2] = {\r
+    {1, arcs_59_0},\r
+    {5, arcs_59_1},\r
+};\r
+static arc arcs_60_0[4] = {\r
+    {135, 1},\r
+    {136, 1},\r
+    {141, 1},\r
+    {142, 2},\r
+};\r
+static arc arcs_60_1[1] = {\r
+    {137, 2},\r
+};\r
+static arc arcs_60_2[1] = {\r
+    {0, 2},\r
+};\r
+static state states_60[3] = {\r
+    {4, arcs_60_0},\r
+    {1, arcs_60_1},\r
+    {1, arcs_60_2},\r
+};\r
+static arc arcs_61_0[1] = {\r
+    {143, 1},\r
+};\r
+static arc arcs_61_1[3] = {\r
+    {144, 1},\r
+    {31, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_61_2[1] = {\r
+    {137, 3},\r
+};\r
+static arc arcs_61_3[1] = {\r
+    {0, 3},\r
+};\r
+static state states_61[4] = {\r
+    {1, arcs_61_0},\r
+    {3, arcs_61_1},\r
+    {1, arcs_61_2},\r
+    {1, arcs_61_3},\r
+};\r
+static arc arcs_62_0[7] = {\r
+    {13, 1},\r
+    {146, 2},\r
+    {149, 3},\r
+    {152, 4},\r
+    {21, 5},\r
+    {154, 5},\r
+    {155, 6},\r
+};\r
+static arc arcs_62_1[3] = {\r
+    {45, 7},\r
+    {145, 7},\r
+    {15, 5},\r
+};\r
+static arc arcs_62_2[2] = {\r
+    {147, 8},\r
+    {148, 5},\r
+};\r
+static arc arcs_62_3[2] = {\r
+    {150, 9},\r
+    {151, 5},\r
+};\r
+static arc arcs_62_4[1] = {\r
+    {153, 10},\r
+};\r
+static arc arcs_62_5[1] = {\r
+    {0, 5},\r
+};\r
+static arc arcs_62_6[2] = {\r
+    {155, 6},\r
+    {0, 6},\r
+};\r
+static arc arcs_62_7[1] = {\r
+    {15, 5},\r
+};\r
+static arc arcs_62_8[1] = {\r
+    {148, 5},\r
+};\r
+static arc arcs_62_9[1] = {\r
+    {151, 5},\r
+};\r
+static arc arcs_62_10[1] = {\r
+    {152, 5},\r
+};\r
+static state states_62[11] = {\r
+    {7, arcs_62_0},\r
+    {3, arcs_62_1},\r
+    {2, arcs_62_2},\r
+    {2, arcs_62_3},\r
+    {1, arcs_62_4},\r
+    {1, arcs_62_5},\r
+    {2, arcs_62_6},\r
+    {1, arcs_62_7},\r
+    {1, arcs_62_8},\r
+    {1, arcs_62_9},\r
+    {1, arcs_62_10},\r
+};\r
+static arc arcs_63_0[1] = {\r
+    {28, 1},\r
+};\r
+static arc arcs_63_1[3] = {\r
+    {156, 2},\r
+    {29, 3},\r
+    {0, 1},\r
+};\r
+static arc arcs_63_2[1] = {\r
+    {0, 2},\r
+};\r
+static arc arcs_63_3[2] = {\r
+    {28, 4},\r
+    {0, 3},\r
+};\r
+static arc arcs_63_4[2] = {\r
+    {29, 3},\r
+    {0, 4},\r
+};\r
+static state states_63[5] = {\r
+    {1, arcs_63_0},\r
+    {3, arcs_63_1},\r
+    {1, arcs_63_2},\r
+    {2, arcs_63_3},\r
+    {2, arcs_63_4},\r
+};\r
+static arc arcs_64_0[1] = {\r
+    {28, 1},\r
+};\r
+static arc arcs_64_1[3] = {\r
+    {157, 2},\r
+    {29, 3},\r
+    {0, 1},\r
+};\r
+static arc arcs_64_2[1] = {\r
+    {0, 2},\r
+};\r
+static arc arcs_64_3[2] = {\r
+    {28, 4},\r
+    {0, 3},\r
+};\r
+static arc arcs_64_4[2] = {\r
+    {29, 3},\r
+    {0, 4},\r
+};\r
+static state states_64[5] = {\r
+    {1, arcs_64_0},\r
+    {3, arcs_64_1},\r
+    {1, arcs_64_2},\r
+    {2, arcs_64_3},\r
+    {2, arcs_64_4},\r
+};\r
+static arc arcs_65_0[1] = {\r
+    {109, 1},\r
+};\r
+static arc arcs_65_1[2] = {\r
+    {25, 2},\r
+    {23, 3},\r
+};\r
+static arc arcs_65_2[1] = {\r
+    {23, 3},\r
+};\r
+static arc arcs_65_3[1] = {\r
+    {28, 4},\r
+};\r
+static arc arcs_65_4[1] = {\r
+    {0, 4},\r
+};\r
+static state states_65[5] = {\r
+    {1, arcs_65_0},\r
+    {2, arcs_65_1},\r
+    {1, arcs_65_2},\r
+    {1, arcs_65_3},\r
+    {1, arcs_65_4},\r
+};\r
+static arc arcs_66_0[3] = {\r
+    {13, 1},\r
+    {146, 2},\r
+    {77, 3},\r
+};\r
+static arc arcs_66_1[2] = {\r
+    {14, 4},\r
+    {15, 5},\r
+};\r
+static arc arcs_66_2[1] = {\r
+    {158, 6},\r
+};\r
+static arc arcs_66_3[1] = {\r
+    {21, 5},\r
+};\r
+static arc arcs_66_4[1] = {\r
+    {15, 5},\r
+};\r
+static arc arcs_66_5[1] = {\r
+    {0, 5},\r
+};\r
+static arc arcs_66_6[1] = {\r
+    {148, 5},\r
+};\r
+static state states_66[7] = {\r
+    {3, arcs_66_0},\r
+    {2, arcs_66_1},\r
+    {1, arcs_66_2},\r
+    {1, arcs_66_3},\r
+    {1, arcs_66_4},\r
+    {1, arcs_66_5},\r
+    {1, arcs_66_6},\r
+};\r
+static arc arcs_67_0[1] = {\r
+    {159, 1},\r
+};\r
+static arc arcs_67_1[2] = {\r
+    {29, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_67_2[2] = {\r
+    {159, 1},\r
+    {0, 2},\r
+};\r
+static state states_67[3] = {\r
+    {1, arcs_67_0},\r
+    {2, arcs_67_1},\r
+    {2, arcs_67_2},\r
+};\r
+static arc arcs_68_0[3] = {\r
+    {77, 1},\r
+    {28, 2},\r
+    {23, 3},\r
+};\r
+static arc arcs_68_1[1] = {\r
+    {77, 4},\r
+};\r
+static arc arcs_68_2[2] = {\r
+    {23, 3},\r
+    {0, 2},\r
+};\r
+static arc arcs_68_3[3] = {\r
+    {28, 5},\r
+    {160, 6},\r
+    {0, 3},\r
+};\r
+static arc arcs_68_4[1] = {\r
+    {77, 6},\r
+};\r
+static arc arcs_68_5[2] = {\r
+    {160, 6},\r
+    {0, 5},\r
+};\r
+static arc arcs_68_6[1] = {\r
+    {0, 6},\r
+};\r
+static state states_68[7] = {\r
+    {3, arcs_68_0},\r
+    {1, arcs_68_1},\r
+    {2, arcs_68_2},\r
+    {3, arcs_68_3},\r
+    {1, arcs_68_4},\r
+    {2, arcs_68_5},\r
+    {1, arcs_68_6},\r
+};\r
+static arc arcs_69_0[1] = {\r
+    {23, 1},\r
+};\r
+static arc arcs_69_1[2] = {\r
+    {28, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_69_2[1] = {\r
+    {0, 2},\r
+};\r
+static state states_69[3] = {\r
+    {1, arcs_69_0},\r
+    {2, arcs_69_1},\r
+    {1, arcs_69_2},\r
+};\r
+static arc arcs_70_0[1] = {\r
+    {84, 1},\r
+};\r
+static arc arcs_70_1[2] = {\r
+    {29, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_70_2[2] = {\r
+    {84, 1},\r
+    {0, 2},\r
+};\r
+static state states_70[3] = {\r
+    {1, arcs_70_0},\r
+    {2, arcs_70_1},\r
+    {2, arcs_70_2},\r
+};\r
+static arc arcs_71_0[1] = {\r
+    {28, 1},\r
+};\r
+static arc arcs_71_1[2] = {\r
+    {29, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_71_2[2] = {\r
+    {28, 1},\r
+    {0, 2},\r
+};\r
+static state states_71[3] = {\r
+    {1, arcs_71_0},\r
+    {2, arcs_71_1},\r
+    {2, arcs_71_2},\r
+};\r
+static arc arcs_72_0[1] = {\r
+    {28, 1},\r
+};\r
+static arc arcs_72_1[4] = {\r
+    {23, 2},\r
+    {157, 3},\r
+    {29, 4},\r
+    {0, 1},\r
+};\r
+static arc arcs_72_2[1] = {\r
+    {28, 5},\r
+};\r
+static arc arcs_72_3[1] = {\r
+    {0, 3},\r
+};\r
+static arc arcs_72_4[2] = {\r
+    {28, 6},\r
+    {0, 4},\r
+};\r
+static arc arcs_72_5[3] = {\r
+    {157, 3},\r
+    {29, 7},\r
+    {0, 5},\r
+};\r
+static arc arcs_72_6[2] = {\r
+    {29, 4},\r
+    {0, 6},\r
+};\r
+static arc arcs_72_7[2] = {\r
+    {28, 8},\r
+    {0, 7},\r
+};\r
+static arc arcs_72_8[1] = {\r
+    {23, 9},\r
+};\r
+static arc arcs_72_9[1] = {\r
+    {28, 10},\r
+};\r
+static arc arcs_72_10[2] = {\r
+    {29, 7},\r
+    {0, 10},\r
+};\r
+static state states_72[11] = {\r
+    {1, arcs_72_0},\r
+    {4, arcs_72_1},\r
+    {1, arcs_72_2},\r
+    {1, arcs_72_3},\r
+    {2, arcs_72_4},\r
+    {3, arcs_72_5},\r
+    {2, arcs_72_6},\r
+    {2, arcs_72_7},\r
+    {1, arcs_72_8},\r
+    {1, arcs_72_9},\r
+    {2, arcs_72_10},\r
+};\r
+static arc arcs_73_0[1] = {\r
+    {161, 1},\r
+};\r
+static arc arcs_73_1[1] = {\r
+    {21, 2},\r
+};\r
+static arc arcs_73_2[2] = {\r
+    {13, 3},\r
+    {23, 4},\r
+};\r
+static arc arcs_73_3[2] = {\r
+    {9, 5},\r
+    {15, 6},\r
+};\r
+static arc arcs_73_4[1] = {\r
+    {24, 7},\r
+};\r
+static arc arcs_73_5[1] = {\r
+    {15, 6},\r
+};\r
+static arc arcs_73_6[1] = {\r
+    {23, 4},\r
+};\r
+static arc arcs_73_7[1] = {\r
+    {0, 7},\r
+};\r
+static state states_73[8] = {\r
+    {1, arcs_73_0},\r
+    {1, arcs_73_1},\r
+    {2, arcs_73_2},\r
+    {2, arcs_73_3},\r
+    {1, arcs_73_4},\r
+    {1, arcs_73_5},\r
+    {1, arcs_73_6},\r
+    {1, arcs_73_7},\r
+};\r
+static arc arcs_74_0[3] = {\r
+    {162, 1},\r
+    {30, 2},\r
+    {31, 3},\r
+};\r
+static arc arcs_74_1[2] = {\r
+    {29, 4},\r
+    {0, 1},\r
+};\r
+static arc arcs_74_2[1] = {\r
+    {28, 5},\r
+};\r
+static arc arcs_74_3[1] = {\r
+    {28, 6},\r
+};\r
+static arc arcs_74_4[4] = {\r
+    {162, 1},\r
+    {30, 2},\r
+    {31, 3},\r
+    {0, 4},\r
+};\r
+static arc arcs_74_5[2] = {\r
+    {29, 7},\r
+    {0, 5},\r
+};\r
+static arc arcs_74_6[1] = {\r
+    {0, 6},\r
+};\r
+static arc arcs_74_7[2] = {\r
+    {162, 5},\r
+    {31, 3},\r
+};\r
+static state states_74[8] = {\r
+    {3, arcs_74_0},\r
+    {2, arcs_74_1},\r
+    {1, arcs_74_2},\r
+    {1, arcs_74_3},\r
+    {4, arcs_74_4},\r
+    {2, arcs_74_5},\r
+    {1, arcs_74_6},\r
+    {2, arcs_74_7},\r
+};\r
+static arc arcs_75_0[1] = {\r
+    {28, 1},\r
+};\r
+static arc arcs_75_1[3] = {\r
+    {157, 2},\r
+    {27, 3},\r
+    {0, 1},\r
+};\r
+static arc arcs_75_2[1] = {\r
+    {0, 2},\r
+};\r
+static arc arcs_75_3[1] = {\r
+    {28, 2},\r
+};\r
+static state states_75[4] = {\r
+    {1, arcs_75_0},\r
+    {3, arcs_75_1},\r
+    {1, arcs_75_2},\r
+    {1, arcs_75_3},\r
+};\r
+static arc arcs_76_0[2] = {\r
+    {156, 1},\r
+    {164, 1},\r
+};\r
+static arc arcs_76_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_76[2] = {\r
+    {2, arcs_76_0},\r
+    {1, arcs_76_1},\r
+};\r
+static arc arcs_77_0[1] = {\r
+    {96, 1},\r
+};\r
+static arc arcs_77_1[1] = {\r
+    {61, 2},\r
+};\r
+static arc arcs_77_2[1] = {\r
+    {85, 3},\r
+};\r
+static arc arcs_77_3[1] = {\r
+    {105, 4},\r
+};\r
+static arc arcs_77_4[2] = {\r
+    {163, 5},\r
+    {0, 4},\r
+};\r
+static arc arcs_77_5[1] = {\r
+    {0, 5},\r
+};\r
+static state states_77[6] = {\r
+    {1, arcs_77_0},\r
+    {1, arcs_77_1},\r
+    {1, arcs_77_2},\r
+    {1, arcs_77_3},\r
+    {2, arcs_77_4},\r
+    {1, arcs_77_5},\r
+};\r
+static arc arcs_78_0[1] = {\r
+    {92, 1},\r
+};\r
+static arc arcs_78_1[1] = {\r
+    {106, 2},\r
+};\r
+static arc arcs_78_2[2] = {\r
+    {163, 3},\r
+    {0, 2},\r
+};\r
+static arc arcs_78_3[1] = {\r
+    {0, 3},\r
+};\r
+static state states_78[4] = {\r
+    {1, arcs_78_0},\r
+    {1, arcs_78_1},\r
+    {2, arcs_78_2},\r
+    {1, arcs_78_3},\r
+};\r
+static arc arcs_79_0[2] = {\r
+    {157, 1},\r
+    {166, 1},\r
+};\r
+static arc arcs_79_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_79[2] = {\r
+    {2, arcs_79_0},\r
+    {1, arcs_79_1},\r
+};\r
+static arc arcs_80_0[1] = {\r
+    {96, 1},\r
+};\r
+static arc arcs_80_1[1] = {\r
+    {61, 2},\r
+};\r
+static arc arcs_80_2[1] = {\r
+    {85, 3},\r
+};\r
+static arc arcs_80_3[1] = {\r
+    {107, 4},\r
+};\r
+static arc arcs_80_4[2] = {\r
+    {165, 5},\r
+    {0, 4},\r
+};\r
+static arc arcs_80_5[1] = {\r
+    {0, 5},\r
+};\r
+static state states_80[6] = {\r
+    {1, arcs_80_0},\r
+    {1, arcs_80_1},\r
+    {1, arcs_80_2},\r
+    {1, arcs_80_3},\r
+    {2, arcs_80_4},\r
+    {1, arcs_80_5},\r
+};\r
+static arc arcs_81_0[1] = {\r
+    {92, 1},\r
+};\r
+static arc arcs_81_1[1] = {\r
+    {106, 2},\r
+};\r
+static arc arcs_81_2[2] = {\r
+    {165, 3},\r
+    {0, 2},\r
+};\r
+static arc arcs_81_3[1] = {\r
+    {0, 3},\r
+};\r
+static state states_81[4] = {\r
+    {1, arcs_81_0},\r
+    {1, arcs_81_1},\r
+    {2, arcs_81_2},\r
+    {1, arcs_81_3},\r
+};\r
+static arc arcs_82_0[1] = {\r
+    {28, 1},\r
+};\r
+static arc arcs_82_1[2] = {\r
+    {29, 0},\r
+    {0, 1},\r
+};\r
+static state states_82[2] = {\r
+    {1, arcs_82_0},\r
+    {2, arcs_82_1},\r
+};\r
+static arc arcs_83_0[1] = {\r
+    {21, 1},\r
+};\r
+static arc arcs_83_1[1] = {\r
+    {0, 1},\r
+};\r
+static state states_83[2] = {\r
+    {1, arcs_83_0},\r
+    {1, arcs_83_1},\r
+};\r
+static arc arcs_84_0[1] = {\r
+    {168, 1},\r
+};\r
+static arc arcs_84_1[2] = {\r
+    {9, 2},\r
+    {0, 1},\r
+};\r
+static arc arcs_84_2[1] = {\r
+    {0, 2},\r
+};\r
+static state states_84[3] = {\r
+    {1, arcs_84_0},\r
+    {2, arcs_84_1},\r
+    {1, arcs_84_2},\r
+};\r
+static dfa dfas[85] = {\r
+    {256, "single_input", 0, 3, states_0,\r
+     "\004\050\060\000\000\000\000\124\360\024\114\220\023\040\010\000\200\041\044\015\002\001"},\r
+    {257, "file_input", 0, 2, states_1,\r
+     "\204\050\060\000\000\000\000\124\360\024\114\220\023\040\010\000\200\041\044\015\002\001"},\r
+    {258, "eval_input", 0, 3, states_2,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {259, "decorator", 0, 7, states_3,\r
+     "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {260, "decorators", 0, 2, states_4,\r
+     "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {261, "decorated", 0, 3, states_5,\r
+     "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {262, "funcdef", 0, 6, states_6,\r
+     "\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {263, "parameters", 0, 4, states_7,\r
+     "\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {264, "varargslist", 0, 10, states_8,\r
+     "\000\040\040\300\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {265, "fpdef", 0, 4, states_9,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {266, "fplist", 0, 3, states_10,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {267, "stmt", 0, 2, states_11,\r
+     "\000\050\060\000\000\000\000\124\360\024\114\220\023\040\010\000\200\041\044\015\002\001"},\r
+    {268, "simple_stmt", 0, 4, states_12,\r
+     "\000\040\040\000\000\000\000\124\360\024\114\000\000\040\010\000\200\041\044\015\000\001"},\r
+    {269, "small_stmt", 0, 2, states_13,\r
+     "\000\040\040\000\000\000\000\124\360\024\114\000\000\040\010\000\200\041\044\015\000\001"},\r
+    {270, "expr_stmt", 0, 6, states_14,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {271, "augassign", 0, 2, states_15,\r
+     "\000\000\000\000\000\300\377\003\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {272, "print_stmt", 0, 9, states_16,\r
+     "\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {273, "del_stmt", 0, 3, states_17,\r
+     "\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {274, "pass_stmt", 0, 2, states_18,\r
+     "\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {275, "flow_stmt", 0, 2, states_19,\r
+     "\000\000\000\000\000\000\000\000\360\000\000\000\000\000\000\000\000\000\000\000\000\001"},\r
+    {276, "break_stmt", 0, 2, states_20,\r
+     "\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {277, "continue_stmt", 0, 2, states_21,\r
+     "\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {278, "return_stmt", 0, 3, states_22,\r
+     "\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {279, "yield_stmt", 0, 2, states_23,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001"},\r
+    {280, "raise_stmt", 0, 7, states_24,\r
+     "\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {281, "import_stmt", 0, 2, states_25,\r
+     "\000\000\000\000\000\000\000\000\000\024\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {282, "import_name", 0, 3, states_26,\r
+     "\000\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {283, "import_from", 0, 8, states_27,\r
+     "\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {284, "import_as_name", 0, 4, states_28,\r
+     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {285, "dotted_as_name", 0, 4, states_29,\r
+     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {286, "import_as_names", 0, 3, states_30,\r
+     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {287, "dotted_as_names", 0, 2, states_31,\r
+     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {288, "dotted_name", 0, 2, states_32,\r
+     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {289, "global_stmt", 0, 3, states_33,\r
+     "\000\000\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {290, "exec_stmt", 0, 7, states_34,\r
+     "\000\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {291, "assert_stmt", 0, 5, states_35,\r
+     "\000\000\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {292, "compound_stmt", 0, 2, states_36,\r
+     "\000\010\020\000\000\000\000\000\000\000\000\220\023\000\000\000\000\000\000\000\002\000"},\r
+    {293, "if_stmt", 0, 8, states_37,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000"},\r
+    {294, "while_stmt", 0, 8, states_38,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000"},\r
+    {295, "for_stmt", 0, 10, states_39,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000"},\r
+    {296, "try_stmt", 0, 13, states_40,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\000\000"},\r
+    {297, "with_stmt", 0, 5, states_41,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000"},\r
+    {298, "with_item", 0, 4, states_42,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {299, "except_clause", 0, 5, states_43,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000"},\r
+    {300, "suite", 0, 5, states_44,\r
+     "\004\040\040\000\000\000\000\124\360\024\114\000\000\040\010\000\200\041\044\015\000\001"},\r
+    {301, "testlist_safe", 0, 5, states_45,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {302, "old_test", 0, 2, states_46,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {303, "old_lambdef", 0, 5, states_47,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000"},\r
+    {304, "test", 0, 6, states_48,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {305, "or_test", 0, 2, states_49,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\010\000\200\041\044\015\000\000"},\r
+    {306, "and_test", 0, 2, states_50,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\010\000\200\041\044\015\000\000"},\r
+    {307, "not_test", 0, 3, states_51,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\010\000\200\041\044\015\000\000"},\r
+    {308, "comparison", 0, 2, states_52,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\000\000\200\041\044\015\000\000"},\r
+    {309, "comp_op", 0, 4, states_53,\r
+     "\000\000\000\000\000\000\000\000\000\000\040\000\000\000\310\077\000\000\000\000\000\000"},\r
+    {310, "expr", 0, 2, states_54,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\000\000\200\041\044\015\000\000"},\r
+    {311, "xor_expr", 0, 2, states_55,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\000\000\200\041\044\015\000\000"},\r
+    {312, "and_expr", 0, 2, states_56,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\000\000\200\041\044\015\000\000"},\r
+    {313, "shift_expr", 0, 2, states_57,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\000\000\200\041\044\015\000\000"},\r
+    {314, "arith_expr", 0, 2, states_58,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\000\000\200\041\044\015\000\000"},\r
+    {315, "term", 0, 2, states_59,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\000\000\200\041\044\015\000\000"},\r
+    {316, "factor", 0, 3, states_60,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\000\000\200\041\044\015\000\000"},\r
+    {317, "power", 0, 4, states_61,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\044\015\000\000"},\r
+    {318, "atom", 0, 11, states_62,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\044\015\000\000"},\r
+    {319, "listmaker", 0, 5, states_63,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {320, "testlist_comp", 0, 5, states_64,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {321, "lambdef", 0, 5, states_65,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000"},\r
+    {322, "trailer", 0, 7, states_66,\r
+     "\000\040\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\004\000\000\000"},\r
+    {323, "subscriptlist", 0, 3, states_67,\r
+     "\000\040\240\000\000\000\000\000\000\040\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {324, "subscript", 0, 7, states_68,\r
+     "\000\040\240\000\000\000\000\000\000\040\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {325, "sliceop", 0, 3, states_69,\r
+     "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {326, "exprlist", 0, 3, states_70,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\000\000\000\200\041\044\015\000\000"},\r
+    {327, "testlist", 0, 3, states_71,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {328, "dictorsetmaker", 0, 11, states_72,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {329, "classdef", 0, 8, states_73,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\002\000"},\r
+    {330, "arglist", 0, 8, states_74,\r
+     "\000\040\040\300\000\000\000\000\000\000\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {331, "argument", 0, 4, states_75,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {332, "list_iter", 0, 2, states_76,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\020\001\000\000\000\000\000\000\000\000\000"},\r
+    {333, "list_for", 0, 6, states_77,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000"},\r
+    {334, "list_if", 0, 4, states_78,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000"},\r
+    {335, "comp_iter", 0, 2, states_79,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\020\001\000\000\000\000\000\000\000\000\000"},\r
+    {336, "comp_for", 0, 6, states_80,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000"},\r
+    {337, "comp_if", 0, 4, states_81,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000"},\r
+    {338, "testlist1", 0, 2, states_82,\r
+     "\000\040\040\000\000\000\000\000\000\000\000\000\000\040\010\000\200\041\044\015\000\000"},\r
+    {339, "encoding_decl", 0, 2, states_83,\r
+     "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},\r
+    {340, "yield_expr", 0, 3, states_84,\r
+     "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001"},\r
+};\r
+static label labels[169] = {\r
+    {0, "EMPTY"},\r
+    {256, 0},\r
+    {4, 0},\r
+    {268, 0},\r
+    {292, 0},\r
+    {257, 0},\r
+    {267, 0},\r
+    {0, 0},\r
+    {258, 0},\r
+    {327, 0},\r
+    {259, 0},\r
+    {50, 0},\r
+    {288, 0},\r
+    {7, 0},\r
+    {330, 0},\r
+    {8, 0},\r
+    {260, 0},\r
+    {261, 0},\r
+    {329, 0},\r
+    {262, 0},\r
+    {1, "def"},\r
+    {1, 0},\r
+    {263, 0},\r
+    {11, 0},\r
+    {300, 0},\r
+    {264, 0},\r
+    {265, 0},\r
+    {22, 0},\r
+    {304, 0},\r
+    {12, 0},\r
+    {16, 0},\r
+    {36, 0},\r
+    {266, 0},\r
+    {269, 0},\r
+    {13, 0},\r
+    {270, 0},\r
+    {272, 0},\r
+    {273, 0},\r
+    {274, 0},\r
+    {275, 0},\r
+    {281, 0},\r
+    {289, 0},\r
+    {290, 0},\r
+    {291, 0},\r
+    {271, 0},\r
+    {340, 0},\r
+    {37, 0},\r
+    {38, 0},\r
+    {39, 0},\r
+    {40, 0},\r
+    {41, 0},\r
+    {42, 0},\r
+    {43, 0},\r
+    {44, 0},\r
+    {45, 0},\r
+    {46, 0},\r
+    {47, 0},\r
+    {49, 0},\r
+    {1, "print"},\r
+    {35, 0},\r
+    {1, "del"},\r
+    {326, 0},\r
+    {1, "pass"},\r
+    {276, 0},\r
+    {277, 0},\r
+    {278, 0},\r
+    {280, 0},\r
+    {279, 0},\r
+    {1, "break"},\r
+    {1, "continue"},\r
+    {1, "return"},\r
+    {1, "raise"},\r
+    {282, 0},\r
+    {283, 0},\r
+    {1, "import"},\r
+    {287, 0},\r
+    {1, "from"},\r
+    {23, 0},\r
+    {286, 0},\r
+    {284, 0},\r
+    {1, "as"},\r
+    {285, 0},\r
+    {1, "global"},\r
+    {1, "exec"},\r
+    {310, 0},\r
+    {1, "in"},\r
+    {1, "assert"},\r
+    {293, 0},\r
+    {294, 0},\r
+    {295, 0},\r
+    {296, 0},\r
+    {297, 0},\r
+    {1, "if"},\r
+    {1, "elif"},\r
+    {1, "else"},\r
+    {1, "while"},\r
+    {1, "for"},\r
+    {1, "try"},\r
+    {299, 0},\r
+    {1, "finally"},\r
+    {1, "with"},\r
+    {298, 0},\r
+    {1, "except"},\r
+    {5, 0},\r
+    {6, 0},\r
+    {301, 0},\r
+    {302, 0},\r
+    {305, 0},\r
+    {303, 0},\r
+    {1, "lambda"},\r
+    {321, 0},\r
+    {306, 0},\r
+    {1, "or"},\r
+    {307, 0},\r
+    {1, "and"},\r
+    {1, "not"},\r
+    {308, 0},\r
+    {309, 0},\r
+    {20, 0},\r
+    {21, 0},\r
+    {28, 0},\r
+    {31, 0},\r
+    {30, 0},\r
+    {29, 0},\r
+    {29, 0},\r
+    {1, "is"},\r
+    {311, 0},\r
+    {18, 0},\r
+    {312, 0},\r
+    {33, 0},\r
+    {313, 0},\r
+    {19, 0},\r
+    {314, 0},\r
+    {34, 0},\r
+    {315, 0},\r
+    {14, 0},\r
+    {15, 0},\r
+    {316, 0},\r
+    {17, 0},\r
+    {24, 0},\r
+    {48, 0},\r
+    {32, 0},\r
+    {317, 0},\r
+    {318, 0},\r
+    {322, 0},\r
+    {320, 0},\r
+    {9, 0},\r
+    {319, 0},\r
+    {10, 0},\r
+    {26, 0},\r
+    {328, 0},\r
+    {27, 0},\r
+    {25, 0},\r
+    {338, 0},\r
+    {2, 0},\r
+    {3, 0},\r
+    {333, 0},\r
+    {336, 0},\r
+    {323, 0},\r
+    {324, 0},\r
+    {325, 0},\r
+    {1, "class"},\r
+    {331, 0},\r
+    {332, 0},\r
+    {334, 0},\r
+    {335, 0},\r
+    {337, 0},\r
+    {339, 0},\r
+    {1, "yield"},\r
+};\r
+grammar _PyParser_Grammar = {\r
+    85,\r
+    dfas,\r
+    {169, labels},\r
+    256\r
+};\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/import.c b/AppPkg/Applications/Python/Python-2.7.10/Python/import.c
new file mode 100644 (file)
index 0000000..6a95d4d
--- /dev/null
@@ -0,0 +1,3481 @@
+\r
+/* Module definition and import implementation */\r
+\r
+#include "Python.h"\r
+\r
+#include "Python-ast.h"\r
+#undef Yield /* undefine macro conflicting with winbase.h */\r
+#include "pyarena.h"\r
+#include "pythonrun.h"\r
+#include "errcode.h"\r
+#include "marshal.h"\r
+#include "code.h"\r
+#include "compile.h"\r
+#include "eval.h"\r
+#include "osdefs.h"\r
+#include "importdl.h"\r
+\r
+#ifdef HAVE_FCNTL_H\r
+#include <fcntl.h>\r
+#endif\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifdef MS_WINDOWS\r
+/* for stat.st_mode */\r
+typedef unsigned short mode_t;\r
+#endif\r
+\r
+\r
+/* Magic word to reject .pyc files generated by other Python versions.\r
+   It should change for each incompatible change to the bytecode.\r
+\r
+   The value of CR and LF is incorporated so if you ever read or write\r
+   a .pyc file in text mode the magic number will be wrong; also, the\r
+   Apple MPW compiler swaps their values, botching string constants.\r
+\r
+   The magic numbers must be spaced apart atleast 2 values, as the\r
+   -U interpeter flag will cause MAGIC+1 being used. They have been\r
+   odd numbers for some time now.\r
+\r
+   There were a variety of old schemes for setting the magic number.\r
+   The current working scheme is to increment the previous value by\r
+   10.\r
+\r
+   Known values:\r
+       Python 1.5:   20121\r
+       Python 1.5.1: 20121\r
+       Python 1.5.2: 20121\r
+       Python 1.6:   50428\r
+       Python 2.0:   50823\r
+       Python 2.0.1: 50823\r
+       Python 2.1:   60202\r
+       Python 2.1.1: 60202\r
+       Python 2.1.2: 60202\r
+       Python 2.2:   60717\r
+       Python 2.3a0: 62011\r
+       Python 2.3a0: 62021\r
+       Python 2.3a0: 62011 (!)\r
+       Python 2.4a0: 62041\r
+       Python 2.4a3: 62051\r
+       Python 2.4b1: 62061\r
+       Python 2.5a0: 62071\r
+       Python 2.5a0: 62081 (ast-branch)\r
+       Python 2.5a0: 62091 (with)\r
+       Python 2.5a0: 62092 (changed WITH_CLEANUP opcode)\r
+       Python 2.5b3: 62101 (fix wrong code: for x, in ...)\r
+       Python 2.5b3: 62111 (fix wrong code: x += yield)\r
+       Python 2.5c1: 62121 (fix wrong lnotab with for loops and\r
+                            storing constants that should have been removed)\r
+       Python 2.5c2: 62131 (fix wrong code: for x, in ... in listcomp/genexp)\r
+       Python 2.6a0: 62151 (peephole optimizations and STORE_MAP opcode)\r
+       Python 2.6a1: 62161 (WITH_CLEANUP optimization)\r
+       Python 2.7a0: 62171 (optimize list comprehensions/change LIST_APPEND)\r
+       Python 2.7a0: 62181 (optimize conditional branches:\r
+                introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE)\r
+       Python 2.7a0  62191 (introduce SETUP_WITH)\r
+       Python 2.7a0  62201 (introduce BUILD_SET)\r
+       Python 2.7a0  62211 (introduce MAP_ADD and SET_ADD)\r
+.\r
+*/\r
+#define MAGIC (62211 | ((long)'\r'<<16) | ((long)'\n'<<24))\r
+\r
+/* Magic word as global; note that _PyImport_Init() can change the\r
+   value of this global to accommodate for alterations of how the\r
+   compiler works which are enabled by command line switches. */\r
+static long pyc_magic = MAGIC;\r
+\r
+/* See _PyImport_FixupExtension() below */\r
+static PyObject *extensions = NULL;\r
+\r
+/* This table is defined in config.c: */\r
+extern struct _inittab _PyImport_Inittab[];\r
+\r
+struct _inittab *PyImport_Inittab = _PyImport_Inittab;\r
+\r
+/* these tables define the module suffixes that Python recognizes */\r
+struct filedescr * _PyImport_Filetab = NULL;\r
+\r
+#ifdef RISCOS\r
+static const struct filedescr _PyImport_StandardFiletab[] = {\r
+    {"/py", "U", PY_SOURCE},\r
+    {"/pyc", "rb", PY_COMPILED},\r
+    {0, 0}\r
+};\r
+#else\r
+static const struct filedescr _PyImport_StandardFiletab[] = {\r
+    {".py", "U", PY_SOURCE},\r
+#ifdef MS_WINDOWS\r
+    {".pyw", "U", PY_SOURCE},\r
+#endif\r
+    {".pyc", "rb", PY_COMPILED},\r
+    {0, 0}\r
+};\r
+#endif\r
+\r
+#ifdef MS_WINDOWS\r
+static int isdir(char *path) {\r
+    DWORD rv;\r
+    /* see issue1293 and issue3677:\r
+     * stat() on Windows doesn't recognise paths like\r
+     * "e:\\shared\\" and "\\\\whiterab-c2znlh\\shared" as dirs.\r
+     * Also reference issue6727:\r
+     * stat() on Windows is broken and doesn't resolve symlinks properly.\r
+     */\r
+    rv = GetFileAttributesA(path);\r
+    return rv != INVALID_FILE_ATTRIBUTES && rv & FILE_ATTRIBUTE_DIRECTORY;\r
+}\r
+#else\r
+#ifdef HAVE_STAT\r
+static int isdir(char *path) {\r
+    struct stat statbuf;\r
+    return stat(path, &statbuf) == 0 && S_ISDIR(statbuf.st_mode);\r
+}\r
+#else\r
+#ifdef RISCOS\r
+/* with RISCOS, isdir is in unixstuff */\r
+#else\r
+int isdir(char *path) {\r
+    return 0;\r
+}\r
+#endif /* RISCOS */\r
+#endif /* HAVE_STAT */\r
+#endif /* MS_WINDOWS */\r
+\r
+/* Initialize things */\r
+\r
+void\r
+_PyImport_Init(void)\r
+{\r
+    const struct filedescr *scan;\r
+    struct filedescr *filetab;\r
+    int countD = 0;\r
+    int countS = 0;\r
+\r
+    /* prepare _PyImport_Filetab: copy entries from\r
+       _PyImport_DynLoadFiletab and _PyImport_StandardFiletab.\r
+     */\r
+#ifdef HAVE_DYNAMIC_LOADING\r
+    for (scan = _PyImport_DynLoadFiletab; scan->suffix != NULL; ++scan)\r
+        ++countD;\r
+#endif\r
+    for (scan = _PyImport_StandardFiletab; scan->suffix != NULL; ++scan)\r
+        ++countS;\r
+    filetab = PyMem_NEW(struct filedescr, countD + countS + 1);\r
+    if (filetab == NULL)\r
+        Py_FatalError("Can't initialize import file table.");\r
+#ifdef HAVE_DYNAMIC_LOADING\r
+    memcpy(filetab, _PyImport_DynLoadFiletab,\r
+           countD * sizeof(struct filedescr));\r
+#endif\r
+    memcpy(filetab + countD, _PyImport_StandardFiletab,\r
+           countS * sizeof(struct filedescr));\r
+    filetab[countD + countS].suffix = NULL;\r
+\r
+    _PyImport_Filetab = filetab;\r
+\r
+    if (Py_OptimizeFlag) {\r
+        /* Replace ".pyc" with ".pyo" in _PyImport_Filetab */\r
+        for (; filetab->suffix != NULL; filetab++) {\r
+#ifndef RISCOS\r
+            if (strcmp(filetab->suffix, ".pyc") == 0)\r
+                filetab->suffix = ".pyo";\r
+#else\r
+            if (strcmp(filetab->suffix, "/pyc") == 0)\r
+                filetab->suffix = "/pyo";\r
+#endif\r
+        }\r
+    }\r
+\r
+    if (Py_UnicodeFlag) {\r
+        /* Fix the pyc_magic so that byte compiled code created\r
+           using the all-Unicode method doesn't interfere with\r
+           code created in normal operation mode. */\r
+        pyc_magic = MAGIC + 1;\r
+    }\r
+}\r
+\r
+void\r
+_PyImportHooks_Init(void)\r
+{\r
+    PyObject *v, *path_hooks = NULL, *zimpimport;\r
+    int err = 0;\r
+\r
+    /* adding sys.path_hooks and sys.path_importer_cache, setting up\r
+       zipimport */\r
+    if (PyType_Ready(&PyNullImporter_Type) < 0)\r
+        goto error;\r
+\r
+    if (Py_VerboseFlag)\r
+        PySys_WriteStderr("# installing zipimport hook\n");\r
+\r
+    v = PyList_New(0);\r
+    if (v == NULL)\r
+        goto error;\r
+    err = PySys_SetObject("meta_path", v);\r
+    Py_DECREF(v);\r
+    if (err)\r
+        goto error;\r
+    v = PyDict_New();\r
+    if (v == NULL)\r
+        goto error;\r
+    err = PySys_SetObject("path_importer_cache", v);\r
+    Py_DECREF(v);\r
+    if (err)\r
+        goto error;\r
+    path_hooks = PyList_New(0);\r
+    if (path_hooks == NULL)\r
+        goto error;\r
+    err = PySys_SetObject("path_hooks", path_hooks);\r
+    if (err) {\r
+  error:\r
+        PyErr_Print();\r
+        Py_FatalError("initializing sys.meta_path, sys.path_hooks, "\r
+                      "path_importer_cache, or NullImporter failed"\r
+                      );\r
+    }\r
+\r
+    zimpimport = PyImport_ImportModule("zipimport");\r
+    if (zimpimport == NULL) {\r
+        PyErr_Clear(); /* No zip import module -- okay */\r
+        if (Py_VerboseFlag)\r
+            PySys_WriteStderr("# can't import zipimport\n");\r
+    }\r
+    else {\r
+        PyObject *zipimporter = PyObject_GetAttrString(zimpimport,\r
+                                                       "zipimporter");\r
+        Py_DECREF(zimpimport);\r
+        if (zipimporter == NULL) {\r
+            PyErr_Clear(); /* No zipimporter object -- okay */\r
+            if (Py_VerboseFlag)\r
+                PySys_WriteStderr(\r
+                    "# can't import zipimport.zipimporter\n");\r
+        }\r
+        else {\r
+            /* sys.path_hooks.append(zipimporter) */\r
+            err = PyList_Append(path_hooks, zipimporter);\r
+            Py_DECREF(zipimporter);\r
+            if (err)\r
+                goto error;\r
+            if (Py_VerboseFlag)\r
+                PySys_WriteStderr(\r
+                    "# installed zipimport hook\n");\r
+        }\r
+    }\r
+    Py_DECREF(path_hooks);\r
+}\r
+\r
+void\r
+_PyImport_Fini(void)\r
+{\r
+    Py_XDECREF(extensions);\r
+    extensions = NULL;\r
+    PyMem_DEL(_PyImport_Filetab);\r
+    _PyImport_Filetab = NULL;\r
+}\r
+\r
+\r
+/* Locking primitives to prevent parallel imports of the same module\r
+   in different threads to return with a partially loaded module.\r
+   These calls are serialized by the global interpreter lock. */\r
+\r
+#ifdef WITH_THREAD\r
+\r
+#include "pythread.h"\r
+\r
+static PyThread_type_lock import_lock = 0;\r
+static long import_lock_thread = -1;\r
+static int import_lock_level = 0;\r
+\r
+void\r
+_PyImport_AcquireLock(void)\r
+{\r
+    long me = PyThread_get_thread_ident();\r
+    if (me == -1)\r
+        return; /* Too bad */\r
+    if (import_lock == NULL) {\r
+        import_lock = PyThread_allocate_lock();\r
+        if (import_lock == NULL)\r
+            return;  /* Nothing much we can do. */\r
+    }\r
+    if (import_lock_thread == me) {\r
+        import_lock_level++;\r
+        return;\r
+    }\r
+    if (import_lock_thread != -1 || !PyThread_acquire_lock(import_lock, 0))\r
+    {\r
+        PyThreadState *tstate = PyEval_SaveThread();\r
+        PyThread_acquire_lock(import_lock, 1);\r
+        PyEval_RestoreThread(tstate);\r
+    }\r
+    import_lock_thread = me;\r
+    import_lock_level = 1;\r
+}\r
+\r
+int\r
+_PyImport_ReleaseLock(void)\r
+{\r
+    long me = PyThread_get_thread_ident();\r
+    if (me == -1 || import_lock == NULL)\r
+        return 0; /* Too bad */\r
+    if (import_lock_thread != me)\r
+        return -1;\r
+    import_lock_level--;\r
+    if (import_lock_level == 0) {\r
+        import_lock_thread = -1;\r
+        PyThread_release_lock(import_lock);\r
+    }\r
+    return 1;\r
+}\r
+\r
+/* This function is called from PyOS_AfterFork to ensure that newly\r
+   created child processes do not share locks with the parent.\r
+   We now acquire the import lock around fork() calls but on some platforms\r
+   (Solaris 9 and earlier? see isue7242) that still left us with problems. */\r
+\r
+void\r
+_PyImport_ReInitLock(void)\r
+{\r
+    if (import_lock != NULL) {\r
+        import_lock = PyThread_allocate_lock();\r
+        if (import_lock == NULL) {\r
+            Py_FatalError("PyImport_ReInitLock failed to create a new lock");\r
+        }\r
+    }\r
+    import_lock_thread = -1;\r
+    import_lock_level = 0;\r
+}\r
+\r
+#endif\r
+\r
+static PyObject *\r
+imp_lock_held(PyObject *self, PyObject *noargs)\r
+{\r
+#ifdef WITH_THREAD\r
+    return PyBool_FromLong(import_lock_thread != -1);\r
+#else\r
+    return PyBool_FromLong(0);\r
+#endif\r
+}\r
+\r
+static PyObject *\r
+imp_acquire_lock(PyObject *self, PyObject *noargs)\r
+{\r
+#ifdef WITH_THREAD\r
+    _PyImport_AcquireLock();\r
+#endif\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+static PyObject *\r
+imp_release_lock(PyObject *self, PyObject *noargs)\r
+{\r
+#ifdef WITH_THREAD\r
+    if (_PyImport_ReleaseLock() < 0) {\r
+        PyErr_SetString(PyExc_RuntimeError,\r
+                        "not holding the import lock");\r
+        return NULL;\r
+    }\r
+#endif\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+static void\r
+imp_modules_reloading_clear(void)\r
+{\r
+    PyInterpreterState *interp = PyThreadState_Get()->interp;\r
+    if (interp->modules_reloading != NULL)\r
+        PyDict_Clear(interp->modules_reloading);\r
+}\r
+\r
+/* Helper for sys */\r
+\r
+PyObject *\r
+PyImport_GetModuleDict(void)\r
+{\r
+    PyInterpreterState *interp = PyThreadState_GET()->interp;\r
+    if (interp->modules == NULL)\r
+        Py_FatalError("PyImport_GetModuleDict: no module dictionary!");\r
+    return interp->modules;\r
+}\r
+\r
+\r
+/* List of names to clear in sys */\r
+static char* sys_deletes[] = {\r
+    "path", "argv", "ps1", "ps2", "exitfunc",\r
+    "exc_type", "exc_value", "exc_traceback",\r
+    "last_type", "last_value", "last_traceback",\r
+    "path_hooks", "path_importer_cache", "meta_path",\r
+    /* misc stuff */\r
+    "flags", "float_info",\r
+    NULL\r
+};\r
+\r
+static char* sys_files[] = {\r
+    "stdin", "__stdin__",\r
+    "stdout", "__stdout__",\r
+    "stderr", "__stderr__",\r
+    NULL\r
+};\r
+\r
+\r
+/* Un-initialize things, as good as we can */\r
+\r
+void\r
+PyImport_Cleanup(void)\r
+{\r
+    Py_ssize_t pos, ndone;\r
+    char *name;\r
+    PyObject *key, *value, *dict;\r
+    PyInterpreterState *interp = PyThreadState_GET()->interp;\r
+    PyObject *modules = interp->modules;\r
+\r
+    if (modules == NULL)\r
+        return; /* Already done */\r
+\r
+    /* Delete some special variables first.  These are common\r
+       places where user values hide and people complain when their\r
+       destructors fail.  Since the modules containing them are\r
+       deleted *last* of all, they would come too late in the normal\r
+       destruction order.  Sigh. */\r
+\r
+    value = PyDict_GetItemString(modules, "__builtin__");\r
+    if (value != NULL && PyModule_Check(value)) {\r
+        dict = PyModule_GetDict(value);\r
+        if (Py_VerboseFlag)\r
+            PySys_WriteStderr("# clear __builtin__._\n");\r
+        PyDict_SetItemString(dict, "_", Py_None);\r
+    }\r
+    value = PyDict_GetItemString(modules, "sys");\r
+    if (value != NULL && PyModule_Check(value)) {\r
+        char **p;\r
+        PyObject *v;\r
+        dict = PyModule_GetDict(value);\r
+        for (p = sys_deletes; *p != NULL; p++) {\r
+            if (Py_VerboseFlag)\r
+                PySys_WriteStderr("# clear sys.%s\n", *p);\r
+            PyDict_SetItemString(dict, *p, Py_None);\r
+        }\r
+        for (p = sys_files; *p != NULL; p+=2) {\r
+            if (Py_VerboseFlag)\r
+                PySys_WriteStderr("# restore sys.%s\n", *p);\r
+            v = PyDict_GetItemString(dict, *(p+1));\r
+            if (v == NULL)\r
+                v = Py_None;\r
+            PyDict_SetItemString(dict, *p, v);\r
+        }\r
+    }\r
+\r
+    /* First, delete __main__ */\r
+    value = PyDict_GetItemString(modules, "__main__");\r
+    if (value != NULL && PyModule_Check(value)) {\r
+        if (Py_VerboseFlag)\r
+            PySys_WriteStderr("# cleanup __main__\n");\r
+        _PyModule_Clear(value);\r
+        PyDict_SetItemString(modules, "__main__", Py_None);\r
+    }\r
+\r
+    /* The special treatment of __builtin__ here is because even\r
+       when it's not referenced as a module, its dictionary is\r
+       referenced by almost every module's __builtins__.  Since\r
+       deleting a module clears its dictionary (even if there are\r
+       references left to it), we need to delete the __builtin__\r
+       module last.  Likewise, we don't delete sys until the very\r
+       end because it is implicitly referenced (e.g. by print).\r
+\r
+       Also note that we 'delete' modules by replacing their entry\r
+       in the modules dict with None, rather than really deleting\r
+       them; this avoids a rehash of the modules dictionary and\r
+       also marks them as "non existent" so they won't be\r
+       re-imported. */\r
+\r
+    /* Next, repeatedly delete modules with a reference count of\r
+       one (skipping __builtin__ and sys) and delete them */\r
+    do {\r
+        ndone = 0;\r
+        pos = 0;\r
+        while (PyDict_Next(modules, &pos, &key, &value)) {\r
+            if (value->ob_refcnt != 1)\r
+                continue;\r
+            if (PyString_Check(key) && PyModule_Check(value)) {\r
+                name = PyString_AS_STRING(key);\r
+                if (strcmp(name, "__builtin__") == 0)\r
+                    continue;\r
+                if (strcmp(name, "sys") == 0)\r
+                    continue;\r
+                if (Py_VerboseFlag)\r
+                    PySys_WriteStderr(\r
+                        "# cleanup[1] %s\n", name);\r
+                _PyModule_Clear(value);\r
+                PyDict_SetItem(modules, key, Py_None);\r
+                ndone++;\r
+            }\r
+        }\r
+    } while (ndone > 0);\r
+\r
+    /* Next, delete all modules (still skipping __builtin__ and sys) */\r
+    pos = 0;\r
+    while (PyDict_Next(modules, &pos, &key, &value)) {\r
+        if (PyString_Check(key) && PyModule_Check(value)) {\r
+            name = PyString_AS_STRING(key);\r
+            if (strcmp(name, "__builtin__") == 0)\r
+                continue;\r
+            if (strcmp(name, "sys") == 0)\r
+                continue;\r
+            if (Py_VerboseFlag)\r
+                PySys_WriteStderr("# cleanup[2] %s\n", name);\r
+            _PyModule_Clear(value);\r
+            PyDict_SetItem(modules, key, Py_None);\r
+        }\r
+    }\r
+\r
+    /* Next, delete sys and __builtin__ (in that order) */\r
+    value = PyDict_GetItemString(modules, "sys");\r
+    if (value != NULL && PyModule_Check(value)) {\r
+        if (Py_VerboseFlag)\r
+            PySys_WriteStderr("# cleanup sys\n");\r
+        _PyModule_Clear(value);\r
+        PyDict_SetItemString(modules, "sys", Py_None);\r
+    }\r
+    value = PyDict_GetItemString(modules, "__builtin__");\r
+    if (value != NULL && PyModule_Check(value)) {\r
+        if (Py_VerboseFlag)\r
+            PySys_WriteStderr("# cleanup __builtin__\n");\r
+        _PyModule_Clear(value);\r
+        PyDict_SetItemString(modules, "__builtin__", Py_None);\r
+    }\r
+\r
+    /* Finally, clear and delete the modules directory */\r
+    PyDict_Clear(modules);\r
+    interp->modules = NULL;\r
+    Py_DECREF(modules);\r
+    Py_CLEAR(interp->modules_reloading);\r
+}\r
+\r
+\r
+/* Helper for pythonrun.c -- return magic number */\r
+\r
+long\r
+PyImport_GetMagicNumber(void)\r
+{\r
+    return pyc_magic;\r
+}\r
+\r
+\r
+/* Magic for extension modules (built-in as well as dynamically\r
+   loaded).  To prevent initializing an extension module more than\r
+   once, we keep a static dictionary 'extensions' keyed by module name\r
+   (for built-in modules) or by filename (for dynamically loaded\r
+   modules), containing these modules.  A copy of the module's\r
+   dictionary is stored by calling _PyImport_FixupExtension()\r
+   immediately after the module initialization function succeeds.  A\r
+   copy can be retrieved from there by calling\r
+   _PyImport_FindExtension(). */\r
+\r
+PyObject *\r
+_PyImport_FixupExtension(char *name, char *filename)\r
+{\r
+    PyObject *modules, *mod, *dict, *copy;\r
+    if (extensions == NULL) {\r
+        extensions = PyDict_New();\r
+        if (extensions == NULL)\r
+            return NULL;\r
+    }\r
+    modules = PyImport_GetModuleDict();\r
+    mod = PyDict_GetItemString(modules, name);\r
+    if (mod == NULL || !PyModule_Check(mod)) {\r
+        PyErr_Format(PyExc_SystemError,\r
+          "_PyImport_FixupExtension: module %.200s not loaded", name);\r
+        return NULL;\r
+    }\r
+    dict = PyModule_GetDict(mod);\r
+    if (dict == NULL)\r
+        return NULL;\r
+    copy = PyDict_Copy(dict);\r
+    if (copy == NULL)\r
+        return NULL;\r
+    PyDict_SetItemString(extensions, filename, copy);\r
+    Py_DECREF(copy);\r
+    return copy;\r
+}\r
+\r
+PyObject *\r
+_PyImport_FindExtension(char *name, char *filename)\r
+{\r
+    PyObject *dict, *mod, *mdict;\r
+    if (extensions == NULL)\r
+        return NULL;\r
+    dict = PyDict_GetItemString(extensions, filename);\r
+    if (dict == NULL)\r
+        return NULL;\r
+    mod = PyImport_AddModule(name);\r
+    if (mod == NULL)\r
+        return NULL;\r
+    mdict = PyModule_GetDict(mod);\r
+    if (mdict == NULL)\r
+        return NULL;\r
+    if (PyDict_Update(mdict, dict))\r
+        return NULL;\r
+    if (Py_VerboseFlag)\r
+        PySys_WriteStderr("import %s # previously loaded (%s)\n",\r
+            name, filename);\r
+    return mod;\r
+}\r
+\r
+\r
+/* Get the module object corresponding to a module name.\r
+   First check the modules dictionary if there's one there,\r
+   if not, create a new one and insert it in the modules dictionary.\r
+   Because the former action is most common, THIS DOES NOT RETURN A\r
+   'NEW' REFERENCE! */\r
+\r
+PyObject *\r
+PyImport_AddModule(const char *name)\r
+{\r
+    PyObject *modules = PyImport_GetModuleDict();\r
+    PyObject *m;\r
+\r
+    if ((m = PyDict_GetItemString(modules, name)) != NULL &&\r
+        PyModule_Check(m))\r
+        return m;\r
+    m = PyModule_New(name);\r
+    if (m == NULL)\r
+        return NULL;\r
+    if (PyDict_SetItemString(modules, name, m) != 0) {\r
+        Py_DECREF(m);\r
+        return NULL;\r
+    }\r
+    Py_DECREF(m); /* Yes, it still exists, in modules! */\r
+\r
+    return m;\r
+}\r
+\r
+/* Remove name from sys.modules, if it's there. */\r
+static void\r
+remove_module(const char *name)\r
+{\r
+    PyObject *modules = PyImport_GetModuleDict();\r
+    if (PyDict_GetItemString(modules, name) == NULL)\r
+        return;\r
+    if (PyDict_DelItemString(modules, name) < 0)\r
+        Py_FatalError("import:  deleting existing key in"\r
+                      "sys.modules failed");\r
+}\r
+\r
+/* Execute a code object in a module and return the module object\r
+ * WITH INCREMENTED REFERENCE COUNT.  If an error occurs, name is\r
+ * removed from sys.modules, to avoid leaving damaged module objects\r
+ * in sys.modules.  The caller may wish to restore the original\r
+ * module object (if any) in this case; PyImport_ReloadModule is an\r
+ * example.\r
+ */\r
+PyObject *\r
+PyImport_ExecCodeModule(char *name, PyObject *co)\r
+{\r
+    return PyImport_ExecCodeModuleEx(name, co, (char *)NULL);\r
+}\r
+\r
+PyObject *\r
+PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname)\r
+{\r
+    PyObject *modules = PyImport_GetModuleDict();\r
+    PyObject *m, *d, *v;\r
+\r
+    m = PyImport_AddModule(name);\r
+    if (m == NULL)\r
+        return NULL;\r
+    /* If the module is being reloaded, we get the old module back\r
+       and re-use its dict to exec the new code. */\r
+    d = PyModule_GetDict(m);\r
+    if (PyDict_GetItemString(d, "__builtins__") == NULL) {\r
+        if (PyDict_SetItemString(d, "__builtins__",\r
+                                 PyEval_GetBuiltins()) != 0)\r
+            goto error;\r
+    }\r
+    /* Remember the filename as the __file__ attribute */\r
+    v = NULL;\r
+    if (pathname != NULL) {\r
+        v = PyString_FromString(pathname);\r
+        if (v == NULL)\r
+            PyErr_Clear();\r
+    }\r
+    if (v == NULL) {\r
+        v = ((PyCodeObject *)co)->co_filename;\r
+        Py_INCREF(v);\r
+    }\r
+    if (PyDict_SetItemString(d, "__file__", v) != 0)\r
+        PyErr_Clear(); /* Not important enough to report */\r
+    Py_DECREF(v);\r
+\r
+    v = PyEval_EvalCode((PyCodeObject *)co, d, d);\r
+    if (v == NULL)\r
+        goto error;\r
+    Py_DECREF(v);\r
+\r
+    if ((m = PyDict_GetItemString(modules, name)) == NULL) {\r
+        PyErr_Format(PyExc_ImportError,\r
+                     "Loaded module %.200s not found in sys.modules",\r
+                     name);\r
+        return NULL;\r
+    }\r
+\r
+    Py_INCREF(m);\r
+\r
+    return m;\r
+\r
+  error:\r
+    remove_module(name);\r
+    return NULL;\r
+}\r
+\r
+\r
+/* Given a pathname for a Python source file, fill a buffer with the\r
+   pathname for the corresponding compiled file.  Return the pathname\r
+   for the compiled file, or NULL if there's no space in the buffer.\r
+   Doesn't set an exception. */\r
+\r
+static char *\r
+make_compiled_pathname(char *pathname, char *buf, size_t buflen)\r
+{\r
+    size_t len = strlen(pathname);\r
+    if (len+2 > buflen)\r
+        return NULL;\r
+\r
+#ifdef MS_WINDOWS\r
+    /* Treat .pyw as if it were .py.  The case of ".pyw" must match\r
+       that used in _PyImport_StandardFiletab. */\r
+    if (len >= 4 && strcmp(&pathname[len-4], ".pyw") == 0)\r
+        --len;          /* pretend 'w' isn't there */\r
+#endif\r
+    memcpy(buf, pathname, len);\r
+    buf[len] = Py_OptimizeFlag ? 'o' : 'c';\r
+    buf[len+1] = '\0';\r
+\r
+    return buf;\r
+}\r
+\r
+\r
+/* Given a pathname for a Python source file, its time of last\r
+   modification, and a pathname for a compiled file, check whether the\r
+   compiled file represents the same version of the source.  If so,\r
+   return a FILE pointer for the compiled file, positioned just after\r
+   the header; if not, return NULL.\r
+   Doesn't set an exception. */\r
+\r
+static FILE *\r
+check_compiled_module(char *pathname, time_t mtime, char *cpathname)\r
+{\r
+    FILE *fp;\r
+    long magic;\r
+    long pyc_mtime;\r
+\r
+    fp = fopen(cpathname, "rb");\r
+    if (fp == NULL)\r
+        return NULL;\r
+    magic = PyMarshal_ReadLongFromFile(fp);\r
+    if (magic != pyc_magic) {\r
+        if (Py_VerboseFlag)\r
+            PySys_WriteStderr("# %s has bad magic\n", cpathname);\r
+        fclose(fp);\r
+        return NULL;\r
+    }\r
+    pyc_mtime = PyMarshal_ReadLongFromFile(fp);\r
+    if (pyc_mtime != mtime) {\r
+        if (Py_VerboseFlag)\r
+            PySys_WriteStderr("# %s has bad mtime\n", cpathname);\r
+        fclose(fp);\r
+        return NULL;\r
+    }\r
+    if (Py_VerboseFlag)\r
+        PySys_WriteStderr("# %s matches %s\n", cpathname, pathname);\r
+    return fp;\r
+}\r
+\r
+\r
+/* Read a code object from a file and check it for validity */\r
+\r
+static PyCodeObject *\r
+read_compiled_module(char *cpathname, FILE *fp)\r
+{\r
+    PyObject *co;\r
+\r
+    co = PyMarshal_ReadLastObjectFromFile(fp);\r
+    if (co == NULL)\r
+        return NULL;\r
+    if (!PyCode_Check(co)) {\r
+        PyErr_Format(PyExc_ImportError,\r
+                     "Non-code object in %.200s", cpathname);\r
+        Py_DECREF(co);\r
+        return NULL;\r
+    }\r
+    return (PyCodeObject *)co;\r
+}\r
+\r
+\r
+/* Load a module from a compiled file, execute it, and return its\r
+   module object WITH INCREMENTED REFERENCE COUNT */\r
+\r
+static PyObject *\r
+load_compiled_module(char *name, char *cpathname, FILE *fp)\r
+{\r
+    long magic;\r
+    PyCodeObject *co;\r
+    PyObject *m;\r
+\r
+    magic = PyMarshal_ReadLongFromFile(fp);\r
+    if (magic != pyc_magic) {\r
+        PyErr_Format(PyExc_ImportError,\r
+                     "Bad magic number in %.200s", cpathname);\r
+        return NULL;\r
+    }\r
+    (void) PyMarshal_ReadLongFromFile(fp);\r
+    co = read_compiled_module(cpathname, fp);\r
+    if (co == NULL)\r
+        return NULL;\r
+    if (Py_VerboseFlag)\r
+        PySys_WriteStderr("import %s # precompiled from %s\n",\r
+            name, cpathname);\r
+    m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, cpathname);\r
+    Py_DECREF(co);\r
+\r
+    return m;\r
+}\r
+\r
+/* Parse a source file and return the corresponding code object */\r
+\r
+static PyCodeObject *\r
+parse_source_module(const char *pathname, FILE *fp)\r
+{\r
+    PyCodeObject *co = NULL;\r
+    mod_ty mod;\r
+    PyCompilerFlags flags;\r
+    PyArena *arena = PyArena_New();\r
+    if (arena == NULL)\r
+        return NULL;\r
+\r
+    flags.cf_flags = 0;\r
+\r
+    mod = PyParser_ASTFromFile(fp, pathname, Py_file_input, 0, 0, &flags,\r
+                               NULL, arena);\r
+    if (mod) {\r
+        co = PyAST_Compile(mod, pathname, NULL, arena);\r
+    }\r
+    PyArena_Free(arena);\r
+    return co;\r
+}\r
+\r
+\r
+/* Helper to open a bytecode file for writing in exclusive mode */\r
+\r
+static FILE *\r
+open_exclusive(char *filename, mode_t mode)\r
+{\r
+#if defined(O_EXCL)&&defined(O_CREAT)&&defined(O_WRONLY)&&defined(O_TRUNC)\r
+    /* Use O_EXCL to avoid a race condition when another process tries to\r
+       write the same file.  When that happens, our open() call fails,\r
+       which is just fine (since it's only a cache).\r
+       XXX If the file exists and is writable but the directory is not\r
+       writable, the file will never be written.  Oh well.\r
+    */\r
+    int fd;\r
+    (void) unlink(filename);\r
+    fd = open(filename, O_EXCL|O_CREAT|O_WRONLY|O_TRUNC\r
+#ifdef O_BINARY\r
+                            |O_BINARY   /* necessary for Windows */\r
+#endif\r
+#ifdef __VMS\r
+            , mode, "ctxt=bin", "shr=nil"\r
+#else\r
+            , mode\r
+#endif\r
+          );\r
+    if (fd < 0)\r
+        return NULL;\r
+    return fdopen(fd, "wb");\r
+#else\r
+    /* Best we can do -- on Windows this can't happen anyway */\r
+    return fopen(filename, "wb");\r
+#endif\r
+}\r
+\r
+\r
+/* Write a compiled module to a file, placing the time of last\r
+   modification of its source into the header.\r
+   Errors are ignored, if a write error occurs an attempt is made to\r
+   remove the file. */\r
+\r
+static void\r
+write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat, time_t mtime)\r
+{\r
+    FILE *fp;\r
+#ifdef MS_WINDOWS   /* since Windows uses different permissions  */\r
+    mode_t mode = srcstat->st_mode & ~S_IEXEC;\r
+    /* Issue #6074: We ensure user write access, so we can delete it later\r
+     * when the source file changes. (On POSIX, this only requires write\r
+     * access to the directory, on Windows, we need write access to the file\r
+     * as well)\r
+     */\r
+    mode |= _S_IWRITE;\r
+#else\r
+    mode_t mode = srcstat->st_mode & ~S_IXUSR & ~S_IXGRP & ~S_IXOTH;\r
+#endif\r
+\r
+    fp = open_exclusive(cpathname, mode);\r
+    if (fp == NULL) {\r
+        if (Py_VerboseFlag)\r
+            PySys_WriteStderr(\r
+                "# can't create %s\n", cpathname);\r
+        return;\r
+    }\r
+    PyMarshal_WriteLongToFile(pyc_magic, fp, Py_MARSHAL_VERSION);\r
+    /* First write a 0 for mtime */\r
+    PyMarshal_WriteLongToFile(0L, fp, Py_MARSHAL_VERSION);\r
+    PyMarshal_WriteObjectToFile((PyObject *)co, fp, Py_MARSHAL_VERSION);\r
+    if (fflush(fp) != 0 || ferror(fp)) {\r
+        if (Py_VerboseFlag)\r
+            PySys_WriteStderr("# can't write %s\n", cpathname);\r
+        /* Don't keep partial file */\r
+        fclose(fp);\r
+        (void) unlink(cpathname);\r
+        return;\r
+    }\r
+    /* Now write the true mtime (as a 32-bit field) */\r
+    fseek(fp, 4L, 0);\r
+    assert(mtime <= 0xFFFFFFFF);\r
+    PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);\r
+    fflush(fp);\r
+    fclose(fp);\r
+    if (Py_VerboseFlag)\r
+        PySys_WriteStderr("# wrote %s\n", cpathname);\r
+}\r
+\r
+static void\r
+update_code_filenames(PyCodeObject *co, PyObject *oldname, PyObject *newname)\r
+{\r
+    PyObject *constants, *tmp;\r
+    Py_ssize_t i, n;\r
+\r
+    if (!_PyString_Eq(co->co_filename, oldname))\r
+        return;\r
+\r
+    tmp = co->co_filename;\r
+    co->co_filename = newname;\r
+    Py_INCREF(co->co_filename);\r
+    Py_DECREF(tmp);\r
+\r
+    constants = co->co_consts;\r
+    n = PyTuple_GET_SIZE(constants);\r
+    for (i = 0; i < n; i++) {\r
+        tmp = PyTuple_GET_ITEM(constants, i);\r
+        if (PyCode_Check(tmp))\r
+            update_code_filenames((PyCodeObject *)tmp,\r
+                                  oldname, newname);\r
+    }\r
+}\r
+\r
+static int\r
+update_compiled_module(PyCodeObject *co, char *pathname)\r
+{\r
+    PyObject *oldname, *newname;\r
+\r
+    if (strcmp(PyString_AsString(co->co_filename), pathname) == 0)\r
+        return 0;\r
+\r
+    newname = PyString_FromString(pathname);\r
+    if (newname == NULL)\r
+        return -1;\r
+\r
+    oldname = co->co_filename;\r
+    Py_INCREF(oldname);\r
+    update_code_filenames(co, oldname, newname);\r
+    Py_DECREF(oldname);\r
+    Py_DECREF(newname);\r
+    return 1;\r
+}\r
+\r
+#ifdef MS_WINDOWS\r
+\r
+/* Seconds between 1.1.1601 and 1.1.1970 */\r
+static __int64 secs_between_epochs = 11644473600;\r
+\r
+/* Get mtime from file pointer. */\r
+\r
+static time_t\r
+win32_mtime(FILE *fp, char *pathname)\r
+{\r
+    __int64 filetime;\r
+    HANDLE fh;\r
+    BY_HANDLE_FILE_INFORMATION file_information;\r
+\r
+    fh = (HANDLE)_get_osfhandle(fileno(fp));\r
+    if (fh == INVALID_HANDLE_VALUE ||\r
+        !GetFileInformationByHandle(fh, &file_information)) {\r
+        PyErr_Format(PyExc_RuntimeError,\r
+                     "unable to get file status from '%s'",\r
+                     pathname);\r
+        return -1;\r
+    }\r
+    /* filetime represents the number of 100ns intervals since\r
+       1.1.1601 (UTC).  Convert to seconds since 1.1.1970 (UTC). */\r
+    filetime = (__int64)file_information.ftLastWriteTime.dwHighDateTime << 32 |\r
+               file_information.ftLastWriteTime.dwLowDateTime;\r
+    return filetime / 10000000 - secs_between_epochs;\r
+}\r
+\r
+#endif  /* #ifdef MS_WINDOWS */\r
+\r
+\r
+/* Load a source module from a given file and return its module\r
+   object WITH INCREMENTED REFERENCE COUNT.  If there's a matching\r
+   byte-compiled file, use that instead. */\r
+\r
+static PyObject *\r
+load_source_module(char *name, char *pathname, FILE *fp)\r
+{\r
+    struct stat st;\r
+    FILE *fpc;\r
+    char *buf;\r
+    char *cpathname;\r
+    PyCodeObject *co = NULL;\r
+    PyObject *m;\r
+    time_t mtime;\r
+\r
+    if (fstat(fileno(fp), &st) != 0) {\r
+        PyErr_Format(PyExc_RuntimeError,\r
+                     "unable to get file status from '%s'",\r
+                     pathname);\r
+        return NULL;\r
+    }\r
+\r
+#ifdef MS_WINDOWS\r
+    mtime = win32_mtime(fp, pathname);\r
+    if (mtime == (time_t)-1 && PyErr_Occurred())\r
+        return NULL;\r
+#else\r
+    mtime = st.st_mtime;\r
+#endif\r
+    if (sizeof mtime > 4) {\r
+        /* Python's .pyc timestamp handling presumes that the timestamp fits\r
+           in 4 bytes. Since the code only does an equality comparison,\r
+           ordering is not important and we can safely ignore the higher bits\r
+           (collisions are extremely unlikely).\r
+         */\r
+        mtime &= 0xFFFFFFFF;\r
+    }\r
+    buf = PyMem_MALLOC(MAXPATHLEN+1);\r
+    if (buf == NULL) {\r
+        return PyErr_NoMemory();\r
+    }\r
+    cpathname = make_compiled_pathname(pathname, buf,\r
+                                       (size_t)MAXPATHLEN + 1);\r
+    if (cpathname != NULL &&\r
+        (fpc = check_compiled_module(pathname, mtime, cpathname))) {\r
+        co = read_compiled_module(cpathname, fpc);\r
+        fclose(fpc);\r
+        if (co == NULL)\r
+            goto error_exit;\r
+        if (update_compiled_module(co, pathname) < 0)\r
+            goto error_exit;\r
+        if (Py_VerboseFlag)\r
+            PySys_WriteStderr("import %s # precompiled from %s\n",\r
+                name, cpathname);\r
+        pathname = cpathname;\r
+    }\r
+    else {\r
+        co = parse_source_module(pathname, fp);\r
+        if (co == NULL)\r
+            goto error_exit;\r
+        if (Py_VerboseFlag)\r
+            PySys_WriteStderr("import %s # from %s\n",\r
+                name, pathname);\r
+        if (cpathname) {\r
+            PyObject *ro = PySys_GetObject("dont_write_bytecode");\r
+            int b = (ro == NULL) ? 0 : PyObject_IsTrue(ro);\r
+            if (b < 0)\r
+                goto error_exit;\r
+            if (!b)\r
+                write_compiled_module(co, cpathname, &st, mtime);\r
+        }\r
+    }\r
+    m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, pathname);\r
+    Py_DECREF(co);\r
+\r
+    PyMem_FREE(buf);\r
+    return m;\r
+\r
+error_exit:\r
+    Py_XDECREF(co);\r
+    PyMem_FREE(buf);\r
+    return NULL;\r
+}\r
+\r
+\r
+/* Forward */\r
+static PyObject *load_module(char *, FILE *, char *, int, PyObject *);\r
+static struct filedescr *find_module(char *, char *, PyObject *,\r
+                                     char *, size_t, FILE **, PyObject **);\r
+static struct _frozen *find_frozen(char *name);\r
+\r
+/* Load a package and return its module object WITH INCREMENTED\r
+   REFERENCE COUNT */\r
+\r
+static PyObject *\r
+load_package(char *name, char *pathname)\r
+{\r
+    PyObject *m, *d;\r
+    PyObject *file = NULL;\r
+    PyObject *path = NULL;\r
+    int err;\r
+    char *buf = NULL;\r
+    FILE *fp = NULL;\r
+    struct filedescr *fdp;\r
+\r
+    m = PyImport_AddModule(name);\r
+    if (m == NULL)\r
+        return NULL;\r
+    if (Py_VerboseFlag)\r
+        PySys_WriteStderr("import %s # directory %s\n",\r
+            name, pathname);\r
+    d = PyModule_GetDict(m);\r
+    file = PyString_FromString(pathname);\r
+    if (file == NULL)\r
+        goto error;\r
+    path = Py_BuildValue("[O]", file);\r
+    if (path == NULL)\r
+        goto error;\r
+    err = PyDict_SetItemString(d, "__file__", file);\r
+    if (err == 0)\r
+        err = PyDict_SetItemString(d, "__path__", path);\r
+    if (err != 0)\r
+        goto error;\r
+    buf = PyMem_MALLOC(MAXPATHLEN+1);\r
+    if (buf == NULL) {\r
+        PyErr_NoMemory();\r
+        goto error;\r
+    }\r
+    buf[0] = '\0';\r
+    fdp = find_module(name, "__init__", path, buf, MAXPATHLEN+1, &fp, NULL);\r
+    if (fdp == NULL) {\r
+        if (PyErr_ExceptionMatches(PyExc_ImportError)) {\r
+            PyErr_Clear();\r
+            Py_INCREF(m);\r
+        }\r
+        else\r
+            m = NULL;\r
+        goto cleanup;\r
+    }\r
+    m = load_module(name, fp, buf, fdp->type, NULL);\r
+    if (fp != NULL)\r
+        fclose(fp);\r
+    goto cleanup;\r
+\r
+  error:\r
+    m = NULL;\r
+  cleanup:\r
+    if (buf)\r
+        PyMem_FREE(buf);\r
+    Py_XDECREF(path);\r
+    Py_XDECREF(file);\r
+    return m;\r
+}\r
+\r
+\r
+/* Helper to test for built-in module */\r
+\r
+static int\r
+is_builtin(char *name)\r
+{\r
+    int i;\r
+    for (i = 0; PyImport_Inittab[i].name != NULL; i++) {\r
+        if (strcmp(name, PyImport_Inittab[i].name) == 0) {\r
+            if (PyImport_Inittab[i].initfunc == NULL)\r
+                return -1;\r
+            else\r
+                return 1;\r
+        }\r
+    }\r
+    return 0;\r
+}\r
+\r
+\r
+/* Return an importer object for a sys.path/pkg.__path__ item 'p',\r
+   possibly by fetching it from the path_importer_cache dict. If it\r
+   wasn't yet cached, traverse path_hooks until a hook is found\r
+   that can handle the path item. Return None if no hook could;\r
+   this tells our caller it should fall back to the builtin\r
+   import mechanism. Cache the result in path_importer_cache.\r
+   Returns a borrowed reference. */\r
+\r
+static PyObject *\r
+get_path_importer(PyObject *path_importer_cache, PyObject *path_hooks,\r
+                  PyObject *p)\r
+{\r
+    PyObject *importer;\r
+    Py_ssize_t j, nhooks;\r
+\r
+    /* These conditions are the caller's responsibility: */\r
+    assert(PyList_Check(path_hooks));\r
+    assert(PyDict_Check(path_importer_cache));\r
+\r
+    nhooks = PyList_Size(path_hooks);\r
+    if (nhooks < 0)\r
+        return NULL; /* Shouldn't happen */\r
+\r
+    importer = PyDict_GetItem(path_importer_cache, p);\r
+    if (importer != NULL)\r
+        return importer;\r
+\r
+    /* set path_importer_cache[p] to None to avoid recursion */\r
+    if (PyDict_SetItem(path_importer_cache, p, Py_None) != 0)\r
+        return NULL;\r
+\r
+    for (j = 0; j < nhooks; j++) {\r
+        PyObject *hook = PyList_GetItem(path_hooks, j);\r
+        if (hook == NULL)\r
+            return NULL;\r
+        importer = PyObject_CallFunctionObjArgs(hook, p, NULL);\r
+        if (importer != NULL)\r
+            break;\r
+\r
+        if (!PyErr_ExceptionMatches(PyExc_ImportError)) {\r
+            return NULL;\r
+        }\r
+        PyErr_Clear();\r
+    }\r
+    if (importer == NULL) {\r
+        importer = PyObject_CallFunctionObjArgs(\r
+            (PyObject *)&PyNullImporter_Type, p, NULL\r
+        );\r
+        if (importer == NULL) {\r
+            if (PyErr_ExceptionMatches(PyExc_ImportError)) {\r
+                PyErr_Clear();\r
+                return Py_None;\r
+            }\r
+        }\r
+    }\r
+    if (importer != NULL) {\r
+        int err = PyDict_SetItem(path_importer_cache, p, importer);\r
+        Py_DECREF(importer);\r
+        if (err != 0)\r
+            return NULL;\r
+    }\r
+    return importer;\r
+}\r
+\r
+PyAPI_FUNC(PyObject *)\r
+PyImport_GetImporter(PyObject *path) {\r
+    PyObject *importer=NULL, *path_importer_cache=NULL, *path_hooks=NULL;\r
+\r
+    if ((path_importer_cache = PySys_GetObject("path_importer_cache"))) {\r
+        if ((path_hooks = PySys_GetObject("path_hooks"))) {\r
+            importer = get_path_importer(path_importer_cache,\r
+                                         path_hooks, path);\r
+        }\r
+    }\r
+    Py_XINCREF(importer); /* get_path_importer returns a borrowed reference */\r
+    return importer;\r
+}\r
+\r
+/* Search the path (default sys.path) for a module.  Return the\r
+   corresponding filedescr struct, and (via return arguments) the\r
+   pathname and an open file.  Return NULL if the module is not found. */\r
+\r
+#ifdef MS_COREDLL\r
+extern FILE *PyWin_FindRegisteredModule(const char *, struct filedescr **,\r
+                                        char *, Py_ssize_t);\r
+#endif\r
+\r
+static int case_ok(char *, Py_ssize_t, Py_ssize_t, char *);\r
+static int find_init_module(char *); /* Forward */\r
+static struct filedescr importhookdescr = {"", "", IMP_HOOK};\r
+\r
+static struct filedescr *\r
+find_module(char *fullname, char *subname, PyObject *path, char *buf,\r
+            size_t buflen, FILE **p_fp, PyObject **p_loader)\r
+{\r
+    Py_ssize_t i, npath;\r
+    size_t len, namelen;\r
+    struct filedescr *fdp = NULL;\r
+    char *filemode;\r
+    FILE *fp = NULL;\r
+    PyObject *path_hooks, *path_importer_cache;\r
+    static struct filedescr fd_frozen = {"", "", PY_FROZEN};\r
+    static struct filedescr fd_builtin = {"", "", C_BUILTIN};\r
+    static struct filedescr fd_package = {"", "", PKG_DIRECTORY};\r
+    char *name;\r
+#if defined(PYOS_OS2)\r
+    size_t saved_len;\r
+    size_t saved_namelen;\r
+    char *saved_buf = NULL;\r
+#endif\r
+    if (p_loader != NULL)\r
+        *p_loader = NULL;\r
+\r
+    if (strlen(subname) > MAXPATHLEN) {\r
+        PyErr_SetString(PyExc_OverflowError,\r
+                        "module name is too long");\r
+        return NULL;\r
+    }\r
+    name = PyMem_MALLOC(MAXPATHLEN+1);\r
+    if (name == NULL) {\r
+        PyErr_NoMemory();\r
+        return NULL;\r
+    }\r
+    strcpy(name, subname);\r
+\r
+    /* sys.meta_path import hook */\r
+    if (p_loader != NULL) {\r
+        PyObject *meta_path;\r
+\r
+        meta_path = PySys_GetObject("meta_path");\r
+        if (meta_path == NULL || !PyList_Check(meta_path)) {\r
+            PyErr_SetString(PyExc_RuntimeError,\r
+                            "sys.meta_path must be a list of "\r
+                            "import hooks");\r
+            goto error_exit;\r
+        }\r
+        Py_INCREF(meta_path);  /* zap guard */\r
+        npath = PyList_Size(meta_path);\r
+        for (i = 0; i < npath; i++) {\r
+            PyObject *loader;\r
+            PyObject *hook = PyList_GetItem(meta_path, i);\r
+            loader = PyObject_CallMethod(hook, "find_module",\r
+                                         "sO", fullname,\r
+                                         path != NULL ?\r
+                                         path : Py_None);\r
+            if (loader == NULL) {\r
+                Py_DECREF(meta_path);\r
+                goto error_exit;  /* true error */\r
+            }\r
+            if (loader != Py_None) {\r
+                /* a loader was found */\r
+                *p_loader = loader;\r
+                Py_DECREF(meta_path);\r
+                PyMem_FREE(name);\r
+                return &importhookdescr;\r
+            }\r
+            Py_DECREF(loader);\r
+        }\r
+        Py_DECREF(meta_path);\r
+    }\r
+\r
+    if (path != NULL && PyString_Check(path)) {\r
+        /* The only type of submodule allowed inside a "frozen"\r
+           package are other frozen modules or packages. */\r
+        if (PyString_Size(path) + 1 + strlen(name) >= (size_t)buflen) {\r
+            PyErr_SetString(PyExc_ImportError,\r
+                            "full frozen module name too long");\r
+            goto error_exit;\r
+        }\r
+        strcpy(buf, PyString_AsString(path));\r
+        strcat(buf, ".");\r
+        strcat(buf, name);\r
+        strcpy(name, buf);\r
+        if (find_frozen(name) != NULL) {\r
+            strcpy(buf, name);\r
+            PyMem_FREE(name);\r
+            return &fd_frozen;\r
+        }\r
+        PyErr_Format(PyExc_ImportError,\r
+                     "No frozen submodule named %.200s", name);\r
+        goto error_exit;\r
+    }\r
+    if (path == NULL) {\r
+        if (is_builtin(name)) {\r
+            strcpy(buf, name);\r
+            PyMem_FREE(name);\r
+            return &fd_builtin;\r
+        }\r
+        if ((find_frozen(name)) != NULL) {\r
+            strcpy(buf, name);\r
+            PyMem_FREE(name);\r
+            return &fd_frozen;\r
+        }\r
+\r
+#ifdef MS_COREDLL\r
+        fp = PyWin_FindRegisteredModule(name, &fdp, buf, buflen);\r
+        if (fp != NULL) {\r
+            *p_fp = fp;\r
+            PyMem_FREE(name);\r
+            return fdp;\r
+        }\r
+#endif\r
+        path = PySys_GetObject("path");\r
+    }\r
+    if (path == NULL || !PyList_Check(path)) {\r
+        PyErr_SetString(PyExc_RuntimeError,\r
+                        "sys.path must be a list of directory names");\r
+        goto error_exit;\r
+    }\r
+\r
+    path_hooks = PySys_GetObject("path_hooks");\r
+    if (path_hooks == NULL || !PyList_Check(path_hooks)) {\r
+        PyErr_SetString(PyExc_RuntimeError,\r
+                        "sys.path_hooks must be a list of "\r
+                        "import hooks");\r
+        goto error_exit;\r
+    }\r
+    path_importer_cache = PySys_GetObject("path_importer_cache");\r
+    if (path_importer_cache == NULL ||\r
+        !PyDict_Check(path_importer_cache)) {\r
+        PyErr_SetString(PyExc_RuntimeError,\r
+                        "sys.path_importer_cache must be a dict");\r
+        goto error_exit;\r
+    }\r
+\r
+    npath = PyList_Size(path);\r
+    namelen = strlen(name);\r
+    for (i = 0; i < npath; i++) {\r
+        PyObject *copy = NULL;\r
+        PyObject *v = PyList_GetItem(path, i);\r
+        if (!v)\r
+            goto error_exit;\r
+#ifdef Py_USING_UNICODE\r
+        if (PyUnicode_Check(v)) {\r
+            copy = PyUnicode_Encode(PyUnicode_AS_UNICODE(v),\r
+                PyUnicode_GET_SIZE(v), Py_FileSystemDefaultEncoding, NULL);\r
+            if (copy == NULL)\r
+                goto error_exit;\r
+            v = copy;\r
+        }\r
+        else\r
+#endif\r
+        if (!PyString_Check(v))\r
+            continue;\r
+        len = PyString_GET_SIZE(v);\r
+        if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) {\r
+            Py_XDECREF(copy);\r
+            continue; /* Too long */\r
+        }\r
+        strcpy(buf, PyString_AS_STRING(v));\r
+        if (strlen(buf) != len) {\r
+            Py_XDECREF(copy);\r
+            continue; /* v contains '\0' */\r
+        }\r
+\r
+        /* sys.path_hooks import hook */\r
+        if (p_loader != NULL) {\r
+            PyObject *importer;\r
+\r
+            importer = get_path_importer(path_importer_cache,\r
+                                         path_hooks, v);\r
+            if (importer == NULL) {\r
+                Py_XDECREF(copy);\r
+                goto error_exit;\r
+            }\r
+            /* Note: importer is a borrowed reference */\r
+            if (importer != Py_None) {\r
+                PyObject *loader;\r
+                loader = PyObject_CallMethod(importer,\r
+                                             "find_module",\r
+                                             "s", fullname);\r
+                Py_XDECREF(copy);\r
+                if (loader == NULL)\r
+                    goto error_exit;  /* error */\r
+                if (loader != Py_None) {\r
+                    /* a loader was found */\r
+                    *p_loader = loader;\r
+                    PyMem_FREE(name);\r
+                    return &importhookdescr;\r
+                }\r
+                Py_DECREF(loader);\r
+                continue;\r
+            }\r
+        }\r
+        /* no hook was found, use builtin import */\r
+\r
+        if (len > 0 && buf[len-1] != SEP\r
+#ifdef ALTSEP\r
+            && buf[len-1] != ALTSEP\r
+#endif\r
+            )\r
+            buf[len++] = SEP;\r
+        strcpy(buf+len, name);\r
+        len += namelen;\r
+\r
+        /* Check for package import (buf holds a directory name,\r
+           and there's an __init__ module in that directory */\r
+        if (isdir(buf) &&         /* it's an existing directory */\r
+            case_ok(buf, len, namelen, name)) { /* case matches */\r
+            if (find_init_module(buf)) { /* and has __init__.py */\r
+                Py_XDECREF(copy);\r
+                PyMem_FREE(name);\r
+                return &fd_package;\r
+            }\r
+            else {\r
+                char warnstr[MAXPATHLEN+80];\r
+                sprintf(warnstr, "Not importing directory "\r
+                    "'%.*s': missing __init__.py",\r
+                    MAXPATHLEN, buf);\r
+                if (PyErr_Warn(PyExc_ImportWarning,\r
+                               warnstr)) {\r
+                    Py_XDECREF(copy);\r
+                    goto error_exit;\r
+                }\r
+            }\r
+        }\r
+#if defined(PYOS_OS2)\r
+        /* take a snapshot of the module spec for restoration\r
+         * after the 8 character DLL hackery\r
+         */\r
+        saved_buf = strdup(buf);\r
+        saved_len = len;\r
+        saved_namelen = namelen;\r
+#endif /* PYOS_OS2 */\r
+        for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {\r
+#if defined(PYOS_OS2) && defined(HAVE_DYNAMIC_LOADING)\r
+            /* OS/2 limits DLLs to 8 character names (w/o\r
+               extension)\r
+             * so if the name is longer than that and its a\r
+             * dynamically loaded module we're going to try,\r
+             * truncate the name before trying\r
+             */\r
+            if (strlen(subname) > 8) {\r
+                /* is this an attempt to load a C extension? */\r
+                const struct filedescr *scan;\r
+                scan = _PyImport_DynLoadFiletab;\r
+                while (scan->suffix != NULL) {\r
+                    if (!strcmp(scan->suffix, fdp->suffix))\r
+                        break;\r
+                    else\r
+                        scan++;\r
+                }\r
+                if (scan->suffix != NULL) {\r
+                    /* yes, so truncate the name */\r
+                    namelen = 8;\r
+                    len -= strlen(subname) - namelen;\r
+                    buf[len] = '\0';\r
+                }\r
+            }\r
+#endif /* PYOS_OS2 */\r
+            strcpy(buf+len, fdp->suffix);\r
+            if (Py_VerboseFlag > 1)\r
+                PySys_WriteStderr("# trying %s\n", buf);\r
+            filemode = fdp->mode;\r
+            if (filemode[0] == 'U')\r
+                filemode = "r" PY_STDIOTEXTMODE;\r
+            fp = fopen(buf, filemode);\r
+            if (fp != NULL) {\r
+                if (case_ok(buf, len, namelen, name))\r
+                    break;\r
+                else {                   /* continue search */\r
+                    fclose(fp);\r
+                    fp = NULL;\r
+                }\r
+            }\r
+#if defined(PYOS_OS2)\r
+            /* restore the saved snapshot */\r
+            strcpy(buf, saved_buf);\r
+            len = saved_len;\r
+            namelen = saved_namelen;\r
+#endif\r
+        }\r
+#if defined(PYOS_OS2)\r
+        /* don't need/want the module name snapshot anymore */\r
+        if (saved_buf)\r
+        {\r
+            free(saved_buf);\r
+            saved_buf = NULL;\r
+        }\r
+#endif\r
+        Py_XDECREF(copy);\r
+        if (fp != NULL)\r
+            break;\r
+    }\r
+    if (fp == NULL) {\r
+        PyErr_Format(PyExc_ImportError,\r
+                     "No module named %.200s", name);\r
+        goto error_exit;\r
+    }\r
+    *p_fp = fp;\r
+    PyMem_FREE(name);\r
+    return fdp;\r
+\r
+error_exit:\r
+    PyMem_FREE(name);\r
+    return NULL;\r
+}\r
+\r
+/* Helpers for main.c\r
+ *  Find the source file corresponding to a named module\r
+ */\r
+struct filedescr *\r
+_PyImport_FindModule(const char *name, PyObject *path, char *buf,\r
+            size_t buflen, FILE **p_fp, PyObject **p_loader)\r
+{\r
+    return find_module((char *) name, (char *) name, path,\r
+                       buf, buflen, p_fp, p_loader);\r
+}\r
+\r
+PyAPI_FUNC(int) _PyImport_IsScript(struct filedescr * fd)\r
+{\r
+    return fd->type == PY_SOURCE || fd->type == PY_COMPILED;\r
+}\r
+\r
+/* case_ok(char* buf, Py_ssize_t len, Py_ssize_t namelen, char* name)\r
+ * The arguments here are tricky, best shown by example:\r
+ *    /a/b/c/d/e/f/g/h/i/j/k/some_long_module_name.py\0\r
+ *    ^                      ^                   ^    ^\r
+ *    |--------------------- buf ---------------------|\r
+ *    |------------------- len ------------------|\r
+ *                           |------ name -------|\r
+ *                           |----- namelen -----|\r
+ * buf is the full path, but len only counts up to (& exclusive of) the\r
+ * extension.  name is the module name, also exclusive of extension.\r
+ *\r
+ * We've already done a successful stat() or fopen() on buf, so know that\r
+ * there's some match, possibly case-insensitive.\r
+ *\r
+ * case_ok() is to return 1 if there's a case-sensitive match for\r
+ * name, else 0.  case_ok() is also to return 1 if envar PYTHONCASEOK\r
+ * exists.\r
+ *\r
+ * case_ok() is used to implement case-sensitive import semantics even\r
+ * on platforms with case-insensitive filesystems.  It's trivial to implement\r
+ * for case-sensitive filesystems.  It's pretty much a cross-platform\r
+ * nightmare for systems with case-insensitive filesystems.\r
+ */\r
+\r
+/* First we may need a pile of platform-specific header files; the sequence\r
+ * of #if's here should match the sequence in the body of case_ok().\r
+ */\r
+#if defined(MS_WINDOWS)\r
+#include <windows.h>\r
+\r
+#elif defined(DJGPP)\r
+#include <dir.h>\r
+\r
+#elif (defined(__MACH__) && defined(__APPLE__) || defined(__CYGWIN__)) && defined(HAVE_DIRENT_H)\r
+#include <sys/types.h>\r
+#include <dirent.h>\r
+\r
+#elif defined(PYOS_OS2)\r
+#define INCL_DOS\r
+#define INCL_DOSERRORS\r
+#define INCL_NOPMAPI\r
+#include <os2.h>\r
+\r
+#elif defined(RISCOS)\r
+#include "oslib/osfscontrol.h"\r
+#endif\r
+\r
+static int\r
+case_ok(char *buf, Py_ssize_t len, Py_ssize_t namelen, char *name)\r
+{\r
+/* Pick a platform-specific implementation; the sequence of #if's here should\r
+ * match the sequence just above.\r
+ */\r
+\r
+/* MS_WINDOWS */\r
+#if defined(MS_WINDOWS)\r
+    WIN32_FIND_DATA data;\r
+    HANDLE h;\r
+\r
+    if (Py_GETENV("PYTHONCASEOK") != NULL)\r
+        return 1;\r
+\r
+    h = FindFirstFile(buf, &data);\r
+    if (h == INVALID_HANDLE_VALUE) {\r
+        PyErr_Format(PyExc_NameError,\r
+          "Can't find file for module %.100s\n(filename %.300s)",\r
+          name, buf);\r
+        return 0;\r
+    }\r
+    FindClose(h);\r
+    return strncmp(data.cFileName, name, namelen) == 0;\r
+\r
+/* DJGPP */\r
+#elif defined(DJGPP)\r
+    struct ffblk ffblk;\r
+    int done;\r
+\r
+    if (Py_GETENV("PYTHONCASEOK") != NULL)\r
+        return 1;\r
+\r
+    done = findfirst(buf, &ffblk, FA_ARCH|FA_RDONLY|FA_HIDDEN|FA_DIREC);\r
+    if (done) {\r
+        PyErr_Format(PyExc_NameError,\r
+          "Can't find file for module %.100s\n(filename %.300s)",\r
+          name, buf);\r
+        return 0;\r
+    }\r
+    return strncmp(ffblk.ff_name, name, namelen) == 0;\r
+\r
+/* new-fangled macintosh (macosx) or Cygwin */\r
+#elif (defined(__MACH__) && defined(__APPLE__) || defined(__CYGWIN__)) && defined(HAVE_DIRENT_H)\r
+    DIR *dirp;\r
+    struct dirent *dp;\r
+    char dirname[MAXPATHLEN + 1];\r
+    const int dirlen = len - namelen - 1; /* don't want trailing SEP */\r
+\r
+    if (Py_GETENV("PYTHONCASEOK") != NULL)\r
+        return 1;\r
+\r
+    /* Copy the dir component into dirname; substitute "." if empty */\r
+    if (dirlen <= 0) {\r
+        dirname[0] = '.';\r
+        dirname[1] = '\0';\r
+    }\r
+    else {\r
+        assert(dirlen <= MAXPATHLEN);\r
+        memcpy(dirname, buf, dirlen);\r
+        dirname[dirlen] = '\0';\r
+    }\r
+    /* Open the directory and search the entries for an exact match. */\r
+    dirp = opendir(dirname);\r
+    if (dirp) {\r
+        char *nameWithExt = buf + len - namelen;\r
+        while ((dp = readdir(dirp)) != NULL) {\r
+            const int thislen =\r
+#ifdef _DIRENT_HAVE_D_NAMELEN\r
+                                    dp->d_namlen;\r
+#else\r
+                                    strlen(dp->d_name);\r
+#endif\r
+            if (thislen >= namelen &&\r
+                strcmp(dp->d_name, nameWithExt) == 0) {\r
+                (void)closedir(dirp);\r
+                return 1; /* Found */\r
+            }\r
+        }\r
+        (void)closedir(dirp);\r
+    }\r
+    return 0 ; /* Not found */\r
+\r
+/* RISC OS */\r
+#elif defined(RISCOS)\r
+    char canon[MAXPATHLEN+1]; /* buffer for the canonical form of the path */\r
+    char buf2[MAXPATHLEN+2];\r
+    char *nameWithExt = buf+len-namelen;\r
+    int canonlen;\r
+    os_error *e;\r
+\r
+    if (Py_GETENV("PYTHONCASEOK") != NULL)\r
+        return 1;\r
+\r
+    /* workaround:\r
+       append wildcard, otherwise case of filename wouldn't be touched */\r
+    strcpy(buf2, buf);\r
+    strcat(buf2, "*");\r
+\r
+    e = xosfscontrol_canonicalise_path(buf2,canon,0,0,MAXPATHLEN+1,&canonlen);\r
+    canonlen = MAXPATHLEN+1-canonlen;\r
+    if (e || canonlen<=0 || canonlen>(MAXPATHLEN+1) )\r
+        return 0;\r
+    if (strcmp(nameWithExt, canon+canonlen-strlen(nameWithExt))==0)\r
+        return 1; /* match */\r
+\r
+    return 0;\r
+\r
+/* OS/2 */\r
+#elif defined(PYOS_OS2)\r
+    HDIR hdir = 1;\r
+    ULONG srchcnt = 1;\r
+    FILEFINDBUF3 ffbuf;\r
+    APIRET rc;\r
+\r
+    if (Py_GETENV("PYTHONCASEOK") != NULL)\r
+        return 1;\r
+\r
+    rc = DosFindFirst(buf,\r
+                      &hdir,\r
+                      FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY,\r
+                      &ffbuf, sizeof(ffbuf),\r
+                      &srchcnt,\r
+                      FIL_STANDARD);\r
+    if (rc != NO_ERROR)\r
+        return 0;\r
+    return strncmp(ffbuf.achName, name, namelen) == 0;\r
+\r
+/* assuming it's a case-sensitive filesystem, so there's nothing to do! */\r
+#else\r
+    return 1;\r
+\r
+#endif\r
+}\r
+\r
+\r
+#ifdef HAVE_STAT\r
+/* Helper to look for __init__.py or __init__.py[co] in potential package */\r
+static int\r
+find_init_module(char *buf)\r
+{\r
+    const size_t save_len = strlen(buf);\r
+    size_t i = save_len;\r
+    char *pname;  /* pointer to start of __init__ */\r
+    struct stat statbuf;\r
+\r
+/*      For calling case_ok(buf, len, namelen, name):\r
+ *      /a/b/c/d/e/f/g/h/i/j/k/some_long_module_name.py\0\r
+ *      ^                      ^                   ^    ^\r
+ *      |--------------------- buf ---------------------|\r
+ *      |------------------- len ------------------|\r
+ *                             |------ name -------|\r
+ *                             |----- namelen -----|\r
+ */\r
+    if (save_len + 13 >= MAXPATHLEN)\r
+        return 0;\r
+    buf[i++] = SEP;\r
+    pname = buf + i;\r
+    strcpy(pname, "__init__.py");\r
+    if (stat(buf, &statbuf) == 0) {\r
+        if (case_ok(buf,\r
+                    save_len + 9,               /* len("/__init__") */\r
+                8,                              /* len("__init__") */\r
+                pname)) {\r
+            buf[save_len] = '\0';\r
+            return 1;\r
+        }\r
+    }\r
+    i += strlen(pname);\r
+    strcpy(buf+i, Py_OptimizeFlag ? "o" : "c");\r
+    if (stat(buf, &statbuf) == 0) {\r
+        if (case_ok(buf,\r
+                    save_len + 9,               /* len("/__init__") */\r
+                8,                              /* len("__init__") */\r
+                pname)) {\r
+            buf[save_len] = '\0';\r
+            return 1;\r
+        }\r
+    }\r
+    buf[save_len] = '\0';\r
+    return 0;\r
+}\r
+\r
+#else\r
+\r
+#ifdef RISCOS\r
+static int\r
+find_init_module(buf)\r
+    char *buf;\r
+{\r
+    int save_len = strlen(buf);\r
+    int i = save_len;\r
+\r
+    if (save_len + 13 >= MAXPATHLEN)\r
+        return 0;\r
+    buf[i++] = SEP;\r
+    strcpy(buf+i, "__init__/py");\r
+    if (isfile(buf)) {\r
+        buf[save_len] = '\0';\r
+        return 1;\r
+    }\r
+\r
+    if (Py_OptimizeFlag)\r
+        strcpy(buf+i, "o");\r
+    else\r
+        strcpy(buf+i, "c");\r
+    if (isfile(buf)) {\r
+        buf[save_len] = '\0';\r
+        return 1;\r
+    }\r
+    buf[save_len] = '\0';\r
+    return 0;\r
+}\r
+#endif /*RISCOS*/\r
+\r
+#endif /* HAVE_STAT */\r
+\r
+\r
+static int init_builtin(char *); /* Forward */\r
+\r
+/* Load an external module using the default search path and return\r
+   its module object WITH INCREMENTED REFERENCE COUNT */\r
+\r
+static PyObject *\r
+load_module(char *name, FILE *fp, char *pathname, int type, PyObject *loader)\r
+{\r
+    PyObject *modules;\r
+    PyObject *m;\r
+    int err;\r
+\r
+    /* First check that there's an open file (if we need one)  */\r
+    switch (type) {\r
+    case PY_SOURCE:\r
+    case PY_COMPILED:\r
+        if (fp == NULL) {\r
+            PyErr_Format(PyExc_ValueError,\r
+               "file object required for import (type code %d)",\r
+                         type);\r
+            return NULL;\r
+        }\r
+    }\r
+\r
+    switch (type) {\r
+\r
+    case PY_SOURCE:\r
+        m = load_source_module(name, pathname, fp);\r
+        break;\r
+\r
+    case PY_COMPILED:\r
+        m = load_compiled_module(name, pathname, fp);\r
+        break;\r
+\r
+#ifdef HAVE_DYNAMIC_LOADING\r
+    case C_EXTENSION:\r
+        m = _PyImport_LoadDynamicModule(name, pathname, fp);\r
+        break;\r
+#endif\r
+\r
+    case PKG_DIRECTORY:\r
+        m = load_package(name, pathname);\r
+        break;\r
+\r
+    case C_BUILTIN:\r
+    case PY_FROZEN:\r
+        if (pathname != NULL && pathname[0] != '\0')\r
+            name = pathname;\r
+        if (type == C_BUILTIN)\r
+            err = init_builtin(name);\r
+        else\r
+            err = PyImport_ImportFrozenModule(name);\r
+        if (err < 0)\r
+            return NULL;\r
+        if (err == 0) {\r
+            PyErr_Format(PyExc_ImportError,\r
+                         "Purported %s module %.200s not found",\r
+                         type == C_BUILTIN ?\r
+                                    "builtin" : "frozen",\r
+                         name);\r
+            return NULL;\r
+        }\r
+        modules = PyImport_GetModuleDict();\r
+        m = PyDict_GetItemString(modules, name);\r
+        if (m == NULL) {\r
+            PyErr_Format(\r
+                PyExc_ImportError,\r
+                "%s module %.200s not properly initialized",\r
+                type == C_BUILTIN ?\r
+                    "builtin" : "frozen",\r
+                name);\r
+            return NULL;\r
+        }\r
+        Py_INCREF(m);\r
+        break;\r
+\r
+    case IMP_HOOK: {\r
+        if (loader == NULL) {\r
+            PyErr_SetString(PyExc_ImportError,\r
+                            "import hook without loader");\r
+            return NULL;\r
+        }\r
+        m = PyObject_CallMethod(loader, "load_module", "s", name);\r
+        break;\r
+    }\r
+\r
+    default:\r
+        PyErr_Format(PyExc_ImportError,\r
+                     "Don't know how to import %.200s (type code %d)",\r
+                      name, type);\r
+        m = NULL;\r
+\r
+    }\r
+\r
+    return m;\r
+}\r
+\r
+\r
+/* Initialize a built-in module.\r
+   Return 1 for success, 0 if the module is not found, and -1 with\r
+   an exception set if the initialization failed. */\r
+\r
+static int\r
+init_builtin(char *name)\r
+{\r
+    struct _inittab *p;\r
+\r
+    if (_PyImport_FindExtension(name, name) != NULL)\r
+        return 1;\r
+\r
+    for (p = PyImport_Inittab; p->name != NULL; p++) {\r
+        if (strcmp(name, p->name) == 0) {\r
+            if (p->initfunc == NULL) {\r
+                PyErr_Format(PyExc_ImportError,\r
+                    "Cannot re-init internal module %.200s",\r
+                    name);\r
+                return -1;\r
+            }\r
+            if (Py_VerboseFlag)\r
+                PySys_WriteStderr("import %s # builtin\n", name);\r
+            (*p->initfunc)();\r
+            if (PyErr_Occurred())\r
+                return -1;\r
+            if (_PyImport_FixupExtension(name, name) == NULL)\r
+                return -1;\r
+            return 1;\r
+        }\r
+    }\r
+    return 0;\r
+}\r
+\r
+\r
+/* Frozen modules */\r
+\r
+static struct _frozen *\r
+find_frozen(char *name)\r
+{\r
+    struct _frozen *p;\r
+\r
+    for (p = PyImport_FrozenModules; ; p++) {\r
+        if (p->name == NULL)\r
+            return NULL;\r
+        if (strcmp(p->name, name) == 0)\r
+            break;\r
+    }\r
+    return p;\r
+}\r
+\r
+static PyObject *\r
+get_frozen_object(char *name)\r
+{\r
+    struct _frozen *p = find_frozen(name);\r
+    int size;\r
+\r
+    if (p == NULL) {\r
+        PyErr_Format(PyExc_ImportError,\r
+                     "No such frozen object named %.200s",\r
+                     name);\r
+        return NULL;\r
+    }\r
+    if (p->code == NULL) {\r
+        PyErr_Format(PyExc_ImportError,\r
+                     "Excluded frozen object named %.200s",\r
+                     name);\r
+        return NULL;\r
+    }\r
+    size = p->size;\r
+    if (size < 0)\r
+        size = -size;\r
+    return PyMarshal_ReadObjectFromString((char *)p->code, size);\r
+}\r
+\r
+/* Initialize a frozen module.\r
+   Return 1 for succes, 0 if the module is not found, and -1 with\r
+   an exception set if the initialization failed.\r
+   This function is also used from frozenmain.c */\r
+\r
+int\r
+PyImport_ImportFrozenModule(char *name)\r
+{\r
+    struct _frozen *p = find_frozen(name);\r
+    PyObject *co;\r
+    PyObject *m;\r
+    int ispackage;\r
+    int size;\r
+\r
+    if (p == NULL)\r
+        return 0;\r
+    if (p->code == NULL) {\r
+        PyErr_Format(PyExc_ImportError,\r
+                     "Excluded frozen object named %.200s",\r
+                     name);\r
+        return -1;\r
+    }\r
+    size = p->size;\r
+    ispackage = (size < 0);\r
+    if (ispackage)\r
+        size = -size;\r
+    if (Py_VerboseFlag)\r
+        PySys_WriteStderr("import %s # frozen%s\n",\r
+            name, ispackage ? " package" : "");\r
+    co = PyMarshal_ReadObjectFromString((char *)p->code, size);\r
+    if (co == NULL)\r
+        return -1;\r
+    if (!PyCode_Check(co)) {\r
+        PyErr_Format(PyExc_TypeError,\r
+                     "frozen object %.200s is not a code object",\r
+                     name);\r
+        goto err_return;\r
+    }\r
+    if (ispackage) {\r
+        /* Set __path__ to the package name */\r
+        PyObject *d, *s;\r
+        int err;\r
+        m = PyImport_AddModule(name);\r
+        if (m == NULL)\r
+            goto err_return;\r
+        d = PyModule_GetDict(m);\r
+        s = PyString_InternFromString(name);\r
+        if (s == NULL)\r
+            goto err_return;\r
+        err = PyDict_SetItemString(d, "__path__", s);\r
+        Py_DECREF(s);\r
+        if (err != 0)\r
+            goto err_return;\r
+    }\r
+    m = PyImport_ExecCodeModuleEx(name, co, "<frozen>");\r
+    if (m == NULL)\r
+        goto err_return;\r
+    Py_DECREF(co);\r
+    Py_DECREF(m);\r
+    return 1;\r
+err_return:\r
+    Py_DECREF(co);\r
+    return -1;\r
+}\r
+\r
+\r
+/* Import a module, either built-in, frozen, or external, and return\r
+   its module object WITH INCREMENTED REFERENCE COUNT */\r
+\r
+PyObject *\r
+PyImport_ImportModule(const char *name)\r
+{\r
+    PyObject *pname;\r
+    PyObject *result;\r
+\r
+    pname = PyString_FromString(name);\r
+    if (pname == NULL)\r
+        return NULL;\r
+    result = PyImport_Import(pname);\r
+    Py_DECREF(pname);\r
+    return result;\r
+}\r
+\r
+/* Import a module without blocking\r
+ *\r
+ * At first it tries to fetch the module from sys.modules. If the module was\r
+ * never loaded before it loads it with PyImport_ImportModule() unless another\r
+ * thread holds the import lock. In the latter case the function raises an\r
+ * ImportError instead of blocking.\r
+ *\r
+ * Returns the module object with incremented ref count.\r
+ */\r
+PyObject *\r
+PyImport_ImportModuleNoBlock(const char *name)\r
+{\r
+    PyObject *result;\r
+    PyObject *modules;\r
+#ifdef WITH_THREAD\r
+    long me;\r
+#endif\r
+\r
+    /* Try to get the module from sys.modules[name] */\r
+    modules = PyImport_GetModuleDict();\r
+    if (modules == NULL)\r
+        return NULL;\r
+\r
+    result = PyDict_GetItemString(modules, name);\r
+    if (result != NULL) {\r
+        Py_INCREF(result);\r
+        return result;\r
+    }\r
+    else {\r
+        PyErr_Clear();\r
+    }\r
+#ifdef WITH_THREAD\r
+    /* check the import lock\r
+     * me might be -1 but I ignore the error here, the lock function\r
+     * takes care of the problem */\r
+    me = PyThread_get_thread_ident();\r
+    if (import_lock_thread == -1 || import_lock_thread == me) {\r
+        /* no thread or me is holding the lock */\r
+        return PyImport_ImportModule(name);\r
+    }\r
+    else {\r
+        PyErr_Format(PyExc_ImportError,\r
+                     "Failed to import %.200s because the import lock"\r
+                     "is held by another thread.",\r
+                     name);\r
+        return NULL;\r
+    }\r
+#else\r
+    return PyImport_ImportModule(name);\r
+#endif\r
+}\r
+\r
+/* Forward declarations for helper routines */\r
+static PyObject *get_parent(PyObject *globals, char *buf,\r
+                            Py_ssize_t *p_buflen, int level);\r
+static PyObject *load_next(PyObject *mod, PyObject *altmod,\r
+                           char **p_name, char *buf, Py_ssize_t *p_buflen);\r
+static int mark_miss(char *name);\r
+static int ensure_fromlist(PyObject *mod, PyObject *fromlist,\r
+                           char *buf, Py_ssize_t buflen, int recursive);\r
+static PyObject * import_submodule(PyObject *mod, char *name, char *fullname);\r
+\r
+/* The Magnum Opus of dotted-name import :-) */\r
+\r
+static PyObject *\r
+import_module_level(char *name, PyObject *globals, PyObject *locals,\r
+                    PyObject *fromlist, int level)\r
+{\r
+    char *buf;\r
+    Py_ssize_t buflen = 0;\r
+    PyObject *parent, *head, *next, *tail;\r
+\r
+    if (strchr(name, '/') != NULL\r
+#ifdef MS_WINDOWS\r
+        || strchr(name, '\\') != NULL\r
+#endif\r
+        ) {\r
+        PyErr_SetString(PyExc_ImportError,\r
+                        "Import by filename is not supported.");\r
+        return NULL;\r
+    }\r
+\r
+    buf = PyMem_MALLOC(MAXPATHLEN+1);\r
+    if (buf == NULL) {\r
+        return PyErr_NoMemory();\r
+    }\r
+    parent = get_parent(globals, buf, &buflen, level);\r
+    if (parent == NULL)\r
+        goto error_exit;\r
+\r
+    head = load_next(parent, level < 0 ? Py_None : parent, &name, buf,\r
+                        &buflen);\r
+    if (head == NULL)\r
+        goto error_exit;\r
+\r
+    tail = head;\r
+    Py_INCREF(tail);\r
+    while (name) {\r
+        next = load_next(tail, tail, &name, buf, &buflen);\r
+        Py_DECREF(tail);\r
+        if (next == NULL) {\r
+            Py_DECREF(head);\r
+            goto error_exit;\r
+        }\r
+        tail = next;\r
+    }\r
+    if (tail == Py_None) {\r
+        /* If tail is Py_None, both get_parent and load_next found\r
+           an empty module name: someone called __import__("") or\r
+           doctored faulty bytecode */\r
+        Py_DECREF(tail);\r
+        Py_DECREF(head);\r
+        PyErr_SetString(PyExc_ValueError,\r
+                        "Empty module name");\r
+        goto error_exit;\r
+    }\r
+\r
+    if (fromlist != NULL) {\r
+        int b = (fromlist == Py_None) ? 0 : PyObject_IsTrue(fromlist);\r
+        if (b < 0) {\r
+            Py_DECREF(tail);\r
+            Py_DECREF(head);\r
+            goto error_exit;\r
+        }\r
+        if (!b)\r
+            fromlist = NULL;\r
+    }\r
+\r
+    if (fromlist == NULL) {\r
+        Py_DECREF(tail);\r
+        PyMem_FREE(buf);\r
+        return head;\r
+    }\r
+\r
+    Py_DECREF(head);\r
+    if (!ensure_fromlist(tail, fromlist, buf, buflen, 0)) {\r
+        Py_DECREF(tail);\r
+        goto error_exit;\r
+    }\r
+\r
+    PyMem_FREE(buf);\r
+    return tail;\r
+\r
+error_exit:\r
+    PyMem_FREE(buf);\r
+    return NULL;\r
+}\r
+\r
+PyObject *\r
+PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals,\r
+                         PyObject *fromlist, int level)\r
+{\r
+    PyObject *result;\r
+    _PyImport_AcquireLock();\r
+    result = import_module_level(name, globals, locals, fromlist, level);\r
+    if (_PyImport_ReleaseLock() < 0) {\r
+        Py_XDECREF(result);\r
+        PyErr_SetString(PyExc_RuntimeError,\r
+                        "not holding the import lock");\r
+        return NULL;\r
+    }\r
+    return result;\r
+}\r
+\r
+/* Return the package that an import is being performed in.  If globals comes\r
+   from the module foo.bar.bat (not itself a package), this returns the\r
+   sys.modules entry for foo.bar.  If globals is from a package's __init__.py,\r
+   the package's entry in sys.modules is returned, as a borrowed reference.\r
+\r
+   The *name* of the returned package is returned in buf, with the length of\r
+   the name in *p_buflen.\r
+\r
+   If globals doesn't come from a package or a module in a package, or a\r
+   corresponding entry is not found in sys.modules, Py_None is returned.\r
+*/\r
+static PyObject *\r
+get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)\r
+{\r
+    static PyObject *namestr = NULL;\r
+    static PyObject *pathstr = NULL;\r
+    static PyObject *pkgstr = NULL;\r
+    PyObject *pkgname, *modname, *modpath, *modules, *parent;\r
+    int orig_level = level;\r
+\r
+    if (globals == NULL || !PyDict_Check(globals) || !level)\r
+        return Py_None;\r
+\r
+    if (namestr == NULL) {\r
+        namestr = PyString_InternFromString("__name__");\r
+        if (namestr == NULL)\r
+            return NULL;\r
+    }\r
+    if (pathstr == NULL) {\r
+        pathstr = PyString_InternFromString("__path__");\r
+        if (pathstr == NULL)\r
+            return NULL;\r
+    }\r
+    if (pkgstr == NULL) {\r
+        pkgstr = PyString_InternFromString("__package__");\r
+        if (pkgstr == NULL)\r
+            return NULL;\r
+    }\r
+\r
+    *buf = '\0';\r
+    *p_buflen = 0;\r
+    pkgname = PyDict_GetItem(globals, pkgstr);\r
+\r
+    if ((pkgname != NULL) && (pkgname != Py_None)) {\r
+        /* __package__ is set, so use it */\r
+        Py_ssize_t len;\r
+        if (!PyString_Check(pkgname)) {\r
+            PyErr_SetString(PyExc_ValueError,\r
+                            "__package__ set to non-string");\r
+            return NULL;\r
+        }\r
+        len = PyString_GET_SIZE(pkgname);\r
+        if (len == 0) {\r
+            if (level > 0) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                    "Attempted relative import in non-package");\r
+                return NULL;\r
+            }\r
+            return Py_None;\r
+        }\r
+        if (len > MAXPATHLEN) {\r
+            PyErr_SetString(PyExc_ValueError,\r
+                            "Package name too long");\r
+            return NULL;\r
+        }\r
+        strcpy(buf, PyString_AS_STRING(pkgname));\r
+    } else {\r
+        /* __package__ not set, so figure it out and set it */\r
+        modname = PyDict_GetItem(globals, namestr);\r
+        if (modname == NULL || !PyString_Check(modname))\r
+            return Py_None;\r
+\r
+        modpath = PyDict_GetItem(globals, pathstr);\r
+        if (modpath != NULL) {\r
+            /* __path__ is set, so modname is already the package name */\r
+            Py_ssize_t len = PyString_GET_SIZE(modname);\r
+            int error;\r
+            if (len > MAXPATHLEN) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "Module name too long");\r
+                return NULL;\r
+            }\r
+            strcpy(buf, PyString_AS_STRING(modname));\r
+            error = PyDict_SetItem(globals, pkgstr, modname);\r
+            if (error) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "Could not set __package__");\r
+                return NULL;\r
+            }\r
+        } else {\r
+            /* Normal module, so work out the package name if any */\r
+            char *start = PyString_AS_STRING(modname);\r
+            char *lastdot = strrchr(start, '.');\r
+            size_t len;\r
+            int error;\r
+            if (lastdot == NULL && level > 0) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                    "Attempted relative import in non-package");\r
+                return NULL;\r
+            }\r
+            if (lastdot == NULL) {\r
+                error = PyDict_SetItem(globals, pkgstr, Py_None);\r
+                if (error) {\r
+                    PyErr_SetString(PyExc_ValueError,\r
+                        "Could not set __package__");\r
+                    return NULL;\r
+                }\r
+                return Py_None;\r
+            }\r
+            len = lastdot - start;\r
+            if (len >= MAXPATHLEN) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "Module name too long");\r
+                return NULL;\r
+            }\r
+            strncpy(buf, start, len);\r
+            buf[len] = '\0';\r
+            pkgname = PyString_FromString(buf);\r
+            if (pkgname == NULL) {\r
+                return NULL;\r
+            }\r
+            error = PyDict_SetItem(globals, pkgstr, pkgname);\r
+            Py_DECREF(pkgname);\r
+            if (error) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "Could not set __package__");\r
+                return NULL;\r
+            }\r
+        }\r
+    }\r
+    while (--level > 0) {\r
+        char *dot = strrchr(buf, '.');\r
+        if (dot == NULL) {\r
+            PyErr_SetString(PyExc_ValueError,\r
+                "Attempted relative import beyond "\r
+                "toplevel package");\r
+            return NULL;\r
+        }\r
+        *dot = '\0';\r
+    }\r
+    *p_buflen = strlen(buf);\r
+\r
+    modules = PyImport_GetModuleDict();\r
+    parent = PyDict_GetItemString(modules, buf);\r
+    if (parent == NULL) {\r
+        if (orig_level < 1) {\r
+            PyObject *err_msg = PyString_FromFormat(\r
+                "Parent module '%.200s' not found "\r
+                "while handling absolute import", buf);\r
+            if (err_msg == NULL) {\r
+                return NULL;\r
+            }\r
+            if (!PyErr_WarnEx(PyExc_RuntimeWarning,\r
+                            PyString_AsString(err_msg), 1)) {\r
+                *buf = '\0';\r
+                *p_buflen = 0;\r
+                parent = Py_None;\r
+            }\r
+            Py_DECREF(err_msg);\r
+        } else {\r
+            PyErr_Format(PyExc_SystemError,\r
+                "Parent module '%.200s' not loaded, "\r
+                "cannot perform relative import", buf);\r
+        }\r
+    }\r
+    return parent;\r
+    /* We expect, but can't guarantee, if parent != None, that:\r
+       - parent.__name__ == buf\r
+       - parent.__dict__ is globals\r
+       If this is violated...  Who cares? */\r
+}\r
+\r
+/* altmod is either None or same as mod */\r
+static PyObject *\r
+load_next(PyObject *mod, PyObject *altmod, char **p_name, char *buf,\r
+          Py_ssize_t *p_buflen)\r
+{\r
+    char *name = *p_name;\r
+    char *dot = strchr(name, '.');\r
+    size_t len;\r
+    char *p;\r
+    PyObject *result;\r
+\r
+    if (strlen(name) == 0) {\r
+        /* completely empty module name should only happen in\r
+           'from . import' (or '__import__("")')*/\r
+        Py_INCREF(mod);\r
+        *p_name = NULL;\r
+        return mod;\r
+    }\r
+\r
+    if (dot == NULL) {\r
+        *p_name = NULL;\r
+        len = strlen(name);\r
+    }\r
+    else {\r
+        *p_name = dot+1;\r
+        len = dot-name;\r
+    }\r
+    if (len == 0) {\r
+        PyErr_SetString(PyExc_ValueError,\r
+                        "Empty module name");\r
+        return NULL;\r
+    }\r
+\r
+    p = buf + *p_buflen;\r
+    if (p != buf)\r
+        *p++ = '.';\r
+    if (p+len-buf >= MAXPATHLEN) {\r
+        PyErr_SetString(PyExc_ValueError,\r
+                        "Module name too long");\r
+        return NULL;\r
+    }\r
+    strncpy(p, name, len);\r
+    p[len] = '\0';\r
+    *p_buflen = p+len-buf;\r
+\r
+    result = import_submodule(mod, p, buf);\r
+    if (result == Py_None && altmod != mod) {\r
+        Py_DECREF(result);\r
+        /* Here, altmod must be None and mod must not be None */\r
+        result = import_submodule(altmod, p, p);\r
+        if (result != NULL && result != Py_None) {\r
+            if (mark_miss(buf) != 0) {\r
+                Py_DECREF(result);\r
+                return NULL;\r
+            }\r
+            strncpy(buf, name, len);\r
+            buf[len] = '\0';\r
+            *p_buflen = len;\r
+        }\r
+    }\r
+    if (result == NULL)\r
+        return NULL;\r
+\r
+    if (result == Py_None) {\r
+        Py_DECREF(result);\r
+        PyErr_Format(PyExc_ImportError,\r
+                     "No module named %.200s", name);\r
+        return NULL;\r
+    }\r
+\r
+    return result;\r
+}\r
+\r
+static int\r
+mark_miss(char *name)\r
+{\r
+    PyObject *modules = PyImport_GetModuleDict();\r
+    return PyDict_SetItemString(modules, name, Py_None);\r
+}\r
+\r
+static int\r
+ensure_fromlist(PyObject *mod, PyObject *fromlist, char *buf, Py_ssize_t buflen,\r
+                int recursive)\r
+{\r
+    int i;\r
+\r
+    if (!PyObject_HasAttrString(mod, "__path__"))\r
+        return 1;\r
+\r
+    for (i = 0; ; i++) {\r
+        PyObject *item = PySequence_GetItem(fromlist, i);\r
+        int hasit;\r
+        if (item == NULL) {\r
+            if (PyErr_ExceptionMatches(PyExc_IndexError)) {\r
+                PyErr_Clear();\r
+                return 1;\r
+            }\r
+            return 0;\r
+        }\r
+        if (!PyString_Check(item)) {\r
+            PyErr_SetString(PyExc_TypeError,\r
+                            "Item in ``from list'' not a string");\r
+            Py_DECREF(item);\r
+            return 0;\r
+        }\r
+        if (PyString_AS_STRING(item)[0] == '*') {\r
+            PyObject *all;\r
+            Py_DECREF(item);\r
+            /* See if the package defines __all__ */\r
+            if (recursive)\r
+                continue; /* Avoid endless recursion */\r
+            all = PyObject_GetAttrString(mod, "__all__");\r
+            if (all == NULL)\r
+                PyErr_Clear();\r
+            else {\r
+                int ret = ensure_fromlist(mod, all, buf, buflen, 1);\r
+                Py_DECREF(all);\r
+                if (!ret)\r
+                    return 0;\r
+            }\r
+            continue;\r
+        }\r
+        hasit = PyObject_HasAttr(mod, item);\r
+        if (!hasit) {\r
+            char *subname = PyString_AS_STRING(item);\r
+            PyObject *submod;\r
+            char *p;\r
+            if (buflen + strlen(subname) >= MAXPATHLEN) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "Module name too long");\r
+                Py_DECREF(item);\r
+                return 0;\r
+            }\r
+            p = buf + buflen;\r
+            *p++ = '.';\r
+            strcpy(p, subname);\r
+            submod = import_submodule(mod, subname, buf);\r
+            Py_XDECREF(submod);\r
+            if (submod == NULL) {\r
+                Py_DECREF(item);\r
+                return 0;\r
+            }\r
+        }\r
+        Py_DECREF(item);\r
+    }\r
+\r
+    /* NOTREACHED */\r
+}\r
+\r
+static int\r
+add_submodule(PyObject *mod, PyObject *submod, char *fullname, char *subname,\r
+              PyObject *modules)\r
+{\r
+    if (mod == Py_None)\r
+        return 1;\r
+    /* Irrespective of the success of this load, make a\r
+       reference to it in the parent package module.  A copy gets\r
+       saved in the modules dictionary under the full name, so get a\r
+       reference from there, if need be.  (The exception is when the\r
+       load failed with a SyntaxError -- then there's no trace in\r
+       sys.modules.  In that case, of course, do nothing extra.) */\r
+    if (submod == NULL) {\r
+        submod = PyDict_GetItemString(modules, fullname);\r
+        if (submod == NULL)\r
+            return 1;\r
+    }\r
+    if (PyModule_Check(mod)) {\r
+        /* We can't use setattr here since it can give a\r
+         * spurious warning if the submodule name shadows a\r
+         * builtin name */\r
+        PyObject *dict = PyModule_GetDict(mod);\r
+        if (!dict)\r
+            return 0;\r
+        if (PyDict_SetItemString(dict, subname, submod) < 0)\r
+            return 0;\r
+    }\r
+    else {\r
+        if (PyObject_SetAttrString(mod, subname, submod) < 0)\r
+            return 0;\r
+    }\r
+    return 1;\r
+}\r
+\r
+static PyObject *\r
+import_submodule(PyObject *mod, char *subname, char *fullname)\r
+{\r
+    PyObject *modules = PyImport_GetModuleDict();\r
+    PyObject *m = NULL;\r
+\r
+    /* Require:\r
+       if mod == None: subname == fullname\r
+       else: mod.__name__ + "." + subname == fullname\r
+    */\r
+\r
+    if ((m = PyDict_GetItemString(modules, fullname)) != NULL) {\r
+        Py_INCREF(m);\r
+    }\r
+    else {\r
+        PyObject *path, *loader = NULL;\r
+        char *buf;\r
+        struct filedescr *fdp;\r
+        FILE *fp = NULL;\r
+\r
+        if (mod == Py_None)\r
+            path = NULL;\r
+        else {\r
+            path = PyObject_GetAttrString(mod, "__path__");\r
+            if (path == NULL) {\r
+                PyErr_Clear();\r
+                Py_INCREF(Py_None);\r
+                return Py_None;\r
+            }\r
+        }\r
+\r
+        buf = PyMem_MALLOC(MAXPATHLEN+1);\r
+        if (buf == NULL) {\r
+            return PyErr_NoMemory();\r
+        }\r
+        buf[0] = '\0';\r
+        fdp = find_module(fullname, subname, path, buf, MAXPATHLEN+1,\r
+                          &fp, &loader);\r
+        Py_XDECREF(path);\r
+        if (fdp == NULL) {\r
+            PyMem_FREE(buf);\r
+            if (!PyErr_ExceptionMatches(PyExc_ImportError))\r
+                return NULL;\r
+            PyErr_Clear();\r
+            Py_INCREF(Py_None);\r
+            return Py_None;\r
+        }\r
+        m = load_module(fullname, fp, buf, fdp->type, loader);\r
+        Py_XDECREF(loader);\r
+        if (fp)\r
+            fclose(fp);\r
+        if (!add_submodule(mod, m, fullname, subname, modules)) {\r
+            Py_XDECREF(m);\r
+            m = NULL;\r
+        }\r
+        PyMem_FREE(buf);\r
+    }\r
+\r
+    return m;\r
+}\r
+\r
+\r
+/* Re-import a module of any kind and return its module object, WITH\r
+   INCREMENTED REFERENCE COUNT */\r
+\r
+PyObject *\r
+PyImport_ReloadModule(PyObject *m)\r
+{\r
+    PyInterpreterState *interp = PyThreadState_Get()->interp;\r
+    PyObject *modules_reloading = interp->modules_reloading;\r
+    PyObject *modules = PyImport_GetModuleDict();\r
+    PyObject *path = NULL, *loader = NULL, *existing_m = NULL;\r
+    char *name, *subname;\r
+    char *buf;\r
+    struct filedescr *fdp;\r
+    FILE *fp = NULL;\r
+    PyObject *newm;\r
+\r
+    if (modules_reloading == NULL) {\r
+        Py_FatalError("PyImport_ReloadModule: "\r
+                      "no modules_reloading dictionary!");\r
+        return NULL;\r
+    }\r
+\r
+    if (m == NULL || !PyModule_Check(m)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                        "reload() argument must be module");\r
+        return NULL;\r
+    }\r
+    name = PyModule_GetName(m);\r
+    if (name == NULL)\r
+        return NULL;\r
+    if (m != PyDict_GetItemString(modules, name)) {\r
+        PyErr_Format(PyExc_ImportError,\r
+                     "reload(): module %.200s not in sys.modules",\r
+                     name);\r
+        return NULL;\r
+    }\r
+    existing_m = PyDict_GetItemString(modules_reloading, name);\r
+    if (existing_m != NULL) {\r
+        /* Due to a recursive reload, this module is already\r
+           being reloaded. */\r
+        Py_INCREF(existing_m);\r
+        return existing_m;\r
+    }\r
+    if (PyDict_SetItemString(modules_reloading, name, m) < 0)\r
+        return NULL;\r
+\r
+    subname = strrchr(name, '.');\r
+    if (subname == NULL)\r
+        subname = name;\r
+    else {\r
+        PyObject *parentname, *parent;\r
+        parentname = PyString_FromStringAndSize(name, (subname-name));\r
+        if (parentname == NULL) {\r
+            imp_modules_reloading_clear();\r
+            return NULL;\r
+        }\r
+        parent = PyDict_GetItem(modules, parentname);\r
+        if (parent == NULL) {\r
+            PyErr_Format(PyExc_ImportError,\r
+                "reload(): parent %.200s not in sys.modules",\r
+                PyString_AS_STRING(parentname));\r
+            Py_DECREF(parentname);\r
+            imp_modules_reloading_clear();\r
+            return NULL;\r
+        }\r
+        Py_DECREF(parentname);\r
+        subname++;\r
+        path = PyObject_GetAttrString(parent, "__path__");\r
+        if (path == NULL)\r
+            PyErr_Clear();\r
+    }\r
+    buf = PyMem_MALLOC(MAXPATHLEN+1);\r
+    if (buf == NULL) {\r
+        Py_XDECREF(path);\r
+        return PyErr_NoMemory();\r
+    }\r
+    buf[0] = '\0';\r
+    fdp = find_module(name, subname, path, buf, MAXPATHLEN+1, &fp, &loader);\r
+    Py_XDECREF(path);\r
+\r
+    if (fdp == NULL) {\r
+        Py_XDECREF(loader);\r
+        imp_modules_reloading_clear();\r
+        PyMem_FREE(buf);\r
+        return NULL;\r
+    }\r
+\r
+    newm = load_module(name, fp, buf, fdp->type, loader);\r
+    Py_XDECREF(loader);\r
+\r
+    if (fp)\r
+        fclose(fp);\r
+    if (newm == NULL) {\r
+        /* load_module probably removed name from modules because of\r
+         * the error.  Put back the original module object.  We're\r
+         * going to return NULL in this case regardless of whether\r
+         * replacing name succeeds, so the return value is ignored.\r
+         */\r
+        PyDict_SetItemString(modules, name, m);\r
+    }\r
+    imp_modules_reloading_clear();\r
+    PyMem_FREE(buf);\r
+    return newm;\r
+}\r
+\r
+\r
+/* Higher-level import emulator which emulates the "import" statement\r
+   more accurately -- it invokes the __import__() function from the\r
+   builtins of the current globals.  This means that the import is\r
+   done using whatever import hooks are installed in the current\r
+   environment, e.g. by "rexec".\r
+   A dummy list ["__doc__"] is passed as the 4th argument so that\r
+   e.g. PyImport_Import(PyString_FromString("win32com.client.gencache"))\r
+   will return <module "gencache"> instead of <module "win32com">. */\r
+\r
+PyObject *\r
+PyImport_Import(PyObject *module_name)\r
+{\r
+    static PyObject *silly_list = NULL;\r
+    static PyObject *builtins_str = NULL;\r
+    static PyObject *import_str = NULL;\r
+    PyObject *globals = NULL;\r
+    PyObject *import = NULL;\r
+    PyObject *builtins = NULL;\r
+    PyObject *r = NULL;\r
+\r
+    /* Initialize constant string objects */\r
+    if (silly_list == NULL) {\r
+        import_str = PyString_InternFromString("__import__");\r
+        if (import_str == NULL)\r
+            return NULL;\r
+        builtins_str = PyString_InternFromString("__builtins__");\r
+        if (builtins_str == NULL)\r
+            return NULL;\r
+        silly_list = Py_BuildValue("[s]", "__doc__");\r
+        if (silly_list == NULL)\r
+            return NULL;\r
+    }\r
+\r
+    /* Get the builtins from current globals */\r
+    globals = PyEval_GetGlobals();\r
+    if (globals != NULL) {\r
+        Py_INCREF(globals);\r
+        builtins = PyObject_GetItem(globals, builtins_str);\r
+        if (builtins == NULL)\r
+            goto err;\r
+    }\r
+    else {\r
+        /* No globals -- use standard builtins, and fake globals */\r
+        builtins = PyImport_ImportModuleLevel("__builtin__",\r
+                                              NULL, NULL, NULL, 0);\r
+        if (builtins == NULL)\r
+            return NULL;\r
+        globals = Py_BuildValue("{OO}", builtins_str, builtins);\r
+        if (globals == NULL)\r
+            goto err;\r
+    }\r
+\r
+    /* Get the __import__ function from the builtins */\r
+    if (PyDict_Check(builtins)) {\r
+        import = PyObject_GetItem(builtins, import_str);\r
+        if (import == NULL)\r
+            PyErr_SetObject(PyExc_KeyError, import_str);\r
+    }\r
+    else\r
+        import = PyObject_GetAttr(builtins, import_str);\r
+    if (import == NULL)\r
+        goto err;\r
+\r
+    /* Call the __import__ function with the proper argument list\r
+     * Always use absolute import here. */\r
+    r = PyObject_CallFunction(import, "OOOOi", module_name, globals,\r
+                              globals, silly_list, 0, NULL);\r
+\r
+  err:\r
+    Py_XDECREF(globals);\r
+    Py_XDECREF(builtins);\r
+    Py_XDECREF(import);\r
+\r
+    return r;\r
+}\r
+\r
+\r
+/* Module 'imp' provides Python access to the primitives used for\r
+   importing modules.\r
+*/\r
+\r
+static PyObject *\r
+imp_get_magic(PyObject *self, PyObject *noargs)\r
+{\r
+    char buf[4];\r
+\r
+    buf[0] = (char) ((pyc_magic >>  0) & 0xff);\r
+    buf[1] = (char) ((pyc_magic >>  8) & 0xff);\r
+    buf[2] = (char) ((pyc_magic >> 16) & 0xff);\r
+    buf[3] = (char) ((pyc_magic >> 24) & 0xff);\r
+\r
+    return PyString_FromStringAndSize(buf, 4);\r
+}\r
+\r
+static PyObject *\r
+imp_get_suffixes(PyObject *self, PyObject *noargs)\r
+{\r
+    PyObject *list;\r
+    struct filedescr *fdp;\r
+\r
+    list = PyList_New(0);\r
+    if (list == NULL)\r
+        return NULL;\r
+    for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {\r
+        PyObject *item = Py_BuildValue("ssi",\r
+                               fdp->suffix, fdp->mode, fdp->type);\r
+        if (item == NULL) {\r
+            Py_DECREF(list);\r
+            return NULL;\r
+        }\r
+        if (PyList_Append(list, item) < 0) {\r
+            Py_DECREF(list);\r
+            Py_DECREF(item);\r
+            return NULL;\r
+        }\r
+        Py_DECREF(item);\r
+    }\r
+    return list;\r
+}\r
+\r
+static PyObject *\r
+call_find_module(char *name, PyObject *path)\r
+{\r
+    extern int fclose(FILE *);\r
+    PyObject *fob, *ret;\r
+    struct filedescr *fdp;\r
+    char *pathname;\r
+    FILE *fp = NULL;\r
+\r
+    pathname = PyMem_MALLOC(MAXPATHLEN+1);\r
+    if (pathname == NULL) {\r
+        return PyErr_NoMemory();\r
+    }\r
+    pathname[0] = '\0';\r
+    if (path == Py_None)\r
+        path = NULL;\r
+    fdp = find_module(NULL, name, path, pathname, MAXPATHLEN+1, &fp, NULL);\r
+    if (fdp == NULL) {\r
+        PyMem_FREE(pathname);\r
+        return NULL;\r
+    }\r
+    if (fp != NULL) {\r
+        fob = PyFile_FromFile(fp, pathname, fdp->mode, fclose);\r
+        if (fob == NULL) {\r
+            PyMem_FREE(pathname);\r
+            return NULL;\r
+        }\r
+    }\r
+    else {\r
+        fob = Py_None;\r
+        Py_INCREF(fob);\r
+    }\r
+    ret = Py_BuildValue("Os(ssi)",\r
+                  fob, pathname, fdp->suffix, fdp->mode, fdp->type);\r
+    Py_DECREF(fob);\r
+    PyMem_FREE(pathname);\r
+    return ret;\r
+}\r
+\r
+static PyObject *\r
+imp_find_module(PyObject *self, PyObject *args)\r
+{\r
+    char *name;\r
+    PyObject *path = NULL;\r
+    if (!PyArg_ParseTuple(args, "s|O:find_module", &name, &path))\r
+        return NULL;\r
+    return call_find_module(name, path);\r
+}\r
+\r
+static PyObject *\r
+imp_init_builtin(PyObject *self, PyObject *args)\r
+{\r
+    char *name;\r
+    int ret;\r
+    PyObject *m;\r
+    if (!PyArg_ParseTuple(args, "s:init_builtin", &name))\r
+        return NULL;\r
+    ret = init_builtin(name);\r
+    if (ret < 0)\r
+        return NULL;\r
+    if (ret == 0) {\r
+        Py_INCREF(Py_None);\r
+        return Py_None;\r
+    }\r
+    m = PyImport_AddModule(name);\r
+    Py_XINCREF(m);\r
+    return m;\r
+}\r
+\r
+static PyObject *\r
+imp_init_frozen(PyObject *self, PyObject *args)\r
+{\r
+    char *name;\r
+    int ret;\r
+    PyObject *m;\r
+    if (!PyArg_ParseTuple(args, "s:init_frozen", &name))\r
+        return NULL;\r
+    ret = PyImport_ImportFrozenModule(name);\r
+    if (ret < 0)\r
+        return NULL;\r
+    if (ret == 0) {\r
+        Py_INCREF(Py_None);\r
+        return Py_None;\r
+    }\r
+    m = PyImport_AddModule(name);\r
+    Py_XINCREF(m);\r
+    return m;\r
+}\r
+\r
+static PyObject *\r
+imp_get_frozen_object(PyObject *self, PyObject *args)\r
+{\r
+    char *name;\r
+\r
+    if (!PyArg_ParseTuple(args, "s:get_frozen_object", &name))\r
+        return NULL;\r
+    return get_frozen_object(name);\r
+}\r
+\r
+static PyObject *\r
+imp_is_builtin(PyObject *self, PyObject *args)\r
+{\r
+    char *name;\r
+    if (!PyArg_ParseTuple(args, "s:is_builtin", &name))\r
+        return NULL;\r
+    return PyInt_FromLong(is_builtin(name));\r
+}\r
+\r
+static PyObject *\r
+imp_is_frozen(PyObject *self, PyObject *args)\r
+{\r
+    char *name;\r
+    struct _frozen *p;\r
+    if (!PyArg_ParseTuple(args, "s:is_frozen", &name))\r
+        return NULL;\r
+    p = find_frozen(name);\r
+    return PyBool_FromLong((long) (p == NULL ? 0 : p->size));\r
+}\r
+\r
+static FILE *\r
+get_file(char *pathname, PyObject *fob, char *mode)\r
+{\r
+    FILE *fp;\r
+    if (fob == NULL) {\r
+        if (mode[0] == 'U')\r
+            mode = "r" PY_STDIOTEXTMODE;\r
+        fp = fopen(pathname, mode);\r
+        if (fp == NULL)\r
+            PyErr_SetFromErrno(PyExc_IOError);\r
+    }\r
+    else {\r
+        fp = PyFile_AsFile(fob);\r
+        if (fp == NULL)\r
+            PyErr_SetString(PyExc_ValueError,\r
+                            "bad/closed file object");\r
+    }\r
+    return fp;\r
+}\r
+\r
+static PyObject *\r
+imp_load_compiled(PyObject *self, PyObject *args)\r
+{\r
+    char *name;\r
+    char *pathname;\r
+    PyObject *fob = NULL;\r
+    PyObject *m;\r
+    FILE *fp;\r
+    if (!PyArg_ParseTuple(args, "ss|O!:load_compiled", &name, &pathname,\r
+                          &PyFile_Type, &fob))\r
+        return NULL;\r
+    fp = get_file(pathname, fob, "rb");\r
+    if (fp == NULL)\r
+        return NULL;\r
+    m = load_compiled_module(name, pathname, fp);\r
+    if (fob == NULL)\r
+        fclose(fp);\r
+    return m;\r
+}\r
+\r
+#ifdef HAVE_DYNAMIC_LOADING\r
+\r
+static PyObject *\r
+imp_load_dynamic(PyObject *self, PyObject *args)\r
+{\r
+    char *name;\r
+    char *pathname;\r
+    PyObject *fob = NULL;\r
+    PyObject *m;\r
+    FILE *fp = NULL;\r
+    if (!PyArg_ParseTuple(args, "ss|O!:load_dynamic", &name, &pathname,\r
+                          &PyFile_Type, &fob))\r
+        return NULL;\r
+    if (fob) {\r
+        fp = get_file(pathname, fob, "r");\r
+        if (fp == NULL)\r
+            return NULL;\r
+    }\r
+    m = _PyImport_LoadDynamicModule(name, pathname, fp);\r
+    return m;\r
+}\r
+\r
+#endif /* HAVE_DYNAMIC_LOADING */\r
+\r
+static PyObject *\r
+imp_load_source(PyObject *self, PyObject *args)\r
+{\r
+    char *name;\r
+    char *pathname;\r
+    PyObject *fob = NULL;\r
+    PyObject *m;\r
+    FILE *fp;\r
+    if (!PyArg_ParseTuple(args, "ss|O!:load_source", &name, &pathname,\r
+                          &PyFile_Type, &fob))\r
+        return NULL;\r
+    fp = get_file(pathname, fob, "r");\r
+    if (fp == NULL)\r
+        return NULL;\r
+    m = load_source_module(name, pathname, fp);\r
+    if (fob == NULL)\r
+        fclose(fp);\r
+    return m;\r
+}\r
+\r
+static PyObject *\r
+imp_load_module(PyObject *self, PyObject *args)\r
+{\r
+    char *name;\r
+    PyObject *fob;\r
+    char *pathname;\r
+    char *suffix; /* Unused */\r
+    char *mode;\r
+    int type;\r
+    FILE *fp;\r
+\r
+    if (!PyArg_ParseTuple(args, "sOs(ssi):load_module",\r
+                          &name, &fob, &pathname,\r
+                          &suffix, &mode, &type))\r
+        return NULL;\r
+    if (*mode) {\r
+        /* Mode must start with 'r' or 'U' and must not contain '+'.\r
+           Implicit in this test is the assumption that the mode\r
+           may contain other modifiers like 'b' or 't'. */\r
+\r
+        if (!(*mode == 'r' || *mode == 'U') || strchr(mode, '+')) {\r
+            PyErr_Format(PyExc_ValueError,\r
+                         "invalid file open mode %.200s", mode);\r
+            return NULL;\r
+        }\r
+    }\r
+    if (fob == Py_None)\r
+        fp = NULL;\r
+    else {\r
+        if (!PyFile_Check(fob)) {\r
+            PyErr_SetString(PyExc_ValueError,\r
+                "load_module arg#2 should be a file or None");\r
+            return NULL;\r
+        }\r
+        fp = get_file(pathname, fob, mode);\r
+        if (fp == NULL)\r
+            return NULL;\r
+    }\r
+    return load_module(name, fp, pathname, type, NULL);\r
+}\r
+\r
+static PyObject *\r
+imp_load_package(PyObject *self, PyObject *args)\r
+{\r
+    char *name;\r
+    char *pathname;\r
+    if (!PyArg_ParseTuple(args, "ss:load_package", &name, &pathname))\r
+        return NULL;\r
+    return load_package(name, pathname);\r
+}\r
+\r
+static PyObject *\r
+imp_new_module(PyObject *self, PyObject *args)\r
+{\r
+    char *name;\r
+    if (!PyArg_ParseTuple(args, "s:new_module", &name))\r
+        return NULL;\r
+    return PyModule_New(name);\r
+}\r
+\r
+static PyObject *\r
+imp_reload(PyObject *self, PyObject *v)\r
+{\r
+    return PyImport_ReloadModule(v);\r
+}\r
+\r
+\r
+/* Doc strings */\r
+\r
+PyDoc_STRVAR(doc_imp,\r
+"This module provides the components needed to build your own\n\\r
+__import__ function.  Undocumented functions are obsolete.");\r
+\r
+PyDoc_STRVAR(doc_reload,\r
+"reload(module) -> module\n\\r
+\n\\r
+Reload the module.  The module must have been successfully imported before.");\r
+\r
+PyDoc_STRVAR(doc_find_module,\r
+"find_module(name, [path]) -> (file, filename, (suffix, mode, type))\n\\r
+Search for a module.  If path is omitted or None, search for a\n\\r
+built-in, frozen or special module and continue search in sys.path.\n\\r
+The module name cannot contain '.'; to search for a submodule of a\n\\r
+package, pass the submodule name and the package's __path__.");\r
+\r
+PyDoc_STRVAR(doc_load_module,\r
+"load_module(name, file, filename, (suffix, mode, type)) -> module\n\\r
+Load a module, given information returned by find_module().\n\\r
+The module name must include the full package name, if any.");\r
+\r
+PyDoc_STRVAR(doc_get_magic,\r
+"get_magic() -> string\n\\r
+Return the magic number for .pyc or .pyo files.");\r
+\r
+PyDoc_STRVAR(doc_get_suffixes,\r
+"get_suffixes() -> [(suffix, mode, type), ...]\n\\r
+Return a list of (suffix, mode, type) tuples describing the files\n\\r
+that find_module() looks for.");\r
+\r
+PyDoc_STRVAR(doc_new_module,\r
+"new_module(name) -> module\n\\r
+Create a new module.  Do not enter it in sys.modules.\n\\r
+The module name must include the full package name, if any.");\r
+\r
+PyDoc_STRVAR(doc_lock_held,\r
+"lock_held() -> boolean\n\\r
+Return True if the import lock is currently held, else False.\n\\r
+On platforms without threads, return False.");\r
+\r
+PyDoc_STRVAR(doc_acquire_lock,\r
+"acquire_lock() -> None\n\\r
+Acquires the interpreter's import lock for the current thread.\n\\r
+This lock should be used by import hooks to ensure thread-safety\n\\r
+when importing modules.\n\\r
+On platforms without threads, this function does nothing.");\r
+\r
+PyDoc_STRVAR(doc_release_lock,\r
+"release_lock() -> None\n\\r
+Release the interpreter's import lock.\n\\r
+On platforms without threads, this function does nothing.");\r
+\r
+static PyMethodDef imp_methods[] = {\r
+    {"reload",           imp_reload,       METH_O,       doc_reload},\r
+    {"find_module",      imp_find_module,  METH_VARARGS, doc_find_module},\r
+    {"get_magic",        imp_get_magic,    METH_NOARGS,  doc_get_magic},\r
+    {"get_suffixes", imp_get_suffixes, METH_NOARGS,  doc_get_suffixes},\r
+    {"load_module",      imp_load_module,  METH_VARARGS, doc_load_module},\r
+    {"new_module",       imp_new_module,   METH_VARARGS, doc_new_module},\r
+    {"lock_held",        imp_lock_held,    METH_NOARGS,  doc_lock_held},\r
+    {"acquire_lock", imp_acquire_lock, METH_NOARGS,  doc_acquire_lock},\r
+    {"release_lock", imp_release_lock, METH_NOARGS,  doc_release_lock},\r
+    /* The rest are obsolete */\r
+    {"get_frozen_object",       imp_get_frozen_object,  METH_VARARGS},\r
+    {"init_builtin",            imp_init_builtin,       METH_VARARGS},\r
+    {"init_frozen",             imp_init_frozen,        METH_VARARGS},\r
+    {"is_builtin",              imp_is_builtin,         METH_VARARGS},\r
+    {"is_frozen",               imp_is_frozen,          METH_VARARGS},\r
+    {"load_compiled",           imp_load_compiled,      METH_VARARGS},\r
+#ifdef HAVE_DYNAMIC_LOADING\r
+    {"load_dynamic",            imp_load_dynamic,       METH_VARARGS},\r
+#endif\r
+    {"load_package",            imp_load_package,       METH_VARARGS},\r
+    {"load_source",             imp_load_source,        METH_VARARGS},\r
+    {NULL,                      NULL}           /* sentinel */\r
+};\r
+\r
+static int\r
+setint(PyObject *d, char *name, int value)\r
+{\r
+    PyObject *v;\r
+    int err;\r
+\r
+    v = PyInt_FromLong((long)value);\r
+    err = PyDict_SetItemString(d, name, v);\r
+    Py_XDECREF(v);\r
+    return err;\r
+}\r
+\r
+typedef struct {\r
+    PyObject_HEAD\r
+} NullImporter;\r
+\r
+static int\r
+NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)\r
+{\r
+    char *path;\r
+    Py_ssize_t pathlen;\r
+\r
+    if (!_PyArg_NoKeywords("NullImporter()", kwds))\r
+        return -1;\r
+\r
+    if (!PyArg_ParseTuple(args, "s:NullImporter",\r
+                          &path))\r
+        return -1;\r
+\r
+    pathlen = strlen(path);\r
+    if (pathlen == 0) {\r
+        PyErr_SetString(PyExc_ImportError, "empty pathname");\r
+        return -1;\r
+    } else {\r
+        if(isdir(path)) {\r
+            PyErr_SetString(PyExc_ImportError,\r
+                            "existing directory");\r
+            return -1;\r
+        }\r
+    }\r
+    return 0;\r
+}\r
+\r
+static PyObject *\r
+NullImporter_find_module(NullImporter *self, PyObject *args)\r
+{\r
+    Py_RETURN_NONE;\r
+}\r
+\r
+static PyMethodDef NullImporter_methods[] = {\r
+    {"find_module", (PyCFunction)NullImporter_find_module, METH_VARARGS,\r
+     "Always return None"\r
+    },\r
+    {NULL}  /* Sentinel */\r
+};\r
+\r
+\r
+PyTypeObject PyNullImporter_Type = {\r
+    PyVarObject_HEAD_INIT(NULL, 0)\r
+    "imp.NullImporter",        /*tp_name*/\r
+    sizeof(NullImporter),      /*tp_basicsize*/\r
+    0,                         /*tp_itemsize*/\r
+    0,                         /*tp_dealloc*/\r
+    0,                         /*tp_print*/\r
+    0,                         /*tp_getattr*/\r
+    0,                         /*tp_setattr*/\r
+    0,                         /*tp_compare*/\r
+    0,                         /*tp_repr*/\r
+    0,                         /*tp_as_number*/\r
+    0,                         /*tp_as_sequence*/\r
+    0,                         /*tp_as_mapping*/\r
+    0,                         /*tp_hash */\r
+    0,                         /*tp_call*/\r
+    0,                         /*tp_str*/\r
+    0,                         /*tp_getattro*/\r
+    0,                         /*tp_setattro*/\r
+    0,                         /*tp_as_buffer*/\r
+    Py_TPFLAGS_DEFAULT,        /*tp_flags*/\r
+    "Null importer object",    /* tp_doc */\r
+    0,                             /* tp_traverse */\r
+    0,                             /* tp_clear */\r
+    0,                             /* tp_richcompare */\r
+    0,                             /* tp_weaklistoffset */\r
+    0,                             /* tp_iter */\r
+    0,                             /* tp_iternext */\r
+    NullImporter_methods,      /* tp_methods */\r
+    0,                         /* tp_members */\r
+    0,                         /* tp_getset */\r
+    0,                         /* tp_base */\r
+    0,                         /* tp_dict */\r
+    0,                         /* tp_descr_get */\r
+    0,                         /* tp_descr_set */\r
+    0,                         /* tp_dictoffset */\r
+    (initproc)NullImporter_init,      /* tp_init */\r
+    0,                         /* tp_alloc */\r
+    PyType_GenericNew          /* tp_new */\r
+};\r
+\r
+\r
+PyMODINIT_FUNC\r
+initimp(void)\r
+{\r
+    PyObject *m, *d;\r
+\r
+    if (PyType_Ready(&PyNullImporter_Type) < 0)\r
+        goto failure;\r
+\r
+    m = Py_InitModule4("imp", imp_methods, doc_imp,\r
+                       NULL, PYTHON_API_VERSION);\r
+    if (m == NULL)\r
+        goto failure;\r
+    d = PyModule_GetDict(m);\r
+    if (d == NULL)\r
+        goto failure;\r
+\r
+    if (setint(d, "SEARCH_ERROR", SEARCH_ERROR) < 0) goto failure;\r
+    if (setint(d, "PY_SOURCE", PY_SOURCE) < 0) goto failure;\r
+    if (setint(d, "PY_COMPILED", PY_COMPILED) < 0) goto failure;\r
+    if (setint(d, "C_EXTENSION", C_EXTENSION) < 0) goto failure;\r
+    if (setint(d, "PY_RESOURCE", PY_RESOURCE) < 0) goto failure;\r
+    if (setint(d, "PKG_DIRECTORY", PKG_DIRECTORY) < 0) goto failure;\r
+    if (setint(d, "C_BUILTIN", C_BUILTIN) < 0) goto failure;\r
+    if (setint(d, "PY_FROZEN", PY_FROZEN) < 0) goto failure;\r
+    if (setint(d, "PY_CODERESOURCE", PY_CODERESOURCE) < 0) goto failure;\r
+    if (setint(d, "IMP_HOOK", IMP_HOOK) < 0) goto failure;\r
+\r
+    Py_INCREF(&PyNullImporter_Type);\r
+    PyModule_AddObject(m, "NullImporter", (PyObject *)&PyNullImporter_Type);\r
+  failure:\r
+    ;\r
+}\r
+\r
+\r
+/* API for embedding applications that want to add their own entries\r
+   to the table of built-in modules.  This should normally be called\r
+   *before* Py_Initialize().  When the table resize fails, -1 is\r
+   returned and the existing table is unchanged.\r
+\r
+   After a similar function by Just van Rossum. */\r
+\r
+int\r
+PyImport_ExtendInittab(struct _inittab *newtab)\r
+{\r
+    static struct _inittab *our_copy = NULL;\r
+    struct _inittab *p;\r
+    int i, n;\r
+\r
+    /* Count the number of entries in both tables */\r
+    for (n = 0; newtab[n].name != NULL; n++)\r
+        ;\r
+    if (n == 0)\r
+        return 0; /* Nothing to do */\r
+    for (i = 0; PyImport_Inittab[i].name != NULL; i++)\r
+        ;\r
+\r
+    /* Allocate new memory for the combined table */\r
+    p = our_copy;\r
+    PyMem_RESIZE(p, struct _inittab, i+n+1);\r
+    if (p == NULL)\r
+        return -1;\r
+\r
+    /* Copy the tables into the new memory */\r
+    if (our_copy != PyImport_Inittab)\r
+        memcpy(p, PyImport_Inittab, (i+1) * sizeof(struct _inittab));\r
+    PyImport_Inittab = our_copy = p;\r
+    memcpy(p+i, newtab, (n+1) * sizeof(struct _inittab));\r
+\r
+    return 0;\r
+}\r
+\r
+/* Shorthand to add a single entry given a name and a function */\r
+\r
+int\r
+PyImport_AppendInittab(const char *name, void (*initfunc)(void))\r
+{\r
+    struct _inittab newtab[2];\r
+\r
+    memset(newtab, '\0', sizeof newtab);\r
+\r
+    newtab[0].name = (char *)name;\r
+    newtab[0].initfunc = initfunc;\r
+\r
+    return PyImport_ExtendInittab(newtab);\r
+}\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/importdl.c b/AppPkg/Applications/Python/Python-2.7.10/Python/importdl.c
new file mode 100644 (file)
index 0000000..0280e81
--- /dev/null
@@ -0,0 +1,78 @@
+\r
+/* Support for dynamic loading of extension modules */\r
+\r
+#include "Python.h"\r
+\r
+/* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is\r
+   supported on this platform. configure will then compile and link in one\r
+   of the dynload_*.c files, as appropriate. We will call a function in\r
+   those modules to get a function pointer to the module's init function.\r
+*/\r
+#ifdef HAVE_DYNAMIC_LOADING\r
+\r
+#include "importdl.h"\r
+\r
+extern dl_funcptr _PyImport_GetDynLoadFunc(const char *name,\r
+                                           const char *shortname,\r
+                                           const char *pathname, FILE *fp);\r
+\r
+\r
+\r
+PyObject *\r
+_PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp)\r
+{\r
+    PyObject *m;\r
+    char *lastdot, *shortname, *packagecontext, *oldcontext;\r
+    dl_funcptr p;\r
+\r
+    if ((m = _PyImport_FindExtension(name, pathname)) != NULL) {\r
+        Py_INCREF(m);\r
+        return m;\r
+    }\r
+    lastdot = strrchr(name, '.');\r
+    if (lastdot == NULL) {\r
+        packagecontext = NULL;\r
+        shortname = name;\r
+    }\r
+    else {\r
+        packagecontext = name;\r
+        shortname = lastdot+1;\r
+    }\r
+\r
+    p = _PyImport_GetDynLoadFunc(name, shortname, pathname, fp);\r
+    if (PyErr_Occurred())\r
+        return NULL;\r
+    if (p == NULL) {\r
+        PyErr_Format(PyExc_ImportError,\r
+           "dynamic module does not define init function (init%.200s)",\r
+                     shortname);\r
+        return NULL;\r
+    }\r
+    oldcontext = _Py_PackageContext;\r
+    _Py_PackageContext = packagecontext;\r
+    (*p)();\r
+    _Py_PackageContext = oldcontext;\r
+    if (PyErr_Occurred())\r
+        return NULL;\r
+\r
+    m = PyDict_GetItemString(PyImport_GetModuleDict(), name);\r
+    if (m == NULL) {\r
+        PyErr_SetString(PyExc_SystemError,\r
+                        "dynamic module not initialized properly");\r
+        return NULL;\r
+    }\r
+    /* Remember the filename as the __file__ attribute */\r
+    if (PyModule_AddStringConstant(m, "__file__", pathname) < 0)\r
+        PyErr_Clear(); /* Not important enough to report */\r
+\r
+    if (_PyImport_FixupExtension(name, pathname) == NULL)\r
+        return NULL;\r
+    if (Py_VerboseFlag)\r
+        PySys_WriteStderr(\r
+            "import %s # dynamically loaded from %s\n",\r
+            name, pathname);\r
+    Py_INCREF(m);\r
+    return m;\r
+}\r
+\r
+#endif /* HAVE_DYNAMIC_LOADING */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/importdl.h b/AppPkg/Applications/Python/Python-2.7.10/Python/importdl.h
new file mode 100644 (file)
index 0000000..7e17246
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef Py_IMPORTDL_H\r
+#define Py_IMPORTDL_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Definitions for dynamic loading of extension modules */\r
+enum filetype {\r
+    SEARCH_ERROR,\r
+    PY_SOURCE,\r
+    PY_COMPILED,\r
+    C_EXTENSION,\r
+    PY_RESOURCE, /* Mac only */\r
+    PKG_DIRECTORY,\r
+    C_BUILTIN,\r
+    PY_FROZEN,\r
+    PY_CODERESOURCE, /* Mac only */\r
+    IMP_HOOK\r
+};\r
+\r
+struct filedescr {\r
+    char *suffix;\r
+    char *mode;\r
+    enum filetype type;\r
+};\r
+extern struct filedescr * _PyImport_Filetab;\r
+extern const struct filedescr _PyImport_DynLoadFiletab[];\r
+\r
+extern PyObject *_PyImport_LoadDynamicModule(char *name, char *pathname,\r
+                                             FILE *);\r
+\r
+/* Max length of module suffix searched for -- accommodates "module.slb" */\r
+#define MAXSUFFIXSIZE 12\r
+\r
+#ifdef MS_WINDOWS\r
+#include <windows.h>\r
+typedef FARPROC dl_funcptr;\r
+#else\r
+#if defined(PYOS_OS2) && !defined(PYCC_GCC)\r
+#include <os2def.h>\r
+typedef int (* APIENTRY dl_funcptr)();\r
+#else\r
+typedef void (*dl_funcptr)(void);\r
+#endif\r
+#endif\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif /* !Py_IMPORTDL_H */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/modsupport.c b/AppPkg/Applications/Python/Python-2.7.10/Python/modsupport.c
new file mode 100644 (file)
index 0000000..e383bdf
--- /dev/null
@@ -0,0 +1,644 @@
+\r
+/* Module support implementation */\r
+\r
+#include "Python.h"\r
+\r
+#define FLAG_SIZE_T 1\r
+typedef double va_double;\r
+\r
+static PyObject *va_build_value(const char *, va_list, int);\r
+\r
+/* Package context -- the full module name for package imports */\r
+char *_Py_PackageContext = NULL;\r
+\r
+/* Py_InitModule4() parameters:\r
+   - name is the module name\r
+   - methods is the list of top-level functions\r
+   - doc is the documentation string\r
+   - passthrough is passed as self to functions defined in the module\r
+   - api_version is the value of PYTHON_API_VERSION at the time the\r
+     module was compiled\r
+\r
+   Return value is a borrowed reference to the module object; or NULL\r
+   if an error occurred (in Python 1.4 and before, errors were fatal).\r
+   Errors may still leak memory.\r
+*/\r
+\r
+static char api_version_warning[] =\r
+"Python C API version mismatch for module %.100s:\\r
+ This Python has API version %d, module %.100s has version %d.";\r
+\r
+PyObject *\r
+Py_InitModule4(const char *name, PyMethodDef *methods, const char *doc,\r
+               PyObject *passthrough, int module_api_version)\r
+{\r
+    PyObject *m, *d, *v, *n;\r
+    PyMethodDef *ml;\r
+    PyInterpreterState *interp = PyThreadState_Get()->interp;\r
+    if (interp->modules == NULL)\r
+        Py_FatalError("Python import machinery not initialized");\r
+    if (module_api_version != PYTHON_API_VERSION) {\r
+        char message[512];\r
+        PyOS_snprintf(message, sizeof(message),\r
+                      api_version_warning, name,\r
+                      PYTHON_API_VERSION, name,\r
+                      module_api_version);\r
+        if (PyErr_Warn(PyExc_RuntimeWarning, message))\r
+            return NULL;\r
+    }\r
+    /* Make sure name is fully qualified.\r
+\r
+       This is a bit of a hack: when the shared library is loaded,\r
+       the module name is "package.module", but the module calls\r
+       Py_InitModule*() with just "module" for the name.  The shared\r
+       library loader squirrels away the true name of the module in\r
+       _Py_PackageContext, and Py_InitModule*() will substitute this\r
+       (if the name actually matches).\r
+    */\r
+    if (_Py_PackageContext != NULL) {\r
+        char *p = strrchr(_Py_PackageContext, '.');\r
+        if (p != NULL && strcmp(name, p+1) == 0) {\r
+            name = _Py_PackageContext;\r
+            _Py_PackageContext = NULL;\r
+        }\r
+    }\r
+    if ((m = PyImport_AddModule(name)) == NULL)\r
+        return NULL;\r
+    d = PyModule_GetDict(m);\r
+    if (methods != NULL) {\r
+        n = PyString_FromString(name);\r
+        if (n == NULL)\r
+            return NULL;\r
+        for (ml = methods; ml->ml_name != NULL; ml++) {\r
+            if ((ml->ml_flags & METH_CLASS) ||\r
+                (ml->ml_flags & METH_STATIC)) {\r
+                PyErr_SetString(PyExc_ValueError,\r
+                                "module functions cannot set"\r
+                                " METH_CLASS or METH_STATIC");\r
+                Py_DECREF(n);\r
+                return NULL;\r
+            }\r
+            v = PyCFunction_NewEx(ml, passthrough, n);\r
+            if (v == NULL) {\r
+                Py_DECREF(n);\r
+                return NULL;\r
+            }\r
+            if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {\r
+                Py_DECREF(v);\r
+                Py_DECREF(n);\r
+                return NULL;\r
+            }\r
+            Py_DECREF(v);\r
+        }\r
+        Py_DECREF(n);\r
+    }\r
+    if (doc != NULL) {\r
+        v = PyString_FromString(doc);\r
+        if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0) {\r
+            Py_XDECREF(v);\r
+            return NULL;\r
+        }\r
+        Py_DECREF(v);\r
+    }\r
+    return m;\r
+}\r
+\r
+\r
+/* Helper for mkvalue() to scan the length of a format */\r
+\r
+static int\r
+countformat(const char *format, int endchar)\r
+{\r
+    int count = 0;\r
+    int level = 0;\r
+    while (level > 0 || *format != endchar) {\r
+        switch (*format) {\r
+        case '\0':\r
+            /* Premature end */\r
+            PyErr_SetString(PyExc_SystemError,\r
+                            "unmatched paren in format");\r
+            return -1;\r
+        case '(':\r
+        case '[':\r
+        case '{':\r
+            if (level == 0)\r
+                count++;\r
+            level++;\r
+            break;\r
+        case ')':\r
+        case ']':\r
+        case '}':\r
+            level--;\r
+            break;\r
+        case '#':\r
+        case '&':\r
+        case ',':\r
+        case ':':\r
+        case ' ':\r
+        case '\t':\r
+            break;\r
+        default:\r
+            if (level == 0)\r
+                count++;\r
+        }\r
+        format++;\r
+    }\r
+    return count;\r
+}\r
+\r
+\r
+/* Generic function to create a value -- the inverse of getargs() */\r
+/* After an original idea and first implementation by Steven Miale */\r
+\r
+static PyObject *do_mktuple(const char**, va_list *, int, int, int);\r
+static PyObject *do_mklist(const char**, va_list *, int, int, int);\r
+static PyObject *do_mkdict(const char**, va_list *, int, int, int);\r
+static PyObject *do_mkvalue(const char**, va_list *, int);\r
+\r
+\r
+static PyObject *\r
+do_mkdict(const char **p_format, va_list *p_va, int endchar, int n, int flags)\r
+{\r
+    PyObject *d;\r
+    int i;\r
+    int itemfailed = 0;\r
+    if (n < 0)\r
+        return NULL;\r
+    if ((d = PyDict_New()) == NULL)\r
+        return NULL;\r
+    /* Note that we can't bail immediately on error as this will leak\r
+       refcounts on any 'N' arguments. */\r
+    for (i = 0; i < n; i+= 2) {\r
+        PyObject *k, *v;\r
+        int err;\r
+        k = do_mkvalue(p_format, p_va, flags);\r
+        if (k == NULL) {\r
+            itemfailed = 1;\r
+            Py_INCREF(Py_None);\r
+            k = Py_None;\r
+        }\r
+        v = do_mkvalue(p_format, p_va, flags);\r
+        if (v == NULL) {\r
+            itemfailed = 1;\r
+            Py_INCREF(Py_None);\r
+            v = Py_None;\r
+        }\r
+        err = PyDict_SetItem(d, k, v);\r
+        Py_DECREF(k);\r
+        Py_DECREF(v);\r
+        if (err < 0 || itemfailed) {\r
+            Py_DECREF(d);\r
+            return NULL;\r
+        }\r
+    }\r
+    if (d != NULL && **p_format != endchar) {\r
+        Py_DECREF(d);\r
+        d = NULL;\r
+        PyErr_SetString(PyExc_SystemError,\r
+                        "Unmatched paren in format");\r
+    }\r
+    else if (endchar)\r
+        ++*p_format;\r
+    return d;\r
+}\r
+\r
+static PyObject *\r
+do_mklist(const char **p_format, va_list *p_va, int endchar, int n, int flags)\r
+{\r
+    PyObject *v;\r
+    int i;\r
+    int itemfailed = 0;\r
+    if (n < 0)\r
+        return NULL;\r
+    v = PyList_New(n);\r
+    if (v == NULL)\r
+        return NULL;\r
+    /* Note that we can't bail immediately on error as this will leak\r
+       refcounts on any 'N' arguments. */\r
+    for (i = 0; i < n; i++) {\r
+        PyObject *w = do_mkvalue(p_format, p_va, flags);\r
+        if (w == NULL) {\r
+            itemfailed = 1;\r
+            Py_INCREF(Py_None);\r
+            w = Py_None;\r
+        }\r
+        PyList_SET_ITEM(v, i, w);\r
+    }\r
+\r
+    if (itemfailed) {\r
+        /* do_mkvalue() should have already set an error */\r
+        Py_DECREF(v);\r
+        return NULL;\r
+    }\r
+    if (**p_format != endchar) {\r
+        Py_DECREF(v);\r
+        PyErr_SetString(PyExc_SystemError,\r
+                        "Unmatched paren in format");\r
+        return NULL;\r
+    }\r
+    if (endchar)\r
+        ++*p_format;\r
+    return v;\r
+}\r
+\r
+#ifdef Py_USING_UNICODE\r
+static int\r
+_ustrlen(Py_UNICODE *u)\r
+{\r
+    int i = 0;\r
+    Py_UNICODE *v = u;\r
+    while (*v != 0) { i++; v++; }\r
+    return i;\r
+}\r
+#endif\r
+\r
+static PyObject *\r
+do_mktuple(const char **p_format, va_list *p_va, int endchar, int n, int flags)\r
+{\r
+    PyObject *v;\r
+    int i;\r
+    int itemfailed = 0;\r
+    if (n < 0)\r
+        return NULL;\r
+    if ((v = PyTuple_New(n)) == NULL)\r
+        return NULL;\r
+    /* Note that we can't bail immediately on error as this will leak\r
+       refcounts on any 'N' arguments. */\r
+    for (i = 0; i < n; i++) {\r
+        PyObject *w = do_mkvalue(p_format, p_va, flags);\r
+        if (w == NULL) {\r
+            itemfailed = 1;\r
+            Py_INCREF(Py_None);\r
+            w = Py_None;\r
+        }\r
+        PyTuple_SET_ITEM(v, i, w);\r
+    }\r
+    if (itemfailed) {\r
+        /* do_mkvalue() should have already set an error */\r
+        Py_DECREF(v);\r
+        return NULL;\r
+    }\r
+    if (**p_format != endchar) {\r
+        Py_DECREF(v);\r
+        PyErr_SetString(PyExc_SystemError,\r
+                        "Unmatched paren in format");\r
+        return NULL;\r
+    }\r
+    if (endchar)\r
+        ++*p_format;\r
+    return v;\r
+}\r
+\r
+static PyObject *\r
+do_mkvalue(const char **p_format, va_list *p_va, int flags)\r
+{\r
+    for (;;) {\r
+        switch (*(*p_format)++) {\r
+        case '(':\r
+            return do_mktuple(p_format, p_va, ')',\r
+                              countformat(*p_format, ')'), flags);\r
+\r
+        case '[':\r
+            return do_mklist(p_format, p_va, ']',\r
+                             countformat(*p_format, ']'), flags);\r
+\r
+        case '{':\r
+            return do_mkdict(p_format, p_va, '}',\r
+                             countformat(*p_format, '}'), flags);\r
+\r
+        case 'b':\r
+        case 'B':\r
+        case 'h':\r
+        case 'i':\r
+            return PyInt_FromLong((long)va_arg(*p_va, int));\r
+\r
+        case 'H':\r
+            return PyInt_FromLong((long)va_arg(*p_va, unsigned int));\r
+\r
+        case 'I':\r
+        {\r
+            unsigned int n;\r
+            n = va_arg(*p_va, unsigned int);\r
+            if (n > (unsigned long)PyInt_GetMax())\r
+                return PyLong_FromUnsignedLong((unsigned long)n);\r
+            else\r
+                return PyInt_FromLong(n);\r
+        }\r
+\r
+        case 'n':\r
+#if SIZEOF_SIZE_T!=SIZEOF_LONG\r
+            return PyInt_FromSsize_t(va_arg(*p_va, Py_ssize_t));\r
+#endif\r
+            /* Fall through from 'n' to 'l' if Py_ssize_t is long */\r
+        case 'l':\r
+            return PyInt_FromLong(va_arg(*p_va, long));\r
+\r
+        case 'k':\r
+        {\r
+            unsigned long n;\r
+            n = va_arg(*p_va, unsigned long);\r
+            if (n > (unsigned long)PyInt_GetMax())\r
+                return PyLong_FromUnsignedLong(n);\r
+            else\r
+                return PyInt_FromLong(n);\r
+        }\r
+\r
+#ifdef HAVE_LONG_LONG\r
+        case 'L':\r
+            return PyLong_FromLongLong((PY_LONG_LONG)va_arg(*p_va, PY_LONG_LONG));\r
+\r
+        case 'K':\r
+            return PyLong_FromUnsignedLongLong((PY_LONG_LONG)va_arg(*p_va, unsigned PY_LONG_LONG));\r
+#endif\r
+#ifdef Py_USING_UNICODE\r
+        case 'u':\r
+        {\r
+            PyObject *v;\r
+            Py_UNICODE *u = va_arg(*p_va, Py_UNICODE *);\r
+            Py_ssize_t n;\r
+            if (**p_format == '#') {\r
+                ++*p_format;\r
+                if (flags & FLAG_SIZE_T)\r
+                    n = va_arg(*p_va, Py_ssize_t);\r
+                else\r
+                    n = va_arg(*p_va, int);\r
+            }\r
+            else\r
+                n = -1;\r
+            if (u == NULL) {\r
+                v = Py_None;\r
+                Py_INCREF(v);\r
+            }\r
+            else {\r
+                if (n < 0)\r
+                    n = _ustrlen(u);\r
+                v = PyUnicode_FromUnicode(u, n);\r
+            }\r
+            return v;\r
+        }\r
+#endif\r
+        case 'f':\r
+        case 'd':\r
+            return PyFloat_FromDouble(\r
+                (double)va_arg(*p_va, va_double));\r
+\r
+#ifndef WITHOUT_COMPLEX\r
+        case 'D':\r
+            return PyComplex_FromCComplex(\r
+                *((Py_complex *)va_arg(*p_va, Py_complex *)));\r
+#endif /* WITHOUT_COMPLEX */\r
+\r
+        case 'c':\r
+        {\r
+            char p[1];\r
+            p[0] = (char)va_arg(*p_va, int);\r
+            return PyString_FromStringAndSize(p, 1);\r
+        }\r
+\r
+        case 's':\r
+        case 'z':\r
+        {\r
+            PyObject *v;\r
+            char *str = va_arg(*p_va, char *);\r
+            Py_ssize_t n;\r
+            if (**p_format == '#') {\r
+                ++*p_format;\r
+                if (flags & FLAG_SIZE_T)\r
+                    n = va_arg(*p_va, Py_ssize_t);\r
+                else\r
+                    n = va_arg(*p_va, int);\r
+            }\r
+            else\r
+                n = -1;\r
+            if (str == NULL) {\r
+                v = Py_None;\r
+                Py_INCREF(v);\r
+            }\r
+            else {\r
+                if (n < 0) {\r
+                    size_t m = strlen(str);\r
+                    if (m > PY_SSIZE_T_MAX) {\r
+                        PyErr_SetString(PyExc_OverflowError,\r
+                            "string too long for Python string");\r
+                        return NULL;\r
+                    }\r
+                    n = (Py_ssize_t)m;\r
+                }\r
+                v = PyString_FromStringAndSize(str, n);\r
+            }\r
+            return v;\r
+        }\r
+\r
+        case 'N':\r
+        case 'S':\r
+        case 'O':\r
+        if (**p_format == '&') {\r
+            typedef PyObject *(*converter)(void *);\r
+            converter func = va_arg(*p_va, converter);\r
+            void *arg = va_arg(*p_va, void *);\r
+            ++*p_format;\r
+            return (*func)(arg);\r
+        }\r
+        else {\r
+            PyObject *v;\r
+            v = va_arg(*p_va, PyObject *);\r
+            if (v != NULL) {\r
+                if (*(*p_format - 1) != 'N')\r
+                    Py_INCREF(v);\r
+            }\r
+            else if (!PyErr_Occurred())\r
+                /* If a NULL was passed\r
+                 * because a call that should\r
+                 * have constructed a value\r
+                 * failed, that's OK, and we\r
+                 * pass the error on; but if\r
+                 * no error occurred it's not\r
+                 * clear that the caller knew\r
+                 * what she was doing. */\r
+                PyErr_SetString(PyExc_SystemError,\r
+                    "NULL object passed to Py_BuildValue");\r
+            return v;\r
+        }\r
+\r
+        case ':':\r
+        case ',':\r
+        case ' ':\r
+        case '\t':\r
+            break;\r
+\r
+        default:\r
+            PyErr_SetString(PyExc_SystemError,\r
+                "bad format char passed to Py_BuildValue");\r
+            return NULL;\r
+\r
+        }\r
+    }\r
+}\r
+\r
+\r
+PyObject *\r
+Py_BuildValue(const char *format, ...)\r
+{\r
+    va_list va;\r
+    PyObject* retval;\r
+    va_start(va, format);\r
+    retval = va_build_value(format, va, 0);\r
+    va_end(va);\r
+    return retval;\r
+}\r
+\r
+PyObject *\r
+_Py_BuildValue_SizeT(const char *format, ...)\r
+{\r
+    va_list va;\r
+    PyObject* retval;\r
+    va_start(va, format);\r
+    retval = va_build_value(format, va, FLAG_SIZE_T);\r
+    va_end(va);\r
+    return retval;\r
+}\r
+\r
+PyObject *\r
+Py_VaBuildValue(const char *format, va_list va)\r
+{\r
+    return va_build_value(format, va, 0);\r
+}\r
+\r
+PyObject *\r
+_Py_VaBuildValue_SizeT(const char *format, va_list va)\r
+{\r
+    return va_build_value(format, va, FLAG_SIZE_T);\r
+}\r
+\r
+static PyObject *\r
+va_build_value(const char *format, va_list va, int flags)\r
+{\r
+    const char *f = format;\r
+    int n = countformat(f, '\0');\r
+    va_list lva;\r
+\r
+#ifdef VA_LIST_IS_ARRAY\r
+    memcpy(lva, va, sizeof(va_list));\r
+#else\r
+#ifdef __va_copy\r
+    __va_copy(lva, va);\r
+#else\r
+    lva = va;\r
+#endif\r
+#endif\r
+\r
+    if (n < 0)\r
+        return NULL;\r
+    if (n == 0) {\r
+        Py_INCREF(Py_None);\r
+        return Py_None;\r
+    }\r
+    if (n == 1)\r
+        return do_mkvalue(&f, &lva, flags);\r
+    return do_mktuple(&f, &lva, '\0', n, flags);\r
+}\r
+\r
+\r
+PyObject *\r
+PyEval_CallFunction(PyObject *obj, const char *format, ...)\r
+{\r
+    va_list vargs;\r
+    PyObject *args;\r
+    PyObject *res;\r
+\r
+    va_start(vargs, format);\r
+\r
+    args = Py_VaBuildValue(format, vargs);\r
+    va_end(vargs);\r
+\r
+    if (args == NULL)\r
+        return NULL;\r
+\r
+    res = PyEval_CallObject(obj, args);\r
+    Py_DECREF(args);\r
+\r
+    return res;\r
+}\r
+\r
+\r
+PyObject *\r
+PyEval_CallMethod(PyObject *obj, const char *methodname, const char *format, ...)\r
+{\r
+    va_list vargs;\r
+    PyObject *meth;\r
+    PyObject *args;\r
+    PyObject *res;\r
+\r
+    meth = PyObject_GetAttrString(obj, methodname);\r
+    if (meth == NULL)\r
+        return NULL;\r
+\r
+    va_start(vargs, format);\r
+\r
+    args = Py_VaBuildValue(format, vargs);\r
+    va_end(vargs);\r
+\r
+    if (args == NULL) {\r
+        Py_DECREF(meth);\r
+        return NULL;\r
+    }\r
+\r
+    res = PyEval_CallObject(meth, args);\r
+    Py_DECREF(meth);\r
+    Py_DECREF(args);\r
+\r
+    return res;\r
+}\r
+\r
+int\r
+PyModule_AddObject(PyObject *m, const char *name, PyObject *o)\r
+{\r
+    PyObject *dict;\r
+    if (!PyModule_Check(m)) {\r
+        PyErr_SetString(PyExc_TypeError,\r
+                    "PyModule_AddObject() needs module as first arg");\r
+        return -1;\r
+    }\r
+    if (!o) {\r
+        if (!PyErr_Occurred())\r
+            PyErr_SetString(PyExc_TypeError,\r
+                            "PyModule_AddObject() needs non-NULL value");\r
+        return -1;\r
+    }\r
+\r
+    dict = PyModule_GetDict(m);\r
+    if (dict == NULL) {\r
+        /* Internal error -- modules must have a dict! */\r
+        PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__",\r
+                     PyModule_GetName(m));\r
+        return -1;\r
+    }\r
+    if (PyDict_SetItemString(dict, name, o))\r
+        return -1;\r
+    Py_DECREF(o);\r
+    return 0;\r
+}\r
+\r
+int\r
+PyModule_AddIntConstant(PyObject *m, const char *name, long value)\r
+{\r
+    PyObject *o = PyInt_FromLong(value);\r
+    if (!o)\r
+        return -1;\r
+    if (PyModule_AddObject(m, name, o) == 0)\r
+        return 0;\r
+    Py_DECREF(o);\r
+    return -1;\r
+}\r
+\r
+int\r
+PyModule_AddStringConstant(PyObject *m, const char *name, const char *value)\r
+{\r
+    PyObject *o = PyString_FromString(value);\r
+    if (!o)\r
+        return -1;\r
+    if (PyModule_AddObject(m, name, o) == 0)\r
+        return 0;\r
+    Py_DECREF(o);\r
+    return -1;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/mysnprintf.c b/AppPkg/Applications/Python/Python-2.7.10/Python/mysnprintf.c
new file mode 100644 (file)
index 0000000..f9481a8
--- /dev/null
@@ -0,0 +1,105 @@
+#include "Python.h"\r
+#include <ctype.h>\r
+\r
+/* snprintf() wrappers.  If the platform has vsnprintf, we use it, else we\r
+   emulate it in a half-hearted way.  Even if the platform has it, we wrap\r
+   it because platforms differ in what vsnprintf does in case the buffer\r
+   is too small:  C99 behavior is to return the number of characters that\r
+   would have been written had the buffer not been too small, and to set\r
+   the last byte of the buffer to \0.  At least MS _vsnprintf returns a\r
+   negative value instead, and fills the entire buffer with non-\0 data.\r
+\r
+   The wrappers ensure that str[size-1] is always \0 upon return.\r
+\r
+   PyOS_snprintf and PyOS_vsnprintf never write more than size bytes\r
+   (including the trailing '\0') into str.\r
+\r
+   If the platform doesn't have vsnprintf, and the buffer size needed to\r
+   avoid truncation exceeds size by more than 512, Python aborts with a\r
+   Py_FatalError.\r
+\r
+   Return value (rv):\r
+\r
+    When 0 <= rv < size, the output conversion was unexceptional, and\r
+    rv characters were written to str (excluding a trailing \0 byte at\r
+    str[rv]).\r
+\r
+    When rv >= size, output conversion was truncated, and a buffer of\r
+    size rv+1 would have been needed to avoid truncation.  str[size-1]\r
+    is \0 in this case.\r
+\r
+    When rv < 0, "something bad happened".  str[size-1] is \0 in this\r
+    case too, but the rest of str is unreliable.  It could be that\r
+    an error in format codes was detected by libc, or on platforms\r
+    with a non-C99 vsnprintf simply that the buffer wasn't big enough\r
+    to avoid truncation, or on platforms without any vsnprintf that\r
+    PyMem_Malloc couldn't obtain space for a temp buffer.\r
+\r
+   CAUTION:  Unlike C99, str != NULL and size > 0 are required.\r
+*/\r
+\r
+int\r
+PyOS_snprintf(char *str, size_t size, const  char  *format, ...)\r
+{\r
+    int rc;\r
+    va_list va;\r
+\r
+    va_start(va, format);\r
+    rc = PyOS_vsnprintf(str, size, format, va);\r
+    va_end(va);\r
+    return rc;\r
+}\r
+\r
+int\r
+PyOS_vsnprintf(char *str, size_t size, const char  *format, va_list va)\r
+{\r
+    int len;  /* # bytes written, excluding \0 */\r
+#ifdef HAVE_SNPRINTF\r
+#define _PyOS_vsnprintf_EXTRA_SPACE 1\r
+#else\r
+#define _PyOS_vsnprintf_EXTRA_SPACE 512\r
+    char *buffer;\r
+#endif\r
+    assert(str != NULL);\r
+    assert(size > 0);\r
+    assert(format != NULL);\r
+    /* We take a size_t as input but return an int.  Sanity check\r
+     * our input so that it won't cause an overflow in the\r
+     * vsnprintf return value or the buffer malloc size.  */\r
+    if (size > INT_MAX - _PyOS_vsnprintf_EXTRA_SPACE) {\r
+        len = -666;\r
+        goto Done;\r
+    }\r
+\r
+#ifdef HAVE_SNPRINTF\r
+    len = vsnprintf(str, size, format, va);\r
+#else\r
+    /* Emulate it. */\r
+    buffer = PyMem_MALLOC(size + _PyOS_vsnprintf_EXTRA_SPACE);\r
+    if (buffer == NULL) {\r
+        len = -666;\r
+        goto Done;\r
+    }\r
+\r
+    len = vsprintf(buffer, format, va);\r
+    if (len < 0)\r
+        /* ignore the error */;\r
+\r
+    else if ((size_t)len >= size + _PyOS_vsnprintf_EXTRA_SPACE)\r
+        Py_FatalError("Buffer overflow in PyOS_snprintf/PyOS_vsnprintf");\r
+\r
+    else {\r
+        const size_t to_copy = (size_t)len < size ?\r
+                                (size_t)len : size - 1;\r
+        assert(to_copy < size);\r
+        memcpy(str, buffer, to_copy);\r
+        str[to_copy] = '\0';\r
+    }\r
+    PyMem_FREE(buffer);\r
+#endif\r
+Done:\r
+    if (size > 0)\r
+        str[size-1] = '\0';\r
+    return len;\r
+#undef _PyOS_vsnprintf_EXTRA_SPACE\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/mystrtoul.c b/AppPkg/Applications/Python/Python-2.7.10/Python/mystrtoul.c
new file mode 100644 (file)
index 0000000..096eb16
--- /dev/null
@@ -0,0 +1,285 @@
+\r
+#include "Python.h"\r
+\r
+#if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE)\r
+#define _SGI_MP_SOURCE\r
+#endif\r
+\r
+/* strtol and strtoul, renamed to avoid conflicts */\r
+\r
+\r
+#include <ctype.h>\r
+#ifdef HAVE_ERRNO_H\r
+#include <errno.h>\r
+#endif\r
+\r
+/* Static overflow check values for bases 2 through 36.\r
+ * smallmax[base] is the largest unsigned long i such that\r
+ * i * base doesn't overflow unsigned long.\r
+ */\r
+static unsigned long smallmax[] = {\r
+    0, /* bases 0 and 1 are invalid */\r
+    0,\r
+    ULONG_MAX / 2,\r
+    ULONG_MAX / 3,\r
+    ULONG_MAX / 4,\r
+    ULONG_MAX / 5,\r
+    ULONG_MAX / 6,\r
+    ULONG_MAX / 7,\r
+    ULONG_MAX / 8,\r
+    ULONG_MAX / 9,\r
+    ULONG_MAX / 10,\r
+    ULONG_MAX / 11,\r
+    ULONG_MAX / 12,\r
+    ULONG_MAX / 13,\r
+    ULONG_MAX / 14,\r
+    ULONG_MAX / 15,\r
+    ULONG_MAX / 16,\r
+    ULONG_MAX / 17,\r
+    ULONG_MAX / 18,\r
+    ULONG_MAX / 19,\r
+    ULONG_MAX / 20,\r
+    ULONG_MAX / 21,\r
+    ULONG_MAX / 22,\r
+    ULONG_MAX / 23,\r
+    ULONG_MAX / 24,\r
+    ULONG_MAX / 25,\r
+    ULONG_MAX / 26,\r
+    ULONG_MAX / 27,\r
+    ULONG_MAX / 28,\r
+    ULONG_MAX / 29,\r
+    ULONG_MAX / 30,\r
+    ULONG_MAX / 31,\r
+    ULONG_MAX / 32,\r
+    ULONG_MAX / 33,\r
+    ULONG_MAX / 34,\r
+    ULONG_MAX / 35,\r
+    ULONG_MAX / 36,\r
+};\r
+\r
+/* maximum digits that can't ever overflow for bases 2 through 36,\r
+ * calculated by [int(math.floor(math.log(2**32, i))) for i in range(2, 37)].\r
+ * Note that this is pessimistic if sizeof(long) > 4.\r
+ */\r
+#if SIZEOF_LONG == 4\r
+static int digitlimit[] = {\r
+    0,  0, 32, 20, 16, 13, 12, 11, 10, 10,  /*  0 -  9 */\r
+    9,  9,  8,  8,  8,  8,  8,  7,  7,  7,  /* 10 - 19 */\r
+    7,  7,  7,  7,  6,  6,  6,  6,  6,  6,  /* 20 - 29 */\r
+    6,  6,  6,  6,  6,  6,  6};             /* 30 - 36 */\r
+#elif SIZEOF_LONG == 8\r
+/* [int(math.floor(math.log(2**64, i))) for i in range(2, 37)] */\r
+static int digitlimit[] = {\r
+         0,   0, 64, 40, 32, 27, 24, 22, 21, 20,  /*  0 -  9 */\r
+    19,  18, 17, 17, 16, 16, 16, 15, 15, 15,  /* 10 - 19 */\r
+    14,  14, 14, 14, 13, 13, 13, 13, 13, 13,  /* 20 - 29 */\r
+    13,  12, 12, 12, 12, 12, 12};             /* 30 - 36 */\r
+#else\r
+#error "Need table for SIZEOF_LONG"\r
+#endif\r
+\r
+/*\r
+**      strtoul\r
+**              This is a general purpose routine for converting\r
+**              an ascii string to an integer in an arbitrary base.\r
+**              Leading white space is ignored.  If 'base' is zero\r
+**              it looks for a leading 0, 0b, 0B, 0o, 0O, 0x or 0X\r
+**              to tell which base.  If these are absent it defaults\r
+**              to 10. Base must be 0 or between 2 and 36 (inclusive).\r
+**              If 'ptr' is non-NULL it will contain a pointer to\r
+**              the end of the scan.\r
+**              Errors due to bad pointers will probably result in\r
+**              exceptions - we don't check for them.\r
+*/\r
+unsigned long\r
+PyOS_strtoul(register char *str, char **ptr, int base)\r
+{\r
+    register unsigned long result = 0; /* return value of the function */\r
+    register int c;             /* current input character */\r
+    register int ovlimit;       /* required digits to overflow */\r
+\r
+    /* skip leading white space */\r
+    while (*str && isspace(Py_CHARMASK(*str)))\r
+        ++str;\r
+\r
+    /* check for leading 0 or 0x for auto-base or base 16 */\r
+    switch (base) {\r
+    case 0:             /* look for leading 0, 0b, 0o or 0x */\r
+        if (*str == '0') {\r
+            ++str;\r
+            if (*str == 'x' || *str == 'X') {\r
+                /* there must be at least one digit after 0x */\r
+                if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) {\r
+                    if (ptr)\r
+                        *ptr = str;\r
+                    return 0;\r
+                }\r
+                ++str;\r
+                base = 16;\r
+            } else if (*str == 'o' || *str == 'O') {\r
+                /* there must be at least one digit after 0o */\r
+                if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 8) {\r
+                    if (ptr)\r
+                        *ptr = str;\r
+                    return 0;\r
+                }\r
+                ++str;\r
+                base = 8;\r
+            } else if (*str == 'b' || *str == 'B') {\r
+                /* there must be at least one digit after 0b */\r
+                if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 2) {\r
+                    if (ptr)\r
+                        *ptr = str;\r
+                    return 0;\r
+                }\r
+                ++str;\r
+                base = 2;\r
+            } else {\r
+                base = 8;\r
+            }\r
+        }\r
+        else\r
+            base = 10;\r
+        break;\r
+\r
+    case 2:     /* skip leading 0b or 0B */\r
+        if (*str == '0') {\r
+            ++str;\r
+            if (*str == 'b' || *str == 'B') {\r
+                /* there must be at least one digit after 0b */\r
+                if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 2) {\r
+                    if (ptr)\r
+                        *ptr = str;\r
+                    return 0;\r
+                }\r
+                ++str;\r
+            }\r
+        }\r
+        break;\r
+\r
+    case 8:     /* skip leading 0o or 0O */\r
+        if (*str == '0') {\r
+            ++str;\r
+            if (*str == 'o' || *str == 'O') {\r
+                /* there must be at least one digit after 0o */\r
+                if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 8) {\r
+                    if (ptr)\r
+                        *ptr = str;\r
+                    return 0;\r
+                }\r
+                ++str;\r
+            }\r
+        }\r
+        break;\r
+\r
+    case 16:            /* skip leading 0x or 0X */\r
+        if (*str == '0') {\r
+            ++str;\r
+            if (*str == 'x' || *str == 'X') {\r
+                /* there must be at least one digit after 0x */\r
+                if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) {\r
+                    if (ptr)\r
+                        *ptr = str;\r
+                    return 0;\r
+                }\r
+                ++str;\r
+            }\r
+        }\r
+        break;\r
+    }\r
+\r
+    /* catch silly bases */\r
+    if (base < 2 || base > 36) {\r
+        if (ptr)\r
+            *ptr = str;\r
+        return 0;\r
+    }\r
+\r
+    /* skip leading zeroes */\r
+    while (*str == '0')\r
+        ++str;\r
+\r
+    /* base is guaranteed to be in [2, 36] at this point */\r
+    ovlimit = digitlimit[base];\r
+\r
+    /* do the conversion until non-digit character encountered */\r
+    while ((c = _PyLong_DigitValue[Py_CHARMASK(*str)]) < base) {\r
+        if (ovlimit > 0) /* no overflow check required */\r
+            result = result * base + c;\r
+        else { /* requires overflow check */\r
+            register unsigned long temp_result;\r
+\r
+            if (ovlimit < 0) /* guaranteed overflow */\r
+                goto overflowed;\r
+\r
+            /* there could be an overflow */\r
+            /* check overflow just from shifting */\r
+            if (result > smallmax[base])\r
+                goto overflowed;\r
+\r
+            result *= base;\r
+\r
+            /* check overflow from the digit's value */\r
+            temp_result = result + c;\r
+            if (temp_result < result)\r
+                goto overflowed;\r
+\r
+            result = temp_result;\r
+        }\r
+\r
+        ++str;\r
+        --ovlimit;\r
+    }\r
+\r
+    /* set pointer to point to the last character scanned */\r
+    if (ptr)\r
+        *ptr = str;\r
+\r
+    return result;\r
+\r
+overflowed:\r
+    if (ptr) {\r
+        /* spool through remaining digit characters */\r
+        while (_PyLong_DigitValue[Py_CHARMASK(*str)] < base)\r
+            ++str;\r
+        *ptr = str;\r
+    }\r
+    errno = ERANGE;\r
+    return (unsigned long)-1;\r
+}\r
+\r
+/* Checking for overflow in PyOS_strtol is a PITA; see comments\r
+ * about PY_ABS_LONG_MIN in longobject.c.\r
+ */\r
+#define PY_ABS_LONG_MIN         (0-(unsigned long)LONG_MIN)\r
+\r
+long\r
+PyOS_strtol(char *str, char **ptr, int base)\r
+{\r
+    long result;\r
+    unsigned long uresult;\r
+    char sign;\r
+\r
+    while (*str && isspace(Py_CHARMASK(*str)))\r
+        str++;\r
+\r
+    sign = *str;\r
+    if (sign == '+' || sign == '-')\r
+        str++;\r
+\r
+    uresult = PyOS_strtoul(str, ptr, base);\r
+\r
+    if (uresult <= (unsigned long)LONG_MAX) {\r
+        result = (long)uresult;\r
+        if (sign == '-')\r
+            result = -result;\r
+    }\r
+    else if (sign == '-' && uresult == PY_ABS_LONG_MIN) {\r
+        result = LONG_MIN;\r
+    }\r
+    else {\r
+        errno = ERANGE;\r
+        result = LONG_MAX;\r
+    }\r
+    return result;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/peephole.c b/AppPkg/Applications/Python/Python-2.7.10/Python/peephole.c
new file mode 100644 (file)
index 0000000..54404a3
--- /dev/null
@@ -0,0 +1,667 @@
+/* Peephole optimizations for bytecode compiler. */\r
+\r
+#include "Python.h"\r
+\r
+#include "Python-ast.h"\r
+#include "node.h"\r
+#include "pyarena.h"\r
+#include "ast.h"\r
+#include "code.h"\r
+#include "compile.h"\r
+#include "symtable.h"\r
+#include "opcode.h"\r
+\r
+#define GETARG(arr, i) ((int)((arr[i+2]<<8) + arr[i+1]))\r
+#define UNCONDITIONAL_JUMP(op)  (op==JUMP_ABSOLUTE || op==JUMP_FORWARD)\r
+#define CONDITIONAL_JUMP(op) (op==POP_JUMP_IF_FALSE || op==POP_JUMP_IF_TRUE \\r
+    || op==JUMP_IF_FALSE_OR_POP || op==JUMP_IF_TRUE_OR_POP)\r
+#define ABSOLUTE_JUMP(op) (op==JUMP_ABSOLUTE || op==CONTINUE_LOOP \\r
+    || op==POP_JUMP_IF_FALSE || op==POP_JUMP_IF_TRUE \\r
+    || op==JUMP_IF_FALSE_OR_POP || op==JUMP_IF_TRUE_OR_POP)\r
+#define JUMPS_ON_TRUE(op) (op==POP_JUMP_IF_TRUE || op==JUMP_IF_TRUE_OR_POP)\r
+#define GETJUMPTGT(arr, i) (GETARG(arr,i) + (ABSOLUTE_JUMP(arr[i]) ? 0 : i+3))\r
+#define SETARG(arr, i, val) arr[i+2] = val>>8; arr[i+1] = val & 255\r
+#define CODESIZE(op)  (HAS_ARG(op) ? 3 : 1)\r
+#define ISBASICBLOCK(blocks, start, bytes) \\r
+    (blocks[start]==blocks[start+bytes-1])\r
+\r
+/* Replace LOAD_CONST c1. LOAD_CONST c2 ... LOAD_CONST cn BUILD_TUPLE n\r
+   with    LOAD_CONST (c1, c2, ... cn).\r
+   The consts table must still be in list form so that the\r
+   new constant (c1, c2, ... cn) can be appended.\r
+   Called with codestr pointing to the first LOAD_CONST.\r
+   Bails out with no change if one or more of the LOAD_CONSTs is missing.\r
+   Also works for BUILD_LIST when followed by an "in" or "not in" test.\r
+*/\r
+static int\r
+tuple_of_constants(unsigned char *codestr, Py_ssize_t n, PyObject *consts)\r
+{\r
+    PyObject *newconst, *constant;\r
+    Py_ssize_t i, arg, len_consts;\r
+\r
+    /* Pre-conditions */\r
+    assert(PyList_CheckExact(consts));\r
+    assert(codestr[n*3] == BUILD_TUPLE || codestr[n*3] == BUILD_LIST);\r
+    assert(GETARG(codestr, (n*3)) == n);\r
+    for (i=0 ; i<n ; i++)\r
+        assert(codestr[i*3] == LOAD_CONST);\r
+\r
+    /* Buildup new tuple of constants */\r
+    newconst = PyTuple_New(n);\r
+    if (newconst == NULL)\r
+        return 0;\r
+    len_consts = PyList_GET_SIZE(consts);\r
+    for (i=0 ; i<n ; i++) {\r
+        arg = GETARG(codestr, (i*3));\r
+        assert(arg < len_consts);\r
+        constant = PyList_GET_ITEM(consts, arg);\r
+        Py_INCREF(constant);\r
+        PyTuple_SET_ITEM(newconst, i, constant);\r
+    }\r
+\r
+    /* Append folded constant onto consts */\r
+    if (PyList_Append(consts, newconst)) {\r
+        Py_DECREF(newconst);\r
+        return 0;\r
+    }\r
+    Py_DECREF(newconst);\r
+\r
+    /* Write NOPs over old LOAD_CONSTS and\r
+       add a new LOAD_CONST newconst on top of the BUILD_TUPLE n */\r
+    memset(codestr, NOP, n*3);\r
+    codestr[n*3] = LOAD_CONST;\r
+    SETARG(codestr, (n*3), len_consts);\r
+    return 1;\r
+}\r
+\r
+/* Replace LOAD_CONST c1. LOAD_CONST c2 BINOP\r
+   with    LOAD_CONST binop(c1,c2)\r
+   The consts table must still be in list form so that the\r
+   new constant can be appended.\r
+   Called with codestr pointing to the first LOAD_CONST.\r
+   Abandons the transformation if the folding fails (i.e.  1+'a').\r
+   If the new constant is a sequence, only folds when the size\r
+   is below a threshold value.  That keeps pyc files from\r
+   becoming large in the presence of code like:  (None,)*1000.\r
+*/\r
+static int\r
+fold_binops_on_constants(unsigned char *codestr, PyObject *consts)\r
+{\r
+    PyObject *newconst, *v, *w;\r
+    Py_ssize_t len_consts, size;\r
+    int opcode;\r
+\r
+    /* Pre-conditions */\r
+    assert(PyList_CheckExact(consts));\r
+    assert(codestr[0] == LOAD_CONST);\r
+    assert(codestr[3] == LOAD_CONST);\r
+\r
+    /* Create new constant */\r
+    v = PyList_GET_ITEM(consts, GETARG(codestr, 0));\r
+    w = PyList_GET_ITEM(consts, GETARG(codestr, 3));\r
+    opcode = codestr[6];\r
+    switch (opcode) {\r
+        case BINARY_POWER:\r
+            newconst = PyNumber_Power(v, w, Py_None);\r
+            break;\r
+        case BINARY_MULTIPLY:\r
+            newconst = PyNumber_Multiply(v, w);\r
+            break;\r
+        case BINARY_DIVIDE:\r
+            /* Cannot fold this operation statically since\r
+               the result can depend on the run-time presence\r
+               of the -Qnew flag */\r
+            return 0;\r
+        case BINARY_TRUE_DIVIDE:\r
+            newconst = PyNumber_TrueDivide(v, w);\r
+            break;\r
+        case BINARY_FLOOR_DIVIDE:\r
+            newconst = PyNumber_FloorDivide(v, w);\r
+            break;\r
+        case BINARY_MODULO:\r
+            newconst = PyNumber_Remainder(v, w);\r
+            break;\r
+        case BINARY_ADD:\r
+            newconst = PyNumber_Add(v, w);\r
+            break;\r
+        case BINARY_SUBTRACT:\r
+            newconst = PyNumber_Subtract(v, w);\r
+            break;\r
+        case BINARY_SUBSCR:\r
+            /* #5057: if v is unicode, there might be differences between\r
+               wide and narrow builds in cases like '\U00012345'[0] or\r
+               '\U00012345abcdef'[3], so it's better to skip the optimization\r
+               in order to produce compatible pycs.\r
+            */\r
+            if (PyUnicode_Check(v))\r
+                return 0;\r
+            newconst = PyObject_GetItem(v, w);\r
+            break;\r
+        case BINARY_LSHIFT:\r
+            newconst = PyNumber_Lshift(v, w);\r
+            break;\r
+        case BINARY_RSHIFT:\r
+            newconst = PyNumber_Rshift(v, w);\r
+            break;\r
+        case BINARY_AND:\r
+            newconst = PyNumber_And(v, w);\r
+            break;\r
+        case BINARY_XOR:\r
+            newconst = PyNumber_Xor(v, w);\r
+            break;\r
+        case BINARY_OR:\r
+            newconst = PyNumber_Or(v, w);\r
+            break;\r
+        default:\r
+            /* Called with an unknown opcode */\r
+            PyErr_Format(PyExc_SystemError,\r
+                 "unexpected binary operation %d on a constant",\r
+                     opcode);\r
+            return 0;\r
+    }\r
+    if (newconst == NULL) {\r
+        PyErr_Clear();\r
+        return 0;\r
+    }\r
+    size = PyObject_Size(newconst);\r
+    if (size == -1)\r
+        PyErr_Clear();\r
+    else if (size > 20) {\r
+        Py_DECREF(newconst);\r
+        return 0;\r
+    }\r
+\r
+    /* Append folded constant into consts table */\r
+    len_consts = PyList_GET_SIZE(consts);\r
+    if (PyList_Append(consts, newconst)) {\r
+        Py_DECREF(newconst);\r
+        return 0;\r
+    }\r
+    Py_DECREF(newconst);\r
+\r
+    /* Write NOP NOP NOP NOP LOAD_CONST newconst */\r
+    memset(codestr, NOP, 4);\r
+    codestr[4] = LOAD_CONST;\r
+    SETARG(codestr, 4, len_consts);\r
+    return 1;\r
+}\r
+\r
+static int\r
+fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)\r
+{\r
+    PyObject *newconst=NULL, *v;\r
+    Py_ssize_t len_consts;\r
+    int opcode;\r
+\r
+    /* Pre-conditions */\r
+    assert(PyList_CheckExact(consts));\r
+    assert(codestr[0] == LOAD_CONST);\r
+\r
+    /* Create new constant */\r
+    v = PyList_GET_ITEM(consts, GETARG(codestr, 0));\r
+    opcode = codestr[3];\r
+    switch (opcode) {\r
+        case UNARY_NEGATIVE:\r
+            /* Preserve the sign of -0.0 */\r
+            if (PyObject_IsTrue(v) == 1)\r
+                newconst = PyNumber_Negative(v);\r
+            break;\r
+        case UNARY_CONVERT:\r
+            newconst = PyObject_Repr(v);\r
+            break;\r
+        case UNARY_INVERT:\r
+            newconst = PyNumber_Invert(v);\r
+            break;\r
+        default:\r
+            /* Called with an unknown opcode */\r
+            PyErr_Format(PyExc_SystemError,\r
+                 "unexpected unary operation %d on a constant",\r
+                     opcode);\r
+            return 0;\r
+    }\r
+    if (newconst == NULL) {\r
+        PyErr_Clear();\r
+        return 0;\r
+    }\r
+\r
+    /* Append folded constant into consts table */\r
+    len_consts = PyList_GET_SIZE(consts);\r
+    if (PyList_Append(consts, newconst)) {\r
+        Py_DECREF(newconst);\r
+        return 0;\r
+    }\r
+    Py_DECREF(newconst);\r
+\r
+    /* Write NOP LOAD_CONST newconst */\r
+    codestr[0] = NOP;\r
+    codestr[1] = LOAD_CONST;\r
+    SETARG(codestr, 1, len_consts);\r
+    return 1;\r
+}\r
+\r
+static unsigned int *\r
+markblocks(unsigned char *code, Py_ssize_t len)\r
+{\r
+    unsigned int *blocks = PyMem_New(unsigned int, len);\r
+    int i,j, opcode, blockcnt = 0;\r
+\r
+    if (blocks == NULL) {\r
+        PyErr_NoMemory();\r
+        return NULL;\r
+    }\r
+    memset(blocks, 0, len*sizeof(int));\r
+\r
+    /* Mark labels in the first pass */\r
+    for (i=0 ; i<len ; i+=CODESIZE(opcode)) {\r
+        opcode = code[i];\r
+        switch (opcode) {\r
+            case FOR_ITER:\r
+            case JUMP_FORWARD:\r
+            case JUMP_IF_FALSE_OR_POP:\r
+            case JUMP_IF_TRUE_OR_POP:\r
+            case POP_JUMP_IF_FALSE:\r
+            case POP_JUMP_IF_TRUE:\r
+            case JUMP_ABSOLUTE:\r
+            case CONTINUE_LOOP:\r
+            case SETUP_LOOP:\r
+            case SETUP_EXCEPT:\r
+            case SETUP_FINALLY:\r
+            case SETUP_WITH:\r
+                j = GETJUMPTGT(code, i);\r
+                blocks[j] = 1;\r
+                break;\r
+        }\r
+    }\r
+    /* Build block numbers in the second pass */\r
+    for (i=0 ; i<len ; i++) {\r
+        blockcnt += blocks[i];          /* increment blockcnt over labels */\r
+        blocks[i] = blockcnt;\r
+    }\r
+    return blocks;\r
+}\r
+\r
+/* Perform basic peephole optimizations to components of a code object.\r
+   The consts object should still be in list form to allow new constants\r
+   to be appended.\r
+\r
+   To keep the optimizer simple, it bails out (does nothing) for code\r
+   containing extended arguments or that has a length over 32,700.  That\r
+   allows us to avoid overflow and sign issues.  Likewise, it bails when\r
+   the lineno table has complex encoding for gaps >= 255.\r
+\r
+   Optimizations are restricted to simple transformations occuring within a\r
+   single basic block.  All transformations keep the code size the same or\r
+   smaller.  For those that reduce size, the gaps are initially filled with\r
+   NOPs.  Later those NOPs are removed and the jump addresses retargeted in\r
+   a single pass.  Line numbering is adjusted accordingly. */\r
+\r
+PyObject *\r
+PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,\r
+                PyObject *lineno_obj)\r
+{\r
+    Py_ssize_t i, j, codelen;\r
+    int nops, h, adj;\r
+    int tgt, tgttgt, opcode;\r
+    unsigned char *codestr = NULL;\r
+    unsigned char *lineno;\r
+    int *addrmap = NULL;\r
+    int new_line, cum_orig_line, last_line, tabsiz;\r
+    int cumlc=0, lastlc=0;      /* Count runs of consecutive LOAD_CONSTs */\r
+    unsigned int *blocks = NULL;\r
+    char *name;\r
+\r
+    /* Bail out if an exception is set */\r
+    if (PyErr_Occurred())\r
+        goto exitError;\r
+\r
+    /* Bypass optimization when the lineno table is too complex */\r
+    assert(PyString_Check(lineno_obj));\r
+    lineno = (unsigned char*)PyString_AS_STRING(lineno_obj);\r
+    tabsiz = PyString_GET_SIZE(lineno_obj);\r
+    if (memchr(lineno, 255, tabsiz) != NULL)\r
+        goto exitUnchanged;\r
+\r
+    /* Avoid situations where jump retargeting could overflow */\r
+    assert(PyString_Check(code));\r
+    codelen = PyString_GET_SIZE(code);\r
+    if (codelen > 32700)\r
+        goto exitUnchanged;\r
+\r
+    /* Make a modifiable copy of the code string */\r
+    codestr = (unsigned char *)PyMem_Malloc(codelen);\r
+    if (codestr == NULL)\r
+        goto exitError;\r
+    codestr = (unsigned char *)memcpy(codestr,\r
+                                      PyString_AS_STRING(code), codelen);\r
+\r
+    /* Verify that RETURN_VALUE terminates the codestring. This allows\r
+       the various transformation patterns to look ahead several\r
+       instructions without additional checks to make sure they are not\r
+       looking beyond the end of the code string.\r
+    */\r
+    if (codestr[codelen-1] != RETURN_VALUE)\r
+        goto exitUnchanged;\r
+\r
+    /* Mapping to new jump targets after NOPs are removed */\r
+    addrmap = PyMem_New(int, codelen);\r
+    if (addrmap == NULL) {\r
+        PyErr_NoMemory();\r
+        goto exitError;\r
+    }\r
+\r
+    blocks = markblocks(codestr, codelen);\r
+    if (blocks == NULL)\r
+        goto exitError;\r
+    assert(PyList_Check(consts));\r
+\r
+    for (i=0 ; i<codelen ; i += CODESIZE(codestr[i])) {\r
+      reoptimize_current:\r
+        opcode = codestr[i];\r
+\r
+        lastlc = cumlc;\r
+        cumlc = 0;\r
+\r
+        switch (opcode) {\r
+            /* Replace UNARY_NOT POP_JUMP_IF_FALSE\r
+               with    POP_JUMP_IF_TRUE */\r
+            case UNARY_NOT:\r
+                if (codestr[i+1] != POP_JUMP_IF_FALSE\r
+                    || !ISBASICBLOCK(blocks,i,4))\r
+                    continue;\r
+                j = GETARG(codestr, i+1);\r
+                codestr[i] = POP_JUMP_IF_TRUE;\r
+                SETARG(codestr, i, j);\r
+                codestr[i+3] = NOP;\r
+                goto reoptimize_current;\r
+\r
+                /* not a is b -->  a is not b\r
+                   not a in b -->  a not in b\r
+                   not a is not b -->  a is b\r
+                   not a not in b -->  a in b\r
+                */\r
+            case COMPARE_OP:\r
+                j = GETARG(codestr, i);\r
+                if (j < 6  ||  j > 9  ||\r
+                    codestr[i+3] != UNARY_NOT  ||\r
+                    !ISBASICBLOCK(blocks,i,4))\r
+                    continue;\r
+                SETARG(codestr, i, (j^1));\r
+                codestr[i+3] = NOP;\r
+                break;\r
+\r
+                /* Replace LOAD_GLOBAL/LOAD_NAME None\r
+                   with LOAD_CONST None */\r
+            case LOAD_NAME:\r
+            case LOAD_GLOBAL:\r
+                j = GETARG(codestr, i);\r
+                name = PyString_AsString(PyTuple_GET_ITEM(names, j));\r
+                if (name == NULL  ||  strcmp(name, "None") != 0)\r
+                    continue;\r
+                for (j=0 ; j < PyList_GET_SIZE(consts) ; j++) {\r
+                    if (PyList_GET_ITEM(consts, j) == Py_None)\r
+                        break;\r
+                }\r
+                if (j == PyList_GET_SIZE(consts)) {\r
+                    if (PyList_Append(consts, Py_None) == -1)\r
+                        goto exitError;\r
+                }\r
+                assert(PyList_GET_ITEM(consts, j) == Py_None);\r
+                codestr[i] = LOAD_CONST;\r
+                SETARG(codestr, i, j);\r
+                cumlc = lastlc + 1;\r
+                break;\r
+\r
+                /* Skip over LOAD_CONST trueconst\r
+                   POP_JUMP_IF_FALSE xx. This improves\r
+                   "while 1" performance. */\r
+            case LOAD_CONST:\r
+                cumlc = lastlc + 1;\r
+                j = GETARG(codestr, i);\r
+                if (codestr[i+3] != POP_JUMP_IF_FALSE  ||\r
+                    !ISBASICBLOCK(blocks,i,6)  ||\r
+                    !PyObject_IsTrue(PyList_GET_ITEM(consts, j)))\r
+                    continue;\r
+                memset(codestr+i, NOP, 6);\r
+                cumlc = 0;\r
+                break;\r
+\r
+                /* Try to fold tuples of constants (includes a case for lists\r
+                   which are only used for "in" and "not in" tests).\r
+                   Skip over BUILD_SEQN 1 UNPACK_SEQN 1.\r
+                   Replace BUILD_SEQN 2 UNPACK_SEQN 2 with ROT2.\r
+                   Replace BUILD_SEQN 3 UNPACK_SEQN 3 with ROT3 ROT2. */\r
+            case BUILD_TUPLE:\r
+            case BUILD_LIST:\r
+                j = GETARG(codestr, i);\r
+                h = i - 3 * j;\r
+                if (h >= 0 &&\r
+                    j <= lastlc &&\r
+                    ((opcode == BUILD_TUPLE &&\r
+                      ISBASICBLOCK(blocks, h, 3*(j+1))) ||\r
+                     (opcode == BUILD_LIST &&\r
+                      codestr[i+3]==COMPARE_OP &&\r
+                      ISBASICBLOCK(blocks, h, 3*(j+2)) &&\r
+                      (GETARG(codestr,i+3)==6 ||\r
+                       GETARG(codestr,i+3)==7))) &&\r
+                    tuple_of_constants(&codestr[h], j, consts)) {\r
+                    assert(codestr[i] == LOAD_CONST);\r
+                    cumlc = 1;\r
+                    break;\r
+                }\r
+                if (codestr[i+3] != UNPACK_SEQUENCE  ||\r
+                    !ISBASICBLOCK(blocks,i,6) ||\r
+                    j != GETARG(codestr, i+3))\r
+                    continue;\r
+                if (j == 1) {\r
+                    memset(codestr+i, NOP, 6);\r
+                } else if (j == 2) {\r
+                    codestr[i] = ROT_TWO;\r
+                    memset(codestr+i+1, NOP, 5);\r
+                } else if (j == 3) {\r
+                    codestr[i] = ROT_THREE;\r
+                    codestr[i+1] = ROT_TWO;\r
+                    memset(codestr+i+2, NOP, 4);\r
+                }\r
+                break;\r
+\r
+                /* Fold binary ops on constants.\r
+                   LOAD_CONST c1 LOAD_CONST c2 BINOP -->  LOAD_CONST binop(c1,c2) */\r
+            case BINARY_POWER:\r
+            case BINARY_MULTIPLY:\r
+            case BINARY_TRUE_DIVIDE:\r
+            case BINARY_FLOOR_DIVIDE:\r
+            case BINARY_MODULO:\r
+            case BINARY_ADD:\r
+            case BINARY_SUBTRACT:\r
+            case BINARY_SUBSCR:\r
+            case BINARY_LSHIFT:\r
+            case BINARY_RSHIFT:\r
+            case BINARY_AND:\r
+            case BINARY_XOR:\r
+            case BINARY_OR:\r
+                if (lastlc >= 2 &&\r
+                    ISBASICBLOCK(blocks, i-6, 7) &&\r
+                    fold_binops_on_constants(&codestr[i-6], consts)) {\r
+                    i -= 2;\r
+                    assert(codestr[i] == LOAD_CONST);\r
+                    cumlc = 1;\r
+                }\r
+                break;\r
+\r
+                /* Fold unary ops on constants.\r
+                   LOAD_CONST c1  UNARY_OP --> LOAD_CONST unary_op(c) */\r
+            case UNARY_NEGATIVE:\r
+            case UNARY_CONVERT:\r
+            case UNARY_INVERT:\r
+                if (lastlc >= 1 &&\r
+                    ISBASICBLOCK(blocks, i-3, 4) &&\r
+                    fold_unaryops_on_constants(&codestr[i-3], consts)) {\r
+                    i -= 2;\r
+                    assert(codestr[i] == LOAD_CONST);\r
+                    cumlc = 1;\r
+                }\r
+                break;\r
+\r
+                /* Simplify conditional jump to conditional jump where the\r
+                   result of the first test implies the success of a similar\r
+                   test or the failure of the opposite test.\r
+                   Arises in code like:\r
+                   "if a and b:"\r
+                   "if a or b:"\r
+                   "a and b or c"\r
+                   "(a and b) and c"\r
+                   x:JUMP_IF_FALSE_OR_POP y   y:JUMP_IF_FALSE_OR_POP z\r
+                      -->  x:JUMP_IF_FALSE_OR_POP z\r
+                   x:JUMP_IF_FALSE_OR_POP y   y:JUMP_IF_TRUE_OR_POP z\r
+                      -->  x:POP_JUMP_IF_FALSE y+3\r
+                   where y+3 is the instruction following the second test.\r
+                */\r
+            case JUMP_IF_FALSE_OR_POP:\r
+            case JUMP_IF_TRUE_OR_POP:\r
+                tgt = GETJUMPTGT(codestr, i);\r
+                j = codestr[tgt];\r
+                if (CONDITIONAL_JUMP(j)) {\r
+                    /* NOTE: all possible jumps here are absolute! */\r
+                    if (JUMPS_ON_TRUE(j) == JUMPS_ON_TRUE(opcode)) {\r
+                        /* The second jump will be\r
+                           taken iff the first is. */\r
+                        tgttgt = GETJUMPTGT(codestr, tgt);\r
+                        /* The current opcode inherits\r
+                           its target's stack behaviour */\r
+                        codestr[i] = j;\r
+                        SETARG(codestr, i, tgttgt);\r
+                        goto reoptimize_current;\r
+                    } else {\r
+                        /* The second jump is not taken if the first is (so\r
+                           jump past it), and all conditional jumps pop their\r
+                           argument when they're not taken (so change the\r
+                           first jump to pop its argument when it's taken). */\r
+                        if (JUMPS_ON_TRUE(opcode))\r
+                            codestr[i] = POP_JUMP_IF_TRUE;\r
+                        else\r
+                            codestr[i] = POP_JUMP_IF_FALSE;\r
+                        SETARG(codestr, i, (tgt + 3));\r
+                        goto reoptimize_current;\r
+                    }\r
+                }\r
+                /* Intentional fallthrough */\r
+\r
+                /* Replace jumps to unconditional jumps */\r
+            case POP_JUMP_IF_FALSE:\r
+            case POP_JUMP_IF_TRUE:\r
+            case FOR_ITER:\r
+            case JUMP_FORWARD:\r
+            case JUMP_ABSOLUTE:\r
+            case CONTINUE_LOOP:\r
+            case SETUP_LOOP:\r
+            case SETUP_EXCEPT:\r
+            case SETUP_FINALLY:\r
+            case SETUP_WITH:\r
+                tgt = GETJUMPTGT(codestr, i);\r
+                /* Replace JUMP_* to a RETURN into just a RETURN */\r
+                if (UNCONDITIONAL_JUMP(opcode) &&\r
+                    codestr[tgt] == RETURN_VALUE) {\r
+                    codestr[i] = RETURN_VALUE;\r
+                    memset(codestr+i+1, NOP, 2);\r
+                    continue;\r
+                }\r
+                if (!UNCONDITIONAL_JUMP(codestr[tgt]))\r
+                    continue;\r
+                tgttgt = GETJUMPTGT(codestr, tgt);\r
+                if (opcode == JUMP_FORWARD) /* JMP_ABS can go backwards */\r
+                    opcode = JUMP_ABSOLUTE;\r
+                if (!ABSOLUTE_JUMP(opcode))\r
+                    tgttgt -= i + 3;        /* Calc relative jump addr */\r
+                if (tgttgt < 0)             /* No backward relative jumps */\r
+                    continue;\r
+                codestr[i] = opcode;\r
+                SETARG(codestr, i, tgttgt);\r
+                break;\r
+\r
+            case EXTENDED_ARG:\r
+                goto exitUnchanged;\r
+\r
+                /* Replace RETURN LOAD_CONST None RETURN with just RETURN */\r
+                /* Remove unreachable JUMPs after RETURN */\r
+            case RETURN_VALUE:\r
+                if (i+4 >= codelen)\r
+                    continue;\r
+                if (codestr[i+4] == RETURN_VALUE &&\r
+                    ISBASICBLOCK(blocks,i,5))\r
+                    memset(codestr+i+1, NOP, 4);\r
+                else if (UNCONDITIONAL_JUMP(codestr[i+1]) &&\r
+                         ISBASICBLOCK(blocks,i,4))\r
+                    memset(codestr+i+1, NOP, 3);\r
+                break;\r
+        }\r
+    }\r
+\r
+    /* Fixup linenotab */\r
+    for (i=0, nops=0 ; i<codelen ; i += CODESIZE(codestr[i])) {\r
+        addrmap[i] = i - nops;\r
+        if (codestr[i] == NOP)\r
+            nops++;\r
+    }\r
+    cum_orig_line = 0;\r
+    last_line = 0;\r
+    for (i=0 ; i < tabsiz ; i+=2) {\r
+        cum_orig_line += lineno[i];\r
+        new_line = addrmap[cum_orig_line];\r
+        assert (new_line - last_line < 255);\r
+        lineno[i] =((unsigned char)(new_line - last_line));\r
+        last_line = new_line;\r
+    }\r
+\r
+    /* Remove NOPs and fixup jump targets */\r
+    for (i=0, h=0 ; i<codelen ; ) {\r
+        opcode = codestr[i];\r
+        switch (opcode) {\r
+            case NOP:\r
+                i++;\r
+                continue;\r
+\r
+            case JUMP_ABSOLUTE:\r
+            case CONTINUE_LOOP:\r
+            case POP_JUMP_IF_FALSE:\r
+            case POP_JUMP_IF_TRUE:\r
+            case JUMP_IF_FALSE_OR_POP:\r
+            case JUMP_IF_TRUE_OR_POP:\r
+                j = addrmap[GETARG(codestr, i)];\r
+                SETARG(codestr, i, j);\r
+                break;\r
+\r
+            case FOR_ITER:\r
+            case JUMP_FORWARD:\r
+            case SETUP_LOOP:\r
+            case SETUP_EXCEPT:\r
+            case SETUP_FINALLY:\r
+            case SETUP_WITH:\r
+                j = addrmap[GETARG(codestr, i) + i + 3] - addrmap[i] - 3;\r
+                SETARG(codestr, i, j);\r
+                break;\r
+        }\r
+        adj = CODESIZE(opcode);\r
+        while (adj--)\r
+            codestr[h++] = codestr[i++];\r
+    }\r
+    assert(h + nops == codelen);\r
+\r
+    code = PyString_FromStringAndSize((char *)codestr, h);\r
+    PyMem_Free(addrmap);\r
+    PyMem_Free(codestr);\r
+    PyMem_Free(blocks);\r
+    return code;\r
+\r
+ exitError:\r
+    code = NULL;\r
+\r
+ exitUnchanged:\r
+    if (blocks != NULL)\r
+        PyMem_Free(blocks);\r
+    if (addrmap != NULL)\r
+        PyMem_Free(addrmap);\r
+    if (codestr != NULL)\r
+        PyMem_Free(codestr);\r
+    Py_XINCREF(code);\r
+    return code;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/pyarena.c b/AppPkg/Applications/Python/Python-2.7.10/Python/pyarena.c
new file mode 100644 (file)
index 0000000..9061891
--- /dev/null
@@ -0,0 +1,213 @@
+#include "Python.h"\r
+#include "pyarena.h"\r
+\r
+/* A simple arena block structure.\r
+\r
+   Measurements with standard library modules suggest the average\r
+   allocation is about 20 bytes and that most compiles use a single\r
+   block.\r
+\r
+   TODO(jhylton): Think about a realloc API, maybe just for the last\r
+   allocation?\r
+*/\r
+\r
+#define DEFAULT_BLOCK_SIZE 8192\r
+#define ALIGNMENT               8\r
+#define ALIGNMENT_MASK          (ALIGNMENT - 1)\r
+#define ROUNDUP(x)              (((x) + ALIGNMENT_MASK) & ~ALIGNMENT_MASK)\r
+\r
+typedef struct _block {\r
+    /* Total number of bytes owned by this block available to pass out.\r
+     * Read-only after initialization.  The first such byte starts at\r
+     * ab_mem.\r
+     */\r
+    size_t ab_size;\r
+\r
+    /* Total number of bytes already passed out.  The next byte available\r
+     * to pass out starts at ab_mem + ab_offset.\r
+     */\r
+    size_t ab_offset;\r
+\r
+    /* An arena maintains a singly-linked, NULL-terminated list of\r
+     * all blocks owned by the arena.  These are linked via the\r
+     * ab_next member.\r
+     */\r
+    struct _block *ab_next;\r
+\r
+    /* Pointer to the first allocatable byte owned by this block.  Read-\r
+     * only after initialization.\r
+     */\r
+    void *ab_mem;\r
+} block;\r
+\r
+/* The arena manages two kinds of memory, blocks of raw memory\r
+   and a list of PyObject* pointers.  PyObjects are decrefed\r
+   when the arena is freed.\r
+*/\r
+\r
+struct _arena {\r
+    /* Pointer to the first block allocated for the arena, never NULL.\r
+       It is used only to find the first block when the arena is\r
+       being freed.\r
+     */\r
+    block *a_head;\r
+\r
+    /* Pointer to the block currently used for allocation.  It's\r
+       ab_next field should be NULL.  If it is not-null after a\r
+       call to block_alloc(), it means a new block has been allocated\r
+       and a_cur should be reset to point it.\r
+     */\r
+    block *a_cur;\r
+\r
+    /* A Python list object containing references to all the PyObject\r
+       pointers associated with this area.  They will be DECREFed\r
+       when the arena is freed.\r
+    */\r
+    PyObject *a_objects;\r
+\r
+#if defined(Py_DEBUG)\r
+    /* Debug output */\r
+    size_t total_allocs;\r
+    size_t total_size;\r
+    size_t total_blocks;\r
+    size_t total_block_size;\r
+    size_t total_big_blocks;\r
+#endif\r
+};\r
+\r
+static block *\r
+block_new(size_t size)\r
+{\r
+    /* Allocate header and block as one unit.\r
+       ab_mem points just past header. */\r
+    block *b = (block *)malloc(sizeof(block) + size);\r
+    if (!b)\r
+        return NULL;\r
+    b->ab_size = size;\r
+    b->ab_mem = (void *)(b + 1);\r
+    b->ab_next = NULL;\r
+    b->ab_offset = ROUNDUP((Py_uintptr_t)(b->ab_mem)) -\r
+      (Py_uintptr_t)(b->ab_mem);\r
+    return b;\r
+}\r
+\r
+static void\r
+block_free(block *b) {\r
+    while (b) {\r
+        block *next = b->ab_next;\r
+        free(b);\r
+        b = next;\r
+    }\r
+}\r
+\r
+static void *\r
+block_alloc(block *b, size_t size)\r
+{\r
+    void *p;\r
+    assert(b);\r
+    size = ROUNDUP(size);\r
+    if (b->ab_offset + size > b->ab_size) {\r
+        /* If we need to allocate more memory than will fit in\r
+           the default block, allocate a one-off block that is\r
+           exactly the right size. */\r
+        /* TODO(jhylton): Think about space waste at end of block */\r
+        block *newbl = block_new(\r
+                        size < DEFAULT_BLOCK_SIZE ?\r
+                        DEFAULT_BLOCK_SIZE : size);\r
+        if (!newbl)\r
+            return NULL;\r
+        assert(!b->ab_next);\r
+        b->ab_next = newbl;\r
+        b = newbl;\r
+    }\r
+\r
+    assert(b->ab_offset + size <= b->ab_size);\r
+    p = (void *)(((char *)b->ab_mem) + b->ab_offset);\r
+    b->ab_offset += size;\r
+    return p;\r
+}\r
+\r
+PyArena *\r
+PyArena_New()\r
+{\r
+    PyArena* arena = (PyArena *)malloc(sizeof(PyArena));\r
+    if (!arena)\r
+        return (PyArena*)PyErr_NoMemory();\r
+\r
+    arena->a_head = block_new(DEFAULT_BLOCK_SIZE);\r
+    arena->a_cur = arena->a_head;\r
+    if (!arena->a_head) {\r
+        free((void *)arena);\r
+        return (PyArena*)PyErr_NoMemory();\r
+    }\r
+    arena->a_objects = PyList_New(0);\r
+    if (!arena->a_objects) {\r
+        block_free(arena->a_head);\r
+        free((void *)arena);\r
+        return (PyArena*)PyErr_NoMemory();\r
+    }\r
+#if defined(Py_DEBUG)\r
+    arena->total_allocs = 0;\r
+    arena->total_size = 0;\r
+    arena->total_blocks = 1;\r
+    arena->total_block_size = DEFAULT_BLOCK_SIZE;\r
+    arena->total_big_blocks = 0;\r
+#endif\r
+    return arena;\r
+}\r
+\r
+void\r
+PyArena_Free(PyArena *arena)\r
+{\r
+    assert(arena);\r
+#if defined(Py_DEBUG)\r
+    /*\r
+    fprintf(stderr,\r
+        "alloc=%d size=%d blocks=%d block_size=%d big=%d objects=%d\n",\r
+        arena->total_allocs, arena->total_size, arena->total_blocks,\r
+        arena->total_block_size, arena->total_big_blocks,\r
+        PyList_Size(arena->a_objects));\r
+    */\r
+#endif\r
+    block_free(arena->a_head);\r
+    /* This property normally holds, except when the code being compiled\r
+       is sys.getobjects(0), in which case there will be two references.\r
+    assert(arena->a_objects->ob_refcnt == 1);\r
+    */\r
+\r
+    Py_DECREF(arena->a_objects);\r
+    free(arena);\r
+}\r
+\r
+void *\r
+PyArena_Malloc(PyArena *arena, size_t size)\r
+{\r
+    void *p = block_alloc(arena->a_cur, size);\r
+    if (!p)\r
+        return PyErr_NoMemory();\r
+#if defined(Py_DEBUG)\r
+    arena->total_allocs++;\r
+    arena->total_size += size;\r
+#endif\r
+    /* Reset cur if we allocated a new block. */\r
+    if (arena->a_cur->ab_next) {\r
+        arena->a_cur = arena->a_cur->ab_next;\r
+#if defined(Py_DEBUG)\r
+        arena->total_blocks++;\r
+        arena->total_block_size += arena->a_cur->ab_size;\r
+        if (arena->a_cur->ab_size > DEFAULT_BLOCK_SIZE)\r
+            ++arena->total_big_blocks;\r
+#endif\r
+    }\r
+    return p;\r
+}\r
+\r
+int\r
+PyArena_AddPyObject(PyArena *arena, PyObject *obj)\r
+{\r
+    int r = PyList_Append(arena->a_objects, obj);\r
+    if (r >= 0) {\r
+        Py_DECREF(obj);\r
+    }\r
+    return r;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/pyctype.c b/AppPkg/Applications/Python/Python-2.7.10/Python/pyctype.c
new file mode 100644 (file)
index 0000000..ea977b3
--- /dev/null
@@ -0,0 +1,214 @@
+#include "Python.h"\r
+\r
+/* Our own locale-independent ctype.h-like macros */\r
+\r
+const unsigned int _Py_ctype_table[256] = {\r
+    0, /* 0x0 '\x00' */\r
+    0, /* 0x1 '\x01' */\r
+    0, /* 0x2 '\x02' */\r
+    0, /* 0x3 '\x03' */\r
+    0, /* 0x4 '\x04' */\r
+    0, /* 0x5 '\x05' */\r
+    0, /* 0x6 '\x06' */\r
+    0, /* 0x7 '\x07' */\r
+    0, /* 0x8 '\x08' */\r
+    PY_CTF_SPACE, /* 0x9 '\t' */\r
+    PY_CTF_SPACE, /* 0xa '\n' */\r
+    PY_CTF_SPACE, /* 0xb '\v' */\r
+    PY_CTF_SPACE, /* 0xc '\f' */\r
+    PY_CTF_SPACE, /* 0xd '\r' */\r
+    0, /* 0xe '\x0e' */\r
+    0, /* 0xf '\x0f' */\r
+    0, /* 0x10 '\x10' */\r
+    0, /* 0x11 '\x11' */\r
+    0, /* 0x12 '\x12' */\r
+    0, /* 0x13 '\x13' */\r
+    0, /* 0x14 '\x14' */\r
+    0, /* 0x15 '\x15' */\r
+    0, /* 0x16 '\x16' */\r
+    0, /* 0x17 '\x17' */\r
+    0, /* 0x18 '\x18' */\r
+    0, /* 0x19 '\x19' */\r
+    0, /* 0x1a '\x1a' */\r
+    0, /* 0x1b '\x1b' */\r
+    0, /* 0x1c '\x1c' */\r
+    0, /* 0x1d '\x1d' */\r
+    0, /* 0x1e '\x1e' */\r
+    0, /* 0x1f '\x1f' */\r
+    PY_CTF_SPACE, /* 0x20 ' ' */\r
+    0, /* 0x21 '!' */\r
+    0, /* 0x22 '"' */\r
+    0, /* 0x23 '#' */\r
+    0, /* 0x24 '$' */\r
+    0, /* 0x25 '%' */\r
+    0, /* 0x26 '&' */\r
+    0, /* 0x27 "'" */\r
+    0, /* 0x28 '(' */\r
+    0, /* 0x29 ')' */\r
+    0, /* 0x2a '*' */\r
+    0, /* 0x2b '+' */\r
+    0, /* 0x2c ',' */\r
+    0, /* 0x2d '-' */\r
+    0, /* 0x2e '.' */\r
+    0, /* 0x2f '/' */\r
+    PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x30 '0' */\r
+    PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x31 '1' */\r
+    PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x32 '2' */\r
+    PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x33 '3' */\r
+    PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x34 '4' */\r
+    PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x35 '5' */\r
+    PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x36 '6' */\r
+    PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x37 '7' */\r
+    PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x38 '8' */\r
+    PY_CTF_DIGIT|PY_CTF_XDIGIT, /* 0x39 '9' */\r
+    0, /* 0x3a ':' */\r
+    0, /* 0x3b ';' */\r
+    0, /* 0x3c '<' */\r
+    0, /* 0x3d '=' */\r
+    0, /* 0x3e '>' */\r
+    0, /* 0x3f '?' */\r
+    0, /* 0x40 '@' */\r
+    PY_CTF_UPPER|PY_CTF_XDIGIT, /* 0x41 'A' */\r
+    PY_CTF_UPPER|PY_CTF_XDIGIT, /* 0x42 'B' */\r
+    PY_CTF_UPPER|PY_CTF_XDIGIT, /* 0x43 'C' */\r
+    PY_CTF_UPPER|PY_CTF_XDIGIT, /* 0x44 'D' */\r
+    PY_CTF_UPPER|PY_CTF_XDIGIT, /* 0x45 'E' */\r
+    PY_CTF_UPPER|PY_CTF_XDIGIT, /* 0x46 'F' */\r
+    PY_CTF_UPPER, /* 0x47 'G' */\r
+    PY_CTF_UPPER, /* 0x48 'H' */\r
+    PY_CTF_UPPER, /* 0x49 'I' */\r
+    PY_CTF_UPPER, /* 0x4a 'J' */\r
+    PY_CTF_UPPER, /* 0x4b 'K' */\r
+    PY_CTF_UPPER, /* 0x4c 'L' */\r
+    PY_CTF_UPPER, /* 0x4d 'M' */\r
+    PY_CTF_UPPER, /* 0x4e 'N' */\r
+    PY_CTF_UPPER, /* 0x4f 'O' */\r
+    PY_CTF_UPPER, /* 0x50 'P' */\r
+    PY_CTF_UPPER, /* 0x51 'Q' */\r
+    PY_CTF_UPPER, /* 0x52 'R' */\r
+    PY_CTF_UPPER, /* 0x53 'S' */\r
+    PY_CTF_UPPER, /* 0x54 'T' */\r
+    PY_CTF_UPPER, /* 0x55 'U' */\r
+    PY_CTF_UPPER, /* 0x56 'V' */\r
+    PY_CTF_UPPER, /* 0x57 'W' */\r
+    PY_CTF_UPPER, /* 0x58 'X' */\r
+    PY_CTF_UPPER, /* 0x59 'Y' */\r
+    PY_CTF_UPPER, /* 0x5a 'Z' */\r
+    0, /* 0x5b '[' */\r
+    0, /* 0x5c '\\' */\r
+    0, /* 0x5d ']' */\r
+    0, /* 0x5e '^' */\r
+    0, /* 0x5f '_' */\r
+    0, /* 0x60 '`' */\r
+    PY_CTF_LOWER|PY_CTF_XDIGIT, /* 0x61 'a' */\r
+    PY_CTF_LOWER|PY_CTF_XDIGIT, /* 0x62 'b' */\r
+    PY_CTF_LOWER|PY_CTF_XDIGIT, /* 0x63 'c' */\r
+    PY_CTF_LOWER|PY_CTF_XDIGIT, /* 0x64 'd' */\r
+    PY_CTF_LOWER|PY_CTF_XDIGIT, /* 0x65 'e' */\r
+    PY_CTF_LOWER|PY_CTF_XDIGIT, /* 0x66 'f' */\r
+    PY_CTF_LOWER, /* 0x67 'g' */\r
+    PY_CTF_LOWER, /* 0x68 'h' */\r
+    PY_CTF_LOWER, /* 0x69 'i' */\r
+    PY_CTF_LOWER, /* 0x6a 'j' */\r
+    PY_CTF_LOWER, /* 0x6b 'k' */\r
+    PY_CTF_LOWER, /* 0x6c 'l' */\r
+    PY_CTF_LOWER, /* 0x6d 'm' */\r
+    PY_CTF_LOWER, /* 0x6e 'n' */\r
+    PY_CTF_LOWER, /* 0x6f 'o' */\r
+    PY_CTF_LOWER, /* 0x70 'p' */\r
+    PY_CTF_LOWER, /* 0x71 'q' */\r
+    PY_CTF_LOWER, /* 0x72 'r' */\r
+    PY_CTF_LOWER, /* 0x73 's' */\r
+    PY_CTF_LOWER, /* 0x74 't' */\r
+    PY_CTF_LOWER, /* 0x75 'u' */\r
+    PY_CTF_LOWER, /* 0x76 'v' */\r
+    PY_CTF_LOWER, /* 0x77 'w' */\r
+    PY_CTF_LOWER, /* 0x78 'x' */\r
+    PY_CTF_LOWER, /* 0x79 'y' */\r
+    PY_CTF_LOWER, /* 0x7a 'z' */\r
+    0, /* 0x7b '{' */\r
+    0, /* 0x7c '|' */\r
+    0, /* 0x7d '}' */\r
+    0, /* 0x7e '~' */\r
+    0, /* 0x7f '\x7f' */\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+};\r
+\r
+\r
+const unsigned char _Py_ctype_tolower[256] = {\r
+    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\r
+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\r
+    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\r
+    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\r
+    0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\r
+    0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,\r
+    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\r
+    0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,\r
+    0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\r
+    0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,\r
+    0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,\r
+    0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,\r
+    0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\r
+    0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,\r
+    0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,\r
+    0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,\r
+    0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\r
+    0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\r
+    0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\r
+    0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\r
+    0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\r
+    0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\r
+    0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\r
+    0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\r
+    0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\r
+    0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\r
+    0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\r
+    0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\r
+    0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\r
+    0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\r
+    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\r
+    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\r
+};\r
+\r
+const unsigned char _Py_ctype_toupper[256] = {\r
+    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\r
+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\r
+    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\r
+    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\r
+    0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,\r
+    0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,\r
+    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\r
+    0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,\r
+    0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\r
+    0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,\r
+    0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,\r
+    0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,\r
+    0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\r
+    0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,\r
+    0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,\r
+    0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,\r
+    0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\r
+    0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\r
+    0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\r
+    0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\r
+    0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\r
+    0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\r
+    0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\r
+    0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\r
+    0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\r
+    0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\r
+    0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\r
+    0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\r
+    0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\r
+    0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\r
+    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\r
+    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\r
+};\r
+\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/pyfpe.c b/AppPkg/Applications/Python/Python-2.7.10/Python/pyfpe.c
new file mode 100644 (file)
index 0000000..46a6197
--- /dev/null
@@ -0,0 +1,23 @@
+#include "pyconfig.h"\r
+#include "pyfpe.h"\r
+/* \r
+ * The signal handler for SIGFPE is actually declared in an external\r
+ * module fpectl, or as preferred by the user.  These variable\r
+ * definitions are required in order to compile Python without\r
+ * getting missing externals, but to actually handle SIGFPE requires\r
+ * defining a handler and enabling generation of SIGFPE.\r
+ */\r
+\r
+#ifdef WANT_SIGFPE_HANDLER\r
+jmp_buf PyFPE_jbuf;\r
+int PyFPE_counter = 0;\r
+#endif\r
+\r
+/* Have this outside the above #ifdef, since some picky ANSI compilers issue a \r
+   warning when compiling an empty file. */\r
+\r
+double\r
+PyFPE_dummy(void *dummy)\r
+{\r
+       return 1.0;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/pymath.c b/AppPkg/Applications/Python/Python-2.7.10/Python/pymath.c
new file mode 100644 (file)
index 0000000..8085bde
--- /dev/null
@@ -0,0 +1,79 @@
+#include "Python.h"\r
+\r
+#ifdef X87_DOUBLE_ROUNDING\r
+/* On x86 platforms using an x87 FPU, this function is called from the\r
+   Py_FORCE_DOUBLE macro (defined in pymath.h) to force a floating-point\r
+   number out of an 80-bit x87 FPU register and into a 64-bit memory location,\r
+   thus rounding from extended precision to double precision. */\r
+double _Py_force_double(double x)\r
+{\r
+    volatile double y;\r
+    y = x;\r
+    return y;\r
+}\r
+#endif\r
+\r
+#ifdef HAVE_GCC_ASM_FOR_X87\r
+\r
+/* inline assembly for getting and setting the 387 FPU control word on\r
+   gcc/x86 */\r
+\r
+unsigned short _Py_get_387controlword(void) {\r
+    unsigned short cw;\r
+    __asm__ __volatile__ ("fnstcw %0" : "=m" (cw));\r
+    return cw;\r
+}\r
+\r
+void _Py_set_387controlword(unsigned short cw) {\r
+    __asm__ __volatile__ ("fldcw %0" : : "m" (cw));\r
+}\r
+\r
+#endif\r
+\r
+\r
+#ifndef HAVE_HYPOT\r
+double hypot(double x, double y)\r
+{\r
+    double yx;\r
+\r
+    x = fabs(x);\r
+    y = fabs(y);\r
+    if (x < y) {\r
+        double temp = x;\r
+        x = y;\r
+        y = temp;\r
+    }\r
+    if (x == 0.)\r
+        return 0.;\r
+    else {\r
+        yx = y/x;\r
+        return x*sqrt(1.+yx*yx);\r
+    }\r
+}\r
+#endif /* HAVE_HYPOT */\r
+\r
+#ifndef HAVE_COPYSIGN\r
+double\r
+copysign(double x, double y)\r
+{\r
+    /* use atan2 to distinguish -0. from 0. */\r
+    if (y > 0. || (y == 0. && atan2(y, -1.) > 0.)) {\r
+        return fabs(x);\r
+    } else {\r
+        return -fabs(x);\r
+    }\r
+}\r
+#endif /* HAVE_COPYSIGN */\r
+\r
+#ifndef HAVE_ROUND\r
+double\r
+round(double x)\r
+{\r
+    double absx, y;\r
+    absx = fabs(x);\r
+    y = floor(absx);\r
+    if (absx - y >= 0.5)\r
+    y += 1.0;\r
+    return copysign(y, x);\r
+}\r
+#endif /* HAVE_ROUND */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/pystate.c b/AppPkg/Applications/Python/Python-2.7.10/Python/pystate.c
new file mode 100644 (file)
index 0000000..3f8a1ee
--- /dev/null
@@ -0,0 +1,665 @@
+\r
+/* Thread and interpreter state structures and their interfaces */\r
+\r
+#include "Python.h"\r
+\r
+/* --------------------------------------------------------------------------\r
+CAUTION\r
+\r
+Always use malloc() and free() directly in this file.  A number of these\r
+functions are advertised as safe to call when the GIL isn't held, and in\r
+a debug build Python redirects (e.g.) PyMem_NEW (etc) to Python's debugging\r
+obmalloc functions.  Those aren't thread-safe (they rely on the GIL to avoid\r
+the expense of doing their own locking).\r
+-------------------------------------------------------------------------- */\r
+\r
+#ifdef HAVE_DLOPEN\r
+#ifdef HAVE_DLFCN_H\r
+#include <dlfcn.h>\r
+#endif\r
+#ifndef RTLD_LAZY\r
+#define RTLD_LAZY 1\r
+#endif\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifdef WITH_THREAD\r
+#include "pythread.h"\r
+static PyThread_type_lock head_mutex = NULL; /* Protects interp->tstate_head */\r
+#define HEAD_INIT() (void)(head_mutex || (head_mutex = PyThread_allocate_lock()))\r
+#define HEAD_LOCK() PyThread_acquire_lock(head_mutex, WAIT_LOCK)\r
+#define HEAD_UNLOCK() PyThread_release_lock(head_mutex)\r
+\r
+/* The single PyInterpreterState used by this process'\r
+   GILState implementation\r
+*/\r
+static PyInterpreterState *autoInterpreterState = NULL;\r
+static int autoTLSkey = 0;\r
+#else\r
+#define HEAD_INIT() /* Nothing */\r
+#define HEAD_LOCK() /* Nothing */\r
+#define HEAD_UNLOCK() /* Nothing */\r
+#endif\r
+\r
+static PyInterpreterState *interp_head = NULL;\r
+\r
+PyThreadState *_PyThreadState_Current = NULL;\r
+PyThreadFrameGetter _PyThreadState_GetFrame = NULL;\r
+\r
+#ifdef WITH_THREAD\r
+static void _PyGILState_NoteThreadState(PyThreadState* tstate);\r
+#endif\r
+\r
+\r
+PyInterpreterState *\r
+PyInterpreterState_New(void)\r
+{\r
+    PyInterpreterState *interp = (PyInterpreterState *)\r
+                                 malloc(sizeof(PyInterpreterState));\r
+\r
+    if (interp != NULL) {\r
+        HEAD_INIT();\r
+#ifdef WITH_THREAD\r
+        if (head_mutex == NULL)\r
+            Py_FatalError("Can't initialize threads for interpreter");\r
+#endif\r
+        interp->modules = NULL;\r
+        interp->modules_reloading = NULL;\r
+        interp->sysdict = NULL;\r
+        interp->builtins = NULL;\r
+        interp->tstate_head = NULL;\r
+        interp->codec_search_path = NULL;\r
+        interp->codec_search_cache = NULL;\r
+        interp->codec_error_registry = NULL;\r
+#ifdef HAVE_DLOPEN\r
+#ifdef RTLD_NOW\r
+        interp->dlopenflags = RTLD_NOW;\r
+#else\r
+        interp->dlopenflags = RTLD_LAZY;\r
+#endif\r
+#endif\r
+#ifdef WITH_TSC\r
+        interp->tscdump = 0;\r
+#endif\r
+\r
+        HEAD_LOCK();\r
+        interp->next = interp_head;\r
+        interp_head = interp;\r
+        HEAD_UNLOCK();\r
+    }\r
+\r
+    return interp;\r
+}\r
+\r
+\r
+void\r
+PyInterpreterState_Clear(PyInterpreterState *interp)\r
+{\r
+    PyThreadState *p;\r
+    HEAD_LOCK();\r
+    for (p = interp->tstate_head; p != NULL; p = p->next)\r
+        PyThreadState_Clear(p);\r
+    HEAD_UNLOCK();\r
+    Py_CLEAR(interp->codec_search_path);\r
+    Py_CLEAR(interp->codec_search_cache);\r
+    Py_CLEAR(interp->codec_error_registry);\r
+    Py_CLEAR(interp->modules);\r
+    Py_CLEAR(interp->modules_reloading);\r
+    Py_CLEAR(interp->sysdict);\r
+    Py_CLEAR(interp->builtins);\r
+}\r
+\r
+\r
+static void\r
+zapthreads(PyInterpreterState *interp)\r
+{\r
+    PyThreadState *p;\r
+    /* No need to lock the mutex here because this should only happen\r
+       when the threads are all really dead (XXX famous last words). */\r
+    while ((p = interp->tstate_head) != NULL) {\r
+        PyThreadState_Delete(p);\r
+    }\r
+}\r
+\r
+\r
+void\r
+PyInterpreterState_Delete(PyInterpreterState *interp)\r
+{\r
+    PyInterpreterState **p;\r
+    zapthreads(interp);\r
+    HEAD_LOCK();\r
+    for (p = &interp_head; ; p = &(*p)->next) {\r
+        if (*p == NULL)\r
+            Py_FatalError(\r
+                "PyInterpreterState_Delete: invalid interp");\r
+        if (*p == interp)\r
+            break;\r
+    }\r
+    if (interp->tstate_head != NULL)\r
+        Py_FatalError("PyInterpreterState_Delete: remaining threads");\r
+    *p = interp->next;\r
+    HEAD_UNLOCK();\r
+    free(interp);\r
+}\r
+\r
+\r
+/* Default implementation for _PyThreadState_GetFrame */\r
+static struct _frame *\r
+threadstate_getframe(PyThreadState *self)\r
+{\r
+    return self->frame;\r
+}\r
+\r
+static PyThreadState *\r
+new_threadstate(PyInterpreterState *interp, int init)\r
+{\r
+    PyThreadState *tstate = (PyThreadState *)malloc(sizeof(PyThreadState));\r
+\r
+    if (_PyThreadState_GetFrame == NULL)\r
+        _PyThreadState_GetFrame = threadstate_getframe;\r
+\r
+    if (tstate != NULL) {\r
+        tstate->interp = interp;\r
+\r
+        tstate->frame = NULL;\r
+        tstate->recursion_depth = 0;\r
+        tstate->tracing = 0;\r
+        tstate->use_tracing = 0;\r
+        tstate->tick_counter = 0;\r
+        tstate->gilstate_counter = 0;\r
+        tstate->async_exc = NULL;\r
+#ifdef WITH_THREAD\r
+        tstate->thread_id = PyThread_get_thread_ident();\r
+#else\r
+        tstate->thread_id = 0;\r
+#endif\r
+\r
+        tstate->dict = NULL;\r
+\r
+        tstate->curexc_type = NULL;\r
+        tstate->curexc_value = NULL;\r
+        tstate->curexc_traceback = NULL;\r
+\r
+        tstate->exc_type = NULL;\r
+        tstate->exc_value = NULL;\r
+        tstate->exc_traceback = NULL;\r
+\r
+        tstate->c_profilefunc = NULL;\r
+        tstate->c_tracefunc = NULL;\r
+        tstate->c_profileobj = NULL;\r
+        tstate->c_traceobj = NULL;\r
+\r
+        tstate->trash_delete_nesting = 0;\r
+        tstate->trash_delete_later = NULL;\r
+\r
+        if (init)\r
+            _PyThreadState_Init(tstate);\r
+\r
+        HEAD_LOCK();\r
+        tstate->next = interp->tstate_head;\r
+        interp->tstate_head = tstate;\r
+        HEAD_UNLOCK();\r
+    }\r
+\r
+    return tstate;\r
+}\r
+\r
+PyThreadState *\r
+PyThreadState_New(PyInterpreterState *interp)\r
+{\r
+    return new_threadstate(interp, 1);\r
+}\r
+\r
+PyThreadState *\r
+_PyThreadState_Prealloc(PyInterpreterState *interp)\r
+{\r
+    return new_threadstate(interp, 0);\r
+}\r
+\r
+void\r
+_PyThreadState_Init(PyThreadState *tstate)\r
+{\r
+#ifdef WITH_THREAD\r
+    _PyGILState_NoteThreadState(tstate);\r
+#endif\r
+}\r
+\r
+void\r
+PyThreadState_Clear(PyThreadState *tstate)\r
+{\r
+    if (Py_VerboseFlag && tstate->frame != NULL)\r
+        fprintf(stderr,\r
+          "PyThreadState_Clear: warning: thread still has a frame\n");\r
+\r
+    Py_CLEAR(tstate->frame);\r
+\r
+    Py_CLEAR(tstate->dict);\r
+    Py_CLEAR(tstate->async_exc);\r
+\r
+    Py_CLEAR(tstate->curexc_type);\r
+    Py_CLEAR(tstate->curexc_value);\r
+    Py_CLEAR(tstate->curexc_traceback);\r
+\r
+    Py_CLEAR(tstate->exc_type);\r
+    Py_CLEAR(tstate->exc_value);\r
+    Py_CLEAR(tstate->exc_traceback);\r
+\r
+    tstate->c_profilefunc = NULL;\r
+    tstate->c_tracefunc = NULL;\r
+    Py_CLEAR(tstate->c_profileobj);\r
+    Py_CLEAR(tstate->c_traceobj);\r
+}\r
+\r
+\r
+/* Common code for PyThreadState_Delete() and PyThreadState_DeleteCurrent() */\r
+static void\r
+tstate_delete_common(PyThreadState *tstate)\r
+{\r
+    PyInterpreterState *interp;\r
+    PyThreadState **p;\r
+    PyThreadState *prev_p = NULL;\r
+    if (tstate == NULL)\r
+        Py_FatalError("PyThreadState_Delete: NULL tstate");\r
+    interp = tstate->interp;\r
+    if (interp == NULL)\r
+        Py_FatalError("PyThreadState_Delete: NULL interp");\r
+    HEAD_LOCK();\r
+    for (p = &interp->tstate_head; ; p = &(*p)->next) {\r
+        if (*p == NULL)\r
+            Py_FatalError(\r
+                "PyThreadState_Delete: invalid tstate");\r
+        if (*p == tstate)\r
+            break;\r
+        /* Sanity check.  These states should never happen but if\r
+         * they do we must abort.  Otherwise we'll end up spinning in\r
+         * in a tight loop with the lock held.  A similar check is done\r
+         * in thread.c find_key().  */\r
+        if (*p == prev_p)\r
+            Py_FatalError(\r
+                "PyThreadState_Delete: small circular list(!)"\r
+                " and tstate not found.");\r
+        prev_p = *p;\r
+        if ((*p)->next == interp->tstate_head)\r
+            Py_FatalError(\r
+                "PyThreadState_Delete: circular list(!) and"\r
+                " tstate not found.");\r
+    }\r
+    *p = tstate->next;\r
+    HEAD_UNLOCK();\r
+    free(tstate);\r
+}\r
+\r
+\r
+void\r
+PyThreadState_Delete(PyThreadState *tstate)\r
+{\r
+    if (tstate == _PyThreadState_Current)\r
+        Py_FatalError("PyThreadState_Delete: tstate is still current");\r
+    tstate_delete_common(tstate);\r
+#ifdef WITH_THREAD\r
+    if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)\r
+        PyThread_delete_key_value(autoTLSkey);\r
+#endif /* WITH_THREAD */\r
+}\r
+\r
+\r
+#ifdef WITH_THREAD\r
+void\r
+PyThreadState_DeleteCurrent()\r
+{\r
+    PyThreadState *tstate = _PyThreadState_Current;\r
+    if (tstate == NULL)\r
+        Py_FatalError(\r
+            "PyThreadState_DeleteCurrent: no current tstate");\r
+    _PyThreadState_Current = NULL;\r
+    if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)\r
+        PyThread_delete_key_value(autoTLSkey);\r
+    tstate_delete_common(tstate);\r
+    PyEval_ReleaseLock();\r
+}\r
+#endif /* WITH_THREAD */\r
+\r
+\r
+PyThreadState *\r
+PyThreadState_Get(void)\r
+{\r
+    if (_PyThreadState_Current == NULL)\r
+        Py_FatalError("PyThreadState_Get: no current thread");\r
+\r
+    return _PyThreadState_Current;\r
+}\r
+\r
+\r
+PyThreadState *\r
+PyThreadState_Swap(PyThreadState *newts)\r
+{\r
+    PyThreadState *oldts = _PyThreadState_Current;\r
+\r
+    _PyThreadState_Current = newts;\r
+    /* It should not be possible for more than one thread state\r
+       to be used for a thread.  Check this the best we can in debug\r
+       builds.\r
+    */\r
+#if defined(Py_DEBUG) && defined(WITH_THREAD)\r
+    if (newts) {\r
+        /* This can be called from PyEval_RestoreThread(). Similar\r
+           to it, we need to ensure errno doesn't change.\r
+        */\r
+        int err = errno;\r
+        PyThreadState *check = PyGILState_GetThisThreadState();\r
+        if (check && check->interp == newts->interp && check != newts)\r
+            Py_FatalError("Invalid thread state for this thread");\r
+        errno = err;\r
+    }\r
+#endif\r
+    return oldts;\r
+}\r
+\r
+/* An extension mechanism to store arbitrary additional per-thread state.\r
+   PyThreadState_GetDict() returns a dictionary that can be used to hold such\r
+   state; the caller should pick a unique key and store its state there.  If\r
+   PyThreadState_GetDict() returns NULL, an exception has *not* been raised\r
+   and the caller should assume no per-thread state is available. */\r
+\r
+PyObject *\r
+PyThreadState_GetDict(void)\r
+{\r
+    if (_PyThreadState_Current == NULL)\r
+        return NULL;\r
+\r
+    if (_PyThreadState_Current->dict == NULL) {\r
+        PyObject *d;\r
+        _PyThreadState_Current->dict = d = PyDict_New();\r
+        if (d == NULL)\r
+            PyErr_Clear();\r
+    }\r
+    return _PyThreadState_Current->dict;\r
+}\r
+\r
+\r
+/* Asynchronously raise an exception in a thread.\r
+   Requested by Just van Rossum and Alex Martelli.\r
+   To prevent naive misuse, you must write your own extension\r
+   to call this, or use ctypes.  Must be called with the GIL held.\r
+   Returns the number of tstates modified (normally 1, but 0 if `id` didn't\r
+   match any known thread id).  Can be called with exc=NULL to clear an\r
+   existing async exception.  This raises no exceptions. */\r
+\r
+int\r
+PyThreadState_SetAsyncExc(long id, PyObject *exc) {\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    PyInterpreterState *interp = tstate->interp;\r
+    PyThreadState *p;\r
+\r
+    /* Although the GIL is held, a few C API functions can be called\r
+     * without the GIL held, and in particular some that create and\r
+     * destroy thread and interpreter states.  Those can mutate the\r
+     * list of thread states we're traversing, so to prevent that we lock\r
+     * head_mutex for the duration.\r
+     */\r
+    HEAD_LOCK();\r
+    for (p = interp->tstate_head; p != NULL; p = p->next) {\r
+        if (p->thread_id == id) {\r
+            /* Tricky:  we need to decref the current value\r
+             * (if any) in p->async_exc, but that can in turn\r
+             * allow arbitrary Python code to run, including\r
+             * perhaps calls to this function.  To prevent\r
+             * deadlock, we need to release head_mutex before\r
+             * the decref.\r
+             */\r
+            PyObject *old_exc = p->async_exc;\r
+            Py_XINCREF(exc);\r
+            p->async_exc = exc;\r
+            HEAD_UNLOCK();\r
+            Py_XDECREF(old_exc);\r
+            return 1;\r
+        }\r
+    }\r
+    HEAD_UNLOCK();\r
+    return 0;\r
+}\r
+\r
+\r
+/* Routines for advanced debuggers, requested by David Beazley.\r
+   Don't use unless you know what you are doing! */\r
+\r
+PyInterpreterState *\r
+PyInterpreterState_Head(void)\r
+{\r
+    return interp_head;\r
+}\r
+\r
+PyInterpreterState *\r
+PyInterpreterState_Next(PyInterpreterState *interp) {\r
+    return interp->next;\r
+}\r
+\r
+PyThreadState *\r
+PyInterpreterState_ThreadHead(PyInterpreterState *interp) {\r
+    return interp->tstate_head;\r
+}\r
+\r
+PyThreadState *\r
+PyThreadState_Next(PyThreadState *tstate) {\r
+    return tstate->next;\r
+}\r
+\r
+/* The implementation of sys._current_frames().  This is intended to be\r
+   called with the GIL held, as it will be when called via\r
+   sys._current_frames().  It's possible it would work fine even without\r
+   the GIL held, but haven't thought enough about that.\r
+*/\r
+PyObject *\r
+_PyThread_CurrentFrames(void)\r
+{\r
+    PyObject *result;\r
+    PyInterpreterState *i;\r
+\r
+    result = PyDict_New();\r
+    if (result == NULL)\r
+        return NULL;\r
+\r
+    /* for i in all interpreters:\r
+     *     for t in all of i's thread states:\r
+     *          if t's frame isn't NULL, map t's id to its frame\r
+     * Because these lists can mutate even when the GIL is held, we\r
+     * need to grab head_mutex for the duration.\r
+     */\r
+    HEAD_LOCK();\r
+    for (i = interp_head; i != NULL; i = i->next) {\r
+        PyThreadState *t;\r
+        for (t = i->tstate_head; t != NULL; t = t->next) {\r
+            PyObject *id;\r
+            int stat;\r
+            struct _frame *frame = t->frame;\r
+            if (frame == NULL)\r
+                continue;\r
+            id = PyInt_FromLong(t->thread_id);\r
+            if (id == NULL)\r
+                goto Fail;\r
+            stat = PyDict_SetItem(result, id, (PyObject *)frame);\r
+            Py_DECREF(id);\r
+            if (stat < 0)\r
+                goto Fail;\r
+        }\r
+    }\r
+    HEAD_UNLOCK();\r
+    return result;\r
+\r
+ Fail:\r
+    HEAD_UNLOCK();\r
+    Py_DECREF(result);\r
+    return NULL;\r
+}\r
+\r
+/* Python "auto thread state" API. */\r
+#ifdef WITH_THREAD\r
+\r
+/* Keep this as a static, as it is not reliable!  It can only\r
+   ever be compared to the state for the *current* thread.\r
+   * If not equal, then it doesn't matter that the actual\r
+     value may change immediately after comparison, as it can't\r
+     possibly change to the current thread's state.\r
+   * If equal, then the current thread holds the lock, so the value can't\r
+     change until we yield the lock.\r
+*/\r
+static int\r
+PyThreadState_IsCurrent(PyThreadState *tstate)\r
+{\r
+    /* Must be the tstate for this thread */\r
+    assert(PyGILState_GetThisThreadState()==tstate);\r
+    /* On Windows at least, simple reads and writes to 32 bit values\r
+       are atomic.\r
+    */\r
+    return tstate == _PyThreadState_Current;\r
+}\r
+\r
+/* Internal initialization/finalization functions called by\r
+   Py_Initialize/Py_Finalize\r
+*/\r
+void\r
+_PyGILState_Init(PyInterpreterState *i, PyThreadState *t)\r
+{\r
+    assert(i && t); /* must init with valid states */\r
+    autoTLSkey = PyThread_create_key();\r
+    autoInterpreterState = i;\r
+    assert(PyThread_get_key_value(autoTLSkey) == NULL);\r
+    assert(t->gilstate_counter == 0);\r
+\r
+    _PyGILState_NoteThreadState(t);\r
+}\r
+\r
+void\r
+_PyGILState_Fini(void)\r
+{\r
+    PyThread_delete_key(autoTLSkey);\r
+    autoInterpreterState = NULL;\r
+}\r
+\r
+/* When a thread state is created for a thread by some mechanism other than\r
+   PyGILState_Ensure, it's important that the GILState machinery knows about\r
+   it so it doesn't try to create another thread state for the thread (this is\r
+   a better fix for SF bug #1010677 than the first one attempted).\r
+*/\r
+static void\r
+_PyGILState_NoteThreadState(PyThreadState* tstate)\r
+{\r
+    /* If autoTLSkey isn't initialized, this must be the very first\r
+       threadstate created in Py_Initialize().  Don't do anything for now\r
+       (we'll be back here when _PyGILState_Init is called). */\r
+    if (!autoInterpreterState)\r
+        return;\r
+\r
+    /* Stick the thread state for this thread in thread local storage.\r
+\r
+       The only situation where you can legitimately have more than one\r
+       thread state for an OS level thread is when there are multiple\r
+       interpreters, when:\r
+\r
+           a) You shouldn't really be using the PyGILState_ APIs anyway,\r
+          and:\r
+\r
+           b) The slightly odd way PyThread_set_key_value works (see\r
+          comments by its implementation) means that the first thread\r
+          state created for that given OS level thread will "win",\r
+          which seems reasonable behaviour.\r
+    */\r
+    if (PyThread_set_key_value(autoTLSkey, (void *)tstate) < 0)\r
+        Py_FatalError("Couldn't create autoTLSkey mapping");\r
+\r
+    /* PyGILState_Release must not try to delete this thread state. */\r
+    tstate->gilstate_counter = 1;\r
+}\r
+\r
+/* The public functions */\r
+PyThreadState *\r
+PyGILState_GetThisThreadState(void)\r
+{\r
+    if (autoInterpreterState == NULL)\r
+        return NULL;\r
+    return (PyThreadState *)PyThread_get_key_value(autoTLSkey);\r
+}\r
+\r
+PyGILState_STATE\r
+PyGILState_Ensure(void)\r
+{\r
+    int current;\r
+    PyThreadState *tcur;\r
+    /* Note that we do not auto-init Python here - apart from\r
+       potential races with 2 threads auto-initializing, pep-311\r
+       spells out other issues.  Embedders are expected to have\r
+       called Py_Initialize() and usually PyEval_InitThreads().\r
+    */\r
+    assert(autoInterpreterState); /* Py_Initialize() hasn't been called! */\r
+    tcur = (PyThreadState *)PyThread_get_key_value(autoTLSkey);\r
+    if (tcur == NULL) {\r
+        /* Create a new thread state for this thread */\r
+        tcur = PyThreadState_New(autoInterpreterState);\r
+        if (tcur == NULL)\r
+            Py_FatalError("Couldn't create thread-state for new thread");\r
+        /* This is our thread state!  We'll need to delete it in the\r
+           matching call to PyGILState_Release(). */\r
+        tcur->gilstate_counter = 0;\r
+        current = 0; /* new thread state is never current */\r
+    }\r
+    else\r
+        current = PyThreadState_IsCurrent(tcur);\r
+    if (current == 0)\r
+        PyEval_RestoreThread(tcur);\r
+    /* Update our counter in the thread-state - no need for locks:\r
+       - tcur will remain valid as we hold the GIL.\r
+       - the counter is safe as we are the only thread "allowed"\r
+         to modify this value\r
+    */\r
+    ++tcur->gilstate_counter;\r
+    return current ? PyGILState_LOCKED : PyGILState_UNLOCKED;\r
+}\r
+\r
+void\r
+PyGILState_Release(PyGILState_STATE oldstate)\r
+{\r
+    PyThreadState *tcur = (PyThreadState *)PyThread_get_key_value(\r
+                                                            autoTLSkey);\r
+    if (tcur == NULL)\r
+        Py_FatalError("auto-releasing thread-state, "\r
+                      "but no thread-state for this thread");\r
+    /* We must hold the GIL and have our thread state current */\r
+    /* XXX - remove the check - the assert should be fine,\r
+       but while this is very new (April 2003), the extra check\r
+       by release-only users can't hurt.\r
+    */\r
+    if (! PyThreadState_IsCurrent(tcur))\r
+        Py_FatalError("This thread state must be current when releasing");\r
+    assert(PyThreadState_IsCurrent(tcur));\r
+    --tcur->gilstate_counter;\r
+    assert(tcur->gilstate_counter >= 0); /* illegal counter value */\r
+\r
+    /* If we're going to destroy this thread-state, we must\r
+     * clear it while the GIL is held, as destructors may run.\r
+     */\r
+    if (tcur->gilstate_counter == 0) {\r
+        /* can't have been locked when we created it */\r
+        assert(oldstate == PyGILState_UNLOCKED);\r
+        PyThreadState_Clear(tcur);\r
+        /* Delete the thread-state.  Note this releases the GIL too!\r
+         * It's vital that the GIL be held here, to avoid shutdown\r
+         * races; see bugs 225673 and 1061968 (that nasty bug has a\r
+         * habit of coming back).\r
+         */\r
+        PyThreadState_DeleteCurrent();\r
+    }\r
+    /* Release the lock if necessary */\r
+    else if (oldstate == PyGILState_UNLOCKED)\r
+        PyEval_SaveThread();\r
+}\r
+\r
+#endif /* WITH_THREAD */\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/pystrcmp.c b/AppPkg/Applications/Python/Python-2.7.10/Python/pystrcmp.c
new file mode 100644 (file)
index 0000000..f1b12b4
--- /dev/null
@@ -0,0 +1,26 @@
+/* Cross platform case insensitive string compare functions\r
+ */\r
+\r
+#include "Python.h"\r
+\r
+int\r
+PyOS_mystrnicmp(const char *s1, const char *s2, Py_ssize_t size)\r
+{\r
+    if (size == 0)\r
+        return 0;\r
+    while ((--size > 0) &&\r
+           (tolower((unsigned)*s1) == tolower((unsigned)*s2))) {\r
+        if (!*s1++ || !*s2++)\r
+            break;\r
+    }\r
+    return tolower((unsigned)*s1) - tolower((unsigned)*s2);\r
+}\r
+\r
+int\r
+PyOS_mystricmp(const char *s1, const char *s2)\r
+{\r
+    while (*s1 && (tolower((unsigned)*s1++) == tolower((unsigned)*s2++))) {\r
+        ;\r
+    }\r
+    return (tolower((unsigned)*s1) - tolower((unsigned)*s2));\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/pystrtod.c b/AppPkg/Applications/Python/Python-2.7.10/Python/pystrtod.c
new file mode 100644 (file)
index 0000000..3d925a1
--- /dev/null
@@ -0,0 +1,1249 @@
+/* -*- Mode: C; c-file-style: "python" -*- */\r
+\r
+#include <Python.h>\r
+#include <locale.h>\r
+\r
+/* Case-insensitive string match used for nan and inf detection; t should be\r
+   lower-case.  Returns 1 for a successful match, 0 otherwise. */\r
+\r
+static int\r
+case_insensitive_match(const char *s, const char *t)\r
+{\r
+    while(*t && Py_TOLOWER(*s) == *t) {\r
+        s++;\r
+        t++;\r
+    }\r
+    return *t ? 0 : 1;\r
+}\r
+\r
+/* _Py_parse_inf_or_nan: Attempt to parse a string of the form "nan", "inf" or\r
+   "infinity", with an optional leading sign of "+" or "-".  On success,\r
+   return the NaN or Infinity as a double and set *endptr to point just beyond\r
+   the successfully parsed portion of the string.  On failure, return -1.0 and\r
+   set *endptr to point to the start of the string. */\r
+\r
+double\r
+_Py_parse_inf_or_nan(const char *p, char **endptr)\r
+{\r
+    double retval;\r
+    const char *s;\r
+    int negate = 0;\r
+\r
+    s = p;\r
+    if (*s == '-') {\r
+        negate = 1;\r
+        s++;\r
+    }\r
+    else if (*s == '+') {\r
+        s++;\r
+    }\r
+    if (case_insensitive_match(s, "inf")) {\r
+        s += 3;\r
+        if (case_insensitive_match(s, "inity"))\r
+            s += 5;\r
+        retval = negate ? -Py_HUGE_VAL : Py_HUGE_VAL;\r
+    }\r
+#ifdef Py_NAN\r
+    else if (case_insensitive_match(s, "nan")) {\r
+        s += 3;\r
+        retval = negate ? -Py_NAN : Py_NAN;\r
+    }\r
+#endif\r
+    else {\r
+        s = p;\r
+        retval = -1.0;\r
+    }\r
+    *endptr = (char *)s;\r
+    return retval;\r
+}\r
+\r
+/**\r
+ * PyOS_ascii_strtod:\r
+ * @nptr:    the string to convert to a numeric value.\r
+ * @endptr:  if non-%NULL, it returns the character after\r
+ *           the last character used in the conversion.\r
+ *\r
+ * Converts a string to a #gdouble value.\r
+ * This function behaves like the standard strtod() function\r
+ * does in the C locale. It does this without actually\r
+ * changing the current locale, since that would not be\r
+ * thread-safe.\r
+ *\r
+ * This function is typically used when reading configuration\r
+ * files or other non-user input that should be locale independent.\r
+ * To handle input from the user you should normally use the\r
+ * locale-sensitive system strtod() function.\r
+ *\r
+ * If the correct value would cause overflow, plus or minus %HUGE_VAL\r
+ * is returned (according to the sign of the value), and %ERANGE is\r
+ * stored in %errno. If the correct value would cause underflow,\r
+ * zero is returned and %ERANGE is stored in %errno.\r
+ * If memory allocation fails, %ENOMEM is stored in %errno.\r
+ *\r
+ * This function resets %errno before calling strtod() so that\r
+ * you can reliably detect overflow and underflow.\r
+ *\r
+ * Return value: the #gdouble value.\r
+ **/\r
+\r
+#ifndef PY_NO_SHORT_FLOAT_REPR\r
+\r
+double\r
+_PyOS_ascii_strtod(const char *nptr, char **endptr)\r
+{\r
+    double result;\r
+    _Py_SET_53BIT_PRECISION_HEADER;\r
+\r
+    assert(nptr != NULL);\r
+    /* Set errno to zero, so that we can distinguish zero results\r
+       and underflows */\r
+    errno = 0;\r
+\r
+    _Py_SET_53BIT_PRECISION_START;\r
+    result = _Py_dg_strtod(nptr, endptr);\r
+    _Py_SET_53BIT_PRECISION_END;\r
+\r
+    if (*endptr == nptr)\r
+        /* string might represent an inf or nan */\r
+        result = _Py_parse_inf_or_nan(nptr, endptr);\r
+\r
+    return result;\r
+\r
+}\r
+\r
+#else\r
+\r
+/*\r
+   Use system strtod;  since strtod is locale aware, we may\r
+   have to first fix the decimal separator.\r
+\r
+   Note that unlike _Py_dg_strtod, the system strtod may not always give\r
+   correctly rounded results.\r
+*/\r
+\r
+double\r
+_PyOS_ascii_strtod(const char *nptr, char **endptr)\r
+{\r
+    char *fail_pos;\r
+    double val = -1.0;\r
+    struct lconv *locale_data;\r
+    const char *decimal_point;\r
+    size_t decimal_point_len;\r
+    const char *p, *decimal_point_pos;\r
+    const char *end = NULL; /* Silence gcc */\r
+    const char *digits_pos = NULL;\r
+    int negate = 0;\r
+\r
+    assert(nptr != NULL);\r
+\r
+    fail_pos = NULL;\r
+\r
+    locale_data = localeconv();\r
+    decimal_point = locale_data->decimal_point;\r
+    decimal_point_len = strlen(decimal_point);\r
+\r
+    assert(decimal_point_len != 0);\r
+\r
+    decimal_point_pos = NULL;\r
+\r
+    /* Parse infinities and nans */\r
+    val = _Py_parse_inf_or_nan(nptr, endptr);\r
+    if (*endptr != nptr)\r
+        return val;\r
+\r
+    /* Set errno to zero, so that we can distinguish zero results\r
+       and underflows */\r
+    errno = 0;\r
+\r
+    /* We process the optional sign manually, then pass the remainder to\r
+       the system strtod.  This ensures that the result of an underflow\r
+       has the correct sign. (bug #1725)  */\r
+    p = nptr;\r
+    /* Process leading sign, if present */\r
+    if (*p == '-') {\r
+        negate = 1;\r
+        p++;\r
+    }\r
+    else if (*p == '+') {\r
+        p++;\r
+    }\r
+\r
+    /* Some platform strtods accept hex floats; Python shouldn't (at the\r
+       moment), so we check explicitly for strings starting with '0x'. */\r
+    if (*p == '0' && (*(p+1) == 'x' || *(p+1) == 'X'))\r
+        goto invalid_string;\r
+\r
+    /* Check that what's left begins with a digit or decimal point */\r
+    if (!Py_ISDIGIT(*p) && *p != '.')\r
+        goto invalid_string;\r
+\r
+    digits_pos = p;\r
+    if (decimal_point[0] != '.' ||\r
+        decimal_point[1] != 0)\r
+    {\r
+        /* Look for a '.' in the input; if present, it'll need to be\r
+           swapped for the current locale's decimal point before we\r
+           call strtod.  On the other hand, if we find the current\r
+           locale's decimal point then the input is invalid. */\r
+        while (Py_ISDIGIT(*p))\r
+            p++;\r
+\r
+        if (*p == '.')\r
+        {\r
+            decimal_point_pos = p++;\r
+\r
+            /* locate end of number */\r
+            while (Py_ISDIGIT(*p))\r
+                p++;\r
+\r
+            if (*p == 'e' || *p == 'E')\r
+                p++;\r
+            if (*p == '+' || *p == '-')\r
+                p++;\r
+            while (Py_ISDIGIT(*p))\r
+                p++;\r
+            end = p;\r
+        }\r
+        else if (strncmp(p, decimal_point, decimal_point_len) == 0)\r
+            /* Python bug #1417699 */\r
+            goto invalid_string;\r
+        /* For the other cases, we need not convert the decimal\r
+           point */\r
+    }\r
+\r
+    if (decimal_point_pos) {\r
+        char *copy, *c;\r
+        /* Create a copy of the input, with the '.' converted to the\r
+           locale-specific decimal point */\r
+        copy = (char *)PyMem_MALLOC(end - digits_pos +\r
+                                    1 + decimal_point_len);\r
+        if (copy == NULL) {\r
+            *endptr = (char *)nptr;\r
+            errno = ENOMEM;\r
+            return val;\r
+        }\r
+\r
+        c = copy;\r
+        memcpy(c, digits_pos, decimal_point_pos - digits_pos);\r
+        c += decimal_point_pos - digits_pos;\r
+        memcpy(c, decimal_point, decimal_point_len);\r
+        c += decimal_point_len;\r
+        memcpy(c, decimal_point_pos + 1,\r
+               end - (decimal_point_pos + 1));\r
+        c += end - (decimal_point_pos + 1);\r
+        *c = 0;\r
+\r
+        val = strtod(copy, &fail_pos);\r
+\r
+        if (fail_pos)\r
+        {\r
+            if (fail_pos > decimal_point_pos)\r
+                fail_pos = (char *)digits_pos +\r
+                    (fail_pos - copy) -\r
+                    (decimal_point_len - 1);\r
+            else\r
+                fail_pos = (char *)digits_pos +\r
+                    (fail_pos - copy);\r
+        }\r
+\r
+        PyMem_FREE(copy);\r
+\r
+    }\r
+    else {\r
+        val = strtod(digits_pos, &fail_pos);\r
+    }\r
+\r
+    if (fail_pos == digits_pos)\r
+        goto invalid_string;\r
+\r
+    if (negate && fail_pos != nptr)\r
+        val = -val;\r
+    *endptr = fail_pos;\r
+\r
+    return val;\r
+\r
+  invalid_string:\r
+    *endptr = (char*)nptr;\r
+    errno = EINVAL;\r
+    return -1.0;\r
+}\r
+\r
+#endif\r
+\r
+/* PyOS_ascii_strtod is DEPRECATED in Python 2.7 and 3.1 */\r
+\r
+double\r
+PyOS_ascii_strtod(const char *nptr, char **endptr)\r
+{\r
+    char *fail_pos;\r
+    const char *p;\r
+    double x;\r
+\r
+    if (PyErr_WarnEx(PyExc_DeprecationWarning,\r
+                     "PyOS_ascii_strtod and PyOS_ascii_atof are "\r
+                     "deprecated.  Use PyOS_string_to_double "\r
+                     "instead.", 1) < 0)\r
+        return -1.0;\r
+\r
+    /* _PyOS_ascii_strtod already does everything that we want,\r
+       except that it doesn't parse leading whitespace */\r
+    p = nptr;\r
+    while (Py_ISSPACE(*p))\r
+        p++;\r
+    x = _PyOS_ascii_strtod(p, &fail_pos);\r
+    if (fail_pos == p)\r
+        fail_pos = (char *)nptr;\r
+    if (endptr)\r
+        *endptr = (char *)fail_pos;\r
+    return x;\r
+}\r
+\r
+/* PyOS_ascii_strtod is DEPRECATED in Python 2.7 and 3.1 */\r
+\r
+double\r
+PyOS_ascii_atof(const char *nptr)\r
+{\r
+    return PyOS_ascii_strtod(nptr, NULL);\r
+}\r
+\r
+/* PyOS_string_to_double is the recommended replacement for the deprecated\r
+   PyOS_ascii_strtod and PyOS_ascii_atof functions.  It converts a\r
+   null-terminated byte string s (interpreted as a string of ASCII characters)\r
+   to a float.  The string should not have leading or trailing whitespace (in\r
+   contrast, PyOS_ascii_strtod allows leading whitespace but not trailing\r
+   whitespace).  The conversion is independent of the current locale.\r
+\r
+   If endptr is NULL, try to convert the whole string.  Raise ValueError and\r
+   return -1.0 if the string is not a valid representation of a floating-point\r
+   number.\r
+\r
+   If endptr is non-NULL, try to convert as much of the string as possible.\r
+   If no initial segment of the string is the valid representation of a\r
+   floating-point number then *endptr is set to point to the beginning of the\r
+   string, -1.0 is returned and again ValueError is raised.\r
+\r
+   On overflow (e.g., when trying to convert '1e500' on an IEEE 754 machine),\r
+   if overflow_exception is NULL then +-Py_HUGE_VAL is returned, and no Python\r
+   exception is raised.  Otherwise, overflow_exception should point to\r
+   a Python exception, this exception will be raised, -1.0 will be returned,\r
+   and *endptr will point just past the end of the converted value.\r
+\r
+   If any other failure occurs (for example lack of memory), -1.0 is returned\r
+   and the appropriate Python exception will have been set.\r
+*/\r
+\r
+double\r
+PyOS_string_to_double(const char *s,\r
+                      char **endptr,\r
+                      PyObject *overflow_exception)\r
+{\r
+    double x, result=-1.0;\r
+    char *fail_pos;\r
+\r
+    errno = 0;\r
+    PyFPE_START_PROTECT("PyOS_string_to_double", return -1.0)\r
+    x = _PyOS_ascii_strtod(s, &fail_pos);\r
+    PyFPE_END_PROTECT(x)\r
+\r
+    if (errno == ENOMEM) {\r
+        PyErr_NoMemory();\r
+        fail_pos = (char *)s;\r
+    }\r
+    else if (!endptr && (fail_pos == s || *fail_pos != '\0'))\r
+        PyErr_Format(PyExc_ValueError,\r
+                      "could not convert string to float: "\r
+                      "%.200s", s);\r
+    else if (fail_pos == s)\r
+        PyErr_Format(PyExc_ValueError,\r
+                      "could not convert string to float: "\r
+                      "%.200s", s);\r
+    else if (errno == ERANGE && fabs(x) >= 1.0 && overflow_exception)\r
+        PyErr_Format(overflow_exception,\r
+                      "value too large to convert to float: "\r
+                      "%.200s", s);\r
+    else\r
+        result = x;\r
+\r
+    if (endptr != NULL)\r
+        *endptr = fail_pos;\r
+    return result;\r
+}\r
+\r
+/* Given a string that may have a decimal point in the current\r
+   locale, change it back to a dot.  Since the string cannot get\r
+   longer, no need for a maximum buffer size parameter. */\r
+Py_LOCAL_INLINE(void)\r
+change_decimal_from_locale_to_dot(char* buffer)\r
+{\r
+    struct lconv *locale_data = localeconv();\r
+    const char *decimal_point = locale_data->decimal_point;\r
+\r
+    if (decimal_point[0] != '.' || decimal_point[1] != 0) {\r
+        size_t decimal_point_len = strlen(decimal_point);\r
+\r
+        if (*buffer == '+' || *buffer == '-')\r
+            buffer++;\r
+        while (Py_ISDIGIT(*buffer))\r
+            buffer++;\r
+        if (strncmp(buffer, decimal_point, decimal_point_len) == 0) {\r
+            *buffer = '.';\r
+            buffer++;\r
+            if (decimal_point_len > 1) {\r
+                /* buffer needs to get smaller */\r
+                size_t rest_len = strlen(buffer +\r
+                                     (decimal_point_len - 1));\r
+                memmove(buffer,\r
+                    buffer + (decimal_point_len - 1),\r
+                    rest_len);\r
+                buffer[rest_len] = 0;\r
+            }\r
+        }\r
+    }\r
+}\r
+\r
+\r
+/* From the C99 standard, section 7.19.6:\r
+The exponent always contains at least two digits, and only as many more digits\r
+as necessary to represent the exponent.\r
+*/\r
+#define MIN_EXPONENT_DIGITS 2\r
+\r
+/* Ensure that any exponent, if present, is at least MIN_EXPONENT_DIGITS\r
+   in length. */\r
+Py_LOCAL_INLINE(void)\r
+ensure_minimum_exponent_length(char* buffer, size_t buf_size)\r
+{\r
+    char *p = strpbrk(buffer, "eE");\r
+    if (p && (*(p + 1) == '-' || *(p + 1) == '+')) {\r
+        char *start = p + 2;\r
+        int exponent_digit_cnt = 0;\r
+        int leading_zero_cnt = 0;\r
+        int in_leading_zeros = 1;\r
+        int significant_digit_cnt;\r
+\r
+        /* Skip over the exponent and the sign. */\r
+        p += 2;\r
+\r
+        /* Find the end of the exponent, keeping track of leading\r
+           zeros. */\r
+        while (*p && Py_ISDIGIT(*p)) {\r
+            if (in_leading_zeros && *p == '0')\r
+                ++leading_zero_cnt;\r
+            if (*p != '0')\r
+                in_leading_zeros = 0;\r
+            ++p;\r
+            ++exponent_digit_cnt;\r
+        }\r
+\r
+        significant_digit_cnt = exponent_digit_cnt - leading_zero_cnt;\r
+        if (exponent_digit_cnt == MIN_EXPONENT_DIGITS) {\r
+            /* If there are 2 exactly digits, we're done,\r
+               regardless of what they contain */\r
+        }\r
+        else if (exponent_digit_cnt > MIN_EXPONENT_DIGITS) {\r
+            int extra_zeros_cnt;\r
+\r
+            /* There are more than 2 digits in the exponent.  See\r
+               if we can delete some of the leading zeros */\r
+            if (significant_digit_cnt < MIN_EXPONENT_DIGITS)\r
+                significant_digit_cnt = MIN_EXPONENT_DIGITS;\r
+            extra_zeros_cnt = exponent_digit_cnt -\r
+                significant_digit_cnt;\r
+\r
+            /* Delete extra_zeros_cnt worth of characters from the\r
+               front of the exponent */\r
+            assert(extra_zeros_cnt >= 0);\r
+\r
+            /* Add one to significant_digit_cnt to copy the\r
+               trailing 0 byte, thus setting the length */\r
+            memmove(start,\r
+                start + extra_zeros_cnt,\r
+                significant_digit_cnt + 1);\r
+        }\r
+        else {\r
+            /* If there are fewer than 2 digits, add zeros\r
+               until there are 2, if there's enough room */\r
+            int zeros = MIN_EXPONENT_DIGITS - exponent_digit_cnt;\r
+            if (start + zeros + exponent_digit_cnt + 1\r
+                  < buffer + buf_size) {\r
+                memmove(start + zeros, start,\r
+                    exponent_digit_cnt + 1);\r
+                memset(start, '0', zeros);\r
+            }\r
+        }\r
+    }\r
+}\r
+\r
+/* Remove trailing zeros after the decimal point from a numeric string; also\r
+   remove the decimal point if all digits following it are zero.  The numeric\r
+   string must end in '\0', and should not have any leading or trailing\r
+   whitespace.  Assumes that the decimal point is '.'. */\r
+Py_LOCAL_INLINE(void)\r
+remove_trailing_zeros(char *buffer)\r
+{\r
+    char *old_fraction_end, *new_fraction_end, *end, *p;\r
+\r
+    p = buffer;\r
+    if (*p == '-' || *p == '+')\r
+        /* Skip leading sign, if present */\r
+        ++p;\r
+    while (Py_ISDIGIT(*p))\r
+        ++p;\r
+\r
+    /* if there's no decimal point there's nothing to do */\r
+    if (*p++ != '.')\r
+        return;\r
+\r
+    /* scan any digits after the point */\r
+    while (Py_ISDIGIT(*p))\r
+        ++p;\r
+    old_fraction_end = p;\r
+\r
+    /* scan up to ending '\0' */\r
+    while (*p != '\0')\r
+        p++;\r
+    /* +1 to make sure that we move the null byte as well */\r
+    end = p+1;\r
+\r
+    /* scan back from fraction_end, looking for removable zeros */\r
+    p = old_fraction_end;\r
+    while (*(p-1) == '0')\r
+        --p;\r
+    /* and remove point if we've got that far */\r
+    if (*(p-1) == '.')\r
+        --p;\r
+    new_fraction_end = p;\r
+\r
+    memmove(new_fraction_end, old_fraction_end, end-old_fraction_end);\r
+}\r
+\r
+/* Ensure that buffer has a decimal point in it.  The decimal point will not\r
+   be in the current locale, it will always be '.'. Don't add a decimal point\r
+   if an exponent is present.  Also, convert to exponential notation where\r
+   adding a '.0' would produce too many significant digits (see issue 5864).\r
+\r
+   Returns a pointer to the fixed buffer, or NULL on failure.\r
+*/\r
+Py_LOCAL_INLINE(char *)\r
+ensure_decimal_point(char* buffer, size_t buf_size, int precision)\r
+{\r
+    int digit_count, insert_count = 0, convert_to_exp = 0;\r
+    char *chars_to_insert, *digits_start;\r
+\r
+    /* search for the first non-digit character */\r
+    char *p = buffer;\r
+    if (*p == '-' || *p == '+')\r
+        /* Skip leading sign, if present.  I think this could only\r
+           ever be '-', but it can't hurt to check for both. */\r
+        ++p;\r
+    digits_start = p;\r
+    while (*p && Py_ISDIGIT(*p))\r
+        ++p;\r
+    digit_count = Py_SAFE_DOWNCAST(p - digits_start, Py_ssize_t, int);\r
+\r
+    if (*p == '.') {\r
+        if (Py_ISDIGIT(*(p+1))) {\r
+            /* Nothing to do, we already have a decimal\r
+               point and a digit after it */\r
+        }\r
+        else {\r
+            /* We have a decimal point, but no following\r
+               digit.  Insert a zero after the decimal. */\r
+            /* can't ever get here via PyOS_double_to_string */\r
+            assert(precision == -1);\r
+            ++p;\r
+            chars_to_insert = "0";\r
+            insert_count = 1;\r
+        }\r
+    }\r
+    else if (!(*p == 'e' || *p == 'E')) {\r
+        /* Don't add ".0" if we have an exponent. */\r
+        if (digit_count == precision) {\r
+            /* issue 5864: don't add a trailing .0 in the case\r
+               where the '%g'-formatted result already has as many\r
+               significant digits as were requested.  Switch to\r
+               exponential notation instead. */\r
+            convert_to_exp = 1;\r
+            /* no exponent, no point, and we shouldn't land here\r
+               for infs and nans, so we must be at the end of the\r
+               string. */\r
+            assert(*p == '\0');\r
+        }\r
+        else {\r
+            assert(precision == -1 || digit_count < precision);\r
+            chars_to_insert = ".0";\r
+            insert_count = 2;\r
+        }\r
+    }\r
+    if (insert_count) {\r
+        size_t buf_len = strlen(buffer);\r
+        if (buf_len + insert_count + 1 >= buf_size) {\r
+            /* If there is not enough room in the buffer\r
+               for the additional text, just skip it.  It's\r
+               not worth generating an error over. */\r
+        }\r
+        else {\r
+            memmove(p + insert_count, p,\r
+                buffer + strlen(buffer) - p + 1);\r
+            memcpy(p, chars_to_insert, insert_count);\r
+        }\r
+    }\r
+    if (convert_to_exp) {\r
+        int written;\r
+        size_t buf_avail;\r
+        p = digits_start;\r
+        /* insert decimal point */\r
+        assert(digit_count >= 1);\r
+        memmove(p+2, p+1, digit_count); /* safe, but overwrites nul */\r
+        p[1] = '.';\r
+        p += digit_count+1;\r
+        assert(p <= buf_size+buffer);\r
+        buf_avail = buf_size+buffer-p;\r
+        if (buf_avail == 0)\r
+            return NULL;\r
+        /* Add exponent.  It's okay to use lower case 'e': we only\r
+           arrive here as a result of using the empty format code or\r
+           repr/str builtins and those never want an upper case 'E' */\r
+        written = PyOS_snprintf(p, buf_avail, "e%+.02d", digit_count-1);\r
+        if (!(0 <= written &&\r
+              written < Py_SAFE_DOWNCAST(buf_avail, size_t, int)))\r
+            /* output truncated, or something else bad happened */\r
+            return NULL;\r
+        remove_trailing_zeros(buffer);\r
+    }\r
+    return buffer;\r
+}\r
+\r
+/* see FORMATBUFLEN in unicodeobject.c */\r
+#define FLOAT_FORMATBUFLEN 120\r
+\r
+/**\r
+ * PyOS_ascii_formatd:\r
+ * @buffer: A buffer to place the resulting string in\r
+ * @buf_size: The length of the buffer.\r
+ * @format: The printf()-style format to use for the\r
+ *          code to use for converting.\r
+ * @d: The #gdouble to convert\r
+ *\r
+ * Converts a #gdouble to a string, using the '.' as\r
+ * decimal point. To format the number you pass in\r
+ * a printf()-style format string. Allowed conversion\r
+ * specifiers are 'e', 'E', 'f', 'F', 'g', 'G', and 'Z'.\r
+ *\r
+ * 'Z' is the same as 'g', except it always has a decimal and\r
+ *     at least one digit after the decimal.\r
+ *\r
+ * Return value: The pointer to the buffer with the converted string.\r
+ * On failure returns NULL but does not set any Python exception.\r
+ **/\r
+char *\r
+_PyOS_ascii_formatd(char       *buffer,\r
+                   size_t      buf_size,\r
+                   const char *format,\r
+                   double      d,\r
+                   int         precision)\r
+{\r
+    char format_char;\r
+    size_t format_len = strlen(format);\r
+\r
+    /* Issue 2264: code 'Z' requires copying the format.  'Z' is 'g', but\r
+       also with at least one character past the decimal. */\r
+    char tmp_format[FLOAT_FORMATBUFLEN];\r
+\r
+    /* The last character in the format string must be the format char */\r
+    format_char = format[format_len - 1];\r
+\r
+    if (format[0] != '%')\r
+        return NULL;\r
+\r
+    /* I'm not sure why this test is here.  It's ensuring that the format\r
+       string after the first character doesn't have a single quote, a\r
+       lowercase l, or a percent. This is the reverse of the commented-out\r
+       test about 10 lines ago. */\r
+    if (strpbrk(format + 1, "'l%"))\r
+        return NULL;\r
+\r
+    /* Also curious about this function is that it accepts format strings\r
+       like "%xg", which are invalid for floats.  In general, the\r
+       interface to this function is not very good, but changing it is\r
+       difficult because it's a public API. */\r
+\r
+    if (!(format_char == 'e' || format_char == 'E' ||\r
+          format_char == 'f' || format_char == 'F' ||\r
+          format_char == 'g' || format_char == 'G' ||\r
+          format_char == 'Z'))\r
+        return NULL;\r
+\r
+    /* Map 'Z' format_char to 'g', by copying the format string and\r
+       replacing the final char with a 'g' */\r
+    if (format_char == 'Z') {\r
+        if (format_len + 1 >= sizeof(tmp_format)) {\r
+            /* The format won't fit in our copy.  Error out.  In\r
+               practice, this will never happen and will be\r
+               detected by returning NULL */\r
+            return NULL;\r
+        }\r
+        strcpy(tmp_format, format);\r
+        tmp_format[format_len - 1] = 'g';\r
+        format = tmp_format;\r
+    }\r
+\r
+\r
+    /* Have PyOS_snprintf do the hard work */\r
+    PyOS_snprintf(buffer, buf_size, format, d);\r
+\r
+    /* Do various fixups on the return string */\r
+\r
+    /* Get the current locale, and find the decimal point string.\r
+       Convert that string back to a dot. */\r
+    change_decimal_from_locale_to_dot(buffer);\r
+\r
+    /* If an exponent exists, ensure that the exponent is at least\r
+       MIN_EXPONENT_DIGITS digits, providing the buffer is large enough\r
+       for the extra zeros.  Also, if there are more than\r
+       MIN_EXPONENT_DIGITS, remove as many zeros as possible until we get\r
+       back to MIN_EXPONENT_DIGITS */\r
+    ensure_minimum_exponent_length(buffer, buf_size);\r
+\r
+    /* If format_char is 'Z', make sure we have at least one character\r
+       after the decimal point (and make sure we have a decimal point);\r
+       also switch to exponential notation in some edge cases where the\r
+       extra character would produce more significant digits that we\r
+       really want. */\r
+    if (format_char == 'Z')\r
+        buffer = ensure_decimal_point(buffer, buf_size, precision);\r
+\r
+    return buffer;\r
+}\r
+\r
+char *\r
+PyOS_ascii_formatd(char       *buffer,\r
+                   size_t      buf_size,\r
+                   const char *format,\r
+                   double      d)\r
+{\r
+    if (PyErr_WarnEx(PyExc_DeprecationWarning,\r
+                     "PyOS_ascii_formatd is deprecated, "\r
+                     "use PyOS_double_to_string instead", 1) < 0)\r
+        return NULL;\r
+\r
+    return _PyOS_ascii_formatd(buffer, buf_size, format, d, -1);\r
+}\r
+\r
+#ifdef PY_NO_SHORT_FLOAT_REPR\r
+\r
+/* The fallback code to use if _Py_dg_dtoa is not available. */\r
+\r
+PyAPI_FUNC(char *) PyOS_double_to_string(double val,\r
+                                         char format_code,\r
+                                         int precision,\r
+                                         int flags,\r
+                                         int *type)\r
+{\r
+    char format[32];\r
+    Py_ssize_t bufsize;\r
+    char *buf;\r
+    int t, exp;\r
+    int upper = 0;\r
+\r
+    /* Validate format_code, and map upper and lower case */\r
+    switch (format_code) {\r
+    case 'e':          /* exponent */\r
+    case 'f':          /* fixed */\r
+    case 'g':          /* general */\r
+        break;\r
+    case 'E':\r
+        upper = 1;\r
+        format_code = 'e';\r
+        break;\r
+    case 'F':\r
+        upper = 1;\r
+        format_code = 'f';\r
+        break;\r
+    case 'G':\r
+        upper = 1;\r
+        format_code = 'g';\r
+        break;\r
+    case 'r':          /* repr format */\r
+        /* Supplied precision is unused, must be 0. */\r
+        if (precision != 0) {\r
+            PyErr_BadInternalCall();\r
+            return NULL;\r
+        }\r
+        /* The repr() precision (17 significant decimal digits) is the\r
+           minimal number that is guaranteed to have enough precision\r
+           so that if the number is read back in the exact same binary\r
+           value is recreated.  This is true for IEEE floating point\r
+           by design, and also happens to work for all other modern\r
+           hardware. */\r
+        precision = 17;\r
+        format_code = 'g';\r
+        break;\r
+    default:\r
+        PyErr_BadInternalCall();\r
+        return NULL;\r
+    }\r
+\r
+    /* Here's a quick-and-dirty calculation to figure out how big a buffer\r
+       we need.  In general, for a finite float we need:\r
+\r
+         1 byte for each digit of the decimal significand, and\r
+\r
+         1 for a possible sign\r
+         1 for a possible decimal point\r
+         2 for a possible [eE][+-]\r
+         1 for each digit of the exponent;  if we allow 19 digits\r
+           total then we're safe up to exponents of 2**63.\r
+         1 for the trailing nul byte\r
+\r
+       This gives a total of 24 + the number of digits in the significand,\r
+       and the number of digits in the significand is:\r
+\r
+         for 'g' format: at most precision, except possibly\r
+           when precision == 0, when it's 1.\r
+         for 'e' format: precision+1\r
+         for 'f' format: precision digits after the point, at least 1\r
+           before.  To figure out how many digits appear before the point\r
+           we have to examine the size of the number.  If fabs(val) < 1.0\r
+           then there will be only one digit before the point.  If\r
+           fabs(val) >= 1.0, then there are at most\r
+\r
+         1+floor(log10(ceiling(fabs(val))))\r
+\r
+           digits before the point (where the 'ceiling' allows for the\r
+           possibility that the rounding rounds the integer part of val\r
+           up).  A safe upper bound for the above quantity is\r
+           1+floor(exp/3), where exp is the unique integer such that 0.5\r
+           <= fabs(val)/2**exp < 1.0.  This exp can be obtained from\r
+           frexp.\r
+\r
+       So we allow room for precision+1 digits for all formats, plus an\r
+       extra floor(exp/3) digits for 'f' format.\r
+\r
+    */\r
+\r
+    if (Py_IS_NAN(val) || Py_IS_INFINITY(val))\r
+        /* 3 for 'inf'/'nan', 1 for sign, 1 for '\0' */\r
+        bufsize = 5;\r
+    else {\r
+        bufsize = 25 + precision;\r
+        if (format_code == 'f' && fabs(val) >= 1.0) {\r
+            frexp(val, &exp);\r
+            bufsize += exp/3;\r
+        }\r
+    }\r
+\r
+    buf = PyMem_Malloc(bufsize);\r
+    if (buf == NULL) {\r
+        PyErr_NoMemory();\r
+        return NULL;\r
+    }\r
+\r
+    /* Handle nan and inf. */\r
+    if (Py_IS_NAN(val)) {\r
+        strcpy(buf, "nan");\r
+        t = Py_DTST_NAN;\r
+    } else if (Py_IS_INFINITY(val)) {\r
+        if (copysign(1., val) == 1.)\r
+            strcpy(buf, "inf");\r
+        else\r
+            strcpy(buf, "-inf");\r
+        t = Py_DTST_INFINITE;\r
+    } else {\r
+        t = Py_DTST_FINITE;\r
+        if (flags & Py_DTSF_ADD_DOT_0)\r
+            format_code = 'Z';\r
+\r
+        PyOS_snprintf(format, sizeof(format), "%%%s.%i%c",\r
+                      (flags & Py_DTSF_ALT ? "#" : ""), precision,\r
+                      format_code);\r
+        _PyOS_ascii_formatd(buf, bufsize, format, val, precision);\r
+    }\r
+\r
+    /* Add sign when requested.  It's convenient (esp. when formatting\r
+     complex numbers) to include a sign even for inf and nan. */\r
+    if (flags & Py_DTSF_SIGN && buf[0] != '-') {\r
+        size_t len = strlen(buf);\r
+        /* the bufsize calculations above should ensure that we've got\r
+           space to add a sign */\r
+        assert((size_t)bufsize >= len+2);\r
+        memmove(buf+1, buf, len+1);\r
+        buf[0] = '+';\r
+    }\r
+    if (upper) {\r
+        /* Convert to upper case. */\r
+        char *p1;\r
+        for (p1 = buf; *p1; p1++)\r
+            *p1 = Py_TOUPPER(*p1);\r
+    }\r
+\r
+    if (type)\r
+        *type = t;\r
+    return buf;\r
+}\r
+\r
+#else\r
+\r
+/* _Py_dg_dtoa is available. */\r
+\r
+/* I'm using a lookup table here so that I don't have to invent a non-locale\r
+   specific way to convert to uppercase */\r
+#define OFS_INF 0\r
+#define OFS_NAN 1\r
+#define OFS_E 2\r
+\r
+/* The lengths of these are known to the code below, so don't change them */\r
+static char *lc_float_strings[] = {\r
+    "inf",\r
+    "nan",\r
+    "e",\r
+};\r
+static char *uc_float_strings[] = {\r
+    "INF",\r
+    "NAN",\r
+    "E",\r
+};\r
+\r
+\r
+/* Convert a double d to a string, and return a PyMem_Malloc'd block of\r
+   memory contain the resulting string.\r
+\r
+   Arguments:\r
+     d is the double to be converted\r
+     format_code is one of 'e', 'f', 'g', 'r'.  'e', 'f' and 'g'\r
+       correspond to '%e', '%f' and '%g';  'r' corresponds to repr.\r
+     mode is one of '0', '2' or '3', and is completely determined by\r
+       format_code: 'e' and 'g' use mode 2; 'f' mode 3, 'r' mode 0.\r
+     precision is the desired precision\r
+     always_add_sign is nonzero if a '+' sign should be included for positive\r
+       numbers\r
+     add_dot_0_if_integer is nonzero if integers in non-exponential form\r
+       should have ".0" added.  Only applies to format codes 'r' and 'g'.\r
+     use_alt_formatting is nonzero if alternative formatting should be\r
+       used.  Only applies to format codes 'e', 'f' and 'g'.  For code 'g',\r
+       at most one of use_alt_formatting and add_dot_0_if_integer should\r
+       be nonzero.\r
+     type, if non-NULL, will be set to one of these constants to identify\r
+       the type of the 'd' argument:\r
+     Py_DTST_FINITE\r
+     Py_DTST_INFINITE\r
+     Py_DTST_NAN\r
+\r
+   Returns a PyMem_Malloc'd block of memory containing the resulting string,\r
+    or NULL on error. If NULL is returned, the Python error has been set.\r
+ */\r
+\r
+static char *\r
+format_float_short(double d, char format_code,\r
+                   int mode, Py_ssize_t precision,\r
+                   int always_add_sign, int add_dot_0_if_integer,\r
+                   int use_alt_formatting, char **float_strings, int *type)\r
+{\r
+    char *buf = NULL;\r
+    char *p = NULL;\r
+    Py_ssize_t bufsize = 0;\r
+    char *digits, *digits_end;\r
+    int decpt_as_int, sign, exp_len, exp = 0, use_exp = 0;\r
+    Py_ssize_t decpt, digits_len, vdigits_start, vdigits_end;\r
+    _Py_SET_53BIT_PRECISION_HEADER;\r
+\r
+    /* _Py_dg_dtoa returns a digit string (no decimal point or exponent).\r
+       Must be matched by a call to _Py_dg_freedtoa. */\r
+    _Py_SET_53BIT_PRECISION_START;\r
+    digits = _Py_dg_dtoa(d, mode, precision, &decpt_as_int, &sign,\r
+                         &digits_end);\r
+    _Py_SET_53BIT_PRECISION_END;\r
+\r
+    decpt = (Py_ssize_t)decpt_as_int;\r
+    if (digits == NULL) {\r
+        /* The only failure mode is no memory. */\r
+        PyErr_NoMemory();\r
+        goto exit;\r
+    }\r
+    assert(digits_end != NULL && digits_end >= digits);\r
+    digits_len = digits_end - digits;\r
+\r
+    if (digits_len && !Py_ISDIGIT(digits[0])) {\r
+        /* Infinities and nans here; adapt Gay's output,\r
+           so convert Infinity to inf and NaN to nan, and\r
+           ignore sign of nan. Then return. */\r
+\r
+        /* ignore the actual sign of a nan */\r
+        if (digits[0] == 'n' || digits[0] == 'N')\r
+            sign = 0;\r
+\r
+        /* We only need 5 bytes to hold the result "+inf\0" . */\r
+        bufsize = 5; /* Used later in an assert. */\r
+        buf = (char *)PyMem_Malloc(bufsize);\r
+        if (buf == NULL) {\r
+            PyErr_NoMemory();\r
+            goto exit;\r
+        }\r
+        p = buf;\r
+\r
+        if (sign == 1) {\r
+            *p++ = '-';\r
+        }\r
+        else if (always_add_sign) {\r
+            *p++ = '+';\r
+        }\r
+        if (digits[0] == 'i' || digits[0] == 'I') {\r
+            strncpy(p, float_strings[OFS_INF], 3);\r
+            p += 3;\r
+\r
+            if (type)\r
+                *type = Py_DTST_INFINITE;\r
+        }\r
+        else if (digits[0] == 'n' || digits[0] == 'N') {\r
+            strncpy(p, float_strings[OFS_NAN], 3);\r
+            p += 3;\r
+\r
+            if (type)\r
+                *type = Py_DTST_NAN;\r
+        }\r
+        else {\r
+            /* shouldn't get here: Gay's code should always return\r
+               something starting with a digit, an 'I',  or 'N' */\r
+            strncpy(p, "ERR", 3);\r
+            p += 3;\r
+            assert(0);\r
+        }\r
+        goto exit;\r
+    }\r
+\r
+    /* The result must be finite (not inf or nan). */\r
+    if (type)\r
+        *type = Py_DTST_FINITE;\r
+\r
+\r
+    /* We got digits back, format them.  We may need to pad 'digits'\r
+       either on the left or right (or both) with extra zeros, so in\r
+       general the resulting string has the form\r
+\r
+         [<sign>]<zeros><digits><zeros>[<exponent>]\r
+\r
+       where either of the <zeros> pieces could be empty, and there's a\r
+       decimal point that could appear either in <digits> or in the\r
+       leading or trailing <zeros>.\r
+\r
+       Imagine an infinite 'virtual' string vdigits, consisting of the\r
+       string 'digits' (starting at index 0) padded on both the left and\r
+       right with infinite strings of zeros.  We want to output a slice\r
+\r
+         vdigits[vdigits_start : vdigits_end]\r
+\r
+       of this virtual string.  Thus if vdigits_start < 0 then we'll end\r
+       up producing some leading zeros; if vdigits_end > digits_len there\r
+       will be trailing zeros in the output.  The next section of code\r
+       determines whether to use an exponent or not, figures out the\r
+       position 'decpt' of the decimal point, and computes 'vdigits_start'\r
+       and 'vdigits_end'. */\r
+    vdigits_end = digits_len;\r
+    switch (format_code) {\r
+    case 'e':\r
+        use_exp = 1;\r
+        vdigits_end = precision;\r
+        break;\r
+    case 'f':\r
+        vdigits_end = decpt + precision;\r
+        break;\r
+    case 'g':\r
+        if (decpt <= -4 || decpt >\r
+            (add_dot_0_if_integer ? precision-1 : precision))\r
+            use_exp = 1;\r
+        if (use_alt_formatting)\r
+            vdigits_end = precision;\r
+        break;\r
+    case 'r':\r
+        /* convert to exponential format at 1e16.  We used to convert\r
+           at 1e17, but that gives odd-looking results for some values\r
+           when a 16-digit 'shortest' repr is padded with bogus zeros.\r
+           For example, repr(2e16+8) would give 20000000000000010.0;\r
+           the true value is 20000000000000008.0. */\r
+        if (decpt <= -4 || decpt > 16)\r
+            use_exp = 1;\r
+        break;\r
+    default:\r
+        PyErr_BadInternalCall();\r
+        goto exit;\r
+    }\r
+\r
+    /* if using an exponent, reset decimal point position to 1 and adjust\r
+       exponent accordingly.*/\r
+    if (use_exp) {\r
+        exp = decpt - 1;\r
+        decpt = 1;\r
+    }\r
+    /* ensure vdigits_start < decpt <= vdigits_end, or vdigits_start <\r
+       decpt < vdigits_end if add_dot_0_if_integer and no exponent */\r
+    vdigits_start = decpt <= 0 ? decpt-1 : 0;\r
+    if (!use_exp && add_dot_0_if_integer)\r
+        vdigits_end = vdigits_end > decpt ? vdigits_end : decpt + 1;\r
+    else\r
+        vdigits_end = vdigits_end > decpt ? vdigits_end : decpt;\r
+\r
+    /* double check inequalities */\r
+    assert(vdigits_start <= 0 &&\r
+           0 <= digits_len &&\r
+           digits_len <= vdigits_end);\r
+    /* decimal point should be in (vdigits_start, vdigits_end] */\r
+    assert(vdigits_start < decpt && decpt <= vdigits_end);\r
+\r
+    /* Compute an upper bound how much memory we need. This might be a few\r
+       chars too long, but no big deal. */\r
+    bufsize =\r
+        /* sign, decimal point and trailing 0 byte */\r
+        3 +\r
+\r
+        /* total digit count (including zero padding on both sides) */\r
+        (vdigits_end - vdigits_start) +\r
+\r
+        /* exponent "e+100", max 3 numerical digits */\r
+        (use_exp ? 5 : 0);\r
+\r
+    /* Now allocate the memory and initialize p to point to the start of\r
+       it. */\r
+    buf = (char *)PyMem_Malloc(bufsize);\r
+    if (buf == NULL) {\r
+        PyErr_NoMemory();\r
+        goto exit;\r
+    }\r
+    p = buf;\r
+\r
+    /* Add a negative sign if negative, and a plus sign if non-negative\r
+       and always_add_sign is true. */\r
+    if (sign == 1)\r
+        *p++ = '-';\r
+    else if (always_add_sign)\r
+        *p++ = '+';\r
+\r
+    /* note that exactly one of the three 'if' conditions is true,\r
+       so we include exactly one decimal point */\r
+    /* Zero padding on left of digit string */\r
+    if (decpt <= 0) {\r
+        memset(p, '0', decpt-vdigits_start);\r
+        p += decpt - vdigits_start;\r
+        *p++ = '.';\r
+        memset(p, '0', 0-decpt);\r
+        p += 0-decpt;\r
+    }\r
+    else {\r
+        memset(p, '0', 0-vdigits_start);\r
+        p += 0 - vdigits_start;\r
+    }\r
+\r
+    /* Digits, with included decimal point */\r
+    if (0 < decpt && decpt <= digits_len) {\r
+        strncpy(p, digits, decpt-0);\r
+        p += decpt-0;\r
+        *p++ = '.';\r
+        strncpy(p, digits+decpt, digits_len-decpt);\r
+        p += digits_len-decpt;\r
+    }\r
+    else {\r
+        strncpy(p, digits, digits_len);\r
+        p += digits_len;\r
+    }\r
+\r
+    /* And zeros on the right */\r
+    if (digits_len < decpt) {\r
+        memset(p, '0', decpt-digits_len);\r
+        p += decpt-digits_len;\r
+        *p++ = '.';\r
+        memset(p, '0', vdigits_end-decpt);\r
+        p += vdigits_end-decpt;\r
+    }\r
+    else {\r
+        memset(p, '0', vdigits_end-digits_len);\r
+        p += vdigits_end-digits_len;\r
+    }\r
+\r
+    /* Delete a trailing decimal pt unless using alternative formatting. */\r
+    if (p[-1] == '.' && !use_alt_formatting)\r
+        p--;\r
+\r
+    /* Now that we've done zero padding, add an exponent if needed. */\r
+    if (use_exp) {\r
+        *p++ = float_strings[OFS_E][0];\r
+        exp_len = sprintf(p, "%+.02d", exp);\r
+        p += exp_len;\r
+    }\r
+  exit:\r
+    if (buf) {\r
+        *p = '\0';\r
+        /* It's too late if this fails, as we've already stepped on\r
+           memory that isn't ours. But it's an okay debugging test. */\r
+        assert(p-buf < bufsize);\r
+    }\r
+    if (digits)\r
+        _Py_dg_freedtoa(digits);\r
+\r
+    return buf;\r
+}\r
+\r
+\r
+PyAPI_FUNC(char *) PyOS_double_to_string(double val,\r
+                                         char format_code,\r
+                                         int precision,\r
+                                         int flags,\r
+                                         int *type)\r
+{\r
+    char **float_strings = lc_float_strings;\r
+    int mode;\r
+\r
+    /* Validate format_code, and map upper and lower case. Compute the\r
+       mode and make any adjustments as needed. */\r
+    switch (format_code) {\r
+    /* exponent */\r
+    case 'E':\r
+        float_strings = uc_float_strings;\r
+        format_code = 'e';\r
+        /* Fall through. */\r
+    case 'e':\r
+        mode = 2;\r
+        precision++;\r
+        break;\r
+\r
+    /* fixed */\r
+    case 'F':\r
+        float_strings = uc_float_strings;\r
+        format_code = 'f';\r
+        /* Fall through. */\r
+    case 'f':\r
+        mode = 3;\r
+        break;\r
+\r
+    /* general */\r
+    case 'G':\r
+        float_strings = uc_float_strings;\r
+        format_code = 'g';\r
+        /* Fall through. */\r
+    case 'g':\r
+        mode = 2;\r
+        /* precision 0 makes no sense for 'g' format; interpret as 1 */\r
+        if (precision == 0)\r
+            precision = 1;\r
+        break;\r
+\r
+    /* repr format */\r
+    case 'r':\r
+        mode = 0;\r
+        /* Supplied precision is unused, must be 0. */\r
+        if (precision != 0) {\r
+            PyErr_BadInternalCall();\r
+            return NULL;\r
+        }\r
+        break;\r
+\r
+    default:\r
+        PyErr_BadInternalCall();\r
+        return NULL;\r
+    }\r
+\r
+    return format_float_short(val, format_code, mode, precision,\r
+                              flags & Py_DTSF_SIGN,\r
+                              flags & Py_DTSF_ADD_DOT_0,\r
+                              flags & Py_DTSF_ALT,\r
+                              float_strings, type);\r
+}\r
+#endif /* ifdef PY_NO_SHORT_FLOAT_REPR */\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/pythonrun.c b/AppPkg/Applications/Python/Python-2.7.10/Python/pythonrun.c
new file mode 100644 (file)
index 0000000..0f76758
--- /dev/null
@@ -0,0 +1,2029 @@
+\r
+/* Python interpreter top-level routines, including init/exit */\r
+\r
+#include "Python.h"\r
+\r
+#include "Python-ast.h"\r
+#undef Yield /* undefine macro conflicting with winbase.h */\r
+#include "grammar.h"\r
+#include "node.h"\r
+#include "token.h"\r
+#include "parsetok.h"\r
+#include "errcode.h"\r
+#include "code.h"\r
+#include "compile.h"\r
+#include "symtable.h"\r
+#include "pyarena.h"\r
+#include "ast.h"\r
+#include "eval.h"\r
+#include "marshal.h"\r
+#include "abstract.h"\r
+\r
+#ifdef HAVE_SIGNAL_H\r
+#include <signal.h>\r
+#endif\r
+\r
+#ifdef MS_WINDOWS\r
+#include "malloc.h" /* for alloca */\r
+#endif\r
+\r
+#ifdef HAVE_LANGINFO_H\r
+#include <locale.h>\r
+#include <langinfo.h>\r
+#endif\r
+\r
+#ifdef MS_WINDOWS\r
+#undef BYTE\r
+#include "windows.h"\r
+#endif\r
+\r
+#ifndef Py_REF_DEBUG\r
+#define PRINT_TOTAL_REFS()\r
+#else /* Py_REF_DEBUG */\r
+#define PRINT_TOTAL_REFS() fprintf(stderr,                              \\r
+                   "[%" PY_FORMAT_SIZE_T "d refs]\n",                   \\r
+                   _Py_GetRefTotal())\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+extern char *Py_GetPath(void);\r
+\r
+extern grammar _PyParser_Grammar; /* From graminit.c */\r
+\r
+/* Forward */\r
+static void initmain(void);\r
+static void initsite(void);\r
+static PyObject *run_mod(mod_ty, const char *, PyObject *, PyObject *,\r
+                          PyCompilerFlags *, PyArena *);\r
+static PyObject *run_pyc_file(FILE *, const char *, PyObject *, PyObject *,\r
+                              PyCompilerFlags *);\r
+static void err_input(perrdetail *);\r
+static void initsigs(void);\r
+static void wait_for_thread_shutdown(void);\r
+static void call_sys_exitfunc(void);\r
+static void call_ll_exitfuncs(void);\r
+extern void _PyUnicode_Init(void);\r
+extern void _PyUnicode_Fini(void);\r
+\r
+#ifdef WITH_THREAD\r
+extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *);\r
+extern void _PyGILState_Fini(void);\r
+#endif /* WITH_THREAD */\r
+\r
+int Py_DebugFlag; /* Needed by parser.c */\r
+int Py_VerboseFlag; /* Needed by import.c */\r
+int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */\r
+int Py_InspectFlag; /* Needed to determine whether to exit at SystemExit */\r
+int Py_NoSiteFlag; /* Suppress 'import site' */\r
+int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */\r
+int Py_DontWriteBytecodeFlag; /* Suppress writing bytecode files (*.py[co]) */\r
+int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */\r
+int Py_FrozenFlag; /* Needed by getpath.c */\r
+int Py_UnicodeFlag = 0; /* Needed by compile.c */\r
+int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */\r
+/* _XXX Py_QnewFlag should go away in 2.3.  It's true iff -Qnew is passed,\r
+  on the command line, and is used in 2.2 by ceval.c to make all "/" divisions\r
+  true divisions (which they will be in 2.3). */\r
+int _Py_QnewFlag = 0;\r
+int Py_NoUserSiteDirectory = 0; /* for -s and site.py */\r
+int Py_HashRandomizationFlag = 0; /* for -R and PYTHONHASHSEED */\r
+\r
+\r
+/* Hack to force loading of object files */\r
+int (*_PyOS_mystrnicmp_hack)(const char *, const char *, Py_ssize_t) = \\r
+    PyOS_mystrnicmp; /* Python/pystrcmp.o */\r
+\r
+/* PyModule_GetWarningsModule is no longer necessary as of 2.6\r
+since _warnings is builtin.  This API should not be used. */\r
+PyObject *\r
+PyModule_GetWarningsModule(void)\r
+{\r
+    return PyImport_ImportModule("warnings");\r
+}\r
+\r
+static int initialized = 0;\r
+\r
+/* API to access the initialized flag -- useful for esoteric use */\r
+\r
+int\r
+Py_IsInitialized(void)\r
+{\r
+    return initialized;\r
+}\r
+\r
+/* Global initializations.  Can be undone by Py_Finalize().  Don't\r
+   call this twice without an intervening Py_Finalize() call.  When\r
+   initializations fail, a fatal error is issued and the function does\r
+   not return.  On return, the first thread and interpreter state have\r
+   been created.\r
+\r
+   Locking: you must hold the interpreter lock while calling this.\r
+   (If the lock has not yet been initialized, that's equivalent to\r
+   having the lock, but you cannot use multiple threads.)\r
+\r
+*/\r
+\r
+static int\r
+add_flag(int flag, const char *envs)\r
+{\r
+    int env = atoi(envs);\r
+    if (flag < env)\r
+        flag = env;\r
+    if (flag < 1)\r
+        flag = 1;\r
+    return flag;\r
+}\r
+\r
+void\r
+Py_InitializeEx(int install_sigs)\r
+{\r
+    PyInterpreterState *interp;\r
+    PyThreadState *tstate;\r
+    PyObject *bimod, *sysmod;\r
+    char *p;\r
+    char *icodeset = NULL; /* On Windows, input codeset may theoretically\r
+                              differ from output codeset. */\r
+    char *codeset = NULL;\r
+    char *errors = NULL;\r
+    int free_codeset = 0;\r
+    int overridden = 0;\r
+    PyObject *sys_stream, *sys_isatty;\r
+#if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)\r
+    char *saved_locale, *loc_codeset;\r
+#endif\r
+#ifdef MS_WINDOWS\r
+    char ibuf[128];\r
+    char buf[128];\r
+#endif\r
+    extern void _Py_ReadyTypes(void);\r
+\r
+    if (initialized)\r
+        return;\r
+    initialized = 1;\r
+\r
+    if ((p = Py_GETENV("PYTHONDEBUG")) && *p != '\0')\r
+        Py_DebugFlag = add_flag(Py_DebugFlag, p);\r
+    if ((p = Py_GETENV("PYTHONVERBOSE")) && *p != '\0')\r
+        Py_VerboseFlag = add_flag(Py_VerboseFlag, p);\r
+    if ((p = Py_GETENV("PYTHONOPTIMIZE")) && *p != '\0')\r
+        Py_OptimizeFlag = add_flag(Py_OptimizeFlag, p);\r
+    if ((p = Py_GETENV("PYTHONDONTWRITEBYTECODE")) && *p != '\0')\r
+        Py_DontWriteBytecodeFlag = add_flag(Py_DontWriteBytecodeFlag, p);\r
+    /* The variable is only tested for existence here; _PyRandom_Init will\r
+       check its value further. */\r
+    if ((p = Py_GETENV("PYTHONHASHSEED")) && *p != '\0')\r
+        Py_HashRandomizationFlag = add_flag(Py_HashRandomizationFlag, p);\r
+\r
+    _PyRandom_Init();\r
+\r
+    interp = PyInterpreterState_New();\r
+    if (interp == NULL)\r
+        Py_FatalError("Py_Initialize: can't make first interpreter");\r
+\r
+    tstate = PyThreadState_New(interp);\r
+    if (tstate == NULL)\r
+        Py_FatalError("Py_Initialize: can't make first thread");\r
+    (void) PyThreadState_Swap(tstate);\r
+\r
+    _Py_ReadyTypes();\r
+\r
+    if (!_PyFrame_Init())\r
+        Py_FatalError("Py_Initialize: can't init frames");\r
+\r
+    if (!_PyInt_Init())\r
+        Py_FatalError("Py_Initialize: can't init ints");\r
+\r
+    if (!_PyLong_Init())\r
+        Py_FatalError("Py_Initialize: can't init longs");\r
+\r
+    if (!PyByteArray_Init())\r
+        Py_FatalError("Py_Initialize: can't init bytearray");\r
+\r
+    _PyFloat_Init();\r
+\r
+    interp->modules = PyDict_New();\r
+    if (interp->modules == NULL)\r
+        Py_FatalError("Py_Initialize: can't make modules dictionary");\r
+    interp->modules_reloading = PyDict_New();\r
+    if (interp->modules_reloading == NULL)\r
+        Py_FatalError("Py_Initialize: can't make modules_reloading dictionary");\r
+\r
+#ifdef Py_USING_UNICODE\r
+    /* Init Unicode implementation; relies on the codec registry */\r
+    _PyUnicode_Init();\r
+#endif\r
+\r
+    bimod = _PyBuiltin_Init();\r
+    if (bimod == NULL)\r
+        Py_FatalError("Py_Initialize: can't initialize __builtin__");\r
+    interp->builtins = PyModule_GetDict(bimod);\r
+    if (interp->builtins == NULL)\r
+        Py_FatalError("Py_Initialize: can't initialize builtins dict");\r
+    Py_INCREF(interp->builtins);\r
+\r
+    sysmod = _PySys_Init();\r
+    if (sysmod == NULL)\r
+        Py_FatalError("Py_Initialize: can't initialize sys");\r
+    interp->sysdict = PyModule_GetDict(sysmod);\r
+    if (interp->sysdict == NULL)\r
+        Py_FatalError("Py_Initialize: can't initialize sys dict");\r
+    Py_INCREF(interp->sysdict);\r
+    _PyImport_FixupExtension("sys", "sys");\r
+    PySys_SetPath(Py_GetPath());\r
+    PyDict_SetItemString(interp->sysdict, "modules",\r
+                         interp->modules);\r
+\r
+    _PyImport_Init();\r
+\r
+    /* initialize builtin exceptions */\r
+    _PyExc_Init();\r
+    _PyImport_FixupExtension("exceptions", "exceptions");\r
+\r
+    /* phase 2 of builtins */\r
+    _PyImport_FixupExtension("__builtin__", "__builtin__");\r
+\r
+    _PyImportHooks_Init();\r
+\r
+    if (install_sigs)\r
+        initsigs(); /* Signal handling stuff, including initintr() */\r
+\r
+    /* Initialize warnings. */\r
+    _PyWarnings_Init();\r
+    if (PySys_HasWarnOptions()) {\r
+        PyObject *warnings_module = PyImport_ImportModule("warnings");\r
+        if (!warnings_module)\r
+            PyErr_Clear();\r
+        Py_XDECREF(warnings_module);\r
+    }\r
+\r
+    initmain(); /* Module __main__ */\r
+\r
+    /* auto-thread-state API, if available */\r
+#ifdef WITH_THREAD\r
+    _PyGILState_Init(interp, tstate);\r
+#endif /* WITH_THREAD */\r
+\r
+    if (!Py_NoSiteFlag)\r
+        initsite(); /* Module site */\r
+\r
+    if ((p = Py_GETENV("PYTHONIOENCODING")) && *p != '\0') {\r
+        p = icodeset = codeset = strdup(p);\r
+        free_codeset = 1;\r
+        errors = strchr(p, ':');\r
+        if (errors) {\r
+            *errors = '\0';\r
+            errors++;\r
+        }\r
+        overridden = 1;\r
+    }\r
+\r
+#if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)\r
+    /* On Unix, set the file system encoding according to the\r
+       user's preference, if the CODESET names a well-known\r
+       Python codec, and Py_FileSystemDefaultEncoding isn't\r
+       initialized by other means. Also set the encoding of\r
+       stdin and stdout if these are terminals, unless overridden.  */\r
+\r
+    if (!overridden || !Py_FileSystemDefaultEncoding) {\r
+        saved_locale = strdup(setlocale(LC_CTYPE, NULL));\r
+        setlocale(LC_CTYPE, "");\r
+        loc_codeset = nl_langinfo(CODESET);\r
+        if (loc_codeset && *loc_codeset) {\r
+            PyObject *enc = PyCodec_Encoder(loc_codeset);\r
+            if (enc) {\r
+                loc_codeset = strdup(loc_codeset);\r
+                Py_DECREF(enc);\r
+            } else {\r
+                if (PyErr_ExceptionMatches(PyExc_LookupError)) {\r
+                    PyErr_Clear();\r
+                    loc_codeset = NULL;\r
+                } else {\r
+                    PyErr_Print();\r
+                    exit(1);\r
+                }\r
+            }\r
+        } else\r
+            loc_codeset = NULL;\r
+        setlocale(LC_CTYPE, saved_locale);\r
+        free(saved_locale);\r
+\r
+        if (!overridden) {\r
+            codeset = icodeset = loc_codeset;\r
+            free_codeset = 1;\r
+        }\r
+\r
+        /* Initialize Py_FileSystemDefaultEncoding from\r
+           locale even if PYTHONIOENCODING is set. */\r
+        if (!Py_FileSystemDefaultEncoding) {\r
+            Py_FileSystemDefaultEncoding = loc_codeset;\r
+            if (!overridden)\r
+                free_codeset = 0;\r
+        }\r
+    }\r
+#endif\r
+\r
+#ifdef MS_WINDOWS\r
+    if (!overridden) {\r
+        icodeset = ibuf;\r
+        codeset = buf;\r
+        sprintf(ibuf, "cp%d", GetConsoleCP());\r
+        sprintf(buf, "cp%d", GetConsoleOutputCP());\r
+    }\r
+#endif\r
+\r
+    if (codeset) {\r
+        sys_stream = PySys_GetObject("stdin");\r
+        sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");\r
+        if (!sys_isatty)\r
+            PyErr_Clear();\r
+        if ((overridden ||\r
+             (sys_isatty && PyObject_IsTrue(sys_isatty))) &&\r
+           PyFile_Check(sys_stream)) {\r
+            if (!PyFile_SetEncodingAndErrors(sys_stream, icodeset, errors))\r
+                Py_FatalError("Cannot set codeset of stdin");\r
+        }\r
+        Py_XDECREF(sys_isatty);\r
+\r
+        sys_stream = PySys_GetObject("stdout");\r
+        sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");\r
+        if (!sys_isatty)\r
+            PyErr_Clear();\r
+        if ((overridden ||\r
+             (sys_isatty && PyObject_IsTrue(sys_isatty))) &&\r
+           PyFile_Check(sys_stream)) {\r
+            if (!PyFile_SetEncodingAndErrors(sys_stream, codeset, errors))\r
+                Py_FatalError("Cannot set codeset of stdout");\r
+        }\r
+        Py_XDECREF(sys_isatty);\r
+\r
+        sys_stream = PySys_GetObject("stderr");\r
+        sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");\r
+        if (!sys_isatty)\r
+            PyErr_Clear();\r
+        if((overridden ||\r
+            (sys_isatty && PyObject_IsTrue(sys_isatty))) &&\r
+           PyFile_Check(sys_stream)) {\r
+            if (!PyFile_SetEncodingAndErrors(sys_stream, codeset, errors))\r
+                Py_FatalError("Cannot set codeset of stderr");\r
+        }\r
+        Py_XDECREF(sys_isatty);\r
+\r
+        if (free_codeset)\r
+            free(codeset);\r
+    }\r
+}\r
+\r
+void\r
+Py_Initialize(void)\r
+{\r
+    Py_InitializeEx(1);\r
+}\r
+\r
+\r
+#ifdef COUNT_ALLOCS\r
+extern void dump_counts(FILE*);\r
+#endif\r
+\r
+/* Undo the effect of Py_Initialize().\r
+\r
+   Beware: if multiple interpreter and/or thread states exist, these\r
+   are not wiped out; only the current thread and interpreter state\r
+   are deleted.  But since everything else is deleted, those other\r
+   interpreter and thread states should no longer be used.\r
+\r
+   (XXX We should do better, e.g. wipe out all interpreters and\r
+   threads.)\r
+\r
+   Locking: as above.\r
+\r
+*/\r
+\r
+void\r
+Py_Finalize(void)\r
+{\r
+    PyInterpreterState *interp;\r
+    PyThreadState *tstate;\r
+\r
+    if (!initialized)\r
+        return;\r
+\r
+    wait_for_thread_shutdown();\r
+\r
+    /* The interpreter is still entirely intact at this point, and the\r
+     * exit funcs may be relying on that.  In particular, if some thread\r
+     * or exit func is still waiting to do an import, the import machinery\r
+     * expects Py_IsInitialized() to return true.  So don't say the\r
+     * interpreter is uninitialized until after the exit funcs have run.\r
+     * Note that Threading.py uses an exit func to do a join on all the\r
+     * threads created thru it, so this also protects pending imports in\r
+     * the threads created via Threading.\r
+     */\r
+    call_sys_exitfunc();\r
+    initialized = 0;\r
+\r
+    /* Get current thread state and interpreter pointer */\r
+    tstate = PyThreadState_GET();\r
+    interp = tstate->interp;\r
+\r
+    /* Disable signal handling */\r
+    PyOS_FiniInterrupts();\r
+\r
+    /* Clear type lookup cache */\r
+    PyType_ClearCache();\r
+\r
+    /* Collect garbage.  This may call finalizers; it's nice to call these\r
+     * before all modules are destroyed.\r
+     * XXX If a __del__ or weakref callback is triggered here, and tries to\r
+     * XXX import a module, bad things can happen, because Python no\r
+     * XXX longer believes it's initialized.\r
+     * XXX     Fatal Python error: Interpreter not initialized (version mismatch?)\r
+     * XXX is easy to provoke that way.  I've also seen, e.g.,\r
+     * XXX     Exception exceptions.ImportError: 'No module named sha'\r
+     * XXX         in <function callback at 0x008F5718> ignored\r
+     * XXX but I'm unclear on exactly how that one happens.  In any case,\r
+     * XXX I haven't seen a real-life report of either of these.\r
+     */\r
+    PyGC_Collect();\r
+#ifdef COUNT_ALLOCS\r
+    /* With COUNT_ALLOCS, it helps to run GC multiple times:\r
+       each collection might release some types from the type\r
+       list, so they become garbage. */\r
+    while (PyGC_Collect() > 0)\r
+        /* nothing */;\r
+#endif\r
+\r
+    /* Destroy all modules */\r
+    PyImport_Cleanup();\r
+\r
+    /* Collect final garbage.  This disposes of cycles created by\r
+     * new-style class definitions, for example.\r
+     * XXX This is disabled because it caused too many problems.  If\r
+     * XXX a __del__ or weakref callback triggers here, Python code has\r
+     * XXX a hard time running, because even the sys module has been\r
+     * XXX cleared out (sys.stdout is gone, sys.excepthook is gone, etc).\r
+     * XXX One symptom is a sequence of information-free messages\r
+     * XXX coming from threads (if a __del__ or callback is invoked,\r
+     * XXX other threads can execute too, and any exception they encounter\r
+     * XXX triggers a comedy of errors as subsystem after subsystem\r
+     * XXX fails to find what it *expects* to find in sys to help report\r
+     * XXX the exception and consequent unexpected failures).  I've also\r
+     * XXX seen segfaults then, after adding print statements to the\r
+     * XXX Python code getting called.\r
+     */\r
+#if 0\r
+    PyGC_Collect();\r
+#endif\r
+\r
+    /* Destroy the database used by _PyImport_{Fixup,Find}Extension */\r
+    _PyImport_Fini();\r
+\r
+    /* Debugging stuff */\r
+#ifdef COUNT_ALLOCS\r
+    dump_counts(stdout);\r
+#endif\r
+\r
+    PRINT_TOTAL_REFS();\r
+\r
+#ifdef Py_TRACE_REFS\r
+    /* Display all objects still alive -- this can invoke arbitrary\r
+     * __repr__ overrides, so requires a mostly-intact interpreter.\r
+     * Alas, a lot of stuff may still be alive now that will be cleaned\r
+     * up later.\r
+     */\r
+    if (Py_GETENV("PYTHONDUMPREFS"))\r
+        _Py_PrintReferences(stderr);\r
+#endif /* Py_TRACE_REFS */\r
+\r
+    /* Clear interpreter state */\r
+    PyInterpreterState_Clear(interp);\r
+\r
+    /* Now we decref the exception classes.  After this point nothing\r
+       can raise an exception.  That's okay, because each Fini() method\r
+       below has been checked to make sure no exceptions are ever\r
+       raised.\r
+    */\r
+\r
+    _PyExc_Fini();\r
+\r
+    /* Cleanup auto-thread-state */\r
+#ifdef WITH_THREAD\r
+    _PyGILState_Fini();\r
+#endif /* WITH_THREAD */\r
+\r
+    /* Delete current thread */\r
+    PyThreadState_Swap(NULL);\r
+    PyInterpreterState_Delete(interp);\r
+\r
+    /* Sundry finalizers */\r
+    PyMethod_Fini();\r
+    PyFrame_Fini();\r
+    PyCFunction_Fini();\r
+    PyTuple_Fini();\r
+    PyList_Fini();\r
+    PySet_Fini();\r
+    PyString_Fini();\r
+    PyByteArray_Fini();\r
+    PyInt_Fini();\r
+    PyFloat_Fini();\r
+    PyDict_Fini();\r
+    _PyRandom_Fini();\r
+\r
+#ifdef Py_USING_UNICODE\r
+    /* Cleanup Unicode implementation */\r
+    _PyUnicode_Fini();\r
+#endif\r
+\r
+    /* XXX Still allocated:\r
+       - various static ad-hoc pointers to interned strings\r
+       - int and float free list blocks\r
+       - whatever various modules and libraries allocate\r
+    */\r
+\r
+    PyGrammar_RemoveAccelerators(&_PyParser_Grammar);\r
+\r
+#ifdef Py_TRACE_REFS\r
+    /* Display addresses (& refcnts) of all objects still alive.\r
+     * An address can be used to find the repr of the object, printed\r
+     * above by _Py_PrintReferences.\r
+     */\r
+    if (Py_GETENV("PYTHONDUMPREFS"))\r
+        _Py_PrintReferenceAddresses(stderr);\r
+#endif /* Py_TRACE_REFS */\r
+#ifdef PYMALLOC_DEBUG\r
+    if (Py_GETENV("PYTHONMALLOCSTATS"))\r
+        _PyObject_DebugMallocStats();\r
+#endif\r
+\r
+    call_ll_exitfuncs();\r
+}\r
+\r
+/* Create and initialize a new interpreter and thread, and return the\r
+   new thread.  This requires that Py_Initialize() has been called\r
+   first.\r
+\r
+   Unsuccessful initialization yields a NULL pointer.  Note that *no*\r
+   exception information is available even in this case -- the\r
+   exception information is held in the thread, and there is no\r
+   thread.\r
+\r
+   Locking: as above.\r
+\r
+*/\r
+\r
+PyThreadState *\r
+Py_NewInterpreter(void)\r
+{\r
+    PyInterpreterState *interp;\r
+    PyThreadState *tstate, *save_tstate;\r
+    PyObject *bimod, *sysmod;\r
+\r
+    if (!initialized)\r
+        Py_FatalError("Py_NewInterpreter: call Py_Initialize first");\r
+\r
+    interp = PyInterpreterState_New();\r
+    if (interp == NULL)\r
+        return NULL;\r
+\r
+    tstate = PyThreadState_New(interp);\r
+    if (tstate == NULL) {\r
+        PyInterpreterState_Delete(interp);\r
+        return NULL;\r
+    }\r
+\r
+    save_tstate = PyThreadState_Swap(tstate);\r
+\r
+    /* XXX The following is lax in error checking */\r
+\r
+    interp->modules = PyDict_New();\r
+    interp->modules_reloading = PyDict_New();\r
+\r
+    bimod = _PyImport_FindExtension("__builtin__", "__builtin__");\r
+    if (bimod != NULL) {\r
+        interp->builtins = PyModule_GetDict(bimod);\r
+        if (interp->builtins == NULL)\r
+            goto handle_error;\r
+        Py_INCREF(interp->builtins);\r
+    }\r
+    sysmod = _PyImport_FindExtension("sys", "sys");\r
+    if (bimod != NULL && sysmod != NULL) {\r
+        interp->sysdict = PyModule_GetDict(sysmod);\r
+        if (interp->sysdict == NULL)\r
+            goto handle_error;\r
+        Py_INCREF(interp->sysdict);\r
+        PySys_SetPath(Py_GetPath());\r
+        PyDict_SetItemString(interp->sysdict, "modules",\r
+                             interp->modules);\r
+        _PyImportHooks_Init();\r
+        initmain();\r
+        if (!Py_NoSiteFlag)\r
+            initsite();\r
+    }\r
+\r
+    if (!PyErr_Occurred())\r
+        return tstate;\r
+\r
+handle_error:\r
+    /* Oops, it didn't work.  Undo it all. */\r
+\r
+    PyErr_Print();\r
+    PyThreadState_Clear(tstate);\r
+    PyThreadState_Swap(save_tstate);\r
+    PyThreadState_Delete(tstate);\r
+    PyInterpreterState_Delete(interp);\r
+\r
+    return NULL;\r
+}\r
+\r
+/* Delete an interpreter and its last thread.  This requires that the\r
+   given thread state is current, that the thread has no remaining\r
+   frames, and that it is its interpreter's only remaining thread.\r
+   It is a fatal error to violate these constraints.\r
+\r
+   (Py_Finalize() doesn't have these constraints -- it zaps\r
+   everything, regardless.)\r
+\r
+   Locking: as above.\r
+\r
+*/\r
+\r
+void\r
+Py_EndInterpreter(PyThreadState *tstate)\r
+{\r
+    PyInterpreterState *interp = tstate->interp;\r
+\r
+    if (tstate != PyThreadState_GET())\r
+        Py_FatalError("Py_EndInterpreter: thread is not current");\r
+    if (tstate->frame != NULL)\r
+        Py_FatalError("Py_EndInterpreter: thread still has a frame");\r
+    if (tstate != interp->tstate_head || tstate->next != NULL)\r
+        Py_FatalError("Py_EndInterpreter: not the last thread");\r
+\r
+    PyImport_Cleanup();\r
+    PyInterpreterState_Clear(interp);\r
+    PyThreadState_Swap(NULL);\r
+    PyInterpreterState_Delete(interp);\r
+}\r
+\r
+static char *progname = "python";\r
+\r
+void\r
+Py_SetProgramName(char *pn)\r
+{\r
+    if (pn && *pn)\r
+        progname = pn;\r
+}\r
+\r
+char *\r
+Py_GetProgramName(void)\r
+{\r
+    return progname;\r
+}\r
+\r
+static char *default_home = NULL;\r
+\r
+void\r
+Py_SetPythonHome(char *home)\r
+{\r
+    default_home = home;\r
+}\r
+\r
+char *\r
+Py_GetPythonHome(void)\r
+{\r
+    char *home = default_home;\r
+    if (home == NULL && !Py_IgnoreEnvironmentFlag)\r
+        home = Py_GETENV("PYTHONHOME");\r
+    return home;\r
+}\r
+\r
+/* Create __main__ module */\r
+\r
+static void\r
+initmain(void)\r
+{\r
+    PyObject *m, *d;\r
+    m = PyImport_AddModule("__main__");\r
+    if (m == NULL)\r
+        Py_FatalError("can't create __main__ module");\r
+    d = PyModule_GetDict(m);\r
+    if (PyDict_GetItemString(d, "__builtins__") == NULL) {\r
+        PyObject *bimod = PyImport_ImportModule("__builtin__");\r
+        if (bimod == NULL ||\r
+            PyDict_SetItemString(d, "__builtins__", bimod) != 0)\r
+            Py_FatalError("can't add __builtins__ to __main__");\r
+        Py_XDECREF(bimod);\r
+    }\r
+}\r
+\r
+/* Import the site module (not into __main__ though) */\r
+\r
+static void\r
+initsite(void)\r
+{\r
+    PyObject *m;\r
+    m = PyImport_ImportModule("site");\r
+    if (m == NULL) {\r
+        PyErr_Print();\r
+        Py_Finalize();\r
+        exit(1);\r
+    }\r
+    else {\r
+        Py_DECREF(m);\r
+    }\r
+}\r
+\r
+/* Parse input from a file and execute it */\r
+\r
+int\r
+PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit,\r
+                     PyCompilerFlags *flags)\r
+{\r
+    if (filename == NULL)\r
+        filename = "???";\r
+    if (Py_FdIsInteractive(fp, filename)) {\r
+        int err = PyRun_InteractiveLoopFlags(fp, filename, flags);\r
+        if (closeit)\r
+            fclose(fp);\r
+        return err;\r
+    }\r
+    else\r
+        return PyRun_SimpleFileExFlags(fp, filename, closeit, flags);\r
+}\r
+\r
+int\r
+PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)\r
+{\r
+    PyObject *v;\r
+    int ret;\r
+    PyCompilerFlags local_flags;\r
+\r
+    if (flags == NULL) {\r
+        flags = &local_flags;\r
+        local_flags.cf_flags = 0;\r
+    }\r
+    v = PySys_GetObject("ps1");\r
+    if (v == NULL) {\r
+        PySys_SetObject("ps1", v = PyString_FromString(">>> "));\r
+        Py_XDECREF(v);\r
+    }\r
+    v = PySys_GetObject("ps2");\r
+    if (v == NULL) {\r
+        PySys_SetObject("ps2", v = PyString_FromString("... "));\r
+        Py_XDECREF(v);\r
+    }\r
+    for (;;) {\r
+        ret = PyRun_InteractiveOneFlags(fp, filename, flags);\r
+        PRINT_TOTAL_REFS();\r
+        if (ret == E_EOF)\r
+            return 0;\r
+        /*\r
+        if (ret == E_NOMEM)\r
+            return -1;\r
+        */\r
+    }\r
+}\r
+\r
+#if 0\r
+/* compute parser flags based on compiler flags */\r
+#define PARSER_FLAGS(flags) \\r
+    ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \\r
+                  PyPARSE_DONT_IMPLY_DEDENT : 0)) : 0)\r
+#endif\r
+#if 1\r
+/* Keep an example of flags with future keyword support. */\r
+#define PARSER_FLAGS(flags) \\r
+    ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \\r
+                  PyPARSE_DONT_IMPLY_DEDENT : 0) \\r
+                | (((flags)->cf_flags & CO_FUTURE_PRINT_FUNCTION) ? \\r
+                   PyPARSE_PRINT_IS_FUNCTION : 0) \\r
+                | (((flags)->cf_flags & CO_FUTURE_UNICODE_LITERALS) ? \\r
+                   PyPARSE_UNICODE_LITERALS : 0) \\r
+                ) : 0)\r
+#endif\r
+\r
+int\r
+PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)\r
+{\r
+    PyObject *m, *d, *v, *w;\r
+    mod_ty mod;\r
+    PyArena *arena;\r
+    char *ps1 = "", *ps2 = "";\r
+    int errcode = 0;\r
+\r
+    v = PySys_GetObject("ps1");\r
+    if (v != NULL) {\r
+        v = PyObject_Str(v);\r
+        if (v == NULL)\r
+            PyErr_Clear();\r
+        else if (PyString_Check(v))\r
+            ps1 = PyString_AsString(v);\r
+    }\r
+    w = PySys_GetObject("ps2");\r
+    if (w != NULL) {\r
+        w = PyObject_Str(w);\r
+        if (w == NULL)\r
+            PyErr_Clear();\r
+        else if (PyString_Check(w))\r
+            ps2 = PyString_AsString(w);\r
+    }\r
+    arena = PyArena_New();\r
+    if (arena == NULL) {\r
+        Py_XDECREF(v);\r
+        Py_XDECREF(w);\r
+        return -1;\r
+    }\r
+    mod = PyParser_ASTFromFile(fp, filename,\r
+                               Py_single_input, ps1, ps2,\r
+                               flags, &errcode, arena);\r
+    Py_XDECREF(v);\r
+    Py_XDECREF(w);\r
+    if (mod == NULL) {\r
+        PyArena_Free(arena);\r
+        if (errcode == E_EOF) {\r
+            PyErr_Clear();\r
+            return E_EOF;\r
+        }\r
+        PyErr_Print();\r
+        return -1;\r
+    }\r
+    m = PyImport_AddModule("__main__");\r
+    if (m == NULL) {\r
+        PyArena_Free(arena);\r
+        return -1;\r
+    }\r
+    d = PyModule_GetDict(m);\r
+    v = run_mod(mod, filename, d, d, flags, arena);\r
+    PyArena_Free(arena);\r
+    if (v == NULL) {\r
+        PyErr_Print();\r
+        return -1;\r
+    }\r
+    Py_DECREF(v);\r
+    if (Py_FlushLine())\r
+        PyErr_Clear();\r
+    return 0;\r
+}\r
+\r
+/* Check whether a file maybe a pyc file: Look at the extension,\r
+   the file type, and, if we may close it, at the first few bytes. */\r
+\r
+static int\r
+maybe_pyc_file(FILE *fp, const char* filename, const char* ext, int closeit)\r
+{\r
+    if (strcmp(ext, ".pyc") == 0 || strcmp(ext, ".pyo") == 0)\r
+        return 1;\r
+\r
+    /* Only look into the file if we are allowed to close it, since\r
+       it then should also be seekable. */\r
+    if (closeit) {\r
+        /* Read only two bytes of the magic. If the file was opened in\r
+           text mode, the bytes 3 and 4 of the magic (\r\n) might not\r
+           be read as they are on disk. */\r
+        unsigned int halfmagic = PyImport_GetMagicNumber() & 0xFFFF;\r
+        unsigned char buf[2];\r
+        /* Mess:  In case of -x, the stream is NOT at its start now,\r
+           and ungetc() was used to push back the first newline,\r
+           which makes the current stream position formally undefined,\r
+           and a x-platform nightmare.\r
+           Unfortunately, we have no direct way to know whether -x\r
+           was specified.  So we use a terrible hack:  if the current\r
+           stream position is not 0, we assume -x was specified, and\r
+           give up.  Bug 132850 on SourceForge spells out the\r
+           hopelessness of trying anything else (fseek and ftell\r
+           don't work predictably x-platform for text-mode files).\r
+        */\r
+        int ispyc = 0;\r
+        if (ftell(fp) == 0) {\r
+            if (fread(buf, 1, 2, fp) == 2 &&\r
+                ((unsigned int)buf[1]<<8 | buf[0]) == halfmagic)\r
+                ispyc = 1;\r
+            rewind(fp);\r
+        }\r
+        return ispyc;\r
+    }\r
+    return 0;\r
+}\r
+\r
+int\r
+PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,\r
+                        PyCompilerFlags *flags)\r
+{\r
+    PyObject *m, *d, *v;\r
+    const char *ext;\r
+    int set_file_name = 0, len, ret = -1;\r
+\r
+    m = PyImport_AddModule("__main__");\r
+    if (m == NULL)\r
+        return -1;\r
+    Py_INCREF(m);\r
+    d = PyModule_GetDict(m);\r
+    if (PyDict_GetItemString(d, "__file__") == NULL) {\r
+        PyObject *f = PyString_FromString(filename);\r
+        if (f == NULL)\r
+            goto done;\r
+        if (PyDict_SetItemString(d, "__file__", f) < 0) {\r
+            Py_DECREF(f);\r
+            goto done;\r
+        }\r
+        set_file_name = 1;\r
+        Py_DECREF(f);\r
+    }\r
+    len = strlen(filename);\r
+    ext = filename + len - (len > 4 ? 4 : 0);\r
+    if (maybe_pyc_file(fp, filename, ext, closeit)) {\r
+        /* Try to run a pyc file. First, re-open in binary */\r
+        if (closeit)\r
+            fclose(fp);\r
+        if ((fp = fopen(filename, "rb")) == NULL) {\r
+            fprintf(stderr, "python: Can't reopen .pyc file\n");\r
+            goto done;\r
+        }\r
+        /* Turn on optimization if a .pyo file is given */\r
+        if (strcmp(ext, ".pyo") == 0)\r
+            Py_OptimizeFlag = 1;\r
+        v = run_pyc_file(fp, filename, d, d, flags);\r
+    } else {\r
+        v = PyRun_FileExFlags(fp, filename, Py_file_input, d, d,\r
+                              closeit, flags);\r
+    }\r
+    if (v == NULL) {\r
+        PyErr_Print();\r
+        goto done;\r
+    }\r
+    Py_DECREF(v);\r
+    if (Py_FlushLine())\r
+        PyErr_Clear();\r
+    ret = 0;\r
+  done:\r
+    if (set_file_name && PyDict_DelItemString(d, "__file__"))\r
+        PyErr_Clear();\r
+    Py_DECREF(m);\r
+    return ret;\r
+}\r
+\r
+int\r
+PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags)\r
+{\r
+    PyObject *m, *d, *v;\r
+    m = PyImport_AddModule("__main__");\r
+    if (m == NULL)\r
+        return -1;\r
+    d = PyModule_GetDict(m);\r
+    v = PyRun_StringFlags(command, Py_file_input, d, d, flags);\r
+    if (v == NULL) {\r
+        PyErr_Print();\r
+        return -1;\r
+    }\r
+    Py_DECREF(v);\r
+    if (Py_FlushLine())\r
+        PyErr_Clear();\r
+    return 0;\r
+}\r
+\r
+static int\r
+parse_syntax_error(PyObject *err, PyObject **message, const char **filename,\r
+                   int *lineno, int *offset, const char **text)\r
+{\r
+    long hold;\r
+    PyObject *v;\r
+\r
+    /* old style errors */\r
+    if (PyTuple_Check(err))\r
+        return PyArg_ParseTuple(err, "O(ziiz)", message, filename,\r
+                                lineno, offset, text);\r
+\r
+    *message = NULL;\r
+\r
+    /* new style errors.  `err' is an instance */\r
+    *message = PyObject_GetAttrString(err, "msg");\r
+    if (!*message)\r
+        goto finally;\r
+\r
+    v = PyObject_GetAttrString(err, "filename");\r
+    if (!v)\r
+        goto finally;\r
+    if (v == Py_None) {\r
+        Py_DECREF(v);\r
+        *filename = NULL;\r
+    }\r
+    else {\r
+        *filename = PyString_AsString(v);\r
+        Py_DECREF(v);\r
+        if (!*filename)\r
+            goto finally;\r
+    }\r
+\r
+    v = PyObject_GetAttrString(err, "lineno");\r
+    if (!v)\r
+        goto finally;\r
+    hold = PyInt_AsLong(v);\r
+    Py_DECREF(v);\r
+    if (hold < 0 && PyErr_Occurred())\r
+        goto finally;\r
+    *lineno = (int)hold;\r
+\r
+    v = PyObject_GetAttrString(err, "offset");\r
+    if (!v)\r
+        goto finally;\r
+    if (v == Py_None) {\r
+        *offset = -1;\r
+        Py_DECREF(v);\r
+    } else {\r
+        hold = PyInt_AsLong(v);\r
+        Py_DECREF(v);\r
+        if (hold < 0 && PyErr_Occurred())\r
+            goto finally;\r
+        *offset = (int)hold;\r
+    }\r
+\r
+    v = PyObject_GetAttrString(err, "text");\r
+    if (!v)\r
+        goto finally;\r
+    if (v == Py_None) {\r
+        Py_DECREF(v);\r
+        *text = NULL;\r
+    }\r
+    else {\r
+        *text = PyString_AsString(v);\r
+        Py_DECREF(v);\r
+        if (!*text)\r
+            goto finally;\r
+    }\r
+    return 1;\r
+\r
+finally:\r
+    Py_XDECREF(*message);\r
+    return 0;\r
+}\r
+\r
+void\r
+PyErr_Print(void)\r
+{\r
+    PyErr_PrintEx(1);\r
+}\r
+\r
+static void\r
+print_error_text(PyObject *f, int offset, const char *text)\r
+{\r
+    char *nl;\r
+    if (offset >= 0) {\r
+        if (offset > 0 && offset == strlen(text) && text[offset - 1] == '\n')\r
+            offset--;\r
+        for (;;) {\r
+            nl = strchr(text, '\n');\r
+            if (nl == NULL || nl-text >= offset)\r
+                break;\r
+            offset -= (int)(nl+1-text);\r
+            text = nl+1;\r
+        }\r
+        while (*text == ' ' || *text == '\t') {\r
+            text++;\r
+            offset--;\r
+        }\r
+    }\r
+    PyFile_WriteString("    ", f);\r
+    PyFile_WriteString(text, f);\r
+    if (*text == '\0' || text[strlen(text)-1] != '\n')\r
+        PyFile_WriteString("\n", f);\r
+    if (offset == -1)\r
+        return;\r
+    PyFile_WriteString("    ", f);\r
+    offset--;\r
+    while (offset > 0) {\r
+        PyFile_WriteString(" ", f);\r
+        offset--;\r
+    }\r
+    PyFile_WriteString("^\n", f);\r
+}\r
+\r
+static void\r
+handle_system_exit(void)\r
+{\r
+    PyObject *exception, *value, *tb;\r
+    int exitcode = 0;\r
+\r
+    if (Py_InspectFlag)\r
+        /* Don't exit if -i flag was given. This flag is set to 0\r
+         * when entering interactive mode for inspecting. */\r
+        return;\r
+\r
+    PyErr_Fetch(&exception, &value, &tb);\r
+    if (Py_FlushLine())\r
+        PyErr_Clear();\r
+    fflush(stdout);\r
+    if (value == NULL || value == Py_None)\r
+        goto done;\r
+    if (PyExceptionInstance_Check(value)) {\r
+        /* The error code should be in the `code' attribute. */\r
+        PyObject *code = PyObject_GetAttrString(value, "code");\r
+        if (code) {\r
+            Py_DECREF(value);\r
+            value = code;\r
+            if (value == Py_None)\r
+                goto done;\r
+        }\r
+        /* If we failed to dig out the 'code' attribute,\r
+           just let the else clause below print the error. */\r
+    }\r
+    if (PyInt_Check(value))\r
+        exitcode = (int)PyInt_AsLong(value);\r
+    else {\r
+        PyObject *sys_stderr = PySys_GetObject("stderr");\r
+        if (sys_stderr != NULL && sys_stderr != Py_None) {\r
+            PyFile_WriteObject(value, sys_stderr, Py_PRINT_RAW);\r
+        } else {\r
+            PyObject_Print(value, stderr, Py_PRINT_RAW);\r
+            fflush(stderr);\r
+        }\r
+        PySys_WriteStderr("\n");\r
+        exitcode = 1;\r
+    }\r
+ done:\r
+    /* Restore and clear the exception info, in order to properly decref\r
+     * the exception, value, and traceback.      If we just exit instead,\r
+     * these leak, which confuses PYTHONDUMPREFS output, and may prevent\r
+     * some finalizers from running.\r
+     */\r
+    PyErr_Restore(exception, value, tb);\r
+    PyErr_Clear();\r
+    Py_Exit(exitcode);\r
+    /* NOTREACHED */\r
+}\r
+\r
+void\r
+PyErr_PrintEx(int set_sys_last_vars)\r
+{\r
+    PyObject *exception, *v, *tb, *hook;\r
+\r
+    if (PyErr_ExceptionMatches(PyExc_SystemExit)) {\r
+        handle_system_exit();\r
+    }\r
+    PyErr_Fetch(&exception, &v, &tb);\r
+    if (exception == NULL)\r
+        return;\r
+    PyErr_NormalizeException(&exception, &v, &tb);\r
+    if (exception == NULL)\r
+        return;\r
+    /* Now we know v != NULL too */\r
+    if (set_sys_last_vars) {\r
+        PySys_SetObject("last_type", exception);\r
+        PySys_SetObject("last_value", v);\r
+        PySys_SetObject("last_traceback", tb);\r
+    }\r
+    hook = PySys_GetObject("excepthook");\r
+    if (hook && hook != Py_None) {\r
+        PyObject *args = PyTuple_Pack(3,\r
+            exception, v, tb ? tb : Py_None);\r
+        PyObject *result = PyEval_CallObject(hook, args);\r
+        if (result == NULL) {\r
+            PyObject *exception2, *v2, *tb2;\r
+            if (PyErr_ExceptionMatches(PyExc_SystemExit)) {\r
+                handle_system_exit();\r
+            }\r
+            PyErr_Fetch(&exception2, &v2, &tb2);\r
+            PyErr_NormalizeException(&exception2, &v2, &tb2);\r
+            /* It should not be possible for exception2 or v2\r
+               to be NULL. However PyErr_Display() can't\r
+               tolerate NULLs, so just be safe. */\r
+            if (exception2 == NULL) {\r
+                exception2 = Py_None;\r
+                Py_INCREF(exception2);\r
+            }\r
+            if (v2 == NULL) {\r
+                v2 = Py_None;\r
+                Py_INCREF(v2);\r
+            }\r
+            if (Py_FlushLine())\r
+                PyErr_Clear();\r
+            fflush(stdout);\r
+            PySys_WriteStderr("Error in sys.excepthook:\n");\r
+            PyErr_Display(exception2, v2, tb2);\r
+            PySys_WriteStderr("\nOriginal exception was:\n");\r
+            PyErr_Display(exception, v, tb);\r
+            Py_DECREF(exception2);\r
+            Py_DECREF(v2);\r
+            Py_XDECREF(tb2);\r
+        }\r
+        Py_XDECREF(result);\r
+        Py_XDECREF(args);\r
+    } else {\r
+        PySys_WriteStderr("sys.excepthook is missing\n");\r
+        PyErr_Display(exception, v, tb);\r
+    }\r
+    Py_XDECREF(exception);\r
+    Py_XDECREF(v);\r
+    Py_XDECREF(tb);\r
+}\r
+\r
+void\r
+PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)\r
+{\r
+    int err = 0;\r
+    PyObject *f = PySys_GetObject("stderr");\r
+    Py_INCREF(value);\r
+    if (f == NULL || f == Py_None)\r
+        fprintf(stderr, "lost sys.stderr\n");\r
+    else {\r
+        if (Py_FlushLine())\r
+            PyErr_Clear();\r
+        fflush(stdout);\r
+        if (tb && tb != Py_None)\r
+            err = PyTraceBack_Print(tb, f);\r
+        if (err == 0 &&\r
+            PyObject_HasAttrString(value, "print_file_and_line"))\r
+        {\r
+            PyObject *message;\r
+            const char *filename, *text;\r
+            int lineno, offset;\r
+            if (!parse_syntax_error(value, &message, &filename,\r
+                                    &lineno, &offset, &text))\r
+                PyErr_Clear();\r
+            else {\r
+                char buf[10];\r
+                PyFile_WriteString("  File \"", f);\r
+                if (filename == NULL)\r
+                    PyFile_WriteString("<string>", f);\r
+                else\r
+                    PyFile_WriteString(filename, f);\r
+                PyFile_WriteString("\", line ", f);\r
+                PyOS_snprintf(buf, sizeof(buf), "%d", lineno);\r
+                PyFile_WriteString(buf, f);\r
+                PyFile_WriteString("\n", f);\r
+                if (text != NULL)\r
+                    print_error_text(f, offset, text);\r
+                Py_DECREF(value);\r
+                value = message;\r
+                /* Can't be bothered to check all those\r
+                   PyFile_WriteString() calls */\r
+                if (PyErr_Occurred())\r
+                    err = -1;\r
+            }\r
+        }\r
+        if (err) {\r
+            /* Don't do anything else */\r
+        }\r
+        else if (PyExceptionClass_Check(exception)) {\r
+            PyObject* moduleName;\r
+            char* className = PyExceptionClass_Name(exception);\r
+            if (className != NULL) {\r
+                char *dot = strrchr(className, '.');\r
+                if (dot != NULL)\r
+                    className = dot+1;\r
+            }\r
+\r
+            moduleName = PyObject_GetAttrString(exception, "__module__");\r
+            if (moduleName == NULL)\r
+                err = PyFile_WriteString("<unknown>", f);\r
+            else {\r
+                char* modstr = PyString_AsString(moduleName);\r
+                if (modstr && strcmp(modstr, "exceptions"))\r
+                {\r
+                    err = PyFile_WriteString(modstr, f);\r
+                    err += PyFile_WriteString(".", f);\r
+                }\r
+                Py_DECREF(moduleName);\r
+            }\r
+            if (err == 0) {\r
+                if (className == NULL)\r
+                      err = PyFile_WriteString("<unknown>", f);\r
+                else\r
+                      err = PyFile_WriteString(className, f);\r
+            }\r
+        }\r
+        else\r
+            err = PyFile_WriteObject(exception, f, Py_PRINT_RAW);\r
+        if (err == 0 && (value != Py_None)) {\r
+            PyObject *s = PyObject_Str(value);\r
+            /* only print colon if the str() of the\r
+               object is not the empty string\r
+            */\r
+            if (s == NULL)\r
+                err = -1;\r
+            else if (!PyString_Check(s) ||\r
+                     PyString_GET_SIZE(s) != 0)\r
+                err = PyFile_WriteString(": ", f);\r
+            if (err == 0)\r
+              err = PyFile_WriteObject(s, f, Py_PRINT_RAW);\r
+            Py_XDECREF(s);\r
+        }\r
+        /* try to write a newline in any case */\r
+        err += PyFile_WriteString("\n", f);\r
+    }\r
+    Py_DECREF(value);\r
+    /* If an error happened here, don't show it.\r
+       XXX This is wrong, but too many callers rely on this behavior. */\r
+    if (err != 0)\r
+        PyErr_Clear();\r
+}\r
+\r
+PyObject *\r
+PyRun_StringFlags(const char *str, int start, PyObject *globals,\r
+                  PyObject *locals, PyCompilerFlags *flags)\r
+{\r
+    PyObject *ret = NULL;\r
+    mod_ty mod;\r
+    PyArena *arena = PyArena_New();\r
+    if (arena == NULL)\r
+        return NULL;\r
+\r
+    mod = PyParser_ASTFromString(str, "<string>", start, flags, arena);\r
+    if (mod != NULL)\r
+        ret = run_mod(mod, "<string>", globals, locals, flags, arena);\r
+    PyArena_Free(arena);\r
+    return ret;\r
+}\r
+\r
+PyObject *\r
+PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals,\r
+                  PyObject *locals, int closeit, PyCompilerFlags *flags)\r
+{\r
+    PyObject *ret;\r
+    mod_ty mod;\r
+    PyArena *arena = PyArena_New();\r
+    if (arena == NULL)\r
+        return NULL;\r
+\r
+    mod = PyParser_ASTFromFile(fp, filename, start, 0, 0,\r
+                               flags, NULL, arena);\r
+    if (closeit)\r
+        fclose(fp);\r
+    if (mod == NULL) {\r
+        PyArena_Free(arena);\r
+        return NULL;\r
+    }\r
+    ret = run_mod(mod, filename, globals, locals, flags, arena);\r
+    PyArena_Free(arena);\r
+    return ret;\r
+}\r
+\r
+static PyObject *\r
+run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals,\r
+         PyCompilerFlags *flags, PyArena *arena)\r
+{\r
+    PyCodeObject *co;\r
+    PyObject *v;\r
+    co = PyAST_Compile(mod, filename, flags, arena);\r
+    if (co == NULL)\r
+        return NULL;\r
+    v = PyEval_EvalCode(co, globals, locals);\r
+    Py_DECREF(co);\r
+    return v;\r
+}\r
+\r
+static PyObject *\r
+run_pyc_file(FILE *fp, const char *filename, PyObject *globals,\r
+             PyObject *locals, PyCompilerFlags *flags)\r
+{\r
+    PyCodeObject *co;\r
+    PyObject *v;\r
+    long magic;\r
+    long PyImport_GetMagicNumber(void);\r
+\r
+    magic = PyMarshal_ReadLongFromFile(fp);\r
+    if (magic != PyImport_GetMagicNumber()) {\r
+        PyErr_SetString(PyExc_RuntimeError,\r
+                   "Bad magic number in .pyc file");\r
+        return NULL;\r
+    }\r
+    (void) PyMarshal_ReadLongFromFile(fp);\r
+    v = PyMarshal_ReadLastObjectFromFile(fp);\r
+    fclose(fp);\r
+    if (v == NULL || !PyCode_Check(v)) {\r
+        Py_XDECREF(v);\r
+        PyErr_SetString(PyExc_RuntimeError,\r
+                   "Bad code object in .pyc file");\r
+        return NULL;\r
+    }\r
+    co = (PyCodeObject *)v;\r
+    v = PyEval_EvalCode(co, globals, locals);\r
+    if (v && flags)\r
+        flags->cf_flags |= (co->co_flags & PyCF_MASK);\r
+    Py_DECREF(co);\r
+    return v;\r
+}\r
+\r
+PyObject *\r
+Py_CompileStringFlags(const char *str, const char *filename, int start,\r
+                      PyCompilerFlags *flags)\r
+{\r
+    PyCodeObject *co;\r
+    mod_ty mod;\r
+    PyArena *arena = PyArena_New();\r
+    if (arena == NULL)\r
+        return NULL;\r
+\r
+    mod = PyParser_ASTFromString(str, filename, start, flags, arena);\r
+    if (mod == NULL) {\r
+        PyArena_Free(arena);\r
+        return NULL;\r
+    }\r
+    if (flags && (flags->cf_flags & PyCF_ONLY_AST)) {\r
+        PyObject *result = PyAST_mod2obj(mod);\r
+        PyArena_Free(arena);\r
+        return result;\r
+    }\r
+    co = PyAST_Compile(mod, filename, flags, arena);\r
+    PyArena_Free(arena);\r
+    return (PyObject *)co;\r
+}\r
+\r
+struct symtable *\r
+Py_SymtableString(const char *str, const char *filename, int start)\r
+{\r
+    struct symtable *st;\r
+    mod_ty mod;\r
+    PyCompilerFlags flags;\r
+    PyArena *arena = PyArena_New();\r
+    if (arena == NULL)\r
+        return NULL;\r
+\r
+    flags.cf_flags = 0;\r
+\r
+    mod = PyParser_ASTFromString(str, filename, start, &flags, arena);\r
+    if (mod == NULL) {\r
+        PyArena_Free(arena);\r
+        return NULL;\r
+    }\r
+    st = PySymtable_Build(mod, filename, 0);\r
+    PyArena_Free(arena);\r
+    return st;\r
+}\r
+\r
+/* Preferred access to parser is through AST. */\r
+mod_ty\r
+PyParser_ASTFromString(const char *s, const char *filename, int start,\r
+                       PyCompilerFlags *flags, PyArena *arena)\r
+{\r
+    mod_ty mod;\r
+    PyCompilerFlags localflags;\r
+    perrdetail err;\r
+    int iflags = PARSER_FLAGS(flags);\r
+\r
+    node *n = PyParser_ParseStringFlagsFilenameEx(s, filename,\r
+                                    &_PyParser_Grammar, start, &err,\r
+                                    &iflags);\r
+    if (flags == NULL) {\r
+        localflags.cf_flags = 0;\r
+        flags = &localflags;\r
+    }\r
+    if (n) {\r
+        flags->cf_flags |= iflags & PyCF_MASK;\r
+        mod = PyAST_FromNode(n, flags, filename, arena);\r
+        PyNode_Free(n);\r
+        return mod;\r
+    }\r
+    else {\r
+        err_input(&err);\r
+        return NULL;\r
+    }\r
+}\r
+\r
+mod_ty\r
+PyParser_ASTFromFile(FILE *fp, const char *filename, int start, char *ps1,\r
+                     char *ps2, PyCompilerFlags *flags, int *errcode,\r
+                     PyArena *arena)\r
+{\r
+    mod_ty mod;\r
+    PyCompilerFlags localflags;\r
+    perrdetail err;\r
+    int iflags = PARSER_FLAGS(flags);\r
+\r
+    node *n = PyParser_ParseFileFlagsEx(fp, filename, &_PyParser_Grammar,\r
+                            start, ps1, ps2, &err, &iflags);\r
+    if (flags == NULL) {\r
+        localflags.cf_flags = 0;\r
+        flags = &localflags;\r
+    }\r
+    if (n) {\r
+        flags->cf_flags |= iflags & PyCF_MASK;\r
+        mod = PyAST_FromNode(n, flags, filename, arena);\r
+        PyNode_Free(n);\r
+        return mod;\r
+    }\r
+    else {\r
+        err_input(&err);\r
+        if (errcode)\r
+            *errcode = err.error;\r
+        return NULL;\r
+    }\r
+}\r
+\r
+/* Simplified interface to parsefile -- return node or set exception */\r
+\r
+node *\r
+PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int flags)\r
+{\r
+    perrdetail err;\r
+    node *n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar,\r
+                                      start, NULL, NULL, &err, flags);\r
+    if (n == NULL)\r
+        err_input(&err);\r
+\r
+    return n;\r
+}\r
+\r
+/* Simplified interface to parsestring -- return node or set exception */\r
+\r
+node *\r
+PyParser_SimpleParseStringFlags(const char *str, int start, int flags)\r
+{\r
+    perrdetail err;\r
+    node *n = PyParser_ParseStringFlags(str, &_PyParser_Grammar,\r
+                                        start, &err, flags);\r
+    if (n == NULL)\r
+        err_input(&err);\r
+    return n;\r
+}\r
+\r
+node *\r
+PyParser_SimpleParseStringFlagsFilename(const char *str, const char *filename,\r
+                                        int start, int flags)\r
+{\r
+    perrdetail err;\r
+    node *n = PyParser_ParseStringFlagsFilename(str, filename,\r
+                            &_PyParser_Grammar, start, &err, flags);\r
+    if (n == NULL)\r
+        err_input(&err);\r
+    return n;\r
+}\r
+\r
+node *\r
+PyParser_SimpleParseStringFilename(const char *str, const char *filename, int start)\r
+{\r
+    return PyParser_SimpleParseStringFlagsFilename(str, filename, start, 0);\r
+}\r
+\r
+/* May want to move a more generalized form of this to parsetok.c or\r
+   even parser modules. */\r
+\r
+void\r
+PyParser_SetError(perrdetail *err)\r
+{\r
+    err_input(err);\r
+}\r
+\r
+/* Set the error appropriate to the given input error code (see errcode.h) */\r
+\r
+static void\r
+err_input(perrdetail *err)\r
+{\r
+    PyObject *v, *w, *errtype;\r
+    PyObject* u = NULL;\r
+    char *msg = NULL;\r
+    errtype = PyExc_SyntaxError;\r
+    switch (err->error) {\r
+    case E_ERROR:\r
+        return;\r
+    case E_SYNTAX:\r
+        errtype = PyExc_IndentationError;\r
+        if (err->expected == INDENT)\r
+            msg = "expected an indented block";\r
+        else if (err->token == INDENT)\r
+            msg = "unexpected indent";\r
+        else if (err->token == DEDENT)\r
+            msg = "unexpected unindent";\r
+        else {\r
+            errtype = PyExc_SyntaxError;\r
+            msg = "invalid syntax";\r
+        }\r
+        break;\r
+    case E_TOKEN:\r
+        msg = "invalid token";\r
+        break;\r
+    case E_EOFS:\r
+        msg = "EOF while scanning triple-quoted string literal";\r
+        break;\r
+    case E_EOLS:\r
+        msg = "EOL while scanning string literal";\r
+        break;\r
+    case E_INTR:\r
+        if (!PyErr_Occurred())\r
+            PyErr_SetNone(PyExc_KeyboardInterrupt);\r
+        goto cleanup;\r
+    case E_NOMEM:\r
+        PyErr_NoMemory();\r
+        goto cleanup;\r
+    case E_EOF:\r
+        msg = "unexpected EOF while parsing";\r
+        break;\r
+    case E_TABSPACE:\r
+        errtype = PyExc_TabError;\r
+        msg = "inconsistent use of tabs and spaces in indentation";\r
+        break;\r
+    case E_OVERFLOW:\r
+        msg = "expression too long";\r
+        break;\r
+    case E_DEDENT:\r
+        errtype = PyExc_IndentationError;\r
+        msg = "unindent does not match any outer indentation level";\r
+        break;\r
+    case E_TOODEEP:\r
+        errtype = PyExc_IndentationError;\r
+        msg = "too many levels of indentation";\r
+        break;\r
+    case E_DECODE: {\r
+        PyObject *type, *value, *tb;\r
+        PyErr_Fetch(&type, &value, &tb);\r
+        if (value != NULL) {\r
+            u = PyObject_Str(value);\r
+            if (u != NULL) {\r
+                msg = PyString_AsString(u);\r
+            }\r
+        }\r
+        if (msg == NULL)\r
+            msg = "unknown decode error";\r
+        Py_XDECREF(type);\r
+        Py_XDECREF(value);\r
+        Py_XDECREF(tb);\r
+        break;\r
+    }\r
+    case E_LINECONT:\r
+        msg = "unexpected character after line continuation character";\r
+        break;\r
+    default:\r
+        fprintf(stderr, "error=%d\n", err->error);\r
+        msg = "unknown parsing error";\r
+        break;\r
+    }\r
+    v = Py_BuildValue("(ziiz)", err->filename,\r
+                      err->lineno, err->offset, err->text);\r
+    w = NULL;\r
+    if (v != NULL)\r
+        w = Py_BuildValue("(sO)", msg, v);\r
+    Py_XDECREF(u);\r
+    Py_XDECREF(v);\r
+    PyErr_SetObject(errtype, w);\r
+    Py_XDECREF(w);\r
+cleanup:\r
+    if (err->text != NULL) {\r
+        PyObject_FREE(err->text);\r
+        err->text = NULL;\r
+    }\r
+}\r
+\r
+/* Print fatal error message and abort */\r
+\r
+void\r
+Py_FatalError(const char *msg)\r
+{\r
+    fprintf(stderr, "Fatal Python error: %s\n", msg);\r
+    fflush(stderr); /* it helps in Windows debug build */\r
+\r
+#ifdef MS_WINDOWS\r
+    {\r
+        size_t len = strlen(msg);\r
+        WCHAR* buffer;\r
+        size_t i;\r
+\r
+        /* Convert the message to wchar_t. This uses a simple one-to-one\r
+        conversion, assuming that the this error message actually uses ASCII\r
+        only. If this ceases to be true, we will have to convert. */\r
+        buffer = alloca( (len+1) * (sizeof *buffer));\r
+        for( i=0; i<=len; ++i)\r
+            buffer[i] = msg[i];\r
+        OutputDebugStringW(L"Fatal Python error: ");\r
+        OutputDebugStringW(buffer);\r
+        OutputDebugStringW(L"\n");\r
+    }\r
+#ifdef _DEBUG\r
+    DebugBreak();\r
+#endif\r
+#endif /* MS_WINDOWS */\r
+    abort();\r
+}\r
+\r
+/* Clean up and exit */\r
+\r
+#ifdef WITH_THREAD\r
+#include "pythread.h"\r
+#endif\r
+\r
+/* Wait until threading._shutdown completes, provided\r
+   the threading module was imported in the first place.\r
+   The shutdown routine will wait until all non-daemon\r
+   "threading" threads have completed. */\r
+static void\r
+wait_for_thread_shutdown(void)\r
+{\r
+#ifdef WITH_THREAD\r
+    PyObject *result;\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    PyObject *threading = PyMapping_GetItemString(tstate->interp->modules,\r
+                                                  "threading");\r
+    if (threading == NULL) {\r
+        /* threading not imported */\r
+        PyErr_Clear();\r
+        return;\r
+    }\r
+    result = PyObject_CallMethod(threading, "_shutdown", "");\r
+    if (result == NULL)\r
+        PyErr_WriteUnraisable(threading);\r
+    else\r
+        Py_DECREF(result);\r
+    Py_DECREF(threading);\r
+#endif\r
+}\r
+\r
+#define NEXITFUNCS 32\r
+static void (*exitfuncs[NEXITFUNCS])(void);\r
+static int nexitfuncs = 0;\r
+\r
+int Py_AtExit(void (*func)(void))\r
+{\r
+    if (nexitfuncs >= NEXITFUNCS)\r
+        return -1;\r
+    exitfuncs[nexitfuncs++] = func;\r
+    return 0;\r
+}\r
+\r
+static void\r
+call_sys_exitfunc(void)\r
+{\r
+    PyObject *exitfunc = PySys_GetObject("exitfunc");\r
+\r
+    if (exitfunc) {\r
+        PyObject *res;\r
+        Py_INCREF(exitfunc);\r
+        PySys_SetObject("exitfunc", (PyObject *)NULL);\r
+        res = PyEval_CallObject(exitfunc, (PyObject *)NULL);\r
+        if (res == NULL) {\r
+            if (!PyErr_ExceptionMatches(PyExc_SystemExit)) {\r
+                PySys_WriteStderr("Error in sys.exitfunc:\n");\r
+            }\r
+            PyErr_Print();\r
+        }\r
+        Py_DECREF(exitfunc);\r
+    }\r
+\r
+    if (Py_FlushLine())\r
+        PyErr_Clear();\r
+}\r
+\r
+static void\r
+call_ll_exitfuncs(void)\r
+{\r
+    while (nexitfuncs > 0)\r
+        (*exitfuncs[--nexitfuncs])();\r
+\r
+    fflush(stdout);\r
+    fflush(stderr);\r
+}\r
+\r
+void\r
+Py_Exit(int sts)\r
+{\r
+    Py_Finalize();\r
+\r
+    exit(sts);\r
+}\r
+\r
+static void\r
+initsigs(void)\r
+{\r
+#ifdef SIGPIPE\r
+    PyOS_setsig(SIGPIPE, SIG_IGN);\r
+#endif\r
+#ifdef SIGXFZ\r
+    PyOS_setsig(SIGXFZ, SIG_IGN);\r
+#endif\r
+#ifdef SIGXFSZ\r
+    PyOS_setsig(SIGXFSZ, SIG_IGN);\r
+#endif\r
+    PyOS_InitInterrupts(); /* May imply initsignal() */\r
+}\r
+\r
+\r
+/*\r
+ * The file descriptor fd is considered ``interactive'' if either\r
+ *   a) isatty(fd) is TRUE, or\r
+ *   b) the -i flag was given, and the filename associated with\r
+ *      the descriptor is NULL or "<stdin>" or "???".\r
+ */\r
+int\r
+Py_FdIsInteractive(FILE *fp, const char *filename)\r
+{\r
+    if (isatty((int)fileno(fp)))\r
+        return 1;\r
+    if (!Py_InteractiveFlag)\r
+        return 0;\r
+    return (filename == NULL) ||\r
+           (strcmp(filename, "<stdin>") == 0) ||\r
+           (strcmp(filename, "???") == 0);\r
+}\r
+\r
+\r
+#if defined(USE_STACKCHECK)\r
+#if defined(WIN32) && defined(_MSC_VER)\r
+\r
+/* Stack checking for Microsoft C */\r
+\r
+#include <malloc.h>\r
+#include <excpt.h>\r
+\r
+/*\r
+ * Return non-zero when we run out of memory on the stack; zero otherwise.\r
+ */\r
+int\r
+PyOS_CheckStack(void)\r
+{\r
+    __try {\r
+        /* alloca throws a stack overflow exception if there's\r
+           not enough space left on the stack */\r
+        alloca(PYOS_STACK_MARGIN * sizeof(void*));\r
+        return 0;\r
+    } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW ?\r
+                    EXCEPTION_EXECUTE_HANDLER :\r
+            EXCEPTION_CONTINUE_SEARCH) {\r
+        int errcode = _resetstkoflw();\r
+        if (errcode == 0)\r
+        {\r
+            Py_FatalError("Could not reset the stack!");\r
+        }\r
+    }\r
+    return 1;\r
+}\r
+\r
+#endif /* WIN32 && _MSC_VER */\r
+\r
+/* Alternate implementations can be added here... */\r
+\r
+#endif /* USE_STACKCHECK */\r
+\r
+\r
+/* Wrappers around sigaction() or signal(). */\r
+\r
+PyOS_sighandler_t\r
+PyOS_getsig(int sig)\r
+{\r
+#ifdef HAVE_SIGACTION\r
+    struct sigaction context;\r
+    if (sigaction(sig, NULL, &context) == -1)\r
+        return SIG_ERR;\r
+    return context.sa_handler;\r
+#else\r
+    PyOS_sighandler_t handler;\r
+/* Special signal handling for the secure CRT in Visual Studio 2005 */\r
+#if defined(_MSC_VER) && _MSC_VER >= 1400\r
+    switch (sig) {\r
+    /* Only these signals are valid */\r
+    case SIGINT:\r
+    case SIGILL:\r
+    case SIGFPE:\r
+    case SIGSEGV:\r
+    case SIGTERM:\r
+    case SIGBREAK:\r
+    case SIGABRT:\r
+        break;\r
+    /* Don't call signal() with other values or it will assert */\r
+    default:\r
+        return SIG_ERR;\r
+    }\r
+#endif /* _MSC_VER && _MSC_VER >= 1400 */\r
+    handler = signal(sig, SIG_IGN);\r
+    if (handler != SIG_ERR)\r
+        signal(sig, handler);\r
+    return handler;\r
+#endif\r
+}\r
+\r
+PyOS_sighandler_t\r
+PyOS_setsig(int sig, PyOS_sighandler_t handler)\r
+{\r
+#ifdef HAVE_SIGACTION\r
+    /* Some code in Modules/signalmodule.c depends on sigaction() being\r
+     * used here if HAVE_SIGACTION is defined.  Fix that if this code\r
+     * changes to invalidate that assumption.\r
+     */\r
+    struct sigaction context, ocontext;\r
+    context.sa_handler = handler;\r
+    sigemptyset(&context.sa_mask);\r
+    context.sa_flags = 0;\r
+    if (sigaction(sig, &context, &ocontext) == -1)\r
+        return SIG_ERR;\r
+    return ocontext.sa_handler;\r
+#else\r
+    PyOS_sighandler_t oldhandler;\r
+    oldhandler = signal(sig, handler);\r
+#ifdef HAVE_SIGINTERRUPT\r
+    siginterrupt(sig, 1);\r
+#endif\r
+    return oldhandler;\r
+#endif\r
+}\r
+\r
+/* Deprecated C API functions still provided for binary compatiblity */\r
+\r
+#undef PyParser_SimpleParseFile\r
+PyAPI_FUNC(node *)\r
+PyParser_SimpleParseFile(FILE *fp, const char *filename, int start)\r
+{\r
+    return PyParser_SimpleParseFileFlags(fp, filename, start, 0);\r
+}\r
+\r
+#undef PyParser_SimpleParseString\r
+PyAPI_FUNC(node *)\r
+PyParser_SimpleParseString(const char *str, int start)\r
+{\r
+    return PyParser_SimpleParseStringFlags(str, start, 0);\r
+}\r
+\r
+#undef PyRun_AnyFile\r
+PyAPI_FUNC(int)\r
+PyRun_AnyFile(FILE *fp, const char *name)\r
+{\r
+    return PyRun_AnyFileExFlags(fp, name, 0, NULL);\r
+}\r
+\r
+#undef PyRun_AnyFileEx\r
+PyAPI_FUNC(int)\r
+PyRun_AnyFileEx(FILE *fp, const char *name, int closeit)\r
+{\r
+    return PyRun_AnyFileExFlags(fp, name, closeit, NULL);\r
+}\r
+\r
+#undef PyRun_AnyFileFlags\r
+PyAPI_FUNC(int)\r
+PyRun_AnyFileFlags(FILE *fp, const char *name, PyCompilerFlags *flags)\r
+{\r
+    return PyRun_AnyFileExFlags(fp, name, 0, flags);\r
+}\r
+\r
+#undef PyRun_File\r
+PyAPI_FUNC(PyObject *)\r
+PyRun_File(FILE *fp, const char *p, int s, PyObject *g, PyObject *l)\r
+{\r
+    return PyRun_FileExFlags(fp, p, s, g, l, 0, NULL);\r
+}\r
+\r
+#undef PyRun_FileEx\r
+PyAPI_FUNC(PyObject *)\r
+PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, int c)\r
+{\r
+    return PyRun_FileExFlags(fp, p, s, g, l, c, NULL);\r
+}\r
+\r
+#undef PyRun_FileFlags\r
+PyAPI_FUNC(PyObject *)\r
+PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l,\r
+                PyCompilerFlags *flags)\r
+{\r
+    return PyRun_FileExFlags(fp, p, s, g, l, 0, flags);\r
+}\r
+\r
+#undef PyRun_SimpleFile\r
+PyAPI_FUNC(int)\r
+PyRun_SimpleFile(FILE *f, const char *p)\r
+{\r
+    return PyRun_SimpleFileExFlags(f, p, 0, NULL);\r
+}\r
+\r
+#undef PyRun_SimpleFileEx\r
+PyAPI_FUNC(int)\r
+PyRun_SimpleFileEx(FILE *f, const char *p, int c)\r
+{\r
+    return PyRun_SimpleFileExFlags(f, p, c, NULL);\r
+}\r
+\r
+\r
+#undef PyRun_String\r
+PyAPI_FUNC(PyObject *)\r
+PyRun_String(const char *str, int s, PyObject *g, PyObject *l)\r
+{\r
+    return PyRun_StringFlags(str, s, g, l, NULL);\r
+}\r
+\r
+#undef PyRun_SimpleString\r
+PyAPI_FUNC(int)\r
+PyRun_SimpleString(const char *s)\r
+{\r
+    return PyRun_SimpleStringFlags(s, NULL);\r
+}\r
+\r
+#undef Py_CompileString\r
+PyAPI_FUNC(PyObject *)\r
+Py_CompileString(const char *str, const char *p, int s)\r
+{\r
+    return Py_CompileStringFlags(str, p, s, NULL);\r
+}\r
+\r
+#undef PyRun_InteractiveOne\r
+PyAPI_FUNC(int)\r
+PyRun_InteractiveOne(FILE *f, const char *p)\r
+{\r
+    return PyRun_InteractiveOneFlags(f, p, NULL);\r
+}\r
+\r
+#undef PyRun_InteractiveLoop\r
+PyAPI_FUNC(int)\r
+PyRun_InteractiveLoop(FILE *f, const char *p)\r
+{\r
+    return PyRun_InteractiveLoopFlags(f, p, NULL);\r
+}\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/structmember.c b/AppPkg/Applications/Python/Python-2.7.10/Python/structmember.c
new file mode 100644 (file)
index 0000000..ce018c7
--- /dev/null
@@ -0,0 +1,363 @@
+\r
+/* Map C struct members to Python object attributes */\r
+\r
+#include "Python.h"\r
+\r
+#include "structmember.h"\r
+\r
+static PyObject *\r
+listmembers(struct memberlist *mlist)\r
+{\r
+    int i, n;\r
+    PyObject *v;\r
+    for (n = 0; mlist[n].name != NULL; n++)\r
+        ;\r
+    v = PyList_New(n);\r
+    if (v != NULL) {\r
+        for (i = 0; i < n; i++)\r
+            PyList_SetItem(v, i,\r
+                           PyString_FromString(mlist[i].name));\r
+        if (PyErr_Occurred()) {\r
+            Py_DECREF(v);\r
+            v = NULL;\r
+        }\r
+        else {\r
+            PyList_Sort(v);\r
+        }\r
+    }\r
+    return v;\r
+}\r
+\r
+PyObject *\r
+PyMember_Get(const char *addr, struct memberlist *mlist, const char *name)\r
+{\r
+    struct memberlist *l;\r
+\r
+    if (strcmp(name, "__members__") == 0)\r
+        return listmembers(mlist);\r
+    for (l = mlist; l->name != NULL; l++) {\r
+        if (strcmp(l->name, name) == 0) {\r
+            PyMemberDef copy;\r
+            copy.name = l->name;\r
+            copy.type = l->type;\r
+            copy.offset = l->offset;\r
+            copy.flags = l->flags;\r
+            copy.doc = NULL;\r
+            return PyMember_GetOne(addr, &copy);\r
+        }\r
+    }\r
+    PyErr_SetString(PyExc_AttributeError, name);\r
+    return NULL;\r
+}\r
+\r
+PyObject *\r
+PyMember_GetOne(const char *addr, PyMemberDef *l)\r
+{\r
+    PyObject *v;\r
+    if ((l->flags & READ_RESTRICTED) &&\r
+        PyEval_GetRestricted()) {\r
+        PyErr_SetString(PyExc_RuntimeError, "restricted attribute");\r
+        return NULL;\r
+    }\r
+    addr += l->offset;\r
+    switch (l->type) {\r
+    case T_BOOL:\r
+        v = PyBool_FromLong(*(char*)addr);\r
+        break;\r
+    case T_BYTE:\r
+        v = PyInt_FromLong(*(char*)addr);\r
+        break;\r
+    case T_UBYTE:\r
+        v = PyLong_FromUnsignedLong(*(unsigned char*)addr);\r
+        break;\r
+    case T_SHORT:\r
+        v = PyInt_FromLong(*(short*)addr);\r
+        break;\r
+    case T_USHORT:\r
+        v = PyLong_FromUnsignedLong(*(unsigned short*)addr);\r
+        break;\r
+    case T_INT:\r
+        v = PyInt_FromLong(*(int*)addr);\r
+        break;\r
+    case T_UINT:\r
+        v = PyLong_FromUnsignedLong(*(unsigned int*)addr);\r
+        break;\r
+    case T_LONG:\r
+        v = PyInt_FromLong(*(long*)addr);\r
+        break;\r
+    case T_ULONG:\r
+        v = PyLong_FromUnsignedLong(*(unsigned long*)addr);\r
+        break;\r
+    case T_PYSSIZET:\r
+        v = PyInt_FromSsize_t(*(Py_ssize_t*)addr);\r
+        break;\r
+    case T_FLOAT:\r
+        v = PyFloat_FromDouble((double)*(float*)addr);\r
+        break;\r
+    case T_DOUBLE:\r
+        v = PyFloat_FromDouble(*(double*)addr);\r
+        break;\r
+    case T_STRING:\r
+        if (*(char**)addr == NULL) {\r
+            Py_INCREF(Py_None);\r
+            v = Py_None;\r
+        }\r
+        else\r
+            v = PyString_FromString(*(char**)addr);\r
+        break;\r
+    case T_STRING_INPLACE:\r
+        v = PyString_FromString((char*)addr);\r
+        break;\r
+    case T_CHAR:\r
+        v = PyString_FromStringAndSize((char*)addr, 1);\r
+        break;\r
+    case T_OBJECT:\r
+        v = *(PyObject **)addr;\r
+        if (v == NULL)\r
+            v = Py_None;\r
+        Py_INCREF(v);\r
+        break;\r
+    case T_OBJECT_EX:\r
+        v = *(PyObject **)addr;\r
+        if (v == NULL)\r
+            PyErr_SetString(PyExc_AttributeError, l->name);\r
+        Py_XINCREF(v);\r
+        break;\r
+#ifdef HAVE_LONG_LONG\r
+    case T_LONGLONG:\r
+        v = PyLong_FromLongLong(*(PY_LONG_LONG *)addr);\r
+        break;\r
+    case T_ULONGLONG:\r
+        v = PyLong_FromUnsignedLongLong(*(unsigned PY_LONG_LONG *)addr);\r
+        break;\r
+#endif /* HAVE_LONG_LONG */\r
+    default:\r
+        PyErr_SetString(PyExc_SystemError, "bad memberdescr type");\r
+        v = NULL;\r
+    }\r
+    return v;\r
+}\r
+\r
+int\r
+PyMember_Set(char *addr, struct memberlist *mlist, const char *name, PyObject *v)\r
+{\r
+    struct memberlist *l;\r
+\r
+    for (l = mlist; l->name != NULL; l++) {\r
+        if (strcmp(l->name, name) == 0) {\r
+            PyMemberDef copy;\r
+            copy.name = l->name;\r
+            copy.type = l->type;\r
+            copy.offset = l->offset;\r
+            copy.flags = l->flags;\r
+            copy.doc = NULL;\r
+            return PyMember_SetOne(addr, &copy, v);\r
+        }\r
+    }\r
+\r
+    PyErr_SetString(PyExc_AttributeError, name);\r
+    return -1;\r
+}\r
+\r
+#define WARN(msg)                                       \\r
+    do {                                                \\r
+    if (PyErr_Warn(PyExc_RuntimeWarning, msg) < 0)      \\r
+        return -1;                                      \\r
+    } while (0)\r
+\r
+int\r
+PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)\r
+{\r
+    PyObject *oldv;\r
+\r
+    addr += l->offset;\r
+\r
+    if ((l->flags & READONLY))\r
+    {\r
+        PyErr_SetString(PyExc_TypeError, "readonly attribute");\r
+        return -1;\r
+    }\r
+    if ((l->flags & PY_WRITE_RESTRICTED) && PyEval_GetRestricted()) {\r
+        PyErr_SetString(PyExc_RuntimeError, "restricted attribute");\r
+        return -1;\r
+    }\r
+    if (v == NULL) {\r
+        if (l->type == T_OBJECT_EX) {\r
+            /* Check if the attribute is set. */\r
+            if (*(PyObject **)addr == NULL) {\r
+                PyErr_SetString(PyExc_AttributeError, l->name);\r
+                return -1;\r
+            }\r
+        }\r
+        else if (l->type != T_OBJECT) {\r
+            PyErr_SetString(PyExc_TypeError,\r
+                            "can't delete numeric/char attribute");\r
+            return -1;\r
+        }\r
+    }\r
+    switch (l->type) {\r
+    case T_BOOL:{\r
+        if (!PyBool_Check(v)) {\r
+            PyErr_SetString(PyExc_TypeError,\r
+                            "attribute value type must be bool");\r
+            return -1;\r
+        }\r
+        if (v == Py_True)\r
+            *(char*)addr = (char) 1;\r
+        else\r
+            *(char*)addr = (char) 0;\r
+        break;\r
+        }\r
+    case T_BYTE:{\r
+        long long_val = PyInt_AsLong(v);\r
+        if ((long_val == -1) && PyErr_Occurred())\r
+            return -1;\r
+        *(char*)addr = (char)long_val;\r
+        /* XXX: For compatibility, only warn about truncations\r
+           for now. */\r
+        if ((long_val > CHAR_MAX) || (long_val < CHAR_MIN))\r
+            WARN("Truncation of value to char");\r
+        break;\r
+        }\r
+    case T_UBYTE:{\r
+        long long_val = PyInt_AsLong(v);\r
+        if ((long_val == -1) && PyErr_Occurred())\r
+            return -1;\r
+        *(unsigned char*)addr = (unsigned char)long_val;\r
+        if ((long_val > UCHAR_MAX) || (long_val < 0))\r
+            WARN("Truncation of value to unsigned char");\r
+        break;\r
+        }\r
+    case T_SHORT:{\r
+        long long_val = PyInt_AsLong(v);\r
+        if ((long_val == -1) && PyErr_Occurred())\r
+            return -1;\r
+        *(short*)addr = (short)long_val;\r
+        if ((long_val > SHRT_MAX) || (long_val < SHRT_MIN))\r
+            WARN("Truncation of value to short");\r
+        break;\r
+        }\r
+    case T_USHORT:{\r
+        long long_val = PyInt_AsLong(v);\r
+        if ((long_val == -1) && PyErr_Occurred())\r
+            return -1;\r
+        *(unsigned short*)addr = (unsigned short)long_val;\r
+        if ((long_val > USHRT_MAX) || (long_val < 0))\r
+            WARN("Truncation of value to unsigned short");\r
+        break;\r
+        }\r
+    case T_INT:{\r
+        long long_val = PyInt_AsLong(v);\r
+        if ((long_val == -1) && PyErr_Occurred())\r
+            return -1;\r
+        *(int *)addr = (int)long_val;\r
+        if ((long_val > INT_MAX) || (long_val < INT_MIN))\r
+            WARN("Truncation of value to int");\r
+        break;\r
+        }\r
+    case T_UINT:{\r
+        unsigned long ulong_val = PyLong_AsUnsignedLong(v);\r
+        if ((ulong_val == (unsigned long)-1) && PyErr_Occurred()) {\r
+            /* XXX: For compatibility, accept negative int values\r
+               as well. */\r
+            PyErr_Clear();\r
+            ulong_val = PyLong_AsLong(v);\r
+            if ((ulong_val == (unsigned long)-1) &&\r
+                PyErr_Occurred())\r
+                return -1;\r
+            *(unsigned int *)addr = (unsigned int)ulong_val;\r
+            WARN("Writing negative value into unsigned field");\r
+        } else\r
+            *(unsigned int *)addr = (unsigned int)ulong_val;\r
+        if (ulong_val > UINT_MAX)\r
+            WARN("Truncation of value to unsigned int");\r
+        break;\r
+        }\r
+    case T_LONG:{\r
+        *(long*)addr = PyLong_AsLong(v);\r
+        if ((*(long*)addr == -1) && PyErr_Occurred())\r
+            return -1;\r
+        break;\r
+        }\r
+    case T_ULONG:{\r
+        *(unsigned long*)addr = PyLong_AsUnsignedLong(v);\r
+        if ((*(unsigned long*)addr == (unsigned long)-1)\r
+            && PyErr_Occurred()) {\r
+            /* XXX: For compatibility, accept negative int values\r
+               as well. */\r
+            PyErr_Clear();\r
+            *(unsigned long*)addr = PyLong_AsLong(v);\r
+            if ((*(unsigned long*)addr == (unsigned long)-1)\r
+                && PyErr_Occurred())\r
+                return -1;\r
+            WARN("Writing negative value into unsigned field");\r
+        }\r
+        break;\r
+        }\r
+    case T_PYSSIZET:{\r
+        *(Py_ssize_t*)addr = PyInt_AsSsize_t(v);\r
+        if ((*(Py_ssize_t*)addr == (Py_ssize_t)-1)\r
+            && PyErr_Occurred())\r
+                        return -1;\r
+        break;\r
+        }\r
+    case T_FLOAT:{\r
+        double double_val = PyFloat_AsDouble(v);\r
+        if ((double_val == -1) && PyErr_Occurred())\r
+            return -1;\r
+        *(float*)addr = (float)double_val;\r
+        break;\r
+        }\r
+    case T_DOUBLE:\r
+        *(double*)addr = PyFloat_AsDouble(v);\r
+        if ((*(double*)addr == -1) && PyErr_Occurred())\r
+            return -1;\r
+        break;\r
+    case T_OBJECT:\r
+    case T_OBJECT_EX:\r
+        Py_XINCREF(v);\r
+        oldv = *(PyObject **)addr;\r
+        *(PyObject **)addr = v;\r
+        Py_XDECREF(oldv);\r
+        break;\r
+    case T_CHAR:\r
+        if (PyString_Check(v) && PyString_Size(v) == 1) {\r
+            *(char*)addr = PyString_AsString(v)[0];\r
+        }\r
+        else {\r
+            PyErr_BadArgument();\r
+            return -1;\r
+        }\r
+        break;\r
+    case T_STRING:\r
+    case T_STRING_INPLACE:\r
+        PyErr_SetString(PyExc_TypeError, "readonly attribute");\r
+        return -1;\r
+#ifdef HAVE_LONG_LONG\r
+    case T_LONGLONG:{\r
+        PY_LONG_LONG value;\r
+        *(PY_LONG_LONG*)addr = value = PyLong_AsLongLong(v);\r
+        if ((value == -1) && PyErr_Occurred())\r
+            return -1;\r
+        break;\r
+        }\r
+    case T_ULONGLONG:{\r
+        unsigned PY_LONG_LONG value;\r
+        /* ??? PyLong_AsLongLong accepts an int, but PyLong_AsUnsignedLongLong\r
+            doesn't ??? */\r
+        if (PyLong_Check(v))\r
+            *(unsigned PY_LONG_LONG*)addr = value = PyLong_AsUnsignedLongLong(v);\r
+        else\r
+            *(unsigned PY_LONG_LONG*)addr = value = PyInt_AsLong(v);\r
+        if ((value == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())\r
+            return -1;\r
+        break;\r
+        }\r
+#endif /* HAVE_LONG_LONG */\r
+    default:\r
+        PyErr_Format(PyExc_SystemError,\r
+                     "bad memberdescr type for %s", l->name);\r
+        return -1;\r
+    }\r
+    return 0;\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/symtable.c b/AppPkg/Applications/Python/Python-2.7.10/Python/symtable.c
new file mode 100644 (file)
index 0000000..661662f
--- /dev/null
@@ -0,0 +1,1556 @@
+#include "Python.h"\r
+#include "Python-ast.h"\r
+#include "code.h"\r
+#include "symtable.h"\r
+#include "structmember.h"\r
+\r
+/* error strings used for warnings */\r
+#define GLOBAL_AFTER_ASSIGN \\r
+"name '%.400s' is assigned to before global declaration"\r
+\r
+#define GLOBAL_AFTER_USE \\r
+"name '%.400s' is used prior to global declaration"\r
+\r
+#define IMPORT_STAR_WARNING "import * only allowed at module level"\r
+\r
+#define RETURN_VAL_IN_GENERATOR \\r
+    "'return' with argument inside generator"\r
+\r
+\r
+static PySTEntryObject *\r
+ste_new(struct symtable *st, identifier name, _Py_block_ty block,\r
+              void *key, int lineno)\r
+{\r
+    PySTEntryObject *ste = NULL;\r
+    PyObject *k = NULL;\r
+\r
+    k = PyLong_FromVoidPtr(key);\r
+    if (k == NULL)\r
+        goto fail;\r
+    ste = PyObject_New(PySTEntryObject, &PySTEntry_Type);\r
+    if (ste == NULL) {\r
+        Py_DECREF(k);\r
+        goto fail;\r
+    }\r
+    ste->ste_table = st;\r
+    ste->ste_id = k; /* ste owns reference to k */\r
+\r
+    ste->ste_name = name;\r
+    Py_INCREF(name);\r
+\r
+    ste->ste_symbols = NULL;\r
+    ste->ste_varnames = NULL;\r
+    ste->ste_children = NULL;\r
+\r
+    ste->ste_symbols = PyDict_New();\r
+    if (ste->ste_symbols == NULL)\r
+        goto fail;\r
+\r
+    ste->ste_varnames = PyList_New(0);\r
+    if (ste->ste_varnames == NULL)\r
+        goto fail;\r
+\r
+    ste->ste_children = PyList_New(0);\r
+    if (ste->ste_children == NULL)\r
+        goto fail;\r
+\r
+    ste->ste_type = block;\r
+    ste->ste_unoptimized = 0;\r
+    ste->ste_nested = 0;\r
+    ste->ste_free = 0;\r
+    ste->ste_varargs = 0;\r
+    ste->ste_varkeywords = 0;\r
+    ste->ste_opt_lineno = 0;\r
+    ste->ste_tmpname = 0;\r
+    ste->ste_lineno = lineno;\r
+\r
+    if (st->st_cur != NULL &&\r
+        (st->st_cur->ste_nested ||\r
+         st->st_cur->ste_type == FunctionBlock))\r
+        ste->ste_nested = 1;\r
+    ste->ste_child_free = 0;\r
+    ste->ste_generator = 0;\r
+    ste->ste_returns_value = 0;\r
+\r
+    if (PyDict_SetItem(st->st_symbols, ste->ste_id, (PyObject *)ste) < 0)\r
+        goto fail;\r
+\r
+    return ste;\r
+ fail:\r
+    Py_XDECREF(ste);\r
+    return NULL;\r
+}\r
+\r
+static PyObject *\r
+ste_repr(PySTEntryObject *ste)\r
+{\r
+    char buf[256];\r
+\r
+    PyOS_snprintf(buf, sizeof(buf),\r
+                  "<symtable entry %.100s(%ld), line %d>",\r
+                  PyString_AS_STRING(ste->ste_name),\r
+                  PyInt_AS_LONG(ste->ste_id), ste->ste_lineno);\r
+    return PyString_FromString(buf);\r
+}\r
+\r
+static void\r
+ste_dealloc(PySTEntryObject *ste)\r
+{\r
+    ste->ste_table = NULL;\r
+    Py_XDECREF(ste->ste_id);\r
+    Py_XDECREF(ste->ste_name);\r
+    Py_XDECREF(ste->ste_symbols);\r
+    Py_XDECREF(ste->ste_varnames);\r
+    Py_XDECREF(ste->ste_children);\r
+    PyObject_Del(ste);\r
+}\r
+\r
+#define OFF(x) offsetof(PySTEntryObject, x)\r
+\r
+static PyMemberDef ste_memberlist[] = {\r
+    {"id",       T_OBJECT, OFF(ste_id), READONLY},\r
+    {"name",     T_OBJECT, OFF(ste_name), READONLY},\r
+    {"symbols",  T_OBJECT, OFF(ste_symbols), READONLY},\r
+    {"varnames", T_OBJECT, OFF(ste_varnames), READONLY},\r
+    {"children", T_OBJECT, OFF(ste_children), READONLY},\r
+    {"optimized",T_INT,    OFF(ste_unoptimized), READONLY},\r
+    {"nested",   T_INT,    OFF(ste_nested), READONLY},\r
+    {"type",     T_INT,    OFF(ste_type), READONLY},\r
+    {"lineno",   T_INT,    OFF(ste_lineno), READONLY},\r
+    {NULL}\r
+};\r
+\r
+PyTypeObject PySTEntry_Type = {\r
+    PyVarObject_HEAD_INIT(&PyType_Type, 0)\r
+    "symtable entry",\r
+    sizeof(PySTEntryObject),\r
+    0,\r
+    (destructor)ste_dealloc,                /* tp_dealloc */\r
+    0,                                      /* tp_print */\r
+    0,                                         /* tp_getattr */\r
+    0,                                          /* tp_setattr */\r
+    0,                                          /* tp_compare */\r
+    (reprfunc)ste_repr,                         /* tp_repr */\r
+    0,                                          /* tp_as_number */\r
+    0,                                          /* tp_as_sequence */\r
+    0,                                          /* tp_as_mapping */\r
+    0,                                          /* tp_hash */\r
+    0,                                          /* tp_call */\r
+    0,                                          /* tp_str */\r
+    PyObject_GenericGetAttr,                    /* tp_getattro */\r
+    0,                                          /* tp_setattro */\r
+    0,                                          /* tp_as_buffer */\r
+    Py_TPFLAGS_DEFAULT,                         /* tp_flags */\r
+    0,                                          /* tp_doc */\r
+    0,                                          /* tp_traverse */\r
+    0,                                          /* tp_clear */\r
+    0,                                          /* tp_richcompare */\r
+    0,                                          /* tp_weaklistoffset */\r
+    0,                                          /* tp_iter */\r
+    0,                                          /* tp_iternext */\r
+    0,                                          /* tp_methods */\r
+    ste_memberlist,                             /* tp_members */\r
+    0,                                          /* tp_getset */\r
+    0,                                          /* tp_base */\r
+    0,                                          /* tp_dict */\r
+    0,                                          /* tp_descr_get */\r
+    0,                                          /* tp_descr_set */\r
+    0,                                          /* tp_dictoffset */\r
+    0,                                          /* tp_init */\r
+    0,                                          /* tp_alloc */\r
+    0,                                          /* tp_new */\r
+};\r
+\r
+static int symtable_analyze(struct symtable *st);\r
+static int symtable_warn(struct symtable *st, char *msg, int lineno);\r
+static int symtable_enter_block(struct symtable *st, identifier name,\r
+                                _Py_block_ty block, void *ast, int lineno);\r
+static int symtable_exit_block(struct symtable *st, void *ast);\r
+static int symtable_visit_stmt(struct symtable *st, stmt_ty s);\r
+static int symtable_visit_expr(struct symtable *st, expr_ty s);\r
+static int symtable_visit_genexp(struct symtable *st, expr_ty s);\r
+static int symtable_visit_setcomp(struct symtable *st, expr_ty e);\r
+static int symtable_visit_dictcomp(struct symtable *st, expr_ty e);\r
+static int symtable_visit_arguments(struct symtable *st, arguments_ty);\r
+static int symtable_visit_excepthandler(struct symtable *st, excepthandler_ty);\r
+static int symtable_visit_alias(struct symtable *st, alias_ty);\r
+static int symtable_visit_comprehension(struct symtable *st, comprehension_ty);\r
+static int symtable_visit_keyword(struct symtable *st, keyword_ty);\r
+static int symtable_visit_slice(struct symtable *st, slice_ty);\r
+static int symtable_visit_params(struct symtable *st, asdl_seq *args, int top);\r
+static int symtable_visit_params_nested(struct symtable *st, asdl_seq *args);\r
+static int symtable_implicit_arg(struct symtable *st, int pos);\r
+\r
+\r
+static identifier top = NULL, lambda = NULL, genexpr = NULL, setcomp = NULL,\r
+    dictcomp = NULL;\r
+\r
+#define GET_IDENTIFIER(VAR) \\r
+    ((VAR) ? (VAR) : ((VAR) = PyString_InternFromString(# VAR)))\r
+\r
+#define DUPLICATE_ARGUMENT \\r
+"duplicate argument '%s' in function definition"\r
+\r
+static struct symtable *\r
+symtable_new(void)\r
+{\r
+    struct symtable *st;\r
+\r
+    st = (struct symtable *)PyMem_Malloc(sizeof(struct symtable));\r
+    if (st == NULL)\r
+        return NULL;\r
+\r
+    st->st_filename = NULL;\r
+    st->st_symbols = NULL;\r
+\r
+    if ((st->st_stack = PyList_New(0)) == NULL)\r
+        goto fail;\r
+    if ((st->st_symbols = PyDict_New()) == NULL)\r
+        goto fail;\r
+    st->st_cur = NULL;\r
+    st->st_private = NULL;\r
+    return st;\r
+ fail:\r
+    PySymtable_Free(st);\r
+    return NULL;\r
+}\r
+\r
+struct symtable *\r
+PySymtable_Build(mod_ty mod, const char *filename, PyFutureFeatures *future)\r
+{\r
+    struct symtable *st = symtable_new();\r
+    asdl_seq *seq;\r
+    int i;\r
+\r
+    if (st == NULL)\r
+        return st;\r
+    st->st_filename = filename;\r
+    st->st_future = future;\r
+    if (!GET_IDENTIFIER(top) ||\r
+        !symtable_enter_block(st, top, ModuleBlock, (void *)mod, 0)) {\r
+        PySymtable_Free(st);\r
+        return NULL;\r
+    }\r
+\r
+    st->st_top = st->st_cur;\r
+    st->st_cur->ste_unoptimized = OPT_TOPLEVEL;\r
+    /* Any other top-level initialization? */\r
+    switch (mod->kind) {\r
+    case Module_kind:\r
+        seq = mod->v.Module.body;\r
+        for (i = 0; i < asdl_seq_LEN(seq); i++)\r
+            if (!symtable_visit_stmt(st,\r
+                        (stmt_ty)asdl_seq_GET(seq, i)))\r
+                goto error;\r
+        break;\r
+    case Expression_kind:\r
+        if (!symtable_visit_expr(st, mod->v.Expression.body))\r
+            goto error;\r
+        break;\r
+    case Interactive_kind:\r
+        seq = mod->v.Interactive.body;\r
+        for (i = 0; i < asdl_seq_LEN(seq); i++)\r
+            if (!symtable_visit_stmt(st,\r
+                        (stmt_ty)asdl_seq_GET(seq, i)))\r
+                goto error;\r
+        break;\r
+    case Suite_kind:\r
+        PyErr_SetString(PyExc_RuntimeError,\r
+                        "this compiler does not handle Suites");\r
+        goto error;\r
+    }\r
+    if (!symtable_exit_block(st, (void *)mod)) {\r
+        PySymtable_Free(st);\r
+        return NULL;\r
+    }\r
+    if (symtable_analyze(st))\r
+        return st;\r
+    PySymtable_Free(st);\r
+    return NULL;\r
+ error:\r
+    (void) symtable_exit_block(st, (void *)mod);\r
+    PySymtable_Free(st);\r
+    return NULL;\r
+}\r
+\r
+void\r
+PySymtable_Free(struct symtable *st)\r
+{\r
+    Py_XDECREF(st->st_symbols);\r
+    Py_XDECREF(st->st_stack);\r
+    PyMem_Free((void *)st);\r
+}\r
+\r
+PySTEntryObject *\r
+PySymtable_Lookup(struct symtable *st, void *key)\r
+{\r
+    PyObject *k, *v;\r
+\r
+    k = PyLong_FromVoidPtr(key);\r
+    if (k == NULL)\r
+        return NULL;\r
+    v = PyDict_GetItem(st->st_symbols, k);\r
+    if (v) {\r
+        assert(PySTEntry_Check(v));\r
+        Py_INCREF(v);\r
+    }\r
+    else {\r
+        PyErr_SetString(PyExc_KeyError,\r
+                        "unknown symbol table entry");\r
+    }\r
+\r
+    Py_DECREF(k);\r
+    return (PySTEntryObject *)v;\r
+}\r
+\r
+int\r
+PyST_GetScope(PySTEntryObject *ste, PyObject *name)\r
+{\r
+    PyObject *v = PyDict_GetItem(ste->ste_symbols, name);\r
+    if (!v)\r
+        return 0;\r
+    assert(PyInt_Check(v));\r
+    return (PyInt_AS_LONG(v) >> SCOPE_OFF) & SCOPE_MASK;\r
+}\r
+\r
+\r
+/* Analyze raw symbol information to determine scope of each name.\r
+\r
+   The next several functions are helpers for PySymtable_Analyze(),\r
+   which determines whether a name is local, global, or free.  In addition,\r
+   it determines which local variables are cell variables; they provide\r
+   bindings that are used for free variables in enclosed blocks.\r
+\r
+   There are also two kinds of free variables, implicit and explicit.  An\r
+   explicit global is declared with the global statement.  An implicit\r
+   global is a free variable for which the compiler has found no binding\r
+   in an enclosing function scope.  The implicit global is either a global\r
+   or a builtin.  Python's module and class blocks use the xxx_NAME opcodes\r
+   to handle these names to implement slightly odd semantics.  In such a\r
+   block, the name is treated as global until it is assigned to; then it\r
+   is treated as a local.\r
+\r
+   The symbol table requires two passes to determine the scope of each name.\r
+   The first pass collects raw facts from the AST: the name is a parameter\r
+   here, the name is used by not defined here, etc.  The second pass analyzes\r
+   these facts during a pass over the PySTEntryObjects created during pass 1.\r
+\r
+   When a function is entered during the second pass, the parent passes\r
+   the set of all name bindings visible to its children.  These bindings\r
+   are used to determine if the variable is free or an implicit global.\r
+   After doing the local analysis, it analyzes each of its child blocks\r
+   using an updated set of name bindings.\r
+\r
+   The children update the free variable set.  If a local variable is free\r
+   in a child, the variable is marked as a cell.  The current function must\r
+   provide runtime storage for the variable that may outlive the function's\r
+   frame.  Cell variables are removed from the free set before the analyze\r
+   function returns to its parent.\r
+\r
+   The sets of bound and free variables are implemented as dictionaries\r
+   mapping strings to None.\r
+*/\r
+\r
+#define SET_SCOPE(DICT, NAME, I) { \\r
+    PyObject *o = PyInt_FromLong(I); \\r
+    if (!o) \\r
+        return 0; \\r
+    if (PyDict_SetItem((DICT), (NAME), o) < 0) { \\r
+        Py_DECREF(o); \\r
+        return 0; \\r
+    } \\r
+    Py_DECREF(o); \\r
+}\r
+\r
+/* Decide on scope of name, given flags.\r
+\r
+   The namespace dictionaries may be modified to record information\r
+   about the new name.  For example, a new global will add an entry to\r
+   global.  A name that was global can be changed to local.\r
+*/\r
+\r
+static int\r
+analyze_name(PySTEntryObject *ste, PyObject *dict, PyObject *name, long flags,\r
+             PyObject *bound, PyObject *local, PyObject *free,\r
+             PyObject *global)\r
+{\r
+    if (flags & DEF_GLOBAL) {\r
+        if (flags & DEF_PARAM) {\r
+            PyErr_Format(PyExc_SyntaxError,\r
+                         "name '%s' is local and global",\r
+                         PyString_AS_STRING(name));\r
+            PyErr_SyntaxLocation(ste->ste_table->st_filename,\r
+                                 ste->ste_lineno);\r
+\r
+            return 0;\r
+        }\r
+        SET_SCOPE(dict, name, GLOBAL_EXPLICIT);\r
+        if (PyDict_SetItem(global, name, Py_None) < 0)\r
+            return 0;\r
+        if (bound && PyDict_GetItem(bound, name)) {\r
+            if (PyDict_DelItem(bound, name) < 0)\r
+                return 0;\r
+        }\r
+        return 1;\r
+    }\r
+    if (flags & DEF_BOUND) {\r
+        SET_SCOPE(dict, name, LOCAL);\r
+        if (PyDict_SetItem(local, name, Py_None) < 0)\r
+            return 0;\r
+        if (PyDict_GetItem(global, name)) {\r
+            if (PyDict_DelItem(global, name) < 0)\r
+                return 0;\r
+        }\r
+        return 1;\r
+    }\r
+    /* If an enclosing block has a binding for this name, it\r
+       is a free variable rather than a global variable.\r
+       Note that having a non-NULL bound implies that the block\r
+       is nested.\r
+    */\r
+    if (bound && PyDict_GetItem(bound, name)) {\r
+        SET_SCOPE(dict, name, FREE);\r
+        ste->ste_free = 1;\r
+        if (PyDict_SetItem(free, name, Py_None) < 0)\r
+            return 0;\r
+        return 1;\r
+    }\r
+    /* If a parent has a global statement, then call it global\r
+       explicit?  It could also be global implicit.\r
+     */\r
+    else if (global && PyDict_GetItem(global, name)) {\r
+        SET_SCOPE(dict, name, GLOBAL_IMPLICIT);\r
+        return 1;\r
+    }\r
+    else {\r
+        if (ste->ste_nested)\r
+            ste->ste_free = 1;\r
+        SET_SCOPE(dict, name, GLOBAL_IMPLICIT);\r
+        return 1;\r
+    }\r
+    /* Should never get here. */\r
+    PyErr_Format(PyExc_SystemError, "failed to set scope for %s",\r
+                 PyString_AS_STRING(name));\r
+    return 0;\r
+}\r
+\r
+#undef SET_SCOPE\r
+\r
+/* If a name is defined in free and also in locals, then this block\r
+   provides the binding for the free variable.  The name should be\r
+   marked CELL in this block and removed from the free list.\r
+\r
+   Note that the current block's free variables are included in free.\r
+   That's safe because no name can be free and local in the same scope.\r
+*/\r
+\r
+static int\r
+analyze_cells(PyObject *scope, PyObject *free)\r
+{\r
+    PyObject *name, *v, *w;\r
+    int success = 0;\r
+    Py_ssize_t pos = 0;\r
+\r
+    w = PyInt_FromLong(CELL);\r
+    if (!w)\r
+        return 0;\r
+    while (PyDict_Next(scope, &pos, &name, &v)) {\r
+        long flags;\r
+        assert(PyInt_Check(v));\r
+        flags = PyInt_AS_LONG(v);\r
+        if (flags != LOCAL)\r
+            continue;\r
+        if (!PyDict_GetItem(free, name))\r
+            continue;\r
+        /* Replace LOCAL with CELL for this name, and remove\r
+           from free. It is safe to replace the value of name\r
+           in the dict, because it will not cause a resize.\r
+         */\r
+        if (PyDict_SetItem(scope, name, w) < 0)\r
+            goto error;\r
+        if (PyDict_DelItem(free, name) < 0)\r
+            goto error;\r
+    }\r
+    success = 1;\r
+ error:\r
+    Py_DECREF(w);\r
+    return success;\r
+}\r
+\r
+/* Check for illegal statements in unoptimized namespaces */\r
+static int\r
+check_unoptimized(const PySTEntryObject* ste) {\r
+    char buf[300];\r
+    const char* trailer;\r
+\r
+    if (ste->ste_type != FunctionBlock || !ste->ste_unoptimized\r
+        || !(ste->ste_free || ste->ste_child_free))\r
+        return 1;\r
+\r
+    trailer = (ste->ste_child_free ?\r
+                   "contains a nested function with free variables" :\r
+                   "is a nested function");\r
+\r
+    switch (ste->ste_unoptimized) {\r
+    case OPT_TOPLEVEL: /* exec / import * at top-level is fine */\r
+    case OPT_EXEC: /* qualified exec is fine */\r
+        return 1;\r
+    case OPT_IMPORT_STAR:\r
+        PyOS_snprintf(buf, sizeof(buf),\r
+                      "import * is not allowed in function '%.100s' "\r
+                      "because it %s",\r
+                      PyString_AS_STRING(ste->ste_name), trailer);\r
+        break;\r
+    case OPT_BARE_EXEC:\r
+        PyOS_snprintf(buf, sizeof(buf),\r
+                      "unqualified exec is not allowed in function "\r
+                      "'%.100s' because it %s",\r
+                      PyString_AS_STRING(ste->ste_name), trailer);\r
+        break;\r
+    default:\r
+        PyOS_snprintf(buf, sizeof(buf),\r
+                      "function '%.100s' uses import * and bare exec, "\r
+                      "which are illegal because it %s",\r
+                      PyString_AS_STRING(ste->ste_name), trailer);\r
+        break;\r
+    }\r
+\r
+    PyErr_SetString(PyExc_SyntaxError, buf);\r
+    PyErr_SyntaxLocation(ste->ste_table->st_filename,\r
+                         ste->ste_opt_lineno);\r
+    return 0;\r
+}\r
+\r
+/* Enter the final scope information into the st_symbols dict.\r
+ *\r
+ * All arguments are dicts.  Modifies symbols, others are read-only.\r
+*/\r
+static int\r
+update_symbols(PyObject *symbols, PyObject *scope,\r
+               PyObject *bound, PyObject *free, int classflag)\r
+{\r
+    PyObject *name, *v, *u, *w, *free_value = NULL;\r
+    Py_ssize_t pos = 0;\r
+\r
+    while (PyDict_Next(symbols, &pos, &name, &v)) {\r
+        long i, flags;\r
+        assert(PyInt_Check(v));\r
+        flags = PyInt_AS_LONG(v);\r
+        w = PyDict_GetItem(scope, name);\r
+        assert(w && PyInt_Check(w));\r
+        i = PyInt_AS_LONG(w);\r
+        flags |= (i << SCOPE_OFF);\r
+        u = PyInt_FromLong(flags);\r
+        if (!u)\r
+            return 0;\r
+        if (PyDict_SetItem(symbols, name, u) < 0) {\r
+            Py_DECREF(u);\r
+            return 0;\r
+        }\r
+        Py_DECREF(u);\r
+    }\r
+\r
+    free_value = PyInt_FromLong(FREE << SCOPE_OFF);\r
+    if (!free_value)\r
+        return 0;\r
+\r
+    /* add a free variable when it's only use is for creating a closure */\r
+    pos = 0;\r
+    while (PyDict_Next(free, &pos, &name, &v)) {\r
+        PyObject *o = PyDict_GetItem(symbols, name);\r
+\r
+        if (o) {\r
+            /* It could be a free variable in a method of\r
+               the class that has the same name as a local\r
+               or global in the class scope.\r
+            */\r
+            if  (classflag &&\r
+                 PyInt_AS_LONG(o) & (DEF_BOUND | DEF_GLOBAL)) {\r
+                long i = PyInt_AS_LONG(o) | DEF_FREE_CLASS;\r
+                o = PyInt_FromLong(i);\r
+                if (!o) {\r
+                    Py_DECREF(free_value);\r
+                    return 0;\r
+                }\r
+                if (PyDict_SetItem(symbols, name, o) < 0) {\r
+                    Py_DECREF(o);\r
+                    Py_DECREF(free_value);\r
+                    return 0;\r
+                }\r
+                Py_DECREF(o);\r
+            }\r
+            /* else it's not free, probably a cell */\r
+            continue;\r
+        }\r
+        if (!PyDict_GetItem(bound, name))\r
+            continue;       /* it's a global */\r
+\r
+        if (PyDict_SetItem(symbols, name, free_value) < 0) {\r
+            Py_DECREF(free_value);\r
+            return 0;\r
+        }\r
+    }\r
+    Py_DECREF(free_value);\r
+    return 1;\r
+}\r
+\r
+/* Make final symbol table decisions for block of ste.\r
+\r
+   Arguments:\r
+   ste -- current symtable entry (input/output)\r
+   bound -- set of variables bound in enclosing scopes (input).  bound\r
+       is NULL for module blocks.\r
+   free -- set of free variables in enclosed scopes (output)\r
+   globals -- set of declared global variables in enclosing scopes (input)\r
+\r
+   The implementation uses two mutually recursive functions,\r
+   analyze_block() and analyze_child_block().  analyze_block() is\r
+   responsible for analyzing the individual names defined in a block.\r
+   analyze_child_block() prepares temporary namespace dictionaries\r
+   used to evaluated nested blocks.\r
+\r
+   The two functions exist because a child block should see the name\r
+   bindings of its enclosing blocks, but those bindings should not\r
+   propagate back to a parent block.\r
+*/\r
+\r
+static int\r
+analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free,\r
+                    PyObject *global, PyObject* child_free);\r
+\r
+static int\r
+analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,\r
+              PyObject *global)\r
+{\r
+    PyObject *name, *v, *local = NULL, *scope = NULL;\r
+    PyObject *newbound = NULL, *newglobal = NULL;\r
+    PyObject *newfree = NULL, *allfree = NULL;\r
+    int i, success = 0;\r
+    Py_ssize_t pos = 0;\r
+\r
+    local = PyDict_New();  /* collect new names bound in block */\r
+    if (!local)\r
+        goto error;\r
+    scope = PyDict_New(); /* collect scopes defined for each name */\r
+    if (!scope)\r
+        goto error;\r
+\r
+    /* Allocate new global and bound variable dictionaries.  These\r
+       dictionaries hold the names visible in nested blocks.  For\r
+       ClassBlocks, the bound and global names are initialized\r
+       before analyzing names, because class bindings aren't\r
+       visible in methods.  For other blocks, they are initialized\r
+       after names are analyzed.\r
+     */\r
+\r
+    /* TODO(jhylton): Package these dicts in a struct so that we\r
+       can write reasonable helper functions?\r
+    */\r
+    newglobal = PyDict_New();\r
+    if (!newglobal)\r
+        goto error;\r
+    newbound = PyDict_New();\r
+    if (!newbound)\r
+        goto error;\r
+    newfree = PyDict_New();\r
+    if (!newfree)\r
+        goto error;\r
+\r
+    if (ste->ste_type == ClassBlock) {\r
+        if (PyDict_Update(newglobal, global) < 0)\r
+            goto error;\r
+        if (bound)\r
+            if (PyDict_Update(newbound, bound) < 0)\r
+                goto error;\r
+    }\r
+\r
+    while (PyDict_Next(ste->ste_symbols, &pos, &name, &v)) {\r
+        long flags = PyInt_AS_LONG(v);\r
+        if (!analyze_name(ste, scope, name, flags,\r
+                          bound, local, free, global))\r
+            goto error;\r
+    }\r
+\r
+    if (ste->ste_type != ClassBlock) {\r
+        if (ste->ste_type == FunctionBlock) {\r
+            if (PyDict_Update(newbound, local) < 0)\r
+                goto error;\r
+        }\r
+        if (bound) {\r
+            if (PyDict_Update(newbound, bound) < 0)\r
+                goto error;\r
+        }\r
+        if (PyDict_Update(newglobal, global) < 0)\r
+            goto error;\r
+    }\r
+\r
+    /* Recursively call analyze_block() on each child block.\r
+\r
+       newbound, newglobal now contain the names visible in\r
+       nested blocks.  The free variables in the children will\r
+       be collected in allfree.\r
+    */\r
+    allfree = PyDict_New();\r
+    if (!allfree)\r
+        goto error;\r
+    for (i = 0; i < PyList_GET_SIZE(ste->ste_children); ++i) {\r
+        PyObject *c = PyList_GET_ITEM(ste->ste_children, i);\r
+        PySTEntryObject* entry;\r
+        assert(c && PySTEntry_Check(c));\r
+        entry = (PySTEntryObject*)c;\r
+        if (!analyze_child_block(entry, newbound, newfree, newglobal,\r
+                                 allfree))\r
+            goto error;\r
+        if (entry->ste_free || entry->ste_child_free)\r
+            ste->ste_child_free = 1;\r
+    }\r
+\r
+    if (PyDict_Update(newfree, allfree) < 0)\r
+        goto error;\r
+    if (ste->ste_type == FunctionBlock && !analyze_cells(scope, newfree))\r
+        goto error;\r
+    if (!update_symbols(ste->ste_symbols, scope, bound, newfree,\r
+                        ste->ste_type == ClassBlock))\r
+        goto error;\r
+    if (!check_unoptimized(ste))\r
+        goto error;\r
+\r
+    if (PyDict_Update(free, newfree) < 0)\r
+        goto error;\r
+    success = 1;\r
+ error:\r
+    Py_XDECREF(local);\r
+    Py_XDECREF(scope);\r
+    Py_XDECREF(newbound);\r
+    Py_XDECREF(newglobal);\r
+    Py_XDECREF(newfree);\r
+    Py_XDECREF(allfree);\r
+    if (!success)\r
+        assert(PyErr_Occurred());\r
+    return success;\r
+}\r
+\r
+static int\r
+analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free,\r
+                    PyObject *global, PyObject* child_free)\r
+{\r
+    PyObject *temp_bound = NULL, *temp_global = NULL, *temp_free = NULL;\r
+\r
+    /* Copy the bound and global dictionaries.\r
+\r
+       These dictionary are used by all blocks enclosed by the\r
+       current block.  The analyze_block() call modifies these\r
+       dictionaries.\r
+\r
+    */\r
+    temp_bound = PyDict_New();\r
+    if (!temp_bound)\r
+        goto error;\r
+    if (PyDict_Update(temp_bound, bound) < 0)\r
+        goto error;\r
+    temp_free = PyDict_New();\r
+    if (!temp_free)\r
+        goto error;\r
+    if (PyDict_Update(temp_free, free) < 0)\r
+        goto error;\r
+    temp_global = PyDict_New();\r
+    if (!temp_global)\r
+        goto error;\r
+    if (PyDict_Update(temp_global, global) < 0)\r
+        goto error;\r
+\r
+    if (!analyze_block(entry, temp_bound, temp_free, temp_global))\r
+        goto error;\r
+    if (PyDict_Update(child_free, temp_free) < 0)\r
+        goto error;\r
+    Py_DECREF(temp_bound);\r
+    Py_DECREF(temp_free);\r
+    Py_DECREF(temp_global);\r
+    return 1;\r
+ error:\r
+    Py_XDECREF(temp_bound);\r
+    Py_XDECREF(temp_free);\r
+    Py_XDECREF(temp_global);\r
+    return 0;\r
+}\r
+\r
+static int\r
+symtable_analyze(struct symtable *st)\r
+{\r
+    PyObject *free, *global;\r
+    int r;\r
+\r
+    free = PyDict_New();\r
+    if (!free)\r
+        return 0;\r
+    global = PyDict_New();\r
+    if (!global) {\r
+        Py_DECREF(free);\r
+        return 0;\r
+    }\r
+    r = analyze_block(st->st_top, NULL, free, global);\r
+    Py_DECREF(free);\r
+    Py_DECREF(global);\r
+    return r;\r
+}\r
+\r
+\r
+static int\r
+symtable_warn(struct symtable *st, char *msg, int lineno)\r
+{\r
+    if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, st->st_filename,\r
+                           lineno, NULL, NULL) < 0)     {\r
+        if (PyErr_ExceptionMatches(PyExc_SyntaxWarning)) {\r
+            PyErr_SetString(PyExc_SyntaxError, msg);\r
+            PyErr_SyntaxLocation(st->st_filename,\r
+                                 st->st_cur->ste_lineno);\r
+        }\r
+        return 0;\r
+    }\r
+    return 1;\r
+}\r
+\r
+/* symtable_enter_block() gets a reference via ste_new.\r
+   This reference is released when the block is exited, via the DECREF\r
+   in symtable_exit_block().\r
+*/\r
+\r
+static int\r
+symtable_exit_block(struct symtable *st, void *ast)\r
+{\r
+    Py_ssize_t end;\r
+\r
+    Py_CLEAR(st->st_cur);\r
+    end = PyList_GET_SIZE(st->st_stack) - 1;\r
+    if (end >= 0) {\r
+        st->st_cur = (PySTEntryObject *)PyList_GET_ITEM(st->st_stack,\r
+                                                        end);\r
+        if (st->st_cur == NULL)\r
+            return 0;\r
+        Py_INCREF(st->st_cur);\r
+        if (PySequence_DelItem(st->st_stack, end) < 0)\r
+            return 0;\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,\r
+                     void *ast, int lineno)\r
+{\r
+    PySTEntryObject *prev = NULL;\r
+\r
+    if (st->st_cur) {\r
+        prev = st->st_cur;\r
+        if (PyList_Append(st->st_stack, (PyObject *)st->st_cur) < 0) {\r
+            return 0;\r
+        }\r
+        Py_DECREF(st->st_cur);\r
+    }\r
+    st->st_cur = ste_new(st, name, block, ast, lineno);\r
+    if (st->st_cur == NULL)\r
+        return 0;\r
+    if (block == ModuleBlock)\r
+        st->st_global = st->st_cur->ste_symbols;\r
+    if (prev) {\r
+        if (PyList_Append(prev->ste_children,\r
+                          (PyObject *)st->st_cur) < 0) {\r
+            return 0;\r
+        }\r
+    }\r
+    return 1;\r
+}\r
+\r
+static long\r
+symtable_lookup(struct symtable *st, PyObject *name)\r
+{\r
+    PyObject *o;\r
+    PyObject *mangled = _Py_Mangle(st->st_private, name);\r
+    if (!mangled)\r
+        return 0;\r
+    o = PyDict_GetItem(st->st_cur->ste_symbols, mangled);\r
+    Py_DECREF(mangled);\r
+    if (!o)\r
+        return 0;\r
+    return PyInt_AsLong(o);\r
+}\r
+\r
+static int\r
+symtable_add_def(struct symtable *st, PyObject *name, int flag)\r
+{\r
+    PyObject *o;\r
+    PyObject *dict;\r
+    long val;\r
+    PyObject *mangled = _Py_Mangle(st->st_private, name);\r
+\r
+    if (!mangled)\r
+        return 0;\r
+    dict = st->st_cur->ste_symbols;\r
+    if ((o = PyDict_GetItem(dict, mangled))) {\r
+        val = PyInt_AS_LONG(o);\r
+        if ((flag & DEF_PARAM) && (val & DEF_PARAM)) {\r
+            /* Is it better to use 'mangled' or 'name' here? */\r
+            PyErr_Format(PyExc_SyntaxError, DUPLICATE_ARGUMENT,\r
+                         PyString_AsString(name));\r
+            PyErr_SyntaxLocation(st->st_filename,\r
+                               st->st_cur->ste_lineno);\r
+            goto error;\r
+        }\r
+        val |= flag;\r
+    } else\r
+        val = flag;\r
+    o = PyInt_FromLong(val);\r
+    if (o == NULL)\r
+        goto error;\r
+    if (PyDict_SetItem(dict, mangled, o) < 0) {\r
+        Py_DECREF(o);\r
+        goto error;\r
+    }\r
+    Py_DECREF(o);\r
+\r
+    if (flag & DEF_PARAM) {\r
+        if (PyList_Append(st->st_cur->ste_varnames, mangled) < 0)\r
+            goto error;\r
+    } else      if (flag & DEF_GLOBAL) {\r
+        /* XXX need to update DEF_GLOBAL for other flags too;\r
+           perhaps only DEF_FREE_GLOBAL */\r
+        val = flag;\r
+        if ((o = PyDict_GetItem(st->st_global, mangled))) {\r
+            val |= PyInt_AS_LONG(o);\r
+        }\r
+        o = PyInt_FromLong(val);\r
+        if (o == NULL)\r
+            goto error;\r
+        if (PyDict_SetItem(st->st_global, mangled, o) < 0) {\r
+            Py_DECREF(o);\r
+            goto error;\r
+        }\r
+        Py_DECREF(o);\r
+    }\r
+    Py_DECREF(mangled);\r
+    return 1;\r
+\r
+error:\r
+    Py_DECREF(mangled);\r
+    return 0;\r
+}\r
+\r
+/* VISIT, VISIT_SEQ and VIST_SEQ_TAIL take an ASDL type as their second argument.\r
+   They use the ASDL name to synthesize the name of the C type and the visit\r
+   function.\r
+\r
+   VISIT_SEQ_TAIL permits the start of an ASDL sequence to be skipped, which is\r
+   useful if the first node in the sequence requires special treatment.\r
+*/\r
+\r
+#define VISIT(ST, TYPE, V) \\r
+    if (!symtable_visit_ ## TYPE((ST), (V))) \\r
+        return 0;\r
+\r
+#define VISIT_IN_BLOCK(ST, TYPE, V, S) \\r
+    if (!symtable_visit_ ## TYPE((ST), (V))) { \\r
+        symtable_exit_block((ST), (S)); \\r
+        return 0; \\r
+    }\r
+\r
+#define VISIT_SEQ(ST, TYPE, SEQ) { \\r
+    int i; \\r
+    asdl_seq *seq = (SEQ); /* avoid variable capture */ \\r
+    for (i = 0; i < asdl_seq_LEN(seq); i++) { \\r
+        TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \\r
+        if (!symtable_visit_ ## TYPE((ST), elt)) \\r
+            return 0; \\r
+    } \\r
+}\r
+\r
+#define VISIT_SEQ_IN_BLOCK(ST, TYPE, SEQ, S) { \\r
+    int i; \\r
+    asdl_seq *seq = (SEQ); /* avoid variable capture */ \\r
+    for (i = 0; i < asdl_seq_LEN(seq); i++) { \\r
+        TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \\r
+        if (!symtable_visit_ ## TYPE((ST), elt)) { \\r
+            symtable_exit_block((ST), (S)); \\r
+            return 0; \\r
+        } \\r
+    } \\r
+}\r
+\r
+#define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) { \\r
+    int i; \\r
+    asdl_seq *seq = (SEQ); /* avoid variable capture */ \\r
+    for (i = (START); i < asdl_seq_LEN(seq); i++) { \\r
+        TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \\r
+        if (!symtable_visit_ ## TYPE((ST), elt)) \\r
+            return 0; \\r
+    } \\r
+}\r
+\r
+#define VISIT_SEQ_TAIL_IN_BLOCK(ST, TYPE, SEQ, START, S) { \\r
+    int i; \\r
+    asdl_seq *seq = (SEQ); /* avoid variable capture */ \\r
+    for (i = (START); i < asdl_seq_LEN(seq); i++) { \\r
+        TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \\r
+        if (!symtable_visit_ ## TYPE((ST), elt)) { \\r
+            symtable_exit_block((ST), (S)); \\r
+            return 0; \\r
+        } \\r
+    } \\r
+}\r
+\r
+static int\r
+symtable_visit_stmt(struct symtable *st, stmt_ty s)\r
+{\r
+    switch (s->kind) {\r
+    case FunctionDef_kind:\r
+        if (!symtable_add_def(st, s->v.FunctionDef.name, DEF_LOCAL))\r
+            return 0;\r
+        if (s->v.FunctionDef.args->defaults)\r
+            VISIT_SEQ(st, expr, s->v.FunctionDef.args->defaults);\r
+        if (s->v.FunctionDef.decorator_list)\r
+            VISIT_SEQ(st, expr, s->v.FunctionDef.decorator_list);\r
+        if (!symtable_enter_block(st, s->v.FunctionDef.name,\r
+                                  FunctionBlock, (void *)s, s->lineno))\r
+            return 0;\r
+        VISIT_IN_BLOCK(st, arguments, s->v.FunctionDef.args, s);\r
+        VISIT_SEQ_IN_BLOCK(st, stmt, s->v.FunctionDef.body, s);\r
+        if (!symtable_exit_block(st, s))\r
+            return 0;\r
+        break;\r
+    case ClassDef_kind: {\r
+        PyObject *tmp;\r
+        if (!symtable_add_def(st, s->v.ClassDef.name, DEF_LOCAL))\r
+            return 0;\r
+        VISIT_SEQ(st, expr, s->v.ClassDef.bases);\r
+        if (s->v.ClassDef.decorator_list)\r
+            VISIT_SEQ(st, expr, s->v.ClassDef.decorator_list);\r
+        if (!symtable_enter_block(st, s->v.ClassDef.name, ClassBlock,\r
+                                  (void *)s, s->lineno))\r
+            return 0;\r
+        tmp = st->st_private;\r
+        st->st_private = s->v.ClassDef.name;\r
+        VISIT_SEQ_IN_BLOCK(st, stmt, s->v.ClassDef.body, s);\r
+        st->st_private = tmp;\r
+        if (!symtable_exit_block(st, s))\r
+            return 0;\r
+        break;\r
+    }\r
+    case Return_kind:\r
+        if (s->v.Return.value) {\r
+            VISIT(st, expr, s->v.Return.value);\r
+            st->st_cur->ste_returns_value = 1;\r
+            if (st->st_cur->ste_generator) {\r
+                PyErr_SetString(PyExc_SyntaxError,\r
+                    RETURN_VAL_IN_GENERATOR);\r
+                PyErr_SyntaxLocation(st->st_filename,\r
+                             s->lineno);\r
+                return 0;\r
+            }\r
+        }\r
+        break;\r
+    case Delete_kind:\r
+        VISIT_SEQ(st, expr, s->v.Delete.targets);\r
+        break;\r
+    case Assign_kind:\r
+        VISIT_SEQ(st, expr, s->v.Assign.targets);\r
+        VISIT(st, expr, s->v.Assign.value);\r
+        break;\r
+    case AugAssign_kind:\r
+        VISIT(st, expr, s->v.AugAssign.target);\r
+        VISIT(st, expr, s->v.AugAssign.value);\r
+        break;\r
+    case Print_kind:\r
+        if (s->v.Print.dest)\r
+            VISIT(st, expr, s->v.Print.dest);\r
+        VISIT_SEQ(st, expr, s->v.Print.values);\r
+        break;\r
+    case For_kind:\r
+        VISIT(st, expr, s->v.For.target);\r
+        VISIT(st, expr, s->v.For.iter);\r
+        VISIT_SEQ(st, stmt, s->v.For.body);\r
+        if (s->v.For.orelse)\r
+            VISIT_SEQ(st, stmt, s->v.For.orelse);\r
+        break;\r
+    case While_kind:\r
+        VISIT(st, expr, s->v.While.test);\r
+        VISIT_SEQ(st, stmt, s->v.While.body);\r
+        if (s->v.While.orelse)\r
+            VISIT_SEQ(st, stmt, s->v.While.orelse);\r
+        break;\r
+    case If_kind:\r
+        /* XXX if 0: and lookup_yield() hacks */\r
+        VISIT(st, expr, s->v.If.test);\r
+        VISIT_SEQ(st, stmt, s->v.If.body);\r
+        if (s->v.If.orelse)\r
+            VISIT_SEQ(st, stmt, s->v.If.orelse);\r
+        break;\r
+    case Raise_kind:\r
+        if (s->v.Raise.type) {\r
+            VISIT(st, expr, s->v.Raise.type);\r
+            if (s->v.Raise.inst) {\r
+                VISIT(st, expr, s->v.Raise.inst);\r
+                if (s->v.Raise.tback)\r
+                    VISIT(st, expr, s->v.Raise.tback);\r
+            }\r
+        }\r
+        break;\r
+    case TryExcept_kind:\r
+        VISIT_SEQ(st, stmt, s->v.TryExcept.body);\r
+        VISIT_SEQ(st, stmt, s->v.TryExcept.orelse);\r
+        VISIT_SEQ(st, excepthandler, s->v.TryExcept.handlers);\r
+        break;\r
+    case TryFinally_kind:\r
+        VISIT_SEQ(st, stmt, s->v.TryFinally.body);\r
+        VISIT_SEQ(st, stmt, s->v.TryFinally.finalbody);\r
+        break;\r
+    case Assert_kind:\r
+        VISIT(st, expr, s->v.Assert.test);\r
+        if (s->v.Assert.msg)\r
+            VISIT(st, expr, s->v.Assert.msg);\r
+        break;\r
+    case Import_kind:\r
+        VISIT_SEQ(st, alias, s->v.Import.names);\r
+        /* XXX Don't have the lineno available inside\r
+           visit_alias */\r
+        if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno)\r
+            st->st_cur->ste_opt_lineno = s->lineno;\r
+        break;\r
+    case ImportFrom_kind:\r
+        VISIT_SEQ(st, alias, s->v.ImportFrom.names);\r
+        /* XXX Don't have the lineno available inside\r
+           visit_alias */\r
+        if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno)\r
+            st->st_cur->ste_opt_lineno = s->lineno;\r
+        break;\r
+    case Exec_kind:\r
+        VISIT(st, expr, s->v.Exec.body);\r
+        if (!st->st_cur->ste_opt_lineno)\r
+            st->st_cur->ste_opt_lineno = s->lineno;\r
+        if (s->v.Exec.globals) {\r
+            st->st_cur->ste_unoptimized |= OPT_EXEC;\r
+            VISIT(st, expr, s->v.Exec.globals);\r
+            if (s->v.Exec.locals)\r
+                VISIT(st, expr, s->v.Exec.locals);\r
+        } else {\r
+            st->st_cur->ste_unoptimized |= OPT_BARE_EXEC;\r
+        }\r
+        break;\r
+    case Global_kind: {\r
+        int i;\r
+        asdl_seq *seq = s->v.Global.names;\r
+        for (i = 0; i < asdl_seq_LEN(seq); i++) {\r
+            identifier name = (identifier)asdl_seq_GET(seq, i);\r
+            char *c_name = PyString_AS_STRING(name);\r
+            long cur = symtable_lookup(st, name);\r
+            if (cur < 0)\r
+                return 0;\r
+            if (cur & (DEF_LOCAL | USE)) {\r
+                char buf[256];\r
+                if (cur & DEF_LOCAL)\r
+                    PyOS_snprintf(buf, sizeof(buf),\r
+                                  GLOBAL_AFTER_ASSIGN,\r
+                                  c_name);\r
+                else\r
+                    PyOS_snprintf(buf, sizeof(buf),\r
+                                  GLOBAL_AFTER_USE,\r
+                                  c_name);\r
+                if (!symtable_warn(st, buf, s->lineno))\r
+                    return 0;\r
+            }\r
+            if (!symtable_add_def(st, name, DEF_GLOBAL))\r
+                return 0;\r
+        }\r
+        break;\r
+    }\r
+    case Expr_kind:\r
+        VISIT(st, expr, s->v.Expr.value);\r
+        break;\r
+    case Pass_kind:\r
+    case Break_kind:\r
+    case Continue_kind:\r
+        /* nothing to do here */\r
+        break;\r
+    case With_kind:\r
+        VISIT(st, expr, s->v.With.context_expr);\r
+        if (s->v.With.optional_vars) {\r
+            VISIT(st, expr, s->v.With.optional_vars);\r
+        }\r
+        VISIT_SEQ(st, stmt, s->v.With.body);\r
+        break;\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+symtable_visit_expr(struct symtable *st, expr_ty e)\r
+{\r
+    switch (e->kind) {\r
+    case BoolOp_kind:\r
+        VISIT_SEQ(st, expr, e->v.BoolOp.values);\r
+        break;\r
+    case BinOp_kind:\r
+        VISIT(st, expr, e->v.BinOp.left);\r
+        VISIT(st, expr, e->v.BinOp.right);\r
+        break;\r
+    case UnaryOp_kind:\r
+        VISIT(st, expr, e->v.UnaryOp.operand);\r
+        break;\r
+    case Lambda_kind: {\r
+        if (!GET_IDENTIFIER(lambda))\r
+            return 0;\r
+        if (e->v.Lambda.args->defaults)\r
+            VISIT_SEQ(st, expr, e->v.Lambda.args->defaults);\r
+        if (!symtable_enter_block(st, lambda,\r
+                                  FunctionBlock, (void *)e, e->lineno))\r
+            return 0;\r
+        VISIT_IN_BLOCK(st, arguments, e->v.Lambda.args, (void*)e);\r
+        VISIT_IN_BLOCK(st, expr, e->v.Lambda.body, (void*)e);\r
+        if (!symtable_exit_block(st, (void *)e))\r
+            return 0;\r
+        break;\r
+    }\r
+    case IfExp_kind:\r
+        VISIT(st, expr, e->v.IfExp.test);\r
+        VISIT(st, expr, e->v.IfExp.body);\r
+        VISIT(st, expr, e->v.IfExp.orelse);\r
+        break;\r
+    case Dict_kind:\r
+        VISIT_SEQ(st, expr, e->v.Dict.keys);\r
+        VISIT_SEQ(st, expr, e->v.Dict.values);\r
+        break;\r
+    case Set_kind:\r
+        VISIT_SEQ(st, expr, e->v.Set.elts);\r
+        break;\r
+    case ListComp_kind:\r
+        VISIT(st, expr, e->v.ListComp.elt);\r
+        VISIT_SEQ(st, comprehension, e->v.ListComp.generators);\r
+        break;\r
+    case GeneratorExp_kind:\r
+        if (!symtable_visit_genexp(st, e))\r
+            return 0;\r
+        break;\r
+    case SetComp_kind:\r
+        if (!symtable_visit_setcomp(st, e))\r
+            return 0;\r
+        break;\r
+    case DictComp_kind:\r
+        if (!symtable_visit_dictcomp(st, e))\r
+            return 0;\r
+        break;\r
+    case Yield_kind:\r
+        if (e->v.Yield.value)\r
+            VISIT(st, expr, e->v.Yield.value);\r
+        st->st_cur->ste_generator = 1;\r
+        if (st->st_cur->ste_returns_value) {\r
+            PyErr_SetString(PyExc_SyntaxError,\r
+                RETURN_VAL_IN_GENERATOR);\r
+            PyErr_SyntaxLocation(st->st_filename,\r
+                         e->lineno);\r
+            return 0;\r
+        }\r
+        break;\r
+    case Compare_kind:\r
+        VISIT(st, expr, e->v.Compare.left);\r
+        VISIT_SEQ(st, expr, e->v.Compare.comparators);\r
+        break;\r
+    case Call_kind:\r
+        VISIT(st, expr, e->v.Call.func);\r
+        VISIT_SEQ(st, expr, e->v.Call.args);\r
+        VISIT_SEQ(st, keyword, e->v.Call.keywords);\r
+        if (e->v.Call.starargs)\r
+            VISIT(st, expr, e->v.Call.starargs);\r
+        if (e->v.Call.kwargs)\r
+            VISIT(st, expr, e->v.Call.kwargs);\r
+        break;\r
+    case Repr_kind:\r
+        VISIT(st, expr, e->v.Repr.value);\r
+        break;\r
+    case Num_kind:\r
+    case Str_kind:\r
+        /* Nothing to do here. */\r
+        break;\r
+    /* The following exprs can be assignment targets. */\r
+    case Attribute_kind:\r
+        VISIT(st, expr, e->v.Attribute.value);\r
+        break;\r
+    case Subscript_kind:\r
+        VISIT(st, expr, e->v.Subscript.value);\r
+        VISIT(st, slice, e->v.Subscript.slice);\r
+        break;\r
+    case Name_kind:\r
+        if (!symtable_add_def(st, e->v.Name.id,\r
+                              e->v.Name.ctx == Load ? USE : DEF_LOCAL))\r
+            return 0;\r
+        break;\r
+    /* child nodes of List and Tuple will have expr_context set */\r
+    case List_kind:\r
+        VISIT_SEQ(st, expr, e->v.List.elts);\r
+        break;\r
+    case Tuple_kind:\r
+        VISIT_SEQ(st, expr, e->v.Tuple.elts);\r
+        break;\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+symtable_implicit_arg(struct symtable *st, int pos)\r
+{\r
+    PyObject *id = PyString_FromFormat(".%d", pos);\r
+    if (id == NULL)\r
+        return 0;\r
+    if (!symtable_add_def(st, id, DEF_PARAM)) {\r
+        Py_DECREF(id);\r
+        return 0;\r
+    }\r
+    Py_DECREF(id);\r
+    return 1;\r
+}\r
+\r
+static int\r
+symtable_visit_params(struct symtable *st, asdl_seq *args, int toplevel)\r
+{\r
+    int i;\r
+\r
+    /* go through all the toplevel arguments first */\r
+    for (i = 0; i < asdl_seq_LEN(args); i++) {\r
+        expr_ty arg = (expr_ty)asdl_seq_GET(args, i);\r
+        if (arg->kind == Name_kind) {\r
+            assert(arg->v.Name.ctx == Param ||\r
+                   (arg->v.Name.ctx == Store && !toplevel));\r
+            if (!symtable_add_def(st, arg->v.Name.id, DEF_PARAM))\r
+                return 0;\r
+        }\r
+        else if (arg->kind == Tuple_kind) {\r
+            assert(arg->v.Tuple.ctx == Store);\r
+            if (toplevel) {\r
+                if (!symtable_implicit_arg(st, i))\r
+                    return 0;\r
+            }\r
+        }\r
+        else {\r
+            PyErr_SetString(PyExc_SyntaxError,\r
+                            "invalid expression in parameter list");\r
+            PyErr_SyntaxLocation(st->st_filename,\r
+                                 st->st_cur->ste_lineno);\r
+            return 0;\r
+        }\r
+    }\r
+\r
+    if (!toplevel) {\r
+        if (!symtable_visit_params_nested(st, args))\r
+            return 0;\r
+    }\r
+\r
+    return 1;\r
+}\r
+\r
+static int\r
+symtable_visit_params_nested(struct symtable *st, asdl_seq *args)\r
+{\r
+    int i;\r
+    for (i = 0; i < asdl_seq_LEN(args); i++) {\r
+        expr_ty arg = (expr_ty)asdl_seq_GET(args, i);\r
+        if (arg->kind == Tuple_kind &&\r
+            !symtable_visit_params(st, arg->v.Tuple.elts, 0))\r
+            return 0;\r
+    }\r
+\r
+    return 1;\r
+}\r
+\r
+static int\r
+symtable_visit_arguments(struct symtable *st, arguments_ty a)\r
+{\r
+    /* skip default arguments inside function block\r
+       XXX should ast be different?\r
+    */\r
+    if (a->args && !symtable_visit_params(st, a->args, 1))\r
+        return 0;\r
+    if (a->vararg) {\r
+        if (!symtable_add_def(st, a->vararg, DEF_PARAM))\r
+            return 0;\r
+        st->st_cur->ste_varargs = 1;\r
+    }\r
+    if (a->kwarg) {\r
+        if (!symtable_add_def(st, a->kwarg, DEF_PARAM))\r
+            return 0;\r
+        st->st_cur->ste_varkeywords = 1;\r
+    }\r
+    if (a->args && !symtable_visit_params_nested(st, a->args))\r
+        return 0;\r
+    return 1;\r
+}\r
+\r
+\r
+static int\r
+symtable_visit_excepthandler(struct symtable *st, excepthandler_ty eh)\r
+{\r
+    if (eh->v.ExceptHandler.type)\r
+        VISIT(st, expr, eh->v.ExceptHandler.type);\r
+    if (eh->v.ExceptHandler.name)\r
+        VISIT(st, expr, eh->v.ExceptHandler.name);\r
+    VISIT_SEQ(st, stmt, eh->v.ExceptHandler.body);\r
+    return 1;\r
+}\r
+\r
+\r
+static int\r
+symtable_visit_alias(struct symtable *st, alias_ty a)\r
+{\r
+    /* Compute store_name, the name actually bound by the import\r
+       operation.  It is different than a->name when a->name is a\r
+       dotted package name (e.g. spam.eggs)\r
+    */\r
+    PyObject *store_name;\r
+    PyObject *name = (a->asname == NULL) ? a->name : a->asname;\r
+    const char *base = PyString_AS_STRING(name);\r
+    char *dot = strchr(base, '.');\r
+    if (dot) {\r
+        store_name = PyString_FromStringAndSize(base, dot - base);\r
+        if (!store_name)\r
+            return 0;\r
+    }\r
+    else {\r
+        store_name = name;\r
+        Py_INCREF(store_name);\r
+    }\r
+    if (strcmp(PyString_AS_STRING(name), "*")) {\r
+        int r = symtable_add_def(st, store_name, DEF_IMPORT);\r
+        Py_DECREF(store_name);\r
+        return r;\r
+    }\r
+    else {\r
+        if (st->st_cur->ste_type != ModuleBlock) {\r
+        int lineno = st->st_cur->ste_lineno;\r
+        if (!symtable_warn(st, IMPORT_STAR_WARNING, lineno)) {\r
+            Py_DECREF(store_name);\r
+            return 0;\r
+        }\r
+        }\r
+        st->st_cur->ste_unoptimized |= OPT_IMPORT_STAR;\r
+        Py_DECREF(store_name);\r
+        return 1;\r
+    }\r
+}\r
+\r
+\r
+static int\r
+symtable_visit_comprehension(struct symtable *st, comprehension_ty lc)\r
+{\r
+    VISIT(st, expr, lc->target);\r
+    VISIT(st, expr, lc->iter);\r
+    VISIT_SEQ(st, expr, lc->ifs);\r
+    return 1;\r
+}\r
+\r
+\r
+static int\r
+symtable_visit_keyword(struct symtable *st, keyword_ty k)\r
+{\r
+    VISIT(st, expr, k->value);\r
+    return 1;\r
+}\r
+\r
+\r
+static int\r
+symtable_visit_slice(struct symtable *st, slice_ty s)\r
+{\r
+    switch (s->kind) {\r
+    case Slice_kind:\r
+        if (s->v.Slice.lower)\r
+            VISIT(st, expr, s->v.Slice.lower)\r
+        if (s->v.Slice.upper)\r
+            VISIT(st, expr, s->v.Slice.upper)\r
+        if (s->v.Slice.step)\r
+            VISIT(st, expr, s->v.Slice.step)\r
+        break;\r
+    case ExtSlice_kind:\r
+        VISIT_SEQ(st, slice, s->v.ExtSlice.dims)\r
+        break;\r
+    case Index_kind:\r
+        VISIT(st, expr, s->v.Index.value)\r
+        break;\r
+    case Ellipsis_kind:\r
+        break;\r
+    }\r
+    return 1;\r
+}\r
+\r
+static int\r
+symtable_new_tmpname(struct symtable *st)\r
+{\r
+    char tmpname[256];\r
+    identifier tmp;\r
+\r
+    PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",\r
+                  ++st->st_cur->ste_tmpname);\r
+    tmp = PyString_InternFromString(tmpname);\r
+    if (!tmp)\r
+        return 0;\r
+    if (!symtable_add_def(st, tmp, DEF_LOCAL))\r
+        return 0;\r
+    Py_DECREF(tmp);\r
+    return 1;\r
+}\r
+\r
+static int\r
+symtable_handle_comprehension(struct symtable *st, expr_ty e,\r
+                              identifier scope_name, asdl_seq *generators,\r
+                              expr_ty elt, expr_ty value)\r
+{\r
+    int is_generator = (e->kind == GeneratorExp_kind);\r
+    int needs_tmp = !is_generator;\r
+    comprehension_ty outermost = ((comprehension_ty)\r
+                                    asdl_seq_GET(generators, 0));\r
+    /* Outermost iterator is evaluated in current scope */\r
+    VISIT(st, expr, outermost->iter);\r
+    /* Create comprehension scope for the rest */\r
+    if (!scope_name ||\r
+        !symtable_enter_block(st, scope_name, FunctionBlock, (void *)e, 0)) {\r
+        return 0;\r
+    }\r
+    st->st_cur->ste_generator = is_generator;\r
+    /* Outermost iter is received as an argument */\r
+    if (!symtable_implicit_arg(st, 0)) {\r
+        symtable_exit_block(st, (void *)e);\r
+        return 0;\r
+    }\r
+    /* Allocate temporary name if needed */\r
+    if (needs_tmp && !symtable_new_tmpname(st)) {\r
+        symtable_exit_block(st, (void *)e);\r
+        return 0;\r
+    }\r
+    VISIT_IN_BLOCK(st, expr, outermost->target, (void*)e);\r
+    VISIT_SEQ_IN_BLOCK(st, expr, outermost->ifs, (void*)e);\r
+    VISIT_SEQ_TAIL_IN_BLOCK(st, comprehension,\r
+                            generators, 1, (void*)e);\r
+    if (value)\r
+        VISIT_IN_BLOCK(st, expr, value, (void*)e);\r
+    VISIT_IN_BLOCK(st, expr, elt, (void*)e);\r
+    return symtable_exit_block(st, (void *)e);\r
+}\r
+\r
+static int\r
+symtable_visit_genexp(struct symtable *st, expr_ty e)\r
+{\r
+    return symtable_handle_comprehension(st, e, GET_IDENTIFIER(genexpr),\r
+                                         e->v.GeneratorExp.generators,\r
+                                         e->v.GeneratorExp.elt, NULL);\r
+}\r
+\r
+static int\r
+symtable_visit_setcomp(struct symtable *st, expr_ty e)\r
+{\r
+    return symtable_handle_comprehension(st, e, GET_IDENTIFIER(setcomp),\r
+                                         e->v.SetComp.generators,\r
+                                         e->v.SetComp.elt, NULL);\r
+}\r
+\r
+static int\r
+symtable_visit_dictcomp(struct symtable *st, expr_ty e)\r
+{\r
+    return symtable_handle_comprehension(st, e, GET_IDENTIFIER(dictcomp),\r
+                                         e->v.DictComp.generators,\r
+                                         e->v.DictComp.key,\r
+                                         e->v.DictComp.value);\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/sysmodule.c b/AppPkg/Applications/Python/Python-2.7.10/Python/sysmodule.c
new file mode 100644 (file)
index 0000000..36e81b4
--- /dev/null
@@ -0,0 +1,1800 @@
+\r
+/* System module */\r
+\r
+/*\r
+Various bits of information used by the interpreter are collected in\r
+module 'sys'.\r
+Function member:\r
+- exit(sts): raise SystemExit\r
+Data members:\r
+- stdin, stdout, stderr: standard file objects\r
+- modules: the table of modules (dictionary)\r
+- path: module search path (list of strings)\r
+- argv: script arguments (list of strings)\r
+- ps1, ps2: optional primary and secondary prompts (strings)\r
+*/\r
+\r
+#include "Python.h"\r
+#include "structseq.h"\r
+#include "code.h"\r
+#include "frameobject.h"\r
+#include "eval.h"\r
+\r
+#include "osdefs.h"\r
+\r
+#ifdef MS_WINDOWS\r
+#define WIN32_LEAN_AND_MEAN\r
+#include "windows.h"\r
+#endif /* MS_WINDOWS */\r
+\r
+#ifdef MS_COREDLL\r
+extern void *PyWin_DLLhModule;\r
+/* A string loaded from the DLL at startup: */\r
+extern const char *PyWin_DLLVersionString;\r
+#endif\r
+\r
+#ifdef __VMS\r
+#include <unixlib.h>\r
+#endif\r
+\r
+#ifdef MS_WINDOWS\r
+#include <windows.h>\r
+#endif\r
+\r
+#ifdef HAVE_LANGINFO_H\r
+#include <locale.h>\r
+#include <langinfo.h>\r
+#endif\r
+\r
+PyObject *\r
+PySys_GetObject(char *name)\r
+{\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    PyObject *sd = tstate->interp->sysdict;\r
+    if (sd == NULL)\r
+        return NULL;\r
+    return PyDict_GetItemString(sd, name);\r
+}\r
+\r
+FILE *\r
+PySys_GetFile(char *name, FILE *def)\r
+{\r
+    FILE *fp = NULL;\r
+    PyObject *v = PySys_GetObject(name);\r
+    if (v != NULL && PyFile_Check(v))\r
+        fp = PyFile_AsFile(v);\r
+    if (fp == NULL)\r
+        fp = def;\r
+    return fp;\r
+}\r
+\r
+int\r
+PySys_SetObject(char *name, PyObject *v)\r
+{\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    PyObject *sd = tstate->interp->sysdict;\r
+    if (v == NULL) {\r
+        if (PyDict_GetItemString(sd, name) == NULL)\r
+            return 0;\r
+        else\r
+            return PyDict_DelItemString(sd, name);\r
+    }\r
+    else\r
+        return PyDict_SetItemString(sd, name, v);\r
+}\r
+\r
+static PyObject *\r
+sys_displayhook(PyObject *self, PyObject *o)\r
+{\r
+    PyObject *outf;\r
+    PyInterpreterState *interp = PyThreadState_GET()->interp;\r
+    PyObject *modules = interp->modules;\r
+    PyObject *builtins = PyDict_GetItemString(modules, "__builtin__");\r
+\r
+    if (builtins == NULL) {\r
+        PyErr_SetString(PyExc_RuntimeError, "lost __builtin__");\r
+        return NULL;\r
+    }\r
+\r
+    /* Print value except if None */\r
+    /* After printing, also assign to '_' */\r
+    /* Before, set '_' to None to avoid recursion */\r
+    if (o == Py_None) {\r
+        Py_INCREF(Py_None);\r
+        return Py_None;\r
+    }\r
+    if (PyObject_SetAttrString(builtins, "_", Py_None) != 0)\r
+        return NULL;\r
+    if (Py_FlushLine() != 0)\r
+        return NULL;\r
+    outf = PySys_GetObject("stdout");\r
+    if (outf == NULL) {\r
+        PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");\r
+        return NULL;\r
+    }\r
+    if (PyFile_WriteObject(o, outf, 0) != 0)\r
+        return NULL;\r
+    PyFile_SoftSpace(outf, 1);\r
+    if (Py_FlushLine() != 0)\r
+        return NULL;\r
+    if (PyObject_SetAttrString(builtins, "_", o) != 0)\r
+        return NULL;\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+PyDoc_STRVAR(displayhook_doc,\r
+"displayhook(object) -> None\n"\r
+"\n"\r
+"Print an object to sys.stdout and also save it in __builtin__._\n"\r
+);\r
+\r
+static PyObject *\r
+sys_excepthook(PyObject* self, PyObject* args)\r
+{\r
+    PyObject *exc, *value, *tb;\r
+    if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb))\r
+        return NULL;\r
+    PyErr_Display(exc, value, tb);\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+PyDoc_STRVAR(excepthook_doc,\r
+"excepthook(exctype, value, traceback) -> None\n"\r
+"\n"\r
+"Handle an exception by displaying it with a traceback on sys.stderr.\n"\r
+);\r
+\r
+static PyObject *\r
+sys_exc_info(PyObject *self, PyObject *noargs)\r
+{\r
+    PyThreadState *tstate;\r
+    tstate = PyThreadState_GET();\r
+    return Py_BuildValue(\r
+        "(OOO)",\r
+        tstate->exc_type != NULL ? tstate->exc_type : Py_None,\r
+        tstate->exc_value != NULL ? tstate->exc_value : Py_None,\r
+        tstate->exc_traceback != NULL ?\r
+            tstate->exc_traceback : Py_None);\r
+}\r
+\r
+PyDoc_STRVAR(exc_info_doc,\r
+"exc_info() -> (type, value, traceback)\n\\r
+\n\\r
+Return information about the most recent exception caught by an except\n\\r
+clause in the current stack frame or in an older stack frame."\r
+);\r
+\r
+static PyObject *\r
+sys_exc_clear(PyObject *self, PyObject *noargs)\r
+{\r
+    PyThreadState *tstate;\r
+    PyObject *tmp_type, *tmp_value, *tmp_tb;\r
+\r
+    if (PyErr_WarnPy3k("sys.exc_clear() not supported in 3.x; "\r
+                       "use except clauses", 1) < 0)\r
+        return NULL;\r
+\r
+    tstate = PyThreadState_GET();\r
+    tmp_type = tstate->exc_type;\r
+    tmp_value = tstate->exc_value;\r
+    tmp_tb = tstate->exc_traceback;\r
+    tstate->exc_type = NULL;\r
+    tstate->exc_value = NULL;\r
+    tstate->exc_traceback = NULL;\r
+    Py_XDECREF(tmp_type);\r
+    Py_XDECREF(tmp_value);\r
+    Py_XDECREF(tmp_tb);\r
+    /* For b/w compatibility */\r
+    PySys_SetObject("exc_type", Py_None);\r
+    PySys_SetObject("exc_value", Py_None);\r
+    PySys_SetObject("exc_traceback", Py_None);\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+PyDoc_STRVAR(exc_clear_doc,\r
+"exc_clear() -> None\n\\r
+\n\\r
+Clear global information on the current exception.  Subsequent calls to\n\\r
+exc_info() will return (None,None,None) until another exception is raised\n\\r
+in the current thread or the execution stack returns to a frame where\n\\r
+another exception is being handled."\r
+);\r
+\r
+static PyObject *\r
+sys_exit(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *exit_code = 0;\r
+    if (!PyArg_UnpackTuple(args, "exit", 0, 1, &exit_code))\r
+        return NULL;\r
+    /* Raise SystemExit so callers may catch it or clean up. */\r
+    PyErr_SetObject(PyExc_SystemExit, exit_code);\r
+    return NULL;\r
+}\r
+\r
+PyDoc_STRVAR(exit_doc,\r
+"exit([status])\n\\r
+\n\\r
+Exit the interpreter by raising SystemExit(status).\n\\r
+If the status is omitted or None, it defaults to zero (i.e., success).\n\\r
+If the status is an integer, it will be used as the system exit status.\n\\r
+If it is another kind of object, it will be printed and the system\n\\r
+exit status will be one (i.e., failure)."\r
+);\r
+\r
+#ifdef Py_USING_UNICODE\r
+\r
+static PyObject *\r
+sys_getdefaultencoding(PyObject *self)\r
+{\r
+    return PyString_FromString(PyUnicode_GetDefaultEncoding());\r
+}\r
+\r
+PyDoc_STRVAR(getdefaultencoding_doc,\r
+"getdefaultencoding() -> string\n\\r
+\n\\r
+Return the current default string encoding used by the Unicode \n\\r
+implementation."\r
+);\r
+\r
+static PyObject *\r
+sys_setdefaultencoding(PyObject *self, PyObject *args)\r
+{\r
+    char *encoding;\r
+    if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding))\r
+        return NULL;\r
+    if (PyUnicode_SetDefaultEncoding(encoding))\r
+        return NULL;\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+PyDoc_STRVAR(setdefaultencoding_doc,\r
+"setdefaultencoding(encoding)\n\\r
+\n\\r
+Set the current default string encoding used by the Unicode implementation."\r
+);\r
+\r
+static PyObject *\r
+sys_getfilesystemencoding(PyObject *self)\r
+{\r
+    if (Py_FileSystemDefaultEncoding)\r
+        return PyString_FromString(Py_FileSystemDefaultEncoding);\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+PyDoc_STRVAR(getfilesystemencoding_doc,\r
+"getfilesystemencoding() -> string\n\\r
+\n\\r
+Return the encoding used to convert Unicode filenames in\n\\r
+operating system filenames."\r
+);\r
+\r
+#endif\r
+\r
+/*\r
+ * Cached interned string objects used for calling the profile and\r
+ * trace functions.  Initialized by trace_init().\r
+ */\r
+static PyObject *whatstrings[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};\r
+\r
+static int\r
+trace_init(void)\r
+{\r
+    static char *whatnames[7] = {"call", "exception", "line", "return",\r
+                                    "c_call", "c_exception", "c_return"};\r
+    PyObject *name;\r
+    int i;\r
+    for (i = 0; i < 7; ++i) {\r
+        if (whatstrings[i] == NULL) {\r
+            name = PyString_InternFromString(whatnames[i]);\r
+            if (name == NULL)\r
+                return -1;\r
+            whatstrings[i] = name;\r
+        }\r
+    }\r
+    return 0;\r
+}\r
+\r
+\r
+static PyObject *\r
+call_trampoline(PyThreadState *tstate, PyObject* callback,\r
+                PyFrameObject *frame, int what, PyObject *arg)\r
+{\r
+    PyObject *args = PyTuple_New(3);\r
+    PyObject *whatstr;\r
+    PyObject *result;\r
+\r
+    if (args == NULL)\r
+        return NULL;\r
+    Py_INCREF(frame);\r
+    whatstr = whatstrings[what];\r
+    Py_INCREF(whatstr);\r
+    if (arg == NULL)\r
+        arg = Py_None;\r
+    Py_INCREF(arg);\r
+    PyTuple_SET_ITEM(args, 0, (PyObject *)frame);\r
+    PyTuple_SET_ITEM(args, 1, whatstr);\r
+    PyTuple_SET_ITEM(args, 2, arg);\r
+\r
+    /* call the Python-level function */\r
+    PyFrame_FastToLocals(frame);\r
+    result = PyEval_CallObject(callback, args);\r
+    PyFrame_LocalsToFast(frame, 1);\r
+    if (result == NULL)\r
+        PyTraceBack_Here(frame);\r
+\r
+    /* cleanup */\r
+    Py_DECREF(args);\r
+    return result;\r
+}\r
+\r
+static int\r
+profile_trampoline(PyObject *self, PyFrameObject *frame,\r
+                   int what, PyObject *arg)\r
+{\r
+    PyThreadState *tstate = frame->f_tstate;\r
+    PyObject *result;\r
+\r
+    if (arg == NULL)\r
+        arg = Py_None;\r
+    result = call_trampoline(tstate, self, frame, what, arg);\r
+    if (result == NULL) {\r
+        PyEval_SetProfile(NULL, NULL);\r
+        return -1;\r
+    }\r
+    Py_DECREF(result);\r
+    return 0;\r
+}\r
+\r
+static int\r
+trace_trampoline(PyObject *self, PyFrameObject *frame,\r
+                 int what, PyObject *arg)\r
+{\r
+    PyThreadState *tstate = frame->f_tstate;\r
+    PyObject *callback;\r
+    PyObject *result;\r
+\r
+    if (what == PyTrace_CALL)\r
+        callback = self;\r
+    else\r
+        callback = frame->f_trace;\r
+    if (callback == NULL)\r
+        return 0;\r
+    result = call_trampoline(tstate, callback, frame, what, arg);\r
+    if (result == NULL) {\r
+        PyEval_SetTrace(NULL, NULL);\r
+        Py_CLEAR(frame->f_trace);\r
+        return -1;\r
+    }\r
+    if (result != Py_None) {\r
+        PyObject *temp = frame->f_trace;\r
+        frame->f_trace = NULL;\r
+        Py_XDECREF(temp);\r
+        frame->f_trace = result;\r
+    }\r
+    else {\r
+        Py_DECREF(result);\r
+    }\r
+    return 0;\r
+}\r
+\r
+static PyObject *\r
+sys_settrace(PyObject *self, PyObject *args)\r
+{\r
+    if (trace_init() == -1)\r
+        return NULL;\r
+    if (args == Py_None)\r
+        PyEval_SetTrace(NULL, NULL);\r
+    else\r
+        PyEval_SetTrace(trace_trampoline, args);\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+PyDoc_STRVAR(settrace_doc,\r
+"settrace(function)\n\\r
+\n\\r
+Set the global debug tracing function.  It will be called on each\n\\r
+function call.  See the debugger chapter in the library manual."\r
+);\r
+\r
+static PyObject *\r
+sys_gettrace(PyObject *self, PyObject *args)\r
+{\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    PyObject *temp = tstate->c_traceobj;\r
+\r
+    if (temp == NULL)\r
+        temp = Py_None;\r
+    Py_INCREF(temp);\r
+    return temp;\r
+}\r
+\r
+PyDoc_STRVAR(gettrace_doc,\r
+"gettrace()\n\\r
+\n\\r
+Return the global debug tracing function set with sys.settrace.\n\\r
+See the debugger chapter in the library manual."\r
+);\r
+\r
+static PyObject *\r
+sys_setprofile(PyObject *self, PyObject *args)\r
+{\r
+    if (trace_init() == -1)\r
+        return NULL;\r
+    if (args == Py_None)\r
+        PyEval_SetProfile(NULL, NULL);\r
+    else\r
+        PyEval_SetProfile(profile_trampoline, args);\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+PyDoc_STRVAR(setprofile_doc,\r
+"setprofile(function)\n\\r
+\n\\r
+Set the profiling function.  It will be called on each function call\n\\r
+and return.  See the profiler chapter in the library manual."\r
+);\r
+\r
+static PyObject *\r
+sys_getprofile(PyObject *self, PyObject *args)\r
+{\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    PyObject *temp = tstate->c_profileobj;\r
+\r
+    if (temp == NULL)\r
+        temp = Py_None;\r
+    Py_INCREF(temp);\r
+    return temp;\r
+}\r
+\r
+PyDoc_STRVAR(getprofile_doc,\r
+"getprofile()\n\\r
+\n\\r
+Return the profiling function set with sys.setprofile.\n\\r
+See the profiler chapter in the library manual."\r
+);\r
+\r
+static PyObject *\r
+sys_setcheckinterval(PyObject *self, PyObject *args)\r
+{\r
+    if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_Py_CheckInterval))\r
+        return NULL;\r
+    _Py_Ticker = _Py_CheckInterval;\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+PyDoc_STRVAR(setcheckinterval_doc,\r
+"setcheckinterval(n)\n\\r
+\n\\r
+Tell the Python interpreter to check for asynchronous events every\n\\r
+n instructions.  This also affects how often thread switches occur."\r
+);\r
+\r
+static PyObject *\r
+sys_getcheckinterval(PyObject *self, PyObject *args)\r
+{\r
+    return PyInt_FromLong(_Py_CheckInterval);\r
+}\r
+\r
+PyDoc_STRVAR(getcheckinterval_doc,\r
+"getcheckinterval() -> current check interval; see setcheckinterval()."\r
+);\r
+\r
+#ifdef WITH_TSC\r
+static PyObject *\r
+sys_settscdump(PyObject *self, PyObject *args)\r
+{\r
+    int bool;\r
+    PyThreadState *tstate = PyThreadState_Get();\r
+\r
+    if (!PyArg_ParseTuple(args, "i:settscdump", &bool))\r
+        return NULL;\r
+    if (bool)\r
+        tstate->interp->tscdump = 1;\r
+    else\r
+        tstate->interp->tscdump = 0;\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+\r
+}\r
+\r
+PyDoc_STRVAR(settscdump_doc,\r
+"settscdump(bool)\n\\r
+\n\\r
+If true, tell the Python interpreter to dump VM measurements to\n\\r
+stderr.  If false, turn off dump.  The measurements are based on the\n\\r
+processor's time-stamp counter."\r
+);\r
+#endif /* TSC */\r
+\r
+static PyObject *\r
+sys_setrecursionlimit(PyObject *self, PyObject *args)\r
+{\r
+    int new_limit;\r
+    if (!PyArg_ParseTuple(args, "i:setrecursionlimit", &new_limit))\r
+        return NULL;\r
+    if (new_limit <= 0) {\r
+        PyErr_SetString(PyExc_ValueError,\r
+                        "recursion limit must be positive");\r
+        return NULL;\r
+    }\r
+    Py_SetRecursionLimit(new_limit);\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+PyDoc_STRVAR(setrecursionlimit_doc,\r
+"setrecursionlimit(n)\n\\r
+\n\\r
+Set the maximum depth of the Python interpreter stack to n.  This\n\\r
+limit prevents infinite recursion from causing an overflow of the C\n\\r
+stack and crashing Python.  The highest possible limit is platform-\n\\r
+dependent."\r
+);\r
+\r
+static PyObject *\r
+sys_getrecursionlimit(PyObject *self)\r
+{\r
+    return PyInt_FromLong(Py_GetRecursionLimit());\r
+}\r
+\r
+PyDoc_STRVAR(getrecursionlimit_doc,\r
+"getrecursionlimit()\n\\r
+\n\\r
+Return the current value of the recursion limit, the maximum depth\n\\r
+of the Python interpreter stack.  This limit prevents infinite\n\\r
+recursion from causing an overflow of the C stack and crashing Python."\r
+);\r
+\r
+#ifdef MS_WINDOWS\r
+PyDoc_STRVAR(getwindowsversion_doc,\r
+"getwindowsversion()\n\\r
+\n\\r
+Return information about the running version of Windows as a named tuple.\n\\r
+The members are named: major, minor, build, platform, service_pack,\n\\r
+service_pack_major, service_pack_minor, suite_mask, and product_type. For\n\\r
+backward compatibility, only the first 5 items are available by indexing.\n\\r
+All elements are numbers, except service_pack which is a string. Platform\n\\r
+may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP/Vista/7,\n\\r
+3 for Windows CE. Product_type may be 1 for a workstation, 2 for a domain\n\\r
+controller, 3 for a server."\r
+);\r
+\r
+static PyTypeObject WindowsVersionType = {0, 0, 0, 0, 0, 0};\r
+\r
+static PyStructSequence_Field windows_version_fields[] = {\r
+    {"major", "Major version number"},\r
+    {"minor", "Minor version number"},\r
+    {"build", "Build number"},\r
+    {"platform", "Operating system platform"},\r
+    {"service_pack", "Latest Service Pack installed on the system"},\r
+    {"service_pack_major", "Service Pack major version number"},\r
+    {"service_pack_minor", "Service Pack minor version number"},\r
+    {"suite_mask", "Bit mask identifying available product suites"},\r
+    {"product_type", "System product type"},\r
+    {0}\r
+};\r
+\r
+static PyStructSequence_Desc windows_version_desc = {\r
+    "sys.getwindowsversion",  /* name */\r
+    getwindowsversion_doc,    /* doc */\r
+    windows_version_fields,   /* fields */\r
+    5                         /* For backward compatibility,\r
+                                 only the first 5 items are accessible\r
+                                 via indexing, the rest are name only */\r
+};\r
+\r
+static PyObject *\r
+sys_getwindowsversion(PyObject *self)\r
+{\r
+    PyObject *version;\r
+    int pos = 0;\r
+    OSVERSIONINFOEX ver;\r
+    ver.dwOSVersionInfoSize = sizeof(ver);\r
+    if (!GetVersionEx((OSVERSIONINFO*) &ver))\r
+        return PyErr_SetFromWindowsErr(0);\r
+\r
+    version = PyStructSequence_New(&WindowsVersionType);\r
+    if (version == NULL)\r
+        return NULL;\r
+\r
+    PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.dwMajorVersion));\r
+    PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.dwMinorVersion));\r
+    PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.dwBuildNumber));\r
+    PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.dwPlatformId));\r
+    PyStructSequence_SET_ITEM(version, pos++, PyString_FromString(ver.szCSDVersion));\r
+    PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wServicePackMajor));\r
+    PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wServicePackMinor));\r
+    PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wSuiteMask));\r
+    PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wProductType));\r
+\r
+    if (PyErr_Occurred()) {\r
+        Py_DECREF(version);\r
+        return NULL;\r
+    }\r
+    return version;\r
+}\r
+\r
+#endif /* MS_WINDOWS */\r
+\r
+#ifdef HAVE_DLOPEN\r
+static PyObject *\r
+sys_setdlopenflags(PyObject *self, PyObject *args)\r
+{\r
+    int new_val;\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    if (!PyArg_ParseTuple(args, "i:setdlopenflags", &new_val))\r
+        return NULL;\r
+    if (!tstate)\r
+        return NULL;\r
+    tstate->interp->dlopenflags = new_val;\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+\r
+PyDoc_STRVAR(setdlopenflags_doc,\r
+"setdlopenflags(n) -> None\n\\r
+\n\\r
+Set the flags used by the interpreter for dlopen calls, such as when the\n\\r
+interpreter loads extension modules.  Among other things, this will enable\n\\r
+a lazy resolving of symbols when importing a module, if called as\n\\r
+sys.setdlopenflags(0).  To share symbols across extension modules, call as\n\\r
+sys.setdlopenflags(ctypes.RTLD_GLOBAL).  Symbolic names for the flag modules\n\\r
+can be either found in the ctypes module, or in the DLFCN module. If DLFCN\n\\r
+is not available, it can be generated from /usr/include/dlfcn.h using the\n\\r
+h2py script.");\r
+\r
+static PyObject *\r
+sys_getdlopenflags(PyObject *self, PyObject *args)\r
+{\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    if (!tstate)\r
+        return NULL;\r
+    return PyInt_FromLong(tstate->interp->dlopenflags);\r
+}\r
+\r
+PyDoc_STRVAR(getdlopenflags_doc,\r
+"getdlopenflags() -> int\n\\r
+\n\\r
+Return the current value of the flags that are used for dlopen calls.\n\\r
+The flag constants are defined in the ctypes and DLFCN modules.");\r
+\r
+#endif  /* HAVE_DLOPEN */\r
+\r
+#ifdef USE_MALLOPT\r
+/* Link with -lmalloc (or -lmpc) on an SGI */\r
+#include <malloc.h>\r
+\r
+static PyObject *\r
+sys_mdebug(PyObject *self, PyObject *args)\r
+{\r
+    int flag;\r
+    if (!PyArg_ParseTuple(args, "i:mdebug", &flag))\r
+        return NULL;\r
+    mallopt(M_DEBUG, flag);\r
+    Py_INCREF(Py_None);\r
+    return Py_None;\r
+}\r
+#endif /* USE_MALLOPT */\r
+\r
+size_t\r
+_PySys_GetSizeOf(PyObject *o)\r
+{\r
+    static PyObject *str__sizeof__ = NULL;\r
+    PyObject *res = NULL;\r
+    Py_ssize_t size;\r
+\r
+    /* Make sure the type is initialized. float gets initialized late */\r
+    if (PyType_Ready(Py_TYPE(o)) < 0)\r
+        return (size_t)-1;\r
+\r
+    /* Instance of old-style class */\r
+    if (PyInstance_Check(o))\r
+        size = PyInstance_Type.tp_basicsize;\r
+    /* all other objects */\r
+    else {\r
+        PyObject *method = _PyObject_LookupSpecial(o, "__sizeof__",\r
+                                                   &str__sizeof__);\r
+        if (method == NULL) {\r
+            if (!PyErr_Occurred())\r
+                PyErr_Format(PyExc_TypeError,\r
+                             "Type %.100s doesn't define __sizeof__",\r
+                             Py_TYPE(o)->tp_name);\r
+        }\r
+        else {\r
+            res = PyObject_CallFunctionObjArgs(method, NULL);\r
+            Py_DECREF(method);\r
+        }\r
+\r
+        if (res == NULL)\r
+            return (size_t)-1;\r
+\r
+        size = (size_t)PyInt_AsSsize_t(res);\r
+        Py_DECREF(res);\r
+        if (size == -1 && PyErr_Occurred())\r
+            return (size_t)-1;\r
+    }\r
+\r
+    if (size < 0) {\r
+        PyErr_SetString(PyExc_ValueError, "__sizeof__() should return >= 0");\r
+        return (size_t)-1;\r
+    }\r
+\r
+    /* add gc_head size */\r
+    if (PyObject_IS_GC(o))\r
+        return ((size_t)size) + sizeof(PyGC_Head);\r
+    return (size_t)size;\r
+}\r
+\r
+static PyObject *\r
+sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds)\r
+{\r
+    static char *kwlist[] = {"object", "default", 0};\r
+    size_t size;\r
+    PyObject *o, *dflt = NULL;\r
+\r
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof",\r
+                                     kwlist, &o, &dflt))\r
+        return NULL;\r
+\r
+    size = _PySys_GetSizeOf(o);\r
+\r
+    if (size == (size_t)-1 && PyErr_Occurred()) {\r
+        /* Has a default value been given */\r
+        if (dflt != NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {\r
+            PyErr_Clear();\r
+            Py_INCREF(dflt);\r
+            return dflt;\r
+        }\r
+        else\r
+            return NULL;\r
+    }\r
+\r
+    return PyInt_FromSize_t(size);\r
+}\r
+\r
+PyDoc_STRVAR(getsizeof_doc,\r
+"getsizeof(object, default) -> int\n\\r
+\n\\r
+Return the size of object in bytes.");\r
+\r
+static PyObject *\r
+sys_getrefcount(PyObject *self, PyObject *arg)\r
+{\r
+    return PyInt_FromSsize_t(arg->ob_refcnt);\r
+}\r
+\r
+#ifdef Py_REF_DEBUG\r
+static PyObject *\r
+sys_gettotalrefcount(PyObject *self)\r
+{\r
+    return PyInt_FromSsize_t(_Py_GetRefTotal());\r
+}\r
+#endif /* Py_REF_DEBUG */\r
+\r
+PyDoc_STRVAR(getrefcount_doc,\r
+"getrefcount(object) -> integer\n\\r
+\n\\r
+Return the reference count of object.  The count returned is generally\n\\r
+one higher than you might expect, because it includes the (temporary)\n\\r
+reference as an argument to getrefcount()."\r
+);\r
+\r
+#ifdef COUNT_ALLOCS\r
+static PyObject *\r
+sys_getcounts(PyObject *self)\r
+{\r
+    extern PyObject *get_counts(void);\r
+\r
+    return get_counts();\r
+}\r
+#endif\r
+\r
+PyDoc_STRVAR(getframe_doc,\r
+"_getframe([depth]) -> frameobject\n\\r
+\n\\r
+Return a frame object from the call stack.  If optional integer depth is\n\\r
+given, return the frame object that many calls below the top of the stack.\n\\r
+If that is deeper than the call stack, ValueError is raised.  The default\n\\r
+for depth is zero, returning the frame at the top of the call stack.\n\\r
+\n\\r
+This function should be used for internal and specialized\n\\r
+purposes only."\r
+);\r
+\r
+static PyObject *\r
+sys_getframe(PyObject *self, PyObject *args)\r
+{\r
+    PyFrameObject *f = PyThreadState_GET()->frame;\r
+    int depth = -1;\r
+\r
+    if (!PyArg_ParseTuple(args, "|i:_getframe", &depth))\r
+        return NULL;\r
+\r
+    while (depth > 0 && f != NULL) {\r
+        f = f->f_back;\r
+        --depth;\r
+    }\r
+    if (f == NULL) {\r
+        PyErr_SetString(PyExc_ValueError,\r
+                        "call stack is not deep enough");\r
+        return NULL;\r
+    }\r
+    Py_INCREF(f);\r
+    return (PyObject*)f;\r
+}\r
+\r
+PyDoc_STRVAR(current_frames_doc,\r
+"_current_frames() -> dictionary\n\\r
+\n\\r
+Return a dictionary mapping each current thread T's thread id to T's\n\\r
+current stack frame.\n\\r
+\n\\r
+This function should be used for specialized purposes only."\r
+);\r
+\r
+static PyObject *\r
+sys_current_frames(PyObject *self, PyObject *noargs)\r
+{\r
+    return _PyThread_CurrentFrames();\r
+}\r
+\r
+PyDoc_STRVAR(call_tracing_doc,\r
+"call_tracing(func, args) -> object\n\\r
+\n\\r
+Call func(*args), while tracing is enabled.  The tracing state is\n\\r
+saved, and restored afterwards.  This is intended to be called from\n\\r
+a debugger from a checkpoint, to recursively debug some other code."\r
+);\r
+\r
+static PyObject *\r
+sys_call_tracing(PyObject *self, PyObject *args)\r
+{\r
+    PyObject *func, *funcargs;\r
+    if (!PyArg_ParseTuple(args, "OO!:call_tracing", &func, &PyTuple_Type, &funcargs))\r
+        return NULL;\r
+    return _PyEval_CallTracing(func, funcargs);\r
+}\r
+\r
+PyDoc_STRVAR(callstats_doc,\r
+"callstats() -> tuple of integers\n\\r
+\n\\r
+Return a tuple of function call statistics, if CALL_PROFILE was defined\n\\r
+when Python was built.  Otherwise, return None.\n\\r
+\n\\r
+When enabled, this function returns detailed, implementation-specific\n\\r
+details about the number of function calls executed. The return value is\n\\r
+a 11-tuple where the entries in the tuple are counts of:\n\\r
+0. all function calls\n\\r
+1. calls to PyFunction_Type objects\n\\r
+2. PyFunction calls that do not create an argument tuple\n\\r
+3. PyFunction calls that do not create an argument tuple\n\\r
+   and bypass PyEval_EvalCodeEx()\n\\r
+4. PyMethod calls\n\\r
+5. PyMethod calls on bound methods\n\\r
+6. PyType calls\n\\r
+7. PyCFunction calls\n\\r
+8. generator calls\n\\r
+9. All other calls\n\\r
+10. Number of stack pops performed by call_function()"\r
+);\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifdef Py_TRACE_REFS\r
+/* Defined in objects.c because it uses static globals if that file */\r
+extern PyObject *_Py_GetObjects(PyObject *, PyObject *);\r
+#endif\r
+\r
+#ifdef DYNAMIC_EXECUTION_PROFILE\r
+/* Defined in ceval.c because it uses static globals if that file */\r
+extern PyObject *_Py_GetDXProfile(PyObject *,  PyObject *);\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+static PyObject *\r
+sys_clear_type_cache(PyObject* self, PyObject* args)\r
+{\r
+    PyType_ClearCache();\r
+    Py_RETURN_NONE;\r
+}\r
+\r
+PyDoc_STRVAR(sys_clear_type_cache__doc__,\r
+"_clear_type_cache() -> None\n\\r
+Clear the internal type lookup cache.");\r
+\r
+\r
+static PyMethodDef sys_methods[] = {\r
+    /* Might as well keep this in alphabetic order */\r
+    {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,\r
+     callstats_doc},\r
+    {"_clear_type_cache",       sys_clear_type_cache,     METH_NOARGS,\r
+     sys_clear_type_cache__doc__},\r
+    {"_current_frames", sys_current_frames, METH_NOARGS,\r
+     current_frames_doc},\r
+    {"displayhook",     sys_displayhook, METH_O, displayhook_doc},\r
+    {"exc_info",        sys_exc_info, METH_NOARGS, exc_info_doc},\r
+    {"exc_clear",       sys_exc_clear, METH_NOARGS, exc_clear_doc},\r
+    {"excepthook",      sys_excepthook, METH_VARARGS, excepthook_doc},\r
+    {"exit",            sys_exit, METH_VARARGS, exit_doc},\r
+#ifdef Py_USING_UNICODE\r
+    {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,\r
+     METH_NOARGS, getdefaultencoding_doc},\r
+#endif\r
+#ifdef HAVE_DLOPEN\r
+    {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,\r
+     getdlopenflags_doc},\r
+#endif\r
+#ifdef COUNT_ALLOCS\r
+    {"getcounts",       (PyCFunction)sys_getcounts, METH_NOARGS},\r
+#endif\r
+#ifdef DYNAMIC_EXECUTION_PROFILE\r
+    {"getdxp",          _Py_GetDXProfile, METH_VARARGS},\r
+#endif\r
+#ifdef Py_USING_UNICODE\r
+    {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding,\r
+     METH_NOARGS, getfilesystemencoding_doc},\r
+#endif\r
+#ifdef Py_TRACE_REFS\r
+    {"getobjects",      _Py_GetObjects, METH_VARARGS},\r
+#endif\r
+#ifdef Py_REF_DEBUG\r
+    {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS},\r
+#endif\r
+    {"getrefcount",     (PyCFunction)sys_getrefcount, METH_O, getrefcount_doc},\r
+    {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS,\r
+     getrecursionlimit_doc},\r
+    {"getsizeof",   (PyCFunction)sys_getsizeof,\r
+     METH_VARARGS | METH_KEYWORDS, getsizeof_doc},\r
+    {"_getframe", sys_getframe, METH_VARARGS, getframe_doc},\r
+#ifdef MS_WINDOWS\r
+    {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS,\r
+     getwindowsversion_doc},\r
+#endif /* MS_WINDOWS */\r
+#ifdef USE_MALLOPT\r
+    {"mdebug",          sys_mdebug, METH_VARARGS},\r
+#endif\r
+#ifdef Py_USING_UNICODE\r
+    {"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS,\r
+     setdefaultencoding_doc},\r
+#endif\r
+    {"setcheckinterval",        sys_setcheckinterval, METH_VARARGS,\r
+     setcheckinterval_doc},\r
+    {"getcheckinterval",        sys_getcheckinterval, METH_NOARGS,\r
+     getcheckinterval_doc},\r
+#ifdef HAVE_DLOPEN\r
+    {"setdlopenflags", sys_setdlopenflags, METH_VARARGS,\r
+     setdlopenflags_doc},\r
+#endif\r
+    {"setprofile",      sys_setprofile, METH_O, setprofile_doc},\r
+    {"getprofile",      sys_getprofile, METH_NOARGS, getprofile_doc},\r
+    {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,\r
+     setrecursionlimit_doc},\r
+#ifdef WITH_TSC\r
+    {"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc},\r
+#endif\r
+    {"settrace",        sys_settrace, METH_O, settrace_doc},\r
+    {"gettrace",        sys_gettrace, METH_NOARGS, gettrace_doc},\r
+    {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},\r
+    {NULL,              NULL}           /* sentinel */\r
+};\r
+\r
+static PyObject *\r
+list_builtin_module_names(void)\r
+{\r
+    PyObject *list = PyList_New(0);\r
+    int i;\r
+    if (list == NULL)\r
+        return NULL;\r
+    for (i = 0; PyImport_Inittab[i].name != NULL; i++) {\r
+        PyObject *name = PyString_FromString(\r
+            PyImport_Inittab[i].name);\r
+        if (name == NULL)\r
+            break;\r
+        PyList_Append(list, name);\r
+        Py_DECREF(name);\r
+    }\r
+    if (PyList_Sort(list) != 0) {\r
+        Py_DECREF(list);\r
+        list = NULL;\r
+    }\r
+    if (list) {\r
+        PyObject *v = PyList_AsTuple(list);\r
+        Py_DECREF(list);\r
+        list = v;\r
+    }\r
+    return list;\r
+}\r
+\r
+static PyObject *warnoptions = NULL;\r
+\r
+void\r
+PySys_ResetWarnOptions(void)\r
+{\r
+    if (warnoptions == NULL || !PyList_Check(warnoptions))\r
+        return;\r
+    PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL);\r
+}\r
+\r
+void\r
+PySys_AddWarnOption(char *s)\r
+{\r
+    PyObject *str;\r
+\r
+    if (warnoptions == NULL || !PyList_Check(warnoptions)) {\r
+        Py_XDECREF(warnoptions);\r
+        warnoptions = PyList_New(0);\r
+        if (warnoptions == NULL)\r
+            return;\r
+    }\r
+    str = PyString_FromString(s);\r
+    if (str != NULL) {\r
+        PyList_Append(warnoptions, str);\r
+        Py_DECREF(str);\r
+    }\r
+}\r
+\r
+int\r
+PySys_HasWarnOptions(void)\r
+{\r
+    return (warnoptions != NULL && (PyList_Size(warnoptions) > 0)) ? 1 : 0;\r
+}\r
+\r
+/* XXX This doc string is too long to be a single string literal in VC++ 5.0.\r
+   Two literals concatenated works just fine.  If you have a K&R compiler\r
+   or other abomination that however *does* understand longer strings,\r
+   get rid of the !!! comment in the middle and the quotes that surround it. */\r
+PyDoc_VAR(sys_doc) =\r
+PyDoc_STR(\r
+"This module provides access to some objects used or maintained by the\n\\r
+interpreter and to functions that interact strongly with the interpreter.\n\\r
+\n\\r
+Dynamic objects:\n\\r
+\n\\r
+argv -- command line arguments; argv[0] is the script pathname if known\n\\r
+path -- module search path; path[0] is the script directory, else ''\n\\r
+modules -- dictionary of loaded modules\n\\r
+\n\\r
+displayhook -- called to show results in an interactive session\n\\r
+excepthook -- called to handle any uncaught exception other than SystemExit\n\\r
+  To customize printing in an interactive session or to install a custom\n\\r
+  top-level exception handler, assign other functions to replace these.\n\\r
+\n\\r
+exitfunc -- if sys.exitfunc exists, this routine is called when Python exits\n\\r
+  Assigning to sys.exitfunc is deprecated; use the atexit module instead.\n\\r
+\n\\r
+stdin -- standard input file object; used by raw_input() and input()\n\\r
+stdout -- standard output file object; used by the print statement\n\\r
+stderr -- standard error object; used for error messages\n\\r
+  By assigning other file objects (or objects that behave like files)\n\\r
+  to these, it is possible to redirect all of the interpreter's I/O.\n\\r
+\n\\r
+last_type -- type of last uncaught exception\n\\r
+last_value -- value of last uncaught exception\n\\r
+last_traceback -- traceback of last uncaught exception\n\\r
+  These three are only available in an interactive session after a\n\\r
+  traceback has been printed.\n\\r
+\n\\r
+exc_type -- type of exception currently being handled\n\\r
+exc_value -- value of exception currently being handled\n\\r
+exc_traceback -- traceback of exception currently being handled\n\\r
+  The function exc_info() should be used instead of these three,\n\\r
+  because it is thread-safe.\n\\r
+"\r
+)\r
+/* concatenating string here */\r
+PyDoc_STR(\r
+"\n\\r
+Static objects:\n\\r
+\n\\r
+float_info -- a dict with information about the float inplementation.\n\\r
+long_info -- a struct sequence with information about the long implementation.\n\\r
+maxint -- the largest supported integer (the smallest is -maxint-1)\n\\r
+maxsize -- the largest supported length of containers.\n\\r
+maxunicode -- the largest supported character\n\\r
+builtin_module_names -- tuple of module names built into this interpreter\n\\r
+version -- the version of this interpreter as a string\n\\r
+version_info -- version information as a named tuple\n\\r
+hexversion -- version information encoded as a single integer\n\\r
+copyright -- copyright notice pertaining to this interpreter\n\\r
+platform -- platform identifier\n\\r
+executable -- absolute path of the executable binary of the Python interpreter\n\\r
+prefix -- prefix used to find the Python library\n\\r
+exec_prefix -- prefix used to find the machine-specific Python library\n\\r
+float_repr_style -- string indicating the style of repr() output for floats\n\\r
+"\r
+)\r
+#ifdef MS_WINDOWS\r
+/* concatenating string here */\r
+PyDoc_STR(\r
+"dllhandle -- [Windows only] integer handle of the Python DLL\n\\r
+winver -- [Windows only] version number of the Python DLL\n\\r
+"\r
+)\r
+#endif /* MS_WINDOWS */\r
+PyDoc_STR(\r
+"__stdin__ -- the original stdin; don't touch!\n\\r
+__stdout__ -- the original stdout; don't touch!\n\\r
+__stderr__ -- the original stderr; don't touch!\n\\r
+__displayhook__ -- the original displayhook; don't touch!\n\\r
+__excepthook__ -- the original excepthook; don't touch!\n\\r
+\n\\r
+Functions:\n\\r
+\n\\r
+displayhook() -- print an object to the screen, and save it in __builtin__._\n\\r
+excepthook() -- print an exception and its traceback to sys.stderr\n\\r
+exc_info() -- return thread-safe information about the current exception\n\\r
+exc_clear() -- clear the exception state for the current thread\n\\r
+exit() -- exit the interpreter by raising SystemExit\n\\r
+getdlopenflags() -- returns flags to be used for dlopen() calls\n\\r
+getprofile() -- get the global profiling function\n\\r
+getrefcount() -- return the reference count for an object (plus one :-)\n\\r
+getrecursionlimit() -- return the max recursion depth for the interpreter\n\\r
+getsizeof() -- return the size of an object in bytes\n\\r
+gettrace() -- get the global debug tracing function\n\\r
+setcheckinterval() -- control how often the interpreter checks for events\n\\r
+setdlopenflags() -- set the flags to be used for dlopen() calls\n\\r
+setprofile() -- set the global profiling function\n\\r
+setrecursionlimit() -- set the max recursion depth for the interpreter\n\\r
+settrace() -- set the global debug tracing function\n\\r
+"\r
+)\r
+/* end of sys_doc */ ;\r
+\r
+static int\r
+_check_and_flush (FILE *stream)\r
+{\r
+  int prev_fail = ferror (stream);\r
+  return fflush (stream) || prev_fail ? EOF : 0;\r
+}\r
+\r
+/* Subversion branch and revision management */\r
+static int svn_initialized;\r
+static char patchlevel_revision[50]; /* Just the number */\r
+static char branch[50];\r
+static char shortbranch[50];\r
+static const char *svn_revision;\r
+\r
+static void\r
+svnversion_init(void)\r
+{\r
+    if (svn_initialized)\r
+        return;\r
+    svn_initialized = 1;\r
+    *patchlevel_revision = '\0';\r
+    strcpy(branch, "");\r
+    strcpy(shortbranch, "unknown");\r
+    svn_revision = "";\r
+    return;\r
+}\r
+\r
+/* Return svnversion output if available.\r
+   Else return Revision of patchlevel.h if on branch.\r
+   Else return empty string */\r
+const char*\r
+Py_SubversionRevision()\r
+{\r
+    svnversion_init();\r
+    return svn_revision;\r
+}\r
+\r
+const char*\r
+Py_SubversionShortBranch()\r
+{\r
+    svnversion_init();\r
+    return shortbranch;\r
+}\r
+\r
+\r
+PyDoc_STRVAR(flags__doc__,\r
+"sys.flags\n\\r
+\n\\r
+Flags provided through command line arguments or environment vars.");\r
+\r
+static PyTypeObject FlagsType = {0, 0, 0, 0, 0, 0};\r
+\r
+static PyStructSequence_Field flags_fields[] = {\r
+    {"debug",                   "-d"},\r
+    {"py3k_warning",            "-3"},\r
+    {"division_warning",        "-Q"},\r
+    {"division_new",            "-Qnew"},\r
+    {"inspect",                 "-i"},\r
+    {"interactive",             "-i"},\r
+    {"optimize",                "-O or -OO"},\r
+    {"dont_write_bytecode",     "-B"},\r
+    {"no_user_site",            "-s"},\r
+    {"no_site",                 "-S"},\r
+    {"ignore_environment",      "-E"},\r
+    {"tabcheck",                "-t or -tt"},\r
+    {"verbose",                 "-v"},\r
+#ifdef RISCOS\r
+    {"riscos_wimp",             "???"},\r
+#endif\r
+    /* {"unbuffered",                   "-u"}, */\r
+    {"unicode",                 "-U"},\r
+    /* {"skip_first",                   "-x"}, */\r
+    {"bytes_warning", "-b"},\r
+    {"hash_randomization", "-R"},\r
+    {0}\r
+};\r
+\r
+static PyStructSequence_Desc flags_desc = {\r
+    "sys.flags",        /* name */\r
+    flags__doc__,       /* doc */\r
+    flags_fields,       /* fields */\r
+#ifdef RISCOS\r
+    17\r
+#else\r
+    16\r
+#endif\r
+};\r
+\r
+static PyObject*\r
+make_flags(void)\r
+{\r
+    int pos = 0;\r
+    PyObject *seq;\r
+\r
+    seq = PyStructSequence_New(&FlagsType);\r
+    if (seq == NULL)\r
+        return NULL;\r
+\r
+#define SetFlag(flag) \\r
+    PyStructSequence_SET_ITEM(seq, pos++, PyInt_FromLong(flag))\r
+\r
+    SetFlag(Py_DebugFlag);\r
+    SetFlag(Py_Py3kWarningFlag);\r
+    SetFlag(Py_DivisionWarningFlag);\r
+    SetFlag(_Py_QnewFlag);\r
+    SetFlag(Py_InspectFlag);\r
+    SetFlag(Py_InteractiveFlag);\r
+    SetFlag(Py_OptimizeFlag);\r
+    SetFlag(Py_DontWriteBytecodeFlag);\r
+    SetFlag(Py_NoUserSiteDirectory);\r
+    SetFlag(Py_NoSiteFlag);\r
+    SetFlag(Py_IgnoreEnvironmentFlag);\r
+    SetFlag(Py_TabcheckFlag);\r
+    SetFlag(Py_VerboseFlag);\r
+#ifdef RISCOS\r
+    SetFlag(Py_RISCOSWimpFlag);\r
+#endif\r
+    /* SetFlag(saw_unbuffered_flag); */\r
+    SetFlag(Py_UnicodeFlag);\r
+    /* SetFlag(skipfirstline); */\r
+    SetFlag(Py_BytesWarningFlag);\r
+    SetFlag(Py_HashRandomizationFlag);\r
+#undef SetFlag\r
+\r
+    if (PyErr_Occurred()) {\r
+        Py_DECREF(seq);\r
+        return NULL;\r
+    }\r
+    return seq;\r
+}\r
+\r
+PyDoc_STRVAR(version_info__doc__,\r
+"sys.version_info\n\\r
+\n\\r
+Version information as a named tuple.");\r
+\r
+static PyTypeObject VersionInfoType = {0, 0, 0, 0, 0, 0};\r
+\r
+static PyStructSequence_Field version_info_fields[] = {\r
+    {"major", "Major release number"},\r
+    {"minor", "Minor release number"},\r
+    {"micro", "Patch release number"},\r
+    {"releaselevel", "'alpha', 'beta', 'candidate', or 'release'"},\r
+    {"serial", "Serial release number"},\r
+    {0}\r
+};\r
+\r
+static PyStructSequence_Desc version_info_desc = {\r
+    "sys.version_info",     /* name */\r
+    version_info__doc__,    /* doc */\r
+    version_info_fields,    /* fields */\r
+    5\r
+};\r
+\r
+static PyObject *\r
+make_version_info(void)\r
+{\r
+    PyObject *version_info;\r
+    char *s;\r
+    int pos = 0;\r
+\r
+    version_info = PyStructSequence_New(&VersionInfoType);\r
+    if (version_info == NULL) {\r
+        return NULL;\r
+    }\r
+\r
+    /*\r
+     * These release level checks are mutually exclusive and cover\r
+     * the field, so don't get too fancy with the pre-processor!\r
+     */\r
+#if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_ALPHA\r
+    s = "alpha";\r
+#elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_BETA\r
+    s = "beta";\r
+#elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_GAMMA\r
+    s = "candidate";\r
+#elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_FINAL\r
+    s = "final";\r
+#endif\r
+\r
+#define SetIntItem(flag) \\r
+    PyStructSequence_SET_ITEM(version_info, pos++, PyInt_FromLong(flag))\r
+#define SetStrItem(flag) \\r
+    PyStructSequence_SET_ITEM(version_info, pos++, PyString_FromString(flag))\r
+\r
+    SetIntItem(PY_MAJOR_VERSION);\r
+    SetIntItem(PY_MINOR_VERSION);\r
+    SetIntItem(PY_MICRO_VERSION);\r
+    SetStrItem(s);\r
+    SetIntItem(PY_RELEASE_SERIAL);\r
+#undef SetIntItem\r
+#undef SetStrItem\r
+\r
+    if (PyErr_Occurred()) {\r
+        Py_CLEAR(version_info);\r
+        return NULL;\r
+    }\r
+    return version_info;\r
+}\r
+\r
+PyObject *\r
+_PySys_Init(void)\r
+{\r
+    PyObject *m, *v, *sysdict;\r
+    PyObject *sysin, *sysout, *syserr;\r
+    char *s;\r
+\r
+    m = Py_InitModule3("sys", sys_methods, sys_doc);\r
+    if (m == NULL)\r
+        return NULL;\r
+    sysdict = PyModule_GetDict(m);\r
+#define SET_SYS_FROM_STRING(key, value)                 \\r
+    v = value;                                          \\r
+    if (v != NULL)                                      \\r
+        PyDict_SetItemString(sysdict, key, v);          \\r
+    Py_XDECREF(v)\r
+\r
+    /* Check that stdin is not a directory\r
+    Using shell redirection, you can redirect stdin to a directory,\r
+    crashing the Python interpreter. Catch this common mistake here\r
+    and output a useful error message. Note that under MS Windows,\r
+    the shell already prevents that. */\r
+#if !defined(MS_WINDOWS)\r
+    {\r
+        struct stat sb;\r
+        if (fstat(fileno(stdin), &sb) == 0 &&\r
+            S_ISDIR(sb.st_mode)) {\r
+            /* There's nothing more we can do. */\r
+            /* Py_FatalError() will core dump, so just exit. */\r
+            PySys_WriteStderr("Python error: <stdin> is a directory, cannot continue\n");\r
+            exit(EXIT_FAILURE);\r
+        }\r
+    }\r
+#endif\r
+\r
+    /* Closing the standard FILE* if sys.std* goes aways causes problems\r
+     * for embedded Python usages. Closing them when somebody explicitly\r
+     * invokes .close() might be possible, but the FAQ promises they get\r
+     * never closed. However, we still need to get write errors when\r
+     * writing fails (e.g. because stdout is redirected), so we flush the\r
+     * streams and check for errors before the file objects are deleted.\r
+     * On OS X, fflush()ing stdin causes an error, so we exempt stdin\r
+     * from that procedure.\r
+     */\r
+    sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL);\r
+    sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush);\r
+    syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush);\r
+    if (PyErr_Occurred())\r
+        return NULL;\r
+\r
+    PyDict_SetItemString(sysdict, "stdin", sysin);\r
+    PyDict_SetItemString(sysdict, "stdout", sysout);\r
+    PyDict_SetItemString(sysdict, "stderr", syserr);\r
+    /* Make backup copies for cleanup */\r
+    PyDict_SetItemString(sysdict, "__stdin__", sysin);\r
+    PyDict_SetItemString(sysdict, "__stdout__", sysout);\r
+    PyDict_SetItemString(sysdict, "__stderr__", syserr);\r
+    PyDict_SetItemString(sysdict, "__displayhook__",\r
+                         PyDict_GetItemString(sysdict, "displayhook"));\r
+    PyDict_SetItemString(sysdict, "__excepthook__",\r
+                         PyDict_GetItemString(sysdict, "excepthook"));\r
+    Py_XDECREF(sysin);\r
+    Py_XDECREF(sysout);\r
+    Py_XDECREF(syserr);\r
+\r
+    SET_SYS_FROM_STRING("version",\r
+                         PyString_FromString(Py_GetVersion()));\r
+    SET_SYS_FROM_STRING("hexversion",\r
+                         PyInt_FromLong(PY_VERSION_HEX));\r
+    svnversion_init();\r
+    SET_SYS_FROM_STRING("subversion",\r
+                         Py_BuildValue("(ssz)", "CPython", branch,\r
+                                      svn_revision));\r
+    SET_SYS_FROM_STRING("_mercurial",\r
+                        Py_BuildValue("(szz)", "CPython", _Py_hgidentifier(),\r
+                                      _Py_hgversion()));\r
+    SET_SYS_FROM_STRING("dont_write_bytecode",\r
+                         PyBool_FromLong(Py_DontWriteBytecodeFlag));\r
+    SET_SYS_FROM_STRING("api_version",\r
+                        PyInt_FromLong(PYTHON_API_VERSION));\r
+    SET_SYS_FROM_STRING("copyright",\r
+                        PyString_FromString(Py_GetCopyright()));\r
+    SET_SYS_FROM_STRING("platform",\r
+                        PyString_FromString(Py_GetPlatform()));\r
+    SET_SYS_FROM_STRING("executable",\r
+                        PyString_FromString(Py_GetProgramFullPath()));\r
+    SET_SYS_FROM_STRING("prefix",\r
+                        PyString_FromString(Py_GetPrefix()));\r
+    SET_SYS_FROM_STRING("exec_prefix",\r
+                        PyString_FromString(Py_GetExecPrefix()));\r
+    SET_SYS_FROM_STRING("maxsize",\r
+                        PyInt_FromSsize_t(PY_SSIZE_T_MAX));\r
+    SET_SYS_FROM_STRING("maxint",\r
+                        PyInt_FromLong(PyInt_GetMax()));\r
+    SET_SYS_FROM_STRING("py3kwarning",\r
+                        PyBool_FromLong(Py_Py3kWarningFlag));\r
+    SET_SYS_FROM_STRING("float_info",\r
+                        PyFloat_GetInfo());\r
+    SET_SYS_FROM_STRING("long_info",\r
+                        PyLong_GetInfo());\r
+#ifdef Py_USING_UNICODE\r
+    SET_SYS_FROM_STRING("maxunicode",\r
+                        PyInt_FromLong(PyUnicode_GetMax()));\r
+#endif\r
+    SET_SYS_FROM_STRING("builtin_module_names",\r
+                        list_builtin_module_names());\r
+    {\r
+        /* Assumes that longs are at least 2 bytes long.\r
+           Should be safe! */\r
+        unsigned long number = 1;\r
+        char *value;\r
+\r
+        s = (char *) &number;\r
+        if (s[0] == 0)\r
+            value = "big";\r
+        else\r
+            value = "little";\r
+        SET_SYS_FROM_STRING("byteorder",\r
+                            PyString_FromString(value));\r
+    }\r
+#ifdef MS_COREDLL\r
+    SET_SYS_FROM_STRING("dllhandle",\r
+                        PyLong_FromVoidPtr(PyWin_DLLhModule));\r
+    SET_SYS_FROM_STRING("winver",\r
+                        PyString_FromString(PyWin_DLLVersionString));\r
+#endif\r
+    if (warnoptions == NULL) {\r
+        warnoptions = PyList_New(0);\r
+    }\r
+    else {\r
+        Py_INCREF(warnoptions);\r
+    }\r
+    if (warnoptions != NULL) {\r
+        PyDict_SetItemString(sysdict, "warnoptions", warnoptions);\r
+    }\r
+\r
+    /* version_info */\r
+    if (VersionInfoType.tp_name == 0)\r
+        PyStructSequence_InitType(&VersionInfoType, &version_info_desc);\r
+    SET_SYS_FROM_STRING("version_info", make_version_info());\r
+    /* prevent user from creating new instances */\r
+    VersionInfoType.tp_init = NULL;\r
+    VersionInfoType.tp_new = NULL;\r
+\r
+    /* flags */\r
+    if (FlagsType.tp_name == 0)\r
+        PyStructSequence_InitType(&FlagsType, &flags_desc);\r
+    SET_SYS_FROM_STRING("flags", make_flags());\r
+    /* prevent user from creating new instances */\r
+    FlagsType.tp_init = NULL;\r
+    FlagsType.tp_new = NULL;\r
+\r
+\r
+#if defined(MS_WINDOWS)\r
+    /* getwindowsversion */\r
+    if (WindowsVersionType.tp_name == 0)\r
+        PyStructSequence_InitType(&WindowsVersionType, &windows_version_desc);\r
+    /* prevent user from creating new instances */\r
+    WindowsVersionType.tp_init = NULL;\r
+    WindowsVersionType.tp_new = NULL;\r
+#endif\r
+\r
+    /* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */\r
+#ifndef PY_NO_SHORT_FLOAT_REPR\r
+    SET_SYS_FROM_STRING("float_repr_style",\r
+                        PyString_FromString("short"));\r
+#else\r
+    SET_SYS_FROM_STRING("float_repr_style",\r
+                        PyString_FromString("legacy"));\r
+#endif\r
+\r
+#undef SET_SYS_FROM_STRING\r
+    if (PyErr_Occurred())\r
+        return NULL;\r
+    return m;\r
+}\r
+\r
+static PyObject *\r
+makepathobject(char *path, int delim)\r
+{\r
+    int i, n;\r
+    char *p;\r
+    PyObject *v, *w;\r
+\r
+    n = 1;\r
+    p = path;\r
+    while ((p = strchr(p, delim)) != NULL) {\r
+        n++;\r
+        p++;\r
+    }\r
+    v = PyList_New(n);\r
+    if (v == NULL)\r
+        return NULL;\r
+    for (i = 0; ; i++) {\r
+        p = strchr(path, delim);\r
+        if (p == NULL)\r
+            p = strchr(path, '\0'); /* End of string */\r
+        w = PyString_FromStringAndSize(path, (Py_ssize_t) (p - path));\r
+        if (w == NULL) {\r
+            Py_DECREF(v);\r
+            return NULL;\r
+        }\r
+        PyList_SetItem(v, i, w);\r
+        if (*p == '\0')\r
+            break;\r
+        path = p+1;\r
+    }\r
+    return v;\r
+}\r
+\r
+void\r
+PySys_SetPath(char *path)\r
+{\r
+    PyObject *v;\r
+    if ((v = makepathobject(path, DELIM)) == NULL)\r
+        Py_FatalError("can't create sys.path");\r
+    if (PySys_SetObject("path", v) != 0)\r
+        Py_FatalError("can't assign sys.path");\r
+    Py_DECREF(v);\r
+}\r
+\r
+static PyObject *\r
+makeargvobject(int argc, char **argv)\r
+{\r
+    PyObject *av;\r
+    if (argc <= 0 || argv == NULL) {\r
+        /* Ensure at least one (empty) argument is seen */\r
+        static char *empty_argv[1] = {""};\r
+        argv = empty_argv;\r
+        argc = 1;\r
+    }\r
+    av = PyList_New(argc);\r
+    if (av != NULL) {\r
+        int i;\r
+        for (i = 0; i < argc; i++) {\r
+#ifdef __VMS\r
+            PyObject *v;\r
+\r
+            /* argv[0] is the script pathname if known */\r
+            if (i == 0) {\r
+                char* fn = decc$translate_vms(argv[0]);\r
+                if ((fn == (char *)0) || fn == (char *)-1)\r
+                    v = PyString_FromString(argv[0]);\r
+                else\r
+                    v = PyString_FromString(\r
+                        decc$translate_vms(argv[0]));\r
+            } else\r
+                v = PyString_FromString(argv[i]);\r
+#else\r
+            PyObject *v = PyString_FromString(argv[i]);\r
+#endif\r
+            if (v == NULL) {\r
+                Py_DECREF(av);\r
+                av = NULL;\r
+                break;\r
+            }\r
+            PyList_SetItem(av, i, v);\r
+        }\r
+    }\r
+    return av;\r
+}\r
+\r
+void\r
+PySys_SetArgvEx(int argc, char **argv, int updatepath)\r
+{\r
+#if defined(HAVE_REALPATH)\r
+    char fullpath[MAXPATHLEN];\r
+#elif defined(MS_WINDOWS) && !defined(MS_WINCE)\r
+    char fullpath[MAX_PATH];\r
+#endif\r
+    PyObject *av = makeargvobject(argc, argv);\r
+    PyObject *path = PySys_GetObject("path");\r
+    if (av == NULL)\r
+        Py_FatalError("no mem for sys.argv");\r
+    if (PySys_SetObject("argv", av) != 0)\r
+        Py_FatalError("can't assign sys.argv");\r
+    if (updatepath && path != NULL) {\r
+        char *argv0 = argv[0];\r
+        char *p = NULL;\r
+        Py_ssize_t n = 0;\r
+        PyObject *a;\r
+#ifdef HAVE_READLINK\r
+        char link[MAXPATHLEN+1];\r
+        char argv0copy[2*MAXPATHLEN+1];\r
+        int nr = 0;\r
+        if (argc > 0 && argv0 != NULL && strcmp(argv0, "-c") != 0)\r
+            nr = readlink(argv0, link, MAXPATHLEN);\r
+        if (nr > 0) {\r
+            /* It's a symlink */\r
+            link[nr] = '\0';\r
+            if (link[0] == SEP)\r
+                argv0 = link; /* Link to absolute path */\r
+            else if (strchr(link, SEP) == NULL)\r
+                ; /* Link without path */\r
+            else {\r
+                /* Must join(dirname(argv0), link) */\r
+                char *q = strrchr(argv0, SEP);\r
+                if (q == NULL)\r
+                    argv0 = link; /* argv0 without path */\r
+                else {\r
+                    /* Must make a copy */\r
+                    strcpy(argv0copy, argv0);\r
+                    q = strrchr(argv0copy, SEP);\r
+                    strcpy(q+1, link);\r
+                    argv0 = argv0copy;\r
+                }\r
+            }\r
+        }\r
+#endif /* HAVE_READLINK */\r
+#if SEP == '\\' /* Special case for MS filename syntax */\r
+        if (argc > 0 && argv0 != NULL && strcmp(argv0, "-c") != 0) {\r
+            char *q;\r
+#if defined(MS_WINDOWS) && !defined(MS_WINCE)\r
+            /* This code here replaces the first element in argv with the full\r
+            path that it represents. Under CE, there are no relative paths so\r
+            the argument must be the full path anyway. */\r
+            char *ptemp;\r
+            if (GetFullPathName(argv0,\r
+                               sizeof(fullpath),\r
+                               fullpath,\r
+                               &ptemp)) {\r
+                argv0 = fullpath;\r
+            }\r
+#endif\r
+            p = strrchr(argv0, SEP);\r
+            /* Test for alternate separator */\r
+            q = strrchr(p ? p : argv0, '/');\r
+            if (q != NULL)\r
+                p = q;\r
+            if (p != NULL) {\r
+                n = p + 1 - argv0;\r
+                if (n > 1 && p[-1] != ':')\r
+                    n--; /* Drop trailing separator */\r
+            }\r
+        }\r
+#else /* All other filename syntaxes */\r
+        if (argc > 0 && argv0 != NULL && strcmp(argv0, "-c") != 0) {\r
+#if defined(HAVE_REALPATH)\r
+            if (realpath(argv0, fullpath)) {\r
+                argv0 = fullpath;\r
+            }\r
+#endif\r
+            p = strrchr(argv0, SEP);\r
+        }\r
+        if (p != NULL) {\r
+#ifndef RISCOS\r
+            n = p + 1 - argv0;\r
+#else /* don't include trailing separator */\r
+            n = p - argv0;\r
+#endif /* RISCOS */\r
+#if SEP == '/' /* Special case for Unix filename syntax */\r
+            if (n > 1)\r
+                n--; /* Drop trailing separator */\r
+#endif /* Unix */\r
+        }\r
+#endif /* All others */\r
+        a = PyString_FromStringAndSize(argv0, n);\r
+        if (a == NULL)\r
+            Py_FatalError("no mem for sys.path insertion");\r
+        if (PyList_Insert(path, 0, a) < 0)\r
+            Py_FatalError("sys.path.insert(0) failed");\r
+        Py_DECREF(a);\r
+    }\r
+    Py_DECREF(av);\r
+}\r
+\r
+void\r
+PySys_SetArgv(int argc, char **argv)\r
+{\r
+    PySys_SetArgvEx(argc, argv, 1);\r
+}\r
+\r
+\r
+/* APIs to write to sys.stdout or sys.stderr using a printf-like interface.\r
+   Adapted from code submitted by Just van Rossum.\r
+\r
+   PySys_WriteStdout(format, ...)\r
+   PySys_WriteStderr(format, ...)\r
+\r
+      The first function writes to sys.stdout; the second to sys.stderr.  When\r
+      there is a problem, they write to the real (C level) stdout or stderr;\r
+      no exceptions are raised.\r
+\r
+      Both take a printf-style format string as their first argument followed\r
+      by a variable length argument list determined by the format string.\r
+\r
+      *** WARNING ***\r
+\r
+      The format should limit the total size of the formatted output string to\r
+      1000 bytes.  In particular, this means that no unrestricted "%s" formats\r
+      should occur; these should be limited using "%.<N>s where <N> is a\r
+      decimal number calculated so that <N> plus the maximum size of other\r
+      formatted text does not exceed 1000 bytes.  Also watch out for "%f",\r
+      which can print hundreds of digits for very large numbers.\r
+\r
+ */\r
+\r
+static void\r
+mywrite(char *name, FILE *fp, const char *format, va_list va)\r
+{\r
+    PyObject *file;\r
+    PyObject *error_type, *error_value, *error_traceback;\r
+\r
+    PyErr_Fetch(&error_type, &error_value, &error_traceback);\r
+    file = PySys_GetObject(name);\r
+    if (file == NULL || PyFile_AsFile(file) == fp)\r
+        vfprintf(fp, format, va);\r
+    else {\r
+        char buffer[1001];\r
+        const int written = PyOS_vsnprintf(buffer, sizeof(buffer),\r
+                                           format, va);\r
+        if (PyFile_WriteString(buffer, file) != 0) {\r
+            PyErr_Clear();\r
+            fputs(buffer, fp);\r
+        }\r
+        if (written < 0 || (size_t)written >= sizeof(buffer)) {\r
+            const char *truncated = "... truncated";\r
+            if (PyFile_WriteString(truncated, file) != 0) {\r
+                PyErr_Clear();\r
+                fputs(truncated, fp);\r
+            }\r
+        }\r
+    }\r
+    PyErr_Restore(error_type, error_value, error_traceback);\r
+}\r
+\r
+void\r
+PySys_WriteStdout(const char *format, ...)\r
+{\r
+    va_list va;\r
+\r
+    va_start(va, format);\r
+    mywrite("stdout", stdout, format, va);\r
+    va_end(va);\r
+}\r
+\r
+void\r
+PySys_WriteStderr(const char *format, ...)\r
+{\r
+    va_list va;\r
+\r
+    va_start(va, format);\r
+    mywrite("stderr", stderr, format, va);\r
+    va_end(va);\r
+}\r
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Python/traceback.c b/AppPkg/Applications/Python/Python-2.7.10/Python/traceback.c
new file mode 100644 (file)
index 0000000..85caa02
--- /dev/null
@@ -0,0 +1,283 @@
+\r
+/* Traceback implementation */\r
+\r
+#include "Python.h"\r
+\r
+#include "code.h"\r
+#include "frameobject.h"\r
+#include "structmember.h"\r
+#include "osdefs.h"\r
+#include "traceback.h"\r
+\r
+#define OFF(x) offsetof(PyTracebackObject, x)\r
+\r
+static PyMemberDef tb_memberlist[] = {\r
+    {"tb_next",         T_OBJECT,       OFF(tb_next), READONLY},\r
+    {"tb_frame",        T_OBJECT,       OFF(tb_frame), READONLY},\r
+    {"tb_lasti",        T_INT,          OFF(tb_lasti), READONLY},\r
+    {"tb_lineno",       T_INT,          OFF(tb_lineno), READONLY},\r
+    {NULL}      /* Sentinel */\r
+};\r
+\r
+static void\r
+tb_dealloc(PyTracebackObject *tb)\r
+{\r
+    PyObject_GC_UnTrack(tb);\r
+    Py_TRASHCAN_SAFE_BEGIN(tb)\r
+    Py_XDECREF(tb->tb_next);\r
+    Py_XDECREF(tb->tb_frame);\r
+    PyObject_GC_Del(tb);\r
+    Py_TRASHCAN_SAFE_END(tb)\r
+}\r
+\r
+static int\r
+tb_traverse(PyTracebackObject *tb, visitproc visit, void *arg)\r
+{\r
+    Py_VISIT(tb->tb_next);\r
+    Py_VISIT(tb->tb_frame);\r
+    return 0;\r
+}\r
+\r
+static void\r
+tb_clear(PyTracebackObject *tb)\r
+{\r
+    Py_CLEAR(tb->tb_next);\r
+    Py_CLEAR(tb->tb_frame);\r
+}\r
+\r
+PyTypeObject PyTraceBack_Type = {\r
+    PyVarObject_HEAD_INIT(&PyType_Type, 0)\r
+    "traceback",\r
+    sizeof(PyTracebackObject),\r
+    0,\r
+    (destructor)tb_dealloc, /*tp_dealloc*/\r
+    0,                  /*tp_print*/\r
+    0,              /*tp_getattr*/\r
+    0,                  /*tp_setattr*/\r
+    0,                  /*tp_compare*/\r
+    0,                  /*tp_repr*/\r
+    0,                  /*tp_as_number*/\r
+    0,                  /*tp_as_sequence*/\r
+    0,                  /*tp_as_mapping*/\r
+    0,                  /* tp_hash */\r
+    0,                  /* tp_call */\r
+    0,                  /* tp_str */\r
+    0,                  /* tp_getattro */\r
+    0,                  /* tp_setattro */\r
+    0,                                          /* tp_as_buffer */\r
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */\r
+    0,                                          /* tp_doc */\r
+    (traverseproc)tb_traverse,                  /* tp_traverse */\r
+    (inquiry)tb_clear,                          /* tp_clear */\r
+    0,                                          /* tp_richcompare */\r
+    0,                                          /* tp_weaklistoffset */\r
+    0,                                          /* tp_iter */\r
+    0,                                          /* tp_iternext */\r
+    0,                                          /* tp_methods */\r
+    tb_memberlist,                              /* tp_members */\r
+    0,                                          /* tp_getset */\r
+    0,                                          /* tp_base */\r
+    0,                                          /* tp_dict */\r
+};\r
+\r
+static PyTracebackObject *\r
+newtracebackobject(PyTracebackObject *next, PyFrameObject *frame)\r
+{\r
+    PyTracebackObject *tb;\r
+    if ((next != NULL && !PyTraceBack_Check(next)) ||\r
+                    frame == NULL || !PyFrame_Check(frame)) {\r
+        PyErr_BadInternalCall();\r
+        return NULL;\r
+    }\r
+    tb = PyObject_GC_New(PyTracebackObject, &PyTraceBack_Type);\r
+    if (tb != NULL) {\r
+        Py_XINCREF(next);\r
+        tb->tb_next = next;\r
+        Py_XINCREF(frame);\r
+        tb->tb_frame = frame;\r
+        tb->tb_lasti = frame->f_lasti;\r
+        tb->tb_lineno = PyFrame_GetLineNumber(frame);\r
+        PyObject_GC_Track(tb);\r
+    }\r
+    return tb;\r
+}\r
+\r
+int\r
+PyTraceBack_Here(PyFrameObject *frame)\r
+{\r
+    PyThreadState *tstate = PyThreadState_GET();\r
+    PyTracebackObject *oldtb = (PyTracebackObject *) tstate->curexc_traceback;\r
+    PyTracebackObject *tb = newtracebackobject(oldtb, frame);\r
+    if (tb == NULL)\r
+        return -1;\r
+    tstate->curexc_traceback = (PyObject *)tb;\r
+    Py_XDECREF(oldtb);\r
+    return 0;\r
+}\r
+\r
+int\r
+_Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno, int indent)\r
+{\r
+    int err = 0;\r
+    FILE *xfp = NULL;\r
+    char linebuf[2000];\r
+    int i;\r
+    char namebuf[MAXPATHLEN+1];\r
+\r
+    if (filename == NULL)\r
+        return -1;\r
+    /* This is needed by Emacs' compile command */\r
+#define FMT "  File \"%.500s\", line %d, in %.500s\n"\r
+    xfp = fopen(filename, "r" PY_STDIOTEXTMODE);\r
+    if (xfp == NULL) {\r
+        /* Search tail of filename in sys.path before giving up */\r
+        PyObject *path;\r
+        const char *tail = strrchr(filename, SEP);\r
+        if (tail == NULL)\r
+            tail = filename;\r
+        else\r
+            tail++;\r
+        path = PySys_GetObject("path");\r
+        if (path != NULL && PyList_Check(path)) {\r
+            Py_ssize_t _npath = PyList_Size(path);\r
+            int npath = Py_SAFE_DOWNCAST(_npath, Py_ssize_t, int);\r
+            size_t taillen = strlen(tail);\r
+            for (i = 0; i < npath; i++) {\r
+                PyObject *v = PyList_GetItem(path, i);\r
+                if (v == NULL) {\r
+                    PyErr_Clear();\r
+                    break;\r
+                }\r
+                if (PyString_Check(v)) {\r
+                    size_t len;\r
+                    len = PyString_GET_SIZE(v);\r
+                    if (len + 1 + taillen >= MAXPATHLEN)\r
+                        continue; /* Too long */\r
+                    strcpy(namebuf, PyString_AsString(v));\r
+                    if (strlen(namebuf) != len)\r
+                        continue; /* v contains '\0' */\r
+                    if (len > 0 && namebuf[len-1] != SEP)\r
+                        namebuf[len++] = SEP;\r
+                    strcpy(namebuf+len, tail);\r
+                    xfp = fopen(namebuf, "r" PY_STDIOTEXTMODE);\r
+                    if (xfp != NULL) {\r
+                        break;\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    if (xfp == NULL)\r
+        return err;\r
+    if (err != 0) {\r
+        fclose(xfp);\r
+        return err;\r
+    }\r
+\r
+    for (i = 0; i < lineno; i++) {\r
+        char* pLastChar = &linebuf[sizeof(linebuf)-2];\r
+        do {\r
+            *pLastChar = '\0';\r
+            if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, xfp, NULL) == NULL)\r
+                break;\r
+            /* fgets read *something*; if it didn't get as\r
+               far as pLastChar, it must have found a newline\r
+               or hit the end of the file;              if pLastChar is \n,\r
+               it obviously found a newline; else we haven't\r
+               yet seen a newline, so must continue */\r
+        } while (*pLastChar != '\0' && *pLastChar != '\n');\r
+    }\r
+    if (i == lineno) {\r
+        char buf[11];\r
+        char *p = linebuf;\r
+        while (*p == ' ' || *p == '\t' || *p == '\014')\r
+            p++;\r
+\r
+        /* Write some spaces before the line */\r
+        strcpy(buf, "          ");\r
+        assert (strlen(buf) == 10);\r
+        while (indent > 0) {\r
+            if(indent < 10)\r
+                buf[indent] = '\0';\r
+            err = PyFile_WriteString(buf, f);\r
+            if (err != 0)\r
+                break;\r
+            indent -= 10;\r
+        }\r
+\r
+        if (err == 0)\r
+            err = PyFile_WriteString(p, f);\r
+        if (err == 0 && strchr(p, '\n') == NULL)\r
+            err = PyFile_WriteString("\n", f);\r
+    }\r
+    fclose(xfp);\r
+    return err;\r
+}\r
+\r
+static int\r
+tb_displayline(PyObject *f, const char *filename, int lineno, const char *name)\r
+{\r
+    int err = 0;\r
+    char linebuf[2000];\r
+\r
+    if (filename == NULL || name == NULL)\r
+        return -1;\r
+    /* This is needed by Emacs' compile command */\r
+#define FMT "  File \"%.500s\", line %d, in %.500s\n"\r
+    PyOS_snprintf(linebuf, sizeof(linebuf), FMT, filename, lineno, name);\r
+    err = PyFile_WriteString(linebuf, f);\r
+    if (err != 0)\r
+        return err;\r
+    return _Py_DisplaySourceLine(f, filename, lineno, 4);\r
+}\r
+\r
+static int\r
+tb_printinternal(PyTracebackObject *tb, PyObject *f, long limit)\r
+{\r
+    int err = 0;\r
+    long depth = 0;\r
+    PyTracebackObject *tb1 = tb;\r
+    while (tb1 != NULL) {\r
+        depth++;\r
+        tb1 = tb1->tb_next;\r
+    }\r
+    while (tb != NULL && err == 0) {\r
+        if (depth <= limit) {\r
+            err = tb_displayline(f,\r
+                PyString_AsString(\r
+                    tb->tb_frame->f_code->co_filename),\r
+                tb->tb_lineno,\r
+                PyString_AsString(tb->tb_frame->f_code->co_name));\r
+        }\r
+        depth--;\r
+        tb = tb->tb_next;\r
+        if (err == 0)\r
+            err = PyErr_CheckSignals();\r
+    }\r
+    return err;\r
+}\r
+\r
+int\r
+PyTraceBack_Print(PyObject *v, PyObject *f)\r
+{\r
+    int err;\r
+    PyObject *limitv;\r
+    long limit = 1000;\r
+    if (v == NULL)\r
+        return 0;\r
+    if (!PyTraceBack_Check(v)) {\r
+        PyErr_BadInternalCall();\r
+        return -1;\r
+    }\r
+    limitv = PySys_GetObject("tracebacklimit");\r
+    if (limitv && PyInt_Check(limitv)) {\r
+        limit = PyInt_AsLong(limitv);\r
+        if (limit <= 0)\r
+            return 0;\r
+    }\r
+    err = PyFile_WriteString("Traceback (most recent call last):\n", f);\r
+    if (!err)\r
+        err = tb_printinternal((PyTracebackObject *)v, f, limit);\r
+    return err;\r
+}\r