Skip to content

Commit eba0243

Browse files
committed
Treat warnings as errors
1 parent eb0b347 commit eba0243

File tree

6 files changed

+75
-25
lines changed

6 files changed

+75
-25
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/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/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/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/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: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ int pwm_set_frequency(const char *key, float freq) {
8282
unsigned long period_ns;
8383
struct pwm_exp *pwm;
8484

85-
if (freq <= 0.0)
85+
if (freq <= 0.0) {
8686
return -1;
87+
}
8788

8889
pwm = lookup_exported_pwm(key);
89-
9090
if (pwm == NULL) {
9191
return -1;
9292
}
@@ -97,7 +97,9 @@ int pwm_set_frequency(const char *key, float freq) {
9797
pwm->period_ns = period_ns;
9898

9999
len = snprintf(buffer, sizeof(buffer), "%lu", period_ns);
100-
write(pwm->period_fd, buffer, len);
100+
if (write(pwm->period_fd, buffer, len) < 0) {
101+
return -1;
102+
}
101103
}
102104

103105
return 1;
@@ -109,13 +111,14 @@ int pwm_set_polarity(const char *key, int polarity) {
109111
struct pwm_exp *pwm;
110112

111113
pwm = lookup_exported_pwm(key);
112-
113114
if (pwm == NULL) {
114115
return -1;
115116
}
116117

117118
len = snprintf(buffer, sizeof(buffer), "%d", polarity);
118-
write(pwm->polarity_fd, buffer, len);
119+
if (write(pwm->polarity_fd, buffer, len) < 0) {
120+
return -1;
121+
}
119122

120123
return 0;
121124
}
@@ -125,19 +128,21 @@ int pwm_set_duty_cycle(const char *key, float duty) {
125128
char buffer[20];
126129
struct pwm_exp *pwm;
127130

128-
if (duty < 0.0 || duty > 100.0)
131+
if (duty < 0.0 || duty > 100.0) {
129132
return -1;
133+
}
130134

131135
pwm = lookup_exported_pwm(key);
132-
133136
if (pwm == NULL) {
134137
return -1;
135138
}
136139

137140
pwm->duty = (unsigned long)(pwm->period_ns * (duty / 100.0));
138141

139142
len = snprintf(buffer, sizeof(buffer), "%lu", pwm->duty);
140-
write(pwm->duty_fd, buffer, len);
143+
if (write(pwm->duty_fd, buffer, len) < 0) {
144+
return -1;
145+
}
141146

142147
return 0;
143148
}
@@ -158,7 +163,6 @@ int pwm_start(const char *key, float duty, float freq, int polarity)
158163
}
159164

160165
snprintf(fragment, sizeof(fragment), "bone_pwm_%s", key);
161-
162166

163167
if (!load_device_tree(fragment)) {
164168
//error enabling pin for pwm
@@ -176,10 +180,10 @@ int pwm_start(const char *key, float duty, float freq, int polarity)
176180
snprintf(duty_path, sizeof(duty_path), "%s/duty", pwm_test_path);
177181
snprintf(polarity_path, sizeof(polarity_path), "%s/polarity", pwm_test_path);
178182

179-
//add period and duty fd to pwm list
180-
if ((period_fd = open(period_path, O_RDWR)) < 0)
183+
//add period and duty fd to pwm list
184+
if ((period_fd = open(period_path, O_RDWR)) < 0) {
181185
return -1;
182-
186+
}
183187

184188
if ((duty_fd = open(duty_path, O_RDWR)) < 0) {
185189
//error, close already opened period_fd.

source/common.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ SOFTWARE.
3737

3838
#include <linux/version.h>
3939
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
40-
#define BBBVERSION41
40+
# ifndef BBBVERSION41
41+
# define BBBVERSION41
42+
# endif
4143
#endif
4244

4345
int setup_error = 0;

source/event_gpio.c

Lines changed: 31 additions & 7 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

@@ -302,7 +319,10 @@ int gpio_get_value(unsigned int gpio, unsigned int *value)
302319
}
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: 5 additions & 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

@@ -870,7 +871,11 @@ initSPI(void)
870871
PyObject* m;
871872

872873
if (PyType_Ready(&SPI_type) < 0)
874+
#if PY_MAJOR_VERSION >= 3
875+
return NULL;
876+
#else
873877
return;
878+
#endif
874879

875880
#if PY_MAJOR_VERSION >= 3
876881
m = PyModule_Create(&moduledef);

0 commit comments

Comments
 (0)