Skip to content

Commit 9fe0193

Browse files
author
rhettinger
committed
* set_new() doesn't need to zero the structure a second time after tp_alloc
has already done the job. * Use a macro form of PyErr_Occurred() inside the set_lookkey() function. git-svn-id: http://svn.python.org/projects/python/trunk@39257 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 496f504 commit 9fe0193

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Include/pyerrors.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ PyAPI_FUNC(void) PyErr_Clear(void);
1515
PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
1616
PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
1717

18+
#ifdef Py_DEBUG
19+
#define _PyErr_OCCURRED() PyErr_Occurred()
20+
#else
21+
#define _PyErr_OCCURRED() (_PyThreadState_Current->curexc_type)
22+
#endif
23+
1824
/* Error testing and normalization */
1925
PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
2026
PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);

Objects/setobject.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ set_lookkey(PySetObject *so, PyObject *key, register long hash)
6666
if (entry->hash == hash) {
6767
/* error can't have been checked yet */
6868
checked_error = 1;
69-
if (PyErr_Occurred()) {
69+
if (_PyErr_OCCURRED()) {
7070
restore_error = 1;
7171
PyErr_Fetch(&err_type, &err_value, &err_tb);
7272
}
@@ -104,7 +104,7 @@ set_lookkey(PySetObject *so, PyObject *key, register long hash)
104104
if (entry->hash == hash && entry->key != dummy) {
105105
if (!checked_error) {
106106
checked_error = 1;
107-
if (PyErr_Occurred()) {
107+
if (_PyErr_OCCURRED()) {
108108
restore_error = 1;
109109
PyErr_Fetch(&err_type, &err_value,
110110
&err_tb);
@@ -720,7 +720,10 @@ make_new_set(PyTypeObject *type, PyObject *iterable)
720720
if (so == NULL)
721721
return NULL;
722722

723-
EMPTY_TO_MINSIZE(so);
723+
/* tp_alloc has already zeroed the structure */
724+
assert(so->table == NULL && so->fill == 0 && so->used == 0);
725+
so->table = so->smalltable;
726+
so->mask = PySet_MINSIZE - 1;
724727
so->lookup = set_lookkey_string;
725728
so->hash = -1;
726729
so->weakreflist = NULL;

0 commit comments

Comments
 (0)