Commit db0b282d authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

unix socket: Store module constants in data structure.

-147 bytes on x86.
parent 8fcf7b85
......@@ -299,7 +299,21 @@ 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 C(name) { #name, name }
struct sym_entry {
const char *sym;
int val;
} constants[] = {
C(AF_UNIX),
C(AF_INET),
C(AF_INET6),
C(SOCK_STREAM),
C(SOCK_DGRAM),
C(SOCK_RAW),
};
#undef C
void rawsocket_init() {
mp_obj_t m = mp_obj_new_module(MP_QSTR_rawsocket);
......@@ -311,10 +325,7 @@ void rawsocket_init() {
rt_store_attr(m, MP_QSTR_gethostbyname, (mp_obj_t)&mod_socket_gethostbyname_obj);
#endif
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);
STORE_INT_CONST(m, SOCK_STREAM);
STORE_INT_CONST(m, SOCK_DGRAM);
STORE_INT_CONST(m, SOCK_RAW);
for (struct sym_entry *p = constants; p->sym != NULL; p++) {
rt_store_attr(m, QSTR_FROM_STR_STATIC(p->sym), MP_OBJ_NEW_SMALL_INT(p->val));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment