Explorar o código

If getattr() fails, hasattr() will fail as well.

Removed hasattr() check, because hasattr() will call getattr() internally
anyway. If hasattr() fails, it means that getattr() has failed. So, there is no
need to call hasattr() before getattr().
Sander Mathijs van Veen %!s(int64=14) %!d(string=hai) anos
pai
achega
cd6e964db2
Modificáronse 1 ficheiros con 3 adicións e 6 borrados
  1. 3 6
      src/c/bison_callback.c

+ 3 - 6
src/c/bison_callback.c

@@ -104,14 +104,11 @@ PyObject* py_callback(PyObject *parser, char *target, int option, int nargs,
     if (unlikely(!res)) return res;
 
     // Check if the "hook_handler" callback exists
-    if (unlikely(!PyObject_HasAttr(parser, py_attr_hook_handler_name)))
-        return res;
-
     handle = PyObject_GetAttr(parser, py_attr_hook_handler_name);
 
-    if (unlikely(!handle)) {
-        Py_DECREF(res);
-        return NULL;
+    if (!handle) {
+        PyErr_Clear();
+        return res;
     }
 
     // Call the "hook_handler" callback