summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-10-07 13:44:55 +1100
committerDamien George <damien.p.george@gmail.com>2016-10-07 13:44:55 +1100
commit620c4c32bf1ad3123d0b5a326fede444149651c3 (patch)
treeb493a7488af0ff6f1d91cf4009a7c8fc804fc3fe
parent3a0a7717304cc34a4d6ef55f767666c918c185b5 (diff)
downloadmicropython-620c4c32bf1ad3123d0b5a326fede444149651c3.tar.gz
micropython-620c4c32bf1ad3123d0b5a326fede444149651c3.zip
extmod/vfs_fat: Use mp_raise_OSError helper function.
-rw-r--r--extmod/fsusermount.c3
-rw-r--r--extmod/vfs_fat.c20
-rw-r--r--extmod/vfs_fat_file.c2
-rw-r--r--extmod/vfs_fat_misc.c4
4 files changed, 11 insertions, 18 deletions
diff --git a/extmod/fsusermount.c b/extmod/fsusermount.c
index cbc1e36220..5882aba991 100644
--- a/extmod/fsusermount.c
+++ b/extmod/fsusermount.c
@@ -31,6 +31,7 @@
#include "py/nlr.h"
#include "py/runtime.h"
+#include "py/mperrno.h"
#include "lib/fatfs/ff.h"
#include "extmod/fsusermount.h"
@@ -183,7 +184,7 @@ mp_obj_t fatfs_umount(mp_obj_t bdev_or_path_in) {
}
if (i == MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount))) {
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EINVAL)));
+ mp_raise_OSError(MP_EINVAL);
}
fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[i];
diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c
index 2e74f19d61..3a17533e43 100644
--- a/extmod/vfs_fat.c
+++ b/extmod/vfs_fat.c
@@ -84,8 +84,7 @@ STATIC mp_obj_t fat_vfs_remove(mp_obj_t vfs_in, mp_obj_t path_in) {
if (res == FR_OK) {
return mp_const_none;
} else {
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
- MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
+ mp_raise_OSError(fresult_to_errno_table[res]);
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_remove_obj, fat_vfs_remove);
@@ -106,8 +105,7 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_
if (res == FR_OK) {
return mp_const_none;
} else {
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
- MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
+ mp_raise_OSError(fresult_to_errno_table[res]);
}
}
@@ -120,8 +118,7 @@ STATIC mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) {
if (res == FR_OK) {
return mp_const_none;
} else {
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
- MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
+ mp_raise_OSError(fresult_to_errno_table[res]);
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_mkdir_obj, fat_vfs_mkdir);
@@ -139,8 +136,7 @@ STATIC mp_obj_t fat_vfs_chdir(mp_obj_t vfs_in, mp_obj_t path_in) {
}
if (res != FR_OK) {
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
- MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
+ mp_raise_OSError(fresult_to_errno_table[res]);
}
return mp_const_none;
@@ -154,7 +150,7 @@ STATIC mp_obj_t fat_vfs_getcwd(mp_obj_t vfs_in) {
FRESULT res = f_getcwd(buf, sizeof buf);
if (res != FR_OK) {
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
+ mp_raise_OSError(fresult_to_errno_table[res]);
}
return mp_obj_new_str(buf, strlen(buf), false);
@@ -215,8 +211,7 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
res = f_stat(path, &fno);
}
if (res != FR_OK) {
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
- MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
+ mp_raise_OSError(fresult_to_errno_table[res]);
}
}
@@ -259,8 +254,7 @@ STATIC mp_obj_t fat_vfs_statvfs(mp_obj_t vfs_in, mp_obj_t path_in) {
DWORD nclst;
FRESULT res = f_getfree(path, &nclst, &fatfs);
if (FR_OK != res) {
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
- MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
+ mp_raise_OSError(fresult_to_errno_table[res]);
}
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL));
diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c
index 0cd61e4605..305d2d2f16 100644
--- a/extmod/vfs_fat_file.c
+++ b/extmod/vfs_fat_file.c
@@ -208,7 +208,7 @@ STATIC mp_obj_t file_open(const mp_obj_type_t *type, mp_arg_val_t *args) {
FRESULT res = f_open(&o->fp, fname, mode);
if (res != FR_OK) {
m_del_obj(pyb_file_obj_t, o);
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
+ mp_raise_OSError(fresult_to_errno_table[res]);
}
// for 'a' mode, we must begin at the end of the file
diff --git a/extmod/vfs_fat_misc.c b/extmod/vfs_fat_misc.c
index 23fe4be88d..d3507a85f3 100644
--- a/extmod/vfs_fat_misc.c
+++ b/extmod/vfs_fat_misc.c
@@ -54,9 +54,7 @@ mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type) {
res = f_opendir(&dir, path); /* Open the directory */
if (res != FR_OK) {
- nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
- MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
-
+ mp_raise_OSError(fresult_to_errno_table[res]);
}
mp_obj_t dir_list = mp_obj_new_list(0, NULL);