Merge branch 'master' of git://factorcode.org/git/factor

db4
slava 2008-04-09 19:47:28 -05:00
commit 0fa5e73ffc
9 changed files with 56 additions and 23 deletions

View File

@ -89,6 +89,11 @@ set_md5sum() {
set_gcc() { set_gcc() {
case $OS in case $OS in
openbsd) ensure_program_installed egcc; CC=egcc;; openbsd) ensure_program_installed egcc; CC=egcc;;
netbsd) if [[ $WORD -eq 64 ]] ; then
CC=/usr/pkg/gcc34/bin/gcc
else
CC=gcc
fi ;;
*) CC=gcc;; *) CC=gcc;;
esac esac
} }
@ -185,6 +190,7 @@ find_architecture() {
i386) ARCH=x86;; i386) ARCH=x86;;
i686) ARCH=x86;; i686) ARCH=x86;;
amd64) ARCH=x86;; amd64) ARCH=x86;;
ppc64) ARCH=ppc;;
*86) ARCH=x86;; *86) ARCH=x86;;
*86_64) ARCH=x86;; *86_64) ARCH=x86;;
"Power Macintosh") ARCH=ppc;; "Power Macintosh") ARCH=ppc;;

View File

@ -12,3 +12,10 @@ os unix? [
[ ] [ "envs" get set-os-envs ] unit-test [ ] [ "envs" get set-os-envs ] unit-test
[ t ] [ os-envs "envs" get = ] unit-test [ t ] [ os-envs "envs" get = ] unit-test
] when ] when
[ ] [ "factor-test-key-1" unset-os-env ] unit-test
[ ] [ "ps3" "factor-test-key-1" set-os-env ] unit-test
[ "ps3" ] [ "factor-test-key-1" os-env ] unit-test
[ ] [ "factor-test-key-1" unset-os-env ] unit-test
[ f ] [ "factor-test-key-1" os-env ] unit-test

View File

@ -1,4 +1,12 @@
#include <ucontext.h>
#define FRAME_RETURN_ADDRESS(frame) *((XT *)(frame_successor(frame) + 1) + 1) #define FRAME_RETURN_ADDRESS(frame) *((XT *)(frame_successor(frame) + 1) + 1)
INLINE void *ucontext_stack_pointer(void *uap)
{
ucontext_t *ucontext = (ucontext_t *)uap;
return (void *)ucontext->uc_mcontext.uc_regs->gregs[PT_R1];
}
#define UAP_PROGRAM_COUNTER(ucontext) \ #define UAP_PROGRAM_COUNTER(ucontext) \
(((ucontext_t *)(ucontext))->uc_mcontext.uc_regs->gregs[PT_NIP]) (((ucontext_t *)(ucontext))->uc_mcontext.uc_regs->gregs[PT_NIP])

View File

@ -15,4 +15,10 @@ DLLEXPORT void c_to_factor_toplevel(CELL quot);
#ifndef environ #ifndef environ
extern char ***_NSGetEnviron(void); extern char ***_NSGetEnviron(void);
#define environ (*_NSGetEnviron()) #define environ (*_NSGetEnviron())
#endif #endif
INLINE void *ucontext_stack_pointer(void *uap)
{
ucontext_t *ucontext = (ucontext_t *)uap;
return ucontext->uc_stack.ss_sp;
}

View File

@ -1,7 +0,0 @@
#include <ucontext.h>
INLINE void *ucontext_stack_pointer(void *uap)
{
ucontext_t *ucontext = (ucontext_t *)uap;
return ucontext->uc_stack.ss_sp;
}

View File

@ -85,6 +85,16 @@ DEFINE_PRIMITIVE(read_dir)
dpush(result); dpush(result);
} }
DEFINE_PRIMITIVE(os_env)
{
char *name = unbox_char_string();
char *value = getenv(name);
if(value == NULL)
dpush(F);
else
box_char_string(value);
}
DEFINE_PRIMITIVE(os_envs) DEFINE_PRIMITIVE(os_envs)
{ {
GROWABLE_ARRAY(result); GROWABLE_ARRAY(result);

View File

@ -215,19 +215,34 @@ void sleep_millis(DWORD msec)
Sleep(msec); Sleep(msec);
} }
DEFINE_PRIMITIVE(os_env)
{
F_CHAR *key = unbox_u16_string();
F_CHAR *value = safe_malloc(MAX_UNICODE_PATH);
int ret;
ret = GetEnvironmentVariable(key, value, MAX_UNICODE_PATH);
if(ret == 0)
dpush(F);
else
dpush(tag_object(from_u16_string(value)));
free(value);
}
DEFINE_PRIMITIVE(set_os_env) DEFINE_PRIMITIVE(set_os_env)
{ {
F_CHAR *key = unbox_u16_string(); F_CHAR *key = unbox_u16_string();
REGISTER_C_STRING(key); REGISTER_C_STRING(key);
F_CHAR *value = unbox_u16_string(); F_CHAR *value = unbox_u16_string();
UNREGISTER_C_STRING(key); UNREGISTER_C_STRING(key);
SetEnvironmentVariable(key, value); if(!SetEnvironmentVariable(key, value))
general_error(ERROR_IO, tag_object(get_error_message()), F, NULL);
} }
DEFINE_PRIMITIVE(unset_os_env) DEFINE_PRIMITIVE(unset_os_env)
{ {
F_CHAR *key = unbox_u16_string(); if(!SetEnvironmentVariable(unbox_u16_string(), NULL)
SetEnvironmentVariable(key, NULL); && GetLastError() != ERROR_ENVVAR_NOT_FOUND)
general_error(ERROR_IO, tag_object(get_error_message()), F, NULL);
} }
DEFINE_PRIMITIVE(set_os_envs) DEFINE_PRIMITIVE(set_os_envs)

View File

@ -27,7 +27,6 @@
#include "os-unix.h" #include "os-unix.h"
#ifdef __APPLE__ #ifdef __APPLE__
#include "os-unix-ucontext.h"
#include "os-macosx.h" #include "os-macosx.h"
#include "mach_signal.h" #include "mach_signal.h"
@ -84,7 +83,6 @@
#if defined(FACTOR_X86) #if defined(FACTOR_X86)
#include "os-linux-x86.32.h" #include "os-linux-x86.32.h"
#elif defined(FACTOR_PPC) #elif defined(FACTOR_PPC)
#include "os-unix-ucontext.h"
#include "os-linux-ppc.h" #include "os-linux-ppc.h"
#elif defined(FACTOR_ARM) #elif defined(FACTOR_ARM)
#include "os-linux-arm.h" #include "os-linux-arm.h"

View File

@ -280,16 +280,6 @@ DEFINE_PRIMITIVE(exit)
exit(to_fixnum(dpop())); exit(to_fixnum(dpop()));
} }
DEFINE_PRIMITIVE(os_env)
{
char *name = unbox_char_string();
char *value = getenv(name);
if(value == NULL)
dpush(F);
else
box_char_string(value);
}
DEFINE_PRIMITIVE(eq) DEFINE_PRIMITIVE(eq)
{ {
CELL lhs = dpop(); CELL lhs = dpop();