summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2012-06-17 05:15:49 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2012-06-17 05:15:49 (GMT)
commitc40bc09942f9532ed957dc8cd4da269ec089e830 (patch)
treef2596be6a738f230f6be4776f7f42d6925a3d747
parent8d5c0b8c198374d0b88f30f04dd29d1f19c1c913 (diff)
downloadcpython-c40bc09942f9532ed957dc8cd4da269ec089e830.zip
cpython-c40bc09942f9532ed957dc8cd4da269ec089e830.tar.gz
cpython-c40bc09942f9532ed957dc8cd4da269ec089e830.tar.bz2
Issue #13783: the PEP 380 implementation no longer expands the public C API
-rw-r--r--Include/genobject.h2
-rw-r--r--Include/pyerrors.h3
-rw-r--r--Misc/NEWS6
-rw-r--r--Objects/exceptions.c6
-rw-r--r--Objects/genobject.c7
-rw-r--r--Python/ceval.c2
6 files changed, 12 insertions, 14 deletions
diff --git a/Include/genobject.h b/Include/genobject.h
index 25f6c33..ed451ba 100644
--- a/Include/genobject.h
+++ b/Include/genobject.h
@@ -34,7 +34,7 @@ PyAPI_DATA(PyTypeObject) PyGen_Type;
PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *);
PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *);
-PyAPI_FUNC(int) PyGen_FetchStopIterationValue(PyObject **);
+PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
PyObject *_PyGen_Send(PyGenObject *, PyObject *);
#ifdef __cplusplus
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index cfae922..2c145ad 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -400,9 +400,6 @@ PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
const char *reason /* UTF-8 encoded string */
);
-/* create a StopIteration exception with the given value */
-PyAPI_FUNC(PyObject *) PyStopIteration_Create(PyObject *);
-
/* These APIs aren't really part of the error implementation, but
often needed to format error messages; the native C lib APIs are
not available on all platforms, which is why we provide emulations
diff --git a/Misc/NEWS b/Misc/NEWS
index 6c587af..5a5813b 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -111,6 +111,12 @@ Library
- Issue #14963: Convert contextlib.ExitStack.__exit__ to use an iterative
algorithm (Patch by Alon Horev)
+C-API
+-----
+
+- Issue #13783: Inadvertent additions to the public C API in the PEP 380
+ implementation have either been removed or marked as private interfaces.
+
Extension Modules
-----------------
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 9e10b7e..f706698 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -516,12 +516,6 @@ StopIteration_traverse(PyStopIterationObject *self, visitproc visit, void *arg)
return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg);
}
-PyObject *
-PyStopIteration_Create(PyObject *value)
-{
- return PyObject_CallFunctionObjArgs(PyExc_StopIteration, value, NULL);
-}
-
ComplexExtendsException(
PyExc_Exception, /* base */
StopIteration, /* name */
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 8c70b5c..6018e5b 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -97,7 +97,8 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc)
/* Delay exception instantiation if we can */
PyErr_SetNone(PyExc_StopIteration);
} else {
- PyObject *e = PyStopIteration_Create(result);
+ PyObject *e = PyObject_CallFunctionObjArgs(
+ PyExc_StopIteration, result, NULL);
if (e != NULL) {
PyErr_SetObject(PyExc_StopIteration, e);
Py_DECREF(e);
@@ -339,7 +340,7 @@ gen_throw(PyGenObject *gen, PyObject *args)
Py_DECREF(ret);
/* Termination repetition of YIELD_FROM */
gen->gi_frame->f_lasti++;
- if (PyGen_FetchStopIterationValue(&val) == 0) {
+ if (_PyGen_FetchStopIterationValue(&val) == 0) {
ret = gen_send_ex(gen, val, 0);
Py_DECREF(val);
} else {
@@ -428,7 +429,7 @@ gen_iternext(PyGenObject *gen)
*/
int
-PyGen_FetchStopIterationValue(PyObject **pvalue) {
+_PyGen_FetchStopIterationValue(PyObject **pvalue) {
PyObject *et, *ev, *tb;
PyObject *value = NULL;
diff --git a/Python/ceval.c b/Python/ceval.c
index b3ec013..7e9318b 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1852,7 +1852,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
PyObject *val;
x = POP(); /* Remove iter from stack */
Py_DECREF(x);
- err = PyGen_FetchStopIterationValue(&val);
+ err = _PyGen_FetchStopIterationValue(&val);
if (err < 0) {
x = NULL;
break;
rt(PyObject *, Py_ssize_t, PyObject *); PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *); -PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, int, int); -PyAPI_FUNC(int) PyList_SetSlice(PyObject *, int, int, PyObject *); +PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t); +PyAPI_FUNC(int) PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *); PyAPI_FUNC(int) PyList_Sort(PyObject *); PyAPI_FUNC(int) PyList_Reverse(PyObject *); PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *); diff --git a/Include/longintrepr.h b/Include/longintrepr.h index 254076e..b1574ba 100644 --- a/Include/longintrepr.h +++ b/Include/longintrepr.h @@ -52,7 +52,7 @@ struct _longobject { digit ob_digit[1]; }; -PyAPI_FUNC(PyLongObject *) _PyLong_New(int); +PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t); /* Return a copy of src. */ PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src); diff --git a/Include/longobject.h b/Include/longobject.h index 209c082..77544ef 100644 --- a/Include/longobject.h +++ b/Include/longobject.h @@ -21,6 +21,11 @@ PyAPI_FUNC(long) PyLong_AsLong(PyObject *); PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *); PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *); +/* For use by intobject.c only */ +PyAPI_FUNC(Py_ssize_t) _PyLong_AsSsize_t(PyObject *); +PyAPI_FUNC(PyObject *) _PyLong_FromSize_t(size_t); +PyAPI_FUNC(PyObject *) _PyLong_FromSsize_t(Py_ssize_t); + /* _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 @@ -43,7 +48,7 @@ PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *); PyAPI_FUNC(PyObject *) PyLong_FromString(char *, char **, int); #ifdef Py_USING_UNICODE -PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, int, int); +PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int); #endif /* _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0. diff --git a/Include/marshal.h b/Include/marshal.h index a9f7320..411fdca 100644 --- a/Include/marshal.h +++ b/Include/marshal.h @@ -17,7 +17,7 @@ PyAPI_FUNC(long) PyMarshal_ReadLongFromFile(FILE *); PyAPI_FUNC(int) PyMarshal_ReadShortFromFile(FILE *); PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromFile(FILE *); PyAPI_FUNC(PyObject *) PyMarshal_ReadLastObjectFromFile(FILE *); -PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, int); +PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t); #ifdef __cplusplus } diff --git a/Include/modsupport.h b/Include/modsupport.h index 7851683..fc9f2e8 100644 --- a/Include/modsupport.h +++ b/Include/modsupport.h @@ -9,6 +9,18 @@ extern "C" { #include +/* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier + to mean Py_ssize_t */ +#ifdef PY_SSIZE_T_CLEAN +#define PyArg_Parse _PyArg_Parse_SizeT +#define PyArg_ParseTuple _PyArg_ParseTuple_SizeT +#define PyArg_ParseTupleAndKeywords _PyArg_ParseTupleAndKeywords_SizeT +#define PyArg_VaParse _PyArg_VaParse_SizeT +#define PyArg_VaParseTupleAndKeywords _PyArg_VaParseTupleAndKeywords_SizeT +#define PyArg_BuildValue _PyArg_BuildValue_SizeT +#define PyArg_VaBuildValue _PyArg_VaBuildValue_SizeT +#endif + PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...); PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...); PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *, @@ -26,6 +38,7 @@ PyAPI_FUNC(int) PyModule_AddObject(PyObject *, const char *, PyObject *); PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long); PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *); + #define PYTHON_API_VERSION 1012 #define PYTHON_API_STRING "1012" /* The API version is maintained (independently from the Python version) @@ -77,11 +90,22 @@ PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char without actually needing a recompile. */ #endif /* MS_WINDOWS */ +#if SIZEOF_SIZE_T != SIZEOF_INT +/* On a 64-bit system, rename the Py_InitModule4 so that 2.4 + modules cannot get loaded into a 2.5 interpreter */ +#define Py_InitModule4 Py_InitModule4_64 +#endif + #ifdef Py_TRACE_REFS -/* When we are tracing reference counts, rename Py_InitModule4 so - modules compiled with incompatible settings will generate a - link-time error. */ -#define Py_InitModule4 Py_InitModule4TraceRefs + /* When we are tracing reference counts, rename Py_InitModule4 so + modules compiled with incompatible settings will generate a + link-time error. */ + #if SIZEOF_SIZE_T != SIZEOF_INT + #undef Py_InitModule4 + #define Py_InitModule4 Py_InitModule4TraceRefs_64 + #else + #define Py_InitModule4 Py_InitModule4TraceRefs + #endif #endif PyAPI_FUNC(PyObject *) Py_InitModule4(const char *name, PyMethodDef *methods, diff --git a/Include/object.h b/Include/object.h index ed6f3d1..faa3057 100644 --- a/Include/object.h +++ b/Include/object.h @@ -92,7 +92,8 @@ whose size is determined when the object is allocated. */ #define PyObject_VAR_HEAD \ PyObject_HEAD \ - int ob_size; /* Number of items in variable part */ + Py_ssize_t ob_size; /* Number of items in variable part */ +#define Py_INVALID_SIZE (Py_ssize_t)-1 /* Nothing is actually declared to be a PyObject, but every pointer to * a Python object can be cast to a PyObject*. This is inheritance built @@ -127,16 +128,29 @@ typedef PyObject * (*unaryfunc)(PyObject *); typedef PyObject * (*binaryfunc)(PyObject *, PyObject *); typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *); typedef int (*inquiry)(PyObject *); +typedef Py_ssize_t (*lenfunc)(PyObject *); typedef int (*coercion)(PyObject **, PyObject **); -typedef PyObject *(*intargfunc)(PyObject *, int); -typedef PyObject *(*intintargfunc)(PyObject *, int, int); +typedef PyObject *(*intargfunc)(PyObject *, int) Py_DEPRECATED(2.5); +typedef PyObject *(*intintargfunc)(PyObject *, int, int) Py_DEPRECATED(2.5); +typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t); +typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t); typedef int(*intobjargproc)(PyObject *, int, PyObject *); typedef int(*intintobjargproc)(PyObject *, int, int, PyObject *); +typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *); +typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *); typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *); + +/* int-based buffer interface */ typedef int (*getreadbufferproc)(PyObject *, int, void **); typedef int (*getwritebufferproc)(PyObject *, int, void **); typedef int (*getsegcountproc)(PyObject *, int *); typedef int (*getcharbufferproc)(PyObject *, int, const char **); +/* ssize_t-based buffer interface */ +typedef Py_ssize_t (*readbufferproc)(PyObject *, Py_ssize_t, void **); +typedef Py_ssize_t (*writebufferproc)(PyObject *, Py_ssize_t, void **); +typedef Py_ssize_t (*segcountproc)(PyObject *, Py_ssize_t *); +typedef Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, const char **); + typedef int (*objobjproc)(PyObject *, PyObject *); typedef int (*visitproc)(PyObject *, void *); typedef int (*traverseproc)(PyObject *, visitproc, void *); @@ -195,30 +209,30 @@ typedef struct { } PyNumberMethods; typedef struct { - inquiry sq_length; + lenfunc sq_length; binaryfunc sq_concat; - intargfunc sq_repeat; - intargfunc sq_item; - intintargfunc sq_slice; - intobjargproc sq_ass_item; - intintobjargproc sq_ass_slice; + ssizeargfunc sq_repeat; + ssizeargfunc sq_item; + ssizessizeargfunc sq_slice; + ssizeobjargproc sq_ass_item; + ssizessizeobjargproc sq_ass_slice; objobjproc sq_contains; /* Added in release 2.0 */ binaryfunc sq_inplace_concat; - intargfunc sq_inplace_repeat; + ssizeargfunc sq_inplace_repeat; } PySequenceMethods; typedef struct { - inquiry mp_length; + lenfunc mp_length; binaryfunc mp_subscript; objobjargproc mp_ass_subscript; } PyMappingMethods; typedef struct { - getreadbufferproc bf_getreadbuffer; - getwritebufferproc bf_getwritebuffer; - getsegcountproc bf_getsegcount; - getcharbufferproc bf_getcharbuffer; + readbufferproc bf_getreadbuffer; + writebufferproc bf_getwritebuffer; + segcountproc bf_getsegcount; + charbufferproc bf_getcharbuffer; } PyBufferProcs; @@ -239,7 +253,7 @@ typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *); typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *); typedef int (*initproc)(PyObject *, PyObject *, PyObject *); typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *); -typedef PyObject *(*allocfunc)(struct _typeobject *, int); +typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t); typedef struct _typeobject { PyObject_VAR_HEAD @@ -362,7 +376,7 @@ PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */ #define PyType_CheckExact(op) ((op)->ob_type == &PyType_Type) PyAPI_FUNC(int) PyType_Ready(PyTypeObject *); -PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, int); +PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t); PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *, PyObject *, PyObject *); PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *); diff --git a/Include/objimpl.h b/Include/objimpl.h index a9412ce..a168c8b 100644 --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -146,9 +146,9 @@ PyAPI_FUNC(void) _PyObject_DebugMallocStats(void); /* Functions */ PyAPI_FUNC(PyObject *) PyObject_Init(PyObject *, PyTypeObject *); PyAPI_FUNC(PyVarObject *) PyObject_InitVar(PyVarObject *, - PyTypeObject *, int); + PyTypeObject *, Py_ssize_t); PyAPI_FUNC(PyObject *) _PyObject_New(PyTypeObject *); -PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, int); +PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t); #define PyObject_New(type, typeobj) \ ( (type *) _PyObject_New(typeobj) ) @@ -291,7 +291,7 @@ extern PyGC_Head *_PyGC_generation0; PyAPI_FUNC(PyObject *) _PyObject_GC_Malloc(size_t); PyAPI_FUNC(PyObject *) _PyObject_GC_New(PyTypeObject *); -PyAPI_FUNC(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, int); +PyAPI_FUNC(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t); PyAPI_FUNC(void) PyObject_GC_Track(void *); PyAPI_FUNC(void) PyObject_GC_UnTrack(void *); PyAPI_FUNC(void) PyObject_GC_Del(void *); diff --git a/Include/pyerrors.h b/Include/pyerrors.h index 94a5290..330a35c 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -156,15 +156,15 @@ PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int); /* create a UnicodeDecodeError object */ PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create( - const char *, const char *, int, int, int, const char *); + const char *, const char *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *); /* create a UnicodeEncodeError object */ PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create( - const char *, const Py_UNICODE *, int, int, int, const char *); + const char *, const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *); /* create a UnicodeTranslateError object */ PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create( - const Py_UNICODE *, int, int, int, const char *); + const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *); /* get the encoding attribute */ PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *); @@ -177,27 +177,27 @@ PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *); /* get the value of the start attribute (the int * may not be NULL) return 0 on success, -1 on failure */ -PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, int *); -PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, int *); -PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, int *); +PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *); +PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *); +PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *); /* assign a new valu