Skip to content

Commit 0fd0168

Browse files
committed
Merge pull request adafruit#607 from Anton-2/osx-clang
Allow compilation of unix port under clang on OS X
2 parents 6ac5dce + da1fffa commit 0fd0168

10 files changed

Lines changed: 74 additions & 6 deletions

File tree

py/modmath.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ STATIC const mp_map_elem_t mp_module_math_globals_table[] = {
151151
{ MP_OBJ_NEW_QSTR(MP_QSTR_copysign), (mp_obj_t)&mp_math_copysign_obj },
152152
{ MP_OBJ_NEW_QSTR(MP_QSTR_fabs), (mp_obj_t)&mp_math_fabs_obj },
153153
{ MP_OBJ_NEW_QSTR(MP_QSTR_floor), (mp_obj_t)&mp_math_floor_obj },
154+
{ MP_OBJ_NEW_QSTR(MP_QSTR_fmod), (mp_obj_t)&mp_math_fmod_obj },
154155
{ MP_OBJ_NEW_QSTR(MP_QSTR_frexp), (mp_obj_t)&mp_math_frexp_obj },
155156
{ MP_OBJ_NEW_QSTR(MP_QSTR_ldexp), (mp_obj_t)&mp_math_ldexp_obj },
156157
{ MP_OBJ_NEW_QSTR(MP_QSTR_modf), (mp_obj_t)&mp_math_modf_obj },

py/nlrx64.S

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232

3333
#if !defined(__CYGWIN__)
3434

35+
#if (defined(__APPLE__) && defined(__MACH__))
36+
#define nlr_jump_fail _nlr_jump_fail
37+
#endif // (defined(__APPLE__) && defined(__MACH__))
38+
3539
/* uint nlr_push(rdi=nlr_buf_t *nlr) */
3640
#if !(defined(__APPLE__) && defined(__MACH__))
3741
.globl nlr_push

py/objexcept.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,13 @@ MP_DEFINE_EXCEPTION(Exception, BaseException)
183183
MP_DEFINE_EXCEPTION(KeyError, LookupError)
184184
MP_DEFINE_EXCEPTION(MemoryError, Exception)
185185
MP_DEFINE_EXCEPTION(NameError, Exception)
186+
/*
186187
MP_DEFINE_EXCEPTION_BASE(NameError)
187-
//MP_DEFINE_EXCEPTION(UnboundLocalError, NameError)
188+
MP_DEFINE_EXCEPTION(UnboundLocalError, NameError)
189+
*/
188190
MP_DEFINE_EXCEPTION(OSError, Exception)
189-
MP_DEFINE_EXCEPTION_BASE(OSError)
190191
/*
192+
MP_DEFINE_EXCEPTION_BASE(OSError)
191193
MP_DEFINE_EXCEPTION(BlockingIOError, OSError)
192194
MP_DEFINE_EXCEPTION(ChildProcessError, OSError)
193195
MP_DEFINE_EXCEPTION(ConnectionError, OSError)

py/vmentrytable.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#if __clang__
28+
#pragma clang diagnostic push
29+
#pragma clang diagnostic ignored "-Winitializer-overrides"
30+
#endif // __clang__
31+
2732
static void* entry_table[256] = {
2833
[0 ... 255] = &&entry_default,
2934
[MP_BC_LOAD_CONST_FALSE] = &&entry_MP_BC_LOAD_CONST_FALSE,
@@ -110,3 +115,7 @@ static void* entry_table[256] = {
110115
[MP_BC_IMPORT_FROM] = &&entry_MP_BC_IMPORT_FROM,
111116
[MP_BC_IMPORT_STAR] = &&entry_MP_BC_IMPORT_STAR,
112117
};
118+
119+
#if __clang__
120+
#pragma clang diagnostic pop
121+
#endif // __clang__

tests/basics/memoryerror.py.exp

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

unix/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT)
1919

2020
UNAME_S := $(shell uname -s)
2121
ifeq ($(UNAME_S),Darwin)
22-
LDFLAGS = $(LDFLAGS_MOD) -lm -Wl,-map,$@.map
23-
else
22+
LDFLAGS = $(LDFLAGS_MOD) -lm -Wl,-map,$@.map,-order_file,order.def
23+
else
2424
LDFLAGS = $(LDFLAGS_MOD) -lm -Wl,-Map=$@.map,--cref
2525
endif
2626

@@ -71,6 +71,11 @@ SRC_C = \
7171
modos.c \
7272
$(SRC_MOD)
7373

74+
# Must be the last file
75+
ifeq ($(UNAME_S),Darwin)
76+
SRC_C += seg_helpers.c
77+
endif
78+
7479
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
7580

7681
include ../py/mkrules.mk

unix/gccollect.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,17 @@ typedef machine_uint_t regs_t[6];
4343

4444
void gc_helper_get_regs(regs_t arr) {
4545
register long rbx asm ("rbx");
46+
asm("" : "=r"(rbx));
4647
register long rbp asm ("rbp");
48+
asm("" : "=r"(rbp));
4749
register long r12 asm ("r12");
50+
asm("" : "=r"(r12));
4851
register long r13 asm ("r13");
52+
asm("" : "=r"(r13));
4953
register long r14 asm ("r14");
54+
asm("" : "=r"(r14));
5055
register long r15 asm ("r15");
56+
asm("" : "=r"(r15));
5157
arr[0] = rbx;
5258
arr[1] = rbp;
5359
arr[2] = r12;

unix/modsocket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ STATIC const mp_obj_type_t microsocket_type = {
292292
.locals_dict = (mp_obj_t)&microsocket_locals_dict,
293293
};
294294

295+
#if MICROPY_SOCKET_EXTRA
295296
STATIC mp_obj_t mod_socket_htons(mp_obj_t arg) {
296297
return MP_OBJ_NEW_SMALL_INT((machine_int_t)htons(MP_OBJ_SMALL_INT_VALUE(arg)));
297298
}
@@ -309,7 +310,6 @@ STATIC mp_obj_t mod_socket_inet_aton(mp_obj_t arg) {
309310
}
310311
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_inet_aton_obj, mod_socket_inet_aton);
311312

312-
#if MICROPY_SOCKET_EXTRA
313313
STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) {
314314
assert(MP_OBJ_IS_TYPE(arg, &mp_type_str));
315315
const char *s = mp_obj_str_get_str(arg);
@@ -322,7 +322,7 @@ STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) {
322322
return mp_obj_new_int(*(int*)*h->h_addr_list);
323323
}
324324
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_gethostbyname_obj, mod_socket_gethostbyname);
325-
#endif
325+
#endif // MICROPY_SOCKET_EXTRA
326326

327327
STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) {
328328
// TODO: Implement all args

unix/order.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
seg_helpers.o: ___bss_start

unix/seg_helpers.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013, 2014 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
/*
28+
This is a stub used to create the symbols __bss_start and _end in a Mach-O object file.
29+
Thoses are needed by the GC, and should point to the start and end of the bss section.
30+
We reach this goal by linking this file last (putting _end at the end...), and using an
31+
order file (order.def) to move __bss_start at the start of bss.
32+
33+
TODO: Some pragma to do it inline ?
34+
*/
35+
36+
char __bss_start = 0;
37+
char _end = 0;
38+

0 commit comments

Comments
 (0)