summaryrefslogtreecommitdiffstatshomepage
path: root/unix/socket.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-02-15 16:10:44 +0000
committerDamien George <damien.p.george@gmail.com>2014-02-15 16:10:44 +0000
commitc5966128c7c8a768f6726f299d85d5daef6bed48 (patch)
treefea6913ae43d722078a837d8c7fd9a1e459f3891 /unix/socket.c
parenta71c83a1d1aeca1d81d7c673929f8e836dec131e (diff)
downloadmicropython-c5966128c7c8a768f6726f299d85d5daef6bed48.tar.gz
micropython-c5966128c7c8a768f6726f299d85d5daef6bed48.zip
Implement proper exception type hierarchy.
Each built-in exception is now a type, with base type BaseException. C exceptions are created by passing a pointer to the exception type to make an instance of. When raising an exception from the VM, an instance is created automatically if an exception type is raised (as opposed to an exception instance). Exception matching (RT_BINARY_OP_EXCEPTION_MATCH) is now proper. Handling of parse error changed to match new exceptions. mp_const_type renamed to mp_type_type for consistency.
Diffstat (limited to 'unix/socket.c')
-rw-r--r--unix/socket.c12
1 files changed, 6 insertions, 6 deletions
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);