Skip to content

Commit 17598d4

Browse files
committed
unix: Don't use -Wno-error=cpp or #warning; fix strict alias warning.
For the sake of older versions of gcc (and other compilers), don't use the #warning CPP directive, nor the -Wno-error=cpp option. Also, fix a strict alias warning in modffi.c for older compilers, and add a test for ffi module. Addresses issue adafruit#847.
1 parent 8002d5d commit 17598d4

File tree

6 files changed

+29
-5
lines changed

6 files changed

+29
-5
lines changed

tests/run-tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def main():
149149
if args.test_dirs is None:
150150
if pyb is None:
151151
# run PC tests
152-
test_dirs = ('basics', 'micropython', 'float', 'import', 'io', 'misc', 'unicode')
152+
test_dirs = ('basics', 'micropython', 'float', 'import', 'io', 'misc', 'unicode', 'unix')
153153
else:
154154
# run pyboard tests
155155
test_dirs = ('basics', 'micropython', 'float', 'pyb', 'pybnative', 'inlineasm')

tests/unix/ffi_float.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# test ffi float support
2+
3+
import ffi
4+
5+
def ffi_open(names):
6+
err = None
7+
for n in names:
8+
try:
9+
mod = ffi.open(n)
10+
return mod
11+
except OSError as e:
12+
err = e
13+
raise err
14+
15+
libc = ffi_open(('libc.so', 'libc.so.0', 'libc.so.6'))
16+
17+
strtof = libc.func("f", "strtof", "sp")
18+
print('%.6f' % strtof('1.23', None))
19+
20+
strtod = libc.func("d", "strtod", "sp")
21+
print('%.6f' % strtod('1.23', None))

tests/unix/ffi_float.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1.230000
2+
1.230000

unix/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ INC += -I$(PY_SRC)
1818
INC += -I$(BUILD)
1919

2020
# compiler settings
21-
CWARN = -Wall -Werror -Wno-error=cpp
21+
CWARN = -Wall -Werror
2222
CFLAGS = $(INC) $(CWARN) -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
2323

2424
# Debugging/Optimization

unix/modffi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ STATIC mp_obj_t return_ffi_value(ffi_arg val, char type)
146146
case 'v':
147147
return mp_const_none;
148148
case 'f': {
149-
float *p = (float*)&val;
150-
return mp_obj_new_float(*p);
149+
union { ffi_arg ffi; float flt; } val_union = { .ffi = val };
150+
return mp_obj_new_float(val_union.flt);
151151
}
152152
case 'd': {
153153
double *p = (double*)&val;

unix/modsocket.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ STATIC mp_obj_t mod_socket_getaddrinfo(mp_uint_t n_args, const mp_obj_t *args) {
371371
hints.ai_flags = AI_NUMERICSERV;
372372
#ifdef __UCLIBC_MAJOR__
373373
#if __UCLIBC_MAJOR__ == 0 && (__UCLIBC_MINOR__ < 9 || (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ <= 32))
374-
#warning Working around uClibc bug with numeric service name
374+
// "warning" requires -Wno-cpp which is a relatively new gcc option, so we choose not to use it.
375+
//#warning Working around uClibc bug with numeric service name
375376
// Older versions og uClibc have bugs when numeric ports in service
376377
// arg require also hints.ai_socktype (or hints.ai_protocol) != 0
377378
// This actually was fixed in 0.9.32.1, but uClibc doesn't allow to

0 commit comments

Comments
 (0)