summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2013-10-29 20:16:58 (GMT)
committerChristian Heimes <christian@cheimes.de>2013-10-29 20:16:58 (GMT)
commitdc6b933d2333e3928c73554a3dcf171ab4611b7d (patch)
treeb80503e4710d4c3cafad950d900cd34c8654c91e
parentee0bac66b2f388e2d685fa5eee2f7a4ea3910186 (diff)
parent34f7383d7ae1d3d040b3978680b9498c4ed150f5 (diff)
downloadcpython-dc6b933d2333e3928c73554a3dcf171ab4611b7d.zip
cpython-dc6b933d2333e3928c73554a3dcf171ab4611b7d.tar.gz
cpython-dc6b933d2333e3928c73554a3dcf171ab4611b7d.tar.bz2
merge
-rw-r--r--Modules/_ctypes/_ctypes.c4
-rw-r--r--Modules/_decimal/_decimal.c28
-rw-r--r--Modules/_localemodule.c5
-rw-r--r--Modules/_testcapimodule.c64
-rw-r--r--Objects/abstract.c2
-rw-r--r--Objects/unicodeobject.c25
6 files changed, 105 insertions, 23 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index daba2ba..9c81247 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -4280,6 +4280,10 @@ Array_subscript(PyObject *myself, PyObject *item)
for (cur = start, i = 0; i < slicelen;
cur += step, i++) {
PyObject *v = Array_item(myself, cur);
+ if (v == NULL) {
+ Py_DECREF(np);
+ return NULL;
+ }
PyList_SET_ITEM(np, i, v);
}
return np;
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index d3e3940..6f9e9de 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -3009,18 +3009,25 @@ convert_op_cmp(PyObject **vcmp, PyObject **wcmp, PyObject *v, PyObject *w,
*wcmp = Py_NotImplemented;
}
}
- else if (PyObject_IsInstance(w, Rational)) {
- *wcmp = numerator_as_decimal(w, context);
- if (*wcmp && !mpd_isspecial(MPD(v))) {
- *vcmp = multiply_by_denominator(v, w, context);
- if (*vcmp == NULL) {
- Py_CLEAR(*wcmp);
+ else {
+ int is_instance = PyObject_IsInstance(w, Rational);
+ if (is_instance < 0) {
+ *wcmp = NULL;
+ return 0;
+ }
+ if (is_instance) {
+ *wcmp = numerator_as_decimal(w, context);
+ if (*wcmp && !mpd_isspecial(MPD(v))) {
+ *vcmp = multiply_by_denominator(v, w, context);
+ if (*vcmp == NULL) {
+ Py_CLEAR(*wcmp);
+ }
}
}
- }
- else {
- Py_INCREF(Py_NotImplemented);
- *wcmp = Py_NotImplemented;
+ else {
+ Py_INCREF(Py_NotImplemented);
+ *wcmp = Py_NotImplemented;
+ }
}
if (*wcmp == NULL || *wcmp == Py_NotImplemented) {
@@ -3180,6 +3187,7 @@ dec_format(PyObject *dec, PyObject *args)
replace_fillchar = 1;
fmt = dec_strdup(fmt, size);
if (fmt == NULL) {
+ PyErr_NoMemory();
return NULL;
}
fmt[0] = '_';
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index b196749..400c344 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -151,8 +151,10 @@ PyLocale_localeconv(PyObject* self)
do { \
if (obj == NULL) \
goto failed; \
- if (PyDict_SetItemString(result, key, obj) < 0) \
+ if (PyDict_SetItemString(result, key, obj) < 0) { \
+ Py_DECREF(obj); \
goto failed; \
+ } \
Py_DECREF(obj); \
} while (0)
@@ -196,7 +198,6 @@ PyLocale_localeconv(PyObject* self)
failed:
Py_XDECREF(result);
- Py_XDECREF(x);
return NULL;
}
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 34b95c0..3362454 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -65,6 +65,69 @@ test_config(PyObject *self)
}
static PyObject*
+test_sizeof_c_types(PyObject *self)
+{
+#define CHECK_SIZEOF(TYPE, EXPECTED) \
+ if (EXPECTED != sizeof(TYPE)) { \
+ PyErr_Format(TestError, \
+ "sizeof(%s) = %u instead of %u", \
+ #TYPE, sizeof(TYPE), EXPECTED); \
+ return (PyObject*)NULL; \
+ }
+#define IS_SIGNED(TYPE) (((TYPE)-1) < (TYPE)0)
+#define CHECK_SIGNNESS(TYPE, SIGNED) \
+ if (IS_SIGNED(TYPE) != SIGNED) { \
+ PyErr_Format(TestError, \
+ "%s signness is, instead of %i", \
+ #TYPE, IS_SIGNED(TYPE), SIGNED); \
+ return (PyObject*)NULL; \
+ }
+
+ /* integer types */
+ CHECK_SIZEOF(Py_UCS1, 1);
+ CHECK_SIZEOF(Py_UCS2, 2);
+ CHECK_SIZEOF(Py_UCS4, 4);
+ CHECK_SIGNNESS(Py_UCS1, 0);
+ CHECK_SIGNNESS(Py_UCS2, 0);
+ CHECK_SIGNNESS(Py_UCS4, 0);
+#ifdef HAVE_INT32_T
+ CHECK_SIZEOF(PY_INT32_T, 4);
+ CHECK_SIGNNESS(PY_INT32_T, 1);
+#endif
+#ifdef HAVE_UINT32_T
+ CHECK_SIZEOF(PY_UINT32_T, 4);
+ CHECK_SIGNNESS(PY_UINT32_T, 0);
+#endif
+#ifdef HAVE_INT64_T
+ CHECK_SIZEOF(PY_INT64_T, 8);
+ CHECK_SIGNNESS(PY_INT64_T, 1);
+#endif
+#ifdef HAVE_UINT64_T
+ CHECK_SIZEOF(PY_UINT64_T, 8);
+ CHECK_SIGNNESS(PY_UINT64_T, 0);
+#endif
+
+ /* pointer/size types */
+ CHECK_SIZEOF(size_t, sizeof(void *));
+ CHECK_SIGNNESS(size_t, 0);
+ CHECK_SIZEOF(Py_ssize_t, sizeof(void *));
+ CHECK_SIGNNESS(Py_ssize_t, 1);
+
+ CHECK_SIZEOF(Py_uintptr_t, sizeof(void *));
+ CHECK_SIGNNESS(Py_uintptr_t, 0);
+ CHECK_SIZEOF(Py_intptr_t, sizeof(void *));
+ CHECK_SIGNNESS(Py_intptr_t, 1);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+
+#undef IS_SIGNED
+#undef CHECK_SIGNESS
+#undef CHECK_SIZEOF
+}
+
+
+static PyObject*
test_list_api(PyObject *self)
{
PyObject* list;
@@ -2783,6 +2846,7 @@ static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS},
{"raise_memoryerror", (PyCFunction)raise_memoryerror, METH_NOARGS},
{"test_config", (PyCFunction)test_config, METH_NOARGS},
+ {"test_sizeof_c_types", (PyCFunction)test_sizeof_c_types, METH_NOARGS},
{"test_datetime_capi", test_datetime_capi, METH_NOARGS},
{"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
{"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 6c7a6cd..91df5da 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -2144,6 +2144,8 @@ PyObject_CallFunction(PyObject *callable, const char *format, ...)
}
else
args = PyTuple_New(0);
+ if (args == NULL)
+ return NULL;
return call_function_tail(callable, args);
}
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index a7ea9c8..208e5e3 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -896,6 +896,19 @@ _PyUnicode_New(Py_ssize_t length)
if (unicode == NULL)
return NULL;
new_size = sizeof(Py_UNICODE) * ((size_t)length + 1);
+
+ _PyUnicode_WSTR_LENGTH(unicode) = length;
+ _PyUnicode_HASH(unicode) = -1;
+ _PyUnicode_STATE(unicode).interned = 0;
+ _PyUnicode_STATE(unicode).kind = 0;
+ _PyUnicode_STATE(unicode).compact = 0;
+ _PyUnicode_STATE(unicode).ready = 0;
+ _PyUnicode_STATE(unicode).ascii = 0;
+ _PyUnicode_DATA_ANY(unicode) = NULL;
+ _PyUnicode_LENGTH(unicode) = 0;
+ _PyUnicode_UTF8(unicode) = NULL;
+ _PyUnicode_UTF8_LENGTH(unicode) = 0;
+
_PyUnicode_WSTR(unicode) = (Py_UNICODE*) PyObject_MALLOC(new_size);
if (!_PyUnicode_WSTR(unicode)) {
Py_DECREF(unicode);
@@ -912,17 +925,7 @@ _PyUnicode_New(Py_ssize_t length)
*/
_PyUnicode_WSTR(unicode)[0] = 0;
_PyUnicode_WSTR(unicode)[length] = 0;
- _PyUnicode_WSTR_LENGTH(unicode) = length;
- _PyUnicode_HASH(unicode) = -1;
- _PyUnicode_STATE(unicode).interned = 0;
- _PyUnicode_STATE(unicode).kind = 0;
- _PyUnicode_STATE(unicode).compact = 0;
- _PyUnicode_STATE(unicode).ready = 0;
- _PyUnicode_STATE(unicode).ascii = 0;
- _PyUnicode_DATA_ANY(unicode) = NULL;
- _PyUnicode_LENGTH(unicode) = 0;
- _PyUnicode_UTF8(unicode) = NULL;
- _PyUnicode_UTF8_LENGTH(unicode) = 0;
+
assert(_PyUnicode_CheckConsistency((PyObject *)unicode, 0));
return unicode;
}