summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-02-15 17:27:45 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2006-02-15 17:27:45 (GMT)
commit18e165558b24d29e7e0ca501842b9236589b012a (patch)
tree841678b5dc1aff3aa48701fee33a6ba7be00a72b /Python
parent44829297348d9121a03fc7df2fac557b583cc7fa (diff)
downloadcpython-18e165558b24d29e7e0ca501842b9236589b012a.zip
cpython-18e165558b24d29e7e0ca501842b9236589b012a.tar.gz
cpython-18e165558b24d29e7e0ca501842b9236589b012a.tar.bz2
Merge ssize_t branch.
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c18
-rw-r--r--Python/ceval.c13
-rw-r--r--Python/codecs.c28
-rw-r--r--Python/compile.c22
-rw-r--r--Python/exceptions.c118
-rw-r--r--Python/getargs.c262
-rw-r--r--Python/import.c34
-rw-r--r--Python/mactoolboxglue.c4
-rw-r--r--Python/marshal.c26
-rw-r--r--Python/modsupport.c7
-rw-r--r--Python/pystrtod.c2
-rw-r--r--Python/pythonrun.c2
-rw-r--r--Python/symtable.c8
-rw-r--r--Python/sysmodule.c2
-rw-r--r--Python/thread_nt.h4
15 files changed, 363 insertions, 187 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 362294f..4f607d6 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -405,7 +405,7 @@ builtin_compile(PyObject *self, PyObject *args)
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))
@@ -824,7 +824,7 @@ builtin_map(PyObject *self, PyObject *args)
PyObject *func, *result;
sequence *seqs = NULL, *sqp;
- int n, len;
+ Py_ssize_t n, len;
register int i, j;
n = PyTuple_Size(args);
@@ -1163,12 +1163,12 @@ In the second form, the callable is called until it returns the sentinel.");
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,
@@ -2346,8 +2346,8 @@ static PyObject *
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))
@@ -2417,9 +2417,9 @@ static PyObject *
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,
diff --git a/Python/ceval.c b/Python/ceval.c
index 501a9a0..0f2b173 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -599,7 +599,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throw)
/* Code access macros */
-#define INSTR_OFFSET() (next_instr - first_instr)
+#define INSTR_OFFSET() ((int)(next_instr - first_instr))
#define NEXTOP() (*next_instr++)
#define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2])
#define PEEKARG() ((next_instr[2]<<8) + next_instr[1])
@@ -637,7 +637,9 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throw)
/* 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])
@@ -3857,7 +3859,7 @@ ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
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;
@@ -3906,6 +3908,7 @@ _PyEval_SliceIndex(PyObject *v, int *pi)
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)
@@ -3925,7 +3928,7 @@ apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */
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))
@@ -3952,7 +3955,7 @@ assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
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))
diff --git a/Python/codecs.c b/Python/codecs.c
index 5c521fb..2fcd6c5 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -460,7 +460,7 @@ PyObject *PyCodec_StrictErrors(PyObject *exc)
#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;
@@ -478,16 +478,16 @@ PyObject *PyCodec_IgnoreErrors(PyObject *exc)
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;
@@ -502,7 +502,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
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;
}
@@ -510,7 +510,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
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;
@@ -525,7 +525,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
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;
}
@@ -540,8 +540,8 @@ PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc)
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;
@@ -631,7 +631,7 @@ PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc)
}
*outp++ = ';';
}
- restuple = Py_BuildValue("(Oi)", res, end);
+ restuple = Py_BuildValue("(On)", res, end);
Py_DECREF(res);
Py_DECREF(object);
return restuple;
@@ -652,8 +652,8 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
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;
@@ -708,7 +708,7 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
*outp++ = hexdigits[c&0xf];
}
- restuple = Py_BuildValue("(Oi)", res, end);
+ restuple = Py_BuildValue("(On)", res, end);
Py_DECREF(res);
Py_DECREF(object);
return restuple;
diff --git a/Python/compile.c b/Python/compile.c
index 0754ea5..e743168 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -317,7 +317,7 @@ compiler_free(struct compiler *c)
static PyObject *
list2dict(PyObject *list)
{
- int i, n;
+ Py_ssize_t i, n;
PyObject *v, *k, *dict = PyDict_New();
n = PyList_Size(list);
@@ -352,7 +352,7 @@ list2dict(PyObject *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);
@@ -407,7 +407,7 @@ static int
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));
@@ -458,7 +458,8 @@ static int
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));
@@ -551,7 +552,8 @@ static int
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));
@@ -653,7 +655,8 @@ markblocks(unsigned char *code, int len)
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;
@@ -989,7 +992,8 @@ static void
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)) {
@@ -1498,7 +1502,7 @@ static int
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);
@@ -4032,7 +4036,7 @@ static PyObject *
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)
diff --git a/Python/exceptions.c b/Python/exceptions.c
index 2e7c820..58e7c94 100644
--- a/Python/exceptions.c
+++ b/Python/exceptions.c
@@ -910,27 +910,34 @@ static PyMethodDef KeyError_methods[] = {
#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)
@@ -940,7 +947,6 @@ int set_int(PyObject *exc, const char *name, int value)
return result;
}
-
static
PyObject *get_string(PyObject *exc, const char *name)
{
@@ -1011,16 +1017,16 @@ PyObject *PyUnicodeTranslateError_GetObject(PyObject *exc)
return get_unicode(exc, "object");
}
-int PyUnicodeEncodeError_GetStart(PyObject *exc, int *start)
+int PyUnicodeEncodeError_GetStart(PyObject *exc, Py_ssize_t *start)
{
if (!get_int(exc, "start", start)) {
PyObject *object = PyUnicodeEncodeError_GetObject(exc);
- int size;
+ Py_ssize_t size;
if (!object)
return -1;
size = PyUnicode_GET_SIZE(object);
if (*start<0)
- *start = 0;
+ *start = 0; /*XXX check for values <0*/
if (*start>=size)
*start = size-1;
Py_DECREF(object);
@@ -1030,11 +1036,11 @@ int PyUnicodeEncodeError_GetStart(PyObject *exc, int *start)
}
-int PyUnicodeDecodeError_GetStart(PyObject *exc, int *start)
+int PyUnicodeDecodeError_GetStart(PyObject *exc, Py_ssize_t *start)
{
if (!get_int(exc, "start", start)) {
PyObject *object = PyUnicodeDecodeError_GetObject(exc);
- int size;
+ Py_ssize_t size;
if (!object)
return -1;
size = PyString_GET_SIZE(object);
@@ -1049,35 +1055,35 @@ int PyUnicodeDecodeError_GetStart(PyObject *exc, int *start)
}
-int PyUnicodeTranslateError_GetStart(PyObject *exc, int *start)
+int PyUnicodeTranslateError_GetStart(PyObject *exc, Py_ssize_t *start)
{
return PyUnicodeEncodeError_GetStart(exc, start);
}
-int PyUnicodeEncodeError_SetStart(PyObject *exc, int start)
+int PyUnicodeEncodeError_SetStart(PyObject *exc, Py_ssize_t start)
{
- return set_int(exc, "start", start);
+ return set_ssize_t(exc, "start", start);
}
-int PyUnicodeDecodeError_SetStart(PyObject *exc, int start)
+int PyUnicodeDecodeError_SetStart(PyObject *exc, Py_ssize_t start)
{
- return set_int(exc, "start", start);
+ return set_ssize_t(exc, "start", start);
}
-int PyUnicodeTranslateError_SetStart(PyObject *exc, int start)
+int PyUnicodeTranslateError_SetStart(PyObject *exc, Py_ssize_t start)
{
- return set_int(exc, "start", start);
+ return set_ssize_t(exc, "start", start);
}
-int PyUnicodeEncodeError_GetEnd(PyObject *exc, int *end)
+int PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
{
if (!get_int(exc, "end", end)) {
PyObject *object = PyUnicodeEncodeError_GetObject(exc);
- int size;
+ Py_ssize_t size;
if (!object)
return -1;
size = PyUnicode_GET_SIZE(object);
@@ -1092,11 +1098,11 @@ int PyUnicodeEncodeError_GetEnd(PyObject *exc, int *end)
}
-int PyUnicodeDecodeError_GetEnd(PyObject *exc, int *end)
+int PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
{
if (!get_int(exc, "end", end)) {
PyObject *object = PyUnicodeDecodeError_GetObject(exc);
- int size;
+ Py_ssize_t size;
if (!object)
return -1;
size = PyString_GET_SIZE(object);
@@ -1111,27 +1117,27 @@ int PyUnicodeDecodeError_GetEnd(PyObject *exc, int *end)
}
-int PyUnicodeTranslateError_GetEnd(PyObject *exc, int *start)
+int PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *start)
{
return PyUnicodeEncodeError_GetEnd(exc, start);
}
-int PyUnicodeEncodeError_SetEnd(PyObject *exc, int end)
+int PyUnicodeEncodeError_SetEnd(PyObject *exc, Py_ssize_t end)
{
- return set_int(exc, "end", end);
+ return set_ssize_t(exc, "end", end);
}
-int PyUnicodeDecodeError_SetEnd(PyObject *exc, int end)
+int PyUnicodeDecodeError_SetEnd(PyObject *exc, Py_ssize_t end)
{
- return set_int(exc, "end", end);
+ return set_ssize_t(exc, "end", end);
}
-int PyUnicodeTranslateError_SetEnd(PyObject *exc, int end)
+int PyUnicodeTranslateError_SetEnd(PyObject *exc, Py_ssize_t end)
{
- return set_int(exc, "end", end);
+ return set_ssize_t(exc, "end", end);
}
@@ -1229,8 +1235,8 @@ UnicodeEncodeError__str__(PyObject *self, PyObject *arg)
{
PyObject *encodingObj = NULL;
PyObject *objectObj = NULL;
- int start;
- int end;
+ Py_ssize_t start;
+ Py_ssize_t end;
PyObject *reasonObj = NULL;
char buffer[1000];
PyObject *result = NULL;
@@ -1270,11 +1276,12 @@ UnicodeEncodeError__str__(PyObject *self, PyObject *arg)
);
}
else {
+ /* XXX %zd? */
PyOS_snprintf(buffer, sizeof(buffer),
"'%.400s' codec can't encode characters in position %d-%d: %.400s",
PyString_AS_STRING(encodingObj),
- start,
- end-1,
+ (int)start,
+ (int)(end-1),
PyString_AS_STRING(reasonObj)
);
}
@@ -1295,10 +1302,10 @@ static PyMethodDef UnicodeEncodeError_methods[] = {
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);
}
@@ -1314,8 +1321,8 @@ UnicodeDecodeError__str__(PyObject *self, PyObject *arg)
{
PyObject *encodingObj = NULL;
PyObject *objectObj = NULL;
- int start;
- int end;
+ Py_ssize_t start;
+ Py_ssize_t end;
PyObject *reasonObj = NULL;
char buffer[1000];
PyObject *result = NULL;
@@ -1338,20 +1345,22 @@ UnicodeDecodeError__str__(PyObject *self, PyObject *arg)
goto error;
if (end==start+1) {
+ /* XXX %zd? */
PyOS_snprintf(buffer, sizeof(buffer),
"'%.400s' codec can't decode byte 0x%02x in position %d: %.400s",
PyString_AS_STRING(encodingObj),
((int)PyString_AS_STRING(objectObj)[start])&0xff,
- start,
+ (int)start,
PyString_AS_STRING(reasonObj)
);
}
else {
+ /* XXX %zd? */
PyOS_snprintf(buffer, sizeof(buffer),
"'%.400s' codec can't decode bytes in position %d-%d: %.400s",
PyString_AS_STRING(encodingObj),
- start,
- end-1,
+ (int)start,
+ (int)(end-1),
PyString_AS_STRING(reasonObj)
);
}
@@ -1372,11 +1381,14 @@ static PyMethodDef UnicodeDecodeError_methods[] = {
PyObject * PyUnicodeDecodeError_Create(
- const char *encoding, const char *object, int length,
- int start, int end, const char *reason)
+ const char *encoding, const char *object, Py_ssize_t length,
+ Py_ssize_t start, Py_ssize_t end, const char *reason)
{
+ assert(length < INT_MAX);
+ assert(start < INT_MAX);
+ assert(end < INT_MAX);
return PyObject_CallFunction(PyExc_UnicodeDecodeError, "ss#iis",
- encoding, object, length, start, end, reason);
+ encoding, object, (int)length, (int)start, (int)end, reason);
}
@@ -1427,8 +1439,8 @@ static PyObject *
UnicodeTranslateError__str__(PyObject *self, PyObject *arg)
{
PyObject *objectObj = NULL;
- int start;
- int end;
+ Py_ssize_t start;
+ Py_ssize_t end;
PyObject *reasonObj = NULL;
char buffer[1000];
PyObject *result = NULL;
@@ -1450,6 +1462,7 @@ UnicodeTranslateError__str__(PyObject *self, PyObject *arg)
if (end==start+1) {
int badchar = (int)PyUnicode_AS_UNICODE(objectObj)[start];
char *format;
+ /* XXX %zd? */
if (badchar <= 0xff)
format = "can't translate character u'\\x%02x' in position %d: %.400s";
else if (badchar <= 0xffff)
@@ -1459,15 +1472,16 @@ UnicodeTranslateError__str__(PyObject *self, PyObject *arg)
PyOS_snprintf(buffer, sizeof(buffer),
format,
badchar,
- start,
+ (int)start,
PyString_AS_STRING(reasonObj)
);
}
else {
+ /* XXX %zd? */
PyOS_snprintf(buffer, sizeof(buffer),
"can't translate characters in position %d-%d: %.400s",
- start,
- end-1,
+ (int)start,
+ (int)(end-1),
PyString_AS_STRING(reasonObj)
);
}
@@ -1487,8 +1501,8 @@ static PyMethodDef UnicodeTranslateError_methods[] = {
PyObject * PyUnicodeTranslateError_Create(
- const Py_UNICODE *object, int length,
- int start, int end, const char *reason)
+ const Py_UNICODE *object, Py_ssize_t length,
+ Py_ssize_t start, Py_ssize_t end, const char *reason)
{
return PyObject_CallFunction(PyExc_UnicodeTranslateError, "u#iis",
object, length, start, end, reason);
@@ -1749,7 +1763,7 @@ void
_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;
diff --git a/Python/getargs.c b/Python/getargs.c
index 9bcf9bc..0615577 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -15,21 +15,24 @@ int PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
int PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,
const char *, const char **, va_list);
+#define FLAG_COMPAT 1
+#define FLAG_SIZE_T 2
+
/* Forward */
static int vgetargs1(PyObject *, const char *, va_list *, int);
static void seterror(int, const char *, int *, const char *, const char *);
-static char *convertitem(PyObject *, const char **, va_list *, int *, char *,
- size_t, PyObject **);
-static char *converttuple(PyObject *, const char **, va_list *,
+static char *convertitem(PyObject *, const char **, va_list *, int, int *,
+ char *, size_t, PyObject **);
+static char *converttuple(PyObject *, const char **, va_list *, int,
int *, char *, size_t, int, PyObject **);
-static char *convertsimple(PyObject *, const char **, va_list *, char *,
+static char *convertsimple(PyObject *, const char **, va_list *, int, char *,
size_t, PyObject **);
-static int convertbuffer(PyObject *, void **p, char **);
+static Py_ssize_t convertbuffer(PyObject *, void **p, char **);
static int vgetargskeywords(PyObject *, PyObject *,
- const char *, const char **, va_list *);
-static char *skipitem(const char **, va_list *);
+ const char *, const char **, va_list *, int);
+static char *skipitem(const char **, va_list *, int);
int
PyArg_Parse(PyObject *args, const char *format, ...)
@@ -38,7 +41,19 @@ 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;
}
@@ -56,6 +71,18 @@ PyArg_ParseTuple(PyObject *args, const char *format, ...)
return retval;
}
+int
+_PyArg_ParseTuple_SizeT(PyObject *args, char *format, ...)
+{
+ int retval;
+ va_list va;
+
+ va_start(va, format);
+ retval = vgetargs1(args, format, &va, FLAG_SIZE_T);
+ va_end(va);
+ return retval;
+}
+
int
PyArg_VaParse(PyObject *args, const char *format, va_list va)
@@ -75,6 +102,24 @@ 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 */
@@ -120,7 +165,7 @@ cleanreturn(int retval, PyObject *freelist)
static int
-vgetargs1(PyObject *args, const char *format, va_list *p_va, int compat)
+vgetargs1(PyObject *args, const char *format, va_list *p_va, int flags)
{
char msgbuf[256];
int levels[32];
@@ -134,8 +179,10 @@ vgetargs1(PyObject *args, const char *format, va_list *p_va, int compat)
int i, len;
char *msg;
PyObject *freelist = NULL;
-
+ int compat = flags & FLAG_COMPAT;
+
assert(compat || (args != (PyObject*)NULL));
+ flags = flags & ~FLAG_COMPAT;
while (endfmt == 0) {
int c = *format++;
@@ -204,8 +251,8 @@ vgetargs1(PyObject *args, const char *format, va_list *p_va, int compat)
PyErr_SetString(PyExc_TypeError, msgbuf);
return 0;
}
- msg = convertitem(args, &format, p_va, levels, msgbuf,
- sizeof(msgbuf), &freelist);
+ msg = convertitem(args, &format, p_va, flags, levels,
+ msgbuf, sizeof(msgbuf), &freelist);
if (msg == NULL)
return cleanreturn(1, freelist);
seterror(levels[0], msg, levels+1, fname, message);
@@ -248,7 +295,8 @@ vgetargs1(PyObject *args, const char *format, va_list *p_va, int compat)
if (*format == '|')
format++;
msg = convertitem(PyTuple_GET_ITEM(args, i), &format, p_va,
- levels, msgbuf, sizeof(msgbuf), &freelist);
+ flags, levels, msgbuf,
+ sizeof(msgbuf), &freelist);
if (msg) {
seterror(i+1, msg, levels, fname, message);
return cleanreturn(0, freelist);
@@ -325,8 +373,9 @@ seterror(int iarg, const char *msg, int *levels, const char *fname,
*/
static char *
-converttuple(PyObject *arg, const char **p_format, va_list *p_va, int *levels,
- char *msgbuf, size_t bufsize, int toplevel, PyObject **freelist)
+converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
+ int *levels, char *msgbuf, size_t bufsize, int toplevel,
+ PyObject **freelist)
{
int level = 0;
int n = 0;
@@ -375,8 +424,8 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int *levels,
char *msg;
PyObject *item;
item = PySequence_GetItem(arg, i);
- msg = convertitem(item, &format, p_va, levels+1, msgbuf,
- bufsize, freelist);
+ msg = convertitem(item, &format, p_va, flags, levels+1,
+ msgbuf, bufsize, freelist);
/* PySequence_GetItem calls tp->sq_item, which INCREFs */
Py_XDECREF(item);
if (msg != NULL) {
@@ -393,22 +442,22 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int *levels,
/* Convert a single item. */
static char *
-convertitem(PyObject *arg, const char **p_format, va_list *p_va, int *levels,
- char *msgbuf, size_t bufsize, PyObject **freelist)
+convertitem(PyObject *arg, const char **p_format, va_list *p_va, int flags,
+ int *levels, char *msgbuf, size_t bufsize, PyObject **freelist)
{
char *msg;
const char *format = *p_format;
if (*format == '(' /* ')' */) {
format++;
- msg = converttuple(arg, &format, p_va, levels, msgbuf,
+ msg = converttuple(arg, &format, p_va, flags, levels, msgbuf,
bufsize, 0, freelist);
if (msg == NULL)
format++;
}
else {
- msg = convertsimple(arg, &format, p_va, msgbuf, bufsize,
- freelist);
+ msg = convertsimple(arg, &format, p_va, flags,
+ msgbuf, bufsize, freelist);
if (msg != NULL)
levels[0] = 0;
}
@@ -460,9 +509,16 @@ float_argument_error(PyObject *arg)
*/
static char *
-convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
+convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
char *msgbuf, size_t bufsize, PyObject **freelist)
{
+ /* For # codes */
+#define FETCH_SIZE int *q=NULL;Py_ssize_t *q2=NULL;\
+ if (flags & FLAG_SIZE_T) q2=va_arg(*p_va, Py_ssize_t*); \
+ else q=va_arg(*p_va, int*);
+#define STORE_SIZE(s) if (flags & FLAG_SIZE_T) *q2=s; else *q=s;
+#define BUFFER_LEN ((flags & FLAG_SIZE_T) ? *q2:*q)
+
const char *format = *p_format;
char c = *format++;
#ifdef Py_USING_UNICODE
@@ -544,7 +600,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
*p = (unsigned short) ival;
break;
}
-
+
case 'i': {/* signed int */
int *p = va_arg(*p_va, int *);
long ival;
@@ -582,6 +638,21 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
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;
@@ -679,11 +750,11 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
case 's': {/* string */
if (*format == '#') {
void **p = (void **)va_arg(*p_va, char **);
- int *q = va_arg(*p_va, int *);
+ FETCH_SIZE;
if (PyString_Check(arg)) {
*p = PyString_AS_STRING(arg);
- *q = PyString_GET_SIZE(arg);
+ STORE_SIZE(PyString_GET_SIZE(arg));
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(arg)) {
@@ -692,15 +763,15 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
return converterr(CONV_UNICODE,
arg, msgbuf, bufsize);
*p = PyString_AS_STRING(uarg);
- *q = PyString_GET_SIZE(uarg);
+ STORE_SIZE(PyString_GET_SIZE(uarg));
}
#endif
else { /* any buffer-like object */
char *buf;
- int count = convertbuffer(arg, p, &buf);
+ Py_ssize_t count = convertbuffer(arg, p, &buf);
if (count < 0)
return converterr(buf, arg, msgbuf, bufsize);
- *q = count;
+ STORE_SIZE(count);
}
format++;
} else {
@@ -729,15 +800,15 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
case 'z': {/* string, may be NULL (None) */
if (*format == '#') { /* any buffer-like object */
void **p = (void **)va_arg(*p_va, char **);
- int *q = va_arg(*p_va, int *);
+ FETCH_SIZE;
if (arg == Py_None) {
*p = 0;
- *q = 0;
+ STORE_SIZE(0);
}
else if (PyString_Check(arg)) {
*p = PyString_AS_STRING(arg);
- *q = PyString_GET_SIZE(arg);
+ STORE_SIZE(PyString_GET_SIZE(arg));
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(arg)) {
@@ -746,15 +817,15 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
return converterr(CONV_UNICODE,
arg, msgbuf, bufsize);
*p = PyString_AS_STRING(uarg);
- *q = PyString_GET_SIZE(uarg);
+ STORE_SIZE(PyString_GET_SIZE(uarg));
}
#endif
else { /* any buffer-like object */
char *buf;
- int count = convertbuffer(arg, p, &buf);
+ Py_ssize_t count = convertbuffer(arg, p, &buf);
if (count < 0)
return converterr(buf, arg, msgbuf, bufsize);
- *q = count;
+ STORE_SIZE(count);
}
format++;
} else {
@@ -777,7 +848,8 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
return converterr("string or None",
arg, msgbuf, bufsize);
if (*format == '#') {
- int *q = va_arg(*p_va, int *);
+ FETCH_SIZE;
+ assert(0); // redundant with if-case
if (arg == Py_None)
*q = 0;
else
@@ -883,10 +955,10 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
trailing 0-byte
*/
- int *buffer_len = va_arg(*p_va, int *);
+ FETCH_SIZE;
format++;
- if (buffer_len == NULL) {
+ if (q == NULL && q2 == NULL) {
Py_DECREF(s);
return converterr(
"(buffer_len is NULL)",
@@ -907,7 +979,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
arg, msgbuf, bufsize);
}
} else {
- if (size + 1 > *buffer_len) {
+ if (size + 1 > BUFFER_LEN) {
Py_DECREF(s);
return converterr(
"(buffer overflow)",
@@ -917,7 +989,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
memcpy(*buffer,
PyString_AS_STRING(s),
size + 1);
- *buffer_len = size;
+ STORE_SIZE(size);
} else {
/* Using a 0-terminated buffer:
@@ -961,17 +1033,17 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
case 'u': {/* raw unicode buffer (Py_UNICODE *) */
if (*format == '#') { /* any buffer-like object */
void **p = (void **)va_arg(*p_va, char **);
- int *q = va_arg(*p_va, int *);
+ FETCH_SIZE;
if (PyUnicode_Check(arg)) {
*p = PyUnicode_AS_UNICODE(arg);
- *q = PyUnicode_GET_SIZE(arg);
+ STORE_SIZE(PyUnicode_GET_SIZE(arg));
}
else {
char *buf;
- int count = convertbuffer(arg, p, &buf);
+ Py_ssize_t count = convertbuffer(arg, p, &buf);
if (count < 0)
return converterr(buf, arg, msgbuf, bufsize);
- *q = count/(sizeof(Py_UNICODE));
+ STORE_SIZE(count/(sizeof(Py_UNICODE)));
}
format++;
} else {
@@ -1061,9 +1133,8 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
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;
@@ -1094,7 +1165,10 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
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;
}
@@ -1107,11 +1181,11 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va,
return NULL;
}
-static int
+static Py_ssize_t
convertbuffer(PyObject *arg, void **p, char **errmsg)
{
PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
- int count;
+ Py_ssize_t count;
if (pb == NULL ||
pb->bf_getreadbuffer == NULL ||
pb->bf_getsegcount == NULL) {
@@ -1151,7 +1225,32 @@ PyArg_ParseTupleAndKeywords(PyObject *args,
}
va_start(va, kwlist);
- retval = vgetargskeywords(args, keywords, format, kwlist, &va);
+ retval = vgetargskeywords(args, keywords, format, kwlist, &va, 0);
+ va_end(va);
+ return retval;
+}
+
+int
+_PyArg_ParseTupleAndKeywords_SizeT(PyObject *args,
+ PyObject *keywords,
+ const char *format,
+ const char **kwlist, ...)
+{
+ int retval;
+ va_list va;
+
+ if ((args == NULL || !PyTuple_Check(args)) ||
+ (keywords != NULL && !PyDict_Check(keywords)) ||
+ format == NULL ||
+ kwlist == NULL)
+ {
+ PyErr_BadInternalCall();
+ return 0;
+ }
+
+ va_start(va, kwlist);
+ retval = vgetargskeywords(args, keywords, format,
+ kwlist, &va, FLAG_SIZE_T);
va_end(va);
return retval;
}
@@ -1185,14 +1284,47 @@ PyArg_VaParseTupleAndKeywords(PyObject *args,
#endif
#endif
- retval = vgetargskeywords(args, keywords, format, kwlist, &lva);
+ retval = vgetargskeywords(args, keywords, format, kwlist, &lva, 0);
+ return retval;
+}
+
+int
+_PyArg_VaParseTupleAndKeywords_SizeT(PyObject *args,
+ PyObject *keywords,
+ const char *format,
+ const char **kwlist, va_list va)
+{
+ int retval;
+ va_list lva;
+
+ if ((args == NULL || !PyTuple_Check(args)) ||
+ (keywords != NULL && !PyDict_Check(keywords)) ||
+ format == NULL ||
+ kwlist == NULL)
+ {
+ PyErr_BadInternalCall();
+ return 0;
+ }
+
+#ifdef VA_LIST_IS_ARRAY
+ memcpy(lva, va, sizeof(va_list));
+#else
+#ifdef __va_copy
+ __va_copy(lva, va);
+#else
+ lva = va;
+#endif
+#endif
+
+ retval = vgetargskeywords(args, keywords, format,
+ kwlist, &lva, FLAG_SIZE_T);
return retval;
}
static int
vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
- const char **kwlist, va_list *p_va)
+ const char **kwlist, va_list *p_va, int flags)
{
char msgbuf[512];
int levels[32];
@@ -1327,7 +1459,8 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
if (*format == '|')
format++;
msg = convertitem(PyTuple_GET_ITEM(args, i), &format, p_va,
- levels, msgbuf, sizeof(msgbuf), &freelist);
+ flags, levels, msgbuf, sizeof(msgbuf),
+ &freelist);
if (msg) {
seterror(i+1, msg, levels, fname, message);
return cleanreturn(0, freelist);
@@ -1347,8 +1480,8 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
item = PyDict_GetItemString(keywords, kwlist[i]);
if (item != NULL) {
Py_INCREF(item);
- msg = convertitem(item, &format, p_va, levels, msgbuf,
- sizeof(msgbuf), &freelist);
+ msg = convertitem(item, &format, p_va, flags, levels,
+ msgbuf, sizeof(msgbuf), &freelist);
Py_DECREF(item);
if (msg) {
seterror(i+1, msg, levels, fname, message);
@@ -1361,7 +1494,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
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);
@@ -1372,7 +1505,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
/* 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;
@@ -1403,7 +1536,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
static char *
-skipitem(const char **p_format, va_list *p_va)
+skipitem(const char **p_format, va_list *p_va, int flags)
{
const char *format = *p_format;
char c = *format++;
@@ -1435,6 +1568,12 @@ skipitem(const char **p_format, va_list *p_va)
(void) va_arg(*p_va, void *);
break;
}
+
+ case 'n': /* Py_ssize_t */
+ {
+ (void) va_arg(*p_va, Py_ssize_t *);
+ break;
+ }
/* string codes */
@@ -1458,7 +1597,10 @@ skipitem(const char **p_format, va_list *p_va)
{
(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;
diff --git a/Python/import.c b/Python/import.c
index 8bd25f7..e019a17 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -351,7 +351,7 @@ static char* sys_files[] = {
void
PyImport_Cleanup(void)
{
- int pos, ndone;
+ Py_ssize_t pos, ndone;
char *name;
PyObject *key, *value, *dict;
PyInterpreterState *interp = PyThreadState_GET()->interp;
@@ -689,7 +689,7 @@ make_compiled_pathname(char *pathname, char *buf, size_t buflen)
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;
@@ -805,10 +805,11 @@ open_exclusive(char *filename)
|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");
@@ -825,7 +826,7 @@ open_exclusive(char *filename)
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;
@@ -850,6 +851,7 @@ write_compiled_module(PyCodeObject *co, char *cpathname, long mtime)
}
/* Now write the true mtime */
fseek(fp, 4L, 0);
+ assert(mtime < LONG_MAX);
PyMarshal_WriteLongToFile(mtime, fp, Py_MARSHAL_VERSION);
fflush(fp);
fclose(fp);
@@ -1061,10 +1063,10 @@ get_path_importer(PyObject *path_importer_cache, PyObject *path_hooks,
#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};
@@ -1372,7 +1374,7 @@ PyAPI_FUNC(int) _PyImport_IsScript(struct filedescr * fd)
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
* ^ ^ ^ ^
@@ -1420,7 +1422,7 @@ PyAPI_FUNC(int) _PyImport_IsScript(struct filedescr * fd)
#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.
@@ -1891,12 +1893,12 @@ PyImport_ImportModule(const char *name)
}
/* 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 :-) */
@@ -1906,7 +1908,7 @@ import_module_ex(char *name, PyObject *globals, PyObject *locals,
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);
@@ -1976,7 +1978,7 @@ PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals,
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;
@@ -2044,7 +2046,7 @@ get_parent(PyObject *globals, char *buf, int *p_buflen)
/* 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, '.');
@@ -2114,7 +2116,7 @@ mark_miss(char *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;
diff --git a/Python/mactoolboxglue.c b/Python/mactoolboxglue.c
index 406b002..7f0627e 100644
--- a/Python/mactoolboxglue.c
+++ b/Python/mactoolboxglue.c
@@ -363,10 +363,10 @@ int (*PyMacGluePtr_##routinename)(PyObject *, object *); \
\
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); \
diff --git a/Python/marshal.c b/Python/marshal.c
index 5617226..e0f138d 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -59,7 +59,7 @@ typedef struct {
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);
@@ -117,7 +117,7 @@ w_long64(long x, WFILE *p)
static void
w_object(PyObject *v, WFILE *p)
{
- int i, n;
+ Py_ssize_t i, n;
p->depth++;
@@ -181,7 +181,7 @@ w_object(PyObject *v, WFILE *p)
else {
char buf[256]; /* Plenty to format any double */
PyFloat_AsReprString(buf, (PyFloatObject *)v);
- n = strlen(buf);
+ n = (int)strlen(buf);
w_byte(TYPE_FLOAT, p);
w_byte(n, p);
w_string(buf, n, p);
@@ -213,14 +213,14 @@ w_object(PyObject *v, WFILE *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);
}
@@ -236,7 +236,7 @@ w_object(PyObject *v, WFILE *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);
@@ -282,7 +282,7 @@ w_object(PyObject *v, WFILE *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! */
@@ -395,9 +395,10 @@ static int
r_string(char *s, int n, RFILE *p)
{
if (p->fp != NULL)
- return fread(s, 1, n, p->fp);
+ /* The result fits into int because it must be <=n. */
+ return (int)fread(s, 1, n, p->fp);
if (p->end - p->ptr < n)
- n = p->end - p->ptr;
+ n = (int)(p->end - p->ptr);
memcpy(s, p->ptr, n);
p->ptr += n;
return n;
@@ -939,7 +940,10 @@ PyMarshal_ReadLastObjectFromFile(FILE *fp)
pBuf = (char *)PyMem_MALLOC(filesize);
if (pBuf != NULL) {
PyObject* v;
- size_t n = fread(pBuf, 1, filesize, fp);
+ size_t n;
+ /* filesize must fit into an int, because it
+ is smaller than REASONABLE_FILE_LIMIT */
+ n = fread(pBuf, 1, (int)filesize, fp);
v = PyMarshal_ReadObjectFromString(pBuf, n);
if (pBuf != buf)
PyMem_FREE(pBuf);
@@ -970,7 +974,7 @@ PyMarshal_ReadObjectFromFile(FILE *fp)
}
PyObject *
-PyMarshal_ReadObjectFromString(char *str, int len)
+PyMarshal_ReadObjectFromString(char *str, Py_ssize_t len)
{
RFILE rf;
PyObject *result;
diff --git a/Python/modsupport.c b/Python/modsupport.c
index 7241936..f92fc34 100644
--- a/Python/modsupport.c
+++ b/Python/modsupport.c
@@ -313,6 +313,11 @@ do_mkvalue(const char **p_format, va_list *p_va)
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));
@@ -371,7 +376,7 @@ do_mkvalue(const char **p_format, va_list *p_va)
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);
}
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 3eccae8..83e792d 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -159,7 +159,7 @@ PyOS_ascii_strtod(const char *nptr, char **endptr)
**/
char *
PyOS_ascii_formatd(char *buffer,
- int buf_len,
+ size_t buf_len,
const char *format,
double d)
{
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 30cb518..0b7de42 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -939,7 +939,7 @@ print_error_text(PyObject *f, int offset, const char *text)
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') {
diff --git a/Python/symtable.c b/Python/symtable.c
index 7e876d4..7f3f5db 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -426,7 +426,8 @@ static int
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)
@@ -507,7 +508,7 @@ update_symbols(PyObject *symbols, PyObject *scope,
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;
@@ -583,7 +584,8 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
{
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)
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index f793b99..b240cc7 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1279,7 +1279,7 @@ PySys_SetArgv(int argc, char **argv)
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];
diff --git a/Python/thread_nt.h b/Python/thread_nt.h
index 47c776f..e52d288 100644
--- a/Python/thread_nt.h
+++ b/Python/thread_nt.h
@@ -170,7 +170,7 @@ bootstrap(void *call)
long
PyThread_start_new_thread(void (*func)(void *), void *arg)
{
- unsigned long rv;
+ uintptr_t rv;
callobj obj;
dprintf(("%ld: PyThread_start_new_thread called\n",
@@ -186,7 +186,7 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
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".
*/