From 4ab7fb50a786f5edb9255df668ecc8ef1c982c10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Wed, 14 May 2025 11:05:02 +0200 Subject: [PATCH] boot: move ecl_core_struct to boot.d --- src/c/boot.d | 80 +++++++++++++++++++++++++++++++++++++++++++++++- src/c/main.d | 71 +----------------------------------------- src/h/ecl.h | 1 + src/h/external.h | 32 ++----------------- src/h/nucleus.h | 27 ++++++++++++++++ 5 files changed, 110 insertions(+), 101 deletions(-) diff --git a/src/c/boot.d b/src/c/boot.d index e7df5b213..878533331 100644 --- a/src/c/boot.d +++ b/src/c/boot.d @@ -3,11 +3,27 @@ /* boot.c - initializing ecl internal data */ -/* -- imports ------------------------------------------------------- */ +/* -- imports --------------------------------------------------------------- */ + +#include +#if defined(ECL_MS_WINDOWS_HOST) +# include +# include +# define MAXPATHLEN 512 +#endif +#ifndef MAXPATHLEN +# ifdef PATH_MAX +# define MAXPATHLEN PATH_MAX +# else +# define MAXPATHLEN sysconf(_PC_PATH_MAX) +# include +# endif +#endif #include #include #include +#include /* -- constants ----------------------------------------------------- */ @@ -115,3 +131,65 @@ ecl_set_option(int option, cl_fixnum value) } return ecl_option_values[option]; } + +/* -- core runtime ---------------------------------------------------------- */ + +/* The root environment is a default execution context. */ +static struct cl_env_struct first_env; + +struct ecl_core_struct ecl_core = { + .first_env = &first_env, + /* processes */ +#ifdef ECL_THREADS + .processes = ECL_NIL, + .last_var_index = 0, + .reused_indices = ECL_NIL, +#endif + /* signals */ + .default_sigmask_bytes = 0, + .known_signals = ECL_NIL, + /* allocation */ + .max_heap_size = 0, + .bytes_consed = ECL_NIL, + .gc_counter = ECL_NIL, + .gc_stats = 0, + .safety_region = NULL, + /* pathnames */ + .path_max = 0, + .pathname_translations = ECL_NIL, + /* LIBRARIES is a list of objects. It behaves as a sequence of weak pointers + thanks to the magic in the garbage collector. */ + .libraries = ECL_NIL, + .library_pathname = ECL_NIL +}; + +/* note that this function does not create any environment */ +int +ecl_boot(void) +{ + int i; + + i = ecl_option_values[ECL_OPT_BOOTED]; + if (i) { + if (i < 0) { + /* We have called cl_shutdown and want to use ECL again. */ + ecl_set_option(ECL_OPT_BOOTED, 1); + } + return 1; + } + + init_process(); + /* init_unixint(); */ + /* init_garbage(); */ + + ecl_core.path_max = MAXPATHLEN; + + return 0; +} + +int +ecl_halt(void) +{ + ecl_set_option(ECL_OPT_BOOTED, -1); + return 0; +} diff --git a/src/c/main.d b/src/c/main.d index c003fbbe8..f97ebf1f2 100644 --- a/src/c/main.d +++ b/src/c/main.d @@ -15,20 +15,6 @@ /******************************** IMPORTS *****************************/ #include -#include -#if defined(ECL_MS_WINDOWS_HOST) -# include -# include -# define MAXPATHLEN 512 -#endif -#ifndef MAXPATHLEN -# ifdef PATH_MAX -# define MAXPATHLEN PATH_MAX -# else -# define NO_PATH_MAX -# include -# endif -#endif #ifdef ECL_USE_MPROTECT # include # ifndef MAP_FAILED @@ -51,61 +37,6 @@ const char *ecl_self; -/* -- core runtime ---------------------------------------------------------- */ - -/* The root environment is a default execution context. */ -static struct cl_env_struct first_env; - -struct ecl_core_struct ecl_core = { - .first_env = &first_env, - /* processes */ -#ifdef ECL_THREADS - .processes = ECL_NIL, - .last_var_index = 0, - .reused_indices = ECL_NIL, -#endif - /* signals */ - .default_sigmask_bytes = 0, - .known_signals = ECL_NIL, - /* allocation */ - .max_heap_size = 0, - .bytes_consed = ECL_NIL, - .gc_counter = ECL_NIL, - .gc_stats = 0, - .safety_region = NULL, - /* pathnames */ - .path_max = 0, - .pathname_translations = ECL_NIL, - /* LIBRARIES is a list of objects. It behaves as a sequence of weak pointers - thanks to the magic in the garbage collector. */ - .libraries = ECL_NIL, - .library_pathname = ECL_NIL -}; - -/* note that this function does not create any environment */ -int -ecl_boot(void) -{ - int i; - - i = ecl_option_values[ECL_OPT_BOOTED]; - if (i) { - if (i < 0) { - /* We have called cl_shutdown and want to use ECL again. */ - ecl_set_option(ECL_OPT_BOOTED, 1); - } - return 1; - } - - init_process(); - /* init_unixint(); */ - /* init_garbage(); */ - - ecl_core.path_max = MAXPATHLEN; - - return 0; -} - /************************ GLOBAL INITIALIZATION ***********************/ static int ARGC; @@ -290,7 +221,7 @@ cl_shutdown(void) ecl_tcp_close_all(); #endif } - ecl_set_option(ECL_OPT_BOOTED, -1); + ecl_halt(); } ecl_def_ct_base_string(str_common_lisp,"COMMON-LISP",11,static,const); diff --git a/src/h/ecl.h b/src/h/ecl.h index ee1fca141..a95e27e70 100644 --- a/src/h/ecl.h +++ b/src/h/ecl.h @@ -80,6 +80,7 @@ #endif #include +#include #include #include #include diff --git a/src/h/external.h b/src/h/external.h index 89ec08a5d..a02e6c72e 100755 --- a/src/h/external.h +++ b/src/h/external.h @@ -171,35 +171,6 @@ struct ecl_interrupt_struct { extern ECL_API cl_env_ptr cl_env_p; #endif -/* Core environment. */ - -struct ecl_core_struct { - cl_env_ptr first_env; -#ifdef ECL_THREADS - cl_object processes; - ecl_mutex_t processes_lock; - ecl_mutex_t global_lock; - ecl_mutex_t error_lock; - ecl_rwlock_t global_env_lock; - cl_index last_var_index; - cl_object reused_indices; -#endif - size_t max_heap_size; - cl_object bytes_consed; - cl_object gc_counter; - bool gc_stats; - char *safety_region; - - cl_index default_sigmask_bytes; - cl_object known_signals; - - int path_max; - cl_object pathname_translations; - - cl_object libraries; - cl_object library_pathname; -}; - /* Per-process data. Modify main.d accordingly. */ struct cl_core_struct { @@ -246,8 +217,9 @@ extern ECL_API void ecl_free(void *ptr); extern ECL_API void ecl_copy(void *dst, void *src, cl_index ndx); #define ecl_free_unsafe(x) ecl_free(x); -/* cold_boot.c */ +/* boot.c */ extern ECL_API int ecl_boot(void); +extern ECL_API int ecl_halt(void); extern ECL_API const cl_object ecl_ct_Jan1st1970UT; extern ECL_API const cl_object ecl_ct_null_string; diff --git a/src/h/nucleus.h b/src/h/nucleus.h index 54c9fc92d..70d7617d9 100644 --- a/src/h/nucleus.h +++ b/src/h/nucleus.h @@ -6,4 +6,31 @@ #include "external.h" +struct ecl_core_struct { + cl_env_ptr first_env; +#ifdef ECL_THREADS + cl_object processes; + ecl_mutex_t processes_lock; + ecl_mutex_t global_lock; + ecl_mutex_t error_lock; + ecl_rwlock_t global_env_lock; + cl_index last_var_index; + cl_object reused_indices; +#endif + size_t max_heap_size; + cl_object bytes_consed; + cl_object gc_counter; + bool gc_stats; + char *safety_region; + + cl_index default_sigmask_bytes; + cl_object known_signals; + + int path_max; + cl_object pathname_translations; + + cl_object libraries; + cl_object library_pathname; +}; + #endif /* ECL_NUCLEUS_H */