Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc6b933

Browse files
committed
merge
2 parents ee0bac6 + 34f7383 commit dc6b933

6 files changed

Lines changed: 105 additions & 23 deletions

File tree

Modules/_ctypes/_ctypes.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4280,6 +4280,10 @@ Array_subscript(PyObject *myself, PyObject *item)
42804280
for (cur = start, i = 0; i < slicelen;
42814281
cur += step, i++) {
42824282
PyObject *v = Array_item(myself, cur);
4283+
if (v == NULL) {
4284+
Py_DECREF(np);
4285+
return NULL;
4286+
}
42834287
PyList_SET_ITEM(np, i, v);
42844288
}
42854289
return np;

Modules/_decimal/_decimal.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,18 +3009,25 @@ convert_op_cmp(PyObject **vcmp, PyObject **wcmp, PyObject *v, PyObject *w,
30093009
*wcmp = Py_NotImplemented;
30103010
}
30113011
}
3012-
else if (PyObject_IsInstance(w, Rational)) {
3013-
*wcmp = numerator_as_decimal(w, context);
3014-
if (*wcmp && !mpd_isspecial(MPD(v))) {
3015-
*vcmp = multiply_by_denominator(v, w, context);
3016-
if (*vcmp == NULL) {
3017-
Py_CLEAR(*wcmp);
3012+
else {
3013+
int is_instance = PyObject_IsInstance(w, Rational);
3014+
if (is_instance < 0) {
3015+
*wcmp = NULL;
3016+
return 0;
3017+
}
3018+
if (is_instance) {
3019+
*wcmp = numerator_as_decimal(w, context);
3020+
if (*wcmp && !mpd_isspecial(MPD(v))) {
3021+
*vcmp = multiply_by_denominator(v, w, context);
3022+
if (*vcmp == NULL) {
3023+
Py_CLEAR(*wcmp);
3024+
}
30183025
}
30193026
}
3020-
}
3021-
else {
3022-
Py_INCREF(Py_NotImplemented);
3023-
*wcmp = Py_NotImplemented;
3027+
else {
3028+
Py_INCREF(Py_NotImplemented);
3029+
*wcmp = Py_NotImplemented;
3030+
}
30243031
}
30253032

30263033
if (*wcmp == NULL || *wcmp == Py_NotImplemented) {
@@ -3180,6 +3187,7 @@ dec_format(PyObject *dec, PyObject *args)
31803187
replace_fillchar = 1;
31813188
fmt = dec_strdup(fmt, size);
31823189
if (fmt == NULL) {
3190+
PyErr_NoMemory();
31833191
return NULL;
31843192
}
31853193
fmt[0] = '_';

Modules/_localemodule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ PyLocale_localeconv(PyObject* self)
151151
do { \
152152
if (obj == NULL) \
153153
goto failed; \
154-
if (PyDict_SetItemString(result, key, obj) < 0) \
154+
if (PyDict_SetItemString(result, key, obj) < 0) { \
155+
Py_DECREF(obj); \
155156
goto failed; \
157+
} \
156158
Py_DECREF(obj); \
157159
} while (0)
158160

@@ -196,7 +198,6 @@ PyLocale_localeconv(PyObject* self)
196198

197199
failed:
198200
Py_XDECREF(result);
199-
Py_XDECREF(x);
200201
return NULL;
201202
}
202203

Modules/_testcapimodule.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,69 @@ test_config(PyObject *self)
6464
return Py_None;
6565
}
6666

67+
static PyObject*
68+
test_sizeof_c_types(PyObject *self)
69+
{
70+
#define CHECK_SIZEOF(TYPE, EXPECTED) \
71+
if (EXPECTED != sizeof(TYPE)) { \
72+
PyErr_Format(TestError, \
73+
"sizeof(%s) = %u instead of %u", \
74+
#TYPE, sizeof(TYPE), EXPECTED); \
75+
return (PyObject*)NULL; \
76+
}
77+
#define IS_SIGNED(TYPE) (((TYPE)-1) < (TYPE)0)
78+
#define CHECK_SIGNNESS(TYPE, SIGNED) \
79+
if (IS_SIGNED(TYPE) != SIGNED) { \
80+
PyErr_Format(TestError, \
81+
"%s signness is, instead of %i", \
82+
#TYPE, IS_SIGNED(TYPE), SIGNED); \
83+
return (PyObject*)NULL; \
84+
}
85+
86+
/* integer types */
87+
CHECK_SIZEOF(Py_UCS1, 1);
88+
CHECK_SIZEOF(Py_UCS2, 2);
89+
CHECK_SIZEOF(Py_UCS4, 4);
90+
CHECK_SIGNNESS(Py_UCS1, 0);
91+
CHECK_SIGNNESS(Py_UCS2, 0);
92+
CHECK_SIGNNESS(Py_UCS4, 0);
93+
#ifdef HAVE_INT32_T
94+
CHECK_SIZEOF(PY_INT32_T, 4);
95+
CHECK_SIGNNESS(PY_INT32_T, 1);
96+
#endif
97+
#ifdef HAVE_UINT32_T
98+
CHECK_SIZEOF(PY_UINT32_T, 4);
99+
CHECK_SIGNNESS(PY_UINT32_T, 0);
100+
#endif
101+
#ifdef HAVE_INT64_T
102+
CHECK_SIZEOF(PY_INT64_T, 8);
103+
CHECK_SIGNNESS(PY_INT64_T, 1);
104+
#endif
105+
#ifdef HAVE_UINT64_T
106+
CHECK_SIZEOF(PY_UINT64_T, 8);
107+
CHECK_SIGNNESS(PY_UINT64_T, 0);
108+
#endif
109+
110+
/* pointer/size types */
111+
CHECK_SIZEOF(size_t, sizeof(void *));
112+
CHECK_SIGNNESS(size_t, 0);
113+
CHECK_SIZEOF(Py_ssize_t, sizeof(void *));
114+
CHECK_SIGNNESS(Py_ssize_t, 1);
115+
116+
CHECK_SIZEOF(Py_uintptr_t, sizeof(void *));
117+
CHECK_SIGNNESS(Py_uintptr_t, 0);
118+
CHECK_SIZEOF(Py_intptr_t, sizeof(void *));
119+
CHECK_SIGNNESS(Py_intptr_t, 1);
120+
121+
Py_INCREF(Py_None);
122+
return Py_None;
123+
124+
#undef IS_SIGNED
125+
#undef CHECK_SIGNESS
126+
#undef CHECK_SIZEOF
127+
}
128+
129+
67130
static PyObject*
68131
test_list_api(PyObject *self)
69132
{
@@ -2783,6 +2846,7 @@ static PyMethodDef TestMethods[] = {
27832846
{"raise_exception", raise_exception, METH_VARARGS},
27842847
{"raise_memoryerror", (PyCFunction)raise_memoryerror, METH_NOARGS},
27852848
{"test_config", (PyCFunction)test_config, METH_NOARGS},
2849+
{"test_sizeof_c_types", (PyCFunction)test_sizeof_c_types, METH_NOARGS},
27862850
{"test_datetime_capi", test_datetime_capi, METH_NOARGS},
27872851
{"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
27882852
{"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},

Objects/abstract.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,8 @@ PyObject_CallFunction(PyObject *callable, const char *format, ...)
21442144
}
21452145
else
21462146
args = PyTuple_New(0);
2147+
if (args == NULL)
2148+
return NULL;
21472149

21482150
return call_function_tail(callable, args);
21492151
}

Objects/unicodeobject.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,19 @@ _PyUnicode_New(Py_ssize_t length)
896896
if (unicode == NULL)
897897
return NULL;
898898
new_size = sizeof(Py_UNICODE) * ((size_t)length + 1);
899+
900+
_PyUnicode_WSTR_LENGTH(unicode) = length;
901+
_PyUnicode_HASH(unicode) = -1;
902+
_PyUnicode_STATE(unicode).interned = 0;
903+
_PyUnicode_STATE(unicode).kind = 0;
904+
_PyUnicode_STATE(unicode).compact = 0;
905+
_PyUnicode_STATE(unicode).ready = 0;
906+
_PyUnicode_STATE(unicode).ascii = 0;
907+
_PyUnicode_DATA_ANY(unicode) = NULL;
908+
_PyUnicode_LENGTH(unicode) = 0;
909+
_PyUnicode_UTF8(unicode) = NULL;
910+
_PyUnicode_UTF8_LENGTH(unicode) = 0;
911+
899912
_PyUnicode_WSTR(unicode) = (Py_UNICODE*) PyObject_MALLOC(new_size);
900913
if (!_PyUnicode_WSTR(unicode)) {
901914
Py_DECREF(unicode);
@@ -912,17 +925,7 @@ _PyUnicode_New(Py_ssize_t length)
912925
*/
913926
_PyUnicode_WSTR(unicode)[0] = 0;
914927
_PyUnicode_WSTR(unicode)[length] = 0;
915-
_PyUnicode_WSTR_LENGTH(unicode) = length;
916-
_PyUnicode_HASH(unicode) = -1;
917-
_PyUnicode_STATE(unicode).interned = 0;
918-
_PyUnicode_STATE(unicode).kind = 0;
919-
_PyUnicode_STATE(unicode).compact = 0;
920-
_PyUnicode_STATE(unicode).ready = 0;
921-
_PyUnicode_STATE(unicode).ascii = 0;
922-
_PyUnicode_DATA_ANY(unicode) = NULL;
923-
_PyUnicode_LENGTH(unicode) = 0;
924-
_PyUnicode_UTF8(unicode) = NULL;
925-
_PyUnicode_UTF8_LENGTH(unicode) = 0;
928+
926929
assert(_PyUnicode_CheckConsistency((PyObject *)unicode, 0));
927930
return unicode;
928931
}

0 commit comments

Comments
 (0)