Compare commits

..

2 Commits

Author SHA1 Message Date
Krzosa Karol
17f4306fc3 Update todo 2026-02-07 14:11:47 +01:00
Krzosa Karol
80df86df3d Stabilize process execution and editor cleanup 2026-02-07 11:08:29 +01:00
7 changed files with 37 additions and 30 deletions

View File

@@ -726,8 +726,8 @@ API double GetTimeSeconds() {
return GetTimeMicros() / 1000000.0; return GetTimeMicros() / 1000000.0;
} }
API String WriteTempFile(String data) { API String WriteTempFile(Allocator allocator, String data) {
Scratch scratch; Scratch scratch(allocator);
#if OS_WINDOWS #if OS_WINDOWS
int buffer_len = MAX_PATH+1; int buffer_len = MAX_PATH+1;
@@ -737,12 +737,12 @@ API String WriteTempFile(String data) {
Assert(result != 0); Assert(result != 0);
String16 temp16 = {buffer, result}; String16 temp16 = {buffer, result};
NormalizePathInPlace(temp16); NormalizePathInPlace(temp16);
String temp_directory = ToString(scratch, temp16); String temp_directory = ToString(allocator, temp16);
#else #else
String temp_directory = "/tmp"; String temp_directory = "/tmp";
#endif #endif
String temp_filename = Format(scratch, "%S/temp%llu", temp_directory, GetTimeNanos()); String temp_filename = Format(allocator, "%S/temp%llu", temp_directory, GetTimeNanos());
bool done = WriteFile(temp_filename, data); bool done = WriteFile(temp_filename, data);
Assert(done); Assert(done);
return temp_filename; return temp_filename;

View File

@@ -32,6 +32,7 @@ bool IsFile(String path);
String GetWorkingDir(Allocator arena); String GetWorkingDir(Allocator arena);
bool IsAbsolute(String path); bool IsAbsolute(String path);
int64_t GetFileModTime(String file); int64_t GetFileModTime(String file);
String WriteTempFile(Allocator allocator, String data);

View File

@@ -118,6 +118,7 @@ void LexDigit(Lexer *lex, Token *t) {
} }
bool IsOkForIdent(Lexer *lex, char c) { bool IsOkForIdent(Lexer *lex, char c) {
Unused(lex);
bool result = IsAlphanumeric(c) || c == '_' || c == '/'; bool result = IsAlphanumeric(c) || c == '_' || c == '/';
return result; return result;
} }

View File

@@ -70,7 +70,7 @@ void Coro_SearchOpenBuffers(mco_coro *co) {
if (out_buffer == NULL) { if (out_buffer == NULL) {
return; return;
} }
Buffer *it = GetBuffer(id, NULL); it = GetBuffer(id, NULL);
if (it == NULL) { if (it == NULL) {
goto skip_buffer; goto skip_buffer;
} }

View File

@@ -233,22 +233,23 @@ Array<char *> SplitCommand(Allocator allocator, String command_line) {
return cmd; return cmd;
} }
Process SpawnProcess(String command_line, String working_dir, String write_stdin, Array<String> enviroment) { Process SpawnProcess(ExecArgs args) {
Scratch scratch; Scratch scratch;
const int PIPE_READ = 0; const int PIPE_READ = 0;
const int PIPE_WRITE = 1; const int PIPE_WRITE = 1;
bool error = false; bool error = false;
working_dir = Copy(scratch, working_dir); String working_dir = Copy(scratch, args.cwd);
chdir(working_dir.data); chdir(working_dir.data);
Process process = {}; Process process = {};
process.args = args; process.args = args;
UnixProcess *plat = (UnixProcess *)&process.platform; UnixProcess *plat = (UnixProcess *)&process.platform;
Array<char *> args = SplitCommand(scratch, command_line); Array<char *> args_cmd = SplitCommand(scratch, args.cmd);
Array<char *> env = {scratch}; Array<char *> env = {scratch};
char *exe = Copy(scratch, args.exe).data;
For (enviroment) { For (args.env) {
Add(&env, Copy(scratch, it).data); Add(&env, Copy(scratch, it).data);
} }
@@ -308,6 +309,7 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin
return process; return process;
} }
if (args.open_stdin) {
error = posix_spawn_file_actions_addclose(&actions, stdin_desc[PIPE_WRITE]) != 0; error = posix_spawn_file_actions_addclose(&actions, stdin_desc[PIPE_WRITE]) != 0;
if (error) { if (error) {
Error("Libc function failed: posix_spawn_file_actions_addclose, with error: %s", strerror(errno)); Error("Libc function failed: posix_spawn_file_actions_addclose, with error: %s", strerror(errno));
@@ -319,9 +321,10 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin
Error("Libc function failed: posix_spawn_file_actions_adddup2 STDIN_FILENO, with error: %s", strerror(errno)); Error("Libc function failed: posix_spawn_file_actions_adddup2 STDIN_FILENO, with error: %s", strerror(errno));
return process; return process;
} }
}
pid_t process_pid = 0; pid_t process_pid = 0;
error = posix_spawnp(&process_pid, args[0], &actions, NULL, args.data, env.data) != 0; error = posix_spawnp(&process_pid, exe, &actions, NULL, args_cmd.data, env.data) != 0;
if (error) { if (error) {
Error("Libc function failed: failed to create process\n, with error: %s", strerror(errno)); Error("Libc function failed: failed to create process\n, with error: %s", strerror(errno));
return process; return process;
@@ -329,12 +332,9 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin
plat->child_stdout_read = stdout_desc[PIPE_READ]; plat->child_stdout_read = stdout_desc[PIPE_READ];
plat->stdin_write = stdin_desc[PIPE_WRITE];
plat->pid = process_pid; plat->pid = process_pid;
if (args.open_stdin) {
if (write_stdin.len) { plat->stdin_write = stdin_desc[PIPE_WRITE];
WriteStdin(&process, write_stdin);
CloseStdin(&process);
} }
process.id = process_pid; process.id = process_pid;
@@ -431,8 +431,13 @@ String FindPython(Allocator allocator) {
for (int i = 0; i < Lengthof(tries); i += 1) { for (int i = 0; i < Lengthof(tries); i += 1) {
For (paths) { For (paths) {
String path_it = Format(scratch, "%S/%S" IF_OS_WINDOWS_ELSE(".exe", ""), it, tries[i]); String path_it = Format(scratch, "%S/%S" IF_OS_WINDOWS_ELSE(".exe", ""), it, tries[i]);
#if OS_WINDOWS
bool is_bad_bad_ms = EndsWith(it, "AppData\\Local\\Microsoft\\WindowsApps") || EndsWith(it, "AppData/Local/Microsoft/WindowsApps"); bool is_bad_bad_ms = EndsWith(it, "AppData\\Local\\Microsoft\\WindowsApps") || EndsWith(it, "AppData/Local/Microsoft/WindowsApps");
if (FileExists(path_it) IF_OS_WINDOWS(&& !is_bad_bad_ms)) { if (is_bad_bad_ms) {
continue;
}
#endif
if (FileExists(path_it)) {
return Copy(allocator, path_it); return Copy(allocator, path_it);
} }
} }
@@ -446,7 +451,7 @@ void SetShell(Allocator allocator, String *exe, String *cmd, String in_cmd) {
*cmd = Format(allocator, "%S /C %S", *exe, in_cmd); *cmd = Format(allocator, "%S /C %S", *exe, in_cmd);
#else #else
*exe = "/usr/bin/bash"; *exe = "/usr/bin/bash";
String temp_file = WriteTempFile(in_cmd); // @todo: maybe try to pass by stdio here String temp_file = WriteTempFile(allocator, in_cmd); // @todo: maybe try to pass by stdio here
*cmd = Format(allocator, "%S %S", *exe, temp_file); *cmd = Format(allocator, "%S %S", *exe, temp_file);
#endif #endif
} }

View File

@@ -7,9 +7,10 @@
- [ ] GetWindowZOrder to IterateWindowsInZOrder - [ ] GetWindowZOrder to IterateWindowsInZOrder
- [ ] Rework history API, tagging modification blocks with carets? - [ ] Rework history API, tagging modification blocks with carets?
- [ ] The lexing / parsing code for config / bindings appears sloppy would be nice to clean it up but I don't have any ideas - [ ] The lexing / parsing code for config / bindings appears sloppy would be nice to clean it up but I don't have any ideas
- [ ] Directory tree doesn't make much sense! Maybe just consolidate into one folder? create nice names - the raddbg idea didn't pan out well here
- [ ] Test BlockArena correctnsess - random allocations, writes and undos, try to crash - [ ] Test BlockArena correctnsess - random allocations, writes and undos, try to crash
- [ ] New error mechanism - New error mechanism - we were losing errors when ReportError was called multiple times, I still want that but I don't want to lose errors, so turn it into a summary list of errors
- [ ] BeginLog EndLog, and then show all logs as a list in the UI thing - [ ] BeginLog EndLog, and then show all logs as a list in the UI thing
- [ ] Undo kinds (to enable history in fuzzy buffers) - [ ] Undo kinds (to enable history in fuzzy buffers)
- [ ] Add undo kind. Snapshot kind, so that history is possible in weird buffers without paying a huge memory cost. The idea is that we would store the exact buffer state to replace with, editor would just save history of first line etc. - [ ] Add undo kind. Snapshot kind, so that history is possible in weird buffers without paying a huge memory cost. The idea is that we would store the exact buffer state to replace with, editor would just save history of first line etc.

View File

@@ -294,7 +294,6 @@ void TestInsertVariable() {
String a = "Thing/@(ProjectFolder)/Another"; String a = "Thing/@(ProjectFolder)/Another";
String b = "Thing/@ProjectFolder/Another"; String b = "Thing/@ProjectFolder/Another";
Assert(InsertVariables(scratch, a) == InsertVariables(scratch, b)); Assert(InsertVariables(scratch, a) == InsertVariables(scratch, b));
int c = 10;
} RegisterFunction(&TestFunctions, TestInsertVariable); } RegisterFunction(&TestFunctions, TestInsertVariable);
@@ -545,7 +544,7 @@ BSet Open(Window *window, String path, ResolveOpenMeta meta, bool set_active = t
if (o.use_python_shell == 1) { if (o.use_python_shell == 1) {
args.exe = FindPython(scratch); args.exe = FindPython(scratch);
String temp_file = WriteTempFile(o.path); String temp_file = WriteTempFile(scratch, o.path);
args.cmd = Format(scratch, "%S %S", args.exe, temp_file); args.cmd = Format(scratch, "%S %S", args.exe, temp_file);
} else { } else {
SetShell(scratch, &args.exe, &args.cmd, o.path); SetShell(scratch, &args.exe, &args.cmd, o.path);