From f6932d650620d3753b5a18df5131227276260f74 Mon Sep 17 00:00:00 2001 From: Emmanuel Blot Date: Thu, 19 Jun 2014 18:54:34 +0200 Subject: Prefix ARRAY_SIZE with micropython prefix MP_ --- unix/modsocket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'unix/modsocket.c') diff --git a/unix/modsocket.c b/unix/modsocket.c index b1a34a39b8..8c5c9706c6 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -436,8 +436,8 @@ STATIC const mp_obj_dict_t mp_module_socket_globals = { .map = { .all_keys_are_qstrs = 1, .table_is_fixed_array = 1, - .used = ARRAY_SIZE(mp_module_socket_globals_table), - .alloc = ARRAY_SIZE(mp_module_socket_globals_table), + .used = MP_ARRAY_SIZE(mp_module_socket_globals_table), + .alloc = MP_ARRAY_SIZE(mp_module_socket_globals_table), .table = (mp_map_elem_t*)mp_module_socket_globals_table, }, }; -- cgit v1.2.3 From 949a49c9da9f8adb64bdddbd8f0258eaa881df2f Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 22 Jun 2014 19:11:34 +0300 Subject: modsocket: Add call to freeaddrinfo(). --- unix/modsocket.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'unix/modsocket.c') diff --git a/unix/modsocket.c b/unix/modsocket.c index 8c5c9706c6..457dc81671 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -368,18 +368,18 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { } struct addrinfo hints; - struct addrinfo *addr; + struct addrinfo *addr_list; memset(&hints, 0, sizeof(hints)); - int res = getaddrinfo(host, serv, NULL/*&hints*/, &addr); + int res = getaddrinfo(host, serv, NULL/*&hints*/, &addr_list); if (res != 0) { // CPython: socket.gaierror nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[addrinfo error %d]", res)); } - assert(addr); + assert(addr_list); mp_obj_t list = mp_obj_new_list(0, NULL); - for (; addr; addr = addr->ai_next) { + for (struct addrinfo *addr = addr_list; addr; addr = addr->ai_next) { mp_obj_tuple_t *t = mp_obj_new_tuple(5, NULL); t->items[0] = MP_OBJ_NEW_SMALL_INT((machine_int_t)addr->ai_family); t->items[1] = MP_OBJ_NEW_SMALL_INT((machine_int_t)addr->ai_socktype); @@ -394,6 +394,7 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { t->items[4] = mp_obj_new_bytearray(addr->ai_addrlen, addr->ai_addr); mp_obj_list_append(list, t); } + freeaddrinfo(addr_list); return list; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod_socket_getaddrinfo); -- cgit v1.2.3 From ff5932a8d8d61351b2a9593ab407cc29c094109d Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 22 Jun 2014 19:14:12 +0300 Subject: modsocket: Workaround uClibc issue with numeric port for getaddrinfo(). It sucks to workaround this on uPy side, but upgrading not upgradable embedded systems sucks even more. --- unix/modsocket.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'unix/modsocket.c') diff --git a/unix/modsocket.c b/unix/modsocket.c index 457dc81671..5dce46b2e9 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -356,6 +356,8 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { const char *host = mp_obj_str_get_str(args[0]); const char *serv = NULL; + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); // getaddrinfo accepts port in string notation, so however // it may seem stupid, we need to convert int to str if (MP_OBJ_IS_SMALL_INT(args[1])) { @@ -363,14 +365,24 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { char buf[6]; sprintf(buf, "%d", port); serv = buf; + hints.ai_flags = AI_NUMERICSERV; +#if __UCLIBC_MAJOR__ == 0 && (__UCLIBC_MINOR__ < 9 || (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ <= 32)) +#warning Working around uClibc bug with numeric service name + // Older versions og uClibc have bugs when numeric ports in service + // arg require also hints.ai_socktype (or hints.ai_protocol) != 0 + // This actually was fixed in 0.9.32.1, but uClibc doesn't allow to + // test for that. + // http://git.uclibc.org/uClibc/commit/libc/inet/getaddrinfo.c?id=bc3be18145e4d5 + // Note that this is crude workaround, precluding UDP socket addresses + // to be returned. TODO: set only if not set by Python args. + hints.ai_socktype = SOCK_STREAM; +#endif } else { serv = mp_obj_str_get_str(args[1]); } - struct addrinfo hints; struct addrinfo *addr_list; - memset(&hints, 0, sizeof(hints)); - int res = getaddrinfo(host, serv, NULL/*&hints*/, &addr_list); + int res = getaddrinfo(host, serv, &hints, &addr_list); if (res != 0) { // CPython: socket.gaierror -- cgit v1.2.3 From 3c9b24bebeb573d10c1187fcf40ec1e1bb1bd7f2 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 24 Jun 2014 21:20:38 +0300 Subject: modsocket: Fix uClibc detection. --- unix/modsocket.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'unix/modsocket.c') diff --git a/unix/modsocket.c b/unix/modsocket.c index 5dce46b2e9..5b3fb01877 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -366,6 +366,7 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { sprintf(buf, "%d", port); serv = buf; hints.ai_flags = AI_NUMERICSERV; +#ifdef __UCLIBC_MAJOR__ #if __UCLIBC_MAJOR__ == 0 && (__UCLIBC_MINOR__ < 9 || (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ <= 32)) #warning Working around uClibc bug with numeric service name // Older versions og uClibc have bugs when numeric ports in service @@ -376,6 +377,7 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { // Note that this is crude workaround, precluding UDP socket addresses // to be returned. TODO: set only if not set by Python args. hints.ai_socktype = SOCK_STREAM; +#endif #endif } else { serv = mp_obj_str_get_str(args[1]); -- cgit v1.2.3