Skip to content

Commit efc0a25

Browse files
committed
Treat warnings as errors
1 parent e7e987a commit efc0a25

File tree

6 files changed

+61
-14
lines changed

6 files changed

+61
-14
lines changed

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,16 @@ build:
1717

1818
install: build
1919
python setup.py install --force
20+
21+
build2:
22+
python2 setup.py build --force
23+
24+
install2: build2
25+
python2 setup.py install --force
26+
27+
build3:
28+
python3 setup.py build --force
29+
30+
install3: build3
31+
python3 setup.py install --force
32+

setup.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
else:
1919
kernel41 = None
2020

21+
CFLAGS = ['-Wall', '-Werror', '-Wno-format-security']
22+
2123
classifiers = ['Development Status :: 3 - Alpha',
2224
'Operating System :: POSIX :: Linux',
2325
'License :: OSI Approved :: MIT License',
@@ -40,9 +42,9 @@
4042
classifiers = classifiers,
4143
packages = find_packages(),
4244
py_modules = ['Adafruit_I2C'],
43-
ext_modules = [Extension('Adafruit_BBIO.GPIO', ['source/py_gpio.c', 'source/event_gpio.c', 'source/c_pinmux.c', 'source/constants.c', 'source/common.c'], extra_compile_args=['-Wno-format-security'], define_macros=kernel41),
44-
Extension('Adafruit_BBIO.PWM', ['source/py_pwm.c', 'source/c_pwm.c', 'source/c_pinmux.c', 'source/constants.c', 'source/common.c'], extra_compile_args=['-Wno-format-security'], define_macros=kernel41),
45-
Extension('Adafruit_BBIO.ADC', ['source/py_adc.c', 'source/c_adc.c', 'source/constants.c', 'source/common.c'], extra_compile_args=['-Wno-format-security'], define_macros=kernel41),
46-
Extension('Adafruit_BBIO.SPI', ['source/spimodule.c', 'source/constants.c', 'source/common.c'], extra_compile_args=['-Wno-format-security'], define_macros=kernel41),
47-
Extension('Adafruit_BBIO.UART', ['source/py_uart.c', 'source/c_uart.c', 'source/constants.c', 'source/common.c'], extra_compile_args=['-Wno-format-security'], define_macros=kernel41)] )
45+
ext_modules = [Extension('Adafruit_BBIO.GPIO', ['source/py_gpio.c', 'source/event_gpio.c', 'source/c_pinmux.c', 'source/constants.c', 'source/common.c'], extra_compile_args=CFLAGS, define_macros=kernel41),
46+
Extension('Adafruit_BBIO.PWM', ['source/py_pwm.c', 'source/c_pwm.c', 'source/c_pinmux.c', 'source/constants.c', 'source/common.c'], extra_compile_args=CFLAGS, define_macros=kernel41),
47+
Extension('Adafruit_BBIO.ADC', ['source/py_adc.c', 'source/c_adc.c', 'source/constants.c', 'source/common.c'], extra_compile_args=CFLAGS, define_macros=kernel41),
48+
Extension('Adafruit_BBIO.SPI', ['source/spimodule.c', 'source/constants.c', 'source/common.c'], extra_compile_args=CFLAGS, define_macros=kernel41),
49+
Extension('Adafruit_BBIO.UART', ['source/py_uart.c', 'source/c_uart.c', 'source/constants.c', 'source/common.c'], extra_compile_args=CFLAGS, define_macros=kernel41)] )
4850

