summaryrefslogtreecommitdiff
path: root/Include
diff options
context:
space:
mode:
Diffstat (limited to 'Include')
-rw-r--r--Include/Python-ast.h33
-rw-r--r--Include/Python.h5
-rw-r--r--Include/abstract.h14
-rw-r--r--Include/bytes_methods.h35
-rw-r--r--Include/bytesobject.h6
-rw-r--r--Include/cStringIO.h7
-rw-r--r--Include/ceval.h4
-rw-r--r--Include/classobject.h1
-rw-r--r--Include/cobject.h26
-rw-r--r--Include/code.h24
-rw-r--r--Include/codecs.h8
-rw-r--r--Include/compile.h2
-rw-r--r--Include/complexobject.h6
-rw-r--r--Include/datetime.h14
-rw-r--r--Include/dictobject.h13
-rw-r--r--Include/dtoa.h15
-rw-r--r--Include/fileobject.h14
-rw-r--r--Include/floatobject.h13
-rw-r--r--Include/frameobject.h10
-rw-r--r--Include/graminit.h12
-rw-r--r--Include/import.h2
-rw-r--r--Include/longintrepr.h71
-rw-r--r--Include/longobject.h17
-rw-r--r--Include/memoryobject.h74
-rw-r--r--Include/object.h31
-rw-r--r--Include/objimpl.h18
-rw-r--r--Include/opcode.h31
-rw-r--r--Include/patchlevel.h15
-rw-r--r--Include/py_curses.h15
-rw-r--r--Include/pycapsule.h56
-rw-r--r--Include/pyctype.h31
-rw-r--r--Include/pyerrors.h19
-rw-r--r--Include/pyexpat.h1
-rw-r--r--Include/pymacconfig.h19
-rw-r--r--Include/pymath.h31
-rw-r--r--Include/pymem.h10
-rw-r--r--Include/pyport.h185
-rw-r--r--Include/pystate.h1
-rw-r--r--Include/pystrtod.h29
-rw-r--r--Include/pythonrun.h3
-rw-r--r--Include/pythread.h9
-rw-r--r--Include/stringobject.h86
-rw-r--r--Include/symtable.h11
-rw-r--r--Include/token.h2
-rw-r--r--Include/tupleobject.h1
-rw-r--r--Include/ucnhash.h4
-rw-r--r--Include/unicodeobject.h6
47 files changed, 788 insertions, 252 deletions
diff --git a/Include/Python-ast.h b/Include/Python-ast.h
index 3210fc7ba9..3f35bbb634 100644
--- a/Include/Python-ast.h
+++ b/Include/Python-ast.h
@@ -185,11 +185,11 @@ struct _stmt {
};
enum _expr_kind {BoolOp_kind=1, BinOp_kind=2, UnaryOp_kind=3, Lambda_kind=4,
- IfExp_kind=5, Dict_kind=6, ListComp_kind=7,
- GeneratorExp_kind=8, Yield_kind=9, Compare_kind=10,
- Call_kind=11, Repr_kind=12, Num_kind=13, Str_kind=14,
- Attribute_kind=15, Subscript_kind=16, Name_kind=17,
- List_kind=18, Tuple_kind=19};
+ 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};
struct _expr {
enum _expr_kind kind;
union {
@@ -226,6 +226,10 @@ struct _expr {
} Dict;
struct {
+ asdl_seq *elts;
+ } Set;
+
+ struct {
expr_ty elt;
asdl_seq *generators;
} ListComp;
@@ -233,6 +237,17 @@ struct _expr {
struct {
expr_ty elt;
asdl_seq *generators;
+ } SetComp;
+
+ struct {
+ expr_ty key;
+ expr_ty value;
+ asdl_seq *generators;
+ } DictComp;
+
+ struct {
+ expr_ty elt;
+ asdl_seq *generators;
} GeneratorExp;
struct {
@@ -449,9 +464,17 @@ expr_ty _Py_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
#define Dict(a0, a1, a2, a3, a4) _Py_Dict(a0, a1, a2, a3, a4)
expr_ty _Py_Dict(asdl_seq * keys, asdl_seq * values, int lineno, int
col_offset, PyArena *arena);
+#define Set(a0, a1, a2, a3) _Py_Set(a0, a1, a2, a3)
+expr_ty _Py_Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena);
#define ListComp(a0, a1, a2, a3, a4) _Py_ListComp(a0, a1, a2, a3, a4)
expr_ty _Py_ListComp(expr_ty elt, asdl_seq * generators, int lineno, int
col_offset, PyArena *arena);
+#define SetComp(a0, a1, a2, a3, a4) _Py_SetComp(a0, a1, a2, a3, a4)
+expr_ty _Py_SetComp(expr_ty elt, asdl_seq * generators, int lineno, int
+ col_offset, PyArena *arena);
+#define DictComp(a0, a1, a2, a3, a4, a5) _Py_DictComp(a0, a1, a2, a3, a4, a5)
+expr_ty _Py_DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int
+ lineno, int col_offset, PyArena *arena);
#define GeneratorExp(a0, a1, a2, a3, a4) _Py_GeneratorExp(a0, a1, a2, a3, a4)
expr_ty _Py_GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int
col_offset, PyArena *arena);
diff --git a/Include/Python.h b/Include/Python.h
index b09b4bbb70..775412b8c4 100644
--- a/Include/Python.h
+++ b/Include/Python.h
@@ -92,7 +92,7 @@
#endif
#include "rangeobject.h"
#include "stringobject.h"
-/* #include "memoryobject.h" */
+#include "memoryobject.h"
#include "bufferobject.h"
#include "bytesobject.h"
#include "bytearrayobject.h"
@@ -107,6 +107,7 @@
#include "classobject.h"
#include "fileobject.h"
#include "cobject.h"
+#include "pycapsule.h"
#include "traceback.h"
#include "sliceobject.h"
#include "cellobject.h"
@@ -134,8 +135,10 @@
#include "compile.h"
#include "eval.h"
+#include "pyctype.h"
#include "pystrtod.h"
#include "pystrcmp.h"
+#include "dtoa.h"
/* _Py_Mangle is defined in compile.c */
PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
diff --git a/Include/abstract.h b/Include/abstract.h
index c78ab00e84..a377423868 100644
--- a/Include/abstract.h
+++ b/Include/abstract.h
@@ -509,7 +509,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
arbitrary data.
0 is returned on success. buffer and buffer_len are only
- set in case no error occurrs. Otherwise, -1 is returned and
+ set in case no error occurs. Otherwise, -1 is returned and
an exception set.
*/
@@ -524,7 +524,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
writeable memory location in buffer of size buffer_len.
0 is returned on success. buffer and buffer_len are only
- set in case no error occurrs. Otherwise, -1 is returned and
+ set in case no error occurs. Otherwise, -1 is returned and
an exception set.
*/
@@ -636,7 +636,8 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
#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 *);
/* Takes an iterator object and calls its tp_iternext slot,
@@ -1382,6 +1383,13 @@ PyAPI_FUNC(int) _PyObject_RealIsInstance(PyObject *inst, PyObject *cls);
PyAPI_FUNC(int) _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls);
+/* For internal use by buffer API functions */
+PyAPI_FUNC(void) _Py_add_one_to_index_F(int nd, Py_ssize_t *index,
+ const Py_ssize_t *shape);
+PyAPI_FUNC(void) _Py_add_one_to_index_C(int nd, Py_ssize_t *index,
+ const Py_ssize_t *shape);
+
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/bytes_methods.h b/Include/bytes_methods.h
index 59873f29a0..4125666212 100644
--- a/Include/bytes_methods.h
+++ b/Include/bytes_methods.h
@@ -34,23 +34,15 @@ extern const char _Py_title__doc__[];
extern const char _Py_capitalize__doc__[];
extern const char _Py_swapcase__doc__[];
-#define FLAG_LOWER 0x01
-#define FLAG_UPPER 0x02
-#define FLAG_ALPHA (FLAG_LOWER|FLAG_UPPER)
-#define FLAG_DIGIT 0x04
-#define FLAG_ALNUM (FLAG_ALPHA|FLAG_DIGIT)
-#define FLAG_SPACE 0x08
-#define FLAG_XDIGIT 0x10
-
-extern const unsigned int _Py_ctype_table[256];
-
-#define ISLOWER(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_LOWER)
-#define ISUPPER(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_UPPER)
-#define ISALPHA(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_ALPHA)
-#define ISDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_DIGIT)
-#define ISXDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_XDIGIT)
-#define ISALNUM(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_ALNUM)
-#define ISSPACE(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_SPACE)
+/* 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)
@@ -67,11 +59,10 @@ extern const unsigned int _Py_ctype_table[256];
#undef isspace
#define isspace(c) undefined_isspace(c)
-extern const unsigned char _Py_ctype_tolower[256];
-extern const unsigned char _Py_ctype_toupper[256];
-
-#define TOLOWER(c) (_Py_ctype_tolower[Py_CHARMASK(c)])
-#define TOUPPER(c) (_Py_ctype_toupper[Py_CHARMASK(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)
diff --git a/Include/bytesobject.h b/Include/bytesobject.h
index a50792c35b..1083da9c82 100644
--- a/Include/bytesobject.h
+++ b/Include/bytesobject.h
@@ -23,11 +23,5 @@
#define _PyBytes_FormatLong _PyString_FormatLong
#define PyBytes_DecodeEscape PyString_DecodeEscape
#define _PyBytes_Join _PyString_Join
-#define PyBytes_Decode PyString_Decode
-#define PyBytes_Encode PyString_Encode
-#define PyBytes_AsEncodedObject PyString_AsEncodedObject
-#define PyBytes_AsEncodedString PyString_AsEncodedString
-#define PyBytes_AsDecodedObject PyString_AsDecodedObject
-#define PyBytes_AsDecodedString PyString_AsDecodedString
#define PyBytes_AsStringAndSize PyString_AsStringAndSize
#define _PyBytes_InsertThousandsGrouping _PyString_InsertThousandsGrouping
diff --git a/Include/cStringIO.h b/Include/cStringIO.h
index d22b9ebb30..6ca44a8303 100644
--- a/Include/cStringIO.h
+++ b/Include/cStringIO.h
@@ -18,9 +18,12 @@ extern "C" {
This would typically be done in your init function.
*/
+
+#define PycStringIO_CAPSULE_NAME "cStringIO.cStringIO_CAPI"
+
#define PycString_IMPORT \
- PycStringIO = (struct PycStringIO_CAPI*)PyCObject_Import("cStringIO", \
- "cStringIO_CAPI")
+ PycStringIO = ((struct PycStringIO_CAPI*)PyCapsule_Import(\
+ PycStringIO_CAPSULE_NAME, 0))
/* Basic functions to manipulate cStringIO objects from C */
diff --git a/Include/ceval.h b/Include/ceval.h
index 40f7b9428b..0e8bd2ab11 100644
--- a/Include/ceval.h
+++ b/Include/ceval.h
@@ -10,10 +10,6 @@ extern "C" {
PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
PyObject *, PyObject *, PyObject *);
-/* DLL-level Backwards compatibility: */
-#undef PyEval_CallObject
-PyAPI_FUNC(PyObject *) PyEval_CallObject(PyObject *, PyObject *);
-
/* Inline this */
#define PyEval_CallObject(func,arg) \
PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
diff --git a/Include/classobject.h b/Include/classobject.h
index 118dd09647..bc03e0d027 100644
--- a/Include/classobject.h
+++ b/Include/classobject.h
@@ -18,6 +18,7 @@ typedef struct {
PyObject *cl_getattr;
PyObject *cl_setattr;
PyObject *cl_delattr;
+ PyObject *cl_weakreflist; /* List of weak references */
} PyClassObject;
typedef struct {
diff --git a/Include/cobject.h b/Include/cobject.h
index 4e24d7dcd6..ad3cd9c982 100644
--- a/Include/cobject.h
+++ b/Include/cobject.h
@@ -1,3 +1,29 @@
+/*
+ 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.
diff --git a/Include/code.h b/Include/code.h
index 8c00700a89..38b2958046 100644
--- a/Include/code.h
+++ b/Include/code.h
@@ -23,8 +23,10 @@ typedef struct {
PyObject *co_filename; /* string (where it was loaded from) */
PyObject *co_name; /* string (name, for reference) */
int co_firstlineno; /* first source line number */
- PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) */
+ PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) See
+ Objects/lnotab_notes.txt for details. */
void *co_zombieframe; /* for optimization only (see frameobject.c) */
+ PyObject *co_weakreflist; /* to support weakrefs to code objects */
} PyCodeObject;
/* Masks for co_flags above */
@@ -70,6 +72,14 @@ PyAPI_FUNC(PyCodeObject *) PyCode_New(
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. */
+PyAPI_FUNC(PyCodeObject *)
+PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno);
+
+/* Return the line number associated with the specified bytecode index
+ in this code object. If you just need the line number of a frame,
+ use PyFrame_GetLineNumber() instead. */
PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
/* for internal use only */
@@ -82,15 +92,11 @@ typedef struct _addr_pair {
int ap_upper;
} PyAddrPair;
-/* Check whether lasti (an instruction offset) falls outside bounds
- and whether it is a line number that should be traced. Returns
- a line number if it should be traced or -1 if the line should not.
-
- If lasti is not within bounds, updates bounds.
+/* Update *bounds to describe the first and one-past-the-last instructions in the
+ same line as lasti. Return the number of that line.
*/
-
-PyAPI_FUNC(int) PyCode_CheckLineNumber(PyCodeObject* co,
- int lasti, PyAddrPair *bounds);
+PyAPI_FUNC(int) _PyCode_CheckLineNumber(PyCodeObject* co,
+ int lasti, PyAddrPair *bounds);
PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts,
PyObject *names, PyObject *lineno_obj);
diff --git a/Include/codecs.h b/Include/codecs.h
index 0d76241dbf..c038c6a92c 100644
--- a/Include/codecs.h
+++ b/Include/codecs.h
@@ -133,7 +133,7 @@ PyAPI_FUNC(PyObject *) PyCodec_StreamWriter(
/* Unicode encoding error handling callback registry API */
-/* Register the error handling callback function error under the name
+/* Register the error handling callback function error under the given
name. This function will be called by the codec when it encounters
unencodable characters/undecodable bytes and doesn't know the
callback name, when name is specified as the error parameter
@@ -141,8 +141,8 @@ PyAPI_FUNC(PyObject *) PyCodec_StreamWriter(
Return 0 on success, -1 on error */
PyAPI_FUNC(int) PyCodec_RegisterError(const char *name, PyObject *error);
-/* Lookup the error handling callback function registered under the
- name error. As a special case NULL can be passed, in which case
+/* Lookup the error handling callback function registered under the given
+ name. As a special case NULL can be passed, in which case
the error handling callback for "strict" will be returned. */
PyAPI_FUNC(PyObject *) PyCodec_LookupError(const char *name);
@@ -152,7 +152,7 @@ PyAPI_FUNC(PyObject *) PyCodec_StrictErrors(PyObject *exc);
/* ignore the unicode error, skipping the faulty input */
PyAPI_FUNC(PyObject *) PyCodec_IgnoreErrors(PyObject *exc);
-/* replace the unicode error with ? or U+FFFD */
+/* replace the unicode encode error with ? or U+FFFD */
PyAPI_FUNC(PyObject *) PyCodec_ReplaceErrors(PyObject *exc);
/* replace the unicode encode error with XML character references */
diff --git a/Include/compile.h b/Include/compile.h
index 43a470d28f..61001016aa 100644
--- a/Include/compile.h
+++ b/Include/compile.h
@@ -33,8 +33,6 @@ PyAPI_FUNC(PyCodeObject *) PyAST_Compile(struct _mod *, const char *,
PyCompilerFlags *, PyArena *);
PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(struct _mod *, const char *);
-#define ERR_LATE_FUTURE \
-"from __future__ imports must occur at the beginning of the file"
#ifdef __cplusplus
}
diff --git a/Include/complexobject.h b/Include/complexobject.h
index 84b6d8b7e1..c9a9500fd7 100644
--- a/Include/complexobject.h
+++ b/Include/complexobject.h
@@ -54,6 +54,12 @@ PyAPI_FUNC(double) PyComplex_RealAsDouble(PyObject *op);
PyAPI_FUNC(double) PyComplex_ImagAsDouble(PyObject *op);
PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op);
+/* Format the object based on the format_spec, as defined in PEP 3101
+ (Advanced String Formatting). */
+PyAPI_FUNC(PyObject *) _PyComplex_FormatAdvanced(PyObject *obj,
+ char *format_spec,
+ Py_ssize_t format_spec_len);
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/datetime.h b/Include/datetime.h
index 28318ea551..47abe5cb86 100644
--- a/Include/datetime.h
+++ b/Include/datetime.h
@@ -158,6 +158,8 @@ typedef struct {
} PyDateTime_CAPI;
+#define PyDateTime_CAPSULE_NAME "datetime.datetime_CAPI"
+
/* "magic" constant used to partially protect against developer mistakes. */
#define DATETIME_API_MAGIC 0x414548d5
@@ -183,18 +185,10 @@ typedef struct {
#else
/* Define global variable for the C API and a macro for setting it. */
-static PyDateTime_CAPI *PyDateTimeAPI;
-
-#define PyDateTime_IMPORT \
- PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import("datetime", \
- "datetime_CAPI")
+static PyDateTime_CAPI *PyDateTimeAPI = NULL;
-/* This macro would be used if PyCObject_ImportEx() was created.
#define PyDateTime_IMPORT \
- PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_ImportEx("datetime", \
- "datetime_CAPI", \
- DATETIME_API_MAGIC)
-*/
+ PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)
/* Macros for type checking when not building the Python core. */
#define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType)
diff --git a/Include/dictobject.h b/Include/dictobject.h
index b046fc7ac8..ece01c64d6 100644
--- a/Include/dictobject.h
+++ b/Include/dictobject.h
@@ -89,10 +89,22 @@ struct _dictobject {
};
PyAPI_DATA(PyTypeObject) PyDict_Type;
+PyAPI_DATA(PyTypeObject) PyDictIterKey_Type;
+PyAPI_DATA(PyTypeObject) PyDictIterValue_Type;
+PyAPI_DATA(PyTypeObject) PyDictIterItem_Type;
+PyAPI_DATA(PyTypeObject) PyDictKeys_Type;
+PyAPI_DATA(PyTypeObject) PyDictItems_Type;
+PyAPI_DATA(PyTypeObject) PyDictValues_Type;
#define PyDict_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
#define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
+#define PyDictKeys_Check(op) (Py_TYPE(op) == &PyDictKeys_Type)
+#define PyDictItems_Check(op) (Py_TYPE(op) == &PyDictItems_Type)
+#define PyDictValues_Check(op) (Py_TYPE(op) == &PyDictValues_Type)
+/* This excludes Values, since they are not sets. */
+# 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);
@@ -111,6 +123,7 @@ 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);
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
+PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);
/* 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
new file mode 100644
index 0000000000..9b434b77b6
--- /dev/null
+++ b/Include/dtoa.h
@@ -0,0 +1,15 @@
+#ifndef PY_NO_SHORT_FLOAT_REPR
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+PyAPI_FUNC(double) _Py_dg_strtod(const char *str, char **ptr);
+PyAPI_FUNC(char *) _Py_dg_dtoa(double d, int mode, int ndigits,
+ int *decpt, int *sign, char **rve);
+PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/Include/fileobject.h b/Include/fileobject.h
index c2334b21c0..ba506ec0b3 100644
--- a/Include/fileobject.h
+++ b/Include/fileobject.h
@@ -70,6 +70,20 @@ size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
*/
int _PyFile_SanitizeMode(char *mode);
+#if defined _MSC_VER && _MSC_VER >= 1400
+/* A routine to check if a file descriptor is valid on Windows. Returns 0
+ * and sets errno to EBADF if it isn't. This is to avoid Assertions
+ * from various functions in the Windows CRT beginning with
+ * 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
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/floatobject.h b/Include/floatobject.h
index 60ede40f85..54e88256a2 100644
--- a/Include/floatobject.h
+++ b/Include/floatobject.h
@@ -21,6 +21,12 @@ 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
@@ -121,6 +127,13 @@ PyAPI_FUNC(PyObject *) _PyFloat_FormatAdvanced(PyObject *obj,
char *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);
+
+
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/frameobject.h b/Include/frameobject.h
index 297b66ddb2..17e7679ac8 100644
--- a/Include/frameobject.h
+++ b/Include/frameobject.h
@@ -38,8 +38,11 @@ typedef struct _frame {
PyThreadState *f_tstate;
int f_lasti; /* Last instruction if called */
- /* As of 2.3 f_lineno is only valid when tracing is active (i.e. when
- f_trace is set) -- at other times use PyCode_Addr2Line instead. */
+ /* Call PyFrame_GetLineNumber() instead of reading this field
+ directly. As of 2.3 f_lineno is only valid when tracing is
+ active (i.e. when f_trace is set). At other times we use
+ PyCode_Addr2Line to calculate the line from the current
+ bytecode index. */
int f_lineno; /* Current line number */
int f_iblock; /* index in f_blockstack */
PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
@@ -77,6 +80,9 @@ PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
PyAPI_FUNC(int) PyFrame_ClearFreeList(void);
+/* Return the line of code the frame is currently executing. */
+PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *);
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/graminit.h b/Include/graminit.h
index 38b4dacff1..40d531e8a1 100644
--- a/Include/graminit.h
+++ b/Include/graminit.h
@@ -42,7 +42,7 @@
#define for_stmt 295
#define try_stmt 296
#define with_stmt 297
-#define with_var 298
+#define with_item 298
#define except_clause 299
#define suite 300
#define testlist_safe 301
@@ -64,7 +64,7 @@
#define power 317
#define atom 318
#define listmaker 319
-#define testlist_gexp 320
+#define testlist_comp 320
#define lambdef 321
#define trailer 322
#define subscriptlist 323
@@ -72,16 +72,16 @@
#define sliceop 325
#define exprlist 326
#define testlist 327
-#define dictmaker 328
+#define dictorsetmaker 328
#define classdef 329
#define arglist 330
#define argument 331
#define list_iter 332
#define list_for 333
#define list_if 334
-#define gen_iter 335
-#define gen_for 336
-#define gen_if 337
+#define comp_iter 335
+#define comp_for 336
+#define comp_if 337
#define testlist1 338
#define encoding_decl 339
#define yield_expr 340
diff --git a/Include/import.h b/Include/import.h
index 76aecdda65..1b7fe0a73c 100644
--- a/Include/import.h
+++ b/Include/import.h
@@ -51,7 +51,7 @@ struct _inittab {
PyAPI_DATA(PyTypeObject) PyNullImporter_Type;
PyAPI_DATA(struct _inittab *) PyImport_Inittab;
-PyAPI_FUNC(int) PyImport_AppendInittab(char *name, void (*initfunc)(void));
+PyAPI_FUNC(int) PyImport_AppendInittab(const char *name, void (*initfunc)(void));
PyAPI_FUNC(int) PyImport_ExtendInittab(struct _inittab *newtab);
struct _frozen {
diff --git a/Include/longintrepr.h b/Include/longintrepr.h
index df157a8f98..6425c30f39 100644
--- a/Include/longintrepr.h
+++ b/Include/longintrepr.h
@@ -7,26 +7,61 @@ extern "C" {
/* This is published for the benefit of "friend" marshal.c only. */
-/* Parameters of the long integer representation.
- These shouldn't have to be changed as C should guarantee that a short
- contains at least 16 bits, but it's made changeable anyway.
- Note: 'digit' should be able to hold 2*MASK+1, and 'twodigits'
- should be able to hold the intermediate results in 'mul'
- (at most (BASE-1)*(2*BASE+1) == MASK*(2*MASK+3)).
- Also, x_sub assumes that 'digit' is an unsigned type, and overflow
- is handled by taking the result mod 2**N for some N > SHIFT.
- And, at some places it is assumed that MASK fits in an int, as well.
- long_pow() requires that SHIFT be divisible by 5. */
+/* Parameters of the long integer representation. There are two different
+ sets of parameters: one set for 30-bit digits, stored in an unsigned 32-bit
+ integer type, and one set for 15-bit digits with each digit stored in an
+ unsigned short. The value of PYLONG_BITS_IN_DIGIT, defined either at
+ configure time or in pyport.h, is used to decide which digit size to use.
+ Type 'digit' should be able to hold 2*PyLong_BASE-1, and type 'twodigits'
+ should be an unsigned integer type able to hold all integers up to
+ PyLong_BASE*PyLong_BASE-1. x_sub assumes that 'digit' is an unsigned type,
+ and that overflow is handled by taking the result modulo 2**N for some N >
+ PyLong_SHIFT. The majority of the code doesn't care about the precise
+ value of PyLong_SHIFT, but there are some notable exceptions:
+
+ - long_pow() requires that PyLong_SHIFT be divisible by 5
+
+ - PyLong_{As,From}ByteArray require that PyLong_SHIFT be at least 8
+
+ - long_hash() requires that PyLong_SHIFT is *strictly* less than the number
+ of bits in an unsigned long, as do the PyLong <-> long (or unsigned long)
+ conversion functions
+
+ - the long <-> size_t/Py_ssize_t conversion functions expect that
+ PyLong_SHIFT is strictly less than the number of bits in a size_t
+
+ - the marshal code currently expects that PyLong_SHIFT is a multiple of 15
+
+ The values 15 and 30 should fit all of the above requirements, on any
+ platform.
+*/
+
+#if PYLONG_BITS_IN_DIGIT == 30
+#if !(defined HAVE_UINT64_T && defined HAVE_UINT32_T && \
+ defined HAVE_INT64_T && defined HAVE_INT32_T)
+#error "30-bit long digits requested, but the necessary types are not available on this platform"
+#endif
+typedef PY_UINT32_T digit;
+typedef PY_INT32_T sdigit; /* signed variant of digit */
+typedef PY_UINT64_T twodigits;
+typedef PY_INT64_T stwodigits; /* signed variant of twodigits */
+#define PyLong_SHIFT 30
+#define _PyLong_DECIMAL_SHIFT 9 /* max(e such that 10**e fits in a digit) */
+#define _PyLong_DECIMAL_BASE ((digit)1000000000) /* 10 ** DECIMAL_SHIFT */
+#elif PYLONG_BITS_IN_DIGIT == 15
typedef unsigned short digit;
-typedef unsigned int wdigit; /* digit widened to parameter size */
-#define BASE_TWODIGITS_TYPE long
-typedef unsigned BASE_TWODIGITS_TYPE twodigits;
-typedef BASE_TWODIGITS_TYPE stwodigits; /* signed variant of twodigits */
-
-#define PyLong_SHIFT 15
-#define PyLong_BASE ((digit)1 << PyLong_SHIFT)
-#define PyLong_MASK ((int)(PyLong_BASE - 1))
+typedef short sdigit; /* signed variant of digit */
+typedef unsigned long twodigits;
+typedef long stwodigits; /* signed variant of twodigits */
+#define PyLong_SHIFT 15
+#define _PyLong_DECIMAL_SHIFT 4 /* max(e such that 10**e fits in a digit) */
+#define _PyLong_DECIMAL_BASE ((digit)10000) /* 10 ** DECIMAL_SHIFT */
+#else
+#error "PYLONG_BITS_IN_DIGIT should be 15 or 30"
+#endif
+#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
diff --git a/Include/longobject.h b/Include/longobject.h
index fa511a7614..2b4046128a 100644
--- a/Include/longobject.h
+++ b/Include/longobject.h
@@ -21,9 +21,11 @@ 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(long) PyLong_AsLong(PyObject *);
+PyAPI_FUNC(long) PyLong_AsLongAndOverflow(PyObject *, int *);
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
@@ -31,13 +33,13 @@ PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *);
#define _PyLong_FromSsize_t PyLong_FromSsize_t
PyAPI_DATA(int) _PyLong_DigitValue[256];
-/* _PyLong_AsScaledDouble returns a double x and an exponent e such that
- the true value is approximately equal to x * 2**(SHIFT*e). e is >= 0.
- x is 0.0 if and only if the input is 0 (in which case, e and x are both
- zeroes). Overflow is impossible. Note that the exponent returned must
- be multiplied by SHIFT! There may not be enough room in an int to store
- e*SHIFT directly. */
-PyAPI_FUNC(double) _PyLong_AsScaledDouble(PyObject *vv, int *e);
+/* _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
+ 0.0 if and only if the input is 0 (in which case, e and x are both
+ 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. */
+PyAPI_FUNC(double) _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e);
PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
@@ -49,6 +51,7 @@ PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG);
PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLong(PyObject *);
PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLong(PyObject *);
PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *);
+PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLongAndOverflow(PyObject *, int *);
#endif /* HAVE_LONG_LONG */
PyAPI_FUNC(PyObject *) PyLong_FromString(char *, char **, int);
diff --git a/Include/memoryobject.h b/Include/memoryobject.h
new file mode 100644
index 0000000000..bf0b621ab9
--- /dev/null
+++ b/Include/memoryobject.h
@@ -0,0 +1,74 @@
+/* Memory view object. In Python this is available as "memoryview". */
+
+#ifndef Py_MEMORYOBJECT_H
+#define Py_MEMORYOBJECT_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
+
+#define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type)
+
+/* 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)
+
+
+PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base,
+ int buffertype,
+ char fort);
+
+ /* Return a contiguous chunk of memory representing the buffer
+ from an object in a memory view object. If a copy is made then the
+ base object for the memory view will be a *new* bytes object.
+
+ Otherwise, the base-object will be the object itself and no
+ data-copying will be done.
+
+ The buffertype argument can be PyBUF_READ, PyBUF_WRITE,
+ PyBUF_SHADOW to determine whether the returned buffer
+ should be READONLY, WRITABLE, or set to update the
+ original buffer if a copy must be made. If buffertype is
+ PyBUF_WRITE and the buffer is not contiguous an error will
+ be raised. In this circumstance, the user can use
+ PyBUF_SHADOW to ensure that a a writable temporary
+ contiguous buffer is returned. The contents of this
+ contiguous buffer will be copied back into the original
+ object after the memoryview object is deleted as long as
+ the original object is writable and allows setting an
+ exclusive write lock. If this is not allowed by the
+ original object, then a BufferError is raised.
+
+ If the object is multi-dimensional and if fortran is 'F',
+ the first dimension of the underlying array will vary the
+ fastest in the buffer. If fortran is 'C', then the last
+ dimension will vary the fastest (C-style contiguous). If
+ fortran is 'A', then it does not matter and you will get
+ whatever the object decides is more efficient.
+
+ A new reference is returned that must be DECREF'd when finished.
+ */
+
+PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
+
+PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info);
+ /* create new if bufptr is NULL
+ will be a new bytesobject in base */
+
+
+/* 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! */
+typedef struct {
+ PyObject_HEAD
+ PyObject *base;
+ Py_buffer view;
+} PyMemoryViewObject;
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_MEMORYOBJECT_H */
diff --git a/Include/object.h b/Include/object.h
index 1bb4d78b66..b3689460ce 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -159,11 +159,11 @@ 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 */
+/* Py3k buffer interface */
typedef struct bufferinfo {
void *buf;
- PyObject *obj; /* borrowed reference */
+ PyObject *obj; /* owned reference */
Py_ssize_t len;
Py_ssize_t itemsize; /* This is Py_ssize_t so it can be
pointed to by strides in simple case.*/
@@ -173,6 +173,8 @@ typedef struct bufferinfo {
Py_ssize_t *shape;
Py_ssize_t *strides;
Py_ssize_t *suboffsets;
+ Py_ssize_t smalltable[2]; /* static store for shape and strides of
+ mono-dimensional buffers. */
void *internal;
} Py_buffer;
@@ -449,6 +451,7 @@ PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
+PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, char *, PyObject **);
PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
@@ -473,6 +476,7 @@ PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
+PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *);
PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *,
PyObject *, PyObject *);
@@ -488,6 +492,13 @@ 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 *)
+_PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *);
+PyAPI_FUNC(int)
+_PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
+ PyObject *, PyObject *);
/* PyObject_Dir(obj) acts like Python __builtin__.dir(obj), returning a
@@ -746,11 +757,13 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
((PyObject*)(op))->ob_refcnt++)
#define Py_DECREF(op) \
- if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
- --((PyObject*)(op))->ob_refcnt != 0) \
- _Py_CHECK_REFCNT(op) \
- else \
- _Py_Dealloc((PyObject *)(op))
+ do { \
+ if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
+ --((PyObject*)(op))->ob_refcnt != 0) \
+ _Py_CHECK_REFCNT(op) \
+ else \
+ _Py_Dealloc((PyObject *)(op)); \
+ } while (0)
/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
* and tp_dealloc implementatons.
@@ -796,8 +809,8 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
} while (0)
/* Macros to use in case the object pointer may be NULL: */
-#define Py_XINCREF(op) if ((op) == NULL) ; else Py_INCREF(op)
-#define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op)
+#define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0)
+#define Py_XDECREF(op) do { if ((op) == NULL) ; else Py_DECREF(op); } while (0)
/*
These are provided as conveniences to Python runtime embedders, so that
diff --git a/Include/objimpl.h b/Include/objimpl.h
index 19beb769b9..55e83eced6 100644
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -108,6 +108,13 @@ PyAPI_FUNC(void) _PyObject_DebugFree(void *p);
PyAPI_FUNC(void) _PyObject_DebugDumpAddress(const void *p);
PyAPI_FUNC(void) _PyObject_DebugCheckAddress(const void *p);
PyAPI_FUNC(void) _PyObject_DebugMallocStats(void);
+PyAPI_FUNC(void *) _PyObject_DebugMallocApi(char api, size_t nbytes);
+PyAPI_FUNC(void *) _PyObject_DebugReallocApi(char api, void *p, size_t nbytes);
+PyAPI_FUNC(void) _PyObject_DebugFreeApi(char api, void *p);
+PyAPI_FUNC(void) _PyObject_DebugCheckAddressApi(char api, const void *p);
+PyAPI_FUNC(void *) _PyMem_DebugMalloc(size_t nbytes);
+PyAPI_FUNC(void *) _PyMem_DebugRealloc(void *p, size_t nbytes);
+PyAPI_FUNC(void) _PyMem_DebugFree(void *p);
#define PyObject_MALLOC _PyObject_DebugMalloc
#define PyObject_Malloc _PyObject_DebugMalloc
#define PyObject_REALLOC _PyObject_DebugRealloc
@@ -285,6 +292,17 @@ extern PyGC_Head *_PyGC_generation0;
g->gc.gc_next = NULL; \
} while (0);
+/* True if the object is currently tracked by the GC. */
+#define _PyObject_GC_IS_TRACKED(o) \
+ ((_Py_AS_GC(o))->gc.gc_refs != _PyGC_REFS_UNTRACKED)
+
+/* True if the object may be tracked by the GC in the future, or already is.
+ This can be useful to implement some optimizations. */
+#define _PyObject_GC_MAY_BE_TRACKED(obj) \
+ (PyObject_IS_GC(obj) && \
+ (!PyTuple_CheckExact(obj) || _PyObject_GC_IS_TRACKED(obj)))
+
+
PyAPI_FUNC(PyObject *) _PyObject_GC_Malloc(size_t);
PyAPI_FUNC(PyObject *) _PyObject_GC_New(PyTypeObject *);
PyAPI_FUNC(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t);
diff --git a/Include/opcode.h b/Include/opcode.h
index 9f20b56d68..9764109adb 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -22,7 +22,6 @@ extern "C" {
#define UNARY_INVERT 15
-#define LIST_APPEND 18
#define BINARY_POWER 19
#define BINARY_MULTIPLY 20
@@ -89,6 +88,7 @@ extern "C" {
#define DELETE_NAME 91 /* "" */
#define UNPACK_SEQUENCE 92 /* Number of sequence items */
#define FOR_ITER 93
+#define LIST_APPEND 94
#define STORE_ATTR 95 /* Index in name list */
#define DELETE_ATTR 96 /* "" */
@@ -99,16 +99,20 @@ extern "C" {
#define LOAD_NAME 101 /* Index in name list */
#define BUILD_TUPLE 102 /* Number of tuple items */
#define BUILD_LIST 103 /* Number of list items */
-#define BUILD_MAP 104 /* Always zero for now */
-#define LOAD_ATTR 105 /* Index in name list */
-#define COMPARE_OP 106 /* Comparison operator */
-#define IMPORT_NAME 107 /* Index in name list */
-#define IMPORT_FROM 108 /* Index in name list */
-
+#define BUILD_SET 104 /* Number of set items */
+#define BUILD_MAP 105 /* Always zero for now */
+#define LOAD_ATTR 106 /* Index in name list */
+#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 111 /* "" */
-#define JUMP_IF_TRUE 112 /* "" */
-#define JUMP_ABSOLUTE 113 /* Target byte offset from beginning of code */
+
+#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 /* "" */
+#define POP_JUMP_IF_TRUE 115 /* "" */
#define LOAD_GLOBAL 116 /* Index in name list */
@@ -138,8 +142,13 @@ extern "C" {
#define CALL_FUNCTION_KW 141 /* #args + (#kwargs<<8) */
#define CALL_FUNCTION_VAR_KW 142 /* #args + (#kwargs<<8) */
+#define SETUP_WITH 143
+
/* Support for opargs more than 16 bits long */
-#define EXTENDED_ARG 143
+#define EXTENDED_ARG 145
+
+#define SET_ADD 146
+#define MAP_ADD 147
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,
diff --git a/Include/patchlevel.h b/Include/patchlevel.h
index b0f049e8b7..12f599c75b 100644
--- a/Include/patchlevel.h
+++ b/Include/patchlevel.h
@@ -21,17 +21,18 @@
/* Version parsed out into numeric values */
/*--start constants--*/
#define PY_MAJOR_VERSION 2
-#define PY_MINOR_VERSION 6
-#define PY_MICRO_VERSION 7
-#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_GAMMA
-#define PY_RELEASE_SERIAL 2
+#define PY_MINOR_VERSION 7
+#define PY_MICRO_VERSION 1
+#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL
+#define PY_RELEASE_SERIAL 0
/* Version as a string */
-#define PY_VERSION "2.6.7rc2+"
+#define PY_VERSION "2.7.1+"
/*--end constants--*/
-/* Subversion Revision number of this file (not of the repository) */
-#define PY_PATCHLEVEL_REVISION "$Revision$"
+/* Subversion Revision number of this file (not of the repository). Empty
+ since Mercurial migration. */
+#define PY_PATCHLEVEL_REVISION ""
/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.
Use this for numeric comparisons, e.g. #if PY_VERSION_HEX >= ... */
diff --git a/Include/py_curses.h b/Include/py_curses.h
index e4c0a6e2c5..657816cbd3 100644
--- a/Include/py_curses.h
+++ b/Include/py_curses.h
@@ -80,6 +80,9 @@ typedef struct {
#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
+#define PyCurses_CAPSULE_NAME "_curses._C_API"
+
+
#ifdef CURSES_MODULE
/* This section is used when compiling _cursesmodule.c */
@@ -94,16 +97,8 @@ static void **PyCurses_API;
#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
#define import_curses() \
-{ \
- PyObject *module = PyImport_ImportModuleNoBlock("_curses"); \
- if (module != NULL) { \
- PyObject *module_dict = PyModule_GetDict(module); \
- PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \
- if (PyCObject_Check(c_api_object)) { \
- PyCurses_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
- } \
- } \
-}
+ PyCurses_API = (void **)PyCapsule_Import(PyCurses_CAPSULE_NAME, 1);
+
#endif
/* general error messages */
diff --git a/Include/pycapsule.h b/Include/pycapsule.h
new file mode 100644
index 0000000000..cd682fc7de
--- /dev/null
+++ b/Include/pycapsule.h
@@ -0,0 +1,56 @@
+
+/* Capsule objects let you wrap a C "void *" pointer in a Python
+ object. They're a way of passing data through the Python interpreter
+ without creating your own custom type.
+
+ Capsules 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.
+
+ For more information, please see "c-api/capsule.html" in the
+ documentation.
+*/
+
+#ifndef Py_CAPSULE_H
+#define Py_CAPSULE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+PyAPI_DATA(PyTypeObject) PyCapsule_Type;
+
+typedef void (*PyCapsule_Destructor)(PyObject *);
+
+#define PyCapsule_CheckExact(op) (Py_TYPE(op) == &PyCapsule_Type)
+
+
+PyAPI_FUNC(PyObject *) PyCapsule_New(
+ void *pointer,
+ const char *name,
+ PyCapsule_Destructor destructor);
+
+PyAPI_FUNC(void *) PyCapsule_GetPointer(PyObject *capsule, const char *name);
+
+PyAPI_FUNC(PyCapsule_Destructor) PyCapsule_GetDestructor(PyObject *capsule);
+
+PyAPI_FUNC(const char *) PyCapsule_GetName(PyObject *capsule);
+
+PyAPI_FUNC(void *) PyCapsule_GetContext(PyObject *capsule);
+
+PyAPI_FUNC(int) PyCapsule_IsValid(PyObject *capsule, const char *name);
+
+PyAPI_FUNC(int) PyCapsule_SetPointer(PyObject *capsule, void *pointer);
+
+PyAPI_FUNC(int) PyCapsule_SetDestructor(PyObject *capsule, PyCapsule_Destructor destructor);
+
+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);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_CAPSULE_H */
diff --git a/Include/pyctype.h b/Include/pyctype.h
new file mode 100644
index 0000000000..c5cc61431d
--- /dev/null
+++ b/Include/pyctype.h
@@ -0,0 +1,31 @@
+#ifndef PYCTYPE_H
+#define PYCTYPE_H
+
+#define PY_CTF_LOWER 0x01
+#define PY_CTF_UPPER 0x02
+#define PY_CTF_ALPHA (PY_CTF_LOWER|PY_CTF_UPPER)
+#define PY_CTF_DIGIT 0x04
+#define PY_CTF_ALNUM (PY_CTF_ALPHA|PY_CTF_DIGIT)
+#define PY_CTF_SPACE 0x08
+#define PY_CTF_XDIGIT 0x10
+
+extern const unsigned int _Py_ctype_table[256];
+
+/* Unlike their C counterparts, the following macros are not meant to
+ * handle an int with any of the values [EOF, 0-UCHAR_MAX]. The argument
+ * must be a signed/unsigned char. */
+#define Py_ISLOWER(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_LOWER)
+#define Py_ISUPPER(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_UPPER)
+#define Py_ISALPHA(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_ALPHA)
+#define Py_ISDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_DIGIT)
+#define Py_ISXDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_XDIGIT)
+#define Py_ISALNUM(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_ALNUM)
+#define Py_ISSPACE(c) (_Py_ctype_table[Py_CHARMASK(c)] & PY_CTF_SPACE)
+
+extern const unsigned char _Py_ctype_tolower[256];
+extern const unsigned char _Py_ctype_toupper[256];
+
+#define Py_TOLOWER(c) (_Py_ctype_tolower[Py_CHARMASK(c)])
+#define Py_TOUPPER(c) (_Py_ctype_toupper[Py_CHARMASK(c)])
+
+#endif /* !PYCTYPE_H */
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index e4f5df6c36..dbe3bfa5f2 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -185,11 +185,12 @@ PyAPI_FUNC(PyObject *) PyErr_NoMemory(void);
PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject(
PyObject *, PyObject *);
-PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(PyObject *, char *);
-#ifdef Py_WIN_WIDE_FILENAMES
+PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(
+ PyObject *, const char *);
+#ifdef MS_WINDOWS
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
- PyObject *, Py_UNICODE *);
-#endif /* Py_WIN_WIDE_FILENAMES */
+ PyObject *, const Py_UNICODE *);
+#endif /* MS_WINDOWS */
PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *, const char *, ...)
Py_GCC_ATTRIBUTE((format(printf, 2, 3)));
@@ -199,19 +200,15 @@ PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilenameObject(
int, const char *);
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
int, const char *);
-#ifdef Py_WIN_WIDE_FILENAMES
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
int, const Py_UNICODE *);
-#endif /* Py_WIN_WIDE_FILENAMES */
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(
PyObject *,int, PyObject *);
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
PyObject *,int, const char *);
-#ifdef Py_WIN_WIDE_FILENAMES
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
PyObject *,int, const Py_UNICODE *);
-#endif /* Py_WIN_WIDE_FILENAMES */
PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
#endif /* MS_WINDOWS */
@@ -223,8 +220,10 @@ PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename, int lineno);
#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
/* Function to create a new exception */
-PyAPI_FUNC(PyObject *) PyErr_NewException(char *name, PyObject *base,
- PyObject *dict);
+PyAPI_FUNC(PyObject *) PyErr_NewException(
+ char *name, PyObject *base, PyObject *dict);
+PyAPI_FUNC(PyObject *) PyErr_NewExceptionWithDoc(
+ char *name, char *doc, PyObject *base, PyObject *dict);
PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
/* In sigcheck.c or signalmodule.c */
diff --git a/Include/pyexpat.h b/Include/pyexpat.h
index 1e79f4e762..5340ef5fa3 100644
--- a/Include/pyexpat.h
+++ b/Include/pyexpat.h
@@ -4,6 +4,7 @@
/* note: you must import expat.h before importing this module! */
#define PyExpat_CAPI_MAGIC "pyexpat.expat_CAPI 1.0"
+#define PyExpat_CAPSULE_NAME "pyexpat.expat_CAPI"
struct PyExpat_CAPI
{
diff --git a/Include/pymacconfig.h b/Include/pymacconfig.h
index fe3a6dec92..24e7b8dac6 100644
--- a/Include/pymacconfig.h
+++ b/Include/pymacconfig.h
@@ -16,7 +16,13 @@
# undef SIZEOF_TIME_T
# undef SIZEOF_VOID_P
# undef SIZEOF__BOOL
+# undef SIZEOF_UINTPTR_T
+# undef SIZEOF_PTHREAD_T
# undef WORDS_BIGENDIAN
+# undef DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754
+# undef DOUBLE_IS_BIG_ENDIAN_IEEE754
+# undef DOUBLE_IS_LITTLE_ENDIAN_IEEE754
+# undef HAVE_GCC_ASM_FOR_X87
# undef VA_LIST_IS_ARRAY
# if defined(__LP64__) && defined(__x86_64__)
@@ -37,6 +43,8 @@
# define SIZEOF_SIZE_T 8
# define SIZEOF_TIME_T 8
# define SIZEOF_VOID_P 8
+# define SIZEOF_UINTPTR_T 8
+# define SIZEOF_PTHREAD_T 8
# else
# ifdef __ppc__
# define SIZEOF__BOOL 4
@@ -48,10 +56,12 @@
# define SIZEOF_SIZE_T 4
# define SIZEOF_TIME_T 4
# define SIZEOF_VOID_P 4
+# define SIZEOF_UINTPTR_T 4
+# define SIZEOF_PTHREAD_T 4
# endif
# if defined(__LP64__)
- /* MacOSX 10.4 (the first release to suppport 64-bit code
+ /* MacOSX 10.4 (the first release to support 64-bit code
* at all) only supports 64-bit in the UNIX layer.
* Therefore surpress the toolbox-glue in 64-bit mode.
*/
@@ -65,8 +75,15 @@
#ifdef __BIG_ENDIAN__
#define WORDS_BIGENDIAN 1
+#define DOUBLE_IS_BIG_ENDIAN_IEEE754
+#else
+#define DOUBLE_IS_LITTLE_ENDIAN_IEEE754
#endif /* __BIG_ENDIAN */
+#ifdef __i386__
+# define HAVE_GCC_ASM_FOR_X87
+#endif
+
/*
* The definition in pyconfig.h is only valid on the OS release
* where configure ran on and not necessarily for all systems where
diff --git a/Include/pymath.h b/Include/pymath.h
index 6ad174d645..e3cf22b823 100644
--- a/Include/pymath.h
+++ b/Include/pymath.h
@@ -3,18 +3,14 @@
#include "pyconfig.h" /* include for defines */
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
-
/**************************************************************************
Symbols and macros to supply platform-independent interfaces to mathematical
functions and constants
**************************************************************************/
-/* Python provides implementations for copysign, acosh, asinh, atanh,
- * log1p and hypot in Python/pymath.c just in case your math library doesn't
- * provide the functions.
+/* Python provides implementations for copysign, round and hypot in
+ * Python/pymath.c just in case your math library doesn't provide the
+ * functions.
*
*Note: PC/pyconfig.h defines copysign as _copysign
*/
@@ -22,20 +18,8 @@ functions and constants
extern double copysign(double, double);
#endif
-#ifndef HAVE_ACOSH
-extern double acosh(double);
-#endif
-
-#ifndef HAVE_ASINH
-extern double asinh(double);
-#endif
-
-#ifndef HAVE_ATANH
-extern double atanh(double);
-#endif
-
-#ifndef HAVE_LOG1P
-extern double log1p(double);
+#ifndef HAVE_ROUND
+extern double round(double);
#endif
#ifndef HAVE_HYPOT
@@ -92,6 +76,11 @@ PyAPI_FUNC(double) _Py_force_double(double);
# endif
#endif
+#ifdef HAVE_GCC_ASM_FOR_X87
+PyAPI_FUNC(unsigned short) _Py_get_387controlword(void);
+PyAPI_FUNC(void) _Py_set_387controlword(unsigned short);
+#endif
+
/* Py_IS_NAN(X)
* Return 1 if float or double arg is a NaN, else 0.
* Caution:
diff --git a/Include/pymem.h b/Include/pymem.h
index c8801bbf05..10b5bea5eb 100644
--- a/Include/pymem.h
+++ b/Include/pymem.h
@@ -59,9 +59,9 @@ PyAPI_FUNC(void) PyMem_Free(void *);
/* Macros. */
#ifdef PYMALLOC_DEBUG
/* Redirect all memory operations to Python's debugging allocator. */
-#define PyMem_MALLOC PyObject_MALLOC
-#define PyMem_REALLOC PyObject_REALLOC
-#define PyMem_FREE PyObject_FREE
+#define PyMem_MALLOC _PyMem_DebugMalloc
+#define PyMem_REALLOC _PyMem_DebugRealloc
+#define PyMem_FREE _PyMem_DebugFree
#else /* ! PYMALLOC_DEBUG */
@@ -71,9 +71,9 @@ PyAPI_FUNC(void) PyMem_Free(void *);
pymalloc. To solve these problems, allocate an extra byte. */
/* Returns NULL to indicate error if a negative size or size larger than
Py_ssize_t can represent is supplied. Helps prevents security holes. */
-#define PyMem_MALLOC(n) (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \
+#define PyMem_MALLOC(n) ((size_t)(n) > (size_t)PY_SSIZE_T_MAX ? NULL \
: malloc((n) ? (n) : 1))
-#define PyMem_REALLOC(p, n) (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \
+#define PyMem_REALLOC(p, n) ((size_t)(n) > (size_t)PY_SSIZE_T_MAX ? NULL \
: realloc((p), (n) ? (n) : 1))
#define PyMem_FREE free
diff --git a/Include/pyport.h b/Include/pyport.h
index ed5fc567ba..1abc14c5af 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -3,6 +3,12 @@
#include "pyconfig.h" /* include for defines */
+/* Some versions of HP-UX & Solaris need inttypes.h for int32_t,
+ INT32_MAX, etc. */
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
@@ -80,6 +86,57 @@ Used in: PY_LONG_LONG
#endif
#endif /* HAVE_LONG_LONG */
+/* a build with 30-bit digits for Python long integers needs an exact-width
+ * 32-bit unsigned integer type to store those digits. (We could just use
+ * type 'unsigned long', but that would be wasteful on a system where longs
+ * are 64-bits.) On Unix systems, the autoconf macro AC_TYPE_UINT32_T defines
+ * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t.
+ * However, it doesn't set HAVE_UINT32_T, so we do that here.
+ */
+#if (defined UINT32_MAX || defined uint32_t)
+#ifndef PY_UINT32_T
+#define HAVE_UINT32_T 1
+#define PY_UINT32_T uint32_t
+#endif
+#endif
+
+/* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the
+ * long integer implementation, when 30-bit digits are enabled.
+ */
+#if (defined UINT64_MAX || defined uint64_t)
+#ifndef PY_UINT64_T
+#define HAVE_UINT64_T 1
+#define PY_UINT64_T uint64_t
+#endif
+#endif
+
+/* Signed variants of the above */
+#if (defined INT32_MAX || defined int32_t)
+#ifndef PY_INT32_T
+#define HAVE_INT32_T 1
+#define PY_INT32_T int32_t
+#endif
+#endif
+#if (defined INT64_MAX || defined int64_t)
+#ifndef PY_INT64_T
+#define HAVE_INT64_T 1
+#define PY_INT64_T int64_t
+#endif
+#endif
+
+/* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all
+ the necessary integer types are available, and we're on a 64-bit platform
+ (as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */
+
+#ifndef PYLONG_BITS_IN_DIGIT
+#if (defined HAVE_UINT64_T && defined HAVE_INT64_T && \
+ defined HAVE_UINT32_T && defined HAVE_INT32_T && SIZEOF_VOID_P >= 8)
+#define PYLONG_BITS_IN_DIGIT 30
+#else
+#define PYLONG_BITS_IN_DIGIT 15
+#endif
+#endif
+
/* 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
@@ -172,6 +229,22 @@ typedef Py_intptr_t Py_ssize_t;
# endif
#endif
+/* PY_FORMAT_LONG_LONG is analogous to PY_FORMAT_SIZE_T above, but for
+ * the long long type instead of the size_t type. It's only available
+ * when HAVE_LONG_LONG is defined. The "high level" Python format
+ * functions listed above will interpret "lld" or "llu" correctly on
+ * all platforms.
+ */
+#ifdef HAVE_LONG_LONG
+# ifndef PY_FORMAT_LONG_LONG
+# if defined(MS_WIN64) || defined(MS_WINDOWS)
+# define PY_FORMAT_LONG_LONG "I64"
+# else
+# error "This platform's pyconfig.h needs to define PY_FORMAT_LONG_LONG"
+# endif
+# endif
+#endif
+
/* Py_LOCAL can be used instead of static to get the fastest possible calling
* convention for functions that are local to a given module.
*
@@ -232,6 +305,10 @@ typedef Py_intptr_t Py_ssize_t;
#include <stdlib.h>
+#ifdef HAVE_IEEEFP_H
+#include <ieeefp.h> /* needed for 'finite' declaration on some platforms */
+#endif
+
#include <math.h> /* Moved here from the math section, before extern "C" */
/********************************************
@@ -327,19 +404,23 @@ extern "C" {
* C doesn't define whether a right-shift of a signed integer sign-extends
* or zero-fills. Here a macro to force sign extension:
* Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
- * Return I >> J, forcing sign extension.
+ * Return I >> J, forcing sign extension. Arithmetically, return the
+ * floor of I/2**J.
* Requirements:
- * I is of basic signed type TYPE (char, short, int, long, or long long).
- * TYPE is one of char, short, int, long, or long long, although long long
- * must not be used except on platforms that support it.
- * J is an integer >= 0 and strictly less than the number of bits in TYPE
- * (because C doesn't define what happens for J outside that range either).
+ * I should have signed integer type. In the terminology of C99, this can
+ * be either one of the five standard signed integer types (signed char,
+ * short, int, long, long long) or an extended signed integer type.
+ * J is an integer >= 0 and strictly less than the number of bits in the
+ * type of I (because C doesn't define what happens for J outside that
+ * range either).
+ * TYPE used to specify the type of I, but is now ignored. It's been left
+ * in for backwards compatibility with versions <= 2.6 or 3.0.
* Caution:
* I may be evaluated more than once.
*/
#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
- ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J))
+ ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
#else
#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
#endif
@@ -427,6 +508,79 @@ extern "C" {
errno = 0; \
} while(0)
+/* The functions _Py_dg_strtod and _Py_dg_dtoa in Python/dtoa.c (which are
+ * required to support the short float repr introduced in Python 3.1) require
+ * that the floating-point unit that's being used for arithmetic operations
+ * on C doubles is set to use 53-bit precision. It also requires that the
+ * FPU rounding mode is round-half-to-even, but that's less often an issue.
+ *
+ * If your FPU isn't already set to 53-bit precision/round-half-to-even, and
+ * you want to make use of _Py_dg_strtod and _Py_dg_dtoa, then you should
+ *
+ * #define HAVE_PY_SET_53BIT_PRECISION 1
+ *
+ * and also give appropriate definitions for the following three macros:
+ *
+ * _PY_SET_53BIT_PRECISION_START : store original FPU settings, and
+ * set FPU to 53-bit precision/round-half-to-even
+ * _PY_SET_53BIT_PRECISION_END : restore original FPU settings
+ * _PY_SET_53BIT_PRECISION_HEADER : any variable declarations needed to
+ * use the two macros above.
+ *
+ * The macros are designed to be used within a single C function: see
+ * Python/pystrtod.c for an example of their use.
+ */
+
+/* get and set x87 control word for gcc/x86 */
+#ifdef HAVE_GCC_ASM_FOR_X87
+#define HAVE_PY_SET_53BIT_PRECISION 1
+/* _Py_get/set_387controlword functions are defined in Python/pymath.c */
+#define _Py_SET_53BIT_PRECISION_HEADER \
+ unsigned short old_387controlword, new_387controlword
+#define _Py_SET_53BIT_PRECISION_START \
+ do { \
+ old_387controlword = _Py_get_387controlword(); \
+ new_387controlword = (old_387controlword & ~0x0f00) | 0x0200; \
+ if (new_387controlword != old_387controlword) \
+ _Py_set_387controlword(new_387controlword); \
+ } while (0)
+#define _Py_SET_53BIT_PRECISION_END \
+ if (new_387controlword != old_387controlword) \
+ _Py_set_387controlword(old_387controlword)
+#endif
+
+/* default definitions are empty */
+#ifndef HAVE_PY_SET_53BIT_PRECISION
+#define _Py_SET_53BIT_PRECISION_HEADER
+#define _Py_SET_53BIT_PRECISION_START
+#define _Py_SET_53BIT_PRECISION_END
+#endif
+
+/* If we can't guarantee 53-bit precision, don't use the code
+ in Python/dtoa.c, but fall back to standard code. This
+ means that repr of a float will be long (17 sig digits).
+
+ Realistically, there are two things that could go wrong:
+
+ (1) doubles aren't IEEE 754 doubles, or
+ (2) we're on x86 with the rounding precision set to 64-bits
+ (extended precision), and we don't know how to change
+ the rounding precision.
+ */
+
+#if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \
+ !defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \
+ !defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754)
+#define PY_NO_SHORT_FLOAT_REPR
+#endif
+
+/* double rounding is symptomatic of use of extended precision on x86. If
+ we're seeing double rounding, and we don't have any mechanism available for
+ changing the FPU rounding precision, then don't use Python/dtoa.c. */
+#if defined(X87_DOUBLE_ROUNDING) && !defined(HAVE_PY_SET_53BIT_PRECISION)
+#define PY_NO_SHORT_FLOAT_REPR
+#endif
+
/* Py_DEPRECATED(version)
* Declare a variable, type, or function deprecated.
* Usage:
@@ -473,7 +627,7 @@ extern char * _getpty(int *, int, mode_t, int);
#endif
#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
-#if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H)
+#if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) && !defined(HAVE_UTIL_H)
/* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
functions, even though they are included in libutil. */
#include <termios.h>
@@ -570,23 +724,24 @@ extern int fdatasync(int);
# ifdef Py_BUILD_CORE
# 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?) */
+ /* module init functions inside the core need no external linkage */
+ /* except for Cygwin to handle embedding (FIXME: BeOS too?) */
# if defined(__CYGWIN__)
# define PyMODINIT_FUNC __declspec(dllexport) void
# else /* __CYGWIN__ */
# define PyMODINIT_FUNC void
# endif /* __CYGWIN__ */
# else /* Py_BUILD_CORE */
- /* Building an extension module, or an embedded situation */
- /* public Python functions and data are imported */
- /* Under Cygwin, auto-import functions to prevent compilation */
- /* failures similar to http://python.org/doc/FAQ.html#3.24 */
+ /* Building an extension module, or an embedded situation */
+ /* public Python functions and data are imported */
+ /* Under Cygwin, auto-import functions to prevent compilation */
+ /* failures similar to those described at the bottom of 4.1: */
+ /* http://docs.python.org/extending/windows.html#a-cookbook-approach */
# if !defined(__CYGWIN__)
# define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
# endif /* !__CYGWIN__ */
# define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
- /* module init functions outside the core must be exported */
+ /* module init functions outside the core must be exported */
# if defined(__cplusplus)
# define PyMODINIT_FUNC extern "C" __declspec(dllexport) void
# else /* __cplusplus */
diff --git a/Include/pystate.h b/Include/pystate.h
index b9fe61e721..729342ccbd 100644
--- a/Include/pystate.h
+++ b/Include/pystate.h
@@ -111,6 +111,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);
diff --git a/Include/pystrtod.h b/Include/pystrtod.h
index c6921da1a5..eec434f1bd 100644
--- a/Include/pystrtod.h
+++ b/Include/pystrtod.h
@@ -8,8 +8,35 @@ extern "C" {
PyAPI_FUNC(double) PyOS_ascii_strtod(const char *str, char **ptr);
PyAPI_FUNC(double) PyOS_ascii_atof(const char *str);
-PyAPI_FUNC(char *) PyOS_ascii_formatd(char *buffer, size_t buf_len, const char *format, double d);
+/* 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);
+
+/* The caller is responsible for calling PyMem_Free to free the buffer
+ that's is returned. */
+PyAPI_FUNC(char *) PyOS_double_to_string(double val,
+ char format_code,
+ int precision,
+ int flags,
+ int *type);
+
+PyAPI_FUNC(double) _Py_parse_inf_or_nan(const char *p, char **endptr);
+
+
+/* PyOS_double_to_string's "flags" parameter can be set to 0 or more of: */
+#define Py_DTSF_SIGN 0x01 /* always add the sign */
+#define Py_DTSF_ADD_DOT_0 0x02 /* if the result is an integer add ".0" */
+#define Py_DTSF_ALT 0x04 /* "alternate" formatting. it's format_code
+ specific */
+
+/* PyOS_double_to_string's "type", if non-NULL, will be set to one of: */
+#define Py_DTST_FINITE 0
+#define Py_DTST_INFINITE 1
+#define Py_DTST_NAN 2
#ifdef __cplusplus
}
diff --git a/Include/pythonrun.h b/Include/pythonrun.h
index 039b498b97..85bdd3d18a 100644
--- a/Include/pythonrun.h
+++ b/Include/pythonrun.h
@@ -114,6 +114,8 @@ PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
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);
/* Internal -- various one-time initializations */
PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
@@ -123,6 +125,7 @@ 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);
diff --git a/Include/pythread.h b/Include/pythread.h
index b5a6ec38a6..dfd61575ea 100644
--- a/Include/pythread.h
+++ b/Include/pythread.h
@@ -2,9 +2,6 @@
#ifndef Py_PYTHREAD_H
#define Py_PYTHREAD_H
-#define NO_EXIT_PROG /* don't define PyThread_exit_prog() */
- /* (the result is no use of signals on SGI) */
-
typedef void *PyThread_type_lock;
typedef void *PyThread_type_sema;
@@ -15,7 +12,6 @@ extern "C" {
PyAPI_FUNC(void) PyThread_init_thread(void);
PyAPI_FUNC(long) PyThread_start_new_thread(void (*)(void *), void *);
PyAPI_FUNC(void) PyThread_exit_thread(void);
-PyAPI_FUNC(void) PyThread__PyThread_exit_thread(void);
PyAPI_FUNC(long) PyThread_get_thread_ident(void);
PyAPI_FUNC(PyThread_type_lock) PyThread_allocate_lock(void);
@@ -28,11 +24,6 @@ PyAPI_FUNC(void) PyThread_release_lock(PyThread_type_lock);
PyAPI_FUNC(size_t) PyThread_get_stacksize(void);
PyAPI_FUNC(int) PyThread_set_stacksize(size_t);
-#ifndef NO_EXIT_PROG
-PyAPI_FUNC(void) PyThread_exit_prog(int);
-PyAPI_FUNC(void) PyThread__PyThread_exit_prog(int);
-#endif
-
/* Thread Local Storage (TLS) API */
PyAPI_FUNC(int) PyThread_create_key(void);
PyAPI_FUNC(void) PyThread_delete_key(int);
diff --git a/Include/stringobject.h b/Include/stringobject.h
index c0a1fca297..18b5b411ac 100644
--- a/Include/stringobject.h
+++ b/Include/stringobject.h
@@ -62,9 +62,9 @@ PyAPI_DATA(PyTypeObject) 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)));
+ Py_GCC_ATTRIBUTE((format(printf, 1, 0)));
PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)
- Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
+ 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);
@@ -74,10 +74,10 @@ 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 *);
+ 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 **);
@@ -107,7 +107,7 @@ PyAPI_FUNC(PyObject*) PyString_Decode(
const char *errors /* error handling */
);
-/* Encodes a char buffer of the given size and returns a
+/* Encodes a char buffer of the given size and returns a
Python object. */
PyAPI_FUNC(PyObject*) PyString_Encode(
@@ -117,50 +117,50 @@ PyAPI_FUNC(PyObject*) PyString_Encode(
const char *errors /* error handling */
);
-/* Encodes a string object and returns the result as Python
+/* 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 */
+ 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.
-
+ 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 */
+ PyObject *str, /* string object */
+ const char *encoding, /* encoding */
+ const char *errors /* error handling */
);
-/* Decodes a string object and returns the result as Python
+/* 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 */
+ 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.
-
+ 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 */
+ 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
@@ -170,29 +170,39 @@ PyAPI_FUNC(PyObject*) PyString_AsDecodedString(
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) */
+ 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);
-PyAPI_FUNC(int) _PyString_InsertThousandsGrouping(char *buffer,
- Py_ssize_t n_buffer,
- Py_ssize_t n_digits,
- Py_ssize_t buf_size,
- Py_ssize_t *count,
- int append_zero_char);
+/* 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);
+ char *format_spec,
+ Py_ssize_t format_spec_len);
#ifdef __cplusplus
}
diff --git a/Include/symtable.h b/Include/symtable.h
index 65775b0c8a..e0a0be41b5 100644
--- a/Include/symtable.h
+++ b/Include/symtable.h
@@ -19,7 +19,6 @@ struct symtable {
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 */
- int st_tmpname; /* temporary name counter */
PyFutureFeatures *st_future; /* module's future features */
};
@@ -65,13 +64,9 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
#define DEF_LOCAL 2 /* assignment in code block */
#define DEF_PARAM 2<<1 /* formal parameter */
#define USE 2<<2 /* name is used */
-#define DEF_STAR 2<<3 /* parameter is star arg */
-#define DEF_DOUBLESTAR 2<<4 /* parameter is star-star arg */
-#define DEF_INTUPLE 2<<5 /* name defined in tuple in parameters */
-#define DEF_FREE 2<<6 /* name used but not defined in nested block */
-#define DEF_FREE_GLOBAL 2<<7 /* free variable is actually implicit global */
-#define DEF_FREE_CLASS 2<<8 /* free variable from class's method */
-#define DEF_IMPORT 2<<9 /* assignment occurred via import */
+#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_BOUND (DEF_LOCAL | DEF_PARAM | DEF_IMPORT)
diff --git a/Include/token.h b/Include/token.h
index 4250000d13..72659ac053 100644
--- a/Include/token.h
+++ b/Include/token.h
@@ -7,6 +7,8 @@
extern "C" {
#endif
+#undef TILDE /* Prevent clash of our definition with system macro. Ex AIX, ioctl.h */
+
#define ENDMARKER 0
#define NAME 1
#define NUMBER 2
diff --git a/Include/tupleobject.h b/Include/tupleobject.h
index 58479ee0ff..a5ab733208 100644
--- a/Include/tupleobject.h
+++ b/Include/tupleobject.h
@@ -44,6 +44,7 @@ PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *);
PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, Py_ssize_t);
PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...);
+PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
/* Macro, trading safety for speed */
#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
diff --git a/Include/ucnhash.h b/Include/ucnhash.h
index 6231c98b30..69b7774a97 100644
--- a/Include/ucnhash.h
+++ b/Include/ucnhash.h
@@ -6,7 +6,9 @@
extern "C" {
#endif
-/* revised ucnhash CAPI interface (exported through a PyCObject) */
+/* revised ucnhash CAPI interface (exported through a "wrapper") */
+
+#define PyUnicodeData_CAPSULE_NAME "unicodedata.ucnhash_CAPI"
typedef struct {
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
index c0a1ca1583..9ab724aa6e 100644
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -740,10 +740,8 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7Stateful(
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7(
const Py_UNICODE *data, /* Unicode char buffer */
Py_ssize_t length, /* number of Py_UNICODE chars to encode */
- int encodeSetO, /* force the encoder to encode characters in
- Set O, as described in RFC2152 */
- int encodeWhiteSpace, /* force the encoder to encode space, tab,
- carriage return and linefeed characters */
+ int base64SetO, /* Encode RFC2152 Set O characters in base64 */
+ int base64WhiteSpace, /* Encode whitespace (sp, ht, nl, cr) in base64 */
const char *errors /* error handling */
);