~ chicken-core (chicken-5) 295b484337017be94f5acd29d22fe961b9bc4162


commit 295b484337017be94f5acd29d22fe961b9bc4162
Author:     felix <felix@call-with-current-continuation.org>
AuthorDate: Wed Apr 16 16:18:54 2025 +0100
Commit:     felix <felix@call-with-current-continuation.org>
CommitDate: Wed Apr 16 17:22:58 2025 +0200

    some attempts at improving use of wide-char OS API

diff --git a/chicken.h b/chicken.h
index 3ad970e9..5779c03d 100644
--- a/chicken.h
+++ b/chicken.h
@@ -1775,7 +1775,7 @@ C_varextern int
 C_varextern C_uword
   C_heap_growth,
   C_heap_shrinkage;
-C_varextern C_WCHAR
+C_varextern C_char
   **C_main_argv,
 #ifdef SEARCH_EXE_PATH
   *C_main_exe,
@@ -1792,7 +1792,7 @@ C_varextern C_word (*C_get_unbound_variable_value_hook)(C_word sym);
 C_BEGIN_C_DECLS
 
 C_fctexport void C_register_debug_info(C_DEBUG_INFO *);
-C_fctexport int CHICKEN_main(int argc, C_WCHAR *argv[], void *toplevel);
+C_fctexport int CHICKEN_main(int argc, C_char *argv[], void *toplevel);
 C_fctexport int CHICKEN_initialize(int heap, int stack, int symbols, void *toplevel);
 C_fctexport C_word CHICKEN_run(void *toplevel);
 C_fctexport C_word CHICKEN_continue(C_word k);
diff --git a/posixwin.scm b/posixwin.scm
index 3d5e0f9d..9c47dcbf 100644
--- a/posixwin.scm
+++ b/posixwin.scm
@@ -353,7 +353,7 @@ get_user_name()
     Returns: pid, zero return value indicates failure.
 */
 static DWORD
-C_process(const char *app, const char *cmdlin, const char **env,
+C_process(const char *app, C_word cmdlin, const char **env,
           int *phandle, int *pstdin_fd, int *pstdout_fd, int *pstderr_fd,
           int params)
 {
@@ -415,7 +415,7 @@ C_process(const char *app, const char *cmdlin, const char **env,
             wchar_t* pb = (wchar_t*)envblk;
             for (p = env; *p; ++p)
             {
-            	wchar_t *u = C_utf16(*p, 0);
+            	wchar_t *u = C_utf16(*p, 0);  /* BOGUS! */
             	int n = wcslen(*u);
                 C_memcpy(pb, *u, n + 1);
                 pb += n + 1;
@@ -433,7 +433,7 @@ C_process(const char *app, const char *cmdlin, const char **env,
     if (success)
     {
         PROCESS_INFORMATION pi;
-        STARTUPINFO si;
+        STARTUPINFOW si;
 
         ZeroMemory(&pi,sizeof pi);
         ZeroMemory(&si,sizeof si);
@@ -510,12 +510,12 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime)
   return _wutime(fn, &tb);
 }
 
-#define C_u_i_execvp(f, a) C_fix(_wexecvp(C_c_string(f), (void *)C_c_pointer_vector_or_null(a)))
-#define C_u_i_execve(f,a,e) C_fix(_wexecve(C_c_string(f), (void *)C_c_pointer_vector_or_null(a), (void *)C_c_pointer_vector_or_null(e)))
+#define C_u_i_execvp(f, a) C_fix(_wexecvp(C_utf16(f, 0), (void *)C_c_pointer_vector_or_null(a)))
+#define C_u_i_execve(f,a,e) C_fix(_wexecve(C_utf16(f, 0), (void *)C_c_pointer_vector_or_null(a), (void *)C_c_pointer_vector_or_null(e)))
 
 /* MS replacement for the fork-exec pair */
-#define C_u_i_spawnvp(m,f,a)    C_fix(_wspawnvp(C_unfix(m), C_c_string(f), (void *)C_c_pointer_vector_or_null(a)))
-#define C_u_i_spawnvpe(m,f,a,e) C_fix(_wspawnvpe(C_unfix(m), C_c_string(f), (void *)C_c_pointer_vector_or_null(a), (void *)C_c_pointer_vector_or_null(e)))
+#define C_u_i_spawnvp(m,f,a)    C_fix(_wspawnvp(C_unfix(m), C_utf16(f, 0), (void *)C_c_pointer_vector_or_null(a)))
+#define C_u_i_spawnvpe(m,f,a,e) C_fix(_wspawnvpe(C_unfix(m), C_utf16(f, 0), (void *)C_c_pointer_vector_or_null(a), (void *)C_c_pointer_vector_or_null(e)))
 
 <#
 
@@ -737,7 +737,7 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime)
   (foreign-lambda* c-pointer ((scheme-object o))
      "char *ptr = C_malloc(C_header_size(o) * sizeof(wchar_t)); \n"
      "if (ptr != NULL) {\n"
-     "  wchar_t *u = C_utf16(C_data_pointer(o), 0); \n"
+     "  wchar_t *u = C_utf16(o, 0); \n"
      "  C_memcpy(ptr, u, wcslen(u) + 1); \n"
      "}\n"
      "C_return(ptr);"))
@@ -815,7 +815,7 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime)
 (define process-impl
   ;; XXX TODO: When environment is implemented, check for embedded NUL bytes!
   (let ([c-process
-	  (foreign-lambda bool "C_process" c-string c-string c-pointer
+	  (foreign-lambda bool "C_process" c-string scheme-object c-pointer
 	    (c-pointer int) (c-pointer int) (c-pointer int) (c-pointer int) int)])
     ; The environment list must be sorted & include current directory
     ; information for the system drives. i.e !C:=...
@@ -829,7 +829,7 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime)
         (let-location ([handle int -1]
                        [stdin_fd int -1] [stdout_fd int -1] [stderr_fd int -1])
           (let ([res
-                  (c-process cmd cmdlin #f
+                  (c-process cmd (##sys#slot cmdlin 0) #f
                     (location handle)
                     (location stdin_fd) (location stdout_fd) (location stderr_fd)
                     (+ (if stdinf 0 1) (if stdoutf 0 2) (if stderrf 0 4)))])
@@ -849,7 +849,7 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime)
 
 ;; TODO: See if this can be moved to posix-common
 (let ((%process
-        (lambda (loc cmd args env exactf enc)
+        (lambda (loc err? cmd args env exactf enc)
           (let ((chkstrlst
                  (lambda (lst)
                    (##sys#check-list lst loc)
@@ -865,10 +865,10 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime)
             (process-impl loc cmd args env #t #t err? exactf enc)))))
   (set! chicken.process#process
     (lambda (cmd #!optional args env (enc 'utf-8) exactf)
-      (%process 'process cmd args env exactf enc) ))
+      (%process 'process #f cmd args env exactf enc) ))
   (set! chicken.process#process*
     (lambda (cmd #!optional args env (enc 'utf-8) exactf)
-      (%process 'process* cmd args env exactf enc) )) )
+      (%process 'process* #t cmd args env exactf enc) )) )
 
 (define-foreign-variable _exstatus int "C_exstatus")
 
diff --git a/runtime.c b/runtime.c
index e8d747e1..6e331d6d 100644
--- a/runtime.c
+++ b/runtime.c
@@ -356,7 +356,7 @@ time_t
   C_startup_time_sec,
   C_startup_time_msec,
   profile_frequency = 10000;
-char
+C_char
   **C_main_argv,
 #ifdef SEARCH_EXE_PATH
   *C_main_exe = NULL,
@@ -604,7 +604,7 @@ C_dbg(C_char *prefix, C_char *fstr, ...)
 
 /* Startup code: */
 
-int CHICKEN_main(int argc, C_WCHAR *argv[], void *toplevel)
+int CHICKEN_main(int argc, char *argv[], void *toplevel)
 {
   C_word h, s, n;
 
@@ -627,7 +627,7 @@ int CHICKEN_main(int argc, C_WCHAR *argv[], void *toplevel)
       panic(C_text("cannot allocate argument-list buffer"));
 
     for(i = 0; i < argc; ++i) {
-    	arg = C_utf8(argv[ i ]);
+    	arg = argv[ i ];
     	n = strlen(arg);
        aptr = (C_char *)malloc(n + 1);
 
@@ -1367,10 +1367,10 @@ C_word C_resize_pending_finalizers(C_word size) {
 
 /* Parse runtime options from command-line: */
 
-void CHICKEN_parse_command_line(int argc, char *argv[], C_word *heap, C_word *stack, C_word *symbols)
+void CHICKEN_parse_command_line(int argc, C_char *argv[], C_word *heap, C_word *stack, C_word *symbols)
 {
   int i;
-  char *ptr;
+  C_char *ptr;
   C_word x;
 
   C_main_argc = argc;
Trap