From e2e01efa84d2ed46d004edf48076e4701accc176 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 13 Jul 2018 22:51:10 -0400 Subject: compiles and runs; hangs on import storage;storage.VfsFat. --- extmod/vfs.h | 2 + extmod/vfs_fat.c | 6 +-- extmod/vfs_fat.h | 25 +++++++++++-- extmod/vfs_fat_diskio.c | 2 +- extmod/vfs_fat_file.c | 2 - extmod/vfs_fat_file.h | 50 ------------------------- ports/atmel-samd/audio_dma.h | 2 +- ports/atmel-samd/common-hal/audiobusio/I2SOut.c | 2 +- ports/atmel-samd/common-hal/audiobusio/PDMIn.h | 2 +- ports/atmel-samd/common-hal/audioio/AudioOut.c | 2 +- py/mpconfig.h | 4 ++ py/mpstate.h | 1 + py/objmodule.c | 4 +- py/objnamedtuple.c | 4 +- py/objnamedtuple.h | 26 ++++++++++--- py/objtype.c | 1 + py/runtime.c | 3 +- py/runtime.h | 1 + shared-bindings/audiobusio/PDMIn.c | 2 +- shared-bindings/audiobusio/PDMIn.h | 2 +- shared-bindings/audioio/WaveFile.c | 2 +- shared-bindings/audioio/WaveFile.h | 2 +- shared-bindings/storage/__init__.c | 1 + shared-bindings/time/__init__.c | 1 + shared-module/os/__init__.c | 2 +- 25 files changed, 71 insertions(+), 80 deletions(-) delete mode 100644 extmod/vfs_fat_file.h diff --git a/extmod/vfs.h b/extmod/vfs.h index 5ab2067e5..38c77943c 100644 --- a/extmod/vfs.h +++ b/extmod/vfs.h @@ -68,6 +68,8 @@ typedef struct _mp_vfs_ilistdir_it_t { bool is_iter; } mp_vfs_ilistdir_it_t; +mp_obj_t mp_vfs_ilistdir_it_iternext(mp_obj_t self_in); + mp_vfs_mount_t *mp_vfs_lookup_path(const char *path, const char **path_out); mp_import_stat_t mp_vfs_import_stat(const char *path); mp_obj_t mp_vfs_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 633c04389..bf58afb1e 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -48,7 +48,7 @@ #define mp_obj_fat_vfs_t fs_user_mount_t -STATIC mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) { +mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) { fs_user_mount_t *vfs = vfs_in; FILINFO fno; assert(vfs != NULL); @@ -411,11 +411,11 @@ STATIC mp_obj_t vfs_fat_getlabel(mp_obj_t self_in) { if (res != FR_OK) { mp_raise_OSError(fresult_to_errno_table[res]); } - return mp_obj_new_str(working_buf, strlen(working_buf), false); + return mp_obj_new_str(working_buf, strlen(working_buf)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getlabel_obj, vfs_fat_getlabel); -static mp_obj_t vfs_fat_setlabel(mp_obj_t self_in, mp_obj_t label_in) { +STATIC mp_obj_t vfs_fat_setlabel(mp_obj_t self_in, mp_obj_t label_in) { fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in); const char *label_str = mp_obj_str_get_str(label_in); FRESULT res = f_setlabel(&self->fatfs, label_str); diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h index 273ddc84e..3f46c278f 100644 --- a/extmod/vfs_fat.h +++ b/extmod/vfs_fat.h @@ -35,8 +35,9 @@ #define FSUSER_NATIVE (0x0001) // readblocks[2]/writeblocks[2] contain native func #define FSUSER_FREE_OBJ (0x0002) // fs_user_mount_t obj should be freed on umount #define FSUSER_HAVE_IOCTL (0x0004) // new protocol with ioctl +#define FSUSER_NO_FILESYSTEM (0x0008) // the block device has no filesystem on it // Device is writable over USB and read-only to MicroPython. -#define FSUSER_USB_WRITABLE (0x0008) +#define FSUSER_USB_WRITABLE (0x0010) typedef struct _fs_user_mount_t { mp_obj_base_t base; @@ -54,12 +55,28 @@ typedef struct _fs_user_mount_t { FATFS fatfs; } fs_user_mount_t; +typedef struct _pyb_file_obj_t { + mp_obj_base_t base; + FIL fp; +} pyb_file_obj_t; + + +// These should be general types (mpy TOOD says so). In micropython, these are defined in +// mpconfigport.h. +#define mp_type_fileio mp_type_vfs_fat_fileio +#define mp_type_textio mp_type_vfs_fat_textio + +extern const mp_obj_type_t mp_type_fileio; +extern const mp_obj_type_t mp_type_textio; + extern const byte fresult_to_errno_table[20]; extern const mp_obj_type_t mp_fat_vfs_type; +extern const mp_obj_type_t mp_type_vfs_fat_fileio; +extern const mp_obj_type_t mp_type_vfs_fat_textio; + +mp_import_stat_t fat_vfs_import_stat(void *vfs, const char *path); -mp_import_stat_t fat_vfs_import_stat(struct _fs_user_mount_t *vfs, const char *path); -mp_obj_t fatfs_builtin_open_self(mp_obj_t self_in, mp_obj_t path, mp_obj_t mode); -MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_open_obj); +MP_DECLARE_CONST_FUN_OBJ_3(fat_vfs_open_obj); mp_obj_t fat_vfs_ilistdir2(struct _fs_user_mount_t *vfs, const char *path, bool is_str_type); diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c index a147d601a..95ef77895 100644 --- a/extmod/vfs_fat_diskio.c +++ b/extmod/vfs_fat_diskio.c @@ -57,7 +57,7 @@ STATIC fs_user_mount_t *disk_get_device(void *bdev) { STATIC DSTATUS disk_initialize ( - bdev_t pdrv /* Physical drive nmuber (0..) */ + bdev_t pdrv /* Physical drive number (0..) */ ) { fs_user_mount_t *vfs = disk_get_device(pdrv); diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index 86ae65aef..e3eebc9c4 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -27,8 +27,6 @@ #include "py/mpconfig.h" #if MICROPY_VFS && MICROPY_VFS_FAT -#include "extmod/vfs_fat_file.h" - #include #include "py/runtime.h" diff --git a/extmod/vfs_fat_file.h b/extmod/vfs_fat_file.h deleted file mode 100644 index 11e4b7aa8..000000000 --- a/extmod/vfs_fat_file.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_EXTMOD_VFS_FAT_FILE_H -#define MICROPY_INCLUDED_EXTMOD_VFS_FAT_FILE_H - -#include "py/mpconfig.h" - -#if MICROPY_VFS && MICROPY_VFS_FAT - -#include "lib/oofatfs/ff.h" -#include "py/obj.h" - -#define mp_type_fileio fatfs_type_fileio -#define mp_type_textio fatfs_type_textio - -extern const mp_obj_type_t mp_type_fileio; -extern const mp_obj_type_t mp_type_textio; - -typedef struct _pyb_file_obj_t { - mp_obj_base_t base; - FIL fp; -} pyb_file_obj_t; - -#endif // MICROPY_VFS && MICROPY_VFS_FAT - -#endif // MICROPY_INCLUDED_EXTMOD_VFS_FAT_FILE_H diff --git a/ports/atmel-samd/audio_dma.h b/ports/atmel-samd/audio_dma.h index 6734adb64..041d675a2 100644 --- a/ports/atmel-samd/audio_dma.h +++ b/ports/atmel-samd/audio_dma.h @@ -27,7 +27,7 @@ #ifndef MICROPY_INCLUDED_ATMEL_SAMD_AUDIO_DMA_H #define MICROPY_INCLUDED_ATMEL_SAMD_AUDIO_DMA_H -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #include "py/obj.h" #include "shared-module/audioio/RawSample.h" #include "shared-module/audioio/WaveFile.h" diff --git a/ports/atmel-samd/common-hal/audiobusio/I2SOut.c b/ports/atmel-samd/common-hal/audiobusio/I2SOut.c index 99087d60c..20bfb2a80 100644 --- a/ports/atmel-samd/common-hal/audiobusio/I2SOut.c +++ b/ports/atmel-samd/common-hal/audiobusio/I2SOut.c @@ -27,7 +27,7 @@ #include #include -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #include "py/gc.h" #include "py/mperrno.h" #include "py/runtime.h" diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.h b/ports/atmel-samd/common-hal/audiobusio/PDMIn.h index 1156c6421..5c4d4feea 100644 --- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.h +++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.h @@ -29,7 +29,7 @@ #include "common-hal/microcontroller/Pin.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #include "py/obj.h" typedef struct { diff --git a/ports/atmel-samd/common-hal/audioio/AudioOut.c b/ports/atmel-samd/common-hal/audioio/AudioOut.c index 4e39d3b44..bbc4bf2e2 100644 --- a/ports/atmel-samd/common-hal/audioio/AudioOut.c +++ b/ports/atmel-samd/common-hal/audioio/AudioOut.c @@ -27,7 +27,7 @@ #include #include -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" #include "py/gc.h" #include "py/mperrno.h" #include "py/runtime.h" diff --git a/py/mpconfig.h b/py/mpconfig.h index d80730809..a846f6a25 100755 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1242,6 +1242,10 @@ typedef double mp_float_t; #define MICROPY_PY_OS_DUPTERM (0) #endif +#ifndef MICROPY_PY_LWIP +#define MICROPY_PY_LWIP (0) +#endif + #ifndef MICROPY_PY_LWIP_SLIP #define MICROPY_PY_LWIP_SLIP (0) #endif diff --git a/py/mpstate.h b/py/mpstate.h index 6e68159ee..eef8696d3 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -177,6 +177,7 @@ typedef struct _mp_state_vm_t { #if MICROPY_PY_OS_DUPTERM mp_obj_t dupterm_objs[MICROPY_PY_OS_DUPTERM]; + mp_obj_t dupterm_arr_obj; #endif #if MICROPY_PY_LWIP_SLIP diff --git a/py/objmodule.c b/py/objmodule.c index b28fb2416..828f556f3 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -213,13 +213,13 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { #if MICROPY_PY_USSL { MP_ROM_QSTR(MP_QSTR_ussl), MP_ROM_PTR(&mp_module_ussl) }, #endif -#ifdef MICROPY_PY_LWIP +#if MICROPY_PY_LWIP { MP_ROM_QSTR(MP_QSTR_lwip), MP_ROM_PTR(&mp_module_lwip) }, #endif #if MICROPY_PY_WEBSOCKET { MP_ROM_QSTR(MP_QSTR_websocket), MP_ROM_PTR(&mp_module_websocket) }, #endif -#ifdef MICROPY_PY_WEBREPL +#if MICROPY_PY_WEBREPL { MP_ROM_QSTR(MP_QSTR__webrepl), MP_ROM_PTR(&mp_module_webrepl) }, #endif #if MICROPY_PY_FRAMEBUF diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c index 832a4a671..e44b68edc 100644 --- a/py/objnamedtuple.c +++ b/py/objnamedtuple.c @@ -60,7 +60,7 @@ STATIC mp_obj_t namedtuple_asdict(mp_obj_t self_in) { MP_DEFINE_CONST_FUN_OBJ_1(namedtuple_asdict_obj, namedtuple_asdict); #endif -STATIC void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_namedtuple_t *o = MP_OBJ_TO_PTR(o_in); mp_printf(print, "%q", o->tuple.base.type->name); @@ -68,7 +68,7 @@ STATIC void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_ki mp_obj_attrtuple_print_helper(print, fields, &o->tuple); } -STATIC void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] == MP_OBJ_NULL) { // load attribute mp_obj_namedtuple_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/py/objnamedtuple.h b/py/objnamedtuple.h index d32af35af..a36404b8d 100644 --- a/py/objnamedtuple.h +++ b/py/objnamedtuple.h @@ -1,9 +1,10 @@ /* - * This file is part of the MicroPython project, http://micropython.org/ + * This file is part of the Micro Python project, http://micropython.org/ * * The MIT License (MIT) * - * Copyright (c) 2014-2017 Paul Sokolovsky + * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2014 Paul Sokolovsky * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,14 +24,22 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + #ifndef MICROPY_INCLUDED_PY_OBJNAMEDTUPLE_H #define MICROPY_INCLUDED_PY_OBJNAMEDTUPLE_H +#include + +#include "py/nlr.h" #include "py/objtuple.h" +#include "py/runtime.h" +#include "py/objstr.h" + +#if MICROPY_PY_COLLECTIONS typedef struct _mp_obj_namedtuple_type_t { mp_obj_type_t base; - size_t n_fields; + mp_uint_t n_fields; qstr fields[]; } mp_obj_namedtuple_type_t; @@ -38,7 +47,12 @@ typedef struct _mp_obj_namedtuple_t { mp_obj_tuple_t tuple; } mp_obj_namedtuple_t; -size_t mp_obj_namedtuple_find_field(const mp_obj_namedtuple_type_t *type, qstr name); -mp_obj_namedtuple_type_t *mp_obj_new_namedtuple_base(size_t n_fields, mp_obj_t *fields); +void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind); + +void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest); + +mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args); + +#endif // MICROPY_PY_COLLECTIONS -#endif // MICROPY_INCLUDED_PY_OBJNAMEDTUPLE_H +#endif // MICROPY_INCLUDED_PY_OBJNAMEDTUPLE_H diff --git a/py/objtype.c b/py/objtype.c index 7244abd9e..b12fadbf7 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -1285,6 +1285,7 @@ STATIC void super_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { dest[0] = mp_call_method_n_kw(2, 0, attr_get_method); } #endif + } return; } diff --git a/py/runtime.c b/py/runtime.c index a9c0ef1e2..4ba4760e6 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -116,10 +116,11 @@ void mp_init(void) { MP_STATE_VM(mp_module_builtins_override_dict) = NULL; #endif - #ifdef MICROPY_PY_OS_DUPTERM + #if MICROPY_PY_OS_DUPTERM for (size_t i = 0; i < MICROPY_PY_OS_DUPTERM; ++i) { MP_STATE_VM(dupterm_objs[i]) = MP_OBJ_NULL; } + MP_STATE_VM(dupterm_arr_obj) = MP_OBJ_NULL; #endif #ifdef MICROPY_FSUSERMOUNT diff --git a/py/runtime.h b/py/runtime.h index 9e860df15..95f89ee9e 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -158,6 +158,7 @@ NORETURN void mp_raise_RuntimeError(const char *msg); NORETURN void mp_raise_ImportError(const char *msg); NORETURN void mp_raise_IndexError(const char *msg); NORETURN void mp_raise_OSError(int errno_); +NORETURN void mp_raise_NotImplementedError(const char *msg); NORETURN void mp_raise_recursion_depth(void); #if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG diff --git a/shared-bindings/audiobusio/PDMIn.c b/shared-bindings/audiobusio/PDMIn.c index 3e0f3c1fc..9ddfc5f11 100644 --- a/shared-bindings/audiobusio/PDMIn.c +++ b/shared-bindings/audiobusio/PDMIn.c @@ -194,7 +194,7 @@ STATIC mp_obj_t audiobusio_pdmin_obj_record(mp_obj_t self_obj, mp_obj_t destinat uint32_t length = MP_OBJ_SMALL_INT_VALUE(destination_length); mp_buffer_info_t bufinfo; - if (MP_OBJ_IS_TYPE(destination, &fatfs_type_fileio)) { + if (MP_OBJ_IS_TYPE(destination, &mp_type_fileio)) { mp_raise_NotImplementedError(""); } else if (mp_get_buffer(destination, &bufinfo, MP_BUFFER_WRITE)) { if (bufinfo.len / mp_binary_get_size('@', bufinfo.typecode, NULL) < length) { diff --git a/shared-bindings/audiobusio/PDMIn.h b/shared-bindings/audiobusio/PDMIn.h index eaed59830..c2a8bab2f 100644 --- a/shared-bindings/audiobusio/PDMIn.h +++ b/shared-bindings/audiobusio/PDMIn.h @@ -29,7 +29,7 @@ #include "common-hal/audiobusio/PDMIn.h" #include "common-hal/microcontroller/Pin.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" extern const mp_obj_type_t audiobusio_pdmin_type; diff --git a/shared-bindings/audioio/WaveFile.c b/shared-bindings/audioio/WaveFile.c index 13c4d6b8f..05768e14d 100644 --- a/shared-bindings/audioio/WaveFile.c +++ b/shared-bindings/audioio/WaveFile.c @@ -73,7 +73,7 @@ STATIC mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_ar audioio_wavefile_obj_t *self = m_new_obj(audioio_wavefile_obj_t); self->base.type = &audioio_wavefile_type; - if (MP_OBJ_IS_TYPE(args[0], &fatfs_type_fileio)) { + if (MP_OBJ_IS_TYPE(args[0], &mp_type_fileio)) { common_hal_audioio_wavefile_construct(self, MP_OBJ_TO_PTR(args[0])); } else { mp_raise_TypeError("file must be a file opened in byte mode"); diff --git a/shared-bindings/audioio/WaveFile.h b/shared-bindings/audioio/WaveFile.h index b6838ce19..255ffbcd5 100644 --- a/shared-bindings/audioio/WaveFile.h +++ b/shared-bindings/audioio/WaveFile.h @@ -29,7 +29,7 @@ #include "common-hal/audioio/AudioOut.h" #include "common-hal/microcontroller/Pin.h" -#include "extmod/vfs_fat_file.h" +#include "extmod/vfs_fat.h" extern const mp_obj_type_t audioio_wavefile_type; diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index ca9281a18..1cfeea59c 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -31,6 +31,7 @@ #include "extmod/vfs_fat.h" #include "py/obj.h" #include "py/objnamedtuple.h" +#include "py/runtime.h" #include "shared-bindings/storage/__init__.h" //| :mod:`storage` --- storage management diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c index a105941c0..6a4dc90e2 100644 --- a/shared-bindings/time/__init__.c +++ b/shared-bindings/time/__init__.c @@ -30,6 +30,7 @@ #include "py/obj.h" #include "py/objnamedtuple.h" +#include "py/runtime.h" #include "lib/timeutils/timeutils.h" #include "shared-bindings/rtc/__init__.h" #include "shared-bindings/time/__init__.h" diff --git a/shared-module/os/__init__.c b/shared-module/os/__init__.c index 1dadd254a..67d489f37 100644 --- a/shared-module/os/__init__.c +++ b/shared-module/os/__init__.c @@ -77,7 +77,7 @@ void common_hal_os_chdir(const char* path) { // subsequent relative paths begin at the root of that VFS. for (vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) { if (vfs->len == 1) { - mp_obj_t root = mp_obj_new_str("/", 1, false); + mp_obj_t root = mp_obj_new_str("/", 1); mp_vfs_proxy_call(vfs, MP_QSTR_chdir, 1, &root); break; } -- cgit v1.2.3