summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-03-07 12:08:51 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2006-03-07 12:08:51 (GMT)
commit725507b52ec40ab49ad87596fff7434322b9b5b1 (patch)
tree5b16b79a6810a7c2683db27ee9d34b10b270ae86 /Python
parent8eb8a829c1e4535be9d98b70875d5193f6b94737 (diff)
downloadcpython-725507b52ec40ab49ad87596fff7434322b9b5b1.zip
cpython-725507b52ec40ab49ad87596fff7434322b9b5b1.tar.gz
cpython-725507b52ec40ab49ad87596fff7434322b9b5b1.tar.bz2
Change int to Py_ssize_t in several places.
Add (int) casts to silence compiler warnings. Raise Python exceptions for overflows.
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c2
-rw-r--r--Python/exceptions.c4
-rw-r--r--Python/import.c8
-rw-r--r--Python/marshal.c36
-rw-r--r--Python/sysmodule.c2
5 files changed, 34 insertions, 18 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 409afd8..c9da78c 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -2514,7 +2514,7 @@ static PyObject *
filterunicode(PyObject *func, PyObject *strobj)
{
PyObject *result;
- register int i, j;
+ register Py_ssize_t i, j;
Py_ssize_t len = PyUnicode_GetSize(strobj);
Py_ssize_t outlen = len;
diff --git a/Python/exceptions.c b/Python/exceptions.c
index 5dec197..b146c97 100644
--- a/Python/exceptions.c
+++ b/Python/exceptions.c
@@ -764,7 +764,7 @@ static PyObject *
SyntaxError__init__(PyObject *self, PyObject *args)
{
PyObject *rtnval = NULL;
- int lenargs;
+ Py_ssize_t lenargs;
if (!(self = get_self(args)))
return NULL;
@@ -889,7 +889,7 @@ SyntaxError__str__(PyObject *self, PyObject *args)
PyErr_Clear();
if (have_filename || have_lineno) {
- int bufsize = PyString_GET_SIZE(str) + 64;
+ Py_ssize_t bufsize = PyString_GET_SIZE(str) + 64;
if (have_filename)
bufsize += PyString_GET_SIZE(filename);
diff --git a/Python/import.c b/Python/import.c
index 4aeeb3a..f214ed5 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -853,7 +853,7 @@ write_compiled_module(PyCodeObject *co, char *cpathname, time_t mtime)
/* Now write the true mtime */
fseek(fp, 4L, 0);
assert(mtime < LONG_MAX);
- PyMarshal_WriteLongToFile(mtime, fp, Py_MARSHAL_VERSION);
+ PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
fflush(fp);
fclose(fp);
if (Py_VerboseFlag)
@@ -1016,7 +1016,7 @@ get_path_importer(PyObject *path_importer_cache, PyObject *path_hooks,
PyObject *p)
{
PyObject *importer;
- int j, nhooks;
+ Py_ssize_t j, nhooks;
/* These conditions are the caller's responsibility: */
assert(PyList_Check(path_hooks));
@@ -1075,7 +1075,7 @@ static struct filedescr *
find_module(char *fullname, char *subname, PyObject *path, char *buf,
size_t buflen, FILE **p_fp, PyObject **p_loader)
{
- int i, npath;
+ Py_ssize_t i, npath;
size_t len, namelen;
struct filedescr *fdp = NULL;
char *filemode;
@@ -2028,7 +2028,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
modpath = PyDict_GetItem(globals, pathstr);
if (modpath != NULL) {
- int len = PyString_GET_SIZE(modname);
+ Py_ssize_t len = PyString_GET_SIZE(modname);
if (len > MAXPATHLEN) {
PyErr_SetString(PyExc_ValueError,
"Module name too long");
diff --git a/Python/marshal.c b/Python/marshal.c
index 7234a5c..c5d5b72 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -186,7 +186,7 @@ w_object(PyObject *v, WFILE *p)
n = strlen(buf);
w_byte(TYPE_FLOAT, p);
w_byte((int)n, p);
- w_string(buf, n, p);
+ w_string(buf, (int)n, p);
}
}
#ifndef WITHOUT_COMPLEX
@@ -215,16 +215,16 @@ w_object(PyObject *v, WFILE *p)
PyComplex_RealAsDouble(v));
PyFloat_AsReprString(buf, temp);
Py_DECREF(temp);
- n = (int)strlen(buf);
- w_byte(n, p);
- w_string(buf, n, p);
+ n = strlen(buf);
+ w_byte((int)n, p);
+ w_string(buf, (int)n, p);
temp = (PyFloatObject*)PyFloat_FromDouble(
PyComplex_ImagAsDouble(v));
PyFloat_AsReprString(buf, temp);
Py_DECREF(temp);
- n = (int)strlen(buf);
- w_byte(n, p);
- w_string(buf, n, p);
+ n = strlen(buf);
+ w_byte((int)n, p);
+ w_string(buf, (int)n, p);
}
}
#endif
@@ -248,8 +248,14 @@ w_object(PyObject *v, WFILE *p)
w_byte(TYPE_STRING, p);
}
n = PyString_GET_SIZE(v);
+ if (n > INT_MAX) {
+ /* huge strings are not supported */
+ p->depth--;
+ p->error = 1;
+ return;
+ }
w_long((long)n, p);
- w_string(PyString_AS_STRING(v), n, p);
+ w_string(PyString_AS_STRING(v), (int)n, p);
}
#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(v)) {
@@ -262,8 +268,13 @@ w_object(PyObject *v, WFILE *p)
}
w_byte(TYPE_UNICODE, p);
n = PyString_GET_SIZE(utf8);
+ if (n > INT_MAX) {
+ p->depth--;
+ p->error = 1;
+ return;
+ }
w_long((long)n, p);
- w_string(PyString_AS_STRING(utf8), n, p);
+ w_string(PyString_AS_STRING(utf8), (int)n, p);
Py_DECREF(utf8);
}
#endif
@@ -350,8 +361,13 @@ w_object(PyObject *v, WFILE *p)
PyBufferProcs *pb = v->ob_type->tp_as_buffer;
w_byte(TYPE_STRING, p);
n = (*pb->bf_getreadbuffer)(v, 0, (void **)&s);
+ if (n > INT_MAX) {
+ p->depth--;
+ p->error = 1;
+ return;
+ }
w_long((long)n, p);
- w_string(s, n, p);
+ w_string(s, (int)n, p);
}
else {
w_byte(TYPE_UNKNOWN, p);
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index a33ac26..6eadd06 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -597,7 +597,7 @@ sys_mdebug(PyObject *self, PyObject *args)
static PyObject *
sys_getrefcount(PyObject *self, PyObject *arg)
{
- return PyInt_FromLong(arg->ob_refcnt);
+ return PyInt_FromSsize_t(arg->ob_refcnt);
}
#ifdef Py_REF_DEBUG