[Python-checkins] commit of r41731 - in python/branches/ssize_t: Include/abstract.h Include/bufferobject.h Include/cStringIO.h Include/ceval.h Include/intobject.h Include/listobject.h Include/longintrepr.h Include/longobject.h Include/marshal.h Include/modsupport.h Include/object.h Include/objimpl.h Include/pyerrors.h Include/pyport.h Include/sliceobject.h Include/stringobject.h Include/tupleobject.h Include/unicodeobject.h Modules/_codecsmodule.c Modules/_hotshot.c Modules/_localemodule.c Modules/arraymodule.c Modules/audioop.c Modules/cPickle.c Modules/cStringIO.c Modules/cjkcodecs/multibytecodec.c Modules/gcmodule.c Modules/parsermodule.c Modules/posixmodule.c Modules/rgbimgmodule.c Modules/zipimport.c Objects/abstract.c Objects/bufferobject.c Objects/classobject.c Objects/fileobject.c Objects/intobject.c Objects/listobject.c Objects/longobject.c Objects/object.c Objects/obmalloc.c Objects/rangeobject.c Objects/sliceobject.c Objects/stringobject.c Objects/structseq.c Objects/tupleobject.c Objects/typeobject.c Objects/unicodeobject.c Objects/weakrefobject.c PC/getpathp.c PC/import_nt.c Parser/parsetok.c Parser/tokenizer.c Python/ceval.c Python/codecs.c Python/exceptions.c Python/getargs.c Python/import.c Python/mactoolboxglue.c Python/marshal.c Python/modsupport.c Python/pythonrun.c Python/sysmodule.c Python/thread_nt.h configure configure.in pyconfig.h.in
martin.v.loewis
python-checkins at python.org
Sat Dec 17 11:20:31 CET 2005
Author: martin.v.loewis
Date: Sat Dec 17 11:20:15 2005
New Revision: 41731
Modified:
python/branches/ssize_t/Include/abstract.h
python/branches/ssize_t/Include/bufferobject.h
python/branches/ssize_t/Include/cStringIO.h
python/branches/ssize_t/Include/ceval.h
python/branches/ssize_t/Include/intobject.h
python/branches/ssize_t/Include/listobject.h
python/branches/ssize_t/Include/longintrepr.h
python/branches/ssize_t/Include/longobject.h
python/branches/ssize_t/Include/marshal.h
python/branches/ssize_t/Include/modsupport.h
python/branches/ssize_t/Include/object.h
python/branches/ssize_t/Include/objimpl.h
python/branches/ssize_t/Include/pyerrors.h
python/branches/ssize_t/Include/pyport.h
python/branches/ssize_t/Include/sliceobject.h
python/branches/ssize_t/Include/stringobject.h
python/branches/ssize_t/Include/tupleobject.h
python/branches/ssize_t/Include/unicodeobject.h
python/branches/ssize_t/Modules/_codecsmodule.c
python/branches/ssize_t/Modules/_hotshot.c
python/branches/ssize_t/Modules/_localemodule.c
python/branches/ssize_t/Modules/arraymodule.c
python/branches/ssize_t/Modules/audioop.c
python/branches/ssize_t/Modules/cPickle.c
python/branches/ssize_t/Modules/cStringIO.c
python/branches/ssize_t/Modules/cjkcodecs/multibytecodec.c
python/branches/ssize_t/Modules/gcmodule.c
python/branches/ssize_t/Modules/parsermodule.c
python/branches/ssize_t/Modules/posixmodule.c
python/branches/ssize_t/Modules/rgbimgmodule.c
python/branches/ssize_t/Modules/zipimport.c
python/branches/ssize_t/Objects/abstract.c
python/branches/ssize_t/Objects/bufferobject.c
python/branches/ssize_t/Objects/classobject.c
python/branches/ssize_t/Objects/fileobject.c
python/branches/ssize_t/Objects/intobject.c
python/branches/ssize_t/Objects/listobject.c
python/branches/ssize_t/Objects/longobject.c
python/branches/ssize_t/Objects/object.c
python/branches/ssize_t/Objects/obmalloc.c
python/branches/ssize_t/Objects/rangeobject.c
python/branches/ssize_t/Objects/sliceobject.c
python/branches/ssize_t/Objects/stringobject.c
python/branches/ssize_t/Objects/structseq.c
python/branches/ssize_t/Objects/tupleobject.c
python/branches/ssize_t/Objects/typeobject.c
python/branches/ssize_t/Objects/unicodeobject.c
python/branches/ssize_t/Objects/weakrefobject.c
python/branches/ssize_t/PC/getpathp.c
python/branches/ssize_t/PC/import_nt.c
python/branches/ssize_t/Parser/parsetok.c
python/branches/ssize_t/Parser/tokenizer.c
python/branches/ssize_t/Python/ceval.c
python/branches/ssize_t/Python/codecs.c
python/branches/ssize_t/Python/exceptions.c
python/branches/ssize_t/Python/getargs.c
python/branches/ssize_t/Python/import.c
python/branches/ssize_t/Python/mactoolboxglue.c
python/branches/ssize_t/Python/marshal.c
python/branches/ssize_t/Python/modsupport.c
python/branches/ssize_t/Python/pythonrun.c
python/branches/ssize_t/Python/sysmodule.c
python/branches/ssize_t/Python/thread_nt.h
python/branches/ssize_t/configure
python/branches/ssize_t/configure.in
python/branches/ssize_t/pyconfig.h.in
Log:
Commit current version of patch 1166195.
Modified: python/branches/ssize_t/Include/abstract.h
==============================================================================
--- python/branches/ssize_t/Include/abstract.h (original)
+++ python/branches/ssize_t/Include/abstract.h Sat Dec 17 11:20:15 2005
@@ -928,7 +928,7 @@
*/
- PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, int count);
+ PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count);
/*
Return the result of repeating sequence object o count times,
@@ -937,14 +937,14 @@
*/
- PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, int i);
+ PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i);
/*
Return the ith element of o, or NULL on failure. This is the
equivalent of the Python expression: o[i].
*/
- PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, int i1, int i2);
+ PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
/*
Return the slice of sequence object o between i1 and i2, or
@@ -953,7 +953,7 @@
*/
- PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, int i, PyObject *v);
+ PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);
/*
Assign object v to the ith element of o. Returns
@@ -962,7 +962,7 @@
*/
- PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, int i);
+ PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);
/*
Delete the ith element of object v. Returns
@@ -970,7 +970,7 @@
statement: del o[i].
*/
- PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, int i1, int i2,
+ PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2,
PyObject *v);
/*
@@ -979,7 +979,7 @@
equivalent of the Python statement: o[i1:i2]=v.
*/
- PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, int i1, int i2);
+ PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
/*
Delete the slice in sequence object, o, from i1 to i2.
@@ -1100,7 +1100,7 @@
*/
- PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, int count);
+ PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count);
/*
Repeat o1 by count, in-place when possible. Return the resulting
Modified: python/branches/ssize_t/Include/bufferobject.h
==============================================================================
--- python/branches/ssize_t/Include/bufferobject.h (original)
+++ python/branches/ssize_t/Include/bufferobject.h Sat Dec 17 11:20:15 2005
@@ -17,13 +17,13 @@
#define Py_END_OF_BUFFER (-1)
PyAPI_FUNC(PyObject *) PyBuffer_FromObject(PyObject *base,
- int offset, int size);
+ int offset, Py_ssize_t size);
PyAPI_FUNC(PyObject *) PyBuffer_FromReadWriteObject(PyObject *base,
int offset,
- int size);
+ Py_ssize_t size);
-PyAPI_FUNC(PyObject *) PyBuffer_FromMemory(void *ptr, int size);
-PyAPI_FUNC(PyObject *) PyBuffer_FromReadWriteMemory(void *ptr, int size);
+PyAPI_FUNC(PyObject *) PyBuffer_FromMemory(void *ptr, Py_ssize_t size);
+PyAPI_FUNC(PyObject *) PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size);
PyAPI_FUNC(PyObject *) PyBuffer_New(int size);
Modified: python/branches/ssize_t/Include/cStringIO.h
==============================================================================
--- python/branches/ssize_t/Include/cStringIO.h (original)
+++ python/branches/ssize_t/Include/cStringIO.h Sat Dec 17 11:20:15 2005
@@ -38,7 +38,7 @@
int(*creadline)(PyObject *, char **);
/* Write a string to an output object*/
- int(*cwrite)(PyObject *, const char *, int);
+ int(*cwrite)(PyObject *, const char *, Py_ssize_t);
/* Get the output object as a Python string (returns new reference). */
PyObject *(*cgetvalue)(PyObject *);
Modified: python/branches/ssize_t/Include/ceval.h
==============================================================================
--- python/branches/ssize_t/Include/ceval.h (original)
+++ python/branches/ssize_t/Include/ceval.h Sat Dec 17 11:20:15 2005
@@ -148,7 +148,7 @@
#endif /* !WITH_THREAD */
-PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, int *);
+PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
#ifdef __cplusplus
Modified: python/branches/ssize_t/Include/intobject.h
==============================================================================
--- python/branches/ssize_t/Include/intobject.h (original)
+++ python/branches/ssize_t/Include/intobject.h Sat Dec 17 11:20:15 2005
@@ -35,7 +35,10 @@
PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, int, int);
#endif
PyAPI_FUNC(PyObject *) PyInt_FromLong(long);
+PyAPI_FUNC(PyObject *) PyInt_FromSize_t(size_t);
+PyAPI_FUNC(PyObject *) PyInt_FromSsize_t(Py_ssize_t);
PyAPI_FUNC(long) PyInt_AsLong(PyObject *);
+PyAPI_FUNC(Py_ssize_t) PyInt_AsSsize_t(PyObject *);
PyAPI_FUNC(unsigned long) PyInt_AsUnsignedLongMask(PyObject *);
#ifdef HAVE_LONG_LONG
PyAPI_FUNC(unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *);
Modified: python/branches/ssize_t/Include/listobject.h
==============================================================================
--- python/branches/ssize_t/Include/listobject.h (original)
+++ python/branches/ssize_t/Include/listobject.h Sat Dec 17 11:20:15 2005
@@ -43,14 +43,14 @@
#define PyList_Check(op) PyObject_TypeCheck(op, &PyList_Type)
#define PyList_CheckExact(op) ((op)->ob_type == &PyList_Type)
-PyAPI_FUNC(PyObject *) PyList_New(int size);
-PyAPI_FUNC(int) PyList_Size(PyObject *);
-PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, int);
-PyAPI_FUNC(int) PyList_SetItem(PyObject *, int, PyObject *);
-PyAPI_FUNC(int) PyList_Insert(PyObject *, int, PyObject *);
+PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);
+PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *);
+PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, Py_ssize_t);
+PyAPI_FUNC(int) PyList_SetItem(PyObject *, Py_ssize_t, PyObject *);
+PyAPI_FUNC(int) PyList_Insert(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 *);
Modified: python/branches/ssize_t/Include/longintrepr.h
==============================================================================
--- python/branches/ssize_t/Include/longintrepr.h (original)
+++ python/branches/ssize_t/Include/longintrepr.h Sat Dec 17 11:20:15 2005
@@ -52,7 +52,7 @@
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);
Modified: python/branches/ssize_t/Include/longobject.h
==============================================================================
--- python/branches/ssize_t/Include/longobject.h (original)
+++ python/branches/ssize_t/Include/longobject.h Sat Dec 17 11:20:15 2005
@@ -18,9 +18,14 @@
PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long);
PyAPI_FUNC(PyObject *) PyLong_FromDouble(double);
PyAPI_FUNC(long) PyLong_AsLong(PyObject *);
+PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *);
PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);
PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
+/* For use by intobject.c only */
+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
Modified: python/branches/ssize_t/Include/marshal.h
==============================================================================
--- python/branches/ssize_t/Include/marshal.h (original)
+++ python/branches/ssize_t/Include/marshal.h Sat Dec 17 11:20:15 2005
@@ -17,7 +17,7 @@
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
}
Modified: python/branches/ssize_t/Include/modsupport.h
==============================================================================
--- python/branches/ssize_t/Include/modsupport.h (original)
+++ python/branches/ssize_t/Include/modsupport.h Sat Dec 17 11:20:15 2005
@@ -9,6 +9,18 @@
#include <stdarg.h>
+/* If PY_SIZE_T_CLEAN is defined, each functions treats #-specifier
+ to mean Py_ssize_t */
+#ifdef PY_SIZE_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_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)
Modified: python/branches/ssize_t/Include/object.h
==============================================================================
--- python/branches/ssize_t/Include/object.h (original)
+++ python/branches/ssize_t/Include/object.h Sat Dec 17 11:20:15 2005
@@ -92,7 +92,8 @@
*/
#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
@@ -130,11 +131,15 @@
typedef int (*coercion)(PyObject **, PyObject **);
typedef PyObject *(*intargfunc)(PyObject *, int);
typedef PyObject *(*intintargfunc)(PyObject *, int, int);
+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(*sizeobjargproc)(PyObject *, size_t, PyObject *);
+typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
-typedef int (*getreadbufferproc)(PyObject *, int, void **);
-typedef int (*getwritebufferproc)(PyObject *, int, void **);
+typedef Py_ssize_t (*getreadbufferproc)(PyObject *, int, void **);
+typedef Py_ssize_t (*getwritebufferproc)(PyObject *, int, void **);
typedef int (*getsegcountproc)(PyObject *, int *);
typedef int (*getcharbufferproc)(PyObject *, int, const char **);
typedef int (*objobjproc)(PyObject *, PyObject *);
@@ -197,15 +202,15 @@
typedef struct {
inquiry 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;
+ sizeobjargproc 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 {
@@ -239,7 +244,7 @@
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 +367,7 @@
#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 *);
Modified: python/branches/ssize_t/Include/objimpl.h
==============================================================================
--- python/branches/ssize_t/Include/objimpl.h (original)
+++ python/branches/ssize_t/Include/objimpl.h Sat Dec 17 11:20:15 2005
@@ -146,9 +146,9 @@
/* 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 @@
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 *);
Modified: python/branches/ssize_t/Include/pyerrors.h
==============================================================================
--- python/branches/ssize_t/Include/pyerrors.h (original)
+++ python/branches/ssize_t/Include/pyerrors.h Sat Dec 17 11:20:15 2005
@@ -156,15 +156,15 @@
/* 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 @@
/* 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 value to the start attribute
return 0 on success, -1 on failure */
-PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, int);
-PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, int);
-PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, int);
+PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t);
+PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t);
+PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t);
/* get the value of the end attribute (the int *may not be NULL)
return 0 on success, -1 on failure */
-PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, int *);
-PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, int *);
-PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, int *);
+PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *);
+PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *);
+PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *);
/* assign a new value to the end attribute
return 0 on success, -1 on failure */
-PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, int);
-PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, int);
-PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, int);
+PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t);
+PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t);
+PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t);
/* get the value of the reason attribute */
PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *);
Modified: python/branches/ssize_t/Include/pyport.h
==============================================================================
--- python/branches/ssize_t/Include/pyport.h (original)
+++ python/branches/ssize_t/Include/pyport.h Sat Dec 17 11:20:15 2005
@@ -85,6 +85,15 @@
# error "Python needs a typedef for Py_uintptr_t in pyport.h."
#endif /* HAVE_UINTPTR_T */
+#ifdef HAVE_SSIZE_T
+typedef ssize_t Py_ssize_t;
+#elif SIZEOF_VOID_P == SIZEOF_SIZE_T
+typedef Py_uintptr_t Py_ssize_t;
+#else
+# error "Python needs a typedef for Py_ssize_t in pyport.h."
+#endif
+#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
+
#include <stdlib.h>
#include <math.h> /* Moved here from the math section, before extern "C" */
Modified: python/branches/ssize_t/Include/sliceobject.h
==============================================================================
--- python/branches/ssize_t/Include/sliceobject.h (original)
+++ python/branches/ssize_t/Include/sliceobject.h Sat Dec 17 11:20:15 2005
@@ -30,11 +30,11 @@
PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop,
PyObject* step);
-PyAPI_FUNC(int) PySlice_GetIndices(PySliceObject *r, int length,
- int *start, int *stop, int *step);
-PyAPI_FUNC(int) PySlice_GetIndicesEx(PySliceObject *r, int length,
- int *start, int *stop,
- int *step, int *slicelength);
+PyAPI_FUNC(int) PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
+ Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step);
+PyAPI_FUNC(int) PySlice_GetIndicesEx(PySliceObject *r, Py_ssize_t length,
+ Py_ssize_t *start, Py_ssize_t *stop,
+ Py_ssize_t *step, Py_ssize_t *slicelength);
#ifdef __cplusplus
}
Modified: python/branches/ssize_t/Include/stringobject.h
==============================================================================
--- python/branches/ssize_t/Include/stringobject.h (original)
+++ python/branches/ssize_t/Include/stringobject.h Sat Dec 17 11:20:15 2005
@@ -58,7 +58,7 @@
#define PyString_Check(op) PyObject_TypeCheck(op, &PyString_Type)
#define PyString_CheckExact(op) ((op)->ob_type == &PyString_Type)
-PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, int);
+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)));
@@ -69,13 +69,13 @@
PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);
PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);
PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);
-PyAPI_FUNC(int) _PyString_Resize(PyObject **, int);
+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 *, int,
- const 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 **);
Modified: python/branches/ssize_t/Include/tupleobject.h
==============================================================================
--- python/branches/ssize_t/Include/tupleobject.h (original)
+++ python/branches/ssize_t/Include/tupleobject.h Sat Dec 17 11:20:15 2005
@@ -36,11 +36,11 @@
#define PyTuple_Check(op) PyObject_TypeCheck(op, &PyTuple_Type)
#define PyTuple_CheckExact(op) ((op)->ob_type == &PyTuple_Type)
-PyAPI_FUNC(PyObject *) PyTuple_New(int size);
-PyAPI_FUNC(int) PyTuple_Size(PyObject *);
-PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, int);
-PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, int, PyObject *);
-PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, int, int);
+PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size);
+PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *);
+PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, Py_ssize_t);
+PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *);
+PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, int);
PyAPI_FUNC(PyObject *) PyTuple_Pack(int, ...);
Modified: python/branches/ssize_t/Include/unicodeobject.h
==============================================================================
--- python/branches/ssize_t/Include/unicodeobject.h (original)
+++ python/branches/ssize_t/Include/unicodeobject.h Sat Dec 17 11:20:15 2005
@@ -420,7 +420,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(
const Py_UNICODE *u, /* Unicode buffer */
- int size /* size of buffer */
+ Py_ssize_t size /* size of buffer */
);
/* Return a read-only pointer to the Unicode object's internal
@@ -455,7 +455,7 @@
PyAPI_FUNC(int) PyUnicode_Resize(
PyObject **unicode, /* Pointer to the Unicode object */
- int length /* New length */
+ Py_ssize_t length /* New length */
);
/* Coerce obj to an Unicode object and return a reference with
@@ -509,7 +509,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_FromWideChar(
register const wchar_t *w, /* wchar_t buffer */
- int size /* size of buffer */
+ Py_ssize_t size /* size of buffer */
);
/* Copies the Unicode Object contents into the wchar_t buffer w. At
@@ -609,7 +609,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_Decode(
const char *s, /* encoded string */
- int size, /* size of buffer */
+ Py_ssize_t size, /* size of buffer */
const char *encoding, /* encoding */
const char *errors /* error handling */
);
@@ -619,7 +619,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_Encode(
const Py_UNICODE *s, /* Unicode char buffer */
- int size, /* number of Py_UNICODE chars to encode */
+ Py_ssize_t size, /* number of Py_UNICODE chars to encode */
const char *encoding, /* encoding */
const char *errors /* error handling */
);
@@ -646,13 +646,13 @@
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7(
const char *string, /* UTF-7 encoded string */
- int length, /* size of string */
+ Py_ssize_t length, /* size of string */
const char *errors /* error handling */
);
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7(
const Py_UNICODE *data, /* Unicode char buffer */
- int length, /* number of Py_UNICODE chars to encode */
+ 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,
@@ -664,15 +664,15 @@
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8(
const char *string, /* UTF-8 encoded string */
- int length, /* size of string */
+ Py_ssize_t length, /* size of string */
const char *errors /* error handling */
);
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8Stateful(
const char *string, /* UTF-8 encoded string */
- int length, /* size of string */
+ Py_ssize_t length, /* size of string */
const char *errors, /* error handling */
- int *consumed /* bytes consumed */
+ Py_ssize_t *consumed /* bytes consumed */
);
PyAPI_FUNC(PyObject*) PyUnicode_AsUTF8String(
@@ -681,7 +681,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF8(
const Py_UNICODE *data, /* Unicode char buffer */
- int length, /* number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* number of Py_UNICODE chars to encode */
const char *errors /* error handling */
);
@@ -712,7 +712,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16(
const char *string, /* UTF-16 encoded string */
- int length, /* size of string */
+ Py_ssize_t length, /* size of string */
const char *errors, /* error handling */
int *byteorder /* pointer to byteorder to use
0=native;-1=LE,1=BE; updated on
@@ -721,12 +721,12 @@
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16Stateful(
const char *string, /* UTF-16 encoded string */
- int length, /* size of string */
+ Py_ssize_t length, /* size of string */
const char *errors, /* error handling */
int *byteorder, /* pointer to byteorder to use
0=native;-1=LE,1=BE; updated on
exit */
- int *consumed /* bytes consumed */
+ Py_ssize_t *consumed /* bytes consumed */
);
/* Returns a Python string using the UTF-16 encoding in native byte
@@ -758,7 +758,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF16(
const Py_UNICODE *data, /* Unicode char buffer */
- int length, /* number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* number of Py_UNICODE chars to encode */
const char *errors, /* error handling */
int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */
);
@@ -767,7 +767,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUnicodeEscape(
const char *string, /* Unicode-Escape encoded string */
- int length, /* size of string */
+ Py_ssize_t length, /* size of string */
const char *errors /* error handling */
);
@@ -777,14 +777,14 @@
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUnicodeEscape(
const Py_UNICODE *data, /* Unicode char buffer */
- int length /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length /* Number of Py_UNICODE chars to encode */
);
/* --- Raw-Unicode-Escape Codecs ------------------------------------------ */
PyAPI_FUNC(PyObject*) PyUnicode_DecodeRawUnicodeEscape(
const char *string, /* Raw-Unicode-Escape encoded string */
- int length, /* size of string */
+ Py_ssize_t length, /* size of string */
const char *errors /* error handling */
);
@@ -794,7 +794,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_EncodeRawUnicodeEscape(
const Py_UNICODE *data, /* Unicode char buffer */
- int length /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length /* Number of Py_UNICODE chars to encode */
);
/* --- Unicode Internal Codec ---------------------------------------------
@@ -803,7 +803,7 @@
PyObject *_PyUnicode_DecodeUnicodeInternal(
const char *string,
- int length,
+ Py_ssize_t length,
const char *errors
);
@@ -815,7 +815,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_DecodeLatin1(
const char *string, /* Latin-1 encoded string */
- int length, /* size of string */
+ Py_ssize_t length, /* size of string */
const char *errors /* error handling */
);
@@ -825,7 +825,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_EncodeLatin1(
const Py_UNICODE *data, /* Unicode char buffer */
- int length, /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
const char *errors /* error handling */
);
@@ -837,7 +837,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_DecodeASCII(
const char *string, /* ASCII encoded string */
- int length, /* size of string */
+ Py_ssize_t length, /* size of string */
const char *errors /* error handling */
);
@@ -847,7 +847,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_EncodeASCII(
const Py_UNICODE *data, /* Unicode char buffer */
- int length, /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
const char *errors /* error handling */
);
@@ -875,7 +875,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_DecodeCharmap(
const char *string, /* Encoded string */
- int length, /* size of string */
+ Py_ssize_t length, /* size of string */
PyObject *mapping, /* character mapping
(char ordinal -> unicode ordinal) */
const char *errors /* error handling */
@@ -889,7 +889,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_EncodeCharmap(
const Py_UNICODE *data, /* Unicode char buffer */
- int length, /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
PyObject *mapping, /* character mapping
(unicode ordinal -> char ordinal) */
const char *errors /* error handling */
@@ -910,7 +910,7 @@
PyAPI_FUNC(PyObject *) PyUnicode_TranslateCharmap(
const Py_UNICODE *data, /* Unicode char buffer */
- int length, /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
PyObject *table, /* Translate table */
const char *errors /* error handling */
);
@@ -921,7 +921,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCS(
const char *string, /* MBCS encoded string */
- int length, /* size of string */
+ Py_ssize_t length, /* size of string */
const char *errors /* error handling */
);
@@ -931,7 +931,7 @@
PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS(
const Py_UNICODE *data, /* Unicode char buffer */
- int length, /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
const char *errors /* error handling */
);
@@ -963,7 +963,7 @@
PyAPI_FUNC(int) PyUnicode_EncodeDecimal(
Py_UNICODE *s, /* Unicode buffer */
- int length, /* Number of Py_UNICODE chars to encode */
+ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
char *output, /* Output buffer; must have size >= length */
const char *errors /* error handling */
);
Modified: python/branches/ssize_t/Modules/_codecsmodule.c
==============================================================================
--- python/branches/ssize_t/Modules/_codecsmodule.c (original)
+++ python/branches/ssize_t/Modules/_codecsmodule.c Sat Dec 17 11:20:15 2005
@@ -35,6 +35,7 @@
------------------------------------------------------------------------ */
+#define PY_SIZE_T_CLEAN
#include "Python.h"
/* --- Registry ----------------------------------------------------------- */
@@ -196,7 +197,7 @@
{
const char *errors = NULL;
const char *data;
- int size;
+ Py_ssize_t size;
if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
&data, &size, &errors))
@@ -284,12 +285,16 @@
int size;
const char *errors = NULL;
int final = 0;
- int consumed;
+ Py_ssize_t consumed;
PyObject *decoded = NULL;
if (!PyArg_ParseTuple(args, "t#|zi:utf_8_decode",
&data, &size, &errors, &final))
return NULL;
+ if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative argument");
+ return 0;
+ }
consumed = size;
decoded = PyUnicode_DecodeUTF8Stateful(data, size, errors,
@@ -308,12 +313,17 @@
const char *errors = NULL;
int byteorder = 0;
int final = 0;
- int consumed;
+ Py_ssize_t consumed;
PyObject *decoded;
if (!PyArg_ParseTuple(args, "t#|zi:utf_16_decode",
&data, &size, &errors, &final))
return NULL;
+ /* XXX Why is consumed initialized to size? mvl */
+ if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative argument");
+ return 0;
+ }
consumed = size;
decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
final ? NULL : &consumed);
@@ -331,12 +341,18 @@
const char *errors = NULL;
int byteorder = -1;
int final = 0;
- int consumed;
+ Py_ssize_t consumed;
PyObject *decoded = NULL;
if (!PyArg_ParseTuple(args, "t#|zi:utf_16_le_decode",
&data, &size, &errors, &final))
return NULL;
+
+ /* XXX Why is consumed initialized to size? mvl */
+ if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative argument");
+ return 0;
+ }
consumed = size;
decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
&byteorder, final ? NULL : &consumed);
@@ -355,12 +371,17 @@
const char *errors = NULL;
int byteorder = 1;
int final = 0;
- int consumed;
+ Py_ssize_t consumed;
PyObject *decoded = NULL;
if (!PyArg_ParseTuple(args, "t#|zi:utf_16_be_decode",
&data, &size, &errors, &final))
return NULL;
+ /* XXX Why is consumed initialized to size? mvl */
+ if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative argument");
+ return 0;
+ }
consumed = size;
decoded = PyUnicode_DecodeUTF16Stateful(data, size, errors,
&byteorder, final ? NULL : &consumed);
@@ -387,12 +408,16 @@
int byteorder = 0;
PyObject *unicode, *tuple;
int final = 0;
- int consumed;
+ Py_ssize_t consumed;
if (!PyArg_ParseTuple(args, "t#|zii:utf_16_ex_decode",
&data, &size, &errors, &byteorder, &final))
return NULL;
-
+ /* XXX Why is consumed initialized to size? mvl */
+ if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative argument");
+ return 0;
+ }
consumed = size;
unicode = PyUnicode_DecodeUTF16Stateful(data, size, errors, &byteorder,
final ? NULL : &consumed);
@@ -513,7 +538,7 @@
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "s#|z:readbuffer_encode",
Modified: python/branches/ssize_t/Modules/_hotshot.c
==============================================================================
--- python/branches/ssize_t/Modules/_hotshot.c (original)
+++ python/branches/ssize_t/Modules/_hotshot.c Sat Dec 17 11:20:15 2005
@@ -71,7 +71,7 @@
PyObject_HEAD
PyObject *filemap;
PyObject *logfilename;
- int index;
+ Py_ssize_t index;
unsigned char buffer[BUFFERSIZE];
FILE *logfp;
int lineevents;
@@ -526,7 +526,7 @@
}
static PyObject *
-logreader_sq_item(LogReaderObject *self, int index)
+logreader_sq_item(LogReaderObject *self, Py_ssize_t index)
{
PyObject *result = logreader_tp_iternext(self);
if (result == NULL && !PyErr_Occurred()) {
@@ -610,13 +610,14 @@
}
static int
-pack_string(ProfilerObject *self, const char *s, int len)
+pack_string(ProfilerObject *self, const char *s, Py_ssize_t len)
{
if (len + PISIZE + self->index >= BUFFERSIZE) {
if (flush_data(self) < 0)
return -1;
}
- if (pack_packed_int(self, len) < 0)
+ assert(len < INT_MAX);
+ if (pack_packed_int(self, (int)len) < 0)
return -1;
memcpy(self->buffer + self->index, s, len);
self->index += len;
@@ -626,8 +627,8 @@
static int
pack_add_info(ProfilerObject *self, const char *s1, const char *s2)
{
- int len1 = strlen(s1);
- int len2 = strlen(s2);
+ Py_ssize_t len1 = strlen(s1);
+ Py_ssize_t len2 = strlen(s2);
if (len1 + len2 + PISIZE*2 + 1 + self->index >= BUFFERSIZE) {
if (flush_data(self) < 0)
@@ -643,7 +644,7 @@
static int
pack_define_file(ProfilerObject *self, int fileno, const char *filename)
{
- int len = strlen(filename);
+ Py_ssize_t len = strlen(filename);
if (len + PISIZE*2 + 1 + self->index >= BUFFERSIZE) {
if (flush_data(self) < 0)
@@ -660,7 +661,7 @@
pack_define_func(ProfilerObject *self, int fileno, int lineno,
const char *funcname)
{
- int len = strlen(funcname);
+ Py_ssize_t len = strlen(funcname);
if (len + PISIZE*3 + 1 + self->index >= BUFFERSIZE) {
if (flush_data(self) < 0)
@@ -1269,7 +1270,7 @@
0, /* sq_length */
0, /* sq_concat */
0, /* sq_repeat */
- (intargfunc)logreader_sq_item, /* sq_item */
+ (ssizeargfunc)logreader_sq_item, /* sq_item */
0, /* sq_slice */
0, /* sq_ass_item */
0, /* sq_ass_slice */
Modified: python/branches/ssize_t/Modules/_localemodule.c
==============================================================================
--- python/branches/ssize_t/Modules/_localemodule.c (original)
+++ python/branches/ssize_t/Modules/_localemodule.c Sat Dec 17 11:20:15 2005
@@ -382,11 +382,11 @@
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SISO639LANGNAME,
locale, sizeof(locale))) {
- int i = strlen(locale);
+ Py_ssize_t i = strlen(locale);
locale[i++] = '_';
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
LOCALE_SISO3166CTRYNAME,
- locale+i, sizeof(locale)-i))
+ locale+i, (int)(sizeof(locale)-i)))
return Py_BuildValue("ss", locale, encoding);
}
Modified: python/branches/ssize_t/Modules/arraymodule.c
==============================================================================
--- python/branches/ssize_t/Modules/arraymodule.c (original)
+++ python/branches/ssize_t/Modules/arraymodule.c Sat Dec 17 11:20:15 2005
@@ -3,6 +3,7 @@
/* An array is a uniform list -- all items have the same type.
The item type is restricted to simple C types like int or float */
+#define PY_SIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
@@ -23,15 +24,15 @@
struct arraydescr {
int typecode;
int itemsize;
- PyObject * (*getitem)(struct arrayobject *, int);
- int (*setitem)(struct arrayobject *, int, PyObject *);
+ PyObject * (*getitem)(struct arrayobject *, Py_ssize_t);
+ int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *);
};
typedef struct arrayobject {
PyObject_HEAD
- int ob_size;
+ Py_ssize_t ob_size;
char *ob_item;
- int allocated;
+ Py_ssize_t allocated;
struct arraydescr *ob_descr;
PyObject *weakreflist; /* List of weak references */
} arrayobject;
@@ -42,7 +43,7 @@
#define array_CheckExact(op) ((op)->ob_type == &Arraytype)
static int
-array_resize(arrayobject *self, int newsize)
+array_resize(arrayobject *self, Py_ssize_t newsize)
{
char *items;
size_t _new_size;
@@ -102,13 +103,13 @@
****************************************************************************/
static PyObject *
-c_getitem(arrayobject *ap, int i)
+c_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyString_FromStringAndSize(&((char *)ap->ob_item)[i], 1);
}
static int
-c_setitem(arrayobject *ap, int i, PyObject *v)
+c_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
char x;
if (!PyArg_Parse(v, "c;array item must be char", &x))
@@ -119,7 +120,7 @@
}
static PyObject *
-b_getitem(arrayobject *ap, int i)
+b_getitem(arrayobject *ap, Py_ssize_t i)
{
long x = ((char *)ap->ob_item)[i];
if (x >= 128)
@@ -128,7 +129,7 @@
}
static int
-b_setitem(arrayobject *ap, int i, PyObject *v)
+b_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
short x;
/* PyArg_Parse's 'b' formatter is for an unsigned char, therefore
@@ -152,14 +153,14 @@
}
static PyObject *
-BB_getitem(arrayobject *ap, int i)
+BB_getitem(arrayobject *ap, Py_ssize_t i)
{
long x = ((unsigned char *)ap->ob_item)[i];
return PyInt_FromLong(x);
}
static int
-BB_setitem(arrayobject *ap, int i, PyObject *v)
+BB_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
unsigned char x;
/* 'B' == unsigned char, maps to PyArg_Parse's 'b' formatter */
@@ -172,16 +173,16 @@
#ifdef Py_USING_UNICODE
static PyObject *
-u_getitem(arrayobject *ap, int i)
+u_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyUnicode_FromUnicode(&((Py_UNICODE *) ap->ob_item)[i], 1);
}
static int
-u_setitem(arrayobject *ap, int i, PyObject *v)
+u_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
Py_UNICODE *p;
- int len;
+ Py_ssize_t len;
if (!PyArg_Parse(v, "u#;array item must be unicode character", &p, &len))
return -1;
@@ -196,13 +197,13 @@
#endif
static PyObject *
-h_getitem(arrayobject *ap, int i)
+h_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyInt_FromLong((long) ((short *)ap->ob_item)[i]);
}
static int
-h_setitem(arrayobject *ap, int i, PyObject *v)
+h_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
short x;
/* 'h' == signed short, maps to PyArg_Parse's 'h' formatter */
@@ -214,13 +215,13 @@
}
static PyObject *
-HH_getitem(arrayobject *ap, int i)
+HH_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyInt_FromLong((long) ((unsigned short *)ap->ob_item)[i]);
}
static int
-HH_setitem(arrayobject *ap, int i, PyObject *v)
+HH_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
int x;
/* PyArg_Parse's 'h' formatter is for a signed short, therefore
@@ -243,13 +244,13 @@
}
static PyObject *
-i_getitem(arrayobject *ap, int i)
+i_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyInt_FromLong((long) ((int *)ap->ob_item)[i]);
}
static int
-i_setitem(arrayobject *ap, int i, PyObject *v)
+i_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
int x;
/* 'i' == signed int, maps to PyArg_Parse's 'i' formatter */
@@ -261,14 +262,14 @@
}
static PyObject *
-II_getitem(arrayobject *ap, int i)
+II_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyLong_FromUnsignedLong(
(unsigned long) ((unsigned int *)ap->ob_item)[i]);
}
static int
-II_setitem(arrayobject *ap, int i, PyObject *v)
+II_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
unsigned long x;
if (PyLong_Check(v)) {
@@ -300,13 +301,13 @@
}
static PyObject *
-l_getitem(arrayobject *ap, int i)
+l_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyInt_FromLong(((long *)ap->ob_item)[i]);
}
static int
-l_setitem(arrayobject *ap, int i, PyObject *v)
+l_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
long x;
if (!PyArg_Parse(v, "l;array item must be integer", &x))
@@ -317,13 +318,13 @@
}
static PyObject *
-LL_getitem(arrayobject *ap, int i)
+LL_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyLong_FromUnsignedLong(((unsigned long *)ap->ob_item)[i]);
}
static int
-LL_setitem(arrayobject *ap, int i, PyObject *v)
+LL_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
unsigned long x;
if (PyLong_Check(v)) {
@@ -355,13 +356,13 @@
}
static PyObject *
-f_getitem(arrayobject *ap, int i)
+f_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyFloat_FromDouble((double) ((float *)ap->ob_item)[i]);
}
static int
-f_setitem(arrayobject *ap, int i, PyObject *v)
+f_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
float x;
if (!PyArg_Parse(v, "f;array item must be float", &x))
@@ -372,13 +373,13 @@
}
static PyObject *
-d_getitem(arrayobject *ap, int i)
+d_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyFloat_FromDouble(((double *)ap->ob_item)[i]);
}
static int
-d_setitem(arrayobject *ap, int i, PyObject *v)
+d_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
double x;
if (!PyArg_Parse(v, "d;array item must be float", &x))
@@ -412,7 +413,7 @@
****************************************************************************/
static PyObject *
-newarrayobject(PyTypeObject *type, int size, struct arraydescr *descr)
+newarrayobject(PyTypeObject *type, Py_ssize_t size, struct arraydescr *descr)
{
arrayobject *op;
size_t nbytes;
@@ -449,7 +450,7 @@
}
static PyObject *
-getarrayitem(PyObject *op, int i)
+getarrayitem(PyObject *op, Py_ssize_t i)
{
register arrayobject *ap;
assert(array_Check(op));
@@ -459,10 +460,10 @@
}
static int
-ins1(arrayobject *self, int where, PyObject *v)
+ins1(arrayobject *self, Py_ssize_t where, PyObject *v)
{
char *items;
- int n = self->ob_size;
+ Py_ssize_t n = self->ob_size;
if (v == NULL) {
PyErr_BadInternalCall();
return -1;
@@ -506,7 +507,7 @@
arrayobject *va, *wa;
PyObject *vi = NULL;
PyObject *wi = NULL;
- int i, k;
+ Py_ssize_t i, k;
PyObject *res;
if (!array_Check(v) || !array_Check(w)) {
@@ -548,8 +549,8 @@
if (k) {
/* No more items to compare -- compare sizes */
- int vs = va->ob_size;
- int ws = wa->ob_size;
+ Py_ssize_t vs = va->ob_size;
+ Py_ssize_t ws = wa->ob_size;
int cmp;
switch (op) {
case Py_LT: cmp = vs < ws; break;
@@ -586,14 +587,14 @@
return res;
}
-static int
+static Py_ssize_t
array_length(arrayobject *a)
{
return a->ob_size;
}
static PyObject *
-array_item(arrayobject *a, int i)
+array_item(arrayobject *a, Py_ssize_t i)
{
if (i < 0 || i >= a->ob_size) {
PyErr_SetString(PyExc_IndexError, "array index out of range");
@@ -603,7 +604,7 @@
}
static PyObject *
-array_slice(arrayobject *a, int ilow, int ihigh)
+array_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
{
arrayobject *np;
if (ilow < 0)
@@ -638,7 +639,7 @@
static PyObject *
array_concat(arrayobject *a, PyObject *bb)
{
- int size;
+ Py_ssize_t size;
arrayobject *np;
if (!array_Check(bb)) {
PyErr_Format(PyExc_TypeError,
@@ -664,13 +665,13 @@
}
static PyObject *
-array_repeat(arrayobject *a, int n)
+array_repeat(arrayobject *a, Py_ssize_t n)
{
- int i;
- int size;
+ Py_ssize_t i;
+ Py_ssize_t size;
arrayobject *np;
char *p;
- int nbytes;
+ Py_ssize_t nbytes;
if (n < 0)
n = 0;
size = a->ob_size * n;
@@ -759,8 +760,9 @@
#undef b
}
+/* XXX should be ssize_t */
static int
-array_ass_item(arrayobject *a, int i, PyObject *v)
+array_ass_item(arrayobject *a, size_t i, PyObject *v)
{
if (i < 0 || i >= a->ob_size) {
PyErr_SetString(PyExc_IndexError,
@@ -773,7 +775,7 @@
}
static int
-setarrayitem(PyObject *a, int i, PyObject *v)
+setarrayitem(PyObject *a, Py_ssize_t i, PyObject *v)
{
assert(array_Check(a));
return array_ass_item((arrayobject *)a, i, v);
@@ -805,7 +807,7 @@
static int
array_do_extend(arrayobject *self, PyObject *bb)
{
- int size;
+ Py_ssize_t size;
if (!array_Check(bb))
return array_iter_extend(self, bb);
@@ -847,10 +849,10 @@
}
static PyObject *
-array_inplace_repeat(arrayobject *self, int n)
+array_inplace_repeat(arrayobject *self, Py_ssize_t n)
{
char *items, *p;
- int size, i;
+ Py_ssize_t size, i;
if (self->ob_size > 0) {
if (n < 0)
@@ -883,7 +885,7 @@
static PyObject *
-ins(arrayobject *self, int where, PyObject *v)
+ins(arrayobject *self, Py_ssize_t where, PyObject *v)
{
if (ins1(self, where, v) != 0)
return NULL;
@@ -894,8 +896,8 @@
static PyObject *
array_count(arrayobject *self, PyObject *v)
{
- int count = 0;
- int i;
+ Py_ssize_t count = 0;
+ Py_ssize_t i;
for (i = 0; i < self->ob_size; i++) {
PyObject *selfi = getarrayitem((PyObject *)self, i);
@@ -906,7 +908,10 @@
else if (cmp < 0)
return NULL;
}
- return PyInt_FromLong((long)count);
+ if (i < LONG_MAX)
+ return PyInt_FromLong((long)count);
+ else
+ return PyLong_FromLong(count);
}
PyDoc_STRVAR(count_doc,
@@ -917,7 +922,7 @@
static PyObject *
array_index(arrayobject *self, PyObject *v)
{
- int i;
+ Py_ssize_t i;
for (i = 0; i < self->ob_size; i++) {
PyObject *selfi = getarrayitem((PyObject *)self, i);
@@ -941,7 +946,8 @@
static int
array_contains(arrayobject *self, PyObject *v)
{
- int i, cmp;
+ Py_ssize_t i;
+ int cmp;
for (i = 0, cmp = 0 ; cmp == 0 && i < self->ob_size; i++) {
PyObject *selfi = getarrayitem((PyObject *)self, i);
@@ -1079,7 +1085,7 @@
array_byteswap(arrayobject *self, PyObject *unused)
{
char *p;
- int i;
+ Py_ssize_t i;
switch (self->ob_descr->itemsize) {
case 1:
@@ -1158,7 +1164,7 @@
static PyObject *
array_reverse(arrayobject *self, PyObject *unused)
{
- register int itemsize = self->ob_descr->itemsize;
+ register Py_ssize_t itemsize = self->ob_descr->itemsize;
register char *p, *q;
/* little buffer to hold items while swapping */
char tmp[256]; /* 8 is probably enough -- but why skimp */
@@ -1223,7 +1229,7 @@
nread = fread(item + (self->ob_size - n) * itemsize,
itemsize, n, fp);
if (nread < (size_t)n) {
- self->ob_size -= (n - nread);
+ self->ob_size -= (n - nread);
PyMem_RESIZE(item, char, self->ob_size*itemsize);
self->ob_item = item;
self->allocated = self->ob_size;
@@ -1275,8 +1281,8 @@
static PyObject *
array_fromlist(arrayobject *self, PyObject *list)
{
- int n;
- int itemsize = self->ob_descr->itemsize;
+ Py_ssize_t n;
+ Py_ssize_t itemsize = self->ob_descr->itemsize;
if (!PyList_Check(list)) {
PyErr_SetString(PyExc_TypeError, "arg must be list");
@@ -1285,7 +1291,7 @@
n = PyList_Size(list);
if (n > 0) {
char *item = self->ob_item;
- int i;
+ Py_ssize_t i;
PyMem_RESIZE(item, char, (self->ob_size + n) * itemsize);
if (item == NULL) {
PyErr_NoMemory();
@@ -1321,7 +1327,7 @@
array_tolist(arrayobject *self, PyObject *unused)
{
PyObject *list = PyList_New(self->ob_size);
- int i;
+ Py_ssize_t i;
if (list == NULL)
return NULL;
@@ -1346,7 +1352,7 @@
array_fromstring(arrayobject *self, PyObject *args)
{
char *str;
- int n;
+ Py_ssize_t n;
int itemsize = self->ob_descr->itemsize;
if (!PyArg_ParseTuple(args, "s#:fromstring", &str, &n))
return NULL;
@@ -1400,7 +1406,7 @@
array_fromunicode(arrayobject *self, PyObject *args)
{
Py_UNICODE *ustr;
- int n;
+ Py_ssize_t n;
if (!PyArg_ParseTuple(args, "u#:fromunicode", &ustr, &n))
return NULL;
@@ -1541,7 +1547,7 @@
{
char buf[256], typecode;
PyObject *s, *t, *v = NULL;
- int len;
+ Py_ssize_t len;
len = a->ob_size;
typecode = a->ob_descr->typecode;
@@ -1586,7 +1592,7 @@
return array_item(self, i);
}
else if (PySlice_Check(item)) {
- int start, stop, step, slicelength, cur, i;
+ Py_ssize_t start, stop, step, slicelength, cur, i;
PyObject* result;
arrayobject* ar;
int itemsize = self->ob_descr->itemsize;
@@ -1640,7 +1646,7 @@
return array_ass_item(self, i, value);
}
else if (PySlice_Check(item)) {
- int start, stop, step, slicelength;
+ Py_ssize_t start, stop, step, slicelength;
int itemsize = self->ob_descr->itemsize;
if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size,
@@ -1654,7 +1660,7 @@
if (value == NULL) {
/* delete slice */
- int cur, i, extra;
+ Py_ssize_t cur, i, extra;
if (slicelength <= 0)
return 0;
@@ -1686,7 +1692,7 @@
}
else {
/* assign slice */
- int cur, i;
+ Py_ssize_t cur, i;
arrayobject* av;
if (!array_Check(value)) {
@@ -1743,7 +1749,7 @@
};
static int
-array_buffer_getreadbuf(arrayobject *self, int index, const void **ptr)
+array_buffer_getreadbuf(arrayobject *self, Py_ssize_t index, const void **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
@@ -1755,7 +1761,7 @@
}
static int
-array_buffer_getwritebuf(arrayobject *self, int index, const void **ptr)
+array_buffer_getwritebuf(arrayobject *self, Py_ssize_t index, const void **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
@@ -1767,7 +1773,7 @@
}
static int
-array_buffer_getsegcount(arrayobject *self, int *lenp)
+array_buffer_getsegcount(arrayobject *self, Py_ssize_t *lenp)
{
if ( lenp )
*lenp = self->ob_size*self->ob_descr->itemsize;
@@ -1777,14 +1783,14 @@
static PySequenceMethods array_as_sequence = {
(inquiry)array_length, /*sq_length*/
(binaryfunc)array_concat, /*sq_concat*/
- (intargfunc)array_repeat, /*sq_repeat*/
- (intargfunc)array_item, /*sq_item*/
- (intintargfunc)array_slice, /*sq_slice*/
- (intobjargproc)array_ass_item, /*sq_ass_item*/
- (intintobjargproc)array_ass_slice, /*sq_ass_slice*/
+ (ssizeargfunc)array_repeat, /*sq_repeat*/
+ (ssizeargfunc)array_item, /*sq_item*/
+ (ssizessizeargfunc)array_slice, /*sq_slice*/
+ (sizeobjargproc)array_ass_item, /*sq_ass_item*/
+ (ssizessizeobjargproc)array_ass_slice, /*sq_ass_slice*/
(objobjproc)array_contains, /*sq_contains*/
(binaryfunc)array_inplace_concat, /*sq_inplace_concat*/
- (intargfunc)array_inplace_repeat /*sq_inplace_repeat*/
+ (ssizeargfunc)array_inplace_repeat /*sq_inplace_repeat*/
};
static PyBufferProcs array_as_buffer = {
@@ -1822,7 +1828,7 @@
for (descr = descriptors; descr->typecode != '\0'; descr++) {
if (descr->typecode == c) {
PyObject *a;
- int len;
+ Py_ssize_t len;
if (initial == NULL || !(PyList_Check(initial)
|| PyTuple_Check(initial)))
@@ -1835,7 +1841,7 @@
return NULL;
if (len > 0) {
- int i;
+ Py_ssize_t i;
for (i = 0; i < len; i++) {
PyObject *v =
PySequence_GetItem(initial, i);
@@ -1864,7 +1870,7 @@
Py_DECREF(v);
#ifdef Py_USING_UNICODE
} else if (initial != NULL && PyUnicode_Check(initial)) {
- int n = PyUnicode_GET_DATA_SIZE(initial);
+ Py_ssize_t n = PyUnicode_GET_DATA_SIZE(initial);
if (n > 0) {
arrayobject *self = (arrayobject *)a;
char *item = self->ob_item;
@@ -2012,9 +2018,9 @@
typedef struct {
PyObject_HEAD
- long index;
+ Py_ssize_t index;
arrayobject *ao;
- PyObject * (*getitem)(struct arrayobject *, int);
+ PyObject * (*getitem)(struct arrayobject *, Py_ssize_t);
} arrayiterobject;
static PyTypeObject PyArrayIter_Type;
Modified: python/branches/ssize_t/Modules/audioop.c
==============================================================================
--- python/branches/ssize_t/Modules/audioop.c (original)
+++ python/branches/ssize_t/Modules/audioop.c Sat Dec 17 11:20:15 2005
@@ -1020,7 +1020,9 @@
cur_i[chan]));
if (PyErr_Occurred())
goto exit;
- len = ncp - PyString_AsString(str);
+ /* We have checked before that the length
+ * of the string fits into int. */
+ len = (int)(ncp - PyString_AsString(str));
if (len == 0) {
/*don't want to resize to zero length*/
rv = PyString_FromStringAndSize("", 0);
Modified: python/branches/ssize_t/Modules/cPickle.c
==============================================================================
--- python/branches/ssize_t/Modules/cPickle.c (original)
+++ python/branches/ssize_t/Modules/cPickle.c Sat Dec 17 11:20:15 2005
@@ -339,7 +339,7 @@
int fast; /* Fast mode doesn't save in memo, don't use if circ ref */
int nesting;
- int (*write_func)(struct Picklerobject *, const char *, int);
+ int (*write_func)(struct Picklerobject *, const char *, Py_ssize_t);
char *write_buf;
int buf_size;
PyObject *dispatch_table;
@@ -417,7 +417,7 @@
}
static int
-write_file(Picklerobject *self, const char *s, int n)
+write_file(Picklerobject *self, const char *s, Py_ssize_t n)
{
size_t nbyteswritten;
@@ -425,6 +425,11 @@
return 0;
}
+ if (n > INT_MAX) {
+ /* String too large */
+ return -1;
+ }
+
Py_BEGIN_ALLOW_THREADS
nbyteswritten = fwrite(s, sizeof(char), n, self->fp);
Py_END_ALLOW_THREADS
@@ -433,11 +438,11 @@
return -1;
}
- return n;
+ return (int)n;
}
static int
-write_cStringIO(Picklerobject *self, const char *s, int n)
+write_cStringIO(Picklerobject *self, const char *s, Py_ssize_t n)
{
if (s == NULL) {
return 0;
@@ -447,21 +452,26 @@
return -1;
}
- return n;
+ return (int)n;
}
static int
-write_none(Picklerobject *self, const char *s, int n)
+write_none(Picklerobject *self, const char *s, Py_ssize_t n)
{
if (s == NULL) return 0;
- return n;
+ if (n > INT_MAX) return -1;
+ return (int)n;
}
static int
-write_other(Picklerobject *self, const char *s, int n)
+write_other(Picklerobject *self, const char *s, Py_ssize_t _n)
{
PyObject *py_str = 0, *junk = 0;
+ int n;
+ if (_n > INT_MAX)
+ return -1;
+ n = (int)_n;
if (s == NULL) {
if (!( self->buf_size )) return 0;
py_str = PyString_FromStringAndSize(self->write_buf,
Modified: python/branches/ssize_t/Modules/cStringIO.c
==============================================================================
--- python/branches/ssize_t/Modules/cStringIO.c (original)
+++ python/branches/ssize_t/Modules/cStringIO.c Sat Dec 17 11:20:15 2005
@@ -57,9 +57,10 @@
typedef struct { /* Subtype of IOobject */
PyObject_HEAD
char *buf;
- int pos, string_size;
+ Py_ssize_t pos, string_size;
- int buf_size, softspace;
+ Py_ssize_t buf_size;
+ int softspace;
} Oobject;
/* Declarations for objects of type StringI */
@@ -186,7 +187,7 @@
static int
IO_creadline(PyObject *self, char **output) {
char *n, *s;
- int l;
+ Py_ssize_t l;
UNLESS (IO__opencheck(IOOOBJECT(self))) return -1;
@@ -197,8 +198,9 @@
*output=((IOobject*)self)->buf + ((IOobject*)self)->pos;
l = n - ((IOobject*)self)->buf - ((IOobject*)self)->pos;
- ((IOobject*)self)->pos += l;
- return l;
+ assert(((IOobject*)self)->pos + l < INT_MAX);
+ ((IOobject*)self)->pos += (int)l;
+ return (int)l;
}
static PyObject *
@@ -324,11 +326,14 @@
static PyObject *
O_seek(Oobject *self, PyObject *args) {
- int position, mode = 0;
+ int i_position;
+ Py_ssize_t position;
+ int mode = 0;
UNLESS (IO__opencheck(IOOOBJECT(self))) return NULL;
- UNLESS (PyArg_ParseTuple(args, "i|i:seek", &position, &mode))
+ UNLESS (PyArg_ParseTuple(args, "i|i:seek", &i_position, &mode))
return NULL;
+ position = i_position;
if (mode == 2) {
position += self->string_size;
@@ -362,8 +367,8 @@
static int
-O_cwrite(PyObject *self, const char *c, int l) {
- int newl;
+O_cwrite(PyObject *self, const char *c, Py_ssize_t l) {
+ Py_ssize_t newl;
Oobject *oself;
UNLESS (IO__opencheck(IOOOBJECT(self))) return -1;
@@ -372,8 +377,10 @@
newl = oself->pos+l;
if (newl >= oself->buf_size) {
oself->buf_size *= 2;
- if (oself->buf_size <= newl)
- oself->buf_size = newl+1;
+ if (oself->buf_size <= newl) {
+ assert(newl + 1 < INT_MAX);
+ oself->buf_size = (int)(newl+1);
+ }
UNLESS (oself->buf =
(char*)realloc(oself->buf, oself->buf_size)) {
PyErr_SetString(PyExc_MemoryError,"out of memory");
@@ -384,13 +391,14 @@
memcpy(oself->buf+oself->pos,c,l);
- oself->pos += l;
+ assert(oself->pos + l < INT_MAX);
+ oself->pos += (int)l;
if (oself->string_size < oself->pos) {
oself->string_size = oself->pos;
}
- return l;
+ return (int)l;
}
static PyObject *
Modified: python/branches/ssize_t/Modules/cjkcodecs/multibytecodec.c
==============================================================================
--- python/branches/ssize_t/Modules/cjkcodecs/multibytecodec.c (original)
+++ python/branches/ssize_t/Modules/cjkcodecs/multibytecodec.c Sat Dec 17 11:20:15 2005
@@ -214,7 +214,7 @@
if (buf->excobj == NULL) {
buf->excobj = PyUnicodeEncodeError_Create(codec->encoding,
buf->inbuf_top,
- (int)(buf->inbuf_end - buf->inbuf_top),
+ buf->inbuf_end - buf->inbuf_top,
start, end, reason);
if (buf->excobj == NULL)
goto errorexit;
Modified: python/branches/ssize_t/Modules/gcmodule.c
==============================================================================
--- python/branches/ssize_t/Modules/gcmodule.c (original)
+++ python/branches/ssize_t/Modules/gcmodule.c Sat Dec 17 11:20:15 2005
@@ -1272,7 +1272,7 @@
}
PyVarObject *
-_PyObject_GC_NewVar(PyTypeObject *tp, int nitems)
+_PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
{
const size_t size = _PyObject_VAR_SIZE(tp, nitems);
PyVarObject *op = (PyVarObject *) _PyObject_GC_Malloc(size);
Modified: python/branches/ssize_t/Modules/parsermodule.c
==============================================================================
--- python/branches/ssize_t/Modules/parsermodule.c (original)
+++ python/branches/ssize_t/Modules/parsermodule.c Sat Dec 17 11:20:15 2005
@@ -55,9 +55,9 @@
static char parser_version_string[] = "0.5";
-typedef PyObject* (*SeqMaker) (int length);
+typedef PyObject* (*SeqMaker) (Py_ssize_t length);
typedef int (*SeqInserter) (PyObject* sequence,
- int index,
+ Py_ssize_t index,
PyObject* element);
/* The function below is copyrighted by Stichting Mathematisch Centrum. The
Modified: python/branches/ssize_t/Modules/posixmodule.c
==============================================================================
--- python/branches/ssize_t/Modules/posixmodule.c (original)
+++ python/branches/ssize_t/Modules/posixmodule.c Sat Dec 17 11:20:15 2005
@@ -1033,7 +1033,7 @@
int res;
#ifdef MS_WINDOWS
- int pathlen;
+ Py_ssize_t pathlen;
char pathcopy[MAX_PATH];
#endif /* MS_WINDOWS */
@@ -1518,7 +1518,7 @@
/* MAX_PATH characters could mean a bigger encoded string */
char namebuf[MAX_PATH*2+5];
char *bufptr = namebuf;
- int len = sizeof(namebuf)/sizeof(namebuf[0]);
+ Py_ssize_t len = sizeof(namebuf)/sizeof(namebuf[0]);
#ifdef Py_WIN_WIDE_FILENAMES
/* If on wide-character-capable OS see if argument
@@ -2216,7 +2216,7 @@
PyObject *argv;
char **argvlist;
int i, argc;
- PyObject *(*getitem)(PyObject *, int);
+ PyObject *(*getitem)(PyObject *, Py_ssize_t);
/* execv has two arguments: (path, argv), where
argv is a list or tuple of strings. */
@@ -2285,7 +2285,7 @@
char **envlist;
PyObject *key, *val, *keys=NULL, *vals=NULL;
int i, pos, argc, envc;
- PyObject *(*getitem)(PyObject *, int);
+ PyObject *(*getitem)(PyObject *, Py_ssize_t);
int lastarg = 0;
/* execve has three arguments: (path, argv, env), where
@@ -2429,7 +2429,7 @@
char **argvlist;
int mode, i, argc;
Py_intptr_t spawnval;
- PyObject *(*getitem)(PyObject *, int);
+ PyObject *(*getitem)(PyObject *, Py_ssize_t);
/* spawnv has three arguments: (mode, path, argv), where
argv is a list or tuple of strings. */
@@ -2518,7 +2518,7 @@
PyObject *key, *val, *keys=NULL, *vals=NULL, *res=NULL;
int mode, i, pos, argc, envc;
Py_intptr_t spawnval;
- PyObject *(*getitem)(PyObject *, int);
+ PyObject *(*getitem)(PyObject *, Py_ssize_t);
int lastarg = 0;
/* spawnve has four arguments: (mode, path, argv, env), where
@@ -2670,7 +2670,7 @@
char **argvlist;
int mode, i, argc;
Py_intptr_t spawnval;
- PyObject *(*getitem)(PyObject *, int);
+ PyObject *(*getitem)(PyObject *, Py_ssize_t);
/* spawnvp has three arguments: (mode, path, argv), where
argv is a list or tuple of strings. */
@@ -2751,7 +2751,7 @@
PyObject *key, *val, *keys=NULL, *vals=NULL, *res=NULL;
int mode, i, pos, argc, envc;
Py_intptr_t spawnval;
- PyObject *(*getitem)(PyObject *, int);
+ PyObject *(*getitem)(PyObject *, Py_ssize_t);
int lastarg = 0;
/* spawnvpe has four arguments: (mode, path, argv, env), where
@@ -4186,14 +4186,15 @@
char *s1,*s2, *s3 = " /c ";
const char *szConsoleSpawn = "w9xpopen.exe";
int i;
- int x;
+ Py_ssize_t x;
if (i = GetEnvironmentVariable("COMSPEC",NULL,0)) {
char *comshell;
s1 = (char *)alloca(i);
if (!(x = GetEnvironmentVariable("COMSPEC", s1, i)))
- return x;
+ /* x < i, so x fits into an integer */
+ return (int)x;
/* Explicitly check if we are using COMMAND.COM. If we are
* then use the w9xpopen hack.
@@ -4219,7 +4220,7 @@
char modulepath[_MAX_PATH];
struct stat statinfo;
GetModuleFileName(NULL, modulepath, sizeof(modulepath));
- for (i = x = 0; modulepath[i]; i++)
+ for (x = i = 0; modulepath[i]; i++)
if (modulepath[i] == SEP)
x = i+1;
modulepath[x] = '\0';
@@ -4396,7 +4397,7 @@
switch (mode & (_O_RDONLY | _O_TEXT | _O_BINARY | _O_WRONLY)) {
case _O_WRONLY | _O_TEXT:
/* Case for writing to child Stdin in text mode. */
- fd1 = _open_osfhandle((long)hChildStdinWrDup, mode);
+ fd1 = _open_osfhandle((intptr_t)hChildStdinWrDup, mode);
f1 = _fdopen(fd1, "w");
f = PyFile_FromFile(f1, cmdstring, "w", _PyPclose);
PyFile_SetBufSize(f, 0);
@@ -4407,7 +4408,7 @@
case _O_RDONLY | _O_TEXT:
/* Case for reading from child Stdout in text mode. */
- fd1 = _open_osfhandle((long)hChildStdoutRdDup, mode);
+ fd1 = _open_osfhandle((intptr_t)hChildStdoutRdDup, mode);
f1 = _fdopen(fd1, "r");
f = PyFile_FromFile(f1, cmdstring, "r", _PyPclose);
PyFile_SetBufSize(f, 0);
@@ -4418,7 +4419,7 @@
case _O_RDONLY | _O_BINARY:
/* Case for readinig from child Stdout in binary mode. */
- fd1 = _open_osfhandle((long)hChildStdoutRdDup, mode);
+ fd1 = _open_osfhandle((intptr_t)hChildStdoutRdDup, mode);
f1 = _fdopen(fd1, "rb");
f = PyFile_FromFile(f1, cmdstring, "rb", _PyPclose);
PyFile_SetBufSize(f, 0);
@@ -4429,7 +4430,7 @@
case _O_WRONLY | _O_BINARY:
/* Case for writing to child Stdin in binary mode. */
- fd1 = _open_osfhandle((long)hChildStdinWrDup, mode);
+ fd1 = _open_osfhandle((intptr_t)hChildStdinWrDup, mode);
f1 = _fdopen(fd1, "wb");
f = PyFile_FromFile(f1, cmdstring, "wb", _PyPclose);
PyFile_SetBufSize(f, 0);
@@ -4455,9 +4456,9 @@
m2 = "wb";
}
- fd1 = _open_osfhandle((long)hChildStdinWrDup, mode);
+ fd1 = _open_osfhandle((intptr_t)hChildStdinWrDup, mode);
f1 = _fdopen(fd1, m2);
- fd2 = _open_osfhandle((long)hChildStdoutRdDup, mode);
+ fd2 = _open_osfhandle((intptr_t)hChildStdoutRdDup, mode);
f2 = _fdopen(fd2, m1);
p1 = PyFile_FromFile(f1, cmdstring, m2, _PyPclose);
PyFile_SetBufSize(p1, 0);
@@ -4487,11 +4488,11 @@
m2 = "wb";
}
- fd1 = _open_osfhandle((long)hChildStdinWrDup, mode);
+ fd1 = _open_osfhandle((intptr_t)hChildStdinWrDup, mode);
f1 = _fdopen(fd1, m2);
- fd2 = _open_osfhandle((long)hChildStdoutRdDup, mode);
+ fd2 = _open_osfhandle((intptr_t)hChildStdoutRdDup, mode);
f2 = _fdopen(fd2, m1);
- fd3 = _open_osfhandle((long)hChildStderrRdDup, mode);
+ fd3 = _open_osfhandle((intptr_t)hChildStderrRdDup, mode);
f3 = _fdopen(fd3, m1);
p1 = PyFile_FromFile(f1, cmdstring, m2, _PyPclose);
p2 = PyFile_FromFile(f2, cmdstring, m1, _PyPclose);
@@ -4993,8 +4994,8 @@
static PyObject *
posix_waitpid(PyObject *self, PyObject *args)
{
- int pid, options;
- int status;
+ intptr_t pid;
+ int status, options;
if (!PyArg_ParseTuple(args, "ii:waitpid", &pid, &options))
return NULL;
Modified: python/branches/ssize_t/Modules/rgbimgmodule.c
==============================================================================
--- python/branches/ssize_t/Modules/rgbimgmodule.c (original)
+++ python/branches/ssize_t/Modules/rgbimgmodule.c Sat Dec 17 11:20:15 2005
@@ -168,7 +168,7 @@
buf[1] = (unsigned char) (val >> 16);
buf[2] = (unsigned char) (val >> 8);
buf[3] = (unsigned char) (val >> 0);
- return fwrite(buf, 4, 1, outf);
+ return (int)fwrite(buf, 4, 1, outf);
}
static void
@@ -200,7 +200,7 @@
putlong(outf, image->min);
putlong(outf, image->max);
putlong(outf, 0);
- return fwrite("no name", 8, 1, outf);
+ return (int)fwrite("no name", 8, 1, outf);
}
static int
@@ -567,7 +567,8 @@
Py_Int32 *starttab = NULL, *lengthtab = NULL;
unsigned char *rlebuf = NULL;
unsigned char *lumbuf = NULL;
- int rlebuflen, goodwrite;
+ int rlebuflen;
+ Py_ssize_t goodwrite;
PyObject *retval = NULL;
if (!PyArg_ParseTuple(args, "s#iiis:longstoimage", &lptr, &len,
Modified: python/branches/ssize_t/Modules/zipimport.c
==============================================================================
--- python/branches/ssize_t/Modules/zipimport.c (original)
+++ python/branches/ssize_t/Modules/zipimport.c Sat Dec 17 11:20:15 2005
@@ -62,7 +62,7 @@
zipimporter_init(ZipImporter *self, PyObject *args, PyObject *kwds)
{
char *path, *p, *prefix, buf[MAXPATHLEN+2];
- int len;
+ Py_ssize_t len;
if (!_PyArg_NoKeywords("zipimporter()", kwds))
return -1;
@@ -231,7 +231,7 @@
static int
make_filename(char *prefix, char *name, char *path)
{
- int len;
+ Py_ssize_t len;
char *p;
len = strlen(prefix);
@@ -249,7 +249,8 @@
*p = SEP;
}
len += strlen(name);
- return len;
+ assert(len < INT_MAX);
+ return (int)len;
}
enum zi_module_info {
@@ -807,7 +808,8 @@
PyObject *raw_data, *data = NULL, *decompress;
char *buf;
FILE *fp;
- int err, bytes_read = 0;
+ int err;
+ Py_ssize_t bytes_read = 0;
long l;
char *datapath;
long compress, data_size, file_size, file_offset;
@@ -1023,7 +1025,7 @@
{
PyObject *toc_entry;
time_t mtime = 0;
- int lastchar = strlen(path) - 1;
+ Py_ssize_t lastchar = strlen(path) - 1;
char savechar = path[lastchar];
path[lastchar] = '\0'; /* strip 'c' or 'o' from *.py[co] */
toc_entry = PyDict_GetItemString(self->files, path);
Modified: python/branches/ssize_t/Objects/abstract.c
==============================================================================
--- python/branches/ssize_t/Objects/abstract.c (original)
+++ python/branches/ssize_t/Objects/abstract.c Sat Dec 17 11:20:15 2005
@@ -648,7 +648,7 @@
}
static PyObject *
-sequence_repeat(intargfunc repeatfunc, PyObject *seq, PyObject *n)
+sequence_repeat(ssizeargfunc repeatfunc, PyObject *seq, PyObject *n)
{
long count;
if (PyInt_Check(n)) {
@@ -842,7 +842,7 @@
PyObject *result = binary_iop1(v, w, NB_SLOT(nb_inplace_multiply),
NB_SLOT(nb_multiply));
if (result == Py_NotImplemented) {
- intargfunc f = NULL;
+ ssizeargfunc f = NULL;
PySequenceMethods *mv = v->ob_type->tp_as_sequence;
PySequenceMethods *mw = w->ob_type->tp_as_sequence;
Py_DECREF(result);
@@ -1148,7 +1148,7 @@
}
PyObject *
-PySequence_Repeat(PyObject *o, int count)
+PySequence_Repeat(PyObject *o, Py_ssize_t count)
{
PySequenceMethods *m;
@@ -1180,7 +1180,7 @@
}
PyObject *
-PySequence_InPlaceRepeat(PyObject *o, int count)
+PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count)
{
PySequenceMethods *m;
@@ -1197,7 +1197,7 @@
}
PyObject *
-PySequence_GetItem(PyObject *s, int i)
+PySequence_GetItem(PyObject *s, Py_ssize_t i) /* XXX negative values */
{
PySequenceMethods *m;
@@ -1239,7 +1239,7 @@
}
PyObject *
-PySequence_GetSlice(PyObject *s, int i1, int i2)
+PySequence_GetSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2)
{
PySequenceMethods *m;
PyMappingMethods *mp;
@@ -1274,7 +1274,7 @@
}
int
-PySequence_SetItem(PyObject *s, int i, PyObject *o)
+PySequence_SetItem(PyObject *s, Py_ssize_t i, PyObject *o)
{
PySequenceMethods *m;
@@ -1301,7 +1301,7 @@
}
int
-PySequence_DelItem(PyObject *s, int i)
+PySequence_DelItem(PyObject *s, Py_ssize_t i)
{
PySequenceMethods *m;
@@ -1328,7 +1328,7 @@
}
int
-PySequence_SetSlice(PyObject *s, int i1, int i2, PyObject *o)
+PySequence_SetSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2, PyObject *o)
{
PySequenceMethods *m;
PyMappingMethods *mp;
@@ -1367,7 +1367,7 @@
}
int
-PySequence_DelSlice(PyObject *s, int i1, int i2)
+PySequence_DelSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2)
{
PySequenceMethods *m;
Modified: python/branches/ssize_t/Objects/bufferobject.c
==============================================================================
--- python/branches/ssize_t/Objects/bufferobject.c (original)
+++ python/branches/ssize_t/Objects/bufferobject.c Sat Dec 17 11:20:15 2005
@@ -56,7 +56,7 @@
static PyObject *
-buffer_from_memory(PyObject *base, int size, int offset, void *ptr,
+buffer_from_memory(PyObject *base, Py_ssize_t size, int offset, void *ptr,
int readonly)
{
PyBufferObject * b;
@@ -113,7 +113,7 @@
PyObject *
-PyBuffer_FromObject(PyObject *base, int offset, int size)
+PyBuffer_FromObject(PyObject *base, int offset, Py_ssize_t size)
{
PyBufferProcs *pb = base->ob_type->tp_as_buffer;
@@ -129,7 +129,7 @@
}
PyObject *
-PyBuffer_FromReadWriteObject(PyObject *base, int offset, int size)
+PyBuffer_FromReadWriteObject(PyObject *base, int offset, Py_ssize_t size)
{
PyBufferProcs *pb = base->ob_type->tp_as_buffer;
@@ -145,13 +145,13 @@
}
PyObject *
-PyBuffer_FromMemory(void *ptr, int size)
+PyBuffer_FromMemory(void *ptr, Py_ssize_t size)
{
return buffer_from_memory(NULL, size, 0, ptr, 1);
}
PyObject *
-PyBuffer_FromReadWriteMemory(void *ptr, int size)
+PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size)
{
return buffer_from_memory(NULL, size, 0, ptr, 0);
}
@@ -367,7 +367,7 @@
}
static PyObject *
-buffer_repeat(PyBufferObject *self, int count)
+buffer_repeat(PyBufferObject *self, Py_ssize_t count)
{
PyObject *ob;
register char *p;
@@ -396,13 +396,13 @@
}
static PyObject *
-buffer_item(PyBufferObject *self, int idx)
+buffer_item(PyBufferObject *self, Py_ssize_t idx)
{
void *ptr;
int size;
if (!get_buf(self, &ptr, &size))
return NULL;
- if ( idx < 0 || idx >= size ) {
+ if (idx < 0 || idx >= size ) {
PyErr_SetString(PyExc_IndexError, "buffer index out of range");
return NULL;
}
@@ -410,7 +410,7 @@
}
static PyObject *
-buffer_slice(PyBufferObject *self, int left, int right)
+buffer_slice(PyBufferObject *self, Py_ssize_t left, Py_ssize_t right)
{
void *ptr;
int size;
@@ -429,7 +429,7 @@
}
static int
-buffer_ass_item(PyBufferObject *self, int idx, PyObject *other)
+buffer_ass_item(PyBufferObject *self, Py_ssize_t idx, PyObject *other)
{
PyBufferProcs *pb;
void *ptr1, *ptr2;
@@ -445,7 +445,7 @@
if (!get_buf(self, &ptr1, &size))
return -1;
- if (idx < 0 || idx >= size) {
+ if (idx >= size) {
PyErr_SetString(PyExc_IndexError,
"buffer assignment index out of range");
return -1;
@@ -480,7 +480,7 @@
}
static int
-buffer_ass_slice(PyBufferObject *self, int left, int right, PyObject *other)
+buffer_ass_slice(PyBufferObject *self, Py_ssize_t left, Py_ssize_t right, PyObject *other)
{
PyBufferProcs *pb;
void *ptr1, *ptr2;
@@ -596,11 +596,11 @@
static PySequenceMethods buffer_as_sequence = {
(inquiry)buffer_length, /*sq_length*/
(binaryfunc)buffer_concat, /*sq_concat*/
- (intargfunc)buffer_repeat, /*sq_repeat*/
- (intargfunc)buffer_item, /*sq_item*/
- (intintargfunc)buffer_slice, /*sq_slice*/
- (intobjargproc)buffer_ass_item, /*sq_ass_item*/
- (intintobjargproc)buffer_ass_slice, /*sq_ass_slice*/
+ (ssizeargfunc)buffer_repeat, /*sq_repeat*/
+ (ssizeargfunc)buffer_item, /*sq_item*/
+ (ssizessizeargfunc)buffer_slice, /*sq_slice*/
+ (sizeobjargproc)buffer_ass_item, /*sq_ass_item*/
+ (ssizessizeobjargproc)buffer_ass_slice, /*sq_ass_slice*/
};
static PyBufferProcs buffer_as_buffer = {
Modified: python/branches/ssize_t/Objects/classobject.c
==============================================================================
--- python/branches/ssize_t/Objects/classobject.c (original)
+++ python/branches/ssize_t/Objects/classobject.c Sat Dec 17 11:20:15 2005
@@ -1103,7 +1103,7 @@
};
static PyObject *
-instance_item(PyInstanceObject *inst, int i)
+instance_item(PyInstanceObject *inst, Py_ssize_t i)
{
PyObject *func, *arg, *res;
@@ -1112,7 +1112,7 @@
func = instance_getattr(inst, getitemstr);
if (func == NULL)
return NULL;
- arg = Py_BuildValue("(i)", i);
+ arg = Py_BuildValue("(n)", i);
if (arg == NULL) {
Py_DECREF(func);
return NULL;
@@ -1325,10 +1325,10 @@
(inquiry)instance_length, /* sq_length */
0, /* sq_concat */
0, /* sq_repeat */
- (intargfunc)instance_item, /* sq_item */
- (intintargfunc)instance_slice, /* sq_slice */
- (intobjargproc)instance_ass_item, /* sq_ass_item */
- (intintobjargproc)instance_ass_slice, /* sq_ass_slice */
+ (ssizeargfunc)instance_item, /* sq_item */
+ (ssizessizeargfunc)instance_slice, /* sq_slice */
+ (sizeobjargproc)instance_ass_item, /* sq_ass_item */
+ (ssizessizeobjargproc)instance_ass_slice,/* sq_ass_slice */
(objobjproc)instance_contains, /* sq_contains */
};
Modified: python/branches/ssize_t/Objects/fileobject.c
==============================================================================
--- python/branches/ssize_t/Objects/fileobject.c (original)
+++ python/branches/ssize_t/Objects/fileobject.c Sat Dec 17 11:20:15 2005
@@ -1,5 +1,6 @@
/* File object implementation */
+#define PY_SIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
@@ -854,7 +855,7 @@
{
char *ptr;
int ntodo;
- size_t ndone, nnow;
+ Py_ssize_t ndone, nnow;
if (f->f_fp == NULL)
return err_closed();
@@ -967,7 +968,8 @@
pvend = buf + total_v_size;
nfree = pvend - pvfree;
memset(pvfree, '\n', nfree);
- p = fgets(pvfree, nfree, fp);
+ assert(nfree < INT_MAX); /* Should be atmost MAXBUFSIZE */
+ p = fgets(pvfree, (int)nfree, fp);
Py_END_ALLOW_THREADS
if (p == NULL) {
@@ -1041,7 +1043,8 @@
pvend = BUF(v) + total_v_size;
nfree = pvend - pvfree;
memset(pvfree, '\n', nfree);
- p = fgets(pvfree, nfree, fp);
+ assert(nfree < INT_MAX);
+ p = fgets(pvfree, (int)nfree, fp);
Py_END_ALLOW_THREADS
if (p == NULL) {
@@ -1431,7 +1434,7 @@
file_write(PyFileObject *f, PyObject *args)
{
char *s;
- int n, n2;
+ Py_ssize_t n, n2;
if (f->f_fp == NULL)
return err_closed();
if (!PyArg_ParseTuple(args, f->f_binary ? "s#" : "t#", &s, &n))
@@ -1457,7 +1460,8 @@
PyObject *list, *line;
PyObject *it; /* iter(seq) */
PyObject *result;
- int i, j, index, len, nwritten, islist;
+ int i, j, index, len, islist;
+ Py_ssize_t nwritten;
assert(seq != NULL);
if (f->f_fp == NULL)
@@ -1752,7 +1756,7 @@
static int
readahead(PyFileObject *f, int bufsize)
{
- int chunksize;
+ Py_ssize_t chunksize;
if (f->f_buf != NULL) {
if( (f->f_bufend - f->f_bufptr) >= 1)
@@ -1792,7 +1796,7 @@
PyStringObject* s;
char *bufptr;
char *buf;
- int len;
+ Py_ssize_t len;
if (f->f_buf == NULL)
if (readahead(f, bufsize) < 0)
@@ -1818,8 +1822,9 @@
bufptr = f->f_bufptr;
buf = f->f_buf;
f->f_buf = NULL; /* Force new readahead buffer */
+ assert(skip+len < INT_MAX);
s = readahead_get_line_skip(
- f, skip+len, bufsize + (bufsize>>2) );
+ f, (int)(skip+len), bufsize + (bufsize>>2) );
if (s == NULL) {
PyMem_Free(buf);
return NULL;
Modified: python/branches/ssize_t/Objects/intobject.c
==============================================================================
--- python/branches/ssize_t/Objects/intobject.c (original)
+++ python/branches/ssize_t/Objects/intobject.c Sat Dec 17 11:20:15 2005
@@ -108,6 +108,22 @@
return (PyObject *) v;
}
+PyObject *
+PyInt_FromSize_t(size_t ival)
+{
+ if (ival <= LONG_MAX)
+ return PyInt_FromLong((long)ival);
+ return _PyLong_FromSize_t(ival);
+}
+
+PyObject *
+PyInt_FromSsize_t(Py_ssize_t ival)
+{
+ if (ival >= LONG_MIN && ival <= LONG_MAX)
+ return PyInt_FromLong((long)ival);
+ return _PyLong_FromSsize_t(ival);
+}
+
static void
int_dealloc(PyIntObject *v)
{
@@ -169,6 +185,57 @@
return val;
}
+Py_ssize_t
+PyInt_AsSsize_t(register PyObject *op)
+{
+#if SIZEOF_SIZE_T==SIZEOF_LONG
+ return PyInt_AsLong(op);
+#else
+ PyNumberMethods *nb;
+ PyIntObject *io;
+ Py_ssize_t val;
+
+ if (op && PyInt_Check(op))
+ return PyInt_AS_LONG((PyIntObject*) op);
+
+ if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
+ (nb->nb_int == NULL && nb->nb_long == 0)) {
+ PyErr_SetString(PyExc_TypeError, "an integer is required");
+ return -1;
+ }
+
+ if (nb->nb_long != 0) {
+ io = (PyIntObject*) (*nb->nb_long) (op);
+ } else {
+ io = (PyIntObject*) (*nb->nb_int) (op);
+ }
+ if (io == NULL)
+ return -1;
+ if (!PyInt_Check(io)) {
+ if (PyLong_Check(io)) {
+ /* got a long? => retry int conversion */
+ val = PyLong_AsSsize_t((PyObject *)io);
+ Py_DECREF(io);
+ if ((val == -1) && PyErr_Occurred())
+ return -1;
+ return val;
+ }
+ else
+ {
+ Py_DECREF(io);
+ PyErr_SetString(PyExc_TypeError,
+ "nb_int should return int object");
+ return -1;
+ }
+ }
+
+ val = PyInt_AS_LONG(io);
+ Py_DECREF(io);
+
+ return val;
+#endif
+}
+
unsigned long
PyInt_AsUnsignedLongMask(register PyObject *op)
{
Modified: python/branches/ssize_t/Objects/listobject.c
==============================================================================
--- python/branches/ssize_t/Objects/listobject.c (original)
+++ python/branches/ssize_t/Objects/listobject.c Sat Dec 17 11:20:15 2005
@@ -22,7 +22,7 @@
* than ob_size on entry.
*/
static int
-list_resize(PyListObject *self, int newsize)
+list_resize(PyListObject *self, Py_ssize_t newsize)
{
PyObject **items;
size_t new_allocated;
@@ -82,7 +82,7 @@
}
PyObject *
-PyList_New(int size)
+PyList_New(Py_ssize_t size)
{
PyListObject *op;
size_t nbytes;
@@ -118,7 +118,7 @@
return (PyObject *) op;
}
-int
+Py_ssize_t
PyList_Size(PyObject *op)
{
if (!PyList_Check(op)) {
@@ -132,13 +132,13 @@
static PyObject *indexerr = NULL;
PyObject *
-PyList_GetItem(PyObject *op, int i)
+PyList_GetItem(PyObject *op, Py_ssize_t i)
{
if (!PyList_Check(op)) {
PyErr_BadInternalCall();
return NULL;
}
- if (i < 0 || i >= ((PyListObject *)op) -> ob_size) {
+ if (i >= ((PyListObject *)op) -> ob_size) {
if (indexerr == NULL)
indexerr = PyString_FromString(
"list index out of range");
@@ -149,7 +149,7 @@
}
int
-PyList_SetItem(register PyObject *op, register int i,
+PyList_SetItem(register PyObject *op, register Py_ssize_t i,
register PyObject *newitem)
{
register PyObject *olditem;
@@ -159,7 +159,7 @@
PyErr_BadInternalCall();
return -1;
}
- if (i < 0 || i >= ((PyListObject *)op) -> ob_size) {
+ if (i >= ((PyListObject *)op) -> ob_size) {
Py_XDECREF(newitem);
PyErr_SetString(PyExc_IndexError,
"list assignment index out of range");
@@ -173,7 +173,7 @@
}
static int
-ins1(PyListObject *self, int where, PyObject *v)
+ins1(PyListObject *self, Py_ssize_t where, PyObject *v)
{
int i, n = self->ob_size;
PyObject **items;
@@ -206,7 +206,7 @@
}
int
-PyList_Insert(PyObject *op, int where, PyObject *newitem)
+PyList_Insert(PyObject *op, Py_ssize_t where, PyObject *newitem)
{
if (!PyList_Check(op)) {
PyErr_BadInternalCall();
@@ -381,7 +381,7 @@
}
static PyObject *
-list_item(PyListObject *a, int i)
+list_item(PyListObject *a, Py_ssize_t i)
{
if (i < 0 || i >= a->ob_size) {
if (indexerr == NULL)
@@ -395,7 +395,7 @@
}
static PyObject *
-list_slice(PyListObject *a, int ilow, int ihigh)
+list_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
{
PyListObject *np;
PyObject **src, **dest;
@@ -424,7 +424,7 @@
}
PyObject *
-PyList_GetSlice(PyObject *a, int ilow, int ihigh)
+PyList_GetSlice(PyObject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
{
if (!PyList_Check(a)) {
PyErr_BadInternalCall();
@@ -473,7 +473,7 @@
}
static PyObject *
-list_repeat(PyListObject *a, int n)
+list_repeat(PyListObject *a, Py_ssize_t n)
{
int i, j;
int size;
@@ -542,7 +542,7 @@
* guaranteed the call cannot fail.
*/
static int
-list_ass_slice(PyListObject *a, int ilow, int ihigh, PyObject *v)
+list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
{
/* Because [X]DECREF can recursively invoke list operations on
this list, we must postpone all [X]DECREF activity until
@@ -640,7 +640,7 @@
}
int
-PyList_SetSlice(PyObject *a, int ilow, int ihigh, PyObject *v)
+PyList_SetSlice(PyObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
{
if (!PyList_Check(a)) {
PyErr_BadInternalCall();
@@ -650,7 +650,7 @@
}
static PyObject *
-list_inplace_repeat(PyListObject *self, int n)
+list_inplace_repeat(PyListObject *self, Py_ssize_t n)
{
PyObject **items;
int size, i, j, p;
@@ -685,7 +685,7 @@
}
static int
-list_ass_item(PyListObject *a, int i, PyObject *v)
+list_ass_item(PyListObject *a, Py_ssize_t i, PyObject *v)
{
PyObject *old_value;
if (i < 0 || i >= a->ob_size) {
@@ -2435,11 +2435,11 @@
static PySequenceMethods list_as_sequence = {
(inquiry)list_length, /* sq_length */
(binaryfunc)list_concat, /* sq_concat */
- (intargfunc)list_repeat, /* sq_repeat */
- (intargfunc)list_item, /* sq_item */
- (intintargfunc)list_slice, /* sq_slice */
- (intobjargproc)list_ass_item, /* sq_ass_item */
- (intintobjargproc)list_ass_slice, /* sq_ass_slice */
+ (ssizeargfunc)list_repeat, /* sq_repeat */
+ (ssizeargfunc)list_item, /* sq_item */
+ (ssizessizeargfunc)list_slice, /* sq_slice */
+ (sizeobjargproc)list_ass_item, /* sq_ass_item */
+ (ssizessizeobjargproc)list_ass_slice, /* sq_ass_slice */
(objobjproc)list_contains, /* sq_contains */
(binaryfunc)list_inplace_concat, /* sq_inplace_concat */
(intargfunc)list_inplace_repeat, /* sq_inplace_repeat */
@@ -2459,7 +2459,7 @@
return list_item(self, i);
}
else if (PyLong_Check(item)) {
- long i = PyLong_AsLong(item);
+ Py_ssize_t i = PyLong_AsSsize_t(item);
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)
@@ -2467,7 +2467,7 @@
return list_item(self, i);
}
else if (PySlice_Check(item)) {
- int start, stop, step, slicelength, cur, i;
+ Py_ssize_t start, stop, step, slicelength, cur, i;
PyObject* result;
PyObject* it;
PyObject **src, **dest;
@@ -2521,7 +2521,7 @@
return list_ass_item(self, i, value);
}
else if (PySlice_Check(item)) {
- int start, stop, step, slicelength;
+ Py_ssize_t start, stop, step, slicelength;
if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size,
&start, &stop, &step, &slicelength) < 0) {
@@ -2601,9 +2601,10 @@
}
if (PySequence_Fast_GET_SIZE(seq) != slicelength) {
+ /* XXX can we use %zd here? */
PyErr_Format(PyExc_ValueError,
"attempt to assign sequence of size %d to extended slice of size %d",
- PySequence_Fast_GET_SIZE(seq),
+ (int)PySequence_Fast_GET_SIZE(seq),
slicelength);
Py_DECREF(seq);
return -1;
Modified: python/branches/ssize_t/Objects/longobject.c
==============================================================================
--- python/branches/ssize_t/Objects/longobject.c (original)
+++ python/branches/ssize_t/Objects/longobject.c Sat Dec 17 11:20:15 2005
@@ -50,7 +50,7 @@
static PyLongObject *
long_normalize(register PyLongObject *v)
{
- int j = ABS(v->ob_size);
+ Py_ssize_t j = ABS(v->ob_size);
register int i = j;
while (i > 0 && v->ob_digit[i-1] == 0)
@@ -64,8 +64,13 @@
Return NULL and set exception if we run out of memory. */
PyLongObject *
-_PyLong_New(int size)
+_PyLong_New(Py_ssize_t size)
{
+ if (size > INT_MAX) {
+ /* XXX: Fix this check when ob_size becomes ssize_t */
+ PyErr_NoMemory();
+ return NULL;
+ }
return PyObject_NEW_VAR(PyLongObject, &PyLong_Type, size);
}
@@ -198,7 +203,8 @@
/* This version by Tim Peters */
register PyLongObject *v;
unsigned long x, prev;
- int i, sign;
+ Py_ssize_t i;
+ int sign;
if (vv == NULL || !PyLong_Check(vv)) {
if (vv != NULL && PyInt_Check(vv))
@@ -235,6 +241,52 @@
return -1;
}
+/* Get a Py_ssize_t from a long int object.
+ Returns -1 and sets an error condition if overflow occurs. */
+
+Py_ssize_t
+PyLong_AsSsize_t(PyObject *vv)
+{
+ register PyLongObject *v;
+ size_t x, prev;
+ Py_ssize_t i;
+ int sign;
+
+ if (vv == NULL || !PyLong_Check(vv)) {
+ if (vv != NULL && PyInt_Check(vv))
+ return PyInt_AsSsize_t(vv);
+ PyErr_BadInternalCall();
+ return -1;
+ }
+ v = (PyLongObject *)vv;
+ i = v->ob_size;
+ sign = 1;
+ x = 0;
+ if (i < 0) {
+ sign = -1;
+ i = -(i);
+ }
+ while (--i >= 0) {
+ prev = x;
+ x = (x << SHIFT) + v->ob_digit[i];
+ if ((x >> SHIFT) != prev)
+ goto overflow;
+ }
+ /* Haven't lost any bits, but if the sign bit is set we're in
+ * trouble *unless* this is the min negative number. So,
+ * trouble iff sign bit set && (positive || some bit set other
+ * than the sign bit).
+ */
+ if ((Py_ssize_t)x < 0 && (sign > 0 || (x << 1) != 0))
+ goto overflow;
+ return (Py_ssize_t)x * sign;
+
+ overflow:
+ PyErr_SetString(PyExc_OverflowError,
+ "long int too large to convert to int");
+ return -1;
+}
+
/* Get a C unsigned long int from a long int object.
Returns -1 and sets an error condition if overflow occurs. */
@@ -243,7 +295,7 @@
{
register PyLongObject *v;
unsigned long x, prev;
- int i;
+ Py_ssize_t i;
if (vv == NULL || !PyLong_Check(vv)) {
if (vv != NULL && PyInt_Check(vv)) {
@@ -286,7 +338,8 @@
{
register PyLongObject *v;
unsigned long x;
- int i, sign;
+ Py_ssize_t i;
+ int sign;
if (vv == NULL || !PyLong_Check(vv)) {
if (vv != NULL && PyInt_Check(vv))
@@ -324,7 +377,7 @@
{
PyLongObject *v = (PyLongObject *)vv;
size_t result = 0;
- int ndigits;
+ Py_ssize_t ndigits;
assert(v != NULL);
assert(PyLong_Check(v));
@@ -334,7 +387,7 @@
digit msd = v->ob_digit[ndigits - 1];
result = (ndigits - 1) * SHIFT;
- if (result / SHIFT != (size_t)ndigits - 1)
+ if (result / SHIFT != ndigits - 1)
goto Overflow;
do {
++result;
@@ -464,7 +517,7 @@
int little_endian, int is_signed)
{
int i; /* index into v->ob_digit */
- int ndigits; /* |v->ob_size| */
+ Py_ssize_t ndigits; /* |v->ob_size| */
twodigits accum; /* sliding register */
unsigned int accumbits; /* # bits in accum */
int do_twos_comp; /* store 2's-comp? is_signed and v < 0 */
@@ -612,7 +665,8 @@
PyLongObject *v;
double x;
const double multiplier = (double)(1L << SHIFT);
- int i, sign;
+ Py_ssize_t i;
+ int sign;
int nbitsneeded;
if (vv == NULL || !PyLong_Check(vv)) {
@@ -769,6 +823,30 @@
SIZEOF_LONG_LONG, IS_LITTLE_ENDIAN, 0);
}
+/* Create a new long int object from a C Py_ssize_t. */
+
+PyObject *
+_PyLong_FromSsize_t(Py_ssize_t ival)
+{
+ Py_ssize_t bytes = ival;
+ int one = 1;
+ return _PyLong_FromByteArray(
+ (unsigned char *)&bytes,
+ SIZEOF_SIZE_T, IS_LITTLE_ENDIAN, 0);
+}
+
+/* Create a new long int object from a C size_t. */
+
+PyObject *
+_PyLong_FromSize_t(size_t ival)
+{
+ size_t bytes = ival;
+ int one = 1;
+ return _PyLong_FromByteArray(
+ (unsigned char *)&bytes,
+ SIZEOF_SIZE_T, IS_LITTLE_ENDIAN, 0);
+}
+
/* Get a C PY_LONG_LONG int from a long int object.
Return -1 and set an error if overflow occurs. */
@@ -856,7 +934,8 @@
{
register PyLongObject *v;
unsigned PY_LONG_LONG x;
- int i, sign;
+ Py_ssize_t i;
+ int sign;
if (vv == NULL || !PyLong_Check(vv)) {
PyErr_BadInternalCall();
@@ -977,10 +1056,10 @@
static PyLongObject *
muladd1(PyLongObject *a, wdigit n, wdigit extra)
{
- int size_a = ABS(a->ob_size);
+ Py_ssize_t size_a = ABS(a->ob_size);
PyLongObject *z = _PyLong_New(size_a+1);
twodigits carry = extra;
- int i;
+ Py_ssize_t i;
if (z == NULL)
return NULL;
@@ -1023,7 +1102,7 @@
static PyLongObject *
divrem1(PyLongObject *a, digit n, digit *prem)
{
- const int size = ABS(a->ob_size);
+ const Py_ssize_t size = ABS(a->ob_size);
PyLongObject *z;
assert(n > 0 && n <= MASK);
@@ -1043,8 +1122,8 @@
{
register PyLongObject *a = (PyLongObject *)aa;
PyStringObject *str;
- int i;
- const int size_a = ABS(a->ob_size);
+ Py_ssize_t i;
+ const Py_ssize_t size_a = ABS(a->ob_size);
char *p;
int bits;
char sign = '\0';
@@ -1104,7 +1183,7 @@
/* Not 0, and base not a power of 2. Divide repeatedly by
base, but for speed use the highest power of base that
fits in a digit. */
- int size = size_a;
+ Py_ssize_t size = size_a;
digit *pin = a->ob_digit;
PyLongObject *scratch;
/* powbasw <- largest power of base that fits in a digit. */
@@ -1197,7 +1276,7 @@
char *p = *str;
char *start = p;
int bits_per_char;
- int n;
+ Py_ssize_t n;
PyLongObject *z;
twodigits accum;
int bits_in_accum;
@@ -1258,7 +1337,7 @@
bits_in_accum += bits_per_char;
if (bits_in_accum >= SHIFT) {
*pdigit++ = (digit)(accum & MASK);
- assert(pdigit - z->ob_digit <= n);
+ assert(pdigit - z->ob_digit <= (int)n);
accum >>= SHIFT;
bits_in_accum -= SHIFT;
assert(bits_in_accum < SHIFT);
@@ -1267,7 +1346,7 @@
if (bits_in_accum) {
assert(bits_in_accum <= SHIFT);
*pdigit++ = (digit)accum;
- assert(pdigit - z->ob_digit <= n);
+ assert(pdigit - z->ob_digit <= (int)n);
}
while (pdigit - z->ob_digit < n)
*pdigit++ = 0;
@@ -1384,7 +1463,7 @@
long_divrem(PyLongObject *a, PyLongObject *b,
PyLongObject **pdiv, PyLongObject **prem)
{
- int size_a = ABS(a->ob_size), size_b = ABS(b->ob_size);
+ Py_ssize_t size_a = ABS(a->ob_size), size_b = ABS(b->ob_size);
PyLongObject *z;
if (size_b == 0) {
@@ -1430,12 +1509,12 @@
static PyLongObject *
x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
{
- int size_v = ABS(v1->ob_size), size_w = ABS(w1->ob_size);
+ Py_ssize_t size_v = ABS(v1->ob_size), size_w = ABS(w1->ob_size);
digit d = (digit) ((twodigits)BASE / (w1->ob_digit[size_w-1] + 1));
PyLongObject *v = mul1(v1, d);
PyLongObject *w = mul1(w1, d);
PyLongObject *a;
- int j, k;
+ Py_ssize_t j, k;
if (v == NULL || w == NULL) {
Py_XDECREF(v);
@@ -1605,7 +1684,7 @@
static PyLongObject *
x_add(PyLongObject *a, PyLongObject *b)
{
- int size_a = ABS(a->ob_size), size_b = ABS(b->ob_size);
+ Py_ssize_t size_a = ABS(a->ob_size), size_b = ABS(b->ob_size);
PyLongObject *z;
int i;
digit carry = 0;
@@ -1639,7 +1718,7 @@
static PyLongObject *
x_sub(PyLongObject *a, PyLongObject *b)
{
- int size_a = ABS(a->ob_size), size_b = ABS(b->ob_size);
+ Py_ssize_t size_a = ABS(a->ob_size), size_b = ABS(b->ob_size);
PyLongObject *z;
int i;
int sign = 1;
@@ -1749,9 +1828,9 @@
x_mul(PyLongObject *a, PyLongObject *b)
{
PyLongObject *z;
- int size_a = ABS(a->ob_size);
- int size_b = ABS(b->ob_size);
- int i;
+ Py_ssize_t size_a = ABS(a->ob_size);
+ Py_ssize_t size_b = ABS(b->ob_size);
+ Py_ssize_t i;
z = _PyLong_New(size_a + size_b);
if (z == NULL)
@@ -1840,8 +1919,8 @@
kmul_split(PyLongObject *n, int size, PyLongObject **high, PyLongObject **low)
{
PyLongObject *hi, *lo;
- int size_lo, size_hi;
- const int size_n = ABS(n->ob_size);
+ Py_ssize_t size_lo, size_hi;
+ const Py_ssize_t size_n = ABS(n->ob_size);
size_lo = MIN(size_n, size);
size_hi = size_n - size_lo;
@@ -1870,8 +1949,8 @@
static PyLongObject *
k_mul(PyLongObject *a, PyLongObject *b)
{
- int asize = ABS(a->ob_size);
- int bsize = ABS(b->ob_size);
+ Py_ssize_t asize = ABS(a->ob_size);
+ Py_ssize_t bsize = ABS(b->ob_size);
PyLongObject *ah = NULL;
PyLongObject *al = NULL;
PyLongObject *bh = NULL;
@@ -1879,7 +1958,7 @@
PyLongObject *ret = NULL;
PyLongObject *t1, *t2, *t3;
int shift; /* the number of digits we split off */
- int i;
+ Py_ssize_t i;
/* (ah*X+al)(bh*X+bl) = ah*bh*X*X + (ah*bl + al*bh)*X + al*bl
* Let k = (ah+al)*(bh+bl) = ah*bl + al*bh + ah*bh + al*bl
@@ -2091,9 +2170,9 @@
static PyLongObject *
k_lopsided_mul(PyLongObject *a, PyLongObject *b)
{
- const int asize = ABS(a->ob_size);
- int bsize = ABS(b->ob_size);
- int nbdone; /* # of b digits already multiplied */
+ const Py_ssize_t asize = ABS(a->ob_size);
+ Py_ssize_t bsize = ABS(b->ob_size);
+ Py_ssize_t nbdone; /* # of b digits already multiplied */
PyLongObject *ret;
PyLongObject *bslice = NULL;
@@ -2346,7 +2425,7 @@
int negativeOutput = 0; /* if x<0 return negative output */
PyLongObject *z = NULL; /* accumulated result */
- int i, j, k; /* counters */
+ Py_ssize_t i, j, k; /* counters */
PyLongObject *temp = NULL;
/* 5-ary values. If the exponent is large enough, table is
@@ -2590,7 +2669,7 @@
PyLongObject *a, *b;
PyLongObject *z = NULL;
long shiftby;
- int newsize, wordshift, loshift, hishift, i, j;
+ Py_ssize_t newsize, wordshift, loshift, hishift, i, j;
digit lomask, himask;
CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b);
@@ -2657,7 +2736,7 @@
PyLongObject *a, *b;
PyLongObject *z = NULL;
long shiftby;
- int oldsize, newsize, wordshift, remshift, i, j;
+ Py_ssize_t oldsize, newsize, wordshift, remshift, i, j;
twodigits accum;
CONVERT_BINOP(v, w, &a, &b);
@@ -2716,7 +2795,7 @@
{
digit maska, maskb; /* 0 or MASK */
int negz;
- int size_a, size_b, size_z;
+ Py_ssize_t size_a, size_b, size_z;
PyLongObject *z;
int i;
digit diga, digb;
@@ -2958,7 +3037,7 @@
long_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyLongObject *tmp, *new;
- int i, n;
+ Py_ssize_t i, n;
assert(PyType_IsSubtype(type, &PyLong_Type));
tmp = (PyLongObject *)long_new(&PyLong_Type, args, kwds);
Modified: python/branches/ssize_t/Objects/object.c
==============================================================================
--- python/branches/ssize_t/Objects/object.c (original)
+++ python/branches/ssize_t/Objects/object.c Sat Dec 17 11:20:15 2005
@@ -170,7 +170,7 @@
}
PyVarObject *
-PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, int size)
+PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, Py_ssize_t size)
{
if (op == NULL)
return (PyVarObject *) PyErr_NoMemory();
@@ -192,7 +192,7 @@
}
PyVarObject *
-_PyObject_NewVar(PyTypeObject *tp, int nitems)
+_PyObject_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
{
PyVarObject *op;
const size_t size = _PyObject_VAR_SIZE(tp, nitems);
Modified: python/branches/ssize_t/Objects/obmalloc.c
==============================================================================
--- python/branches/ssize_t/Objects/obmalloc.c (original)
+++ python/branches/ssize_t/Objects/obmalloc.c Sat Dec 17 11:20:15 2005
@@ -816,7 +816,7 @@
{
void *bp;
poolp pool;
- uint size;
+ size_t size;
if (p == NULL)
return PyObject_Malloc(nbytes);
@@ -1018,7 +1018,7 @@
if (p == NULL)
return NULL;
- write4(p, nbytes);
+ write4(p, (ulong)nbytes);
p[4] = p[5] = p[6] = p[7] = FORBIDDENBYTE;
if (nbytes > 0)
@@ -1081,7 +1081,7 @@
if (q == NULL)
return NULL;
- write4(q, nbytes);
+ write4(q, (ulong)nbytes);
assert(q[4] == FORBIDDENBYTE &&
q[5] == FORBIDDENBYTE &&
q[6] == FORBIDDENBYTE &&
Modified: python/branches/ssize_t/Objects/rangeobject.c
==============================================================================
--- python/branches/ssize_t/Objects/rangeobject.c (original)
+++ python/branches/ssize_t/Objects/rangeobject.c Sat Dec 17 11:20:15 2005
@@ -91,7 +91,7 @@
slightly faster than range() and more memory efficient.");
static PyObject *
-range_item(rangeobject *r, int i)
+range_item(rangeobject *r, Py_ssize_t i)
{
if (i < 0 || i >= r->len) {
PyErr_SetString(PyExc_IndexError,
@@ -140,7 +140,7 @@
(inquiry)range_length, /* sq_length */
0, /* sq_concat */
0, /* sq_repeat */
- (intargfunc)range_item, /* sq_item */
+ (ssizeargfunc)range_item, /* sq_item */
0, /* sq_slice */
};
Modified: python/branches/ssize_t/Objects/sliceobject.c
==============================================================================
--- python/branches/ssize_t/Objects/sliceobject.c (original)
+++ python/branches/ssize_t/Objects/sliceobject.c Sat Dec 17 11:20:15 2005
@@ -80,9 +80,10 @@
}
int
-PySlice_GetIndices(PySliceObject *r, int length,
- int *start, int *stop, int *step)
+PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
+ Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)
{
+ /* XXX support long ints */
if (r->step == Py_None) {
*step = 1;
} else {
@@ -110,12 +111,12 @@
}
int
-PySlice_GetIndicesEx(PySliceObject *r, int length,
- int *start, int *stop, int *step, int *slicelength)
+PySlice_GetIndicesEx(PySliceObject *r, Py_ssize_t length,
+ Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength)
{
/* this is harder to get right than you might think */
- int defstart, defstop;
+ Py_ssize_t defstart, defstop;
if (r->step == Py_None) {
*step = 1;
@@ -230,7 +231,7 @@
static PyObject*
slice_indices(PySliceObject* self, PyObject* len)
{
- int ilen, start, stop, step, slicelength;
+ Py_ssize_t ilen, start, stop, step, slicelength;
ilen = PyInt_AsLong(len);
Modified: python/branches/ssize_t/Objects/stringobject.c
==============================================================================
--- python/branches/ssize_t/Objects/stringobject.c (original)
+++ python/branches/ssize_t/Objects/stringobject.c Sat Dec 17 11:20:15 2005
@@ -49,7 +49,7 @@
parameter (for PyString_FromString()).
*/
PyObject *
-PyString_FromStringAndSize(const char *str, int size)
+PyString_FromStringAndSize(const char *str, Py_ssize_t size)
{
register PyStringObject *op;
assert(size >= 0);
@@ -154,7 +154,7 @@
PyString_FromFormatV(const char *format, va_list vargs)
{
va_list count;
- int n = 0;
+ Py_ssize_t n = 0;
const char* f;
char *s;
PyObject* string;
@@ -235,7 +235,8 @@
for (f = format; *f; f++) {
if (*f == '%') {
const char* p = f++;
- int i, longflag = 0;
+ Py_ssize_t i;
+ int longflag = 0;
/* parse the width.precision part (we're only
interested in the precision value, if any) */
n = 0;
@@ -519,16 +520,16 @@
specified encoding. */
PyObject *PyString_DecodeEscape(const char *s,
- int len,
+ Py_ssize_t len,
const char *errors,
- int unicode,
+ Py_ssize_t unicode,
const char *recode_encoding)
{
int c;
char *p, *buf;
const char *end;
PyObject *v;
- int newlen = recode_encoding ? 4*len:len;
+ Py_ssize_t newlen = recode_encoding ? 4*len:len;
v = PyString_FromStringAndSize((char *)NULL, newlen);
if (v == NULL)
return NULL;
@@ -885,7 +886,7 @@
static PyObject *
string_concat(register PyStringObject *a, register PyObject *bb)
{
- register unsigned int size;
+ register size_t size;
register PyStringObject *op;
if (!PyString_Check(bb)) {
#ifdef Py_USING_UNICODE
@@ -909,6 +910,7 @@
return (PyObject *)a;
}
size = a->ob_size + b->ob_size;
+ /* XXX check overflow */
/* Inline PyObject_NewVar */
op = (PyStringObject *)PyObject_MALLOC(sizeof(PyStringObject) + size);
if (op == NULL)
@@ -924,11 +926,11 @@
}
static PyObject *
-string_repeat(register PyStringObject *a, register int n)
+string_repeat(register PyStringObject *a, register Py_ssize_t n)
{
register int i;
register int j;
- register int size;
+ register Py_ssize_t size;
register PyStringObject *op;
size_t nbytes;
if (n < 0)
@@ -980,7 +982,8 @@
/* String slice a[i:j] consists of characters a[i] ... a[j-1] */
static PyObject *
-string_slice(register PyStringObject *a, register int i, register int j)
+string_slice(register PyStringObject *a, register Py_ssize_t i,
+ register Py_ssize_t j)
/* j -- may be negative! */
{
if (i < 0)
@@ -1047,7 +1050,7 @@
}
static PyObject *
-string_item(PyStringObject *a, register int i)
+string_item(PyStringObject *a, register Py_ssize_t i)
{
PyObject *v;
char *pchar;
@@ -1173,7 +1176,7 @@
return string_item(self,i);
}
else if (PyLong_Check(item)) {
- long i = PyLong_AsLong(item);
+ Py_ssize_t i = PyLong_AsSsize_t(item);
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)
@@ -1181,7 +1184,7 @@
return string_item(self,i);
}
else if (PySlice_Check(item)) {
- int start, stop, step, slicelength, cur, i;
+ Py_ssize_t start, stop, step, slicelength, cur, i;
char* source_buf;
char* result_buf;
PyObject* result;
@@ -1262,9 +1265,9 @@
static PySequenceMethods string_as_sequence = {
(inquiry)string_length, /*sq_length*/
(binaryfunc)string_concat, /*sq_concat*/
- (intargfunc)string_repeat, /*sq_repeat*/
- (intargfunc)string_item, /*sq_item*/
- (intintargfunc)string_slice, /*sq_slice*/
+ (ssizeargfunc)string_repeat, /*sq_repeat*/
+ (ssizeargfunc)string_item, /*sq_item*/
+ (ssizessizeargfunc)string_slice, /*sq_slice*/
0, /*sq_ass_item*/
0, /*sq_ass_slice*/
(objobjproc)string_contains /*sq_contains*/
@@ -1734,6 +1737,7 @@
int n, i = 0, last = INT_MAX;
PyObject *subobj;
+ /* XXX ssize_t i */
if (!PyArg_ParseTuple(args, "O|O&O&:find/rfind/index/rindex",
&subobj, _PyEval_SliceIndex, &i, _PyEval_SliceIndex, &last))
return -2;
@@ -3521,7 +3525,7 @@
*/
int
-_PyString_Resize(PyObject **pv, int newsize)
+_PyString_Resize(PyObject **pv, Py_ssize_t newsize)
{
register PyObject *v;
register PyStringObject *sv;
@@ -3625,7 +3629,7 @@
(flags&F_ALT) ? "#" : "",
prec, type);
PyOS_ascii_formatd(buf, buflen, fmt, x);
- return strlen(buf);
+ return (int)strlen(buf);
}
/* _PyString_FormatLong emulates the format codes d, u, o, x and X, and
@@ -3832,7 +3836,7 @@
PyOS_snprintf(buf, buflen, fmt, -x);
else
PyOS_snprintf(buf, buflen, fmt, x);
- return strlen(buf);
+ return (int)strlen(buf);
}
static int
@@ -3865,7 +3869,8 @@
PyString_Format(PyObject *format, PyObject *args)
{
char *fmt, *res;
- int fmtcnt, rescnt, reslen, arglen, argidx;
+ int arglen, argidx;
+ Py_ssize_t reslen, rescnt, fmtcnt;
int args_owned = 0;
PyObject *result, *orig_args;
#ifdef Py_USING_UNICODE
@@ -3895,23 +3900,23 @@
if (args->ob_type->tp_as_mapping && !PyTuple_Check(args) &&
!PyObject_TypeCheck(args, &PyBaseString_Type))
dict = args;
- while (--fmtcnt >= 0) {
+ while (fmtcnt-- != 0) {
if (*fmt != '%') {
- if (--rescnt < 0) {
+ if (rescnt == 0) {
rescnt = fmtcnt + 100;
reslen += rescnt;
if (_PyString_Resize(&result, reslen) < 0)
return NULL;
res = PyString_AS_STRING(result)
+ reslen - rescnt;
- --rescnt;
}
+ rescnt--;
*res++ = *fmt++;
}
else {
/* Got a format specifier */
int flags = 0;
- int width = -1;
+ Py_ssize_t width = -1;
int prec = -1;
int c = '\0';
int fill;
@@ -3930,7 +3935,7 @@
fmt++;
if (*fmt == '(') {
char *keystart;
- int keylen;
+ Py_ssize_t keylen;
PyObject *key;
int pcount = 1;
@@ -4187,7 +4192,7 @@
}
if (width < len)
width = len;
- if (rescnt - (sign != 0) < width) {
+ if ((rescnt - (sign != 0)) < width) {
reslen -= rescnt;
rescnt = width + fmtcnt + 100;
reslen += rescnt;
Modified: python/branches/ssize_t/Objects/structseq.c
==============================================================================
--- python/branches/ssize_t/Objects/structseq.c (original)
+++ python/branches/ssize_t/Objects/structseq.c Sat Dec 17 11:20:15 2005
@@ -56,7 +56,7 @@
}
static PyObject*
-structseq_item(PyStructSequence *obj, int i)
+structseq_item(PyStructSequence *obj, Py_ssize_t i)
{
if (i < 0 || i >= VISIBLE_SIZE(obj)) {
PyErr_SetString(PyExc_IndexError, "tuple index out of range");
@@ -67,7 +67,7 @@
}
static PyObject*
-structseq_slice(PyStructSequence *obj, int low, int high)
+structseq_slice(PyStructSequence *obj, Py_ssize_t low, Py_ssize_t high)
{
PyTupleObject *np;
int i;
@@ -200,7 +200,7 @@
}
static PyObject *
-structseq_repeat(PyStructSequence *obj, int n)
+structseq_repeat(PyStructSequence *obj, Py_ssize_t n)
{
PyObject *tup, *result;
tup = make_tuple(obj);
@@ -286,9 +286,9 @@
static PySequenceMethods structseq_as_sequence = {
(inquiry)structseq_length,
(binaryfunc)structseq_concat, /* sq_concat */
- (intargfunc)structseq_repeat, /* sq_repeat */
- (intargfunc)structseq_item, /* sq_item */
- (intintargfunc)structseq_slice, /* sq_slice */
+ (ssizeargfunc)structseq_repeat, /* sq_repeat */
+ (ssizeargfunc)structseq_item, /* sq_item */
+ (ssizessizeargfunc)structseq_slice, /* sq_slice */
0, /* sq_ass_item */
0, /* sq_ass_slice */
(objobjproc)structseq_contains, /* sq_contains */
Modified: python/branches/ssize_t/Objects/tupleobject.c
==============================================================================
--- python/branches/ssize_t/Objects/tupleobject.c (original)
+++ python/branches/ssize_t/Objects/tupleobject.c Sat Dec 17 11:20:15 2005
@@ -24,7 +24,7 @@
#endif
PyObject *
-PyTuple_New(register int size)
+PyTuple_New(register Py_ssize_t size)
{
register PyTupleObject *op;
int i;
@@ -82,7 +82,7 @@
return (PyObject *) op;
}
-int
+Py_ssize_t
PyTuple_Size(register PyObject *op)
{
if (!PyTuple_Check(op)) {
@@ -94,7 +94,7 @@
}
PyObject *
-PyTuple_GetItem(register PyObject *op, register int i)
+PyTuple_GetItem(register PyObject *op, register Py_ssize_t i)
{
if (!PyTuple_Check(op)) {
PyErr_BadInternalCall();
@@ -108,7 +108,7 @@
}
int
-PyTuple_SetItem(register PyObject *op, register int i, PyObject *newitem)
+PyTuple_SetItem(register PyObject *op, register Py_ssize_t i, PyObject *newitem)
{
register PyObject *olditem;
register PyObject **p;
@@ -286,7 +286,7 @@
return x;
}
-static int
+static Py_ssize_t
tuplelength(PyTupleObject *a)
{
return a->ob_size;
@@ -304,7 +304,7 @@
}
static PyObject *
-tupleitem(register PyTupleObject *a, register int i)
+tupleitem(register PyTupleObject *a, register Py_ssize_t i)
{
if (i < 0 || i >= a->ob_size) {
PyErr_SetString(PyExc_IndexError, "tuple index out of range");
@@ -315,7 +315,8 @@
}
static PyObject *
-tupleslice(register PyTupleObject *a, register int ilow, register int ihigh)
+tupleslice(register PyTupleObject *a, register Py_ssize_t ilow,
+ register Py_ssize_t ihigh)
{
register PyTupleObject *np;
PyObject **src, **dest;
@@ -346,7 +347,7 @@
}
PyObject *
-PyTuple_GetSlice(PyObject *op, int i, int j)
+PyTuple_GetSlice(PyObject *op, Py_ssize_t i, Py_ssize_t j)
{
if (op == NULL || !PyTuple_Check(op)) {
PyErr_BadInternalCall();
@@ -395,7 +396,7 @@
}
static PyObject *
-tuplerepeat(PyTupleObject *a, int n)
+tuplerepeat(PyTupleObject *a, Py_ssize_t n)
{
int i, j;
int size;
@@ -573,9 +574,9 @@
static PySequenceMethods tuple_as_sequence = {
(inquiry)tuplelength, /* sq_length */
(binaryfunc)tupleconcat, /* sq_concat */
- (intargfunc)tuplerepeat, /* sq_repeat */
- (intargfunc)tupleitem, /* sq_item */
- (intintargfunc)tupleslice, /* sq_slice */
+ (ssizeargfunc)tuplerepeat, /* sq_repeat */
+ (ssizeargfunc)tupleitem, /* sq_item */
+ (ssizessizeargfunc)tupleslice, /* sq_slice */
0, /* sq_ass_item */
0, /* sq_ass_slice */
(objobjproc)tuplecontains, /* sq_contains */
@@ -591,7 +592,7 @@
return tupleitem(self, i);
}
else if (PyLong_Check(item)) {
- long i = PyLong_AsLong(item);
+ Py_ssize_t i = PyLong_AsSsize_t(item);
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)
@@ -599,7 +600,7 @@
return tupleitem(self, i);
}
else if (PySlice_Check(item)) {
- int start, stop, step, slicelength, cur, i;
+ Py_ssize_t start, stop, step, slicelength, cur, i;
PyObject* result;
PyObject* it;
PyObject **src, **dest;
Modified: python/branches/ssize_t/Objects/typeobject.c
==============================================================================
--- python/branches/ssize_t/Objects/typeobject.c (original)
+++ python/branches/ssize_t/Objects/typeobject.c Sat Dec 17 11:20:15 2005
@@ -443,7 +443,7 @@
}
PyObject *
-PyType_GenericAlloc(PyTypeObject *type, int nitems)
+PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
{
PyObject *obj;
const size_t size = _PyObject_VAR_SIZE(type, nitems+1);
@@ -1529,7 +1529,7 @@
PyObject *tmp = slots;
PyObject *o, *o1;
int i;
- intintargfunc copy = slots->ob_type->tp_as_sequence->sq_slice;
+ ssizessizeargfunc copy = slots->ob_type->tp_as_sequence->sq_slice;
for (i = 0; i < nslots; i++) {
if (PyUnicode_Check(o = PyTuple_GET_ITEM(tmp, i))) {
if (tmp == slots) {
@@ -3335,9 +3335,10 @@
}
if (n == PyTuple_GET_SIZE(ob))
return 1;
+ /* XXX %zd? */
PyErr_Format(
PyExc_TypeError,
- "expected %d arguments, got %d", n, PyTuple_GET_SIZE(ob));
+ "expected %d arguments, got %d", n, (int)PyTuple_GET_SIZE(ob));
return 0;
}
@@ -5286,7 +5287,9 @@
if (c != 0)
return c;
else
- return a - b;
+ /* Cannot use a-b, as this gives off_t,
+ which may lose precision when converted to int. */
+ return (a > b) ? 1 : (a < b) ? -1 : 0;
}
/* Initialize the slotdefs table by adding interned string objects for the
Modified: python/branches/ssize_t/Objects/unicodeobject.c
==============================================================================
--- python/branches/ssize_t/Objects/unicodeobject.c (original)
+++ python/branches/ssize_t/Objects/unicodeobject.c Sat Dec 17 11:20:15 2005
@@ -119,7 +119,7 @@
static
int unicode_resize(register PyUnicodeObject *unicode,
- int length)
+ Py_ssize_t length)
{
void *oldstr;
@@ -154,7 +154,8 @@
return -1;
}
unicode->str[length] = 0;
- unicode->length = length;
+ assert(length < INT_MAX);
+ unicode->length = (int)length;
reset:
/* Reset the object caches */
@@ -176,7 +177,7 @@
*/
static
-PyUnicodeObject *_PyUnicode_New(int length)
+PyUnicodeObject *_PyUnicode_New(Py_ssize_t length)
{
register PyUnicodeObject *unicode;
@@ -225,7 +226,8 @@
*/
unicode->str[0] = 0;
unicode->str[length] = 0;
- unicode->length = length;
+ assert(length<INT_MAX);
+ unicode->length = (int)length;
unicode->hash = -1;
unicode->defenc = NULL;
return unicode;
@@ -263,7 +265,7 @@
}
}
-int PyUnicode_Resize(PyObject **unicode, int length)
+int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
{
register PyUnicodeObject *v;
@@ -303,7 +305,7 @@
PyUnicode_Resize(((PyObject **)(unicodevar)), length)
PyObject *PyUnicode_FromUnicode(const Py_UNICODE *u,
- int size)
+ Py_ssize_t size)
{
PyUnicodeObject *unicode;
@@ -347,7 +349,7 @@
#ifdef HAVE_WCHAR_H
PyObject *PyUnicode_FromWideChar(register const wchar_t *w,
- int size)
+ Py_ssize_t size)
{
PyUnicodeObject *unicode;
@@ -520,7 +522,7 @@
}
PyObject *PyUnicode_Decode(const char *s,
- int size,
+ Py_ssize_t size,
const char *encoding,
const char *errors)
{
@@ -588,7 +590,7 @@
}
PyObject *PyUnicode_Encode(const Py_UNICODE *s,
- int size,
+ Py_ssize_t size,
const char *encoding,
const char *errors)
{
@@ -742,16 +744,17 @@
static
int unicode_decode_call_errorhandler(const char *errors, PyObject **errorHandler,
const char *encoding, const char *reason,
- const char *input, int insize, int *startinpos, int *endinpos, PyObject **exceptionObject, const char **inptr,
- PyObject **output, int *outpos, Py_UNICODE **outptr)
+ const char *input, Py_ssize_t insize, Py_ssize_t *startinpos, Py_ssize_t *endinpos, PyObject **exceptionObject, const char **inptr,
+ PyObject **output, Py_ssize_t *outpos, Py_UNICODE **outptr)
{
static char *argparse = "O!i;decoding error handler must return (unicode, int) tuple";
PyObject *restuple = NULL;
PyObject *repunicode = NULL;
- int outsize = PyUnicode_GET_SIZE(*output);
- int requiredsize;
- int newpos;
+ Py_ssize_t outsize = PyUnicode_GET_SIZE(*output);
+ Py_ssize_t requiredsize;
+ int inewpos;
+ Py_ssize_t newpos;
Py_UNICODE *repptr;
int repsize;
int res = -1;
@@ -784,12 +787,15 @@
PyErr_Format(PyExc_TypeError, &argparse[4]);
goto onError;
}
- if (!PyArg_ParseTuple(restuple, argparse, &PyUnicode_Type, &repunicode, &newpos))
+ if (!PyArg_ParseTuple(restuple, argparse, &PyUnicode_Type, &repunicode, &inewpos))
goto onError;
- if (newpos<0)
- newpos = insize+newpos;
+ if (inewpos<0)
+ newpos = insize+inewpos;
+ else
+ newpos = inewpos;
if (newpos<0 || newpos>insize) {
- PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", newpos);
+ /* XXX %zd? */
+ PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", (int)newpos);
goto onError;
}
@@ -887,13 +893,13 @@
}
PyObject *PyUnicode_DecodeUTF7(const char *s,
- int size,
+ Py_ssize_t size,
const char *errors)
{
const char *starts = s;
- int startinpos;
- int endinpos;
- int outpos;
+ Py_ssize_t startinpos;
+ Py_ssize_t endinpos;
+ Py_ssize_t outpos;
const char *e;
PyUnicodeObject *unicode;
Py_UNICODE *p;
@@ -1023,16 +1029,16 @@
PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s,
- int size,
+ Py_ssize_t size,
int encodeSetO,
int encodeWhiteSpace,
const char *errors)
{
PyObject *v;
/* It might be possible to tighten this worst case */
- unsigned int cbAllocated = 5 * size;
+ Py_ssize_t cbAllocated = 5 * size;
int inShift = 0;
- int i = 0;
+ Py_ssize_t i = 0;
unsigned int bitsleft = 0;
unsigned long charsleft = 0;
char * out;
@@ -1147,22 +1153,22 @@
};
PyObject *PyUnicode_DecodeUTF8(const char *s,
- int size,
+ Py_ssize_t size,
const char *errors)
{
return PyUnicode_DecodeUTF8Stateful(s, size, errors, NULL);
}
PyObject *PyUnicode_DecodeUTF8Stateful(const char *s,
- int size,
+ Py_ssize_t size,
const char *errors,
- int *consumed)
+ Py_ssize_t *consumed)
{
const char *starts = s;
int n;
- int startinpos;
- int endinpos;
- int outpos;
+ Py_ssize_t startinpos;
+ Py_ssize_t endinpos;
+ Py_ssize_t outpos;
const char *e;
PyUnicodeObject *unicode;
Py_UNICODE *p;
@@ -1347,15 +1353,15 @@
*/
PyObject *
PyUnicode_EncodeUTF8(const Py_UNICODE *s,
- int size,
+ Py_ssize_t size,
const char *errors)
{
#define MAX_SHORT_UNICHARS 300 /* largest size we'll do on the stack */
- int i; /* index into s of next input byte */
+ Py_ssize_t i; /* index into s of next input byte */
PyObject *v; /* result string object */
char *p; /* next free byte in output buffer */
- int nallocated; /* number of result bytes allocated */
+ Py_ssize_t nallocated; /* number of result bytes allocated */
int nneeded; /* number of result bytes needed */
char stackbuf[MAX_SHORT_UNICHARS * 4];
@@ -1455,7 +1461,7 @@
PyObject *
PyUnicode_DecodeUTF16(const char *s,
- int size,
+ Py_ssize_t size,
const char *errors,
int *byteorder)
{
@@ -1464,15 +1470,15 @@
PyObject *
PyUnicode_DecodeUTF16Stateful(const char *s,
- int size,
+ Py_ssize_t size,
const char *errors,
int *byteorder,
- int *consumed)
+ Py_ssize_t *consumed)
{
const char *starts = s;
- int startinpos;
- int endinpos;
- int outpos;
+ Py_ssize_t startinpos;
+ Py_ssize_t endinpos;
+ Py_ssize_t outpos;
PyUnicodeObject *unicode;
Py_UNICODE *p;
const unsigned char *q, *e;
@@ -1630,7 +1636,7 @@
PyObject *
PyUnicode_EncodeUTF16(const Py_UNICODE *s,
- int size,
+ Py_ssize_t size,
const char *errors,
int byteorder)
{
@@ -1716,13 +1722,13 @@
static _PyUnicode_Name_CAPI *ucnhash_CAPI = NULL;
PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
- int size,
+ Py_ssize_t size,
const char *errors)
{
const char *starts = s;
- int startinpos;
- int endinpos;
- int outpos;
+ Py_ssize_t startinpos;
+ Py_ssize_t endinpos;
+ Py_ssize_t outpos;
int i;
PyUnicodeObject *v;
Py_UNICODE *p;
@@ -1896,7 +1902,7 @@
/* found a name. look it up in the unicode database */
message = "unknown Unicode character name";
s++;
- if (ucnhash_CAPI->getcode(start, s-start-1, &chr))
+ if (ucnhash_CAPI->getcode(start, (int)(s-start-1), &chr))
goto store;
}
}
@@ -1962,12 +1968,12 @@
*/
static const Py_UNICODE *findchar(const Py_UNICODE *s,
- int size,
+ Py_ssize_t size,
Py_UNICODE ch);
static
PyObject *unicodeescape_string(const Py_UNICODE *s,
- int size,
+ Py_ssize_t size,
int quotes)
{
PyObject *repr;
@@ -2093,7 +2099,7 @@
}
PyObject *PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
- int size)
+ Py_ssize_t size)
{
return unicodeescape_string(s, size, 0);
}
@@ -2111,13 +2117,13 @@
/* --- Raw Unicode Escape Codec ------------------------------------------- */
PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
- int size,
+ Py_ssize_t size,
const char *errors)
{
const char *starts = s;
- int startinpos;
- int endinpos;
- int outpos;
+ Py_ssize_t startinpos;
+ Py_ssize_t endinpos;
+ Py_ssize_t outpos;
PyUnicodeObject *v;
Py_UNICODE *p;
const char *end;
@@ -2216,7 +2222,7 @@
}
PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
- int size)
+ Py_ssize_t size)
{
PyObject *repr;
char *p;
@@ -2284,13 +2290,13 @@
/* --- Unicode Internal Codec ------------------------------------------- */
PyObject *_PyUnicode_DecodeUnicodeInternal(const char *s,
- int size,
+ Py_ssize_t size,
const char *errors)
{
const char *starts = s;
- int startinpos;
- int endinpos;
- int outpos;
+ Py_ssize_t startinpos;
+ Py_ssize_t endinpos;
+ Py_ssize_t outpos;
Py_UNICODE unimax;
PyUnicodeObject *v;
Py_UNICODE *p;
@@ -2359,7 +2365,7 @@
/* --- Latin-1 Codec ------------------------------------------------------ */
PyObject *PyUnicode_DecodeLatin1(const char *s,
- int size,
+ Py_ssize_t size,
const char *errors)
{
PyUnicodeObject *v;
@@ -2389,8 +2395,8 @@
/* create or adjust a UnicodeEncodeError */
static void make_encode_exception(PyObject **exceptionObject,
const char *encoding,
- const Py_UNICODE *unicode, int size,
- int startpos, int endpos,
+ const Py_UNICODE *unicode, Py_ssize_t size,
+ Py_ssize_t startpos, Py_ssize_t endpos,
const char *reason)
{
if (*exceptionObject == NULL) {
@@ -2414,8 +2420,8 @@
/* raises a UnicodeEncodeError */
static void raise_encode_exception(PyObject **exceptionObject,
const char *encoding,
- const Py_UNICODE *unicode, int size,
- int startpos, int endpos,
+ const Py_UNICODE *unicode, Py_ssize_t size,
+ Py_ssize_t startpos, Py_ssize_t endpos,
const char *reason)
{
make_encode_exception(exceptionObject,
@@ -2431,9 +2437,9 @@
static PyObject *unicode_encode_call_errorhandler(const char *errors,
PyObject **errorHandler,
const char *encoding, const char *reason,
- const Py_UNICODE *unicode, int size, PyObject **exceptionObject,
- int startpos, int endpos,
- int *newpos)
+ const Py_UNICODE *unicode, Py_ssize_t size, PyObject **exceptionObject,
+ Py_ssize_t startpos, Py_ssize_t endpos,
+ Py_ssize_t *newpos)
{
static char *argparse = "O!i;encoding error handler must return (unicode, int) tuple";
@@ -2468,7 +2474,8 @@
if (*newpos<0)
*newpos = size+*newpos;
if (*newpos<0 || *newpos>size) {
- PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", *newpos);
+ /* XXX %zd? */
+ PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", (int)*newpos);
Py_DECREF(restuple);
return NULL;
}
@@ -2478,7 +2485,7 @@
}
static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
- int size,
+ Py_ssize_t size,
const char *errors,
int limit)
{
@@ -2492,8 +2499,8 @@
/* pointer into the output */
char *str;
/* current output position */
- int respos = 0;
- int ressize;
+ Py_ssize_t respos = 0;
+ Py_ssize_t ressize;
char *encoding = (limit == 256) ? "latin-1" : "ascii";
char *reason = (limit == 256) ? "ordinal not in range(256)" : "ordinal not in range(128)";
PyObject *errorHandler = NULL;
@@ -2522,12 +2529,12 @@
++p;
}
else {
- int unicodepos = p-startp;
- int requiredsize;
+ Py_ssize_t unicodepos = p-startp;
+ Py_ssize_t requiredsize;
PyObject *repunicode;
- int repsize;
- int newpos;
- int respos;
+ Py_ssize_t repsize;
+ Py_ssize_t newpos;
+ Py_ssize_t respos;
Py_UNICODE *uni2;
/* startpos for collecting unencodable chars */
const Py_UNICODE *collstart = p;
@@ -2653,7 +2660,7 @@
}
PyObject *PyUnicode_EncodeLatin1(const Py_UNICODE *p,
- int size,
+ Py_ssize_t size,
const char *errors)
{
return unicode_encode_ucs1(p, size, errors, 256);
@@ -2673,15 +2680,15 @@
/* --- 7-bit ASCII Codec -------------------------------------------------- */
PyObject *PyUnicode_DecodeASCII(const char *s,
- int size,
+ Py_ssize_t size,
const char *errors)
{
const char *starts = s;
PyUnicodeObject *v;
Py_UNICODE *p;
- int startinpos;
- int endinpos;
- int outpos;
+ Py_ssize_t startinpos;
+ Py_ssize_t endinpos;
+ Py_ssize_t outpos;
const char *e;
PyObject *errorHandler = NULL;
PyObject *exc = NULL;
@@ -2732,7 +2739,7 @@
}
PyObject *PyUnicode_EncodeASCII(const Py_UNICODE *p,
- int size,
+ Py_ssize_t size,
const char *errors)
{
return unicode_encode_ucs1(p, size, errors, 128);
@@ -2754,14 +2761,16 @@
/* --- MBCS codecs for Windows -------------------------------------------- */
PyObject *PyUnicode_DecodeMBCS(const char *s,
- int size,
+ Py_ssize_t size,
const char *errors)
{
PyUnicodeObject *v;
Py_UNICODE *p;
+ DWORD usize;
/* First get the size of the result */
- DWORD usize = MultiByteToWideChar(CP_ACP, 0, s, size, NULL, 0);
+ assert(size < INT_MAX);
+ usize = MultiByteToWideChar(CP_ACP, 0, s, (int)size, NULL, 0);
if (size > 0 && usize==0)
return PyErr_SetFromWindowsErrWithFilename(0, NULL);
@@ -2771,7 +2780,7 @@
if (usize == 0)
return (PyObject *)v;
p = PyUnicode_AS_UNICODE(v);
- if (0 == MultiByteToWideChar(CP_ACP, 0, s, size, p, usize)) {
+ if (0 == MultiByteToWideChar(CP_ACP, 0, s, (int)size, p, usize)) {
Py_DECREF(v);
return PyErr_SetFromWindowsErrWithFilename(0, NULL);
}
@@ -2780,7 +2789,7 @@
}
PyObject *PyUnicode_EncodeMBCS(const Py_UNICODE *p,
- int size,
+ Py_ssize_t size,
const char *errors)
{
PyObject *repr;
@@ -2792,7 +2801,8 @@
return PyString_FromString("");
/* First get the size of the result */
- mbcssize = WideCharToMultiByte(CP_ACP, 0, p, size, NULL, 0, NULL, NULL);
+ assert(size<INT_MAX);
+ mbcssize = WideCharToMultiByte(CP_ACP, 0, p, (int)size, NULL, 0, NULL, NULL);
if (mbcssize==0)
return PyErr_SetFromWindowsErrWithFilename(0, NULL);
@@ -2804,7 +2814,8 @@
/* Do the conversion */
s = PyString_AS_STRING(repr);
- if (0 == WideCharToMultiByte(CP_ACP, 0, p, size, s, mbcssize, NULL, NULL)) {
+ assert(size < INT_MAX);
+ if (0 == WideCharToMultiByte(CP_ACP, 0, p, (int)size, s, mbcssize, NULL, NULL)) {
Py_DECREF(repr);
return PyErr_SetFromWindowsErrWithFilename(0, NULL);
}
@@ -2827,14 +2838,14 @@
/* --- Character Mapping Codec -------------------------------------------- */
PyObject *PyUnicode_DecodeCharmap(const char *s,
- int size,
+ Py_ssize_t size,
PyObject *mapping,
const char *errors)
{
const char *starts = s;
- int startinpos;
- int endinpos;
- int outpos;
+ Py_ssize_t startinpos;
+ Py_ssize_t endinpos;
+ Py_ssize_t outpos;
const char *e;
PyUnicodeObject *v;
Py_UNICODE *p;
@@ -3039,7 +3050,7 @@
reallocation error occurred. The caller must decref the result */
static
PyObject *charmapencode_output(Py_UNICODE c, PyObject *mapping,
- PyObject **outobj, int *outpos)
+ PyObject **outobj, Py_ssize_t *outpos)
{
PyObject *rep = charmapencode_lookup(c, mapping);
@@ -3049,9 +3060,9 @@
return rep;
else {
char *outstart = PyString_AS_STRING(*outobj);
- int outsize = PyString_GET_SIZE(*outobj);
+ Py_ssize_t outsize = PyString_GET_SIZE(*outobj);
if (PyInt_Check(rep)) {
- int requiredsize = *outpos+1;
+ Py_ssize_t requiredsize = *outpos+1;
if (outsize<requiredsize) {
/* exponentially overallocate to minimize reallocations */
if (requiredsize < 2*outsize)
@@ -3067,7 +3078,7 @@
else {
const char *repchars = PyString_AS_STRING(rep);
int repsize = PyString_GET_SIZE(rep);
- int requiredsize = *outpos+repsize;
+ Py_ssize_t requiredsize = *outpos+repsize;
if (outsize<requiredsize) {
/* exponentially overallocate to minimize reallocations */
if (requiredsize < 2*outsize)
@@ -3089,14 +3100,14 @@
Return 0 on success, -1 on error */
static
int charmap_encoding_error(
- const Py_UNICODE *p, int size, int *inpos, PyObject *mapping,
+ const Py_UNICODE *p, Py_ssize_t size, Py_ssize_t *inpos, PyObject *mapping,
PyObject **exceptionObject,
int *known_errorHandler, PyObject **errorHandler, const char *errors,
- PyObject **res, int *respos)
+ PyObject **res, Py_ssize_t *respos)
{
PyObject *repunicode = NULL; /* initialize to prevent gcc warning */
int repsize;
- int newpos;
+ Py_ssize_t newpos;
Py_UNICODE *uni2;
/* startpos for collecting unencodable chars */
int collstartpos = *inpos;
@@ -3202,16 +3213,16 @@
}
PyObject *PyUnicode_EncodeCharmap(const Py_UNICODE *p,
- int size,
+ Py_ssize_t size,
PyObject *mapping,
const char *errors)
{
/* output object */
PyObject *res = NULL;
/* current input position */
- int inpos = 0;
+ Py_ssize_t inpos = 0;
/* current output position */
- int respos = 0;
+ Py_ssize_t respos = 0;
PyObject *errorHandler = NULL;
PyObject *exc = NULL;
/* the following variable is used for caching string comparisons
@@ -3282,8 +3293,8 @@
/* create or adjust a UnicodeTranslateError */
static void make_translate_exception(PyObject **exceptionObject,
- const Py_UNICODE *unicode, int size,
- int startpos, int endpos,
+ const Py_UNICODE *unicode, Py_ssize_t size,
+ Py_ssize_t startpos, Py_ssize_t endpos,
const char *reason)
{
if (*exceptionObject == NULL) {
@@ -3306,8 +3317,8 @@
/* raises a UnicodeTranslateError */
static void raise_translate_exception(PyObject **exceptionObject,
- const Py_UNICODE *unicode, int size,
- int startpos, int endpos,
+ const Py_UNICODE *unicode, Py_ssize_t size,
+ Py_ssize_t startpos, Py_ssize_t endpos,
const char *reason)
{
make_translate_exception(exceptionObject,
@@ -3323,12 +3334,13 @@
static PyObject *unicode_translate_call_errorhandler(const char *errors,
PyObject **errorHandler,
const char *reason,
- const Py_UNICODE *unicode, int size, PyObject **exceptionObject,
- int startpos, int endpos,
- int *newpos)
+ const Py_UNICODE *unicode, Py_ssize_t size, PyObject **exceptionObject,
+ Py_ssize_t startpos, Py_ssize_t endpos,
+ Py_ssize_t *newpos)
{
static char *argparse = "O!i;translating error handler must return (unicode, int) tuple";
+ int i_newpos;
PyObject *restuple;
PyObject *resunicode;
@@ -3353,14 +3365,17 @@
return NULL;
}
if (!PyArg_ParseTuple(restuple, argparse, &PyUnicode_Type,
- &resunicode, newpos)) {
+ &resunicode, &i_newpos)) {
Py_DECREF(restuple);
return NULL;
}
- if (*newpos<0)
- *newpos = size+*newpos;
+ if (i_newpos<0)
+ *newpos = size+i_newpos;
+ else
+ *newpos = i_newpos;
if (*newpos<0 || *newpos>size) {
- PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", *newpos);
+ /* XXX %zd? */
+ PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", (int)*newpos);
Py_DECREF(restuple);
return NULL;
}
@@ -3485,7 +3500,7 @@
}
PyObject *PyUnicode_TranslateCharmap(const Py_UNICODE *p,
- int size,
+ Py_ssize_t size,
PyObject *mapping,
const char *errors)
{
@@ -3533,7 +3548,7 @@
else { /* untranslatable character */
PyObject *repunicode = NULL; /* initialize to prevent gcc warning */
int repsize;
- int newpos;
+ Py_ssize_t newpos;
Py_UNICODE *uni2;
/* startpos for collecting untranslatable chars */
const Py_UNICODE *collstart = p;
@@ -3650,7 +3665,7 @@
/* --- Decimal Encoder ---------------------------------------------------- */
int PyUnicode_EncodeDecimal(Py_UNICODE *s,
- int length,
+ Py_ssize_t length,
char *output,
const char *errors)
{
@@ -3675,7 +3690,7 @@
int decimal;
PyObject *repunicode;
int repsize;
- int newpos;
+ Py_ssize_t newpos;
Py_UNICODE *uni2;
Py_UNICODE *collstart;
Py_UNICODE *collend;
@@ -3965,7 +3980,7 @@
static
const Py_UNICODE *findchar(const Py_UNICODE *s,
- int size,
+ Py_ssize_t size,
Py_UNICODE ch)
{
/* like wcschr, but doesn't stop at NULL characters */
@@ -5270,7 +5285,7 @@
}
static PyObject *
-unicode_getitem(PyUnicodeObject *self, int index)
+unicode_getitem(PyUnicodeObject *self, Py_ssize_t index)
{
if (index < 0 || index >= self->length) {
PyErr_SetString(PyExc_IndexError, "string index out of range");
@@ -5849,7 +5864,7 @@
static PyObject*
-unicode_repeat(PyUnicodeObject *str, int len)
+unicode_repeat(PyUnicodeObject *str, Py_ssize_t len)
{
PyUnicodeObject *u;
Py_UNICODE *p;
@@ -6439,9 +6454,9 @@
static PySequenceMethods unicode_as_sequence = {
(inquiry) unicode_length, /* sq_length */
(binaryfunc) PyUnicode_Concat, /* sq_concat */
- (intargfunc) unicode_repeat, /* sq_repeat */
- (intargfunc) unicode_getitem, /* sq_item */
- (intintargfunc) unicode_slice, /* sq_slice */
+ (ssizeargfunc) unicode_repeat, /* sq_repeat */
+ (ssizeargfunc) unicode_getitem, /* sq_item */
+ (ssizessizeargfunc) unicode_slice, /* sq_slice */
0, /* sq_ass_item */
0, /* sq_ass_slice */
(objobjproc)PyUnicode_Contains, /*sq_contains*/
@@ -6456,14 +6471,14 @@
i += PyString_GET_SIZE(self);
return unicode_getitem(self, i);
} else if (PyLong_Check(item)) {
- long i = PyLong_AsLong(item);
+ Py_ssize_t i = PyLong_AsSsize_t(item);
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)
i += PyString_GET_SIZE(self);
return unicode_getitem(self, i);
} else if (PySlice_Check(item)) {
- int start, stop, step, slicelength, cur, i;
+ Py_ssize_t start, stop, step, slicelength, cur, i;
Py_UNICODE* source_buf;
Py_UNICODE* result_buf;
PyObject* result;
@@ -6867,7 +6882,7 @@
fmt++;
if (*fmt == '(') {
Py_UNICODE *keystart;
- int keylen;
+ Py_ssize_t keylen;
PyObject *key;
int pcount = 1;
Modified: python/branches/ssize_t/Objects/weakrefobject.c
==============================================================================
--- python/branches/ssize_t/Objects/weakrefobject.c (original)
+++ python/branches/ssize_t/Objects/weakrefobject.c Sat Dec 17 11:20:15 2005
@@ -520,7 +520,7 @@
/* sequence slots */
static PyObject *
-proxy_slice(PyWeakReference *proxy, int i, int j)
+proxy_slice(PyWeakReference *proxy, Py_ssize_t i, Py_ssize_t j)
{
if (!proxy_checkref(proxy))
return NULL;
@@ -528,7 +528,7 @@
}
static int
-proxy_ass_slice(PyWeakReference *proxy, int i, int j, PyObject *value)
+proxy_ass_slice(PyWeakReference *proxy, Py_ssize_t i, Py_ssize_t j, PyObject *value)
{
if (!proxy_checkref(proxy))
return -1;
@@ -629,9 +629,9 @@
0, /*sq_concat*/
0, /*sq_repeat*/
0, /*sq_item*/
- (intintargfunc)proxy_slice, /*sq_slice*/
+ (ssizessizeargfunc)proxy_slice, /*sq_slice*/
0, /*sq_ass_item*/
- (intintobjargproc)proxy_ass_slice, /*sq_ass_slice*/
+ (ssizessizeobjargproc)proxy_ass_slice, /*sq_ass_slice*/
(objobjproc)proxy_contains, /* sq_contains */
};
Modified: python/branches/ssize_t/PC/getpathp.c
==============================================================================
--- python/branches/ssize_t/PC/getpathp.c (original)
+++ python/branches/ssize_t/PC/getpathp.c Sat Dec 17 11:20:15 2005
@@ -169,7 +169,8 @@
static int
gotlandmark(char *landmark)
{
- int n, ok;
+ int ok;
+ Py_ssize_t n;
n = strlen(prefix);
join(prefix, landmark);
@@ -302,10 +303,11 @@
dataSize--;
}
if (ppPaths[index]) {
- int len = _tcslen(ppPaths[index]);
+ Py_ssize_t len = _tcslen(ppPaths[index]);
_tcsncpy(szCur, ppPaths[index], len);
szCur += len;
- dataSize -= len;
+ assert(dataSize > len);
+ dataSize -= (int)len;
}
}
if (skipcore)
@@ -632,7 +634,7 @@
char lookBuf[MAXPATHLEN+1];
char *look = buf - 1; /* 'buf' is at the end of the buffer */
while (1) {
- int nchars;
+ Py_ssize_t nchars;
char *lookEnd = look;
/* 'look' will end up one character before the
start of the path in question - even if this
Modified: python/branches/ssize_t/PC/import_nt.c
==============================================================================
--- python/branches/ssize_t/PC/import_nt.c (original)
+++ python/branches/ssize_t/PC/import_nt.c Sat Dec 17 11:20:15 2005
@@ -18,7 +18,7 @@
FILE *PyWin_FindRegisteredModule(const char *moduleName,
struct filedescr **ppFileDesc,
char *pathBuf,
- int pathLen)
+ Py_ssize_t pathLen)
{
char *moduleKey;
const char keyPrefix[] = "Software\\Python\\PythonCore\\";
@@ -53,13 +53,14 @@
"Software\\Python\\PythonCore\\%s\\Modules\\%s%s",
PyWin_DLLVersionString, moduleName, debugString);
- modNameSize = pathLen;
+ assert(pathLen < INT_MAX);
+ modNameSize = (int)pathLen;
regStat = RegQueryValue(keyBase, moduleKey, pathBuf, &modNameSize);
if (regStat != ERROR_SUCCESS) {
/* No user setting - lookup in machine settings */
keyBase = HKEY_LOCAL_MACHINE;
/* be anal - failure may have reset size param */
- modNameSize = pathLen;
+ modNameSize = (int)pathLen;
regStat = RegQueryValue(keyBase, moduleKey,
pathBuf, &modNameSize);
Modified: python/branches/ssize_t/Parser/parsetok.c
==============================================================================
--- python/branches/ssize_t/Parser/parsetok.c (original)
+++ python/branches/ssize_t/Parser/parsetok.c Sat Dec 17 11:20:15 2005
@@ -185,7 +185,8 @@
if (tok->lineno <= 1 && tok->done == E_EOF)
err_ret->error = E_EOF;
err_ret->lineno = tok->lineno;
- err_ret->offset = tok->cur - tok->buf;
+ assert(tok->cur - tok->buf < INT_MAX);
+ err_ret->offset = (int)(tok->cur - tok->buf);
if (tok->buf != NULL) {
size_t len = tok->inp - tok->buf;
err_ret->text = (char *) PyObject_MALLOC(len + 1);
Modified: python/branches/ssize_t/Parser/tokenizer.c
==============================================================================
--- python/branches/ssize_t/Parser/tokenizer.c (original)
+++ python/branches/ssize_t/Parser/tokenizer.c Sat Dec 17 11:20:15 2005
@@ -170,7 +170,7 @@
}
static char *
-new_string(const char *s, int len)
+new_string(const char *s, Py_ssize_t len)
{
char* result = PyMem_NEW(char, len + 1);
if (result != NULL) {
@@ -206,9 +206,9 @@
/* Return the coding spec in S, or NULL if none is found. */
static char *
-get_coding_spec(const char *s, int size)
+get_coding_spec(const char *s, Py_ssize_t size)
{
- int i;
+ Py_ssize_t i;
/* Coding spec must be in a comment, and that comment must be
* the only statement on the source code line. */
for (i = 0; i < size - 6; i++) {
@@ -253,7 +253,7 @@
Return 1 on success, 0 on failure. */
static int
-check_coding_spec(const char* line, int size, struct tok_state *tok,
+check_coding_spec(const char* line, Py_ssize_t size, struct tok_state *tok,
int set_readline(struct tok_state *, const char *))
{
char * cs;
@@ -814,7 +814,7 @@
}
else {
int done = 0;
- int cur = 0;
+ Py_ssize_t cur = 0;
char *pt;
if (tok->start == NULL) {
if (tok->buf == NULL) {
@@ -848,10 +848,10 @@
tok->lineno++;
/* Read until '\n' or EOF */
while (!done) {
- int curstart = tok->start == NULL ? -1 :
- tok->start - tok->buf;
- int curvalid = tok->inp - tok->buf;
- int newsize = curvalid + BUFSIZ;
+ Py_ssize_t curstart = tok->start == NULL ? -1 :
+ tok->start - tok->buf;
+ Py_ssize_t curvalid = tok->inp - tok->buf;
+ Py_ssize_t newsize = curvalid + BUFSIZ;
char *newbuf = tok->buf;
PyMem_RESIZE(newbuf, char, newsize);
if (newbuf == NULL) {
@@ -1384,7 +1384,7 @@
letter_quote:
/* String */
if (c == '\'' || c == '"') {
- int quote2 = tok->cur - tok->start + 1;
+ Py_ssize_t quote2 = tok->cur - tok->start + 1;
int quote = c;
int triple = 0;
int tripcount = 0;
Modified: python/branches/ssize_t/Python/ceval.c
==============================================================================
--- python/branches/ssize_t/Python/ceval.c (original)
+++ python/branches/ssize_t/Python/ceval.c Sat Dec 17 11:20:15 2005
@@ -599,7 +599,7 @@
/* Code access macros */
-#define INSTR_OFFSET() (next_instr - first_instr)
+#define INSTR_OFFSET() ((int)(next_instr - first_instr))
#define NEXTOP() (*next_instr++)
#define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2])
#define PEEKARG() ((next_instr[2]<<8) + next_instr[1])
@@ -637,7 +637,9 @@
/* Stack manipulation macros */
-#define STACK_LEVEL() (stack_pointer - f->f_valuestack)
+/* The stack can grow at most MAXINT deep, as co_nlocals and
+ co_stacksize are ints. */
+#define STACK_LEVEL() ((int)(stack_pointer - f->f_valuestack))
#define EMPTY() (STACK_LEVEL() == 0)
#define TOP() (stack_pointer[-1])
#define SECOND() (stack_pointer[-2])
@@ -3856,7 +3858,7 @@
called by the SLICE opcode with v and/or w equal to NULL.
*/
int
-_PyEval_SliceIndex(PyObject *v, int *pi)
+_PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
{
if (v != NULL) {
long x;
@@ -3905,6 +3907,7 @@
return 0;
}
/* Truncate -- very long indices are truncated anyway */
+ /* XXX truncate by ssize maximum */
if (x > INT_MAX)
x = INT_MAX;
else if (x < -INT_MAX)
Modified: python/branches/ssize_t/Python/codecs.c
==============================================================================
--- python/branches/ssize_t/Python/codecs.c (original)
+++ python/branches/ssize_t/Python/codecs.c Sat Dec 17 11:20:15 2005
@@ -460,7 +460,7 @@
#ifdef Py_USING_UNICODE
PyObject *PyCodec_IgnoreErrors(PyObject *exc)
{
- int end;
+ Py_ssize_t end;
if (PyObject_IsInstance(exc, PyExc_UnicodeEncodeError)) {
if (PyUnicodeEncodeError_GetEnd(exc, &end))
return NULL;
@@ -485,9 +485,9 @@
PyObject *PyCodec_ReplaceErrors(PyObject *exc)
{
PyObject *restuple;
- int start;
- int end;
- int i;
+ Py_ssize_t start;
+ Py_ssize_t end;
+ Py_ssize_t i;
if (PyObject_IsInstance(exc, PyExc_UnicodeEncodeError)) {
PyObject *res;
@@ -540,8 +540,8 @@
if (PyObject_IsInstance(exc, PyExc_UnicodeEncodeError)) {
PyObject *restuple;
PyObject *object;
- int start;
- int end;
+ Py_ssize_t start;
+ Py_ssize_t end;
PyObject *res;
Py_UNICODE *p;
Py_UNICODE *startp;
@@ -652,8 +652,8 @@
if (PyObject_IsInstance(exc, PyExc_UnicodeEncodeError)) {
PyObject *restuple;
PyObject *object;
- int start;
- int end;
+ Py_ssize_t start;
+ Py_ssize_t end;
PyObject *res;
Py_UNICODE *p;
Py_UNICODE *startp;
Modified: python/branches/ssize_t/Python/exceptions.c
==============================================================================
--- python/branches/ssize_t/Python/exceptions.c (original)
+++ python/branches/ssize_t/Python/exceptions.c Sat Dec 17 11:20:15 2005
@@ -910,27 +910,30 @@
#ifdef Py_USING_UNICODE
static
-int get_int(PyObject *exc, const char *name, int *value)
+int get_int(PyObject *exc, const char *name, Py_ssize_t *value)
{
PyObject *attr = PyObject_GetAttrString(exc, (char *)name);
if (!attr)
return -1;
- if (!PyInt_Check(attr)) {
+ if (PyInt_Check(attr)) {
+ *value = PyInt_AS_LONG(attr);
+ } else if (PyLong_Check(attr)) {
+ *value = (size_t)PyLong_AsLongLong(attr); /* XXX overflow?*/
+ } else {
PyErr_Format(PyExc_TypeError, "%.200s attribute must be int", name);
Py_DECREF(attr);
return -1;
}
- *value = PyInt_AS_LONG(attr);
Py_DECREF(attr);
return 0;
}
static
-int set_int(PyObject *exc, const char *name, int value)
+int set_ssize_t(PyObject *exc, const char *name, Py_ssize_t value)
{
- PyObject *obj = PyInt_FromLong(value);
+ PyObject *obj = PyInt_FromSsize_t(value);
int result;
if (!obj)
@@ -940,7 +943,6 @@
return result;
}
-
static
PyObject *get_string(PyObject *exc, const char *name)
{
@@ -1011,16 +1013,16 @@
return get_unicode(exc, "object");
}
-int PyUnicodeEncodeError_GetStart(PyObject *exc, int *start)
+int PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start)
{
if (!get_int(exc, "start", start)) {
PyObject *object = PyUnicodeEncodeError_GetObject(exc);
- int size;
+ Py_ssize_t size;
if (!object)
return -1;
size = PyUnicode_GET_SIZE(object);
if (*start<0)
- *start = 0;
+ *start = 0; /*XXX check for values <0*/
if (*start>=size)
*start = size-1;
Py_DECREF(object);
@@ -1030,11 +1032,11 @@
}
-int PyUnicodeDecodeError_GetStart(PyObject *exc, int *start)
+int PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start)
{
if (!get_int(exc, "start", start)) {
PyObject *object = PyUnicodeDecodeError_GetObject(exc);
- int size;
+ Py_ssize_t size;
if (!object)
return -1;
size = PyString_GET_SIZE(object);
@@ -1049,35 +1051,35 @@
}
-int PyUnicodeTranslateError_GetStart(PyObject *exc, int *start)
+int PyUnicodeTranslateError_GetStart(PyObject *exc, Py_ssize_t *start)
{
return PyUnicodeEncodeError_GetStart(exc, start);
}
-int PyUnicodeEncodeError_SetStart(PyObject *exc, int start)
+int PyUnicodeEncodeError_SetStart(PyObject *exc, Py_ssize_t start)
{
- return set_int(exc, "start", start);
+ return set_ssize_t(exc, "start", start);
}
-int PyUnicodeDecodeError_SetStart(PyObject *exc, int start)
+int PyUnicodeDecodeError_SetStart(PyObject *exc, Py_ssize_t start)
{
- return set_int(exc, "start", start);
+ return set_ssize_t(exc, "start", start);
}
-int PyUnicodeTranslateError_SetStart(PyObject *exc, int start)
+int PyUnicodeTranslateError_SetStart(PyObject *exc, Py_ssize_t start)
{
- return set_int(exc, "start", start);
+ return set_ssize_t(exc, "start", start);
}
-int PyUnicodeEncodeError_GetEnd(PyObject *exc, int *end)
+int PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
{
if (!get_int(exc, "end", end)) {
PyObject *object = PyUnicodeEncodeError_GetObject(exc);
- int size;
+ Py_ssize_t size;
if (!object)
return -1;
size = PyUnicode_GET_SIZE(object);
@@ -1092,11 +1094,11 @@
}
-int PyUnicodeDecodeError_GetEnd(PyObject *exc, int *end)
+int PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
{
if (!get_int(exc, "end", end)) {
PyObject *object = PyUnicodeDecodeError_GetObject(exc);
- int size;
+ Py_ssize_t size;
if (!object)
return -1;
size = PyString_GET_SIZE(object);
@@ -1111,27 +1113,27 @@
}
-int PyUnicodeTranslateError_GetEnd(PyObject *exc, int *start)
+int PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *start)
{
return PyUnicodeEncodeError_GetEnd(exc, start);
}
-int PyUnicodeEncodeError_SetEnd(PyObject *exc, int end)
+int PyUnicodeEncodeError_SetEnd(PyObject *exc, Py_ssize_t end)
{
- return set_int(exc, "end", end);
+ return set_ssize_t(exc, "end", end);
}
-int PyUnicodeDecodeError_SetEnd(PyObject *exc, int end)
+int PyUnicodeDecodeError_SetEnd(PyObject *exc, Py_ssize_t end)
{
- return set_int(exc, "end", end);
+ return set_ssize_t(exc, "end", end);
}
-int PyUnicodeTranslateError_SetEnd(PyObject *exc, int end)
+int PyUnicodeTranslateError_SetEnd(PyObject *exc, Py_ssize_t end)
{
- return set_int(exc, "end", end);
+ return set_ssize_t(exc, "end", end);
}
@@ -1229,8 +1231,8 @@
{
PyObject *encodingObj = NULL;
PyObject *objectObj = NULL;
- int start;
- int end;
+ Py_ssize_t start;
+ Py_ssize_t end;
PyObject *reasonObj = NULL;
char buffer[1000];
PyObject *result = NULL;
@@ -1270,11 +1272,12 @@
);
}
else {
+ /* XXX %zd? */
PyOS_snprintf(buffer, sizeof(buffer),
"'%.400s' codec can't encode characters in position %d-%d: %.400s",
PyString_AS_STRING(encodingObj),
- start,
- end-1,
+ (int)start,
+ (int)(end-1),
PyString_AS_STRING(reasonObj)
);
}
@@ -1295,8 +1298,8 @@
PyObject * PyUnicodeEncodeError_Create(
- const char *encoding, const Py_UNICODE *object, int length,
- int start, int end, const char *reason)
+ const char *encoding, const Py_UNICODE *object, Py_ssize_t length,
+ Py_ssize_t start, Py_ssize_t end, const char *reason)
{
return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#iis",
encoding, object, length, start, end, reason);
@@ -1314,8 +1317,8 @@
{
PyObject *encodingObj = NULL;
PyObject *objectObj = NULL;
- int start;
- int end;
+ Py_ssize_t start;
+ Py_ssize_t end;
PyObject *reasonObj = NULL;
char buffer[1000];
PyObject *result = NULL;
@@ -1338,20 +1341,22 @@
goto error;
if (end==start+1) {
+ /* XXX %zd? */
PyOS_snprintf(buffer, sizeof(buffer),
"'%.400s' codec can't decode byte 0x%02x in position %d: %.400s",
PyString_AS_STRING(encodingObj),
((int)PyString_AS_STRING(objectObj)[start])&0xff,
- start,
+ (int)start,
PyString_AS_STRING(reasonObj)
);
}
else {
+ /* XXX %zd? */
PyOS_snprintf(buffer, sizeof(buffer),
"'%.400s' codec can't decode bytes in position %d-%d: %.400s",
PyString_AS_STRING(encodingObj),
- start,
- end-1,
+ (int)start,
+ (int)(end-1),
PyString_AS_STRING(reasonObj)
);
}
@@ -1372,11 +1377,14 @@
PyObject * PyUnicodeDecodeError_Create(
- const char *encoding, const char *object, int length,
- int start, int end, const char *reason)
+ const char *encoding, const char *object, Py_ssize_t length,
+ Py_ssize_t start, Py_ssize_t end, const char *reason)
{
+ assert(length < INT_MAX);
+ assert(start < INT_MAX);
+ assert(end < INT_MAX);
return PyObject_CallFunction(PyExc_UnicodeDecodeError, "ss#iis",
- encoding, object, length, start, end, reason);
+ encoding, object, (int)length, (int)start, (int)end, reason);
}
@@ -1427,8 +1435,8 @@
UnicodeTranslateError__str__(PyObject *self, PyObject *arg)
{
PyObject *objectObj = NULL;
- int start;
- int end;
+ Py_ssize_t start;
+ Py_ssize_t end;
PyObject *reasonObj = NULL;
char buffer[1000];
PyObject *result = NULL;
@@ -1450,6 +1458,7 @@
if (end==start+1) {
int badchar = (int)PyUnicode_AS_UNICODE(objectObj)[start];
char *format;
+ /* XXX %zd? */
if (badchar <= 0xff)
format = "can't translate character u'\\x%02x' in position %d: %.400s";
else if (badchar <= 0xffff)
@@ -1459,15 +1468,16 @@
PyOS_snprintf(buffer, sizeof(buffer),
format,
badchar,
- start,
+ (int)start,
PyString_AS_STRING(reasonObj)
);
}
else {
+ /* XXX %zd? */
PyOS_snprintf(buffer, sizeof(buffer),
"can't translate characters in position %d-%d: %.400s",
- start,
- end-1,
+ (int)start,
+ (int)(end-1),
PyString_AS_STRING(reasonObj)
);
}
@@ -1487,8 +1497,8 @@
PyObject * PyUnicodeTranslateError_Create(
- const Py_UNICODE *object, int length,
- int start, int end, const char *reason)
+ const Py_UNICODE *object, Py_ssize_t length,
+ Py_ssize_t start, Py_ssize_t end, const char *reason)
{
return PyObject_CallFunction(PyExc_UnicodeTranslateError, "u#iis",
object, length, start, end, reason);
@@ -1749,7 +1759,7 @@
_PyExc_Init(void)
{
char *modulename = "exceptions";
- int modnamesz = strlen(modulename);
+ Py_ssize_t modnamesz = strlen(modulename);
int i;
PyObject *me, *mydict, *bltinmod, *bdict, *doc, *args;
Modified: python/branches/ssize_t/Python/getargs.c
==============================================================================
--- python/branches/ssize_t/Python/getargs.c (original)
+++ python/branches/ssize_t/Python/getargs.c Sat Dec 17 11:20:15 2005
@@ -15,21 +15,24 @@
int PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,
const char *, const char **, va_list);
+#define FLAG_COMPAT 1
+#define FLAG_SIZE_T 2
+
/* Forward */
static int vgetargs1(PyObject *, const char *, va_list *, int);
static void seterror(int, const char *, int *, const char *, const char *);
-static char *convertitem(PyObject *, const char **, va_list *, int *, char *,
- size_t, PyObject **);
-static char *converttuple(PyObject *, const char **, va_list *,
+static char *convertitem(PyObject *, const char **, va_list *, int, int *,
+ char *, size_t, PyObject **);
+static char *converttuple(PyObject *, const char **, va_list *, int,
int *, char *, size_t, int, PyObject **);
-static char *convertsimple(PyObject *, const char **, va_list *, char *,
+static char *convertsimple(PyObject *, const char **, va_list *, int, char *,
size_t, PyObject **);
-static int convertbuffer(PyObject *, void **p, char **);
+static Py_ssize_t convertbuffer(PyObject *, void **p, char **);
static int vgetargskeywords(PyObject *, PyObject *,
- const char *, const char **, va_list *);
-static char *skipitem(const char **, va_list *);
+ const char *, const char **, va_list *, int);
+static char *skipitem(const char **, va_list *, int);
int
PyArg_Parse(PyObject *args, const char *format, ...)
@@ -38,7 +41,19 @@
va_list va;
va_start(va, format);
- retval = vgetargs1(args, format, &va, 1);
+ retval = vgetargs1(args, format, &va, FLAG_COMPAT);
+ va_end(va);
+ return retval;
+}
+
+int
+_PyArg_Parse_SizeT(PyObject *args, char *format, ...)
+{
+ int retval;
+ va_list va;
+
+ va_start(va, format);
+ retval = vgetargs1(args, format, &va, FLAG_COMPAT|FLAG_SIZE_T);
va_end(va);
return retval;
}
@@ -56,6 +71,18 @@
return retval;
}
+int
+_PyArg_ParseTuple_SizeT(PyObject *args, char *format, ...)
+{
+ int retval;
+ va_list va;
+
+ va_start(va, format);
+ retval = vgetargs1(args, format, &va, FLAG_SIZE_T);
+ va_end(va);
+ return retval;
+}
+
int
PyArg_VaParse(PyObject *args, const char *format, va_list va)
@@ -75,6 +102,24 @@
return vgetargs1(args, format, &lva, 0);
}
+int
+_PyArg_VaParse_SizeT(PyObject *args, char *format, va_list va)
+{
+ va_list lva;
+
+#ifdef VA_LIST_IS_ARRAY
+ memcpy(lva, va, sizeof(va_list));
+#else
+#ifdef __va_copy
+ __va_copy(lva, va);
+#else
+ lva = va;
+#endif
+#endif
+
+ return vgetargs1(args, format, &lva, FLAG_SIZE_T);
+}
+
/* Handle cleanup of allocated memory in case of exception */
@@ -120,7 +165,7 @@
static int
-vgetargs1(PyObject *args, const char *format, va_list *p_va, int compat)
+vgetargs1(PyObject *args, const char *format, va_list *p_va, int flags)
{
char msgbuf[256];
int levels[32];
@@ -134,8 +179,10 @@
int i, len;
char *msg;
PyObject *freelist = NULL;
-
+ int compat = flags & FLAG_COMPAT;
+
assert(compat || (args != (PyObject*)NULL));
+ flags = flags & ~FLAG_COMPAT;
while (endfmt == 0) {
int c = *format++;
@@ -204,8 +251,8 @@
PyErr_SetString(PyExc_TypeError, msgbuf);
return 0;
}
- msg = convertitem(args, &format, p_va, levels, msgbuf,
- sizeof(msgbuf), &freelist);
+ msg = convertitem(args, &format, p_va, flags, levels,
+ msgbuf, sizeof(msgbuf), &freelist);
if (msg == NULL)
return cleanreturn(1, freelist);
seterror(levels[0], msg, levels+1, fname, message);
@@ -248,7 +295,8 @@
if (*format == '|')
format++;
msg = convertitem(PyTuple_GET_ITEM(args, i), &format, p_va,
- levels, msgbuf, sizeof(msgbuf), &freelist);
+ flags, levels, msgbuf,
+ sizeof(msgbuf), &freelist);
if (msg) {
seterror(i+1, msg, levels, fname, message);
return cleanreturn(0, freelist);
@@ -325,8 +373,9 @@
*/
static char *
-converttuple(PyObject *arg, const char **p_format, va_list *p_va, int *levels,
- char *msgbuf, size_t bufsize, int toplevel, PyObject **freelist)
+converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
+ int *levels, char *msgbuf, size_t bufsize, int toplevel,
+ PyObject **freelist)
{
int level = 0;
int n = 0;
@@ -375,8 +424,8 @@
char *msg;
PyObject *item;
item = PySequence_GetItem(arg, i);
- msg = convertitem(item, &format, p_va, levels+1, msgbuf,
- bufsize, freelist);
+ msg = convertitem(item, &format, p_va, flags, levels+1,
+ msgbuf, bufsize, freelist);
/* PySequence_GetItem calls tp->sq_item, which INCREFs */
Py_XDECREF(item);
if (msg != NULL) {
@@ -393,22 +442,22 @@
/* Convert a single item. */
static char *
-convertitem(PyObject *arg, const char **p_format, va_list *p_va, int *levels,
- char *msgbuf, size_t bufsize, PyObject **freelist)
+convertitem(PyObject *arg, const char **p_format, va_list *p_va, int flags,
+ int *levels, char *msgbuf, size_t bufsize, PyObject **freelist)
{
char *msg;
const char *format = *p_format;
if (*format == '(' /* ')' */) {
format++;
- msg = converttuple(arg, &format, p_va, levels, msgbuf,
+ msg = converttuple(arg, &format, p_va, flags, levels, msgbuf,
bufsize, 0, freelist);
if (msg == NULL)
format++;
}
else {
- msg = convertsimple(arg, &format, p_va, msgbuf, bufsize,
- freelist);
+ msg = convertsimple(arg, &format, p_va, flags,
+ msgbuf, bufsize, freelist);
if (msg != NULL)
levels[0] = 0;
}
@@ -460,9 +509,16 @@
*/
static char *
-convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
+convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
char *msgbuf, size_t bufsize, PyObject **freelist)
{
+ /* For # codes */
+#define FETCH_SIZE int *q=NULL;Py_ssize_t *q2=NULL;\
+ if (flags & FLAG_SIZE_T) q2=va_arg(*p_va, Py_ssize_t*); \
+ else q=va_arg(*p_va, int*);
+#define STORE_SIZE(s) if (flags & FLAG_SIZE_T) *q2=s; else *q=s;
+#define BUFFER_LEN ((flags & FLAG_SIZE_T) ? *q2:*q)
+
const char *format = *p_format;
char c = *format++;
#ifdef Py_USING_UNICODE
@@ -544,7 +600,7 @@
*p = (unsigned short) ival;
break;
}
-
+
case 'i': {/* signed int */
int *p = va_arg(*p_va, int *);
long ival;
@@ -582,6 +638,21 @@
break;
}
+ case 'n': /* Py_ssize_t */
+#if SIZEOF_SIZE_T != SIZEOF_LONG
+ {
+ Py_ssize_t *p = va_arg(*p_va, Py_ssize_t *);
+ Py_ssize_t ival;
+ if (float_argument_error(arg))
+ return converterr("integer<i>", arg, msgbuf, bufsize);
+ ival = PyInt_AsSsize_t(arg);
+ if (ival == -1 && PyErr_Occurred())
+ return converterr("integer<i>", arg, msgbuf, bufsize);
+ *p = ival;
+ break;
+ }
+#endif
+ /* Fall through from 'L' to 'l' if Py_ssize_t is int */
case 'l': {/* long int */
long *p = va_arg(*p_va, long *);
long ival;
@@ -679,11 +750,11 @@
case 's': {/* string */
if (*format == '#') {
void **p = (void **)va_arg(*p_va, char **);
- int *q = va_arg(*p_va, int *);
+ FETCH_SIZE;
if (PyString_Check(arg)) {
*p = PyString_AS_STRING(arg);
- *q = PyString_GET_SIZE(arg);
+ STORE_SIZE(PyString_GET_SIZE(arg));
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(arg)) {
@@ -692,15 +763,15 @@
return converterr(CONV_UNICODE,
arg, msgbuf, bufsize);
*p = PyString_AS_STRING(uarg);
- *q = PyString_GET_SIZE(uarg);
+ STORE_SIZE(PyString_GET_SIZE(uarg));
}
#endif
else { /* any buffer-like object */
char *buf;
- int count = convertbuffer(arg, p, &buf);
+ Py_ssize_t count = convertbuffer(arg, p, &buf);
if (count < 0)
return converterr(buf, arg, msgbuf, bufsize);
- *q = count;
+ STORE_SIZE(count);
}
format++;
} else {
@@ -729,15 +800,15 @@
case 'z': {/* string, may be NULL (None) */
if (*format == '#') { /* any buffer-like object */
void **p = (void **)va_arg(*p_va, char **);
- int *q = va_arg(*p_va, int *);
+ FETCH_SIZE;
if (arg == Py_None) {
*p = 0;
- *q = 0;
+ STORE_SIZE(0);
}
else if (PyString_Check(arg)) {
*p = PyString_AS_STRING(arg);
- *q = PyString_GET_SIZE(arg);
+ STORE_SIZE(PyString_GET_SIZE(arg));
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(arg)) {
@@ -746,15 +817,15 @@
return converterr(CONV_UNICODE,
arg, msgbuf, bufsize);
*p = PyString_AS_STRING(uarg);
- *q = PyString_GET_SIZE(uarg);
+ STORE_SIZE(PyString_GET_SIZE(uarg));
}
#endif
else { /* any buffer-like object */
char *buf;
- int count = convertbuffer(arg, p, &buf);
+ Py_ssize_t count = convertbuffer(arg, p, &buf);
if (count < 0)
return converterr(buf, arg, msgbuf, bufsize);
- *q = count;
+ STORE_SIZE(count);
}
format++;
} else {
@@ -777,7 +848,8 @@
return converterr("string or None",
arg, msgbuf, bufsize);
if (*format == '#') {
- int *q = va_arg(*p_va, int *);
+ FETCH_SIZE;
+ assert(0); // redundant with if-case
if (arg == Py_None)
*q = 0;
else
@@ -883,10 +955,10 @@
trailing 0-byte
*/
- int *buffer_len = va_arg(*p_va, int *);
+ FETCH_SIZE;
format++;
- if (buffer_len == NULL) {
+ if (q == NULL && q2 == NULL) {
Py_DECREF(s);
return converterr(
"(buffer_len is NULL)",
@@ -907,7 +979,7 @@
arg, msgbuf, bufsize);
}
} else {
- if (size + 1 > *buffer_len) {
+ if (size + 1 > BUFFER_LEN) {
Py_DECREF(s);
return converterr(
"(buffer overflow)",
@@ -917,7 +989,7 @@
memcpy(*buffer,
PyString_AS_STRING(s),
size + 1);
- *buffer_len = size;
+ STORE_SIZE(size);
} else {
/* Using a 0-terminated buffer:
@@ -961,17 +1033,17 @@
case 'u': {/* raw unicode buffer (Py_UNICODE *) */
if (*format == '#') { /* any buffer-like object */
void **p = (void **)va_arg(*p_va, char **);
- int *q = va_arg(*p_va, int *);
+ FETCH_SIZE;
if (PyUnicode_Check(arg)) {
*p = PyUnicode_AS_UNICODE(arg);
- *q = PyUnicode_GET_SIZE(arg);
+ STORE_SIZE(PyUnicode_GET_SIZE(arg));
}
else {
char *buf;
- int count = convertbuffer(arg, p, &buf);
+ Py_ssize_t count = convertbuffer(arg, p, &buf);
if (count < 0)
return converterr(buf, arg, msgbuf, bufsize);
- *q = count/(sizeof(Py_UNICODE));
+ STORE_SIZE(count/(sizeof(Py_UNICODE)));
}
format++;
} else {
@@ -1061,9 +1133,8 @@
if ((count = pb->bf_getwritebuffer(arg, 0, p)) < 0)
return converterr("(unspecified)", arg, msgbuf, bufsize);
if (*format == '#') {
- int *q = va_arg(*p_va, int *);
-
- *q = count;
+ FETCH_SIZE;
+ STORE_SIZE(count);
format++;
}
break;
@@ -1073,6 +1144,7 @@
const char **p = va_arg(*p_va, const char **);
PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
int count;
+ FETCH_SIZE;
if (*format++ != '#')
return converterr(
@@ -1094,7 +1166,7 @@
count = pb->bf_getcharbuffer(arg, 0, p);
if (count < 0)
return converterr("(unspecified)", arg, msgbuf, bufsize);
- *va_arg(*p_va, int *) = count;
+ STORE_SIZE(count);
break;
}
@@ -1107,11 +1179,11 @@
return NULL;
}
-static int
+static Py_ssize_t
convertbuffer(PyObject *arg, void **p, char **errmsg)
{
PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
- int count;
+ Py_ssize_t count;
if (pb == NULL ||
pb->bf_getreadbuffer == NULL ||
pb->bf_getsegcount == NULL) {
@@ -1151,7 +1223,32 @@
}
va_start(va, kwlist);
- retval = vgetargskeywords(args, keywords, format, kwlist, &va);
+ retval = vgetargskeywords(args, keywords, format, kwlist, &va, 0);
+ va_end(va);
+ return retval;
+}
+
+int
+_PyArg_ParseTupleAndKeywords_SizeT(PyObject *args,
+ PyObject *keywords,
+ const char *format,
+ const char **kwlist, ...)
+{
+ int retval;
+ va_list va;
+
+ if ((args == NULL || !PyTuple_Check(args)) ||
+ (keywords != NULL && !PyDict_Check(keywords)) ||
+ format == NULL ||
+ kwlist == NULL)
+ {
+ PyErr_BadInternalCall();
+ return 0;
+ }
+
+ va_start(va, kwlist);
+ retval = vgetargskeywords(args, keywords, format,
+ kwlist, &va, FLAG_SIZE_T);
va_end(va);
return retval;
}
@@ -1185,14 +1282,47 @@
#endif
#endif
- retval = vgetargskeywords(args, keywords, format, kwlist, &lva);
+ retval = vgetargskeywords(args, keywords, format, kwlist, &lva, 0);
+ return retval;
+}
+
+int
+_PyArg_VaParseTupleAndKeywords_SizeT(PyObject *args,
+ PyObject *keywords,
+ const char *format,
+ const char **kwlist, va_list va)
+{
+ int retval;
+ va_list lva;
+
+ if ((args == NULL || !PyTuple_Check(args)) ||
+ (keywords != NULL && !PyDict_Check(keywords)) ||
+ format == NULL ||
+ kwlist == NULL)
+ {
+ PyErr_BadInternalCall();
+ return 0;
+ }
+
+#ifdef VA_LIST_IS_ARRAY
+ memcpy(lva, va, sizeof(va_list));
+#else
+#ifdef __va_copy
+ __va_copy(lva, va);
+#else
+ lva = va;
+#endif
+#endif
+
+ retval = vgetargskeywords(args, keywords, format,
+ kwlist, &lva, FLAG_SIZE_T);
return retval;
}
static int
vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
- const char **kwlist, va_list *p_va)
+ const char **kwlist, va_list *p_va, int flags)
{
char msgbuf[512];
int levels[32];
@@ -1327,7 +1457,8 @@
if (*format == '|')
format++;
msg = convertitem(PyTuple_GET_ITEM(args, i), &format, p_va,
- levels, msgbuf, sizeof(msgbuf), &freelist);
+ flags, levels, msgbuf, sizeof(msgbuf),
+ &freelist);
if (msg) {
seterror(i+1, msg, levels, fname, message);
return cleanreturn(0, freelist);
@@ -1347,8 +1478,8 @@
item = PyDict_GetItemString(keywords, kwlist[i]);
if (item != NULL) {
Py_INCREF(item);
- msg = convertitem(item, &format, p_va, levels, msgbuf,
- sizeof(msgbuf), &freelist);
+ msg = convertitem(item, &format, p_va, flags, levels,
+ msgbuf, sizeof(msgbuf), &freelist);
Py_DECREF(item);
if (msg) {
seterror(i+1, msg, levels, fname, message);
@@ -1361,7 +1492,7 @@
else if (PyErr_Occurred())
return cleanreturn(0, freelist);
else {
- msg = skipitem(&format, p_va);
+ msg = skipitem(&format, p_va, flags);
if (msg) {
seterror(i+1, msg, levels, fname, message);
return cleanreturn(0, freelist);
@@ -1403,7 +1534,7 @@
static char *
-skipitem(const char **p_format, va_list *p_va)
+skipitem(const char **p_format, va_list *p_va, int flags)
{
const char *format = *p_format;
char c = *format++;
@@ -1435,6 +1566,12 @@
(void) va_arg(*p_va, void *);
break;
}
+
+ case 'n': /* Py_ssize_t */
+ {
+ (void) va_arg(*p_va, Py_ssize_t *);
+ break;
+ }
/* string codes */
@@ -1458,7 +1595,10 @@
{
(void) va_arg(*p_va, char **);
if (*format == '#') {
- (void) va_arg(*p_va, int *);
+ if (flags & FLAG_SIZE_T)
+ (void) va_arg(*p_va, Py_ssize_t *);
+ else
+ (void) va_arg(*p_va, int *);
format++;
}
break;
Modified: python/branches/ssize_t/Python/import.c
==============================================================================
--- python/branches/ssize_t/Python/import.c (original)
+++ python/branches/ssize_t/Python/import.c Sat Dec 17 11:20:15 2005
@@ -688,7 +688,7 @@
Doesn't set an exception. */
static FILE *
-check_compiled_module(char *pathname, long mtime, char *cpathname)
+check_compiled_module(char *pathname, time_t mtime, char *cpathname)
{
FILE *fp;
long magic;
@@ -803,10 +803,11 @@
|O_BINARY /* necessary for Windows */
#endif
#ifdef __VMS
- , 0666, "ctxt=bin", "shr=nil");
+ , 0666, "ctxt=bin", "shr=nil"
#else
- , 0666);
+ , 0666
#endif
+ );
if (fd < 0)
return NULL;
return fdopen(fd, "wb");
@@ -823,7 +824,7 @@
remove the file. */
static void
-write_compiled_module(PyCodeObject *co, char *cpathname, long mtime)
+write_compiled_module(PyCodeObject *co, char *cpathname, time_t mtime)
{
FILE *fp;
@@ -848,6 +849,7 @@
}
/* Now write the true mtime */
fseek(fp, 4L, 0);
+ assert(mtime < LONG_MAX);
PyMarshal_WriteLongToFile(mtime, fp, Py_MARSHAL_VERSION);
fflush(fp);
fclose(fp);
@@ -1059,10 +1061,10 @@
#ifdef MS_COREDLL
extern FILE *PyWin_FindRegisteredModule(const char *, struct filedescr **,
- char *, int);
+ char *, Py_ssize_t);
#endif
-static int case_ok(char *, int, int, char *);
+static int case_ok(char *, Py_ssize_t, Py_ssize_t, char *);
static int find_init_module(char *); /* Forward */
static struct filedescr importhookdescr = {"", "", IMP_HOOK};
@@ -1370,7 +1372,7 @@
return fd->type == PY_SOURCE || fd->type == PY_COMPILED;
}
-/* case_ok(char* buf, int len, int namelen, char* name)
+/* case_ok(char* buf, Py_ssize_t len, Py_ssize_t namelen, char* name)
* The arguments here are tricky, best shown by example:
* /a/b/c/d/e/f/g/h/i/j/k/some_long_module_name.py\0
* ^ ^ ^ ^
@@ -1418,7 +1420,7 @@
#endif
static int
-case_ok(char *buf, int len, int namelen, char *name)
+case_ok(char *buf, Py_ssize_t len, Py_ssize_t namelen, char *name)
{
/* Pick a platform-specific implementation; the sequence of #if's here should
* match the sequence just above.
@@ -1889,12 +1891,12 @@
}
/* Forward declarations for helper routines */
-static PyObject *get_parent(PyObject *globals, char *buf, int *p_buflen);
+static PyObject *get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen);
static PyObject *load_next(PyObject *mod, PyObject *altmod,
- char **p_name, char *buf, int *p_buflen);
+ char **p_name, char *buf, Py_ssize_t *p_buflen);
static int mark_miss(char *name);
static int ensure_fromlist(PyObject *mod, PyObject *fromlist,
- char *buf, int buflen, int recursive);
+ char *buf, Py_ssize_t buflen, int recursive);
static PyObject * import_submodule(PyObject *mod, char *name, char *fullname);
/* The Magnum Opus of dotted-name import :-) */
@@ -1904,7 +1906,7 @@
PyObject *fromlist)
{
char buf[MAXPATHLEN+1];
- int buflen = 0;
+ Py_ssize_t buflen = 0;
PyObject *parent, *head, *next, *tail;
parent = get_parent(globals, buf, &buflen);
@@ -1974,7 +1976,7 @@
corresponding entry is not found in sys.modules, Py_None is returned.
*/
static PyObject *
-get_parent(PyObject *globals, char *buf, int *p_buflen)
+get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen)
{
static PyObject *namestr = NULL;
static PyObject *pathstr = NULL;
@@ -2042,7 +2044,7 @@
/* altmod is either None or same as mod */
static PyObject *
load_next(PyObject *mod, PyObject *altmod, char **p_name, char *buf,
- int *p_buflen)
+ Py_ssize_t *p_buflen)
{
char *name = *p_name;
char *dot = strchr(name, '.');
@@ -2112,7 +2114,7 @@
}
static int
-ensure_fromlist(PyObject *mod, PyObject *fromlist, char *buf, int buflen,
+ensure_fromlist(PyObject *mod, PyObject *fromlist, char *buf, Py_ssize_t buflen,
int recursive)
{
int i;
Modified: python/branches/ssize_t/Python/mactoolboxglue.c
==============================================================================
--- python/branches/ssize_t/Python/mactoolboxglue.c (original)
+++ python/branches/ssize_t/Python/mactoolboxglue.c Sat Dec 17 11:20:15 2005
@@ -363,10 +363,10 @@
\
int routinename(PyObject *pyobj, object *cobj) { \
if (!PyMacGluePtr_##routinename) { \
- if (!PyImport_ImportModule(module)) return NULL; \
+ if (!PyImport_ImportModule(module)) return 0; \
if (!PyMacGluePtr_##routinename) { \
PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \
- return NULL; \
+ return 0; \
} \
} \
return (*PyMacGluePtr_##routinename)(pyobj, cobj); \
Modified: python/branches/ssize_t/Python/marshal.c
==============================================================================
--- python/branches/ssize_t/Python/marshal.c (original)
+++ python/branches/ssize_t/Python/marshal.c Sat Dec 17 11:20:15 2005
@@ -181,7 +181,7 @@
else {
char buf[256]; /* Plenty to format any double */
PyFloat_AsReprString(buf, (PyFloatObject *)v);
- n = strlen(buf);
+ n = (int)strlen(buf);
w_byte(TYPE_FLOAT, p);
w_byte(n, p);
w_string(buf, n, p);
@@ -213,14 +213,14 @@
PyComplex_RealAsDouble(v));
PyFloat_AsReprString(buf, temp);
Py_DECREF(temp);
- n = strlen(buf);
+ n = (int)strlen(buf);
w_byte(n, p);
w_string(buf, n, p);
temp = (PyFloatObject*)PyFloat_FromDouble(
PyComplex_ImagAsDouble(v));
PyFloat_AsReprString(buf, temp);
Py_DECREF(temp);
- n = strlen(buf);
+ n = (int)strlen(buf);
w_byte(n, p);
w_string(buf, n, p);
}
@@ -395,9 +395,10 @@
r_string(char *s, int n, RFILE *p)
{
if (p->fp != NULL)
- return fread(s, 1, n, p->fp);
+ /* The result fits into int because it must be <=n. */
+ return (int)fread(s, 1, n, p->fp);
if (p->end - p->ptr < n)
- n = p->end - p->ptr;
+ n = (int)(p->end - p->ptr);
memcpy(s, p->ptr, n);
p->ptr += n;
return n;
@@ -939,7 +940,10 @@
pBuf = (char *)PyMem_MALLOC(filesize);
if (pBuf != NULL) {
PyObject* v;
- size_t n = fread(pBuf, 1, filesize, fp);
+ size_t n;
+ /* filesize must fit into an int, because it
+ is smaller than REASONABLE_FILE_LIMIT */
+ n = fread(pBuf, 1, (int)filesize, fp);
v = PyMarshal_ReadObjectFromString(pBuf, n);
if (pBuf != buf)
PyMem_FREE(pBuf);
@@ -970,7 +974,7 @@
}
PyObject *
-PyMarshal_ReadObjectFromString(char *str, int len)
+PyMarshal_ReadObjectFromString(char *str, Py_ssize_t len)
{
RFILE rf;
PyObject *result;
Modified: python/branches/ssize_t/Python/modsupport.c
==============================================================================
--- python/branches/ssize_t/Python/modsupport.c (original)
+++ python/branches/ssize_t/Python/modsupport.c Sat Dec 17 11:20:15 2005
@@ -313,6 +313,11 @@
return PyInt_FromLong(n);
}
+ case 'n':
+#if SIZEOF_SIZE_T!=SIZEOF_LONG
+ return PyLong_FromSsize_t(va_arg(*p_va, Py_Ssize_t));
+#endif
+ /* Fall through from 'n' to 'l' if Py_ssize_t is long */
case 'l':
return PyInt_FromLong(va_arg(*p_va, long));
Modified: python/branches/ssize_t/Python/pythonrun.c
==============================================================================
--- python/branches/ssize_t/Python/pythonrun.c (original)
+++ python/branches/ssize_t/Python/pythonrun.c Sat Dec 17 11:20:15 2005
@@ -933,7 +933,7 @@
nl = strchr(text, '\n');
if (nl == NULL || nl-text >= offset)
break;
- offset -= (nl+1-text);
+ offset -= (int)(nl+1-text);
text = nl+1;
}
while (*text == ' ' || *text == '\t') {
Modified: python/branches/ssize_t/Python/sysmodule.c
==============================================================================
--- python/branches/ssize_t/Python/sysmodule.c (original)
+++ python/branches/ssize_t/Python/sysmodule.c Sat Dec 17 11:20:15 2005
@@ -1191,7 +1191,7 @@
if (path != NULL) {
char *argv0 = argv[0];
char *p = NULL;
- int n = 0;
+ Py_ssize_t n = 0;
PyObject *a;
#ifdef HAVE_READLINK
char link[MAXPATHLEN+1];
Modified: python/branches/ssize_t/Python/thread_nt.h
==============================================================================
--- python/branches/ssize_t/Python/thread_nt.h (original)
+++ python/branches/ssize_t/Python/thread_nt.h Sat Dec 17 11:20:15 2005
@@ -170,7 +170,7 @@
long
PyThread_start_new_thread(void (*func)(void *), void *arg)
{
- unsigned long rv;
+ uintptr_t rv;
callobj obj;
dprintf(("%ld: PyThread_start_new_thread called\n",
@@ -186,7 +186,7 @@
return -1;
rv = _beginthread(bootstrap, 0, &obj); /* use default stack size */
- if (rv == (unsigned long)-1) {
+ if (rv == (uintptr_t)-1) {
/* I've seen errno == EAGAIN here, which means "there are
* too many threads".
*/
Modified: python/branches/ssize_t/configure
==============================================================================
--- python/branches/ssize_t/configure (original)
+++ python/branches/ssize_t/configure Sat Dec 17 11:20:15 2005
@@ -1,5 +1,5 @@
#! /bin/sh
-# From configure.in Revision: 39267 .
+# From configure.in Revision: 41695 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.59 for python 2.5.
#
@@ -6077,6 +6077,70 @@
fi
+echo "$as_me:$LINENO: checking for ssize_t" >&5
+echo $ECHO_N "checking for ssize_t... $ECHO_C" >&6
+if test "${ac_cv_type_ssize_t+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+if ((ssize_t *) 0)
+ return 0;
+if (sizeof (ssize_t))
+ return 0;
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_type_ssize_t=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_type_ssize_t=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type_ssize_t" >&5
+echo "${ECHO_T}$ac_cv_type_ssize_t" >&6
+if test $ac_cv_type_ssize_t = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_SSIZE_T 1
+_ACEOF
+
+fi
+
# Sizes of various common basic types
# ANSI C requires sizeof(char) == 1, so no need to check it
@@ -8978,6 +9042,420 @@
_ACEOF
+echo "$as_me:$LINENO: checking for size_t" >&5
+echo $ECHO_N "checking for size_t... $ECHO_C" >&6
+if test "${ac_cv_type_size_t+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+if ((size_t *) 0)
+ return 0;
+if (sizeof (size_t))
+ return 0;
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_type_size_t=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_type_size_t=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type_size_t" >&5
+echo "${ECHO_T}$ac_cv_type_size_t" >&6
+
+echo "$as_me:$LINENO: checking size of size_t" >&5
+echo $ECHO_N "checking size of size_t... $ECHO_C" >&6
+if test "${ac_cv_sizeof_size_t+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if test "$ac_cv_type_size_t" = yes; then
+ # The cast to unsigned long works around a bug in the HP C Compiler
+ # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
+ # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
+ # This bug is HP SR number 8606223364.
+ if test "$cross_compiling" = yes; then
+ # Depending upon the size, compute the lo and hi bounds.
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (size_t))) >= 0)];
+test_array [0] = 0
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_lo=0 ac_mid=0
+ while :; do
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (size_t))) <= $ac_mid)];
+test_array [0] = 0
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_hi=$ac_mid; break
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_lo=`expr $ac_mid + 1`
+ if test $ac_lo -le $ac_mid; then
+ ac_lo= ac_hi=
+ break
+ fi
+ ac_mid=`expr 2 '*' $ac_mid + 1`
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ done
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (size_t))) < 0)];
+test_array [0] = 0
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_hi=-1 ac_mid=-1
+ while :; do
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (size_t))) >= $ac_mid)];
+test_array [0] = 0
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_lo=$ac_mid; break
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_hi=`expr '(' $ac_mid ')' - 1`
+ if test $ac_mid -le $ac_hi; then
+ ac_lo= ac_hi=
+ break
+ fi
+ ac_mid=`expr 2 '*' $ac_mid`
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ done
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_lo= ac_hi=
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+# Binary search between lo and hi bounds.
+while test "x$ac_lo" != "x$ac_hi"; do
+ ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo`
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (size_t))) <= $ac_mid)];
+test_array [0] = 0
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_hi=$ac_mid
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_lo=`expr '(' $ac_mid ')' + 1`
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+case $ac_lo in
+?*) ac_cv_sizeof_size_t=$ac_lo;;
+'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (size_t), 77
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute sizeof (size_t), 77
+See \`config.log' for more details." >&2;}
+ { (exit 1); exit 1; }; } ;;
+esac
+else
+ if test "$cross_compiling" = yes; then
+ { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&2;}
+ { (exit 1); exit 1; }; }
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+long longval () { return (long) (sizeof (size_t)); }
+unsigned long ulongval () { return (long) (sizeof (size_t)); }
+#include <stdio.h>
+#include <stdlib.h>
+int
+main ()
+{
+
+ FILE *f = fopen ("conftest.val", "w");
+ if (! f)
+ exit (1);
+ if (((long) (sizeof (size_t))) < 0)
+ {
+ long i = longval ();
+ if (i != ((long) (sizeof (size_t))))
+ exit (1);
+ fprintf (f, "%ld\n", i);
+ }
+ else
+ {
+ unsigned long i = ulongval ();
+ if (i != ((long) (sizeof (size_t))))
+ exit (1);
+ fprintf (f, "%lu\n", i);
+ }
+ exit (ferror (f) || fclose (f) != 0);
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_sizeof_size_t=`cat conftest.val`
+else
+ echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+{ { echo "$as_me:$LINENO: error: cannot compute sizeof (size_t), 77
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute sizeof (size_t), 77
+See \`config.log' for more details." >&2;}
+ { (exit 1); exit 1; }; }
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+rm -f conftest.val
+else
+ ac_cv_sizeof_size_t=0
+fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_sizeof_size_t" >&5
+echo "${ECHO_T}$ac_cv_sizeof_size_t" >&6
+cat >>confdefs.h <<_ACEOF
+#define SIZEOF_SIZE_T $ac_cv_sizeof_size_t
+_ACEOF
+
+
echo "$as_me:$LINENO: checking for long long support" >&5
echo $ECHO_N "checking for long long support... $ECHO_C" >&6
Modified: python/branches/ssize_t/configure.in
==============================================================================
--- python/branches/ssize_t/configure.in (original)
+++ python/branches/ssize_t/configure.in Sat Dec 17 11:20:15 2005
@@ -1073,6 +1073,8 @@
AC_TYPE_SIGNAL
AC_TYPE_SIZE_T
AC_TYPE_UID_T
+AC_CHECK_TYPE(ssize_t,
+ AC_DEFINE(HAVE_SSIZE_T, 1, Define if your compiler provides ssize_t),,)
# Sizes of various common basic types
# ANSI C requires sizeof(char) == 1, so no need to check it
@@ -1083,6 +1085,7 @@
AC_CHECK_SIZEOF(float, 4)
AC_CHECK_SIZEOF(double, 8)
AC_CHECK_SIZEOF(fpos_t, 4)
+AC_CHECK_SIZEOF(size_t, 4)
AC_MSG_CHECKING(for long long support)
have_long_long=no
Modified: python/branches/ssize_t/pyconfig.h.in
==============================================================================
--- python/branches/ssize_t/pyconfig.h.in (original)
+++ python/branches/ssize_t/pyconfig.h.in Sat Dec 17 11:20:15 2005
@@ -449,6 +449,9 @@
/* Define if you have the 'socketpair' function. */
#undef HAVE_SOCKETPAIR
+/* Define if your compiler provides ssize_t */
+#undef HAVE_SSIZE_T
+
/* Define to 1 if you have the `statvfs' function. */
#undef HAVE_STATVFS
@@ -757,6 +760,9 @@
/* The size of a `short', as computed by sizeof. */
#undef SIZEOF_SHORT
+/* The size of a `size_t', as computed by sizeof. */
+#undef SIZEOF_SIZE_T
+
/* The number of bytes in a time_t. */
#undef SIZEOF_TIME_T
More information about the Python-checkins
mailing list