From 7630a9be744e4d2b98b0efa2978b7d1c96d17041 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 23 Feb 2014 03:40:11 +0200 Subject: [PATCH] Update python bindings for new libmp --- src/py/py_assert.h | 6 +++--- src/py/py_file.c | 12 ++++++------ src/py/py_image.c | 4 ++-- src/py/py_imlib.c | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/py/py_assert.h b/src/py/py_assert.h index ae0553e16..3e1897410 100644 --- a/src/py/py_assert.h +++ b/src/py/py_assert.h @@ -4,7 +4,7 @@ do { \ if ((cond) ==0){ \ nlr_jump(mp_obj_new_exception_msg( \ - MP_QSTR_OSError, \ + &mp_type_OSError, \ "Operation not supported")); \ } \ } while(0) @@ -15,7 +15,7 @@ __typeof__ (type) _b = (type); \ if (!MP_OBJ_IS_TYPE(_a, _b)) { \ nlr_jump(mp_obj_new_exception_msg_varg( \ - MP_QSTR_TypeError, \ + &mp_type_TypeError, \ "can't convert %s to %s", \ mp_obj_get_type_str(_a), \ _b->name)); \ @@ -27,7 +27,7 @@ __typeof__ (obj) _a = (obj); \ if (!MP_OBJ_IS_STR(_a)) { \ nlr_jump(mp_obj_new_exception_msg_varg( \ - MP_QSTR_TypeError, \ + &mp_type_TypeError, \ "can't convert %s to %s", \ mp_obj_get_type_str(_a), \ str_type.name)); \ diff --git a/src/py/py_file.c b/src/py/py_file.c index fb4debaa2..a23bf4792 100644 --- a/src/py/py_file.c +++ b/src/py/py_file.c @@ -57,14 +57,14 @@ mp_obj_t py_file_read(py_file_obj_t *file, mp_obj_t n_obj) mp_obj_t py_file_write(py_file_obj_t *file, mp_obj_t buf) { uint len; - const byte *str; + const char *str; FRESULT res; str = mp_obj_str_get_data(buf, &len); res = f_write(&file->fp, str, len, &len); if (res != FR_OK) { - nlr_jump(mp_obj_new_exception_msg(qstr_from_str("File"), ffs_strerror(res))); + nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res))); } return mp_obj_new_int(len); @@ -87,8 +87,8 @@ static const mp_method_t py_file_methods[] = { }; static const mp_obj_type_t py_file_type = { - { &mp_const_type }, - "File", + { &mp_type_type }, + .name = MP_QSTR_File, .print = py_file_print, .methods = py_file_methods, }; @@ -113,7 +113,7 @@ mp_obj_t py_file_open(mp_obj_t path, mp_obj_t mode_str) mode = FA_READ|FA_WRITE|FA_OPEN_EXISTING; break; default: - nlr_jump(mp_obj_new_exception_msg(qstr_from_str("File"), "invalid open mode")); + nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid open mode")); } /* Create new python file obj */ @@ -123,7 +123,7 @@ mp_obj_t py_file_open(mp_obj_t path, mp_obj_t mode_str) /* Open underlying file handle */ res = f_open(&o->fp, mp_obj_str_get_str(path), mode); if (res != FR_OK) { - nlr_jump(mp_obj_new_exception_msg(qstr_from_str("File"), ffs_strerror(res))); + nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res))); } return o; } diff --git a/src/py/py_image.c b/src/py/py_image.c index b40a63067..46eb791c5 100644 --- a/src/py/py_image.c +++ b/src/py/py_image.c @@ -29,8 +29,8 @@ static const mp_method_t py_image_methods[] = { }; const mp_obj_type_t py_image_type = { - { &mp_const_type }, - "image", + { &mp_type_type }, + .name = MP_QSTR_Image, .print = py_image_print, .methods = py_image_methods, // .load_attr = py_image_load_attr, diff --git a/src/py/py_imlib.c b/src/py/py_imlib.c index fe8277819..fac182796 100644 --- a/src/py/py_imlib.c +++ b/src/py/py_imlib.c @@ -28,7 +28,7 @@ static void py_cascade_print(void (*print)(void *env, const char *fmt, ...), voi } static const mp_obj_type_t py_cascade_type = { - { &mp_const_type }, + { &mp_type_type }, "Cascade", .print = py_cascade_print, }; @@ -153,7 +153,7 @@ mp_obj_t py_imlib_load_cascade(mp_obj_t path_obj) const char *path = mp_obj_str_get_str(path_obj); int res = imlib_load_cascade(&cascade, path); if (res != FR_OK) { - nlr_jump(mp_obj_new_exception_msg(qstr_from_str("Imlib"), ffs_strerror(res))); + nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res))); } o = m_new_obj(py_cascade_obj_t); @@ -174,7 +174,7 @@ mp_obj_t py_imlib_load_template(mp_obj_t path_obj) int res = imlib_load_template(image, path); if (res != FR_OK) { - nlr_jump(mp_obj_new_exception_msg(qstr_from_str("Imlib"), ffs_strerror(res))); + nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res))); } return image_obj; @@ -209,7 +209,7 @@ mp_obj_t py_imlib_save_template(mp_obj_t image_obj, mp_obj_t rectangle_obj, mp_o free(t.data); if (res != FR_OK) { - nlr_jump(mp_obj_new_exception_msg(qstr_from_str("Imlib"), ffs_strerror(res))); + nlr_jump(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res))); } return mp_const_true;