use new PyDict_SetDefault() C-API function in Py3.4
authorStefan Behnel <stefan_ml@behnel.de>
Fri, 8 Mar 2013 07:07:36 +0000 (08:07 +0100)
committerStefan Behnel <stefan_ml@behnel.de>
Fri, 8 Mar 2013 07:07:36 +0000 (08:07 +0100)
Cython/Utility/Optimize.c

index 109e539..7b2ae07 100644 (file)
@@ -154,8 +154,16 @@ static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *ke
 /////////////// dict_setdefault ///////////////
 //@requires: ObjectHandling.c::PyObjectCallMethod
 
-static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value, int is_safe_type) {
+static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value,
+                                                       CYTHON_UNUSED int is_safe_type) {
     PyObject* value;
+#if PY_VERSION_HEX >= 0x030400A0
+    // we keep the method call at the end to avoid "unused" C compiler warnings
+    if (1) {
+        value = PyDict_SetDefault(d, key, default_value);
+        if (unlikely(!value)) return NULL;
+        Py_INCREF(value);
+#else
     if (is_safe_type == 1 || (is_safe_type == -1 &&
         /* the following builtins presumably have repeatably safe and fast hash functions */
 #if PY_MAJOR_VERSION >= 3
@@ -179,6 +187,7 @@ static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *ke
         }
         Py_INCREF(value);
 #endif
+#endif
     } else {
         value = __Pyx_PyObject_CallMethod2(d, PYIDENT("setdefault"), key, default_value);
     }