diff --git a/unix/file.c b/unix/file.c index 41eb39e025..f2e4556dd9 100644 --- a/unix/file.c +++ b/unix/file.c @@ -17,14 +17,14 @@ typedef struct _mp_obj_fdfile_t { int fd; } mp_obj_fdfile_t; -static const mp_obj_type_t rawfile_type; +STATIC const mp_obj_type_t rawfile_type; -static void fdfile_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { +STATIC void fdfile_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { mp_obj_fdfile_t *self = self_in; print(env, "", self->fd); } -static machine_int_t fdfile_read(mp_obj_t o_in, void *buf, machine_uint_t size, int *errcode) { +STATIC machine_int_t fdfile_read(mp_obj_t o_in, void *buf, machine_uint_t size, int *errcode) { mp_obj_fdfile_t *o = o_in; machine_int_t r = read(o->fd, buf, size); if (r == -1) { @@ -33,7 +33,7 @@ static machine_int_t fdfile_read(mp_obj_t o_in, void *buf, machine_uint_t size, return r; } -static machine_int_t fdfile_write(mp_obj_t o_in, const void *buf, machine_uint_t size, int *errcode) { +STATIC machine_int_t fdfile_write(mp_obj_t o_in, const void *buf, machine_uint_t size, int *errcode) { mp_obj_fdfile_t *o = o_in; machine_int_t r = write(o->fd, buf, size); if (r == -1) { @@ -42,32 +42,32 @@ static machine_int_t fdfile_write(mp_obj_t o_in, const void *buf, machine_uint_t return r; } -static mp_obj_t fdfile_close(mp_obj_t self_in) { +STATIC mp_obj_t fdfile_close(mp_obj_t self_in) { mp_obj_fdfile_t *self = self_in; close(self->fd); return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_1(fdfile_close_obj, fdfile_close); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(fdfile_close_obj, fdfile_close); mp_obj_t fdfile___exit__(uint n_args, const mp_obj_t *args) { return fdfile_close(args[0]); } -static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fdfile___exit___obj, 4, 4, fdfile___exit__); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fdfile___exit___obj, 4, 4, fdfile___exit__); -static mp_obj_t fdfile_fileno(mp_obj_t self_in) { +STATIC mp_obj_t fdfile_fileno(mp_obj_t self_in) { mp_obj_fdfile_t *self = self_in; return MP_OBJ_NEW_SMALL_INT((machine_int_t)self->fd); } -static MP_DEFINE_CONST_FUN_OBJ_1(fdfile_fileno_obj, fdfile_fileno); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(fdfile_fileno_obj, fdfile_fileno); -static mp_obj_fdfile_t *fdfile_new(int fd) { +STATIC mp_obj_fdfile_t *fdfile_new(int fd) { mp_obj_fdfile_t *o = m_new_obj(mp_obj_fdfile_t); o->base.type = &rawfile_type; o->fd = fd; return o; } -static mp_obj_t fdfile_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { +STATIC mp_obj_t fdfile_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { mp_obj_fdfile_t *o = m_new_obj(mp_obj_fdfile_t); o->base.type = type_in; @@ -123,7 +123,7 @@ STATIC const mp_map_elem_t rawfile_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table); -static const mp_obj_type_t rawfile_type = { +STATIC const mp_obj_type_t rawfile_type = { { &mp_type_type }, .name = MP_QSTR_io_dot_FileIO, .print = fdfile_print, diff --git a/unix/main.c b/unix/main.c index 911d908b1a..b4a1646c28 100644 --- a/unix/main.c +++ b/unix/main.c @@ -42,7 +42,7 @@ void microsocket_init(); void time_init(); void ffi_init(); -static void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, bool is_repl) { +STATIC void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, bool is_repl) { if (lex == NULL) { return; } @@ -94,7 +94,7 @@ static void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind } } -static char *strjoin(const char *s1, int sep_char, const char *s2) { +STATIC char *strjoin(const char *s1, int sep_char, const char *s2) { int l1 = strlen(s1); int l2 = strlen(s2); char *s = malloc(l1 + l2 + 2); @@ -108,7 +108,7 @@ static char *strjoin(const char *s1, int sep_char, const char *s2) { return s; } -static char *prompt(char *p) { +STATIC char *prompt(char *p) { #if MICROPY_USE_READLINE char *line = readline(p); if (line) { @@ -133,7 +133,7 @@ static char *prompt(char *p) { return line; } -static void do_repl(void) { +STATIC void do_repl(void) { for (;;) { char *line = prompt(">>> "); if (line == NULL) { @@ -159,12 +159,12 @@ static void do_repl(void) { } } -static void do_file(const char *file) { +STATIC void do_file(const char *file) { mp_lexer_t *lex = mp_lexer_new_from_file(file); execute_from_lexer(lex, MP_PARSE_FILE_INPUT, false); } -static void do_str(const char *str) { +STATIC void do_str(const char *str) { mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, str, strlen(str), false); execute_from_lexer(lex, MP_PARSE_SINGLE_INPUT, false); } @@ -174,33 +174,33 @@ typedef struct _test_obj_t { int value; } test_obj_t; -static void test_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { +STATIC void test_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { test_obj_t *self = self_in; print(env, "", self->value); } -static mp_obj_t test_get(mp_obj_t self_in) { +STATIC mp_obj_t test_get(mp_obj_t self_in) { test_obj_t *self = self_in; return mp_obj_new_int(self->value); } -static mp_obj_t test_set(mp_obj_t self_in, mp_obj_t arg) { +STATIC mp_obj_t test_set(mp_obj_t self_in, mp_obj_t arg) { test_obj_t *self = self_in; self->value = mp_obj_get_int(arg); return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_1(test_get_obj, test_get); -static MP_DEFINE_CONST_FUN_OBJ_2(test_set_obj, test_set); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(test_get_obj, test_get); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(test_set_obj, test_set); -static const mp_map_elem_t test_locals_dict_table[] = { +STATIC const mp_map_elem_t test_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_get), (mp_obj_t)&test_get_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_set), (mp_obj_t)&test_set_obj }, }; STATIC MP_DEFINE_CONST_DICT(test_locals_dict, test_locals_dict_table); -static const mp_obj_type_t test_type = { +STATIC const mp_obj_type_t test_type = { { &mp_type_type }, .name = MP_QSTR_Test, .print = test_print, @@ -249,7 +249,7 @@ mp_obj_t qstr_info(void) { #if MICROPY_ENABLE_GC // TODO: this doesn't belong here -static mp_obj_t pyb_gc(void) { +STATIC mp_obj_t pyb_gc(void) { gc_collect(); return mp_const_none; } diff --git a/unix/socket.c b/unix/socket.c index 915400e442..5f3fdaa62f 100644 --- a/unix/socket.c +++ b/unix/socket.c @@ -27,14 +27,14 @@ typedef struct _mp_obj_socket_t { int fd; } mp_obj_socket_t; -static const mp_obj_type_t microsocket_type; +STATIC const mp_obj_type_t microsocket_type; // Helper functions #define RAISE_ERRNO(err_flag, error_val) \ { if (err_flag == -1) \ { nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error_val)); } } -static void get_buffer(mp_obj_t obj, buffer_info_t *bufinfo) { +STATIC void get_buffer(mp_obj_t obj, buffer_info_t *bufinfo) { mp_obj_base_t *o = (mp_obj_base_t *)obj; if (o->type->buffer_p.get_buffer == NULL) { goto error; @@ -49,7 +49,7 @@ error: nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "Operation not supported")); } -static mp_obj_socket_t *socket_new(int fd) { +STATIC mp_obj_socket_t *socket_new(int fd) { mp_obj_socket_t *o = m_new_obj(mp_obj_socket_t); o->base.type = µsocket_type; o->fd = fd; @@ -57,12 +57,12 @@ static mp_obj_socket_t *socket_new(int fd) { } -static void socket_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { +STATIC void socket_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { mp_obj_socket_t *self = self_in; print(env, "<_socket %d>", self->fd); } -static machine_int_t socket_read(mp_obj_t o_in, void *buf, machine_uint_t size, int *errcode) { +STATIC machine_int_t socket_read(mp_obj_t o_in, void *buf, machine_uint_t size, int *errcode) { mp_obj_socket_t *o = o_in; machine_int_t r = read(o->fd, buf, size); if (r == -1) { @@ -71,7 +71,7 @@ static machine_int_t socket_read(mp_obj_t o_in, void *buf, machine_uint_t size, return r; } -static machine_int_t socket_write(mp_obj_t o_in, const void *buf, machine_uint_t size, int *errcode) { +STATIC machine_int_t socket_write(mp_obj_t o_in, const void *buf, machine_uint_t size, int *errcode) { mp_obj_socket_t *o = o_in; machine_int_t r = write(o->fd, buf, size); if (r == -1) { @@ -80,20 +80,20 @@ static machine_int_t socket_write(mp_obj_t o_in, const void *buf, machine_uint_t return r; } -static mp_obj_t socket_close(mp_obj_t self_in) { +STATIC mp_obj_t socket_close(mp_obj_t self_in) { mp_obj_socket_t *self = self_in; close(self->fd); return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close); -static mp_obj_t socket_fileno(mp_obj_t self_in) { +STATIC mp_obj_t socket_fileno(mp_obj_t self_in) { mp_obj_socket_t *self = self_in; return MP_OBJ_NEW_SMALL_INT((machine_int_t)self->fd); } -static MP_DEFINE_CONST_FUN_OBJ_1(socket_fileno_obj, socket_fileno); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_fileno_obj, socket_fileno); -static mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { +STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { mp_obj_socket_t *self = self_in; buffer_info_t bufinfo; get_buffer(addr_in, &bufinfo); @@ -101,9 +101,9 @@ static mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { RAISE_ERRNO(r, errno); return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); -static mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { +STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { mp_obj_socket_t *self = self_in; buffer_info_t bufinfo; get_buffer(addr_in, &bufinfo); @@ -111,17 +111,17 @@ static mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { RAISE_ERRNO(r, errno); return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); -static mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog_in) { +STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog_in) { mp_obj_socket_t *self = self_in; int r = listen(self->fd, MP_OBJ_SMALL_INT_VALUE(backlog_in)); RAISE_ERRNO(r, errno); return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen); -static mp_obj_t socket_accept(mp_obj_t self_in) { +STATIC mp_obj_t socket_accept(mp_obj_t self_in) { mp_obj_socket_t *self = self_in; struct sockaddr addr; socklen_t addr_len = sizeof(addr); @@ -134,9 +134,9 @@ static mp_obj_t socket_accept(mp_obj_t self_in) { return t; } -static MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); -static mp_obj_t socket_recv(uint n_args, const mp_obj_t *args) { +STATIC mp_obj_t socket_recv(uint n_args, const mp_obj_t *args) { mp_obj_socket_t *self = args[0]; int sz = MP_OBJ_SMALL_INT_VALUE(args[1]); int flags = 0; @@ -152,9 +152,9 @@ static mp_obj_t socket_recv(uint n_args, const mp_obj_t *args) { buf = m_realloc(buf, sz, out_sz); return MP_OBJ_NEW_QSTR(qstr_from_strn_take(buf, out_sz, out_sz)); } -static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_obj, 2, 3, socket_recv); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_obj, 2, 3, socket_recv); -static mp_obj_t socket_send(uint n_args, const mp_obj_t *args) { +STATIC mp_obj_t socket_send(uint n_args, const mp_obj_t *args) { mp_obj_socket_t *self = args[0]; int flags = 0; @@ -169,9 +169,9 @@ static mp_obj_t socket_send(uint n_args, const mp_obj_t *args) { return MP_OBJ_NEW_SMALL_INT((machine_int_t)out_sz); } -static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_send_obj, 2, 3, socket_send); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_send_obj, 2, 3, socket_send); -static mp_obj_t socket_setsockopt(uint n_args, const mp_obj_t *args) { +STATIC mp_obj_t socket_setsockopt(uint n_args, const mp_obj_t *args) { mp_obj_socket_t *self = args[0]; int level = MP_OBJ_SMALL_INT_VALUE(args[1]); int option = mp_obj_get_int(args[2]); @@ -192,9 +192,9 @@ static mp_obj_t socket_setsockopt(uint n_args, const mp_obj_t *args) { RAISE_ERRNO(r, errno); return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); -static mp_obj_t socket_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { +STATIC mp_obj_t socket_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { int family = AF_INET; int type = SOCK_STREAM; int proto = 0; @@ -217,7 +217,7 @@ static mp_obj_t socket_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const return socket_new(fd); } -static const mp_map_elem_t microsocket_locals_dict_table[] = { +STATIC const mp_map_elem_t microsocket_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_fileno), (mp_obj_t)&socket_fileno_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_makefile), (mp_obj_t)&mp_identity_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj }, @@ -240,7 +240,7 @@ static const mp_map_elem_t microsocket_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(microsocket_locals_dict, microsocket_locals_dict_table); -static const mp_obj_type_t microsocket_type = { +STATIC const mp_obj_type_t microsocket_type = { { &mp_type_type }, .name = MP_QSTR_socket, .print = socket_print, @@ -254,12 +254,12 @@ static const mp_obj_type_t microsocket_type = { .locals_dict = (mp_obj_t)µsocket_locals_dict, }; -static mp_obj_t mod_socket_htons(mp_obj_t arg) { +STATIC mp_obj_t mod_socket_htons(mp_obj_t arg) { return MP_OBJ_NEW_SMALL_INT((machine_int_t)htons(MP_OBJ_SMALL_INT_VALUE(arg))); } -static MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_htons_obj, mod_socket_htons); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_htons_obj, mod_socket_htons); -static mp_obj_t mod_socket_inet_aton(mp_obj_t arg) { +STATIC mp_obj_t mod_socket_inet_aton(mp_obj_t arg) { assert(MP_OBJ_IS_TYPE(arg, &mp_type_str)); const char *s = mp_obj_str_get_str(arg); struct in_addr addr; @@ -269,10 +269,10 @@ static mp_obj_t mod_socket_inet_aton(mp_obj_t arg) { return mp_obj_new_int(addr.s_addr); } -static MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_inet_aton_obj, mod_socket_inet_aton); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_inet_aton_obj, mod_socket_inet_aton); #if MICROPY_SOCKET_EXTRA -static mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) { +STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) { assert(MP_OBJ_IS_TYPE(arg, &mp_type_str)); const char *s = mp_obj_str_get_str(arg); struct hostent *h = gethostbyname(s); @@ -282,10 +282,10 @@ static mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) { assert(h->h_length == 4); return mp_obj_new_int(*(int*)*h->h_addr_list); } -static MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_gethostbyname_obj, mod_socket_gethostbyname); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_gethostbyname_obj, mod_socket_gethostbyname); #endif -static mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { +STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { // TODO: Implement all args assert(n_args == 2); assert(MP_OBJ_IS_STR(args[0])); @@ -331,13 +331,13 @@ static mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { } return list; } -static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod_socket_getaddrinfo); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod_socket_getaddrinfo); extern mp_obj_type_t sockaddr_in_type; #define C(name) { #name, name } -static const struct sym_entry { +STATIC const struct sym_entry { const char *sym; int val; } constants[] = { diff --git a/unix/time.c b/unix/time.c index fb52133580..032528947c 100644 --- a/unix/time.c +++ b/unix/time.c @@ -10,13 +10,13 @@ #include "obj.h" #include "runtime.h" -static mp_obj_t mod_time_time() { +STATIC mp_obj_t mod_time_time() { return mp_obj_new_int((machine_int_t)time(NULL)); } -static MP_DEFINE_CONST_FUN_OBJ_0(mod_time_time_obj, mod_time_time); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_time_obj, mod_time_time); // Note: this is deprecated since CPy3.3, but pystone still uses it. -static mp_obj_t mod_time_clock() { +STATIC mp_obj_t mod_time_clock() { // return mp_obj_new_int((machine_int_t)clock()); // POSIX requires CLOCKS_PER_SEC equals 1000000, so that's what we assume // float cannot represent full range of int32 precisely, so we pre-divide @@ -24,9 +24,9 @@ static mp_obj_t mod_time_clock() { // to preserve integer part resolution. return mp_obj_new_float((float)(clock() / 1000) / 1000.0); } -static MP_DEFINE_CONST_FUN_OBJ_0(mod_time_clock_obj, mod_time_clock); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_clock_obj, mod_time_clock); -static mp_obj_t mod_time_sleep(mp_obj_t arg) { +STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) { #if MICROPY_ENABLE_FLOAT struct timeval tv; mp_float_t val = mp_obj_get_float(arg); @@ -39,7 +39,7 @@ static mp_obj_t mod_time_sleep(mp_obj_t arg) { #endif return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_obj, mod_time_sleep); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_obj, mod_time_sleep); void time_init() { mp_obj_t m = mp_obj_new_module(QSTR_FROM_STR_STATIC("time"));