Commit 5ba0cbe3 authored by Raymond Hettinger's avatar Raymond Hettinger

* 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.
parent fe889f3c
...@@ -15,6 +15,12 @@ PyAPI_FUNC(void) PyErr_Clear(void); ...@@ -15,6 +15,12 @@ PyAPI_FUNC(void) PyErr_Clear(void);
PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **); PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *); PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
#ifdef Py_DEBUG
#define _PyErr_OCCURRED() PyErr_Occurred()
#else
#define _PyErr_OCCURRED() (_PyThreadState_Current->curexc_type)
#endif
/* Error testing and normalization */ /* Error testing and normalization */
PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *); PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *); PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);
......
...@@ -66,7 +66,7 @@ set_lookkey(PySetObject *so, PyObject *key, register long hash) ...@@ -66,7 +66,7 @@ set_lookkey(PySetObject *so, PyObject *key, register long hash)
if (entry->hash == hash) { if (entry->hash == hash) {
/* error can't have been checked yet */ /* error can't have been checked yet */
checked_error = 1; checked_error = 1;
if (PyErr_Occurred()) { if (_PyErr_OCCURRED()) {
restore_error = 1; restore_error = 1;
PyErr_Fetch(&err_type, &err_value, &err_tb); PyErr_Fetch(&err_type, &err_value, &err_tb);
} }
...@@ -104,7 +104,7 @@ set_lookkey(PySetObject *so, PyObject *key, register long hash) ...@@ -104,7 +104,7 @@ set_lookkey(PySetObject *so, PyObject *key, register long hash)
if (entry->hash == hash && entry->key != dummy) { if (entry->hash == hash && entry->key != dummy) {
if (!checked_error) { if (!checked_error) {
checked_error = 1; checked_error = 1;
if (PyErr_Occurred()) { if (_PyErr_OCCURRED()) {
restore_error = 1; restore_error = 1;
PyErr_Fetch(&err_type, &err_value, PyErr_Fetch(&err_type, &err_value,
&err_tb); &err_tb);
...@@ -720,7 +720,10 @@ make_new_set(PyTypeObject *type, PyObject *iterable) ...@@ -720,7 +720,10 @@ make_new_set(PyTypeObject *type, PyObject *iterable)
if (so == NULL) if (so == NULL)
return NULL; return NULL;
EMPTY_TO_MINSIZE(so); /* tp_alloc has already zeroed the structure */
assert(so->table == NULL && so->fill == 0 && so->used == 0);
so->table = so->smalltable;
so->mask = PySet_MINSIZE - 1;
so->lookup = set_lookkey_string; so->lookup = set_lookkey_string;
so->hash = -1; so->hash = -1;
so->weakreflist = NULL; so->weakreflist = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment