From 23d7ab77865f8b17042f5cd4c6720cca475e0eb5 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Wed, 13 Jan 2016 14:27:10 -0800 Subject: [PATCH] Remove nested functions nested functions are not supported on llvm/clang compiler, replacing them helps make code portable and be compilable with non-gcc compilers additionally fix the diagnostic messages clang reported source/c_gpio.c:130:18: warning: comparison of distinct pointer types ('volatile uint32_t *' (aka 'volatile unsigned int *') an d 'void *') [-Wcompare-distinct-pointer-types] if (gpio_map < MAP_FAILED) ~~~~~~~~ ^ ~~~~~~~~~~ source/c_gpio.c:89:13: warning: variable 'peri_base' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninit ialized] if (fread(buf, 1, sizeof buf, fp) == sizeof buf) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ source/c_gpio.c:116:17: note: uninitialized use occurs here gpio_base = peri_base + GPIO_BASE_OFFSET; ^~~~~~~~~ source/c_gpio.c:89:9: note: remove the 'if' if its condition is always true if (fread(buf, 1, sizeof buf, fp) == sizeof buf) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ source/c_gpio.c:64:23: note: initialize the variable 'peri_base' to silence this warning uint32_t peri_base; Signed-off-by: Khem Raj [Pierre-Jean: update for version 0.7.0] Signed-off-by: Pierre-Jean Texier --- Upstream-Status: Submitted source/c_gpio.c | 6 +-- source/py_gpio.c | 135 ++++++++++++++++++++++++++++--------------------------- 2 files changed, 71 insertions(+), 70 deletions(-) diff --git a/source/py_gpio.c b/source/py_gpio.c index d54cc7f..007bad5 100644 --- a/source/py_gpio.c +++ b/source/py_gpio.c @@ -69,6 +69,20 @@ static int mmap_gpio_mem(void) return 0; } } +static inline int cleanup_one(unsigned int gpio) +{ + // clean up any /sys/class exports + event_cleanup(gpio); + + // set everything back to input + if (gpio_direction[gpio] != -1) { + setup_gpio(gpio, INPUT, PUD_OFF); + gpio_direction[gpio] = -1; + return 1; + } + return 0; +} + // python function cleanup(channel=None) static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs) @@ -83,19 +97,6 @@ static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs) PyObject *tempobj; static char *kwlist[] = {"channel", NULL}; - void cleanup_one(void) - { - // clean up any /sys/class exports - event_cleanup(gpio); - - // set everything back to input - if (gpio_direction[gpio] != -1) { - setup_gpio(gpio, INPUT, PUD_OFF); - gpio_direction[gpio] = -1; - found = 1; - } - } - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, &chanlist)) return NULL; @@ -140,7 +141,7 @@ static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs) } else if (channel != -666) { // channel was an int indicating single channel if (get_gpio_number(channel, &gpio)) return NULL; - cleanup_one(); + found = cleanup_one(gpio); } else { // channel was a list/tuple for (i=0; i