Skip to content

Commit f0ee018

Browse files
authored
Merge pull request #131 from adafruit/fix-gcc-warnings
Fix gcc warnings
2 parents e105c8f + 6d78f9d commit f0ee018

File tree

10 files changed

+55
-52
lines changed

10 files changed

+55
-52
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
else:
1919
kernel41 = None
2020

21-
CFLAGS = ['-Wall', '-Werror', '-Wno-format-security']
21+
CFLAGS = ['-Wall', '-Werror', '-Wextra', '-Wno-missing-field-initializers' ]
2222

2323
classifiers = ['Development Status :: 3 - Alpha',
2424
'Operating System :: POSIX :: Linux',

source/c_pwm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ BBIO_err pwm_set_duty_cycle(const char *key, float duty) {
272272
return BBIO_OK;
273273
}
274274

275-
BBIO_err pwm_setup(const char *key, float duty, float freq, int polarity)
275+
BBIO_err pwm_setup(const char *key, __attribute__ ((unused)) float duty, __attribute__ ((unused)) float freq, __attribute__ ((unused)) int polarity)
276276
{
277277
BBIO_err err;
278278
struct pwm_exp *new_pwm;
@@ -489,7 +489,7 @@ BBIO_err pwm_start(const char *key, float duty, float freq, int polarity)
489489
{
490490
BBIO_err err;
491491
char buffer[20];
492-
int len;
492+
ssize_t len;
493493

494494
struct pwm_exp *pwm = lookup_exported_pwm(key);
495495
if (pwm == NULL) {
@@ -518,7 +518,7 @@ BBIO_err pwm_start(const char *key, float duty, float freq, int polarity)
518518
len = read(pwm->period_fd, buffer, sizeof(buffer));
519519
if (len < 0) {
520520
return BBIO_SYSFS;
521-
} else if (len >= sizeof(buffer)) {
521+
} else if (len >= (ssize_t)sizeof(buffer)) {
522522
// If this is the case, there's more in the file.
523523
// This should never happen, as it would mean that
524524
// the period is 10^8 seconds
@@ -534,7 +534,7 @@ BBIO_err pwm_start(const char *key, float duty, float freq, int polarity)
534534
len = read(pwm->duty_fd, buffer, sizeof(buffer));
535535
if (len < 0) {
536536
return BBIO_SYSFS;
537-
} else if (len >= sizeof(buffer)) {
537+
} else if (len >= (ssize_t)sizeof(buffer)) {
538538
// If this is the case, there's more in the file.
539539
// This should never happen, as it would mean that
540540
// the period is 10^8 seconds

source/common.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ BBIO_err get_pwm_key(const char *input, char *key)
337337
return BBIO_INVARG;
338338
}
339339

340-
BBIO_err get_adc_ain(const char *key, unsigned int *ain)
340+
// TODO: fix warning
341+
// source/common.c:344:14: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
342+
BBIO_err get_adc_ain(const char *key, int *ain)
341343
{
342344
*ain = lookup_ain_by_key(key);
343345

@@ -451,7 +453,7 @@ BBIO_err load_device_tree(const char *name)
451453
}
452454

453455
//if the device isn't already loaded, load it, and return
454-
fprintf(file, name);
456+
fprintf(file, "%s", name);
455457
fclose(file);
456458

457459
//0.2 second delay

source/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int gpio_direction[120];
7979

8080
BBIO_err get_gpio_number(const char *key, unsigned int *gpio);
8181
BBIO_err get_pwm_key(const char *input, char *key);
82-
BBIO_err get_adc_ain(const char *key, unsigned int *ain);
82+
BBIO_err get_adc_ain(const char *key, int *ain);
8383
BBIO_err get_uart_device_tree_name(const char *name, char *dt);
8484
BBIO_err build_path(const char *partial_path, const char *prefix, char *full_path, size_t full_path_len);
8585
int get_spi_bus_path_number(unsigned int spi);

source/event_gpio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ int gpio_initial(unsigned int gpio)
471471
return 0;
472472
}
473473

474-
void *poll_thread(void *threadarg)
474+
void *poll_thread(__attribute__ ((unused)) void *threadarg)
475475
{
476476
struct epoll_event events;
477477
char buf;

source/py_adc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ SOFTWARE.
3939
//}
4040

4141
// python function setup()
42-
static PyObject *py_setup_adc(PyObject *self, PyObject *args)
42+
static PyObject *py_setup_adc(__attribute__ ((unused)) PyObject *self, __attribute__ ((unused)) PyObject *args)
4343
{
4444
BBIO_err err;
4545

@@ -55,9 +55,9 @@ static PyObject *py_setup_adc(PyObject *self, PyObject *args)
5555
}
5656

5757
// python function read(channel)
58-
static PyObject *py_read(PyObject *self, PyObject *args)
58+
static PyObject *py_read(__attribute__ ((unused)) PyObject *self, PyObject *args)
5959
{
60-
unsigned int ain;
60+
int ain;
6161
float value;
6262
char *channel;
6363
PyObject *py_value;
@@ -98,9 +98,9 @@ static PyObject *py_read(PyObject *self, PyObject *args)
9898
}
9999

100100
// python function read(channel)
101-
static PyObject *py_read_raw(PyObject *self, PyObject *args)
101+
static PyObject *py_read_raw(__attribute__ ((unused)) PyObject *self, PyObject *args)
102102
{
103-
unsigned int ain;
103+
int ain;
104104
float value;
105105
char *channel;
106106
PyObject *py_value;

source/py_gpio.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static int init_module(void)
6161
}
6262

6363
// python function cleanup()
64-
static PyObject *py_cleanup(PyObject *self, PyObject *args)
64+
static PyObject *py_cleanup(__attribute__ ((unused)) PyObject *self, __attribute__ ((unused)) PyObject *args)
6565
{
6666
// clean up any exports
6767
event_cleanup();
@@ -70,7 +70,7 @@ static PyObject *py_cleanup(PyObject *self, PyObject *args)
7070
}
7171

7272
// python function setup(channel, direction, pull_up_down=PUD_OFF, initial=None, delay=0)
73-
static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwargs)
73+
static PyObject *py_setup_channel(__attribute__ ((unused)) PyObject *self, PyObject *args, PyObject *kwargs)
7474
{
7575
unsigned int gpio;
7676
char *channel;
@@ -151,7 +151,7 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
151151
}
152152

153153
// python function output(channel, value)
154-
static PyObject *py_output_gpio(PyObject *self, PyObject *args)
154+
static PyObject *py_output_gpio(__attribute__ ((unused)) PyObject *self, PyObject *args)
155155
{
156156
unsigned int gpio;
157157
int value;
@@ -177,7 +177,7 @@ static PyObject *py_output_gpio(PyObject *self, PyObject *args)
177177
}
178178

179179
// python function value = input(channel)
180-
static PyObject *py_input_gpio(PyObject *self, PyObject *args)
180+
static PyObject *py_input_gpio(__attribute__ ((unused)) PyObject *self, PyObject *args)
181181
{
182182
unsigned int gpio;
183183
char *channel;
@@ -276,7 +276,7 @@ static int add_py_callback(char *channel, unsigned int gpio, unsigned int bounce
276276
}
277277

278278
// python function add_event_callback(gpio, callback, bouncetime=0)
279-
static PyObject *py_add_event_callback(PyObject *self, PyObject *args, PyObject *kwargs)
279+
static PyObject *py_add_event_callback(__attribute__ ((unused)) PyObject *self, PyObject *args, PyObject *kwargs)
280280
{
281281
unsigned int gpio;
282282
char *channel;
@@ -318,7 +318,7 @@ static PyObject *py_add_event_callback(PyObject *self, PyObject *args, PyObject
318318
}
319319

320320
// python function add_event_detect(gpio, edge, callback=None, bouncetime=0
321-
static PyObject *py_add_event_detect(PyObject *self, PyObject *args, PyObject *kwargs)
321+
static PyObject *py_add_event_detect(__attribute__ ((unused)) PyObject *self, PyObject *args, PyObject *kwargs)
322322
{
323323
unsigned int gpio;
324324
char *channel;
@@ -375,7 +375,7 @@ static PyObject *py_add_event_detect(PyObject *self, PyObject *args, PyObject *k
375375
}
376376

377377
// python function remove_event_detect(gpio)
378-
static PyObject *py_remove_event_detect(PyObject *self, PyObject *args)
378+
static PyObject *py_remove_event_detect(__attribute__ ((unused)) PyObject *self, PyObject *args)
379379
{
380380
unsigned int gpio;
381381
char *channel;
@@ -416,7 +416,7 @@ static PyObject *py_remove_event_detect(PyObject *self, PyObject *args)
416416
}
417417

418418
// python function value = event_detected(channel)
419-
static PyObject *py_event_detected(PyObject *self, PyObject *args)
419+
static PyObject *py_event_detected(__attribute__ ((unused)) PyObject *self, PyObject *args)
420420
{
421421
unsigned int gpio;
422422
char *channel;
@@ -436,7 +436,7 @@ static PyObject *py_event_detected(PyObject *self, PyObject *args)
436436
}
437437

438438
// python function py_wait_for_edge(gpio, edge, timeout = -1)
439-
static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
439+
static PyObject *py_wait_for_edge(__attribute__ ((unused)) PyObject *self, PyObject *args)
440440
{
441441
unsigned int gpio;
442442
int edge, result, timeout;
@@ -490,7 +490,7 @@ static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
490490
}
491491

492492
// python function value = gpio_function(gpio)
493-
static PyObject *py_gpio_function(PyObject *self, PyObject *args)
493+
static PyObject *py_gpio_function(__attribute__ ((unused)) PyObject *self, PyObject *args)
494494
{
495495
unsigned int gpio;
496496
unsigned int value;
@@ -517,7 +517,7 @@ static PyObject *py_gpio_function(PyObject *self, PyObject *args)
517517
}
518518

519519
// python function setwarnings(state)
520-
static PyObject *py_setwarnings(PyObject *self, PyObject *args)
520+
static PyObject *py_setwarnings(__attribute__ ((unused)) PyObject *self, __attribute__ ((unused)) PyObject *args)
521521
{
522522
if (!PyArg_ParseTuple(args, "i", &gpio_warnings))
523523
return NULL;

source/py_pwm.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ SOFTWARE.
2727
#include "c_pwm.h"
2828

2929
// python function cleanup()
30-
static PyObject *py_cleanup(PyObject *self, PyObject *args)
30+
static PyObject *py_cleanup(__attribute__ ((unused)) PyObject *self, __attribute__ ((unused)) PyObject *args)
3131
{
3232
// unexport the PWM
3333
pwm_cleanup();
@@ -36,7 +36,7 @@ static PyObject *py_cleanup(PyObject *self, PyObject *args)
3636
}
3737

3838
// python function start(channel, duty_cycle, freq)
39-
static PyObject *py_start_channel(PyObject *self, PyObject *args, PyObject *kwargs)
39+
static PyObject *py_start_channel(__attribute__ ((unused)) PyObject *self, PyObject *args, PyObject *kwargs)
4040
{
4141
char key[8];
4242
char *channel;
@@ -106,7 +106,7 @@ static PyObject *py_start_channel(PyObject *self, PyObject *args, PyObject *kwar
106106
}
107107

108108
// python function stop(channel)
109-
static PyObject *py_stop_channel(PyObject *self, PyObject *args, PyObject *kwargs)
109+
static PyObject *py_stop_channel(__attribute__ ((unused)) PyObject *self, PyObject *args, __attribute__ ((unused)) PyObject *kwargs)
110110
{
111111
char key[8];
112112
char *channel;
@@ -138,7 +138,7 @@ static PyObject *py_stop_channel(PyObject *self, PyObject *args, PyObject *kwarg
138138
}
139139

140140
// python method PWM.set_duty_cycle(channel, duty_cycle)
141-
static PyObject *py_set_duty_cycle(PyObject *self, PyObject *args, PyObject *kwargs)
141+
static PyObject *py_set_duty_cycle(__attribute__ ((unused)) PyObject *self, PyObject *args, PyObject *kwargs)
142142
{
143143
char key[8];
144144
char *channel;
@@ -172,7 +172,7 @@ static PyObject *py_set_duty_cycle(PyObject *self, PyObject *args, PyObject *kwa
172172
}
173173

174174
// python method PWM.set_frequency(channel, frequency)
175-
static PyObject *py_set_frequency(PyObject *self, PyObject *args, PyObject *kwargs)
175+
static PyObject *py_set_frequency(__attribute__ ((unused)) PyObject *self, PyObject *args, PyObject *kwargs)
176176
{
177177
char key[8];
178178
char *channel;
@@ -257,4 +257,4 @@ PyMODINIT_FUNC initPWM(void)
257257
#else
258258
return;
259259
#endif
260-
}
260+
}

source/py_uart.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ SOFTWARE.
2929
const char *valid_uarts[4] = {"UART1", "UART2", "UART4", "UART5"};
3030

3131
// python function cleanup()
32-
static PyObject *py_cleanup(PyObject *self, PyObject *args)
32+
static PyObject *py_cleanup(__attribute__ ((unused)) PyObject *self, __attribute__ ((unused)) PyObject *args)
3333
{
3434
// unexport the UART
3535
uart_cleanup();
@@ -38,7 +38,7 @@ static PyObject *py_cleanup(PyObject *self, PyObject *args)
3838
}
3939

4040
// python function setup()
41-
static PyObject *py_setup_uart(PyObject *self, PyObject *args)
41+
static PyObject *py_setup_uart(__attribute__ ((unused)) PyObject *self, PyObject *args)
4242
{
4343
char dt[FILENAME_BUFFER_SIZE];
4444
char *channel;
@@ -107,4 +107,4 @@ PyMODINIT_FUNC initUART(void)
107107
#else
108108
return;
109109
#endif
110-
}
110+
}

0 commit comments

Comments
 (0)