summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-09 08:28:01 +0800
committerGitHub <[email protected]>2025-11-09 08:28:01 +0800
commita1b0ec856e2c22aac84022feb05b6687912e3d6e (patch)
treea4679af3be46069a480be76bdc322eeeefcc4049 /core/src
parent0b91f564b00bf22d611a70c17088ba3a155b8a84 (diff)
parent91ef5fa9376814db12d35a020008a0d692883945 (diff)
Merge pull request #6989 from xmake-io/async
Add async support in os APIs
Diffstat (limited to 'core/src')
m---------core/src/tbox/tbox0
-rw-r--r--core/src/xmake/engine.c36
-rw-r--r--core/src/xmake/thread/event_wait.c2
3 files changed, 35 insertions, 3 deletions
diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox
-Subproject 9bb164af89169f9194be7663795d954b0578831
+Subproject c3a4be464e2e42efdff83ca4abf22134facf5bf
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index 0e79140e6..61ba79af1 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -769,11 +769,25 @@ static tb_bool_t xm_engine_save_arguments(xm_engine_t* engine, tb_int_t argc, tb
return tb_true;
}
-static tb_size_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** argv, tb_char_t* path, tb_size_t maxn)
+static tb_bool_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** argv, tb_char_t* path, tb_size_t maxn)
{
// check
tb_assert_and_check_return_val(engine && path && maxn, tb_false);
+ /* we cache it, because the current path will be changed in thread.
+ *
+ * The executable file compiled using cosmocc on macOS might retrieve a relative path to the programfile.
+ * If the root directory has been changed, the retrieved programfile will be a non-existent path.
+ */
+ static tb_char_t s_program_filepath[TB_PATH_MAXN] = {0};
+ if (s_program_filepath[0])
+ {
+ tb_strlcpy(path, s_program_filepath, maxn);
+ lua_pushstring(engine->lua, s_program_filepath);
+ lua_setglobal(engine->lua, "_PROGRAM_FILE");
+ return tb_true;
+ }
+
tb_bool_t ok = tb_false;
do
{
@@ -813,7 +827,10 @@ static tb_size_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg
if (!_NSGetExecutablePath(path, &bufsize))
ok = tb_true;
#elif defined(XM_PROC_SELF_FILE)
- // get the executale file path as program directory
+ /* get the executale file path as program directory
+ *
+ * @see it may be a relative path
+ */
ssize_t size = readlink(XM_PROC_SELF_FILE, path, (size_t)maxn);
if (size > 0 && size < maxn)
{
@@ -878,6 +895,9 @@ static tb_size_t xm_engine_get_program_file(xm_engine_t* engine, tb_char_t** arg
// trace
tb_trace_d("programfile: %s", path);
+ // cache it
+ tb_strlcpy(s_program_filepath, path, sizeof(s_program_filepath));
+
// save the directory to the global variable: _PROGRAM_FILE
lua_pushstring(engine->lua, path);
lua_setglobal(engine->lua, "_PROGRAM_FILE");
@@ -909,6 +929,15 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t* engine, tb_char_t*
// check
tb_assert_and_check_return_val(engine && path && maxn, tb_false);
+ static tb_char_t s_program_directory[TB_PATH_MAXN] = {0};
+ if (s_program_directory[0])
+ {
+ tb_strlcpy(path, s_program_directory, maxn);
+ lua_pushstring(engine->lua, s_program_directory);
+ lua_setglobal(engine->lua, "_PROGRAM_DIR");
+ return tb_true;
+ }
+
tb_bool_t ok = tb_false;
tb_char_t data[TB_PATH_MAXN] = {0};
do
@@ -994,6 +1023,9 @@ static tb_bool_t xm_engine_get_program_directory(xm_engine_t* engine, tb_char_t*
// trace
tb_trace_d("programdir: %s", path);
+ // cache it
+ tb_strlcpy(s_program_directory, path, sizeof(s_program_directory));
+
// save the directory to the global variable: _PROGRAM_DIR
lua_pushstring(engine->lua, path);
lua_setglobal(engine->lua, "_PROGRAM_DIR");
diff --git a/core/src/xmake/thread/event_wait.c b/core/src/xmake/thread/event_wait.c
index 0831036c6..d6d628311 100644
--- a/core/src/xmake/thread/event_wait.c
+++ b/core/src/xmake/thread/event_wait.c
@@ -15,7 +15,7 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_event_unlock.c
+ * @file thread_event_wait.c
*
*/