[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] Some hacks for Windows Chicken
From: |
Sergey Khorev |
Subject: |
[Chicken-users] Some hacks for Windows Chicken |
Date: |
Mon, 22 Nov 2004 09:40:57 +0300 |
1) Simple patch. Get rid of unneeded declaration
[----- patch1 begin -----]
*** posixwin.scm.bak Mon Sep 20 18:55:35 2004
--- posixwin.scm Sat Nov 20 14:48:45 2004
***************
*** 91,98 ****
#include <time.h>
- extern char **environ;
-
#define ARG_MAX 256
#define PIPE_BUF 512
--- 91,96 ----
[----- patch1 end -----]
2) As I wrote about a week ago, MSVC-built Chicken uses static C runtime. It
means that every .exe and .dll contains its own copy of C runtime and,
accordingly, the set of runtime-structures (e.g. environment block).
The illustration:
(getenv "M") ; => #f
(use posix)
(setenv "M" "qqq)
(getenv "M") ; => #f ; !!!!!
Here is a workaround (use WinAPI function rather than C):
[----- patch2 begin -----]
*** runtime.c.bak Sun Sep 26 19:28:16 2004
--- runtime.c Sun Nov 21 09:28:50 2004
***************
*** 6861,6866 ****
--- 6861,6895 ----
}
+ #if defined(_MSC_VER) && !defined(_DLL)
+ /* we're using static C runtime
+ * each module has its own environment block
+ * use WinAPI to have consistent look to environment */
+
+ # define ENV_SIZE 32767
+ static char *envbuf;
+ static char *C_getenv(const char *var)
+ {
+ envbuf = (char *)malloc(ENV_SIZE);
+ if(!envbuf)
+ return NULL;
+ if(!GetEnvironmentVariable(var, envbuf, ENV_SIZE))
+ {
+ free(envbuf);
+ return NULL;
+ }
+ else
+ return envbuf;
+ }
+ static void C_free_envbuf()
+ {
+ free(envbuf);
+ }
+ #else
+ # define C_getenv(v) getenv(v)
+ # define C_free_envbuf() {}
+ #endif
+
void C_get_environment_variable(C_word c, C_word closure, C_word k,
C_word name)
{
int len;
***************
*** 6876,6882 ****
strncpy(buffer, C_c_string(name), len);
buffer[ len ] = '\0';
! if((save_string = getenv(buffer)) == NULL)
C_kontinue(k, C_SCHEME_FALSE);
C_save(k);
--- 6905,6911 ----
strncpy(buffer, C_c_string(name), len);
buffer[ len ] = '\0';
! if((save_string = C_getenv(buffer)) == NULL)
C_kontinue(k, C_SCHEME_FALSE);
C_save(k);
***************
*** 6896,6901 ****
--- 6925,6931 ----
*a = C_alloc(1 + C_bytestowords(len + 1)),
str = C_string(&a, len, save_string);
+ C_free_envbuf();
C_kontinue(k, str);
}
[----- patch2 end -----]
3) And here is the patch to build Chicken with a dynamic C runtime
(issue command 'nmake -f makefile.vc DYNAMIC_C_RUNTIME=yes')
I can imagine when static RTL may be better than dynamic one. So I think,
that it should be an option: which runtime to use.
[----- patch3 begin -----]
diff -cr ../chicken.bak/chicken.h ./chicken.h
*** ../chicken.bak/chicken.h Fri Nov 12 11:38:03 2004
--- ./chicken.h Sat Nov 20 10:57:54 2004
***************
*** 1251,1256 ****
--- 1251,1257 ----
C_fctexport void C_machine_type(C_word c, C_word closure, C_word k) C_noret;
C_fctexport void C_software_version(C_word c, C_word closure, C_word
k) C_noret;
C_fctexport void C_build_platform(C_word c, C_word closure, C_word k) C_noret;
+ C_fctexport void C_c_runtime(C_word c, C_word closure, C_word k) C_noret;
C_fctexport void C_register_finalizer(C_word c, C_word closure,
C_word k, C_word x, C_word proc) C_noret;
C_fctexport void C_dload(C_word c, C_word closure, C_word k, C_word
name, C_word entry) C_noret;
C_fctexport void C_become(C_word c, C_word closure, C_word k, C_word
table) C_noret;
diff -cr ../chicken.bak/csc.scm.in ./csc.scm.in
*** ../chicken.bak/csc.scm.in Tue Oct 19 09:24:19 2004
--- ./csc.scm.in Sat Nov 20 11:04:03 2004
***************
*** 181,187 ****
(define compile-options
(if win
! '("/c" "/I%CHICKEN_HOME%" "/DC_NO_PIC_NO_DLL")
(cons* "-c" "-DC_NO_PIC_NO_DLL" (if include-dir (list "-I"
include-dir) '())) ) )
(define translation-optimization-options
default-translation-optimization-options)
--- 181,187 ----
(define compile-options
(if win
! (cons* "/c" "/I%CHICKEN_HOME%" "/DC_NO_PIC_NO_DLL" (if (eq?
(c-runtime) 'dynamic) '("/MD") '()))
(cons* "-c" "-DC_NO_PIC_NO_DLL" (if include-dir (list "-I"
include-dir) '())) ) )
(define translation-optimization-options
default-translation-optimization-options)
diff -cr ../chicken.bak/library.scm ./library.scm
*** ../chicken.bak/library.scm Tue Nov 16 10:53:16 2004
--- ./library.scm Sat Nov 20 11:04:46 2004
***************
*** 2549,2554 ****
--- 2549,2558 ----
(let ([sym (string->symbol ((##core#primitive "C_build_platform")))])
(lambda () sym) ) )
+ (define c-runtime
+ (let ([sym (string->symbol ((##core#primitive "C_c_runtime")))])
+ (lambda () sym) ) )
+
(define chicken-version
(let ([v (string-append (number->string build-version) "."
(number->string build-number))])
(lambda () v) ) )
diff -cr ../chicken.bak/makefile.vc ./makefile.vc
*** ../chicken.bak/makefile.vc Tue Nov 2 11:19:50 2004
--- ./makefile.vc Sat Nov 20 11:15:15 2004
***************
*** 2,7 ****
--- 2,10 ----
CC = cl
CFLAGS = /nologo /O2 /DC_DEFAULT_TARGET_STACK_SIZE=300000
/DC_NO_PIC_NO_DLL /DHAVE_LOADLIBRARY /DHAVE_GETPROCADDRESS
/DHAVE_WINDOWS_H
+ !if "$(DYNAMIC_C_RUNTIME)" == "yes"
+ CFLAGS = $(CFLAGS) /MD
+ !endif
LFLAGS = /nologo /subsystem:console /incremental:no /machine:I386
CHICKEN = chicken
SFLAGS = -quiet -explicit-use -debug-level 0 -optimize-level 2
diff -cr ../chicken.bak/runtime.c ./runtime.c
*** ../chicken.bak/runtime.c Fri Nov 12 11:38:08 2004
--- ./runtime.c Sat Nov 20 10:57:07 2004
***************
*** 7098,7103 ****
--- 7098,7126 ----
}
+ void C_c_runtime(C_word c, C_word closure, C_word k)
+ {
+ C_word *a, s;
+
+ if(c != 2) C_bad_argc(c, 2);
+
+ #if defined(_MSC_VER)
+ # if defined(_DLL)
+ a = C_alloc(2 + C_bytestowords(7));
+ s = C_string2(&a, "dynamic");
+ # else
+ a = C_alloc(2 + C_bytestowords(6));
+ s = C_string2(&a, "static");
+ # endif
+ #else
+ a = C_alloc(2 + C_bytestowords(7));
+ s = C_string2(&a, "unknown");
+ #endif
+
+ C_kontinue(k, s);
+ }
+
+
void C_software_version(C_word c, C_word closure, C_word k)
{
C_word *a, s;
[----- patch3 end -----]
4) And a question: (require-extension posix), (use posix), (require 'posix)
all work for MSVC but on MinGW version only (require 'posix) works.
What can be a reason for that?
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Chicken-users] Some hacks for Windows Chicken,
Sergey Khorev <=