Commit bb4c6f35 authored by Damien George's avatar Damien George
Browse files

py: Make MP_OBJ_NEW_SMALL_INT cast arg to mp_int_t itself.

Addresses issue #724.
parent fa1ecda3
...@@ -296,13 +296,13 @@ static inline void set_aligned_basic(uint val_type, void *p, mp_uint_t v) { ...@@ -296,13 +296,13 @@ static inline void set_aligned_basic(uint val_type, void *p, mp_uint_t v) {
STATIC mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) { STATIC mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) {
switch (val_type) { switch (val_type) {
case UINT8: case UINT8:
return MP_OBJ_NEW_SMALL_INT((mp_int_t)((uint8_t*)p)[index]); return MP_OBJ_NEW_SMALL_INT(((uint8_t*)p)[index]);
case INT8: case INT8:
return MP_OBJ_NEW_SMALL_INT((mp_int_t)((int8_t*)p)[index]); return MP_OBJ_NEW_SMALL_INT(((int8_t*)p)[index]);
case UINT16: case UINT16:
return MP_OBJ_NEW_SMALL_INT((mp_int_t)((uint16_t*)p)[index]); return MP_OBJ_NEW_SMALL_INT(((uint16_t*)p)[index]);
case INT16: case INT16:
return MP_OBJ_NEW_SMALL_INT((mp_int_t)((int16_t*)p)[index]); return MP_OBJ_NEW_SMALL_INT(((int16_t*)p)[index]);
case UINT32: case UINT32:
return mp_obj_new_int_from_uint(((uint32_t*)p)[index]); return mp_obj_new_int_from_uint(((uint32_t*)p)[index]);
case INT32: case INT32:
......
...@@ -42,7 +42,7 @@ extern uint gc_collected; ...@@ -42,7 +42,7 @@ extern uint gc_collected;
STATIC mp_obj_t py_gc_collect(void) { STATIC mp_obj_t py_gc_collect(void) {
gc_collect(); gc_collect();
#if MICROPY_PY_GC_COLLECT_RETVAL #if MICROPY_PY_GC_COLLECT_RETVAL
return MP_OBJ_NEW_SMALL_INT((mp_uint_t)gc_collected); return MP_OBJ_NEW_SMALL_INT(gc_collected);
#else #else
return mp_const_none; return mp_const_none;
#endif #endif
...@@ -64,14 +64,14 @@ MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable); ...@@ -64,14 +64,14 @@ MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable);
STATIC mp_obj_t gc_mem_free(void) { STATIC mp_obj_t gc_mem_free(void) {
gc_info_t info; gc_info_t info;
gc_info(&info); gc_info(&info);
return MP_OBJ_NEW_SMALL_INT((mp_uint_t)info.free); return MP_OBJ_NEW_SMALL_INT(info.free);
} }
MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_free_obj, gc_mem_free); MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_free_obj, gc_mem_free);
STATIC mp_obj_t gc_mem_alloc(void) { STATIC mp_obj_t gc_mem_alloc(void) {
gc_info_t info; gc_info_t info;
gc_info(&info); gc_info(&info);
return MP_OBJ_NEW_SMALL_INT((mp_uint_t)info.used); return MP_OBJ_NEW_SMALL_INT(info.used);
} }
MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_alloc_obj, gc_mem_alloc); MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_alloc_obj, gc_mem_alloc);
......
...@@ -35,15 +35,15 @@ ...@@ -35,15 +35,15 @@
#if MICROPY_MEM_STATS #if MICROPY_MEM_STATS
STATIC mp_obj_t mp_micropython_mem_total() { STATIC mp_obj_t mp_micropython_mem_total() {
return MP_OBJ_NEW_SMALL_INT((mp_int_t)m_get_total_bytes_allocated()); return MP_OBJ_NEW_SMALL_INT(m_get_total_bytes_allocated());
} }
STATIC mp_obj_t mp_micropython_mem_current() { STATIC mp_obj_t mp_micropython_mem_current() {
return MP_OBJ_NEW_SMALL_INT((mp_int_t)m_get_current_bytes_allocated()); return MP_OBJ_NEW_SMALL_INT(m_get_current_bytes_allocated());
} }
STATIC mp_obj_t mp_micropython_mem_peak() { STATIC mp_obj_t mp_micropython_mem_peak() {
return MP_OBJ_NEW_SMALL_INT((mp_int_t)m_get_peak_bytes_allocated()); return MP_OBJ_NEW_SMALL_INT(m_get_peak_bytes_allocated());
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_total_obj, mp_micropython_mem_total); STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_total_obj, mp_micropython_mem_total);
......
...@@ -368,7 +368,7 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) { ...@@ -368,7 +368,7 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
MP_OBJ_IS_STR(o_in) || MP_OBJ_IS_STR(o_in) ||
#endif #endif
MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) { MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) {
return MP_OBJ_NEW_SMALL_INT((mp_int_t)mp_obj_str_get_len(o_in)); return MP_OBJ_NEW_SMALL_INT(mp_obj_str_get_len(o_in));
} else { } else {
mp_obj_type_t *type = mp_obj_get_type(o_in); mp_obj_type_t *type = mp_obj_get_type(o_in);
if (type->unary_op != NULL) { if (type->unary_op != NULL) {
......
...@@ -76,10 +76,10 @@ typedef struct _mp_obj_base_t mp_obj_base_t; ...@@ -76,10 +76,10 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
#define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str)) #define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str))
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1) #define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)
#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)(((small_int) << 1) | 1)) #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_int_t)(small_int)) << 1) | 1))
#define MP_OBJ_QSTR_VALUE(o) (((mp_int_t)(o)) >> 2) #define MP_OBJ_QSTR_VALUE(o) (((mp_int_t)(o)) >> 2)
#define MP_OBJ_NEW_QSTR(qstr) ((mp_obj_t)((((mp_uint_t)qstr) << 2) | 2)) #define MP_OBJ_NEW_QSTR(qstr) ((mp_obj_t)((((mp_uint_t)(qstr)) << 2) | 2))
// These macros are used to declare and define constant function objects // These macros are used to declare and define constant function objects
// You can put "static" in front of the definitions to make them local // You can put "static" in front of the definitions to make them local
......
...@@ -74,7 +74,7 @@ STATIC mp_obj_t bool_unary_op(int op, mp_obj_t o_in) { ...@@ -74,7 +74,7 @@ STATIC mp_obj_t bool_unary_op(int op, mp_obj_t o_in) {
STATIC mp_obj_t bool_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { STATIC mp_obj_t bool_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
if (MP_BINARY_OP_OR <= op && op <= MP_BINARY_OP_NOT_EQUAL) { if (MP_BINARY_OP_OR <= op && op <= MP_BINARY_OP_NOT_EQUAL) {
return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT((mp_int_t)mp_obj_is_true(lhs_in)), rhs_in); return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT(mp_obj_is_true(lhs_in)), rhs_in);
} }
return MP_OBJ_NULL; // op not supported return MP_OBJ_NULL; // op not supported
} }
......
...@@ -75,7 +75,7 @@ STATIC mp_obj_t dict_unary_op(int op, mp_obj_t self_in) { ...@@ -75,7 +75,7 @@ STATIC mp_obj_t dict_unary_op(int op, mp_obj_t self_in) {
mp_obj_dict_t *self = self_in; mp_obj_dict_t *self = self_in;
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(self->map.used != 0); case MP_UNARY_OP_BOOL: return MP_BOOL(self->map.used != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->map.used); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->map.used);
default: return MP_OBJ_NULL; // op not supported default: return MP_OBJ_NULL; // op not supported
} }
} }
......
...@@ -64,7 +64,7 @@ STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, co ...@@ -64,7 +64,7 @@ STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, co
return mp_parse_num_integer(s, l, 0); return mp_parse_num_integer(s, l, 0);
#if MICROPY_PY_BUILTINS_FLOAT #if MICROPY_PY_BUILTINS_FLOAT
} else if (MP_OBJ_IS_TYPE(args[0], &mp_type_float)) { } else if (MP_OBJ_IS_TYPE(args[0], &mp_type_float)) {
return MP_OBJ_NEW_SMALL_INT((mp_int_t)(MICROPY_FLOAT_C_FUN(trunc)(mp_obj_float_get(args[0])))); return MP_OBJ_NEW_SMALL_INT((MICROPY_FLOAT_C_FUN(trunc)(mp_obj_float_get(args[0]))));
#endif #endif
} else { } else {
// try to convert to small int (eg from bool) // try to convert to small int (eg from bool)
......
...@@ -476,7 +476,7 @@ STATIC mp_obj_t set_unary_op(int op, mp_obj_t self_in) { ...@@ -476,7 +476,7 @@ STATIC mp_obj_t set_unary_op(int op, mp_obj_t self_in) {
mp_obj_set_t *self = self_in; mp_obj_set_t *self = self_in;
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(self->set.used != 0); case MP_UNARY_OP_BOOL: return MP_BOOL(self->set.used != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->set.used); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->set.used);
default: return MP_OBJ_NULL; // op not supported default: return MP_OBJ_NULL; // op not supported
} }
} }
......
...@@ -370,7 +370,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { ...@@ -370,7 +370,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
#endif #endif
const byte *p = str_index_to_ptr(type, self_data, self_len, index, false); const byte *p = str_index_to_ptr(type, self_data, self_len, index, false);
if (type == &mp_type_bytes) { if (type == &mp_type_bytes) {
return MP_OBJ_NEW_SMALL_INT((mp_int_t)*p); return MP_OBJ_NEW_SMALL_INT(*p);
} else { } else {
return mp_obj_new_str((char*)p, 1, true); return mp_obj_new_str((char*)p, 1, true);
} }
...@@ -1917,7 +1917,7 @@ STATIC mp_obj_t bytes_it_iternext(mp_obj_t self_in) { ...@@ -1917,7 +1917,7 @@ STATIC mp_obj_t bytes_it_iternext(mp_obj_t self_in) {
mp_obj_str_it_t *self = self_in; mp_obj_str_it_t *self = self_in;
GET_STR_DATA_LEN(self->str, str, len); GET_STR_DATA_LEN(self->str, str, len);
if (self->cur < len) { if (self->cur < len) {
mp_obj_t o_out = MP_OBJ_NEW_SMALL_INT((mp_int_t)str[self->cur]); mp_obj_t o_out = MP_OBJ_NEW_SMALL_INT(str[self->cur]);
self->cur += 1; self->cur += 1;
return o_out; return o_out;
} else { } else {
......
...@@ -257,7 +257,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { ...@@ -257,7 +257,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
#endif #endif
if (type == &mp_type_bytes) { if (type == &mp_type_bytes) {
uint index_val = mp_get_index(type, self_len, index, false); uint index_val = mp_get_index(type, self_len, index, false);
return MP_OBJ_NEW_SMALL_INT((mp_int_t)self_data[index_val]); return MP_OBJ_NEW_SMALL_INT(self_data[index_val]);
} }
const byte *s = str_index_to_ptr(type, self_data, self_len, index, false); const byte *s = str_index_to_ptr(type, self_data, self_len, index, false);
int len = 1; int len = 1;
......
...@@ -206,7 +206,7 @@ STATIC mp_obj_t file_obj_make_new(mp_obj_t type, uint n_args, uint n_kw, const m ...@@ -206,7 +206,7 @@ STATIC mp_obj_t file_obj_make_new(mp_obj_t type, uint n_args, uint n_kw, const m
FRESULT res = f_open(&o->fp, fname, mode); FRESULT res = f_open(&o->fp, fname, mode);
if (res != FR_OK) { if (res != FR_OK) {
m_del_obj(pyb_file_obj_t, o); m_del_obj(pyb_file_obj_t, o);
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)fresult_to_errno_table[res]))); nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
} }
// for 'a' mode, we must begin at the end of the file // for 'a' mode, we must begin at the end of the file
......
...@@ -352,7 +352,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name); ...@@ -352,7 +352,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name);
/// Get the pin port. /// Get the pin port.
STATIC mp_obj_t pin_port(mp_obj_t self_in) { STATIC mp_obj_t pin_port(mp_obj_t self_in) {
pin_obj_t *self = self_in; pin_obj_t *self = self_in;
return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->port); return MP_OBJ_NEW_SMALL_INT(self->port);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port); STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port);
...@@ -360,7 +360,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port); ...@@ -360,7 +360,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port);
/// Get the pin number. /// Get the pin number.
STATIC mp_obj_t pin_pin(mp_obj_t self_in) { STATIC mp_obj_t pin_pin(mp_obj_t self_in) {
pin_obj_t *self = self_in; pin_obj_t *self = self_in;
return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->pin); return MP_OBJ_NEW_SMALL_INT(self->pin);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin); STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin);
......
...@@ -114,7 +114,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fdfile___exit___obj, 4, 4, fdfile___e ...@@ -114,7 +114,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fdfile___exit___obj, 4, 4, fdfile___e
STATIC mp_obj_t fdfile_fileno(mp_obj_t self_in) { STATIC mp_obj_t fdfile_fileno(mp_obj_t self_in) {
mp_obj_fdfile_t *self = self_in; mp_obj_fdfile_t *self = self_in;
check_fd_is_open(self); check_fd_is_open(self);
return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->fd); return MP_OBJ_NEW_SMALL_INT(self->fd);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(fdfile_fileno_obj, fdfile_fileno); STATIC MP_DEFINE_CONST_FUN_OBJ_1(fdfile_fileno_obj, fdfile_fileno);
...@@ -167,7 +167,7 @@ STATIC mp_obj_t fdfile_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const ...@@ -167,7 +167,7 @@ STATIC mp_obj_t fdfile_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
const char *fname = mp_obj_str_get_str(args[0]); const char *fname = mp_obj_str_get_str(args[0]);
int fd = open(fname, mode, 0644); int fd = open(fname, mode, 0644);
if (fd == -1) { if (fd == -1) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)errno))); nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno)));
} }
o->fd = fd; o->fd = fd;
return o; return o;
......
...@@ -179,7 +179,7 @@ STATIC mp_obj_t ffimod_func(uint n_args, const mp_obj_t *args) { ...@@ -179,7 +179,7 @@ STATIC mp_obj_t ffimod_func(uint n_args, const mp_obj_t *args) {
void *sym = dlsym(self->handle, symname); void *sym = dlsym(self->handle, symname);
if (sym == NULL) { if (sym == NULL) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)errno))); nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno)));
} }
int nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(args[3])); int nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(args[3]));
mp_obj_ffifunc_t *o = m_new_obj_var(mp_obj_ffifunc_t, ffi_type*, nparams); mp_obj_ffifunc_t *o = m_new_obj_var(mp_obj_ffifunc_t, ffi_type*, nparams);
...@@ -253,7 +253,7 @@ STATIC mp_obj_t ffimod_var(mp_obj_t self_in, mp_obj_t vartype_in, mp_obj_t symna ...@@ -253,7 +253,7 @@ STATIC mp_obj_t ffimod_var(mp_obj_t self_in, mp_obj_t vartype_in, mp_obj_t symna
void *sym = dlsym(self->handle, symname); void *sym = dlsym(self->handle, symname);
if (sym == NULL) { if (sym == NULL) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)errno))); nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno)));
} }
mp_obj_ffivar_t *o = m_new_obj(mp_obj_ffivar_t); mp_obj_ffivar_t *o = m_new_obj(mp_obj_ffivar_t);
o->base.type = &ffivar_type; o->base.type = &ffivar_type;
...@@ -269,7 +269,7 @@ STATIC mp_obj_t ffimod_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const ...@@ -269,7 +269,7 @@ STATIC mp_obj_t ffimod_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
void *mod = dlopen(fname, RTLD_NOW | RTLD_LOCAL); void *mod = dlopen(fname, RTLD_NOW | RTLD_LOCAL);
if (mod == NULL) { if (mod == NULL) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)errno))); nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno)));
} }
mp_obj_ffimod_t *o = m_new_obj(mp_obj_ffimod_t); mp_obj_ffimod_t *o = m_new_obj(mp_obj_ffimod_t);
o->base.type = type_in; o->base.type = type_in;
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#define RAISE_ERRNO(err_flag, error_val) \ #define RAISE_ERRNO(err_flag, error_val) \
{ if (err_flag == -1) \ { if (err_flag == -1) \
{ nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)error_val))); } } { nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(error_val))); } }
STATIC mp_obj_t mod_os_stat(mp_obj_t path_in) { STATIC mp_obj_t mod_os_stat(mp_obj_t path_in) {
struct stat sb; struct stat sb;
...@@ -51,12 +51,12 @@ STATIC mp_obj_t mod_os_stat(mp_obj_t path_in) { ...@@ -51,12 +51,12 @@ STATIC mp_obj_t mod_os_stat(mp_obj_t path_in) {
RAISE_ERRNO(res, errno); RAISE_ERRNO(res, errno);
mp_obj_tuple_t *t = mp_obj_new_tuple(10, NULL); mp_obj_tuple_t *t = mp_obj_new_tuple(10, NULL);
t->items[0] = MP_OBJ_NEW_SMALL_INT((mp_int_t)sb.st_mode); t->items[0] = MP_OBJ_NEW_SMALL_INT(sb.st_mode);
t->items[1] = MP_OBJ_NEW_SMALL_INT((mp_int_t)sb.st_ino); t->items[1] = MP_OBJ_NEW_SMALL_INT(sb.st_ino);
t->items[2] = MP_OBJ_NEW_SMALL_INT((mp_int_t)sb.st_dev); t->items[2] = MP_OBJ_NEW_SMALL_INT(sb.st_dev);
t->items[3] = MP_OBJ_NEW_SMALL_INT((mp_int_t)sb.st_nlink); t->items[3] = MP_OBJ_NEW_SMALL_INT(sb.st_nlink);
t->items[4] = MP_OBJ_NEW_SMALL_INT((mp_int_t)sb.st_uid); t->items[4] = MP_OBJ_NEW_SMALL_INT(sb.st_uid);
t->items[5] = MP_OBJ_NEW_SMALL_INT((mp_int_t)sb.st_gid); t->items[5] = MP_OBJ_NEW_SMALL_INT(sb.st_gid);
t->items[6] = MP_OBJ_NEW_SMALL_INT(sb.st_size); t->items[6] = MP_OBJ_NEW_SMALL_INT(sb.st_size);
t->items[7] = MP_OBJ_NEW_SMALL_INT(sb.st_atime); t->items[7] = MP_OBJ_NEW_SMALL_INT(sb.st_atime);
t->items[8] = MP_OBJ_NEW_SMALL_INT(sb.st_mtime); t->items[8] = MP_OBJ_NEW_SMALL_INT(sb.st_mtime);
......
...@@ -76,7 +76,7 @@ STATIC const mp_obj_type_t microsocket_type; ...@@ -76,7 +76,7 @@ STATIC const mp_obj_type_t microsocket_type;
// Helper functions // Helper functions
#define RAISE_ERRNO(err_flag, error_val) \ #define RAISE_ERRNO(err_flag, error_val) \
{ if (err_flag == -1) \ { if (err_flag == -1) \
{ nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)error_val))); } } { nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(error_val))); } }
STATIC mp_obj_socket_t *socket_new(int fd) { STATIC mp_obj_socket_t *socket_new(int fd) {
mp_obj_socket_t *o = m_new_obj(mp_obj_socket_t); mp_obj_socket_t *o = m_new_obj(mp_obj_socket_t);
...@@ -120,7 +120,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close); ...@@ -120,7 +120,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close);
STATIC mp_obj_t socket_fileno(mp_obj_t self_in) { STATIC mp_obj_t socket_fileno(mp_obj_t self_in) {
mp_obj_socket_t *self = self_in; mp_obj_socket_t *self = self_in;
return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->fd); return MP_OBJ_NEW_SMALL_INT(self->fd);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_fileno_obj, socket_fileno); STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_fileno_obj, socket_fileno);
...@@ -205,7 +205,7 @@ STATIC mp_obj_t socket_send(uint n_args, const mp_obj_t *args) { ...@@ -205,7 +205,7 @@ STATIC mp_obj_t socket_send(uint n_args, const mp_obj_t *args) {
int out_sz = send(self->fd, bufinfo.buf, bufinfo.len, flags); int out_sz = send(self->fd, bufinfo.buf, bufinfo.len, flags);
RAISE_ERRNO(out_sz, errno); RAISE_ERRNO(out_sz, errno);
return MP_OBJ_NEW_SMALL_INT((mp_int_t)out_sz); return MP_OBJ_NEW_SMALL_INT(out_sz);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_send_obj, 2, 3, socket_send); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_send_obj, 2, 3, socket_send);
...@@ -255,7 +255,7 @@ STATIC mp_obj_t socket_makefile(uint n_args, const mp_obj_t *args) { ...@@ -255,7 +255,7 @@ STATIC mp_obj_t socket_makefile(uint n_args, const mp_obj_t *args) {
mp_obj_socket_t *self = args[0]; mp_obj_socket_t *self = args[0];
mp_obj_t *new_args = alloca(n_args * sizeof(mp_obj_t)); mp_obj_t *new_args = alloca(n_args * sizeof(mp_obj_t));
memcpy(new_args + 1, args + 1, (n_args - 1) * sizeof(mp_obj_t)); memcpy(new_args + 1, args + 1, (n_args - 1) * sizeof(mp_obj_t));
new_args[0] = MP_OBJ_NEW_SMALL_INT((mp_int_t)self->fd); new_args[0] = MP_OBJ_NEW_SMALL_INT(self->fd);
return mp_builtin_open(n_args, new_args); return mp_builtin_open(n_args, new_args);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile);
...@@ -321,7 +321,7 @@ STATIC const mp_obj_type_t microsocket_type = { ...@@ -321,7 +321,7 @@ STATIC const mp_obj_type_t microsocket_type = {
#if MICROPY_SOCKET_EXTRA #if MICROPY_SOCKET_EXTRA
STATIC mp_obj_t mod_socket_htons(mp_obj_t arg) { STATIC mp_obj_t mod_socket_htons(mp_obj_t arg) {
return MP_OBJ_NEW_SMALL_INT((mp_int_t)htons(MP_OBJ_SMALL_INT_VALUE(arg))); return MP_OBJ_NEW_SMALL_INT(htons(MP_OBJ_SMALL_INT_VALUE(arg)));
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_htons_obj, mod_socket_htons); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_htons_obj, mod_socket_htons);
...@@ -343,7 +343,7 @@ STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) { ...@@ -343,7 +343,7 @@ STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) {
struct hostent *h = gethostbyname(s); struct hostent *h = gethostbyname(s);
if (h == NULL) { if (h == NULL) {
// CPython: socket.herror // CPython: socket.herror
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT((mp_int_t)h_errno))); nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(h_errno)));
} }
assert(h->h_length == 4); assert(h->h_length == 4);
return mp_obj_new_int(*(int*)*h->h_addr_list); return mp_obj_new_int(*(int*)*h->h_addr_list);
...@@ -397,9 +397,9 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { ...@@ -397,9 +397,9 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) {
mp_obj_t list = mp_obj_new_list(0, NULL); mp_obj_t list = mp_obj_new_list(0, NULL);
for (struct addrinfo *addr = addr_list; addr; addr = addr->ai_next) { for (struct addrinfo *addr = addr_list; addr; addr = addr->ai_next) {
mp_obj_tuple_t *t = mp_obj_new_tuple(5, NULL); mp_obj_tuple_t *t = mp_obj_new_tuple(5, NULL);
t->items[0] = MP_OBJ_NEW_SMALL_INT((mp_int_t)addr->ai_family); t->items[0] = MP_OBJ_NEW_SMALL_INT(addr->ai_family);
t->items[1] = MP_OBJ_NEW_SMALL_INT((mp_int_t)addr->ai_socktype); t->items[1] = MP_OBJ_NEW_SMALL_INT(addr->ai_socktype);
t->items[2] = MP_OBJ_NEW_SMALL_INT((mp_int_t)addr->ai_protocol); t->items[2] = MP_OBJ_NEW_SMALL_INT(addr->ai_protocol);
// "canonname will be a string representing the canonical name of the host // "canonname will be a string representing the canonical name of the host
// if AI_CANONNAME is part of the flags argument; else canonname will be empty." ?? // if AI_CANONNAME is part of the flags argument; else canonname will be empty." ??
if (addr->ai_canonname) { if (addr->ai_canonname) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment