Skip to content

Commit 620c4c3

Browse files
committed
extmod/vfs_fat: Use mp_raise_OSError helper function.
1 parent 3a0a771 commit 620c4c3

File tree

4 files changed

+11
-18
lines changed

4 files changed

+11
-18
lines changed

extmod/fsusermount.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "py/nlr.h"
3333
#include "py/runtime.h"
34+
#include "py/mperrno.h"
3435
#include "lib/fatfs/ff.h"
3536
#include "extmod/fsusermount.h"
3637

@@ -183,7 +184,7 @@ mp_obj_t fatfs_umount(mp_obj_t bdev_or_path_in) {
183184
}
184185

185186
if (i == MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount))) {
186-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EINVAL)));
187+
mp_raise_OSError(MP_EINVAL);
187188
}
188189

189190
fs_user_mount_t *vfs = MP_STATE_PORT(fs_user_mount)[i];

extmod/vfs_fat.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ STATIC mp_obj_t fat_vfs_remove(mp_obj_t vfs_in, mp_obj_t path_in) {
8484
if (res == FR_OK) {
8585
return mp_const_none;
8686
} else {
87-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
88-
MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
87+
mp_raise_OSError(fresult_to_errno_table[res]);
8988
}
9089
}
9190
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_
106105
if (res == FR_OK) {
107106
return mp_const_none;
108107
} else {
109-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
110-
MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
108+
mp_raise_OSError(fresult_to_errno_table[res]);
111109
}
112110

113111
}
@@ -120,8 +118,7 @@ STATIC mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) {
120118
if (res == FR_OK) {
121119
return mp_const_none;
122120
} else {
123-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
124-
MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
121+
mp_raise_OSError(fresult_to_errno_table[res]);
125122
}
126123
}
127124
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) {
139136
}
140137

141138
if (res != FR_OK) {
142-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
143-
MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
139+
mp_raise_OSError(fresult_to_errno_table[res]);
144140
}
145141

146142
return mp_const_none;
@@ -154,7 +150,7 @@ STATIC mp_obj_t fat_vfs_getcwd(mp_obj_t vfs_in) {
154150
FRESULT res = f_getcwd(buf, sizeof buf);
155151

156152
if (res != FR_OK) {
157-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
153+
mp_raise_OSError(fresult_to_errno_table[res]);
158154
}
159155

160156
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) {
215211
res = f_stat(path, &fno);
216212
}
217213
if (res != FR_OK) {
218-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
219-
MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
214+
mp_raise_OSError(fresult_to_errno_table[res]);
220215
}
221216
}
222217

@@ -259,8 +254,7 @@ STATIC mp_obj_t fat_vfs_statvfs(mp_obj_t vfs_in, mp_obj_t path_in) {
259254
DWORD nclst;
260255
FRESULT res = f_getfree(path, &nclst, &fatfs);
261256
if (FR_OK != res) {
262-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
263-
MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
257+
mp_raise_OSError(fresult_to_errno_table[res]);
264258
}
265259

266260
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL));

extmod/vfs_fat_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ STATIC mp_obj_t file_open(const mp_obj_type_t *type, mp_arg_val_t *args) {
208208
FRESULT res = f_open(&o->fp, fname, mode);
209209
if (res != FR_OK) {
210210
m_del_obj(pyb_file_obj_t, o);
211-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
211+
mp_raise_OSError(fresult_to_errno_table[res]);
212212
}
213213

214214
// for 'a' mode, we must begin at the end of the file

extmod/vfs_fat_misc.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ mp_obj_t fat_vfs_listdir(const char *path, bool is_str_type) {
5454

5555
res = f_opendir(&dir, path); /* Open the directory */
5656
if (res != FR_OK) {
57-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError,
58-
MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
59-
57+
mp_raise_OSError(fresult_to_errno_table[res]);
6058
}
6159

6260
mp_obj_t dir_list = mp_obj_new_list(0, NULL);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy