equivalent to the Python expression: type(o).
*/
- PyAPI_FUNC(int) PyObject_Size(PyObject *o);
+ PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o);
/*
Return the size of object o. If the object, o, provides
/* For DLL compatibility */
#undef PyObject_Length
- PyAPI_FUNC(int) PyObject_Length(PyObject *o);
+ PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);
#define PyObject_Length PyObject_Size
- PyAPI_FUNC(int) _PyObject_LengthHint(PyObject *o);
+ PyAPI_FUNC(Py_ssize_t) _PyObject_LengthHint(PyObject *o);
/*
Return the size of object o. If the object, o, provides
PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
const char **buffer,
- int *buffer_len);
+ Py_ssize_t *buffer_len);
/*
Takes an arbitrary object which must support the (character,
PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
const void **buffer,
- int *buffer_len);
+ Py_ssize_t *buffer_len);
/*
Same as PyObject_AsCharBuffer() except that this API expects
PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
void **buffer,
- int *buffer_len);
+ Py_ssize_t *buffer_len);
/*
Takes an arbitrary object which must support the (writeable,
*/
- PyAPI_FUNC(int) PySequence_Size(PyObject *o);
+ PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o);
/*
Return the size of sequence object o, or -1 on failure.
/* For DLL compatibility */
#undef PySequence_Length
- PyAPI_FUNC(int) PySequence_Length(PyObject *o);
+ PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o);
#define PySequence_Length PySequence_Size
*/
- 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,
*/
- 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
*/
- 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
*/
- 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
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);
/*
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.
*/
- 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
This function always succeeds.
*/
- PyAPI_FUNC(int) PyMapping_Size(PyObject *o);
+ PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o);
/*
Returns the number of keys in object o on success, and -1 on
/* For DLL compatibility */
#undef PyMapping_Length
- PyAPI_FUNC(int) PyMapping_Length(PyObject *o);
+ PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o);
#define PyMapping_Length PyMapping_Size
#define Py_END_OF_BUFFER (-1)
PyAPI_FUNC(PyObject *) PyBuffer_FromObject(PyObject *base,
- int offset, int size);
+ Py_ssize_t offset, Py_ssize_t size);
PyAPI_FUNC(PyObject *) PyBuffer_FromReadWriteObject(PyObject *base,
- int offset,
- int size);
+ Py_ssize_t offset,
+ 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);
+PyAPI_FUNC(PyObject *) PyBuffer_New(Py_ssize_t size);
#ifdef __cplusplus
}
/* Read a string from an input object. If the last argument
is -1, the remainder will be read.
*/
- int(*cread)(PyObject *, char **, int);
+ int(*cread)(PyObject *, char **, Py_ssize_t);
/* Read a line from an input object. Returns the length of the read
line as an int and a pointer inside the object buffer as char** (so
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 *);
#endif /* !WITH_THREAD */
-PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, int *);
+PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
#ifdef __cplusplus
PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key);
PyAPI_FUNC(void) PyDict_Clear(PyObject *mp);
PyAPI_FUNC(int) PyDict_Next(
- PyObject *mp, int *pos, PyObject **key, PyObject **value);
+ PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value);
PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp);
PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp);
PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp);
-PyAPI_FUNC(int) PyDict_Size(PyObject *mp);
+PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp);
PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp);
PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key);
PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);
#ifdef Py_USING_UNICODE
-PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, int, int);
+PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
#endif
PyAPI_FUNC(PyObject *) PyInt_FromLong(long);
+PyAPI_FUNC(PyObject *) PyInt_FromSize_t(size_t);
+PyAPI_FUNC(PyObject *) PyInt_FromSsize_t(Py_ssize_t);
PyAPI_FUNC(long) PyInt_AsLong(PyObject *);
+PyAPI_FUNC(Py_ssize_t) PyInt_AsSsize_t(PyObject *);
PyAPI_FUNC(unsigned long) PyInt_AsUnsignedLongMask(PyObject *);
#ifdef HAVE_LONG_LONG
PyAPI_FUNC(unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *);
* Items must normally not be NULL, except during construction when
* the list is not yet visible outside the function that builds it.
*/
- int allocated;
+ Py_ssize_t allocated;
} PyListObject;
PyAPI_DATA(PyTypeObject) PyList_Type;
#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 *);
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);
PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);
PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
+/* For use by intobject.c only */
+PyAPI_FUNC(Py_ssize_t) _PyLong_AsSsize_t(PyObject *);
+PyAPI_FUNC(PyObject *) _PyLong_FromSize_t(size_t);
+PyAPI_FUNC(PyObject *) _PyLong_FromSsize_t(Py_ssize_t);
+
/* _PyLong_AsScaledDouble returns a double x and an exponent e such that
the true value is approximately equal to x * 2**(SHIFT*e). e is >= 0.
x is 0.0 if and only if the input is 0 (in which case, e and x are both
PyAPI_FUNC(PyObject *) PyLong_FromString(char *, char **, int);
#ifdef Py_USING_UNICODE
-PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, int, int);
+PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
#endif
/* _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
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
}
#include <stdarg.h>
+/* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier
+ to mean Py_ssize_t */
+#ifdef PY_SSIZE_T_CLEAN
+#define PyArg_Parse _PyArg_Parse_SizeT
+#define PyArg_ParseTuple _PyArg_ParseTuple_SizeT
+#define PyArg_ParseTupleAndKeywords _PyArg_ParseTupleAndKeywords_SizeT
+#define PyArg_VaParse _PyArg_VaParse_SizeT
+#define PyArg_VaParseTupleAndKeywords _PyArg_VaParseTupleAndKeywords_SizeT
+#define PyArg_BuildValue _PyArg_BuildValue_SizeT
+#define PyArg_VaBuildValue _PyArg_VaBuildValue_SizeT
+#endif
+
PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);
PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...);
PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
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)
without actually needing a recompile. */
#endif /* MS_WINDOWS */
+#if SIZEOF_SIZE_T != SIZEOF_INT
+/* On a 64-bit system, rename the Py_InitModule4 so that 2.4
+ modules cannot get loaded into a 2.5 interpreter */
+#define Py_InitModule4 Py_InitModule4_64
+#endif
+
#ifdef Py_TRACE_REFS
-/* When we are tracing reference counts, rename Py_InitModule4 so
- modules compiled with incompatible settings will generate a
- link-time error. */
-#define Py_InitModule4 Py_InitModule4TraceRefs
+ /* When we are tracing reference counts, rename Py_InitModule4 so
+ modules compiled with incompatible settings will generate a
+ link-time error. */
+ #if SIZEOF_SIZE_T != SIZEOF_INT
+ #undef Py_InitModule4
+ #define Py_InitModule4 Py_InitModule4TraceRefs_64
+ #else
+ #define Py_InitModule4 Py_InitModule4TraceRefs
+ #endif
#endif
PyAPI_FUNC(PyObject *) Py_InitModule4(const char *name, PyMethodDef *methods,
*/
#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
typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
typedef int (*inquiry)(PyObject *);
+typedef Py_ssize_t (*lenfunc)(PyObject *);
typedef int (*coercion)(PyObject **, PyObject **);
-typedef PyObject *(*intargfunc)(PyObject *, int);
-typedef PyObject *(*intintargfunc)(PyObject *, int, int);
+typedef PyObject *(*intargfunc)(PyObject *, int) Py_DEPRECATED(2.5);
+typedef PyObject *(*intintargfunc)(PyObject *, int, int) Py_DEPRECATED(2.5);
+typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
+typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
typedef int(*intobjargproc)(PyObject *, int, PyObject *);
typedef int(*intintobjargproc)(PyObject *, int, int, PyObject *);
+typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
+typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
+
+/* int-based buffer interface */
typedef int (*getreadbufferproc)(PyObject *, int, void **);
typedef int (*getwritebufferproc)(PyObject *, int, void **);
typedef int (*getsegcountproc)(PyObject *, int *);
typedef int (*getcharbufferproc)(PyObject *, int, const char **);
+/* ssize_t-based buffer interface */
+typedef Py_ssize_t (*readbufferproc)(PyObject *, Py_ssize_t, void **);
+typedef Py_ssize_t (*writebufferproc)(PyObject *, Py_ssize_t, void **);
+typedef Py_ssize_t (*segcountproc)(PyObject *, Py_ssize_t *);
+typedef Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, const char **);
+
typedef int (*objobjproc)(PyObject *, PyObject *);
typedef int (*visitproc)(PyObject *, void *);
typedef int (*traverseproc)(PyObject *, visitproc, void *);
} PyNumberMethods;
typedef struct {
- inquiry sq_length;
+ lenfunc sq_length;
binaryfunc sq_concat;
- intargfunc sq_repeat;
- intargfunc sq_item;
- intintargfunc sq_slice;
- intobjargproc sq_ass_item;
- intintobjargproc sq_ass_slice;
+ ssizeargfunc sq_repeat;
+ ssizeargfunc sq_item;
+ ssizessizeargfunc sq_slice;
+ ssizeobjargproc sq_ass_item;
+ ssizessizeobjargproc sq_ass_slice;
objobjproc sq_contains;
/* Added in release 2.0 */
binaryfunc sq_inplace_concat;
- intargfunc sq_inplace_repeat;
+ ssizeargfunc sq_inplace_repeat;
} PySequenceMethods;
typedef struct {
- inquiry mp_length;
+ lenfunc mp_length;
binaryfunc mp_subscript;
objobjargproc mp_ass_subscript;
} PyMappingMethods;
typedef struct {
- getreadbufferproc bf_getreadbuffer;
- getwritebufferproc bf_getwritebuffer;
- getsegcountproc bf_getsegcount;
- getcharbufferproc bf_getcharbuffer;
+ readbufferproc bf_getreadbuffer;
+ writebufferproc bf_getwritebuffer;
+ segcountproc bf_getsegcount;
+ charbufferproc bf_getcharbuffer;
} PyBufferProcs;
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
#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 *);
/* 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) )
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 *);
/* 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 *);
/* 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 *);
# 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" */
PyAPI_FUNC(double) PyOS_ascii_strtod(const char *str, char **ptr);
PyAPI_FUNC(double) PyOS_ascii_atof(const char *str);
-PyAPI_FUNC(char *) PyOS_ascii_formatd(char *buffer, int buf_len, const char *format, double d);
+PyAPI_FUNC(char *) PyOS_ascii_formatd(char *buffer, size_t buf_len, const char *format, double d);
#ifdef __cplusplus
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
}
#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)));
PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)
Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
-PyAPI_FUNC(int) PyString_Size(PyObject *);
+PyAPI_FUNC(Py_ssize_t) PyString_Size(PyObject *);
PyAPI_FUNC(char *) PyString_AsString(PyObject *);
PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);
PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);
PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);
-PyAPI_FUNC(int) _PyString_Resize(PyObject **, 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 **);
PyAPI_FUNC(PyObject*) PyString_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 */
);
PyAPI_FUNC(PyObject*) PyString_Encode(
const char *s, /* string char buffer */
- int size, /* number of chars to encode */
+ Py_ssize_t size, /* number of chars to encode */
const char *encoding, /* encoding */
const char *errors /* error handling */
);
PyAPI_FUNC(int) PyString_AsStringAndSize(
register PyObject *obj, /* string or Unicode object */
register char **s, /* pointer to buffer variable */
- register int *len /* pointer to length variable or NULL
+ register Py_ssize_t *len /* pointer to length variable or NULL
(only possible for 0-terminated
strings) */
);
#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(int) _PyTuple_Resize(PyObject **, int);
-PyAPI_FUNC(PyObject *) PyTuple_Pack(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 **, Py_ssize_t);
+PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...);
/* Macro, trading safety for speed */
#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
typedef struct {
PyObject_HEAD
- int length; /* Length of raw Unicode data in buffer */
+ Py_ssize_t length; /* Length of raw Unicode data in buffer */
Py_UNICODE *str; /* Raw Unicode buffer */
long hash; /* Hash value; -1 if not set */
PyObject *defenc; /* (Default) Encoded version as Python
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
/* Get the length of the Unicode object. */
-PyAPI_FUNC(int) PyUnicode_GetSize(
+PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(
PyObject *unicode /* Unicode object */
);
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
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
possibly trailing 0-termination character) or -1 in case of an
error. */
-PyAPI_FUNC(int) PyUnicode_AsWideChar(
+PyAPI_FUNC(Py_ssize_t) PyUnicode_AsWideChar(
PyUnicodeObject *unicode, /* Unicode object */
register wchar_t *w, /* wchar_t buffer */
- int size /* size of buffer */
+ Py_ssize_t size /* size of buffer */
);
#endif
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 */
);
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 */
);
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,
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(
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 */
);
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
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
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 */
);
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 */
);
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 */
);
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 ---------------------------------------------
PyObject *_PyUnicode_DecodeUnicodeInternal(
const char *string,
- int length,
+ Py_ssize_t length,
const char *errors
);
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 */
);
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 */
);
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 */
);
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 */
);
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 */
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 */
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 */
);
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 */
);
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 */
);
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 */
);
PyAPI_FUNC(PyObject*) PyUnicode_Split(
PyObject *s, /* String to split */
PyObject *sep, /* String separator */
- int maxsplit /* Maxsplit count */
+ Py_ssize_t maxsplit /* Maxsplit count */
);
/* Dito, but split at line breaks.
PyAPI_FUNC(PyObject*) PyUnicode_RSplit(
PyObject *s, /* String to split */
PyObject *sep, /* String separator */
- int maxsplit /* Maxsplit count */
+ Py_ssize_t maxsplit /* Maxsplit count */
);
/* Translate a string by applying a character mapping table to it and
/* Return 1 if substr matches str[start:end] at the given tail end, 0
otherwise. */
-PyAPI_FUNC(int) PyUnicode_Tailmatch(
+PyAPI_FUNC(Py_ssize_t) PyUnicode_Tailmatch(
PyObject *str, /* String */
PyObject *substr, /* Prefix or Suffix string */
- int start, /* Start index */
- int end, /* Stop index */
+ Py_ssize_t start, /* Start index */
+ Py_ssize_t end, /* Stop index */
int direction /* Tail end: -1 prefix, +1 suffix */
);
given search direction or -1 if not found. -2 is returned in case
an error occurred and an exception is set. */
-PyAPI_FUNC(int) PyUnicode_Find(
+PyAPI_FUNC(Py_ssize_t) PyUnicode_Find(
PyObject *str, /* String */
PyObject *substr, /* Substring to find */
- int start, /* Start index */
- int end, /* Stop index */
+ Py_ssize_t start, /* Start index */
+ Py_ssize_t end, /* Stop index */
int direction /* Find direction: +1 forward, -1 backward */
);
/* Count the number of occurrences of substr in str[start:end]. */
-PyAPI_FUNC(int) PyUnicode_Count(
+PyAPI_FUNC(Py_ssize_t) PyUnicode_Count(
PyObject *str, /* String */
PyObject *substr, /* Substring to count */
- int start, /* Start index */
- int end /* Stop index */
+ Py_ssize_t start, /* Start index */
+ Py_ssize_t end /* Stop index */
);
/* Replace at most maxcount occurrences of substr in str with replstr
PyObject *str, /* String */
PyObject *substr, /* Substring to find */
PyObject *replstr, /* Substring to replace */
- int maxcount /* Max. number of replacements to apply;
+ Py_ssize_t maxcount /* Max. number of replacements to apply;
-1 = all */
);
self.checkequal('abcabcabc', 'abc', '__mul__', 3)
self.checkraises(TypeError, 'abc', '__mul__')
self.checkraises(TypeError, 'abc', '__mul__', '')
- self.checkraises(OverflowError, 10000*'abc', '__mul__', 2000000000)
+ # XXX: on a 64-bit system, this doesn't raise an overflow error,
+ # but either raises a MemoryError, or succeeds (if you have 54TiB)
+ #self.checkraises(OverflowError, 10000*'abc', '__mul__', 2000000000)
def test_join(self):
# join now works with any sequence type
Core and builtins
-----------------
+- PEP 353: Using ssize_t as the index type.
+
- Patch #1400181, fix unicode string formatting to not use the locale.
This is how string objects work. u'%f' could use , instead of .
for the decimal point. Now both strings and unicode always use periods.
}
else if (PyString_Check(result)) {
char* data;
- int size;
+ Py_ssize_t size;
CLEAR_DBT(*secKey);
#if PYTHON_API_VERSION <= 1007
/*-------------------------------------------------------------- */
/* Mapping and Dictionary-like access routines */
-int DB_length(DBObject* self)
+Py_ssize_t DB_length(DBObject* self)
{
int err;
long size = 0;
static PyMappingMethods DB_mapping = {
- (inquiry)DB_length, /*mp_length*/
+ (lenfunc)DB_length, /*mp_length*/
(binaryfunc)DB_subscript, /*mp_subscript*/
(objobjargproc)DB_ass_sub, /*mp_ass_subscript*/
};
------------------------------------------------------------------------ */
+#define PY_SSIZE_T_CLEAN
#include "Python.h"
/* --- Registry ----------------------------------------------------------- */
{
const char *errors = NULL;
const char *data;
- int size;
+ Py_ssize_t size;
if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
&data, &size, &errors))
PyObject *obj;
const char *errors = NULL;
const char *data;
- int size;
+ Py_ssize_t size;
if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode",
&obj, &errors))
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:utf_7_decode",
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t 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,
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
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);
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
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);
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
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);
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
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);
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:unicode_escape_decode",
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:raw_unicode_escape_decode",
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:latin_1_decode",
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:ascii_decode",
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
PyObject *mapping = NULL;
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:mbcs_decode",
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "s#|z:readbuffer_encode",
PyObject *args)
{
const char *data;
- int size;
+ Py_ssize_t size;
const char *errors = NULL;
if (!PyArg_ParseTuple(args, "t#|z:charbuffer_encode",
PyObject *obj;
const char *errors = NULL;
const char *data;
- int size;
+ Py_ssize_t size;
if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode",
&obj, &errors))
#endif
/* compatibility macros */
+#if (PY_VERSION_HEX < 0x02050000)
+typedef int Py_ssize_t;
+#endif
#if (PY_VERSION_HEX < 0x02040000)
#define PyDict_CheckExact PyDict_Check
#if (PY_VERSION_HEX < 0x02020000)
}
static PyObject*
-element_getitem(ElementObject* self, int index)
+element_getitem(PyObject* _self, Py_ssize_t index)
{
+ ElementObject* self = (ElementObject*)_self;
if (!self->extra || index < 0 || index >= self->extra->length) {
PyErr_SetString(
PyExc_IndexError,
}
static PyObject*
-element_getslice(ElementObject* self, int start, int end)
+element_getslice(PyObject* _self, Py_ssize_t start, Py_ssize_t end)
{
- int i;
+ ElementObject* self = (ElementObject*)_self;
+ Py_ssize_t i;
PyObject* list;
if (!self->extra)
return PyDict_Keys(self->extra->attrib);
}
-static int
+static Py_ssize_t
element_length(ElementObject* self)
{
if (!self->extra)
}
static int
-element_setslice(ElementObject* self, int start, int end, PyObject* item)
+element_setslice(PyObject* _self, Py_ssize_t start, Py_ssize_t end, PyObject* item)
{
+ ElementObject* self = (ElementObject*)_self;
int i, new, old;
PyObject* recycle = NULL;
}
static int
-element_setitem(ElementObject* self, int index, PyObject* item)
+element_setitem(PyObject* _self, Py_ssize_t index, PyObject* item)
{
+ ElementObject* self = (ElementObject*)_self;
int i;
PyObject* old;
}
static PySequenceMethods element_as_sequence = {
- (inquiry) element_length,
+ (lenfunc) element_length,
0, /* sq_concat */
0, /* sq_repeat */
- (intargfunc) element_getitem,
- (intintargfunc) element_getslice,
- (intobjargproc) element_setitem,
- (intintobjargproc) element_setslice,
+ element_getitem,
+ element_getslice,
+ element_setitem,
+ element_setslice,
};
statichere PyTypeObject Element_Type = {
PyObject_HEAD
PyObject *filemap;
PyObject *logfilename;
- int index;
+ Py_ssize_t index;
unsigned char buffer[BUFFERSIZE];
FILE *logfp;
int lineevents;
}
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()) {
}
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;
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)
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)
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)
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 */
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);
}
static int
test_dict_inner(int count)
{
- int pos = 0, iterations = 0, i;
+ Py_ssize_t pos = 0, iterations = 0;
+ int i;
PyObject *dict = PyDict_New();
PyObject *v, *k;
/* 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_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
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;
#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;
****************************************************************************/
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))
}
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)
}
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
}
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 */
#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;
#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 */
}
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
}
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 */
}
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)) {
}
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))
}
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)) {
}
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))
}
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))
****************************************************************************/
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;
}
static PyObject *
-getarrayitem(PyObject *op, int i)
+getarrayitem(PyObject *op, Py_ssize_t i)
{
register arrayobject *ap;
assert(array_Check(op));
}
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;
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)) {
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;
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");
}
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)
static PyObject *
array_concat(arrayobject *a, PyObject *bb)
{
- int size;
+ Py_ssize_t size;
arrayobject *np;
if (!array_Check(bb)) {
PyErr_Format(PyExc_TypeError,
}
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;
}
static int
-array_ass_item(arrayobject *a, int i, PyObject *v)
+array_ass_item(arrayobject *a, Py_ssize_t i, PyObject *v)
{
if (i < 0 || i >= a->ob_size) {
PyErr_SetString(PyExc_IndexError,
}
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);
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);
}
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)
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;
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);
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,
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);
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);
array_byteswap(arrayobject *self, PyObject *unused)
{
char *p;
- int i;
+ Py_ssize_t i;
switch (self->ob_descr->itemsize) {
case 1:
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 */
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;
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");
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();
array_tolist(arrayobject *self, PyObject *unused)
{
PyObject *list = PyList_New(self->ob_size);
- int i;
+ Py_ssize_t i;
if (list == NULL)
return NULL;
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;
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;
{
char buf[256], typecode;
PyObject *s, *t, *v = NULL;
- int len;
+ Py_ssize_t len;
len = a->ob_size;
typecode = a->ob_descr->typecode;
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;
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,
if (value == NULL) {
/* delete slice */
- int cur, i, extra;
+ Py_ssize_t cur, i, extra;
if (slicelength <= 0)
return 0;
}
else {
/* assign slice */
- int cur, i;
+ Py_ssize_t cur, i;
arrayobject* av;
if (!array_Check(value)) {
if (av->ob_size != slicelength) {
PyErr_Format(PyExc_ValueError,
- "attempt to assign array of size %d to extended slice of size %d",
- av->ob_size, slicelength);
+ "attempt to assign array of size %ld to extended slice of size %ld",
+ /*XXX*/(long)av->ob_size, /*XXX*/(long)slicelength);
return -1;
}
}
static PyMappingMethods array_as_mapping = {
- (inquiry)array_length,
+ (lenfunc)array_length,
(binaryfunc)array_subscr,
(objobjargproc)array_ass_subscr
};
-static int
-array_buffer_getreadbuf(arrayobject *self, int index, const void **ptr)
+static Py_ssize_t
+array_buffer_getreadbuf(arrayobject *self, Py_ssize_t index, const void **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
return self->ob_size*self->ob_descr->itemsize;
}
-static int
-array_buffer_getwritebuf(arrayobject *self, int index, const void **ptr)
+static Py_ssize_t
+array_buffer_getwritebuf(arrayobject *self, Py_ssize_t index, const void **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
return self->ob_size*self->ob_descr->itemsize;
}
-static int
-array_buffer_getsegcount(arrayobject *self, int *lenp)
+static Py_ssize_t
+array_buffer_getsegcount(arrayobject *self, Py_ssize_t *lenp)
{
if ( lenp )
*lenp = self->ob_size*self->ob_descr->itemsize;
}
static PySequenceMethods array_as_sequence = {
- (inquiry)array_length, /*sq_length*/
+ (lenfunc)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*/
+ (ssizeobjargproc)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 = {
- (getreadbufferproc)array_buffer_getreadbuf,
- (getwritebufferproc)array_buffer_getwritebuf,
- (getsegcountproc)array_buffer_getsegcount,
+ (readbufferproc)array_buffer_getreadbuf,
+ (writebufferproc)array_buffer_getwritebuf,
+ (segcountproc)array_buffer_getsegcount,
};
static PyObject *
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)))
return NULL;
if (len > 0) {
- int i;
+ Py_ssize_t i;
for (i = 0; i < len; i++) {
PyObject *v =
PySequence_GetItem(initial, i);
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;
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;
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);
#define BSDDB_END_SAVE(_dp) Py_END_ALLOW_THREADS
#endif
-static int
+static Py_ssize_t
bsddb_length(bsddbobject *dp)
{
check_bsddbobject_open(dp, -1);
}
static PyMappingMethods bsddb_as_mapping = {
- (inquiry)bsddb_length, /*mp_length*/
+ (lenfunc)bsddb_length, /*mp_length*/
(binaryfunc)bsddb_subscript, /*mp_subscript*/
(objobjargproc)bsddb_ass_sub, /*mp_ass_subscript*/
};
PyObject *v = PyList_GET_ITEM(list, i);
if (!PyString_Check(v)) {
const char *buffer;
- int len;
+ Py_ssize_t len;
if (PyObject_AsCharBuffer(v, &buffer, &len)) {
PyErr_SetString(PyExc_TypeError,
"writelines() "
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;
int *marks;
int num_marks;
int marks_size;
- int (*read_func)(struct Unpicklerobject *, char **, int);
- int (*readline_func)(struct Unpicklerobject *, char **);
+ Py_ssize_t (*read_func)(struct Unpicklerobject *, char **, Py_ssize_t);
+ Py_ssize_t (*readline_func)(struct Unpicklerobject *, char **);
int buf_size;
char *buf;
PyObject *find_class;
}
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;
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
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;
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,
}
-static int
-read_file(Unpicklerobject *self, char **s, int n)
+static Py_ssize_t
+read_file(Unpicklerobject *self, char **s, Py_ssize_t n)
{
size_t nbytesread;
}
-static int
+static Py_ssize_t
readline_file(Unpicklerobject *self, char **s)
{
int i;
}
-static int
-read_cStringIO(Unpicklerobject *self, char **s, int n)
+static Py_ssize_t
+read_cStringIO(Unpicklerobject *self, char **s, Py_ssize_t n)
{
char *ptr;
}
-static int
+static Py_ssize_t
readline_cStringIO(Unpicklerobject *self, char **s)
{
- int n;
+ Py_ssize_t n;
char *ptr;
if ((n = PycStringIO->creadline((PyObject *)self->file, &ptr)) < 0) {
}
-static int
-read_other(Unpicklerobject *self, char **s, int n)
+static Py_ssize_t
+read_other(Unpicklerobject *self, char **s, Py_ssize_t n)
{
PyObject *bytes, *str=0;
- if (!( bytes = PyInt_FromLong(n))) return -1;
+ if (!( bytes = PyInt_FromSsize_t(n))) return -1;
ARG_TUP(self, bytes);
if (self->arg) {
}
-static int
+static Py_ssize_t
readline_other(Unpicklerobject *self, char **s)
{
PyObject *str;
- int str_size;
+ Py_ssize_t str_size;
if (!( str = PyObject_CallObject(self->readline, empty_tuple))) {
return -1;
static PyObject *
whichmodule(PyObject *global, PyObject *global_name)
{
- int i, j;
+ Py_ssize_t i, j;
PyObject *module = 0, *modules_dict = 0,
*global_name_attr = 0, *name = 0;
static int
load_counted_long(Unpicklerobject *self, int size)
{
- int i;
+ Py_ssize_t i;
char *nbytes;
unsigned char *pdata;
PyObject *along;
PyObject *state, *inst, *slotstate;
PyObject *__setstate__;
PyObject *d_key, *d_value;
- int i;
+ Py_ssize_t i;
int res = -1;
/* Stack is ... instance, state. We want to leave instance at
initcPickle(void)
{
PyObject *m, *d, *di, *v, *k;
- int i;
+ Py_ssize_t i;
char *rev = "1.71"; /* XXX when does this change? */
PyObject *format_version;
PyObject *compatible_formats;
typedef struct {
PyObject_HEAD
char *buf;
- int pos, string_size;
+ Py_ssize_t pos, string_size;
} IOobject;
#define IOOOBJECT(O) ((IOobject*)(O))
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 */
typedef struct { /* Subtype of IOobject */
PyObject_HEAD
char *buf;
- int pos, string_size;
+ Py_ssize_t pos, string_size;
/* We store a reference to the object here in order to keep
the buffer alive during the lifetime of the Iobject. */
PyObject *pbuf;
"read([s]) -- Read s characters, or the rest of the string");
static int
-IO_cread(PyObject *self, char **output, int n) {
+IO_cread(PyObject *self, char **output, Py_ssize_t n) {
int l;
UNLESS (IO__opencheck(IOOOBJECT(self))) return -1;
static PyObject *
IO_read(IOobject *self, PyObject *args) {
- int n = -1;
+ Py_ssize_t n = -1;
char *output;
- UNLESS (PyArg_ParseTuple(args, "|i:read", &n)) return NULL;
+ UNLESS (PyArg_ParseTuple(args, "|n:read", &n)) return NULL;
if ( (n=IO_cread((PyObject*)self,&output,n)) < 0) return NULL;
static int
IO_creadline(PyObject *self, char **output) {
char *n, *s;
- int l;
+ Py_ssize_t l;
UNLESS (IO__opencheck(IOOOBJECT(self))) return -1;
*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 *
static PyObject *
IO_truncate(IOobject *self, PyObject *args) {
- int pos = -1;
+ Py_ssize_t pos = -1;
UNLESS (IO__opencheck(self)) return NULL;
- UNLESS (PyArg_ParseTuple(args, "|i:truncate", &pos)) return NULL;
+ UNLESS (PyArg_ParseTuple(args, "|n:truncate", &pos)) return NULL;
if (pos < 0) pos = self->pos;
if (self->string_size > pos) self->string_size = pos;
static PyObject *
O_seek(Oobject *self, PyObject *args) {
- int position, mode = 0;
+ 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, "n|i:seek", &position, &mode))
return NULL;
if (mode == 2) {
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;
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");
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 *
if (it == NULL)
return NULL;
while ((s = PyIter_Next(it)) != NULL) {
- int n;
+ Py_ssize_t n;
char *c;
if (PyString_AsStringAndSize(s, &c, &n) == -1) {
Py_DECREF(it);
static PyObject *
I_seek(Iobject *self, PyObject *args) {
- int position, mode = 0;
+ 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, "n|i:seek", &position, &mode))
return NULL;
if (mode == 2) position += self->string_size;
newIobject(PyObject *s) {
Iobject *self;
char *buf;
- int size;
+ Py_ssize_t size;
if (PyObject_AsReadBuffer(s, (const void **)&buf, &size)) {
PyErr_Format(PyExc_TypeError, "expected read buffer, %.200s found",
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;
"Extend the left side of the deque with elements from the iterable");
static int
-_deque_rotate(dequeobject *deque, int n)
+_deque_rotate(dequeobject *deque, Py_ssize_t n)
{
int i, len=deque->len, halflen=(len+1)>>1;
PyObject *item, *rv;
PyDoc_STRVAR(rotate_doc,
"Rotate the deque n steps to the right (default n=1). If n is negative, rotates left.");
-static int
+static Py_ssize_t
deque_len(dequeobject *deque)
{
return deque->len;
static PyObject *
deque_remove(dequeobject *deque, PyObject *value)
{
- int i, n=deque->len;
+ Py_ssize_t i, n=deque->len;
for (i=0 ; i<n ; i++) {
PyObject *item = deque->leftblock->data[deque->leftindex];
*/
static int
-deque_del_item(dequeobject *deque, int i)
+deque_del_item(dequeobject *deque, Py_ssize_t i)
{
PyObject *item;
}
static int
-deque_ass_item(dequeobject *deque, int i, PyObject *v)
+deque_ass_item(dequeobject *deque, Py_ssize_t i, PyObject *v)
{
PyObject *old_value;
block *b;
}
static PySequenceMethods deque_as_sequence = {
- (inquiry)deque_len, /* sq_length */
+ (lenfunc)deque_len, /* sq_length */
0, /* sq_concat */
0, /* sq_repeat */
- (intargfunc)deque_item, /* sq_item */
+ (ssizeargfunc)deque_item, /* sq_item */
0, /* sq_slice */
- (intobjargproc)deque_ass_item, /* sq_ass_item */
+ (ssizeobjargproc)deque_ass_item, /* sq_ass_item */
};
/* deque object ********************************************************/
*/
static PyObject *
-time_alloc(PyTypeObject *type, int aware)
+time_alloc(PyTypeObject *type, Py_ssize_t aware)
{
PyObject *self;
}
static PyObject *
-datetime_alloc(PyTypeObject *type, int aware)
+datetime_alloc(PyTypeObject *type, Py_ssize_t aware)
{
PyObject *self;
PyObject_Del(dp);
}
-static int
+static Py_ssize_t
dbm_length(dbmobject *dp)
{
if (dp->di_dbm == NULL) {
}
static PyMappingMethods dbm_as_mapping = {
- (inquiry)dbm_length, /*mp_length*/
+ (lenfunc)dbm_length, /*mp_length*/
(binaryfunc)dbm_subscript, /*mp_subscript*/
(objobjargproc)dbm_ass_sub, /*mp_ass_subscript*/
};
}
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);
PyObject_Del(dp);
}
-static int
+static Py_ssize_t
dbm_length(dbmobject *dp)
{
if (dp->di_dbm == NULL) {
}
static PyMappingMethods dbm_as_mapping = {
- (inquiry)dbm_length, /*mp_length*/
+ (lenfunc)dbm_length, /*mp_length*/
(binaryfunc)dbm_subscript, /*mp_subscript*/
(objobjargproc)dbm_ass_sub, /*mp_ass_subscript*/
};
/* Functions for treating an mmap'ed file as a buffer */
-static int
-mmap_buffer_getreadbuf(mmap_object *self, int index, const void **ptr)
+static Py_ssize_t
+mmap_buffer_getreadbuf(mmap_object *self, Py_ssize_t index, const void **ptr)
{
CHECK_VALID(-1);
if ( index != 0 ) {
return self->size;
}
-static int
-mmap_buffer_getwritebuf(mmap_object *self, int index, const void **ptr)
+static Py_ssize_t
+mmap_buffer_getwritebuf(mmap_object *self, Py_ssize_t index, const void **ptr)
{
CHECK_VALID(-1);
if ( index != 0 ) {
return self->size;
}
-static int
-mmap_buffer_getsegcount(mmap_object *self, int *lenp)
+static Py_ssize_t
+mmap_buffer_getsegcount(mmap_object *self, Py_ssize_t *lenp)
{
CHECK_VALID(-1);
if (lenp)
return 1;
}
-static int
-mmap_buffer_getcharbuffer(mmap_object *self, int index, const void **ptr)
+static Py_ssize_t
+mmap_buffer_getcharbuffer(mmap_object *self, Py_ssize_t index, const void **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
return Py_FindMethod (mmap_object_methods, (PyObject *)self, name);
}
-static int
+static Py_ssize_t
mmap_length(mmap_object *self)
{
CHECK_VALID(-1);
}
static PyObject *
-mmap_item(mmap_object *self, int i)
+mmap_item(mmap_object *self, Py_ssize_t i)
{
CHECK_VALID(NULL);
if (i < 0 || (size_t)i >= self->size) {
}
static PyObject *
-mmap_slice(mmap_object *self, int ilow, int ihigh)
+mmap_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh)
{
CHECK_VALID(NULL);
if (ilow < 0)
}
static PyObject *
-mmap_repeat(mmap_object *self, int n)
+mmap_repeat(mmap_object *self, Py_ssize_t n)
{
CHECK_VALID(NULL);
PyErr_SetString(PyExc_SystemError,
}
static int
-mmap_ass_slice(mmap_object *self, int ilow, int ihigh, PyObject *v)
+mmap_ass_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
{
const char *buf;
}
static int
-mmap_ass_item(mmap_object *self, int i, PyObject *v)
+mmap_ass_item(mmap_object *self, Py_ssize_t i, PyObject *v)
{
const char *buf;
}
static PySequenceMethods mmap_as_sequence = {
- (inquiry)mmap_length, /*sq_length*/
+ (lenfunc)mmap_length, /*sq_length*/
(binaryfunc)mmap_concat, /*sq_concat*/
- (intargfunc)mmap_repeat, /*sq_repeat*/
- (intargfunc)mmap_item, /*sq_item*/
- (intintargfunc)mmap_slice, /*sq_slice*/
- (intobjargproc)mmap_ass_item, /*sq_ass_item*/
- (intintobjargproc)mmap_ass_slice, /*sq_ass_slice*/
+ (ssizeargfunc)mmap_repeat, /*sq_repeat*/
+ (ssizeargfunc)mmap_item, /*sq_item*/
+ (ssizessizeargfunc)mmap_slice, /*sq_slice*/
+ (ssizeobjargproc)mmap_ass_item, /*sq_ass_item*/
+ (ssizessizeobjargproc)mmap_ass_slice, /*sq_ass_slice*/
};
static PyBufferProcs mmap_as_buffer = {
- (getreadbufferproc)mmap_buffer_getreadbuf,
- (getwritebufferproc)mmap_buffer_getwritebuf,
- (getsegcountproc)mmap_buffer_getsegcount,
- (getcharbufferproc)mmap_buffer_getcharbuffer,
+ (readbufferproc)mmap_buffer_getreadbuf,
+ (writebufferproc)mmap_buffer_getwritebuf,
+ (segcountproc)mmap_buffer_getsegcount,
+ (charbufferproc)mmap_buffer_getcharbuffer,
};
static PyTypeObject mmap_object_type = {
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
static node*
build_node_children(PyObject *tuple, node *root, int *line_num)
{
- int len = PyObject_Size(tuple);
- int i, err;
+ Py_ssize_t len = PyObject_Size(tuple);
+ Py_ssize_t i;
+ int err;
for (i = 1; i < len; ++i) {
/* elem must always be a sequence, however simple */
return (0);
}
if (ISTERMINAL(type)) {
- int len = PyObject_Size(elem);
+ Py_ssize_t len = PyObject_Size(elem);
PyObject *temp;
if ((len != 2) && (len != 3)) {
/* 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
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. */
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
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. */
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
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. */
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
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.
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);
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);
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);
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);
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);
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);
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;
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
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
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,
static int
update_ufd_array(pollObject *self)
{
- int i, pos;
+ Py_ssize_t i, pos;
PyObject *key, *value;
self->ufd_len = PyDict_Size(self->dict);
static PyObject *
SHA_new(PyObject *self, PyObject *args, PyObject *kwdict)
{
- static char *kwlist[] = {"string", NULL};
+ static const char *kwlist[] = {"string", NULL};
SHAobject *new;
unsigned char *cp = NULL;
int len;
int i, reslen = 0, slen = 0, sz = 100;
PyObject *res = NULL;
char* p = NULL;
- intargfunc getitemfunc;
+ ssizeargfunc getitemfunc;
WARN;
if (!PyArg_ParseTuple(args, "O|t#:join", &seq, &sep, &seplen))
do_strip(PyObject *args, int striptype)
{
char *s;
- int len, i, j;
+ Py_ssize_t len, i, j;
if (PyString_AsStringAndSize(args, &s, &len))
strop_lower(PyObject *self, PyObject *args)
{
char *s, *s_new;
- int i, n;
+ Py_ssize_t i, n;
PyObject *new;
int changed;
strop_upper(PyObject *self, PyObject *args)
{
char *s, *s_new;
- int i, n;
+ Py_ssize_t i, n;
PyObject *new;
int changed;
strop_capitalize(PyObject *self, PyObject *args)
{
char *s, *s_new;
- int i, n;
+ Py_ssize_t i, n;
PyObject *new;
int changed;
strop_swapcase(PyObject *self, PyObject *args)
{
char *s, *s_new;
- int i, n;
+ Py_ssize_t i, n;
PyObject *new;
int changed;
*p = SEP;
}
len += strlen(name);
+ assert(len < INT_MAX);
return (int)len;
}
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;
{
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);
return v;
}
-int
+Py_ssize_t
PyObject_Size(PyObject *o)
{
PySequenceMethods *m;
}
#undef PyObject_Length
-int
+Py_ssize_t
PyObject_Length(PyObject *o)
{
return PyObject_Size(o);
}
#define PyObject_Length PyObject_Size
-int
+Py_ssize_t
_PyObject_LengthHint(PyObject *o)
{
- int rv = PyObject_Size(o);
+ Py_ssize_t rv = PyObject_Size(o);
if (rv != -1)
return rv;
if (PyErr_ExceptionMatches(PyExc_TypeError) ||
PyErr_Fetch(&err_type, &err_value, &err_tb);
ro = PyObject_CallMethod(o, "__length_hint__", NULL);
if (ro != NULL) {
- rv = (int)PyInt_AsLong(ro);
+ rv = PyInt_AsLong(ro);
Py_DECREF(ro);
Py_XDECREF(err_type);
Py_XDECREF(err_value);
int PyObject_AsCharBuffer(PyObject *obj,
const char **buffer,
- int *buffer_len)
+ Py_ssize_t *buffer_len)
{
PyBufferProcs *pb;
const char *pp;
- int len;
+ Py_ssize_t len;
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
null_error();
int PyObject_AsReadBuffer(PyObject *obj,
const void **buffer,
- int *buffer_len)
+ Py_ssize_t *buffer_len)
{
PyBufferProcs *pb;
void *pp;
- int len;
+ Py_ssize_t len;
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
null_error();
int PyObject_AsWriteBuffer(PyObject *obj,
void **buffer,
- int *buffer_len)
+ Py_ssize_t *buffer_len)
{
PyBufferProcs *pb;
void*pp;
- int len;
+ Py_ssize_t len;
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
null_error();
}
static PyObject *
-sequence_repeat(intargfunc repeatfunc, PyObject *seq, PyObject *n)
+sequence_repeat(ssizeargfunc repeatfunc, PyObject *seq, PyObject *n)
{
long count;
if (PyInt_Check(n)) {
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);
/* Add a check for embedded NULL-bytes in the argument. */
static PyObject *
-int_from_string(const char *s, int len)
+int_from_string(const char *s, Py_ssize_t len)
{
char *end;
PyObject *x;
{
PyNumberMethods *m;
const char *buffer;
- int buffer_len;
+ Py_ssize_t buffer_len;
if (o == NULL)
return null_error();
/* Add a check for embedded NULL-bytes in the argument. */
static PyObject *
-long_from_string(const char *s, int len)
+long_from_string(const char *s, Py_ssize_t len)
{
char *end;
PyObject *x;
{
PyNumberMethods *m;
const char *buffer;
- int buffer_len;
+ Py_ssize_t buffer_len;
if (o == NULL)
return null_error();
s->ob_type->tp_as_sequence->sq_item != NULL;
}
-int
+Py_ssize_t
PySequence_Size(PyObject *s)
{
PySequenceMethods *m;
}
#undef PySequence_Length
-int
+Py_ssize_t
PySequence_Length(PyObject *s)
{
return PySequence_Size(s);
}
PyObject *
-PySequence_Repeat(PyObject *o, int count)
+PySequence_Repeat(PyObject *o, Py_ssize_t count)
{
PySequenceMethods *m;
}
PyObject *
-PySequence_InPlaceRepeat(PyObject *o, int count)
+PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count)
{
PySequenceMethods *m;
}
PyObject *
-PySequence_GetItem(PyObject *s, int i)
+PySequence_GetItem(PyObject *s, Py_ssize_t i)
{
PySequenceMethods *m;
if (m && m->sq_item) {
if (i < 0) {
if (m->sq_length) {
- int l = (*m->sq_length)(s);
+ Py_ssize_t l = (*m->sq_length)(s);
if (l < 0)
return NULL;
i += l;
}
static PyObject *
-sliceobj_from_intint(int i, int j)
+sliceobj_from_intint(Py_ssize_t i, Py_ssize_t j)
{
PyObject *start, *end, *slice;
start = PyInt_FromLong((long)i);
}
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;
if (m && m->sq_slice) {
if (i1 < 0 || i2 < 0) {
if (m->sq_length) {
- int l = (*m->sq_length)(s);
+ Py_ssize_t l = (*m->sq_length)(s);
if (l < 0)
return NULL;
if (i1 < 0)
}
int
-PySequence_SetItem(PyObject *s, int i, PyObject *o)
+PySequence_SetItem(PyObject *s, Py_ssize_t i, PyObject *o)
{
PySequenceMethods *m;
if (m && m->sq_ass_item) {
if (i < 0) {
if (m->sq_length) {
- int l = (*m->sq_length)(s);
+ Py_ssize_t l = (*m->sq_length)(s);
if (l < 0)
return -1;
i += l;
}
int
-PySequence_DelItem(PyObject *s, int i)
+PySequence_DelItem(PyObject *s, Py_ssize_t i)
{
PySequenceMethods *m;
if (m && m->sq_ass_item) {
if (i < 0) {
if (m->sq_length) {
- int l = (*m->sq_length)(s);
+ Py_ssize_t l = (*m->sq_length)(s);
if (l < 0)
return -1;
i += l;
}
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;
if (m && m->sq_ass_slice) {
if (i1 < 0 || i2 < 0) {
if (m->sq_length) {
- int l = (*m->sq_length)(s);
+ Py_ssize_t l = (*m->sq_length)(s);
if (l < 0)
return -1;
if (i1 < 0)
}
int
-PySequence_DelSlice(PyObject *s, int i1, int i2)
+PySequence_DelSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2)
{
PySequenceMethods *m;
if (m && m->sq_ass_slice) {
if (i1 < 0 || i2 < 0) {
if (m->sq_length) {
- int l = (*m->sq_length)(s);
+ Py_ssize_t l = (*m->sq_length)(s);
if (l < 0)
return -1;
if (i1 < 0)
PySequence_Tuple(PyObject *v)
{
PyObject *it; /* iter(v) */
- int n; /* guess for result tuple size */
+ Py_ssize_t n; /* guess for result tuple size */
PyObject *result;
- int j;
+ Py_ssize_t j;
if (v == NULL)
return null_error();
break;
}
if (j >= n) {
- int oldn = n;
+ Py_ssize_t oldn = n;
/* The over-allocation strategy can grow a bit faster
than for lists because unlike lists the
over-allocation isn't permanent -- we reclaim
o->ob_type->tp_as_sequence->sq_slice);
}
-int
+Py_ssize_t
PyMapping_Size(PyObject *o)
{
PyMappingMethods *m;
}
#undef PyMapping_Length
-int
+Py_ssize_t
PyMapping_Length(PyObject *o)
{
return PyMapping_Size(o);
abstract_issubclass(PyObject *derived, PyObject *cls)
{
PyObject *bases;
- int i, n;
+ Py_ssize_t i, n;
int r = 0;
}
}
else if (PyTuple_Check(cls)) {
- int i, n;
+ Py_ssize_t i, n;
if (!recursion_depth) {
PyErr_SetString(PyExc_RuntimeError,
return -1;
if (PyTuple_Check(cls)) {
- int i;
- int n = PyTuple_GET_SIZE(cls);
+ Py_ssize_t i;
+ Py_ssize_t n = PyTuple_GET_SIZE(cls);
if (!recursion_depth) {
PyErr_SetString(PyExc_RuntimeError,
PyObject_HEAD
PyObject *b_base;
void *b_ptr;
- int b_size;
- int b_offset;
+ Py_ssize_t b_size;
+ Py_ssize_t b_offset;
int b_readonly;
long b_hash;
} PyBufferObject;
static int
-get_buf(PyBufferObject *self, void **ptr, int *size)
+get_buf(PyBufferObject *self, void **ptr, Py_ssize_t *size)
{
if (self->b_base == NULL) {
assert (ptr != NULL);
*size = self->b_size;
}
else {
- int count, offset;
- getreadbufferproc proc;
+ Py_ssize_t count, offset;
+ readbufferproc proc;
PyBufferProcs *bp = self->b_base->ob_type->tp_as_buffer;
if ((*bp->bf_getsegcount)(self->b_base, NULL) != 1) {
PyErr_SetString(PyExc_TypeError,
if (self->b_readonly)
proc = bp->bf_getreadbuffer;
else
- proc = (getreadbufferproc)bp->bf_getwritebuffer;
+ proc = (readbufferproc)bp->bf_getwritebuffer;
if ((count = (*proc)(self->b_base, 0, ptr)) < 0)
return 0;
/* apply constraints to the start/end */
static PyObject *
-buffer_from_memory(PyObject *base, int size, int offset, void *ptr,
+buffer_from_memory(PyObject *base, Py_ssize_t size, Py_ssize_t offset, void *ptr,
int readonly)
{
PyBufferObject * b;
}
static PyObject *
-buffer_from_object(PyObject *base, int size, int offset, int readonly)
+buffer_from_object(PyObject *base, Py_ssize_t size, Py_ssize_t offset, int readonly)
{
if (offset < 0) {
PyErr_SetString(PyExc_ValueError,
/* another buffer, refer to the base object */
PyBufferObject *b = (PyBufferObject *)base;
if (b->b_size != Py_END_OF_BUFFER) {
- int base_size = b->b_size - offset;
+ Py_ssize_t base_size = b->b_size - offset;
if (base_size < 0)
base_size = 0;
if (size == Py_END_OF_BUFFER || size > base_size)
PyObject *
-PyBuffer_FromObject(PyObject *base, int offset, int size)
+PyBuffer_FromObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size)
{
PyBufferProcs *pb = base->ob_type->tp_as_buffer;
}
PyObject *
-PyBuffer_FromReadWriteObject(PyObject *base, int offset, int size)
+PyBuffer_FromReadWriteObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size)
{
PyBufferProcs *pb = base->ob_type->tp_as_buffer;
}
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);
}
PyObject *
-PyBuffer_New(int size)
+PyBuffer_New(Py_ssize_t size)
{
PyObject *o;
PyBufferObject * b;
"size must be zero or positive");
return NULL;
}
+ /* XXX: check for overflow in multiply */
/* Inline PyObject_New */
o = PyObject_MALLOC(sizeof(*b) + size);
if ( o == NULL )
buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
{
PyObject *ob;
- int offset = 0;
- int size = Py_END_OF_BUFFER;
+ Py_ssize_t offset = 0;
+ Py_ssize_t size = Py_END_OF_BUFFER;
if (!_PyArg_NoKeywords("buffer()", kw))
return NULL;
- if (!PyArg_ParseTuple(args, "O|ii:buffer", &ob, &offset, &size))
+ if (!PyArg_ParseTuple(args, "O|ll:buffer", &ob, &offset, &size))
return NULL;
return PyBuffer_FromObject(ob, offset, size);
}
buffer_compare(PyBufferObject *self, PyBufferObject *other)
{
void *p1, *p2;
- int len_self, len_other, min_len, cmp;
+ Py_ssize_t len_self, len_other, min_len;
+ int cmp;
if (!get_buf(self, &p1, &len_self))
return -1;
static PyObject *
buffer_repr(PyBufferObject *self)
{
- char *status = self->b_readonly ? "read-only" : "read-write";
+ const char *status = self->b_readonly ? "read-only" : "read-write";
if ( self->b_base == NULL )
- return PyString_FromFormat("<%s buffer ptr %p, size %d at %p>",
+ return PyString_FromFormat("<%s buffer ptr %p, size %ld at %p>",
status,
self->b_ptr,
self->b_size,
self);
else
return PyString_FromFormat(
- "<%s buffer for %p, size %d, offset %d at %p>",
+ "<%s buffer for %p, size %ld, offset %ld at %p>",
status,
self->b_base,
self->b_size,
buffer_hash(PyBufferObject *self)
{
void *ptr;
- int size;
- register int len;
+ Py_ssize_t size;
+ register Py_ssize_t len;
register unsigned char *p;
register long x;
buffer_str(PyBufferObject *self)
{
void *ptr;
- int size;
+ Py_ssize_t size;
if (!get_buf(self, &ptr, &size))
return NULL;
return PyString_FromStringAndSize(ptr, size);
/* Sequence methods */
-static int
+static Py_ssize_t
buffer_length(PyBufferObject *self)
{
void *ptr;
- int size;
+ Py_ssize_t size;
if (!get_buf(self, &ptr, &size))
return -1;
return size;
void *ptr1, *ptr2;
char *p;
PyObject *ob;
- int size, count;
+ Py_ssize_t size, count;
if ( pb == NULL ||
pb->bf_getreadbuffer == NULL ||
}
static PyObject *
-buffer_repeat(PyBufferObject *self, int count)
+buffer_repeat(PyBufferObject *self, Py_ssize_t count)
{
PyObject *ob;
register char *p;
void *ptr;
- int size;
+ Py_ssize_t size;
if ( count < 0 )
count = 0;
}
static PyObject *
-buffer_item(PyBufferObject *self, int idx)
+buffer_item(PyBufferObject *self, Py_ssize_t idx)
{
void *ptr;
- int size;
+ Py_ssize_t size;
if (!get_buf(self, &ptr, &size))
return NULL;
if ( idx < 0 || idx >= size ) {
}
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;
+ Py_ssize_t size;
if (!get_buf(self, &ptr, &size))
return NULL;
if ( left < 0 )
}
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;
- int size;
- int count;
+ Py_ssize_t size;
+ Py_ssize_t count;
if ( self->b_readonly ) {
PyErr_SetString(PyExc_TypeError,
}
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;
- int size;
- int slice_len;
- int count;
+ Py_ssize_t size;
+ Py_ssize_t slice_len;
+ Py_ssize_t count;
if ( self->b_readonly ) {
PyErr_SetString(PyExc_TypeError,
/* Buffer methods */
-static int
-buffer_getreadbuf(PyBufferObject *self, int idx, void **pp)
+static Py_ssize_t
+buffer_getreadbuf(PyBufferObject *self, Py_ssize_t idx, void **pp)
{
- int size;
+ Py_ssize_t size;
if ( idx != 0 ) {
PyErr_SetString(PyExc_SystemError,
"accessing non-existent buffer segment");
return size;
}
-static int
-buffer_getwritebuf(PyBufferObject *self, int idx, void **pp)
+static Py_ssize_t
+buffer_getwritebuf(PyBufferObject *self, Py_ssize_t idx, void **pp)
{
if ( self->b_readonly )
{
return buffer_getreadbuf(self, idx, pp);
}
-static int
-buffer_getsegcount(PyBufferObject *self, int *lenp)
+static Py_ssize_t
+buffer_getsegcount(PyBufferObject *self, Py_ssize_t *lenp)
{
void *ptr;
- int size;
+ Py_ssize_t size;
if (!get_buf(self, &ptr, &size))
return -1;
if (lenp)
return 1;
}
-static int
-buffer_getcharbuf(PyBufferObject *self, int idx, const char **pp)
+static Py_ssize_t
+buffer_getcharbuf(PyBufferObject *self, Py_ssize_t idx, const char **pp)
{
void *ptr;
- int size;
+ Py_ssize_t size;
if ( idx != 0 ) {
PyErr_SetString(PyExc_SystemError,
"accessing non-existent buffer segment");
static PySequenceMethods buffer_as_sequence = {
- (inquiry)buffer_length, /*sq_length*/
+ (lenfunc)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*/
+ (ssizeobjargproc)buffer_ass_item, /*sq_ass_item*/
+ (ssizessizeobjargproc)buffer_ass_slice, /*sq_ass_slice*/
};
static PyBufferProcs buffer_as_buffer = {
- (getreadbufferproc)buffer_getreadbuf,
- (getwritebufferproc)buffer_getwritebuf,
- (getsegcountproc)buffer_getsegcount,
- (getcharbufferproc)buffer_getcharbuf,
+ (readbufferproc)buffer_getreadbuf,
+ (writebufferproc)buffer_getwritebuf,
+ (segcountproc)buffer_getsegcount,
+ (charbufferproc)buffer_getcharbuf,
};
PyTypeObject PyBuffer_Type = {
return NULL;
}
else {
- int i, n;
+ Py_ssize_t i, n;
PyObject *base;
if (!PyTuple_Check(bases)) {
PyErr_SetString(PyExc_TypeError,
static PyObject *
class_lookup(PyClassObject *cp, PyObject *name, PyClassObject **pclass)
{
- int i, n;
+ Py_ssize_t i, n;
PyObject *value = PyDict_GetItem(cp->cl_dict, name);
if (value != NULL) {
*pclass = cp;
static char *
set_bases(PyClassObject *c, PyObject *v)
{
- int i, n;
+ Py_ssize_t i, n;
if (v == NULL || !PyTuple_Check(v))
return "__bases__ must be a tuple object";
int
PyClass_IsSubclass(PyObject *class, PyObject *base)
{
- int i, n;
+ Py_ssize_t i, n;
PyClassObject *cp;
if (class == base)
return 1;
static PyObject *getitemstr, *setitemstr, *delitemstr, *lenstr;
static PyObject *iterstr, *nextstr;
-static int
+static Py_ssize_t
instance_length(PyInstanceObject *inst)
{
PyObject *func;
PyObject *res;
- int outcome;
+ Py_ssize_t outcome;
if (lenstr == NULL)
lenstr = PyString_InternFromString("__len__");
if (res == NULL)
return -1;
if (PyInt_Check(res)) {
- long temp = PyInt_AsLong(res);
- outcome = (int)temp;
-#if SIZEOF_INT < SIZEOF_LONG
+ Py_ssize_t temp = PyInt_AsSsize_t(res);
+ if (temp == -1 && PyErr_Occurred()) {
+ Py_DECREF(res);
+ return -1;
+ }
+ outcome = (Py_ssize_t)temp;
+#if SIZEOF_SIZE_T < SIZEOF_LONG
/* Overflow check -- range of PyInt is more than C int */
if (outcome != temp) {
PyErr_SetString(PyExc_OverflowError,
}
static PyMappingMethods instance_as_mapping = {
- (inquiry)instance_length, /* mp_length */
+ (lenfunc)instance_length, /* mp_length */
(binaryfunc)instance_subscript, /* mp_subscript */
(objobjargproc)instance_ass_subscript, /* mp_ass_subscript */
};
static PyObject *
-instance_item(PyInstanceObject *inst, int i)
+instance_item(PyInstanceObject *inst, Py_ssize_t i)
{
PyObject *func, *arg, *res;
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;
}
static PyObject *
-sliceobj_from_intint(int i, int j)
+sliceobj_from_intint(Py_ssize_t i, Py_ssize_t j)
{
PyObject *start, *end, *res;
static PyObject *
-instance_slice(PyInstanceObject *inst, int i, int j)
+instance_slice(PyInstanceObject *inst, Py_ssize_t i, Py_ssize_t j)
{
PyObject *func, *arg, *res;
static PyObject *getslicestr;
}
static int
-instance_ass_item(PyInstanceObject *inst, int i, PyObject *item)
+instance_ass_item(PyInstanceObject *inst, Py_ssize_t i, PyObject *item)
{
PyObject *func, *arg, *res;
}
static int
-instance_ass_slice(PyInstanceObject *inst, int i, int j, PyObject *value)
+instance_ass_slice(PyInstanceObject *inst, Py_ssize_t i, Py_ssize_t j, PyObject *value)
{
PyObject *func, *arg, *res;
static PyObject *setslicestr, *delslicestr;
static PySequenceMethods
instance_as_sequence = {
- (inquiry)instance_length, /* sq_length */
+ (lenfunc)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 */
+ (ssizeobjargproc)instance_ass_item, /* sq_ass_item */
+ (ssizessizeobjargproc)instance_ass_slice,/* sq_ass_slice */
(objobjproc)instance_contains, /* sq_contains */
};
Py_INCREF(arg);
}
else {
- int argcount = PyTuple_Size(arg);
+ Py_ssize_t argcount = PyTuple_Size(arg);
PyObject *newarg = PyTuple_New(argcount + 1);
int i;
if (newarg == NULL)
static void
intern_strings(PyObject *tuple)
{
- int i;
+ Py_ssize_t i;
for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) {
PyObject *v = PyTuple_GET_ITEM(tuple, i);
PyObject *lnotab)
{
PyCodeObject *co;
- int i;
+ Py_ssize_t i;
/* Check argument types */
if (argcount < 0 || nlocals < 0 ||
code == NULL ||
{
PyObject *newtuple;
PyObject *item;
- int i, len;
+ Py_ssize_t i, len;
len = PyTuple_GET_SIZE(tup);
newtuple = PyTuple_New(len);
#ifdef Py_USING_UNICODE
char s_buffer[256];
#endif
- int len;
+ Py_ssize_t len;
if (PyString_Check(v)) {
s = PyString_AS_STRING(v);
NULL))
return NULL;
s = s_buffer;
- len = (int)strlen(s);
+ len = strlen(s);
}
#endif
else if (PyObject_AsCharBuffer(v, &s, &len)) {
static PyObject *
methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds)
{
- int argc;
+ Py_ssize_t argc;
PyObject *self, *func, *result;
/* Make sure that the first argument is acceptable as 'self' */
static PyObject *
wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds)
{
- int argc;
+ Py_ssize_t argc;
PyObject *self, *func, *result;
/* Make sure that the first argument is acceptable as 'self' */
PyObject *dict;
} proxyobject;
-static int
+static Py_ssize_t
proxy_len(proxyobject *pp)
{
return PyObject_Size(pp->dict);
}
static PyMappingMethods proxy_as_mapping = {
- (inquiry)proxy_len, /* mp_length */
+ (lenfunc)proxy_len, /* mp_length */
(binaryfunc)proxy_getitem, /* mp_subscript */
0, /* mp_ass_subscript */
};
static dictentry *
lookdict(dictobject *mp, PyObject *key, register long hash)
{
- register int i;
- register unsigned int perturb;
+ register Py_ssize_t i;
+ register size_t perturb;
register dictentry *freeslot;
register unsigned int mask = mp->ma_mask;
dictentry *ep0 = mp->ma_table;
static dictentry *
lookdict_string(dictobject *mp, PyObject *key, register long hash)
{
- register int i;
- register unsigned int perturb;
+ register Py_ssize_t i;
+ register size_t perturb;
register dictentry *freeslot;
register unsigned int mask = mp->ma_mask;
dictentry *ep0 = mp->ma_table;
* delete keys), via PyDict_SetItem().
*/
int
-PyDict_Next(PyObject *op, int *ppos, PyObject **pkey, PyObject **pvalue)
+PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue)
{
- register int i, mask;
+ register Py_ssize_t i;
+ register int mask;
register dictentry *ep;
if (!PyDict_Check(op))
static PyObject *
dict_repr(dictobject *mp)
{
- int i;
+ Py_ssize_t i;
PyObject *s, *temp, *colon = NULL;
PyObject *pieces = NULL, *result = NULL;
PyObject *key, *value;
return result;
}
-static int
+static Py_ssize_t
dict_length(dictobject *mp)
{
return mp->ma_used;
}
static PyMappingMethods dict_as_mapping = {
- (inquiry)dict_length, /*mp_length*/
+ (lenfunc)dict_length, /*mp_length*/
(binaryfunc)dict_subscript, /*mp_subscript*/
(objobjargproc)dict_ass_sub, /*mp_ass_subscript*/
};
PyDict_MergeFromSeq2(PyObject *d, PyObject *seq2, int override)
{
PyObject *it; /* iter(seq2) */
- int i; /* index into seq2 of current element */
+ int i; /* index into seq2 of current element */
PyObject *item; /* seq2[i] */
PyObject *fast; /* item as a 2-tuple or 2-list */
for (i = 0; ; ++i) {
PyObject *key, *value;
- int n;
+ Py_ssize_t n;
fast = NULL;
item = PyIter_Next(it);
if (n != 2) {
PyErr_Format(PyExc_ValueError,
"dictionary update sequence element #%d "
- "has length %d; 2 is required",
+ "has length %ld; 2 is required",
i, n);
goto Fail;
}
return NULL;
}
-int
+Py_ssize_t
PyDict_Size(PyObject *mp)
{
if (mp == NULL || !PyDict_Check(mp)) {
static int
dict_traverse(PyObject *op, visitproc visit, void *arg)
{
- int i = 0, err;
+ Py_ssize_t i = 0;
+ int err;
PyObject *pk;
PyObject *pv;
static PyObject *
dictiter_len(dictiterobject *di)
{
- int len = 0;
+ long len = 0;
if (di->di_dict != NULL && di->di_used == di->di_dict->ma_used)
len = di->len;
return PyInt_FromLong(len);
static PyObject *
reversed_len(reversedobject *ro)
{
- int position, seqsize;
+ Py_ssize_t position, seqsize;
if (ro->seq == NULL)
return PyInt_FromLong(0);
/* File object implementation */
+#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
file_readinto(PyFileObject *f, PyObject *args)
{
char *ptr;
- int ntodo;
- size_t ndone, nnow;
+ Py_ssize_t ntodo;
+ Py_ssize_t ndone, nnow;
if (f->f_fp == NULL)
return err_closed();
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) {
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) {
if (n < 0 && result != NULL && PyString_Check(result)) {
char *s = PyString_AS_STRING(result);
- int len = PyString_GET_SIZE(result);
+ Py_ssize_t len = PyString_GET_SIZE(result);
if (len == 0) {
Py_DECREF(result);
result = NULL;
#ifdef Py_USING_UNICODE
if (n < 0 && result != NULL && PyUnicode_Check(result)) {
Py_UNICODE *s = PyUnicode_AS_UNICODE(result);
- int len = PyUnicode_GET_SIZE(result);
+ Py_ssize_t len = PyUnicode_GET_SIZE(result);
if (len == 0) {
Py_DECREF(result);
result = NULL;
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))
PyObject *list, *line;
PyObject *it; /* iter(seq) */
PyObject *result;
- int i, j, index, len, nwritten, islist;
+ int index, islist;
+ Py_ssize_t i, j, nwritten, len;
assert(seq != NULL);
if (f->f_fp == NULL)
PyObject *v = PyList_GET_ITEM(list, i);
if (!PyString_Check(v)) {
const char *buffer;
- int len;
if (((f->f_binary &&
PyObject_AsReadBuffer(v,
(const void**)&buffer,
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)
PyStringObject* s;
char *bufptr;
char *buf;
- int len;
+ Py_ssize_t len;
if (f->f_buf == NULL)
if (readahead(f, bufsize) < 0)
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;
int
PyFile_SoftSpace(PyObject *f, int newflag)
{
- int oldflag = 0;
+ long oldflag = 0;
if (f == NULL) {
/* Do nothing */
}
else {
if (PyInt_Check(v))
oldflag = PyInt_AsLong(v);
+ assert(oldflag < INT_MAX);
Py_DECREF(v);
}
v = PyInt_FromLong((long)newflag);
Py_DECREF(v);
}
}
- return oldflag;
+ return (int)oldflag;
}
/* Interfaces to write objects/strings to file-like objects */
#ifdef Py_USING_UNICODE
char s_buffer[256]; /* for objects convertible to a char buffer */
#endif
- int len;
+ Py_ssize_t len;
if (pend)
*pend = NULL;
NULL))
return NULL;
s = s_buffer;
- len = (int)strlen(s);
+ len = strlen(s);
}
#endif
else if (PyObject_AsCharBuffer(v, &s, &len)) {
int new_lasti = 0; /* The new value of f_lasti */
int new_iblock = 0; /* The new value of f_iblock */
char *code = NULL; /* The bytecode for the frame... */
- int code_len = 0; /* ...and its length */
+ Py_ssize_t code_len = 0; /* ...and its length */
char *lnotab = NULL; /* Iterating over co_lnotab */
- int lnotab_len = 0; /* (ditto) */
+ Py_ssize_t lnotab_len = 0; /* (ditto) */
int offset = 0; /* (ditto) */
int line = 0; /* (ditto) */
int addr = 0; /* (ditto) */
PyFrameObject *back = tstate->frame;
PyFrameObject *f;
PyObject *builtins;
- int extras, ncells, nfrees, i;
+ Py_ssize_t extras, ncells, nfrees, i;
#ifdef Py_DEBUG
if (code == NULL || globals == NULL || !PyDict_Check(globals) ||
/* Convert between "fast" version of locals and dictionary version */
static void
-map_to_dict(PyObject *map, int nmap, PyObject *dict, PyObject **values,
- int deref)
+map_to_dict(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values,
+ Py_ssize_t deref)
{
- int j;
+ Py_ssize_t j;
for (j = nmap; --j >= 0; ) {
PyObject *key = PyTuple_GET_ITEM(map, j);
PyObject *value = values[j];
}
static void
-dict_to_map(PyObject *map, int nmap, PyObject *dict, PyObject **values,
- int deref, int clear)
+dict_to_map(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values,
+ Py_ssize_t deref, int clear)
{
- int j;
+ Py_ssize_t j;
for (j = nmap; --j >= 0; ) {
PyObject *key = PyTuple_GET_ITEM(map, j);
PyObject *value = PyObject_GetItem(dict, key);
PyObject *locals, *map;
PyObject **fast;
PyObject *error_type, *error_value, *error_traceback;
- int j;
+ Py_ssize_t j;
if (f == NULL)
return;
locals = f->f_locals;
PyObject *locals, *map;
PyObject **fast;
PyObject *error_type, *error_value, *error_traceback;
- int j;
+ Py_ssize_t j;
if (f == NULL)
return;
locals = f->f_locals;
func_set_code(PyFunctionObject *op, PyObject *value)
{
PyObject *tmp;
- int nfree, nclosure;
+ Py_ssize_t nfree, nclosure;
if (restricted())
return -1;
PyTuple_GET_SIZE(op->func_closure));
if (nclosure != nfree) {
PyErr_Format(PyExc_ValueError,
- "%s() requires a code object with %d free vars,"
- " not %d",
+ "%s() requires a code object with %ld free vars,"
+ " not %ld",
PyString_AsString(op->func_name),
nclosure, nfree);
return -1;
PyObject *defaults = Py_None;
PyObject *closure = Py_None;
PyFunctionObject *newfunc;
- int nfree, nclosure;
+ Py_ssize_t nfree, nclosure;
static const char *kwlist[] = {"code", "globals", "name",
"argdefs", "closure", 0};
nclosure = closure == Py_None ? 0 : PyTuple_GET_SIZE(closure);
if (nfree != nclosure)
return PyErr_Format(PyExc_ValueError,
- "%s requires closure of length %d, not %d",
+ "%s requires closure of length %ld, not %ld",
PyString_AS_STRING(code->co_name),
nfree, nclosure);
if (nclosure) {
- int i;
+ Py_ssize_t i;
for (i = 0; i < nclosure; i++) {
PyObject *o = PyTuple_GET_ITEM(closure, i);
if (!PyCell_Check(o)) {
PyObject *result;
PyObject *argdefs;
PyObject **d, **k;
- int nk, nd;
+ Py_ssize_t nk, nd;
argdefs = PyFunction_GET_DEFAULTS(func);
if (argdefs != NULL && PyTuple_Check(argdefs)) {
}
if (kw != NULL && PyDict_Check(kw)) {
- int pos, i;
+ Py_ssize_t pos, i;
nk = PyDict_Size(kw);
k = PyMem_NEW(PyObject *, 2*nk);
if (k == NULL) {
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)
{
return val;
}
+Py_ssize_t
+PyInt_AsSsize_t(register PyObject *op)
+{
+ PyNumberMethods *nb;
+ PyIntObject *io;
+ Py_ssize_t val;
+ if (op && !PyInt_CheckExact(op) && PyLong_Check(op))
+ return _PyLong_AsSsize_t(op);
+#if SIZEOF_SIZE_T==SIZEOF_LONG
+ return PyInt_AsLong(op);
+#else
+
+ 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)
{
#ifdef Py_USING_UNICODE
PyObject *
-PyInt_FromUnicode(Py_UNICODE *s, int length, int base)
+PyInt_FromUnicode(Py_UNICODE *s, Py_ssize_t length, int base)
{
PyObject *result;
char *buffer = PyMem_MALLOC(length+1);
static PyObject *
iter_len(seqiterobject *it)
{
- int seqsize, len;
+ Py_ssize_t seqsize, len;
if (it->it_seq) {
seqsize = PySequence_Size(it->it_seq);
* 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;
- int allocated = self->allocated;
+ Py_ssize_t allocated = self->allocated;
/* Bypass realloc() when a previous overallocation is large enough
to accommodate the newsize. If the newsize falls lower than half
}
PyObject *
-PyList_New(int size)
+PyList_New(Py_ssize_t size)
{
PyListObject *op;
size_t nbytes;
return (PyObject *) op;
}
-int
+Py_ssize_t
PyList_Size(PyObject *op)
{
if (!PyList_Check(op)) {
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();
}
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;
}
static int
-ins1(PyListObject *self, int where, PyObject *v)
+ins1(PyListObject *self, Py_ssize_t where, PyObject *v)
{
- int i, n = self->ob_size;
+ Py_ssize_t i, n = self->ob_size;
PyObject **items;
if (v == NULL) {
PyErr_BadInternalCall();
}
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();
static int
app1(PyListObject *self, PyObject *v)
{
- int n = PyList_GET_SIZE(self);
+ Py_ssize_t n = PyList_GET_SIZE(self);
assert (v != NULL);
if (n == INT_MAX) {
static void
list_dealloc(PyListObject *op)
{
- int i;
+ Py_ssize_t i;
PyObject_GC_UnTrack(op);
Py_TRASHCAN_SAFE_BEGIN(op)
if (op->ob_item != NULL) {
static int
list_print(PyListObject *op, FILE *fp, int flags)
{
- int i;
+ int rc;
+ Py_ssize_t i;
- i = Py_ReprEnter((PyObject*)op);
- if (i != 0) {
- if (i < 0)
- return i;
+ rc = Py_ReprEnter((PyObject*)op);
+ if (rc != 0) {
+ if (rc < 0)
+ return rc;
fprintf(fp, "[...]");
return 0;
}
static PyObject *
list_repr(PyListObject *v)
{
- int i;
+ Py_ssize_t i;
PyObject *s, *temp;
PyObject *pieces = NULL, *result = NULL;
return result;
}
-static int
+static Py_ssize_t
list_length(PyListObject *a)
{
return a->ob_size;
static int
list_contains(PyListObject *a, PyObject *el)
{
- int i, cmp;
+ Py_ssize_t i;
+ int cmp;
for (i = 0, cmp = 0 ; cmp == 0 && i < a->ob_size; ++i)
cmp = PyObject_RichCompareBool(el, PyList_GET_ITEM(a, i),
}
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)
}
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;
- int i, len;
+ Py_ssize_t i, len;
if (ilow < 0)
ilow = 0;
else if (ilow > a->ob_size)
}
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();
static PyObject *
list_concat(PyListObject *a, PyObject *bb)
{
- int size;
- int i;
+ Py_ssize_t size;
+ Py_ssize_t i;
PyObject **src, **dest;
PyListObject *np;
if (!PyList_Check(bb)) {
}
static PyObject *
-list_repeat(PyListObject *a, int n)
+list_repeat(PyListObject *a, Py_ssize_t n)
{
- int i, j;
- int size;
+ Py_ssize_t i, j;
+ Py_ssize_t size;
PyListObject *np;
PyObject **p, **items;
PyObject *elem;
static int
list_clear(PyListObject *a)
{
- int i;
+ Py_ssize_t i;
PyObject **item = a->ob_item;
if (item != NULL) {
/* Because XDECREF can recursively invoke operations on
* 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
PyObject **item;
PyObject **vitem = NULL;
PyObject *v_as_SF = NULL; /* PySequence_Fast(v) */
- int n; /* # of elements in replacement list */
- int norig; /* # of elements in list getting replaced */
- int d; /* Change in size */
- int k;
+ Py_ssize_t n; /* # of elements in replacement list */
+ Py_ssize_t norig; /* # of elements in list getting replaced */
+ Py_ssize_t d; /* Change in size */
+ Py_ssize_t k;
size_t s;
int result = -1; /* guilty until proved innocent */
#define b ((PyListObject *)v)
}
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();
}
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;
+ Py_ssize_t size, i, j, p;
size = PyList_GET_SIZE(self);
}
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) {
static PyObject *
listinsert(PyListObject *self, PyObject *args)
{
- int i;
+ Py_ssize_t i;
PyObject *v;
- if (!PyArg_ParseTuple(args, "iO:insert", &i, &v))
+ if (!PyArg_ParseTuple(args, "nO:insert", &i, &v))
return NULL;
if (ins1(self, i, v) == 0)
Py_RETURN_NONE;
listextend(PyListObject *self, PyObject *b)
{
PyObject *it; /* iter(v) */
- int m; /* size of self */
- int n; /* guess for size of b */
- int mn; /* m + n */
- int i;
+ Py_ssize_t m; /* size of self */
+ Py_ssize_t n; /* guess for size of b */
+ Py_ssize_t mn; /* m + n */
+ Py_ssize_t i;
PyObject *(*iternext)(PyObject *);
/* Special cases:
static PyObject *
listpop(PyListObject *self, PyObject *args)
{
- int i = -1;
+ Py_ssize_t i = -1;
PyObject *v, *arg = NULL;
int status;
return NULL;
if (arg != NULL) {
if (PyInt_Check(arg))
- i = (int)(PyInt_AS_LONG((PyIntObject*) arg));
- else if (!PyArg_ParseTuple(args, "|i:pop", &i))
+ i = PyInt_AS_LONG((PyIntObject*) arg);
+ else if (!PyArg_ParseTuple(args, "|n:pop", &i))
return NULL;
}
if (self->ob_size == 0) {
{
PyObject *res;
PyObject *args;
- int i;
+ Py_ssize_t i;
assert(compare != NULL);
/* Call the user's comparison function and translate the 3-way
binarysort(PyObject **lo, PyObject **hi, PyObject **start, PyObject *compare)
/* compare -- comparison function object, or NULL for default */
{
- register int k;
+ register Py_ssize_t k;
register PyObject **l, **p, **r;
register PyObject *pivot;
Returns -1 in case of error.
*/
-static int
+static Py_ssize_t
count_run(PyObject **lo, PyObject **hi, PyObject *compare, int *descending)
{
- int k;
- int n;
+ Py_ssize_t k;
+ Py_ssize_t n;
assert(lo < hi);
*descending = 0;
Returns -1 on error. See listsort.txt for info on the method.
*/
-static int
-gallop_left(PyObject *key, PyObject **a, int n, int hint, PyObject *compare)
+static Py_ssize_t
+gallop_left(PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize_t hint, PyObject *compare)
{
- int ofs;
- int lastofs;
- int k;
+ Py_ssize_t ofs;
+ Py_ssize_t lastofs;
+ Py_ssize_t k;
assert(key && a && n > 0 && hint >= 0 && hint < n);
/* a[hint] < key -- gallop right, until
* a[hint + lastofs] < key <= a[hint + ofs]
*/
- const int maxofs = n - hint; /* &a[n-1] is highest */
+ const Py_ssize_t maxofs = n - hint; /* &a[n-1] is highest */
while (ofs < maxofs) {
IFLT(a[ofs], key) {
lastofs = ofs;
/* key <= a[hint] -- gallop left, until
* a[hint - ofs] < key <= a[hint - lastofs]
*/
- const int maxofs = hint + 1; /* &a[0] is lowest */
+ const Py_ssize_t maxofs = hint + 1; /* &a[0] is lowest */
while (ofs < maxofs) {
IFLT(*(a-ofs), key)
break;
*/
++lastofs;
while (lastofs < ofs) {
- int m = lastofs + ((ofs - lastofs) >> 1);
+ Py_ssize_t m = lastofs + ((ofs - lastofs) >> 1);
IFLT(a[m], key)
lastofs = m+1; /* a[m] < key */
we're sticking to "<" comparisons that it's much harder to follow if
written as one routine with yet another "left or right?" flag.
*/
-static int
-gallop_right(PyObject *key, PyObject **a, int n, int hint, PyObject *compare)
+static Py_ssize_t
+gallop_right(PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize_t hint, PyObject *compare)
{
- int ofs;
- int lastofs;
- int k;
+ Py_ssize_t ofs;
+ Py_ssize_t lastofs;
+ Py_ssize_t k;
assert(key && a && n > 0 && hint >= 0 && hint < n);
/* key < a[hint] -- gallop left, until
* a[hint - ofs] <= key < a[hint - lastofs]
*/
- const int maxofs = hint + 1; /* &a[0] is lowest */
+ const Py_ssize_t maxofs = hint + 1; /* &a[0] is lowest */
while (ofs < maxofs) {
IFLT(key, *(a-ofs)) {
lastofs = ofs;
/* a[hint] <= key -- gallop right, until
* a[hint + lastofs] <= key < a[hint + ofs]
*/
- const int maxofs = n - hint; /* &a[n-1] is highest */
+ const Py_ssize_t maxofs = n - hint; /* &a[n-1] is highest */
while (ofs < maxofs) {
IFLT(key, a[ofs])
break;
*/
++lastofs;
while (lastofs < ofs) {
- int m = lastofs + ((ofs - lastofs) >> 1);
+ Py_ssize_t m = lastofs + ((ofs - lastofs) >> 1);
IFLT(key, a[m])
ofs = m; /* key < a[m] */
*/
struct s_slice {
PyObject **base;
- int len;
+ Py_ssize_t len;
};
typedef struct s_MergeState {
* to MIN_GALLOP. merge_lo and merge_hi tend to nudge it higher for
* random data, and lower for highly structured data.
*/
- int min_gallop;
+ Py_ssize_t min_gallop;
/* 'a' is temp storage to help with merges. It contains room for
* alloced entries.
*/
PyObject **a; /* may point to temparray below */
- int alloced;
+ Py_ssize_t alloced;
/* A stack of n pending runs yet to be merged. Run #i starts at
* address base[i] and extends for len[i] elements. It's always
* Returns 0 on success and -1 if the memory can't be gotten.
*/
static int
-merge_getmem(MergeState *ms, int need)
+merge_getmem(MergeState *ms, Py_ssize_t need)
{
assert(ms != NULL);
if (need <= ms->alloced)
* merge, and should have na <= nb. See listsort.txt for more info.
* Return 0 if successful, -1 if error.
*/
-static int
-merge_lo(MergeState *ms, PyObject **pa, int na, PyObject **pb, int nb)
+static Py_ssize_t
+merge_lo(MergeState *ms, PyObject **pa, Py_ssize_t na,
+ PyObject **pb, Py_ssize_t nb)
{
- int k;
+ Py_ssize_t k;
PyObject *compare;
PyObject **dest;
int result = -1; /* guilty until proved innocent */
- int min_gallop = ms->min_gallop;
+ Py_ssize_t min_gallop = ms->min_gallop;
assert(ms && pa && pb && na > 0 && nb > 0 && pa + na == pb);
if (MERGE_GETMEM(ms, na) < 0)
compare = ms->compare;
for (;;) {
- int acount = 0; /* # of times A won in a row */
- int bcount = 0; /* # of times B won in a row */
+ Py_ssize_t acount = 0; /* # of times A won in a row */
+ Py_ssize_t bcount = 0; /* # of times B won in a row */
/* Do the straightforward thing until (if ever) one run
* appears to win consistently.
* merge, and should have na >= nb. See listsort.txt for more info.
* Return 0 if successful, -1 if error.
*/
-static int
-merge_hi(MergeState *ms, PyObject **pa, int na, PyObject **pb, int nb)
+static Py_ssize_t
+merge_hi(MergeState *ms, PyObject **pa, Py_ssize_t na, PyObject **pb, Py_ssize_t nb)
{
- int k;
+ Py_ssize_t k;
PyObject *compare;
PyObject **dest;
int result = -1; /* guilty until proved innocent */
PyObject **basea;
PyObject **baseb;
- int min_gallop = ms->min_gallop;
+ Py_ssize_t min_gallop = ms->min_gallop;
assert(ms && pa && pb && na > 0 && nb > 0 && pa + na == pb);
if (MERGE_GETMEM(ms, nb) < 0)
compare = ms->compare;
for (;;) {
- int acount = 0; /* # of times A won in a row */
- int bcount = 0; /* # of times B won in a row */
+ Py_ssize_t acount = 0; /* # of times A won in a row */
+ Py_ssize_t bcount = 0; /* # of times B won in a row */
/* Do the straightforward thing until (if ever) one run
* appears to win consistently.
/* Merge the two runs at stack indices i and i+1.
* Returns 0 on success, -1 on error.
*/
-static int
-merge_at(MergeState *ms, int i)
+static Py_ssize_t
+merge_at(MergeState *ms, Py_ssize_t i)
{
PyObject **pa, **pb;
- int na, nb;
- int k;
+ Py_ssize_t na, nb;
+ Py_ssize_t k;
PyObject *compare;
assert(ms != NULL);
assert(ms);
while (ms->n > 1) {
- int n = ms->n - 2;
+ Py_ssize_t n = ms->n - 2;
if (n > 0 && p[n-1].len <= p[n].len + p[n+1].len) {
if (p[n-1].len < p[n+1].len)
--n;
assert(ms);
while (ms->n > 1) {
- int n = ms->n - 2;
+ Py_ssize_t n = ms->n - 2;
if (n > 0 && p[n-1].len < p[n+1].len)
--n;
if (merge_at(ms, n) < 0)
*
* See listsort.txt for more info.
*/
-static int
-merge_compute_minrun(int n)
+static Py_ssize_t
+merge_compute_minrun(Py_ssize_t n)
{
- int r = 0; /* becomes 1 if any 1 bits are shifted off */
+ Py_ssize_t r = 0; /* becomes 1 if any 1 bits are shifted off */
assert(n >= 0);
while (n >= 64) {
{
MergeState ms;
PyObject **lo, **hi;
- int nremaining;
- int minrun;
- int saved_ob_size, saved_allocated;
+ Py_ssize_t nremaining;
+ Py_ssize_t minrun;
+ Py_ssize_t saved_ob_size, saved_allocated;
PyObject **saved_ob_item;
PyObject **final_ob_item;
PyObject *compare = NULL;
PyObject *result = NULL; /* guilty until proved innocent */
int reverse = 0;
PyObject *keyfunc = NULL;
- int i;
+ Py_ssize_t i;
PyObject *key, *value, *kvpair;
static const char *kwlist[] = {"cmp", "key", "reverse", 0};
minrun = merge_compute_minrun(nremaining);
do {
int descending;
- int n;
+ Py_ssize_t n;
/* Identify next run. */
n = count_run(lo, hi, compare, &descending);
reverse_slice(lo, lo + n);
/* If short, extend to min(minrun, nremaining). */
if (n < minrun) {
- const int force = nremaining <= minrun ?
+ const Py_ssize_t force = nremaining <= minrun ?
nremaining : minrun;
if (binarysort(lo, lo + force, lo + n, compare) < 0)
goto fail;
{
PyObject *w;
PyObject **p;
- int n;
+ Py_ssize_t n;
if (v == NULL || !PyList_Check(v)) {
PyErr_BadInternalCall();
return NULL;
static PyObject *
listindex(PyListObject *self, PyObject *args)
{
- int i, start=0, stop=self->ob_size;
+ Py_ssize_t i, start=0, stop=self->ob_size;
PyObject *v;
if (!PyArg_ParseTuple(args, "O|O&O&:index", &v,
for (i = start; i < stop && i < self->ob_size; i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0)
- return PyInt_FromLong((long)i);
+ return PyInt_FromSsize_t(i);
else if (cmp < 0)
return NULL;
}
static PyObject *
listcount(PyListObject *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++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
else if (cmp < 0)
return NULL;
}
- return PyInt_FromLong((long)count);
+ return PyInt_FromSsize_t(count);
}
static PyObject *
listremove(PyListObject *self, PyObject *v)
{
- int i;
+ Py_ssize_t i;
for (i = 0; i < self->ob_size; i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
static int
list_traverse(PyListObject *o, visitproc visit, void *arg)
{
- int i, err;
+ Py_ssize_t i;
PyObject *x;
for (i = o->ob_size; --i >= 0; ) {
x = o->ob_item[i];
if (x != NULL) {
- err = visit(x, arg);
+ int err = visit(x, arg);
if (err)
return err;
}
list_richcompare(PyObject *v, PyObject *w, int op)
{
PyListObject *vl, *wl;
- int i;
+ Py_ssize_t i;
if (!PyList_Check(v) || !PyList_Check(w)) {
Py_INCREF(Py_NotImplemented);
if (i >= vl->ob_size || i >= wl->ob_size) {
/* No more items to compare -- compare sizes */
- int vs = vl->ob_size;
- int ws = wl->ob_size;
+ Py_ssize_t vs = vl->ob_size;
+ Py_ssize_t ws = wl->ob_size;
int cmp;
PyObject *res;
switch (op) {
};
static PySequenceMethods list_as_sequence = {
- (inquiry)list_length, /* sq_length */
+ (lenfunc)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 */
+ (ssizeobjargproc)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 */
+ (ssizeargfunc)list_inplace_repeat, /* sq_inplace_repeat */
};
PyDoc_STRVAR(list_doc,
static PyObject *
list_subscript(PyListObject* self, PyObject* item)
{
- if (PyInt_Check(item)) {
- long i = PyInt_AS_LONG(item);
- if (i < 0)
- i += PyList_GET_SIZE(self);
- return list_item(self, i);
- }
- else if (PyLong_Check(item)) {
- long i = PyLong_AsLong(item);
+ if (PyInt_Check(item) || PyLong_Check(item)) {
+ Py_ssize_t i = PyInt_AsSsize_t(item);
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)
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;
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) {
if (value == NULL) {
/* delete slice */
PyObject **garbage;
- int cur, i;
+ Py_ssize_t cur, i;
if (slicelength <= 0)
return 0;
for (cur = start, i = 0;
cur < stop;
cur += step, i++) {
- int lim = step;
+ Py_ssize_t lim = step;
garbage[i] = PyList_GET_ITEM(self, cur);
else {
/* assign slice */
PyObject **garbage, *ins, *seq, **seqitems, **selfitems;
- int cur, i;
+ Py_ssize_t cur, i;
/* protect against a[::-1] = a */
if (self == (PyListObject*)value) {
}
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",
+ "attempt to assign sequence of size %ld to extended slice of size %ld",
PySequence_Fast_GET_SIZE(seq),
slicelength);
Py_DECREF(seq);
}
static PyMappingMethods list_as_mapping = {
- (inquiry)list_length,
+ (lenfunc)list_length,
(binaryfunc)list_subscript,
(objobjargproc)list_ass_subscript
};
static PyObject *
listiter_len(listiterobject *it)
{
- int len;
+ Py_ssize_t len;
if (it->it_seq) {
len = PyList_GET_SIZE(it->it_seq) - it->it_index;
if (len >= 0)
- return PyInt_FromLong((long)len);
+ return PyInt_FromSsize_t(len);
}
return PyInt_FromLong(0);
}
return NULL;
}
-static int
+static Py_ssize_t
listreviter_len(listreviterobject *it)
{
- int len = it->it_index + 1;
+ Py_ssize_t len = it->it_index + 1;
if (it->it_seq == NULL || PyList_GET_SIZE(it->it_seq) < len)
return 0;
return len;
}
static PySequenceMethods listreviter_as_sequence = {
- (inquiry)listreviter_len, /* sq_length */
+ (lenfunc)listreviter_len, /* sq_length */
0, /* sq_concat */
};
static PyLongObject *
long_normalize(register PyLongObject *v)
{
- int j = ABS(v->ob_size);
- register int i = j;
+ Py_ssize_t j = ABS(v->ob_size);
+ Py_ssize_t i = j;
while (i > 0 && v->ob_digit[i-1] == 0)
--i;
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);
}
_PyLong_Copy(PyLongObject *src)
{
PyLongObject *result;
- int i;
+ Py_ssize_t i;
assert(src != NULL);
i = src->ob_size;
/* 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))
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)) {
+ 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. */
{
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)) {
{
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))
{
PyLongObject *v = (PyLongObject *)vv;
size_t result = 0;
- int ndigits;
+ Py_ssize_t ndigits;
assert(v != NULL);
assert(PyLong_Check(v));
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;
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 */
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)) {
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. */
{
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();
* x[m-1], and the remaining carry (0 or 1) is returned.
*/
static digit
-v_iadd(digit *x, int m, digit *y, int n)
+v_iadd(digit *x, Py_ssize_t m, digit *y, Py_ssize_t n)
{
int i;
digit carry = 0;
* far as x[m-1], and the remaining borrow (0 or 1) is returned.
*/
static digit
-v_isub(digit *x, int m, digit *y, int n)
+v_isub(digit *x, Py_ssize_t m, digit *y, Py_ssize_t n)
{
int i;
digit borrow = 0;
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;
immutable. */
static digit
-inplace_divrem1(digit *pout, digit *pin, int size, digit n)
+inplace_divrem1(digit *pout, digit *pin, Py_ssize_t size, digit n)
{
twodigits rem = 0;
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);
{
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';
/* 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. */
char *p = *str;
char *start = p;
int bits_per_char;
- int n;
+ Py_ssize_t n;
PyLongObject *z;
twodigits accum;
int bits_in_accum;
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);
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;
#ifdef Py_USING_UNICODE
PyObject *
-PyLong_FromUnicode(Py_UNICODE *u, int length, int base)
+PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)
{
PyObject *result;
char *buffer = PyMem_MALLOC(length+1);
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) {
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);
static int
long_compare(PyLongObject *a, PyLongObject *b)
{
- int sign;
+ Py_ssize_t sign;
if (a->ob_size != b->ob_size) {
if (ABS(a->ob_size) == 0 && ABS(b->ob_size) == 0)
sign = a->ob_size - b->ob_size;
}
else {
- int i = ABS(a->ob_size);
+ Py_ssize_t i = ABS(a->ob_size);
while (--i >= 0 && a->ob_digit[i] == b->ob_digit[i])
;
if (i < 0)
long_hash(PyLongObject *v)
{
long x;
- int i, sign;
+ Py_ssize_t i;
+ int sign;
/* This is designed so that Python ints and longs with the
same value hash to the same value, otherwise comparisons
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;
/* Ensure a is the larger of the two: */
if (size_a < size_b) {
{ PyLongObject *temp = a; a = b; b = temp; }
- { int size_temp = size_a;
+ { Py_ssize_t size_temp = size_a;
size_a = size_b;
size_b = size_temp; }
}
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;
+ Py_ssize_t i;
int sign = 1;
digit borrow = 0;
if (size_a < size_b) {
sign = -1;
{ PyLongObject *temp = a; a = b; b = temp; }
- { int size_temp = size_a;
+ { Py_ssize_t size_temp = size_a;
size_a = size_b;
size_b = size_temp; }
}
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)
Returns 0 on success, -1 on failure.
*/
static int
-kmul_split(PyLongObject *n, int size, PyLongObject **high, PyLongObject **low)
+kmul_split(PyLongObject *n, Py_ssize_t 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;
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;
PyLongObject *bl = NULL;
PyLongObject *ret = NULL;
PyLongObject *t1, *t2, *t3;
- int shift; /* the number of digits we split off */
- int i;
+ Py_ssize_t shift; /* the number of digits we split off */
+ 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
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;
nbdone = 0;
while (bsize > 0) {
PyLongObject *product;
- const int nbtouse = MIN(bsize, asize);
+ const Py_ssize_t nbtouse = MIN(bsize, asize);
/* Multiply the next slice of b by a. */
memcpy(bslice->ob_digit, b->ob_digit + nbdone,
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
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);
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);
{
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;
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);
PyCFunctionObject* f = (PyCFunctionObject*)func;
PyCFunction meth = PyCFunction_GET_FUNCTION(func);
PyObject *self = PyCFunction_GET_SELF(func);
- int size;
+ long size;
switch (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)) {
case METH_VARARGS:
if (size == 0)
return (*meth)(self, NULL);
PyErr_Format(PyExc_TypeError,
- "%.200s() takes no arguments (%d given)",
+ "%.200s() takes no arguments (%ld given)",
f->m_ml->ml_name, size);
return NULL;
}
if (size == 1)
return (*meth)(self, PyTuple_GET_ITEM(arg, 0));
PyErr_Format(PyExc_TypeError,
- "%.200s() takes exactly one argument (%d given)",
+ "%.200s() takes exactly one argument (%ld given)",
f->m_ml->ml_name, size);
return NULL;
}
None, rather than deleting them from the dictionary, to
avoid rehashing the dictionary (to some extent). */
- int pos;
+ Py_ssize_t pos;
PyObject *key, *value;
PyObject *d;
}
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();
}
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);
if (dictoffset == 0)
return NULL;
if (dictoffset < 0) {
- int tsize;
+ Py_ssize_t tsize;
size_t size;
tsize = ((PyVarObject *)obj)->ob_size;
/* Inline _PyType_Lookup */
{
- int i, n;
+ Py_ssize_t i, n;
PyObject *mro, *base, *dict;
/* Look in tp_dict of types in MRO */
if (dictoffset != 0) {
PyObject *dict;
if (dictoffset < 0) {
- int tsize;
+ Py_ssize_t tsize;
size_t size;
tsize = ((PyVarObject *)obj)->ob_size;
int
PyObject_IsTrue(PyObject *v)
{
- int res;
+ Py_ssize_t res;
if (v == Py_True)
return 1;
if (v == Py_False)
res = (*v->ob_type->tp_as_sequence->sq_length)(v);
else
return 1;
- return (res > 0) ? 1 : res;
+ /* if it is negative, it should be either -1 or -2 */
+ return (res > 0) ? 1 : Py_SAFE_DOWNCAST(res, Py_ssize_t, int);
}
/* equivalent of 'not v'
PyErr_Clear();
else {
/* We have no guarantee that bases is a real tuple */
- int i, n;
+ Py_ssize_t i, n;
n = PySequence_Size(bases); /* This better be right */
if (n < 0)
PyErr_Clear();
/* Hack to force loading of abstract.o */
-int (*_Py_abstract_hack)(PyObject *) = PyObject_Size;
+Py_ssize_t (*_Py_abstract_hack)(PyObject *) = PyObject_Size;
/* Python's malloc wrappers (see pymem.h) */
{
PyObject *dict;
PyObject *list;
- int i;
+ Py_ssize_t i;
dict = PyThreadState_GetDict();
if (dict == NULL)
{
PyObject *dict;
PyObject *list;
- int i;
+ Py_ssize_t i;
dict = PyThreadState_GetDict();
if (dict == NULL)
/* This is only useful when running memory debuggers such as
* Purify or Valgrind. Uncomment to use.
*
-#define Py_USING_MEMORY_DEBUGGER
*/
+#define Py_USING_MEMORY_DEBUGGER
#ifdef Py_USING_MEMORY_DEBUGGER
{
void *bp;
poolp pool;
- uint size;
+ size_t size;
if (p == NULL)
return PyObject_Malloc(nbytes);
bumpserialno();
total = nbytes + 16;
+#if SIZEOF_SIZE_T < 8
+ /* XXX do this check only on 32-bit machines */
if (total < nbytes || (total >> 31) > 1) {
/* overflow, or we can't represent it in 4 bytes */
/* Obscure: can't do (total >> 32) != 0 instead, because
size_t is an unsigned type. */
return NULL;
}
+#endif
p = (uchar *)PyObject_Malloc(total);
if (p == NULL)
return NULL;
- write4(p, nbytes);
+ write4(p, (ulong)nbytes);
p[4] = p[5] = p[6] = p[7] = FORBIDDENBYTE;
if (nbytes > 0)
if (q == NULL)
return NULL;
- write4(q, nbytes);
+ write4(q, (ulong)nbytes);
assert(q[4] == FORBIDDENBYTE &&
q[5] == FORBIDDENBYTE &&
q[6] == FORBIDDENBYTE &&
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,
"xrange object index out of range");
return NULL;
}
- return PyInt_FromLong(r->start + (i % r->len) * r->step);
+ return PyInt_FromSsize_t(r->start + (i % r->len) * r->step);
}
-static int
+static Py_ssize_t
range_length(rangeobject *r)
{
-#if LONG_MAX != INT_MAX
+#if LONG_MAX != INT_MAX /* XXX ssize_t_max */
if (r->len > INT_MAX) {
PyErr_SetString(PyExc_ValueError,
"xrange object size cannot be reported");
return -1;
}
#endif
- return (int)(r->len);
+ return (Py_ssize_t)(r->len);
}
static PyObject *
}
static PySequenceMethods range_as_sequence = {
- (inquiry)range_length, /* sq_length */
+ (lenfunc)range_length, /* sq_length */
0, /* sq_concat */
0, /* sq_repeat */
- (intargfunc)range_item, /* sq_item */
+ (ssizeargfunc)range_item, /* sq_item */
0, /* sq_slice */
};
static setentry *
set_lookkey(PySetObject *so, PyObject *key, register long hash)
{
- register int i;
- register unsigned int perturb;
+ register Py_ssize_t i;
+ register size_t perturb;
register setentry *freeslot;
register unsigned int mask = so->mask;
setentry *table = so->table;
static setentry *
set_lookkey_string(PySetObject *so, PyObject *key, register long hash)
{
- register int i;
- register unsigned int perturb;
+ register Py_ssize_t i;
+ register size_t perturb;
register setentry *freeslot;
register unsigned int mask = so->mask;
setentry *table = so->table;
* mutates the table.
*/
static int
-set_next(PySetObject *so, int *pos_ptr, setentry **entry_ptr)
+set_next(PySetObject *so, Py_ssize_t *pos_ptr, setentry **entry_ptr)
{
- register int i, mask;
+ Py_ssize_t i;
+ int mask;
register setentry *table;
assert (PyAnySet_Check(so));
set_tp_print(PySetObject *so, FILE *fp, int flags)
{
setentry *entry;
- int pos=0;
+ Py_ssize_t pos=0;
char *emit = ""; /* No separator emitted on first pass */
char *separator = ", ";
return result;
}
-static int
+static Py_ssize_t
set_len(PyObject *so)
{
return ((PySetObject *)so)->used;
static int
set_traverse(PySetObject *so, visitproc visit, void *arg)
{
- int pos = 0;
+ Py_ssize_t pos = 0;
setentry *entry;
while (set_next(so, &pos, &entry))
PySetObject *so = (PySetObject *)self;
long h, hash = 1927868237L;
setentry *entry;
- int pos = 0;
+ Py_ssize_t pos = 0;
if (so->hash != -1)
return so->hash;
static PyObject *
setiter_len(setiterobject *si)
{
- int len = 0;
+ long len = 0;
if (si->si_set != NULL && si->si_used == si->si_set->used)
len = si->len;
return PyInt_FromLong(len);
if (PyDict_Check(other)) {
PyObject *value;
- int pos = 0;
+ Py_ssize_t pos = 0;
while (PyDict_Next(other, &pos, &key, &value)) {
if (set_add_key(so, key) == -1)
return -1;
return NULL;
if (PyAnySet_Check(other)) {
- int pos = 0;
+ Py_ssize_t pos = 0;
setentry *entry;
if (PySet_GET_SIZE(other) > PySet_GET_SIZE(so)) {
if (PyAnySet_Check(other)) {
setentry *entry;
- int pos = 0;
+ Py_ssize_t pos = 0;
while (set_next((PySetObject *)other, &pos, &entry))
set_discard_entry(so, entry);
{
PyObject *result;
setentry *entry;
- int pos = 0;
+ Py_ssize_t pos = 0;
if (!PyAnySet_Check(other) && !PyDict_Check(other)) {
result = set_copy(so);
{
PySetObject *otherset;
PyObject *key;
- int pos = 0;
+ Py_ssize_t pos = 0;
setentry *entry;
if ((PyObject *)so == other)
set_issubset(PySetObject *so, PyObject *other)
{
setentry *entry;
- int pos = 0;
+ Py_ssize_t pos = 0;
if (!PyAnySet_Check(other)) {
PyObject *tmp, *result;
}
static PySequenceMethods set_as_sequence = {
- (inquiry)set_len, /* sq_length */
+ (lenfunc)set_len, /* sq_length */
0, /* sq_concat */
0, /* sq_repeat */
0, /* sq_item */
}
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 {
}
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;
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);
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);
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;
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;
PyObject *PyString_Decode(const char *s,
- int size,
+ Py_ssize_t size,
const char *encoding,
const char *errors)
{
}
PyObject *PyString_Encode(const char *s,
- int size,
+ Py_ssize_t size,
const char *encoding,
const char *errors)
{
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;
PyObject *u, *w;
char *r;
const char* t;
- int rn;
+ Py_ssize_t rn;
t = s;
/* Decode non-ASCII bytes as UTF-8. */
while (t < end && (*t & 0x80)) t++;
}
}
if (p-buf < newlen)
- _PyString_Resize(&v, (int)(p - buf));
+ _PyString_Resize(&v, p - buf);
return v;
failed:
Py_DECREF(v);
return NULL;
}
-static int
+static Py_ssize_t
string_getsize(register PyObject *op)
{
char *s;
- int len;
+ Py_ssize_t len;
if (PyString_AsStringAndSize(op, &s, &len))
return -1;
return len;
string_getbuffer(register PyObject *op)
{
char *s;
- int len;
+ Py_ssize_t len;
if (PyString_AsStringAndSize(op, &s, &len))
return NULL;
return s;
}
-int
+Py_ssize_t
PyString_Size(register PyObject *op)
{
if (!PyString_Check(op))
int
PyString_AsStringAndSize(register PyObject *obj,
register char **s,
- register int *len)
+ register Py_ssize_t *len)
{
if (s == NULL) {
PyErr_BadInternalCall();
*s = PyString_AS_STRING(obj);
if (len != NULL)
*len = PyString_GET_SIZE(obj);
- else if ((int)strlen(*s) != PyString_GET_SIZE(obj)) {
+ else if (strlen(*s) != PyString_GET_SIZE(obj)) {
PyErr_SetString(PyExc_TypeError,
"expected string without null bytes");
return -1;
static int
string_print(PyStringObject *op, FILE *fp, int flags)
{
- int i;
+ Py_ssize_t i;
char c;
int quote;
return NULL;
}
else {
- register int i;
+ register Py_ssize_t i;
register char c;
register char *p;
int quote;
}
}
-static int
+static Py_ssize_t
string_length(PyStringObject *a)
{
return a->ob_size;
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
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)
PyObject_INIT_VAR(op, &PyString_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
- memcpy(op->ob_sval, a->ob_sval, (int) a->ob_size);
- memcpy(op->ob_sval + a->ob_size, b->ob_sval, (int) b->ob_size);
+ memcpy(op->ob_sval, a->ob_sval, a->ob_size);
+ memcpy(op->ob_sval + a->ob_size, b->ob_sval, b->ob_size);
op->ob_sval[size] = '\0';
return (PyObject *) op;
#undef b
}
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 i;
+ register Py_ssize_t j;
+ register Py_ssize_t size;
register PyStringObject *op;
size_t nbytes;
if (n < 0)
}
i = 0;
if (i < size) {
- memcpy(op->ob_sval, a->ob_sval, (int) a->ob_size);
- i = (int) a->ob_size;
+ memcpy(op->ob_sval, a->ob_sval, a->ob_size);
+ i = a->ob_size;
}
while (i < size) {
j = (i <= size-i) ? i : size-i;
/* 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)
}
if (j < i)
j = i;
- return PyString_FromStringAndSize(a->ob_sval + i, (int) (j-i));
+ return PyString_FromStringAndSize(a->ob_sval + i, j-i);
}
static int
char *s = PyString_AS_STRING(a);
const char *sub = PyString_AS_STRING(el);
char *last;
- int len_sub = PyString_GET_SIZE(el);
+ Py_ssize_t len_sub = PyString_GET_SIZE(el);
int shortsub;
char firstchar, lastchar;
}
static PyObject *
-string_item(PyStringObject *a, register int i)
+string_item(PyStringObject *a, register Py_ssize_t i)
{
PyObject *v;
char *pchar;
string_richcompare(PyStringObject *a, PyStringObject *b, int op)
{
int c;
- int len_a, len_b;
- int min_len;
+ Py_ssize_t len_a, len_b;
+ Py_ssize_t min_len;
PyObject *result;
/* Make sure both arguments are strings. */
static long
string_hash(PyStringObject *a)
{
- register int len;
+ register Py_ssize_t len;
register unsigned char *p;
register long x;
static PyObject*
string_subscript(PyStringObject* self, PyObject* item)
{
- if (PyInt_Check(item)) {
- long i = PyInt_AS_LONG(item);
- if (i < 0)
- i += PyString_GET_SIZE(self);
- return string_item(self,i);
- }
- else if (PyLong_Check(item)) {
- long i = PyLong_AsLong(item);
+ if (PyInt_Check(item) || PyLong_Check(item)) {
+ Py_ssize_t i = PyInt_AsSsize_t(item);
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)
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;
}
}
-static int
-string_buffer_getreadbuf(PyStringObject *self, int index, const void **ptr)
+static Py_ssize_t
+string_buffer_getreadbuf(PyStringObject *self, Py_ssize_t index, const void **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
return self->ob_size;
}
-static int
-string_buffer_getwritebuf(PyStringObject *self, int index, const void **ptr)
+static Py_ssize_t
+string_buffer_getwritebuf(PyStringObject *self, Py_ssize_t index, const void **ptr)
{
PyErr_SetString(PyExc_TypeError,
"Cannot use string as modifiable buffer");
return -1;
}
-static int
-string_buffer_getsegcount(PyStringObject *self, int *lenp)
+static Py_ssize_t
+string_buffer_getsegcount(PyStringObject *self, Py_ssize_t *lenp)
{
if ( lenp )
*lenp = self->ob_size;
return 1;
}
-static int
-string_buffer_getcharbuf(PyStringObject *self, int index, const char **ptr)
+static Py_ssize_t
+string_buffer_getcharbuf(PyStringObject *self, Py_ssize_t index, const char **ptr)
{
if ( index != 0 ) {
PyErr_SetString(PyExc_SystemError,
}
static PySequenceMethods string_as_sequence = {
- (inquiry)string_length, /*sq_length*/
+ (lenfunc)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*/
};
static PyMappingMethods string_as_mapping = {
- (inquiry)string_length,
+ (lenfunc)string_length,
(binaryfunc)string_subscript,
0,
};
static PyBufferProcs string_as_buffer = {
- (getreadbufferproc)string_buffer_getreadbuf,
- (getwritebufferproc)string_buffer_getwritebuf,
- (getsegcountproc)string_buffer_getsegcount,
- (getcharbufferproc)string_buffer_getcharbuf,
+ (readbufferproc)string_buffer_getreadbuf,
+ (writebufferproc)string_buffer_getwritebuf,
+ (segcountproc)string_buffer_getsegcount,
+ (charbufferproc)string_buffer_getcharbuf,
};
Py_DECREF(str);
static PyObject *
-split_whitespace(const char *s, int len, int maxsplit)
+split_whitespace(const char *s, Py_ssize_t len, int maxsplit)
{
- int i, j;
+ Py_ssize_t i, j;
PyObject *str;
PyObject *list = PyList_New(0);
}
static PyObject *
-split_char(const char *s, int len, char ch, int maxcount)
+split_char(const char *s, Py_ssize_t len, char ch, int maxcount)
{
- register int i, j;
+ register Py_ssize_t i, j;
PyObject *str;
PyObject *list = PyList_New(0);
static PyObject *
string_split(PyStringObject *self, PyObject *args)
{
- int len = PyString_GET_SIZE(self), n, i, j, err;
+ Py_ssize_t len = PyString_GET_SIZE(self), n, i, j;
+ int err;
int maxsplit = -1;
const char *s = PyString_AS_STRING(self), *sub;
PyObject *list, *item, *subobj = Py_None;
if (s[i] == sub[0] && memcmp(s+i, sub, n) == 0) {
if (maxsplit-- <= 0)
break;
- item = PyString_FromStringAndSize(s+j, (int)(i-j));
+ item = PyString_FromStringAndSize(s+j, i-j);
if (item == NULL)
goto fail;
err = PyList_Append(list, item);
else
i++;
}
- item = PyString_FromStringAndSize(s+j, (int)(len-j));
+ item = PyString_FromStringAndSize(s+j, len-j);
if (item == NULL)
goto fail;
err = PyList_Append(list, item);
}
static PyObject *
-rsplit_whitespace(const char *s, int len, int maxsplit)
+rsplit_whitespace(const char *s, Py_ssize_t len, int maxsplit)
{
- int i, j;
+ Py_ssize_t i, j;
PyObject *str;
PyObject *list = PyList_New(0);
}
static PyObject *
-rsplit_char(const char *s, int len, char ch, int maxcount)
+rsplit_char(const char *s, Py_ssize_t len, char ch, int maxcount)
{
- register int i, j;
+ register Py_ssize_t i, j;
PyObject *str;
PyObject *list = PyList_New(0);
static PyObject *
string_rsplit(PyStringObject *self, PyObject *args)
{
- int len = PyString_GET_SIZE(self), n, i, j, err;
+ Py_ssize_t len = PyString_GET_SIZE(self), n, i, j;
+ int err;
int maxsplit = -1;
const char *s = PyString_AS_STRING(self), *sub;
PyObject *list, *item, *subobj = Py_None;
if (s[i] == sub[0] && memcmp(s+i, sub, n) == 0) {
if (maxsplit-- <= 0)
break;
- item = PyString_FromStringAndSize(s+i+n, (int)(j-i-n));
+ item = PyString_FromStringAndSize(s+i+n, j-i-n);
if (item == NULL)
goto fail;
err = PyList_Insert(list, 0, item);
string_join(PyStringObject *self, PyObject *orig)
{
char *sep = PyString_AS_STRING(self);
- const int seplen = PyString_GET_SIZE(self);
+ const Py_ssize_t seplen = PyString_GET_SIZE(self);
PyObject *res = NULL;
char *p;
- int seqlen = 0;
+ Py_ssize_t seqlen = 0;
size_t sz = 0;
- int i;
+ Py_ssize_t i;
PyObject *seq, *item;
seq = PySequence_Fast(orig, "");
PyErr_Format(PyExc_TypeError,
"sequence item %i: expected string,"
" %.80s found",
- i, item->ob_type->tp_name);
+ /*XXX*/(int)i, item->ob_type->tp_name);
Py_DECREF(seq);
return NULL;
}
}
/* Allocate result space. */
- res = PyString_FromStringAndSize((char*)NULL, (int)sz);
+ res = PyString_FromStringAndSize((char*)NULL, sz);
if (res == NULL) {
Py_DECREF(seq);
return NULL;
}
static void
-string_adjust_indices(int *start, int *end, int len)
+string_adjust_indices(Py_ssize_t *start, Py_ssize_t *end, Py_ssize_t len)
{
if (*end > len)
*end = len;
*start = 0;
}
-static long
+static Py_ssize_t
string_find_internal(PyStringObject *self, PyObject *args, int dir)
{
const char *s = PyString_AS_STRING(self), *sub;
- int len = PyString_GET_SIZE(self);
- int n, i = 0, last = INT_MAX;
+ Py_ssize_t len = PyString_GET_SIZE(self);
+ Py_ssize_t 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;
return (long)i;
}
else {
- int j;
+ Py_ssize_t j;
if (n == 0 && i <= last)
- return (long)last;
+ return last;
for (j = last-n; j >= i; --j)
if (s[j] == sub[0] && memcmp(&s[j], sub, n) == 0)
- return (long)j;
+ return j;
}
return -1;
static PyObject *
string_find(PyStringObject *self, PyObject *args)
{
- long result = string_find_internal(self, args, +1);
+ Py_ssize_t result = string_find_internal(self, args, +1);
if (result == -2)
return NULL;
- return PyInt_FromLong(result);
+ return PyInt_FromSsize_t(result);
}
static PyObject *
string_index(PyStringObject *self, PyObject *args)
{
- long result = string_find_internal(self, args, +1);
+ Py_ssize_t result = string_find_internal(self, args, +1);
if (result == -2)
return NULL;
if (result == -1) {
"substring not found");
return NULL;
}
- return PyInt_FromLong(result);
+ return PyInt_FromSsize_t(result);
}
static PyObject *
string_rfind(PyStringObject *self, PyObject *args)
{
- long result = string_find_internal(self, args, -1);
+ Py_ssize_t result = string_find_internal(self, args, -1);
if (result == -2)
return NULL;
- return PyInt_FromLong(result);
+ return PyInt_FromSsize_t(result);
}
static PyObject *
string_rindex(PyStringObject *self, PyObject *args)
{
- long result = string_find_internal(self, args, -1);
+ Py_ssize_t result = string_find_internal(self, args, -1);
if (result == -2)
return NULL;
if (result == -1) {
"substring not found");
return NULL;
}
- return PyInt_FromLong(result);
+ return PyInt_FromSsize_t(result);
}
do_xstrip(PyStringObject *self, int striptype, PyObject *sepobj)
{
char *s = PyString_AS_STRING(self);
- int len = PyString_GET_SIZE(self);
+ Py_ssize_t len = PyString_GET_SIZE(self);
char *sep = PyString_AS_STRING(sepobj);
- int seplen = PyString_GET_SIZE(sepobj);
- int i, j;
+ Py_ssize_t seplen = PyString_GET_SIZE(sepobj);
+ Py_ssize_t i, j;
i = 0;
if (striptype != RIGHTSTRIP) {
do_strip(PyStringObject *self, int striptype)
{
char *s = PyString_AS_STRING(self);
- int len = PyString_GET_SIZE(self), i, j;
+ Py_ssize_t len = PyString_GET_SIZE(self), i, j;
i = 0;
if (striptype != RIGHTSTRIP) {
string_lower(PyStringObject *self)
{
char *s = PyString_AS_STRING(self), *s_new;
- int i, n = PyString_GET_SIZE(self);
+ Py_ssize_t i, n = PyString_GET_SIZE(self);
PyObject *new;
new = PyString_FromStringAndSize(NULL, n);
string_upper(PyStringObject *self)
{
char *s = PyString_AS_STRING(self), *s_new;
- int i, n = PyString_GET_SIZE(self);
+ Py_ssize_t i, n = PyString_GET_SIZE(self);
PyObject *new;
new = PyString_FromStringAndSize(NULL, n);
string_title(PyStringObject *self)
{
char *s = PyString_AS_STRING(self), *s_new;
- int i, n = PyString_GET_SIZE(self);
+ Py_ssize_t i, n = PyString_GET_SIZE(self);
int previous_is_cased = 0;
PyObject *new;
string_capitalize(PyStringObject *self)
{
char *s = PyString_AS_STRING(self), *s_new;
- int i, n = PyString_GET_SIZE(self);
+ Py_ssize_t i, n = PyString_GET_SIZE(self);
PyObject *new;
new = PyString_FromStringAndSize(NULL, n);
string_count(PyStringObject *self, PyObject *args)
{
const char *s = PyString_AS_STRING(self), *sub, *t;
- int len = PyString_GET_SIZE(self), n;
- int i = 0, last = INT_MAX;
- int m, r;
+ Py_ssize_t len = PyString_GET_SIZE(self), n;
+ Py_ssize_t i = 0, last = INT_MAX;
+ Py_ssize_t m, r;
PyObject *subobj;
if (!PyArg_ParseTuple(args, "O|O&O&:count", &subobj,
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(subobj)) {
- int count;
+ Py_ssize_t count;
count = PyUnicode_Count((PyObject *)self, subobj, i, last);
if (count == -1)
return NULL;
m = last + 1 - n;
if (n == 0)
- return PyInt_FromLong((long) (m-i));
+ return PyInt_FromSsize_t(m-i);
r = 0;
while (i < m) {
break;
i = t - s;
}
- return PyInt_FromLong((long) r);
+ return PyInt_FromSsize_t(r);
}
PyDoc_STRVAR(swapcase__doc__,
string_swapcase(PyStringObject *self)
{
char *s = PyString_AS_STRING(self), *s_new;
- int i, n = PyString_GET_SIZE(self);
+ Py_ssize_t i, n = PyString_GET_SIZE(self);
PyObject *new;
new = PyString_FromStringAndSize(NULL, n);
{
register char *input, *output;
register const char *table;
- register int i, c, changed = 0;
+ register Py_ssize_t i, c, changed = 0;
PyObject *input_obj = (PyObject*)self;
const char *table1, *output_start, *del_table=NULL;
- int inlen, tablen, dellen = 0;
+ Py_ssize_t inlen, tablen, dellen = 0;
PyObject *result;
int trans_table[256];
PyObject *tableobj, *delobj = NULL;
found, or -1 if not found. If len of PAT is greater than length of
MEM, the function returns -1.
*/
-static int
-mymemfind(const char *mem, int len, const char *pat, int pat_len)
+static Py_ssize_t
+mymemfind(const char *mem, Py_ssize_t len, const char *pat, Py_ssize_t pat_len)
{
- register int ii;
+ register Py_ssize_t ii;
/* pattern can not occur in the last pat_len-1 chars */
len -= pat_len;
meaning mem=1111 and pat==11 returns 2.
mem=11111 and pat==11 also return 2.
*/
-static int
-mymemcnt(const char *mem, int len, const char *pat, int pat_len)
+static Py_ssize_t
+mymemcnt(const char *mem, Py_ssize_t len, const char *pat, Py_ssize_t pat_len)
{
- register int offset = 0;
- int nfound = 0;
+ register Py_ssize_t offset = 0;
+ Py_ssize_t nfound = 0;
while (len >= 0) {
offset = mymemfind(mem, len, pat, pat_len);
NULL if an error occurred.
*/
static char *
-mymemreplace(const char *str, int len, /* input string */
- const char *pat, int pat_len, /* pattern string to find */
- const char *sub, int sub_len, /* substitution string */
- int count, /* number of replacements */
- int *out_len)
+mymemreplace(const char *str, Py_ssize_t len, /* input string */
+ const char *pat, Py_ssize_t pat_len, /* pattern string to find */
+ const char *sub, Py_ssize_t sub_len, /* substitution string */
+ Py_ssize_t count, /* number of replacements */
+ Py_ssize_t *out_len)
{
char *out_s;
char *new_s;
- int nfound, offset, new_len;
+ Py_ssize_t nfound, offset, new_len;
if (len == 0 || (pat_len == 0 && sub_len == 0) || pat_len > len)
goto return_same;
{
const char *str = PyString_AS_STRING(self), *sub, *repl;
char *new_s;
- const int len = PyString_GET_SIZE(self);
- int sub_len, repl_len, out_len;
+ const Py_ssize_t len = PyString_GET_SIZE(self);
+ Py_ssize_t sub_len, repl_len, out_len;
int count = -1;
PyObject *new;
PyObject *subobj, *replobj;
string_startswith(PyStringObject *self, PyObject *args)
{
const char* str = PyString_AS_STRING(self);
- int len = PyString_GET_SIZE(self);
+ Py_ssize_t len = PyString_GET_SIZE(self);
const char* prefix;
- int plen;
- int start = 0;
- int end = INT_MAX;
+ Py_ssize_t plen;
+ Py_ssize_t start = 0;
+ Py_ssize_t end = INT_MAX;
PyObject *subobj;
if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &subobj,
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(subobj)) {
- int rc;
+ Py_ssize_t rc;
rc = PyUnicode_Tailmatch((PyObject *)self,
subobj, start, end, -1);
if (rc == -1)
string_endswith(PyStringObject *self, PyObject *args)
{
const char* str = PyString_AS_STRING(self);
- int len = PyString_GET_SIZE(self);
+ Py_ssize_t len = PyString_GET_SIZE(self);
const char* suffix;
- int slen;
- int start = 0;
- int end = INT_MAX;
+ Py_ssize_t slen;
+ Py_ssize_t start = 0;
+ Py_ssize_t end = INT_MAX;
PyObject *subobj;
if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &subobj,
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(subobj)) {
- int rc;
+ Py_ssize_t rc;
rc = PyUnicode_Tailmatch((PyObject *)self,
subobj, start, end, +1);
if (rc == -1)
{
const char *e, *p;
char *q;
- int i, j;
+ Py_ssize_t i, j;
PyObject *u;
int tabsize = 8;
}
static PyObject *
-pad(PyStringObject *self, int left, int right, char fill)
+pad(PyStringObject *self, Py_ssize_t left, Py_ssize_t right, char fill)
{
PyObject *u;
static PyObject *
string_center(PyStringObject *self, PyObject *args)
{
- int marg, left;
- int width;
+ Py_ssize_t marg, left;
+ long width;
char fillchar = ' ';
- if (!PyArg_ParseTuple(args, "i|c:center", &width, &fillchar))
+ if (!PyArg_ParseTuple(args, "l|c:center", &width, &fillchar))
return NULL;
if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
static PyObject *
string_zfill(PyStringObject *self, PyObject *args)
{
- int fill;
+ long fill;
PyObject *s;
char *p;
int width;
- if (!PyArg_ParseTuple(args, "i:zfill", &width))
+ if (!PyArg_ParseTuple(args, "l:zfill", &width))
return NULL;
if (PyString_GET_SIZE(self) >= width) {
static PyObject*
string_splitlines(PyStringObject *self, PyObject *args)
{
- register int i;
- register int j;
- int len;
+ register Py_ssize_t i;
+ register Py_ssize_t j;
+ Py_ssize_t len;
int keepends = 0;
PyObject *list;
PyObject *str;
goto onError;
for (i = j = 0; i < len; ) {
- int eol;
+ Py_ssize_t eol;
/* Find a line and append it */
while (i < len && data[i] != '\n' && data[i] != '\r')
str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *tmp, *pnew;
- int n;
+ Py_ssize_t n;
assert(PyType_IsSubtype(type, &PyString_Type));
tmp = string_new(&PyString_Type, args, kwds);
*/
int
-_PyString_Resize(PyObject **pv, int newsize)
+_PyString_Resize(PyObject **pv, Py_ssize_t newsize)
{
register PyObject *v;
register PyStringObject *sv;
(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
{
PyObject *result = NULL;
char *buf;
- int i;
+ Py_ssize_t i;
int sign; /* 1 if '-', else 0 */
int len; /* number of characters */
int numdigits; /* len == numnondigits + numdigits */
PyOS_snprintf(buf, buflen, fmt, -x);
else
PyOS_snprintf(buf, buflen, fmt, x);
- return strlen(buf);
+ return (int)strlen(buf);
}
static int
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
else {
/* Got a format specifier */
int flags = 0;
- int width = -1;
+ Py_ssize_t width = -1;
int prec = -1;
int c = '\0';
int fill;
fmt++;
if (*fmt == '(') {
char *keystart;
- int keylen;
+ Py_ssize_t keylen;
PyObject *key;
int pcount = 1;
{
PyObject *keys;
PyStringObject *s;
- int i, n;
+ Py_ssize_t i, n;
if (interned == NULL || !PyDict_Check(interned))
return;
static void
structseq_dealloc(PyStructSequence *obj)
{
- int i, size;
+ Py_ssize_t i, size;
size = REAL_SIZE(obj);
for (i = 0; i < size; ++i) {
PyObject_Del(obj);
}
-static int
+static Py_ssize_t
structseq_length(PyStructSequence *obj)
{
return VISIBLE_SIZE(obj);
}
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");
}
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;
+ Py_ssize_t i;
if (low < 0)
low = 0;
PyObject *dict = NULL;
PyObject *ob;
PyStructSequence *res = NULL;
- int len, min_len, max_len, i, n_unnamed_fields;
+ Py_ssize_t len, min_len, max_len, i, n_unnamed_fields;
static const char *kwlist[] = {"sequence", "dict", 0};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:structseq",
if (min_len != max_len) {
if (len < min_len) {
PyErr_Format(PyExc_TypeError,
- "%.500s() takes an at least %d-sequence (%d-sequence given)",
+ "%.500s() takes an at least %ld-sequence (%ld-sequence given)",
type->tp_name, min_len, len);
Py_DECREF(arg);
return NULL;
if (len > max_len) {
PyErr_Format(PyExc_TypeError,
- "%.500s() takes an at most %d-sequence (%d-sequence given)",
+ "%.500s() takes an at most %ld-sequence (%ld-sequence given)",
type->tp_name, max_len, len);
Py_DECREF(arg);
return NULL;
else {
if (len != min_len) {
PyErr_Format(PyExc_TypeError,
- "%.500s() takes a %d-sequence (%d-sequence given)",
+ "%.500s() takes a %ld-sequence (%ld-sequence given)",
type->tp_name, min_len, len);
Py_DECREF(arg);
return NULL;
}
static PyObject *
-structseq_repeat(PyStructSequence *obj, int n)
+structseq_repeat(PyStructSequence *obj, Py_ssize_t n)
{
PyObject *tup, *result;
tup = make_tuple(obj);
}
static PySequenceMethods structseq_as_sequence = {
- (inquiry)structseq_length,
+ (lenfunc)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 */
#endif
PyObject *
-PyTuple_New(register int size)
+PyTuple_New(register Py_ssize_t size)
{
register PyTupleObject *op;
- int i;
+ Py_ssize_t i;
if (size < 0) {
PyErr_BadInternalCall();
return NULL;
else
#endif
{
- int nbytes = size * sizeof(PyObject *);
+ Py_ssize_t nbytes = size * sizeof(PyObject *);
/* Check for overflow */
if (nbytes / sizeof(PyObject *) != (size_t)size ||
(nbytes += sizeof(PyTupleObject) - sizeof(PyObject *))
return (PyObject *) op;
}
-int
+Py_ssize_t
PyTuple_Size(register PyObject *op)
{
if (!PyTuple_Check(op)) {
}
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();
}
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;
}
PyObject *
-PyTuple_Pack(int n, ...)
+PyTuple_Pack(Py_ssize_t n, ...)
{
- int i;
+ Py_ssize_t i;
PyObject *o;
PyObject *result;
PyObject **items;
static void
tupledealloc(register PyTupleObject *op)
{
- register int i;
- register int len = op->ob_size;
+ register Py_ssize_t i;
+ register Py_ssize_t len = op->ob_size;
PyObject_GC_UnTrack(op);
Py_TRASHCAN_SAFE_BEGIN(op)
if (len > 0) {
static int
tupleprint(PyTupleObject *op, FILE *fp, int flags)
{
- int i;
+ Py_ssize_t i;
fprintf(fp, "(");
for (i = 0; i < op->ob_size; i++) {
if (i > 0)
static PyObject *
tuplerepr(PyTupleObject *v)
{
- int i, n;
+ Py_ssize_t i, n;
PyObject *s, *temp;
PyObject *pieces, *result = NULL;
tuplehash(PyTupleObject *v)
{
register long x, y;
- register int len = v->ob_size;
+ register Py_ssize_t len = v->ob_size;
register PyObject **p;
long mult = 1000003L;
x = 0x345678L;
return x;
}
-static int
+static Py_ssize_t
tuplelength(PyTupleObject *a)
{
return a->ob_size;
static int
tuplecontains(PyTupleObject *a, PyObject *el)
{
- int i, cmp;
+ Py_ssize_t i;
+ int cmp;
for (i = 0, cmp = 0 ; cmp == 0 && i < a->ob_size; ++i)
cmp = PyObject_RichCompareBool(el, PyTuple_GET_ITEM(a, i),
}
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");
}
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;
- register int i;
- int len;
+ register Py_ssize_t i;
+ Py_ssize_t len;
if (ilow < 0)
ilow = 0;
if (ihigh > a->ob_size)
}
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();
static PyObject *
tupleconcat(register PyTupleObject *a, register PyObject *bb)
{
- register int size;
- register int i;
+ register Py_ssize_t size;
+ register Py_ssize_t i;
PyObject **src, **dest;
PyTupleObject *np;
if (!PyTuple_Check(bb)) {
}
static PyObject *
-tuplerepeat(PyTupleObject *a, int n)
+tuplerepeat(PyTupleObject *a, Py_ssize_t n)
{
- int i, j;
- int size;
+ Py_ssize_t i, j;
+ Py_ssize_t size;
PyTupleObject *np;
PyObject **p, **items;
if (n < 0)
static int
tupletraverse(PyTupleObject *o, visitproc visit, void *arg)
{
- int i, err;
+ Py_ssize_t i;
PyObject *x;
for (i = o->ob_size; --i >= 0; ) {
x = o->ob_item[i];
if (x != NULL) {
- err = visit(x, arg);
+ int err = visit(x, arg);
if (err)
return err;
}
tuplerichcompare(PyObject *v, PyObject *w, int op)
{
PyTupleObject *vt, *wt;
- int i;
- int vlen, wlen;
+ Py_ssize_t i;
+ Py_ssize_t vlen, wlen;
if (!PyTuple_Check(v) || !PyTuple_Check(w)) {
Py_INCREF(Py_NotImplemented);
tuple_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *tmp, *new, *item;
- int i, n;
+ Py_ssize_t i, n;
assert(PyType_IsSubtype(type, &PyTuple_Type));
tmp = tuple_new(&PyTuple_Type, args, kwds);
"If the argument is a tuple, the return value is the same object.");
static PySequenceMethods tuple_as_sequence = {
- (inquiry)tuplelength, /* sq_length */
+ (lenfunc)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 */
static PyObject*
tuplesubscript(PyTupleObject* self, PyObject* item)
{
- if (PyInt_Check(item)) {
- long i = PyInt_AS_LONG(item);
- if (i < 0)
- i += PyTuple_GET_SIZE(self);
- return tupleitem(self, i);
- }
- else if (PyLong_Check(item)) {
- long i = PyLong_AsLong(item);
+ if (PyInt_Check(item) || PyLong_Check(item)) {
+ Py_ssize_t i = PyInt_AsSsize_t(item);
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)
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;
};
static PyMappingMethods tuple_as_mapping = {
- (inquiry)tuplelength,
+ (lenfunc)tuplelength,
(binaryfunc)tuplesubscript,
0
};
known to some other part of the code. */
int
-_PyTuple_Resize(PyObject **pv, int newsize)
+_PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
{
register PyTupleObject *v;
register PyTupleObject *sv;
- int i;
- int oldsize;
+ Py_ssize_t i;
+ Py_ssize_t oldsize;
v = (PyTupleObject *) *pv;
if (v == NULL || v->ob_type != &PyTuple_Type ||
static PyObject *
tupleiter_len(tupleiterobject *it)
{
- int len = 0;
+ long len = 0;
if (it->it_seq)
len = PyTuple_GET_SIZE(it->it_seq) - it->it_index;
return PyInt_FromLong(len);
{
PyTypeObject *subclass;
PyObject *ref, *subclasses, *old_mro;
- int i, n;
+ Py_ssize_t i, n;
subclasses = type->tp_subclasses;
if (subclasses == NULL)
static int
type_set_bases(PyTypeObject *type, PyObject *value, void *context)
{
- int i, r = 0;
+ Py_ssize_t i;
+ int r = 0;
PyObject *ob, *temp;
PyTypeObject *new_base, *old_base;
PyObject *old_bases, *old_mro;
}
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);
static int
traverse_slots(PyTypeObject *type, PyObject *self, visitproc visit, void *arg)
{
- int i, n;
+ Py_ssize_t i, n;
PyMemberDef *mp;
n = type->ob_size;
static void
clear_slots(PyTypeObject *type, PyObject *self)
{
- int i, n;
+ Py_ssize_t i, n;
PyMemberDef *mp;
n = type->ob_size;
if (mro != NULL) {
/* Deal with multiple inheritance without recursion
by walking the MRO tuple */
- int i, n;
+ Py_ssize_t i, n;
assert(PyTuple_Check(mro));
n = PyTuple_GET_SIZE(mro);
for (i = 0; i < n; i++) {
fill_classic_mro(PyObject *mro, PyObject *cls)
{
PyObject *bases, *base;
- int i, n;
+ Py_ssize_t i, n;
assert(PyList_Check(mro));
assert(PyClass_Check(cls));
static int
tail_contains(PyObject *list, int whence, PyObject *o) {
- int j, size;
+ Py_ssize_t j, size;
size = PyList_GET_SIZE(list);
for (j = whence+1; j < size; j++) {
static int
check_duplicates(PyObject *list)
{
- int i, j, n;
+ Py_ssize_t i, j, n;
/* Let's use a quadratic time algorithm,
assuming that the bases lists is short.
*/
static void
set_mro_error(PyObject *to_merge, int *remain)
{
- int i, n, off, to_merge_size;
+ Py_ssize_t i, n, off, to_merge_size;
char buf[1000];
PyObject *k, *v;
PyObject *set = PyDict_New();
static int
pmerge(PyObject *acc, PyObject* to_merge) {
- int i, j, to_merge_size;
+ Py_ssize_t i, j, to_merge_size, empty_cnt;
int *remain;
- int ok, empty_cnt;
+ int ok;
to_merge_size = PyList_GET_SIZE(to_merge);
static PyObject *
mro_implementation(PyTypeObject *type)
{
- int i, n, ok;
+ Py_ssize_t i, n;
+ int ok;
PyObject *bases, *result;
PyObject *to_merge, *bases_aslist;
if (tuple == NULL)
return -1;
if (checkit) {
- int i, len;
+ Py_ssize_t i, len;
PyObject *cls;
PyTypeObject *solid;
static PyTypeObject *
best_base(PyObject *bases)
{
- int i, n;
+ Py_ssize_t i, n;
PyTypeObject *base, *winner, *candidate, *base_i;
PyObject *base_proto;
valid_identifier(PyObject *s)
{
unsigned char *p;
- int i, n;
+ Py_ssize_t i, n;
if (!PyString_Check(s)) {
PyErr_SetString(PyExc_TypeError,
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) {
PyTypeObject *type, *base, *tmptype, *winner;
PyHeapTypeObject *et;
PyMemberDef *mp;
- int i, nbases, nslots, slotoffset, add_dict, add_weak;
+ Py_ssize_t i, nbases, nslots, slotoffset, add_dict, add_weak;
int j, may_add_dict, may_add_weak;
assert(args != NULL && PyTuple_Check(args));
/* Special case: type(x) should return x->ob_type */
{
- const int nargs = PyTuple_GET_SIZE(args);
- const int nkwds = kwds == NULL ? 0 : PyDict_Size(kwds);
+ const Py_ssize_t nargs = PyTuple_GET_SIZE(args);
+ const Py_ssize_t nkwds = kwds == NULL ? 0 : PyDict_Size(kwds);
if (PyType_CheckExact(metatype) && nargs == 1 && nkwds == 0) {
PyObject *x = PyTuple_GET_ITEM(args, 0);
PyObject *
_PyType_Lookup(PyTypeObject *type, PyObject *name)
{
- int i, n;
+ Py_ssize_t i, n;
PyObject *mro, *res, *base, *dict;
/* Look in tp_dict of types in MRO */
type_subclasses(PyTypeObject *type, PyObject *args_ignored)
{
PyObject *list, *raw, *ref;
- int i, n;
+ Py_ssize_t i, n;
list = PyList_New(0);
if (list == NULL)
PyObject *getstate = NULL, *state = NULL, *names = NULL;
PyObject *slots = NULL, *listitems = NULL, *dictitems = NULL;
PyObject *copy_reg = NULL, *newobj = NULL, *res = NULL;
- int i, n;
+ Py_ssize_t i, n;
cls = PyObject_GetAttrString(obj, "__class__");
if (cls == NULL)
{
PyObject *dict, *bases;
PyTypeObject *base;
- int i, n;
+ Py_ssize_t i, n;
if (type->tp_flags & Py_TPFLAGS_READY) {
assert(type->tp_dict != NULL);
static void
remove_subclass(PyTypeObject *base, PyTypeObject *type)
{
- int i;
+ Py_ssize_t i;
PyObject *list, *ref;
list = base->tp_subclasses;
}
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;
}
entries, one regular and one with reversed arguments. */
static PyObject *
-wrap_inquiry(PyObject *self, PyObject *args, void *wrapped)
+wrap_lenfunc(PyObject *self, PyObject *args, void *wrapped)
{
- inquiry func = (inquiry)wrapped;
- int res;
+ lenfunc func = (lenfunc)wrapped;
+ Py_ssize_t res;
if (!check_num_args(args, 0))
return NULL;
}
static PyObject *
-wrap_intargfunc(PyObject *self, PyObject *args, void *wrapped)
+wrap_ssizeargfunc(PyObject *self, PyObject *args, void *wrapped)
{
- intargfunc func = (intargfunc)wrapped;
- int i;
+ ssizeargfunc func = (ssizeargfunc)wrapped;
+ Py_ssize_t i;
- if (!PyArg_ParseTuple(args, "i", &i))
+ if (!PyArg_ParseTuple(args, "n", &i))
return NULL;
return (*func)(self, i);
}
-static int
+static Py_ssize_t
getindex(PyObject *self, PyObject *arg)
{
- int i;
+ Py_ssize_t i;
- i = PyInt_AsLong(arg);
+ i = PyInt_AsSsize_t(arg);
if (i == -1 && PyErr_Occurred())
return -1;
if (i < 0) {
PySequenceMethods *sq = self->ob_type->tp_as_sequence;
if (sq && sq->sq_length) {
- int n = (*sq->sq_length)(self);
+ Py_ssize_t n = (*sq->sq_length)(self);
if (n < 0)
return -1;
i += n;
static PyObject *
wrap_sq_item(PyObject *self, PyObject *args, void *wrapped)
{
- intargfunc func = (intargfunc)wrapped;
+ ssizeargfunc func = (ssizeargfunc)wrapped;
PyObject *arg;
- int i;
+ Py_ssize_t i;
if (PyTuple_GET_SIZE(args) == 1) {
arg = PyTuple_GET_ITEM(args, 0);
}
static PyObject *
-wrap_intintargfunc(PyObject *self, PyObject *args, void *wrapped)
+wrap_ssizessizeargfunc(PyObject *self, PyObject *args, void *wrapped)
{
- intintargfunc func = (intintargfunc)wrapped;
- int i, j;
+ ssizessizeargfunc func = (ssizessizeargfunc)wrapped;
+ Py_ssize_t i, j;
- if (!PyArg_ParseTuple(args, "ii", &i, &j))
+ if (!PyArg_ParseTuple(args, "nn", &i, &j))
return NULL;
return (*func)(self, i, j);
}
static PyObject *
wrap_sq_setitem(PyObject *self, PyObject *args, void *wrapped)
{
- intobjargproc func = (intobjargproc)wrapped;
- int i, res;
+ ssizeobjargproc func = (ssizeobjargproc)wrapped;
+ Py_ssize_t i;
+ int res;
PyObject *arg, *value;
if (!PyArg_UnpackTuple(args, "", 2, 2, &arg, &value))
static PyObject *
wrap_sq_delitem(PyObject *self, PyObject *args, void *wrapped)
{
- intobjargproc func = (intobjargproc)wrapped;
- int i, res;
+ ssizeobjargproc func = (ssizeobjargproc)wrapped;
+ Py_ssize_t i;
+ int res;
PyObject *arg;
if (!check_num_args(args, 1))
}
static PyObject *
-wrap_intintobjargproc(PyObject *self, PyObject *args, void *wrapped)
+wrap_ssizessizeobjargproc(PyObject *self, PyObject *args, void *wrapped)
{
- intintobjargproc func = (intintobjargproc)wrapped;
- int i, j, res;
+ ssizessizeobjargproc func = (ssizessizeobjargproc)wrapped;
+ Py_ssize_t i, j;
+ int res;
PyObject *value;
- if (!PyArg_ParseTuple(args, "iiO", &i, &j, &value))
+ if (!PyArg_ParseTuple(args, "nnO", &i, &j, &value))
return NULL;
res = (*func)(self, i, j, value);
if (res == -1 && PyErr_Occurred())
static PyObject *
wrap_delslice(PyObject *self, PyObject *args, void *wrapped)
{
- intintobjargproc func = (intintobjargproc)wrapped;
- int i, j, res;
+ ssizessizeobjargproc func = (ssizessizeobjargproc)wrapped;
+ Py_ssize_t i, j;
+ int res;
- if (!PyArg_ParseTuple(args, "ii", &i, &j))
+ if (!PyArg_ParseTuple(args, "nn", &i, &j))
return NULL;
res = (*func)(self, i, j, NULL);
if (res == -1 && PyErr_Occurred())
"(" ARGCODES ")", arg1, arg2); \
}
-static int
+static Py_ssize_t
slot_sq_length(PyObject *self)
{
static PyObject *len_str;
PyObject *res = call_method(self, "__len__", &len_str, "()");
- long temp;
- int len;
+ Py_ssize_t temp;
+ Py_ssize_t len;
if (res == NULL)
return -1;
- temp = PyInt_AsLong(res);
+ temp = PyInt_AsSsize_t(res);
len = (int)temp;
Py_DECREF(res);
if (len == -1 && PyErr_Occurred())
return -1;
-#if SIZEOF_INT < SIZEOF_LONG
- /* Overflow check -- range of PyInt is more than C int */
+#if SIZEOF_SIZE_T < SIZEOF_LONG
+ /* Overflow check -- range of PyInt is more than C ssize_t */
if (len != temp) {
PyErr_SetString(PyExc_OverflowError,
"__len__() should return 0 <= outcome < 2**31");
/* Super-optimized version of slot_sq_item.
Other slots could do the same... */
static PyObject *
-slot_sq_item(PyObject *self, int i)
+slot_sq_item(PyObject *self, Py_ssize_t i)
{
static PyObject *getitem_str;
PyObject *func, *args = NULL, *ival = NULL, *retval = NULL;
return NULL;
}
-SLOT2(slot_sq_slice, "__getslice__", int, int, "ii")
+SLOT2(slot_sq_slice, "__getslice__", Py_ssize_t, Py_ssize_t, "nn")
static int
-slot_sq_ass_item(PyObject *self, int index, PyObject *value)
+slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value)
{
PyObject *res;
static PyObject *delitem_str, *setitem_str;
}
static int
-slot_sq_ass_slice(PyObject *self, int i, int j, PyObject *value)
+slot_sq_ass_slice(PyObject *self, Py_ssize_t i, Py_ssize_t j, PyObject *value)
{
PyObject *res;
static PyObject *delslice_str, *setslice_str;
{
PyObject *func, *args, *res;
static PyObject *cmp_str;
- int c;
+ Py_ssize_t c;
func = lookup_method(self, "__cmp__", &cmp_str);
if (func == NULL) {
static PyObject *new_str;
PyObject *func;
PyObject *newargs, *x;
- int i, n;
+ Py_ssize_t i, n;
if (new_str == NULL) {
new_str = PyString_InternFromString("__new__");
"x." NAME "(y) <==> " DOC)
static slotdef slotdefs[] = {
- SQSLOT("__len__", sq_length, slot_sq_length, wrap_inquiry,
+ SQSLOT("__len__", sq_length, slot_sq_length, wrap_lenfunc,
"x.__len__() <==> len(x)"),
/* Heap types defining __add__/__mul__ have sq_concat/sq_repeat == NULL.
The logic in abstract.c always falls back to nb_add/nb_multiply in
test_descr.notimplemented() */
SQSLOT("__add__", sq_concat, NULL, wrap_binaryfunc,
"x.__add__(y) <==> x+y"),
- SQSLOT("__mul__", sq_repeat, NULL, wrap_intargfunc,
+ SQSLOT("__mul__", sq_repeat, NULL, wrap_ssizeargfunc,
"x.__mul__(n) <==> x*n"),
- SQSLOT("__rmul__", sq_repeat, NULL, wrap_intargfunc,
+ SQSLOT("__rmul__", sq_repeat, NULL, wrap_ssizeargfunc,
"x.__rmul__(n) <==> n*x"),
SQSLOT("__getitem__", sq_item, slot_sq_item, wrap_sq_item,
"x.__getitem__(y) <==> x[y]"),
- SQSLOT("__getslice__", sq_slice, slot_sq_slice, wrap_intintargfunc,
+ SQSLOT("__getslice__", sq_slice, slot_sq_slice, wrap_ssizessizeargfunc,
"x.__getslice__(i, j) <==> x[i:j]\n\
\n\
Use of negative indices is not supported."),
SQSLOT("__delitem__", sq_ass_item, slot_sq_ass_item, wrap_sq_delitem,
"x.__delitem__(y) <==> del x[y]"),
SQSLOT("__setslice__", sq_ass_slice, slot_sq_ass_slice,
- wrap_intintobjargproc,
+ wrap_ssizessizeobjargproc,
"x.__setslice__(i, j, y) <==> x[i:j]=y\n\
\n\
Use of negative indices is not supported."),
SQSLOT("__iadd__", sq_inplace_concat, NULL,
wrap_binaryfunc, "x.__iadd__(y) <==> x+=y"),
SQSLOT("__imul__", sq_inplace_repeat, NULL,
- wrap_intargfunc, "x.__imul__(y) <==> x*=y"),
+ wrap_ssizeargfunc, "x.__imul__(y) <==> x*=y"),
- MPSLOT("__len__", mp_length, slot_mp_length, wrap_inquiry,
+ MPSLOT("__len__", mp_length, slot_mp_length, wrap_lenfunc,
"x.__len__() <==> len(x)"),
MPSLOT("__getitem__", mp_subscript, slot_mp_subscript,
wrap_binaryfunc,
proper indirection pointer (as_buffer, etc.); it returns NULL if the
indirection pointer is NULL. */
static void **
-slotptr(PyTypeObject *type, int offset)
+slotptr(PyTypeObject *type, int ioffset)
{
char *ptr;
+ long offset = ioffset;
/* Note: this depends on the order of the members of PyHeapTypeObject! */
assert(offset >= 0);
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
{
PyTypeObject *subclass;
PyObject *ref, *subclasses, *dict;
- int i, n;
+ Py_ssize_t i, n;
subclasses = type->tp_subclasses;
if (subclasses == NULL)
PyObject *mro, *res, *tmp, *dict;
PyTypeObject *starttype;
descrgetfunc f;
- int i, n;
+ Py_ssize_t i, n;
starttype = su->obj_type;
mro = starttype->tp_mro;
static
int unicode_resize(register PyUnicodeObject *unicode,
- int length)
+ Py_ssize_t length)
{
void *oldstr;
return -1;
}
unicode->str[length] = 0;
- unicode->length = length;
+ assert(length < INT_MAX);
+ unicode->length = (int)length;
reset:
/* Reset the object caches */
*/
static
-PyUnicodeObject *_PyUnicode_New(int length)
+PyUnicodeObject *_PyUnicode_New(Py_ssize_t length)
{
register PyUnicodeObject *unicode;
*/
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;
}
}
-int PyUnicode_Resize(PyObject **unicode, int length)
+int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
{
register PyUnicodeObject *v;
PyUnicode_Resize(((PyObject **)(unicodevar)), length)
PyObject *PyUnicode_FromUnicode(const Py_UNICODE *u,
- int size)
+ Py_ssize_t size)
{
PyUnicodeObject *unicode;
#ifdef HAVE_WCHAR_H
PyObject *PyUnicode_FromWideChar(register const wchar_t *w,
- int size)
+ Py_ssize_t size)
{
PyUnicodeObject *unicode;
return (PyObject *)unicode;
}
-int PyUnicode_AsWideChar(PyUnicodeObject *unicode,
- register wchar_t *w,
- int size)
+Py_ssize_t PyUnicode_AsWideChar(PyUnicodeObject *unicode,
+ wchar_t *w,
+ Py_ssize_t size)
{
if (unicode == NULL) {
PyErr_BadInternalCall();
const char *errors)
{
const char *s = NULL;
- int len;
+ Py_ssize_t len;
PyObject *v;
if (obj == NULL) {
}
PyObject *PyUnicode_Decode(const char *s,
- int size,
+ Py_ssize_t size,
const char *encoding,
const char *errors)
{
}
PyObject *PyUnicode_Encode(const Py_UNICODE *s,
- int size,
+ Py_ssize_t size,
const char *encoding,
const char *errors)
{
return NULL;
}
-int PyUnicode_GetSize(PyObject *unicode)
+Py_ssize_t PyUnicode_GetSize(PyObject *unicode)
{
if (!PyUnicode_Check(unicode)) {
PyErr_BadArgument();
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";
+ static char *argparse = "O!n;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;
+ Py_ssize_t newpos;
Py_UNICODE *repptr;
- int repsize;
+ Py_ssize_t repsize;
int res = -1;
if (*errorHandler == NULL) {
if (newpos<0)
newpos = insize+newpos;
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;
}
}
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;
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;
};
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;
*/
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];
PyObject *
PyUnicode_DecodeUTF16(const char *s,
- int size,
+ Py_ssize_t size,
const char *errors,
int *byteorder)
{
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;
PyObject *
PyUnicode_EncodeUTF16(const Py_UNICODE *s,
- int size,
+ Py_ssize_t size,
const char *errors,
int byteorder)
{
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;
/* 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;
}
}
*/
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;
}
PyObject *PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
- int size)
+ Py_ssize_t size)
{
return unicodeescape_string(s, size, 0);
}
/* --- 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;
}
PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
- int size)
+ Py_ssize_t size)
{
PyObject *repr;
char *p;
/* --- 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;
PyUnicodeObject *v;
Py_UNICODE *p;
const char *end;
/* --- Latin-1 Codec ------------------------------------------------------ */
PyObject *PyUnicode_DecodeLatin1(const char *s,
- int size,
+ Py_ssize_t size,
const char *errors)
{
PyUnicodeObject *v;
/* 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) {
/* 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,
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";
+ static char *argparse = "O!n;encoding error handler must return (unicode, int) tuple";
PyObject *restuple;
PyObject *resunicode;
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;
}
}
static PyObject *unicode_encode_ucs1(const Py_UNICODE *p,
- int size,
+ Py_ssize_t size,
const char *errors,
int limit)
{
/* 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;
++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;
}
PyObject *PyUnicode_EncodeLatin1(const Py_UNICODE *p,
- int size,
+ Py_ssize_t size,
const char *errors)
{
return unicode_encode_ucs1(p, size, errors, 256);
/* --- 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;
}
PyObject *PyUnicode_EncodeASCII(const Py_UNICODE *p,
- int size,
+ Py_ssize_t size,
const char *errors)
{
return unicode_encode_ucs1(p, size, errors, 128);
/* --- 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);
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);
}
}
PyObject *PyUnicode_EncodeMBCS(const Py_UNICODE *p,
- int size,
+ Py_ssize_t size,
const char *errors)
{
PyObject *repr;
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);
/* 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);
}
/* --- 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;
- int extrachars = 0;
+ Py_ssize_t extrachars = 0;
PyObject *errorHandler = NULL;
PyObject *exc = NULL;
Py_UNICODE *mapstring = NULL;
- int maplen = 0;
+ Py_ssize_t maplen = 0;
/* Default to Latin-1 */
if (mapping == NULL)
continue;
}
else if (PyUnicode_Check(x)) {
- int targetsize = PyUnicode_GET_SIZE(x);
+ Py_ssize_t targetsize = PyUnicode_GET_SIZE(x);
if (targetsize == 1)
/* 1-1 mapping */
/* 1-n mapping */
if (targetsize > extrachars) {
/* resize first */
- int oldpos = (int)(p - PyUnicode_AS_UNICODE(v));
- int needed = (targetsize - extrachars) + \
+ Py_ssize_t oldpos = p - PyUnicode_AS_UNICODE(v);
+ Py_ssize_t needed = (targetsize - extrachars) + \
(targetsize << 2);
extrachars += needed;
if (_PyUnicode_Resize(&v,
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);
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)
}
else {
const char *repchars = PyString_AS_STRING(rep);
- int repsize = PyString_GET_SIZE(rep);
- int requiredsize = *outpos+repsize;
+ Py_ssize_t repsize = PyString_GET_SIZE(rep);
+ Py_ssize_t requiredsize = *outpos+repsize;
if (outsize<requiredsize) {
/* exponentially overallocate to minimize reallocations */
if (requiredsize < 2*outsize)
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 repsize;
+ Py_ssize_t newpos;
Py_UNICODE *uni2;
/* startpos for collecting unencodable chars */
- int collstartpos = *inpos;
- int collendpos = *inpos+1;
- int collpos;
+ Py_ssize_t collstartpos = *inpos;
+ Py_ssize_t collendpos = *inpos+1;
+ Py_ssize_t collpos;
char *encoding = "charmap";
char *reason = "character maps to <undefined>";
}
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
/* 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) {
/* 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,
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;
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;
}
Return 0 on success, -1 on error */
static
int charmaptranslate_makespace(PyObject **outobj, Py_UNICODE **outp,
- int requiredsize)
+ Py_ssize_t requiredsize)
{
- int oldsize = PyUnicode_GET_SIZE(*outobj);
+ Py_ssize_t oldsize = PyUnicode_GET_SIZE(*outobj);
if (requiredsize > oldsize) {
/* remember old output position */
- int outpos = *outp-PyUnicode_AS_UNICODE(*outobj);
+ Py_ssize_t outpos = *outp-PyUnicode_AS_UNICODE(*outobj);
/* exponentially overallocate to minimize reallocations */
if (requiredsize < 2 * oldsize)
requiredsize = 2 * oldsize;
Return 0 on success, -1 on error. */
static
int charmaptranslate_output(const Py_UNICODE *startinp, const Py_UNICODE *curinp,
- int insize, PyObject *mapping, PyObject **outobj, Py_UNICODE **outp,
+ Py_ssize_t insize, PyObject *mapping, PyObject **outobj, Py_UNICODE **outp,
PyObject **res)
{
if (charmaptranslate_lookup(*curinp, mapping, res))
*(*outp)++ = (Py_UNICODE)PyInt_AS_LONG(*res);
}
else if (PyUnicode_Check(*res)) {
- int repsize = PyUnicode_GET_SIZE(*res);
+ Py_ssize_t repsize = PyUnicode_GET_SIZE(*res);
if (repsize==1) {
/* no overflow check, because we know that the space is enough */
*(*outp)++ = *PyUnicode_AS_UNICODE(*res);
}
else if (repsize!=0) {
/* more than one character */
- int requiredsize = (*outp-PyUnicode_AS_UNICODE(*outobj)) +
+ Py_ssize_t requiredsize = (*outp-PyUnicode_AS_UNICODE(*outobj)) +
(insize - (curinp-startinp)) +
repsize - 1;
if (charmaptranslate_makespace(outobj, outp, requiredsize))
}
PyObject *PyUnicode_TranslateCharmap(const Py_UNICODE *p,
- int size,
+ Py_ssize_t size,
PyObject *mapping,
const char *errors)
{
/* pointer into the output */
Py_UNICODE *str;
/* current output position */
- int respos = 0;
+ Py_ssize_t respos = 0;
char *reason = "character maps to <undefined>";
PyObject *errorHandler = NULL;
PyObject *exc = NULL;
++p;
else { /* untranslatable character */
PyObject *repunicode = NULL; /* initialize to prevent gcc warning */
- int repsize;
- int newpos;
+ Py_ssize_t repsize;
+ Py_ssize_t newpos;
Py_UNICODE *uni2;
/* startpos for collecting untranslatable chars */
const Py_UNICODE *collstart = p;
/* --- Decimal Encoder ---------------------------------------------------- */
int PyUnicode_EncodeDecimal(Py_UNICODE *s,
- int length,
+ Py_ssize_t length,
char *output,
const char *errors)
{
register Py_UNICODE ch = *p;
int decimal;
PyObject *repunicode;
- int repsize;
- int newpos;
+ Py_ssize_t repsize;
+ Py_ssize_t newpos;
Py_UNICODE *uni2;
Py_UNICODE *collstart;
Py_UNICODE *collend;
/* --- Helpers ------------------------------------------------------------ */
static
-int count(PyUnicodeObject *self,
- int start,
- int end,
- PyUnicodeObject *substring)
+Py_ssize_t count(PyUnicodeObject *self,
+ Py_ssize_t start,
+ Py_ssize_t end,
+ PyUnicodeObject *substring)
{
int count = 0;
return count;
}
-int PyUnicode_Count(PyObject *str,
+Py_ssize_t PyUnicode_Count(PyObject *str,
PyObject *substr,
- int start,
- int end)
+ Py_ssize_t start,
+ Py_ssize_t end)
{
- int result;
+ Py_ssize_t result;
str = PyUnicode_FromObject(str);
if (str == NULL)
}
static
-int findstring(PyUnicodeObject *self,
+Py_ssize_t findstring(PyUnicodeObject *self,
PyUnicodeObject *substring,
- int start,
- int end,
+ Py_ssize_t start,
+ Py_ssize_t end,
int direction)
{
if (start < 0)
return -1;
}
-int PyUnicode_Find(PyObject *str,
+Py_ssize_t PyUnicode_Find(PyObject *str,
PyObject *substr,
- int start,
- int end,
+ Py_ssize_t start,
+ Py_ssize_t end,
int direction)
{
- int result;
+ Py_ssize_t result;
str = PyUnicode_FromObject(str);
if (str == NULL)
static
int tailmatch(PyUnicodeObject *self,
PyUnicodeObject *substring,
- int start,
- int end,
+ Py_ssize_t start,
+ Py_ssize_t end,
int direction)
{
if (start < 0)
return 0;
}
-int PyUnicode_Tailmatch(PyObject *str,
+Py_ssize_t PyUnicode_Tailmatch(PyObject *str,
PyObject *substr,
- int start,
- int end,
+ Py_ssize_t start,
+ Py_ssize_t end,
int direction)
{
- int result;
+ Py_ssize_t result;
str = PyUnicode_FromObject(str);
if (str == NULL)
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 */
static
int fixupper(PyUnicodeObject *self)
{
- int len = self->length;
+ Py_ssize_t len = self->length;
Py_UNICODE *s = self->str;
int status = 0;
static
int fixlower(PyUnicodeObject *self)
{
- int len = self->length;
+ Py_ssize_t len = self->length;
Py_UNICODE *s = self->str;
int status = 0;
static
int fixswapcase(PyUnicodeObject *self)
{
- int len = self->length;
+ Py_ssize_t len = self->length;
Py_UNICODE *s = self->str;
int status = 0;
static
int fixcapitalize(PyUnicodeObject *self)
{
- int len = self->length;
+ Py_ssize_t len = self->length;
Py_UNICODE *s = self->str;
int status = 0;
size_t res_used; /* # used bytes */
Py_UNICODE *res_p; /* pointer to free byte in res's string area */
PyObject *fseq; /* PySequence_Fast(seq) */
- int seqlen; /* len(fseq) -- number of items in sequence */
+ Py_ssize_t seqlen; /* len(fseq) -- number of items in sequence */
PyObject *item;
int i;
static
PyUnicodeObject *pad(PyUnicodeObject *self,
- int left,
- int right,
+ Py_ssize_t left,
+ Py_ssize_t right,
Py_UNICODE fill)
{
PyUnicodeObject *u;
static
PyObject *split_whitespace(PyUnicodeObject *self,
PyObject *list,
- int maxcount)
+ Py_ssize_t maxcount)
{
- register int i;
- register int j;
- int len = self->length;
+ register Py_ssize_t i;
+ register Py_ssize_t j;
+ Py_ssize_t len = self->length;
PyObject *str;
for (i = j = 0; i < len; ) {
PyObject *PyUnicode_Splitlines(PyObject *string,
int keepends)
{
- register int i;
- register int j;
- int len;
+ register Py_ssize_t i;
+ register Py_ssize_t j;
+ Py_ssize_t len;
PyObject *list;
PyObject *str;
Py_UNICODE *data;
goto onError;
for (i = j = 0; i < len; ) {
- int eol;
+ Py_ssize_t eol;
/* Find a line and append it */
while (i < len && !Py_UNICODE_ISLINEBREAK(data[i]))
PyObject *split_char(PyUnicodeObject *self,
PyObject *list,
Py_UNICODE ch,
- int maxcount)
+ Py_ssize_t maxcount)
{
- register int i;
- register int j;
- int len = self->length;
+ register Py_ssize_t i;
+ register Py_ssize_t j;
+ Py_ssize_t len = self->length;
PyObject *str;
for (i = j = 0; i < len; ) {
PyObject *split_substring(PyUnicodeObject *self,
PyObject *list,
PyUnicodeObject *substring,
- int maxcount)
+ Py_ssize_t maxcount)
{
- register int i;
- register int j;
- int len = self->length;
- int sublen = substring->length;
+ register Py_ssize_t i;
+ register Py_ssize_t j;
+ Py_ssize_t len = self->length;
+ Py_ssize_t sublen = substring->length;
PyObject *str;
for (i = j = 0; i <= len - sublen; ) {
static
PyObject *rsplit_whitespace(PyUnicodeObject *self,
PyObject *list,
- int maxcount)
+ Py_ssize_t maxcount)
{
- register int i;
- register int j;
- int len = self->length;
+ register Py_ssize_t i;
+ register Py_ssize_t j;
+ Py_ssize_t len = self->length;
PyObject *str;
for (i = j = len - 1; i >= 0; ) {
PyObject *rsplit_char(PyUnicodeObject *self,
PyObject *list,
Py_UNICODE ch,
- int maxcount)
+ Py_ssize_t maxcount)
{
- register int i;
- register int j;
- int len = self->length;
+ register Py_ssize_t i;
+ register Py_ssize_t j;
+ Py_ssize_t len = self->length;
PyObject *str;
for (i = j = len - 1; i >= 0; ) {
PyObject *rsplit_substring(PyUnicodeObject *self,
PyObject *list,
PyUnicodeObject *substring,
- int maxcount)
+ Py_ssize_t maxcount)
{
- register int i;
- register int j;
- int len = self->length;
- int sublen = substring->length;
+ register Py_ssize_t i;
+ register Py_ssize_t j;
+ Py_ssize_t len = self->length;
+ Py_ssize_t sublen = substring->length;
PyObject *str;
for (i = len - sublen, j = len; i >= 0; ) {
static
PyObject *split(PyUnicodeObject *self,
PyUnicodeObject *substring,
- int maxcount)
+ Py_ssize_t maxcount)
{
PyObject *list;
static
PyObject *rsplit(PyUnicodeObject *self,
PyUnicodeObject *substring,
- int maxcount)
+ Py_ssize_t maxcount)
{
PyObject *list;
PyObject *replace(PyUnicodeObject *self,
PyUnicodeObject *str1,
PyUnicodeObject *str2,
- int maxcount)
+ Py_ssize_t maxcount)
{
PyUnicodeObject *u;
}
} else {
- int n, i;
+ Py_ssize_t n, i;
Py_UNICODE *p;
/* replace strings */
{
PyObject *list;
PyObject *item;
- int i;
+ Py_ssize_t i;
/* Split into words */
list = split(self, NULL, -1);
static PyObject *
unicode_center(PyUnicodeObject *self, PyObject *args)
{
- int marg, left;
- int width;
+ Py_ssize_t marg, left;
+ Py_ssize_t width;
Py_UNICODE fillchar = ' ';
if (!PyArg_ParseTuple(args, "i|O&:center", &width, convert_uc, &fillchar))
static int
unicode_compare(PyUnicodeObject *str1, PyUnicodeObject *str2)
{
- int len1, len2;
+ Py_ssize_t len1, len2;
Py_UNICODE *s1 = str1->str;
Py_UNICODE *s2 = str2->str;
static int
unicode_compare(PyUnicodeObject *str1, PyUnicodeObject *str2)
{
- register int len1, len2;
+ register Py_ssize_t len1, len2;
Py_UNICODE *s1 = str1->str;
Py_UNICODE *s2 = str2->str;
PyObject *element)
{
PyUnicodeObject *u = NULL, *v = NULL;
- int result, size;
+ int result;
+ Py_ssize_t size;
register const Py_UNICODE *lhs, *end, *rhs;
/* Coerce the two arguments */
unicode_count(PyUnicodeObject *self, PyObject *args)
{
PyUnicodeObject *substring;
- int start = 0;
- int end = INT_MAX;
+ Py_ssize_t start = 0;
+ Py_ssize_t end = INT_MAX;
PyObject *result;
if (!PyArg_ParseTuple(args, "O|O&O&:count", &substring,
Py_UNICODE *e;
Py_UNICODE *p;
Py_UNICODE *q;
- int i, j;
+ Py_ssize_t i, j;
PyUnicodeObject *u;
int tabsize = 8;
unicode_find(PyUnicodeObject *self, PyObject *args)
{
PyUnicodeObject *substring;
- int start = 0;
- int end = INT_MAX;
+ Py_ssize_t start = 0;
+ Py_ssize_t end = INT_MAX;
PyObject *result;
if (!PyArg_ParseTuple(args, "O|O&O&:find", &substring,
if (substring == NULL)
return NULL;
- result = PyInt_FromLong(findstring(self, substring, start, end, 1));
+ result = PyInt_FromSsize_t(findstring(self, substring, start, end, 1));
Py_DECREF(substring);
return result;
}
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");
strings and Unicode objects behave in the same way as
dictionary keys. */
- register int len;
+ register Py_ssize_t len;
register Py_UNICODE *p;
register long x;
static PyObject *
unicode_index(PyUnicodeObject *self, PyObject *args)
{
- int result;
+ Py_ssize_t result;
PyUnicodeObject *substring;
- int start = 0;
- int end = INT_MAX;
+ Py_ssize_t start = 0;
+ Py_ssize_t end = INT_MAX;
if (!PyArg_ParseTuple(args, "O|O&O&:index", &substring,
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
PyErr_SetString(PyExc_ValueError, "substring not found");
return NULL;
}
- return PyInt_FromLong(result);
+ return PyInt_FromSsize_t(result);
}
PyDoc_STRVAR(islower__doc__,
return PyUnicode_Join(self, data);
}
-static int
+static Py_ssize_t
unicode_length(PyUnicodeObject *self)
{
return self->length;
_PyUnicode_XStrip(PyUnicodeObject *self, int striptype, PyObject *sepobj)
{
Py_UNICODE *s = PyUnicode_AS_UNICODE(self);
- int len = PyUnicode_GET_SIZE(self);
+ Py_ssize_t len = PyUnicode_GET_SIZE(self);
Py_UNICODE *sep = PyUnicode_AS_UNICODE(sepobj);
- int seplen = PyUnicode_GET_SIZE(sepobj);
- int i, j;
+ Py_ssize_t seplen = PyUnicode_GET_SIZE(sepobj);
+ Py_ssize_t i, j;
i = 0;
if (striptype != RIGHTSTRIP) {
do_strip(PyUnicodeObject *self, int striptype)
{
Py_UNICODE *s = PyUnicode_AS_UNICODE(self);
- int len = PyUnicode_GET_SIZE(self), i, j;
+ Py_ssize_t len = PyUnicode_GET_SIZE(self), i, j;
i = 0;
if (striptype != RIGHTSTRIP) {
static PyObject*
-unicode_repeat(PyUnicodeObject *str, int len)
+unicode_repeat(PyUnicodeObject *str, Py_ssize_t len)
{
PyUnicodeObject *u;
Py_UNICODE *p;
- int nchars;
+ Py_ssize_t nchars;
size_t nbytes;
if (len < 0)
PyObject *PyUnicode_Replace(PyObject *obj,
PyObject *subobj,
PyObject *replobj,
- int maxcount)
+ Py_ssize_t maxcount)
{
PyObject *self;
PyObject *str1;
{
PyUnicodeObject *str1;
PyUnicodeObject *str2;
- int maxcount = -1;
+ Py_ssize_t maxcount = -1;
PyObject *result;
- if (!PyArg_ParseTuple(args, "OO|i:replace", &str1, &str2, &maxcount))
+ if (!PyArg_ParseTuple(args, "OO|n:replace", &str1, &str2, &maxcount))
return NULL;
str1 = (PyUnicodeObject *)PyUnicode_FromObject((PyObject *)str1);
if (str1 == NULL)
unicode_rfind(PyUnicodeObject *self, PyObject *args)
{
PyUnicodeObject *substring;
- int start = 0;
- int end = INT_MAX;
+ Py_ssize_t start = 0;
+ Py_ssize_t end = INT_MAX;
PyObject *result;
if (!PyArg_ParseTuple(args, "O|O&O&:rfind", &substring,
if (substring == NULL)
return NULL;
- result = PyInt_FromLong(findstring(self, substring, start, end, -1));
+ result = PyInt_FromSsize_t(findstring(self, substring, start, end, -1));
Py_DECREF(substring);
return result;
static PyObject *
unicode_rindex(PyUnicodeObject *self, PyObject *args)
{
- int result;
+ Py_ssize_t result;
PyUnicodeObject *substring;
- int start = 0;
- int end = INT_MAX;
+ Py_ssize_t start = 0;
+ Py_ssize_t end = INT_MAX;
if (!PyArg_ParseTuple(args, "O|O&O&:rindex", &substring,
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
PyErr_SetString(PyExc_ValueError, "substring not found");
return NULL;
}
- return PyInt_FromLong(result);
+ return PyInt_FromSsize_t(result);
}
PyDoc_STRVAR(rjust__doc__,
}
static PyObject*
-unicode_slice(PyUnicodeObject *self, int start, int end)
+unicode_slice(PyUnicodeObject *self, Py_ssize_t start, Py_ssize_t end)
{
/* standard clamping */
if (start < 0)
PyObject *PyUnicode_Split(PyObject *s,
PyObject *sep,
- int maxsplit)
+ Py_ssize_t maxsplit)
{
PyObject *result;
unicode_split(PyUnicodeObject *self, PyObject *args)
{
PyObject *substring = Py_None;
- int maxcount = -1;
+ Py_ssize_t maxcount = -1;
- if (!PyArg_ParseTuple(args, "|Oi:split", &substring, &maxcount))
+ if (!PyArg_ParseTuple(args, "|On:split", &substring, &maxcount))
return NULL;
if (substring == Py_None)
PyObject *PyUnicode_RSplit(PyObject *s,
PyObject *sep,
- int maxsplit)
+ Py_ssize_t maxsplit)
{
PyObject *result;
unicode_rsplit(PyUnicodeObject *self, PyObject *args)
{
PyObject *substring = Py_None;
- int maxcount = -1;
+ Py_ssize_t maxcount = -1;
- if (!PyArg_ParseTuple(args, "|Oi:rsplit", &substring, &maxcount))
+ if (!PyArg_ParseTuple(args, "|On:rsplit", &substring, &maxcount))
return NULL;
if (substring == Py_None)
static PyObject *
unicode_zfill(PyUnicodeObject *self, PyObject *args)
{
- int fill;
+ Py_ssize_t fill;
PyUnicodeObject *u;
- int width;
- if (!PyArg_ParseTuple(args, "i:zfill", &width))
+ Py_ssize_t width;
+ if (!PyArg_ParseTuple(args, "n:zfill", &width))
return NULL;
if (self->length >= width) {
PyObject *args)
{
PyUnicodeObject *substring;
- int start = 0;
- int end = INT_MAX;
+ Py_ssize_t start = 0;
+ Py_ssize_t end = INT_MAX;
PyObject *result;
if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &substring,
PyObject *args)
{
PyUnicodeObject *substring;
- int start = 0;
- int end = INT_MAX;
+ Py_ssize_t start = 0;
+ Py_ssize_t end = INT_MAX;
PyObject *result;
if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &substring,
};
static PySequenceMethods unicode_as_sequence = {
- (inquiry) unicode_length, /* sq_length */
+ (lenfunc) 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*/
static PyObject*
unicode_subscript(PyUnicodeObject* self, PyObject* item)
{
- if (PyInt_Check(item)) {
- long i = PyInt_AS_LONG(item);
- if (i < 0)
- i += PyUnicode_GET_SIZE(self);
- return unicode_getitem(self, i);
- } else if (PyLong_Check(item)) {
- long i = PyLong_AsLong(item);
+ if (PyInt_Check(item) || PyLong_Check(item)) {
+ Py_ssize_t i = PyInt_AsSsize_t(item);
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)
i += PyUnicode_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;
}
static PyMappingMethods unicode_as_mapping = {
- (inquiry)unicode_length, /* mp_length */
+ (lenfunc)unicode_length, /* mp_length */
(binaryfunc)unicode_subscript, /* mp_subscript */
(objobjargproc)0, /* mp_ass_subscript */
};
-static int
+static Py_ssize_t
unicode_buffer_getreadbuf(PyUnicodeObject *self,
- int index,
+ Py_ssize_t index,
const void **ptr)
{
if (index != 0) {
return PyUnicode_GET_DATA_SIZE(self);
}
-static int
-unicode_buffer_getwritebuf(PyUnicodeObject *self, int index,
+static Py_ssize_t
+unicode_buffer_getwritebuf(PyUnicodeObject *self, Py_ssize_t index,
const void **ptr)
{
PyErr_SetString(PyExc_TypeError,
static int
unicode_buffer_getsegcount(PyUnicodeObject *self,
- int *lenp)
+ Py_ssize_t *lenp)
{
if (lenp)
*lenp = PyUnicode_GET_DATA_SIZE(self);
static int
unicode_buffer_getcharbuf(PyUnicodeObject *self,
- int index,
+ Py_ssize_t index,
const void **ptr)
{
PyObject *str;
/* Helpers for PyUnicode_Format() */
static PyObject *
-getnextarg(PyObject *args, int arglen, int *p_argidx)
+getnextarg(PyObject *args, Py_ssize_t arglen, Py_ssize_t *p_argidx)
{
- int argidx = *p_argidx;
+ Py_ssize_t argidx = *p_argidx;
if (argidx < arglen) {
(*p_argidx)++;
if (arglen < 0)
#define F_ALT (1<<3)
#define F_ZERO (1<<4)
-static int
+static Py_ssize_t
strtounicode(Py_UNICODE *buffer, const char *charbuffer)
{
- register long i;
- long len = strlen(charbuffer);
+ register Py_ssize_t i;
+ Py_ssize_t len = strlen(charbuffer);
for (i = len - 1; i >= 0; i--)
buffer[i] = (Py_UNICODE) charbuffer[i];
doubletounicode(Py_UNICODE *buffer, size_t len, const char *format, double x)
{
PyOS_ascii_formatd((char *)buffer, len, format, x);
- return strtounicode(buffer, (char *)buffer);
+ return Py_SAFE_DOWNCAST(strtounicode(buffer, (char *)buffer),
+ Py_ssize_t, int);
}
static int
longtounicode(Py_UNICODE *buffer, size_t len, const char *format, long x)
{
PyOS_snprintf((char *)buffer, len, format, x);
- return strtounicode(buffer, (char *)buffer);
+ return Py_SAFE_DOWNCAST(strtounicode(buffer, (char *)buffer),
+ Py_ssize_t, int);
}
/* XXX To save some code duplication, formatfloat/long/int could have been
worst case length = 3 + 10 (len of INT_MAX) + 1 = 14 (use 20)*/
char fmt[20];
double x;
+ Py_ssize_t result;
x = PyFloat_AsDouble(v);
if (x == -1.0 && PyErr_Occurred())
char fmt[64]; /* plenty big enough! */
char *sign;
long x;
+ Py_ssize_t result;
x = PyInt_AsLong(v);
if (x == -1 && PyErr_Occurred())
PyObject *args)
{
Py_UNICODE *fmt, *res;
- int fmtcnt, rescnt, reslen, arglen, argidx;
+ Py_ssize_t fmtcnt, rescnt, reslen, arglen, argidx;
int args_owned = 0;
PyUnicodeObject *result = NULL;
PyObject *dict = NULL;
else {
/* Got a format specifier */
int flags = 0;
- int width = -1;
+ Py_ssize_t width = -1;
int prec = -1;
Py_UNICODE c = '\0';
Py_UNICODE fill;
PyObject *temp = NULL;
Py_UNICODE *pbuf;
Py_UNICODE sign;
- int len;
+ Py_ssize_t len;
Py_UNICODE formatbuf[FORMATBUFLEN]; /* For format{float,int,char}() */
fmt++;
if (*fmt == '(') {
Py_UNICODE *keystart;
- int keylen;
+ Py_ssize_t keylen;
PyObject *key;
int pcount = 1;
}
static PyBufferProcs unicode_as_buffer = {
- (getreadbufferproc) unicode_buffer_getreadbuf,
- (getwritebufferproc) unicode_buffer_getwritebuf,
- (getsegcountproc) unicode_buffer_getsegcount,
- (getcharbufferproc) unicode_buffer_getcharbuf,
+ (readbufferproc) unicode_buffer_getreadbuf,
+ (writebufferproc) unicode_buffer_getwritebuf,
+ (segcountproc) unicode_buffer_getsegcount,
+ (charbufferproc) unicode_buffer_getcharbuf,
};
static PyObject *
unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyUnicodeObject *tmp, *pnew;
- int n;
+ Py_ssize_t n;
assert(PyType_IsSubtype(type, &PyUnicode_Type));
tmp = (PyUnicodeObject *)unicode_new(&PyUnicode_Type, args, kwds);
/* 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;
}
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;
/* mapping slots */
-static int
+static Py_ssize_t
proxy_length(PyWeakReference *proxy)
{
if (!proxy_checkref(proxy))
};
static PySequenceMethods proxy_as_sequence = {
- (inquiry)proxy_length, /*sq_length*/
+ (lenfunc)proxy_length, /*sq_length*/
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 */
};
static PyMappingMethods proxy_as_mapping = {
- (inquiry)proxy_length, /*mp_length*/
+ (lenfunc)proxy_length, /*mp_length*/
(binaryfunc)proxy_getitem, /*mp_subscript*/
(objobjargproc)proxy_setitem, /*mp_ass_subscript*/
};
}
if (*list != NULL) {
PyWeakReference *current = *list;
- int count = _PyWeakref_GetWeakrefCount(current);
+ Py_ssize_t count = _PyWeakref_GetWeakrefCount(current);
int restore_error = PyErr_Occurred() ? 1 : 0;
PyObject *err_type, *err_value, *err_tb;
}
else {
PyObject *tuple = PyTuple_New(count * 2);
- int i = 0;
+ Py_ssize_t i = 0;
for (i = 0; i < count; ++i) {
PyWeakReference *next = current->wr_next;
static int
gotlandmark(char *landmark)
{
- int n, ok;
+ int ok;
+ Py_ssize_t n;
n = strlen(prefix);
join(prefix, landmark);
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)
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
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\\";
"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);
#endif
#endif /* MS_WIN64 */
+/* Define like size_t, omitting the "unsigned" */
+#ifdef MS_WIN64
+typedef __int64 ssize_t;
+#else
+typedef _W64 int ssize_t;
+#endif
+#define HAVE_SSIZE_T 1
+
#if defined(MS_WIN32) && !defined(MS_WIN64)
#ifdef _M_IX86
#define COMPILER _Py_PASTE_VERSION("32 bit (Intel)")
# define SIZEOF_OFF_T 4
# define SIZEOF_FPOS_T 8
# define SIZEOF_HKEY 8
+# define SIZEOF_SIZE_T 8
/* configure.in defines HAVE_LARGEFILE_SUPPORT iff HAVE_LONG_LONG,
sizeof(off_t) > sizeof(long), and sizeof(PY_LONG_LONG) >= sizeof(off_t).
On Win64 the second condition is not true, but if fpos_t replaces off_t
# define SIZEOF_OFF_T 4
# define SIZEOF_FPOS_T 8
# define SIZEOF_HKEY 4
+# define SIZEOF_SIZE_T 4
#endif
#ifdef _DEBUG
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;
if (tok->buf != NULL) {
+ assert(tok->cur - tok->buf < INT_MAX);
+ err_ret->offset = (int)(tok->cur - tok->buf);
size_t len = tok->inp - tok->buf;
err_ret->text = (char *) PyObject_MALLOC(len + 1);
if (err_ret->text != NULL) {
}
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) {
/* 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++) {
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;
}
else {
int done = 0;
- int cur = 0;
+ Py_ssize_t cur = 0;
char *pt;
if (tok->start == NULL) {
if (tok->buf == NULL) {
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) {
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;
int supplied_flags = 0;
PyCompilerFlags cf;
PyObject *result = NULL, *cmd, *tmp = NULL;
- int length;
+ Py_ssize_t length;
if (!PyArg_ParseTuple(args, "Oss|ii:compile", &cmd, &filename,
&startstr, &supplied_flags, &dont_inherit))
PyObject *func, *result;
sequence *seqs = NULL, *sqp;
- int n, len;
+ Py_ssize_t n, len;
register int i, j;
n = PyTuple_Size(args);
static PyObject *
builtin_len(PyObject *self, PyObject *v)
{
- long res;
+ Py_ssize_t res;
res = PyObject_Size(v);
if (res < 0 && PyErr_Occurred())
return NULL;
- return PyInt_FromLong(res);
+ return PyInt_FromSsize_t(res);
}
PyDoc_STRVAR(len_doc,
filtertuple(PyObject *func, PyObject *tuple)
{
PyObject *result;
- register int i, j;
- int len = PyTuple_Size(tuple);
+ Py_ssize_t i, j;
+ Py_ssize_t len = PyTuple_Size(tuple);
if (len == 0) {
if (PyTuple_CheckExact(tuple))
filterstring(PyObject *func, PyObject *strobj)
{
PyObject *result;
- register int i, j;
- int len = PyString_Size(strobj);
- int outlen = len;
+ Py_ssize_t i, j;
+ Py_ssize_t len = PyString_Size(strobj);
+ Py_ssize_t outlen = len;
if (func == Py_None) {
/* If it's a real string we can return the original,
/* 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])
/* 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])
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;
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)
PySequenceMethods *sq = tp->tp_as_sequence;
if (sq && sq->sq_slice && ISINT(v) && ISINT(w)) {
- int ilow = 0, ihigh = INT_MAX;
+ Py_ssize_t ilow = 0, ihigh = INT_MAX;
if (!_PyEval_SliceIndex(v, &ilow))
return NULL;
if (!_PyEval_SliceIndex(w, &ihigh))
PySequenceMethods *sq = tp->tp_as_sequence;
if (sq && sq->sq_slice && ISINT(v) && ISINT(w)) {
- int ilow = 0, ihigh = INT_MAX;
+ Py_ssize_t ilow = 0, ihigh = INT_MAX;
if (!_PyEval_SliceIndex(v, &ilow))
return -1;
if (!_PyEval_SliceIndex(w, &ihigh))
#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;
return NULL;
}
/* ouch: passing NULL, 0, pos gives None instead of u'' */
- return Py_BuildValue("(u#i)", &end, 0, end);
+ return Py_BuildValue("(u#n)", &end, 0, end);
}
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;
for (p = PyUnicode_AS_UNICODE(res), i = start;
i<end; ++p, ++i)
*p = '?';
- restuple = Py_BuildValue("(Oi)", res, end);
+ restuple = Py_BuildValue("(On)", res, end);
Py_DECREF(res);
return restuple;
}
Py_UNICODE res = Py_UNICODE_REPLACEMENT_CHARACTER;
if (PyUnicodeDecodeError_GetEnd(exc, &end))
return NULL;
- return Py_BuildValue("(u#i)", &res, 1, end);
+ return Py_BuildValue("(u#n)", &res, 1, end);
}
else if (PyObject_IsInstance(exc, PyExc_UnicodeTranslateError)) {
PyObject *res;
for (p = PyUnicode_AS_UNICODE(res), i = start;
i<end; ++p, ++i)
*p = Py_UNICODE_REPLACEMENT_CHARACTER;
- restuple = Py_BuildValue("(Oi)", res, end);
+ restuple = Py_BuildValue("(On)", res, end);
Py_DECREF(res);
return restuple;
}
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;
}
*outp++ = ';';
}
- restuple = Py_BuildValue("(Oi)", res, end);
+ restuple = Py_BuildValue("(On)", res, end);
Py_DECREF(res);
Py_DECREF(object);
return restuple;
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;
*outp++ = hexdigits[c&0xf];
}
- restuple = Py_BuildValue("(Oi)", res, end);
+ restuple = Py_BuildValue("(On)", res, end);
Py_DECREF(res);
Py_DECREF(object);
return restuple;
static PyObject *
list2dict(PyObject *list)
{
- int i, n;
+ Py_ssize_t i, n;
PyObject *v, *k, *dict = PyDict_New();
n = PyList_Size(list);
static PyObject *
dictbytype(PyObject *src, int scope_type, int flag, int offset)
{
- int pos = 0, i = offset, scope;
+ Py_ssize_t pos = 0, i = offset, scope;
PyObject *k, *v, *dest = PyDict_New();
assert(offset >= 0);
tuple_of_constants(unsigned char *codestr, int n, PyObject *consts)
{
PyObject *newconst, *constant;
- int i, arg, len_consts;
+ Py_ssize_t i, arg, len_consts;
/* Pre-conditions */
assert(PyList_CheckExact(consts));
fold_binops_on_constants(unsigned char *codestr, PyObject *consts)
{
PyObject *newconst, *v, *w;
- int len_consts, opcode, size;
+ Py_ssize_t len_consts, size;
+ int opcode;
/* Pre-conditions */
assert(PyList_CheckExact(consts));
fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
{
PyObject *newconst=NULL, *v;
- int len_consts, opcode;
+ Py_ssize_t len_consts;
+ int opcode;
/* Pre-conditions */
assert(PyList_CheckExact(consts));
static PyObject *
optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *lineno_obj)
{
- int i, j, codelen, nops, h, adj;
+ Py_ssize_t i, j, codelen;
+ int nops, h, adj;
int tgt, tgttgt, opcode;
unsigned char *codestr = NULL;
unsigned char *lineno;
compiler_display_symbols(PyObject *name, PyObject *symbols)
{
PyObject *key, *value;
- int flags, pos = 0;
+ int flags;
+ Py_ssize_t pos = 0;
fprintf(stderr, "block %s\n", PyString_AS_STRING(name));
while (PyDict_Next(symbols, &pos, &key, &value)) {
compiler_add_o(struct compiler *c, PyObject *dict, PyObject *o)
{
PyObject *t, *v;
- int arg;
+ Py_ssize_t arg;
/* necessary to make sure types aren't coerced (e.g., int and long) */
t = PyTuple_Pack(2, o, o->ob_type);
dict_keys_inorder(PyObject *dict, int offset)
{
PyObject *tuple, *k, *v;
- int i, pos = 0, size = PyDict_Size(dict);
+ Py_ssize_t i, pos = 0, size = PyDict_Size(dict);
tuple = PyTuple_New(size);
if (tuple == NULL)
#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);
+ if (*value == -1) {
+ Py_DECREF(attr);
+ return -1;
+ }
+ } 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)
return result;
}
-
static
PyObject *get_string(PyObject *exc, const char *name)
{
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);
}
-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);
}
-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);
}
-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);
}
-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);
}
{
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;
);
}
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)
);
}
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",
+ return PyObject_CallFunction(PyExc_UnicodeEncodeError, "su#nns",
encoding, object, length, start, end, reason);
}
{
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;
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)
);
}
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);
}
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;
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)
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)
);
}
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);
_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;
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, ...)
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;
}
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)
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 */
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];
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++;
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);
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);
*/
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;
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) {
/* 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;
}
*/
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
*p = (unsigned short) ival;
break;
}
-
+
case 'i': {/* signed int */
int *p = va_arg(*p_va, int *);
long ival;
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 'n' to 'l' if Py_ssize_t is int */
case 'l': {/* long int */
long *p = va_arg(*p_va, long *);
long ival;
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)) {
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 {
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)) {
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 {
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
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)",
arg, msgbuf, bufsize);
}
} else {
- if (size + 1 > *buffer_len) {
+ if (size + 1 > BUFFER_LEN) {
Py_DECREF(s);
return converterr(
"(buffer overflow)",
memcpy(*buffer,
PyString_AS_STRING(s),
size + 1);
- *buffer_len = size;
+ STORE_SIZE(size);
} else {
/* Using a 0-terminated buffer:
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 {
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;
count = pb->bf_getcharbuffer(arg, 0, p);
if (count < 0)
return converterr("(unspecified)", arg, msgbuf, bufsize);
- *va_arg(*p_va, int *) = count;
+ {
+ FETCH_SIZE;
+ STORE_SIZE(count);
+ }
break;
}
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) {
}
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;
}
#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];
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);
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);
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);
/* make sure there are no extraneous keyword arguments */
if (nkeywords > 0) {
PyObject *key, *value;
- int pos = 0;
+ Py_ssize_t pos = 0;
while (PyDict_Next(keywords, &pos, &key, &value)) {
int match = 0;
char *ks;
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++;
(void) va_arg(*p_va, void *);
break;
}
+
+ case 'n': /* Py_ssize_t */
+ {
+ (void) va_arg(*p_va, Py_ssize_t *);
+ break;
+ }
/* string codes */
{
(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;
void
PyImport_Cleanup(void)
{
- int pos, ndone;
+ Py_ssize_t pos, ndone;
char *name;
PyObject *key, *value, *dict;
PyInterpreterState *interp = PyThreadState_GET()->interp;
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;
|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");
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;
}
/* Now write the true mtime */
fseek(fp, 4L, 0);
+ assert(mtime < LONG_MAX);
PyMarshal_WriteLongToFile(mtime, fp, Py_MARSHAL_VERSION);
fflush(fp);
fclose(fp);
#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};
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
* ^ ^ ^ ^
#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.
}
/* 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 :-) */
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);
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;
/* 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, '.');
}
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;
\
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); \
static void
w_more(int c, WFILE *p)
{
- int size, newsize;
+ Py_ssize_t size, newsize;
if (p->str == NULL)
return; /* An error already occurred */
size = PyString_Size(p->str);
static void
w_object(PyObject *v, WFILE *p)
{
- int i, n;
+ Py_ssize_t i, n;
p->depth++;
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);
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);
}
goto exit;
}
else {
- o = PyInt_FromLong(PyDict_Size(p->strings));
+ o = PyInt_FromSsize_t(PyDict_Size(p->strings));
PyDict_SetItem(p->strings, v, o);
Py_DECREF(o);
w_byte(TYPE_INTERNED, p);
}
}
else if (PyDict_Check(v)) {
- int pos;
+ Py_ssize_t pos;
PyObject *key, *value;
w_byte(TYPE_DICT, p);
/* This one is NULL object terminated! */
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;
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);
}
PyObject *
-PyMarshal_ReadObjectFromString(char *str, int len)
+PyMarshal_ReadObjectFromString(char *str, Py_ssize_t len)
{
RFILE rf;
PyObject *result;
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));
case 'c':
{
char p[1];
- p[0] = va_arg(*p_va, int);
+ p[0] = (char)va_arg(*p_va, int);
return PyString_FromStringAndSize(p, 1);
}
**/
char *
PyOS_ascii_formatd(char *buffer,
- int buf_len,
+ size_t buf_len,
const char *format,
double d)
{
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') {
analyze_cells(PyObject *scope, PyObject *free)
{
PyObject *name, *v, *w;
- int pos = 0, success = 0;
+ int success = 0;
+ Py_ssize_t pos = 0;
w = PyInt_FromLong(CELL);
if (!w)
PyObject *bound, PyObject *free, int class)
{
PyObject *name, *v, *u, *w, *free_value = NULL;
- int pos = 0;
+ Py_ssize_t pos = 0;
while (PyDict_Next(symbols, &pos, &name, &v)) {
long i, flags;
{
PyObject *name, *v, *local = NULL, *scope = NULL, *newbound = NULL;
PyObject *newglobal = NULL, *newfree = NULL;
- int i, pos = 0, success = 0;
+ int i, success = 0;
+ Py_ssize_t pos = 0;
local = PyDict_New();
if (!local)
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];
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",
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".
*/
if ((char*)d==end) pd->nobjs=k;
}
-static drawfile_object *findobj(PyDrawFObject *pd,int n)
+static drawfile_object *findobj(PyDrawFObject *pd,Py_ssize_t n)
{ drawfile_diagram *dd=pd->drawf;
drawfile_object *d=dd->objects;
for(;n>0;n--) d=NEXT(d);
return (PyObject*)p;
}
-static PyObject *drawf_repeat(PyDrawFObject *b,int i)
+static PyObject *drawf_repeat(PyDrawFObject *b,Py_ssize_t i)
{ PyErr_SetString(PyExc_IndexError,"drawf repetition not implemented");
return NULL;
}
-static PyObject *drawf_item(PyDrawFObject *b,int i)
+static PyObject *drawf_item(PyDrawFObject *b,Py_ssize_t i)
{ PyDrawFObject *c;
- int size;
+ Py_ssize_t size;
drawfile_diagram *dd;
drawfile_object *d;
if(i<0||i>=b->nobjs)
return (PyObject*)c;
}
-static PyObject *drawf_slice(PyDrawFObject *b,int i,int j)
+static PyObject *drawf_slice(PyDrawFObject *b,Py_ssize_t i,Py_ssize_t j)
{ PyDrawFObject *c;
- int size,n;
+ Py_ssize_t size,n;
drawfile_diagram *dd;
drawfile_object *d;
if(i<0||j>b->nobjs)
return (PyObject*)c;
}
-static int drawf_ass_item(PyDrawFObject *b,int i,PyObject *v)
+static int drawf_ass_item(PyDrawFObject *b,Py_ssize_t i,PyObject *v)
{ PyErr_SetString(PyExc_IndexError,"drawf ass not implemented");
return NULL;
}
}
*/
-static int drawf_ass_slice(PyDrawFObject *b,int i,int j,PyObject *v)
+static int drawf_ass_slice(PyDrawFObject *b,Py_ssize_t i,Py_ssize_t j,PyObject *v)
{ PyErr_SetString(PyExc_IndexError,"drawf ass_slice not implemented");
return NULL;
}
static PySequenceMethods drawf_as_sequence=
{ (inquiry)drawf_len,
(binaryfunc)drawf_concat,
- (intargfunc)drawf_repeat,
- (intargfunc)drawf_item,
- (intintargfunc)drawf_slice,
- (intobjargproc)drawf_ass_item,
- (intintobjargproc)drawf_ass_slice,
+ (ssizeargfunc)drawf_repeat,
+ (ssizeargfunc)drawf_item,
+ (ssizessizeargfunc)drawf_slice,
+ (ssizeobjargproc)drawf_ass_item,
+ (ssizessizeobjargproc)drawf_ass_slice,
};
static PyObject *PyDrawF_GetAttr(PyDrawFObject *s,char *name)
return NULL;
}
-static PyObject *block_repeat(PyBlockObject *b,int i)
+static PyObject *block_repeat(PyBlockObject *b,Py_ssize_t i)
{ PyErr_SetString(PyExc_IndexError,"block repetition not implemented");
return NULL;
}
-static PyObject *block_item(PyBlockObject *b,int i)
+static PyObject *block_item(PyBlockObject *b,Py_ssize_t i)
{ if(i<0||4*i>=b->length)
{ PyErr_SetString(PyExc_IndexError,"block index out of range");
return NULL;
return PyInt_FromLong(((long*)(b->block))[i]);
}
-static PyObject *block_slice(PyBlockObject *b,int i,int j)
-{ int n,k;
+static PyObject *block_slice(PyBlockObject *b,Py_ssize_t i,Py_ssize_t j)
+{ Py_ssize_t n,k;
long *p=b->block;
PyObject *result;
if(j>b->length/4) j=b->length/4;
}
n=j-i;
result=PyList_New(n);
- for(k=0;k<n;k++) PyList_SetItem(result,k,PyInt_FromLong(p[i+k]));
+ for(k=0;k<n;k++) PyList_SetItem(result,k,PyInt_FromSsize_t(p[i+k]));
return result;
}
-static int block_ass_item(PyBlockObject *b,int i,PyObject *v)
+static int block_ass_item(PyBlockObject *b,Py_ssize_t i,PyObject *v)
{ if(i<0||i>=b->length/4)
{ PyErr_SetString(PyExc_IndexError,"block index out of range");
return -1;
return 0;
}
-static int block_ass_slice(PyBlockObject *b,int i,int j,PyObject *v)
-{ int n,k;
+static int block_ass_slice(PyBlockObject *b,Py_ssize_t i,Py_ssize_t j,PyObject *v)
+{ Py_ssize_t n,k;
long *p=b->block;
if(j>b->length/4) j=b->length/4;
if(i<0||i>j)
static PySequenceMethods block_as_sequence=
{ (inquiry)block_len, /*sq_length*/
(binaryfunc)block_concat, /*sq_concat*/
- (intargfunc)block_repeat, /*sq_repeat*/
- (intargfunc)block_item, /*sq_item*/
- (intintargfunc)block_slice, /*sq_slice*/
- (intobjargproc)block_ass_item, /*sq_ass_item*/
- (intintobjargproc)block_ass_slice, /*sq_ass_slice*/
+ (ssizeargfunc)block_repeat, /*sq_repeat*/
+ (ssizeargfunc)block_item, /*sq_item*/
+ (ssizessizeargfunc)block_slice, /*sq_slice*/
+ (ssizeobjargproc)block_ass_item, /*sq_ass_item*/
+ (ssizessizeobjargproc)block_ass_slice, /*sq_ass_slice*/
};
static PyObject *PyBlock_GetAttr(PyBlockObject *s,char *name)
#! /bin/sh
-# From configure.in Revision: 42199 .
+# From configure.in Revision: 42307 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.59 for python 2.5.
#
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
_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
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
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
/* 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
/* 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