From 40459eab2c4a3af4a5eccd1b3cbe1bd94353f9c7 Mon Sep 17 00:00:00 2001 From: Cyril Hrubis Date: Mon, 4 Jun 2012 16:22:41 +0200 Subject: [PATCH] pywrap: Fix error reporting. The python headers define _GNU_SOURCE so the strerror_r variant is GNU one, which may use the passed buffer to, but that is not guaranted it also may return pointer to some statically allocated buffer. Also make sure _GNU_SOURCE is defined in pywrap.mk. --- pylib/gfxprim/common.i | 16 ++++++---------- pywrap.mk | 4 ++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pylib/gfxprim/common.i b/pylib/gfxprim/common.i index 66b37b09..bc99ff3b 100644 --- a/pylib/gfxprim/common.i +++ b/pylib/gfxprim/common.i @@ -23,11 +23,9 @@ %exception funcname { $action if (result == NULL) { - int errno0 = errno; - const int errbuf_len = 128; - char errbuf[errbuf_len]; - strerror_r(errno0, errbuf, errbuf_len); - PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errbuf); + char errbuf[128]; + char *errmsg = strerror_r(errno, errbuf, sizeof(errbuf)); + PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errmsg); return NULL; } } @@ -42,11 +40,9 @@ %exception funcname { $action if (result != 0) { - int errno0 = errno; - const int errbuf_len = 128; - char errbuf[errbuf_len]; - strerror_r(errno0, errbuf, errbuf_len); - PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errbuf); + char errbuf[128]; + char *errmsg = strerror_r(errno, errbuf, sizeof(errbuf)); + PyErr_Format(PyExc_RuntimeError, "Error in function %s: %s", "$name", errmsg); return NULL; } } diff --git a/pywrap.mk b/pywrap.mk index 0ec56027..03d22cfc 100644 --- a/pywrap.mk +++ b/pywrap.mk @@ -23,10 +23,10 @@ endif # VERBOSE $(SWIG_LIB): $(SWIG_C) ifdef VERBOSE - $(CC) $< $(CFLAGS) $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP $(LDLIBS) -L$(TOPDIR)/build/ -o $@ + $(CC) $< $(CFLAGS) -D_GNU_SOURCE=1 $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP $(LDLIBS) -L$(TOPDIR)/build/ -o $@ else # VERBOSE @echo "LD $@" - @$(CC) $< $(CFLAGS) $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP $(LDLIBS) -L$(TOPDIR)/build/ -o $@ + @$(CC) $< $(CFLAGS) -D_GNU_SOURCE=1 $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP $(LDLIBS) -L$(TOPDIR)/build/ -o $@ endif # VERBOSE endif # ifneq ($(SWIG),) -- 2.11.4.GIT