all: Rename mod_umodule*, ^umodule* to remove the "u" prefix.
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
parent
1bf2dcb15e
commit
7f5d5c7271
@ -8,9 +8,9 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
|
||||
MP_DYNRUNTIME_INIT_ENTRY
|
||||
|
||||
mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_heapq));
|
||||
mp_store_global(MP_QSTR_heappush, MP_OBJ_FROM_PTR(&mod_uheapq_heappush_obj));
|
||||
mp_store_global(MP_QSTR_heappop, MP_OBJ_FROM_PTR(&mod_uheapq_heappop_obj));
|
||||
mp_store_global(MP_QSTR_heapify, MP_OBJ_FROM_PTR(&mod_uheapq_heapify_obj));
|
||||
mp_store_global(MP_QSTR_heappush, MP_OBJ_FROM_PTR(&mod_heapq_heappush_obj));
|
||||
mp_store_global(MP_QSTR_heappop, MP_OBJ_FROM_PTR(&mod_heapq_heappop_obj));
|
||||
mp_store_global(MP_QSTR_heapify, MP_OBJ_FROM_PTR(&mod_heapq_heapify_obj));
|
||||
|
||||
MP_DYNRUNTIME_INIT_EXIT
|
||||
}
|
||||
|
@ -17,15 +17,15 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
|
||||
yasmarang_d = 233;
|
||||
|
||||
mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_random));
|
||||
mp_store_global(MP_QSTR_getrandbits, MP_OBJ_FROM_PTR(&mod_urandom_getrandbits_obj));
|
||||
mp_store_global(MP_QSTR_seed, MP_OBJ_FROM_PTR(&mod_urandom_seed_obj));
|
||||
mp_store_global(MP_QSTR_getrandbits, MP_OBJ_FROM_PTR(&mod_random_getrandbits_obj));
|
||||
mp_store_global(MP_QSTR_seed, MP_OBJ_FROM_PTR(&mod_random_seed_obj));
|
||||
#if MICROPY_PY_URANDOM_EXTRA_FUNCS
|
||||
mp_store_global(MP_QSTR_randrange, MP_OBJ_FROM_PTR(&mod_urandom_randrange_obj));
|
||||
mp_store_global(MP_QSTR_randint, MP_OBJ_FROM_PTR(&mod_urandom_randint_obj));
|
||||
mp_store_global(MP_QSTR_choice, MP_OBJ_FROM_PTR(&mod_urandom_choice_obj));
|
||||
mp_store_global(MP_QSTR_randrange, MP_OBJ_FROM_PTR(&mod_random_randrange_obj));
|
||||
mp_store_global(MP_QSTR_randint, MP_OBJ_FROM_PTR(&mod_random_randint_obj));
|
||||
mp_store_global(MP_QSTR_choice, MP_OBJ_FROM_PTR(&mod_random_choice_obj));
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
mp_store_global(MP_QSTR_random, MP_OBJ_FROM_PTR(&mod_urandom_random_obj));
|
||||
mp_store_global(MP_QSTR_uniform, MP_OBJ_FROM_PTR(&mod_urandom_uniform_obj));
|
||||
mp_store_global(MP_QSTR_random, MP_OBJ_FROM_PTR(&mod_random_random_obj));
|
||||
mp_store_global(MP_QSTR_uniform, MP_OBJ_FROM_PTR(&mod_random_uniform_obj));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -28,7 +28,7 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
|
||||
MP_OBJ_TYPE_SET_SLOT(&decompio_type, locals_dict, (void*)&decompio_locals_dict, 2);
|
||||
|
||||
mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_zlib));
|
||||
mp_store_global(MP_QSTR_decompress, MP_OBJ_FROM_PTR(&mod_uzlib_decompress_obj));
|
||||
mp_store_global(MP_QSTR_decompress, MP_OBJ_FROM_PTR(&mod_zlib_decompress_obj));
|
||||
mp_store_global(MP_QSTR_DecompIO, MP_OBJ_FROM_PTR(&decompio_type));
|
||||
|
||||
MP_DYNRUNTIME_INIT_EXIT
|
||||
|
@ -1801,7 +1801,7 @@ const mp_obj_module_t mp_module_lwip = {
|
||||
|
||||
MP_REGISTER_MODULE(MP_QSTR_lwip, mp_module_lwip);
|
||||
|
||||
// On LWIP-ports, this is the usocket module (replaces extmod/modusocket.c).
|
||||
// On LWIP-ports, this is the socket module (replaces extmod/modusocket.c).
|
||||
MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_lwip);
|
||||
|
||||
MP_REGISTER_ROOT_POINTER(mp_obj_t lwip_slip_stream);
|
||||
|
@ -211,7 +211,7 @@ STATIC void aes_process_ctr_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *
|
||||
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t ucryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t cryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 2, 3, false);
|
||||
|
||||
const mp_int_t block_mode = mp_obj_get_int(args[1]);
|
||||
@ -332,33 +332,33 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) {
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t ucryptolib_aes_encrypt(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t cryptolib_aes_encrypt(size_t n_args, const mp_obj_t *args) {
|
||||
return aes_process(n_args, args, true);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ucryptolib_aes_encrypt_obj, 2, 3, ucryptolib_aes_encrypt);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(cryptolib_aes_encrypt_obj, 2, 3, cryptolib_aes_encrypt);
|
||||
|
||||
STATIC mp_obj_t ucryptolib_aes_decrypt(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t cryptolib_aes_decrypt(size_t n_args, const mp_obj_t *args) {
|
||||
return aes_process(n_args, args, false);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ucryptolib_aes_decrypt_obj, 2, 3, ucryptolib_aes_decrypt);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(cryptolib_aes_decrypt_obj, 2, 3, cryptolib_aes_decrypt);
|
||||
|
||||
STATIC const mp_rom_map_elem_t ucryptolib_aes_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_encrypt), MP_ROM_PTR(&ucryptolib_aes_encrypt_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_decrypt), MP_ROM_PTR(&ucryptolib_aes_decrypt_obj) },
|
||||
STATIC const mp_rom_map_elem_t cryptolib_aes_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_encrypt), MP_ROM_PTR(&cryptolib_aes_encrypt_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_decrypt), MP_ROM_PTR(&cryptolib_aes_decrypt_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(ucryptolib_aes_locals_dict, ucryptolib_aes_locals_dict_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(cryptolib_aes_locals_dict, cryptolib_aes_locals_dict_table);
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
ucryptolib_aes_type,
|
||||
cryptolib_aes_type,
|
||||
MP_QSTR_aes,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, ucryptolib_aes_make_new,
|
||||
locals_dict, &ucryptolib_aes_locals_dict
|
||||
make_new, cryptolib_aes_make_new,
|
||||
locals_dict, &cryptolib_aes_locals_dict
|
||||
);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_cryptolib_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cryptolib) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_aes), MP_ROM_PTR(&ucryptolib_aes_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_aes), MP_ROM_PTR(&cryptolib_aes_type) },
|
||||
#if MICROPY_PY_UCRYPTOLIB_CONSTS
|
||||
{ MP_ROM_QSTR(MP_QSTR_MODE_ECB), MP_ROM_INT(UCRYPTOLIB_MODE_ECB) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MODE_CBC), MP_ROM_INT(UCRYPTOLIB_MODE_CBC) },
|
||||
|
@ -64,14 +64,14 @@ typedef struct _mp_obj_hash_t {
|
||||
uintptr_t state[0]; // must be aligned to a machine word
|
||||
} mp_obj_hash_t;
|
||||
|
||||
static void uhashlib_ensure_not_final(mp_obj_hash_t *self) {
|
||||
static void hashlib_ensure_not_final(mp_obj_hash_t *self) {
|
||||
if (self->final) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("hash is final"));
|
||||
}
|
||||
}
|
||||
|
||||
#if MICROPY_PY_UHASHLIB_SHA256
|
||||
STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg);
|
||||
STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg);
|
||||
|
||||
#if MICROPY_SSL_MBEDTLS
|
||||
|
||||
@ -81,30 +81,30 @@ STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg);
|
||||
#define mbedtls_sha256_finish_ret mbedtls_sha256_finish
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_sha256_context), type);
|
||||
o->final = false;
|
||||
mbedtls_sha256_init((mbedtls_sha256_context *)&o->state);
|
||||
mbedtls_sha256_starts_ret((mbedtls_sha256_context *)&o->state, 0);
|
||||
if (n_args == 1) {
|
||||
uhashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
hashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uhashlib_ensure_not_final(self);
|
||||
hashlib_ensure_not_final(self);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||
mbedtls_sha256_update_ret((mbedtls_sha256_context *)&self->state, bufinfo.buf, bufinfo.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
|
||||
STATIC mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uhashlib_ensure_not_final(self);
|
||||
hashlib_ensure_not_final(self);
|
||||
self->final = true;
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, 32);
|
||||
@ -116,29 +116,29 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
|
||||
|
||||
#include "lib/crypto-algorithms/sha256.c"
|
||||
|
||||
STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX), type);
|
||||
o->final = false;
|
||||
sha256_init((CRYAL_SHA256_CTX *)o->state);
|
||||
if (n_args == 1) {
|
||||
uhashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
hashlib_sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uhashlib_ensure_not_final(self);
|
||||
hashlib_ensure_not_final(self);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||
sha256_update((CRYAL_SHA256_CTX *)self->state, bufinfo.buf, bufinfo.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
|
||||
STATIC mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uhashlib_ensure_not_final(self);
|
||||
hashlib_ensure_not_final(self);
|
||||
self->final = true;
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, SHA256_BLOCK_SIZE);
|
||||
@ -147,52 +147,52 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(uhashlib_sha256_update_obj, uhashlib_sha256_update);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(uhashlib_sha256_digest_obj, uhashlib_sha256_digest);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(hashlib_sha256_update_obj, hashlib_sha256_update);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(hashlib_sha256_digest_obj, hashlib_sha256_digest);
|
||||
|
||||
STATIC const mp_rom_map_elem_t uhashlib_sha256_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&uhashlib_sha256_update_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&uhashlib_sha256_digest_obj) },
|
||||
STATIC const mp_rom_map_elem_t hashlib_sha256_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hashlib_sha256_update_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hashlib_sha256_digest_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(uhashlib_sha256_locals_dict, uhashlib_sha256_locals_dict_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(hashlib_sha256_locals_dict, hashlib_sha256_locals_dict_table);
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
uhashlib_sha256_type,
|
||||
hashlib_sha256_type,
|
||||
MP_QSTR_sha256,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, uhashlib_sha256_make_new,
|
||||
locals_dict, &uhashlib_sha256_locals_dict
|
||||
locals_dict, &hashlib_sha256_locals_dict
|
||||
);
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_UHASHLIB_SHA1
|
||||
STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg);
|
||||
STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg);
|
||||
|
||||
#if MICROPY_SSL_AXTLS
|
||||
STATIC mp_obj_t uhashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(SHA1_CTX), type);
|
||||
o->final = false;
|
||||
SHA1_Init((SHA1_CTX *)o->state);
|
||||
if (n_args == 1) {
|
||||
uhashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
hashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uhashlib_ensure_not_final(self);
|
||||
hashlib_ensure_not_final(self);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||
SHA1_Update((SHA1_CTX *)self->state, bufinfo.buf, bufinfo.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) {
|
||||
STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uhashlib_ensure_not_final(self);
|
||||
hashlib_ensure_not_final(self);
|
||||
self->final = true;
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, SHA1_SIZE);
|
||||
@ -209,30 +209,30 @@ STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) {
|
||||
#define mbedtls_sha1_finish_ret mbedtls_sha1_finish
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t uhashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_sha1_context), type);
|
||||
o->final = false;
|
||||
mbedtls_sha1_init((mbedtls_sha1_context *)o->state);
|
||||
mbedtls_sha1_starts_ret((mbedtls_sha1_context *)o->state);
|
||||
if (n_args == 1) {
|
||||
uhashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
hashlib_sha1_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uhashlib_ensure_not_final(self);
|
||||
hashlib_ensure_not_final(self);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||
mbedtls_sha1_update_ret((mbedtls_sha1_context *)self->state, bufinfo.buf, bufinfo.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) {
|
||||
STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uhashlib_ensure_not_final(self);
|
||||
hashlib_ensure_not_final(self);
|
||||
self->final = true;
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, 20);
|
||||
@ -242,51 +242,51 @@ STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) {
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(uhashlib_sha1_update_obj, uhashlib_sha1_update);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(uhashlib_sha1_digest_obj, uhashlib_sha1_digest);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(hashlib_sha1_update_obj, hashlib_sha1_update);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(hashlib_sha1_digest_obj, hashlib_sha1_digest);
|
||||
|
||||
STATIC const mp_rom_map_elem_t uhashlib_sha1_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&uhashlib_sha1_update_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&uhashlib_sha1_digest_obj) },
|
||||
STATIC const mp_rom_map_elem_t hashlib_sha1_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hashlib_sha1_update_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hashlib_sha1_digest_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(uhashlib_sha1_locals_dict, uhashlib_sha1_locals_dict_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(hashlib_sha1_locals_dict, hashlib_sha1_locals_dict_table);
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
uhashlib_sha1_type,
|
||||
hashlib_sha1_type,
|
||||
MP_QSTR_sha1,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, uhashlib_sha1_make_new,
|
||||
locals_dict, &uhashlib_sha1_locals_dict
|
||||
make_new, hashlib_sha1_make_new,
|
||||
locals_dict, &hashlib_sha1_locals_dict
|
||||
);
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_UHASHLIB_MD5
|
||||
STATIC mp_obj_t uhashlib_md5_update(mp_obj_t self_in, mp_obj_t arg);
|
||||
STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg);
|
||||
|
||||
#if MICROPY_SSL_AXTLS
|
||||
STATIC mp_obj_t uhashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(MD5_CTX), type);
|
||||
o->final = false;
|
||||
MD5_Init((MD5_CTX *)o->state);
|
||||
if (n_args == 1) {
|
||||
uhashlib_md5_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
hashlib_md5_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uhashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uhashlib_ensure_not_final(self);
|
||||
hashlib_ensure_not_final(self);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||
MD5_Update((MD5_CTX *)self->state, bufinfo.buf, bufinfo.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) {
|
||||
STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uhashlib_ensure_not_final(self);
|
||||
hashlib_ensure_not_final(self);
|
||||
self->final = true;
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, MD5_SIZE);
|
||||
@ -303,30 +303,30 @@ STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) {
|
||||
#define mbedtls_md5_finish_ret mbedtls_md5_finish
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t uhashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_md5_context), type);
|
||||
o->final = false;
|
||||
mbedtls_md5_init((mbedtls_md5_context *)o->state);
|
||||
mbedtls_md5_starts_ret((mbedtls_md5_context *)o->state);
|
||||
if (n_args == 1) {
|
||||
uhashlib_md5_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
hashlib_md5_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uhashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uhashlib_ensure_not_final(self);
|
||||
hashlib_ensure_not_final(self);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
|
||||
mbedtls_md5_update_ret((mbedtls_md5_context *)self->state, bufinfo.buf, bufinfo.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) {
|
||||
STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) {
|
||||
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
uhashlib_ensure_not_final(self);
|
||||
hashlib_ensure_not_final(self);
|
||||
self->final = true;
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, 16);
|
||||
@ -336,34 +336,34 @@ STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) {
|
||||
}
|
||||
#endif // MICROPY_SSL_MBEDTLS
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(uhashlib_md5_update_obj, uhashlib_md5_update);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(uhashlib_md5_digest_obj, uhashlib_md5_digest);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(hashlib_md5_update_obj, hashlib_md5_update);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(hashlib_md5_digest_obj, hashlib_md5_digest);
|
||||
|
||||
STATIC const mp_rom_map_elem_t uhashlib_md5_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&uhashlib_md5_update_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&uhashlib_md5_digest_obj) },
|
||||
STATIC const mp_rom_map_elem_t hashlib_md5_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hashlib_md5_update_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hashlib_md5_digest_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(uhashlib_md5_locals_dict, uhashlib_md5_locals_dict_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(hashlib_md5_locals_dict, hashlib_md5_locals_dict_table);
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
uhashlib_md5_type,
|
||||
hashlib_md5_type,
|
||||
MP_QSTR_md5,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, uhashlib_md5_make_new,
|
||||
locals_dict, &uhashlib_md5_locals_dict
|
||||
make_new, hashlib_md5_make_new,
|
||||
locals_dict, &hashlib_md5_locals_dict
|
||||
);
|
||||
#endif // MICROPY_PY_UHASHLIB_MD5
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hashlib) },
|
||||
#if MICROPY_PY_UHASHLIB_SHA256
|
||||
{ MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&uhashlib_sha256_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&hashlib_sha256_type) },
|
||||
#endif
|
||||
#if MICROPY_PY_UHASHLIB_SHA1
|
||||
{ MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&uhashlib_sha1_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&hashlib_sha1_type) },
|
||||
#endif
|
||||
#if MICROPY_PY_UHASHLIB_MD5
|
||||
{ MP_ROM_QSTR(MP_QSTR_md5), MP_ROM_PTR(&uhashlib_md5_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_md5), MP_ROM_PTR(&hashlib_md5_type) },
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -31,14 +31,14 @@
|
||||
|
||||
// the algorithm here is modelled on CPython's heapq.py
|
||||
|
||||
STATIC mp_obj_list_t *uheapq_get_heap(mp_obj_t heap_in) {
|
||||
STATIC mp_obj_list_t *heapq_get_heap(mp_obj_t heap_in) {
|
||||
if (!mp_obj_is_type(heap_in, &mp_type_list)) {
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("heap must be a list"));
|
||||
}
|
||||
return MP_OBJ_TO_PTR(heap_in);
|
||||
}
|
||||
|
||||
STATIC void uheapq_heap_siftdown(mp_obj_list_t *heap, mp_uint_t start_pos, mp_uint_t pos) {
|
||||
STATIC void heapq_heap_siftdown(mp_obj_list_t *heap, mp_uint_t start_pos, mp_uint_t pos) {
|
||||
mp_obj_t item = heap->items[pos];
|
||||
while (pos > start_pos) {
|
||||
mp_uint_t parent_pos = (pos - 1) >> 1;
|
||||
@ -53,7 +53,7 @@ STATIC void uheapq_heap_siftdown(mp_obj_list_t *heap, mp_uint_t start_pos, mp_ui
|
||||
heap->items[pos] = item;
|
||||
}
|
||||
|
||||
STATIC void uheapq_heap_siftup(mp_obj_list_t *heap, mp_uint_t pos) {
|
||||
STATIC void heapq_heap_siftup(mp_obj_list_t *heap, mp_uint_t pos) {
|
||||
mp_uint_t start_pos = pos;
|
||||
mp_uint_t end_pos = heap->len;
|
||||
mp_obj_t item = heap->items[pos];
|
||||
@ -67,19 +67,19 @@ STATIC void uheapq_heap_siftup(mp_obj_list_t *heap, mp_uint_t pos) {
|
||||
pos = child_pos;
|
||||
}
|
||||
heap->items[pos] = item;
|
||||
uheapq_heap_siftdown(heap, start_pos, pos);
|
||||
heapq_heap_siftdown(heap, start_pos, pos);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mod_uheapq_heappush(mp_obj_t heap_in, mp_obj_t item) {
|
||||
mp_obj_list_t *heap = uheapq_get_heap(heap_in);
|
||||
STATIC mp_obj_t mod_heapq_heappush(mp_obj_t heap_in, mp_obj_t item) {
|
||||
mp_obj_list_t *heap = heapq_get_heap(heap_in);
|
||||
mp_obj_list_append(heap_in, item);
|
||||
uheapq_heap_siftdown(heap, 0, heap->len - 1);
|
||||
heapq_heap_siftdown(heap, 0, heap->len - 1);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_uheapq_heappush_obj, mod_uheapq_heappush);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_heapq_heappush_obj, mod_heapq_heappush);
|
||||
|
||||
STATIC mp_obj_t mod_uheapq_heappop(mp_obj_t heap_in) {
|
||||
mp_obj_list_t *heap = uheapq_get_heap(heap_in);
|
||||
STATIC mp_obj_t mod_heapq_heappop(mp_obj_t heap_in) {
|
||||
mp_obj_list_t *heap = heapq_get_heap(heap_in);
|
||||
if (heap->len == 0) {
|
||||
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap"));
|
||||
}
|
||||
@ -88,27 +88,27 @@ STATIC mp_obj_t mod_uheapq_heappop(mp_obj_t heap_in) {
|
||||
heap->items[0] = heap->items[heap->len];
|
||||
heap->items[heap->len] = MP_OBJ_NULL; // so we don't retain a pointer
|
||||
if (heap->len) {
|
||||
uheapq_heap_siftup(heap, 0);
|
||||
heapq_heap_siftup(heap, 0);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_uheapq_heappop_obj, mod_uheapq_heappop);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_heapq_heappop_obj, mod_heapq_heappop);
|
||||
|
||||
STATIC mp_obj_t mod_uheapq_heapify(mp_obj_t heap_in) {
|
||||
mp_obj_list_t *heap = uheapq_get_heap(heap_in);
|
||||
STATIC mp_obj_t mod_heapq_heapify(mp_obj_t heap_in) {
|
||||
mp_obj_list_t *heap = heapq_get_heap(heap_in);
|
||||
for (mp_uint_t i = heap->len / 2; i > 0;) {
|
||||
uheapq_heap_siftup(heap, --i);
|
||||
heapq_heap_siftup(heap, --i);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_uheapq_heapify_obj, mod_uheapq_heapify);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_heapq_heapify_obj, mod_heapq_heapify);
|
||||
|
||||
#if !MICROPY_ENABLE_DYNRUNTIME
|
||||
STATIC const mp_rom_map_elem_t mp_module_heapq_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_heapq) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_heappush), MP_ROM_PTR(&mod_uheapq_heappush_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_heappop), MP_ROM_PTR(&mod_uheapq_heappop_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_heapify), MP_ROM_PTR(&mod_uheapq_heapify_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_heappush), MP_ROM_PTR(&mod_heapq_heappush_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_heappop), MP_ROM_PTR(&mod_heapq_heappop_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_heapify), MP_ROM_PTR(&mod_heapq_heapify_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_heapq_globals, mp_module_heapq_globals_table);
|
||||
|
@ -41,7 +41,7 @@ enum {
|
||||
DUMP_MODE_TO_STREAM = 2,
|
||||
};
|
||||
|
||||
STATIC mp_obj_t mod_ujson_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, unsigned int mode) {
|
||||
STATIC mp_obj_t mod_json_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, unsigned int mode) {
|
||||
enum { ARG_separators };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_separators, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
|
||||
@ -78,34 +78,34 @@ STATIC mp_obj_t mod_ujson_dump_helper(size_t n_args, const mp_obj_t *pos_args, m
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mod_ujson_dump(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return mod_ujson_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STREAM);
|
||||
STATIC mp_obj_t mod_json_dump(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return mod_json_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STREAM);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ujson_dump_obj, 2, mod_ujson_dump);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dump_obj, 2, mod_json_dump);
|
||||
|
||||
STATIC mp_obj_t mod_ujson_dumps(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return mod_ujson_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STRING);
|
||||
STATIC mp_obj_t mod_json_dumps(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return mod_json_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STRING);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ujson_dumps_obj, 1, mod_ujson_dumps);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dumps_obj, 1, mod_json_dumps);
|
||||
|
||||
#else
|
||||
|
||||
STATIC mp_obj_t mod_ujson_dump(mp_obj_t obj, mp_obj_t stream) {
|
||||
STATIC mp_obj_t mod_json_dump(mp_obj_t obj, mp_obj_t stream) {
|
||||
mp_get_stream_raise(stream, MP_STREAM_OP_WRITE);
|
||||
mp_print_t print = {MP_OBJ_TO_PTR(stream), mp_stream_write_adaptor};
|
||||
mp_obj_print_helper(&print, obj, PRINT_JSON);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_ujson_dump_obj, mod_ujson_dump);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_json_dump_obj, mod_json_dump);
|
||||
|
||||
STATIC mp_obj_t mod_ujson_dumps(mp_obj_t obj) {
|
||||
STATIC mp_obj_t mod_json_dumps(mp_obj_t obj) {
|
||||
vstr_t vstr;
|
||||
mp_print_t print;
|
||||
vstr_init_print(&vstr, 8, &print);
|
||||
mp_obj_print_helper(&print, obj, PRINT_JSON);
|
||||
return mp_obj_new_str_from_utf8_vstr(&vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_dumps_obj, mod_ujson_dumps);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_dumps_obj, mod_json_dumps);
|
||||
|
||||
#endif
|
||||
|
||||
@ -122,19 +122,19 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_dumps_obj, mod_ujson_dumps);
|
||||
// strings). It does 1 pass over the input stream. It tries to be fast and
|
||||
// small in code size, while not using more RAM than necessary.
|
||||
|
||||
typedef struct _ujson_stream_t {
|
||||
typedef struct _json_stream_t {
|
||||
mp_obj_t stream_obj;
|
||||
mp_uint_t (*read)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode);
|
||||
int errcode;
|
||||
byte cur;
|
||||
} ujson_stream_t;
|
||||
} json_stream_t;
|
||||
|
||||
#define S_EOF (0) // null is not allowed in json stream so is ok as EOF marker
|
||||
#define S_END(s) ((s).cur == S_EOF)
|
||||
#define S_CUR(s) ((s).cur)
|
||||
#define S_NEXT(s) (ujson_stream_next(&(s)))
|
||||
#define S_NEXT(s) (json_stream_next(&(s)))
|
||||
|
||||
STATIC byte ujson_stream_next(ujson_stream_t *s) {
|
||||
STATIC byte json_stream_next(json_stream_t *s) {
|
||||
mp_uint_t ret = s->read(s->stream_obj, &s->cur, 1, &s->errcode);
|
||||
if (s->errcode != 0) {
|
||||
mp_raise_OSError(s->errcode);
|
||||
@ -145,9 +145,9 @@ STATIC byte ujson_stream_next(ujson_stream_t *s) {
|
||||
return s->cur;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mod_ujson_load(mp_obj_t stream_obj) {
|
||||
STATIC mp_obj_t mod_json_load(mp_obj_t stream_obj) {
|
||||
const mp_stream_p_t *stream_p = mp_get_stream_raise(stream_obj, MP_STREAM_OP_READ);
|
||||
ujson_stream_t s = {stream_obj, stream_p->read, 0, 0};
|
||||
json_stream_t s = {stream_obj, stream_p->read, 0, 0};
|
||||
vstr_t vstr;
|
||||
vstr_init(&vstr, 8);
|
||||
mp_obj_list_t stack; // we use a list as a simple stack for nested JSON
|
||||
@ -355,23 +355,23 @@ success:
|
||||
fail:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("syntax error in JSON"));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_load_obj, mod_ujson_load);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_load_obj, mod_json_load);
|
||||
|
||||
STATIC mp_obj_t mod_ujson_loads(mp_obj_t obj) {
|
||||
STATIC mp_obj_t mod_json_loads(mp_obj_t obj) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(obj, &bufinfo, MP_BUFFER_READ);
|
||||
vstr_t vstr = {bufinfo.len, bufinfo.len, (char *)bufinfo.buf, true};
|
||||
mp_obj_stringio_t sio = {{&mp_type_stringio}, &vstr, 0, MP_OBJ_NULL};
|
||||
return mod_ujson_load(MP_OBJ_FROM_PTR(&sio));
|
||||
return mod_json_load(MP_OBJ_FROM_PTR(&sio));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_loads_obj, mod_ujson_loads);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_loads_obj, mod_json_loads);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_json_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_json) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_ujson_dump_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_dumps), MP_ROM_PTR(&mod_ujson_dumps_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_load), MP_ROM_PTR(&mod_ujson_load_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_loads), MP_ROM_PTR(&mod_ujson_loads_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_json_dump_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_dumps), MP_ROM_PTR(&mod_json_dumps_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_load), MP_ROM_PTR(&mod_json_load_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_loads), MP_ROM_PTR(&mod_json_loads_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_json_globals, mp_module_json_globals_table);
|
||||
|
@ -85,7 +85,7 @@ STATIC uint32_t yasmarang_randbelow(uint32_t n) {
|
||||
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t mod_urandom_getrandbits(mp_obj_t num_in) {
|
||||
STATIC mp_obj_t mod_random_getrandbits(mp_obj_t num_in) {
|
||||
int n = mp_obj_get_int(num_in);
|
||||
if (n > 32 || n < 0) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bits must be 32 or less"));
|
||||
@ -98,9 +98,9 @@ STATIC mp_obj_t mod_urandom_getrandbits(mp_obj_t num_in) {
|
||||
mask >>= (32 - n);
|
||||
return mp_obj_new_int_from_uint(yasmarang() & mask);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_urandom_getrandbits_obj, mod_urandom_getrandbits);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_random_getrandbits_obj, mod_random_getrandbits);
|
||||
|
||||
STATIC mp_obj_t mod_urandom_seed(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t mod_random_seed(size_t n_args, const mp_obj_t *args) {
|
||||
mp_uint_t seed;
|
||||
if (n_args == 0 || args[0] == mp_const_none) {
|
||||
#ifdef MICROPY_PY_URANDOM_SEED_INIT_FUNC
|
||||
@ -117,11 +117,11 @@ STATIC mp_obj_t mod_urandom_seed(size_t n_args, const mp_obj_t *args) {
|
||||
yasmarang_dat = 0;
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_urandom_seed_obj, 0, 1, mod_urandom_seed);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_seed_obj, 0, 1, mod_random_seed);
|
||||
|
||||
#if MICROPY_PY_URANDOM_EXTRA_FUNCS
|
||||
|
||||
STATIC mp_obj_t mod_urandom_randrange(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t start = mp_obj_get_int(args[0]);
|
||||
if (n_args == 1) {
|
||||
// range(stop)
|
||||
@ -161,9 +161,9 @@ STATIC mp_obj_t mod_urandom_randrange(size_t n_args, const mp_obj_t *args) {
|
||||
error:
|
||||
mp_raise_ValueError(NULL);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_urandom_randrange_obj, 1, 3, mod_urandom_randrange);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_randrange_obj, 1, 3, mod_random_randrange);
|
||||
|
||||
STATIC mp_obj_t mod_urandom_randint(mp_obj_t a_in, mp_obj_t b_in) {
|
||||
STATIC mp_obj_t mod_random_randint(mp_obj_t a_in, mp_obj_t b_in) {
|
||||
mp_int_t a = mp_obj_get_int(a_in);
|
||||
mp_int_t b = mp_obj_get_int(b_in);
|
||||
if (a <= b) {
|
||||
@ -172,9 +172,9 @@ STATIC mp_obj_t mod_urandom_randint(mp_obj_t a_in, mp_obj_t b_in) {
|
||||
mp_raise_ValueError(NULL);
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_urandom_randint_obj, mod_urandom_randint);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_random_randint_obj, mod_random_randint);
|
||||
|
||||
STATIC mp_obj_t mod_urandom_choice(mp_obj_t seq) {
|
||||
STATIC mp_obj_t mod_random_choice(mp_obj_t seq) {
|
||||
mp_int_t len = mp_obj_get_int(mp_obj_len(seq));
|
||||
if (len > 0) {
|
||||
return mp_obj_subscr(seq, mp_obj_new_int(yasmarang_randbelow(len)), MP_OBJ_SENTINEL);
|
||||
@ -182,7 +182,7 @@ STATIC mp_obj_t mod_urandom_choice(mp_obj_t seq) {
|
||||
mp_raise_type(&mp_type_IndexError);
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_urandom_choice_obj, mod_urandom_choice);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_random_choice_obj, mod_random_choice);
|
||||
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
|
||||
@ -199,51 +199,51 @@ STATIC mp_float_t yasmarang_float(void) {
|
||||
return u.f - 1;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mod_urandom_random(void) {
|
||||
STATIC mp_obj_t mod_random_random(void) {
|
||||
return mp_obj_new_float(yasmarang_float());
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_urandom_random_obj, mod_urandom_random);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_random_random_obj, mod_random_random);
|
||||
|
||||
STATIC mp_obj_t mod_urandom_uniform(mp_obj_t a_in, mp_obj_t b_in) {
|
||||
STATIC mp_obj_t mod_random_uniform(mp_obj_t a_in, mp_obj_t b_in) {
|
||||
mp_float_t a = mp_obj_get_float(a_in);
|
||||
mp_float_t b = mp_obj_get_float(b_in);
|
||||
return mp_obj_new_float(a + (b - a) * yasmarang_float());
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_urandom_uniform_obj, mod_urandom_uniform);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_random_uniform_obj, mod_random_uniform);
|
||||
|
||||
#endif
|
||||
|
||||
#endif // MICROPY_PY_URANDOM_EXTRA_FUNCS
|
||||
|
||||
#if SEED_ON_IMPORT
|
||||
STATIC mp_obj_t mod_urandom___init__(void) {
|
||||
STATIC mp_obj_t mod_random___init__(void) {
|
||||
// This module may be imported by more than one name so need to ensure
|
||||
// that it's only ever seeded once.
|
||||
static bool seeded = false;
|
||||
if (!seeded) {
|
||||
seeded = true;
|
||||
mod_urandom_seed(0, NULL);
|
||||
mod_random_seed(0, NULL);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_urandom___init___obj, mod_urandom___init__);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_random___init___obj, mod_random___init__);
|
||||
#endif
|
||||
|
||||
#if !MICROPY_ENABLE_DYNRUNTIME
|
||||
STATIC const mp_rom_map_elem_t mp_module_random_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_random) },
|
||||
#if SEED_ON_IMPORT
|
||||
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&mod_urandom___init___obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&mod_random___init___obj) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_getrandbits), MP_ROM_PTR(&mod_urandom_getrandbits_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_seed), MP_ROM_PTR(&mod_urandom_seed_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_getrandbits), MP_ROM_PTR(&mod_random_getrandbits_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_seed), MP_ROM_PTR(&mod_random_seed_obj) },
|
||||
#if MICROPY_PY_URANDOM_EXTRA_FUNCS
|
||||
{ MP_ROM_QSTR(MP_QSTR_randrange), MP_ROM_PTR(&mod_urandom_randrange_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_randint), MP_ROM_PTR(&mod_urandom_randint_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_choice), MP_ROM_PTR(&mod_urandom_choice_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_randrange), MP_ROM_PTR(&mod_random_randrange_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_randint), MP_ROM_PTR(&mod_random_randint_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_choice), MP_ROM_PTR(&mod_random_choice_obj) },
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
{ MP_ROM_QSTR(MP_QSTR_random), MP_ROM_PTR(&mod_urandom_random_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_uniform), MP_ROM_PTR(&mod_urandom_uniform_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_random), MP_ROM_PTR(&mod_random_random_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_uniform), MP_ROM_PTR(&mod_random_uniform_obj) },
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
@ -194,7 +194,7 @@ STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
||||
mp_printf(print, "<re %p>", self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t ure_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
mp_obj_re_t *self;
|
||||
if (mp_obj_is_type(args[0], (mp_obj_type_t *)&re_type)) {
|
||||
@ -223,12 +223,12 @@ STATIC mp_obj_t ure_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
|
||||
}
|
||||
|
||||
STATIC mp_obj_t re_match(size_t n_args, const mp_obj_t *args) {
|
||||
return ure_exec(true, n_args, args);
|
||||
return re_exec(true, n_args, args);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_match_obj, 2, 4, re_match);
|
||||
|
||||
STATIC mp_obj_t re_search(size_t n_args, const mp_obj_t *args) {
|
||||
return ure_exec(false, n_args, args);
|
||||
return re_exec(false, n_args, args);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_search_obj, 2, 4, re_search);
|
||||
|
||||
|
@ -540,10 +540,10 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
);
|
||||
|
||||
/******************************************************************************/
|
||||
// usocket module
|
||||
// socket module
|
||||
|
||||
// function usocket.getaddrinfo(host, port)
|
||||
STATIC mp_obj_t mod_usocket_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
||||
// function socket.getaddrinfo(host, port)
|
||||
STATIC mp_obj_t mod_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
||||
size_t hlen;
|
||||
const char *host = mp_obj_str_get_data(args[0], &hlen);
|
||||
mp_int_t port = mp_obj_get_int(args[1]);
|
||||
@ -613,13 +613,13 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
||||
tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_BIG);
|
||||
return mp_obj_new_list(1, (mp_obj_t *)&tuple);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_usocket_getaddrinfo_obj, 2, 6, mod_usocket_getaddrinfo);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod_socket_getaddrinfo);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_usocket_getaddrinfo_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_socket_getaddrinfo_obj) },
|
||||
|
||||
// class constants
|
||||
{ MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(MOD_NETWORK_AF_INET) },
|
||||
|
@ -53,7 +53,7 @@ struct ssl_args {
|
||||
mp_arg_val_t do_handshake;
|
||||
};
|
||||
|
||||
STATIC const mp_obj_type_t ussl_socket_type;
|
||||
STATIC const mp_obj_type_t ssl_socket_type;
|
||||
|
||||
// Table of error strings corresponding to SSL_xxx error codes.
|
||||
STATIC const char *const ssl_error_tab1[] = {
|
||||
@ -84,7 +84,7 @@ STATIC const char *const ssl_error_tab2[] = {
|
||||
"NOT_SUPPORTED",
|
||||
};
|
||||
|
||||
STATIC NORETURN void ussl_raise_error(int err) {
|
||||
STATIC NORETURN void ssl_raise_error(int err) {
|
||||
MP_STATIC_ASSERT(SSL_NOT_OK - 3 == SSL_EAGAIN);
|
||||
MP_STATIC_ASSERT(SSL_ERROR_CONN_LOST - 18 == SSL_ERROR_NOT_SUPPORTED);
|
||||
|
||||
@ -117,13 +117,13 @@ STATIC NORETURN void ussl_raise_error(int err) {
|
||||
}
|
||||
|
||||
|
||||
STATIC mp_obj_ssl_socket_t *ussl_socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||
STATIC mp_obj_ssl_socket_t *ssl_socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
|
||||
#else
|
||||
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
||||
#endif
|
||||
o->base.type = &ussl_socket_type;
|
||||
o->base.type = &ssl_socket_type;
|
||||
o->buf = NULL;
|
||||
o->bytes_left = 0;
|
||||
o->sock = sock;
|
||||
@ -175,7 +175,7 @@ STATIC mp_obj_ssl_socket_t *ussl_socket_new(mp_obj_t sock, struct ssl_args *args
|
||||
} else if (r == SSL_EAGAIN) {
|
||||
r = MP_EAGAIN;
|
||||
}
|
||||
ussl_raise_error(r);
|
||||
ssl_raise_error(r);
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,13 +184,13 @@ STATIC mp_obj_ssl_socket_t *ussl_socket_new(mp_obj_t sock, struct ssl_args *args
|
||||
return o;
|
||||
}
|
||||
|
||||
STATIC void ussl_socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
STATIC void ssl_socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
(void)kind;
|
||||
mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "<_SSLSocket %p>", self->ssl_sock);
|
||||
}
|
||||
|
||||
STATIC mp_uint_t ussl_socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) {
|
||||
STATIC mp_uint_t ssl_socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) {
|
||||
mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in);
|
||||
|
||||
if (o->ssl_sock == NULL) {
|
||||
@ -239,7 +239,7 @@ STATIC mp_uint_t ussl_socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int
|
||||
return size;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t ussl_socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {
|
||||
STATIC mp_uint_t ssl_socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {
|
||||
mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in);
|
||||
|
||||
if (o->ssl_sock == NULL) {
|
||||
@ -251,7 +251,7 @@ STATIC mp_uint_t ussl_socket_write(mp_obj_t o_in, const void *buf, mp_uint_t siz
|
||||
eagain:
|
||||
r = ssl_write(o->ssl_sock, buf, size);
|
||||
if (r == 0) {
|
||||
// see comment in ussl_socket_read above
|
||||
// see comment in ssl_socket_read above
|
||||
if (o->blocking) {
|
||||
goto eagain;
|
||||
} else {
|
||||
@ -271,7 +271,7 @@ eagain:
|
||||
return r;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t ussl_socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||
STATIC mp_uint_t ssl_socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||
mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(o_in);
|
||||
if (request == MP_STREAM_CLOSE && self->ssl_sock != NULL) {
|
||||
ssl_free(self->ssl_sock);
|
||||
@ -282,7 +282,7 @@ STATIC mp_uint_t ussl_socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t a
|
||||
return mp_get_stream(self->sock)->ioctl(self->sock, request, arg, errcode);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t ussl_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
|
||||
STATIC mp_obj_t ssl_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
|
||||
mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(self_in);
|
||||
mp_obj_t sock = o->sock;
|
||||
mp_obj_t dest[3];
|
||||
@ -292,36 +292,36 @@ STATIC mp_obj_t ussl_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
|
||||
o->blocking = mp_obj_is_true(flag_in);
|
||||
return res;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ussl_socket_setblocking_obj, ussl_socket_setblocking);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ssl_socket_setblocking_obj, ssl_socket_setblocking);
|
||||
|
||||
STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
|
||||
STATIC const mp_rom_map_elem_t ssl_socket_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&ussl_socket_setblocking_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&ssl_socket_setblocking_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ussl_socket_locals_dict, ussl_socket_locals_dict_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(ssl_socket_locals_dict, ssl_socket_locals_dict_table);
|
||||
|
||||
STATIC const mp_stream_p_t ussl_socket_stream_p = {
|
||||
.read = ussl_socket_read,
|
||||
.write = ussl_socket_write,
|
||||
.ioctl = ussl_socket_ioctl,
|
||||
STATIC const mp_stream_p_t ssl_socket_stream_p = {
|
||||
.read = ssl_socket_read,
|
||||
.write = ssl_socket_write,
|
||||
.ioctl = ssl_socket_ioctl,
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
ussl_socket_type,
|
||||
ssl_socket_type,
|
||||
// Save on qstr's, reuse same as for module
|
||||
MP_QSTR_ssl,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
print, ussl_socket_print,
|
||||
protocol, &ussl_socket_stream_p,
|
||||
locals_dict, &ussl_socket_locals_dict
|
||||
print, ssl_socket_print,
|
||||
protocol, &ssl_socket_stream_p,
|
||||
locals_dict, &ssl_socket_locals_dict
|
||||
);
|
||||
|
||||
STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
@ -341,7 +341,7 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,
|
||||
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t *)&args);
|
||||
|
||||
return MP_OBJ_FROM_PTR(ussl_socket_new(sock, &args));
|
||||
return MP_OBJ_FROM_PTR(ssl_socket_new(sock, &args));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 1, mod_ssl_wrap_socket);
|
||||
|
||||
|
@ -73,7 +73,7 @@ struct ssl_args {
|
||||
mp_arg_val_t do_handshake;
|
||||
};
|
||||
|
||||
STATIC const mp_obj_type_t ussl_socket_type;
|
||||
STATIC const mp_obj_type_t ssl_socket_type;
|
||||
|
||||
#ifdef MBEDTLS_DEBUG_C
|
||||
STATIC void mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str) {
|
||||
@ -168,7 +168,7 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||
#else
|
||||
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
||||
#endif
|
||||
o->base.type = &ussl_socket_type;
|
||||
o->base.type = &ssl_socket_type;
|
||||
o->sock = sock;
|
||||
o->poll_mask = 0;
|
||||
o->last_error = 0;
|
||||
@ -435,7 +435,7 @@ STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, i
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
|
||||
STATIC const mp_rom_map_elem_t ssl_socket_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
|
||||
@ -451,22 +451,22 @@ STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_getpeercert), MP_ROM_PTR(&mod_ssl_getpeercert_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ussl_socket_locals_dict, ussl_socket_locals_dict_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(ssl_socket_locals_dict, ssl_socket_locals_dict_table);
|
||||
|
||||
STATIC const mp_stream_p_t ussl_socket_stream_p = {
|
||||
STATIC const mp_stream_p_t ssl_socket_stream_p = {
|
||||
.read = socket_read,
|
||||
.write = socket_write,
|
||||
.ioctl = socket_ioctl,
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
ussl_socket_type,
|
||||
ssl_socket_type,
|
||||
// Save on qstr's, reuse same as for module
|
||||
MP_QSTR_ssl,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
print, socket_print,
|
||||
protocol, &ussl_socket_stream_p,
|
||||
locals_dict, &ussl_socket_locals_dict
|
||||
protocol, &ssl_socket_stream_p,
|
||||
locals_dict, &ssl_socket_locals_dict
|
||||
);
|
||||
|
||||
STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
|
@ -46,16 +46,16 @@ struct qentry {
|
||||
mp_obj_t args;
|
||||
};
|
||||
|
||||
typedef struct _mp_obj_utimeq_t {
|
||||
typedef struct _mp_obj_timeq_t {
|
||||
mp_obj_base_t base;
|
||||
mp_uint_t alloc;
|
||||
mp_uint_t len;
|
||||
struct qentry items[];
|
||||
} mp_obj_utimeq_t;
|
||||
} mp_obj_timeq_t;
|
||||
|
||||
STATIC mp_uint_t utimeq_id;
|
||||
STATIC mp_uint_t timeq_id;
|
||||
|
||||
STATIC mp_obj_utimeq_t *utimeq_get_heap(mp_obj_t heap_in) {
|
||||
STATIC mp_obj_timeq_t *timeq_get_heap(mp_obj_t heap_in) {
|
||||
return MP_OBJ_TO_PTR(heap_in);
|
||||
}
|
||||
|
||||
@ -74,17 +74,17 @@ STATIC bool time_less_than(struct qentry *item, struct qentry *parent) {
|
||||
return res && res < (MODULO / 2);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t utimeq_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t timeq_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
mp_uint_t alloc = mp_obj_get_int(args[0]);
|
||||
mp_obj_utimeq_t *o = mp_obj_malloc_var(mp_obj_utimeq_t, struct qentry, alloc, type);
|
||||
mp_obj_timeq_t *o = mp_obj_malloc_var(mp_obj_timeq_t, struct qentry, alloc, type);
|
||||
memset(o->items, 0, sizeof(*o->items) * alloc);
|
||||
o->alloc = alloc;
|
||||
o->len = 0;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC void utimeq_heap_siftdown(mp_obj_utimeq_t *heap, mp_uint_t start_pos, mp_uint_t pos) {
|
||||
STATIC void timeq_heap_siftdown(mp_obj_timeq_t *heap, mp_uint_t start_pos, mp_uint_t pos) {
|
||||
struct qentry item = heap->items[pos];
|
||||
while (pos > start_pos) {
|
||||
mp_uint_t parent_pos = (pos - 1) >> 1;
|
||||
@ -100,7 +100,7 @@ STATIC void utimeq_heap_siftdown(mp_obj_utimeq_t *heap, mp_uint_t start_pos, mp_
|
||||
heap->items[pos] = item;
|
||||
}
|
||||
|
||||
STATIC void utimeq_heap_siftup(mp_obj_utimeq_t *heap, mp_uint_t pos) {
|
||||
STATIC void timeq_heap_siftup(mp_obj_timeq_t *heap, mp_uint_t pos) {
|
||||
mp_uint_t start_pos = pos;
|
||||
mp_uint_t end_pos = heap->len;
|
||||
struct qentry item = heap->items[pos];
|
||||
@ -117,29 +117,29 @@ STATIC void utimeq_heap_siftup(mp_obj_utimeq_t *heap, mp_uint_t pos) {
|
||||
pos = child_pos;
|
||||
}
|
||||
heap->items[pos] = item;
|
||||
utimeq_heap_siftdown(heap, start_pos, pos);
|
||||
timeq_heap_siftdown(heap, start_pos, pos);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mod_utimeq_heappush(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t mod_timeq_heappush(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
mp_obj_t heap_in = args[0];
|
||||
mp_obj_utimeq_t *heap = utimeq_get_heap(heap_in);
|
||||
mp_obj_timeq_t *heap = timeq_get_heap(heap_in);
|
||||
if (heap->len == heap->alloc) {
|
||||
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("queue overflow"));
|
||||
}
|
||||
mp_uint_t l = heap->len;
|
||||
heap->items[l].time = MP_OBJ_SMALL_INT_VALUE(args[1]);
|
||||
heap->items[l].id = utimeq_id++;
|
||||
heap->items[l].id = timeq_id++;
|
||||
heap->items[l].callback = args[2];
|
||||
heap->items[l].args = args[3];
|
||||
utimeq_heap_siftdown(heap, 0, heap->len);
|
||||
timeq_heap_siftdown(heap, 0, heap->len);
|
||||
heap->len++;
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_utimeq_heappush_obj, 4, 4, mod_utimeq_heappush);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_timeq_heappush_obj, 4, 4, mod_timeq_heappush);
|
||||
|
||||
STATIC mp_obj_t mod_utimeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) {
|
||||
mp_obj_utimeq_t *heap = utimeq_get_heap(heap_in);
|
||||
STATIC mp_obj_t mod_timeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) {
|
||||
mp_obj_timeq_t *heap = timeq_get_heap(heap_in);
|
||||
if (heap->len == 0) {
|
||||
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap"));
|
||||
}
|
||||
@ -157,14 +157,14 @@ STATIC mp_obj_t mod_utimeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) {
|
||||
heap->items[heap->len].callback = MP_OBJ_NULL; // so we don't retain a pointer
|
||||
heap->items[heap->len].args = MP_OBJ_NULL;
|
||||
if (heap->len) {
|
||||
utimeq_heap_siftup(heap, 0);
|
||||
timeq_heap_siftup(heap, 0);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_utimeq_heappop_obj, mod_utimeq_heappop);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_timeq_heappop_obj, mod_timeq_heappop);
|
||||
|
||||
STATIC mp_obj_t mod_utimeq_peektime(mp_obj_t heap_in) {
|
||||
mp_obj_utimeq_t *heap = utimeq_get_heap(heap_in);
|
||||
STATIC mp_obj_t mod_timeq_peektime(mp_obj_t heap_in) {
|
||||
mp_obj_timeq_t *heap = timeq_get_heap(heap_in);
|
||||
if (heap->len == 0) {
|
||||
mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap"));
|
||||
}
|
||||
@ -172,22 +172,22 @@ STATIC mp_obj_t mod_utimeq_peektime(mp_obj_t heap_in) {
|
||||
struct qentry *item = &heap->items[0];
|
||||
return MP_OBJ_NEW_SMALL_INT(item->time);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_utimeq_peektime_obj, mod_utimeq_peektime);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_timeq_peektime_obj, mod_timeq_peektime);
|
||||
|
||||
#if DEBUG
|
||||
STATIC mp_obj_t mod_utimeq_dump(mp_obj_t heap_in) {
|
||||
mp_obj_utimeq_t *heap = utimeq_get_heap(heap_in);
|
||||
STATIC mp_obj_t mod_timeq_dump(mp_obj_t heap_in) {
|
||||
mp_obj_timeq_t *heap = timeq_get_heap(heap_in);
|
||||
for (int i = 0; i < heap->len; i++) {
|
||||
printf(UINT_FMT "\t%p\t%p\n", heap->items[i].time,
|
||||
MP_OBJ_TO_PTR(heap->items[i].callback), MP_OBJ_TO_PTR(heap->items[i].args));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_utimeq_dump_obj, mod_utimeq_dump);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_timeq_dump_obj, mod_timeq_dump);
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t utimeq_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
mp_obj_utimeq_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
STATIC mp_obj_t timeq_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
mp_obj_timeq_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
switch (op) {
|
||||
case MP_UNARY_OP_BOOL:
|
||||
return mp_obj_new_bool(self->len != 0);
|
||||
@ -198,29 +198,29 @@ STATIC mp_obj_t utimeq_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t utimeq_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_push), MP_ROM_PTR(&mod_utimeq_heappush_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&mod_utimeq_heappop_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_peektime), MP_ROM_PTR(&mod_utimeq_peektime_obj) },
|
||||
STATIC const mp_rom_map_elem_t timeq_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_push), MP_ROM_PTR(&mod_timeq_heappush_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&mod_timeq_heappop_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_peektime), MP_ROM_PTR(&mod_timeq_peektime_obj) },
|
||||
#if DEBUG
|
||||
{ MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_utimeq_dump_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_timeq_dump_obj) },
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(utimeq_locals_dict, utimeq_locals_dict_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(timeq_locals_dict, timeq_locals_dict_table);
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
utimeq_type,
|
||||
timeq_type,
|
||||
MP_QSTR_timeq,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, utimeq_make_new,
|
||||
unary_op, utimeq_unary_op,
|
||||
locals_dict, &utimeq_locals_dict
|
||||
make_new, timeq_make_new,
|
||||
unary_op, timeq_unary_op,
|
||||
locals_dict, &timeq_locals_dict
|
||||
);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_timeq_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_timeq) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_timeq), MP_ROM_PTR(&utimeq_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_timeq), MP_ROM_PTR(&timeq_type) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_timeq_globals, mp_module_timeq_globals_table);
|
||||
|
@ -299,16 +299,16 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &websocket_locals_dict
|
||||
);
|
||||
|
||||
STATIC const mp_rom_map_elem_t uwebsocket_module_globals_table[] = {
|
||||
STATIC const mp_rom_map_elem_t websocket_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_websocket) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_websocket), MP_ROM_PTR(&websocket_type) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(uwebsocket_module_globals, uwebsocket_module_globals_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(websocket_module_globals, websocket_module_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_websocket = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t *)&uwebsocket_module_globals,
|
||||
.globals = (mp_obj_dict_t *)&websocket_module_globals,
|
||||
};
|
||||
|
||||
MP_REGISTER_MODULE(MP_QSTR_websocket, mp_module_websocket);
|
||||
|
@ -150,7 +150,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
);
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t mod_zlib_decompress(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_t data = args[0];
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
|
||||
@ -164,7 +164,7 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
decomp->dest = dest_buf;
|
||||
decomp->dest_limit = dest_buf + dest_buf_size;
|
||||
DEBUG_printf("uzlib: Initial out buffer: " UINT_FMT " bytes\n", dest_buf_size);
|
||||
DEBUG_printf("zlib: Initial out buffer: " UINT_FMT " bytes\n", dest_buf_size);
|
||||
decomp->source = bufinfo.buf;
|
||||
decomp->source_limit = (byte *)bufinfo.buf + bufinfo.len;
|
||||
|
||||
@ -198,7 +198,7 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
|
||||
mp_uint_t final_sz = decomp->dest - dest_buf;
|
||||
DEBUG_printf("uzlib: Resizing from " UINT_FMT " to final size: " UINT_FMT " bytes\n", dest_buf_size, final_sz);
|
||||
DEBUG_printf("zlib: Resizing from " UINT_FMT " to final size: " UINT_FMT " bytes\n", dest_buf_size, final_sz);
|
||||
dest_buf = (byte *)m_renew(byte, dest_buf, dest_buf_size, final_sz);
|
||||
mp_obj_t res = mp_obj_new_bytearray_by_ref(final_sz, dest_buf);
|
||||
m_del_obj(TINF_DATA, decomp);
|
||||
@ -207,12 +207,12 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
||||
error:
|
||||
mp_raise_type_arg(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_decompress_obj, 1, 3, mod_uzlib_decompress);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_zlib_decompress_obj, 1, 3, mod_zlib_decompress);
|
||||
|
||||
#if !MICROPY_ENABLE_DYNRUNTIME
|
||||
STATIC const mp_rom_map_elem_t mp_module_zlib_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zlib) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&mod_uzlib_decompress_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&mod_zlib_decompress_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_DecompIO), MP_ROM_PTR(&decompio_type) },
|
||||
};
|
||||
|
||||
|
@ -41,14 +41,14 @@
|
||||
|
||||
/******************************************************************************/
|
||||
// The following set of macros and functions provide a glue between the CC3100
|
||||
// simplelink layer and the functions/methods provided by the usocket module.
|
||||
// They were historically in a separate file because usocket was designed to
|
||||
// simplelink layer and the functions/methods provided by the socket module.
|
||||
// They were historically in a separate file because socket was designed to
|
||||
// work with multiple NICs, and the wlan_XXX functions just provided one
|
||||
// particular NIC implementation (that of the CC3100). But the CC3200 port only
|
||||
// supports a single NIC (being the CC3100) so it's unnecessary and inefficient
|
||||
// to provide an intermediate wrapper layer. Hence the wlan_XXX functions
|
||||
// are provided below as static functions so they can be inlined directly by
|
||||
// the corresponding usocket calls.
|
||||
// the corresponding socket calls.
|
||||
|
||||
#define WLAN_MAX_RX_SIZE 16000
|
||||
#define WLAN_MAX_TX_SIZE 1476
|
||||
@ -769,11 +769,11 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
);
|
||||
|
||||
/******************************************************************************/
|
||||
// usocket module
|
||||
// socket module
|
||||
|
||||
// function usocket.getaddrinfo(host, port)
|
||||
// function socket.getaddrinfo(host, port)
|
||||
/// \function getaddrinfo(host, port)
|
||||
STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
|
||||
STATIC mp_obj_t mod_socket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
|
||||
size_t hlen;
|
||||
const char *host = mp_obj_str_get_data(host_in, &hlen);
|
||||
mp_int_t port = mp_obj_get_int(port_in);
|
||||
@ -792,13 +792,13 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
|
||||
tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_LITTLE);
|
||||
return mp_obj_new_list(1, (mp_obj_t*)&tuple);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_usocket_getaddrinfo_obj, mod_usocket_getaddrinfo);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_getaddrinfo_obj, mod_socket_getaddrinfo);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_usocket_getaddrinfo_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_socket_getaddrinfo_obj) },
|
||||
|
||||
// class constants
|
||||
{ MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(SL_AF_INET) },
|
||||
|
@ -125,7 +125,7 @@
|
||||
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0)
|
||||
#define MICROPY_KBD_EXCEPTION (1)
|
||||
|
||||
// We define our own list of errno constants to include in uerrno module
|
||||
// We define our own list of errno constants to include in errno module
|
||||
#define MICROPY_PY_UERRNO_LIST \
|
||||
X(EPERM) \
|
||||
X(EIO) \
|
||||
|
@ -225,7 +225,7 @@ soft_reset_exit:
|
||||
machine_pins_deinit();
|
||||
machine_deinit();
|
||||
#if MICROPY_PY_USOCKET_EVENTS
|
||||
usocket_events_deinit();
|
||||
socket_events_deinit();
|
||||
#endif
|
||||
|
||||
mp_deinit();
|
||||
|
@ -63,7 +63,7 @@ static inline void esp_exceptions(esp_err_t e) {
|
||||
}
|
||||
}
|
||||
|
||||
void usocket_events_deinit(void);
|
||||
void socket_events_deinit(void);
|
||||
void network_wlan_event_handler(system_event_t *event);
|
||||
void esp_initialise_wifi(void);
|
||||
|
||||
|
@ -87,22 +87,22 @@ void _socket_settimeout(socket_obj_t *sock, uint64_t timeout_ms);
|
||||
// This divisor is used to reduce the load on the system, so it doesn't poll sockets too often
|
||||
#define USOCKET_EVENTS_DIVISOR (8)
|
||||
|
||||
STATIC uint8_t usocket_events_divisor;
|
||||
STATIC socket_obj_t *usocket_events_head;
|
||||
STATIC uint8_t socket_events_divisor;
|
||||
STATIC socket_obj_t *socket_events_head;
|
||||
|
||||
void usocket_events_deinit(void) {
|
||||
usocket_events_head = NULL;
|
||||
void socket_events_deinit(void) {
|
||||
socket_events_head = NULL;
|
||||
}
|
||||
|
||||
// Assumes the socket is not already in the linked list, and adds it
|
||||
STATIC void usocket_events_add(socket_obj_t *sock) {
|
||||
sock->events_next = usocket_events_head;
|
||||
usocket_events_head = sock;
|
||||
STATIC void socket_events_add(socket_obj_t *sock) {
|
||||
sock->events_next = socket_events_head;
|
||||
socket_events_head = sock;
|
||||
}
|
||||
|
||||
// Assumes the socket is already in the linked list, and removes it
|
||||
STATIC void usocket_events_remove(socket_obj_t *sock) {
|
||||
for (socket_obj_t **s = &usocket_events_head;; s = &(*s)->events_next) {
|
||||
STATIC void socket_events_remove(socket_obj_t *sock) {
|
||||
for (socket_obj_t **s = &socket_events_head;; s = &(*s)->events_next) {
|
||||
if (*s == sock) {
|
||||
*s = (*s)->events_next;
|
||||
return;
|
||||
@ -111,20 +111,20 @@ STATIC void usocket_events_remove(socket_obj_t *sock) {
|
||||
}
|
||||
|
||||
// Polls all registered sockets for readability and calls their callback if they are readable
|
||||
void usocket_events_handler(void) {
|
||||
if (usocket_events_head == NULL) {
|
||||
void socket_events_handler(void) {
|
||||
if (socket_events_head == NULL) {
|
||||
return;
|
||||
}
|
||||
if (--usocket_events_divisor) {
|
||||
if (--socket_events_divisor) {
|
||||
return;
|
||||
}
|
||||
usocket_events_divisor = USOCKET_EVENTS_DIVISOR;
|
||||
socket_events_divisor = USOCKET_EVENTS_DIVISOR;
|
||||
|
||||
fd_set rfds;
|
||||
FD_ZERO(&rfds);
|
||||
int max_fd = 0;
|
||||
|
||||
for (socket_obj_t *s = usocket_events_head; s != NULL; s = s->events_next) {
|
||||
for (socket_obj_t *s = socket_events_head; s != NULL; s = s->events_next) {
|
||||
FD_SET(s->fd, &rfds);
|
||||
max_fd = MAX(max_fd, s->fd);
|
||||
}
|
||||
@ -137,7 +137,7 @@ void usocket_events_handler(void) {
|
||||
}
|
||||
|
||||
// Call the callbacks
|
||||
for (socket_obj_t *s = usocket_events_head; s != NULL; s = s->events_next) {
|
||||
for (socket_obj_t *s = socket_events_head; s != NULL; s = s->events_next) {
|
||||
if (FD_ISSET(s->fd, &rfds)) {
|
||||
mp_call_function_1_protected(s->events_callback, s);
|
||||
}
|
||||
@ -402,12 +402,12 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
|
||||
case 20: {
|
||||
if (args[3] == mp_const_none) {
|
||||
if (self->events_callback != MP_OBJ_NULL) {
|
||||
usocket_events_remove(self);
|
||||
socket_events_remove(self);
|
||||
self->events_callback = MP_OBJ_NULL;
|
||||
}
|
||||
} else {
|
||||
if (self->events_callback == MP_OBJ_NULL) {
|
||||
usocket_events_add(self);
|
||||
socket_events_add(self);
|
||||
}
|
||||
self->events_callback = args[3];
|
||||
}
|
||||
@ -736,7 +736,7 @@ STATIC mp_uint_t socket_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintpt
|
||||
if (socket->fd >= 0) {
|
||||
#if MICROPY_PY_USOCKET_EVENTS
|
||||
if (socket->events_callback != MP_OBJ_NULL) {
|
||||
usocket_events_remove(socket);
|
||||
socket_events_remove(socket);
|
||||
socket->events_callback = MP_OBJ_NULL;
|
||||
}
|
||||
#endif
|
||||
@ -871,5 +871,5 @@ const mp_obj_module_t mp_module_socket = {
|
||||
|
||||
// Note: This port doesn't define MICROPY_PY_USOCKET or MICROPY_PY_LWIP so
|
||||
// this will not conflict with the common implementation provided by
|
||||
// extmod/mod{lwip,usocket}.c.
|
||||
// extmod/mod{lwip,socket}.c.
|
||||
MP_REGISTER_MODULE(MP_QSTR_socket, mp_module_socket);
|
||||
|
@ -170,7 +170,7 @@ void *esp_native_code_commit(void *, size_t, void *);
|
||||
#define MICROPY_END_ATOMIC_SECTION(state) portEXIT_CRITICAL_NESTED(state)
|
||||
|
||||
#if MICROPY_PY_USOCKET_EVENTS
|
||||
#define MICROPY_PY_USOCKET_EVENTS_HANDLER extern void usocket_events_handler(void); usocket_events_handler();
|
||||
#define MICROPY_PY_USOCKET_EVENTS_HANDLER extern void socket_events_handler(void); socket_events_handler();
|
||||
#else
|
||||
#define MICROPY_PY_USOCKET_EVENTS_HANDLER
|
||||
#endif
|
||||
|
@ -43,7 +43,7 @@
|
||||
#include "gccollect.h"
|
||||
#include "modmachine.h"
|
||||
#include "modmusic.h"
|
||||
#include "modules/uos/microbitfs.h"
|
||||
#include "modules/os/microbitfs.h"
|
||||
#include "led.h"
|
||||
#include "uart.h"
|
||||
#include "nrf.h"
|
||||
@ -301,15 +301,15 @@ soft_reset:
|
||||
#if MICROPY_MBFS
|
||||
// Use micro:bit filesystem
|
||||
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
|
||||
return uos_mbfs_new_reader(filename);
|
||||
return os_mbfs_new_reader(filename);
|
||||
}
|
||||
|
||||
mp_import_stat_t mp_import_stat(const char *path) {
|
||||
return uos_mbfs_import_stat(path);
|
||||
return os_mbfs_import_stat(path);
|
||||
}
|
||||
|
||||
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||
return uos_mbfs_open(n_args, args);
|
||||
return os_mbfs_open(n_args, args);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
||||
|
||||
|
@ -121,8 +121,8 @@ typedef struct _persistent_config_t {
|
||||
uint8_t marker; // Should always be PERSISTENT_DATA_MARKER
|
||||
} persistent_config_t;
|
||||
|
||||
extern const mp_obj_type_t uos_mbfs_fileio_type;
|
||||
extern const mp_obj_type_t uos_mbfs_textio_type;
|
||||
extern const mp_obj_type_t os_mbfs_fileio_type;
|
||||
extern const mp_obj_type_t os_mbfs_textio_type;
|
||||
|
||||
// Page indexes count down from the end of ROM.
|
||||
STATIC uint8_t first_page_index;
|
||||
@ -360,7 +360,7 @@ STATIC file_descriptor_obj *microbit_file_open(const char *name, size_t name_len
|
||||
}
|
||||
|
||||
STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary) {
|
||||
file_descriptor_obj *res = mp_obj_malloc(file_descriptor_obj, binary ? &uos_mbfs_fileio_type : &uos_mbfs_textio_type);
|
||||
file_descriptor_obj *res = mp_obj_malloc(file_descriptor_obj, binary ? &os_mbfs_fileio_type : &os_mbfs_textio_type);
|
||||
res->start_chunk = start_chunk;
|
||||
res->seek_chunk = start_chunk;
|
||||
res->seek_offset = file_system_chunks[start_chunk].header.name_len+2;
|
||||
@ -511,9 +511,9 @@ STATIC mp_uint_t file_read_byte(file_descriptor_obj *fd) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// Now follows the code to integrate this filesystem into the uos module.
|
||||
// Now follows the code to integrate this filesystem into the os module.
|
||||
|
||||
mp_lexer_t *uos_mbfs_new_reader(const char *filename) {
|
||||
mp_lexer_t *os_mbfs_new_reader(const char *filename) {
|
||||
file_descriptor_obj *fd = microbit_file_open(filename, strlen(filename), false, false);
|
||||
if (fd == NULL) {
|
||||
mp_raise_OSError(MP_ENOENT);
|
||||
@ -525,7 +525,7 @@ mp_lexer_t *uos_mbfs_new_reader(const char *filename) {
|
||||
return mp_lexer_new(qstr_from_str(filename), reader);
|
||||
}
|
||||
|
||||
mp_import_stat_t uos_mbfs_import_stat(const char *path) {
|
||||
mp_import_stat_t os_mbfs_import_stat(const char *path) {
|
||||
uint8_t chunk = microbit_find_file(path, strlen(path));
|
||||
if (chunk == FILE_NOT_FOUND) {
|
||||
return MP_IMPORT_STAT_NO_EXIST;
|
||||
@ -534,38 +534,38 @@ mp_import_stat_t uos_mbfs_import_stat(const char *path) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uos_mbfs_file_name(mp_obj_t self) {
|
||||
STATIC mp_obj_t os_mbfs_file_name(mp_obj_t self) {
|
||||
file_descriptor_obj *fd = (file_descriptor_obj*)self;
|
||||
return microbit_file_name(fd);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_file_name_obj, uos_mbfs_file_name);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_name_obj, os_mbfs_file_name);
|
||||
|
||||
STATIC mp_obj_t uos_mbfs_file_close(mp_obj_t self) {
|
||||
STATIC mp_obj_t os_mbfs_file_close(mp_obj_t self) {
|
||||
file_descriptor_obj *fd = (file_descriptor_obj*)self;
|
||||
microbit_file_close(fd);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_file_close_obj, uos_mbfs_file_close);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_close_obj, os_mbfs_file_close);
|
||||
|
||||
STATIC mp_obj_t uos_mbfs_remove(mp_obj_t name) {
|
||||
STATIC mp_obj_t os_mbfs_remove(mp_obj_t name) {
|
||||
return microbit_remove(name);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_remove_obj, uos_mbfs_remove);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_remove_obj, os_mbfs_remove);
|
||||
|
||||
STATIC mp_obj_t uos_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t os_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
return uos_mbfs_file_close(args[0]);
|
||||
return os_mbfs_file_close(args[0]);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(uos_mbfs_file___exit___obj, 4, 4, uos_mbfs_file___exit__);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_mbfs_file___exit___obj, 4, 4, os_mbfs_file___exit__);
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
mp_fun_1_t iternext;
|
||||
uint8_t index;
|
||||
} uos_mbfs_ilistdir_it_t;
|
||||
} os_mbfs_ilistdir_it_t;
|
||||
|
||||
STATIC mp_obj_t uos_mbfs_ilistdir_it_iternext(mp_obj_t self_in) {
|
||||
uos_mbfs_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
STATIC mp_obj_t os_mbfs_ilistdir_it_iternext(mp_obj_t self_in) {
|
||||
os_mbfs_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
// Read until the next FILE_START chunk.
|
||||
for (; self->index <= chunks_in_file_system; self->index++) {
|
||||
@ -589,27 +589,27 @@ STATIC mp_obj_t uos_mbfs_ilistdir_it_iternext(mp_obj_t self_in) {
|
||||
return MP_OBJ_STOP_ITERATION;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uos_mbfs_ilistdir(void) {
|
||||
uos_mbfs_ilistdir_it_t *iter = mp_obj_malloc(uos_mbfs_ilistdir_it_t, &mp_type_polymorph_iter);
|
||||
iter->iternext = uos_mbfs_ilistdir_it_iternext;
|
||||
STATIC mp_obj_t os_mbfs_ilistdir(void) {
|
||||
os_mbfs_ilistdir_it_t *iter = mp_obj_malloc(os_mbfs_ilistdir_it_t, &mp_type_polymorph_iter);
|
||||
iter->iternext = os_mbfs_ilistdir_it_iternext;
|
||||
iter->index = 1;
|
||||
|
||||
return MP_OBJ_FROM_PTR(iter);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(uos_mbfs_ilistdir_obj, uos_mbfs_ilistdir);
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_ilistdir_obj, os_mbfs_ilistdir);
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(uos_mbfs_listdir_obj, microbit_file_list);
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_listdir_obj, microbit_file_list);
|
||||
|
||||
STATIC mp_obj_t microbit_file_writable(mp_obj_t self) {
|
||||
return mp_obj_new_bool(((file_descriptor_obj *)self)->writable);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_file_writable_obj, microbit_file_writable);
|
||||
|
||||
STATIC const mp_map_elem_t uos_mbfs_file_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&uos_mbfs_file_close_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_name), (mp_obj_t)&uos_mbfs_file_name_obj },
|
||||
STATIC const mp_map_elem_t os_mbfs_file_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&os_mbfs_file_close_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_name), (mp_obj_t)&os_mbfs_file_name_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR___enter__), (mp_obj_t)&mp_identity_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR___exit__), (mp_obj_t)&uos_mbfs_file___exit___obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR___exit__), (mp_obj_t)&os_mbfs_file___exit___obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_writable), (mp_obj_t)µbit_file_writable_obj },
|
||||
/* Stream methods */
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj },
|
||||
@ -617,7 +617,7 @@ STATIC const mp_map_elem_t uos_mbfs_file_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj},
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(uos_mbfs_file_locals_dict, uos_mbfs_file_locals_dict_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(os_mbfs_file_locals_dict, os_mbfs_file_locals_dict_table);
|
||||
|
||||
|
||||
STATIC const mp_stream_p_t textio_stream_p = {
|
||||
@ -627,11 +627,11 @@ STATIC const mp_stream_p_t textio_stream_p = {
|
||||
};
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
uos_mbfs_textio_type,
|
||||
os_mbfs_textio_type,
|
||||
MP_QSTR_TextIO,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
protocol, &textio_stream_p,
|
||||
locals_dict, &uos_mbfs_file_locals_dict
|
||||
locals_dict, &os_mbfs_file_locals_dict
|
||||
);
|
||||
|
||||
|
||||
@ -641,15 +641,15 @@ STATIC const mp_stream_p_t fileio_stream_p = {
|
||||
};
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
uos_mbfs_fileio_type,
|
||||
os_mbfs_fileio_type,
|
||||
MP_QSTR_FileIO,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
protocol, &fileio_stream_p,
|
||||
locals_dict, &uos_mbfs_file_locals_dict
|
||||
locals_dict, &os_mbfs_file_locals_dict
|
||||
);
|
||||
|
||||
// From micro:bit fileobj.c
|
||||
mp_obj_t uos_mbfs_open(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_t os_mbfs_open(size_t n_args, const mp_obj_t *args) {
|
||||
/// -1 means default; 0 explicitly false; 1 explicitly true.
|
||||
int read = -1;
|
||||
int text = -1;
|
||||
@ -683,7 +683,7 @@ mode_error:
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("illegal mode"));
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uos_mbfs_stat(mp_obj_t filename) {
|
||||
STATIC mp_obj_t os_mbfs_stat(mp_obj_t filename) {
|
||||
mp_obj_t file_size = microbit_file_size(filename);
|
||||
|
||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL));
|
||||
@ -699,6 +699,6 @@ STATIC mp_obj_t uos_mbfs_stat(mp_obj_t filename) {
|
||||
t->items[9] = MP_OBJ_NEW_SMALL_INT(0); // st_ctime
|
||||
return MP_OBJ_FROM_PTR(t);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(uos_mbfs_stat_obj, uos_mbfs_stat);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_stat_obj, os_mbfs_stat);
|
||||
|
||||
#endif // MICROPY_MBFS
|
||||
|
@ -40,14 +40,14 @@
|
||||
#define MBFS_LOG_CHUNK_SIZE 7
|
||||
#endif
|
||||
|
||||
mp_obj_t uos_mbfs_open(size_t n_args, const mp_obj_t *args);
|
||||
mp_obj_t os_mbfs_open(size_t n_args, const mp_obj_t *args);
|
||||
void microbit_filesystem_init(void);
|
||||
mp_lexer_t *uos_mbfs_new_reader(const char *filename);
|
||||
mp_import_stat_t uos_mbfs_import_stat(const char *path);
|
||||
mp_lexer_t *os_mbfs_new_reader(const char *filename);
|
||||
mp_import_stat_t os_mbfs_import_stat(const char *path);
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ_0(uos_mbfs_listdir_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_0(uos_mbfs_ilistdir_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(uos_mbfs_remove_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(uos_mbfs_stat_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_0(os_mbfs_listdir_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_0(os_mbfs_ilistdir_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(os_mbfs_remove_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(os_mbfs_stat_obj);
|
||||
|
||||
#endif // __MICROPY_INCLUDED_FILESYSTEM_H__
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "py/objstr.h"
|
||||
#include "lib/oofatfs/ff.h"
|
||||
#include "lib/oofatfs/diskio.h"
|
||||
#include "modules/uos/microbitfs.h"
|
||||
#include "modules/os/microbitfs.h"
|
||||
#include "extmod/vfs.h"
|
||||
#include "extmod/vfs_fat.h"
|
||||
#include "extmod/vfs_lfs.h"
|
||||
@ -158,10 +158,10 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mod_os_sync_obj) },
|
||||
|
||||
#elif MICROPY_MBFS
|
||||
{ MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&uos_mbfs_listdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&uos_mbfs_ilistdir_obj) }, // uses ~136 bytes
|
||||
{ MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&uos_mbfs_stat_obj) }, // uses ~228 bytes
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&uos_mbfs_remove_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&os_mbfs_listdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&os_mbfs_ilistdir_obj) }, // uses ~136 bytes
|
||||
{ MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&os_mbfs_stat_obj) }, // uses ~228 bytes
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_mbfs_remove_obj) },
|
||||
#endif
|
||||
|
||||
/// \constant sep - separation character used in paths
|
||||
|
@ -133,7 +133,7 @@
|
||||
#define MICROPY_FATFS_MAX_SS (4096)
|
||||
#endif
|
||||
|
||||
// Use port specific uos module rather than extmod variant.
|
||||
// Use port specific os module rather than extmod variant.
|
||||
#define MICROPY_PY_UOS (0)
|
||||
|
||||
#define MICROPY_STREAMS_NON_BLOCK (1)
|
||||
|
@ -30,7 +30,7 @@
|
||||
// Entries for sys.path
|
||||
Q(/flash)
|
||||
|
||||
// For uos.sep
|
||||
// For os.sep
|
||||
Q(/)
|
||||
|
||||
Q(a)
|
||||
|
@ -33,7 +33,7 @@ Q(/flash/lib)
|
||||
Q(/sd)
|
||||
Q(/sd/lib)
|
||||
|
||||
// For uos.sep
|
||||
// For os.sep
|
||||
Q(/)
|
||||
|
||||
#if MICROPY_HW_ENABLE_USB
|
||||
|
@ -116,7 +116,7 @@ STATIC mp_obj_t machine_unique_id(void) {
|
||||
// 0x0080a040: 50534b54 332e3120 ff091645
|
||||
//
|
||||
// MicroPython (this code and same order as shown in Arduino IDE)
|
||||
// >>> ubinascii.hexlify(machine.unique_id())
|
||||
// >>> binascii.hexlify(machine.unique_id())
|
||||
// b'6e27f15f50534b54332e3120ff091645'
|
||||
|
||||
#if defined(MCU_SAMD21)
|
||||
|
@ -89,7 +89,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_micros_obj, pyb_elapsed_micros);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(pyb_main_obj); // defined in main.c
|
||||
|
||||
// Get or set the UART object that the REPL is repeated on.
|
||||
// This is a legacy function, use of uos.dupterm is preferred.
|
||||
// This is a legacy function, use of os.dupterm is preferred.
|
||||
STATIC mp_obj_t pyb_repl_uart(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args == 0) {
|
||||
if (MP_STATE_PORT(pyb_stdio_uart) == NULL) {
|
||||
|
@ -33,7 +33,7 @@ Q(/flash/lib)
|
||||
Q(/sd)
|
||||
Q(/sd/lib)
|
||||
|
||||
// For uos.sep
|
||||
// For os.sep
|
||||
Q(/)
|
||||
|
||||
#if MICROPY_HW_ENABLE_USB
|
||||
|
@ -66,7 +66,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(pyb_rng_get_obj, pyb_rng_get);
|
||||
// For MCUs that don't have an RNG we still need to provide a rng_get() function,
|
||||
// eg for lwIP and random.seed(). A pseudo-RNG is not really ideal but we go with
|
||||
// it for now, seeding with numbers which will be somewhat different each time. We
|
||||
// don't want to use urandom's pRNG because then the user won't see a reproducible
|
||||
// don't want to use random's pRNG because then the user won't see a reproducible
|
||||
// random stream.
|
||||
|
||||
// Yasmarang random number generator by Ilya Levin
|
||||
|
@ -364,7 +364,7 @@ STATIC mp_obj_t extra_coverage(void) {
|
||||
mp_repl_autocomplete("import ", 7, &mp_plat_print, &str);
|
||||
len = mp_repl_autocomplete("import ut", 9, &mp_plat_print, &str);
|
||||
mp_printf(&mp_plat_print, "%.*s\n", (int)len, str);
|
||||
mp_repl_autocomplete("import utime", 12, &mp_plat_print, &str);
|
||||
mp_repl_autocomplete("import time", 12, &mp_plat_print, &str);
|
||||
|
||||
mp_store_global(MP_QSTR_sys, mp_import_name(MP_QSTR_sys, mp_const_none, MP_OBJ_NEW_SMALL_INT(0)));
|
||||
mp_repl_autocomplete("sys.", 4, &mp_plat_print, &str);
|
||||
|
@ -54,11 +54,10 @@
|
||||
/*
|
||||
The idea of this module is to implement reasonable minimum of
|
||||
socket-related functions to write typical clients and servers.
|
||||
The module named "usocket" on purpose, to allow to make
|
||||
Python-level module more (or fully) compatible with CPython
|
||||
"socket", e.g.:
|
||||
It's then possible to make a Python-level module more (or fully)
|
||||
compatible with CPython "socket", e.g.:
|
||||
---- socket.py ----
|
||||
from usocket import *
|
||||
from socket import *
|
||||
from socket_more_funcs import *
|
||||
from socket_more_funcs2 import *
|
||||
-------------------
|
||||
@ -487,7 +486,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, siz
|
||||
return MP_OBJ_FROM_PTR(socket_new(fd));
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t usocket_locals_dict_table[] = {
|
||||
STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_fileno), MP_ROM_PTR(&socket_fileno_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_makefile), MP_ROM_PTR(&socket_makefile_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
|
||||
@ -508,9 +507,9 @@ STATIC const mp_rom_map_elem_t usocket_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(usocket_locals_dict, usocket_locals_dict_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table);
|
||||
|
||||
STATIC const mp_stream_p_t usocket_stream_p = {
|
||||
STATIC const mp_stream_p_t socket_stream_p = {
|
||||
.read = socket_read,
|
||||
.write = socket_write,
|
||||
.ioctl = socket_ioctl,
|
||||
@ -522,8 +521,8 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, socket_make_new,
|
||||
print, socket_print,
|
||||
protocol, &usocket_stream_p,
|
||||
locals_dict, &usocket_locals_dict
|
||||
protocol, &socket_stream_p,
|
||||
locals_dict, &socket_locals_dict
|
||||
);
|
||||
|
||||
#define BINADDR_MAX_LEN sizeof(struct in6_addr)
|
||||
|
@ -255,7 +255,7 @@ void mp_hal_get_random(size_t n, void *buf) {
|
||||
#ifdef _HAVE_GETRANDOM
|
||||
RAISE_ERRNO(getrandom(buf, n, 0), errno);
|
||||
#else
|
||||
int fd = open("/dev/urandom", O_RDONLY);
|
||||
int fd = open("/dev/random", O_RDONLY);
|
||||
RAISE_ERRNO(fd, errno);
|
||||
RAISE_ERRNO(read(fd, buf, n), errno);
|
||||
close(fd);
|
||||
|
@ -1273,7 +1273,7 @@ typedef double mp_float_t;
|
||||
#define MICROPY_PY_COLLECTIONS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES)
|
||||
#endif
|
||||
|
||||
// Whether to provide "ucollections.deque" type
|
||||
// Whether to provide "collections.deque" type
|
||||
#ifndef MICROPY_PY_COLLECTIONS_DEQUE
|
||||
#define MICROPY_PY_COLLECTIONS_DEQUE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
|
||||
#endif
|
||||
@ -1458,44 +1458,44 @@ typedef double mp_float_t;
|
||||
#define MICROPY_PY_SYS_ATTR_DELEGATION (MICROPY_PY_SYS_PS1_PS2 || MICROPY_PY_SYS_TRACEBACKLIMIT)
|
||||
#endif
|
||||
|
||||
// Whether to provide "uerrno" module
|
||||
// Whether to provide "errno" module
|
||||
#ifndef MICROPY_PY_UERRNO
|
||||
#define MICROPY_PY_UERRNO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
|
||||
#endif
|
||||
|
||||
// Whether to provide the uerrno.errorcode dict
|
||||
// Whether to provide the errno.errorcode dict
|
||||
#ifndef MICROPY_PY_UERRNO_ERRORCODE
|
||||
#define MICROPY_PY_UERRNO_ERRORCODE (1)
|
||||
#endif
|
||||
|
||||
// Whether to provide "uselect" module (baremetal implementation)
|
||||
// Whether to provide "select" module (baremetal implementation)
|
||||
#ifndef MICROPY_PY_USELECT
|
||||
#define MICROPY_PY_USELECT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
|
||||
#endif
|
||||
|
||||
// Whether to enable the select() function in the "uselect" module (baremetal
|
||||
// Whether to enable the select() function in the "select" module (baremetal
|
||||
// implementation). This is present for compatibility but can be disabled to
|
||||
// save space.
|
||||
#ifndef MICROPY_PY_USELECT_SELECT
|
||||
#define MICROPY_PY_USELECT_SELECT (1)
|
||||
#endif
|
||||
|
||||
// Whether to provide the "utime" module
|
||||
// Whether to provide the "time" module
|
||||
#ifndef MICROPY_PY_UTIME
|
||||
#define MICROPY_PY_UTIME (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_BASIC_FEATURES)
|
||||
#endif
|
||||
|
||||
// Whether to provide utime.gmtime/localtime/mktime functions
|
||||
// Whether to provide time.gmtime/localtime/mktime functions
|
||||
#ifndef MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME
|
||||
#define MICROPY_PY_UTIME_GMTIME_LOCALTIME_MKTIME (0)
|
||||
#endif
|
||||
|
||||
// Whether to provide utime.time/time_ns functions
|
||||
// Whether to provide time.time/time_ns functions
|
||||
#ifndef MICROPY_PY_UTIME_TIME_TIME_NS
|
||||
#define MICROPY_PY_UTIME_TIME_TIME_NS (0)
|
||||
#endif
|
||||
|
||||
// Period of values returned by utime.ticks_ms(), ticks_us(), ticks_cpu()
|
||||
// Period of values returned by time.ticks_ms(), ticks_us(), ticks_cpu()
|
||||
// functions. Should be power of two. All functions above use the same
|
||||
// period, so if underlying hardware/API has different periods, the
|
||||
// minimum of them should be used. The value below is the maximum value
|
||||
@ -1686,7 +1686,7 @@ typedef double mp_float_t;
|
||||
#define MICROPY_PY_USSL (0)
|
||||
#endif
|
||||
|
||||
// Whether to add finaliser code to ussl objects
|
||||
// Whether to add finaliser code to ssl objects
|
||||
#ifndef MICROPY_PY_USSL_FINALISER
|
||||
#define MICROPY_PY_USSL_FINALISER (0)
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user