aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Include
diff options
context:
space:
mode:
Diffstat (limited to 'Include')
-rw-r--r--Include/Python-ast.h122
-rw-r--r--Include/Python.h51
-rw-r--r--Include/abstract.h263
-rw-r--r--Include/accu.h37
-rw-r--r--Include/asdl.h4
-rw-r--r--Include/ast.h7
-rw-r--r--Include/bltinmodule.h14
-rw-r--r--Include/boolobject.h6
-rw-r--r--Include/bufferobject.h33
-rw-r--r--Include/bytearrayobject.h4
-rw-r--r--Include/bytes_methods.h43
-rw-r--r--Include/bytesobject.h157
-rw-r--r--Include/cStringIO.h73
-rw-r--r--Include/cellobject.h3
-rw-r--r--Include/ceval.h76
-rw-r--r--Include/classobject.h71
-rw-r--r--Include/cobject.h89
-rw-r--r--Include/code.h26
-rw-r--r--Include/codecs.h15
-rw-r--r--Include/compile.h14
-rw-r--r--Include/complexobject.h16
-rw-r--r--Include/datetime.h10
-rw-r--r--Include/descrobject.h26
-rw-r--r--Include/dictobject.h22
-rw-r--r--Include/dtoa.h2
-rw-r--r--Include/dynamic_annotations.h499
-rw-r--r--Include/errcode.h1
-rw-r--r--Include/eval.h8
-rw-r--r--Include/fileobject.h70
-rw-r--r--Include/fileutils.h58
-rw-r--r--Include/floatobject.h45
-rw-r--r--Include/frameobject.h20
-rw-r--r--Include/funcobject.h17
-rw-r--r--Include/genobject.h2
-rw-r--r--Include/graminit.h130
-rw-r--r--Include/import.h75
-rw-r--r--Include/intobject.h80
-rw-r--r--Include/iterobject.h4
-rw-r--r--Include/listobject.h9
-rw-r--r--Include/longintrepr.h10
-rw-r--r--Include/longobject.h65
-rw-r--r--Include/marshal.h2
-rw-r--r--Include/memoryobject.h8
-rw-r--r--Include/methodobject.h18
-rw-r--r--Include/modsupport.h52
-rw-r--r--Include/moduleobject.h40
-rw-r--r--Include/object.h258
-rw-r--r--Include/objimpl.h22
-rw-r--r--Include/opcode.h55
-rw-r--r--Include/osdefs.h29
-rw-r--r--Include/parsetok.h40
-rw-r--r--Include/patchlevel.h12
-rw-r--r--Include/py_curses.h4
-rw-r--r--Include/pyarena.h2
-rw-r--r--Include/pyatomic.h184
-rw-r--r--Include/pycapsule.h5
-rw-r--r--Include/pyctype.h2
-rw-r--r--Include/pydebug.h13
-rw-r--r--Include/pyerrors.h169
-rw-r--r--Include/pygetopt.h7
-rw-r--r--Include/pymactoolbox.h217
-rw-r--r--Include/pymath.h4
-rw-r--r--Include/pyport.h181
-rw-r--r--Include/pystate.h39
-rw-r--r--Include/pystrcmp.h2
-rw-r--r--Include/pystrtod.h8
-rw-r--r--Include/pythonrun.h147
-rw-r--r--Include/pythread.h50
-rw-r--r--Include/pytime.h48
-rw-r--r--Include/rangeobject.h5
-rw-r--r--Include/setobject.h20
-rw-r--r--Include/sliceobject.h9
-rw-r--r--Include/stringobject.h210
-rw-r--r--Include/structmember.h80
-rw-r--r--Include/structseq.h34
-rw-r--r--Include/symtable.h61
-rw-r--r--Include/sysmodule.h26
-rw-r--r--Include/timefuncs.h2
-rw-r--r--Include/token.h62
-rw-r--r--Include/traceback.h17
-rw-r--r--Include/tupleobject.h9
-rw-r--r--Include/typeslots.h76
-rw-r--r--Include/ucnhash.h3
-rw-r--r--Include/unicodeobject.h561
-rw-r--r--Include/warnings.h28
-rw-r--r--Include/weakrefobject.h6
86 files changed, 2899 insertions, 2205 deletions
diff --git a/Include/Python-ast.h b/Include/Python-ast.h
index 3f35bbb6347..0ad788b8eeb 100644
--- a/Include/Python-ast.h
+++ b/Include/Python-ast.h
@@ -30,6 +30,8 @@ typedef struct _excepthandler *excepthandler_ty;
typedef struct _arguments *arguments_ty;
+typedef struct _arg *arg_ty;
+
typedef struct _keyword *keyword_ty;
typedef struct _alias *alias_ty;
@@ -60,12 +62,12 @@ struct _mod {
};
enum _stmt_kind {FunctionDef_kind=1, ClassDef_kind=2, Return_kind=3,
- Delete_kind=4, Assign_kind=5, AugAssign_kind=6, Print_kind=7,
- For_kind=8, While_kind=9, If_kind=10, With_kind=11,
- Raise_kind=12, TryExcept_kind=13, TryFinally_kind=14,
- Assert_kind=15, Import_kind=16, ImportFrom_kind=17,
- Exec_kind=18, Global_kind=19, Expr_kind=20, Pass_kind=21,
- Break_kind=22, Continue_kind=23};
+ Delete_kind=4, Assign_kind=5, AugAssign_kind=6, For_kind=7,
+ While_kind=8, If_kind=9, With_kind=10, Raise_kind=11,
+ TryExcept_kind=12, TryFinally_kind=13, Assert_kind=14,
+ Import_kind=15, ImportFrom_kind=16, Global_kind=17,
+ Nonlocal_kind=18, Expr_kind=19, Pass_kind=20, Break_kind=21,
+ Continue_kind=22};
struct _stmt {
enum _stmt_kind kind;
union {
@@ -74,11 +76,15 @@ struct _stmt {
arguments_ty args;
asdl_seq *body;
asdl_seq *decorator_list;
+ expr_ty returns;
} FunctionDef;
struct {
identifier name;
asdl_seq *bases;
+ asdl_seq *keywords;
+ expr_ty starargs;
+ expr_ty kwargs;
asdl_seq *body;
asdl_seq *decorator_list;
} ClassDef;
@@ -103,12 +109,6 @@ struct _stmt {
} AugAssign;
struct {
- expr_ty dest;
- asdl_seq *values;
- bool nl;
- } Print;
-
- struct {
expr_ty target;
expr_ty iter;
asdl_seq *body;
@@ -134,9 +134,8 @@ struct _stmt {
} With;
struct {
- expr_ty type;
- expr_ty inst;
- expr_ty tback;
+ expr_ty exc;
+ expr_ty cause;
} Raise;
struct {
@@ -166,14 +165,12 @@ struct _stmt {
} ImportFrom;
struct {
- expr_ty body;
- expr_ty globals;
- expr_ty locals;
- } Exec;
+ asdl_seq *names;
+ } Global;
struct {
asdl_seq *names;
- } Global;
+ } Nonlocal;
struct {
expr_ty value;
@@ -187,9 +184,10 @@ struct _stmt {
enum _expr_kind {BoolOp_kind=1, BinOp_kind=2, UnaryOp_kind=3, Lambda_kind=4,
IfExp_kind=5, Dict_kind=6, Set_kind=7, ListComp_kind=8,
SetComp_kind=9, DictComp_kind=10, GeneratorExp_kind=11,
- Yield_kind=12, Compare_kind=13, Call_kind=14, Repr_kind=15,
- Num_kind=16, Str_kind=17, Attribute_kind=18,
- Subscript_kind=19, Name_kind=20, List_kind=21, Tuple_kind=22};
+ Yield_kind=12, Compare_kind=13, Call_kind=14, Num_kind=15,
+ Str_kind=16, Bytes_kind=17, Ellipsis_kind=18,
+ Attribute_kind=19, Subscript_kind=20, Starred_kind=21,
+ Name_kind=22, List_kind=23, Tuple_kind=24};
struct _expr {
enum _expr_kind kind;
union {
@@ -269,10 +267,6 @@ struct _expr {
} Call;
struct {
- expr_ty value;
- } Repr;
-
- struct {
object n;
} Num;
@@ -281,6 +275,10 @@ struct _expr {
} Str;
struct {
+ string s;
+ } Bytes;
+
+ struct {
expr_ty value;
identifier attr;
expr_context_ty ctx;
@@ -293,6 +291,11 @@ struct _expr {
} Subscript;
struct {
+ expr_ty value;
+ expr_context_ty ctx;
+ } Starred;
+
+ struct {
identifier id;
expr_context_ty ctx;
} Name;
@@ -312,7 +315,7 @@ struct _expr {
int col_offset;
};
-enum _slice_kind {Ellipsis_kind=1, Slice_kind=2, ExtSlice_kind=3, Index_kind=4};
+enum _slice_kind {Slice_kind=1, ExtSlice_kind=2, Index_kind=3};
struct _slice {
enum _slice_kind kind;
union {
@@ -345,7 +348,7 @@ struct _excepthandler {
union {
struct {
expr_ty type;
- expr_ty name;
+ identifier name;
asdl_seq *body;
} ExceptHandler;
@@ -357,8 +360,17 @@ struct _excepthandler {
struct _arguments {
asdl_seq *args;
identifier vararg;
+ expr_ty varargannotation;
+ asdl_seq *kwonlyargs;
identifier kwarg;
+ expr_ty kwargannotation;
asdl_seq *defaults;
+ asdl_seq *kw_defaults;
+};
+
+struct _arg {
+ identifier arg;
+ expr_ty annotation;
};
struct _keyword {
@@ -380,12 +392,13 @@ mod_ty _Py_Interactive(asdl_seq * body, PyArena *arena);
mod_ty _Py_Expression(expr_ty body, PyArena *arena);
#define Suite(a0, a1) _Py_Suite(a0, a1)
mod_ty _Py_Suite(asdl_seq * body, PyArena *arena);
-#define FunctionDef(a0, a1, a2, a3, a4, a5, a6) _Py_FunctionDef(a0, a1, a2, a3, a4, a5, a6)
+#define FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7) _Py_FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7)
stmt_ty _Py_FunctionDef(identifier name, arguments_ty args, asdl_seq * body,
- asdl_seq * decorator_list, int lineno, int col_offset,
- PyArena *arena);
-#define ClassDef(a0, a1, a2, a3, a4, a5, a6) _Py_ClassDef(a0, a1, a2, a3, a4, a5, a6)
-stmt_ty _Py_ClassDef(identifier name, asdl_seq * bases, asdl_seq * body,
+ asdl_seq * decorator_list, expr_ty returns, int lineno,
+ int col_offset, PyArena *arena);
+#define ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) _Py_ClassDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)
+stmt_ty _Py_ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords,
+ expr_ty starargs, expr_ty kwargs, asdl_seq * body,
asdl_seq * decorator_list, int lineno, int col_offset,
PyArena *arena);
#define Return(a0, a1, a2, a3) _Py_Return(a0, a1, a2, a3)
@@ -399,9 +412,6 @@ stmt_ty _Py_Assign(asdl_seq * targets, expr_ty value, int lineno, int
#define AugAssign(a0, a1, a2, a3, a4, a5) _Py_AugAssign(a0, a1, a2, a3, a4, a5)
stmt_ty _Py_AugAssign(expr_ty target, operator_ty op, expr_ty value, int
lineno, int col_offset, PyArena *arena);
-#define Print(a0, a1, a2, a3, a4, a5) _Py_Print(a0, a1, a2, a3, a4, a5)
-stmt_ty _Py_Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int
- col_offset, PyArena *arena);
#define For(a0, a1, a2, a3, a4, a5, a6) _Py_For(a0, a1, a2, a3, a4, a5, a6)
stmt_ty _Py_For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq *
orelse, int lineno, int col_offset, PyArena *arena);
@@ -414,9 +424,9 @@ stmt_ty _Py_If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno,
#define With(a0, a1, a2, a3, a4, a5) _Py_With(a0, a1, a2, a3, a4, a5)
stmt_ty _Py_With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body,
int lineno, int col_offset, PyArena *arena);
-#define Raise(a0, a1, a2, a3, a4, a5) _Py_Raise(a0, a1, a2, a3, a4, a5)
-stmt_ty _Py_Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int
- col_offset, PyArena *arena);
+#define Raise(a0, a1, a2, a3, a4) _Py_Raise(a0, a1, a2, a3, a4)
+stmt_ty _Py_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset,
+ PyArena *arena);
#define TryExcept(a0, a1, a2, a3, a4, a5) _Py_TryExcept(a0, a1, a2, a3, a4, a5)
stmt_ty _Py_TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse,
int lineno, int col_offset, PyArena *arena);
@@ -432,12 +442,12 @@ stmt_ty _Py_Import(asdl_seq * names, int lineno, int col_offset, PyArena
#define ImportFrom(a0, a1, a2, a3, a4, a5) _Py_ImportFrom(a0, a1, a2, a3, a4, a5)
stmt_ty _Py_ImportFrom(identifier module, asdl_seq * names, int level, int
lineno, int col_offset, PyArena *arena);
-#define Exec(a0, a1, a2, a3, a4, a5) _Py_Exec(a0, a1, a2, a3, a4, a5)
-stmt_ty _Py_Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int
- col_offset, PyArena *arena);
#define Global(a0, a1, a2, a3) _Py_Global(a0, a1, a2, a3)
stmt_ty _Py_Global(asdl_seq * names, int lineno, int col_offset, PyArena
*arena);
+#define Nonlocal(a0, a1, a2, a3) _Py_Nonlocal(a0, a1, a2, a3)
+stmt_ty _Py_Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena
+ *arena);
#define Expr(a0, a1, a2, a3) _Py_Expr(a0, a1, a2, a3)
stmt_ty _Py_Expr(expr_ty value, int lineno, int col_offset, PyArena *arena);
#define Pass(a0, a1, a2) _Py_Pass(a0, a1, a2)
@@ -487,18 +497,23 @@ expr_ty _Py_Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators,
expr_ty _Py_Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty
starargs, expr_ty kwargs, int lineno, int col_offset, PyArena
*arena);
-#define Repr(a0, a1, a2, a3) _Py_Repr(a0, a1, a2, a3)
-expr_ty _Py_Repr(expr_ty value, int lineno, int col_offset, PyArena *arena);
#define Num(a0, a1, a2, a3) _Py_Num(a0, a1, a2, a3)
expr_ty _Py_Num(object n, int lineno, int col_offset, PyArena *arena);
#define Str(a0, a1, a2, a3) _Py_Str(a0, a1, a2, a3)
expr_ty _Py_Str(string s, int lineno, int col_offset, PyArena *arena);
+#define Bytes(a0, a1, a2, a3) _Py_Bytes(a0, a1, a2, a3)
+expr_ty _Py_Bytes(string s, int lineno, int col_offset, PyArena *arena);
+#define Ellipsis(a0, a1, a2) _Py_Ellipsis(a0, a1, a2)
+expr_ty _Py_Ellipsis(int lineno, int col_offset, PyArena *arena);
#define Attribute(a0, a1, a2, a3, a4, a5) _Py_Attribute(a0, a1, a2, a3, a4, a5)
expr_ty _Py_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
lineno, int col_offset, PyArena *arena);
#define Subscript(a0, a1, a2, a3, a4, a5) _Py_Subscript(a0, a1, a2, a3, a4, a5)
expr_ty _Py_Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int
lineno, int col_offset, PyArena *arena);
+#define Starred(a0, a1, a2, a3, a4) _Py_Starred(a0, a1, a2, a3, a4)
+expr_ty _Py_Starred(expr_ty value, expr_context_ty ctx, int lineno, int
+ col_offset, PyArena *arena);
#define Name(a0, a1, a2, a3, a4) _Py_Name(a0, a1, a2, a3, a4)
expr_ty _Py_Name(identifier id, expr_context_ty ctx, int lineno, int
col_offset, PyArena *arena);
@@ -508,8 +523,6 @@ expr_ty _Py_List(asdl_seq * elts, expr_context_ty ctx, int lineno, int
#define Tuple(a0, a1, a2, a3, a4) _Py_Tuple(a0, a1, a2, a3, a4)
expr_ty _Py_Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int
col_offset, PyArena *arena);
-#define Ellipsis(a0) _Py_Ellipsis(a0)
-slice_ty _Py_Ellipsis(PyArena *arena);
#define Slice(a0, a1, a2, a3) _Py_Slice(a0, a1, a2, a3)
slice_ty _Py_Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena);
#define ExtSlice(a0, a1) _Py_ExtSlice(a0, a1)
@@ -520,11 +533,16 @@ slice_ty _Py_Index(expr_ty value, PyArena *arena);
comprehension_ty _Py_comprehension(expr_ty target, expr_ty iter, asdl_seq *
ifs, PyArena *arena);
#define ExceptHandler(a0, a1, a2, a3, a4, a5) _Py_ExceptHandler(a0, a1, a2, a3, a4, a5)
-excepthandler_ty _Py_ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body,
- int lineno, int col_offset, PyArena *arena);
-#define arguments(a0, a1, a2, a3, a4) _Py_arguments(a0, a1, a2, a3, a4)
-arguments_ty _Py_arguments(asdl_seq * args, identifier vararg, identifier
- kwarg, asdl_seq * defaults, PyArena *arena);
+excepthandler_ty _Py_ExceptHandler(expr_ty type, identifier name, asdl_seq *
+ body, int lineno, int col_offset, PyArena
+ *arena);
+#define arguments(a0, a1, a2, a3, a4, a5, a6, a7, a8) _Py_arguments(a0, a1, a2, a3, a4, a5, a6, a7, a8)
+arguments_ty _Py_arguments(asdl_seq * args, identifier vararg, expr_ty
+ varargannotation, asdl_seq * kwonlyargs, identifier
+ kwarg, expr_ty kwargannotation, asdl_seq * defaults,
+ asdl_seq * kw_defaults, PyArena *arena);
+#define arg(a0, a1, a2) _Py_arg(a0, a1, a2)
+arg_ty _Py_arg(identifier arg, expr_ty annotation, PyArena *arena);
#define keyword(a0, a1, a2) _Py_keyword(a0, a1, a2)
keyword_ty _Py_keyword(identifier arg, expr_ty value, PyArena *arena);
#define alias(a0, a1, a2) _Py_alias(a0, a1, a2)
diff --git a/Include/Python.h b/Include/Python.h
index 775412b8c4e..d6e47c24630 100644
--- a/Include/Python.h
+++ b/Include/Python.h
@@ -8,14 +8,6 @@
#include "pyconfig.h"
#include "pymacconfig.h"
-/* Cyclic gc is always enabled, starting with release 2.3a1. Supply the
- * old symbol for the benefit of extension modules written before then
- * that may be conditionalizing on it. The core doesn't use it anymore.
- */
-#ifndef WITH_CYCLE_GC
-#define WITH_CYCLE_GC 1
-#endif
-
#include <limits.h>
#ifndef UCHAR_MAX
@@ -57,13 +49,7 @@
#include "pyport.h"
-/* pyconfig.h or pyport.h may or may not define DL_IMPORT */
-#ifndef DL_IMPORT /* declarations for DLL import/export */
-#define DL_IMPORT(RTYPE) RTYPE
-#endif
-#ifndef DL_EXPORT /* declarations for DLL import/export */
-#define DL_EXPORT(RTYPE) RTYPE
-#endif
+#include "pyatomic.h"
/* Debug-mode build with pymalloc implies PYMALLOC_DEBUG.
* PYMALLOC_DEBUG is in error if pymalloc is not in use.
@@ -75,27 +61,25 @@
#error "PYMALLOC_DEBUG requires WITH_PYMALLOC"
#endif
#include "pymath.h"
+#include "pytime.h"
#include "pymem.h"
#include "object.h"
#include "objimpl.h"
+#include "typeslots.h"
#include "pydebug.h"
+#include "bytearrayobject.h"
+#include "bytesobject.h"
#include "unicodeobject.h"
-#include "intobject.h"
-#include "boolobject.h"
#include "longobject.h"
+#include "longintrepr.h"
+#include "boolobject.h"
#include "floatobject.h"
-#ifndef WITHOUT_COMPLEX
#include "complexobject.h"
-#endif
#include "rangeobject.h"
-#include "stringobject.h"
#include "memoryobject.h"
-#include "bufferobject.h"
-#include "bytesobject.h"
-#include "bytearrayobject.h"
#include "tupleobject.h"
#include "listobject.h"
#include "dictobject.h"
@@ -106,7 +90,6 @@
#include "funcobject.h"
#include "classobject.h"
#include "fileobject.h"
-#include "cobject.h"
#include "pycapsule.h"
#include "traceback.h"
#include "sliceobject.h"
@@ -116,6 +99,7 @@
#include "descrobject.h"
#include "warnings.h"
#include "weakrefobject.h"
+#include "structseq.h"
#include "codecs.h"
#include "pyerrors.h"
@@ -131,6 +115,7 @@
#include "import.h"
#include "abstract.h"
+#include "bltinmodule.h"
#include "compile.h"
#include "eval.h"
@@ -139,19 +124,23 @@
#include "pystrtod.h"
#include "pystrcmp.h"
#include "dtoa.h"
+#include "fileutils.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
/* _Py_Mangle is defined in compile.c */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
+#endif
-/* PyArg_GetInt is deprecated and should not be used, use PyArg_Parse(). */
-#define PyArg_GetInt(v, a) PyArg_Parse((v), "i", (a))
-
-/* PyArg_NoArgs should not be necessary.
- Set ml_flags in the PyMethodDef to METH_NOARGS. */
-#define PyArg_NoArgs(v) PyArg_Parse(v, "")
+#ifdef __cplusplus
+}
+#endif
/* Argument must be a char or an int in [-128, 127] or [0, 255]. */
-#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
+#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
#include "pyfpe.h"
diff --git a/Include/abstract.h b/Include/abstract.h
index a377423868b..0fe0956b14f 100644
--- a/Include/abstract.h
+++ b/Include/abstract.h
@@ -228,29 +228,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
*/
#define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A),NULL)
- PyAPI_FUNC(int) PyObject_Cmp(PyObject *o1, PyObject *o2, int *result);
-
- /*
- Compare the values of o1 and o2 using a routine provided by
- o1, if one exists, otherwise with a routine provided by o2.
- The result of the comparison is returned in result. Returns
- -1 on failure. This is the equivalent of the Python
- statement: result=cmp(o1,o2).
-
- */
-
- /* Implemented elsewhere:
-
- int PyObject_Compare(PyObject *o1, PyObject *o2);
-
- Compare the values of o1 and o2 using a routine provided by
- o1, if one exists, otherwise with a routine provided by o2.
- Returns the result of the comparison on success. On error,
- the value returned is undefined. This is equivalent to the
- Python expression: cmp(o1,o2).
-
- */
-
/* Implemented elsewhere:
PyObject *PyObject_Repr(PyObject *o);
@@ -259,7 +236,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
string representation on success, NULL on failure. This is
the equivalent of the Python expression: repr(o).
- Called by the repr() built-in function and by reverse quotes.
+ Called by the repr() built-in function.
*/
@@ -271,20 +248,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
string representation on success, NULL on failure. This is
the equivalent of the Python expression: str(o).)
- Called by the str() built-in function and by the print
- statement.
-
- */
-
- /* Implemented elsewhere:
-
- PyObject *PyObject_Unicode(PyObject *o);
-
- Compute the unicode representation of object, o. Returns the
- unicode representation on success, NULL on failure. This is
- the equivalent of the Python expression: unistr(o).)
-
- Called by the unistr() built-in function.
+ Called by the str() and print() built-in functions.
*/
@@ -296,35 +260,30 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
object is callable and 0 otherwise.
This function always succeeds.
-
*/
-
-
PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable_object,
- PyObject *args, PyObject *kw);
+ PyObject *args, PyObject *kw);
/*
Call a callable Python object, callable_object, with
arguments and keywords arguments. The 'args' argument can not be
NULL, but the 'kw' argument can be NULL.
-
*/
PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable_object,
- PyObject *args);
+ PyObject *args);
/*
Call a callable Python object, callable_object, with
arguments given by the tuple, args. If no arguments are
needed, then args may be NULL. Returns the result of the
call on success, or NULL on failure. This is the equivalent
- of the Python expression: apply(o,args).
-
+ of the Python expression: o(*args).
*/
PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable_object,
- char *format, ...);
+ char *format, ...);
/*
Call a callable Python object, callable_object, with a
@@ -332,13 +291,12 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
using a mkvalue-style format string. The format may be NULL,
indicating that no arguments are provided. Returns the
result of the call on success, or NULL on failure. This is
- the equivalent of the Python expression: apply(o,args).
-
+ the equivalent of the Python expression: o(*args).
*/
- PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *o, char *m,
- char *format, ...);
+ PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *o, char *method,
+ char *format, ...);
/*
Call the method named m of object o with a variable number of
@@ -356,19 +314,19 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
char *format, ...);
PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,
- ...);
+ ...);
/*
Call a callable Python object, callable_object, with a
variable number of C arguments. The C arguments are provided
as PyObject * values, terminated by a NULL. Returns the
result of the call on success, or NULL on failure. This is
- the equivalent of the Python expression: apply(o,args).
+ the equivalent of the Python expression: o(*args).
*/
PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(PyObject *o,
- PyObject *m, ...);
+ PyObject *method, ...);
/*
Call the method named m of object o with a variable number of
@@ -386,7 +344,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Compute and return the hash, hash_value, of an object, o. On
failure, return -1. This is the equivalent of the Python
expression: hash(o).
-
*/
@@ -397,7 +354,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns 1 if the object, o, is considered to be true, 0 if o is
considered to be false and -1 on failure. This is equivalent to the
Python expression: not not o
-
*/
/* Implemented elsewhere:
@@ -407,7 +363,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns 0 if the object, o, is considered to be true, 1 if o is
considered to be false and -1 on failure. This is equivalent to the
Python expression: not o
-
*/
PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o);
@@ -425,7 +380,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
both sequence and mapping protocols, the sequence size is
returned. On error, -1 is returned. This is the equivalent
to the Python expression: len(o).
-
*/
/* For DLL compatibility */
@@ -433,7 +387,9 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);
#define PyObject_Length PyObject_Size
+#ifndef Py_LIMITED_API
PyAPI_FUNC(Py_ssize_t) _PyObject_LengthHint(PyObject *o, Py_ssize_t);
+#endif
/*
Guess the size of object o using len(o) or o.__length_hint__().
@@ -447,7 +403,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Return element of o corresponding to the object, key, or NULL
on failure. This is the equivalent of the Python expression:
o[key].
-
*/
PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);
@@ -473,9 +428,15 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
This is the equivalent of the Python statement: del o[key].
*/
+ /* old buffer API
+ FIXME: usage of these should all be replaced in Python itself
+ but for backwards compatibility we will implement them.
+ Their usage without a corresponding "unlock" mechansim
+ may create issues (but they would already be there). */
+
PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
- const char **buffer,
- Py_ssize_t *buffer_len);
+ const char **buffer,
+ Py_ssize_t *buffer_len);
/*
Takes an arbitrary object which must support the (character,
@@ -486,7 +447,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
0 is returned on success. buffer and buffer_len are only
set in case no error occurs. Otherwise, -1 is returned and
an exception set.
-
*/
PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);
@@ -495,12 +455,11 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Checks whether an arbitrary object supports the (character,
single segment) buffer interface. Returns 1 on success, 0
on failure.
-
*/
PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
- const void **buffer,
- Py_ssize_t *buffer_len);
+ const void **buffer,
+ Py_ssize_t *buffer_len);
/*
Same as PyObject_AsCharBuffer() except that this API expects
@@ -511,29 +470,27 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
0 is returned on success. buffer and buffer_len are only
set in case no error occurs. Otherwise, -1 is returned and
an exception set.
-
*/
PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
- void **buffer,
- Py_ssize_t *buffer_len);
+ void **buffer,
+ Py_ssize_t *buffer_len);
/*
- Takes an arbitrary object which must support the (writeable,
+ Takes an arbitrary object which must support the (writable,
single segment) buffer interface and returns a pointer to a
- writeable memory location in buffer of size buffer_len.
+ writable memory location in buffer of size buffer_len.
0 is returned on success. buffer and buffer_len are only
set in case no error occurs. Otherwise, -1 is returned and
an exception set.
-
*/
/* new buffer API */
+#ifndef Py_LIMITED_API
#define PyObject_CheckBuffer(obj) \
- (((obj)->ob_type->tp_as_buffer != NULL) && \
- (PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_NEWBUFFER)) && \
+ (((obj)->ob_type->tp_as_buffer != NULL) && \
((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL))
/* Return 1 if the getbuffer function is available, otherwise
@@ -575,7 +532,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
error (i.e. the object does not have a buffer interface or
it is not working).
- If fort is 'F' and the object is multi-dimensional,
+ If fort is 'F', then if the object is multi-dimensional,
then the data will be copied into the array in
Fortran-style (first dimension varies the fastest). If
fort is 'C', then the data will be copied into the array
@@ -619,6 +576,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/* Releases a Py_buffer obtained from getbuffer ParseTuple's s*.
*/
+#endif /* Py_LIMITED_API */
PyAPI_FUNC(PyObject *) PyObject_Format(PyObject* obj,
PyObject *format_spec);
@@ -635,8 +593,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
is an iterator, this returns itself. */
#define PyIter_Check(obj) \
- (PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_ITER) && \
- (obj)->ob_type->tp_iternext != NULL && \
+ ((obj)->ob_type->tp_iternext != NULL && \
(obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented)
PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);
@@ -654,7 +611,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
false otherwise.
This function always succeeds.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2);
@@ -662,8 +618,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
Returns the result of adding o1 and o2, or null on failure.
This is the equivalent of the Python expression: o1+o2.
-
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);
@@ -672,7 +626,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of subtracting o2 from o1, or null on
failure. This is the equivalent of the Python expression:
o1-o2.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);
@@ -681,17 +634,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of multiplying o1 and o2, or null on
failure. This is the equivalent of the Python expression:
o1*o2.
-
-
- */
-
- PyAPI_FUNC(PyObject *) PyNumber_Divide(PyObject *o1, PyObject *o2);
-
- /*
- Returns the result of dividing o1 by o2, or null on failure.
- This is the equivalent of the Python expression: o1/o2.
-
-
*/
PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2);
@@ -700,8 +642,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of dividing o1 by o2 giving an integral result,
or null on failure.
This is the equivalent of the Python expression: o1//o2.
-
-
*/
PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2);
@@ -710,8 +650,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of dividing o1 by o2 giving a float result,
or null on failure.
This is the equivalent of the Python expression: o1/o2.
-
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2);
@@ -720,8 +658,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the remainder of dividing o1 by o2, or null on
failure. This is the equivalent of the Python expression:
o1%o2.
-
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2);
@@ -730,18 +666,15 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
See the built-in function divmod. Returns NULL on failure.
This is the equivalent of the Python expression:
divmod(o1,o2).
-
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,
- PyObject *o3);
+ PyObject *o3);
/*
See the built-in function pow. Returns NULL on failure.
This is the equivalent of the Python expression:
pow(o1,o2,o3), where o3 is optional.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o);
@@ -749,7 +682,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
Returns the negation of o on success, or null on failure.
This is the equivalent of the Python expression: -o.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o);
@@ -757,7 +689,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
Returns the (what?) of o on success, or NULL on failure.
This is the equivalent of the Python expression: +o.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o);
@@ -765,7 +696,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
Returns the absolute value of o, or null on failure. This is
the equivalent of the Python expression: abs(o).
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o);
@@ -774,8 +704,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the bitwise negation of o on success, or NULL on
failure. This is the equivalent of the Python expression:
~o.
-
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2);
@@ -784,8 +712,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of left shifting o1 by o2 on success, or
NULL on failure. This is the equivalent of the Python
expression: o1 << o2.
-
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2);
@@ -794,7 +720,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of right shifting o1 by o2 on success, or
NULL on failure. This is the equivalent of the Python
expression: o1 >> o2.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2);
@@ -804,7 +729,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
NULL on failure. This is the equivalent of the Python
expression: o1&o2.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2);
@@ -813,8 +737,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the bitwise exclusive or of o1 by o2 on success, or
NULL on failure. This is the equivalent of the Python
expression: o1^o2.
-
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);
@@ -823,31 +745,10 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of bitwise or on o1 and o2 on success, or
NULL on failure. This is the equivalent of the Python
expression: o1|o2.
-
- */
-
- /* Implemented elsewhere:
-
- int PyNumber_Coerce(PyObject **p1, PyObject **p2);
-
- This function takes the addresses of two variables of type
- PyObject*.
-
- If the objects pointed to by *p1 and *p2 have the same type,
- increment their reference count and return 0 (success).
- If the objects can be converted to a common numeric type,
- replace *p1 and *p2 by their converted value (with 'new'
- reference counts), and return 0.
- If no conversion is possible, or if some other error occurs,
- return -1 (failure) and don't increment the reference counts.
- The call PyNumber_Coerce(&o1, &o2) is equivalent to the Python
- statement o1, o2 = coerce(o1, o2).
-
*/
#define PyIndex_Check(obj) \
((obj)->ob_type->tp_as_number != NULL && \
- PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_INDEX) && \
(obj)->ob_type->tp_as_number->nb_index != NULL)
PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o);
@@ -868,9 +769,11 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
that can accept a char* naming integral's type.
*/
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyNumber_ConvertIntegralToInt(
PyObject *integral,
const char* error_format);
+#endif
/*
Returns the object converted to Py_ssize_t by going through
@@ -880,22 +783,12 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
is cleared and the value is clipped.
*/
- PyAPI_FUNC(PyObject *) PyNumber_Int(PyObject *o);
+ PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o);
/*
Returns the o converted to an integer object on success, or
NULL on failure. This is the equivalent of the Python
expression: int(o).
-
- */
-
- PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o);
-
- /*
- Returns the o converted to a long integer object on success,
- or NULL on failure. This is the equivalent of the Python
- expression: long(o).
-
*/
PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o);
@@ -914,7 +807,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of adding o2 to o1, possibly in-place, or null
on failure. This is the equivalent of the Python expression:
o1 += o2.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
@@ -923,7 +815,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of subtracting o2 from o1, possibly in-place or
null on failure. This is the equivalent of the Python expression:
o1 -= o2.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
@@ -932,38 +823,26 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of multiplying o1 by o2, possibly in-place, or
null on failure. This is the equivalent of the Python expression:
o1 *= o2.
-
- */
-
- PyAPI_FUNC(PyObject *) PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2);
-
- /*
- Returns the result of dividing o1 by o2, possibly in-place, or null
- on failure. This is the equivalent of the Python expression:
- o1 /= o2.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1,
- PyObject *o2);
+ PyObject *o2);
/*
Returns the result of dividing o1 by o2 giving an integral result,
possibly in-place, or null on failure.
This is the equivalent of the Python expression:
o1 /= o2.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1,
- PyObject *o2);
+ PyObject *o2);
/*
Returns the result of dividing o1 by o2 giving a float result,
possibly in-place, or null on failure.
This is the equivalent of the Python expression:
o1 /= o2.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);
@@ -972,17 +851,15 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the remainder of dividing o1 by o2, possibly in-place, or
null on failure. This is the equivalent of the Python expression:
o1 %= o2.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,
- PyObject *o3);
+ PyObject *o3);
/*
Returns the result of raising o1 to the power of o2, possibly
in-place, or null on failure. This is the equivalent of the Python
expression: o1 **= o2, or pow(o1, o2, o3) if o3 is present.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);
@@ -991,7 +868,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of left shifting o1 by o2, possibly in-place, or
null on failure. This is the equivalent of the Python expression:
o1 <<= o2.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);
@@ -1000,7 +876,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of right shifting o1 by o2, possibly in-place or
null on failure. This is the equivalent of the Python expression:
o1 >>= o2.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);
@@ -1009,7 +884,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of bitwise and of o1 and o2, possibly in-place,
or null on failure. This is the equivalent of the Python
expression: o1 &= o2.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);
@@ -1018,7 +892,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the bitwise exclusive or of o1 by o2, possibly in-place, or
null on failure. This is the equivalent of the Python expression:
o1 ^= o2.
-
*/
PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);
@@ -1027,10 +900,8 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Returns the result of bitwise or of o1 and o2, possibly in-place,
or null on failure. This is the equivalent of the Python
expression: o1 |= o2.
-
*/
-
PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base);
/*
@@ -1049,14 +920,12 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
otherwise.
This function always succeeds.
-
*/
PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o);
/*
Return the size of sequence object o, or -1 on failure.
-
*/
/* For DLL compatibility */
@@ -1071,7 +940,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Return the concatenation of o1 and o2 on success, and NULL on
failure. This is the equivalent of the Python
expression: o1+o2.
-
*/
PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count);
@@ -1080,7 +948,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Return the result of repeating sequence object o count times,
or NULL on failure. This is the equivalent of the Python
expression: o1*count.
-
*/
PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i);
@@ -1096,7 +963,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Return the slice of sequence object o between i1 and i2, or
NULL on failure. This is the equivalent of the Python
expression: o[i1:i2].
-
*/
PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);
@@ -1105,7 +971,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Assign object v to the ith element of o. Returns
-1 on failure. This is the equivalent of the Python
statement: o[i]=v.
-
*/
PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);
@@ -1117,7 +982,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
*/
PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2,
- PyObject *v);
+ PyObject *v);
/*
Assign the sequence object, v, to the slice in sequence
@@ -1198,11 +1063,13 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
Use __contains__ if possible, else _PySequence_IterSearch().
*/
+#ifndef Py_LIMITED_API
#define PY_ITERSEARCH_COUNT 1
#define PY_ITERSEARCH_INDEX 2
#define PY_ITERSEARCH_CONTAINS 3
PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq,
PyObject *obj, int operation);
+#endif
/*
Iterate over seq. Result depends on the operation:
PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if
@@ -1305,7 +1172,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
On success, return 1 if the mapping object has the key, key,
and 0 otherwise. This is equivalent to the Python expression:
- o.has_key(key).
+ key in o.
This function always succeeds.
*/
@@ -1315,43 +1182,34 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*
Return 1 if the mapping object has the key, key,
and 0 otherwise. This is equivalent to the Python expression:
- o.has_key(key).
+ key in o.
This function always succeeds.
*/
- /* Implemented as macro:
-
- PyObject *PyMapping_Keys(PyObject *o);
+ PyAPI_FUNC(PyObject *) PyMapping_Keys(PyObject *o);
- On success, return a list of the keys in object o. On
- failure, return NULL. This is equivalent to the Python
- expression: o.keys().
+ /*
+ On success, return a list or tuple of the keys in object o.
+ On failure, return NULL.
*/
-#define PyMapping_Keys(O) PyObject_CallMethod(O,"keys",NULL)
-
- /* Implemented as macro:
- PyObject *PyMapping_Values(PyObject *o);
+ PyAPI_FUNC(PyObject *) PyMapping_Values(PyObject *o);
- On success, return a list of the values in object o. On
- failure, return NULL. This is equivalent to the Python
- expression: o.values().
+ /*
+ On success, return a list or tuple of the values in object o.
+ On failure, return NULL.
*/
-#define PyMapping_Values(O) PyObject_CallMethod(O,"values",NULL)
-
- /* Implemented as macro:
- PyObject *PyMapping_Items(PyObject *o);
+ PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o);
- On success, return a list of the items in object o, where
- each item is a tuple containing a key-value pair. On
- failure, return NULL. This is equivalent to the Python
- expression: o.items().
+ /*
+ On success, return a list or tuple of the items in object o,
+ where each item is a tuple containing a key-value pair.
+ On failure, return NULL.
*/
-#define PyMapping_Items(O) PyObject_CallMethod(O,"items",NULL)
PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, char *key);
@@ -1378,10 +1236,15 @@ PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);
/* issubclass(object, typeorclass) */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyObject_RealIsInstance(PyObject *inst, PyObject *cls);
PyAPI_FUNC(int) _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls);
+PyAPI_FUNC(char *const *) _PySequence_BytesToCharpArray(PyObject* self);
+
+PyAPI_FUNC(void) _Py_FreeCharPArray(char *const array[]);
+#endif
/* For internal use by buffer API functions */
PyAPI_FUNC(void) _Py_add_one_to_index_F(int nd, Py_ssize_t *index,
diff --git a/Include/accu.h b/Include/accu.h
new file mode 100644
index 00000000000..3636ea6c98f
--- /dev/null
+++ b/Include/accu.h
@@ -0,0 +1,37 @@
+#ifndef Py_LIMITED_API
+#ifndef Py_ACCU_H
+#define Py_ACCU_H
+
+/*** This is a private API for use by the interpreter and the stdlib.
+ *** Its definition may be changed or removed at any moment.
+ ***/
+
+/*
+ * A two-level accumulator of unicode objects that avoids both the overhead
+ * of keeping a huge number of small separate objects, and the quadratic
+ * behaviour of using a naive repeated concatenation scheme.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#undef small /* defined by some Windows headers */
+
+typedef struct {
+ PyObject *large; /* A list of previously accumulated large strings */
+ PyObject *small; /* Pending small strings */
+} _PyAccu;
+
+PyAPI_FUNC(int) _PyAccu_Init(_PyAccu *acc);
+PyAPI_FUNC(int) _PyAccu_Accumulate(_PyAccu *acc, PyObject *unicode);
+PyAPI_FUNC(PyObject *) _PyAccu_FinishAsList(_PyAccu *acc);
+PyAPI_FUNC(PyObject *) _PyAccu_Finish(_PyAccu *acc);
+PyAPI_FUNC(void) _PyAccu_Destroy(_PyAccu *acc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* Py_ACCU_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/asdl.h b/Include/asdl.h
index 84e837e752a..9bb06978da2 100644
--- a/Include/asdl.h
+++ b/Include/asdl.h
@@ -5,10 +5,6 @@ typedef PyObject * identifier;
typedef PyObject * string;
typedef PyObject * object;
-#ifndef __cplusplus
-typedef enum {false, true} bool;
-#endif
-
/* It would be nice if the code generated by asdl_c.py was completely
independent of Python, but it is a goal the requires too much work
at this stage. So, for example, I'll represent identifiers as
diff --git a/Include/ast.h b/Include/ast.h
index cc14b7fd762..a015336f032 100644
--- a/Include/ast.h
+++ b/Include/ast.h
@@ -4,8 +4,11 @@
extern "C" {
#endif
-PyAPI_FUNC(mod_ty) PyAST_FromNode(const node *, PyCompilerFlags *flags,
- const char *, PyArena *);
+PyAPI_FUNC(mod_ty) PyAST_FromNode(
+ const node *n,
+ PyCompilerFlags *flags,
+ const char *filename, /* decoded from the filesystem encoding */
+ PyArena *arena);
#ifdef __cplusplus
}
diff --git a/Include/bltinmodule.h b/Include/bltinmodule.h
new file mode 100644
index 00000000000..868c9e6443b
--- /dev/null
+++ b/Include/bltinmodule.h
@@ -0,0 +1,14 @@
+#ifndef Py_BLTINMODULE_H
+#define Py_BLTINMODULE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+PyAPI_DATA(PyTypeObject) PyFilter_Type;
+PyAPI_DATA(PyTypeObject) PyMap_Type;
+PyAPI_DATA(PyTypeObject) PyZip_Type;
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_BLTINMODULE_H */
diff --git a/Include/boolobject.h b/Include/boolobject.h
index 74e854f706b..7cc2f1fe239 100644
--- a/Include/boolobject.h
+++ b/Include/boolobject.h
@@ -7,8 +7,6 @@ extern "C" {
#endif
-typedef PyIntObject PyBoolObject;
-
PyAPI_DATA(PyTypeObject) PyBool_Type;
#define PyBool_Check(x) (Py_TYPE(x) == &PyBool_Type)
@@ -17,10 +15,10 @@ PyAPI_DATA(PyTypeObject) PyBool_Type;
Don't forget to apply Py_INCREF() when returning either!!! */
/* Don't use these directly */
-PyAPI_DATA(PyIntObject) _Py_ZeroStruct, _Py_TrueStruct;
+PyAPI_DATA(struct _longobject) _Py_FalseStruct, _Py_TrueStruct;
/* Use these macros */
-#define Py_False ((PyObject *) &_Py_ZeroStruct)
+#define Py_False ((PyObject *) &_Py_FalseStruct)
#define Py_True ((PyObject *) &_Py_TrueStruct)
/* Macros for returning Py_True or Py_False, respectively */
diff --git a/Include/bufferobject.h b/Include/bufferobject.h
deleted file mode 100644
index 6dd83458c58..00000000000
--- a/Include/bufferobject.h
+++ /dev/null
@@ -1,33 +0,0 @@
-
-/* Buffer object interface */
-
-/* Note: the object's structure is private */
-
-#ifndef Py_BUFFEROBJECT_H
-#define Py_BUFFEROBJECT_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-PyAPI_DATA(PyTypeObject) PyBuffer_Type;
-
-#define PyBuffer_Check(op) (Py_TYPE(op) == &PyBuffer_Type)
-
-#define Py_END_OF_BUFFER (-1)
-
-PyAPI_FUNC(PyObject *) PyBuffer_FromObject(PyObject *base,
- Py_ssize_t offset, Py_ssize_t size);
-PyAPI_FUNC(PyObject *) PyBuffer_FromReadWriteObject(PyObject *base,
- Py_ssize_t offset,
- Py_ssize_t size);
-
-PyAPI_FUNC(PyObject *) PyBuffer_FromMemory(void *ptr, Py_ssize_t size);
-PyAPI_FUNC(PyObject *) PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size);
-
-PyAPI_FUNC(PyObject *) PyBuffer_New(Py_ssize_t size);
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* !Py_BUFFEROBJECT_H */
diff --git a/Include/bytearrayobject.h b/Include/bytearrayobject.h
index e1281a628c7..eccd44c7517 100644
--- a/Include/bytearrayobject.h
+++ b/Include/bytearrayobject.h
@@ -19,6 +19,7 @@ extern "C" {
*/
/* Object layout */
+#ifndef Py_LIMITED_API
typedef struct {
PyObject_VAR_HEAD
/* XXX(nnorwitz): should ob_exports be Py_ssize_t? */
@@ -26,6 +27,7 @@ typedef struct {
Py_ssize_t ob_alloc; /* How many bytes allocated */
char *ob_bytes;
} PyByteArrayObject;
+#endif
/* Type object */
PyAPI_DATA(PyTypeObject) PyByteArray_Type;
@@ -44,12 +46,14 @@ PyAPI_FUNC(char *) PyByteArray_AsString(PyObject *);
PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t);
/* Macros, trading safety for speed */
+#ifndef Py_LIMITED_API
#define PyByteArray_AS_STRING(self) \
(assert(PyByteArray_Check(self)), \
Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_bytes : _PyByteArray_empty_string)
#define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)),Py_SIZE(self))
PyAPI_DATA(char) _PyByteArray_empty_string[];
+#endif
#ifdef __cplusplus
}
diff --git a/Include/bytes_methods.h b/Include/bytes_methods.h
index 41256662129..1498b8f83c2 100644
--- a/Include/bytes_methods.h
+++ b/Include/bytes_methods.h
@@ -1,8 +1,9 @@
+#ifndef Py_LIMITED_API
#ifndef Py_BYTES_CTYPE_H
#define Py_BYTES_CTYPE_H
/*
- * The internal implementation behind PyString (bytes) and PyBytes (buffer)
+ * The internal implementation behind PyBytes (bytes) and PyByteArray (bytearray)
* methods of the given names, they operate on ASCII byte strings.
*/
extern PyObject* _Py_bytes_isspace(const char *cptr, Py_ssize_t len);
@@ -20,6 +21,9 @@ extern void _Py_bytes_title(char *result, char *s, Py_ssize_t len);
extern void _Py_bytes_capitalize(char *result, char *s, Py_ssize_t len);
extern void _Py_bytes_swapcase(char *result, char *s, Py_ssize_t len);
+/* This one gets the raw argument list. */
+extern PyObject* _Py_bytes_maketrans(PyObject *args);
+
/* Shared __doc__ strings. */
extern const char _Py_isspace__doc__[];
extern const char _Py_isalpha__doc__[];
@@ -33,43 +37,10 @@ extern const char _Py_upper__doc__[];
extern const char _Py_title__doc__[];
extern const char _Py_capitalize__doc__[];
extern const char _Py_swapcase__doc__[];
-
-/* These are left in for backward compatibility and will be removed
- in 2.8/3.2 */
-#define ISLOWER(c) Py_ISLOWER(c)
-#define ISUPPER(c) Py_ISUPPER(c)
-#define ISALPHA(c) Py_ISALPHA(c)
-#define ISDIGIT(c) Py_ISDIGIT(c)
-#define ISXDIGIT(c) Py_ISXDIGIT(c)
-#define ISALNUM(c) Py_ISALNUM(c)
-#define ISSPACE(c) Py_ISSPACE(c)
-
-#undef islower
-#define islower(c) undefined_islower(c)
-#undef isupper
-#define isupper(c) undefined_isupper(c)
-#undef isalpha
-#define isalpha(c) undefined_isalpha(c)
-#undef isdigit
-#define isdigit(c) undefined_isdigit(c)
-#undef isxdigit
-#define isxdigit(c) undefined_isxdigit(c)
-#undef isalnum
-#define isalnum(c) undefined_isalnum(c)
-#undef isspace
-#define isspace(c) undefined_isspace(c)
-
-/* These are left in for backward compatibility and will be removed
- in 2.8/3.2 */
-#define TOLOWER(c) Py_TOLOWER(c)
-#define TOUPPER(c) Py_TOUPPER(c)
-
-#undef tolower
-#define tolower(c) undefined_tolower(c)
-#undef toupper
-#define toupper(c) undefined_toupper(c)
+extern const char _Py_maketrans__doc__[];
/* this is needed because some docs are shared from the .o, not static */
#define PyDoc_STRVAR_shared(name,str) const char name[] = PyDoc_STR(str)
#endif /* !Py_BYTES_CTYPE_H */
+#endif /* !Py_LIMITED_API */
diff --git a/Include/bytesobject.h b/Include/bytesobject.h
index 1083da9c826..e1af89f9c95 100644
--- a/Include/bytesobject.h
+++ b/Include/bytesobject.h
@@ -1,27 +1,130 @@
-#define PyBytesObject PyStringObject
-#define PyBytes_Type PyString_Type
-
-#define PyBytes_Check PyString_Check
-#define PyBytes_CheckExact PyString_CheckExact
-#define PyBytes_CHECK_INTERNED PyString_CHECK_INTERNED
-#define PyBytes_AS_STRING PyString_AS_STRING
-#define PyBytes_GET_SIZE PyString_GET_SIZE
-#define Py_TPFLAGS_BYTES_SUBCLASS Py_TPFLAGS_STRING_SUBCLASS
-
-#define PyBytes_FromStringAndSize PyString_FromStringAndSize
-#define PyBytes_FromString PyString_FromString
-#define PyBytes_FromFormatV PyString_FromFormatV
-#define PyBytes_FromFormat PyString_FromFormat
-#define PyBytes_Size PyString_Size
-#define PyBytes_AsString PyString_AsString
-#define PyBytes_Repr PyString_Repr
-#define PyBytes_Concat PyString_Concat
-#define PyBytes_ConcatAndDel PyString_ConcatAndDel
-#define _PyBytes_Resize _PyString_Resize
-#define _PyBytes_Eq _PyString_Eq
-#define PyBytes_Format PyString_Format
-#define _PyBytes_FormatLong _PyString_FormatLong
-#define PyBytes_DecodeEscape PyString_DecodeEscape
-#define _PyBytes_Join _PyString_Join
-#define PyBytes_AsStringAndSize PyString_AsStringAndSize
-#define _PyBytes_InsertThousandsGrouping _PyString_InsertThousandsGrouping
+
+/* Bytes (String) object interface */
+
+#ifndef Py_BYTESOBJECT_H
+#define Py_BYTESOBJECT_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdarg.h>
+
+/*
+Type PyBytesObject represents a character string. An extra zero byte is
+reserved at the end to ensure it is zero-terminated, but a size is
+present so strings with null bytes in them can be represented. This
+is an immutable object type.
+
+There are functions to create new string objects, to test
+an object for string-ness, and to get the
+string value. The latter function returns a null pointer
+if the object is not of the proper type.
+There is a variant that takes an explicit size as well as a
+variant that assumes a zero-terminated string. Note that none of the
+functions should be applied to nil objects.
+*/
+
+/* Caching the hash (ob_shash) saves recalculation of a string's hash value.
+ This significantly speeds up dict lookups. */
+
+#ifndef Py_LIMITED_API
+typedef struct {
+ PyObject_VAR_HEAD
+ Py_hash_t ob_shash;
+ char ob_sval[1];
+
+ /* Invariants:
+ * ob_sval contains space for 'ob_size+1' elements.
+ * ob_sval[ob_size] == 0.
+ * ob_shash is the hash of the string or -1 if not computed yet.
+ */
+} PyBytesObject;
+#endif
+
+PyAPI_DATA(PyTypeObject) PyBytes_Type;
+PyAPI_DATA(PyTypeObject) PyBytesIter_Type;
+
+#define PyBytes_Check(op) \
+ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS)
+#define PyBytes_CheckExact(op) (Py_TYPE(op) == &PyBytes_Type)
+
+PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t);
+PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *);
+PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *);
+PyAPI_FUNC(PyObject *) PyBytes_FromFormatV(const char*, va_list)
+ Py_GCC_ATTRIBUTE((format(printf, 1, 0)));
+PyAPI_FUNC(PyObject *) PyBytes_FromFormat(const char*, ...)
+ Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
+PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *);
+PyAPI_FUNC(char *) PyBytes_AsString(PyObject *);
+PyAPI_FUNC(PyObject *) PyBytes_Repr(PyObject *, int);
+PyAPI_FUNC(void) PyBytes_Concat(PyObject **, PyObject *);
+PyAPI_FUNC(void) PyBytes_ConcatAndDel(PyObject **, PyObject *);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(int) _PyBytes_Resize(PyObject **, Py_ssize_t);
+PyAPI_FUNC(PyObject *) _PyBytes_FormatLong(PyObject*, int, int,
+ int, char**, int*);
+#endif
+PyAPI_FUNC(PyObject *) PyBytes_DecodeEscape(const char *, Py_ssize_t,
+ const char *, Py_ssize_t,
+ const char *);
+
+/* Macro, trading safety for speed */
+#ifndef Py_LIMITED_API
+#define PyBytes_AS_STRING(op) (assert(PyBytes_Check(op)), \
+ (((PyBytesObject *)(op))->ob_sval))
+#define PyBytes_GET_SIZE(op) (assert(PyBytes_Check(op)),Py_SIZE(op))
+#endif
+
+/* _PyBytes_Join(sep, x) is like sep.join(x). sep must be PyBytesObject*,
+ x must be an iterable object. */
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(PyObject *) _PyBytes_Join(PyObject *sep, PyObject *x);
+#endif
+
+/* Provides access to the internal data buffer and size of a string
+ object or the default encoded version of an Unicode object. Passing
+ NULL as *len parameter will force the string buffer to be
+ 0-terminated (passing a string with embedded NULL characters will
+ cause an exception). */
+PyAPI_FUNC(int) PyBytes_AsStringAndSize(
+ register PyObject *obj, /* string or Unicode object */
+ register char **s, /* pointer to buffer variable */
+ register Py_ssize_t *len /* pointer to length variable or NULL
+ (only possible for 0-terminated
+ strings) */
+ );
+
+/* Using the current locale, insert the thousands grouping
+ into the string pointed to by buffer. For the argument descriptions,
+ see Objects/stringlib/localeutil.h */
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(Py_ssize_t) _PyBytes_InsertThousandsGroupingLocale(char *buffer,
+ Py_ssize_t n_buffer,
+ char *digits,
+ Py_ssize_t n_digits,
+ Py_ssize_t min_width);
+
+/* Using explicit passed-in values, insert the thousands grouping
+ into the string pointed to by buffer. For the argument descriptions,
+ see Objects/stringlib/localeutil.h */
+PyAPI_FUNC(Py_ssize_t) _PyBytes_InsertThousandsGrouping(char *buffer,
+ Py_ssize_t n_buffer,
+ char *digits,
+ Py_ssize_t n_digits,
+ Py_ssize_t min_width,
+ const char *grouping,
+ const char *thousands_sep);
+#endif
+
+/* Flags used by string formatting */
+#define F_LJUST (1<<0)
+#define F_SIGN (1<<1)
+#define F_BLANK (1<<2)
+#define F_ALT (1<<3)
+#define F_ZERO (1<<4)
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_BYTESOBJECT_H */
diff --git a/Include/cStringIO.h b/Include/cStringIO.h
deleted file mode 100644
index 6ca44a83030..00000000000
--- a/Include/cStringIO.h
+++ /dev/null
@@ -1,73 +0,0 @@
-#ifndef Py_CSTRINGIO_H
-#define Py_CSTRINGIO_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
-
- This header provides access to cStringIO objects from C.
- Functions are provided for calling cStringIO objects and
- macros are provided for testing whether you have cStringIO
- objects.
-
- Before calling any of the functions or macros, you must initialize
- the routines with:
-
- PycString_IMPORT
-
- This would typically be done in your init function.
-
-*/
-
-#define PycStringIO_CAPSULE_NAME "cStringIO.cStringIO_CAPI"
-
-#define PycString_IMPORT \
- PycStringIO = ((struct PycStringIO_CAPI*)PyCapsule_Import(\
- PycStringIO_CAPSULE_NAME, 0))
-
-/* Basic functions to manipulate cStringIO objects from C */
-
-static struct PycStringIO_CAPI {
-
- /* Read a string from an input object. If the last argument
- is -1, the remainder will be read.
- */
- int(*cread)(PyObject *, char **, Py_ssize_t);
-
- /* Read a line from an input object. Returns the length of the read
- line as an int and a pointer inside the object buffer as char** (so
- the caller doesn't have to provide its own buffer as destination).
- */
- int(*creadline)(PyObject *, char **);
-
- /* Write a string to an output object*/
- int(*cwrite)(PyObject *, const char *, Py_ssize_t);
-
- /* Get the output object as a Python string (returns new reference). */
- PyObject *(*cgetvalue)(PyObject *);
-
- /* Create a new output object */
- PyObject *(*NewOutput)(int);
-
- /* Create an input object from a Python string
- (copies the Python string reference).
- */
- PyObject *(*NewInput)(PyObject *);
-
- /* The Python types for cStringIO input and output objects.
- Note that you can do input on an output object.
- */
- PyTypeObject *InputType, *OutputType;
-
-} *PycStringIO;
-
-/* These can be used to test if you have one */
-#define PycStringIO_InputCheck(O) \
- (Py_TYPE(O)==PycStringIO->InputType)
-#define PycStringIO_OutputCheck(O) \
- (Py_TYPE(O)==PycStringIO->OutputType)
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* !Py_CSTRINGIO_H */
diff --git a/Include/cellobject.h b/Include/cellobject.h
index c927ee5da12..a0aa4d947c2 100644
--- a/Include/cellobject.h
+++ b/Include/cellobject.h
@@ -1,5 +1,5 @@
/* Cell object interface */
-
+#ifndef Py_LIMITED_API
#ifndef Py_CELLOBJECT_H
#define Py_CELLOBJECT_H
#ifdef __cplusplus
@@ -26,3 +26,4 @@ PyAPI_FUNC(int) PyCell_Set(PyObject *, PyObject *);
}
#endif
#endif /* !Py_TUPLEOBJECT_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/ceval.h b/Include/ceval.h
index 0e8bd2ab113..6811367d762 100644
--- a/Include/ceval.h
+++ b/Include/ceval.h
@@ -20,8 +20,10 @@ PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj,
const char *methodname,
const char *format, ...);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
+#endif
struct _frame; /* Avoid including frameobject.h */
@@ -29,35 +31,80 @@ PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void);
PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void);
PyAPI_FUNC(PyObject *) PyEval_GetLocals(void);
PyAPI_FUNC(struct _frame *) PyEval_GetFrame(void);
-PyAPI_FUNC(int) PyEval_GetRestricted(void);
/* Look at the current frame's (if any) code's co_flags, and turn on
the corresponding compiler flags in cf->cf_flags. Return 1 if any
flag was set, else return 0. */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
-
-PyAPI_FUNC(int) Py_FlushLine(void);
+#endif
PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);
PyAPI_FUNC(int) Py_MakePendingCalls(void);
-/* Protection against deeply nested recursive calls */
+/* Protection against deeply nested recursive calls
+
+ In Python 3.0, this protection has two levels:
+ * normal anti-recursion protection is triggered when the recursion level
+ exceeds the current recursion limit. It raises a RuntimeError, and sets
+ the "overflowed" flag in the thread state structure. This flag
+ temporarily *disables* the normal protection; this allows cleanup code
+ to potentially outgrow the recursion limit while processing the
+ RuntimeError.
+ * "last chance" anti-recursion protection is triggered when the recursion
+ level exceeds "current recursion limit + 50". By construction, this
+ protection can only be triggered when the "overflowed" flag is set. It
+ means the cleanup code has itself gone into an infinite loop, or the
+ RuntimeError has been mistakingly ignored. When this protection is
+ triggered, the interpreter aborts with a Fatal Error.
+
+ In addition, the "overflowed" flag is automatically reset when the
+ recursion level drops below "current recursion limit - 50". This heuristic
+ is meant to ensure that the normal anti-recursion protection doesn't get
+ disabled too long.
+
+ Please note: this scheme has its own limitations. See:
+ http://mail.python.org/pipermail/python-dev/2008-August/082106.html
+ for some observations.
+*/
PyAPI_FUNC(void) Py_SetRecursionLimit(int);
PyAPI_FUNC(int) Py_GetRecursionLimit(void);
-#define Py_EnterRecursiveCall(where) \
+#define Py_EnterRecursiveCall(where) \
(_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \
_Py_CheckRecursiveCall(where))
#define Py_LeaveRecursiveCall() \
- (--PyThreadState_GET()->recursion_depth)
+ do{ if(_Py_MakeEndRecCheck(PyThreadState_GET()->recursion_depth)) \
+ PyThreadState_GET()->overflowed = 0; \
+ } while(0)
PyAPI_FUNC(int) _Py_CheckRecursiveCall(char *where);
PyAPI_DATA(int) _Py_CheckRecursionLimit;
+
#ifdef USE_STACKCHECK
-# define _Py_MakeRecCheck(x) (++(x) > --_Py_CheckRecursionLimit)
+/* With USE_STACKCHECK, we artificially decrement the recursion limit in order
+ to trigger regular stack checks in _Py_CheckRecursiveCall(), except if
+ the "overflowed" flag is set, in which case we need the true value
+ of _Py_CheckRecursionLimit for _Py_MakeEndRecCheck() to function properly.
+*/
+# define _Py_MakeRecCheck(x) \
+ (++(x) > (_Py_CheckRecursionLimit += PyThreadState_GET()->overflowed - 1))
#else
# define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit)
#endif
+#define _Py_MakeEndRecCheck(x) \
+ (--(x) < ((_Py_CheckRecursionLimit > 100) \
+ ? (_Py_CheckRecursionLimit - 50) \
+ : (3 * (_Py_CheckRecursionLimit >> 2))))
+
+#define Py_ALLOW_RECURSION \
+ do { unsigned char _old = PyThreadState_GET()->recursion_critical;\
+ PyThreadState_GET()->recursion_critical = 1;
+
+#define Py_END_ALLOW_RECURSION \
+ PyThreadState_GET()->recursion_critical = _old; \
+ } while(0);
+
PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *);
PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);
@@ -65,10 +112,6 @@ PyAPI_FUNC(PyObject *) PyEval_GetCallStats(PyObject *);
PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *);
PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);
-/* this used to be handled on a per-thread basis - now just two globals */
-PyAPI_DATA(volatile int) _Py_Ticker;
-PyAPI_DATA(int) _Py_CheckInterval;
-
/* Interface for threads.
A module that plans to do a blocking system call (or something else
@@ -108,7 +151,7 @@ PyAPI_DATA(int) _Py_CheckInterval;
Py_END_ALLOW_THREADS!!!
The function PyEval_InitThreads() should be called only from
- initthread() in "threadmodule.c".
+ init_thread() in "_threadmodule.c".
Note that not yet all candidates have been converted to use this
mechanism!
@@ -121,12 +164,18 @@ PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
PyAPI_FUNC(void) PyEval_InitThreads(void);
+PyAPI_FUNC(void) _PyEval_FiniThreads(void);
PyAPI_FUNC(void) PyEval_AcquireLock(void);
PyAPI_FUNC(void) PyEval_ReleaseLock(void);
PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
PyAPI_FUNC(void) PyEval_ReInitThreads(void);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds);
+PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void);
+#endif
+
#define Py_BEGIN_ALLOW_THREADS { \
PyThreadState *_save; \
_save = PyEval_SaveThread();
@@ -144,7 +193,10 @@ PyAPI_FUNC(void) PyEval_ReInitThreads(void);
#endif /* !WITH_THREAD */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
+PyAPI_FUNC(void) _PyEval_SignalAsyncExc(void);
+#endif
#ifdef __cplusplus
diff --git a/Include/classobject.h b/Include/classobject.h
index bc03e0d0270..eeeb3e95a87 100644
--- a/Include/classobject.h
+++ b/Include/classobject.h
@@ -1,8 +1,8 @@
-
-/* Class object interface */
+/* Former class object interface -- now only bound methods are here */
/* Revealing some structures (not for general use) */
+#ifndef Py_LIMITED_API
#ifndef Py_CLASSOBJECT_H
#define Py_CLASSOBJECT_H
#ifdef __cplusplus
@@ -11,58 +11,19 @@ extern "C" {
typedef struct {
PyObject_HEAD
- PyObject *cl_bases; /* A tuple of class objects */
- PyObject *cl_dict; /* A dictionary */
- PyObject *cl_name; /* A string */
- /* The following three are functions or NULL */
- PyObject *cl_getattr;
- PyObject *cl_setattr;
- PyObject *cl_delattr;
- PyObject *cl_weakreflist; /* List of weak references */
-} PyClassObject;
-
-typedef struct {
- PyObject_HEAD
- PyClassObject *in_class; /* The class object */
- PyObject *in_dict; /* A dictionary */
- PyObject *in_weakreflist; /* List of weak references */
-} PyInstanceObject;
-
-typedef struct {
- PyObject_HEAD
PyObject *im_func; /* The callable object implementing the method */
- PyObject *im_self; /* The instance it is bound to, or NULL */
- PyObject *im_class; /* The class that asked for the method */
+ PyObject *im_self; /* The instance it is bound to */
PyObject *im_weakreflist; /* List of weak references */
} PyMethodObject;
-PyAPI_DATA(PyTypeObject) PyClass_Type, PyInstance_Type, PyMethod_Type;
+PyAPI_DATA(PyTypeObject) PyMethod_Type;
-#define PyClass_Check(op) ((op)->ob_type == &PyClass_Type)
-#define PyInstance_Check(op) ((op)->ob_type == &PyInstance_Type)
#define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type)
-PyAPI_FUNC(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *);
-PyAPI_FUNC(PyObject *) PyInstance_New(PyObject *, PyObject *,
- PyObject *);
-PyAPI_FUNC(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *);
-PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);
+PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *);
PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
-PyAPI_FUNC(PyObject *) PyMethod_Class(PyObject *);
-
-/* Look up attribute with name (a string) on instance object pinst, using
- * only the instance and base class dicts. If a descriptor is found in
- * a class dict, the descriptor is returned without calling it.
- * Returns NULL if nothing found, else a borrowed reference to the
- * value associated with name in the dict in which name was found.
- * The point of this routine is that it never calls arbitrary Python
- * code, so is always "safe": all it does is dict lookups. The function
- * can't fail, never sets an exception, and NULL is not an error (it just
- * means "not found").
- */
-PyAPI_FUNC(PyObject *) _PyInstance_Lookup(PyObject *pinst, PyObject *name);
/* Macros for direct access to these values. Type checks are *not*
done, so use with care. */
@@ -70,14 +31,28 @@ PyAPI_FUNC(PyObject *) _PyInstance_Lookup(PyObject *pinst, PyObject *name);
(((PyMethodObject *)meth) -> im_func)
#define PyMethod_GET_SELF(meth) \
(((PyMethodObject *)meth) -> im_self)
-#define PyMethod_GET_CLASS(meth) \
- (((PyMethodObject *)meth) -> im_class)
-
-PyAPI_FUNC(int) PyClass_IsSubclass(PyObject *, PyObject *);
PyAPI_FUNC(int) PyMethod_ClearFreeList(void);
+typedef struct {
+ PyObject_HEAD
+ PyObject *func;
+} PyInstanceMethodObject;
+
+PyAPI_DATA(PyTypeObject) PyInstanceMethod_Type;
+
+#define PyInstanceMethod_Check(op) ((op)->ob_type == &PyInstanceMethod_Type)
+
+PyAPI_FUNC(PyObject *) PyInstanceMethod_New(PyObject *);
+PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *);
+
+/* Macros for direct access to these values. Type checks are *not*
+ done, so use with care. */
+#define PyInstanceMethod_GET_FUNCTION(meth) \
+ (((PyInstanceMethodObject *)meth) -> func)
+
#ifdef __cplusplus
}
#endif
#endif /* !Py_CLASSOBJECT_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/cobject.h b/Include/cobject.h
deleted file mode 100644
index ad3cd9c9828..00000000000
--- a/Include/cobject.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- CObjects are marked Pending Deprecation as of Python 2.7.
- The full schedule for 2.x is as follows:
- - CObjects are marked Pending Deprecation in Python 2.7.
- - CObjects will be marked Deprecated in Python 2.8
- (if there is one).
- - CObjects will be removed in Python 2.9 (if there is one).
-
- Additionally, for the Python 3.x series:
- - CObjects were marked Deprecated in Python 3.1.
- - CObjects will be removed in Python 3.2.
-
- You should switch all use of CObjects to capsules. Capsules
- have a safer and more consistent API. For more information,
- see Include/pycapsule.h, or read the "Capsules" topic in
- the "Python/C API Reference Manual".
-
- Python 2.7 no longer uses CObjects itself; all objects which
- were formerly CObjects are now capsules. Note that this change
- does not by itself break binary compatibility with extensions
- built for previous versions of Python--PyCObject_AsVoidPtr()
- has been changed to also understand capsules.
-
-*/
-
-/* original file header comment follows: */
-
-/* C objects to be exported from one extension module to another.
-
- C objects are used for communication between extension modules.
- They provide a way for an extension module to export a C interface
- to other extension modules, so that extension modules can use the
- Python import mechanism to link to one another.
-
-*/
-
-#ifndef Py_COBJECT_H
-#define Py_COBJECT_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-PyAPI_DATA(PyTypeObject) PyCObject_Type;
-
-#define PyCObject_Check(op) (Py_TYPE(op) == &PyCObject_Type)
-
-/* Create a PyCObject from a pointer to a C object and an optional
- destructor function. If the second argument is non-null, then it
- will be called with the first argument if and when the PyCObject is
- destroyed.
-
-*/
-PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtr(
- void *cobj, void (*destruct)(void*));
-
-
-/* Create a PyCObject from a pointer to a C object, a description object,
- and an optional destructor function. If the third argument is non-null,
- then it will be called with the first and second arguments if and when
- the PyCObject is destroyed.
-*/
-PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtrAndDesc(
- void *cobj, void *desc, void (*destruct)(void*,void*));
-
-/* Retrieve a pointer to a C object from a PyCObject. */
-PyAPI_FUNC(void *) PyCObject_AsVoidPtr(PyObject *);
-
-/* Retrieve a pointer to a description object from a PyCObject. */
-PyAPI_FUNC(void *) PyCObject_GetDesc(PyObject *);
-
-/* Import a pointer to a C object from a module using a PyCObject. */
-PyAPI_FUNC(void *) PyCObject_Import(char *module_name, char *cobject_name);
-
-/* Modify a C object. Fails (==0) if object has a destructor. */
-PyAPI_FUNC(int) PyCObject_SetVoidPtr(PyObject *self, void *cobj);
-
-
-typedef struct {
- PyObject_HEAD
- void *cobject;
- void *desc;
- void (*destructor)(void *);
-} PyCObject;
-
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* !Py_COBJECT_H */
diff --git a/Include/code.h b/Include/code.h
index 38b2958046a..e773b6a47ce 100644
--- a/Include/code.h
+++ b/Include/code.h
@@ -1,5 +1,6 @@
/* Definitions for bytecode */
+#ifndef Py_LIMITED_API
#ifndef Py_CODE_H
#define Py_CODE_H
#ifdef __cplusplus
@@ -10,6 +11,7 @@ extern "C" {
typedef struct {
PyObject_HEAD
int co_argcount; /* #arguments, except *args */
+ int co_kwonlyargcount; /* #keyword only arguments */
int co_nlocals; /* #local variables */
int co_stacksize; /* #entries needed for evaluation stack */
int co_flags; /* CO_..., see below */
@@ -19,9 +21,9 @@ typedef struct {
PyObject *co_varnames; /* tuple of strings (local variable names) */
PyObject *co_freevars; /* tuple of strings (free variable names) */
PyObject *co_cellvars; /* tuple of strings (cell variable names) */
- /* The rest doesn't count for hash/cmp */
- PyObject *co_filename; /* string (where it was loaded from) */
- PyObject *co_name; /* string (name, for reference) */
+ /* The rest doesn't count for hash or comparisons */
+ PyObject *co_filename; /* unicode (where it was loaded from) */
+ PyObject *co_name; /* unicode (name, for reference) */
int co_firstlineno; /* first source line number */
PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) See
Objects/lnotab_notes.txt for details. */
@@ -43,8 +45,8 @@ typedef struct {
*/
#define CO_NOFREE 0x0040
+/* These are no longer used. */
#if 0
-/* This is no longer used. Stopped defining in 2.5, do not re-use. */
#define CO_GENERATOR_ALLOWED 0x1000
#endif
#define CO_FUTURE_DIVISION 0x2000
@@ -53,12 +55,12 @@ typedef struct {
#define CO_FUTURE_PRINT_FUNCTION 0x10000
#define CO_FUTURE_UNICODE_LITERALS 0x20000
+#define CO_FUTURE_BARRY_AS_BDFL 0x40000
+
/* This should be defined if a future statement modifies the syntax.
For example, when a keyword is added.
*/
-#if 1
#define PY_PARSER_REQUIRES_FUTURE_KEYWORD
-#endif
#define CO_MAXBLOCKS 20 /* Max static block nesting within a function */
@@ -69,8 +71,9 @@ PyAPI_DATA(PyTypeObject) PyCode_Type;
/* Public interface */
PyAPI_FUNC(PyCodeObject *) PyCode_New(
- int, int, int, int, PyObject *, PyObject *, PyObject *, PyObject *,
- PyObject *, PyObject *, PyObject *, PyObject *, int, PyObject *);
+ int, int, int, int, int, PyObject *, PyObject *,
+ PyObject *, PyObject *, PyObject *, PyObject *,
+ PyObject *, PyObject *, int, PyObject *);
/* same as struct above */
/* Creates a new empty code object with the specified source location. */
@@ -83,10 +86,6 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno);
PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
/* for internal use only */
-#define _PyCode_GETCODEPTR(co, pp) \
- ((*Py_TYPE((co)->co_code)->tp_as_buffer->bf_getreadbuffer) \
- ((co)->co_code, 0, (void **)(pp)))
-
typedef struct _addr_pair {
int ap_lower;
int ap_upper;
@@ -95,8 +94,10 @@ typedef struct _addr_pair {
/* Update *bounds to describe the first and one-past-the-last instructions in the
same line as lasti. Return the number of that line.
*/
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyCode_CheckLineNumber(PyCodeObject* co,
int lasti, PyAddrPair *bounds);
+#endif
PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts,
PyObject *names, PyObject *lineno_obj);
@@ -105,3 +106,4 @@ PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts,
}
#endif
#endif /* !Py_CODE_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/codecs.h b/Include/codecs.h
index c038c6a92c6..dff09e778ba 100644
--- a/Include/codecs.h
+++ b/Include/codecs.h
@@ -27,7 +27,7 @@ PyAPI_FUNC(int) PyCodec_Register(
PyObject *search_function
);
-/* Codec register lookup API.
+/* Codec registry lookup API.
Looks up the given encoding and returns a CodecInfo object with
function attributes which implement the different aspects of
@@ -45,9 +45,22 @@ PyAPI_FUNC(int) PyCodec_Register(
*/
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyCodec_Lookup(
const char *encoding
);
+#endif
+
+/* Codec registry encoding check API.
+
+ Returns 1/0 depending on whether there is a registered codec for
+ the given encoding.
+
+*/
+
+PyAPI_FUNC(int) PyCodec_KnownEncoding(
+ const char *encoding
+ );
/* Generic codec based encoding API.
diff --git a/Include/compile.h b/Include/compile.h
index 61001016aa1..bc53b392390 100644
--- a/Include/compile.h
+++ b/Include/compile.h
@@ -1,4 +1,4 @@
-
+#ifndef Py_LIMITED_API
#ifndef Py_COMPILE_H
#define Py_COMPILE_H
@@ -26,11 +26,16 @@ typedef struct {
#define FUTURE_WITH_STATEMENT "with_statement"
#define FUTURE_PRINT_FUNCTION "print_function"
#define FUTURE_UNICODE_LITERALS "unicode_literals"
-
+#define FUTURE_BARRY_AS_BDFL "barry_as_FLUFL"
struct _mod; /* Declare the existence of this type */
-PyAPI_FUNC(PyCodeObject *) PyAST_Compile(struct _mod *, const char *,
- PyCompilerFlags *, PyArena *);
+#define PyAST_Compile(mod, s, f, ar) PyAST_CompileEx(mod, s, f, -1, ar)
+PyAPI_FUNC(PyCodeObject *) PyAST_CompileEx(
+ struct _mod *mod,
+ const char *filename, /* decoded from the filesystem encoding */
+ PyCompilerFlags *flags,
+ int optimize,
+ PyArena *arena);
PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(struct _mod *, const char *);
@@ -38,3 +43,4 @@ PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(struct _mod *, const char *);
}
#endif
#endif /* !Py_COMPILE_H */
+#endif /* !Py_LIMITED_API */
diff --git a/Include/complexobject.h b/Include/complexobject.h
index c9a9500fd75..c379b08916f 100644
--- a/Include/complexobject.h
+++ b/Include/complexobject.h
@@ -6,6 +6,7 @@
extern "C" {
#endif
+#ifndef Py_LIMITED_API
typedef struct {
double real;
double imag;
@@ -28,7 +29,7 @@ PyAPI_FUNC(Py_complex) c_prod(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) c_quot(Py_complex, Py_complex);
PyAPI_FUNC(Py_complex) c_pow(Py_complex, Py_complex);
PyAPI_FUNC(double) c_abs(Py_complex);
-
+#endif
/* Complex object interface */
@@ -36,29 +37,36 @@ PyAPI_FUNC(double) c_abs(Py_complex);
PyComplexObject represents a complex number with double-precision
real and imaginary parts.
*/
-
+#ifndef Py_LIMITED_API
typedef struct {
PyObject_HEAD
Py_complex cval;
-} PyComplexObject;
+} PyComplexObject;
+#endif
PyAPI_DATA(PyTypeObject) PyComplex_Type;
#define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type)
#define PyComplex_CheckExact(op) (Py_TYPE(op) == &PyComplex_Type)
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);
+#endif
PyAPI_FUNC(PyObject *) PyComplex_FromDoubles(double real, double imag);
PyAPI_FUNC(double) PyComplex_RealAsDouble(PyObject *op);
PyAPI_FUNC(double) PyComplex_ImagAsDouble(PyObject *op);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op);
+#endif
/* Format the object based on the format_spec, as defined in PEP 3101
(Advanced String Formatting). */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyComplex_FormatAdvanced(PyObject *obj,
- char *format_spec,
+ Py_UNICODE *format_spec,
Py_ssize_t format_spec_len);
+#endif
#ifdef __cplusplus
}
diff --git a/Include/datetime.h b/Include/datetime.h
index 47abe5cb865..db57a18e66b 100644
--- a/Include/datetime.h
+++ b/Include/datetime.h
@@ -1,6 +1,6 @@
/* datetime.h
*/
-
+#ifndef Py_LIMITED_API
#ifndef DATETIME_H
#define DATETIME_H
#ifdef __cplusplus
@@ -34,7 +34,7 @@ extern "C" {
typedef struct
{
PyObject_HEAD
- long hashcode; /* -1 when unknown */
+ Py_hash_t hashcode; /* -1 when unknown */
int days; /* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */
int seconds; /* 0 <= seconds < 24*3600 is invariant */
int microseconds; /* 0 <= microseconds < 1000000 is invariant */
@@ -51,7 +51,7 @@ typedef struct
*/
#define _PyTZINFO_HEAD \
PyObject_HEAD \
- long hashcode; \
+ Py_hash_t hashcode; \
char hastzinfo; /* boolean flag */
/* No _PyDateTime_BaseTZInfo is allocated; it's just to have something
@@ -161,9 +161,6 @@ typedef struct {
#define PyDateTime_CAPSULE_NAME "datetime.datetime_CAPI"
-/* "magic" constant used to partially protect against developer mistakes. */
-#define DATETIME_API_MAGIC 0x414548d5
-
#ifdef Py_BUILD_CORE
/* Macros for type checking when building the Python core. */
@@ -237,3 +234,4 @@ static PyDateTime_CAPI *PyDateTimeAPI = NULL;
}
#endif
#endif
+#endif /* !Py_LIMITED_API */
diff --git a/Include/descrobject.h b/Include/descrobject.h
index b542732b16d..646b3cca4e4 100644
--- a/Include/descrobject.h
+++ b/Include/descrobject.h
@@ -16,6 +16,7 @@ typedef struct PyGetSetDef {
void *closure;
} PyGetSetDef;
+#ifndef Py_LIMITED_API
typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args,
void *wrapped);
@@ -37,15 +38,17 @@ struct wrapperbase {
/* Various kinds of descriptor objects */
-#define PyDescr_COMMON \
- PyObject_HEAD \
- PyTypeObject *d_type; \
- PyObject *d_name
-
typedef struct {
- PyDescr_COMMON;
+ PyObject_HEAD
+ PyTypeObject *d_type;
+ PyObject *d_name;
} PyDescrObject;
+#define PyDescr_COMMON PyDescrObject d_common
+
+#define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type)
+#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
+
typedef struct {
PyDescr_COMMON;
PyMethodDef *d_method;
@@ -66,21 +69,28 @@ typedef struct {
struct wrapperbase *d_base;
void *d_wrapped; /* This can be any function pointer */
} PyWrapperDescrObject;
+#endif /* Py_LIMITED_API */
-PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
-PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
+PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type;
PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
+PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
+PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
+PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
+PyAPI_DATA(PyTypeObject) _PyMethodWrapper_Type;
PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
+struct PyMemberDef; /* forward declaration for following prototype */
PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *,
struct PyMemberDef *);
PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
struct PyGetSetDef *);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
struct wrapperbase *, void *);
#define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set != NULL)
+#endif
PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);
diff --git a/Include/dictobject.h b/Include/dictobject.h
index ece01c64d60..b0267859197 100644
--- a/Include/dictobject.h
+++ b/Include/dictobject.h
@@ -45,14 +45,12 @@ meaning otherwise.
* majority of dicts (consisting mostly of usually-small instance dicts and
* usually-small dicts created to pass keyword arguments).
*/
+#ifndef Py_LIMITED_API
#define PyDict_MINSIZE 8
typedef struct {
- /* Cached hash code of me_key. Note that hash codes are C longs.
- * We have to use Py_ssize_t instead because dict_popitem() abuses
- * me_hash to hold a search finger.
- */
- Py_ssize_t me_hash;
+ /* Cached hash code of me_key. */
+ Py_hash_t me_hash;
PyObject *me_key;
PyObject *me_value;
} PyDictEntry;
@@ -84,9 +82,10 @@ struct _dictobject {
* setitem calls.
*/
PyDictEntry *ma_table;
- PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, long hash);
+ PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, Py_hash_t hash);
PyDictEntry ma_smalltable[PyDict_MINSIZE];
};
+#endif /* Py_LIMITED_API */
PyAPI_DATA(PyTypeObject) PyDict_Type;
PyAPI_DATA(PyTypeObject) PyDictIterKey_Type;
@@ -106,24 +105,31 @@ PyAPI_DATA(PyTypeObject) PyDictValues_Type;
# define PyDictViewSet_Check(op) \
(PyDictKeys_Check(op) || PyDictItems_Check(op))
+
PyAPI_FUNC(PyObject *) PyDict_New(void);
PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);
+PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key);
PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item);
PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key);
PyAPI_FUNC(void) PyDict_Clear(PyObject *mp);
PyAPI_FUNC(int) PyDict_Next(
PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyDict_Next(
- PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, long *hash);
+ PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash);
+#endif
PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp);
PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp);
PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp);
PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp);
PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp);
PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key);
-PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, long hash);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash);
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);
+PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp);
+#endif
/* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */
PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other);
diff --git a/Include/dtoa.h b/Include/dtoa.h
index 9b434b77b6e..819bd0f2070 100644
--- a/Include/dtoa.h
+++ b/Include/dtoa.h
@@ -1,3 +1,4 @@
+#ifndef Py_LIMITED_API
#ifndef PY_NO_SHORT_FLOAT_REPR
#ifdef __cplusplus
extern "C" {
@@ -13,3 +14,4 @@ PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);
}
#endif
#endif
+#endif
diff --git a/Include/dynamic_annotations.h b/Include/dynamic_annotations.h
new file mode 100644
index 00000000000..d63c5db0857
--- /dev/null
+++ b/Include/dynamic_annotations.h
@@ -0,0 +1,499 @@
+/* Copyright (c) 2008-2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ---
+ * Author: Kostya Serebryany
+ * Copied to CPython by Jeffrey Yasskin, with all macros renamed to
+ * start with _Py_ to avoid colliding with users embedding Python, and
+ * with deprecated macros removed.
+ */
+
+/* This file defines dynamic annotations for use with dynamic analysis
+ tool such as valgrind, PIN, etc.
+
+ Dynamic annotation is a source code annotation that affects
+ the generated code (that is, the annotation is not a comment).
+ Each such annotation is attached to a particular
+ instruction and/or to a particular object (address) in the program.
+
+ The annotations that should be used by users are macros in all upper-case
+ (e.g., _Py_ANNOTATE_NEW_MEMORY).
+
+ Actual implementation of these macros may differ depending on the
+ dynamic analysis tool being used.
+
+ See http://code.google.com/p/data-race-test/ for more information.
+
+ This file supports the following dynamic analysis tools:
+ - None (DYNAMIC_ANNOTATIONS_ENABLED is not defined or zero).
+ Macros are defined empty.
+ - ThreadSanitizer, Helgrind, DRD (DYNAMIC_ANNOTATIONS_ENABLED is 1).
+ Macros are defined as calls to non-inlinable empty functions
+ that are intercepted by Valgrind. */
+
+#ifndef __DYNAMIC_ANNOTATIONS_H__
+#define __DYNAMIC_ANNOTATIONS_H__
+
+#ifndef DYNAMIC_ANNOTATIONS_ENABLED
+# define DYNAMIC_ANNOTATIONS_ENABLED 0
+#endif
+
+#if DYNAMIC_ANNOTATIONS_ENABLED != 0
+
+ /* -------------------------------------------------------------
+ Annotations useful when implementing condition variables such as CondVar,
+ using conditional critical sections (Await/LockWhen) and when constructing
+ user-defined synchronization mechanisms.
+
+ The annotations _Py_ANNOTATE_HAPPENS_BEFORE() and
+ _Py_ANNOTATE_HAPPENS_AFTER() can be used to define happens-before arcs in
+ user-defined synchronization mechanisms: the race detector will infer an
+ arc from the former to the latter when they share the same argument
+ pointer.
+
+ Example 1 (reference counting):
+
+ void Unref() {
+ _Py_ANNOTATE_HAPPENS_BEFORE(&refcount_);
+ if (AtomicDecrementByOne(&refcount_) == 0) {
+ _Py_ANNOTATE_HAPPENS_AFTER(&refcount_);
+ delete this;
+ }
+ }
+
+ Example 2 (message queue):
+
+ void MyQueue::Put(Type *e) {
+ MutexLock lock(&mu_);
+ _Py_ANNOTATE_HAPPENS_BEFORE(e);
+ PutElementIntoMyQueue(e);
+ }
+
+ Type *MyQueue::Get() {
+ MutexLock lock(&mu_);
+ Type *e = GetElementFromMyQueue();
+ _Py_ANNOTATE_HAPPENS_AFTER(e);
+ return e;
+ }
+
+ Note: when possible, please use the existing reference counting and message
+ queue implementations instead of inventing new ones. */
+
+ /* Report that wait on the condition variable at address "cv" has succeeded
+ and the lock at address "lock" is held. */
+#define _Py_ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) \
+ AnnotateCondVarWait(__FILE__, __LINE__, cv, lock)
+
+ /* Report that wait on the condition variable at "cv" has succeeded. Variant
+ w/o lock. */
+#define _Py_ANNOTATE_CONDVAR_WAIT(cv) \
+ AnnotateCondVarWait(__FILE__, __LINE__, cv, NULL)
+
+ /* Report that we are about to signal on the condition variable at address
+ "cv". */
+#define _Py_ANNOTATE_CONDVAR_SIGNAL(cv) \
+ AnnotateCondVarSignal(__FILE__, __LINE__, cv)
+
+ /* Report that we are about to signal_all on the condition variable at "cv". */
+#define _Py_ANNOTATE_CONDVAR_SIGNAL_ALL(cv) \
+ AnnotateCondVarSignalAll(__FILE__, __LINE__, cv)
+
+ /* Annotations for user-defined synchronization mechanisms. */
+#define _Py_ANNOTATE_HAPPENS_BEFORE(obj) _Py_ANNOTATE_CONDVAR_SIGNAL(obj)
+#define _Py_ANNOTATE_HAPPENS_AFTER(obj) _Py_ANNOTATE_CONDVAR_WAIT(obj)
+
+ /* Report that the bytes in the range [pointer, pointer+size) are about
+ to be published safely. The race checker will create a happens-before
+ arc from the call _Py_ANNOTATE_PUBLISH_MEMORY_RANGE(pointer, size) to
+ subsequent accesses to this memory.
+ Note: this annotation may not work properly if the race detector uses
+ sampling, i.e. does not observe all memory accesses.
+ */
+#define _Py_ANNOTATE_PUBLISH_MEMORY_RANGE(pointer, size) \
+ AnnotatePublishMemoryRange(__FILE__, __LINE__, pointer, size)
+
+ /* Instruct the tool to create a happens-before arc between mu->Unlock() and
+ mu->Lock(). This annotation may slow down the race detector and hide real
+ races. Normally it is used only when it would be difficult to annotate each
+ of the mutex's critical sections individually using the annotations above.
+ This annotation makes sense only for hybrid race detectors. For pure
+ happens-before detectors this is a no-op. For more details see
+ http://code.google.com/p/data-race-test/wiki/PureHappensBeforeVsHybrid . */
+#define _Py_ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) \
+ AnnotateMutexIsUsedAsCondVar(__FILE__, __LINE__, mu)
+
+ /* -------------------------------------------------------------
+ Annotations useful when defining memory allocators, or when memory that
+ was protected in one way starts to be protected in another. */
+
+ /* Report that a new memory at "address" of size "size" has been allocated.
+ This might be used when the memory has been retrieved from a free list and
+ is about to be reused, or when a the locking discipline for a variable
+ changes. */
+#define _Py_ANNOTATE_NEW_MEMORY(address, size) \
+ AnnotateNewMemory(__FILE__, __LINE__, address, size)
+
+ /* -------------------------------------------------------------
+ Annotations useful when defining FIFO queues that transfer data between
+ threads. */
+
+ /* Report that the producer-consumer queue (such as ProducerConsumerQueue) at
+ address "pcq" has been created. The _Py_ANNOTATE_PCQ_* annotations should
+ be used only for FIFO queues. For non-FIFO queues use
+ _Py_ANNOTATE_HAPPENS_BEFORE (for put) and _Py_ANNOTATE_HAPPENS_AFTER (for
+ get). */
+#define _Py_ANNOTATE_PCQ_CREATE(pcq) \
+ AnnotatePCQCreate(__FILE__, __LINE__, pcq)
+
+ /* Report that the queue at address "pcq" is about to be destroyed. */
+#define _Py_ANNOTATE_PCQ_DESTROY(pcq) \
+ AnnotatePCQDestroy(__FILE__, __LINE__, pcq)
+
+ /* Report that we are about to put an element into a FIFO queue at address
+ "pcq". */
+#define _Py_ANNOTATE_PCQ_PUT(pcq) \
+ AnnotatePCQPut(__FILE__, __LINE__, pcq)
+
+ /* Report that we've just got an element from a FIFO queue at address "pcq". */
+#define _Py_ANNOTATE_PCQ_GET(pcq) \
+ AnnotatePCQGet(__FILE__, __LINE__, pcq)
+
+ /* -------------------------------------------------------------
+ Annotations that suppress errors. It is usually better to express the
+ program's synchronization using the other annotations, but these can
+ be used when all else fails. */
+
+ /* Report that we may have a benign race at "pointer", with size
+ "sizeof(*(pointer))". "pointer" must be a non-void* pointer. Insert at the
+ point where "pointer" has been allocated, preferably close to the point
+ where the race happens. See also _Py_ANNOTATE_BENIGN_RACE_STATIC. */
+#define _Py_ANNOTATE_BENIGN_RACE(pointer, description) \
+ AnnotateBenignRaceSized(__FILE__, __LINE__, pointer, \
+ sizeof(*(pointer)), description)
+
+ /* Same as _Py_ANNOTATE_BENIGN_RACE(address, description), but applies to
+ the memory range [address, address+size). */
+#define _Py_ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \
+ AnnotateBenignRaceSized(__FILE__, __LINE__, address, size, description)
+
+ /* Request the analysis tool to ignore all reads in the current thread
+ until _Py_ANNOTATE_IGNORE_READS_END is called.
+ Useful to ignore intentional racey reads, while still checking
+ other reads and all writes.
+ See also _Py_ANNOTATE_UNPROTECTED_READ. */
+#define _Py_ANNOTATE_IGNORE_READS_BEGIN() \
+ AnnotateIgnoreReadsBegin(__FILE__, __LINE__)
+
+ /* Stop ignoring reads. */
+#define _Py_ANNOTATE_IGNORE_READS_END() \
+ AnnotateIgnoreReadsEnd(__FILE__, __LINE__)
+
+ /* Similar to _Py_ANNOTATE_IGNORE_READS_BEGIN, but ignore writes. */
+#define _Py_ANNOTATE_IGNORE_WRITES_BEGIN() \
+ AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
+
+ /* Stop ignoring writes. */
+#define _Py_ANNOTATE_IGNORE_WRITES_END() \
+ AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
+
+ /* Start ignoring all memory accesses (reads and writes). */
+#define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \
+ do {\
+ _Py_ANNOTATE_IGNORE_READS_BEGIN();\
+ _Py_ANNOTATE_IGNORE_WRITES_BEGIN();\
+ }while(0)\
+
+ /* Stop ignoring all memory accesses. */
+#define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_END() \
+ do {\
+ _Py_ANNOTATE_IGNORE_WRITES_END();\
+ _Py_ANNOTATE_IGNORE_READS_END();\
+ }while(0)\
+
+ /* Similar to _Py_ANNOTATE_IGNORE_READS_BEGIN, but ignore synchronization events:
+ RWLOCK* and CONDVAR*. */
+#define _Py_ANNOTATE_IGNORE_SYNC_BEGIN() \
+ AnnotateIgnoreSyncBegin(__FILE__, __LINE__)
+
+ /* Stop ignoring sync events. */
+#define _Py_ANNOTATE_IGNORE_SYNC_END() \
+ AnnotateIgnoreSyncEnd(__FILE__, __LINE__)
+
+
+ /* Enable (enable!=0) or disable (enable==0) race detection for all threads.
+ This annotation could be useful if you want to skip expensive race analysis
+ during some period of program execution, e.g. during initialization. */
+#define _Py_ANNOTATE_ENABLE_RACE_DETECTION(enable) \
+ AnnotateEnableRaceDetection(__FILE__, __LINE__, enable)
+
+ /* -------------------------------------------------------------
+ Annotations useful for debugging. */
+
+ /* Request to trace every access to "address". */
+#define _Py_ANNOTATE_TRACE_MEMORY(address) \
+ AnnotateTraceMemory(__FILE__, __LINE__, address)
+
+ /* Report the current thread name to a race detector. */
+#define _Py_ANNOTATE_THREAD_NAME(name) \
+ AnnotateThreadName(__FILE__, __LINE__, name)
+
+ /* -------------------------------------------------------------
+ Annotations useful when implementing locks. They are not
+ normally needed by modules that merely use locks.
+ The "lock" argument is a pointer to the lock object. */
+
+ /* Report that a lock has been created at address "lock". */
+#define _Py_ANNOTATE_RWLOCK_CREATE(lock) \
+ AnnotateRWLockCreate(__FILE__, __LINE__, lock)
+
+ /* Report that the lock at address "lock" is about to be destroyed. */
+#define _Py_ANNOTATE_RWLOCK_DESTROY(lock) \
+ AnnotateRWLockDestroy(__FILE__, __LINE__, lock)
+
+ /* Report that the lock at address "lock" has been acquired.
+ is_w=1 for writer lock, is_w=0 for reader lock. */
+#define _Py_ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \
+ AnnotateRWLockAcquired(__FILE__, __LINE__, lock, is_w)
+
+ /* Report that the lock at address "lock" is about to be released. */
+#define _Py_ANNOTATE_RWLOCK_RELEASED(lock, is_w) \
+ AnnotateRWLockReleased(__FILE__, __LINE__, lock, is_w)
+
+ /* -------------------------------------------------------------
+ Annotations useful when implementing barriers. They are not
+ normally needed by modules that merely use barriers.
+ The "barrier" argument is a pointer to the barrier object. */
+
+ /* Report that the "barrier" has been initialized with initial "count".
+ If 'reinitialization_allowed' is true, initialization is allowed to happen
+ multiple times w/o calling barrier_destroy() */
+#define _Py_ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) \
+ AnnotateBarrierInit(__FILE__, __LINE__, barrier, count, \
+ reinitialization_allowed)
+
+ /* Report that we are about to enter barrier_wait("barrier"). */
+#define _Py_ANNOTATE_BARRIER_WAIT_BEFORE(barrier) \
+ AnnotateBarrierWaitBefore(__FILE__, __LINE__, barrier)
+
+ /* Report that we just exited barrier_wait("barrier"). */
+#define _Py_ANNOTATE_BARRIER_WAIT_AFTER(barrier) \
+ AnnotateBarrierWaitAfter(__FILE__, __LINE__, barrier)
+
+ /* Report that the "barrier" has been destroyed. */
+#define _Py_ANNOTATE_BARRIER_DESTROY(barrier) \
+ AnnotateBarrierDestroy(__FILE__, __LINE__, barrier)
+
+ /* -------------------------------------------------------------
+ Annotations useful for testing race detectors. */
+
+ /* Report that we expect a race on the variable at "address".
+ Use only in unit tests for a race detector. */
+#define _Py_ANNOTATE_EXPECT_RACE(address, description) \
+ AnnotateExpectRace(__FILE__, __LINE__, address, description)
+
+ /* A no-op. Insert where you like to test the interceptors. */
+#define _Py_ANNOTATE_NO_OP(arg) \
+ AnnotateNoOp(__FILE__, __LINE__, arg)
+
+ /* Force the race detector to flush its state. The actual effect depends on
+ * the implementation of the detector. */
+#define _Py_ANNOTATE_FLUSH_STATE() \
+ AnnotateFlushState(__FILE__, __LINE__)
+
+
+#else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */
+
+#define _Py_ANNOTATE_RWLOCK_CREATE(lock) /* empty */
+#define _Py_ANNOTATE_RWLOCK_DESTROY(lock) /* empty */
+#define _Py_ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) /* empty */
+#define _Py_ANNOTATE_RWLOCK_RELEASED(lock, is_w) /* empty */
+#define _Py_ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) /* */
+#define _Py_ANNOTATE_BARRIER_WAIT_BEFORE(barrier) /* empty */
+#define _Py_ANNOTATE_BARRIER_WAIT_AFTER(barrier) /* empty */
+#define _Py_ANNOTATE_BARRIER_DESTROY(barrier) /* empty */
+#define _Py_ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) /* empty */
+#define _Py_ANNOTATE_CONDVAR_WAIT(cv) /* empty */
+#define _Py_ANNOTATE_CONDVAR_SIGNAL(cv) /* empty */
+#define _Py_ANNOTATE_CONDVAR_SIGNAL_ALL(cv) /* empty */
+#define _Py_ANNOTATE_HAPPENS_BEFORE(obj) /* empty */
+#define _Py_ANNOTATE_HAPPENS_AFTER(obj) /* empty */
+#define _Py_ANNOTATE_PUBLISH_MEMORY_RANGE(address, size) /* empty */
+#define _Py_ANNOTATE_UNPUBLISH_MEMORY_RANGE(address, size) /* empty */
+#define _Py_ANNOTATE_SWAP_MEMORY_RANGE(address, size) /* empty */
+#define _Py_ANNOTATE_PCQ_CREATE(pcq) /* empty */
+#define _Py_ANNOTATE_PCQ_DESTROY(pcq) /* empty */
+#define _Py_ANNOTATE_PCQ_PUT(pcq) /* empty */
+#define _Py_ANNOTATE_PCQ_GET(pcq) /* empty */
+#define _Py_ANNOTATE_NEW_MEMORY(address, size) /* empty */
+#define _Py_ANNOTATE_EXPECT_RACE(address, description) /* empty */
+#define _Py_ANNOTATE_BENIGN_RACE(address, description) /* empty */
+#define _Py_ANNOTATE_BENIGN_RACE_SIZED(address, size, description) /* empty */
+#define _Py_ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) /* empty */
+#define _Py_ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mu) /* empty */
+#define _Py_ANNOTATE_TRACE_MEMORY(arg) /* empty */
+#define _Py_ANNOTATE_THREAD_NAME(name) /* empty */
+#define _Py_ANNOTATE_IGNORE_READS_BEGIN() /* empty */
+#define _Py_ANNOTATE_IGNORE_READS_END() /* empty */
+#define _Py_ANNOTATE_IGNORE_WRITES_BEGIN() /* empty */
+#define _Py_ANNOTATE_IGNORE_WRITES_END() /* empty */
+#define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() /* empty */
+#define _Py_ANNOTATE_IGNORE_READS_AND_WRITES_END() /* empty */
+#define _Py_ANNOTATE_IGNORE_SYNC_BEGIN() /* empty */
+#define _Py_ANNOTATE_IGNORE_SYNC_END() /* empty */
+#define _Py_ANNOTATE_ENABLE_RACE_DETECTION(enable) /* empty */
+#define _Py_ANNOTATE_NO_OP(arg) /* empty */
+#define _Py_ANNOTATE_FLUSH_STATE() /* empty */
+
+#endif /* DYNAMIC_ANNOTATIONS_ENABLED */
+
+/* Use the macros above rather than using these functions directly. */
+#ifdef __cplusplus
+extern "C" {
+#endif
+void AnnotateRWLockCreate(const char *file, int line,
+ const volatile void *lock);
+void AnnotateRWLockDestroy(const char *file, int line,
+ const volatile void *lock);
+void AnnotateRWLockAcquired(const char *file, int line,
+ const volatile void *lock, long is_w);
+void AnnotateRWLockReleased(const char *file, int line,
+ const volatile void *lock, long is_w);
+void AnnotateBarrierInit(const char *file, int line,
+ const volatile void *barrier, long count,
+ long reinitialization_allowed);
+void AnnotateBarrierWaitBefore(const char *file, int line,
+ const volatile void *barrier);
+void AnnotateBarrierWaitAfter(const char *file, int line,
+ const volatile void *barrier);
+void AnnotateBarrierDestroy(const char *file, int line,
+ const volatile void *barrier);
+void AnnotateCondVarWait(const char *file, int line,
+ const volatile void *cv,
+ const volatile void *lock);
+void AnnotateCondVarSignal(const char *file, int line,
+ const volatile void *cv);
+void AnnotateCondVarSignalAll(const char *file, int line,
+ const volatile void *cv);
+void AnnotatePublishMemoryRange(const char *file, int line,
+ const volatile void *address,
+ long size);
+void AnnotateUnpublishMemoryRange(const char *file, int line,
+ const volatile void *address,
+ long size);
+void AnnotatePCQCreate(const char *file, int line,
+ const volatile void *pcq);
+void AnnotatePCQDestroy(const char *file, int line,
+ const volatile void *pcq);
+void AnnotatePCQPut(const char *file, int line,
+ const volatile void *pcq);
+void AnnotatePCQGet(const char *file, int line,
+ const volatile void *pcq);
+void AnnotateNewMemory(const char *file, int line,
+ const volatile void *address,
+ long size);
+void AnnotateExpectRace(const char *file, int line,
+ const volatile void *address,
+ const char *description);
+void AnnotateBenignRace(const char *file, int line,
+ const volatile void *address,
+ const char *description);
+void AnnotateBenignRaceSized(const char *file, int line,
+ const volatile void *address,
+ long size,
+ const char *description);
+void AnnotateMutexIsUsedAsCondVar(const char *file, int line,
+ const volatile void *mu);
+void AnnotateTraceMemory(const char *file, int line,
+ const volatile void *arg);
+void AnnotateThreadName(const char *file, int line,
+ const char *name);
+void AnnotateIgnoreReadsBegin(const char *file, int line);
+void AnnotateIgnoreReadsEnd(const char *file, int line);
+void AnnotateIgnoreWritesBegin(const char *file, int line);
+void AnnotateIgnoreWritesEnd(const char *file, int line);
+void AnnotateEnableRaceDetection(const char *file, int line, int enable);
+void AnnotateNoOp(const char *file, int line,
+ const volatile void *arg);
+void AnnotateFlushState(const char *file, int line);
+
+/* Return non-zero value if running under valgrind.
+
+ If "valgrind.h" is included into dynamic_annotations.c,
+ the regular valgrind mechanism will be used.
+ See http://valgrind.org/docs/manual/manual-core-adv.html about
+ RUNNING_ON_VALGRIND and other valgrind "client requests".
+ The file "valgrind.h" may be obtained by doing
+ svn co svn://svn.valgrind.org/valgrind/trunk/include
+
+ If for some reason you can't use "valgrind.h" or want to fake valgrind,
+ there are two ways to make this function return non-zero:
+ - Use environment variable: export RUNNING_ON_VALGRIND=1
+ - Make your tool intercept the function RunningOnValgrind() and
+ change its return value.
+ */
+int RunningOnValgrind(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#if DYNAMIC_ANNOTATIONS_ENABLED != 0 && defined(__cplusplus)
+
+ /* _Py_ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racey reads.
+
+ Instead of doing
+ _Py_ANNOTATE_IGNORE_READS_BEGIN();
+ ... = x;
+ _Py_ANNOTATE_IGNORE_READS_END();
+ one can use
+ ... = _Py_ANNOTATE_UNPROTECTED_READ(x); */
+ template <class T>
+ inline T _Py_ANNOTATE_UNPROTECTED_READ(const volatile T &x) {
+ _Py_ANNOTATE_IGNORE_READS_BEGIN();
+ T res = x;
+ _Py_ANNOTATE_IGNORE_READS_END();
+ return res;
+ }
+ /* Apply _Py_ANNOTATE_BENIGN_RACE_SIZED to a static variable. */
+#define _Py_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \
+ namespace { \
+ class static_var ## _annotator { \
+ public: \
+ static_var ## _annotator() { \
+ _Py_ANNOTATE_BENIGN_RACE_SIZED(&static_var, \
+ sizeof(static_var), \
+ # static_var ": " description); \
+ } \
+ }; \
+ static static_var ## _annotator the ## static_var ## _annotator;\
+ }
+#else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */
+
+#define _Py_ANNOTATE_UNPROTECTED_READ(x) (x)
+#define _Py_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) /* empty */
+
+#endif /* DYNAMIC_ANNOTATIONS_ENABLED */
+
+#endif /* __DYNAMIC_ANNOTATIONS_H__ */
diff --git a/Include/errcode.h b/Include/errcode.h
index becec80c8ac..6bb3cc1e5f7 100644
--- a/Include/errcode.h
+++ b/Include/errcode.h
@@ -29,6 +29,7 @@ extern "C" {
#define E_EOFS 23 /* EOF in triple-quoted string */
#define E_EOLS 24 /* EOL in single-quoted string */
#define E_LINECONT 25 /* Unexpected characters after a line continuation */
+#define E_IDENTIFIER 26 /* Invalid characters in identifier */
#ifdef __cplusplus
}
diff --git a/Include/eval.h b/Include/eval.h
index b78dfe0fae0..a1c6e817dd3 100644
--- a/Include/eval.h
+++ b/Include/eval.h
@@ -7,17 +7,19 @@
extern "C" {
#endif
-PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyCodeObject *, PyObject *, PyObject *);
+PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyObject *, PyObject *, PyObject *);
-PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyCodeObject *co,
+PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyObject *co,
PyObject *globals,
PyObject *locals,
PyObject **args, int argc,
PyObject **kwds, int kwdc,
PyObject **defs, int defc,
- PyObject *closure);
+ PyObject *kwdefs, PyObject *closure);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyEval_CallTracing(PyObject *func, PyObject *args);
+#endif
#ifdef __cplusplus
}
diff --git a/Include/fileobject.h b/Include/fileobject.h
index 1b540f902f1..a99c94d2d54 100644
--- a/Include/fileobject.h
+++ b/Include/fileobject.h
@@ -1,5 +1,4 @@
-
-/* File object interface */
+/* File object interface (what's left of it -- see io.py) */
#ifndef Py_FILEOBJECT_H
#define Py_FILEOBJECT_H
@@ -7,68 +6,31 @@
extern "C" {
#endif
-typedef struct {
- PyObject_HEAD
- FILE *f_fp;
- PyObject *f_name;
- PyObject *f_mode;
- int (*f_close)(FILE *);
- int f_softspace; /* Flag used by 'print' command */
- int f_binary; /* Flag which indicates whether the file is
- open in binary (1) or text (0) mode */
- char* f_buf; /* Allocated readahead buffer */
- char* f_bufend; /* Points after last occupied position */
- char* f_bufptr; /* Current buffer position */
- char *f_setbuf; /* Buffer for setbuf(3) and setvbuf(3) */
- int f_univ_newline; /* Handle any newline convention */
- int f_newlinetypes; /* Types of newlines seen */
- int f_skipnextlf; /* Skip next \n */
- PyObject *f_encoding;
- PyObject *f_errors;
- PyObject *weakreflist; /* List of weak references */
- int unlocked_count; /* Num. currently running sections of code
- using f_fp with the GIL released. */
- int readable;
- int writable;
-} PyFileObject;
-
-PyAPI_DATA(PyTypeObject) PyFile_Type;
-
-#define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type)
-#define PyFile_CheckExact(op) (Py_TYPE(op) == &PyFile_Type)
+#define PY_STDIOTEXTMODE "b"
-PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *);
-PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int);
-PyAPI_FUNC(int) PyFile_SetEncoding(PyObject *, const char *);
-PyAPI_FUNC(int) PyFile_SetEncodingAndErrors(PyObject *, const char *, char *errors);
-PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *,
- int (*)(FILE *));
-PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *);
-PyAPI_FUNC(void) PyFile_IncUseCount(PyFileObject *);
-PyAPI_FUNC(void) PyFile_DecUseCount(PyFileObject *);
-PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);
+PyAPI_FUNC(PyObject *) PyFile_FromFd(int, char *, char *, int, char *, char *,
+ char *, int);
PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
-PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int);
PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(char *) Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
+#endif
/* The default encoding used by the platform file system APIs
If non-NULL, this is different than the default encoding for strings
*/
PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
+PyAPI_DATA(int) Py_HasFileSystemDefaultEncoding;
-/* Routines to replace fread() and fgets() which accept any of \r, \n
- or \r\n as line terminators.
-*/
-#define PY_STDIOTEXTMODE "b"
-char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
-size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
+/* Internal API
-/* A routine to do sanity checking on the file mode string. returns
- non-zero on if an exception occurred
-*/
-int _PyFile_SanitizeMode(char *mode);
+ The std printer acts as a preliminary sys.stderr until the new io
+ infrastructure is in place. */
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(PyObject *) PyFile_NewStdPrinter(int);
+PyAPI_DATA(PyTypeObject) PyStdPrinter_Type;
#if defined _MSC_VER && _MSC_VER >= 1400
/* A routine to check if a file descriptor is valid on Windows. Returns 0
@@ -77,12 +39,10 @@ int _PyFile_SanitizeMode(char *mode);
* Visual Studio 2005
*/
int _PyVerify_fd(int fd);
-#elif defined _MSC_VER && _MSC_VER >= 1200
-/* fdopen doesn't set errno EBADF and crashes for large fd on debug build */
-#define _PyVerify_fd(fd) (_get_osfhandle(fd) >= 0)
#else
#define _PyVerify_fd(A) (1) /* dummy */
#endif
+#endif /* Py_LIMITED_API */
/* A routine to check if a file descriptor can be select()-ed. */
#ifdef HAVE_SELECT
diff --git a/Include/fileutils.h b/Include/fileutils.h
new file mode 100644
index 00000000000..2fade9b95cd
--- /dev/null
+++ b/Include/fileutils.h
@@ -0,0 +1,58 @@
+#ifndef Py_FILEUTILS_H
+#define Py_FILEUTILS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+PyAPI_FUNC(wchar_t *) _Py_char2wchar(
+ const char *arg,
+ size_t *size);
+
+PyAPI_FUNC(char*) _Py_wchar2char(
+ const wchar_t *text,
+ size_t *error_pos);
+
+#if defined(HAVE_STAT) && !defined(MS_WINDOWS)
+PyAPI_FUNC(int) _Py_wstat(
+ const wchar_t* path,
+ struct stat *buf);
+#endif
+
+#ifdef HAVE_STAT
+PyAPI_FUNC(int) _Py_stat(
+ PyObject *path,
+ struct stat *statbuf);
+#endif
+
+PyAPI_FUNC(FILE *) _Py_wfopen(
+ const wchar_t *path,
+ const wchar_t *mode);
+
+PyAPI_FUNC(FILE*) _Py_fopen(
+ PyObject *path,
+ const char *mode);
+
+#ifdef HAVE_READLINK
+PyAPI_FUNC(int) _Py_wreadlink(
+ const wchar_t *path,
+ wchar_t *buf,
+ size_t bufsiz);
+#endif
+
+#ifdef HAVE_REALPATH
+PyAPI_FUNC(wchar_t*) _Py_wrealpath(
+ const wchar_t *path,
+ wchar_t *resolved_path,
+ size_t resolved_path_size);
+#endif
+
+PyAPI_FUNC(wchar_t*) _Py_wgetcwd(
+ wchar_t *buf,
+ size_t size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !Py_FILEUTILS_H */
diff --git a/Include/floatobject.h b/Include/floatobject.h
index 54e88256a2e..90f0a454aa2 100644
--- a/Include/floatobject.h
+++ b/Include/floatobject.h
@@ -11,22 +11,18 @@ PyFloatObject represents a (double precision) floating point number.
extern "C" {
#endif
+#ifndef Py_LIMITED_API
typedef struct {
PyObject_HEAD
double ob_fval;
} PyFloatObject;
+#endif
PyAPI_DATA(PyTypeObject) PyFloat_Type;
#define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type)
#define PyFloat_CheckExact(op) (Py_TYPE(op) == &PyFloat_Type)
-/* The str() precision PyFloat_STR_PRECISION is chosen so that in most cases,
- the rounding noise created by various operations is suppressed, while
- giving plenty of precision for practical use. */
-
-#define PyFloat_STR_PRECISION 12
-
#ifdef Py_NAN
#define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN)
#endif
@@ -42,10 +38,8 @@ PyAPI_FUNC(double) PyFloat_GetMax(void);
PyAPI_FUNC(double) PyFloat_GetMin(void);
PyAPI_FUNC(PyObject *) PyFloat_GetInfo(void);
-/* Return Python float from string PyObject. Second argument ignored on
- input, and, if non-NULL, NULL is stored into *junk (this tried to serve a
- purpose once but can't be made to work as intended). */
-PyAPI_FUNC(PyObject *) PyFloat_FromString(PyObject*, char** junk);
+/* Return Python float from string PyObject. */
+PyAPI_FUNC(PyObject *) PyFloat_FromString(PyObject*);
/* Return Python float from C double. */
PyAPI_FUNC(PyObject *) PyFloat_FromDouble(double);
@@ -53,21 +47,11 @@ PyAPI_FUNC(PyObject *) PyFloat_FromDouble(double);
/* Extract C double from Python float. The macro version trades safety for
speed. */
PyAPI_FUNC(double) PyFloat_AsDouble(PyObject *);
+#ifndef Py_LIMITED_API
#define PyFloat_AS_DOUBLE(op) (((PyFloatObject *)(op))->ob_fval)
+#endif
-/* Write repr(v) into the char buffer argument, followed by null byte. The
- buffer must be "big enough"; >= 100 is very safe.
- PyFloat_AsReprString(buf, x) strives to print enough digits so that
- PyFloat_FromString(buf) then reproduces x exactly. */
-PyAPI_FUNC(void) PyFloat_AsReprString(char*, PyFloatObject *v);
-
-/* Write str(v) into the char buffer argument, followed by null byte. The
- buffer must be "big enough"; >= 100 is very safe. Note that it's
- unusual to be able to get back the float you started with from
- PyFloat_AsString's result -- use PyFloat_AsReprString() if you want to
- preserve precision across conversions. */
-PyAPI_FUNC(void) PyFloat_AsString(char*, PyFloatObject *v);
-
+#ifndef Py_LIMITED_API
/* _PyFloat_{Pack,Unpack}{4,8}
*
* The struct and pickle (at least) modules need an efficient platform-
@@ -103,6 +87,11 @@ PyAPI_FUNC(void) PyFloat_AsString(char*, PyFloatObject *v);
PyAPI_FUNC(int) _PyFloat_Pack4(double x, unsigned char *p, int le);
PyAPI_FUNC(int) _PyFloat_Pack8(double x, unsigned char *p, int le);
+/* Needed for the old way for marshal to store a floating point number.
+ Returns the string length copied into p, -1 on error.
+ */
+PyAPI_FUNC(int) _PyFloat_Repr(double x, char *p, size_t len);
+
/* Used to get the important decimal digits of a double */
PyAPI_FUNC(int) _PyFloat_Digits(char *buf, double v, int *signum);
PyAPI_FUNC(void) _PyFloat_DigitsInit(void);
@@ -124,15 +113,9 @@ PyAPI_FUNC(int) PyFloat_ClearFreeList(void);
/* Format the object based on the format_spec, as defined in PEP 3101
(Advanced String Formatting). */
PyAPI_FUNC(PyObject *) _PyFloat_FormatAdvanced(PyObject *obj,
- char *format_spec,
+ Py_UNICODE *format_spec,
Py_ssize_t format_spec_len);
-
-/* Round a C double x to the closest multiple of 10**-ndigits. Returns a
- Python float on success, or NULL (with an appropriate exception set) on
- failure. Used in builtin_round in bltinmodule.c. */
-PyAPI_FUNC(PyObject *) _Py_double_round(double x, int ndigits);
-
-
+#endif /* Py_LIMITED_API */
#ifdef __cplusplus
}
diff --git a/Include/frameobject.h b/Include/frameobject.h
index 17e7679ac87..1fb64bb2681 100644
--- a/Include/frameobject.h
+++ b/Include/frameobject.h
@@ -1,6 +1,7 @@
/* Frame object interface */
+#ifndef Py_LIMITED_API
#ifndef Py_FRAMEOBJECT_H
#define Py_FRAMEOBJECT_H
#ifdef __cplusplus
@@ -27,13 +28,13 @@ typedef struct _frame {
PyObject **f_stacktop;
PyObject *f_trace; /* Trace function */
- /* If an exception is raised in this frame, the next three are used to
- * record the exception info (if any) originally in the thread state. See
- * comments before set_exc_info() -- it's not obvious.
- * Invariant: if _type is NULL, then so are _value and _traceback.
- * Desired invariant: all three are NULL, or all three are non-NULL. That
- * one isn't currently true, but "should be".
- */
+ /* In a generator, we need to be able to swap between the exception
+ state inside the generator and the exception state of the calling
+ frame (which shouldn't be impacted when the generator "yields"
+ from an except handler).
+ These three fields exist exactly for that, and are unused for
+ non-generator frames. See the SAVE_EXC_STATE and SWAP_EXC_STATE
+ macros in ceval.c for details of their use. */
PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;
PyThreadState *f_tstate;
@@ -54,9 +55,7 @@ typedef struct _frame {
PyAPI_DATA(PyTypeObject) PyFrame_Type;
-#define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
-#define PyFrame_IsRestricted(f) \
- ((f)->f_builtins != (f)->f_tstate->interp->builtins)
+#define PyFrame_Check(op) (Py_TYPE(op) == &PyFrame_Type)
PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
PyObject *, PyObject *);
@@ -87,3 +86,4 @@ PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *);
}
#endif
#endif /* !Py_FRAMEOBJECT_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/funcobject.h b/Include/funcobject.h
index eb19f4c3890..521d87bf9f1 100644
--- a/Include/funcobject.h
+++ b/Include/funcobject.h
@@ -1,6 +1,6 @@
/* Function object interface */
-
+#ifndef Py_LIMITED_API
#ifndef Py_FUNCOBJECT_H
#define Py_FUNCOBJECT_H
#ifdef __cplusplus
@@ -10,7 +10,7 @@ extern "C" {
/* Function objects and code objects should not be confused with each other:
*
* Function objects are created by the execution of the 'def' statement.
- * They reference a code object in their func_code attribute, which is a
+ * They reference a code object in their __code__ attribute, which is a
* purely syntactic object, i.e. nothing more than a compiled version of some
* source code lines. There is one code object per source code "fragment",
* but each code object can be referenced by zero or many function objects
@@ -20,15 +20,17 @@ extern "C" {
typedef struct {
PyObject_HEAD
- PyObject *func_code; /* A code object */
+ PyObject *func_code; /* A code object, the __code__ attribute */
PyObject *func_globals; /* A dictionary (other mappings won't do) */
PyObject *func_defaults; /* NULL or a tuple */
+ PyObject *func_kwdefaults; /* NULL or a dict */
PyObject *func_closure; /* NULL or a tuple of cell objects */
PyObject *func_doc; /* The __doc__ attribute, can be anything */
PyObject *func_name; /* The __name__ attribute, a string object */
PyObject *func_dict; /* The __dict__ attribute, a dict or NULL */
PyObject *func_weakreflist; /* List of weak references */
PyObject *func_module; /* The __module__ attribute, can be anything */
+ PyObject *func_annotations; /* Annotations, a dict or NULL */
/* Invariant:
* func_closure contains the bindings for func_code->co_freevars, so
@@ -47,8 +49,12 @@ PyAPI_FUNC(PyObject *) PyFunction_GetGlobals(PyObject *);
PyAPI_FUNC(PyObject *) PyFunction_GetModule(PyObject *);
PyAPI_FUNC(PyObject *) PyFunction_GetDefaults(PyObject *);
PyAPI_FUNC(int) PyFunction_SetDefaults(PyObject *, PyObject *);
+PyAPI_FUNC(PyObject *) PyFunction_GetKwDefaults(PyObject *);
+PyAPI_FUNC(int) PyFunction_SetKwDefaults(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyFunction_GetClosure(PyObject *);
PyAPI_FUNC(int) PyFunction_SetClosure(PyObject *, PyObject *);
+PyAPI_FUNC(PyObject *) PyFunction_GetAnnotations(PyObject *);
+PyAPI_FUNC(int) PyFunction_SetAnnotations(PyObject *, PyObject *);
/* Macros for direct access to these values. Type checks are *not*
done, so use with care. */
@@ -60,8 +66,12 @@ PyAPI_FUNC(int) PyFunction_SetClosure(PyObject *, PyObject *);
(((PyFunctionObject *)func) -> func_module)
#define PyFunction_GET_DEFAULTS(func) \
(((PyFunctionObject *)func) -> func_defaults)
+#define PyFunction_GET_KW_DEFAULTS(func) \
+ (((PyFunctionObject *)func) -> func_kwdefaults)
#define PyFunction_GET_CLOSURE(func) \
(((PyFunctionObject *)func) -> func_closure)
+#define PyFunction_GET_ANNOTATIONS(func) \
+ (((PyFunctionObject *)func) -> func_annotations)
/* The classmethod and staticmethod types lives here, too */
PyAPI_DATA(PyTypeObject) PyClassMethod_Type;
@@ -74,3 +84,4 @@ PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *);
}
#endif
#endif /* !Py_FUNCOBJECT_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/genobject.h b/Include/genobject.h
index 135561b701b..d29fb1ed1df 100644
--- a/Include/genobject.h
+++ b/Include/genobject.h
@@ -1,6 +1,7 @@
/* Generator object interface */
+#ifndef Py_LIMITED_API
#ifndef Py_GENOBJECT_H
#define Py_GENOBJECT_H
#ifdef __cplusplus
@@ -38,3 +39,4 @@ PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *);
}
#endif
#endif /* !Py_GENOBJECT_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/graminit.h b/Include/graminit.h
index 40d531e8a15..e0e27f98c38 100644
--- a/Include/graminit.h
+++ b/Include/graminit.h
@@ -8,64 +8,64 @@
#define decorated 261
#define funcdef 262
#define parameters 263
-#define varargslist 264
-#define fpdef 265
-#define fplist 266
-#define stmt 267
-#define simple_stmt 268
-#define small_stmt 269
-#define expr_stmt 270
-#define augassign 271
-#define print_stmt 272
-#define del_stmt 273
-#define pass_stmt 274
-#define flow_stmt 275
-#define break_stmt 276
-#define continue_stmt 277
-#define return_stmt 278
-#define yield_stmt 279
-#define raise_stmt 280
-#define import_stmt 281
-#define import_name 282
-#define import_from 283
-#define import_as_name 284
-#define dotted_as_name 285
-#define import_as_names 286
-#define dotted_as_names 287
-#define dotted_name 288
-#define global_stmt 289
-#define exec_stmt 290
-#define assert_stmt 291
-#define compound_stmt 292
-#define if_stmt 293
-#define while_stmt 294
-#define for_stmt 295
-#define try_stmt 296
-#define with_stmt 297
-#define with_item 298
-#define except_clause 299
-#define suite 300
-#define testlist_safe 301
-#define old_test 302
-#define old_lambdef 303
-#define test 304
-#define or_test 305
-#define and_test 306
-#define not_test 307
-#define comparison 308
-#define comp_op 309
-#define expr 310
-#define xor_expr 311
-#define and_expr 312
-#define shift_expr 313
-#define arith_expr 314
-#define term 315
-#define factor 316
-#define power 317
-#define atom 318
-#define listmaker 319
-#define testlist_comp 320
-#define lambdef 321
+#define typedargslist 264
+#define tfpdef 265
+#define varargslist 266
+#define vfpdef 267
+#define stmt 268
+#define simple_stmt 269
+#define small_stmt 270
+#define expr_stmt 271
+#define testlist_star_expr 272
+#define augassign 273
+#define del_stmt 274
+#define pass_stmt 275
+#define flow_stmt 276
+#define break_stmt 277
+#define continue_stmt 278
+#define return_stmt 279
+#define yield_stmt 280
+#define raise_stmt 281
+#define import_stmt 282
+#define import_name 283
+#define import_from 284
+#define import_as_name 285
+#define dotted_as_name 286
+#define import_as_names 287
+#define dotted_as_names 288
+#define dotted_name 289
+#define global_stmt 290
+#define nonlocal_stmt 291
+#define assert_stmt 292
+#define compound_stmt 293
+#define if_stmt 294
+#define while_stmt 295
+#define for_stmt 296
+#define try_stmt 297
+#define with_stmt 298
+#define with_item 299
+#define except_clause 300
+#define suite 301
+#define test 302
+#define test_nocond 303
+#define lambdef 304
+#define lambdef_nocond 305
+#define or_test 306
+#define and_test 307
+#define not_test 308
+#define comparison 309
+#define comp_op 310
+#define star_expr 311
+#define expr 312
+#define xor_expr 313
+#define and_expr 314
+#define shift_expr 315
+#define arith_expr 316
+#define term 317
+#define factor 318
+#define power 319
+#define atom 320
+#define testlist_comp 321
#define trailer 322
#define subscriptlist 323
#define subscript 324
@@ -76,12 +76,8 @@
#define classdef 329
#define arglist 330
#define argument 331
-#define list_iter 332
-#define list_for 333
-#define list_if 334
-#define comp_iter 335
-#define comp_for 336
-#define comp_if 337
-#define testlist1 338
-#define encoding_decl 339
-#define yield_expr 340
+#define comp_iter 332
+#define comp_for 333
+#define comp_if 334
+#define encoding_decl 335
+#define yield_expr 336
diff --git a/Include/import.h b/Include/import.h
index 1b7fe0a73c3..400e97cefe2 100644
--- a/Include/import.h
+++ b/Include/import.h
@@ -8,25 +8,52 @@ extern "C" {
#endif
PyAPI_FUNC(long) PyImport_GetMagicNumber(void);
-PyAPI_FUNC(PyObject *) PyImport_ExecCodeModule(char *name, PyObject *co);
+PyAPI_FUNC(const char *) PyImport_GetMagicTag(void);
+PyAPI_FUNC(PyObject *) PyImport_ExecCodeModule(
+ char *name, /* UTF-8 encoded string */
+ PyObject *co
+ );
PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleEx(
- char *name, PyObject *co, char *pathname);
+ char *name, /* UTF-8 encoded string */
+ PyObject *co,
+ char *pathname /* decoded from the filesystem encoding */
+ );
+PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleWithPathnames(
+ char *name, /* UTF-8 encoded string */
+ PyObject *co,
+ char *pathname, /* decoded from the filesystem encoding */
+ char *cpathname /* decoded from the filesystem encoding */
+ );
PyAPI_FUNC(PyObject *) PyImport_GetModuleDict(void);
-PyAPI_FUNC(PyObject *) PyImport_AddModule(const char *name);
-PyAPI_FUNC(PyObject *) PyImport_ImportModule(const char *name);
-PyAPI_FUNC(PyObject *) PyImport_ImportModuleNoBlock(const char *);
-PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel(char *name,
- PyObject *globals, PyObject *locals, PyObject *fromlist, int level);
+PyAPI_FUNC(PyObject *) PyImport_AddModule(
+ const char *name /* UTF-8 encoded string */
+ );
+PyAPI_FUNC(PyObject *) PyImport_ImportModule(
+ const char *name /* UTF-8 encoded string */
+ );
+PyAPI_FUNC(PyObject *) PyImport_ImportModuleNoBlock(
+ const char *name /* UTF-8 encoded string */
+ );
+PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel(
+ char *name, /* UTF-8 encoded string */
+ PyObject *globals,
+ PyObject *locals,
+ PyObject *fromlist,
+ int level
+ );
#define PyImport_ImportModuleEx(n, g, l, f) \
- PyImport_ImportModuleLevel(n, g, l, f, -1)
+ PyImport_ImportModuleLevel(n, g, l, f, -1)
PyAPI_FUNC(PyObject *) PyImport_GetImporter(PyObject *path);
PyAPI_FUNC(PyObject *) PyImport_Import(PyObject *name);
PyAPI_FUNC(PyObject *) PyImport_ReloadModule(PyObject *m);
PyAPI_FUNC(void) PyImport_Cleanup(void);
-PyAPI_FUNC(int) PyImport_ImportFrozenModule(char *);
+PyAPI_FUNC(int) PyImport_ImportFrozenModule(
+ char *name /* UTF-8 encoded string */
+ );
+#ifndef Py_LIMITED_API
#ifdef WITH_THREAD
PyAPI_FUNC(void) _PyImport_AcquireLock(void);
PyAPI_FUNC(int) _PyImport_ReleaseLock(void);
@@ -35,27 +62,36 @@ PyAPI_FUNC(int) _PyImport_ReleaseLock(void);
#define _PyImport_ReleaseLock() 1
#endif
-PyAPI_FUNC(struct filedescr *) _PyImport_FindModule(
- const char *, PyObject *, char *, size_t, FILE **, PyObject **);
-PyAPI_FUNC(int) _PyImport_IsScript(struct filedescr *);
PyAPI_FUNC(void) _PyImport_ReInitLock(void);
-PyAPI_FUNC(PyObject *)_PyImport_FindExtension(char *, char *);
-PyAPI_FUNC(PyObject *)_PyImport_FixupExtension(char *, char *);
+PyAPI_FUNC(PyObject *)_PyImport_FindBuiltin(
+ char *name /* UTF-8 encoded string */
+ );
+PyAPI_FUNC(PyObject *)_PyImport_FindExtensionUnicode(char *, PyObject *);
+PyAPI_FUNC(int)_PyImport_FixupBuiltin(
+ PyObject *mod,
+ char *name /* UTF-8 encoded string */
+ );
+PyAPI_FUNC(int)_PyImport_FixupExtensionUnicode(PyObject*, char *, PyObject *);
struct _inittab {
char *name;
- void (*initfunc)(void);
+ PyObject* (*initfunc)(void);
};
+PyAPI_DATA(struct _inittab *) PyImport_Inittab;
+PyAPI_FUNC(int) PyImport_ExtendInittab(struct _inittab *newtab);
+#endif /* Py_LIMITED_API */
PyAPI_DATA(PyTypeObject) PyNullImporter_Type;
-PyAPI_DATA(struct _inittab *) PyImport_Inittab;
-PyAPI_FUNC(int) PyImport_AppendInittab(const char *name, void (*initfunc)(void));
-PyAPI_FUNC(int) PyImport_ExtendInittab(struct _inittab *newtab);
+PyAPI_FUNC(int) PyImport_AppendInittab(
+ const char *name, /* ASCII encoded string */
+ PyObject* (*initfunc)(void)
+ );
+#ifndef Py_LIMITED_API
struct _frozen {
- char *name;
+ char *name; /* ASCII encoded string */
unsigned char *code;
int size;
};
@@ -64,6 +100,7 @@ struct _frozen {
collection of frozen modules: */
PyAPI_DATA(struct _frozen *) PyImport_FrozenModules;
+#endif
#ifdef __cplusplus
}
diff --git a/Include/intobject.h b/Include/intobject.h
deleted file mode 100644
index 78746a63484..00000000000
--- a/Include/intobject.h
+++ /dev/null
@@ -1,80 +0,0 @@
-
-/* Integer object interface */
-
-/*
-PyIntObject represents a (long) integer. This is an immutable object;
-an integer cannot change its value after creation.
-
-There are functions to create new integer objects, to test an object
-for integer-ness, and to get the integer value. The latter functions
-returns -1 and sets errno to EBADF if the object is not an PyIntObject.
-None of the functions should be applied to nil objects.
-
-The type PyIntObject is (unfortunately) exposed here so we can declare
-_Py_TrueStruct and _Py_ZeroStruct in boolobject.h; don't use this.
-*/
-
-#ifndef Py_INTOBJECT_H
-#define Py_INTOBJECT_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
- PyObject_HEAD
- long ob_ival;
-} PyIntObject;
-
-PyAPI_DATA(PyTypeObject) PyInt_Type;
-
-#define PyInt_Check(op) \
- PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_INT_SUBCLASS)
-#define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type)
-
-PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);
-#ifdef Py_USING_UNICODE
-PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
-#endif
-PyAPI_FUNC(PyObject *) PyInt_FromLong(long);
-PyAPI_FUNC(PyObject *) PyInt_FromSize_t(size_t);
-PyAPI_FUNC(PyObject *) PyInt_FromSsize_t(Py_ssize_t);
-PyAPI_FUNC(long) PyInt_AsLong(PyObject *);
-PyAPI_FUNC(Py_ssize_t) PyInt_AsSsize_t(PyObject *);
-PyAPI_FUNC(unsigned long) PyInt_AsUnsignedLongMask(PyObject *);
-#ifdef HAVE_LONG_LONG
-PyAPI_FUNC(unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *);
-#endif
-
-PyAPI_FUNC(long) PyInt_GetMax(void);
-
-/* Macro, trading safety for speed */
-#define PyInt_AS_LONG(op) (((PyIntObject *)(op))->ob_ival)
-
-/* These aren't really part of the Int object, but they're handy; the protos
- * are necessary for systems that need the magic of PyAPI_FUNC and that want
- * to have stropmodule as a dynamically loaded module instead of building it
- * into the main Python shared library/DLL. Guido thinks I'm weird for
- * building it this way. :-) [cjh]
- */
-PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int);
-PyAPI_FUNC(long) PyOS_strtol(char *, char **, int);
-
-/* free list api */
-PyAPI_FUNC(int) PyInt_ClearFreeList(void);
-
-/* Convert an integer to the given base. Returns a string.
- If base is 2, 8 or 16, add the proper prefix '0b', '0o' or '0x'.
- If newstyle is zero, then use the pre-2.6 behavior of octal having
- a leading "0" */
-PyAPI_FUNC(PyObject*) _PyInt_Format(PyIntObject* v, int base, int newstyle);
-
-/* Format the object based on the format_spec, as defined in PEP 3101
- (Advanced String Formatting). */
-PyAPI_FUNC(PyObject *) _PyInt_FormatAdvanced(PyObject *obj,
- char *format_spec,
- Py_ssize_t format_spec_len);
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* !Py_INTOBJECT_H */
diff --git a/Include/iterobject.h b/Include/iterobject.h
index 4bd19c29098..f61726f1f7f 100644
--- a/Include/iterobject.h
+++ b/Include/iterobject.h
@@ -6,16 +6,18 @@ extern "C" {
#endif
PyAPI_DATA(PyTypeObject) PySeqIter_Type;
+PyAPI_DATA(PyTypeObject) PyCallIter_Type;
+PyAPI_DATA(PyTypeObject) PyCmpWrapper_Type;
#define PySeqIter_Check(op) (Py_TYPE(op) == &PySeqIter_Type)
PyAPI_FUNC(PyObject *) PySeqIter_New(PyObject *);
-PyAPI_DATA(PyTypeObject) PyCallIter_Type;
#define PyCallIter_Check(op) (Py_TYPE(op) == &PyCallIter_Type)
PyAPI_FUNC(PyObject *) PyCallIter_New(PyObject *, PyObject *);
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/listobject.h b/Include/listobject.h
index c4458733b9c..949b1a3e319 100644
--- a/Include/listobject.h
+++ b/Include/listobject.h
@@ -19,6 +19,7 @@ returned item's reference count.
extern "C" {
#endif
+#ifndef Py_LIMITED_API
typedef struct {
PyObject_VAR_HEAD
/* Vector of pointers to list elements. list[0] is ob_item[0], etc. */
@@ -37,8 +38,12 @@ typedef struct {
*/
Py_ssize_t allocated;
} PyListObject;
+#endif
PyAPI_DATA(PyTypeObject) PyList_Type;
+PyAPI_DATA(PyTypeObject) PyListIter_Type;
+PyAPI_DATA(PyTypeObject) PyListRevIter_Type;
+PyAPI_DATA(PyTypeObject) PySortWrapper_Type;
#define PyList_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
@@ -55,12 +60,16 @@ PyAPI_FUNC(int) PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
PyAPI_FUNC(int) PyList_Sort(PyObject *);
PyAPI_FUNC(int) PyList_Reverse(PyObject *);
PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *);
+#endif
/* Macro, trading safety for speed */
+#ifndef Py_LIMITED_API
#define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
#define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
#define PyList_GET_SIZE(op) Py_SIZE(op)
+#endif
#ifdef __cplusplus
}
diff --git a/Include/longintrepr.h b/Include/longintrepr.h
index 6425c30f39b..b94f7b2e2c5 100644
--- a/Include/longintrepr.h
+++ b/Include/longintrepr.h
@@ -1,3 +1,4 @@
+#ifndef Py_LIMITED_API
#ifndef Py_LONGINTREPR_H
#define Py_LONGINTREPR_H
#ifdef __cplusplus
@@ -33,6 +34,9 @@ extern "C" {
- the marshal code currently expects that PyLong_SHIFT is a multiple of 15
+ - NSMALLNEGINTS and NSMALLPOSINTS should be small enough to fit in a single
+ digit; with the current values this forces PyLong_SHIFT >= 9
+
The values 15 and 30 should fit all of the above requirements, on any
platform.
*/
@@ -63,11 +67,6 @@ typedef long stwodigits; /* signed variant of twodigits */
#define PyLong_BASE ((digit)1 << PyLong_SHIFT)
#define PyLong_MASK ((digit)(PyLong_BASE - 1))
-/* b/w compatibility with Python 2.5 */
-#define SHIFT PyLong_SHIFT
-#define BASE PyLong_BASE
-#define MASK PyLong_MASK
-
#if PyLong_SHIFT % 5 != 0
#error "longobject.c requires that PyLong_SHIFT be divisible by 5"
#endif
@@ -101,3 +100,4 @@ PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src);
}
#endif
#endif /* !Py_LONGINTREPR_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/longobject.h b/Include/longobject.h
index 2b4046128ab..c09565a1179 100644
--- a/Include/longobject.h
+++ b/Include/longobject.h
@@ -17,21 +17,42 @@ PyAPI_DATA(PyTypeObject) PyLong_Type;
PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long);
-PyAPI_FUNC(PyObject *) PyLong_FromDouble(double);
PyAPI_FUNC(PyObject *) PyLong_FromSize_t(size_t);
PyAPI_FUNC(PyObject *) PyLong_FromSsize_t(Py_ssize_t);
+PyAPI_FUNC(PyObject *) PyLong_FromDouble(double);
PyAPI_FUNC(long) PyLong_AsLong(PyObject *);
PyAPI_FUNC(long) PyLong_AsLongAndOverflow(PyObject *, int *);
+PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *);
+PyAPI_FUNC(size_t) PyLong_AsSize_t(PyObject *);
PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);
PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
-PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *);
PyAPI_FUNC(PyObject *) PyLong_GetInfo(void);
-/* For use by intobject.c only */
-#define _PyLong_AsSsize_t PyLong_AsSsize_t
-#define _PyLong_FromSize_t PyLong_FromSize_t
-#define _PyLong_FromSsize_t PyLong_FromSsize_t
-PyAPI_DATA(int) _PyLong_DigitValue[256];
+/* It may be useful in the future. I've added it in the PyInt -> PyLong
+ cleanup to keep the extra information. [CH] */
+#define PyLong_AS_LONG(op) PyLong_AsLong(op)
+
+/* Issue #1983: pid_t can be longer than a C long on some systems */
+#if !defined(SIZEOF_PID_T) || SIZEOF_PID_T == SIZEOF_INT
+#define _Py_PARSE_PID "i"
+#define PyLong_FromPid PyLong_FromLong
+#define PyLong_AsPid PyLong_AsLong
+#elif SIZEOF_PID_T == SIZEOF_LONG
+#define _Py_PARSE_PID "l"
+#define PyLong_FromPid PyLong_FromLong
+#define PyLong_AsPid PyLong_AsLong
+#elif defined(SIZEOF_LONG_LONG) && SIZEOF_PID_T == SIZEOF_LONG_LONG
+#define _Py_PARSE_PID "L"
+#define PyLong_FromPid PyLong_FromLongLong
+#define PyLong_AsPid PyLong_AsLongLong
+#else
+#error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or sizeof(long long)"
+#endif /* SIZEOF_PID_T */
+
+/* Used by Python/mystrtoul.c. */
+#ifndef Py_LIMITED_API
+PyAPI_DATA(unsigned char) _PyLong_DigitValue[256];
+#endif
/* _PyLong_Frexp returns a double x and an exponent e such that the
true value is approximately equal to x * 2**e. e is >= 0. x is
@@ -39,7 +60,9 @@ PyAPI_DATA(int) _PyLong_DigitValue[256];
zeroes); otherwise, 0.5 <= abs(x) < 1.0. On overflow, which is
possible if the number of bits doesn't fit into a Py_ssize_t, sets
OverflowError and returns -1.0 for x, 0 for e. */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(double) _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e);
+#endif
PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
@@ -55,10 +78,11 @@ PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLongAndOverflow(PyObject *, int *);
#endif /* HAVE_LONG_LONG */
PyAPI_FUNC(PyObject *) PyLong_FromString(char *, char **, int);
-#ifdef Py_USING_UNICODE
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
#endif
+#ifndef Py_LIMITED_API
/* _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
v must not be NULL, and must be a normalized long.
There are no error cases.
@@ -75,6 +99,14 @@ PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);
*/
PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v);
+/* _PyLong_DivmodNear. Given integers a and b, compute the nearest
+ integer q to the exact quotient a / b, rounding to the nearest even integer
+ in the case of a tie. Return (q, r), where r = a - q*b. The remainder r
+ will satisfy abs(r) <= abs(b)/2, with equality possible only if q is
+ even.
+*/
+PyAPI_FUNC(PyObject *) _PyLong_DivmodNear(PyObject *, PyObject *);
+
/* _PyLong_FromByteArray: View the n unsigned bytes as a binary integer in
base 256, and return a Python long with the same numeric value.
If n is 0, the integer is 0. Else:
@@ -115,18 +147,23 @@ PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v,
unsigned char* bytes, size_t n,
int little_endian, int is_signed);
+
/* _PyLong_Format: Convert the long to a string object with given base,
- appending a base prefix of 0[box] if base is 2, 8 or 16.
- Add a trailing "L" if addL is non-zero.
- If newstyle is zero, then use the pre-2.6 behavior of octal having
- a leading "0", instead of the prefix "0o" */
-PyAPI_FUNC(PyObject *) _PyLong_Format(PyObject *aa, int base, int addL, int newstyle);
+ appending a base prefix of 0[box] if base is 2, 8 or 16. */
+PyAPI_FUNC(PyObject *) _PyLong_Format(PyObject *aa, int base);
/* Format the object based on the format_spec, as defined in PEP 3101
(Advanced String Formatting). */
PyAPI_FUNC(PyObject *) _PyLong_FormatAdvanced(PyObject *obj,
- char *format_spec,
+ Py_UNICODE *format_spec,
Py_ssize_t format_spec_len);
+#endif /* Py_LIMITED_API */
+
+/* These aren't really part of the long object, but they're handy. The
+ functions are in Python/mystrtoul.c.
+ */
+PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int);
+PyAPI_FUNC(long) PyOS_strtol(char *, char **, int);
#ifdef __cplusplus
}
diff --git a/Include/marshal.h b/Include/marshal.h
index 411fdca3676..e96d062b18b 100644
--- a/Include/marshal.h
+++ b/Include/marshal.h
@@ -13,10 +13,12 @@ PyAPI_FUNC(void) PyMarshal_WriteLongToFile(long, FILE *, int);
PyAPI_FUNC(void) PyMarshal_WriteObjectToFile(PyObject *, FILE *, int);
PyAPI_FUNC(PyObject *) PyMarshal_WriteObjectToString(PyObject *, int);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(long) PyMarshal_ReadLongFromFile(FILE *);
PyAPI_FUNC(int) PyMarshal_ReadShortFromFile(FILE *);
PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromFile(FILE *);
PyAPI_FUNC(PyObject *) PyMarshal_ReadLastObjectFromFile(FILE *);
+#endif
PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
#ifdef __cplusplus
diff --git a/Include/memoryobject.h b/Include/memoryobject.h
index bf0b621ab92..62ecbd64492 100644
--- a/Include/memoryobject.h
+++ b/Include/memoryobject.h
@@ -10,10 +10,12 @@ PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
#define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type)
+#ifndef Py_LIMITED_API
/* Get a pointer to the underlying Py_buffer of a memoryview object. */
#define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view)
/* Get a pointer to the PyObject from which originates a memoryview object. */
#define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj)
+#endif
PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base,
@@ -53,20 +55,22 @@ PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base,
PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info);
/* create new if bufptr is NULL
will be a new bytesobject in base */
+#endif
/* The struct is declared here so that macros can work, but it shouldn't
be considered public. Don't access those fields directly, use the macros
and functions instead! */
+#ifndef Py_LIMITED_API
typedef struct {
PyObject_HEAD
- PyObject *base;
Py_buffer view;
} PyMemoryViewObject;
-
+#endif
#ifdef __cplusplus
}
diff --git a/Include/methodobject.h b/Include/methodobject.h
index 6e160b63900..7e67c0bf9aa 100644
--- a/Include/methodobject.h
+++ b/Include/methodobject.h
@@ -26,12 +26,14 @@ PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
/* Macros for direct access to these values. Type checks are *not*
done, so use with care. */
+#ifndef Py_LIMITED_API
#define PyCFunction_GET_FUNCTION(func) \
(((PyCFunctionObject *)func) -> m_ml -> ml_meth)
#define PyCFunction_GET_SELF(func) \
(((PyCFunctionObject *)func) -> m_self)
#define PyCFunction_GET_FLAGS(func) \
(((PyCFunctionObject *)func) -> m_ml -> ml_flags)
+#endif
PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
struct PyMethodDef {
@@ -43,14 +45,12 @@ struct PyMethodDef {
};
typedef struct PyMethodDef PyMethodDef;
-PyAPI_FUNC(PyObject *) Py_FindMethod(PyMethodDef[], PyObject *, const char *);
-
#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
PyObject *);
/* Flag passed to newmethodobject */
-#define METH_OLDARGS 0x0000
+/* #define METH_OLDARGS 0x0000 -- unsupported now */
#define METH_VARARGS 0x0001
#define METH_KEYWORDS 0x0002
/* METH_NOARGS and METH_O must not be combined with the flags above. */
@@ -63,27 +63,21 @@ PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
#define METH_CLASS 0x0010
#define METH_STATIC 0x0020
-/* METH_COEXIST allows a method to be entered eventhough a slot has
+/* METH_COEXIST allows a method to be entered even though a slot has
already filled the entry. When defined, the flag allows a separate
method, "__contains__" for example, to coexist with a defined
slot like sq_contains. */
#define METH_COEXIST 0x0040
-typedef struct PyMethodChain {
- PyMethodDef *methods; /* Methods of this type */
- struct PyMethodChain *link; /* NULL or base type */
-} PyMethodChain;
-
-PyAPI_FUNC(PyObject *) Py_FindMethodInChain(PyMethodChain *, PyObject *,
- const char *);
-
+#ifndef Py_LIMITED_API
typedef struct {
PyObject_HEAD
PyMethodDef *m_ml; /* Description of the C function to call */
PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */
PyObject *m_module; /* The __module__ attribute, can be anything */
} PyCFunctionObject;
+#endif
PyAPI_FUNC(int) PyCFunction_ClearFreeList(void);
diff --git a/Include/modsupport.h b/Include/modsupport.h
index d4dddef0b59..bf6478f4c2c 100644
--- a/Include/modsupport.h
+++ b/Include/modsupport.h
@@ -27,10 +27,13 @@ PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);
PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...) Py_FORMAT_PARSETUPLE(PyArg_ParseTuple, 2, 3);
PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
const char *, char **, ...);
+PyAPI_FUNC(int) PyArg_ValidateKeywordArguments(PyObject *);
PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, const char *, Py_ssize_t, Py_ssize_t, ...);
PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...);
PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kw);
+#endif
PyAPI_FUNC(int) PyArg_VaParse(PyObject *, const char *, va_list);
PyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,
@@ -43,6 +46,8 @@ PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char
#define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
#define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant(m, #c, c)
+#define Py_CLEANUP_SUPPORTED 0x20000
+
#define PYTHON_API_VERSION 1013
#define PYTHON_API_STRING "1013"
/* The API version is maintained (independently from the Python version)
@@ -89,44 +94,33 @@ PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char
9-Jan-1995 GvR Initial version (incompatible with older API)
*/
-#ifdef MS_WINDOWS
-/* Special defines for Windows versions used to live here. Things
- have changed, and the "Version" is now in a global string variable.
- Reason for this is that this for easier branding of a "custom DLL"
- without actually needing a recompile. */
-#endif /* MS_WINDOWS */
-
-#if SIZEOF_SIZE_T != SIZEOF_INT
-/* On a 64-bit system, rename the Py_InitModule4 so that 2.4
- modules cannot get loaded into a 2.5 interpreter */
-#define Py_InitModule4 Py_InitModule4_64
-#endif
+/* The PYTHON_ABI_VERSION is introduced in PEP 384. For the lifetime of
+ Python 3, it will stay at the value of 3; changes to the limited API
+ must be performed in a strictly backwards-compatible manner. */
+#define PYTHON_ABI_VERSION 3
+#define PYTHON_ABI_STRING "3"
#ifdef Py_TRACE_REFS
- /* When we are tracing reference counts, rename Py_InitModule4 so
+ /* When we are tracing reference counts, rename PyModule_Create2 so
modules compiled with incompatible settings will generate a
link-time error. */
- #if SIZEOF_SIZE_T != SIZEOF_INT
- #undef Py_InitModule4
- #define Py_InitModule4 Py_InitModule4TraceRefs_64
- #else
- #define Py_InitModule4 Py_InitModule4TraceRefs
- #endif
+ #define PyModule_Create2 PyModule_Create2TraceRefs
#endif
-PyAPI_FUNC(PyObject *) Py_InitModule4(const char *name, PyMethodDef *methods,
- const char *doc, PyObject *self,
- int apiver);
-
-#define Py_InitModule(name, methods) \
- Py_InitModule4(name, methods, (char *)NULL, (PyObject *)NULL, \
- PYTHON_API_VERSION)
+PyAPI_FUNC(PyObject *) PyModule_Create2(struct PyModuleDef*,
+ int apiver);
-#define Py_InitModule3(name, methods, doc) \
- Py_InitModule4(name, methods, doc, (PyObject *)NULL, \
- PYTHON_API_VERSION)
+#ifdef Py_LIMITED_API
+#define PyModule_Create(module) \
+ PyModule_Create2(module, PYTHON_ABI_VERSION)
+#else
+#define PyModule_Create(module) \
+ PyModule_Create2(module, PYTHON_API_VERSION)
+#endif
+#ifndef Py_LIMITED_API
PyAPI_DATA(char *) _Py_PackageContext;
+#endif
#ifdef __cplusplus
}
diff --git a/Include/moduleobject.h b/Include/moduleobject.h
index b387f5bfd49..7b2bf1c144e 100644
--- a/Include/moduleobject.h
+++ b/Include/moduleobject.h
@@ -12,11 +12,45 @@ PyAPI_DATA(PyTypeObject) PyModule_Type;
#define PyModule_Check(op) PyObject_TypeCheck(op, &PyModule_Type)
#define PyModule_CheckExact(op) (Py_TYPE(op) == &PyModule_Type)
-PyAPI_FUNC(PyObject *) PyModule_New(const char *);
+PyAPI_FUNC(PyObject *) PyModule_New(
+ const char *name /* UTF-8 encoded string */
+ );
PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *);
-PyAPI_FUNC(char *) PyModule_GetName(PyObject *);
-PyAPI_FUNC(char *) PyModule_GetFilename(PyObject *);
+PyAPI_FUNC(const char *) PyModule_GetName(PyObject *);
+PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *);
+PyAPI_FUNC(PyObject *) PyModule_GetFilenameObject(PyObject *);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(void) _PyModule_Clear(PyObject *);
+#endif
+PyAPI_FUNC(struct PyModuleDef*) PyModule_GetDef(PyObject*);
+PyAPI_FUNC(void*) PyModule_GetState(PyObject*);
+
+typedef struct PyModuleDef_Base {
+ PyObject_HEAD
+ PyObject* (*m_init)(void);
+ Py_ssize_t m_index;
+ PyObject* m_copy;
+} PyModuleDef_Base;
+
+#define PyModuleDef_HEAD_INIT { \
+ PyObject_HEAD_INIT(NULL) \
+ NULL, /* m_init */ \
+ 0, /* m_index */ \
+ NULL, /* m_copy */ \
+ }
+
+typedef struct PyModuleDef{
+ PyModuleDef_Base m_base;
+ const char* m_name;
+ const char* m_doc;
+ Py_ssize_t m_size;
+ PyMethodDef *m_methods;
+ inquiry m_reload;
+ traverseproc m_traverse;
+ inquiry m_clear;
+ freefunc m_free;
+}PyModuleDef;
+
#ifdef __cplusplus
}
diff --git a/Include/object.h b/Include/object.h
index 1ba33eb6c1c..6120ab813c4 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -61,6 +61,10 @@ whose size is determined when the object is allocated.
#define Py_REF_DEBUG
#endif
+#if defined(Py_LIMITED_API) && defined(Py_REF_DEBUG)
+#error Py_LIMITED_API is incompatible with Py_DEBUG, Py_TRACE_REFS, and Py_REF_DEBUG
+#endif
+
#ifdef Py_TRACE_REFS
/* Define pointers to support a doubly-linked list of all live heap objects. */
#define _PyObject_HEAD_EXTRA \
@@ -75,17 +79,14 @@ whose size is determined when the object is allocated.
#endif
/* PyObject_HEAD defines the initial segment of every PyObject. */
-#define PyObject_HEAD \
- _PyObject_HEAD_EXTRA \
- Py_ssize_t ob_refcnt; \
- struct _typeobject *ob_type;
+#define PyObject_HEAD PyObject ob_base;
#define PyObject_HEAD_INIT(type) \
- _PyObject_EXTRA_INIT \
- 1, type,
+ { _PyObject_EXTRA_INIT \
+ 1, type },
#define PyVarObject_HEAD_INIT(type, size) \
- PyObject_HEAD_INIT(type) size,
+ { PyObject_HEAD_INIT(type) size },
/* PyObject_VAR_HEAD defines the initial segment of all variable-size
* container objects. These end with a declaration of an array with 1
@@ -93,9 +94,7 @@ whose size is determined when the object is allocated.
* has room for ob_size elements. Note that ob_size is an element count,
* not necessarily a byte count.
*/
-#define PyObject_VAR_HEAD \
- PyObject_HEAD \
- Py_ssize_t ob_size; /* Number of items in variable part */
+#define PyObject_VAR_HEAD PyVarObject ob_base;
#define Py_INVALID_SIZE (Py_ssize_t)-1
/* Nothing is actually declared to be a PyObject, but every pointer to
@@ -104,11 +103,14 @@ whose size is determined when the object is allocated.
* in addition, be cast to PyVarObject*.
*/
typedef struct _object {
- PyObject_HEAD
+ _PyObject_HEAD_EXTRA
+ Py_ssize_t ob_refcnt;
+ struct _typeobject *ob_type;
} PyObject;
typedef struct {
- PyObject_VAR_HEAD
+ PyObject ob_base;
+ Py_ssize_t ob_size; /* Number of items in variable part */
} PyVarObject;
#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
@@ -135,32 +137,14 @@ typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
typedef int (*inquiry)(PyObject *);
typedef Py_ssize_t (*lenfunc)(PyObject *);
-typedef int (*coercion)(PyObject **, PyObject **);
-typedef PyObject *(*intargfunc)(PyObject *, int) Py_DEPRECATED(2.5);
-typedef PyObject *(*intintargfunc)(PyObject *, int, int) Py_DEPRECATED(2.5);
typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
-typedef int(*intobjargproc)(PyObject *, int, PyObject *);
-typedef int(*intintobjargproc)(PyObject *, int, int, PyObject *);
typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
-
-
-/* int-based buffer interface */
-typedef int (*getreadbufferproc)(PyObject *, int, void **);
-typedef int (*getwritebufferproc)(PyObject *, int, void **);
-typedef int (*getsegcountproc)(PyObject *, int *);
-typedef int (*getcharbufferproc)(PyObject *, int, char **);
-/* ssize_t-based buffer interface */
-typedef Py_ssize_t (*readbufferproc)(PyObject *, Py_ssize_t, void **);
-typedef Py_ssize_t (*writebufferproc)(PyObject *, Py_ssize_t, void **);
-typedef Py_ssize_t (*segcountproc)(PyObject *, Py_ssize_t *);
-typedef Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, char **);
-
-
-/* Py3k buffer interface */
+#ifndef Py_LIMITED_API
+/* buffer interface */
typedef struct bufferinfo {
void *buf;
PyObject *obj; /* owned reference */
@@ -209,50 +193,43 @@ typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
#define PyBUF_READ 0x100
#define PyBUF_WRITE 0x200
-#define PyBUF_SHADOW 0x400
-/* end Py3k buffer interface */
+
+/* End buffer interface */
+#endif /* Py_LIMITED_API */
typedef int (*objobjproc)(PyObject *, PyObject *);
typedef int (*visitproc)(PyObject *, void *);
typedef int (*traverseproc)(PyObject *, visitproc, void *);
+#ifndef Py_LIMITED_API
typedef struct {
- /* For numbers without flag bit Py_TPFLAGS_CHECKTYPES set, all
- arguments are guaranteed to be of the object's type (modulo
- coercion hacks -- i.e. if the type's coercion function
- returns other types, then these are allowed as well). Numbers that
- have the Py_TPFLAGS_CHECKTYPES flag bit set should check *both*
+ /* Number implementations must check *both*
arguments for proper type and implement the necessary conversions
in the slot functions themselves. */
binaryfunc nb_add;
binaryfunc nb_subtract;
binaryfunc nb_multiply;
- binaryfunc nb_divide;
binaryfunc nb_remainder;
binaryfunc nb_divmod;
ternaryfunc nb_power;
unaryfunc nb_negative;
unaryfunc nb_positive;
unaryfunc nb_absolute;
- inquiry nb_nonzero;
+ inquiry nb_bool;
unaryfunc nb_invert;
binaryfunc nb_lshift;
binaryfunc nb_rshift;
binaryfunc nb_and;
binaryfunc nb_xor;
binaryfunc nb_or;
- coercion nb_coerce;
unaryfunc nb_int;
- unaryfunc nb_long;
+ void *nb_reserved; /* the slot formerly known as nb_long */
unaryfunc nb_float;
- unaryfunc nb_oct;
- unaryfunc nb_hex;
- /* Added in release 2.0 */
+
binaryfunc nb_inplace_add;
binaryfunc nb_inplace_subtract;
binaryfunc nb_inplace_multiply;
- binaryfunc nb_inplace_divide;
binaryfunc nb_inplace_remainder;
ternaryfunc nb_inplace_power;
binaryfunc nb_inplace_lshift;
@@ -261,14 +238,11 @@ typedef struct {
binaryfunc nb_inplace_xor;
binaryfunc nb_inplace_or;
- /* Added in release 2.2 */
- /* The following require the Py_TPFLAGS_HAVE_CLASS flag */
binaryfunc nb_floor_divide;
binaryfunc nb_true_divide;
binaryfunc nb_inplace_floor_divide;
binaryfunc nb_inplace_true_divide;
- /* Added in release 2.5 */
unaryfunc nb_index;
} PyNumberMethods;
@@ -277,11 +251,11 @@ typedef struct {
binaryfunc sq_concat;
ssizeargfunc sq_repeat;
ssizeargfunc sq_item;
- ssizessizeargfunc sq_slice;
+ void *was_sq_slice;
ssizeobjargproc sq_ass_item;
- ssizessizeobjargproc sq_ass_slice;
+ void *was_sq_ass_slice;
objobjproc sq_contains;
- /* Added in release 2.0 */
+
binaryfunc sq_inplace_concat;
ssizeargfunc sq_inplace_repeat;
} PySequenceMethods;
@@ -292,26 +266,28 @@ typedef struct {
objobjargproc mp_ass_subscript;
} PyMappingMethods;
+
typedef struct {
- readbufferproc bf_getreadbuffer;
- writebufferproc bf_getwritebuffer;
- segcountproc bf_getsegcount;
- charbufferproc bf_getcharbuffer;
- getbufferproc bf_getbuffer;
- releasebufferproc bf_releasebuffer;
+ getbufferproc bf_getbuffer;
+ releasebufferproc bf_releasebuffer;
} PyBufferProcs;
-
+#endif /* Py_LIMITED_API */
typedef void (*freefunc)(void *);
typedef void (*destructor)(PyObject *);
+#ifndef Py_LIMITED_API
+/* We can't provide a full compile-time check that limited-API
+ users won't implement tp_print. However, not defining printfunc
+ and making tp_print of a different function pointer type
+ should at least cause a warning in most cases. */
typedef int (*printfunc)(PyObject *, FILE *, int);
+#endif
typedef PyObject *(*getattrfunc)(PyObject *, char *);
typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
-typedef int (*cmpfunc)(PyObject *, PyObject *);
typedef PyObject *(*reprfunc)(PyObject *);
-typedef long (*hashfunc)(PyObject *);
+typedef Py_hash_t (*hashfunc)(PyObject *);
typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
typedef PyObject *(*getiterfunc) (PyObject *);
typedef PyObject *(*iternextfunc) (PyObject *);
@@ -321,6 +297,9 @@ typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);
+#ifdef Py_LIMITED_API
+typedef struct _typeobject PyTypeObject; /* opaque */
+#else
typedef struct _typeobject {
PyObject_VAR_HEAD
const char *tp_name; /* For printing, in format "<module>.<name>" */
@@ -332,7 +311,7 @@ typedef struct _typeobject {
printfunc tp_print;
getattrfunc tp_getattr;
setattrfunc tp_setattr;
- cmpfunc tp_compare;
+ void *tp_reserved; /* formerly known as tp_compare */
reprfunc tp_repr;
/* Method suites for standard classes */
@@ -371,7 +350,6 @@ typedef struct _typeobject {
/* weak reference enabler */
Py_ssize_t tp_weaklistoffset;
- /* Added in release 2.2 */
/* Iterators */
getiterfunc tp_iter;
iternextfunc tp_iternext;
@@ -409,8 +387,24 @@ typedef struct _typeobject {
struct _typeobject *tp_next;
#endif
} PyTypeObject;
+#endif
+
+typedef struct{
+ int slot; /* slot id, see below */
+ void *pfunc; /* function pointer */
+} PyType_Slot;
+typedef struct{
+ const char* name;
+ int basicsize;
+ int itemsize;
+ int flags;
+ PyType_Slot *slots; /* terminated by slot==0. */
+} PyType_Spec;
+PyAPI_FUNC(PyObject*) PyType_FromSpec(PyType_Spec*);
+
+#ifndef Py_LIMITED_API
/* The *real* layout of a type object when allocated on the heap */
typedef struct _heaptypeobject {
/* Note: there's a dependency on the order of these members
@@ -431,7 +425,7 @@ typedef struct _heaptypeobject {
/* access macro to the members which are floating "behind" the object */
#define PyHeapType_GET_MEMBERS(etype) \
((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))
-
+#endif
/* Generic type check */
PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
@@ -442,6 +436,8 @@ PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
+PyAPI_FUNC(long) PyType_GetFlags(PyTypeObject*);
+
#define PyType_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
#define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type)
@@ -450,22 +446,24 @@ PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
PyObject *, PyObject *);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, char *, PyObject **);
+PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
+#endif
PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
/* Generic operations on objects */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
+PyAPI_FUNC(void) _Py_BreakPoint(void);
PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
+#endif
PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *);
-PyAPI_FUNC(PyObject *) _PyObject_Str(PyObject *);
PyAPI_FUNC(PyObject *) PyObject_Str(PyObject *);
-#define PyObject_Bytes PyObject_Str
-#ifdef Py_USING_UNICODE
-PyAPI_FUNC(PyObject *) PyObject_Unicode(PyObject *);
-#endif
-PyAPI_FUNC(int) PyObject_Compare(PyObject *, PyObject *);
+PyAPI_FUNC(PyObject *) PyObject_ASCII(PyObject *);
+PyAPI_FUNC(PyObject *) PyObject_Bytes(PyObject *);
PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *);
@@ -474,24 +472,24 @@ PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *);
PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
+#endif
PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *);
+#endif
PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *,
PyObject *, PyObject *);
-PyAPI_FUNC(long) PyObject_Hash(PyObject *);
-PyAPI_FUNC(long) PyObject_HashNotImplemented(PyObject *);
+PyAPI_FUNC(Py_hash_t) PyObject_Hash(PyObject *);
+PyAPI_FUNC(Py_hash_t) PyObject_HashNotImplemented(PyObject *);
PyAPI_FUNC(int) PyObject_IsTrue(PyObject *);
PyAPI_FUNC(int) PyObject_Not(PyObject *);
PyAPI_FUNC(int) PyCallable_Check(PyObject *);
-PyAPI_FUNC(int) PyNumber_Coerce(PyObject **, PyObject **);
-PyAPI_FUNC(int) PyNumber_CoerceEx(PyObject **, PyObject **);
PyAPI_FUNC(void) PyObject_ClearWeakRefs(PyObject *);
-/* A slot function whose address we need to compare */
-extern int _PyObject_SlotCompare(PyObject *, PyObject *);
/* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes
dict as the last parameter. */
PyAPI_FUNC(PyObject *)
@@ -501,8 +499,8 @@ _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
PyObject *, PyObject *);
-/* PyObject_Dir(obj) acts like Python __builtin__.dir(obj), returning a
- list of strings. PyObject_Dir(NULL) is like __builtin__.dir(),
+/* PyObject_Dir(obj) acts like Python builtins.dir(obj), returning a
+ list of strings. PyObject_Dir(NULL) is like builtins.dir(),
returning the names of the current locals. In this case, if there are
no current locals, NULL is returned, and PyErr_Occurred() is false.
*/
@@ -514,12 +512,14 @@ PyAPI_FUNC(int) Py_ReprEnter(PyObject *);
PyAPI_FUNC(void) Py_ReprLeave(PyObject *);
/* Helpers for hash functions */
-PyAPI_FUNC(long) _Py_HashDouble(double);
-PyAPI_FUNC(long) _Py_HashPointer(void*);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(Py_hash_t) _Py_HashDouble(double);
+PyAPI_FUNC(Py_hash_t) _Py_HashPointer(void*);
+#endif
typedef struct {
- long prefix;
- long suffix;
+ Py_hash_t prefix;
+ Py_hash_t suffix;
} _Py_HashSecret_t;
PyAPI_DATA(_Py_HashSecret_t) _Py_HashSecret;
@@ -528,7 +528,7 @@ PyAPI_DATA(int) _Py_HashSecret_Initialized;
#endif
/* Helper for passing objects to printf and the like */
-#define PyObject_REPR(obj) PyString_AS_STRING(PyObject_Repr(obj))
+#define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj))
/* Flag bits for printing: */
#define Py_PRINT_RAW 1 /* No string quotes etc. */
@@ -546,48 +546,16 @@ Arbitration of the flag bit positions will need to be coordinated among
all extension writers who publically release their extensions (this will
be fewer than you might expect!)..
-Python 1.5.2 introduced the bf_getcharbuffer slot into PyBufferProcs.
+Most flags were removed as of Python 3.0 to make room for new flags. (Some
+flags are not for backwards compatibility but to indicate the presence of an
+optional feature; these flags remain of course.)
Type definitions should use Py_TPFLAGS_DEFAULT for their tp_flags value.
Code can use PyType_HasFeature(type_ob, flag_value) to test whether the
given type object has a specified feature.
-
-NOTE: when building the core, Py_TPFLAGS_DEFAULT includes
-Py_TPFLAGS_HAVE_VERSION_TAG; outside the core, it doesn't. This is so
-that extensions that modify tp_dict of their own types directly don't
-break, since this was allowed in 2.5. In 3.0 they will have to
-manually remove this flag though!
*/
-/* PyBufferProcs contains bf_getcharbuffer */
-#define Py_TPFLAGS_HAVE_GETCHARBUFFER (1L<<0)
-
-/* PySequenceMethods contains sq_contains */
-#define Py_TPFLAGS_HAVE_SEQUENCE_IN (1L<<1)
-
-/* This is here for backwards compatibility. Extensions that use the old GC
- * API will still compile but the objects will not be tracked by the GC. */
-#define Py_TPFLAGS_GC 0 /* used to be (1L<<2) */
-
-/* PySequenceMethods and PyNumberMethods contain in-place operators */
-#define Py_TPFLAGS_HAVE_INPLACEOPS (1L<<3)
-
-/* PyNumberMethods do their own coercion */
-#define Py_TPFLAGS_CHECKTYPES (1L<<4)
-
-/* tp_richcompare is defined */
-#define Py_TPFLAGS_HAVE_RICHCOMPARE (1L<<5)
-
-/* Objects which are weakly referencable if their tp_weaklistoffset is >0 */
-#define Py_TPFLAGS_HAVE_WEAKREFS (1L<<6)
-
-/* tp_iter is defined */
-#define Py_TPFLAGS_HAVE_ITER (1L<<7)
-
-/* New members introduced by Python 2.2 exist */
-#define Py_TPFLAGS_HAVE_CLASS (1L<<8)
-
/* Set if the type object is dynamically allocated */
#define Py_TPFLAGS_HEAPTYPE (1L<<9)
@@ -610,9 +578,6 @@ manually remove this flag though!
#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
#endif
-/* Objects support nb_index in PyNumberMethods */
-#define Py_TPFLAGS_HAVE_INDEX (1L<<17)
-
/* Objects support type attribute cache */
#define Py_TPFLAGS_HAVE_VERSION_TAG (1L<<18)
#define Py_TPFLAGS_VALID_VERSION_TAG (1L<<19)
@@ -620,41 +585,27 @@ manually remove this flag though!
/* Type is abstract and cannot be instantiated */
#define Py_TPFLAGS_IS_ABSTRACT (1L<<20)
-/* Has the new buffer protocol */
-#define Py_TPFLAGS_HAVE_NEWBUFFER (1L<<21)
-
/* These flags are used to determine if a type is a subclass. */
#define Py_TPFLAGS_INT_SUBCLASS (1L<<23)
#define Py_TPFLAGS_LONG_SUBCLASS (1L<<24)
#define Py_TPFLAGS_LIST_SUBCLASS (1L<<25)
#define Py_TPFLAGS_TUPLE_SUBCLASS (1L<<26)
-#define Py_TPFLAGS_STRING_SUBCLASS (1L<<27)
+#define Py_TPFLAGS_BYTES_SUBCLASS (1L<<27)
#define Py_TPFLAGS_UNICODE_SUBCLASS (1L<<28)
#define Py_TPFLAGS_DICT_SUBCLASS (1L<<29)
#define Py_TPFLAGS_BASE_EXC_SUBCLASS (1L<<30)
#define Py_TPFLAGS_TYPE_SUBCLASS (1L<<31)
-#define Py_TPFLAGS_DEFAULT_EXTERNAL ( \
- Py_TPFLAGS_HAVE_GETCHARBUFFER | \
- Py_TPFLAGS_HAVE_SEQUENCE_IN | \
- Py_TPFLAGS_HAVE_INPLACEOPS | \
- Py_TPFLAGS_HAVE_RICHCOMPARE | \
- Py_TPFLAGS_HAVE_WEAKREFS | \
- Py_TPFLAGS_HAVE_ITER | \
- Py_TPFLAGS_HAVE_CLASS | \
+#define Py_TPFLAGS_DEFAULT ( \
Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
- Py_TPFLAGS_HAVE_INDEX | \
- 0)
-#define Py_TPFLAGS_DEFAULT_CORE (Py_TPFLAGS_DEFAULT_EXTERNAL | \
- Py_TPFLAGS_HAVE_VERSION_TAG)
+ Py_TPFLAGS_HAVE_VERSION_TAG | \
+ 0)
-#ifdef Py_BUILD_CORE
-#define Py_TPFLAGS_DEFAULT Py_TPFLAGS_DEFAULT_CORE
+#ifdef Py_LIMITED_API
+#define PyType_HasFeature(t,f) ((PyType_GetFlags(t) & (f)) != 0)
#else
-#define Py_TPFLAGS_DEFAULT Py_TPFLAGS_DEFAULT_EXTERNAL
-#endif
-
#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
+#endif
#define PyType_FastSubclass(t,f) PyType_HasFeature(t,f)
@@ -757,9 +708,13 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
#define _Py_ForgetReference(op) _Py_INC_TPFREES(op)
+#ifdef Py_LIMITED_API
+PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
+#else
#define _Py_Dealloc(op) ( \
_Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \
(*Py_TYPE(op)->tp_dealloc)((PyObject *)(op)))
+#endif
#endif /* !Py_TRACE_REFS */
#define Py_INCREF(op) ( \
@@ -861,21 +816,6 @@ PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
*/
PyAPI_DATA(int) _Py_SwappedOp[];
-/*
-Define staticforward and statichere for source compatibility with old
-C extensions.
-
-The staticforward define was needed to support certain broken C
-compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the
-static keyword when it was used with a forward declaration of a static
-initialized structure. Standard C allows the forward declaration with
-static, and we've decided to stop catering to broken C compilers.
-(In fact, we expect that the compilers are all fixed eight years later.)
-*/
-
-#define staticforward static
-#define statichere static
-
/*
More conventions
@@ -971,7 +911,7 @@ chain of N deallocations is broken into N / PyTrash_UNWIND_LEVEL pieces,
with the call stack never exceeding a depth of PyTrash_UNWIND_LEVEL.
*/
-/* This is the old private API, invoked by the macros before 2.7.4.
+/* This is the old private API, invoked by the macros before 3.2.4.
Kept for binary compatibility of extensions. */
PyAPI_FUNC(void) _PyTrash_deposit_object(PyObject*);
PyAPI_FUNC(void) _PyTrash_destroy_chain(void);
diff --git a/Include/objimpl.h b/Include/objimpl.h
index 55e83eced6a..8fc3fc1e9a7 100644
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -138,9 +138,6 @@ PyAPI_FUNC(void) _PyMem_DebugFree(void *p);
#define PyObject_Del PyObject_Free
#define PyObject_DEL PyObject_FREE
-/* for source compatibility with 2.2 */
-#define _PyObject_Del PyObject_Free
-
/*
* Generic object allocator interface
* ==================================
@@ -245,10 +242,8 @@ PyAPI_FUNC(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, Py_ssize_t);
#define PyObject_GC_Resize(type, op, n) \
( (type *) _PyObject_GC_Resize((PyVarObject *)(op), (n)) )
-/* for source compatibility with 2.2 */
-#define _PyObject_GC_Del PyObject_GC_Del
-
/* GC information is stored BEFORE the object structure. */
+#ifndef Py_LIMITED_API
typedef union _gc_head {
struct {
union _gc_head *gc_next;
@@ -301,7 +296,7 @@ extern PyGC_Head *_PyGC_generation0;
#define _PyObject_GC_MAY_BE_TRACKED(obj) \
(PyObject_IS_GC(obj) && \
(!PyTuple_CheckExact(obj) || _PyObject_GC_IS_TRACKED(obj)))
-
+#endif /* Py_LIMITED_API */
PyAPI_FUNC(PyObject *) _PyObject_GC_Malloc(size_t);
PyAPI_FUNC(PyObject *) _PyObject_GC_New(PyTypeObject *);
@@ -330,20 +325,9 @@ PyAPI_FUNC(void) PyObject_GC_Del(void *);
} \
} while (0)
-/* This is here for the sake of backwards compatibility. Extensions that
- * use the old GC API will still compile but the objects will not be
- * tracked by the GC. */
-#define PyGC_HEAD_SIZE 0
-#define PyObject_GC_Init(op)
-#define PyObject_GC_Fini(op)
-#define PyObject_AS_GC(op) (op)
-#define PyObject_FROM_GC(op) (op)
-
/* Test if a type supports weak references */
-#define PyType_SUPPORTS_WEAKREFS(t) \
- (PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) \
- && ((t)->tp_weaklistoffset > 0))
+#define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0)
#define PyObject_GET_WEAKREFS_LISTPTR(o) \
((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset))
diff --git a/Include/opcode.h b/Include/opcode.h
index 9764109adb2..6b1094449e9 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -12,20 +12,19 @@ extern "C" {
#define ROT_TWO 2
#define ROT_THREE 3
#define DUP_TOP 4
-#define ROT_FOUR 5
+#define DUP_TOP_TWO 5
#define NOP 9
#define UNARY_POSITIVE 10
#define UNARY_NEGATIVE 11
#define UNARY_NOT 12
-#define UNARY_CONVERT 13
#define UNARY_INVERT 15
#define BINARY_POWER 19
#define BINARY_MULTIPLY 20
-#define BINARY_DIVIDE 21
+
#define BINARY_MODULO 22
#define BINARY_ADD 23
#define BINARY_SUBTRACT 24
@@ -35,20 +34,11 @@ extern "C" {
#define INPLACE_FLOOR_DIVIDE 28
#define INPLACE_TRUE_DIVIDE 29
-#define SLICE 30
-/* Also uses 31-33 */
-
-#define STORE_SLICE 40
-/* Also uses 41-43 */
-
-#define DELETE_SLICE 50
-/* Also uses 51-53 */
-
#define STORE_MAP 54
#define INPLACE_ADD 55
#define INPLACE_SUBTRACT 56
#define INPLACE_MULTIPLY 57
-#define INPLACE_DIVIDE 58
+
#define INPLACE_MODULO 59
#define STORE_SUBSCR 60
#define DELETE_SUBSCR 61
@@ -60,12 +50,10 @@ extern "C" {
#define BINARY_OR 66
#define INPLACE_POWER 67
#define GET_ITER 68
-
+#define STORE_LOCALS 69
#define PRINT_EXPR 70
-#define PRINT_ITEM 71
-#define PRINT_NEWLINE 72
-#define PRINT_ITEM_TO 73
-#define PRINT_NEWLINE_TO 74
+#define LOAD_BUILD_CLASS 71
+
#define INPLACE_LSHIFT 75
#define INPLACE_RSHIFT 76
#define INPLACE_AND 77
@@ -73,14 +61,14 @@ extern "C" {
#define INPLACE_OR 79
#define BREAK_LOOP 80
#define WITH_CLEANUP 81
-#define LOAD_LOCALS 82
+
#define RETURN_VALUE 83
#define IMPORT_STAR 84
-#define EXEC_STMT 85
+
#define YIELD_VALUE 86
#define POP_BLOCK 87
#define END_FINALLY 88
-#define BUILD_CLASS 89
+#define POP_EXCEPT 89
#define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */
@@ -88,13 +76,14 @@ extern "C" {
#define DELETE_NAME 91 /* "" */
#define UNPACK_SEQUENCE 92 /* Number of sequence items */
#define FOR_ITER 93
-#define LIST_APPEND 94
+#define UNPACK_EX 94 /* Num items before variable part +
+ (Num items after variable part << 8) */
#define STORE_ATTR 95 /* Index in name list */
#define DELETE_ATTR 96 /* "" */
#define STORE_GLOBAL 97 /* "" */
#define DELETE_GLOBAL 98 /* "" */
-#define DUP_TOPX 99 /* number of items to duplicate */
+
#define LOAD_CONST 100 /* Index in const list */
#define LOAD_NAME 101 /* Index in name list */
#define BUILD_TUPLE 102 /* Number of tuple items */
@@ -105,10 +94,9 @@ extern "C" {
#define COMPARE_OP 107 /* Comparison operator */
#define IMPORT_NAME 108 /* Index in name list */
#define IMPORT_FROM 109 /* Index in name list */
-#define JUMP_FORWARD 110 /* Number of bytes to skip */
-#define JUMP_IF_FALSE_OR_POP 111 /* Target byte offset from beginning
- of code */
+#define JUMP_FORWARD 110 /* Number of bytes to skip */
+#define JUMP_IF_FALSE_OR_POP 111 /* Target byte offset from beginning of code */
#define JUMP_IF_TRUE_OR_POP 112 /* "" */
#define JUMP_ABSOLUTE 113 /* "" */
#define POP_JUMP_IF_FALSE 114 /* "" */
@@ -128,13 +116,14 @@ extern "C" {
#define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */
/* CALL_FUNCTION_XXX opcodes defined below depend on this definition */
#define CALL_FUNCTION 131 /* #args + (#kwargs<<8) */
-#define MAKE_FUNCTION 132 /* #defaults */
+#define MAKE_FUNCTION 132 /* #defaults + #kwdefaults<<8 + #annotations<<16 */
#define BUILD_SLICE 133 /* Number of items */
-#define MAKE_CLOSURE 134 /* #free vars */
+#define MAKE_CLOSURE 134 /* same as MAKE_FUNCTION */
#define LOAD_CLOSURE 135 /* Load free variable from closure */
#define LOAD_DEREF 136 /* Load and dereference from closure cell */
#define STORE_DEREF 137 /* Store into cell */
+#define DELETE_DEREF 138 /* Delete closure cell */
/* The next 3 opcodes must be contiguous and satisfy
(CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */
@@ -145,12 +134,20 @@ extern "C" {
#define SETUP_WITH 143
/* Support for opargs more than 16 bits long */
-#define EXTENDED_ARG 145
+#define EXTENDED_ARG 144
+#define LIST_APPEND 145
#define SET_ADD 146
#define MAP_ADD 147
+/* EXCEPT_HANDLER is a special, implicit block type which is created when
+ entering an except handler. It is not an opcode but we define it here
+ as we want it to be available to both frameobject.c and ceval.c, while
+ remaining private.*/
+#define EXCEPT_HANDLER 257
+
+
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,
PyCmp_IN, PyCmp_NOT_IN, PyCmp_IS, PyCmp_IS_NOT, PyCmp_EXC_MATCH, PyCmp_BAD};
diff --git a/Include/osdefs.h b/Include/osdefs.h
index 77af9237546..90b430a635b 100644
--- a/Include/osdefs.h
+++ b/Include/osdefs.h
@@ -12,38 +12,23 @@ extern "C" {
#if defined(MS_WINDOWS) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__DJGPP__) || defined(PYOS_OS2)
#if defined(PYOS_OS2) && defined(PYCC_GCC)
#define MAXPATHLEN 260
-#define SEP '/'
-#define ALTSEP '\\'
+#define SEP L'/'
+#define ALTSEP L'\\'
#else
-#define SEP '\\'
-#define ALTSEP '/'
+#define SEP L'\\'
+#define ALTSEP L'/'
#define MAXPATHLEN 256
#endif
-#define DELIM ';'
+#define DELIM L';'
#endif
#endif
-#ifdef RISCOS
-#define SEP '.'
-#define MAXPATHLEN 256
-#define DELIM ','
-#endif
-
-
/* Filename separator */
#ifndef SEP
-#define SEP '/'
+#define SEP L'/'
#endif
/* Max pathname length */
-#ifdef __hpux
-#include <sys/param.h>
-#include <limits.h>
-#ifndef PATH_MAX
-#define PATH_MAX MAXPATHLEN
-#endif
-#endif
-
#ifndef MAXPATHLEN
#if defined(PATH_MAX) && PATH_MAX > 1024
#define MAXPATHLEN PATH_MAX
@@ -54,7 +39,7 @@ extern "C" {
/* Search path entry delimiter */
#ifndef DELIM
-#define DELIM ':'
+#define DELIM L':'
#endif
#ifdef __cplusplus
diff --git a/Include/parsetok.h b/Include/parsetok.h
index ec1eb6ff7d8..4b7694f90f1 100644
--- a/Include/parsetok.h
+++ b/Include/parsetok.h
@@ -1,6 +1,6 @@
/* Parser-tokenizer link interface */
-
+#ifndef Py_LIMITED_API
#ifndef Py_PARSETOK_H
#define Py_PARSETOK_H
#ifdef __cplusplus
@@ -9,10 +9,10 @@ extern "C" {
typedef struct {
int error;
- const char *filename;
+ const char *filename; /* decoded from the filesystem encoding */
int lineno;
int offset;
- char *text;
+ char *text; /* UTF-8-encoded string */
int token;
int expected;
} perrdetail;
@@ -25,12 +25,12 @@ typedef struct {
#if 0
#define PyPARSE_WITH_IS_KEYWORD 0x0003
-#endif
-
#define PyPARSE_PRINT_IS_FUNCTION 0x0004
#define PyPARSE_UNICODE_LITERALS 0x0008
+#endif
-
+#define PyPARSE_IGNORE_COOKIE 0x0010
+#define PyPARSE_BARRY_AS_BDFL 0x0020
PyAPI_FUNC(node *) PyParser_ParseString(const char *, grammar *, int,
perrdetail *);
@@ -39,21 +39,32 @@ PyAPI_FUNC(node *) PyParser_ParseFile (FILE *, const char *, grammar *, int,
PyAPI_FUNC(node *) PyParser_ParseStringFlags(const char *, grammar *, int,
perrdetail *, int);
-PyAPI_FUNC(node *) PyParser_ParseFileFlags(FILE *, const char *, grammar *,
+PyAPI_FUNC(node *) PyParser_ParseFileFlags(FILE *, const char *,
+ const char*, grammar *,
int, char *, char *,
perrdetail *, int);
-PyAPI_FUNC(node *) PyParser_ParseFileFlagsEx(FILE *, const char *, grammar *,
- int, char *, char *,
- perrdetail *, int *);
+PyAPI_FUNC(node *) PyParser_ParseFileFlagsEx(
+ FILE *fp,
+ const char *filename, /* decoded from the filesystem encoding */
+ const char *enc,
+ grammar *g,
+ int start,
+ char *ps1,
+ char *ps2,
+ perrdetail *err_ret,
+ int *flags);
PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilename(const char *,
const char *,
grammar *, int,
perrdetail *, int);
-PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilenameEx(const char *,
- const char *,
- grammar *, int,
- perrdetail *, int *);
+PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilenameEx(
+ const char *s,
+ const char *filename, /* decoded from the filesystem encoding */
+ grammar *g,
+ int start,
+ perrdetail *err_ret,
+ int *flags);
/* Note that he following function is defined in pythonrun.c not parsetok.c. */
PyAPI_FUNC(void) PyParser_SetError(perrdetail *);
@@ -62,3 +73,4 @@ PyAPI_FUNC(void) PyParser_SetError(perrdetail *);
}
#endif
#endif /* !Py_PARSETOK_H */
+#endif /* !Py_LIMITED_API */
diff --git a/Include/patchlevel.h b/Include/patchlevel.h
index bbdd67be534..0839071c766 100644
--- a/Include/patchlevel.h
+++ b/Include/patchlevel.h
@@ -1,9 +1,5 @@
-/* Newfangled version identification scheme.
-
- This scheme was added in Python 1.5.2b2; before that time, only PATCHLEVEL
- was available. To test for presence of the scheme, test for
- defined(PY_MAJOR_VERSION).
+/* Python version identification scheme.
When the major or minor version changes, the VERSION variable in
configure.ac must also be changed.
@@ -20,14 +16,14 @@
/* Version parsed out into numeric values */
/*--start constants--*/
-#define PY_MAJOR_VERSION 2
-#define PY_MINOR_VERSION 7
+#define PY_MAJOR_VERSION 3
+#define PY_MINOR_VERSION 2
#define PY_MICRO_VERSION 3
#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL
#define PY_RELEASE_SERIAL 0
/* Version as a string */
-#define PY_VERSION "2.7.3+"
+#define PY_VERSION "3.2.3+"
/*--end constants--*/
/* Subversion Revision number of this file (not of the repository). Empty
diff --git a/Include/py_curses.h b/Include/py_curses.h
index 657816cbd32..a891c42be65 100644
--- a/Include/py_curses.h
+++ b/Include/py_curses.h
@@ -139,14 +139,14 @@ static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
static PyObject *PyCurses_ ## X (PyObject *self) \
{ \
PyCursesInitialised \
- return PyInt_FromLong((long) X()); }
+ return PyLong_FromLong((long) X()); }
#define NoArgReturnStringFunction(X) \
static PyObject *PyCurses_ ## X (PyObject *self) \
{ \
PyCursesInitialised \
- return PyString_FromString(X()); }
+ return PyBytes_FromString(X()); }
#define NoArgTrueFalseFunction(X) \
static PyObject *PyCurses_ ## X (PyObject *self) \
diff --git a/Include/pyarena.h b/Include/pyarena.h
index 5f193feceea..db3ad0188fe 100644
--- a/Include/pyarena.h
+++ b/Include/pyarena.h
@@ -1,6 +1,7 @@
/* An arena-like memory interface for the compiler.
*/
+#ifndef Py_LIMITED_API
#ifndef Py_PYARENA_H
#define Py_PYARENA_H
@@ -60,3 +61,4 @@ extern "C" {
#endif
#endif /* !Py_PYARENA_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/pyatomic.h b/Include/pyatomic.h
new file mode 100644
index 00000000000..d4e19e0070b
--- /dev/null
+++ b/Include/pyatomic.h
@@ -0,0 +1,184 @@
+#ifndef Py_LIMITED_API
+#ifndef Py_ATOMIC_H
+#define Py_ATOMIC_H
+/* XXX: When compilers start offering a stdatomic.h with lock-free
+ atomic_int and atomic_address types, include that here and rewrite
+ the atomic operations in terms of it. */
+
+#include "dynamic_annotations.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* This is modeled after the atomics interface from C1x, according to
+ * the draft at
+ * http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1425.pdf.
+ * Operations and types are named the same except with a _Py_ prefix
+ * and have the same semantics.
+ *
+ * Beware, the implementations here are deep magic.
+ */
+
+typedef enum _Py_memory_order {
+ _Py_memory_order_relaxed,
+ _Py_memory_order_acquire,
+ _Py_memory_order_release,
+ _Py_memory_order_acq_rel,
+ _Py_memory_order_seq_cst
+} _Py_memory_order;
+
+typedef struct _Py_atomic_address {
+ void *_value;
+} _Py_atomic_address;
+
+typedef struct _Py_atomic_int {
+ int _value;
+} _Py_atomic_int;
+
+/* Only support GCC (for expression statements) and x86 (for simple
+ * atomic semantics) for now */
+#if defined(__GNUC__) && (defined(__i386__) || defined(__amd64))
+
+static __inline__ void
+_Py_atomic_signal_fence(_Py_memory_order order)
+{
+ if (order != _Py_memory_order_relaxed)
+ __asm__ volatile("":::"memory");
+}
+
+static __inline__ void
+_Py_atomic_thread_fence(_Py_memory_order order)
+{
+ if (order != _Py_memory_order_relaxed)
+ __asm__ volatile("mfence":::"memory");
+}
+
+/* Tell the race checker about this operation's effects. */
+static __inline__ void
+_Py_ANNOTATE_MEMORY_ORDER(const volatile void *address, _Py_memory_order order)
+{
+ (void)address; /* shut up -Wunused-parameter */
+ switch(order) {
+ case _Py_memory_order_release:
+ case _Py_memory_order_acq_rel:
+ case _Py_memory_order_seq_cst:
+ _Py_ANNOTATE_HAPPENS_BEFORE(address);
+ break;
+ case _Py_memory_order_relaxed:
+ case _Py_memory_order_acquire:
+ break;
+ }
+ switch(order) {
+ case _Py_memory_order_acquire:
+ case _Py_memory_order_acq_rel:
+ case _Py_memory_order_seq_cst:
+ _Py_ANNOTATE_HAPPENS_AFTER(address);
+ break;
+ case _Py_memory_order_relaxed:
+ case _Py_memory_order_release:
+ break;
+ }
+}
+
+#define _Py_atomic_store_explicit(ATOMIC_VAL, NEW_VAL, ORDER) \
+ __extension__ ({ \
+ __typeof__(ATOMIC_VAL) atomic_val = ATOMIC_VAL; \
+ __typeof__(atomic_val->_value) new_val = NEW_VAL;\
+ volatile __typeof__(new_val) *volatile_data = &atomic_val->_value; \
+ _Py_memory_order order = ORDER; \
+ _Py_ANNOTATE_MEMORY_ORDER(atomic_val, order); \
+ \
+ /* Perform the operation. */ \
+ _Py_ANNOTATE_IGNORE_WRITES_BEGIN(); \
+ switch(order) { \
+ case _Py_memory_order_release: \
+ _Py_atomic_signal_fence(_Py_memory_order_release); \
+ /* fallthrough */ \
+ case _Py_memory_order_relaxed: \
+ *volatile_data = new_val; \
+ break; \
+ \
+ case _Py_memory_order_acquire: \
+ case _Py_memory_order_acq_rel: \
+ case _Py_memory_order_seq_cst: \
+ __asm__ volatile("xchg %0, %1" \
+ : "+r"(new_val) \
+ : "m"(atomic_val->_value) \
+ : "memory"); \
+ break; \
+ } \
+ _Py_ANNOTATE_IGNORE_WRITES_END(); \
+ })
+
+#define _Py_atomic_load_explicit(ATOMIC_VAL, ORDER) \
+ __extension__ ({ \
+ __typeof__(ATOMIC_VAL) atomic_val = ATOMIC_VAL; \
+ __typeof__(atomic_val->_value) result; \
+ volatile __typeof__(result) *volatile_data = &atomic_val->_value; \
+ _Py_memory_order order = ORDER; \
+ _Py_ANNOTATE_MEMORY_ORDER(atomic_val, order); \
+ \
+ /* Perform the operation. */ \
+ _Py_ANNOTATE_IGNORE_READS_BEGIN(); \
+ switch(order) { \
+ case _Py_memory_order_release: \
+ case _Py_memory_order_acq_rel: \
+ case _Py_memory_order_seq_cst: \
+ /* Loads on x86 are not releases by default, so need a */ \
+ /* thread fence. */ \
+ _Py_atomic_thread_fence(_Py_memory_order_release); \
+ break; \
+ default: \
+ /* No fence */ \
+ break; \
+ } \
+ result = *volatile_data; \
+ switch(order) { \
+ case _Py_memory_order_acquire: \
+ case _Py_memory_order_acq_rel: \
+ case _Py_memory_order_seq_cst: \
+ /* Loads on x86 are automatically acquire operations so */ \
+ /* can get by with just a compiler fence. */ \
+ _Py_atomic_signal_fence(_Py_memory_order_acquire); \
+ break; \
+ default: \
+ /* No fence */ \
+ break; \
+ } \
+ _Py_ANNOTATE_IGNORE_READS_END(); \
+ result; \
+ })
+
+#else /* !gcc x86 */
+/* Fall back to other compilers and processors by assuming that simple
+ volatile accesses are atomic. This is false, so people should port
+ this. */
+#define _Py_atomic_signal_fence(/*memory_order*/ ORDER) ((void)0)
+#define _Py_atomic_thread_fence(/*memory_order*/ ORDER) ((void)0)
+#define _Py_atomic_store_explicit(ATOMIC_VAL, NEW_VAL, ORDER) \
+ ((ATOMIC_VAL)->_value = NEW_VAL)
+#define _Py_atomic_load_explicit(ATOMIC_VAL, ORDER) \
+ ((ATOMIC_VAL)->_value)
+
+#endif /* !gcc x86 */
+
+/* Standardized shortcuts. */
+#define _Py_atomic_store(ATOMIC_VAL, NEW_VAL) \
+ _Py_atomic_store_explicit(ATOMIC_VAL, NEW_VAL, _Py_memory_order_seq_cst)
+#define _Py_atomic_load(ATOMIC_VAL) \
+ _Py_atomic_load_explicit(ATOMIC_VAL, _Py_memory_order_seq_cst)
+
+/* Python-local extensions */
+
+#define _Py_atomic_store_relaxed(ATOMIC_VAL, NEW_VAL) \
+ _Py_atomic_store_explicit(ATOMIC_VAL, NEW_VAL, _Py_memory_order_relaxed)
+#define _Py_atomic_load_relaxed(ATOMIC_VAL) \
+ _Py_atomic_load_explicit(ATOMIC_VAL, _Py_memory_order_relaxed)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* Py_ATOMIC_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/pycapsule.h b/Include/pycapsule.h
index cd682fc7de6..d9ecda7a4b6 100644
--- a/Include/pycapsule.h
+++ b/Include/pycapsule.h
@@ -48,7 +48,10 @@ PyAPI_FUNC(int) PyCapsule_SetName(PyObject *capsule, const char *name);
PyAPI_FUNC(int) PyCapsule_SetContext(PyObject *capsule, void *context);
-PyAPI_FUNC(void *) PyCapsule_Import(const char *name, int no_block);
+PyAPI_FUNC(void *) PyCapsule_Import(
+ const char *name, /* UTF-8 encoded string */
+ int no_block);
+
#ifdef __cplusplus
}
diff --git a/Include/pyctype.h b/Include/pyctype.h
index 673cf2eb009..6bce63eeb63 100644
--- a/Include/pyctype.h
+++ b/Include/pyctype.h
@@ -1,3 +1,4 @@
+#ifndef Py_LIMITED_API
#ifndef PYCTYPE_H
#define PYCTYPE_H
@@ -29,3 +30,4 @@ PyAPI_DATA(const unsigned char) _Py_ctype_toupper[256];
#define Py_TOUPPER(c) (_Py_ctype_toupper[Py_CHARMASK(c)])
#endif /* !PYCTYPE_H */
+#endif /* !Py_LIMITED_API */
diff --git a/Include/pydebug.h b/Include/pydebug.h
index 0f45960f90f..e23cbdc3ad6 100644
--- a/Include/pydebug.h
+++ b/Include/pydebug.h
@@ -1,4 +1,4 @@
-
+#ifndef Py_LIMITED_API
#ifndef Py_PYDEBUG_H
#define Py_PYDEBUG_H
#ifdef __cplusplus
@@ -7,6 +7,7 @@ extern "C" {
PyAPI_DATA(int) Py_DebugFlag;
PyAPI_DATA(int) Py_VerboseFlag;
+PyAPI_DATA(int) Py_QuietFlag;
PyAPI_DATA(int) Py_InteractiveFlag;
PyAPI_DATA(int) Py_InspectFlag;
PyAPI_DATA(int) Py_OptimizeFlag;
@@ -14,18 +15,11 @@ PyAPI_DATA(int) Py_NoSiteFlag;
PyAPI_DATA(int) Py_BytesWarningFlag;
PyAPI_DATA(int) Py_UseClassExceptionsFlag;
PyAPI_DATA(int) Py_FrozenFlag;
-PyAPI_DATA(int) Py_TabcheckFlag;
-PyAPI_DATA(int) Py_UnicodeFlag;
PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
PyAPI_DATA(int) Py_DivisionWarningFlag;
PyAPI_DATA(int) Py_DontWriteBytecodeFlag;
PyAPI_DATA(int) Py_NoUserSiteDirectory;
-/* _XXX Py_QnewFlag should go away in 3.0. It's true iff -Qnew is passed,
- on the command line, and is used in 2.2 by ceval.c to make all "/" divisions
- true divisions (which they will be in 3.0). */
-PyAPI_DATA(int) _Py_QnewFlag;
-/* Warn about 3.x issues */
-PyAPI_DATA(int) Py_Py3kWarningFlag;
+PyAPI_DATA(int) Py_UnbufferedStdioFlag;
PyAPI_DATA(int) Py_HashRandomizationFlag;
/* this is a wrapper around getenv() that pays attention to
@@ -39,3 +33,4 @@ PyAPI_FUNC(void) Py_FatalError(const char *message);
}
#endif
#endif /* !Py_PYDEBUG_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index dbe3bfa5f2d..4bb3c01443b 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -6,18 +6,18 @@ extern "C" {
/* Error objects */
+#ifndef Py_LIMITED_API
+/* PyException_HEAD defines the initial segment of every exception class. */
+#define PyException_HEAD PyObject_HEAD PyObject *dict;\
+ PyObject *args; PyObject *traceback;\
+ PyObject *context; PyObject *cause;
+
typedef struct {
- PyObject_HEAD
- PyObject *dict;
- PyObject *args;
- PyObject *message;
+ PyException_HEAD
} PyBaseExceptionObject;
typedef struct {
- PyObject_HEAD
- PyObject *dict;
- PyObject *args;
- PyObject *message;
+ PyException_HEAD
PyObject *msg;
PyObject *filename;
PyObject *lineno;
@@ -26,33 +26,22 @@ typedef struct {
PyObject *print_file_and_line;
} PySyntaxErrorObject;
-#ifdef Py_USING_UNICODE
typedef struct {
- PyObject_HEAD
- PyObject *dict;
- PyObject *args;
- PyObject *message;
+ PyException_HEAD
PyObject *encoding;
PyObject *object;
Py_ssize_t start;
Py_ssize_t end;
PyObject *reason;
} PyUnicodeErrorObject;
-#endif
typedef struct {
- PyObject_HEAD
- PyObject *dict;
- PyObject *args;
- PyObject *message;
+ PyException_HEAD
PyObject *code;
} PySystemExitObject;
typedef struct {
- PyObject_HEAD
- PyObject *dict;
- PyObject *args;
- PyObject *message;
+ PyException_HEAD
PyObject *myerrno;
PyObject *strerror;
PyObject *filename;
@@ -60,28 +49,30 @@ typedef struct {
#ifdef MS_WINDOWS
typedef struct {
- PyObject_HEAD
- PyObject *dict;
- PyObject *args;
- PyObject *message;
+ PyException_HEAD
PyObject *myerrno;
PyObject *strerror;
PyObject *filename;
PyObject *winerror;
} PyWindowsErrorObject;
#endif
+#endif
/* Error handling definitions */
PyAPI_FUNC(void) PyErr_SetNone(PyObject *);
PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *);
-PyAPI_FUNC(void) PyErr_SetString(PyObject *, const char *);
+PyAPI_FUNC(void) PyErr_SetString(
+ PyObject *exception,
+ const char *string /* decoded from utf-8 */
+ );
PyAPI_FUNC(PyObject *) PyErr_Occurred(void);
PyAPI_FUNC(void) PyErr_Clear(void);
PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
+PyAPI_FUNC(void) Py_FatalError(const char *message);
-#ifdef Py_DEBUG
+#if defined(Py_DEBUG) || defined(Py_LIMITED_API)
#define _PyErr_OCCURRED() PyErr_Occurred()
#else
#define _PyErr_OCCURRED() (_PyThreadState_Current->curexc_type)
@@ -92,25 +83,32 @@ PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);
PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
+/* Traceback manipulation (PEP 3134) */
+PyAPI_FUNC(int) PyException_SetTraceback(PyObject *, PyObject *);
+PyAPI_FUNC(PyObject *) PyException_GetTraceback(PyObject *);
+
+/* Cause manipulation (PEP 3134) */
+PyAPI_FUNC(PyObject *) PyException_GetCause(PyObject *);
+PyAPI_FUNC(void) PyException_SetCause(PyObject *, PyObject *);
+
+/* Context manipulation (PEP 3134) */
+PyAPI_FUNC(PyObject *) PyException_GetContext(PyObject *);
+PyAPI_FUNC(void) PyException_SetContext(PyObject *, PyObject *);
+
+
/* */
#define PyExceptionClass_Check(x) \
- (PyClass_Check((x)) || (PyType_Check((x)) && \
- PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)))
+ (PyType_Check((x)) && \
+ PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))
#define PyExceptionInstance_Check(x) \
- (PyInstance_Check((x)) || \
- PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS))
+ PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS)
-#define PyExceptionClass_Name(x) \
- (PyClass_Check((x)) \
- ? PyString_AS_STRING(((PyClassObject*)(x))->cl_name) \
- : (char *)(((PyTypeObject*)(x))->tp_name))
+#define PyExceptionClass_Name(x) \
+ ((char *)(((PyTypeObject*)(x))->tp_name))
-#define PyExceptionInstance_Class(x) \
- ((PyInstance_Check((x)) \
- ? (PyObject*)((PyInstanceObject*)(x))->in_class \
- : (PyObject*)((x)->ob_type)))
+#define PyExceptionInstance_Class(x) ((PyObject*)((x)->ob_type))
/* Predefined exceptions */
@@ -119,7 +117,6 @@ PyAPI_DATA(PyObject *) PyExc_BaseException;
PyAPI_DATA(PyObject *) PyExc_Exception;
PyAPI_DATA(PyObject *) PyExc_StopIteration;
PyAPI_DATA(PyObject *) PyExc_GeneratorExit;
-PyAPI_DATA(PyObject *) PyExc_StandardError;
PyAPI_DATA(PyObject *) PyExc_ArithmeticError;
PyAPI_DATA(PyObject *) PyExc_LookupError;
@@ -162,7 +159,6 @@ PyAPI_DATA(PyObject *) PyExc_VMSError;
PyAPI_DATA(PyObject *) PyExc_BufferError;
-PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst;
PyAPI_DATA(PyObject *) PyExc_RecursionErrorInst;
/* Predefined warning categories */
@@ -176,6 +172,7 @@ PyAPI_DATA(PyObject *) PyExc_FutureWarning;
PyAPI_DATA(PyObject *) PyExc_ImportWarning;
PyAPI_DATA(PyObject *) PyExc_UnicodeWarning;
PyAPI_DATA(PyObject *) PyExc_BytesWarning;
+PyAPI_DATA(PyObject *) PyExc_ResourceWarning;
/* Convenience functions */
@@ -186,44 +183,59 @@ PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject(
PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(
- PyObject *, const char *);
-#ifdef MS_WINDOWS
+ PyObject *exc,
+ const char *filename /* decoded from the filesystem encoding */
+ );
+#if defined(MS_WINDOWS) && !defined(Py_LIMITED_API)
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
PyObject *, const Py_UNICODE *);
#endif /* MS_WINDOWS */
-PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *, const char *, ...)
- Py_GCC_ATTRIBUTE((format(printf, 2, 3)));
+PyAPI_FUNC(PyObject *) PyErr_Format(
+ PyObject *exception,
+ const char *format, /* ASCII-encoded string */
+ ...
+ );
#ifdef MS_WINDOWS
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilenameObject(
int, const char *);
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
- int, const char *);
+ int ierr,
+ const char *filename /* decoded from the filesystem encoding */
+ );
+#ifndef Py_LIMITED_API
+/* XXX redeclare to use WSTRING */
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
int, const Py_UNICODE *);
+#endif
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(
PyObject *,int, PyObject *);
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
- PyObject *,int, const char *);
+ PyObject *exc,
+ int ierr,
+ const char *filename /* decoded from the filesystem encoding */
+ );
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
PyObject *,int, const Py_UNICODE *);
+#endif
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
#endif /* MS_WINDOWS */
/* Export the old function so that the existing API remains available: */
PyAPI_FUNC(void) PyErr_BadInternalCall(void);
-PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename, int lineno);
+PyAPI_FUNC(void) _PyErr_BadInternalCall(const char *filename, int lineno);
/* Mask the old API with a call to the new API for code compiled under
Python 2.0: */
#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
/* Function to create a new exception */
PyAPI_FUNC(PyObject *) PyErr_NewException(
- char *name, PyObject *base, PyObject *dict);
+ const char *name, PyObject *base, PyObject *dict);
PyAPI_FUNC(PyObject *) PyErr_NewExceptionWithDoc(
- char *name, char *doc, PyObject *base, PyObject *dict);
+ const char *name, const char *doc, PyObject *base, PyObject *dict);
PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
/* In sigcheck.c or signalmodule.c */
@@ -231,27 +243,57 @@ PyAPI_FUNC(int) PyErr_CheckSignals(void);
PyAPI_FUNC(void) PyErr_SetInterrupt(void);
/* In signalmodule.c */
+#ifndef Py_LIMITED_API
int PySignal_SetWakeupFd(int fd);
+#endif
/* Support for adding program text to SyntaxErrors */
-PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
-PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int);
+PyAPI_FUNC(void) PyErr_SyntaxLocation(
+ const char *filename, /* decoded from the filesystem encoding */
+ int lineno);
+PyAPI_FUNC(void) PyErr_SyntaxLocationEx(
+ const char *filename, /* decoded from the filesystem encoding */
+ int lineno,
+ int col_offset);
+PyAPI_FUNC(PyObject *) PyErr_ProgramText(
+ const char *filename, /* decoded from the filesystem encoding */
+ int lineno);
-#ifdef Py_USING_UNICODE
/* The following functions are used to create and modify unicode
exceptions from C */
/* create a UnicodeDecodeError object */
PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create(
- const char *, const char *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
+ const char *encoding, /* UTF-8 encoded string */
+ const char *object,
+ Py_ssize_t length,
+ Py_ssize_t start,
+ Py_ssize_t end,
+ const char *reason /* UTF-8 encoded string */
+ );
/* create a UnicodeEncodeError object */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
- const char *, const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
+ const char *encoding, /* UTF-8 encoded string */
+ const Py_UNICODE *object,
+ Py_ssize_t length,
+ Py_ssize_t start,
+ Py_ssize_t end,
+ const char *reason /* UTF-8 encoded string */
+ );
+#endif
/* create a UnicodeTranslateError object */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
- const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
+ const Py_UNICODE *object,
+ Py_ssize_t length,
+ Py_ssize_t start,
+ Py_ssize_t end,
+ const char *reason /* UTF-8 encoded string */
+ );
+#endif
/* get the encoding attribute */
PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *);
@@ -294,12 +336,17 @@ PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *);
/* assign a new value to the reason attribute
return 0 on success, -1 on failure */
PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason(
- PyObject *, const char *);
+ PyObject *exc,
+ const char *reason /* UTF-8 encoded string */
+ );
PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason(
- PyObject *, const char *);
+ PyObject *exc,
+ const char *reason /* UTF-8 encoded string */
+ );
PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
- PyObject *, const char *);
-#endif
+ PyObject *exc,
+ const char *reason /* UTF-8 encoded string */
+ );
/* These APIs aren't really part of the error implementation, but
diff --git a/Include/pygetopt.h b/Include/pygetopt.h
index 9860d360e1e..425c7dd6546 100644
--- a/Include/pygetopt.h
+++ b/Include/pygetopt.h
@@ -5,12 +5,15 @@
extern "C" {
#endif
+#ifndef Py_LIMITED_API
PyAPI_DATA(int) _PyOS_opterr;
PyAPI_DATA(int) _PyOS_optind;
-PyAPI_DATA(char *) _PyOS_optarg;
+PyAPI_DATA(wchar_t *) _PyOS_optarg;
PyAPI_FUNC(void) _PyOS_ResetGetOpt(void);
-PyAPI_FUNC(int) _PyOS_GetOpt(int argc, char **argv, char *optstring);
+#endif
+
+PyAPI_FUNC(int) _PyOS_GetOpt(int argc, wchar_t **argv, wchar_t *optstring);
#ifdef __cplusplus
}
diff --git a/Include/pymactoolbox.h b/Include/pymactoolbox.h
deleted file mode 100644
index fd15975270b..00000000000
--- a/Include/pymactoolbox.h
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
-** pymactoolbox.h - globals defined in mactoolboxglue.c
-*/
-#ifndef Py_PYMACTOOLBOX_H
-#define Py_PYMACTOOLBOX_H
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-#include <Carbon/Carbon.h>
-
-#ifndef __LP64__
-#include <QuickTime/QuickTime.h>
-#endif /* !__LP64__ */
-
-/*
-** Helper routines for error codes and such.
-*/
-char *PyMac_StrError(int); /* strerror with mac errors */
-extern PyObject *PyMac_OSErrException; /* Exception for OSErr */
-PyObject *PyMac_GetOSErrException(void); /* Initialize & return it */
-PyObject *PyErr_Mac(PyObject *, int); /* Exception with a mac error */
-PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */
-#ifndef __LP64__
-extern OSErr PyMac_GetFullPathname(FSSpec *, char *, int); /* convert
- fsspec->path */
-#endif /* __LP64__ */
-
-/*
-** These conversion routines are defined in mactoolboxglue.c itself.
-*/
-int PyMac_GetOSType(PyObject *, OSType *); /* argument parser for OSType */
-PyObject *PyMac_BuildOSType(OSType); /* Convert OSType to PyObject */
-
-PyObject *PyMac_BuildNumVersion(NumVersion);/* Convert NumVersion to PyObject */
-
-int PyMac_GetStr255(PyObject *, Str255); /* argument parser for Str255 */
-PyObject *PyMac_BuildStr255(Str255); /* Convert Str255 to PyObject */
-PyObject *PyMac_BuildOptStr255(Str255); /* Convert Str255 to PyObject,
- NULL to None */
-
-int PyMac_GetRect(PyObject *, Rect *); /* argument parser for Rect */
-PyObject *PyMac_BuildRect(Rect *); /* Convert Rect to PyObject */
-
-int PyMac_GetPoint(PyObject *, Point *); /* argument parser for Point */
-PyObject *PyMac_BuildPoint(Point); /* Convert Point to PyObject */
-
-int PyMac_GetEventRecord(PyObject *, EventRecord *); /* argument parser for
- EventRecord */
-PyObject *PyMac_BuildEventRecord(EventRecord *); /* Convert EventRecord to
- PyObject */
-
-int PyMac_GetFixed(PyObject *, Fixed *); /* argument parser for Fixed */
-PyObject *PyMac_BuildFixed(Fixed); /* Convert Fixed to PyObject */
-int PyMac_Getwide(PyObject *, wide *); /* argument parser for wide */
-PyObject *PyMac_Buildwide(wide *); /* Convert wide to PyObject */
-
-/*
-** The rest of the routines are implemented by extension modules. If they are
-** dynamically loaded mactoolboxglue will contain a stub implementation of the
-** routine, which imports the module, whereupon the module's init routine will
-** communicate the routine pointer back to the stub.
-** If USE_TOOLBOX_OBJECT_GLUE is not defined there is no glue code, and the
-** extension modules simply declare the routine. This is the case for static
-** builds (and could be the case for MacPython CFM builds, because CFM extension
-** modules can reference each other without problems).
-*/
-
-#ifdef USE_TOOLBOX_OBJECT_GLUE
-/*
-** These macros are used in the module init code. If we use toolbox object glue
-** it sets the function pointer to point to the real function.
-*/
-#define PyMac_INIT_TOOLBOX_OBJECT_NEW(object, rtn) { \
- extern PyObject *(*PyMacGluePtr_##rtn)(object); \
- PyMacGluePtr_##rtn = _##rtn; \
-}
-#define PyMac_INIT_TOOLBOX_OBJECT_CONVERT(object, rtn) { \
- extern int (*PyMacGluePtr_##rtn)(PyObject *, object *); \
- PyMacGluePtr_##rtn = _##rtn; \
-}
-#else
-/*
-** If we don't use toolbox object glue the init macros are empty. Moreover, we define
-** _xxx_New to be the same as xxx_New, and the code in mactoolboxglue isn't included.
-*/
-#define PyMac_INIT_TOOLBOX_OBJECT_NEW(object, rtn)
-#define PyMac_INIT_TOOLBOX_OBJECT_CONVERT(object, rtn)
-#endif /* USE_TOOLBOX_OBJECT_GLUE */
-
-/* macfs exports */
-#ifndef __LP64__
-int PyMac_GetFSSpec(PyObject *, FSSpec *); /* argument parser for FSSpec */
-PyObject *PyMac_BuildFSSpec(FSSpec *); /* Convert FSSpec to PyObject */
-#endif /* !__LP64__ */
-
-int PyMac_GetFSRef(PyObject *, FSRef *); /* argument parser for FSRef */
-PyObject *PyMac_BuildFSRef(FSRef *); /* Convert FSRef to PyObject */
-
-/* AE exports */
-extern PyObject *AEDesc_New(AppleEvent *); /* XXXX Why passed by address?? */
-extern PyObject *AEDesc_NewBorrowed(AppleEvent *);
-extern int AEDesc_Convert(PyObject *, AppleEvent *);
-
-/* Cm exports */
-extern PyObject *CmpObj_New(Component);
-extern int CmpObj_Convert(PyObject *, Component *);
-extern PyObject *CmpInstObj_New(ComponentInstance);
-extern int CmpInstObj_Convert(PyObject *, ComponentInstance *);
-
-/* Ctl exports */
-#ifndef __LP64__
-extern PyObject *CtlObj_New(ControlHandle);
-extern int CtlObj_Convert(PyObject *, ControlHandle *);
-#endif /* !__LP64__ */
-
-/* Dlg exports */
-#ifndef __LP64__
-extern PyObject *DlgObj_New(DialogPtr);
-extern int DlgObj_Convert(PyObject *, DialogPtr *);
-extern PyObject *DlgObj_WhichDialog(DialogPtr);
-#endif /* !__LP64__ */
-
-/* Drag exports */
-#ifndef __LP64__
-extern PyObject *DragObj_New(DragReference);
-extern int DragObj_Convert(PyObject *, DragReference *);
-#endif /* !__LP64__ */
-
-/* List exports */
-#ifndef __LP64__
-extern PyObject *ListObj_New(ListHandle);
-extern int ListObj_Convert(PyObject *, ListHandle *);
-#endif /* !__LP64__ */
-
-/* Menu exports */
-#ifndef __LP64__
-extern PyObject *MenuObj_New(MenuHandle);
-extern int MenuObj_Convert(PyObject *, MenuHandle *);
-#endif /* !__LP64__ */
-
-/* Qd exports */
-#ifndef __LP64__
-extern PyObject *GrafObj_New(GrafPtr);
-extern int GrafObj_Convert(PyObject *, GrafPtr *);
-extern PyObject *BMObj_New(BitMapPtr);
-extern int BMObj_Convert(PyObject *, BitMapPtr *);
-extern PyObject *QdRGB_New(RGBColor *);
-extern int QdRGB_Convert(PyObject *, RGBColor *);
-#endif /* !__LP64__ */
-
-/* Qdoffs exports */
-#ifndef __LP64__
-extern PyObject *GWorldObj_New(GWorldPtr);
-extern int GWorldObj_Convert(PyObject *, GWorldPtr *);
-#endif /* !__LP64__ */
-
-/* Qt exports */
-#ifndef __LP64__
-extern PyObject *TrackObj_New(Track);
-extern int TrackObj_Convert(PyObject *, Track *);
-extern PyObject *MovieObj_New(Movie);
-extern int MovieObj_Convert(PyObject *, Movie *);
-extern PyObject *MovieCtlObj_New(MovieController);
-extern int MovieCtlObj_Convert(PyObject *, MovieController *);
-extern PyObject *TimeBaseObj_New(TimeBase);
-extern int TimeBaseObj_Convert(PyObject *, TimeBase *);
-extern PyObject *UserDataObj_New(UserData);
-extern int UserDataObj_Convert(PyObject *, UserData *);
-extern PyObject *MediaObj_New(Media);
-extern int MediaObj_Convert(PyObject *, Media *);
-#endif /* !__LP64__ */
-
-/* Res exports */
-extern PyObject *ResObj_New(Handle);
-extern int ResObj_Convert(PyObject *, Handle *);
-extern PyObject *OptResObj_New(Handle);
-extern int OptResObj_Convert(PyObject *, Handle *);
-
-/* TE exports */
-#ifndef __LP64__
-extern PyObject *TEObj_New(TEHandle);
-extern int TEObj_Convert(PyObject *, TEHandle *);
-#endif /* !__LP64__ */
-
-/* Win exports */
-#ifndef __LP64__
-extern PyObject *WinObj_New(WindowPtr);
-extern int WinObj_Convert(PyObject *, WindowPtr *);
-extern PyObject *WinObj_WhichWindow(WindowPtr);
-#endif /* !__LP64__ */
-
-/* CF exports */
-extern PyObject *CFObj_New(CFTypeRef);
-extern int CFObj_Convert(PyObject *, CFTypeRef *);
-extern PyObject *CFTypeRefObj_New(CFTypeRef);
-extern int CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
-extern PyObject *CFStringRefObj_New(CFStringRef);
-extern int CFStringRefObj_Convert(PyObject *, CFStringRef *);
-extern PyObject *CFMutableStringRefObj_New(CFMutableStringRef);
-extern int CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *);
-extern PyObject *CFArrayRefObj_New(CFArrayRef);
-extern int CFArrayRefObj_Convert(PyObject *, CFArrayRef *);
-extern PyObject *CFMutableArrayRefObj_New(CFMutableArrayRef);
-extern int CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *);
-extern PyObject *CFDictionaryRefObj_New(CFDictionaryRef);
-extern int CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *);
-extern PyObject *CFMutableDictionaryRefObj_New(CFMutableDictionaryRef);
-extern int CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *);
-extern PyObject *CFURLRefObj_New(CFURLRef);
-extern int CFURLRefObj_Convert(PyObject *, CFURLRef *);
-extern int OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *);
-
-#ifdef __cplusplus
- }
-#endif
-#endif
diff --git a/Include/pymath.h b/Include/pymath.h
index e3cf22b8237..b4eda66e6e2 100644
--- a/Include/pymath.h
+++ b/Include/pymath.h
@@ -67,6 +67,7 @@ extern double copysign(double, double);
nothing. */
/* we take double rounding as evidence of x87 usage */
+#ifndef Py_LIMITED_API
#ifndef Py_FORCE_DOUBLE
# ifdef X87_DOUBLE_ROUNDING
PyAPI_FUNC(double) _Py_force_double(double);
@@ -75,11 +76,14 @@ PyAPI_FUNC(double) _Py_force_double(double);
# define Py_FORCE_DOUBLE(X) (X)
# endif
#endif
+#endif
+#ifndef Py_LIMITED_API
#ifdef HAVE_GCC_ASM_FOR_X87
PyAPI_FUNC(unsigned short) _Py_get_387controlword(void);
PyAPI_FUNC(void) _Py_set_387controlword(unsigned short);
#endif
+#endif
/* Py_IS_NAN(X)
* Return 1 if float or double arg is a NaN, else 0.
diff --git a/Include/pyport.h b/Include/pyport.h
index 85e852f8b08..c74ff9c7a4b 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -41,17 +41,6 @@ Used in: PY_LONG_LONG
**************************************************************************/
-
-/* For backward compatibility only. Obsolete, do not use. */
-#ifdef HAVE_PROTOTYPES
-#define Py_PROTO(x) x
-#else
-#define Py_PROTO(x) ()
-#endif
-#ifndef Py_FPROTO
-#define Py_FPROTO(x) Py_PROTO(x)
-#endif
-
/* typedefs for some C9X-defined synonyms for integral types.
*
* The names in Python are exactly the same as the C9X names, except with a
@@ -73,15 +62,20 @@ Used in: PY_LONG_LONG
#define PY_LLONG_MAX LLONG_MAX
#define PY_ULLONG_MAX ULLONG_MAX
#elif defined(__LONG_LONG_MAX__)
-/* Otherwise, if GCC has a builtin define, use that. */
+/* Otherwise, if GCC has a builtin define, use that. (Definition of
+ * PY_LLONG_MIN assumes two's complement with no trap representation.) */
#define PY_LLONG_MAX __LONG_LONG_MAX__
-#define PY_LLONG_MIN (-PY_LLONG_MAX-1)
-#define PY_ULLONG_MAX (__LONG_LONG_MAX__*2ULL + 1ULL)
-#else
-/* Otherwise, rely on two's complement. */
-#define PY_ULLONG_MAX (~0ULL)
-#define PY_LLONG_MAX ((long long)(PY_ULLONG_MAX>>1))
-#define PY_LLONG_MIN (-PY_LLONG_MAX-1)
+#define PY_LLONG_MIN (-PY_LLONG_MAX - 1)
+#define PY_ULLONG_MAX (PY_LLONG_MAX * Py_ULL(2) + 1)
+#elif defined(SIZEOF_LONG_LONG)
+/* Otherwise compute from SIZEOF_LONG_LONG, assuming two's complement, no
+ padding bits, and no trap representation. Note: PY_ULLONG_MAX was
+ previously #defined as (~0ULL) here; but that'll give the wrong value in a
+ preprocessor expression on systems where long long != intmax_t. */
+#define PY_LLONG_MAX \
+ (1 + 2 * ((Py_LL(1) << (CHAR_BIT * SIZEOF_LONG_LONG - 2)) - 1))
+#define PY_LLONG_MIN (-PY_LLONG_MAX - 1)
+#define PY_ULLONG_MAX (PY_LLONG_MAX * Py_ULL(2) + 1)
#endif /* LLONG_MAX */
#endif
#endif /* HAVE_LONG_LONG */
@@ -150,6 +144,23 @@ Used in: PY_LONG_LONG
#endif
#endif
+/* Prime multiplier used in string and various other hashes. */
+#define _PyHASH_MULTIPLIER 1000003UL /* 0xf4243 */
+
+/* Parameters used for the numeric hash implementation. See notes for
+ _PyHash_Double in Objects/object.c. Numeric hashes are based on
+ reduction modulo the prime 2**_PyHASH_BITS - 1. */
+
+#if SIZEOF_VOID_P >= 8
+#define _PyHASH_BITS 61
+#else
+#define _PyHASH_BITS 31
+#endif
+#define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1)
+#define _PyHASH_INF 314159
+#define _PyHASH_NAN 0
+#define _PyHASH_IMAG _PyHASH_MULTIPLIER
+
/* uintptr_t is the C9X name for an unsigned integral type such that a
* legitimate void* can be cast to uintptr_t and then back to void* again
* without loss of information. Similarly for intptr_t, wrt a signed
@@ -187,6 +198,11 @@ typedef Py_intptr_t Py_ssize_t;
# error "Python needs a typedef for Py_ssize_t in pyport.h."
#endif
+/* Py_hash_t is the same size as a pointer. */
+typedef Py_ssize_t Py_hash_t;
+/* Py_uhash_t is the unsigned equivalent needed to calculate numeric hash. */
+typedef size_t Py_uhash_t;
+
/* Largest possible value of size_t.
SIZE_MAX is part of C99, so it might be defined on some
platforms. If it is not defined, (size_t)-1 is a portable
@@ -216,9 +232,10 @@ typedef Py_intptr_t Py_ssize_t;
* all platforms (Python interprets the format string itself, and does whatever
* the platform C requires to convert a size_t/Py_ssize_t argument):
*
- * PyString_FromFormat
+ * PyBytes_FromFormat
* PyErr_Format
- * PyString_FromFormatV
+ * PyBytes_FromFormatV
+ * PyUnicode_FromFormatV
*
* Lower-level uses require that you interpolate the correct format modifier
* yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for
@@ -275,8 +292,6 @@ typedef Py_intptr_t Py_ssize_t;
* should keep using static.
*/
-#undef USE_INLINE /* XXX - set via configure? */
-
#if defined(_MSC_VER)
#if defined(PY_LOCAL_AGGRESSIVE)
/* enable more aggressive optimization for visual studio */
@@ -347,9 +362,7 @@ typedef Py_intptr_t Py_ssize_t;
/* NB caller must include <sys/types.h> */
#ifdef HAVE_SYS_SELECT_H
-
#include <sys/select.h>
-
#endif /* !HAVE_SYS_SELECT_H */
/*******************************
@@ -378,11 +391,6 @@ typedef Py_intptr_t Py_ssize_t;
#define HAVE_FSTAT
#endif
-#ifdef RISCOS
-#include <sys/types.h>
-#include "unixstuff.h"
-#endif
-
#ifdef HAVE_SYS_STAT_H
#if defined(PYOS_OS2) && defined(PYCC_GCC)
#include <sys/types.h>
@@ -618,6 +626,7 @@ extern "C" {
#define PY_NO_SHORT_FLOAT_REPR
#endif
+
/* Py_DEPRECATED(version)
* Declare a variable, type, or function deprecated.
* Usage:
@@ -645,12 +654,6 @@ in platform-specific #ifdefs.
extern int gethostname(char *, int);
#endif
-#ifdef __BEOS__
-/* Unchecked */
-/* It's in the libs, but not the headers... - [cjh] */
-int shutdown( int, int );
-#endif
-
#ifdef HAVE__GETPTY
#include <sys/types.h> /* we need to import mode_t */
extern char * _getpty(int *, int, mode_t, int);
@@ -659,12 +662,12 @@ extern char * _getpty(int *, int, mode_t, int);
/* On QNX 6, struct termio must be declared by including sys/termio.h
if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must
be included before termios.h or it will generate an error. */
-#if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux)
+#ifdef HAVE_SYS_TERMIO_H
#include <sys/termio.h>
#endif
#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
-#if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) && !defined(HAVE_UTIL_H)
+#if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H)
/* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
functions, even though they are included in libutil. */
#include <termios.h>
@@ -674,25 +677,6 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
-/* These are pulled from various places. It isn't obvious on what platforms
- they are necessary, nor what the exact prototype should look like (which
- is likely to vary between platforms!) If you find you need one of these
- declarations, please move them to a platform-specific block and include
- proper prototypes. */
-#if 0
-
-/* From Modules/resource.c */
-extern int getrusage();
-extern int getpagesize();
-
-/* From Python/sysmodule.c and Modules/posixmodule.c */
-extern int fclose(FILE *);
-
-/* From Modules/posixmodule.c */
-extern int fdatasync(int);
-#endif /* 0 */
-
-
/* On 4.4BSD-descendants, ctype functions serves the whole range of
* wchar_t character set rather than single byte code points only.
* This characteristic can break some operations of string object
@@ -748,10 +732,10 @@ extern int fdatasync(int);
/*
All windows ports, except cygwin, are handled in PC/pyconfig.h.
- BeOS and cygwin are the only other autoconf platform requiring special
- linkage handling and both of these use __declspec().
+ Cygwin is the only other autoconf platform requiring special
+ linkage handling and it uses __declspec().
*/
-#if defined(__CYGWIN__) || defined(__BEOS__)
+#if defined(__CYGWIN__)
# define HAVE_DECLSPEC_DLL
#endif
@@ -762,11 +746,11 @@ extern int fdatasync(int);
# define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
# define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
/* module init functions inside the core need no external linkage */
- /* except for Cygwin to handle embedding (FIXME: BeOS too?) */
+ /* except for Cygwin to handle embedding */
# if defined(__CYGWIN__)
-# define PyMODINIT_FUNC __declspec(dllexport) void
+# define PyMODINIT_FUNC __declspec(dllexport) PyObject*
# else /* __CYGWIN__ */
-# define PyMODINIT_FUNC void
+# define PyMODINIT_FUNC PyObject*
# endif /* __CYGWIN__ */
# else /* Py_BUILD_CORE */
/* Building an extension module, or an embedded situation */
@@ -780,9 +764,9 @@ extern int fdatasync(int);
# define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
/* module init functions outside the core must be exported */
# if defined(__cplusplus)
-# define PyMODINIT_FUNC extern "C" __declspec(dllexport) void
+# define PyMODINIT_FUNC extern "C" __declspec(dllexport) PyObject*
# else /* __cplusplus */
-# define PyMODINIT_FUNC __declspec(dllexport) void
+# define PyMODINIT_FUNC __declspec(dllexport) PyObject*
# endif /* __cplusplus */
# endif /* Py_BUILD_CORE */
# endif /* HAVE_DECLSPEC */
@@ -797,62 +781,12 @@ extern int fdatasync(int);
#endif
#ifndef PyMODINIT_FUNC
# if defined(__cplusplus)
-# define PyMODINIT_FUNC extern "C" void
+# define PyMODINIT_FUNC extern "C" PyObject*
# else /* __cplusplus */
-# define PyMODINIT_FUNC void
+# define PyMODINIT_FUNC PyObject*
# endif /* __cplusplus */
#endif
-/* Deprecated DL_IMPORT and DL_EXPORT macros */
-#if defined(Py_ENABLE_SHARED) && defined (HAVE_DECLSPEC_DLL)
-# if defined(Py_BUILD_CORE)
-# define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
-# define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
-# else
-# define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
-# define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
-# endif
-#endif
-#ifndef DL_EXPORT
-# define DL_EXPORT(RTYPE) RTYPE
-#endif
-#ifndef DL_IMPORT
-# define DL_IMPORT(RTYPE) RTYPE
-#endif
-/* End of deprecated DL_* macros */
-
-/* If the fd manipulation macros aren't defined,
- here is a set that should do the job */
-
-#if 0 /* disabled and probably obsolete */
-
-#ifndef FD_SETSIZE
-#define FD_SETSIZE 256
-#endif
-
-#ifndef FD_SET
-
-typedef long fd_mask;
-
-#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
-#ifndef howmany
-#define howmany(x, y) (((x)+((y)-1))/(y))
-#endif /* howmany */
-
-typedef struct fd_set {
- fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
-} fd_set;
-
-#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
-#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
-#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
-#define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p)))
-
-#endif /* FD_SET */
-
-#endif /* fd manipulation macros */
-
-
/* limits.h constants that may be missing */
#ifndef INT_MAX
@@ -894,8 +828,7 @@ typedef struct fd_set {
* Hide GCC attributes from compilers that don't support them.
*/
#if (!defined(__GNUC__) || __GNUC__ < 2 || \
- (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) && \
- !defined(RISCOS)
+ (__GNUC__ == 2 && __GNUC_MINOR__ < 7) )
#define Py_GCC_ATTRIBUTE(x)
#else
#define Py_GCC_ATTRIBUTE(x) __attribute__(x)
@@ -938,4 +871,14 @@ typedef struct fd_set {
#define Py_ULL(x) Py_LL(x##U)
#endif
+#ifdef VA_LIST_IS_ARRAY
+#define Py_VA_COPY(x, y) Py_MEMCPY((x), (y), sizeof(va_list))
+#else
+#ifdef __va_copy
+#define Py_VA_COPY __va_copy
+#else
+#define Py_VA_COPY(x, y) (x) = (y)
+#endif
+#endif
+
#endif /* Py_PYPORT_H */
diff --git a/Include/pystate.h b/Include/pystate.h
index f2cfc30208f..060efa7ffd5 100644
--- a/Include/pystate.h
+++ b/Include/pystate.h
@@ -13,12 +13,16 @@ extern "C" {
struct _ts; /* Forward */
struct _is; /* Forward */
+#ifdef Py_LIMITED_API
+typedef struct _is PyInterpreterState;
+#else
typedef struct _is {
struct _is *next;
struct _ts *tstate_head;
PyObject *modules;
+ PyObject *modules_by_index;
PyObject *sysdict;
PyObject *builtins;
PyObject *modules_reloading;
@@ -26,6 +30,8 @@ typedef struct _is {
PyObject *codec_search_path;
PyObject *codec_search_cache;
PyObject *codec_error_registry;
+ int codecs_initialized;
+ int fscodec_initialized;
#ifdef HAVE_DLOPEN
int dlopenflags;
@@ -35,12 +41,14 @@ typedef struct _is {
#endif
} PyInterpreterState;
+#endif
/* State unique per thread */
struct _frame; /* Avoid including frameobject.h */
+#ifndef Py_LIMITED_API
/* Py_tracefunc return -1 when raising an exception, or 0 for success. */
typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);
@@ -52,7 +60,11 @@ typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);
#define PyTrace_C_CALL 4
#define PyTrace_C_EXCEPTION 5
#define PyTrace_C_RETURN 6
+#endif
+#ifdef Py_LIMITED_API
+typedef struct _ts PyThreadState;
+#else
typedef struct _ts {
/* See Python/ceval.c for comments explaining most fields */
@@ -61,6 +73,10 @@ typedef struct _ts {
struct _frame *frame;
int recursion_depth;
+ char overflowed; /* The stack has overflowed. Allow 50 more calls
+ to handle the runtime error. */
+ char recursion_critical; /* The current calls must not cause
+ a stack overflow. */
/* 'tracing' keeps track of the execution depth when tracing/profiling.
This is to prevent the actual trace/profile code from being recorded in
the trace/profile. */
@@ -82,6 +98,8 @@ typedef struct _ts {
PyObject *dict; /* Stores per-thread state */
+ /* XXX doesn't mean anything anymore (the comment below is obsolete)
+ => deprecate or remove? */
/* tick_counter is incremented whenever the check_interval ticker
* reaches zero. The purpose is to give a useful measure of the number
* of interpreted bytecode instructions in a given thread. This
@@ -101,11 +119,14 @@ typedef struct _ts {
/* XXX signal handlers should also be here */
} PyThreadState;
+#endif
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
+PyAPI_FUNC(int) _PyState_AddModule(PyObject*, struct PyModuleDef*);
+PyAPI_FUNC(PyObject*) PyState_FindModule(struct PyModuleDef*);
PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);
@@ -114,6 +135,7 @@ PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
#ifdef WITH_THREAD
PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
+PyAPI_FUNC(void) _PyGILState_Reinit(void);
#endif
PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
@@ -124,12 +146,17 @@ PyAPI_FUNC(int) PyThreadState_SetAsyncExc(long, PyObject *);
/* Variable and macro for in-line access to current thread state */
-PyAPI_DATA(PyThreadState *) _PyThreadState_Current;
+/* Assuming the current thread holds the GIL, this is the
+ PyThreadState for the current thread. */
+#ifndef Py_LIMITED_API
+PyAPI_DATA(_Py_atomic_address) _PyThreadState_Current;
+#endif
-#ifdef Py_DEBUG
+#if defined(Py_DEBUG) || defined(Py_LIMITED_API)
#define PyThreadState_GET() PyThreadState_Get()
#else
-#define PyThreadState_GET() (_PyThreadState_Current)
+#define PyThreadState_GET() \
+ ((PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current))
#endif
typedef
@@ -180,19 +207,25 @@ PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void);
/* The implementation of sys._current_frames() Returns a dict mapping
thread id to that thread's current frame.
*/
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyThread_CurrentFrames(void);
+#endif
/* Routines for advanced debuggers, requested by David Beazley.
Don't use unless you know what you are doing! */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void);
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);
PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);
+#endif
/* hook for PyEval_GetFrame(), requested for Psyco */
+#ifndef Py_LIMITED_API
PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame;
+#endif
#ifdef __cplusplus
}
diff --git a/Include/pystrcmp.h b/Include/pystrcmp.h
index 369c7e77ff6..edb12397e3c 100644
--- a/Include/pystrcmp.h
+++ b/Include/pystrcmp.h
@@ -8,7 +8,7 @@ extern "C" {
PyAPI_FUNC(int) PyOS_mystrnicmp(const char *, const char *, Py_ssize_t);
PyAPI_FUNC(int) PyOS_mystricmp(const char *, const char *);
-#if defined(MS_WINDOWS) || defined(PYOS_OS2)
+#ifdef MS_WINDOWS
#define PyOS_strnicmp strnicmp
#define PyOS_stricmp stricmp
#else
diff --git a/Include/pystrtod.h b/Include/pystrtod.h
index eec434f1bd1..23fd1c62551 100644
--- a/Include/pystrtod.h
+++ b/Include/pystrtod.h
@@ -6,12 +6,6 @@ extern "C" {
#endif
-PyAPI_FUNC(double) PyOS_ascii_strtod(const char *str, char **ptr);
-PyAPI_FUNC(double) PyOS_ascii_atof(const char *str);
-
-/* Deprecated in 2.7 and 3.1. Will disappear in 2.8 (if it exists) and 3.2 */
-PyAPI_FUNC(char *) PyOS_ascii_formatd(char *buffer, size_t buf_len,
- const char *format, double d);
PyAPI_FUNC(double) PyOS_string_to_double(const char *str,
char **endptr,
PyObject *overflow_exception);
@@ -24,7 +18,9 @@ PyAPI_FUNC(char *) PyOS_double_to_string(double val,
int flags,
int *type);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(double) _Py_parse_inf_or_nan(const char *p, char **endptr);
+#endif
/* PyOS_double_to_string's "flags" parameter can be set to 0 or more of: */
diff --git a/Include/pythonrun.h b/Include/pythonrun.h
index 6bfc1750500..e244ce713b0 100644
--- a/Include/pythonrun.h
+++ b/Include/pythonrun.h
@@ -9,21 +9,24 @@ extern "C" {
#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
- CO_FUTURE_UNICODE_LITERALS)
+ CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL)
#define PyCF_MASK_OBSOLETE (CO_NESTED)
#define PyCF_SOURCE_IS_UTF8 0x0100
#define PyCF_DONT_IMPLY_DEDENT 0x0200
#define PyCF_ONLY_AST 0x0400
+#define PyCF_IGNORE_COOKIE 0x0800
+#ifndef Py_LIMITED_API
typedef struct {
int cf_flags; /* bitmask of CO_xxx flags relevant to future */
} PyCompilerFlags;
+#endif
-PyAPI_FUNC(void) Py_SetProgramName(char *);
-PyAPI_FUNC(char *) Py_GetProgramName(void);
+PyAPI_FUNC(void) Py_SetProgramName(wchar_t *);
+PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
-PyAPI_FUNC(void) Py_SetPythonHome(char *);
-PyAPI_FUNC(char *) Py_GetPythonHome(void);
+PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *);
+PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
PyAPI_FUNC(void) Py_Initialize(void);
PyAPI_FUNC(void) Py_InitializeEx(int);
@@ -32,54 +35,113 @@ PyAPI_FUNC(int) Py_IsInitialized(void);
PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);
PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);
-PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
-PyAPI_FUNC(int) PyRun_AnyFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
-PyAPI_FUNC(int) PyRun_SimpleFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
-PyAPI_FUNC(int) PyRun_InteractiveOneFlags(FILE *, const char *, PyCompilerFlags *);
-PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(FILE *, const char *, PyCompilerFlags *);
-
-PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(const char *, const char *,
- int, PyCompilerFlags *flags,
- PyArena *);
-PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(FILE *, const char *, int,
- char *, char *,
- PyCompilerFlags *, int *,
- PyArena *);
+PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
+PyAPI_FUNC(int) PyRun_AnyFileExFlags(
+ FILE *fp,
+ const char *filename, /* decoded from the filesystem encoding */
+ int closeit,
+ PyCompilerFlags *flags);
+PyAPI_FUNC(int) PyRun_SimpleFileExFlags(
+ FILE *fp,
+ const char *filename, /* decoded from the filesystem encoding */
+ int closeit,
+ PyCompilerFlags *flags);
+PyAPI_FUNC(int) PyRun_InteractiveOneFlags(
+ FILE *fp,
+ const char *filename, /* decoded from the filesystem encoding */
+ PyCompilerFlags *flags);
+PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(
+ FILE *fp,
+ const char *filename, /* decoded from the filesystem encoding */
+ PyCompilerFlags *flags);
+
+PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(
+ const char *s,
+ const char *filename, /* decoded from the filesystem encoding */
+ int start,
+ PyCompilerFlags *flags,
+ PyArena *arena);
+PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(
+ FILE *fp,
+ const char *filename, /* decoded from the filesystem encoding */
+ const char* enc,
+ int start,
+ char *ps1,
+ char *ps2,
+ PyCompilerFlags *flags,
+ int *errcode,
+ PyArena *arena);
+#endif
+
+#ifndef PyParser_SimpleParseString
#define PyParser_SimpleParseString(S, B) \
PyParser_SimpleParseStringFlags(S, B, 0)
#define PyParser_SimpleParseFile(FP, S, B) \
PyParser_SimpleParseFileFlags(FP, S, B, 0)
+#endif
PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
int);
PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
int, int);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
PyObject *, PyCompilerFlags *);
-PyAPI_FUNC(PyObject *) PyRun_FileExFlags(FILE *, const char *, int,
- PyObject *, PyObject *, int,
- PyCompilerFlags *);
+PyAPI_FUNC(PyObject *) PyRun_FileExFlags(
+ FILE *fp,
+ const char *filename, /* decoded from the filesystem encoding */
+ int start,
+ PyObject *globals,
+ PyObject *locals,
+ int closeit,
+ PyCompilerFlags *flags);
+#endif
-#define Py_CompileString(str, p, s) Py_CompileStringFlags(str, p, s, NULL)
-PyAPI_FUNC(PyObject *) Py_CompileStringFlags(const char *, const char *, int,
- PyCompilerFlags *);
-PyAPI_FUNC(struct symtable *) Py_SymtableString(const char *, const char *, int);
+#ifdef Py_LIMITED_API
+PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);
+#else
+#define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1)
+#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1)
+PyAPI_FUNC(PyObject *) Py_CompileStringExFlags(
+ const char *str,
+ const char *filename, /* decoded from the filesystem encoding */
+ int start,
+ PyCompilerFlags *flags,
+ int optimize);
+#endif
+PyAPI_FUNC(struct symtable *) Py_SymtableString(
+ const char *str,
+ const char *filename, /* decoded from the filesystem encoding */
+ int start);
PyAPI_FUNC(void) PyErr_Print(void);
PyAPI_FUNC(void) PyErr_PrintEx(int);
PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
+/* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level
+ * exit functions.
+ */
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(void) _Py_PyAtExit(void (*func)(void));
+#endif
PyAPI_FUNC(int) Py_AtExit(void (*func)(void));
PyAPI_FUNC(void) Py_Exit(int);
+/* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(void) _Py_RestoreSignals(void);
+
PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
+#endif
/* Bootstrap */
-PyAPI_FUNC(int) Py_Main(int argc, char **argv);
+PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
+#ifndef Py_LIMITED_API
/* Use macros for a bunch of old variants */
#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
@@ -98,12 +160,17 @@ PyAPI_FUNC(int) Py_Main(int argc, char **argv);
PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
#define PyRun_FileFlags(fp, p, s, g, l, flags) \
PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
+#endif
/* In getpath.c */
-PyAPI_FUNC(char *) Py_GetProgramFullPath(void);
-PyAPI_FUNC(char *) Py_GetPrefix(void);
-PyAPI_FUNC(char *) Py_GetExecPrefix(void);
-PyAPI_FUNC(char *) Py_GetPath(void);
+PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
+PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
+PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
+PyAPI_FUNC(wchar_t *) Py_GetPath(void);
+PyAPI_FUNC(void) Py_SetPath(const wchar_t *);
+#ifdef MS_WINDOWS
+int _Py_CheckPython3();
+#endif
/* In their own files */
PyAPI_FUNC(const char *) Py_GetVersion(void);
@@ -111,26 +178,29 @@ PyAPI_FUNC(const char *) Py_GetPlatform(void);
PyAPI_FUNC(const char *) Py_GetCopyright(void);
PyAPI_FUNC(const char *) Py_GetCompiler(void);
PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(const char *) _Py_svnversion(void);
PyAPI_FUNC(const char *) Py_SubversionRevision(void);
PyAPI_FUNC(const char *) Py_SubversionShortBranch(void);
PyAPI_FUNC(const char *) _Py_hgidentifier(void);
PyAPI_FUNC(const char *) _Py_hgversion(void);
+#endif
/* Internal -- various one-time initializations */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
PyAPI_FUNC(PyObject *) _PySys_Init(void);
PyAPI_FUNC(void) _PyImport_Init(void);
PyAPI_FUNC(void) _PyExc_Init(void);
PyAPI_FUNC(void) _PyImportHooks_Init(void);
PyAPI_FUNC(int) _PyFrame_Init(void);
-PyAPI_FUNC(int) _PyInt_Init(void);
-PyAPI_FUNC(int) _PyLong_Init(void);
PyAPI_FUNC(void) _PyFloat_Init(void);
PyAPI_FUNC(int) PyByteArray_Init(void);
PyAPI_FUNC(void) _PyRandom_Init(void);
+#endif
/* Various internal finalizers */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(void) _PyExc_Fini(void);
PyAPI_FUNC(void) _PyImport_Fini(void);
PyAPI_FUNC(void) PyMethod_Fini(void);
@@ -140,17 +210,24 @@ PyAPI_FUNC(void) PyDict_Fini(void);
PyAPI_FUNC(void) PyTuple_Fini(void);
PyAPI_FUNC(void) PyList_Fini(void);
PyAPI_FUNC(void) PySet_Fini(void);
-PyAPI_FUNC(void) PyString_Fini(void);
-PyAPI_FUNC(void) PyInt_Fini(void);
+PyAPI_FUNC(void) PyBytes_Fini(void);
+PyAPI_FUNC(void) PyByteArray_Fini(void);
PyAPI_FUNC(void) PyFloat_Fini(void);
PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
-PyAPI_FUNC(void) PyByteArray_Fini(void);
+PyAPI_FUNC(void) _PyGC_Fini(void);
+
+PyAPI_DATA(PyThreadState *) _Py_Finalizing;
+#endif
/* Stuff with no proper home (yet) */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, char *);
+#endif
PyAPI_DATA(int) (*PyOS_InputHook)(void);
PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *);
+#ifndef Py_LIMITED_API
PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
+#endif
/* Stack size, in "pointers" (so we get extra safety margins
on 64-bit platforms). On a 32-bit platform, this translates
diff --git a/Include/pythread.h b/Include/pythread.h
index dfd61575ea1..9806c61159b 100644
--- a/Include/pythread.h
+++ b/Include/pythread.h
@@ -9,6 +9,14 @@ typedef void *PyThread_type_sema;
extern "C" {
#endif
+/* Return status codes for Python lock acquisition. Chosen for maximum
+ * backwards compatibility, ie failure -> 0, success -> 1. */
+typedef enum PyLockStatus {
+ PY_LOCK_FAILURE = 0,
+ PY_LOCK_ACQUIRED = 1,
+ PY_LOCK_INTR
+} PyLockStatus;
+
PyAPI_FUNC(void) PyThread_init_thread(void);
PyAPI_FUNC(long) PyThread_start_new_thread(void (*)(void *), void *);
PyAPI_FUNC(void) PyThread_exit_thread(void);
@@ -19,6 +27,48 @@ PyAPI_FUNC(void) PyThread_free_lock(PyThread_type_lock);
PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int);
#define WAIT_LOCK 1
#define NOWAIT_LOCK 0
+
+/* PY_TIMEOUT_T is the integral type used to specify timeouts when waiting
+ on a lock (see PyThread_acquire_lock_timed() below).
+ PY_TIMEOUT_MAX is the highest usable value (in microseconds) of that
+ type, and depends on the system threading API.
+
+ NOTE: this isn't the same value as `_thread.TIMEOUT_MAX`. The _thread
+ module exposes a higher-level API, with timeouts expressed in seconds
+ and floating-point numbers allowed.
+*/
+#if defined(HAVE_LONG_LONG)
+#define PY_TIMEOUT_T PY_LONG_LONG
+#define PY_TIMEOUT_MAX PY_LLONG_MAX
+#else
+#define PY_TIMEOUT_T long
+#define PY_TIMEOUT_MAX LONG_MAX
+#endif
+
+/* In the NT API, the timeout is a DWORD and is expressed in milliseconds */
+#if defined (NT_THREADS)
+#if (Py_LL(0xFFFFFFFF) * 1000 < PY_TIMEOUT_MAX)
+#undef PY_TIMEOUT_MAX
+#define PY_TIMEOUT_MAX (Py_LL(0xFFFFFFFF) * 1000)
+#endif
+#endif
+
+/* If microseconds == 0, the call is non-blocking: it returns immediately
+ even when the lock can't be acquired.
+ If microseconds > 0, the call waits up to the specified duration.
+ If microseconds < 0, the call waits until success (or abnormal failure)
+
+ microseconds must be less than PY_TIMEOUT_MAX. Behaviour otherwise is
+ undefined.
+
+ If intr_flag is true and the acquire is interrupted by a signal, then the
+ call will return PY_LOCK_INTR. The caller may reattempt to acquire the
+ lock.
+*/
+PyAPI_FUNC(PyLockStatus) PyThread_acquire_lock_timed(PyThread_type_lock,
+ PY_TIMEOUT_T microseconds,
+ int intr_flag);
+
PyAPI_FUNC(void) PyThread_release_lock(PyThread_type_lock);
PyAPI_FUNC(size_t) PyThread_get_stacksize(void);
diff --git a/Include/pytime.h b/Include/pytime.h
new file mode 100644
index 00000000000..d707bdb9a87
--- /dev/null
+++ b/Include/pytime.h
@@ -0,0 +1,48 @@
+#ifndef Py_LIMITED_API
+#ifndef Py_PYTIME_H
+#define Py_PYTIME_H
+
+#include "pyconfig.h" /* include for defines */
+
+/**************************************************************************
+Symbols and macros to supply platform-independent interfaces to time related
+functions and constants
+**************************************************************************/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef HAVE_GETTIMEOFDAY
+typedef struct timeval _PyTime_timeval;
+#else
+typedef struct {
+ time_t tv_sec; /* seconds since Jan. 1, 1970 */
+ long tv_usec; /* and microseconds */
+} _PyTime_timeval;
+#endif
+
+/* Similar to POSIX gettimeofday but cannot fail. If system gettimeofday
+ * fails or is not available, fall back to lower resolution clocks.
+ */
+PyAPI_FUNC(void) _PyTime_gettimeofday(_PyTime_timeval *tp);
+
+#define _PyTime_ADD_SECONDS(tv, interval) \
+do { \
+ tv.tv_usec += (long) (((long) interval - interval) * 1000000); \
+ tv.tv_sec += (time_t) interval + (time_t) (tv.tv_usec / 1000000); \
+ tv.tv_usec %= 1000000; \
+} while (0)
+
+#define _PyTime_INTERVAL(tv_start, tv_end) \
+ ((tv_end.tv_sec - tv_start.tv_sec) + \
+ (tv_end.tv_usec - tv_start.tv_usec) * 0.000001)
+
+/* Dummy to force linking. */
+PyAPI_FUNC(void) _PyTime_Init(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* Py_PYTIME_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/rangeobject.h b/Include/rangeobject.h
index 36c9cee5a87..7e4dc28894b 100644
--- a/Include/rangeobject.h
+++ b/Include/rangeobject.h
@@ -7,9 +7,6 @@
extern "C" {
#endif
-/* This is about the type 'xrange', not the built-in function range(), which
- returns regular lists. */
-
/*
A range object represents an integer range. This is an immutable object;
a range cannot change its value after creation.
@@ -19,6 +16,8 @@ they are represented by a start, stop, and step datamembers.
*/
PyAPI_DATA(PyTypeObject) PyRange_Type;
+PyAPI_DATA(PyTypeObject) PyRangeIter_Type;
+PyAPI_DATA(PyTypeObject) PyLongRangeIter_Type;
#define PyRange_Check(op) (Py_TYPE(op) == &PyRange_Type)
diff --git a/Include/setobject.h b/Include/setobject.h
index 52b07d52df1..623411101d5 100644
--- a/Include/setobject.h
+++ b/Include/setobject.h
@@ -18,11 +18,12 @@ Note: .pop() abuses the hash field of an Unused or Dummy slot to
hold a search finger. The hash field of Unused or Dummy slots has
no meaning otherwise.
*/
-
+#ifndef Py_LIMITED_API
#define PySet_MINSIZE 8
typedef struct {
- long hash; /* cached hash code for the entry key */
+ /* Cached hash code of the key. */
+ Py_hash_t hash;
PyObject *key;
} setentry;
@@ -49,15 +50,17 @@ struct _setobject {
* saves repeated runtime null-tests.
*/
setentry *table;
- setentry *(*lookup)(PySetObject *so, PyObject *key, long hash);
+ setentry *(*lookup)(PySetObject *so, PyObject *key, Py_hash_t hash);
setentry smalltable[PySet_MINSIZE];
- long hash; /* only used by frozenset objects */
+ Py_hash_t hash; /* only used by frozenset objects */
PyObject *weakreflist; /* List of weak references */
};
+#endif /* Py_LIMITED_API */
PyAPI_DATA(PyTypeObject) PySet_Type;
PyAPI_DATA(PyTypeObject) PyFrozenSet_Type;
+PyAPI_DATA(PyTypeObject) PySetIter_Type;
/* Invariants for frozensets:
* data is immutable.
@@ -83,15 +86,20 @@ PyAPI_DATA(PyTypeObject) PyFrozenSet_Type;
PyAPI_FUNC(PyObject *) PySet_New(PyObject *);
PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *);
PyAPI_FUNC(Py_ssize_t) PySet_Size(PyObject *anyset);
+#ifndef Py_LIMITED_API
#define PySet_GET_SIZE(so) (((PySetObject *)(so))->used)
+#endif
PyAPI_FUNC(int) PySet_Clear(PyObject *set);
PyAPI_FUNC(int) PySet_Contains(PyObject *anyset, PyObject *key);
PyAPI_FUNC(int) PySet_Discard(PyObject *set, PyObject *key);
PyAPI_FUNC(int) PySet_Add(PyObject *set, PyObject *key);
-PyAPI_FUNC(int) _PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **key);
-PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash);
+#endif
PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);
+#endif
#ifdef __cplusplus
}
diff --git a/Include/sliceobject.h b/Include/sliceobject.h
index 8ab62dd4f8f..8bec17909d6 100644
--- a/Include/sliceobject.h
+++ b/Include/sliceobject.h
@@ -18,11 +18,12 @@ A slice object containing start, stop, and step data members (the
names are from range). After much talk with Guido, it was decided to
let these be any arbitrary python type. Py_None stands for omitted values.
*/
-
+#ifndef Py_LIMITED_API
typedef struct {
PyObject_HEAD
PyObject *start, *stop, *step; /* not NULL */
} PySliceObject;
+#endif
PyAPI_DATA(PyTypeObject) PySlice_Type;
PyAPI_DATA(PyTypeObject) PyEllipsis_Type;
@@ -31,10 +32,12 @@ PyAPI_DATA(PyTypeObject) PyEllipsis_Type;
PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop,
PyObject* step);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PySlice_FromIndices(Py_ssize_t start, Py_ssize_t stop);
-PyAPI_FUNC(int) PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
+#endif
+PyAPI_FUNC(int) PySlice_GetIndices(PyObject *r, Py_ssize_t length,
Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step);
-PyAPI_FUNC(int) PySlice_GetIndicesEx(PySliceObject *r, Py_ssize_t length,
+PyAPI_FUNC(int) PySlice_GetIndicesEx(PyObject *r, Py_ssize_t length,
Py_ssize_t *start, Py_ssize_t *stop,
Py_ssize_t *step, Py_ssize_t *slicelength);
diff --git a/Include/stringobject.h b/Include/stringobject.h
deleted file mode 100644
index 18b5b411aca..00000000000
--- a/Include/stringobject.h
+++ /dev/null
@@ -1,210 +0,0 @@
-
-/* String (str/bytes) object interface */
-
-#ifndef Py_STRINGOBJECT_H
-#define Py_STRINGOBJECT_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdarg.h>
-
-/*
-Type PyStringObject represents a character string. An extra zero byte is
-reserved at the end to ensure it is zero-terminated, but a size is
-present so strings with null bytes in them can be represented. This
-is an immutable object type.
-
-There are functions to create new string objects, to test
-an object for string-ness, and to get the
-string value. The latter function returns a null pointer
-if the object is not of the proper type.
-There is a variant that takes an explicit size as well as a
-variant that assumes a zero-terminated string. Note that none of the
-functions should be applied to nil objects.
-*/
-
-/* Caching the hash (ob_shash) saves recalculation of a string's hash value.
- Interning strings (ob_sstate) tries to ensure that only one string
- object with a given value exists, so equality tests can be one pointer
- comparison. This is generally restricted to strings that "look like"
- Python identifiers, although the intern() builtin can be used to force
- interning of any string.
- Together, these sped the interpreter by up to 20%. */
-
-typedef struct {
- PyObject_VAR_HEAD
- long ob_shash;
- int ob_sstate;
- char ob_sval[1];
-
- /* Invariants:
- * ob_sval contains space for 'ob_size+1' elements.
- * ob_sval[ob_size] == 0.
- * ob_shash is the hash of the string or -1 if not computed yet.
- * ob_sstate != 0 iff the string object is in stringobject.c's
- * 'interned' dictionary; in this case the two references
- * from 'interned' to this object are *not counted* in ob_refcnt.
- */
-} PyStringObject;
-
-#define SSTATE_NOT_INTERNED 0
-#define SSTATE_INTERNED_MORTAL 1
-#define SSTATE_INTERNED_IMMORTAL 2
-
-PyAPI_DATA(PyTypeObject) PyBaseString_Type;
-PyAPI_DATA(PyTypeObject) PyString_Type;
-
-#define PyString_Check(op) \
- PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS)
-#define PyString_CheckExact(op) (Py_TYPE(op) == &PyString_Type)
-
-PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);
-PyAPI_FUNC(PyObject *) PyString_FromString(const char *);
-PyAPI_FUNC(PyObject *) PyString_FromFormatV(const char*, va_list)
- Py_GCC_ATTRIBUTE((format(printf, 1, 0)));
-PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)
- Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
-PyAPI_FUNC(Py_ssize_t) PyString_Size(PyObject *);
-PyAPI_FUNC(char *) PyString_AsString(PyObject *);
-PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);
-PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);
-PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);
-PyAPI_FUNC(int) _PyString_Resize(PyObject **, Py_ssize_t);
-PyAPI_FUNC(int) _PyString_Eq(PyObject *, PyObject*);
-PyAPI_FUNC(PyObject *) PyString_Format(PyObject *, PyObject *);
-PyAPI_FUNC(PyObject *) _PyString_FormatLong(PyObject*, int, int,
- int, char**, int*);
-PyAPI_FUNC(PyObject *) PyString_DecodeEscape(const char *, Py_ssize_t,
- const char *, Py_ssize_t,
- const char *);
-
-PyAPI_FUNC(void) PyString_InternInPlace(PyObject **);
-PyAPI_FUNC(void) PyString_InternImmortal(PyObject **);
-PyAPI_FUNC(PyObject *) PyString_InternFromString(const char *);
-PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void);
-
-/* Use only if you know it's a string */
-#define PyString_CHECK_INTERNED(op) (((PyStringObject *)(op))->ob_sstate)
-
-/* Macro, trading safety for speed */
-#define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)
-#define PyString_GET_SIZE(op) Py_SIZE(op)
-
-/* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*,
- x must be an iterable object. */
-PyAPI_FUNC(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);
-
-/* --- Generic Codecs ----------------------------------------------------- */
-
-/* Create an object by decoding the encoded string s of the
- given size. */
-
-PyAPI_FUNC(PyObject*) PyString_Decode(
- const char *s, /* encoded string */
- Py_ssize_t size, /* size of buffer */
- const char *encoding, /* encoding */
- const char *errors /* error handling */
- );
-
-/* Encodes a char buffer of the given size and returns a
- Python object. */
-
-PyAPI_FUNC(PyObject*) PyString_Encode(
- const char *s, /* string char buffer */
- Py_ssize_t size, /* number of chars to encode */
- const char *encoding, /* encoding */
- const char *errors /* error handling */
- );
-
-/* Encodes a string object and returns the result as Python
- object. */
-
-PyAPI_FUNC(PyObject*) PyString_AsEncodedObject(
- PyObject *str, /* string object */
- const char *encoding, /* encoding */
- const char *errors /* error handling */
- );
-
-/* Encodes a string object and returns the result as Python string
- object.
-
- If the codec returns an Unicode object, the object is converted
- back to a string using the default encoding.
-
- DEPRECATED - use PyString_AsEncodedObject() instead. */
-
-PyAPI_FUNC(PyObject*) PyString_AsEncodedString(
- PyObject *str, /* string object */
- const char *encoding, /* encoding */
- const char *errors /* error handling */
- );
-
-/* Decodes a string object and returns the result as Python
- object. */
-
-PyAPI_FUNC(PyObject*) PyString_AsDecodedObject(
- PyObject *str, /* string object */
- const char *encoding, /* encoding */
- const char *errors /* error handling */
- );
-
-/* Decodes a string object and returns the result as Python string
- object.
-
- If the codec returns an Unicode object, the object is converted
- back to a string using the default encoding.
-
- DEPRECATED - use PyString_AsDecodedObject() instead. */
-
-PyAPI_FUNC(PyObject*) PyString_AsDecodedString(
- PyObject *str, /* string object */
- const char *encoding, /* encoding */
- const char *errors /* error handling */
- );
-
-/* Provides access to the internal data buffer and size of a string
- object or the default encoded version of an Unicode object. Passing
- NULL as *len parameter will force the string buffer to be
- 0-terminated (passing a string with embedded NULL characters will
- cause an exception). */
-
-PyAPI_FUNC(int) PyString_AsStringAndSize(
- register PyObject *obj, /* string or Unicode object */
- register char **s, /* pointer to buffer variable */
- register Py_ssize_t *len /* pointer to length variable or NULL
- (only possible for 0-terminated
- strings) */
- );
-
-
-/* Using the current locale, insert the thousands grouping
- into the string pointed to by buffer. For the argument descriptions,
- see Objects/stringlib/localeutil.h */
-PyAPI_FUNC(Py_ssize_t) _PyString_InsertThousandsGroupingLocale(char *buffer,
- Py_ssize_t n_buffer,
- char *digits,
- Py_ssize_t n_digits,
- Py_ssize_t min_width);
-
-/* Using explicit passed-in values, insert the thousands grouping
- into the string pointed to by buffer. For the argument descriptions,
- see Objects/stringlib/localeutil.h */
-PyAPI_FUNC(Py_ssize_t) _PyString_InsertThousandsGrouping(char *buffer,
- Py_ssize_t n_buffer,
- char *digits,
- Py_ssize_t n_digits,
- Py_ssize_t min_width,
- const char *grouping,
- const char *thousands_sep);
-
-/* Format the object based on the format_spec, as defined in PEP 3101
- (Advanced String Formatting). */
-PyAPI_FUNC(PyObject *) _PyBytes_FormatAdvanced(PyObject *obj,
- char *format_spec,
- Py_ssize_t format_spec_len);
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* !Py_STRINGOBJECT_H */
diff --git a/Include/structmember.h b/Include/structmember.h
index fe5b44ea342..0b85b2ac94b 100644
--- a/Include/structmember.h
+++ b/Include/structmember.h
@@ -19,74 +19,62 @@ extern "C" {
#define offsetof(type, member) ( (int) & ((type*)0) -> member )
#endif
-/* An array of memberlist structures defines the name, type and offset
+/* An array of PyMemberDef structures defines the name, type and offset
of selected members of a C structure. These can be read by
- PyMember_Get() and set by PyMember_Set() (except if their READONLY flag
- is set). The array must be terminated with an entry whose name
+ PyMember_GetOne() and set by PyMember_SetOne() (except if their READONLY
+ flag is set). The array must be terminated with an entry whose name
pointer is NULL. */
-struct memberlist {
- /* Obsolete version, for binary backwards compatibility */
- char *name;
- int type;
- int offset;
- int flags;
-};
-
typedef struct PyMemberDef {
- /* Current version, use this */
- char *name;
- int type;
- Py_ssize_t offset;
- int flags;
- char *doc;
+ /* Current version, use this */
+ char *name;
+ int type;
+ Py_ssize_t offset;
+ int flags;
+ char *doc;
} PyMemberDef;
/* Types */
-#define T_SHORT 0
-#define T_INT 1
-#define T_LONG 2
-#define T_FLOAT 3
-#define T_DOUBLE 4
-#define T_STRING 5
-#define T_OBJECT 6
+#define T_SHORT 0
+#define T_INT 1
+#define T_LONG 2
+#define T_FLOAT 3
+#define T_DOUBLE 4
+#define T_STRING 5
+#define T_OBJECT 6
/* XXX the ordering here is weird for binary compatibility */
-#define T_CHAR 7 /* 1-character string */
-#define T_BYTE 8 /* 8-bit signed int */
+#define T_CHAR 7 /* 1-character string */
+#define T_BYTE 8 /* 8-bit signed int */
/* unsigned variants: */
-#define T_UBYTE 9
-#define T_USHORT 10
-#define T_UINT 11
-#define T_ULONG 12
+#define T_UBYTE 9
+#define T_USHORT 10
+#define T_UINT 11
+#define T_ULONG 12
/* Added by Jack: strings contained in the structure */
-#define T_STRING_INPLACE 13
+#define T_STRING_INPLACE 13
/* Added by Lillo: bools contained in the structure (assumed char) */
-#define T_BOOL 14
+#define T_BOOL 14
-#define T_OBJECT_EX 16 /* Like T_OBJECT, but raises AttributeError
- when the value is NULL, instead of
- converting to None. */
+#define T_OBJECT_EX 16 /* Like T_OBJECT, but raises AttributeError
+ when the value is NULL, instead of
+ converting to None. */
#ifdef HAVE_LONG_LONG
-#define T_LONGLONG 17
-#define T_ULONGLONG 18
+#define T_LONGLONG 17
+#define T_ULONGLONG 18
#endif /* HAVE_LONG_LONG */
-#define T_PYSSIZET 19 /* Py_ssize_t */
+#define T_PYSSIZET 19 /* Py_ssize_t */
+#define T_NONE 20 /* Value is always None */
/* Flags */
-#define READONLY 1
-#define RO READONLY /* Shorthand */
-#define READ_RESTRICTED 2
+#define READONLY 1
+#define READ_RESTRICTED 2
#define PY_WRITE_RESTRICTED 4
-#define RESTRICTED (READ_RESTRICTED | PY_WRITE_RESTRICTED)
-
+#define RESTRICTED (READ_RESTRICTED | PY_WRITE_RESTRICTED)
-/* Obsolete API, for binary backwards compatibility */
-PyAPI_FUNC(PyObject *) PyMember_Get(const char *, struct memberlist *, const char *);
-PyAPI_FUNC(int) PyMember_Set(char *, struct memberlist *, const char *, PyObject *);
/* Current API, use this */
PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
diff --git a/Include/structseq.h b/Include/structseq.h
index e662916fe4c..30c52aca9ba 100644
--- a/Include/structseq.h
+++ b/Include/structseq.h
@@ -1,5 +1,5 @@
-/* Tuple object interface */
+/* Named tuple object interface */
#ifndef Py_STRUCTSEQ_H
#define Py_STRUCTSEQ_H
@@ -8,32 +8,38 @@ extern "C" {
#endif
typedef struct PyStructSequence_Field {
- char *name;
- char *doc;
+ char *name;
+ char *doc;
} PyStructSequence_Field;
typedef struct PyStructSequence_Desc {
- char *name;
- char *doc;
- struct PyStructSequence_Field *fields;
- int n_in_sequence;
+ char *name;
+ char *doc;
+ struct PyStructSequence_Field *fields;
+ int n_in_sequence;
} PyStructSequence_Desc;
extern char* PyStructSequence_UnnamedField;
+#ifndef Py_LIMITED_API
PyAPI_FUNC(void) PyStructSequence_InitType(PyTypeObject *type,
- PyStructSequence_Desc *desc);
+ PyStructSequence_Desc *desc);
+#endif
+PyAPI_FUNC(PyTypeObject*) PyStructSequence_NewType(PyStructSequence_Desc *desc);
PyAPI_FUNC(PyObject *) PyStructSequence_New(PyTypeObject* type);
-typedef struct {
- PyObject_VAR_HEAD
- PyObject *ob_item[1];
-} PyStructSequence;
+#ifndef Py_LIMITED_API
+typedef PyTupleObject PyStructSequence;
/* Macro, *only* to be used to fill in brand new objects */
-#define PyStructSequence_SET_ITEM(op, i, v) \
- (((PyStructSequence *)(op))->ob_item[i] = v)
+#define PyStructSequence_SET_ITEM(op, i, v) PyTuple_SET_ITEM(op, i, v)
+
+#define PyStructSequence_GET_ITEM(op, i) PyTuple_GET_ITEM(op, i)
+#endif
+
+PyAPI_FUNC(void) PyStructSequence_SetItem(PyObject*, Py_ssize_t, PyObject*);
+PyAPI_FUNC(PyObject*) PyStructSequence_GetItem(PyObject*, Py_ssize_t);
#ifdef __cplusplus
}
diff --git a/Include/symtable.h b/Include/symtable.h
index e0a0be41b5a..fd7de049b65 100644
--- a/Include/symtable.h
+++ b/Include/symtable.h
@@ -1,3 +1,4 @@
+#ifndef Py_LIMITED_API
#ifndef Py_SYMTABLE_H
#define Py_SYMTABLE_H
@@ -5,30 +6,36 @@
extern "C" {
#endif
+/* XXX(ncoghlan): This is a weird mix of public names and interpreter internal
+ * names.
+ */
+
typedef enum _block_type { FunctionBlock, ClassBlock, ModuleBlock }
_Py_block_ty;
struct _symtable_entry;
struct symtable {
- const char *st_filename; /* name of file being compiled */
+ const char *st_filename; /* name of file being compiled,
+ decoded from the filesystem encoding */
struct _symtable_entry *st_cur; /* current symbol table entry */
- struct _symtable_entry *st_top; /* module entry */
- PyObject *st_symbols; /* dictionary of symbol table entries */
- PyObject *st_stack; /* stack of namespace info */
- PyObject *st_global; /* borrowed ref to MODULE in st_symbols */
- int st_nblocks; /* number of blocks */
- PyObject *st_private; /* name of current class or NULL */
- PyFutureFeatures *st_future; /* module's future features */
+ struct _symtable_entry *st_top; /* symbol table entry for module */
+ PyObject *st_blocks; /* dict: map AST node addresses
+ * to symbol table entries */
+ PyObject *st_stack; /* list: stack of namespace info */
+ PyObject *st_global; /* borrowed ref to st_top->st_symbols */
+ int st_nblocks; /* number of blocks used */
+ PyObject *st_private; /* name of current class or NULL */
+ PyFutureFeatures *st_future; /* module's future features */
};
typedef struct _symtable_entry {
PyObject_HEAD
- PyObject *ste_id; /* int: key in st_symbols */
- PyObject *ste_symbols; /* dict: name to flags */
- PyObject *ste_name; /* string: name of block */
+ PyObject *ste_id; /* int: key in ste_table->st_blocks */
+ PyObject *ste_symbols; /* dict: variable names to flags */
+ PyObject *ste_name; /* string: name of current block */
PyObject *ste_varnames; /* list of variable names */
- PyObject *ste_children; /* list of child ids */
+ PyObject *ste_children; /* list of child blocks */
_Py_block_ty ste_type; /* module, class, or function */
int ste_unoptimized; /* false if namespace is optimized */
int ste_nested; /* true if block is nested */
@@ -41,7 +48,9 @@ typedef struct _symtable_entry {
unsigned ste_returns_value : 1; /* true if namespace uses return with
an argument */
int ste_lineno; /* first line of block */
+ int ste_col_offset; /* offset of first line of block */
int ste_opt_lineno; /* lineno of last exec or import * */
+ int ste_opt_col_offset; /* offset of last exec or import * */
int ste_tmpname; /* counter for listcomp temp vars */
struct symtable *ste_table;
} PySTEntryObject;
@@ -52,8 +61,10 @@ PyAPI_DATA(PyTypeObject) PySTEntry_Type;
PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *);
-PyAPI_FUNC(struct symtable *) PySymtable_Build(mod_ty, const char *,
- PyFutureFeatures *);
+PyAPI_FUNC(struct symtable *) PySymtable_Build(
+ mod_ty mod,
+ const char *filename, /* decoded from the filesystem encoding */
+ PyFutureFeatures *future);
PyAPI_FUNC(PySTEntryObject *) PySymtable_Lookup(struct symtable *, void *);
PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
@@ -63,19 +74,20 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
#define DEF_GLOBAL 1 /* global stmt */
#define DEF_LOCAL 2 /* assignment in code block */
#define DEF_PARAM 2<<1 /* formal parameter */
-#define USE 2<<2 /* name is used */
-#define DEF_FREE 2<<3 /* name used but not defined in nested block */
-#define DEF_FREE_CLASS 2<<4 /* free variable from class's method */
-#define DEF_IMPORT 2<<5 /* assignment occurred via import */
+#define DEF_NONLOCAL 2<<2 /* nonlocal stmt */
+#define USE 2<<3 /* name is used */
+#define DEF_FREE 2<<4 /* name used but not defined in nested block */
+#define DEF_FREE_CLASS 2<<5 /* free variable from class's method */
+#define DEF_IMPORT 2<<6 /* assignment occurred via import */
#define DEF_BOUND (DEF_LOCAL | DEF_PARAM | DEF_IMPORT)
/* GLOBAL_EXPLICIT and GLOBAL_IMPLICIT are used internally by the symbol
table. GLOBAL is returned from PyST_GetScope() for either of them.
- It is stored in ste_symbols at bits 12-14.
+ It is stored in ste_symbols at bits 12-15.
*/
-#define SCOPE_OFF 11
-#define SCOPE_MASK 7
+#define SCOPE_OFFSET 11
+#define SCOPE_MASK (DEF_GLOBAL | DEF_LOCAL | DEF_PARAM | DEF_NONLOCAL)
#define LOCAL 1
#define GLOBAL_EXPLICIT 2
@@ -83,11 +95,9 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
#define FREE 4
#define CELL 5
-/* The following three names are used for the ste_unoptimized bit field */
+/* The following two names are used for the ste_unoptimized bit field */
#define OPT_IMPORT_STAR 1
-#define OPT_EXEC 2
-#define OPT_BARE_EXEC 4
-#define OPT_TOPLEVEL 8 /* top-level names, including eval and exec */
+#define OPT_TOPLEVEL 2 /* top-level names, including eval and exec */
#define GENERATOR 1
#define GENERATOR_EXPRESSION 2
@@ -96,3 +106,4 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
}
#endif
#endif /* !Py_SYMTABLE_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/sysmodule.h b/Include/sysmodule.h
index 16af1196ec9..010e6e080a9 100644
--- a/Include/sysmodule.h
+++ b/Include/sysmodule.h
@@ -7,25 +7,31 @@
extern "C" {
#endif
-PyAPI_FUNC(PyObject *) PySys_GetObject(char *);
-PyAPI_FUNC(int) PySys_SetObject(char *, PyObject *);
-PyAPI_FUNC(FILE *) PySys_GetFile(char *, FILE *);
-PyAPI_FUNC(void) PySys_SetArgv(int, char **);
-PyAPI_FUNC(void) PySys_SetArgvEx(int, char **, int);
-PyAPI_FUNC(void) PySys_SetPath(char *);
+PyAPI_FUNC(PyObject *) PySys_GetObject(const char *);
+PyAPI_FUNC(int) PySys_SetObject(const char *, PyObject *);
+PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
+PyAPI_FUNC(void) PySys_SetArgvEx(int, wchar_t **, int);
+PyAPI_FUNC(void) PySys_SetPath(const wchar_t *);
PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)
- Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
+ Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...)
- Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
+ Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
+PyAPI_FUNC(void) PySys_FormatStdout(const char *format, ...);
+PyAPI_FUNC(void) PySys_FormatStderr(const char *format, ...);
+#ifndef Py_LIMITED_API
PyAPI_DATA(PyObject *) _PySys_TraceFunc, *_PySys_ProfileFunc;
-PyAPI_DATA(int) _PySys_CheckInterval;
+#endif
PyAPI_FUNC(void) PySys_ResetWarnOptions(void);
-PyAPI_FUNC(void) PySys_AddWarnOption(char *);
+PyAPI_FUNC(void) PySys_AddWarnOption(const wchar_t *);
+PyAPI_FUNC(void) PySys_AddWarnOptionUnicode(PyObject *);
PyAPI_FUNC(int) PySys_HasWarnOptions(void);
+PyAPI_FUNC(void) PySys_AddXOption(const wchar_t *);
+PyAPI_FUNC(PyObject *) PySys_GetXOptions(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/timefuncs.h b/Include/timefuncs.h
index 553142dba0f..3c4357505ac 100644
--- a/Include/timefuncs.h
+++ b/Include/timefuncs.h
@@ -14,7 +14,9 @@ extern "C" {
* to fit in a time_t. ValueError is set on return iff the return
* value is (time_t)-1 and PyErr_Occurred().
*/
+#ifndef Py_LIMITED_API
PyAPI_FUNC(time_t) _PyTime_DoubleToTimet(double x);
+#endif
#ifdef __cplusplus
diff --git a/Include/token.h b/Include/token.h
index 72659ac053f..f7f650456ef 100644
--- a/Include/token.h
+++ b/Include/token.h
@@ -1,6 +1,6 @@
/* Token types */
-
+#ifndef Py_LIMITED_API
#ifndef Py_TOKEN_H
#define Py_TOKEN_H
#ifdef __cplusplus
@@ -34,36 +34,37 @@ extern "C" {
#define EQUAL 22
#define DOT 23
#define PERCENT 24
-#define BACKQUOTE 25
-#define LBRACE 26
-#define RBRACE 27
-#define EQEQUAL 28
-#define NOTEQUAL 29
-#define LESSEQUAL 30
-#define GREATEREQUAL 31
-#define TILDE 32
-#define CIRCUMFLEX 33
-#define LEFTSHIFT 34
-#define RIGHTSHIFT 35
-#define DOUBLESTAR 36
-#define PLUSEQUAL 37
-#define MINEQUAL 38
-#define STAREQUAL 39
-#define SLASHEQUAL 40
-#define PERCENTEQUAL 41
-#define AMPEREQUAL 42
-#define VBAREQUAL 43
-#define CIRCUMFLEXEQUAL 44
-#define LEFTSHIFTEQUAL 45
-#define RIGHTSHIFTEQUAL 46
-#define DOUBLESTAREQUAL 47
-#define DOUBLESLASH 48
-#define DOUBLESLASHEQUAL 49
-#define AT 50
+#define LBRACE 25
+#define RBRACE 26
+#define EQEQUAL 27
+#define NOTEQUAL 28
+#define LESSEQUAL 29
+#define GREATEREQUAL 30
+#define TILDE 31
+#define CIRCUMFLEX 32
+#define LEFTSHIFT 33
+#define RIGHTSHIFT 34
+#define DOUBLESTAR 35
+#define PLUSEQUAL 36
+#define MINEQUAL 37
+#define STAREQUAL 38
+#define SLASHEQUAL 39
+#define PERCENTEQUAL 40
+#define AMPEREQUAL 41
+#define VBAREQUAL 42
+#define CIRCUMFLEXEQUAL 43
+#define LEFTSHIFTEQUAL 44
+#define RIGHTSHIFTEQUAL 45
+#define DOUBLESTAREQUAL 46
+#define DOUBLESLASH 47
+#define DOUBLESLASHEQUAL 48
+#define AT 49
+#define RARROW 50
+#define ELLIPSIS 51
/* Don't forget to update the table _PyParser_TokenNames in tokenizer.c! */
-#define OP 51
-#define ERRORTOKEN 52
-#define N_TOKENS 53
+#define OP 52
+#define ERRORTOKEN 53
+#define N_TOKENS 54
/* Special definitions for cooperation with parser */
@@ -83,3 +84,4 @@ PyAPI_FUNC(int) PyToken_ThreeChars(int, int, int);
}
#endif
#endif /* !Py_TOKEN_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/traceback.h b/Include/traceback.h
index e7943dae969..69e3d05453b 100644
--- a/Include/traceback.h
+++ b/Include/traceback.h
@@ -8,18 +8,21 @@ extern "C" {
struct _frame;
/* Traceback interface */
-
+#ifndef Py_LIMITED_API
typedef struct _traceback {
- PyObject_HEAD
- struct _traceback *tb_next;
- struct _frame *tb_frame;
- int tb_lasti;
- int tb_lineno;
+ PyObject_HEAD
+ struct _traceback *tb_next;
+ struct _frame *tb_frame;
+ int tb_lasti;
+ int tb_lineno;
} PyTracebackObject;
+#endif
PyAPI_FUNC(int) PyTraceBack_Here(struct _frame *);
PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *);
-PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, const char *, int, int);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, PyObject *, int, int);
+#endif
/* Reveal traceback type so we can typecheck traceback objects */
PyAPI_DATA(PyTypeObject) PyTraceBack_Type;
diff --git a/Include/tupleobject.h b/Include/tupleobject.h
index a5ab733208b..f17b7882bed 100644
--- a/Include/tupleobject.h
+++ b/Include/tupleobject.h
@@ -21,6 +21,7 @@ inserted in the tuple. Similarly, PyTuple_GetItem does not increment the
returned item's reference count.
*/
+#ifndef Py_LIMITED_API
typedef struct {
PyObject_VAR_HEAD
PyObject *ob_item[1];
@@ -30,8 +31,10 @@ typedef struct {
* the tuple is not yet visible outside the function that builds it.
*/
} PyTupleObject;
+#endif
PyAPI_DATA(PyTypeObject) PyTuple_Type;
+PyAPI_DATA(PyTypeObject) PyTupleIter_Type;
#define PyTuple_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
@@ -42,16 +45,22 @@ PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *);
PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, Py_ssize_t);
PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *);
PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, Py_ssize_t);
+#endif
PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
+#endif
/* Macro, trading safety for speed */
+#ifndef Py_LIMITED_API
#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
#define PyTuple_GET_SIZE(op) Py_SIZE(op)
/* Macro, *only* to be used to fill in brand new tuples */
#define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
+#endif
PyAPI_FUNC(int) PyTuple_ClearFreeList(void);
diff --git a/Include/typeslots.h b/Include/typeslots.h
new file mode 100644
index 00000000000..ad3cdfb19ad
--- /dev/null
+++ b/Include/typeslots.h
@@ -0,0 +1,76 @@
+/* Do not renumber the file; these numbers are part of the stable ABI. */
+/* Disabled, see #10181 */
+#undef Py_bf_getbuffer
+#undef Py_bf_releasebuffer
+#define Py_mp_ass_subscript 3
+#define Py_mp_length 4
+#define Py_mp_subscript 5
+#define Py_nb_absolute 6
+#define Py_nb_add 7
+#define Py_nb_and 8
+#define Py_nb_bool 9
+#define Py_nb_divmod 10
+#define Py_nb_float 11
+#define Py_nb_floor_divide 12
+#define Py_nb_index 13
+#define Py_nb_inplace_add 14
+#define Py_nb_inplace_and 15
+#define Py_nb_inplace_floor_divide 16
+#define Py_nb_inplace_lshift 17
+#define Py_nb_inplace_multiply 18
+#define Py_nb_inplace_or 19
+#define Py_nb_inplace_power 20
+#define Py_nb_inplace_remainder 21
+#define Py_nb_inplace_rshift 22
+#define Py_nb_inplace_subtract 23
+#define Py_nb_inplace_true_divide 24
+#define Py_nb_inplace_xor 25
+#define Py_nb_int 26
+#define Py_nb_invert 27
+#define Py_nb_lshift 28
+#define Py_nb_multiply 29
+#define Py_nb_negative 30
+#define Py_nb_or 31
+#define Py_nb_positive 32
+#define Py_nb_power 33
+#define Py_nb_remainder 34
+#define Py_nb_rshift 35
+#define Py_nb_subtract 36
+#define Py_nb_true_divide 37
+#define Py_nb_xor 38
+#define Py_sq_ass_item 39
+#define Py_sq_concat 40
+#define Py_sq_contains 41
+#define Py_sq_inplace_concat 42
+#define Py_sq_inplace_repeat 43
+#define Py_sq_item 44
+#define Py_sq_length 45
+#define Py_sq_repeat 46
+#define Py_tp_alloc 47
+#define Py_tp_base 48
+#define Py_tp_bases 49
+#define Py_tp_call 50
+#define Py_tp_clear 51
+#define Py_tp_dealloc 52
+#define Py_tp_del 53
+#define Py_tp_descr_get 54
+#define Py_tp_descr_set 55
+#define Py_tp_doc 56
+#define Py_tp_getattr 57
+#define Py_tp_getattro 58
+#define Py_tp_hash 59
+#define Py_tp_init 60
+#define Py_tp_is_gc 61
+#define Py_tp_iter 62
+#define Py_tp_iternext 63
+#define Py_tp_methods 64
+#define Py_tp_new 65
+#define Py_tp_repr 66
+#define Py_tp_richcompare 67
+#define Py_tp_setattr 68
+#define Py_tp_setattro 69
+#define Py_tp_str 70
+#define Py_tp_traverse 71
+#define Py_tp_members 72
+#define Py_tp_getset 73
+#define Py_tp_free 74
diff --git a/Include/ucnhash.h b/Include/ucnhash.h
index 69b7774a97f..70fdf130694 100644
--- a/Include/ucnhash.h
+++ b/Include/ucnhash.h
@@ -1,5 +1,5 @@
/* Unicode name database interface */
-
+#ifndef Py_LIMITED_API
#ifndef Py_UCNHASH_H
#define Py_UCNHASH_H
#ifdef __cplusplus
@@ -31,3 +31,4 @@ typedef struct {
}
#endif
#endif /* !Py_UCNHASH_H */
+#endif /* !Py_LIMITED_API */
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
index 9ab724aa6e0..379a90c6c27 100644
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -7,7 +7,8 @@
Unicode implementation based on original code by Fredrik Lundh,
modified by Marc-Andre Lemburg (mal@lemburg.com) according to the
-Unicode Integration Proposal (see file Misc/unicode.txt).
+Unicode Integration Proposal. (See
+http://www.egenix.com/files/python/unicode-proposal.txt).
Copyright (c) Corporation for National Research Initiatives.
@@ -60,12 +61,8 @@ Copyright (c) Corporation for National Research Initiatives.
/* --- Internal Unicode Format -------------------------------------------- */
-#ifndef Py_USING_UNICODE
-
-#define PyUnicode_Check(op) 0
-#define PyUnicode_CheckExact(op) 0
-
-#else
+/* Python 3.x requires unicode */
+#define Py_USING_UNICODE
/* FIXME: MvL's new implementation assumes that Py_UNICODE_SIZE is
properly set, but the default rules below doesn't set it. I'll
@@ -82,7 +79,7 @@ Copyright (c) Corporation for National Research Initiatives.
#define Py_UNICODE_WIDE
#endif
-/* Set these flags if the platform has "wchar.h", "wctype.h" and the
+/* Set these flags if the platform has "wchar.h" and the
wchar_t type is a 16-bit unsigned type */
/* #define HAVE_WCHAR_H */
/* #define HAVE_USABLE_WCHAR_T */
@@ -103,8 +100,8 @@ Copyright (c) Corporation for National Research Initiatives.
#endif
/* If the compiler provides a wchar_t type we try to support it
- through the interface functions PyUnicode_FromWideChar() and
- PyUnicode_AsWideChar(). */
+ through the interface functions PyUnicode_FromWideChar(),
+ PyUnicode_AsWideChar() and PyUnicode_AsWideCharString(). */
#ifdef HAVE_USABLE_WCHAR_T
# ifndef HAVE_WCHAR_H
@@ -134,7 +131,9 @@ typedef unsigned long Py_UCS4;
Python and represents a single Unicode element in the Unicode
type. */
+#ifndef Py_LIMITED_API
typedef PY_UNICODE_TYPE Py_UNICODE;
+#endif
/* --- UCS-2/UCS-4 Name Mangling ------------------------------------------ */
@@ -147,8 +146,11 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define PyUnicode_AsASCIIString PyUnicodeUCS2_AsASCIIString
# define PyUnicode_AsCharmapString PyUnicodeUCS2_AsCharmapString
+# define PyUnicode_AsDecodedObject PyUnicodeUCS2_AsDecodedObject
+# define PyUnicode_AsDecodedUnicode PyUnicodeUCS2_AsDecodedUnicode
# define PyUnicode_AsEncodedObject PyUnicodeUCS2_AsEncodedObject
# define PyUnicode_AsEncodedString PyUnicodeUCS2_AsEncodedString
+# define PyUnicode_AsEncodedUnicode PyUnicodeUCS2_AsEncodedUnicode
# define PyUnicode_AsLatin1String PyUnicodeUCS2_AsLatin1String
# define PyUnicode_AsRawUnicodeEscapeString PyUnicodeUCS2_AsRawUnicodeEscapeString
# define PyUnicode_AsUTF32String PyUnicodeUCS2_AsUTF32String
@@ -157,15 +159,21 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define PyUnicode_AsUnicode PyUnicodeUCS2_AsUnicode
# define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS2_AsUnicodeEscapeString
# define PyUnicode_AsWideChar PyUnicodeUCS2_AsWideChar
+# define PyUnicode_AsWideCharString PyUnicodeUCS2_AsWideCharString
# define PyUnicode_ClearFreeList PyUnicodeUCS2_ClearFreelist
# define PyUnicode_Compare PyUnicodeUCS2_Compare
+# define PyUnicode_CompareWithASCIIString PyUnicodeUCS2_CompareWithASCIIString
# define PyUnicode_Concat PyUnicodeUCS2_Concat
+# define PyUnicode_Append PyUnicodeUCS2_Append
+# define PyUnicode_AppendAndDel PyUnicodeUCS2_AppendAndDel
# define PyUnicode_Contains PyUnicodeUCS2_Contains
# define PyUnicode_Count PyUnicodeUCS2_Count
# define PyUnicode_Decode PyUnicodeUCS2_Decode
# define PyUnicode_DecodeASCII PyUnicodeUCS2_DecodeASCII
# define PyUnicode_DecodeCharmap PyUnicodeUCS2_DecodeCharmap
# define PyUnicode_DecodeLatin1 PyUnicodeUCS2_DecodeLatin1
+# define PyUnicode_DecodeFSDefault PyUnicodeUCS2_DecodeFSDefault
+# define PyUnicode_DecodeFSDefaultAndSize PyUnicodeUCS2_DecodeFSDefaultAndSize
# define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS2_DecodeRawUnicodeEscape
# define PyUnicode_DecodeUTF32 PyUnicodeUCS2_DecodeUTF32
# define PyUnicode_DecodeUTF32Stateful PyUnicodeUCS2_DecodeUTF32Stateful
@@ -195,9 +203,12 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define PyUnicode_FromStringAndSize PyUnicodeUCS2_FromStringAndSize
# define PyUnicode_FromUnicode PyUnicodeUCS2_FromUnicode
# define PyUnicode_FromWideChar PyUnicodeUCS2_FromWideChar
+# define PyUnicode_FSConverter PyUnicodeUCS2_FSConverter
+# define PyUnicode_FSDecoder PyUnicodeUCS2_FSDecoder
# define PyUnicode_GetDefaultEncoding PyUnicodeUCS2_GetDefaultEncoding
# define PyUnicode_GetMax PyUnicodeUCS2_GetMax
# define PyUnicode_GetSize PyUnicodeUCS2_GetSize
+# define PyUnicode_IsIdentifier PyUnicodeUCS2_IsIdentifier
# define PyUnicode_Join PyUnicodeUCS2_Join
# define PyUnicode_Partition PyUnicodeUCS2_Partition
# define PyUnicode_RPartition PyUnicodeUCS2_RPartition
@@ -205,7 +216,6 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define PyUnicode_Replace PyUnicodeUCS2_Replace
# define PyUnicode_Resize PyUnicodeUCS2_Resize
# define PyUnicode_RichCompare PyUnicodeUCS2_RichCompare
-# define PyUnicode_SetDefaultEncoding PyUnicodeUCS2_SetDefaultEncoding
# define PyUnicode_Split PyUnicodeUCS2_Split
# define PyUnicode_Splitlines PyUnicodeUCS2_Splitlines
# define PyUnicode_Tailmatch PyUnicodeUCS2_Tailmatch
@@ -214,28 +224,17 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS2_AsDefaultEncodedString
# define _PyUnicode_Fini _PyUnicodeUCS2_Fini
# define _PyUnicode_Init _PyUnicodeUCS2_Init
-# define _PyUnicode_IsAlpha _PyUnicodeUCS2_IsAlpha
-# define _PyUnicode_IsDecimalDigit _PyUnicodeUCS2_IsDecimalDigit
-# define _PyUnicode_IsDigit _PyUnicodeUCS2_IsDigit
-# define _PyUnicode_IsLinebreak _PyUnicodeUCS2_IsLinebreak
-# define _PyUnicode_IsLowercase _PyUnicodeUCS2_IsLowercase
-# define _PyUnicode_IsNumeric _PyUnicodeUCS2_IsNumeric
-# define _PyUnicode_IsTitlecase _PyUnicodeUCS2_IsTitlecase
-# define _PyUnicode_IsUppercase _PyUnicodeUCS2_IsUppercase
-# define _PyUnicode_IsWhitespace _PyUnicodeUCS2_IsWhitespace
-# define _PyUnicode_ToDecimalDigit _PyUnicodeUCS2_ToDecimalDigit
-# define _PyUnicode_ToDigit _PyUnicodeUCS2_ToDigit
-# define _PyUnicode_ToLowercase _PyUnicodeUCS2_ToLowercase
-# define _PyUnicode_ToNumeric _PyUnicodeUCS2_ToNumeric
-# define _PyUnicode_ToTitlecase _PyUnicodeUCS2_ToTitlecase
-# define _PyUnicode_ToUppercase _PyUnicodeUCS2_ToUppercase
+# define PyUnicode_strdup PyUnicodeUCS2_strdup
#else
# define PyUnicode_AsASCIIString PyUnicodeUCS4_AsASCIIString
# define PyUnicode_AsCharmapString PyUnicodeUCS4_AsCharmapString
+# define PyUnicode_AsDecodedObject PyUnicodeUCS4_AsDecodedObject
+# define PyUnicode_AsDecodedUnicode PyUnicodeUCS4_AsDecodedUnicode
# define PyUnicode_AsEncodedObject PyUnicodeUCS4_AsEncodedObject
# define PyUnicode_AsEncodedString PyUnicodeUCS4_AsEncodedString
+# define PyUnicode_AsEncodedUnicode PyUnicodeUCS4_AsEncodedUnicode
# define PyUnicode_AsLatin1String PyUnicodeUCS4_AsLatin1String
# define PyUnicode_AsRawUnicodeEscapeString PyUnicodeUCS4_AsRawUnicodeEscapeString
# define PyUnicode_AsUTF32String PyUnicodeUCS4_AsUTF32String
@@ -244,15 +243,21 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define PyUnicode_AsUnicode PyUnicodeUCS4_AsUnicode
# define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS4_AsUnicodeEscapeString
# define PyUnicode_AsWideChar PyUnicodeUCS4_AsWideChar
+# define PyUnicode_AsWideCharString PyUnicodeUCS4_AsWideCharString
# define PyUnicode_ClearFreeList PyUnicodeUCS4_ClearFreelist
# define PyUnicode_Compare PyUnicodeUCS4_Compare
+# define PyUnicode_CompareWithASCIIString PyUnicodeUCS4_CompareWithASCIIString
# define PyUnicode_Concat PyUnicodeUCS4_Concat
+# define PyUnicode_Append PyUnicodeUCS4_Append
+# define PyUnicode_AppendAndDel PyUnicodeUCS4_AppendAndDel
# define PyUnicode_Contains PyUnicodeUCS4_Contains
# define PyUnicode_Count PyUnicodeUCS4_Count
# define PyUnicode_Decode PyUnicodeUCS4_Decode
# define PyUnicode_DecodeASCII PyUnicodeUCS4_DecodeASCII
# define PyUnicode_DecodeCharmap PyUnicodeUCS4_DecodeCharmap
# define PyUnicode_DecodeLatin1 PyUnicodeUCS4_DecodeLatin1
+# define PyUnicode_DecodeFSDefault PyUnicodeUCS4_DecodeFSDefault
+# define PyUnicode_DecodeFSDefaultAndSize PyUnicodeUCS4_DecodeFSDefaultAndSize
# define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS4_DecodeRawUnicodeEscape
# define PyUnicode_DecodeUTF32 PyUnicodeUCS4_DecodeUTF32
# define PyUnicode_DecodeUTF32Stateful PyUnicodeUCS4_DecodeUTF32Stateful
@@ -282,9 +287,12 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define PyUnicode_FromStringAndSize PyUnicodeUCS4_FromStringAndSize
# define PyUnicode_FromUnicode PyUnicodeUCS4_FromUnicode
# define PyUnicode_FromWideChar PyUnicodeUCS4_FromWideChar
+# define PyUnicode_FSConverter PyUnicodeUCS4_FSConverter
+# define PyUnicode_FSDecoder PyUnicodeUCS4_FSDecoder
# define PyUnicode_GetDefaultEncoding PyUnicodeUCS4_GetDefaultEncoding
# define PyUnicode_GetMax PyUnicodeUCS4_GetMax
# define PyUnicode_GetSize PyUnicodeUCS4_GetSize
+# define PyUnicode_IsIdentifier PyUnicodeUCS4_IsIdentifier
# define PyUnicode_Join PyUnicodeUCS4_Join
# define PyUnicode_Partition PyUnicodeUCS4_Partition
# define PyUnicode_RPartition PyUnicodeUCS4_RPartition
@@ -292,7 +300,6 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define PyUnicode_Replace PyUnicodeUCS4_Replace
# define PyUnicode_Resize PyUnicodeUCS4_Resize
# define PyUnicode_RichCompare PyUnicodeUCS4_RichCompare
-# define PyUnicode_SetDefaultEncoding PyUnicodeUCS4_SetDefaultEncoding
# define PyUnicode_Split PyUnicodeUCS4_Split
# define PyUnicode_Splitlines PyUnicodeUCS4_Splitlines
# define PyUnicode_Tailmatch PyUnicodeUCS4_Tailmatch
@@ -301,65 +308,19 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS4_AsDefaultEncodedString
# define _PyUnicode_Fini _PyUnicodeUCS4_Fini
# define _PyUnicode_Init _PyUnicodeUCS4_Init
-# define _PyUnicode_IsAlpha _PyUnicodeUCS4_IsAlpha
-# define _PyUnicode_IsDecimalDigit _PyUnicodeUCS4_IsDecimalDigit
-# define _PyUnicode_IsDigit _PyUnicodeUCS4_IsDigit
-# define _PyUnicode_IsLinebreak _PyUnicodeUCS4_IsLinebreak
-# define _PyUnicode_IsLowercase _PyUnicodeUCS4_IsLowercase
-# define _PyUnicode_IsNumeric _PyUnicodeUCS4_IsNumeric
-# define _PyUnicode_IsTitlecase _PyUnicodeUCS4_IsTitlecase
-# define _PyUnicode_IsUppercase _PyUnicodeUCS4_IsUppercase
-# define _PyUnicode_IsWhitespace _PyUnicodeUCS4_IsWhitespace
-# define _PyUnicode_ToDecimalDigit _PyUnicodeUCS4_ToDecimalDigit
-# define _PyUnicode_ToDigit _PyUnicodeUCS4_ToDigit
-# define _PyUnicode_ToLowercase _PyUnicodeUCS4_ToLowercase
-# define _PyUnicode_ToNumeric _PyUnicodeUCS4_ToNumeric
-# define _PyUnicode_ToTitlecase _PyUnicodeUCS4_ToTitlecase
-# define _PyUnicode_ToUppercase _PyUnicodeUCS4_ToUppercase
-
+# define PyUnicode_strdup PyUnicodeUCS4_strdup
#endif
/* --- Internal Unicode Operations ---------------------------------------- */
-/* If you want Python to use the compiler's wctype.h functions instead
- of the ones supplied with Python, define WANT_WCTYPE_FUNCTIONS or
- configure Python using --with-wctype-functions. This reduces the
- interpreter's code size. */
-
-#if defined(HAVE_USABLE_WCHAR_T) && defined(WANT_WCTYPE_FUNCTIONS)
-
-#include <wctype.h>
-
-#define Py_UNICODE_ISSPACE(ch) iswspace(ch)
-
-#define Py_UNICODE_ISLOWER(ch) iswlower(ch)
-#define Py_UNICODE_ISUPPER(ch) iswupper(ch)
-#define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch)
-#define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch)
-
-#define Py_UNICODE_TOLOWER(ch) towlower(ch)
-#define Py_UNICODE_TOUPPER(ch) towupper(ch)
-#define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch)
-
-#define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)
-#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)
-#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)
-
-#define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)
-#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)
-#define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch)
-
-#define Py_UNICODE_ISALPHA(ch) iswalpha(ch)
-
-#else
-
/* Since splitting on whitespace is an important use case, and
whitespace in most situations is solely ASCII whitespace, we
optimize for the common case by using a quick look-up table
_Py_ascii_whitespace (see below) with an inlined check.
*/
+#ifndef Py_LIMITED_API
#define Py_UNICODE_ISSPACE(ch) \
((ch) < 128U ? _Py_ascii_whitespace[(ch)] : _PyUnicode_IsWhitespace(ch))
@@ -375,6 +336,7 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
#define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)
#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)
#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)
+#define Py_UNICODE_ISPRINTABLE(ch) _PyUnicode_IsPrintable(ch)
#define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)
#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)
@@ -382,8 +344,6 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
#define Py_UNICODE_ISALPHA(ch) _PyUnicode_IsAlpha(ch)
-#endif
-
#define Py_UNICODE_ISALNUM(ch) \
(Py_UNICODE_ISALPHA(ch) || \
Py_UNICODE_ISDECIMAL(ch) || \
@@ -398,13 +358,14 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\
} while (0)
-/* Check if substring matches at given offset. the offset must be
- valid, and the substring must not be empty */
+/* Check if substring matches at given offset. The offset must be
+ valid, and the substring must not be empty. */
#define Py_UNICODE_MATCH(string, offset, substring) \
((*((string)->str + (offset)) == *((substring)->str)) && \
((*((string)->str + (offset) + (substring)->length-1) == *((substring)->str + (substring)->length-1))) && \
!memcmp((string)->str + (offset), (substring)->str, (substring)->length*sizeof(Py_UNICODE)))
+#endif /* Py_LIMITED_API */
#ifdef __cplusplus
extern "C" {
@@ -412,31 +373,43 @@ extern "C" {
/* --- Unicode Type ------------------------------------------------------- */
+#ifndef Py_LIMITED_API
typedef struct {
PyObject_HEAD
Py_ssize_t length; /* Length of raw Unicode data in buffer */
Py_UNICODE *str; /* Raw Unicode buffer */
- long hash; /* Hash value; -1 if not set */
+ Py_hash_t hash; /* Hash value; -1 if not set */
+ int state; /* != 0 if interned. In this case the two
+ * references from the dictionary to this object
+ * are *not* counted in ob_refcnt. */
PyObject *defenc; /* (Default) Encoded version as Python
string, or NULL; this is used for
implementing the buffer protocol */
} PyUnicodeObject;
+#endif
PyAPI_DATA(PyTypeObject) PyUnicode_Type;
+PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type;
+
+#define SSTATE_NOT_INTERNED 0
+#define SSTATE_INTERNED_MORTAL 1
+#define SSTATE_INTERNED_IMMORTAL 2
#define PyUnicode_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
#define PyUnicode_CheckExact(op) (Py_TYPE(op) == &PyUnicode_Type)
/* Fast access macros */
+#ifndef Py_LIMITED_API
#define PyUnicode_GET_SIZE(op) \
- (((PyUnicodeObject *)(op))->length)
+ (assert(PyUnicode_Check(op)),(((PyUnicodeObject *)(op))->length))
#define PyUnicode_GET_DATA_SIZE(op) \
- (((PyUnicodeObject *)(op))->length * sizeof(Py_UNICODE))
+ (assert(PyUnicode_Check(op)),(((PyUnicodeObject *)(op))->length * sizeof(Py_UNICODE)))
#define PyUnicode_AS_UNICODE(op) \
- (((PyUnicodeObject *)(op))->str)
+ (assert(PyUnicode_Check(op)),(((PyUnicodeObject *)(op))->str))
#define PyUnicode_AS_DATA(op) \
- ((const char *)((PyUnicodeObject *)(op))->str)
+ (assert(PyUnicode_Check(op)),((const char *)((PyUnicodeObject *)(op))->str))
+#endif
/* --- Constants ---------------------------------------------------------- */
@@ -461,29 +434,33 @@ PyAPI_DATA(PyTypeObject) PyUnicode_Type;
The buffer is copied into the new object. */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(
const Py_UNICODE *u, /* Unicode buffer */
Py_ssize_t size /* size of buffer */
);
+#endif
-/* Similar to PyUnicode_FromUnicode(), but u points to Latin-1 encoded bytes */
+/* Similar to PyUnicode_FromUnicode(), but u points to UTF-8 encoded bytes */
PyAPI_FUNC(PyObject*) PyUnicode_FromStringAndSize(
- const char *u, /* char buffer */
- Py_ssize_t size /* size of buffer */
+ const char *u, /* UTF-8 encoded string */
+ Py_ssize_t size /* size of buffer */
);
/* Similar to PyUnicode_FromUnicode(), but u points to null-terminated
- Latin-1 encoded bytes */
+ UTF-8 encoded bytes */
PyAPI_FUNC(PyObject*) PyUnicode_FromString(
- const char *u /* string */
+ const char *u /* UTF-8 encoded string */
);
/* Return a read-only pointer to the Unicode object's internal
Py_UNICODE buffer. */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(
PyObject *unicode /* Unicode object */
);
+#endif
/* Get the length of the Unicode object. */
@@ -491,8 +468,10 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(
PyObject *unicode /* Unicode object */
);
+#ifndef Py_LIMITED_API
/* Get the maximum ordinal for a Unicode character. */
PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void);
+#endif
/* Resize an already allocated Unicode object to the new size length.
@@ -518,9 +497,9 @@ PyAPI_FUNC(int) PyUnicode_Resize(
Coercion is done in the following way:
- 1. String and other char buffer compatible objects are decoded
- under the assumptions that they contain data using the current
- default encoding. Decoding is done in "strict" mode.
+ 1. bytes, bytearray and other char buffer compatible objects are decoded
+ under the assumptions that they contain data using the UTF-8
+ encoding. Decoding is done in "strict" mode.
2. All other objects (including Unicode objects) raise an
exception.
@@ -542,7 +521,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromEncodedObject(
Unicode objects are passed back as-is (subclasses are converted to
true Unicode objects), all other objects are delegated to
PyUnicode_FromEncodedObject(obj, NULL, "strict") which results in
- using the default encoding as basis for decoding the object.
+ using UTF-8 encoding as basis for decoding the object.
The API returns NULL in case of an error. The caller is responsible
for decref'ing the returned objects.
@@ -553,20 +532,40 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromObject(
register PyObject *obj /* Object */
);
-PyAPI_FUNC(PyObject *) PyUnicode_FromFormatV(const char*, va_list);
-PyAPI_FUNC(PyObject *) PyUnicode_FromFormat(const char*, ...);
+PyAPI_FUNC(PyObject *) PyUnicode_FromFormatV(
+ const char *format, /* ASCII-encoded string */
+ va_list vargs
+ );
+PyAPI_FUNC(PyObject *) PyUnicode_FromFormat(
+ const char *format, /* ASCII-encoded string */
+ ...
+ );
+#ifndef Py_LIMITED_API
/* Format the object based on the format_spec, as defined in PEP 3101
(Advanced String Formatting). */
PyAPI_FUNC(PyObject *) _PyUnicode_FormatAdvanced(PyObject *obj,
Py_UNICODE *format_spec,
Py_ssize_t format_spec_len);
+#endif
+
+PyAPI_FUNC(void) PyUnicode_InternInPlace(PyObject **);
+PyAPI_FUNC(void) PyUnicode_InternImmortal(PyObject **);
+PyAPI_FUNC(PyObject *) PyUnicode_InternFromString(
+ const char *u /* UTF-8 encoded string */
+ );
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(void) _Py_ReleaseInternedUnicodeStrings(void);
+#endif
+
+/* Use only if you know it's a string */
+#define PyUnicode_CHECK_INTERNED(op) (((PyUnicodeObject *)(op))->state)
/* --- wchar_t support for platforms which support it --------------------- */
#ifdef HAVE_WCHAR_H
-/* Create a Unicode Object from the whcar_t buffer w of the given
+/* Create a Unicode Object from the wchar_t buffer w of the given
size.
The buffer is copied into the new object. */
@@ -589,11 +588,24 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromWideChar(
error. */
PyAPI_FUNC(Py_ssize_t) PyUnicode_AsWideChar(
- PyUnicodeObject *unicode, /* Unicode object */
+ PyObject *unicode, /* Unicode object */
register wchar_t *w, /* wchar_t buffer */
Py_ssize_t size /* size of buffer */
);
+/* Convert the Unicode object to a wide character string. The output string
+ always ends with a nul character. If size is not NULL, write the number of
+ wide characters (excluding the null character) into *size.
+
+ Returns a buffer allocated by PyMem_Alloc() (use PyMem_Free() to free it)
+ on success. On error, returns NULL, *size is undefined and raises a
+ MemoryError. */
+
+PyAPI_FUNC(wchar_t*) PyUnicode_AsWideCharString(
+ PyObject *unicode, /* Unicode object */
+ Py_ssize_t *size /* number of characters of the result */
+ );
+
#endif
/* --- Unicode ordinals --------------------------------------------------- */
@@ -623,9 +635,9 @@ PyAPI_FUNC(int) PyUnicode_ClearFreeList(void);
Many of these APIs take two arguments encoding and errors. These
parameters encoding and errors have the same semantics as the ones
- of the builtin unicode() API.
+ of the builtin str() API.
- Setting encoding to NULL causes the default encoding to be used.
+ Setting encoding to NULL causes the default encoding (UTF-8) to be used.
Error handling is set by errors which may also be set to NULL
meaning to use the default handling defined for the codec. Default
@@ -642,7 +654,8 @@ PyAPI_FUNC(int) PyUnicode_ClearFreeList(void);
/* Return a Python string holding the default encoded value of the
Unicode object.
- The resulting string is cached in the Unicode object for subsequent
+ Same as PyUnicode_AsUTF8String() except
+ the resulting string is cached in the Unicode object for subsequent
usage by this function. The cached version is needed to implement
the character buffer interface and will live (at least) as long as
the Unicode object itself.
@@ -653,29 +666,53 @@ PyAPI_FUNC(int) PyUnicode_ClearFreeList(void);
*/
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) _PyUnicode_AsDefaultEncodedString(
- PyObject *, const char *);
+ PyObject *unicode,
+ const char *errors);
+#endif
-/* Returns the currently active default encoding.
+/* Returns a pointer to the default encoding (UTF-8) of the
+ Unicode object unicode and the size of the encoded representation
+ in bytes stored in *size.
- The default encoding is currently implemented as run-time settable
- process global. This may change in future versions of the
- interpreter to become a parameter which is managed on a per-thread
- basis.
+ In case of an error, no *size is set.
- */
+ *** This API is for interpreter INTERNAL USE ONLY and will likely
+ *** be removed or changed in the future.
-PyAPI_FUNC(const char*) PyUnicode_GetDefaultEncoding(void);
+ *** If you need to access the Unicode object as UTF-8 bytes string,
+ *** please use PyUnicode_AsUTF8String() instead.
+
+*/
-/* Sets the currently active default encoding.
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(char *) _PyUnicode_AsStringAndSize(
+ PyObject *unicode,
+ Py_ssize_t *size);
+#endif
- Returns 0 on success, -1 in case of an error.
+/* Returns a pointer to the default encoding (UTF-8) of the
+ Unicode object unicode.
- */
+ Use of this API is DEPRECATED since no size information can be
+ extracted from the returned data.
-PyAPI_FUNC(int) PyUnicode_SetDefaultEncoding(
- const char *encoding /* Encoding name in standard form */
- );
+ *** This API is for interpreter INTERNAL USE ONLY and will likely
+ *** be removed or changed for Python 3.1.
+
+ *** If you need to access the Unicode object as UTF-8 bytes string,
+ *** please use PyUnicode_AsUTF8String() instead.
+
+*/
+
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(char *) _PyUnicode_AsString(PyObject *unicode);
+#endif
+
+/* Returns "utf-8". */
+
+PyAPI_FUNC(const char*) PyUnicode_GetDefaultEncoding(void);
/* --- Generic Codecs ----------------------------------------------------- */
@@ -689,15 +726,35 @@ PyAPI_FUNC(PyObject*) PyUnicode_Decode(
const char *errors /* error handling */
);
+/* Decode a Unicode object unicode and return the result as Python
+ object. */
+
+PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedObject(
+ PyObject *unicode, /* Unicode object */
+ const char *encoding, /* encoding */
+ const char *errors /* error handling */
+ );
+
+/* Decode a Unicode object unicode and return the result as Unicode
+ object. */
+
+PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedUnicode(
+ PyObject *unicode, /* Unicode object */
+ const char *encoding, /* encoding */
+ const char *errors /* error handling */
+ );
+
/* Encodes a Py_UNICODE buffer of the given size and returns a
Python string object. */
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) PyUnicode_Encode(
const Py_UNICODE *s, /* Unicode char buffer */
Py_ssize_t size, /* number of Py_UNICODE chars to encode */
const char *encoding, /* encoding */
const char *errors /* error handling */
);
+#endif
/* Encodes a Unicode object and returns the result as Python
object. */
@@ -717,11 +774,21 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedString(
const char *errors /* error handling */
);
+/* Encodes a Unicode object and returns the result as Unicode
+ object. */
+
+PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedUnicode(
+ PyObject *unicode, /* Unicode object */
+ const char *encoding, /* encoding */
+ const char *errors /* error handling */
+ );
+
+/* Build an encoding map. */
+
PyAPI_FUNC(PyObject*) PyUnicode_BuildEncodingMap(
PyObject* string /* 256 character map */
);
-
/* --- UTF-7 Codecs ------------------------------------------------------- */
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7(
@@ -737,13 +804,15 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7Stateful(
Py_ssize_t *consumed /* bytes consumed */
);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7(
const Py_UNICODE *data, /* Unicode char buffer */
- Py_ssize_t length, /* number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* number of Py_UNICODE chars to encode */
int base64SetO, /* Encode RFC2152 Set O characters in base64 */
int base64WhiteSpace, /* Encode whitespace (sp, ht, nl, cr) in base64 */
const char *errors /* error handling */
);
+#endif
/* --- UTF-8 Codecs ------------------------------------------------------- */
@@ -757,18 +826,20 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8Stateful(
const char *string, /* UTF-8 encoded string */
Py_ssize_t length, /* size of string */
const char *errors, /* error handling */
- Py_ssize_t *consumed /* bytes consumed */
+ Py_ssize_t *consumed /* bytes consumed */
);
PyAPI_FUNC(PyObject*) PyUnicode_AsUTF8String(
PyObject *unicode /* Unicode object */
);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF8(
const Py_UNICODE *data, /* Unicode char buffer */
- Py_ssize_t length, /* number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* number of Py_UNICODE chars to encode */
const char *errors /* error handling */
);
+#endif
/* --- UTF-32 Codecs ------------------------------------------------------ */
@@ -837,12 +908,14 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsUTF32String(
*/
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF32(
const Py_UNICODE *data, /* Unicode char buffer */
Py_ssize_t length, /* number of Py_UNICODE chars to encode */
const char *errors, /* error handling */
int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */
);
+#endif
/* --- UTF-16 Codecs ------------------------------------------------------ */
@@ -885,7 +958,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16Stateful(
int *byteorder, /* pointer to byteorder to use
0=native;-1=LE,1=BE; updated on
exit */
- Py_ssize_t *consumed /* bytes consumed */
+ Py_ssize_t *consumed /* bytes consumed */
);
/* Returns a Python string using the UTF-16 encoding in native byte
@@ -915,12 +988,14 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsUTF16String(
*/
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF16(
const Py_UNICODE *data, /* Unicode char buffer */
- Py_ssize_t length, /* number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* number of Py_UNICODE chars to encode */
const char *errors, /* error handling */
int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */
);
+#endif
/* --- Unicode-Escape Codecs ---------------------------------------------- */
@@ -934,10 +1009,12 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsUnicodeEscapeString(
PyObject *unicode /* Unicode object */
);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUnicodeEscape(
const Py_UNICODE *data, /* Unicode char buffer */
- Py_ssize_t length /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length /* Number of Py_UNICODE chars to encode */
);
+#endif
/* --- Raw-Unicode-Escape Codecs ------------------------------------------ */
@@ -951,20 +1028,24 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsRawUnicodeEscapeString(
PyObject *unicode /* Unicode object */
);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) PyUnicode_EncodeRawUnicodeEscape(
const Py_UNICODE *data, /* Unicode char buffer */
- Py_ssize_t length /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length /* Number of Py_UNICODE chars to encode */
);
+#endif
/* --- Unicode Internal Codec ---------------------------------------------
Only for internal use in _codecsmodule.c */
+#ifndef Py_LIMITED_API
PyObject *_PyUnicode_DecodeUnicodeInternal(
const char *string,
Py_ssize_t length,
const char *errors
);
+#endif
/* --- Latin-1 Codecs -----------------------------------------------------
@@ -982,11 +1063,13 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsLatin1String(
PyObject *unicode /* Unicode object */
);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) PyUnicode_EncodeLatin1(
const Py_UNICODE *data, /* Unicode char buffer */
- Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
const char *errors /* error handling */
);
+#endif
/* --- ASCII Codecs -------------------------------------------------------
@@ -1004,11 +1087,13 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsASCIIString(
PyObject *unicode /* Unicode object */
);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) PyUnicode_EncodeASCII(
const Py_UNICODE *data, /* Unicode char buffer */
- Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
const char *errors /* error handling */
);
+#endif
/* --- Character Map Codecs -----------------------------------------------
@@ -1046,6 +1131,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsCharmapString(
(unicode ordinal -> char ordinal) */
);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) PyUnicode_EncodeCharmap(
const Py_UNICODE *data, /* Unicode char buffer */
Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
@@ -1053,6 +1139,7 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeCharmap(
(unicode ordinal -> char ordinal) */
const char *errors /* error handling */
);
+#endif
/* Translate a Py_UNICODE buffer of the given length by applying a
character mapping table to it and return the resulting Unicode
@@ -1067,12 +1154,14 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeCharmap(
*/
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyUnicode_TranslateCharmap(
const Py_UNICODE *data, /* Unicode char buffer */
- Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
PyObject *table, /* Translate table */
const char *errors /* error handling */
);
+#endif
#ifdef MS_WIN32
@@ -1095,11 +1184,13 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsMBCSString(
PyObject *unicode /* Unicode object */
);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS(
const Py_UNICODE *data, /* Unicode char buffer */
- Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
const char *errors /* error handling */
);
+#endif
#endif /* MS_WIN32 */
@@ -1127,12 +1218,75 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS(
*/
+#ifndef Py_LIMITED_API
PyAPI_FUNC(int) PyUnicode_EncodeDecimal(
Py_UNICODE *s, /* Unicode buffer */
- Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
char *output, /* Output buffer; must have size >= length */
const char *errors /* error handling */
);
+#endif
+
+/* Transforms code points that have decimal digit property to the
+ corresponding ASCII digit code points.
+
+ Returns a new Unicode string on success, NULL on failure.
+*/
+
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(PyObject*) PyUnicode_TransformDecimalToASCII(
+ Py_UNICODE *s, /* Unicode buffer */
+ Py_ssize_t length /* Number of Py_UNICODE chars to transform */
+ );
+#endif
+
+/* --- File system encoding ---------------------------------------------- */
+
+/* ParseTuple converter: encode str objects to bytes using
+ PyUnicode_EncodeFSDefault(); bytes objects are output as-is. */
+
+PyAPI_FUNC(int) PyUnicode_FSConverter(PyObject*, void*);
+
+/* ParseTuple converter: decode bytes objects to unicode using
+ PyUnicode_DecodeFSDefaultAndSize(); str objects are output as-is. */
+
+PyAPI_FUNC(int) PyUnicode_FSDecoder(PyObject*, void*);
+
+/* Decode a null-terminated string using Py_FileSystemDefaultEncoding
+ and the "surrogateescape" error handler.
+
+ If Py_FileSystemDefaultEncoding is not set, fall back to the locale
+ encoding.
+
+ Use PyUnicode_DecodeFSDefaultAndSize() if the string length is known.
+*/
+
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefault(
+ const char *s /* encoded string */
+ );
+
+/* Decode a string using Py_FileSystemDefaultEncoding
+ and the "surrogateescape" error handler.
+
+ If Py_FileSystemDefaultEncoding is not set, fall back to the locale
+ encoding.
+*/
+
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefaultAndSize(
+ const char *s, /* encoded string */
+ Py_ssize_t size /* size */
+ );
+
+/* Encode a Unicode object to Py_FileSystemDefaultEncoding with the
+ "surrogateescape" error handler, and return bytes.
+
+ If Py_FileSystemDefaultEncoding is not set, fall back to the locale
+ encoding.
+*/
+
+PyAPI_FUNC(PyObject*) PyUnicode_EncodeFSDefault(
+ PyObject *unicode
+ );
/* --- Methods & Slots ----------------------------------------------------
@@ -1147,6 +1301,22 @@ PyAPI_FUNC(PyObject*) PyUnicode_Concat(
PyObject *right /* Right string */
);
+/* Concat two strings and put the result in *pleft
+ (sets *pleft to NULL on error) */
+
+PyAPI_FUNC(void) PyUnicode_Append(
+ PyObject **pleft, /* Pointer to left string */
+ PyObject *right /* Right string */
+ );
+
+/* Concat two strings, put the result in *pleft and drop the right object
+ (sets *pleft to NULL on error) */
+
+PyAPI_FUNC(void) PyUnicode_AppendAndDel(
+ PyObject **pleft, /* Pointer to left string */
+ PyObject *right /* Right string */
+ );
+
/* Split a string giving a list of Unicode strings.
If sep is NULL, splitting will be done at all whitespace
@@ -1285,6 +1455,11 @@ PyAPI_FUNC(int) PyUnicode_Compare(
PyObject *right /* Right string */
);
+PyAPI_FUNC(int) PyUnicode_CompareWithASCIIString(
+ PyObject *left,
+ const char *right /* ASCII-encoded string */
+ );
+
/* Rich compare two strings and return one of the following:
- NULL in case an exception was raised
@@ -1326,17 +1501,54 @@ PyAPI_FUNC(int) PyUnicode_Contains(
PyObject *element /* Element string */
);
+/* Checks whether the string contains any NUL characters. */
+
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(int) _PyUnicode_HasNULChars(PyObject *);
+#endif
+
+/* Checks whether argument is a valid identifier. */
+
+PyAPI_FUNC(int) PyUnicode_IsIdentifier(PyObject *s);
+
+#ifndef Py_LIMITED_API
/* Externally visible for str.strip(unicode) */
PyAPI_FUNC(PyObject *) _PyUnicode_XStrip(
PyUnicodeObject *self,
int striptype,
PyObject *sepobj
);
+#endif
+
+/* Using the current locale, insert the thousands grouping
+ into the string pointed to by buffer. For the argument descriptions,
+ see Objects/stringlib/localeutil.h */
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(Py_ssize_t) _PyUnicode_InsertThousandsGroupingLocale(Py_UNICODE *buffer,
+ Py_ssize_t n_buffer,
+ Py_UNICODE *digits,
+ Py_ssize_t n_digits,
+ Py_ssize_t min_width);
+#endif
+
+/* Using explicit passed-in values, insert the thousands grouping
+ into the string pointed to by buffer. For the argument descriptions,
+ see Objects/stringlib/localeutil.h */
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(Py_ssize_t) _PyUnicode_InsertThousandsGrouping(Py_UNICODE *buffer,
+ Py_ssize_t n_buffer,
+ Py_UNICODE *digits,
+ Py_ssize_t n_digits,
+ Py_ssize_t min_width,
+ const char *grouping,
+ const char *thousands_sep);
+#endif
/* === Characters Type APIs =============================================== */
/* Helper array used by Py_UNICODE_ISSPACE(). */
+#ifndef Py_LIMITED_API
PyAPI_DATA(const unsigned char) _Py_ascii_whitespace[];
/* These should not be used directly. Use the Py_UNICODE_IS* and
@@ -1347,67 +1559,124 @@ PyAPI_DATA(const unsigned char) _Py_ascii_whitespace[];
*/
PyAPI_FUNC(int) _PyUnicode_IsLowercase(
- Py_UNICODE ch /* Unicode character */
+ Py_UCS4 ch /* Unicode character */
);
PyAPI_FUNC(int) _PyUnicode_IsUppercase(
- Py_UNICODE ch /* Unicode character */
+ Py_UCS4 ch /* Unicode character */
);
PyAPI_FUNC(int) _PyUnicode_IsTitlecase(
- Py_UNICODE ch /* Unicode character */
+ Py_UCS4 ch /* Unicode character */
+ );
+
+PyAPI_FUNC(int) _PyUnicode_IsXidStart(
+ Py_UCS4 ch /* Unicode character */
+ );
+
+PyAPI_FUNC(int) _PyUnicode_IsXidContinue(
+ Py_UCS4 ch /* Unicode character */
);
PyAPI_FUNC(int) _PyUnicode_IsWhitespace(
- const Py_UNICODE ch /* Unicode character */
+ const Py_UCS4 ch /* Unicode character */
);
PyAPI_FUNC(int) _PyUnicode_IsLinebreak(
- const Py_UNICODE ch /* Unicode character */
+ const Py_UCS4 ch /* Unicode character */
);
-PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToLowercase(
- Py_UNICODE ch /* Unicode character */
+PyAPI_FUNC(Py_UCS4) _PyUnicode_ToLowercase(
+ Py_UCS4 ch /* Unicode character */
);
-PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToUppercase(
- Py_UNICODE ch /* Unicode character */
+PyAPI_FUNC(Py_UCS4) _PyUnicode_ToUppercase(
+ Py_UCS4 ch /* Unicode character */
);
-PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToTitlecase(
- Py_UNICODE ch /* Unicode character */
+PyAPI_FUNC(Py_UCS4) _PyUnicode_ToTitlecase(
+ Py_UCS4 ch /* Unicode character */
);
PyAPI_FUNC(int) _PyUnicode_ToDecimalDigit(
- Py_UNICODE ch /* Unicode character */
+ Py_UCS4 ch /* Unicode character */
);
PyAPI_FUNC(int) _PyUnicode_ToDigit(
- Py_UNICODE ch /* Unicode character */
+ Py_UCS4 ch /* Unicode character */
);
PyAPI_FUNC(double) _PyUnicode_ToNumeric(
- Py_UNICODE ch /* Unicode character */
+ Py_UCS4 ch /* Unicode character */
);
PyAPI_FUNC(int) _PyUnicode_IsDecimalDigit(
- Py_UNICODE ch /* Unicode character */
+ Py_UCS4 ch /* Unicode character */
);
PyAPI_FUNC(int) _PyUnicode_IsDigit(
- Py_UNICODE ch /* Unicode character */
+ Py_UCS4 ch /* Unicode character */
);
PyAPI_FUNC(int) _PyUnicode_IsNumeric(
- Py_UNICODE ch /* Unicode character */
+ Py_UCS4 ch /* Unicode character */
+ );
+
+PyAPI_FUNC(int) _PyUnicode_IsPrintable(
+ Py_UCS4 ch /* Unicode character */
);
PyAPI_FUNC(int) _PyUnicode_IsAlpha(
- Py_UNICODE ch /* Unicode character */
+ Py_UCS4 ch /* Unicode character */
+ );
+
+PyAPI_FUNC(size_t) Py_UNICODE_strlen(
+ const Py_UNICODE *u
+ );
+
+PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcpy(
+ Py_UNICODE *s1,
+ const Py_UNICODE *s2);
+
+PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strcat(
+ Py_UNICODE *s1, const Py_UNICODE *s2);
+
+PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strncpy(
+ Py_UNICODE *s1,
+ const Py_UNICODE *s2,
+ size_t n);
+
+PyAPI_FUNC(int) Py_UNICODE_strcmp(
+ const Py_UNICODE *s1,
+ const Py_UNICODE *s2
+ );
+
+PyAPI_FUNC(int) Py_UNICODE_strncmp(
+ const Py_UNICODE *s1,
+ const Py_UNICODE *s2,
+ size_t n
+ );
+
+PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr(
+ const Py_UNICODE *s,
+ Py_UNICODE c
+ );
+
+PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr(
+ const Py_UNICODE *s,
+ Py_UNICODE c
+ );
+
+/* Create a copy of a unicode string ending with a nul character. Return NULL
+ and raise a MemoryError exception on memory allocation failure, otherwise
+ return a new allocated buffer (use PyMem_Free() to free the buffer). */
+
+PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy(
+ PyObject *unicode
);
+#endif /* Py_LIMITED_API */
#ifdef __cplusplus
}
#endif
-#endif /* Py_USING_UNICODE */
#endif /* !Py_UNICODEOBJECT_H */
diff --git a/Include/warnings.h b/Include/warnings.h
index 0818d7a117e..b7db681cc41 100644
--- a/Include/warnings.h
+++ b/Include/warnings.h
@@ -4,17 +4,31 @@
extern "C" {
#endif
-PyAPI_FUNC(void) _PyWarnings_Init(void);
-
-PyAPI_FUNC(int) PyErr_WarnEx(PyObject *, const char *, Py_ssize_t);
-PyAPI_FUNC(int) PyErr_WarnExplicit(PyObject *, const char *, const char *, int,
- const char *, PyObject *);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(PyObject*) _PyWarnings_Init(void);
+#endif
-#define PyErr_WarnPy3k(msg, stacklevel) \
- (Py_Py3kWarningFlag ? PyErr_WarnEx(PyExc_DeprecationWarning, msg, stacklevel) : 0)
+PyAPI_FUNC(int) PyErr_WarnEx(
+ PyObject *category,
+ const char *message, /* UTF-8 encoded string */
+ Py_ssize_t stack_level);
+PyAPI_FUNC(int) PyErr_WarnFormat(
+ PyObject *category,
+ Py_ssize_t stack_level,
+ const char *format, /* ASCII-encoded string */
+ ...);
+PyAPI_FUNC(int) PyErr_WarnExplicit(
+ PyObject *category,
+ const char *message, /* UTF-8 encoded string */
+ const char *filename, /* decoded from the filesystem encoding */
+ int lineno,
+ const char *module, /* UTF-8 encoded string */
+ PyObject *registry);
/* DEPRECATED: Use PyErr_WarnEx() instead. */
+#ifndef Py_LIMITED_API
#define PyErr_Warn(category, msg) PyErr_WarnEx(category, msg, 1)
+#endif
#ifdef __cplusplus
}
diff --git a/Include/weakrefobject.h b/Include/weakrefobject.h
index e46aecf3858..537e7ebf287 100644
--- a/Include/weakrefobject.h
+++ b/Include/weakrefobject.h
@@ -12,6 +12,7 @@ typedef struct _PyWeakReference PyWeakReference;
/* PyWeakReference is the base struct for the Python ReferenceType, ProxyType,
* and CallableProxyType.
*/
+#ifndef Py_LIMITED_API
struct _PyWeakReference {
PyObject_HEAD
@@ -27,7 +28,7 @@ struct _PyWeakReference {
/* A cache for wr_object's hash code. As usual for hashes, this is -1
* if the hash code isn't known yet.
*/
- long hash;
+ Py_hash_t hash;
/* If wr_object is weakly referenced, wr_object has a doubly-linked NULL-
* terminated list of weak references to it. These are the list pointers.
@@ -37,6 +38,7 @@ struct _PyWeakReference {
PyWeakReference *wr_prev;
PyWeakReference *wr_next;
};
+#endif
PyAPI_DATA(PyTypeObject) _PyWeakref_RefType;
PyAPI_DATA(PyTypeObject) _PyWeakref_ProxyType;
@@ -62,9 +64,11 @@ PyAPI_FUNC(PyObject *) PyWeakref_NewProxy(PyObject *ob,
PyObject *callback);
PyAPI_FUNC(PyObject *) PyWeakref_GetObject(PyObject *ref);
+#ifndef Py_LIMITED_API
PyAPI_FUNC(Py_ssize_t) _PyWeakref_GetWeakrefCount(PyWeakReference *head);
PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
+#endif
/* Explanation for the Py_REFCNT() check: when a weakref's target is part
of a long chain of deallocations which triggers the trashcan mechanism,