diff --git a/ekc3/ekc3.c b/ekc3/ekc3.c
index 3d0c980..6998924 100644
--- a/ekc3/ekc3.c
+++ b/ekc3/ekc3.c
@@ -499,10 +499,10 @@ s_str * ekc3_render_file_to_str (const s_str *path, s_str *dest)
fclose(fp);
return NULL;
}
- file_dir = frame_get_w(&g_kc3_env.global_frame, &g_sym___DIR__);
+ file_dir = frame_get_w(&g_kc3_env->global_frame, &g_sym___DIR__);
file_dir_save = *file_dir;
file_dirname(path, &file_dir->data.str);
- file_path = frame_get_w(&g_kc3_env.global_frame, &g_sym___FILE__);
+ file_path = frame_get_w(&g_kc3_env->global_frame, &g_sym___FILE__);
file_path_save = *file_path;
file_path->data.str = *path;
result = ekc3_render_buf_to_str(&in, dest);
diff --git a/event/event.c b/event/event.c
index 0aa1858..98975ca 100644
--- a/event/event.c
+++ b/event/event.c
@@ -93,8 +93,7 @@ void kc3_event_callback (int fd, short events, void *tag_tuple)
(events_list, list_new_ptr
(ev, list_new_tag_copy
(arg, NULL))));
- if (! env_eval_call_callable_args(&g_kc3_env, callable, arguments,
- &tmp)) {
+ if (! eval_callable_call(callable, arguments, &tmp)) {
err_puts("kc3_event_callback: callback failed");
assert(! "kc3_event_callback: callback failed");
abort();
diff --git a/http/mime_type.c b/http/mime_type.c
index b3ed039..e3113b6 100644
--- a/http/mime_type.c
+++ b/http/mime_type.c
@@ -26,7 +26,7 @@ const s_sym ** http_mime_type (const s_str *ext, const s_sym **dest)
tag_init_sym(&tag_mime_type_sym, sym_1("mime_type"));
tag_init_var(&tag_mime_type_value, &g_sym_Sym);
default_mime_type = sym_1("application/octet-stream");
- if (! facts_with_tags(&g_kc3_env.facts, &cursor, &tag_ext,
+ if (! facts_with_tags(&g_kc3_env->facts, &cursor, &tag_ext,
&tag_mime_type_sym, &tag_mime_type_value))
goto default_mime_type;
if (! facts_cursor_next(&cursor, &fact) ||
@@ -130,7 +130,7 @@ bool http_mime_type_def (s_tag *ext, const s_sym * const *mime_type)
assert(mime_type);
tag_init_sym(&tag_mime_type_sym, sym_1("mime_type"));
tag_init_sym(&tag_mime_type_value, *mime_type);
- if (! facts_replace_tags(&g_kc3_env.facts, ext,
+ if (! facts_replace_tags(&g_kc3_env->facts, ext,
&tag_mime_type_sym,
&tag_mime_type_value))
return false;
diff --git a/httpd/httpd.c b/httpd/httpd.c
index a5688fb..dfbf5d5 100644
--- a/httpd/httpd.c
+++ b/httpd/httpd.c
@@ -38,7 +38,7 @@ int main (int argc, char **argv)
s_tag tmp = {0};
const struct tm *utc = NULL;
kc3_init(NULL, &argc, &argv);
- g_kc3_env.trace = true;
+ g_kc3_env->trace = true;
while (argc > 0 && argv[0] && argv[0][0] == '-') {
skip = 1;
p = argv[0] + 1;
@@ -52,7 +52,7 @@ int main (int argc, char **argv)
return 1;
}
str_init_1(&str, NULL, argv[1]);
- if (! facts_open_file(&g_kc3_env.facts, &str)) {
+ if (! facts_open_file(&g_kc3_env->facts, &str)) {
err_puts("kc3_httpd: -D: facts_open_file");
assert(! "kc3_httpd: -D: facts_open_file");
kc3_clean(NULL);
@@ -112,18 +112,18 @@ int main (int argc, char **argv)
kc3_clean(NULL);
return 1;
}
- buf_file_close(&g_kc3_env.out);
+ buf_file_close(&g_kc3_env->out);
dup2(log_fd, 1);
- buf_fd_open_w(&g_kc3_env.out, 1);
- buf_file_close(&g_kc3_env.err);
+ buf_fd_open_w(&g_kc3_env->out, 1);
+ buf_file_close(&g_kc3_env->err);
dup2(log_fd, 2);
- buf_fd_open_w(&g_kc3_env.err, 2);
- buf_file_close(&g_kc3_env.in);
+ buf_fd_open_w(&g_kc3_env->err, 2);
+ buf_file_close(&g_kc3_env->in);
close(0);
}
ident_init(&daemonize_ident, &g_sym_KC3, sym_1("daemonize"));
tag_init_bool(&daemonize_value, daemonize);
- env_def(&g_kc3_env, &daemonize_ident, &daemonize_value);
+ env_def(g_kc3_env, &daemonize_ident, &daemonize_value);
io_puts("KC3 HTTPd loading, please wait...");
#ifndef WIN32
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
diff --git a/ikc3/ikc3.c b/ikc3/ikc3.c
index 7bf61da..ddc5b48 100644
--- a/ikc3/ikc3.c
+++ b/ikc3/ikc3.c
@@ -48,19 +48,19 @@ sw ikc3_run (void)
sw r;
s_tag result;
while (1) {
- r = buf_ignore_spaces(&g_kc3_env.in);
+ r = buf_ignore_spaces(&g_kc3_env->in);
if (r < 0)
return 0;
- r = buf_parse_comments(&g_kc3_env.in);
+ r = buf_parse_comments(&g_kc3_env->in);
if (r < 0)
return 0;
- r = buf_parse_tag(&g_kc3_env.in, &input);
+ r = buf_parse_tag(&g_kc3_env->in, &input);
if (r > 0) {
if (! eval_tag(&input, &result)) {
tag_clean(&input);
continue;
}
- if (buf_inspect_tag(&g_kc3_env.out, &result) < 0) {
+ if (buf_inspect_tag(&g_kc3_env->out, &result) < 0) {
tag_clean(&input);
tag_clean(&result);
return 0;
@@ -70,11 +70,11 @@ sw ikc3_run (void)
}
if (r < 0 ||
(r == 0 &&
- (r = buf_ignore_character(&g_kc3_env.in)) <= 0))
+ (r = buf_ignore_character(&g_kc3_env->in)) <= 0))
return 0;
- if ((r = buf_write_1(&g_kc3_env.out, "\n")) < 0)
+ if ((r = buf_write_1(&g_kc3_env->out, "\n")) < 0)
return 0;
- if ((r = buf_flush(&g_kc3_env.out)) < 0)
+ if ((r = buf_flush(&g_kc3_env->out)) < 0)
return 0;
}
return 0;
@@ -96,7 +96,7 @@ int main (int argc, char **argv)
return usage("ikc3");
if (! kc3_init(NULL, &argc, &argv))
return 1;
- env = &g_kc3_env;
+ env = g_kc3_env;
in_original = env->in;
buf_init(&env->in, false, sizeof(in_data), in_data);
while (argc) {
diff --git a/kc3s/kc3s.c b/kc3s/kc3s.c
index 92f59ec..a427323 100644
--- a/kc3s/kc3s.c
+++ b/kc3s/kc3s.c
@@ -63,14 +63,14 @@ sw kc3s_run (void)
s_tag input;
sw r;
s_tag result;
- while ((r = buf_ignore_spaces(&g_kc3_env.in)) >= 0) {
- if ((r = buf_parse_tag(&g_kc3_env.in, &input)) > 0) {
+ while ((r = buf_ignore_spaces(&g_kc3_env->in)) >= 0) {
+ if ((r = buf_parse_tag(&g_kc3_env->in, &input)) > 0) {
if (! eval_tag(&input, &result)) {
tag_clean(&input);
continue;
}
/*
- if (buf_inspect_tag(&g_kc3_env.out, &result) < 0) {
+ if (buf_inspect_tag(&g_kc3_env->out, &result) < 0) {
tag_clean(&input);
tag_clean(&result);
break;
@@ -79,14 +79,14 @@ sw kc3s_run (void)
tag_clean(&input);
tag_clean(&result);
/*
- buf_write_u8(&g_kc3_env.out, '\n');
- if ((r = buf_flush(&g_kc3_env.out)) < 0)
+ buf_write_u8(&g_kc3_env->out, '\n');
+ if ((r = buf_flush(&g_kc3_env->out)) < 0)
break;
*/
}
if (r < 0 ||
(r == 0 &&
- (r = buf_ignore_character(&g_kc3_env.in)) <= 0))
+ (r = buf_ignore_character(&g_kc3_env->in)) <= 0))
break;
}
return 0;
@@ -107,7 +107,7 @@ int main (int argc, char **argv)
return usage(argv[0]);
if (! kc3_init(NULL, &argc, &argv))
return 1;
- env = &g_kc3_env;
+ env = g_kc3_env;
in_original = env->in;
buf_init(&env->in, false, sizeof(in_data), in_data);
while (argc) {
diff --git a/libkc3/array.c b/libkc3/array.c
index 941e6e9..c879640 100644
--- a/libkc3/array.c
+++ b/libkc3/array.c
@@ -18,6 +18,7 @@
#include "buf_inspect.h"
#include "buf_parse.h"
#include "data.h"
+#include "eval.h"
#include "io.h"
#include "list.h"
#include "sym.h"
@@ -236,7 +237,7 @@ s_array * array_init_1 (s_array *array, const char *p)
array_clean(&tmp);
return NULL;
}
- if (! env_eval_array(&g_kc3_env, &tmp, array)) {
+ if (! eval_array(&tmp, array)) {
err_puts("array_init_1: env_eval_array");
assert(! "array_init_1: env_eval_array");
array_clean(&tmp);
diff --git a/libkc3/assert.h b/libkc3/assert.h
index d5eaf0e..5b753c2 100644
--- a/libkc3/assert.h
+++ b/libkc3/assert.h
@@ -23,8 +23,8 @@ void abort (void);
do { \
sw assert_line = __LINE__; \
if (! (test)) { \
- if (g_kc3_env.argv && g_kc3_env.argv[0]) { \
- err_write_1(g_kc3_env.argv[0]); \
+ if (g_kc3_env->argv && g_kc3_env->argv[0]) { \
+ err_write_1(g_kc3_env->argv[0]); \
err_write_1(": "); \
} \
err_write_1("assertion failed: "); \
diff --git a/libkc3/buf_inspect.c b/libkc3/buf_inspect.c
index 4c6ee24..e51c81e 100644
--- a/libkc3/buf_inspect.c
+++ b/libkc3/buf_inspect.c
@@ -2264,7 +2264,7 @@ sw buf_inspect_ident (s_buf *buf, const s_ident *ident)
assert(ident);
result = 0;
// FIXME
- if (ident->module && ident->module != g_kc3_env.current_defmodule) {
+ if (ident->module && ident->module != g_kc3_env->current_defmodule) {
if ((r = buf_inspect_sym(buf, &ident->module)) < 0)
return r;
result += r;
@@ -2283,7 +2283,7 @@ sw buf_inspect_ident_size (s_pretty *pretty, const s_ident *ident)
sw r;
sw result = 0;
assert(ident);
- if (ident->module && ident->module != g_kc3_env.current_defmodule) {
+ if (ident->module && ident->module != g_kc3_env->current_defmodule) {
if ((r = buf_inspect_sym_size(pretty, &ident->module)) < 0)
return r;
result += r;
diff --git a/libkc3/buf_parse.c b/libkc3/buf_parse.c
index 79063c1..36c08df 100644
--- a/libkc3/buf_parse.c
+++ b/libkc3/buf_parse.c
@@ -4025,7 +4025,7 @@ sw buf_parse_tag_ident (s_buf *buf, s_tag *dest)
r = buf_parse_ident(buf, &dest->data.ident);
if (r > 0) {
if (! dest->data.ident.module &&
- (tag = frame_get_w(&g_kc3_env.read_time_frame,
+ (tag = frame_get_w(&g_kc3_env->read_time_frame,
dest->data.ident.sym)))
tag_init_copy(dest, tag);
else
diff --git a/libkc3/call.c b/libkc3/call.c
index f8f994f..33bc3e4 100644
--- a/libkc3/call.c
+++ b/libkc3/call.c
@@ -36,7 +36,7 @@ void call_clean (s_call *call)
bool call_get (s_call *call)
{
- return env_call_get(&g_kc3_env, call);
+ return env_call_get(g_kc3_env, call);
}
s_call * call_init (s_call *call)
diff --git a/libkc3/cfn.c b/libkc3/cfn.c
index 4a68a91..225eadb 100644
--- a/libkc3/cfn.c
+++ b/libkc3/cfn.c
@@ -127,12 +127,12 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
}
}
if (cfn->ptr.f) {
- if (! (trace = list_new(g_kc3_env.stacktrace)))
+ if (! (trace = list_new(g_kc3_env->stacktrace)))
goto ko;
tag_init_list(&trace->tag, list_new_sym
(cfn->name, list_new_copy
(args)));
- g_kc3_env.stacktrace = trace;
+ g_kc3_env->stacktrace = trace;
ffi_call(&cfn->cif, cfn->ptr.f, result, arg_values);
if (cfn->arg_result) {
if (result_pointer != arg_pointer_result) {
@@ -153,7 +153,7 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
}
else
*dest = tmp;
- g_kc3_env.stacktrace = list_delete(trace);
+ g_kc3_env->stacktrace = list_delete(trace);
}
else {
err_puts("cfn_apply: NULL function pointer");
diff --git a/libkc3/env.c b/libkc3/env.c
index f77ef9c..f720d05 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -63,7 +63,7 @@
#include "tuple.h"
#include "var.h"
-thread_local s_env g_kc3_env;
+thread_local s_env *g_kc3_env = NULL;
static void env_clean_globals (s_env *env);
static void env_clean_toplevel (s_env *env);
@@ -790,7 +790,7 @@ bool env_eval_call_fn_args (s_env *env, const s_fn *fn,
err_inspect_fn_pattern(args);
err_write_1("\n");
err_puts("stacktrace:");
- err_inspect_stacktrace(g_kc3_env.stacktrace);
+ err_inspect_stacktrace(env->stacktrace);
err_write_1("\n");
list_delete_all(args);
list_delete_all(env->search_modules);
@@ -2668,7 +2668,10 @@ s_ident * env_ident_resolve_module (s_env *env,
s_env * env_init (s_env *env, int *argc, char ***argv)
{
s_str path;
- assert(env);
+ if (! env)
+ env = g_kc3_env = alloc(sizeof(s_env));
+ if (! env)
+ return NULL;
env->trace = false;
if (! env_init_args(env, argc, argv))
return NULL;
diff --git a/libkc3/env.h b/libkc3/env.h
index 197fc07..c44441b 100644
--- a/libkc3/env.h
+++ b/libkc3/env.h
@@ -15,7 +15,7 @@
#include "types.h"
-extern thread_local s_env g_kc3_env;
+extern thread_local s_env *g_kc3_env;
/* Stack allocation compatible functions, call env_clean after use. */
void env_clean (s_env *env);
diff --git a/libkc3/eval.c b/libkc3/eval.c
index fff636f..40426ef 100644
--- a/libkc3/eval.c
+++ b/libkc3/eval.c
@@ -14,10 +14,14 @@
#include "assert.h"
#include "env.h"
+bool eval_array (s_array *array, s_array *dest)
+{
+ return env_eval_array(g_kc3_env, array, dest);
+}
bool eval_call (s_call *call, s_tag *dest)
{
- return env_eval_call(&g_kc3_env, call, dest);
+ return env_eval_call(g_kc3_env, call, dest);
}
bool eval_callable_call (s_callable *callable, s_list *arguments,
@@ -32,10 +36,10 @@ bool eval_callable_call (s_callable *callable, s_list *arguments,
}
switch (callable->type) {
case CALLABLE_CFN:
- return env_eval_call_cfn_args(&g_kc3_env, &callable->data.cfn,
+ return env_eval_call_cfn_args(g_kc3_env, &callable->data.cfn,
arguments, dest);
case CALLABLE_FN:
- return env_eval_call_fn_args(&g_kc3_env, &callable->data.fn,
+ return env_eval_call_fn_args(g_kc3_env, &callable->data.fn,
arguments, dest);
case CALLABLE_VOID:
err_puts("eval_callable_call: CALLABLE_VOID");
@@ -51,10 +55,10 @@ bool eval_callable_call (s_callable *callable, s_list *arguments,
bool eval_fn_call (const s_fn *fn, s_list *args, s_tag *dest)
{
- return env_eval_call_fn_args(&g_kc3_env, fn, args, dest);
+ return env_eval_call_fn_args(g_kc3_env, fn, args, dest);
}
bool eval_tag (s_tag *tag, s_tag *dest)
{
- return env_eval_tag(&g_kc3_env, tag, dest);
+ return env_eval_tag(g_kc3_env, tag, dest);
}
diff --git a/libkc3/eval.h b/libkc3/eval.h
index 54b2d99..7cd56e8 100644
--- a/libkc3/eval.h
+++ b/libkc3/eval.h
@@ -15,6 +15,7 @@
#include "types.h"
+bool eval_array (s_array *array, s_array *dest);
bool eval_call (s_call *call, s_tag *dest);
bool eval_call_function (s_call *call,
s_tag *dest);
diff --git a/libkc3/fact.c b/libkc3/fact.c
index 9c7885a..9386d3b 100644
--- a/libkc3/fact.c
+++ b/libkc3/fact.c
@@ -92,7 +92,7 @@ void fact_w_clean (s_fact_w *fact)
s_fact_w * fact_w_eval (s_fact_w *fact, s_fact_w *dest)
{
- return env_fact_w_eval(&g_kc3_env, fact, dest);
+ return env_fact_w_eval(g_kc3_env, fact, dest);
}
s_fact_w * fact_w_init (s_fact_w *fact)
diff --git a/libkc3/file.c b/libkc3/file.c
index 0f3a548..ee7392b 100644
--- a/libkc3/file.c
+++ b/libkc3/file.c
@@ -433,10 +433,10 @@ s_str * file_search (const s_str *suffix, const s_sym *mode,
const s_str *str;
s_str tmp = {0};
buf_init(&buf, false, sizeof(buf_s), buf_s);
- if ((r = buf_write_str(&buf, &g_kc3_env.argv0_dir)) < 0)
+ if ((r = buf_write_str(&buf, &g_kc3_env->argv0_dir)) < 0)
return NULL;
buf_save_init(&buf, &save);
- path = g_kc3_env.path;
+ path = g_kc3_env->path;
while (path) {
if (path->tag.type == TAG_STR) {
buf_save_restore_rpos(&buf, &save);
diff --git a/libkc3/ident.c b/libkc3/ident.c
index 7323d37..b0f095b 100644
--- a/libkc3/ident.c
+++ b/libkc3/ident.c
@@ -57,7 +57,7 @@ bool ident_first_character_is_reserved (character c)
s_tag * ident_get (const s_ident *ident, s_tag *dest)
{
- return env_ident_get(&g_kc3_env, ident, dest);
+ return env_ident_get(g_kc3_env, ident, dest);
}
s_ident * ident_init (s_ident *ident, const s_sym *module,
@@ -110,12 +110,12 @@ s_ident * ident_init_copy (s_ident *ident, const s_ident *src)
bool * ident_is_special_operator (const s_ident *ident, bool *dest)
{
- return env_ident_is_special_operator(&g_kc3_env, ident, dest);
+ return env_ident_is_special_operator(g_kc3_env, ident, dest);
}
s_ident * ident_resolve_module (const s_ident *ident, s_ident *dest)
{
- return env_ident_resolve_module(&g_kc3_env, ident, dest);
+ return env_ident_resolve_module(g_kc3_env, ident, dest);
}
bool ident_to_tag_type (const s_ident *ident, e_tag_type *dest)
diff --git a/libkc3/io.c b/libkc3/io.c
index 5e0c698..7116165 100644
--- a/libkc3/io.c
+++ b/libkc3/io.c
@@ -30,10 +30,10 @@
sw err_inspect_ ## name (type x) \
{ \
sw r; \
- r = buf_inspect_ ## name(&g_kc3_env.err, x); \
+ r = buf_inspect_ ## name(&g_kc3_env->err, x); \
if (r < 0) \
return r; \
- buf_flush(&g_kc3_env.err); \
+ buf_flush(&g_kc3_env->err); \
return r; \
}
@@ -41,10 +41,10 @@
sw io_inspect_ ## name (type x) \
{ \
sw r; \
- r = buf_inspect_ ## name(&g_kc3_env.out, x); \
+ r = buf_inspect_ ## name(&g_kc3_env->out, x); \
if (r < 0) \
return r; \
- buf_flush(&g_kc3_env.out); \
+ buf_flush(&g_kc3_env->out); \
return r; \
}
@@ -56,7 +56,7 @@
sw err_flush (void)
{
- return buf_flush(&g_kc3_env.err);
+ return buf_flush(&g_kc3_env->err);
}
sw err_inspect (const s_tag *x)
@@ -75,10 +75,10 @@ sw err_inspect_buf (const s_buf *buf)
sw err_inspect_list (const s_list *x)
{
sw r;
- r = buf_inspect_list(&g_kc3_env.err, &x);
+ r = buf_inspect_list(&g_kc3_env->err, &x);
if (r < 0)
return r;
- buf_flush(&g_kc3_env.err);
+ buf_flush(&g_kc3_env->err);
return r;
}
@@ -91,64 +91,64 @@ sw err_puts (const char *x)
{
sw r;
sw result = 0;
- if ((r = buf_write_1(&g_kc3_env.err, x)) < 0)
+ if ((r = buf_write_1(&g_kc3_env->err, x)) < 0)
return r;
result += r;
- if ((r = buf_write_u8(&g_kc3_env.err, '\n')) < 0)
+ if ((r = buf_write_u8(&g_kc3_env->err, '\n')) < 0)
return r;
result += r;
- buf_flush(&g_kc3_env.err);
+ buf_flush(&g_kc3_env->err);
return result;
}
sw err_write (const void *x, uw len)
{
sw r;
- if ((r = buf_write(&g_kc3_env.err, x, len)) > 0)
- buf_flush(&g_kc3_env.err);
+ if ((r = buf_write(&g_kc3_env->err, x, len)) > 0)
+ buf_flush(&g_kc3_env->err);
return r;
}
sw err_write_1 (const char *x)
{
sw r;
- if ((r = buf_write_1(&g_kc3_env.err, x)) > 0)
- buf_flush(&g_kc3_env.err);
+ if ((r = buf_write_1(&g_kc3_env->err, x)) > 0)
+ buf_flush(&g_kc3_env->err);
return r;
}
sw err_write_str (const s_str *x)
{
sw r;
- if ((r = buf_write_str(&g_kc3_env.err, x)) > 0)
- buf_flush(&g_kc3_env.err);
+ if ((r = buf_write_str(&g_kc3_env->err, x)) > 0)
+ buf_flush(&g_kc3_env->err);
return r;
}
sw err_write_u8 (u8 x)
{
sw r;
- if ((r = buf_write_u8(&g_kc3_env.err, x)) > 0)
- buf_flush(&g_kc3_env.err);
+ if ((r = buf_write_u8(&g_kc3_env->err, x)) > 0)
+ buf_flush(&g_kc3_env->err);
return r;
}
sw io_flush (void)
{
- return buf_flush(&g_kc3_env.out);
+ return buf_flush(&g_kc3_env->out);
}
sw io_inspect (const s_tag *x)
{
sw r;
sw result = 0;
- if ((r = buf_inspect_tag(&g_kc3_env.out, x)) < 0)
+ if ((r = buf_inspect_tag(&g_kc3_env->out, x)) < 0)
return r;
result += r;
- if ((r = buf_write_u8(&g_kc3_env.out, '\n')) < 0)
+ if ((r = buf_write_u8(&g_kc3_env->out, '\n')) < 0)
return r;
result += r;
- buf_flush(&g_kc3_env.out);
+ buf_flush(&g_kc3_env->out);
return result;
}
@@ -169,45 +169,45 @@ sw io_puts (const char *x)
{
sw r;
sw result = 0;
- if ((r = buf_write_1(&g_kc3_env.out, x)) < 0)
+ if ((r = buf_write_1(&g_kc3_env->out, x)) < 0)
return r;
result += r;
- if ((r = buf_write_u8(&g_kc3_env.out, '\n')) < 0)
+ if ((r = buf_write_u8(&g_kc3_env->out, '\n')) < 0)
return r;
result += r;
- buf_flush(&g_kc3_env.out);
+ buf_flush(&g_kc3_env->out);
return result;
}
sw io_write (const void *x, uw len)
{
sw r;
- if ((r = buf_write(&g_kc3_env.out, x, len)) > 0)
- buf_flush(&g_kc3_env.out);
+ if ((r = buf_write(&g_kc3_env->out, x, len)) > 0)
+ buf_flush(&g_kc3_env->out);
return r;
}
sw io_write_1 (const char *x)
{
sw r;
- if ((r = buf_write_1(&g_kc3_env.out, x)) > 0)
- buf_flush(&g_kc3_env.out);
+ if ((r = buf_write_1(&g_kc3_env->out, x)) > 0)
+ buf_flush(&g_kc3_env->out);
return r;
}
sw io_write_str (const s_str *x)
{
sw r;
- if ((r = buf_write_str(&g_kc3_env.out, x)) > 0)
- buf_flush(&g_kc3_env.out);
+ if ((r = buf_write_str(&g_kc3_env->out, x)) > 0)
+ buf_flush(&g_kc3_env->out);
return r;
}
sw io_write_u8 (u8 x)
{
sw r;
- if ((r = buf_write_u8(&g_kc3_env.out, x)) > 0)
- buf_flush(&g_kc3_env.out);
+ if ((r = buf_write_u8(&g_kc3_env->out, x)) > 0)
+ buf_flush(&g_kc3_env->out);
return r;
}
diff --git a/libkc3/kc3.c b/libkc3/kc3.c
index a4210e7..0df9c66 100644
--- a/libkc3/kc3.c
+++ b/libkc3/kc3.c
@@ -117,12 +117,12 @@ s_tag * kc3_access (s_tag *tag, s_list **key,
bool * kc3_and (s_tag *a, s_tag *b, bool *dest)
{
- return env_and(&g_kc3_env, a, b, dest);
+ return env_and(g_kc3_env, a, b, dest);
}
s_list ** kc3_args (s_list **dest)
{
- return env_args(&g_kc3_env, dest);
+ return env_args(g_kc3_env, dest);
}
void kc3_break (void)
@@ -144,19 +144,19 @@ s_tag * kc3_buf_parse_tag (s_buf *buf, s_tag *dest)
void kc3_clean (s_env *env)
{
if (! env)
- env = &g_kc3_env;
+ env = g_kc3_env;
env_clean(env);
sym_delete_all();
}
s_tag * kc3_def (const s_call *call, s_tag *dest)
{
- return env_kc3_def(&g_kc3_env, call, dest);
+ return env_kc3_def(g_kc3_env, call, dest);
}
s_tag * kc3_defmodule (const s_sym **name, const s_block *block, s_tag *dest)
{
- return env_defmodule(&g_kc3_env, name, block, dest);
+ return env_defmodule(g_kc3_env, name, block, dest);
}
s_tag * kc3_defoperator (const s_sym **name, const s_sym **sym,
@@ -165,7 +165,7 @@ s_tag * kc3_defoperator (const s_sym **name, const s_sym **sym,
const s_sym **operator_associativity,
s_tag *dest)
{
- return env_defoperator(&g_kc3_env, name, sym, symbol_value,
+ return env_defoperator(g_kc3_env, name, sym, symbol_value,
operator_precedence,
operator_associativity, dest);
}
@@ -177,7 +177,7 @@ s_tag * kc3_defstruct (s_list **spec, s_tag *dest)
if (! spec)
return NULL;
tmp.type = TAG_SYM;
- tmp.data.sym = env_defstruct(&g_kc3_env, *spec);
+ tmp.data.sym = env_defstruct(g_kc3_env, *spec);
*dest = tmp;
return dest;
}
@@ -204,7 +204,7 @@ void ** kc3_dlopen (const s_str *path, void **dest)
s_facts ** kc3_env_db (s_facts **dest)
{
- *dest = &g_kc3_env.facts;
+ *dest = &g_kc3_env->facts;
return dest;
}
@@ -280,7 +280,7 @@ bool * kc3_facts_add_tags (s_facts *facts, s_tag *subject,
s_tag * kc3_facts_collect_with (s_facts *facts, s_list **spec,
p_callable *callback, s_tag *dest)
{
- return env_facts_collect_with(&g_kc3_env, facts, spec, *callback,
+ return env_facts_collect_with(g_kc3_env, facts, spec, *callback,
dest);
}
@@ -291,7 +291,7 @@ s_tag * kc3_facts_collect_with_tags (s_facts *facts,
p_callable *callback,
s_tag *dest)
{
- return env_facts_collect_with_tags(&g_kc3_env, facts, subject,
+ return env_facts_collect_with_tags(g_kc3_env, facts, subject,
predicate, object, *callback,
dest);
}
@@ -299,21 +299,21 @@ s_tag * kc3_facts_collect_with_tags (s_facts *facts,
s_tag * kc3_facts_first_with (s_facts *facts, s_list **spec,
p_callable *callback, s_tag *dest)
{
- return env_facts_first_with(&g_kc3_env, facts, spec, *callback, dest);
+ return env_facts_first_with(g_kc3_env, facts, spec, *callback, dest);
}
s_tag * kc3_facts_first_with_tags (s_facts *facts, s_tag *subject,
s_tag *predicate, s_tag *object,
p_callable *callback, s_tag *dest)
{
- return env_facts_first_with_tags(&g_kc3_env, facts, subject,
+ return env_facts_first_with_tags(g_kc3_env, facts, subject,
predicate, object, *callback, dest);
}
uw * kc3_facts_next_id (uw *dest)
{
assert(dest);
- *dest = g_kc3_env.facts.next_id;
+ *dest = g_kc3_env->facts.next_id;
return dest;
}
@@ -345,20 +345,20 @@ bool * kc3_facts_replace_tags (s_facts *facts,
s_tag * kc3_facts_with (s_facts *facts, s_list **spec,
p_callable *callback, s_tag *dest)
{
- return env_facts_with(&g_kc3_env, facts, spec, *callback, dest);
+ return env_facts_with(g_kc3_env, facts, spec, *callback, dest);
}
s_tag * kc3_facts_with_macro (s_tag *facts_tag, s_tag *spec_tag,
s_tag *block_tag, s_tag *dest)
{
- return env_facts_with_macro(&g_kc3_env, facts_tag, spec_tag, block_tag, dest);
+ return env_facts_with_macro(g_kc3_env, facts_tag, spec_tag, block_tag, dest);
}
s_tag * kc3_facts_with_tags (s_facts *facts, s_tag *subject,
s_tag *predicate, s_tag *object,
p_callable *callback, s_tag *dest)
{
- return env_facts_with_tags(&g_kc3_env, facts, subject, predicate,
+ return env_facts_with_tags(g_kc3_env, facts, subject, predicate,
object, *callback, dest);
}
@@ -374,7 +374,7 @@ s_tag * kc3_facts_with_tuple (s_facts *facts, s_tuple *tuple,
assert(! "kc3_facts_with_tuple: tuple count < 3");
return NULL;
}
- return env_facts_with_tags(&g_kc3_env, facts, tuple->tag,
+ return env_facts_with_tags(g_kc3_env, facts, tuple->tag,
tuple->tag + 1, tuple->tag + 2,
*callback, dest);
}
@@ -418,7 +418,7 @@ s_tag * kc3_if_then_else (s_tag *cond, s_tag *then,
bool cond_bool = false;
s_tag cond_eval = {0};
const s_sym *type;
- if (env_eval_tag(&g_kc3_env, cond, &cond_eval)) {
+ if (env_eval_tag(g_kc3_env, cond, &cond_eval)) {
if (cond_eval.type == TAG_BOOL)
cond_bool = cond_eval.data.bool;
else {
@@ -431,11 +431,11 @@ s_tag * kc3_if_then_else (s_tag *cond, s_tag *then,
tag_clean(&cond_eval);
}
if (cond_bool) {
- if (! env_eval_tag(&g_kc3_env, then, dest))
+ if (! env_eval_tag(g_kc3_env, then, dest))
return NULL;
return dest;
}
- if (! env_eval_tag(&g_kc3_env, else_, dest))
+ if (! env_eval_tag(g_kc3_env, else_, dest))
return NULL;
return dest;
}
@@ -443,7 +443,7 @@ s_tag * kc3_if_then_else (s_tag *cond, s_tag *then,
s_env * kc3_init (s_env *env, int *argc, char ***argv)
{
if (! env)
- env = &g_kc3_env;
+ env = g_kc3_env;
return env_init(env, argc, argv);
}
@@ -459,13 +459,13 @@ s_tag * kc3_integer_reduce (s_tag *tag, s_tag *dest)
s_tag * kc3_let (s_tag *vars, s_tag *tag, s_tag *dest)
{
- return env_let(&g_kc3_env, vars, tag, dest);
+ return env_let(g_kc3_env, vars, tag, dest);
}
void kc3_license (void)
{
- buf_write_1(&g_kc3_env.out, g_kc3_license);
- buf_flush(&g_kc3_env.out);
+ buf_write_1(&g_kc3_env->out, g_kc3_license);
+ buf_flush(&g_kc3_env->out);
}
s_array * kc3_list_to_array (s_list **list,
@@ -477,17 +477,17 @@ s_array * kc3_list_to_array (s_list **list,
bool kc3_load (const s_str *path)
{
- return env_load(&g_kc3_env, path);
+ return env_load(g_kc3_env, path);
}
bool kc3_maybe_reload (const s_str *path)
{
- return env_maybe_reload(&g_kc3_env, path);
+ return env_maybe_reload(g_kc3_env, path);
}
const s_sym ** kc3_module (const s_sym **dest)
{
- return env_module(&g_kc3_env, dest);
+ return env_module(g_kc3_env, dest);
}
bool * kc3_must_clean (const s_sym * const *sym, bool *dest)
@@ -511,12 +511,12 @@ uw * kc3_offsetof (const s_sym * const *module,
s_tag * kc3_operator_find_by_sym (const s_sym * const *sym, s_tag *dest)
{
- return env_operator_find_by_sym(&g_kc3_env, *sym, dest);
+ return env_operator_find_by_sym(g_kc3_env, *sym, dest);
}
bool * kc3_or (s_tag *a, s_tag *b, bool *dest)
{
- return env_or(&g_kc3_env, a, b, dest);
+ return env_or(g_kc3_env, a, b, dest);
}
sw kc3_puts (const s_tag *tag)
@@ -542,17 +542,17 @@ sw kc3_puts (const s_tag *tag)
bool kc3_require (const s_sym * const *module)
{
- return env_module_ensure_loaded(&g_kc3_env, *module);
+ return env_module_ensure_loaded(g_kc3_env, *module);
}
s_list ** kc3_search_modules (s_list **dest)
{
- return env_search_modules(&g_kc3_env, dest);
+ return env_search_modules(g_kc3_env, dest);
}
s_list ** kc3_stacktrace (s_list **dest)
{
- return env_stacktrace(&g_kc3_env, dest);
+ return env_stacktrace(g_kc3_env, dest);
}
s_str * kc3_str (const s_tag *tag, s_str *dest)
@@ -721,15 +721,30 @@ s_tag * kc3_thread_delete (u_ptr_w *thread, s_tag *dest)
assert(! "kc3_thread_delete: pthread_join");
return NULL;
}
- *dest = *tmp;
- free(tmp);
+ if (tmp->type != TAG_TUPLE ||
+ tmp->data.tuple.count != 2) {
+ err_puts("kc3_thread_delete: invalid value");
+ assert(! "kc3_thread_delete: invalid value");
+ tag_delete(tmp);
+ return NULL;
+ }
+ if (! tag_init_copy(dest, tmp->data.tuple.tag)) {
+ tag_delete(tmp);
+ return NULL;
+ }
+ tag_delete(tmp);
return dest;
}
u_ptr_w * kc3_thread_new (u_ptr_w *dest, p_callable *start)
{
+ s_tag *tag;
+ if (! (tag = tag_new_tuple(2)))
+ return NULL;
+ if (! tag_init_callable_copy(tag->data.tuple.tag + 1, start))
+ return NULL;
if (pthread_create((pthread_t *) &dest->p, NULL, kc3_thread_start,
- *start)) {
+ tag)) {
err_puts("kc3_thread_new: pthread_create");
assert(! "kc3_thread_new: pthread_create");
return NULL;
@@ -739,17 +754,23 @@ u_ptr_w * kc3_thread_new (u_ptr_w *dest, p_callable *start)
void * kc3_thread_start (void *arg)
{
- s_callable *start;
s_tag *tag;
- start = arg;
- if (! (tag = tag_new()))
+ s_callable *start;
+ tag = arg;
+ if (tag->type != TAG_TUPLE ||
+ tag->data.tuple.count != 2 ||
+ tag->data.tuple.tag[1].type != TAG_CALLABLE) {
+ err_puts("kc3_thread_start: invalid argument");
+ assert(! "kc3_thread_start: invalid argument");
return NULL;
- if (! eval_callable_call(start, NULL, tag))
+ }
+ start = tag->data.tuple.tag[1].data.callable;
+ if (! eval_callable_call(start, NULL, tag->data.tuple.tag))
return NULL;
return tag;
}
s_tag * kc3_while (s_tag *cond, s_tag *body, s_tag *dest)
{
- return env_while(&g_kc3_env, cond, body, dest);
+ return env_while(g_kc3_env, cond, body, dest);
}
diff --git a/libkc3/module.c b/libkc3/module.c
index 6e48f88..30ea017 100644
--- a/libkc3/module.c
+++ b/libkc3/module.c
@@ -26,40 +26,40 @@
bool module_ensure_loaded (const s_sym *module)
{
- return env_module_ensure_loaded(&g_kc3_env, module);
+ return env_module_ensure_loaded(g_kc3_env, module);
}
bool * module_has_ident (const s_sym *module, const s_ident *ident,
bool *dest)
{
- return env_module_has_ident(&g_kc3_env, module, ident, dest);
+ return env_module_has_ident(g_kc3_env, module, ident, dest);
}
bool * module_has_symbol (const s_sym *module, const s_sym *sym,
bool *dest)
{
- return env_module_has_symbol(&g_kc3_env, module, sym, dest);
+ return env_module_has_symbol(g_kc3_env, module, sym, dest);
}
bool * module_is_loading (const s_sym *module, bool *dest)
{
- return env_module_is_loading(&g_kc3_env, module, dest);
+ return env_module_is_loading(g_kc3_env, module, dest);
}
bool module_load (const s_sym *module)
{
- return env_module_load(&g_kc3_env, module);
+ return env_module_load(g_kc3_env, module);
}
const s_time ** module_load_time (const s_sym *module,
const s_time **dest)
{
- return env_module_load_time(&g_kc3_env, module, dest);
+ return env_module_load_time(g_kc3_env, module, dest);
}
bool module_maybe_reload (const s_sym *module)
{
- return env_module_maybe_reload(&g_kc3_env, module);
+ return env_module_maybe_reload(g_kc3_env, module);
}
s_str * module_path (const s_sym *module, const s_str *prefix,
diff --git a/libkc3/operator.c b/libkc3/operator.c
index a0c5c52..2064e98 100644
--- a/libkc3/operator.c
+++ b/libkc3/operator.c
@@ -15,36 +15,36 @@
s8 operator_arity (const s_ident *op)
{
- return env_operator_arity(&g_kc3_env, op);
+ return env_operator_arity(g_kc3_env, op);
}
bool * operator_find (const s_ident *op, bool *dest)
{
- return env_operator_find(&g_kc3_env, op, dest);
+ return env_operator_find(g_kc3_env, op, dest);
}
s_ident * operator_ident (const s_ident *op, s_ident *dest)
{
- return env_operator_ident(&g_kc3_env, op, dest);
+ return env_operator_ident(g_kc3_env, op, dest);
}
bool * operator_is_right_associative (const s_ident *op, bool *dest)
{
- return env_operator_is_right_associative(&g_kc3_env, op, dest);
+ return env_operator_is_right_associative(g_kc3_env, op, dest);
}
sw * operator_precedence (const s_ident *op, sw *dest)
{
- return env_operator_precedence(&g_kc3_env, op, dest);
+ return env_operator_precedence(g_kc3_env, op, dest);
}
s_ident * operator_resolve (const s_ident *op, u8 arity,
s_ident *dest)
{
- return env_operator_resolve(&g_kc3_env, op, arity, dest);
+ return env_operator_resolve(g_kc3_env, op, arity, dest);
}
const s_sym ** operator_symbol (const s_ident *op, const s_sym **dest)
{
- return env_operator_symbol(&g_kc3_env, op, dest);
+ return env_operator_symbol(g_kc3_env, op, dest);
}
diff --git a/libkc3/s.c.in b/libkc3/s.c.in
index 70d4a33..368ed1e 100644
--- a/libkc3/s.c.in
+++ b/libkc3/s.c.in
@@ -101,7 +101,7 @@ s_bits$ * s_bits$_init_cast
}
if (true) {
err_puts("s_bits$_cast: stacktrace:");
- err_inspect_list(g_kc3_env.stacktrace);
+ err_inspect_list(g_kc3_env->stacktrace);
err_write_1("\n");
}
assert(! "s_bits$_cast: cannot cast to S_bits$");
diff --git a/libkc3/s16.c b/libkc3/s16.c
index 37f1caf..facdd2d 100644
--- a/libkc3/s16.c
+++ b/libkc3/s16.c
@@ -101,7 +101,7 @@ s16 * s16_init_cast
}
if (true) {
err_puts("s16_cast: stacktrace:");
- err_inspect_list(g_kc3_env.stacktrace);
+ err_inspect_list(g_kc3_env->stacktrace);
err_write_1("\n");
}
assert(! "s16_cast: cannot cast to S16");
diff --git a/libkc3/s32.c b/libkc3/s32.c
index 9f6426a..9882afc 100644
--- a/libkc3/s32.c
+++ b/libkc3/s32.c
@@ -101,7 +101,7 @@ s32 * s32_init_cast
}
if (true) {
err_puts("s32_cast: stacktrace:");
- err_inspect_list(g_kc3_env.stacktrace);
+ err_inspect_list(g_kc3_env->stacktrace);
err_write_1("\n");
}
assert(! "s32_cast: cannot cast to S32");
diff --git a/libkc3/s64.c b/libkc3/s64.c
index dde01ae..7b4bfb1 100644
--- a/libkc3/s64.c
+++ b/libkc3/s64.c
@@ -101,7 +101,7 @@ s64 * s64_init_cast
}
if (true) {
err_puts("s64_cast: stacktrace:");
- err_inspect_list(g_kc3_env.stacktrace);
+ err_inspect_list(g_kc3_env->stacktrace);
err_write_1("\n");
}
assert(! "s64_cast: cannot cast to S64");
diff --git a/libkc3/s8.c b/libkc3/s8.c
index 3b7c008..e6d90c1 100644
--- a/libkc3/s8.c
+++ b/libkc3/s8.c
@@ -101,7 +101,7 @@ s8 * s8_init_cast
}
if (true) {
err_puts("s8_cast: stacktrace:");
- err_inspect_list(g_kc3_env.stacktrace);
+ err_inspect_list(g_kc3_env->stacktrace);
err_write_1("\n");
}
assert(! "s8_cast: cannot cast to S8");
diff --git a/libkc3/special_operator.c b/libkc3/special_operator.c
index de505cc..0d11541 100644
--- a/libkc3/special_operator.c
+++ b/libkc3/special_operator.c
@@ -15,5 +15,5 @@
u8 special_operator_arity (const s_ident *ident)
{
- return env_special_operator_arity(&g_kc3_env, ident);
+ return env_special_operator_arity(g_kc3_env, ident);
}
diff --git a/libkc3/struct.c b/libkc3/struct.c
index a573830..a908f22 100644
--- a/libkc3/struct.c
+++ b/libkc3/struct.c
@@ -256,7 +256,7 @@ s_struct * struct_init_1 (s_struct *s, const char *p)
err_inspect_struct(&tmp);
err_write_1("\n");
}
- if (! env_eval_struct(&g_kc3_env, &tmp, &tmp2)) {
+ if (! env_eval_struct(g_kc3_env, &tmp, &tmp2)) {
err_puts("struct_init_1: env_eval_struct");
assert(! "struct_init_1: env_eval_struct");
struct_clean(&tmp);
diff --git a/libkc3/struct_type.c b/libkc3/struct_type.c
index 8879402..924a29f 100644
--- a/libkc3/struct_type.c
+++ b/libkc3/struct_type.c
@@ -64,13 +64,13 @@ void struct_type_delete (s_struct_type *st)
bool * struct_type_exists (const s_sym *module, bool *dest)
{
- return env_struct_type_exists(&g_kc3_env, module, dest);
+ return env_struct_type_exists(g_kc3_env, module, dest);
}
s_struct_type ** struct_type_find (const s_sym *module,
s_struct_type **dest)
{
- return env_struct_type_find(&g_kc3_env, module, dest);
+ return env_struct_type_find(g_kc3_env, module, dest);
}
uw * struct_type_find_key_index (const s_struct_type *st,
diff --git a/libkc3/sw.c b/libkc3/sw.c
index ed966fa..ae9dfb3 100644
--- a/libkc3/sw.c
+++ b/libkc3/sw.c
@@ -101,7 +101,7 @@ sw * sw_init_cast
}
if (true) {
err_puts("sw_cast: stacktrace:");
- err_inspect_list(g_kc3_env.stacktrace);
+ err_inspect_list(g_kc3_env->stacktrace);
err_write_1("\n");
}
assert(! "sw_cast: cannot cast to Sw");
diff --git a/libkc3/sym.c b/libkc3/sym.c
index 0bd57d5..9ee548b 100644
--- a/libkc3/sym.c
+++ b/libkc3/sym.c
@@ -724,7 +724,7 @@ const s_sym * sym_new (const s_str *src)
bool sym_search_modules (const s_sym *sym, const s_sym **dest)
{
- return env_sym_search_modules(&g_kc3_env, sym, dest);
+ return env_sym_search_modules(g_kc3_env, sym, dest);
}
bool sym_to_ffi_type (const s_sym *sym, ffi_type *result_type,
diff --git a/libkc3/tag.c b/libkc3/tag.c
index 9981ed2..9b35f58 100644
--- a/libkc3/tag.c
+++ b/libkc3/tag.c
@@ -278,7 +278,7 @@ s_tag * tag_equal (s_tag *a, s_tag *b, s_tag *dest)
assert(a);
assert(b);
assert(dest);
- if (! env_eval_equal_tag (&g_kc3_env, false, a, b, dest))
+ if (! env_eval_equal_tag (g_kc3_env, false, a, b, dest))
return NULL;
return dest;
}
@@ -330,7 +330,7 @@ uw * tag_hash_uw (const s_tag *tag, uw *dest)
bool tag_ident_is_bound (const s_tag *tag)
{
- return env_tag_ident_is_bound(&g_kc3_env, tag);
+ return env_tag_ident_is_bound(g_kc3_env, tag);
}
s_tag * tag_init (s_tag *tag)
diff --git a/libkc3/u.c.in b/libkc3/u.c.in
index cd96b02..4547c92 100644
--- a/libkc3/u.c.in
+++ b/libkc3/u.c.in
@@ -118,7 +118,7 @@ u_bits$ * u_bits$_init_str (u_bits$ *u, const s_str *str)
if (buf_parse_u_bits$(&buf, &tmp) <= 0) {
if (false) {
err_puts("u_bits$_init_str: buf_parse_u_bits$");
- err_inspect_stacktrace(g_kc3_env.stacktrace);
+ err_inspect_stacktrace(g_kc3_env->stacktrace);
err_write_1("\n");
assert(! "u_bits$_init_str: buf_parse_u_bits$");
}
diff --git a/libkc3/u16.c b/libkc3/u16.c
index a92f2fd..193257f 100644
--- a/libkc3/u16.c
+++ b/libkc3/u16.c
@@ -118,7 +118,7 @@ u16 * u16_init_str (u16 *u, const s_str *str)
if (buf_parse_u16(&buf, &tmp) <= 0) {
if (false) {
err_puts("u16_init_str: buf_parse_u16");
- err_inspect_stacktrace(g_kc3_env.stacktrace);
+ err_inspect_stacktrace(g_kc3_env->stacktrace);
err_write_1("\n");
assert(! "u16_init_str: buf_parse_u16");
}
diff --git a/libkc3/u32.c b/libkc3/u32.c
index a2ba402..82a9af2 100644
--- a/libkc3/u32.c
+++ b/libkc3/u32.c
@@ -118,7 +118,7 @@ u32 * u32_init_str (u32 *u, const s_str *str)
if (buf_parse_u32(&buf, &tmp) <= 0) {
if (false) {
err_puts("u32_init_str: buf_parse_u32");
- err_inspect_stacktrace(g_kc3_env.stacktrace);
+ err_inspect_stacktrace(g_kc3_env->stacktrace);
err_write_1("\n");
assert(! "u32_init_str: buf_parse_u32");
}
diff --git a/libkc3/u64.c b/libkc3/u64.c
index 0e8bed3..33d84c4 100644
--- a/libkc3/u64.c
+++ b/libkc3/u64.c
@@ -118,7 +118,7 @@ u64 * u64_init_str (u64 *u, const s_str *str)
if (buf_parse_u64(&buf, &tmp) <= 0) {
if (false) {
err_puts("u64_init_str: buf_parse_u64");
- err_inspect_stacktrace(g_kc3_env.stacktrace);
+ err_inspect_stacktrace(g_kc3_env->stacktrace);
err_write_1("\n");
assert(! "u64_init_str: buf_parse_u64");
}
diff --git a/libkc3/u8.c b/libkc3/u8.c
index cf94c64..b7b166c 100644
--- a/libkc3/u8.c
+++ b/libkc3/u8.c
@@ -118,7 +118,7 @@ u8 * u8_init_str (u8 *u, const s_str *str)
if (buf_parse_u8(&buf, &tmp) <= 0) {
if (false) {
err_puts("u8_init_str: buf_parse_u8");
- err_inspect_stacktrace(g_kc3_env.stacktrace);
+ err_inspect_stacktrace(g_kc3_env->stacktrace);
err_write_1("\n");
assert(! "u8_init_str: buf_parse_u8");
}
diff --git a/libkc3/uw.c b/libkc3/uw.c
index c956226..dc5a4c4 100644
--- a/libkc3/uw.c
+++ b/libkc3/uw.c
@@ -118,7 +118,7 @@ uw * uw_init_str (uw *u, const s_str *str)
if (buf_parse_uw(&buf, &tmp) <= 0) {
if (false) {
err_puts("uw_init_str: buf_parse_uw");
- err_inspect_stacktrace(g_kc3_env.stacktrace);
+ err_inspect_stacktrace(g_kc3_env->stacktrace);
err_write_1("\n");
assert(! "uw_init_str: buf_parse_uw");
}
diff --git a/test/libkc3_test.c b/test/libkc3_test.c
index 302ca9c..ef75fd0 100644
--- a/test/libkc3_test.c
+++ b/test/libkc3_test.c
@@ -53,7 +53,7 @@ int main (int argc, char **argv)
{
if (! kc3_init(NULL, &argc, &argv))
return 1;
- test_init(g_kc3_env.argv[0], &argc, &argv);
+ test_init(g_kc3_env->argv[0], &argc, &argv);
TEST_TARGET(types);
TEST_TARGET(array);
TEST_TARGET(bool);