From c348ef1ad1d4ffb64b25c4e48521abe9fec3b608 Mon Sep 17 00:00:00 2001 From: Larry Hastings Date: Sun, 16 Mar 2014 23:05:59 -0700 Subject: Version bump to 3.5, step 2. --- Include/patchlevel.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Include') diff --git a/Include/patchlevel.h b/Include/patchlevel.h index 72f540da48..16124f5995 100644 --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -17,13 +17,13 @@ /* Version parsed out into numeric values */ /*--start constants--*/ #define PY_MAJOR_VERSION 3 -#define PY_MINOR_VERSION 4 +#define PY_MINOR_VERSION 5 #define PY_MICRO_VERSION 0 -#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL +#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_ALPHA #define PY_RELEASE_SERIAL 0 /* Version as a string */ -#define PY_VERSION "3.4.0+" +#define PY_VERSION "3.5.0a0" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. -- cgit v1.2.1 From 3f16b927b6791867124ec969049fde4d61df0157 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 9 Apr 2014 23:55:56 -0400 Subject: PEP 465: a dedicated infix operator for matrix multiplication (closes #21176) --- Include/Python-ast.h | 6 +++--- Include/abstract.h | 12 ++++++++++++ Include/object.h | 3 +++ Include/opcode.h | 3 +++ Include/token.h | 13 +++++++------ Include/typeslots.h | 2 ++ 6 files changed, 30 insertions(+), 9 deletions(-) (limited to 'Include') diff --git a/Include/Python-ast.h b/Include/Python-ast.h index 67d677b233..37e9a606c2 100644 --- a/Include/Python-ast.h +++ b/Include/Python-ast.h @@ -15,9 +15,9 @@ typedef struct _slice *slice_ty; typedef enum _boolop { And=1, Or=2 } boolop_ty; -typedef enum _operator { Add=1, Sub=2, Mult=3, Div=4, Mod=5, Pow=6, LShift=7, - RShift=8, BitOr=9, BitXor=10, BitAnd=11, FloorDiv=12 } - operator_ty; +typedef enum _operator { Add=1, Sub=2, Mult=3, MatMult=4, Div=5, Mod=6, Pow=7, + LShift=8, RShift=9, BitOr=10, BitXor=11, BitAnd=12, + FloorDiv=13 } operator_ty; typedef enum _unaryop { Invert=1, Not=2, UAdd=3, USub=4 } unaryop_ty; diff --git a/Include/abstract.h b/Include/abstract.h index 6e850b82e8..db70f213bc 100644 --- a/Include/abstract.h +++ b/Include/abstract.h @@ -658,6 +658,12 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ o1*o2. */ + PyAPI_FUNC(PyObject *) PyNumber_MatrixMultiply(PyObject *o1, PyObject *o2); + + /* + This is the equivalent of the Python expression: o1 @ o2. + */ + PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2); /* @@ -832,6 +838,12 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ o1 *= o2. */ + PyAPI_FUNC(PyObject *) PyNumber_InPlaceMatrixMultiply(PyObject *o1, PyObject *o2); + + /* + This is the equivalent of the Python expression: o1 @= o2. + */ + PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1, PyObject *o2); diff --git a/Include/object.h b/Include/object.h index 7584d4cdde..f3c87ebd22 100644 --- a/Include/object.h +++ b/Include/object.h @@ -275,6 +275,9 @@ typedef struct { binaryfunc nb_inplace_true_divide; unaryfunc nb_index; + + binaryfunc nb_matrix_multiply; + binaryfunc nb_inplace_matrix_multiply; } PyNumberMethods; typedef struct { diff --git a/Include/opcode.h b/Include/opcode.h index 0936f2d9f4..9e5f0bf5d1 100644 --- a/Include/opcode.h +++ b/Include/opcode.h @@ -20,6 +20,9 @@ extern "C" { #define UNARY_INVERT 15 +#define BINARY_MATRIX_MULTIPLY 16 +#define INPLACE_MATRIX_MULTIPLY 17 + #define BINARY_POWER 19 #define BINARY_MULTIPLY 20 diff --git a/Include/token.h b/Include/token.h index 905022b8d2..2b213eeb32 100644 --- a/Include/token.h +++ b/Include/token.h @@ -58,13 +58,14 @@ extern "C" { #define DOUBLESTAREQUAL 46 #define DOUBLESLASH 47 #define DOUBLESLASHEQUAL 48 -#define AT 49 -#define RARROW 50 -#define ELLIPSIS 51 +#define AT 49 +#define ATEQUAL 50 +#define RARROW 51 +#define ELLIPSIS 52 /* Don't forget to update the table _PyParser_TokenNames in tokenizer.c! */ -#define OP 52 -#define ERRORTOKEN 53 -#define N_TOKENS 54 +#define OP 53 +#define ERRORTOKEN 54 +#define N_TOKENS 55 /* Special definitions for cooperation with parser */ diff --git a/Include/typeslots.h b/Include/typeslots.h index ad3cdfb19a..da2e87cb71 100644 --- a/Include/typeslots.h +++ b/Include/typeslots.h @@ -74,3 +74,5 @@ #define Py_tp_members 72 #define Py_tp_getset 73 #define Py_tp_free 74 +#define Py_nb_matrix_multiply 75 +#define Py_nb_inplace_matrix_multiply 76 -- cgit v1.2.1 From 765f45228325ffa98d26860aeeea9c14a5d3b499 Mon Sep 17 00:00:00 2001 From: Andrew Kuchling Date: Mon, 14 Apr 2014 14:19:52 -0400 Subject: #11983: update comment to describe which fields are used and why. Original patch by Caelyn McAulay; modified after discussion w/ her at the PyCon 2014 sprints. --- Include/code.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'Include') diff --git a/Include/code.h b/Include/code.h index 7c7e5bf8dc..ff2b97efe9 100644 --- a/Include/code.h +++ b/Include/code.h @@ -21,7 +21,12 @@ 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 or comparisons */ + /* The rest aren't used in either hash or comparisons, except for + co_name (used in both) and co_firstlineno (used only in + comparisons). This is done to preserve the name and line number + for tracebacks and debuggers; otherwise, constant de-duplication + would collapse identical functions/lambdas defined on different lines. + */ unsigned char *co_cell2arg; /* Maps cell vars which are arguments. */ PyObject *co_filename; /* unicode (where it was loaded from) */ PyObject *co_name; /* unicode (name, for reference) */ -- cgit v1.2.1 From dff5c306a08b09cb59f5c5acc80fee8bd4e43166 Mon Sep 17 00:00:00 2001 From: Kushal Das Date: Tue, 15 Apr 2014 23:50:06 +0530 Subject: Closes Issue 17861: Autogenerate Include/opcode.h from opcode.py. It includes required changes in Makefile.pre.in and configure.ac among other files. --- Include/opcode.h | 249 ++++++++++++++++++++++++------------------------------- 1 file changed, 109 insertions(+), 140 deletions(-) (limited to 'Include') diff --git a/Include/opcode.h b/Include/opcode.h index 9e5f0bf5d1..0638b5468c 100644 --- a/Include/opcode.h +++ b/Include/opcode.h @@ -1,3 +1,4 @@ +/* Auto-generated by Tools/scripts/generate_opcode_h.py */ #ifndef Py_OPCODE_H #define Py_OPCODE_H #ifdef __cplusplus @@ -5,144 +6,111 @@ extern "C" { #endif -/* Instruction opcodes for compiled code */ - -#define POP_TOP 1 -#define ROT_TWO 2 -#define ROT_THREE 3 -#define DUP_TOP 4 -#define DUP_TOP_TWO 5 -#define NOP 9 - -#define UNARY_POSITIVE 10 -#define UNARY_NEGATIVE 11 -#define UNARY_NOT 12 - -#define UNARY_INVERT 15 - -#define BINARY_MATRIX_MULTIPLY 16 -#define INPLACE_MATRIX_MULTIPLY 17 - -#define BINARY_POWER 19 - -#define BINARY_MULTIPLY 20 - -#define BINARY_MODULO 22 -#define BINARY_ADD 23 -#define BINARY_SUBTRACT 24 -#define BINARY_SUBSCR 25 -#define BINARY_FLOOR_DIVIDE 26 -#define BINARY_TRUE_DIVIDE 27 -#define INPLACE_FLOOR_DIVIDE 28 -#define INPLACE_TRUE_DIVIDE 29 - -#define STORE_MAP 54 -#define INPLACE_ADD 55 -#define INPLACE_SUBTRACT 56 -#define INPLACE_MULTIPLY 57 - -#define INPLACE_MODULO 59 -#define STORE_SUBSCR 60 -#define DELETE_SUBSCR 61 - -#define BINARY_LSHIFT 62 -#define BINARY_RSHIFT 63 -#define BINARY_AND 64 -#define BINARY_XOR 65 -#define BINARY_OR 66 -#define INPLACE_POWER 67 -#define GET_ITER 68 -#define PRINT_EXPR 70 -#define LOAD_BUILD_CLASS 71 -#define YIELD_FROM 72 - -#define INPLACE_LSHIFT 75 -#define INPLACE_RSHIFT 76 -#define INPLACE_AND 77 -#define INPLACE_XOR 78 -#define INPLACE_OR 79 -#define BREAK_LOOP 80 -#define WITH_CLEANUP 81 - -#define RETURN_VALUE 83 -#define IMPORT_STAR 84 - -#define YIELD_VALUE 86 -#define POP_BLOCK 87 -#define END_FINALLY 88 -#define POP_EXCEPT 89 - -#define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */ - -#define STORE_NAME 90 /* Index in name list */ -#define DELETE_NAME 91 /* "" */ -#define UNPACK_SEQUENCE 92 /* Number of sequence items */ -#define FOR_ITER 93 -#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 LOAD_CONST 100 /* Index in const list */ -#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_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_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 */ - -#define CONTINUE_LOOP 119 /* Start of loop (absolute) */ -#define SETUP_LOOP 120 /* Target address (relative) */ -#define SETUP_EXCEPT 121 /* "" */ -#define SETUP_FINALLY 122 /* "" */ - -#define LOAD_FAST 124 /* Local variable number */ -#define STORE_FAST 125 /* Local variable number */ -#define DELETE_FAST 126 /* Local variable number */ - -#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 + #kwdefaults<<8 + #annotations<<16 */ -#define BUILD_SLICE 133 /* Number of items */ - -#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 */ -#define CALL_FUNCTION_VAR 140 /* #args + (#kwargs<<8) */ -#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 144 - -#define LIST_APPEND 145 -#define SET_ADD 146 -#define MAP_ADD 147 - -#define LOAD_CLASSDEREF 148 + /* Instruction opcodes for compiled code */ +#define POP_TOP 1 +#define ROT_TWO 2 +#define ROT_THREE 3 +#define DUP_TOP 4 +#define DUP_TOP_TWO 5 +#define NOP 9 +#define UNARY_POSITIVE 10 +#define UNARY_NEGATIVE 11 +#define UNARY_NOT 12 +#define UNARY_INVERT 15 +#define BINARY_MATRIX_MULTIPLY 16 +#define INPLACE_MATRIX_MULTIPLY 17 +#define BINARY_POWER 19 +#define BINARY_MULTIPLY 20 +#define BINARY_MODULO 22 +#define BINARY_ADD 23 +#define BINARY_SUBTRACT 24 +#define BINARY_SUBSCR 25 +#define BINARY_FLOOR_DIVIDE 26 +#define BINARY_TRUE_DIVIDE 27 +#define INPLACE_FLOOR_DIVIDE 28 +#define INPLACE_TRUE_DIVIDE 29 +#define STORE_MAP 54 +#define INPLACE_ADD 55 +#define INPLACE_SUBTRACT 56 +#define INPLACE_MULTIPLY 57 +#define INPLACE_MODULO 59 +#define STORE_SUBSCR 60 +#define DELETE_SUBSCR 61 +#define BINARY_LSHIFT 62 +#define BINARY_RSHIFT 63 +#define BINARY_AND 64 +#define BINARY_XOR 65 +#define BINARY_OR 66 +#define INPLACE_POWER 67 +#define GET_ITER 68 +#define PRINT_EXPR 70 +#define LOAD_BUILD_CLASS 71 +#define YIELD_FROM 72 +#define INPLACE_LSHIFT 75 +#define INPLACE_RSHIFT 76 +#define INPLACE_AND 77 +#define INPLACE_XOR 78 +#define INPLACE_OR 79 +#define BREAK_LOOP 80 +#define WITH_CLEANUP 81 +#define RETURN_VALUE 83 +#define IMPORT_STAR 84 +#define YIELD_VALUE 86 +#define POP_BLOCK 87 +#define END_FINALLY 88 +#define POP_EXCEPT 89 +#define HAVE_ARGUMENT 90 +#define STORE_NAME 90 +#define DELETE_NAME 91 +#define UNPACK_SEQUENCE 92 +#define FOR_ITER 93 +#define UNPACK_EX 94 +#define STORE_ATTR 95 +#define DELETE_ATTR 96 +#define STORE_GLOBAL 97 +#define DELETE_GLOBAL 98 +#define LOAD_CONST 100 +#define LOAD_NAME 101 +#define BUILD_TUPLE 102 +#define BUILD_LIST 103 +#define BUILD_SET 104 +#define BUILD_MAP 105 +#define LOAD_ATTR 106 +#define COMPARE_OP 107 +#define IMPORT_NAME 108 +#define IMPORT_FROM 109 +#define JUMP_FORWARD 110 +#define JUMP_IF_FALSE_OR_POP 111 +#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 +#define CONTINUE_LOOP 119 +#define SETUP_LOOP 120 +#define SETUP_EXCEPT 121 +#define SETUP_FINALLY 122 +#define LOAD_FAST 124 +#define STORE_FAST 125 +#define DELETE_FAST 126 +#define RAISE_VARARGS 130 +#define CALL_FUNCTION 131 +#define MAKE_FUNCTION 132 +#define BUILD_SLICE 133 +#define MAKE_CLOSURE 134 +#define LOAD_CLOSURE 135 +#define LOAD_DEREF 136 +#define STORE_DEREF 137 +#define DELETE_DEREF 138 +#define CALL_FUNCTION_VAR 140 +#define CALL_FUNCTION_KW 141 +#define CALL_FUNCTION_VAR_KW 142 +#define SETUP_WITH 143 +#define EXTENDED_ARG 144 +#define LIST_APPEND 145 +#define SET_ADD 146 +#define MAP_ADD 147 +#define LOAD_CLASSDEREF 148 /* 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 @@ -151,8 +119,9 @@ extern "C" { #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}; +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}; #define HAS_ARG(op) ((op) >= HAVE_ARGUMENT) -- cgit v1.2.1 From 0255df41b9cc48d9dd3f98ccc70b191939f3719f Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 17 Apr 2014 00:00:31 -0400 Subject: support setting fpu precision on m68k (closes #20904) Patch from Andreas Schwab. --- Include/pyport.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Include') diff --git a/Include/pyport.h b/Include/pyport.h index c706213c87..69deb9f8bf 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -588,6 +588,25 @@ extern "C" { } while (0) #endif +#ifdef HAVE_GCC_ASM_FOR_MC68881 +#define HAVE_PY_SET_53BIT_PRECISION 1 +#define _Py_SET_53BIT_PRECISION_HEADER \ + unsigned int old_fpcr, new_fpcr +#define _Py_SET_53BIT_PRECISION_START \ + do { \ + __asm__ ("fmove.l %%fpcr,%0" : "=g" (old_fpcr)); \ + /* Set double precision / round to nearest. */ \ + new_fpcr = (old_fpcr & ~0xf0) | 0x80; \ + if (new_fpcr != old_fpcr) \ + __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (new_fpcr)); \ + } while (0) +#define _Py_SET_53BIT_PRECISION_END \ + do { \ + if (new_fpcr != old_fpcr) \ + __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (old_fpcr)); \ + } while (0) +#endif + /* default definitions are empty */ #ifndef HAVE_PY_SET_53BIT_PRECISION #define _Py_SET_53BIT_PRECISION_HEADER -- cgit v1.2.1 From 595eab7fac1c64b8a25352d0dd40f1e7b62ee58a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 2 May 2014 22:31:14 +0200 Subject: Issue #21233: Add new C functions: PyMem_RawCalloc(), PyMem_Calloc(), PyObject_Calloc(), _PyObject_GC_Calloc(). bytes(int) and bytearray(int) are now using ``calloc()`` instead of ``malloc()`` for large objects which is faster and use less memory (until the bytearray buffer is filled with data). --- Include/objimpl.h | 4 +++- Include/pymem.h | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'Include') diff --git a/Include/objimpl.h b/Include/objimpl.h index 3f21b70e07..65b6d91c36 100644 --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -95,6 +95,7 @@ PyObject_{New, NewVar, Del}. the raw memory. */ PyAPI_FUNC(void *) PyObject_Malloc(size_t size); +PyAPI_FUNC(void *) PyObject_Calloc(size_t nelem, size_t elsize); PyAPI_FUNC(void *) PyObject_Realloc(void *ptr, size_t new_size); PyAPI_FUNC(void) PyObject_Free(void *ptr); @@ -321,7 +322,8 @@ extern PyGC_Head *_PyGC_generation0; (!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_Malloc(size_t size); +PyAPI_FUNC(PyObject *) _PyObject_GC_Calloc(size_t size); PyAPI_FUNC(PyObject *) _PyObject_GC_New(PyTypeObject *); PyAPI_FUNC(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t); PyAPI_FUNC(void) PyObject_GC_Track(void *); diff --git a/Include/pymem.h b/Include/pymem.h index 2372b864a1..7a8dd43fa8 100644 --- a/Include/pymem.h +++ b/Include/pymem.h @@ -13,6 +13,7 @@ extern "C" { #ifndef Py_LIMITED_API PyAPI_FUNC(void *) PyMem_RawMalloc(size_t size); +PyAPI_FUNC(void *) PyMem_RawCalloc(size_t nelem, size_t elsize); PyAPI_FUNC(void *) PyMem_RawRealloc(void *ptr, size_t new_size); PyAPI_FUNC(void) PyMem_RawFree(void *ptr); #endif @@ -57,6 +58,7 @@ PyAPI_FUNC(void) PyMem_RawFree(void *ptr); */ PyAPI_FUNC(void *) PyMem_Malloc(size_t size); +PyAPI_FUNC(void *) PyMem_Calloc(size_t nelem, size_t elsize); PyAPI_FUNC(void *) PyMem_Realloc(void *ptr, size_t new_size); PyAPI_FUNC(void) PyMem_Free(void *ptr); @@ -132,6 +134,9 @@ typedef struct { /* allocate a memory block */ void* (*malloc) (void *ctx, size_t size); + /* allocate a memory block initialized by zeros */ + void* (*calloc) (void *ctx, size_t nelem, size_t elsize); + /* allocate or resize a memory block */ void* (*realloc) (void *ctx, void *ptr, size_t new_size); -- cgit v1.2.1 From 414421d85e3241df4800dcc36373526d437b62ef Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 3 May 2014 16:32:11 -0700 Subject: Issue 21101: Internal API for dict getitem and setitem where the hash value is known. --- Include/dictobject.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Include') diff --git a/Include/dictobject.h b/Include/dictobject.h index ef122bde97..3e0544ab02 100644 --- a/Include/dictobject.h +++ b/Include/dictobject.h @@ -50,6 +50,8 @@ PyAPI_DATA(PyTypeObject) PyDictValues_Type; PyAPI_FUNC(PyObject *) PyDict_New(void); PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key); +PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key, + Py_hash_t hash); PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key); PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key); @@ -58,6 +60,8 @@ PyAPI_FUNC(PyObject *) PyDict_SetDefault( PyObject *mp, PyObject *key, PyObject *defaultobj); #endif PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item); +PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key, + PyObject *item, Py_hash_t hash); PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key); PyAPI_FUNC(void) PyDict_Clear(PyObject *mp); PyAPI_FUNC(int) PyDict_Next( -- cgit v1.2.1 From 8bd934c29d2b3c415b44617459027c3c5dec8332 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 3 May 2014 19:39:15 -0400 Subject: do not expose known hash api in stable API --- Include/dictobject.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Include') diff --git a/Include/dictobject.h b/Include/dictobject.h index 3e0544ab02..09dff59191 100644 --- a/Include/dictobject.h +++ b/Include/dictobject.h @@ -50,8 +50,10 @@ PyAPI_DATA(PyTypeObject) PyDictValues_Type; PyAPI_FUNC(PyObject *) PyDict_New(void); PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key); +#ifndef Py_LIMITED_API PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key, Py_hash_t hash); +#endif PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key); PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key); @@ -60,8 +62,10 @@ PyAPI_FUNC(PyObject *) PyDict_SetDefault( PyObject *mp, PyObject *key, PyObject *defaultobj); #endif PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item); +#ifndef Py_LIMITED_API PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key, PyObject *item, Py_hash_t hash); +#endif PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key); PyAPI_FUNC(void) PyDict_Clear(PyObject *mp); PyAPI_FUNC(int) PyDict_Next( -- cgit v1.2.1 From e409cb0905a799d6de9b91b82b0bb5648b12aaec Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 14 May 2014 17:24:35 +0200 Subject: Issue #21490: Add new C macros: Py_ABS() and Py_STRINGIFY() Keep _Py_STRINGIZE() in PC/pyconfig.h to not introduce a dependency between pyconfig.h and pymacros.h. --- Include/pymacro.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Include') diff --git a/Include/pymacro.h b/Include/pymacro.h index 7997c55cd6..3f6f5dce61 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -1,13 +1,26 @@ #ifndef Py_PYMACRO_H #define Py_PYMACRO_H +/* Minimum value between x and y */ #define Py_MIN(x, y) (((x) > (y)) ? (y) : (x)) + +/* Maximum value between x and y */ #define Py_MAX(x, y) (((x) > (y)) ? (x) : (y)) +/* Absolute value of the number x */ +#define Py_ABS(x) ((x) < 0 ? -(x) : (x)) + +#define _Py_XSTRINGIFY(x) #x + +/* Convert the argument to a string. For example, Py_STRINGIFY(123) is replaced + with "123" by the preprocessor. Defines are also replaced by their value. + For example Py_STRINGIFY(__LINE__) is replaced by the line number, not + by "__LINE__". */ +#define Py_STRINGIFY(x) _Py_XSTRINGIFY(x) + /* Argument must be a char or an int in [-128, 127] or [0, 255]. */ #define Py_CHARMASK(c) ((unsigned char)((c) & 0xff)) - /* Assert a build-time dependency, as an expression. Your compile will fail if the condition isn't true, or can't be evaluated -- cgit v1.2.1 From 1be655495f46dd956c0df2bb04f237e1d127e762 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 2 Jun 2014 21:57:10 +0200 Subject: Issue #21233: Rename the C structure "PyMemAllocator" to "PyMemAllocatorEx" to make sure that the code using it will be adapted for the new "calloc" field (instead of crashing). --- Include/pymem.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Include') diff --git a/Include/pymem.h b/Include/pymem.h index 7a8dd43fa8..043db64deb 100644 --- a/Include/pymem.h +++ b/Include/pymem.h @@ -128,7 +128,7 @@ typedef enum { } PyMemAllocatorDomain; typedef struct { - /* user context passed as the first argument to the 3 functions */ + /* user context passed as the first argument to the 4 functions */ void *ctx; /* allocate a memory block */ @@ -142,11 +142,11 @@ typedef struct { /* release a memory block */ void (*free) (void *ctx, void *ptr); -} PyMemAllocator; +} PyMemAllocatorEx; /* Get the memory block allocator of the specified domain. */ PyAPI_FUNC(void) PyMem_GetAllocator(PyMemAllocatorDomain domain, - PyMemAllocator *allocator); + PyMemAllocatorEx *allocator); /* Set the memory block allocator of the specified domain. @@ -160,7 +160,7 @@ PyAPI_FUNC(void) PyMem_GetAllocator(PyMemAllocatorDomain domain, PyMem_SetupDebugHooks() function must be called to reinstall the debug hooks on top on the new allocator. */ PyAPI_FUNC(void) PyMem_SetAllocator(PyMemAllocatorDomain domain, - PyMemAllocator *allocator); + PyMemAllocatorEx *allocator); /* Setup hooks to detect bugs in the following Python memory allocator functions: -- cgit v1.2.1 From cb7bff4fcfe8f736d1095a0be0c363dfec14a564 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 16 Jun 2014 15:59:28 +0200 Subject: Issue #21205: Add a new ``__qualname__`` attribute to generator, the qualified name, and use it in the representation of a generator (``repr(gen)``). The default name of the generator (``__name__`` attribute) is now get from the function instead of the code. Use ``gen.gi_code.co_name`` to get the name of the code. --- Include/genobject.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Include') diff --git a/Include/genobject.h b/Include/genobject.h index 65f1ecfd54..23571e663b 100644 --- a/Include/genobject.h +++ b/Include/genobject.h @@ -25,6 +25,12 @@ typedef struct { /* List of weak reference. */ PyObject *gi_weakreflist; + + /* Name of the generator. */ + PyObject *gi_name; + + /* Qualified name of the generator. */ + PyObject *gi_qualname; } PyGenObject; PyAPI_DATA(PyTypeObject) PyGen_Type; @@ -33,6 +39,8 @@ PyAPI_DATA(PyTypeObject) PyGen_Type; #define PyGen_CheckExact(op) (Py_TYPE(op) == &PyGen_Type) PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *); +PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(struct _frame *, + PyObject *name, PyObject *qualname); PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *); PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **); PyObject *_PyGen_Send(PyGenObject *, PyObject *); -- cgit v1.2.1 From b5ef7340b83f919205a2043c3bd2f13b15dcea05 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Mon, 7 Jul 2014 18:49:30 -0400 Subject: Issue #21803: remove macro indirections in complexobject.h --- Include/complexobject.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'Include') diff --git a/Include/complexobject.h b/Include/complexobject.h index 1934f3b380..cb8c52c580 100644 --- a/Include/complexobject.h +++ b/Include/complexobject.h @@ -14,21 +14,13 @@ typedef struct { /* Operations on complex numbers from complexmodule.c */ -#define c_sum _Py_c_sum -#define c_diff _Py_c_diff -#define c_neg _Py_c_neg -#define c_prod _Py_c_prod -#define c_quot _Py_c_quot -#define c_pow _Py_c_pow -#define c_abs _Py_c_abs - -PyAPI_FUNC(Py_complex) c_sum(Py_complex, Py_complex); -PyAPI_FUNC(Py_complex) c_diff(Py_complex, Py_complex); -PyAPI_FUNC(Py_complex) c_neg(Py_complex); -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); +PyAPI_FUNC(Py_complex) _Py_c_sum(Py_complex, Py_complex); +PyAPI_FUNC(Py_complex) _Py_c_diff(Py_complex, Py_complex); +PyAPI_FUNC(Py_complex) _Py_c_neg(Py_complex); +PyAPI_FUNC(Py_complex) _Py_c_prod(Py_complex, Py_complex); +PyAPI_FUNC(Py_complex) _Py_c_quot(Py_complex, Py_complex); +PyAPI_FUNC(Py_complex) _Py_c_pow(Py_complex, Py_complex); +PyAPI_FUNC(double) _Py_c_abs(Py_complex); #endif /* Complex object interface */ -- cgit v1.2.1 From a8a4cafd7ddf4628ac533ce42aeb769fa4f7d313 Mon Sep 17 00:00:00 2001 From: "Martin v. L?wis" Date: Sun, 27 Jul 2014 16:25:09 +0200 Subject: Issue #20179: Apply Argument Clinic to bytes and bytearray. Patch by Tal Einat. --- Include/bytes_methods.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Include') diff --git a/Include/bytes_methods.h b/Include/bytes_methods.h index 1498b8f83c..290488124a 100644 --- a/Include/bytes_methods.h +++ b/Include/bytes_methods.h @@ -21,8 +21,8 @@ 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); +/* The maketrans() static method. */ +extern PyObject* _Py_bytes_maketrans(PyObject *frm, PyObject *to); /* Shared __doc__ strings. */ extern const char _Py_isspace__doc__[]; -- cgit v1.2.1 From c3f54dd5d927667235986b636624f5690e067a27 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 29 Jul 2014 22:32:47 +0200 Subject: Issue #22054: Add os.get_blocking() and os.set_blocking() functions to get and set the blocking mode of a file descriptor (False if the O_NONBLOCK flag is set, True otherwise). These functions are not available on Windows. --- Include/fileutils.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Include') diff --git a/Include/fileutils.h b/Include/fileutils.h index e9bad80b87..f2a43f75c4 100644 --- a/Include/fileutils.h +++ b/Include/fileutils.h @@ -70,7 +70,14 @@ PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable, int *atomic_flag_works); PyAPI_FUNC(int) _Py_dup(int fd); -#endif + +#ifndef MS_WINDOWS +PyAPI_FUNC(int) _Py_get_blocking(int fd); + +PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking); +#endif /* !MS_WINDOWS */ + +#endif /* Py_LIMITED_API */ #ifdef __cplusplus } -- cgit v1.2.1 From db4ad80ec7958ad28530e990b75c8aff03e2bd38 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 1 Aug 2014 12:28:48 +0200 Subject: Issue #18395: Rename ``_Py_char2wchar()`` to :c:func:`Py_DecodeLocale`, rename ``_Py_wchar2char()`` to :c:func:`Py_EncodeLocale`, and document these functions. --- Include/fileutils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Include') diff --git a/Include/fileutils.h b/Include/fileutils.h index f2a43f75c4..c5eebc5c07 100644 --- a/Include/fileutils.h +++ b/Include/fileutils.h @@ -7,11 +7,11 @@ extern "C" { PyAPI_FUNC(PyObject *) _Py_device_encoding(int); -PyAPI_FUNC(wchar_t *) _Py_char2wchar( +PyAPI_FUNC(wchar_t *) Py_DecodeLocale( const char *arg, size_t *size); -PyAPI_FUNC(char*) _Py_wchar2char( +PyAPI_FUNC(char*) Py_EncodeLocale( const wchar_t *text, size_t *error_pos); -- cgit v1.2.1 From f6843defec386221310ff7cd64c1c457b9c1a6f4 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 6 Aug 2014 19:31:40 -0400 Subject: Issue #22116: C functions and methods (of the 'builtin_function_or_method' type) can now be weakref'ed. Patch by Wei Wu. --- Include/methodobject.h | 1 + 1 file changed, 1 insertion(+) (limited to 'Include') diff --git a/Include/methodobject.h b/Include/methodobject.h index 3cc2ea9308..0236228617 100644 --- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -77,6 +77,7 @@ typedef struct { 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 */ + PyObject *m_weakreflist; /* List of weak references */ } PyCFunctionObject; #endif -- cgit v1.2.1 From affccb4da7a3eea42bb7941044961aa2acb8a0f9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 29 Aug 2014 16:31:59 +0200 Subject: Issue #22043: _PyTime_Init() now checks if the system clock works. Other changes: * The whole _PyTime API is private (not defined if Py_LIMITED_API is set) * _PyTime_gettimeofday_info() also returns -1 on error * Simplify PyTime_gettimeofday(): only use clock_gettime(CLOCK_REALTIME) or gettimeofday() on UNIX. Don't fallback to ftime() or time() anymore. --- Include/pytime.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'Include') diff --git a/Include/pytime.h b/Include/pytime.h index b0fc6d0354..14e95960e6 100644 --- a/Include/pytime.h +++ b/Include/pytime.h @@ -13,6 +13,8 @@ functions and constants extern "C" { #endif +#ifndef Py_LIMITED_API + #ifdef HAVE_GETTIMEOFDAY typedef struct timeval _PyTime_timeval; #else @@ -37,7 +39,7 @@ PyAPI_FUNC(void) _PyTime_gettimeofday(_PyTime_timeval *tp); /* Similar to _PyTime_gettimeofday() but retrieve also information on the * clock used to get the current time. */ -PyAPI_FUNC(void) _PyTime_gettimeofday_info( +PyAPI_FUNC(int) _PyTime_gettimeofday_info( _PyTime_timeval *tp, _Py_clock_info_t *info); @@ -52,8 +54,6 @@ do { \ ((tv_end.tv_sec - tv_start.tv_sec) + \ (tv_end.tv_usec - tv_start.tv_usec) * 0.000001) -#ifndef Py_LIMITED_API - typedef enum { /* Round towards zero. */ _PyTime_ROUND_DOWN=0, @@ -92,10 +92,11 @@ PyAPI_FUNC(int) _PyTime_ObjectToTimespec( time_t *sec, long *nsec, _PyTime_round_t); -#endif -/* Dummy to force linking. */ -PyAPI_FUNC(void) _PyTime_Init(void); +/* Initialize time. + Return 0 on success, raise an exception and return -1 on error. */ +PyAPI_FUNC(int) _PyTime_Init(void); +#endif /* Py_LIMITED_API */ #ifdef __cplusplus } -- cgit v1.2.1 From de0f2c502b20223c08f4d7dc933912b65ffa9df2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 31 Aug 2014 15:48:55 +0200 Subject: pytime.h: remove duplicated "#ifndef Py_LIMITED_API" --- Include/pytime.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'Include') diff --git a/Include/pytime.h b/Include/pytime.h index 14e95960e6..0f969b3c05 100644 --- a/Include/pytime.h +++ b/Include/pytime.h @@ -13,8 +13,6 @@ functions and constants extern "C" { #endif -#ifndef Py_LIMITED_API - #ifdef HAVE_GETTIMEOFDAY typedef struct timeval _PyTime_timeval; #else @@ -96,7 +94,6 @@ PyAPI_FUNC(int) _PyTime_ObjectToTimespec( /* Initialize time. Return 0 on success, raise an exception and return -1 on error. */ PyAPI_FUNC(int) _PyTime_Init(void); -#endif /* Py_LIMITED_API */ #ifdef __cplusplus } -- cgit v1.2.1 From f3579a8d0eed6151a1e2f34f6cad0677bfe45246 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 2 Sep 2014 23:18:25 +0200 Subject: Issue #22043: time.monotonic() is now always available threading.Lock.acquire(), threading.RLock.acquire() and socket operations now use a monotonic clock, instead of the system clock, when a timeout is used. --- Include/pytime.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Include') diff --git a/Include/pytime.h b/Include/pytime.h index 0f969b3c05..7a14456d3f 100644 --- a/Include/pytime.h +++ b/Include/pytime.h @@ -91,6 +91,24 @@ PyAPI_FUNC(int) _PyTime_ObjectToTimespec( long *nsec, _PyTime_round_t); +/* Get the time of a monotonic clock, i.e. a clock that cannot go backwards. + The clock is not affected by system clock updates. The reference point of + the returned value is undefined, so that only the difference between the + results of consecutive calls is valid. + + The function never fails. _PyTime_Init() ensures that a monotonic clock + is available and works. */ +PyAPI_FUNC(void) _PyTime_monotonic( + _PyTime_timeval *tp); + +/* Similar to _PyTime_monotonic(), fill also info (if set) with information of + the function used to get the time. + + Return 0 on success, raise an exception and return -1 on error. */ +PyAPI_FUNC(int) _PyTime_monotonic_info( + _PyTime_timeval *tp, + _Py_clock_info_t *info); + /* Initialize time. Return 0 on success, raise an exception and return -1 on error. */ PyAPI_FUNC(int) _PyTime_Init(void); -- cgit v1.2.1 From dbf5294cd5f6a2360be77f4c5ed964b7f146d04f Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Tue, 30 Sep 2014 21:16:27 +0200 Subject: Issue #18711: Add a new `PyErr_FormatV` function, similar to `PyErr_Format` but accepting a `va_list` argument. --- Include/pyerrors.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Include') diff --git a/Include/pyerrors.h b/Include/pyerrors.h index e44fb5f0eb..24bc2b7a8d 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -242,6 +242,12 @@ PyAPI_FUNC(PyObject *) PyErr_Format( const char *format, /* ASCII-encoded string */ ... ); +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 +PyAPI_FUNC(PyObject *) PyErr_FormatV( + PyObject *exception, + const char *format, + va_list vargs); +#endif #ifdef MS_WINDOWS PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename( -- cgit v1.2.1 From 9e89645e729b5d502bc52b4f33a064d92c4ed645 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 10 Oct 2014 11:55:41 +0200 Subject: Issue #22591: Drop support of MS-DOS Drop support of MS-DOS, especially of the DJGPP compiler (MS-DOS port of GCC). Today is a sad day. Good bye MS-DOS, good bye my friend :'-( --- Include/osdefs.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'Include') diff --git a/Include/osdefs.h b/Include/osdefs.h index 0c2e34b879..bd84c1c12c 100644 --- a/Include/osdefs.h +++ b/Include/osdefs.h @@ -7,15 +7,12 @@ extern "C" { /* Operating system dependencies */ -/* Mod by chrish: QNX has WATCOM, but isn't DOS */ -#if !defined(__QNX__) -#if defined(MS_WINDOWS) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__DJGPP__) +#ifdef MS_WINDOWS #define SEP L'\\' #define ALTSEP L'/' #define MAXPATHLEN 256 #define DELIM L';' #endif -#endif /* Filename separator */ #ifndef SEP -- cgit v1.2.1 From 6e9be5f210237c3f6dc67bc6f84db6f0324c1054 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 18 Nov 2014 23:34:33 +0200 Subject: Issue #22453: Removed non-documented macro PyObject_REPR(). --- Include/object.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'Include') diff --git a/Include/object.h b/Include/object.h index f3c87ebd22..e348d61d1b 100644 --- a/Include/object.h +++ b/Include/object.h @@ -575,9 +575,6 @@ PyAPI_FUNC(PyObject *) PyObject_Dir(PyObject *); PyAPI_FUNC(int) Py_ReprEnter(PyObject *); PyAPI_FUNC(void) Py_ReprLeave(PyObject *); -/* Helper for passing objects to printf and the like */ -#define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj)) - /* Flag bits for printing: */ #define Py_PRINT_RAW 1 /* No string quotes etc. */ -- cgit v1.2.1 From 86a58dabec40bfb4c112b918cabd7eb21e52183c Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Thu, 20 Nov 2014 21:39:37 +1000 Subject: Issue #22869: Split pythonrun into two modules - interpreter startup and shutdown code moved to a new pylifecycle.c module - Py_OptimizeFlag moved into the new module with the other global flags --- Include/Python.h | 1 + Include/object.h | 7 +++ Include/pydebug.h | 2 + Include/pyerrors.h | 1 + Include/pylifecycle.h | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++ Include/pythonrun.h | 110 -------------------------------------------- 6 files changed, 135 insertions(+), 110 deletions(-) create mode 100644 Include/pylifecycle.h (limited to 'Include') diff --git a/Include/Python.h b/Include/Python.h index 2dd82903bc..46d2eced92 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -112,6 +112,7 @@ #include "pyarena.h" #include "modsupport.h" #include "pythonrun.h" +#include "pylifecycle.h" #include "ceval.h" #include "sysmodule.h" #include "intrcheck.h" diff --git a/Include/object.h b/Include/object.h index e348d61d1b..e29608aed6 100644 --- a/Include/object.h +++ b/Include/object.h @@ -65,6 +65,7 @@ whose size is determined when the object is allocated. #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 \ @@ -710,11 +711,17 @@ PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void); _Py_NegativeRefcount(__FILE__, __LINE__, \ (PyObject *)(OP)); \ } +/* Py_REF_DEBUG also controls the display of refcounts and memory block + * allocations at the interactive prompt and at interpreter shutdown + */ +PyAPI_FUNC(void) _PyDebug_PrintTotalRefs(void); +#define _PY_DEBUG_PRINT_TOTAL_REFS() _PyDebug_PrintTotalRefs() #else #define _Py_INC_REFTOTAL #define _Py_DEC_REFTOTAL #define _Py_REF_DEBUG_COMMA #define _Py_CHECK_REFCNT(OP) /* a semicolon */; +#define _PY_DEBUG_PRINT_TOTAL_REFS() #endif /* Py_REF_DEBUG */ #ifdef COUNT_ALLOCS diff --git a/Include/pydebug.h b/Include/pydebug.h index 8fe98183f9..19bec2bd81 100644 --- a/Include/pydebug.h +++ b/Include/pydebug.h @@ -5,6 +5,8 @@ extern "C" { #endif +/* These global variable are defined in pylifecycle.c */ +/* XXX (ncoghlan): move these declarations to pylifecycle.h? */ PyAPI_DATA(int) Py_DebugFlag; PyAPI_DATA(int) Py_VerboseFlag; PyAPI_DATA(int) Py_QuietFlag; diff --git a/Include/pyerrors.h b/Include/pyerrors.h index 65b09f02de..8a7e4f419c 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -99,6 +99,7 @@ PyAPI_FUNC(void) PyErr_SetExcInfo(PyObject *, PyObject *, PyObject *); #define _Py_NO_RETURN #endif +/* Defined in Python/pylifecycle.c */ PyAPI_FUNC(void) Py_FatalError(const char *message) _Py_NO_RETURN; #if defined(Py_DEBUG) || defined(Py_LIMITED_API) diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h new file mode 100644 index 0000000000..ccdebe26a4 --- /dev/null +++ b/Include/pylifecycle.h @@ -0,0 +1,124 @@ + +/* Interfaces to configure, query, create & destroy the Python runtime */ + +#ifndef Py_PYLIFECYCLE_H +#define Py_PYLIFECYCLE_H +#ifdef __cplusplus +extern "C" { +#endif + +PyAPI_FUNC(void) Py_SetProgramName(wchar_t *); +PyAPI_FUNC(wchar_t *) Py_GetProgramName(void); + +PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *); +PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void); + +#ifndef Py_LIMITED_API +/* Only used by applications that embed the interpreter and need to + * override the standard encoding determination mechanism + */ +PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding, + const char *errors); +#endif + +PyAPI_FUNC(void) Py_Initialize(void); +PyAPI_FUNC(void) Py_InitializeEx(int); +#ifndef Py_LIMITED_API +PyAPI_FUNC(void) _Py_InitializeEx_Private(int, int); +#endif +PyAPI_FUNC(void) Py_Finalize(void); +PyAPI_FUNC(int) Py_IsInitialized(void); +PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void); +PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *); + + +/* 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 __main__ (defined in Modules/main.c) */ +PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv); + +/* In getpath.c */ +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); +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_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(PyObject * bltinmod); +PyAPI_FUNC(void) _PyImportHooks_Init(void); +PyAPI_FUNC(int) _PyFrame_Init(void); +PyAPI_FUNC(int) _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); +PyAPI_FUNC(void) PyFrame_Fini(void); +PyAPI_FUNC(void) PyCFunction_Fini(void); +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) PyBytes_Fini(void); +PyAPI_FUNC(void) PyByteArray_Fini(void); +PyAPI_FUNC(void) PyFloat_Fini(void); +PyAPI_FUNC(void) PyOS_FiniInterrupts(void); +PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void); +PyAPI_FUNC(void) _PyGC_Fini(void); +PyAPI_FUNC(void) PySlice_Fini(void); +PyAPI_FUNC(void) _PyType_Fini(void); +PyAPI_FUNC(void) _PyRandom_Fini(void); + +PyAPI_DATA(PyThreadState *) _Py_Finalizing; +#endif + +/* Signals */ +typedef void (*PyOS_sighandler_t)(int); +PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int); +PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t); + +/* Random */ +PyAPI_FUNC(int) _PyOS_URandom (void *buffer, Py_ssize_t size); + +#ifdef __cplusplus +} +#endif +#endif /* !Py_PYLIFECYCLE_H */ diff --git a/Include/pythonrun.h b/Include/pythonrun.h index 2fc5578f04..1d9b71beaa 100644 --- a/Include/pythonrun.h +++ b/Include/pythonrun.h @@ -22,30 +22,6 @@ typedef struct { } PyCompilerFlags; #endif -PyAPI_FUNC(void) Py_SetProgramName(wchar_t *); -PyAPI_FUNC(wchar_t *) Py_GetProgramName(void); - -PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *); -PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void); - -#ifndef Py_LIMITED_API -/* Only used by applications that embed the interpreter and need to - * override the standard encoding determination mechanism - */ -PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding, - const char *errors); -#endif - -PyAPI_FUNC(void) Py_Initialize(void); -PyAPI_FUNC(void) Py_InitializeEx(int); -#ifndef Py_LIMITED_API -PyAPI_FUNC(void) _Py_InitializeEx_Private(int, int); -#endif -PyAPI_FUNC(void) Py_Finalize(void); -PyAPI_FUNC(int) Py_IsInitialized(void); -PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void); -PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *); - #ifndef Py_LIMITED_API PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *); PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *); @@ -166,26 +142,6 @@ 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, 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) @@ -207,64 +163,6 @@ PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv); PyRun_FileExFlags(fp, p, s, g, l, 0, flags) #endif -/* In getpath.c */ -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); -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_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(PyObject * bltinmod); -PyAPI_FUNC(void) _PyImportHooks_Init(void); -PyAPI_FUNC(int) _PyFrame_Init(void); -PyAPI_FUNC(int) _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); -PyAPI_FUNC(void) PyFrame_Fini(void); -PyAPI_FUNC(void) PyCFunction_Fini(void); -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) PyBytes_Fini(void); -PyAPI_FUNC(void) PyByteArray_Fini(void); -PyAPI_FUNC(void) PyFloat_Fini(void); -PyAPI_FUNC(void) PyOS_FiniInterrupts(void); -PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void); -PyAPI_FUNC(void) _PyGC_Fini(void); -PyAPI_FUNC(void) PySlice_Fini(void); -PyAPI_FUNC(void) _PyType_Fini(void); -PyAPI_FUNC(void) _PyRandom_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 *, const char *); @@ -290,14 +188,6 @@ PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState; PyAPI_FUNC(int) PyOS_CheckStack(void); #endif -/* Signals */ -typedef void (*PyOS_sighandler_t)(int); -PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int); -PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t); - -/* Random */ -PyAPI_FUNC(int) _PyOS_URandom (void *buffer, Py_ssize_t size); - #ifdef __cplusplus } #endif -- cgit v1.2.1 From 11e25614459b076ba1c6b12d6a08cf491212d9db Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 25 Nov 2014 13:57:17 +0200 Subject: Issue #19676: Added the "namereplace" error handler. --- Include/codecs.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Include') diff --git a/Include/codecs.h b/Include/codecs.h index b3088e4902..466913540f 100644 --- a/Include/codecs.h +++ b/Include/codecs.h @@ -225,6 +225,9 @@ PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc); /* replace the unicode encode error with backslash escapes (\x, \u and \U) */ PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc); +/* replace the unicode encode error with backslash escapes (\N, \x, \u and \U) */ +PyAPI_FUNC(PyObject *) PyCodec_NameReplaceErrors(PyObject *exc); + PyAPI_DATA(const char *) Py_hexdigits; #ifdef __cplusplus -- cgit v1.2.1 From 2bd55106424dcbb668766c96472ec26e8d7bba2e Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 26 Dec 2014 17:28:16 -0800 Subject: Neaten-up setobject.h - Move all Py_LIMITED_API exclusions together under one #ifndef - Group PyAPI_FUNC functions and PyAPI_DATA together. - Bring related comments together and put them in the appropriate section. --- Include/setobject.h | 84 +++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 45 deletions(-) (limited to 'Include') diff --git a/Include/setobject.h b/Include/setobject.h index ae3f556365..edf1b63855 100644 --- a/Include/setobject.h +++ b/Include/setobject.h @@ -6,9 +6,9 @@ extern "C" { #endif +#ifndef Py_LIMITED_API -/* -There are three kinds of slots in the table: +/* There are three kinds of entries in the table: 1. Unused: key == NULL 2. Active: key != NULL and key != dummy @@ -18,7 +18,7 @@ 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 { @@ -27,17 +27,22 @@ typedef struct { Py_hash_t hash; } setentry; +/* The SetObject data structure is shared by set and frozenset objects. + +Invariant for sets: + - hash is -1 + +Invariants for frozensets: + - data is immutable. + - hash is the hash of the frozenset or -1 if not computed yet. -/* -This data structure is shared by set and frozenset objects. */ -typedef struct _setobject PySetObject; -struct _setobject { +typedef struct _setobject { PyObject_HEAD - Py_ssize_t fill; /* # Active + # Dummy */ - Py_ssize_t used; /* # Active */ + Py_ssize_t fill; /* Number active and dummy entries*/ + Py_ssize_t used; /* Number active entries */ /* The table contains mask + 1 slots, and that's a power of 2. * We store the mask instead of the size because the mask is more @@ -45,33 +50,42 @@ struct _setobject { */ Py_ssize_t mask; - /* table points to smalltable for small tables, else to - * additional malloc'ed memory. table is never NULL! This rule - * saves repeated runtime null-tests. + /* The table points to a fixed-size smalltable for small tables + * or to additional malloc'ed memory for bigger tables. + * The table pointer is never NULL which saves us from repeated + * runtime null-tests. */ setentry *table; - setentry *(*lookup)(PySetObject *so, PyObject *key, Py_hash_t hash); - Py_hash_t hash; /* only used by frozenset objects */ + setentry *(*lookup)(struct _setobject *so, PyObject *key, Py_hash_t hash); + Py_hash_t hash; /* Only used by frozenset objects */ setentry smalltable[PySet_MINSIZE]; PyObject *weakreflist; /* List of weak references */ -}; -#endif /* Py_LIMITED_API */ +} PySetObject; + +#define PySet_GET_SIZE(so) (((PySetObject *)(so))->used) + +PyAPI_DATA(PyObject *) _PySet_Dummy; + +PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash); +PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable); +PyAPI_FUNC(int) PySet_ClearFreeList(void); + +#endif /* Section excluded by Py_LIMITED_API */ PyAPI_DATA(PyTypeObject) PySet_Type; PyAPI_DATA(PyTypeObject) PyFrozenSet_Type; PyAPI_DATA(PyTypeObject) PySetIter_Type; -#ifndef Py_LIMITED_API -PyAPI_DATA(PyObject *) _PySet_Dummy; -#endif +PyAPI_FUNC(PyObject *) PySet_New(PyObject *); +PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *); -/* Invariants for frozensets: - * data is immutable. - * hash is the hash of the frozenset or -1 if not computed yet. - * Invariants for sets: - * hash is -1 - */ +PyAPI_FUNC(int) PySet_Add(PyObject *set, PyObject *key); +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(PyObject *) PySet_Pop(PyObject *set); +PyAPI_FUNC(Py_ssize_t) PySet_Size(PyObject *anyset); #define PyFrozenSet_CheckExact(ob) (Py_TYPE(ob) == &PyFrozenSet_Type) #define PyAnySet_CheckExact(ob) \ @@ -87,26 +101,6 @@ PyAPI_DATA(PyObject *) _PySet_Dummy; (Py_TYPE(ob) == &PyFrozenSet_Type || \ PyType_IsSubtype(Py_TYPE(ob), &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); -#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); - -PyAPI_FUNC(int) PySet_ClearFreeList(void); -#endif - #ifdef __cplusplus } #endif -- cgit v1.2.1 From 3effb6eaf7b79664e7146fec5605830829d5e566 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 28 Dec 2014 17:15:12 -0800 Subject: Minor comment clean-up --- Include/setobject.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Include') diff --git a/Include/setobject.h b/Include/setobject.h index edf1b63855..8f8e34f254 100644 --- a/Include/setobject.h +++ b/Include/setobject.h @@ -22,9 +22,8 @@ no meaning otherwise. #define PySet_MINSIZE 8 typedef struct { - /* Cached hash code of the key. */ PyObject *key; - Py_hash_t hash; + Py_hash_t hash; /* Cached hash code of the key */ } setentry; /* The SetObject data structure is shared by set and frozenset objects. -- cgit v1.2.1 From f6350e4f6255b00991a0fc9f7a7c516932dfd6c6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 9 Jan 2015 02:13:19 +0100 Subject: Issue #22038: pyatomic.h now uses stdatomic.h or GCC built-in functions for atomic memory access if available. Patch written by Vitor de Lima and Gustavo Temple. --- Include/pyatomic.h | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) (limited to 'Include') diff --git a/Include/pyatomic.h b/Include/pyatomic.h index d4e19e0070..80bd825bd7 100644 --- a/Include/pyatomic.h +++ b/Include/pyatomic.h @@ -1,12 +1,15 @@ #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" +#include "pyconfig.h" + +#if defined(HAVE_STD_ATOMIC) +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -20,6 +23,76 @@ extern "C" { * Beware, the implementations here are deep magic. */ +#if defined(HAVE_STD_ATOMIC) + +typedef enum _Py_memory_order { + _Py_memory_order_relaxed = memory_order_relaxed, + _Py_memory_order_acquire = memory_order_acquire, + _Py_memory_order_release = memory_order_release, + _Py_memory_order_acq_rel = memory_order_acq_rel, + _Py_memory_order_seq_cst = memory_order_seq_cst +} _Py_memory_order; + +typedef struct _Py_atomic_address { + _Atomic void *_value; +} _Py_atomic_address; + +typedef struct _Py_atomic_int { + atomic_int _value; +} _Py_atomic_int; + +#define _Py_atomic_signal_fence(/*memory_order*/ ORDER) \ + atomic_signal_fence(ORDER) + +#define _Py_atomic_thread_fence(/*memory_order*/ ORDER) \ + atomic_thread_fence(ORDER) + +#define _Py_atomic_store_explicit(ATOMIC_VAL, NEW_VAL, ORDER) \ + atomic_store_explicit(&(ATOMIC_VAL)->_value, NEW_VAL, ORDER) + +#define _Py_atomic_load_explicit(ATOMIC_VAL, ORDER) \ + atomic_load_explicit(&(ATOMIC_VAL)->_value, ORDER) + +/* Use builtin atomic operations in GCC >= 4.7 */ +#elif defined(HAVE_BUILTIN_ATOMIC) + +typedef enum _Py_memory_order { + _Py_memory_order_relaxed = __ATOMIC_RELAXED, + _Py_memory_order_acquire = __ATOMIC_ACQUIRE, + _Py_memory_order_release = __ATOMIC_RELEASE, + _Py_memory_order_acq_rel = __ATOMIC_ACQ_REL, + _Py_memory_order_seq_cst = __ATOMIC_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; + +#define _Py_atomic_signal_fence(/*memory_order*/ ORDER) \ + __atomic_signal_fence(ORDER) + +#define _Py_atomic_thread_fence(/*memory_order*/ ORDER) \ + __atomic_thread_fence(ORDER) + +#define _Py_atomic_store_explicit(ATOMIC_VAL, NEW_VAL, ORDER) \ + (assert((ORDER) == __ATOMIC_RELAXED \ + || (ORDER) == __ATOMIC_SEQ_CST \ + || (ORDER) == __ATOMIC_RELEASE), \ + __atomic_store_n(&(ATOMIC_VAL)->_value, NEW_VAL, ORDER)) + +#define _Py_atomic_load_explicit(ATOMIC_VAL, ORDER) \ + (assert((ORDER) == __ATOMIC_RELAXED \ + || (ORDER) == __ATOMIC_SEQ_CST \ + || (ORDER) == __ATOMIC_ACQUIRE \ + || (ORDER) == __ATOMIC_CONSUME), \ + __atomic_load_n(&(ATOMIC_VAL)->_value, ORDER)) + +#else + typedef enum _Py_memory_order { _Py_memory_order_relaxed, _Py_memory_order_acquire, @@ -162,6 +235,7 @@ _Py_ANNOTATE_MEMORY_ORDER(const volatile void *address, _Py_memory_order order) ((ATOMIC_VAL)->_value) #endif /* !gcc x86 */ +#endif /* Standardized shortcuts. */ #define _Py_atomic_store(ATOMIC_VAL, NEW_VAL) \ -- cgit v1.2.1 From 76810cb5ae8fd10d968febc017031c0147dd192d Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 18 Jan 2015 13:12:42 -0800 Subject: Issue 23261: Clean-up the hack to store the set.pop() search finger in a hash field instead of the setobject. --- Include/setobject.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Include') diff --git a/Include/setobject.h b/Include/setobject.h index 8f8e34f254..79124d0f6e 100644 --- a/Include/setobject.h +++ b/Include/setobject.h @@ -14,9 +14,7 @@ extern "C" { 2. Active: key != NULL and key != dummy 3. Dummy: key == dummy -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. +The hash field of Unused or Dummy slots have no meaning. */ #define PySet_MINSIZE 8 @@ -59,6 +57,7 @@ typedef struct _setobject { Py_hash_t hash; /* Only used by frozenset objects */ setentry smalltable[PySet_MINSIZE]; + Py_ssize_t finger; /* Search finger for pop() */ PyObject *weakreflist; /* List of weak references */ } PySetObject; -- cgit v1.2.1 From 7e17d7ffa19aecaa39ff771d846a0d6286e4f1cf Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Fri, 23 Jan 2015 20:05:18 -0800 Subject: Issue20284: Implement PEP461 --- Include/bytesobject.h | 1 + Include/unicodeobject.h | 2 ++ 2 files changed, 3 insertions(+) (limited to 'Include') diff --git a/Include/bytesobject.h b/Include/bytesobject.h index 0ee8d366d4..e379bace37 100644 --- a/Include/bytesobject.h +++ b/Include/bytesobject.h @@ -62,6 +62,7 @@ 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_Format(PyObject *, PyObject *); #endif PyAPI_FUNC(PyObject *) PyBytes_DecodeEscape(const char *, Py_ssize_t, const char *, Py_ssize_t, diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index 729f584816..d2ffabee16 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -2245,6 +2245,8 @@ PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr( Py_UNICODE c ); +PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int); + /* 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). */ -- cgit v1.2.1 From d82392d2ae8e9780569b38c112d1d785c289ca69 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 25 Jan 2015 16:12:49 -0800 Subject: Issue #23119: Simplify setobject by inlining the special case for unicode equality testing. --- Include/setobject.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Include') diff --git a/Include/setobject.h b/Include/setobject.h index 79124d0f6e..a8b8d33ebb 100644 --- a/Include/setobject.h +++ b/Include/setobject.h @@ -35,7 +35,7 @@ Invariants for frozensets: */ -typedef struct _setobject { +typedef struct { PyObject_HEAD Py_ssize_t fill; /* Number active and dummy entries*/ @@ -53,7 +53,6 @@ typedef struct _setobject { * runtime null-tests. */ setentry *table; - setentry *(*lookup)(struct _setobject *so, PyObject *key, Py_hash_t hash); Py_hash_t hash; /* Only used by frozenset objects */ setentry smalltable[PySet_MINSIZE]; -- cgit v1.2.1 From f93951081085c7086cdfd22f6e54bdacfd2a8be8 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 26 Jan 2015 21:54:35 -0800 Subject: Remove unneeded dummy test from the set search loop (when the hashes match we know the key is not a dummy). --- Include/setobject.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Include') diff --git a/Include/setobject.h b/Include/setobject.h index a8b8d33ebb..bb5316f6d2 100644 --- a/Include/setobject.h +++ b/Include/setobject.h @@ -14,7 +14,10 @@ extern "C" { 2. Active: key != NULL and key != dummy 3. Dummy: key == dummy -The hash field of Unused or Dummy slots have no meaning. +The hash field of Unused slots have no meaning. +The hash field of Dummny slots are set to -1 +meaning that dummy entries can be detected by +either entry->key==dummy or by entry->hash==-1. */ #define PySet_MINSIZE 8 -- cgit v1.2.1 From b0f483844b90a0f9b24d9579182f8acff3d3b739 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 29 Jan 2015 22:00:32 -0800 Subject: Move the set search finger before the smalltable. --- Include/setobject.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Include') diff --git a/Include/setobject.h b/Include/setobject.h index bb5316f6d2..f17bc1b035 100644 --- a/Include/setobject.h +++ b/Include/setobject.h @@ -57,9 +57,9 @@ typedef struct { */ setentry *table; Py_hash_t hash; /* Only used by frozenset objects */ - setentry smalltable[PySet_MINSIZE]; - Py_ssize_t finger; /* Search finger for pop() */ + + setentry smalltable[PySet_MINSIZE]; PyObject *weakreflist; /* List of weak references */ } PySetObject; -- cgit v1.2.1 From fd700b4184cb6d730d1b29354f8a8d5bf23de999 Mon Sep 17 00:00:00 2001 From: Larry Hastings Date: Sat, 7 Feb 2015 16:00:55 -0800 Subject: Release bump for 3.5.0a1. --- Include/patchlevel.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Include') diff --git a/Include/patchlevel.h b/Include/patchlevel.h index 16124f5995..9606c154b1 100644 --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -20,10 +20,10 @@ #define PY_MINOR_VERSION 5 #define PY_MICRO_VERSION 0 #define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_ALPHA -#define PY_RELEASE_SERIAL 0 +#define PY_RELEASE_SERIAL 1 /* Version as a string */ -#define PY_VERSION "3.5.0a0" +#define PY_VERSION "3.5.0a1" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. -- cgit v1.2.1 From 1a886e6e267679eb3b59b262cbc6b36eef88a5b9 Mon Sep 17 00:00:00 2001 From: Larry Hastings Date: Sun, 8 Feb 2015 14:07:14 -0800 Subject: Post-release updates for Python 3.5.0a1. --- Include/patchlevel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Include') diff --git a/Include/patchlevel.h b/Include/patchlevel.h index 9606c154b1..ea0c042bfb 100644 --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -23,7 +23,7 @@ #define PY_RELEASE_SERIAL 1 /* Version as a string */ -#define PY_VERSION "3.5.0a1" +#define PY_VERSION "3.5.0a1+" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. -- cgit v1.2.1 From 4b5c8edd294f02afef7407d9fd5236789bd4bc34 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Sat, 21 Feb 2015 08:44:05 -0800 Subject: Issue #23152: Implement _Py_fstat() to support files larger than 2 GB on Windows. fstat() may fail with EOVERFLOW on files larger than 2 GB because the file size type is an signed 32-bit integer. --- Include/fileutils.h | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'Include') diff --git a/Include/fileutils.h b/Include/fileutils.h index c5eebc5c07..6effd88f3d 100644 --- a/Include/fileutils.h +++ b/Include/fileutils.h @@ -21,11 +21,40 @@ PyAPI_FUNC(int) _Py_wstat( struct stat *buf); #endif +#if defined(HAVE_FSTAT) || defined(MS_WINDOWS) + +#ifdef MS_WINDOWS +struct _Py_stat_struct { + unsigned long st_dev; + __int64 st_ino; + unsigned short st_mode; + int st_nlink; + int st_uid; + int st_gid; + unsigned long st_rdev; + __int64 st_size; + time_t st_atime; + int st_atime_nsec; + time_t st_mtime; + int st_mtime_nsec; + time_t st_ctime; + int st_ctime_nsec; + unsigned long st_file_attributes; +}; +#else +# define _Py_stat_struct stat +#endif + +PyAPI_FUNC(int) _Py_fstat( + int fd, + struct _Py_stat_struct *stat); +#endif /* HAVE_FSTAT || MS_WINDOWS */ + #ifdef HAVE_STAT PyAPI_FUNC(int) _Py_stat( PyObject *path, struct stat *statbuf); -#endif +#endif /* HAVE_STAT */ #ifndef Py_LIMITED_API PyAPI_FUNC(int) _Py_open( -- cgit v1.2.1 From ced0e7fcfd363dbf4e0a636418a82c65c6ec5944 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 22 Feb 2015 19:39:36 +0200 Subject: Issue #23152: Move declaration into a header and exclude from stable API. --- Include/fileutils.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Include') diff --git a/Include/fileutils.h b/Include/fileutils.h index 6effd88f3d..5ddd511622 100644 --- a/Include/fileutils.h +++ b/Include/fileutils.h @@ -21,6 +21,7 @@ PyAPI_FUNC(int) _Py_wstat( struct stat *buf); #endif +#ifndef Py_LIMITED_API #if defined(HAVE_FSTAT) || defined(MS_WINDOWS) #ifdef MS_WINDOWS @@ -41,6 +42,10 @@ struct _Py_stat_struct { int st_ctime_nsec; unsigned long st_file_attributes; }; + +PyAPI_FUNC(void) _Py_time_t_to_FILE_TIME(time_t, int, FILETIME *); +PyAPI_FUNC(void) _Py_attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *, + ULONG, struct _Py_stat_struct *); #else # define _Py_stat_struct stat #endif @@ -49,6 +54,7 @@ PyAPI_FUNC(int) _Py_fstat( int fd, struct _Py_stat_struct *stat); #endif /* HAVE_FSTAT || MS_WINDOWS */ +#endif /* Py_LIMITED_API */ #ifdef HAVE_STAT PyAPI_FUNC(int) _Py_stat( -- cgit v1.2.1 From 0016d9a8d58ab6bd20bb8d9c38a61f23a15fc296 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 22 Feb 2015 21:34:54 +0200 Subject: Issue #23152: Move declarations back to posixmodule.c. Declarations of Windows-specific auxilary functions need Windows types from windows.h. Instead of including windows.h in Python.h and making it available to all Windows users, it is simpler and safer just move declarations to the single file that needs them. --- Include/fileutils.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'Include') diff --git a/Include/fileutils.h b/Include/fileutils.h index 5ddd511622..bb9048116d 100644 --- a/Include/fileutils.h +++ b/Include/fileutils.h @@ -42,10 +42,6 @@ struct _Py_stat_struct { int st_ctime_nsec; unsigned long st_file_attributes; }; - -PyAPI_FUNC(void) _Py_time_t_to_FILE_TIME(time_t, int, FILETIME *); -PyAPI_FUNC(void) _Py_attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *, - ULONG, struct _Py_stat_struct *); #else # define _Py_stat_struct stat #endif -- cgit v1.2.1 From 6139bc8c6c02db0e084b495d1fe5ac9707635ecb Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Fri, 6 Mar 2015 14:47:02 -0800 Subject: Issue #23524: Replace _PyVerify_fd function with calling _set_thread_local_invalid_parameter_handler on every thread. --- Include/fileobject.h | 11 ----------- Include/fileutils.h | 12 ++++++++++++ 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'Include') diff --git a/Include/fileobject.h b/Include/fileobject.h index 0939744e6d..03155d3da7 100644 --- a/Include/fileobject.h +++ b/Include/fileobject.h @@ -32,17 +32,6 @@ PyAPI_DATA(int) Py_HasFileSystemDefaultEncoding; #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 - * 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); -#else -#define _PyVerify_fd(A) (1) /* dummy */ -#endif #endif /* Py_LIMITED_API */ /* A routine to check if a file descriptor can be select()-ed. */ diff --git a/Include/fileutils.h b/Include/fileutils.h index bb9048116d..95632edb11 100644 --- a/Include/fileutils.h +++ b/Include/fileutils.h @@ -108,6 +108,18 @@ PyAPI_FUNC(int) _Py_get_blocking(int fd); PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking); #endif /* !MS_WINDOWS */ +#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); + +#else +#define _PyVerify_fd(A) (1) /* dummy */ +#endif + #endif /* Py_LIMITED_API */ #ifdef __cplusplus -- cgit v1.2.1 From ef35d11c6986437b4eac74a6657377607c34841a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 6 Mar 2015 23:35:27 +0100 Subject: Issue #23571: PyObject_Call(), PyCFunction_Call() and call_function() now raise a SystemError if a function returns a result and raises an exception. The SystemError is chained to the previous exception. Refactor also PyObject_Call() and PyCFunction_Call() to make them more readable. Remove some checks which became useless (duplicate checks). Change reviewed by Serhiy Storchaka. --- Include/abstract.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Include') diff --git a/Include/abstract.h b/Include/abstract.h index db70f213bc..56fbf86035 100644 --- a/Include/abstract.h +++ b/Include/abstract.h @@ -266,6 +266,11 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable_object, PyObject *args, PyObject *kw); +#ifndef Py_LIMITED_API + PyAPI_FUNC(PyObject *) _Py_CheckFunctionResult(PyObject *obj, + const char *func_name); +#endif + /* Call a callable Python object, callable_object, with arguments and keywords arguments. The 'args' argument can not be -- cgit v1.2.1 From ebe018cd2c0afba30ec08c4ccb2736180607e8c1 Mon Sep 17 00:00:00 2001 From: Larry Hastings Date: Sun, 8 Mar 2015 00:24:34 -0800 Subject: Release bump for 3.5.0a2. --- Include/patchlevel.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Include') diff --git a/Include/patchlevel.h b/Include/patchlevel.h index ea0c042bfb..7ca27757f6 100644 --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -20,10 +20,10 @@ #define PY_MINOR_VERSION 5 #define PY_MICRO_VERSION 0 #define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_ALPHA -#define PY_RELEASE_SERIAL 1 +#define PY_RELEASE_SERIAL 2 /* Version as a string */ -#define PY_VERSION "3.5.0a1+" +#define PY_VERSION "3.5.0a2" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. -- cgit v1.2.1 From 09fa4a063f0e5c091d54aec6dc39a975e3579c88 Mon Sep 17 00:00:00 2001 From: Larry Hastings Date: Mon, 9 Mar 2015 02:39:47 -0700 Subject: Post-release changes for 3.5.0a2. --- Include/patchlevel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Include') diff --git a/Include/patchlevel.h b/Include/patchlevel.h index 7ca27757f6..e137b65fd9 100644 --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -23,7 +23,7 @@ #define PY_RELEASE_SERIAL 2 /* Version as a string */ -#define PY_VERSION "3.5.0a2" +#define PY_VERSION "3.5.0a2+" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. -- cgit v1.2.1