summaryrefslogtreecommitdiffstatshomepage
path: root/unix
diff options
context:
space:
mode:
Diffstat (limited to 'unix')
-rw-r--r--unix/ffi.c41
-rw-r--r--unix/file.c4
-rw-r--r--unix/main.c11
-rw-r--r--unix/qstrdefsport.h4
-rw-r--r--unix/socket.c12
5 files changed, 38 insertions, 34 deletions
diff --git a/unix/ffi.c b/unix/ffi.c
index a82e4e3386..ef9c6ea9d2 100644
--- a/unix/ffi.c
+++ b/unix/ffi.c
@@ -46,7 +46,7 @@ typedef struct _mp_obj_fficallback_t {
ffi_type *params[];
} mp_obj_fficallback_t;
-static const mp_obj_type_t opaque_type;
+//static const mp_obj_type_t opaque_type;
static const mp_obj_type_t ffimod_type;
static const mp_obj_type_t ffifunc_type;
static const mp_obj_type_t fficallback_type;
@@ -80,7 +80,7 @@ static ffi_type *get_ffi_type(mp_obj_t o_in)
}
// TODO: Support actual libffi type objects
- nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "Unknown type"));
+ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Unknown type"));
}
static mp_obj_t return_ffi_value(ffi_arg val, char type)
@@ -118,7 +118,7 @@ static mp_obj_t ffimod_func(uint n_args, const mp_obj_t *args) {
void *sym = dlsym(self->handle, symname);
if (sym == NULL) {
- nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "[Errno %d]", errno));
+ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
}
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);
@@ -136,7 +136,7 @@ static mp_obj_t ffimod_func(uint n_args, const mp_obj_t *args) {
int res = ffi_prep_cif(&o->cif, FFI_DEFAULT_ABI, nparams, char2ffi_type(*rettype), o->params);
if (res != FFI_OK) {
- nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "Error in ffi_prep_cif"));
+ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error in ffi_prep_cif"));
}
return o;
@@ -173,12 +173,12 @@ static mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t
int res = ffi_prep_cif(&o->cif, FFI_DEFAULT_ABI, nparams, char2ffi_type(*rettype), o->params);
if (res != FFI_OK) {
- nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "Error in ffi_prep_cif"));
+ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error in ffi_prep_cif"));
}
res = ffi_prep_closure_loc(o->clo, &o->cif, call_py_func, func_in, o->func);
if (res != FFI_OK) {
- nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "ffi_prep_closure_loc"));
+ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "ffi_prep_closure_loc"));
}
return o;
@@ -192,7 +192,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);
if (sym == NULL) {
- nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "[Errno %d]", errno));
+ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
}
mp_obj_ffivar_t *o = m_new_obj(mp_obj_ffivar_t);
o->base.type = &ffivar_type;
@@ -208,7 +208,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);
if (mod == NULL) {
- nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "[Errno %d]", errno));
+ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
}
mp_obj_ffimod_t *o = m_new_obj(mp_obj_ffimod_t);
o->base.type = type_in;
@@ -224,8 +224,8 @@ static const mp_method_t ffimod_type_methods[] = {
};
static const mp_obj_type_t ffimod_type = {
- { &mp_const_type },
- "ffimod",
+ { &mp_type_type },
+ .name = MP_QSTR_ffimod,
.print = ffimod_print,
.make_new = ffimod_make_new,
.methods = ffimod_type_methods,
@@ -270,8 +270,8 @@ mp_obj_t ffifunc_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *
}
static const mp_obj_type_t ffifunc_type = {
- { &mp_const_type },
- "ffifunc",
+ { &mp_type_type },
+ .name = MP_QSTR_ffifunc,
.print = ffifunc_print,
.call = ffifunc_call,
};
@@ -284,8 +284,8 @@ static void fficallback_print(void (*print)(void *env, const char *fmt, ...), vo
}
static const mp_obj_type_t fficallback_type = {
- { &mp_const_type },
- "fficallback",
+ { &mp_type_type },
+ .name = MP_QSTR_fficallback,
.print = fficallback_print,
};
@@ -316,20 +316,21 @@ static const mp_method_t ffivar_type_methods[] = {
};
static const mp_obj_type_t ffivar_type = {
- { &mp_const_type },
- "ffivar",
+ { &mp_type_type },
+ .name = MP_QSTR_ffivar,
.print = ffivar_print,
.methods = ffivar_type_methods,
};
-// Generic opaque storage object
+// Generic opaque storage object (unused)
+/*
static const mp_obj_type_t opaque_type = {
- { &mp_const_type },
- "opaqueval",
+ { &mp_type_type },
+ .name = MP_QSTR_opaqueval,
// .print = opaque_print,
};
-
+*/
mp_obj_t mod_ffi_open(uint n_args, const mp_obj_t *args) {
return ffimod_make_new((mp_obj_t)&ffimod_type, n_args, 0, args);
diff --git a/unix/file.c b/unix/file.c
index 4e8fba54c8..444a05d491 100644
--- a/unix/file.c
+++ b/unix/file.c
@@ -99,7 +99,7 @@ static mp_obj_t fdfile_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
int fd = open(fname, mode, 0644);
if (fd == -1) {
- nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "[Errno %d]", errno));
+ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
}
return fdfile_new(fd);
}
@@ -115,7 +115,7 @@ static const mp_method_t rawfile_type_methods[] = {
};
static const mp_obj_type_t rawfile_type = {
- { &mp_const_type },
+ { &mp_type_type },
.name = MP_QSTR_io_dot_FileIO,
.print = fdfile_print,
.make_new = fdfile_make_new,
diff --git a/unix/main.c b/unix/main.c
index 6aafe94ddd..8e6a76bbad 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -11,6 +11,7 @@
#include "lexerunix.h"
#include "parse.h"
#include "obj.h"
+#include "parsehelper.h"
#include "compile.h"
#include "runtime0.h"
#include "runtime.h"
@@ -49,14 +50,12 @@ static void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind
return;
}
- qstr parse_exc_id;
- const char *parse_exc_msg;
- mp_parse_node_t pn = mp_parse(lex, input_kind, &parse_exc_id, &parse_exc_msg);
+ mp_parse_error_kind_t parse_error_kind;
+ mp_parse_node_t pn = mp_parse(lex, input_kind, &parse_error_kind);
if (pn == MP_PARSE_NODE_NULL) {
// parse error
- mp_lexer_show_error_pythonic_prefix(lex);
- printf("%s: %s\n", qstr_str(parse_exc_id), parse_exc_msg);
+ mp_parse_show_exception(lex, parse_error_kind);
mp_lexer_free(lex);
return;
}
@@ -194,7 +193,7 @@ static const mp_method_t test_methods[] = {
};
static const mp_obj_type_t test_type = {
- { &mp_const_type },
+ { &mp_type_type },
.name = MP_QSTR_Test,
.print = test_print,
.methods = test_methods,
diff --git a/unix/qstrdefsport.h b/unix/qstrdefsport.h
index 42c88b4693..867afaeac0 100644
--- a/unix/qstrdefsport.h
+++ b/unix/qstrdefsport.h
@@ -17,3 +17,7 @@ Q(getaddrinfo)
Q(microsocket)
Q(io.FileIO)
+Q(ffimod)
+Q(ffifunc)
+Q(fficallback)
+Q(ffivar)
diff --git a/unix/socket.c b/unix/socket.c
index 25c4bfcb46..a9cf4a81a0 100644
--- a/unix/socket.c
+++ b/unix/socket.c
@@ -29,7 +29,7 @@ static const mp_obj_type_t microsocket_type;
// Helper functions
#define RAISE_ERRNO(err_flag, error_val) \
{ if (err_flag == -1) \
- { nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "[Errno %d]", error_val)); } }
+ { nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error_val)); } }
static void get_buffer(mp_obj_t obj, buffer_info_t *bufinfo) {
mp_obj_base_t *o = (mp_obj_base_t *)obj;
@@ -43,7 +43,7 @@ static void get_buffer(mp_obj_t obj, buffer_info_t *bufinfo) {
return;
error:
- nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "Operation not supported"));
+ nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "Operation not supported"));
}
static mp_obj_socket_t *socket_new(int fd) {
@@ -237,7 +237,7 @@ static const mp_method_t microsocket_type_methods[] = {
};
static const mp_obj_type_t microsocket_type = {
- { &mp_const_type },
+ { &mp_type_type },
.name = MP_QSTR_socket,
.print = socket_print,
.make_new = socket_make_new,
@@ -260,7 +260,7 @@ static mp_obj_t mod_socket_inet_aton(mp_obj_t arg) {
const char *s = mp_obj_str_get_str(arg);
struct in_addr addr;
if (!inet_aton(s, &addr)) {
- nlr_jump(mp_obj_new_exception_msg(MP_QSTR_OSError, "Invalid IP address"));
+ nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, "Invalid IP address"));
}
return mp_obj_new_int(addr.s_addr);
@@ -273,7 +273,7 @@ static mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) {
const char *s = mp_obj_str_get_str(arg);
struct hostent *h = gethostbyname(s);
if (h == NULL) {
- nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "[Errno %d]", errno));
+ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
}
assert(h->h_length == 4);
return mp_obj_new_int(*(int*)*h->h_addr_list);
@@ -305,7 +305,7 @@ static mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) {
int res = getaddrinfo(host, serv, NULL/*&hints*/, &addr);
if (res != 0) {
- nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "[addrinfo error %d]", res));
+ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[addrinfo error %d]", res));
}
assert(addr);