Browse Source

unix modsocket: Convert to static module structures.

pull/512/head
Paul Sokolovsky 11 years ago
parent
commit
e1e4249a67
  1. 1
      unix/main.c
  2. 49
      unix/modsocket.c
  3. 2
      unix/mpconfigport.h
  4. 45
      unix/qstrdefsport.h

1
unix/main.c

@ -357,7 +357,6 @@ int main(int argc, char **argv) {
mp_store_name(qstr_from_str("gc"), (mp_obj_t)&pyb_gc_obj);
#endif
microsocket_init();
#if MICROPY_MOD_FFI
ffi_init();
#endif

49
unix/modsocket.c

@ -322,12 +322,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 C(name) { #name, name }
STATIC const mp_map_elem_t mp_module_socket_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_microsocket) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&microsocket_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&mod_socket_getaddrinfo_obj },
#if MICROPY_SOCKET_EXTRA
{ MP_OBJ_NEW_QSTR(MP_QSTR_sockaddr_in), (mp_obj_t)&sockaddr_in_type },
{ MP_OBJ_NEW_QSTR(MP_QSTR_htons), (mp_obj_t)&mod_socket_htons_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_inet_aton), (mp_obj_t)&mod_socket_inet_aton_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_gethostbyname), (mp_obj_t)&mod_socket_gethostbyname_obj },
#endif
STATIC const struct sym_entry {
const char *sym;
int val;
} constants[] = {
#define C(name) { MP_OBJ_NEW_QSTR(MP_QSTR_ ## name), MP_OBJ_NEW_SMALL_INT(name) }
C(AF_UNIX),
C(AF_INET),
C(AF_INET6),
@ -344,23 +350,22 @@ STATIC const struct sym_entry {
C(SO_KEEPALIVE),
C(SO_LINGER),
C(SO_REUSEADDR),
{NULL}
#undef C
};
#undef C
STATIC const mp_obj_dict_t mp_module_socket_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = sizeof(mp_module_socket_globals_table) / sizeof(mp_map_elem_t),
.alloc = sizeof(mp_module_socket_globals_table) / sizeof(mp_map_elem_t),
.table = (mp_map_elem_t*)mp_module_socket_globals_table,
},
};
void microsocket_init() {
mp_obj_t m = mp_obj_new_module(MP_QSTR_microsocket);
mp_store_attr(m, MP_QSTR_socket, (mp_obj_t)&microsocket_type);
#if MICROPY_SOCKET_EXTRA
mp_store_attr(m, MP_QSTR_sockaddr_in, (mp_obj_t)&sockaddr_in_type);
mp_store_attr(m, MP_QSTR_htons, (mp_obj_t)&mod_socket_htons_obj);
mp_store_attr(m, MP_QSTR_inet_aton, (mp_obj_t)&mod_socket_inet_aton_obj);
mp_store_attr(m, MP_QSTR_gethostbyname, (mp_obj_t)&mod_socket_gethostbyname_obj);
#endif
mp_store_attr(m, MP_QSTR_getaddrinfo, (mp_obj_t)&mod_socket_getaddrinfo_obj);
for (const struct sym_entry *p = constants; p->sym != NULL; p++) {
mp_store_attr(m, QSTR_FROM_STR_STATIC(p->sym), MP_OBJ_NEW_SMALL_INT((machine_int_t)p->val));
}
}
const mp_obj_module_t mp_module_socket = {
.base = { &mp_type_module },
.name = MP_QSTR_microsocket,
.globals = (mp_obj_dict_t*)&mp_module_socket_globals,
};

2
unix/mpconfigport.h

@ -18,8 +18,10 @@
#define MICROPY_ENABLE_MOD_CMATH (1)
extern const struct _mp_obj_module_t mp_module_time;
extern const struct _mp_obj_module_t mp_module_socket;
#define MICROPY_EXTRA_BUILTIN_MODULES \
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&mp_module_time }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_microsocket), (mp_obj_t)&mp_module_socket }, \
// type definitions for the specific machine

45
unix/qstrdefsport.h

@ -2,26 +2,12 @@
Q(Test)
Q(rawsocket)
Q(socket)
Q(sockaddr_in)
Q(htons)
Q(inet_aton)
Q(gethostbyname)
Q(getaddrinfo)
Q(microsocket)
Q(fileno)
Q(read)
Q(readall)
Q(readline)
Q(write)
Q(makefile)
Q(connect)
Q(bind)
Q(listen)
Q(accept)
Q(recv)
Q(setsockopt)
Q(FileIO)
Q(ffimod)
@ -34,3 +20,34 @@ Q(var)
Q(time)
Q(clock)
Q(sleep)
Q(socket)
Q(sockaddr_in)
Q(htons)
Q(inet_aton)
Q(gethostbyname)
Q(getaddrinfo)
Q(microsocket)
Q(connect)
Q(bind)
Q(listen)
Q(accept)
Q(recv)
Q(setsockopt)
Q(AF_UNIX)
Q(AF_INET)
Q(AF_INET6)
Q(SOCK_STREAM)
Q(SOCK_DGRAM)
Q(SOCK_RAW)
Q(MSG_DONTROUTE)
Q(MSG_DONTWAIT)
Q(SOL_SOCKET)
Q(SO_BROADCAST)
Q(SO_ERROR)
Q(SO_KEEPALIVE)
Q(SO_LINGER)
Q(SO_REUSEADDR)

Loading…
Cancel
Save