summaryrefslogtreecommitdiffstatshomepage
path: root/unix
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-13 12:52:39 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-13 12:52:39 +0100
commit640e7e4779d5d6b5e53fa305e5fe824da7783090 (patch)
treec299b3caf77aca8923a6fdb5554dd5a27ffc4c4e /unix
parentf95c68e53638aa363797595b0d618bbe08c56bb3 (diff)
parent4165cd1c0cfc4eabf446be504787090be84a421b (diff)
downloadmicropython-640e7e4779d5d6b5e53fa305e5fe824da7783090.tar.gz
micropython-640e7e4779d5d6b5e53fa305e5fe824da7783090.zip
Merge pull request #476 from pfalcon/static-sys
Convert sys module to static allocation
Diffstat (limited to 'unix')
-rw-r--r--unix/file.c9
-rw-r--r--unix/main.c11
-rw-r--r--unix/mpconfigport.h1
-rw-r--r--unix/qstrdefsport.h4
4 files changed, 7 insertions, 18 deletions
diff --git a/unix/file.c b/unix/file.c
index fa7be791a4..a0a865a263 100644
--- a/unix/file.c
+++ b/unix/file.c
@@ -146,9 +146,6 @@ mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_open_obj, 1, 2, mp_builtin_open);
-void file_init() {
- mp_obj_t m_sys = mp_obj_new_module(MP_QSTR_sys);
- mp_store_attr(m_sys, MP_QSTR_stdin, fdfile_new(STDIN_FILENO));
- mp_store_attr(m_sys, MP_QSTR_stdout, fdfile_new(STDOUT_FILENO));
- mp_store_attr(m_sys, MP_QSTR_stderr, fdfile_new(STDERR_FILENO));
-}
+const mp_obj_fdfile_t mp_sys_stdin_obj = { .base = {&rawfile_type}, .fd = STDIN_FILENO };
+const mp_obj_fdfile_t mp_sys_stdout_obj = { .base = {&rawfile_type}, .fd = STDOUT_FILENO };
+const mp_obj_fdfile_t mp_sys_stderr_obj = { .base = {&rawfile_type}, .fd = STDERR_FILENO };
diff --git a/unix/main.c b/unix/main.c
index f18e40a7fa..e582244b39 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -42,7 +42,6 @@ long heap_size = 128*1024 * (sizeof(machine_uint_t) / 4);
// Stack top at the start of program
void *stack_top;
-void file_init();
void microsocket_init();
void time_init();
void ffi_init();
@@ -326,7 +325,7 @@ int main(int argc, char **argv) {
p++;
}
}
- mp_sys_path = mp_obj_new_list(path_num, NULL);
+ mp_obj_list_init(mp_sys_path, path_num);
mp_obj_t *path_items;
mp_obj_list_get(mp_sys_path, &path_num, &path_items);
path_items[0] = MP_OBJ_NEW_QSTR(MP_QSTR_);
@@ -348,10 +347,7 @@ int main(int argc, char **argv) {
p = p1 + 1;
}
- mp_obj_t m_sys = mp_obj_new_module(MP_QSTR_sys);
- mp_store_attr(m_sys, MP_QSTR_path, mp_sys_path);
- mp_obj_t py_argv = mp_obj_new_list(0, NULL);
- mp_store_attr(m_sys, MP_QSTR_argv, py_argv);
+ mp_obj_list_init(mp_sys_argv, 0);
mp_store_name(qstr_from_str("test"), test_obj_new(42));
mp_store_name(qstr_from_str("mem_info"), mp_make_function_n(0, mem_info));
@@ -360,7 +356,6 @@ int main(int argc, char **argv) {
mp_store_name(qstr_from_str("gc"), (mp_obj_t)&pyb_gc_obj);
#endif
- file_init();
microsocket_init();
#if MICROPY_MOD_TIME
time_init();
@@ -418,7 +413,7 @@ int main(int argc, char **argv) {
free(basedir);
for (int i = a; i < argc; i++) {
- mp_obj_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
+ mp_obj_list_append(mp_sys_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
}
do_file(argv[a]);
executed = true;
diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h
index e2f2a69e11..832bdb05fb 100644
--- a/unix/mpconfigport.h
+++ b/unix/mpconfigport.h
@@ -13,6 +13,7 @@
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_PATH_MAX (PATH_MAX)
+#define MICROPY_MOD_SYS_STDFILES (1)
// type definitions for the specific machine
diff --git a/unix/qstrdefsport.h b/unix/qstrdefsport.h
index a4772a2be9..42f20d2657 100644
--- a/unix/qstrdefsport.h
+++ b/unix/qstrdefsport.h
@@ -2,10 +2,6 @@
Q(Test)
-Q(argv)
-Q(stdin)
-Q(stdout)
-Q(stderr)
Q(rawsocket)
Q(socket)
Q(sockaddr_in)