source/c_pwm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,9 @@ BBIO_err pwm_start(const char *key, float duty, float freq, int polarity)
564564
BBIO_err pwm_disable(const char *key)
565565
{
566566
struct pwm_exp *pwm, *temp, *prev_pwm = NULL;
567-
BBIO_err err;
568567

569568
#ifndef BBBVERSION41
569+
BBIO_err err;
570570
char fragment[18];
571571
snprintf(fragment, sizeof(fragment), "bone_pwm_%s", key);
572572
err = unload_device_tree(fragment);

source/common.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ SOFTWARE.
3737
#include <glob.h>
3838
#include "common.h"
3939

40+
#include <linux/version.h>
41+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
42+
# ifndef BBBVERSION41
43+
# define BBBVERSION41
44+
# endif
45+
#endif
46+
4047
int setup_error = 0;
4148
int module_setup = 0;
4249

source/event_gpio.c

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ int gpio_export(unsigned int gpio)
8484
return -1;
8585
}
8686
len = snprintf(str_gpio, sizeof(str_gpio), "%d", gpio);
87-
write(fd, str_gpio, len);
87+
int ret = write(fd, str_gpio, len);
8888
close(fd);
89+
if (ret < 0) {
90+
return ret;
91+
}
8992

9093
// add to list
9194
new_gpio = malloc(sizeof(struct gpio_exp));
@@ -197,8 +200,11 @@ int gpio_unexport(unsigned int gpio)
197200
return -1;
198201

199202
len = snprintf(str_gpio, sizeof(str_gpio), "%d", gpio);
200-
write(fd, str_gpio, len);
203+
int ret = write(fd, str_gpio, len);
201204
close(fd);
205+
if (ret < 0) {
206+
return ret;
207+
}
202208

203209
// remove from list
204210
g = exported_gpios;
@@ -237,8 +243,12 @@ int gpio_set_direction(unsigned int gpio, unsigned int in_flag)
237243
strncpy(direction, "in", ARRAY_SIZE(direction) - 1);
238244
}
239245

240-
write(fd, direction, strlen(direction));
246+
int ret = write(fd, direction, strlen(direction));
241247
close(fd);
248+
if (ret < 0) {
249+
return ret;
250+
}
251+
242252
return 0;
243253
}
244254

@@ -253,7 +263,10 @@ int gpio_get_direction(unsigned int gpio, unsigned int *value)
253263
return -1;
254264

255265
lseek(fd, 0, SEEK_SET);
256-
read(fd, &direction, sizeof(direction) - 1);
266+
int ret = read(fd, &direction, sizeof(direction) - 1);
267+
if (ret < 0) {
268+
return ret;
269+
}
257270

258271
if (strcmp(direction, "out") == 0) {
259272
*value = OUTPUT;
@@ -285,8 +298,12 @@ int gpio_set_value(unsigned int gpio, unsigned int value)
285298
strncpy(vstr, "0", ARRAY_SIZE(vstr) - 1);
286299
}
287300

288-
write(fd, vstr, strlen(vstr));
301+
int ret = write(fd, vstr, strlen(vstr));
289302
close(fd);
303+
if (ret < 0) {
304+
return ret;
305+
}
306+
290307
return 0;
291308
}
292309

@@ -299,10 +316,13 @@ int gpio_get_value(unsigned int gpio, unsigned int *value)
299316
{
300317
if ((fd = open_value_file(gpio)) == -1)
301318
return -1;
302-
}
319+
}
303320

304321
lseek(fd, 0, SEEK_SET);
305-
read(fd, &ch, sizeof(ch));
322+
int ret = read(fd, &ch, sizeof(ch));
323+
if (ret < 0) {
324+
return ret;
325+
}
306326

307327
if (ch != '0') {
308328
*value = 1;
@@ -323,8 +343,12 @@ int gpio_set_edge(unsigned int gpio, unsigned int edge)
323343
if ((fd = open(filename, O_WRONLY)) < 0)
324344
return -1;
325345

326-
write(fd, stredge[edge], strlen(stredge[edge]) + 1);
346+
int ret = write(fd, stredge[edge], strlen(stredge[edge]) + 1);
327347
close(fd);
348+
if (ret < 0) {
349+
return ret;
350+
}
351+
328352
return 0;
329353
}
330354

source/spimodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#if PY_MAJOR_VERSION < 3
3737
# define PyLong_AS_LONG(val) PyInt_AS_LONG(val)
3838
# define PyLong_AsLong(val) PyInt_AsLong(val)
39+
# undef PyLong_Check
3940
# define PyLong_Check(val) PyInt_Check(val)
4041
#endif
4142

0 commit comments

Comments
 (0)