diff options
Diffstat (limited to 'unix/socket.c')
-rw-r--r-- | unix/socket.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/unix/socket.c b/unix/socket.c index e48d8545f7..ae87ba4656 100644 --- a/unix/socket.c +++ b/unix/socket.c @@ -10,7 +10,7 @@ #include "nlr.h" #include "misc.h" #include "mpconfig.h" -#include "mpqstr.h" +#include "qstr.h" #include "obj.h" #include "objtuple.h" #include "objarray.h" @@ -136,13 +136,12 @@ static mp_obj_t socket_recv(uint n_args, const mp_obj_t *args) { flags = MP_OBJ_SMALL_INT_VALUE(args[2]); } - char *buf = m_new(char, sz + 1); + char *buf = m_new(char, sz); int out_sz = recv(self->fd, buf, sz, flags); RAISE_ERRNO(out_sz, errno); - buf = m_realloc(buf, sz + 1, out_sz + 1); - buf[out_sz] = 0; - return MP_OBJ_NEW_QSTR(qstr_from_str_take(buf, out_sz + 1)); + 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); @@ -159,7 +158,7 @@ static mp_obj_t socket_send(uint n_args, const mp_obj_t *args) { int out_sz = send(self->fd, buf, sz, flags); RAISE_ERRNO(out_sz, errno); - return MP_OBJ_NEW_SMALL_INT(out_sz); + 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); @@ -287,7 +286,7 @@ static mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { // "canonname will be a string representing the canonical name of the host // if AI_CANONNAME is part of the flags argument; else canonname will be empty." ?? if (addr->ai_canonname) { - t->items[3] = MP_OBJ_NEW_QSTR(qstr_from_strn_copy(addr->ai_canonname, strlen(addr->ai_canonname))); + t->items[3] = MP_OBJ_NEW_QSTR(qstr_from_str(addr->ai_canonname)); } else { t->items[3] = mp_const_none; } @@ -300,18 +299,18 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod extern mp_obj_type_t sockaddr_in_type; -#define STORE_INT_CONST(m, name) rt_store_attr(m, qstr_from_str_static(#name), MP_OBJ_NEW_SMALL_INT(name)) +#define STORE_INT_CONST(m, name) rt_store_attr(m, QSTR_FROM_STR_STATIC(#name), MP_OBJ_NEW_SMALL_INT(name)) void rawsocket_init() { - mp_obj_t m = mp_obj_new_module(qstr_from_str_static("rawsocket")); - rt_store_attr(m, qstr_from_str_static("socket"), (mp_obj_t)&rawsocket_type); + mp_obj_t m = mp_obj_new_module(MP_QSTR_rawsocket); + rt_store_attr(m, MP_QSTR_socket, (mp_obj_t)&rawsocket_type); #if MICROPY_SOCKET_EXTRA - rt_store_attr(m, qstr_from_str_static("sockaddr_in"), (mp_obj_t)&sockaddr_in_type); - rt_store_attr(m, qstr_from_str_static("htons"), (mp_obj_t)&mod_socket_htons_obj); - rt_store_attr(m, qstr_from_str_static("inet_aton"), (mp_obj_t)&mod_socket_inet_aton_obj); - rt_store_attr(m, qstr_from_str_static("gethostbyname"), (mp_obj_t)&mod_socket_gethostbyname_obj); + rt_store_attr(m, MP_QSTR_sockaddr_in, (mp_obj_t)&sockaddr_in_type); + rt_store_attr(m, MP_QSTR_htons, (mp_obj_t)&mod_socket_htons_obj); + rt_store_attr(m, MP_QSTR_inet_aton, (mp_obj_t)&mod_socket_inet_aton_obj); + rt_store_attr(m, MP_QSTR_gethostbyname, (mp_obj_t)&mod_socket_gethostbyname_obj); #endif - rt_store_attr(m, qstr_from_str_static("getaddrinfo"), (mp_obj_t)&mod_socket_getaddrinfo_obj); + rt_store_attr(m, MP_QSTR_getaddrinfo, (mp_obj_t)&mod_socket_getaddrinfo_obj); STORE_INT_CONST(m, AF_UNIX); STORE_INT_CONST(m, AF_INET); STORE_INT_CONST(m, AF_INET6); |