[Python-checkins] r46246 - python/trunk/Modules/_struct.c
bob.ippolito
python-checkins at python.org
Thu May 25 21:33:38 CEST 2006
Author: bob.ippolito
Date: Thu May 25 21:33:38 2006
New Revision: 46246
Modified:
python/trunk/Modules/_struct.c
Log:
Use LONG_MIN and LONG_MAX to check Python integer bounds instead of the incorrect INT_MIN and INT_MAX
Modified: python/trunk/Modules/_struct.c
==============================================================================
--- python/trunk/Modules/_struct.c (original)
+++ python/trunk/Modules/_struct.c Thu May 25 21:33:38 2006
@@ -291,7 +291,7 @@
unsigned int x;
memcpy((char *)&x, p, sizeof x);
#ifdef PY_USE_INT_WHEN_POSSIBLE
- if (x <= INT_MAX)
+ if (x <= LONG_MAX)
return PyInt_FromLong((long)x);
#endif
return PyLong_FromUnsignedLong((unsigned long)x);
@@ -311,7 +311,7 @@
unsigned long x;
memcpy((char *)&x, p, sizeof x);
#ifdef PY_USE_INT_WHEN_POSSIBLE
- if (x <= INT_MAX)
+ if (x <= LONG_MAX)
return PyInt_FromLong((long)x);
#endif
return PyLong_FromUnsignedLong(x);
@@ -328,7 +328,7 @@
PY_LONG_LONG x;
memcpy((char *)&x, p, sizeof x);
#ifdef PY_USE_INT_WHEN_POSSIBLE
- if (x >= INT_MIN && x <= INT_MAX)
+ if (x >= LONG_MIN && x <= LONG_MAX)
return PyInt_FromLong(Py_SAFE_DOWNCAST(x, PY_LONG_LONG, long));
#endif
return PyLong_FromLongLong(x);
@@ -340,7 +340,7 @@
unsigned PY_LONG_LONG x;
memcpy((char *)&x, p, sizeof x);
#ifdef PY_USE_INT_WHEN_POSSIBLE
- if (x <= INT_MAX)
+ if (x <= LONG_MAX)
return PyInt_FromLong(Py_SAFE_DOWNCAST(x, unsigned PY_LONG_LONG, long));
#endif
return PyLong_FromUnsignedLongLong(x);
@@ -607,7 +607,7 @@
x = (x<<8) | (*p++ & 0xFF);
} while (--i > 0);
#ifdef PY_USE_INT_WHEN_POSSIBLE
- if (x <= INT_MAX)
+ if (x <= LONG_MAX)
return PyInt_FromLong((long)x);
#else
if (SIZEOF_LONG > f->size)
@@ -629,7 +629,7 @@
if (SIZEOF_LONG_LONG > f->size)
x |= -(x & (1L << (8 * f->size - 1)));
#ifdef PY_USE_INT_WHEN_POSSIBLE
- if (x >= INT_MIN && x <= INT_MAX)
+ if (x >= LONG_MIN && x <= LONG_MAX)
return PyInt_FromLong(Py_SAFE_DOWNCAST(x, PY_LONG_LONG, long));
#endif
return PyLong_FromLongLong(x);
@@ -651,7 +651,7 @@
x = (x<<8) | (*p++ & 0xFF);
} while (--i > 0);
#ifdef PY_USE_INT_WHEN_POSSIBLE
- if (x <= INT_MAX)
+ if (x <= LONG_MAX)
return PyInt_FromLong(Py_SAFE_DOWNCAST(x, unsigned PY_LONG_LONG, long));
#endif
return PyLong_FromUnsignedLongLong(x);
@@ -806,7 +806,7 @@
x = (x<<8) | (p[--i] & 0xFF);
} while (i > 0);
#ifdef PY_USE_INT_WHEN_POSSIBLE
- if (x <= INT_MAX)
+ if (x <= LONG_MAX)
return PyInt_FromLong((long)x);
#else
if (SIZEOF_LONG > f->size)
@@ -828,7 +828,7 @@
if (SIZEOF_LONG_LONG > f->size)
x |= -(x & (1L << (8 * f->size - 1)));
#ifdef PY_USE_INT_WHEN_POSSIBLE
- if (x >= INT_MIN && x <= INT_MAX)
+ if (x >= LONG_MIN && x <= LONG_MAX)
return PyInt_FromLong(Py_SAFE_DOWNCAST(x, PY_LONG_LONG, long));
#endif
return PyLong_FromLongLong(x);
@@ -850,7 +850,7 @@
x = (x<<8) | (p[--i] & 0xFF);
} while (i > 0);
#ifdef PY_USE_INT_WHEN_POSSIBLE
- if (x <= INT_MAX)
+ if (x <= LONG_MAX)
return PyInt_FromLong(Py_SAFE_DOWNCAST(x, unsigned PY_LONG_LONG, long));
#endif
return PyLong_FromUnsignedLongLong(x);
@@ -1477,14 +1477,17 @@
if (PyType_Ready(&PyStructType) < 0)
return;
+
/* Add some symbolic constants to the module */
if (StructError == NULL) {
StructError = PyErr_NewException("struct.error", NULL, NULL);
if (StructError == NULL)
return;
}
+
Py_INCREF(StructError);
PyModule_AddObject(m, "error", StructError);
+
Py_INCREF((PyObject*)&PyStructType);
PyModule_AddObject(m, "Struct", (PyObject*)&PyStructType);
}
More information about the Python-checkins
mailing list