On 7 Jul, 21:12, sturlamolden <sturlamol...@yahoo.no> wrote: > > #define PyMem_MALLOC(n) (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \ > > : malloc((n) ? (n) : 1)) > > I was afraid of that :(
Also observe that this macro is very badly written (even illegal) C. Consider what this would do: PyMem_MALLOC(n++) According to Linus Thorvalds using macros like this is not even legal C: http://www.linuxfocus.org/common/src/January2004_linus.html This would be ok, and safe as long as we use the GIL: register Py_ssize_t __pymem_malloc_tmp; #define PyMem_MALLOC(n)\ (__pymem_malloc_tmp = n, (((__pymem_malloc_tmp) < 0 || (__pymem_malloc_tmp) > PY_SSIZE_T_MAX) ? NULL \ : malloc((__pymem_malloc_tmp) ? (__pymem_malloc_tmp) : 1))) An inline function is a better solution, but not ANSI C standard: inline void *PyMem_MALLOC(Py_ssize_t n) { return (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL : malloc((n) ? (n) : 1)); } -- http://mail.python.org/mailman/listinfo/python-list