summaryrefslogtreecommitdiff
path: root/Cython/Utility/ModuleSetupCode.c
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2015-03-29 08:41:05 +0200
committerStefan Behnel <stefan_ml@behnel.de>2015-03-29 08:41:05 +0200
commit9990450e1be30dd64e1641071d626eda8d832077 (patch)
tree09d020c41895f5899f8a4dfb35e1c1f75fddd222 /Cython/Utility/ModuleSetupCode.c
parentbcb1043346786605e0cf0d0096cbe006f140ddf0 (diff)
downloadcython-9990450e1be30dd64e1641071d626eda8d832077.tar.gz
improve declaration of __Pyx_sst_abs() macro to avoid using llabs() before C99
--HG-- extra : amend_source : 69b25b07657205e86aade4f4f8285e721e4648b0
Diffstat (limited to 'Cython/Utility/ModuleSetupCode.c')
-rw-r--r--Cython/Utility/ModuleSetupCode.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c
index fb49a84e5..6ca2dddad 100644
--- a/Cython/Utility/ModuleSetupCode.c
+++ b/Cython/Utility/ModuleSetupCode.c
@@ -183,9 +183,17 @@
#define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
-#define __Pyx_sst_abs(value) \
- (sizeof(int) >= sizeof(Py_ssize_t) ? abs(value) : \
- (sizeof(long) >= sizeof(Py_ssize_t) ? labs(value) : llabs(value)))
+// fast and unsafe abs(Py_ssize_t) that ignores the overflow for (-PY_SSIZE_T_MAX-1)
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+ #define __Pyx_sst_abs(value) \
+ (sizeof(int) >= sizeof(Py_ssize_t) ? abs(value) : \
+ (sizeof(long) >= sizeof(Py_ssize_t) ? labs(value) : llabs(value)))
+#else
+ #define __Pyx_sst_abs(value) \
+ (sizeof(int) >= sizeof(Py_ssize_t) ? abs(value) : \
+ (sizeof(long) >= sizeof(Py_ssize_t) ? labs(value) : \
+ ((value<0) ? -value : value)))
+#endif
/* inline attribute */
#ifndef CYTHON_INLINE