Inside: fix embedding example to use functions
In some embedding contexts, functions must be used instead of globals for things like `scheme_current_thread` and `scheme_false`.
This commit is contained in:
parent
5c10eb13eb
commit
4e57e160fb
|
@ -11,7 +11,8 @@
|
||||||
The Racket run-time system can be embedded into a larger program. The
|
The Racket run-time system can be embedded into a larger program. The
|
||||||
embedding process for Racket CGC or Racket 3m (see @secref[cgc-v-3m])
|
embedding process for Racket CGC or Racket 3m (see @secref[cgc-v-3m])
|
||||||
is essentially the same, but the process for Racket 3m is most easily
|
is essentially the same, but the process for Racket 3m is most easily
|
||||||
understood as a variant of the process for Racket CGC.
|
understood as a variant of the process for Racket CGC (even though
|
||||||
|
Racket 3m is the standard variant of Racket).
|
||||||
|
|
||||||
@section{CGC Embedding}
|
@section{CGC Embedding}
|
||||||
|
|
||||||
|
@ -181,6 +182,7 @@ static int run(Scheme_Env *e, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
Scheme_Object *curout;
|
Scheme_Object *curout;
|
||||||
int i;
|
int i;
|
||||||
|
Scheme_Thread *th;
|
||||||
mz_jmp_buf * volatile save, fresh;
|
mz_jmp_buf * volatile save, fresh;
|
||||||
|
|
||||||
/* Declare embedded modules in "base.c": */
|
/* Declare embedded modules in "base.c": */
|
||||||
|
@ -191,11 +193,13 @@ static int run(Scheme_Env *e, int argc, char *argv[])
|
||||||
curout = scheme_get_param(scheme_current_config(),
|
curout = scheme_get_param(scheme_current_config(),
|
||||||
MZCONFIG_OUTPUT_PORT);
|
MZCONFIG_OUTPUT_PORT);
|
||||||
|
|
||||||
|
th = scheme_get_current_thread();
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
save = scheme_current_thread->error_buf;
|
save = th->error_buf;
|
||||||
scheme_current_thread->error_buf = &fresh;
|
th->error_buf = &fresh;
|
||||||
if (scheme_setjmp(scheme_error_buf)) {
|
if (scheme_setjmp(*th->error_buf)) {
|
||||||
scheme_current_thread->error_buf = save;
|
th->error_buf = save;
|
||||||
return -1; /* There was an error */
|
return -1; /* There was an error */
|
||||||
} else {
|
} else {
|
||||||
Scheme_Object *v, *a[2];
|
Scheme_Object *v, *a[2];
|
||||||
|
@ -206,7 +210,7 @@ static int run(Scheme_Env *e, int argc, char *argv[])
|
||||||
a[0] = scheme_intern_symbol("racket/base");
|
a[0] = scheme_intern_symbol("racket/base");
|
||||||
a[1] = scheme_intern_symbol("read-eval-print-loop");
|
a[1] = scheme_intern_symbol("read-eval-print-loop");
|
||||||
scheme_apply(scheme_dynamic_require(2, a), 0, NULL);
|
scheme_apply(scheme_dynamic_require(2, a), 0, NULL);
|
||||||
scheme_current_thread->error_buf = save;
|
th->error_buf = save;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -307,15 +311,17 @@ static int run(Scheme_Env *e, int argc, char *argv[])
|
||||||
Scheme_Object *curout = NULL, *v = NULL, *a[2] = {NULL, NULL};
|
Scheme_Object *curout = NULL, *v = NULL, *a[2] = {NULL, NULL};
|
||||||
Scheme_Config *config = NULL;
|
Scheme_Config *config = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
Scheme_Thread *th = NULL;
|
||||||
mz_jmp_buf * volatile save = NULL, fresh;
|
mz_jmp_buf * volatile save = NULL, fresh;
|
||||||
|
|
||||||
MZ_GC_DECL_REG(8);
|
MZ_GC_DECL_REG(9);
|
||||||
MZ_GC_VAR_IN_REG(0, e);
|
MZ_GC_VAR_IN_REG(0, e);
|
||||||
MZ_GC_VAR_IN_REG(1, curout);
|
MZ_GC_VAR_IN_REG(1, curout);
|
||||||
MZ_GC_VAR_IN_REG(2, save);
|
MZ_GC_VAR_IN_REG(2, save);
|
||||||
MZ_GC_VAR_IN_REG(3, config);
|
MZ_GC_VAR_IN_REG(3, config);
|
||||||
MZ_GC_VAR_IN_REG(4, v);
|
MZ_GC_VAR_IN_REG(4, v);
|
||||||
MZ_GC_ARRAY_VAR_IN_REG(5, a, 2);
|
MZ_GC_VAR_IN_REG(5, th);
|
||||||
|
MZ_GC_ARRAY_VAR_IN_REG(6, a, 2);
|
||||||
|
|
||||||
MZ_GC_REG();
|
MZ_GC_REG();
|
||||||
|
|
||||||
|
@ -327,11 +333,13 @@ static int run(Scheme_Env *e, int argc, char *argv[])
|
||||||
config = scheme_current_config();
|
config = scheme_current_config();
|
||||||
curout = scheme_get_param(config, MZCONFIG_OUTPUT_PORT);
|
curout = scheme_get_param(config, MZCONFIG_OUTPUT_PORT);
|
||||||
|
|
||||||
|
th = scheme_get_current_thread();
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
save = scheme_current_thread->error_buf;
|
save = th->error_buf;
|
||||||
scheme_current_thread->error_buf = &fresh;
|
th->error_buf = &fresh;
|
||||||
if (scheme_setjmp(scheme_error_buf)) {
|
if (scheme_setjmp(*th->error_buf)) {
|
||||||
scheme_current_thread->error_buf = save;
|
th->error_buf = save;
|
||||||
return -1; /* There was an error */
|
return -1; /* There was an error */
|
||||||
} else {
|
} else {
|
||||||
v = scheme_eval_string(argv[i], e);
|
v = scheme_eval_string(argv[i], e);
|
||||||
|
@ -343,7 +351,7 @@ static int run(Scheme_Env *e, int argc, char *argv[])
|
||||||
a[1] = scheme_intern_symbol("read-eval-print-loop");
|
a[1] = scheme_intern_symbol("read-eval-print-loop");
|
||||||
v = scheme_dynamic_require(2, a);
|
v = scheme_dynamic_require(2, a);
|
||||||
scheme_apply(v, 0, NULL);
|
scheme_apply(v, 0, NULL);
|
||||||
scheme_current_thread->error_buf = save;
|
th->error_buf = save;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ Racket thread; all other threads are created through calls to
|
||||||
|
|
||||||
Information about each internal Racket thread is kept in a
|
Information about each internal Racket thread is kept in a
|
||||||
@cppi{Scheme_Thread} structure. A pointer to the current thread's
|
@cppi{Scheme_Thread} structure. A pointer to the current thread's
|
||||||
structure is available as @cppi{scheme_current_thread}. A
|
structure is available as @cppdef{scheme_current_thread} or
|
||||||
|
from @cppi{scheme_get_current_thread}. A
|
||||||
@cpp{Scheme_Thread} structure includes the following fields:
|
@cpp{Scheme_Thread} structure includes the following fields:
|
||||||
|
|
||||||
@itemize[
|
@itemize[
|
||||||
|
@ -378,6 +379,12 @@ The following function @cpp{mzsleep} is an appropriate
|
||||||
|
|
||||||
@section{Thread Functions}
|
@section{Thread Functions}
|
||||||
|
|
||||||
|
@function[(Scheme_Thread* scheme_get_current_thread)]{
|
||||||
|
|
||||||
|
Returns the currently executing thread. The result is equivalent to
|
||||||
|
@cppi{scheme_current_thread}, but the function form must be used in
|
||||||
|
some embedding contexts.}
|
||||||
|
|
||||||
@function[(Scheme_Object* scheme_thread
|
@function[(Scheme_Object* scheme_thread
|
||||||
[Scheme_Object* thunk])]{
|
[Scheme_Object* thunk])]{
|
||||||
|
|
||||||
|
|
|
@ -296,6 +296,9 @@ There are six global constants:
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
In some embedding contexts, the function forms
|
||||||
|
@cppi{scheme_make_null}, etc., must be used, instead.
|
||||||
|
|
||||||
@; ----------------------------------------------------------------------
|
@; ----------------------------------------------------------------------
|
||||||
|
|
||||||
@section[#:tag "im:strings"]{Strings}
|
@section[#:tag "im:strings"]{Strings}
|
||||||
|
@ -325,6 +328,31 @@ For more fine-grained control over UTF-8 encoding, use the
|
||||||
|
|
||||||
@section{Value Functions}
|
@section{Value Functions}
|
||||||
|
|
||||||
|
@function[(Scheme_Object* scheme_make_null)]{
|
||||||
|
|
||||||
|
Returns @cppi{scheme_null}.
|
||||||
|
}
|
||||||
|
|
||||||
|
@function[(Scheme_Object* scheme_make_eof)]{
|
||||||
|
|
||||||
|
Returns @cppi{scheme_eof}.
|
||||||
|
}
|
||||||
|
|
||||||
|
@function[(Scheme_Object* scheme_make_true)]{
|
||||||
|
|
||||||
|
Returns @cppi{scheme_true}.
|
||||||
|
}
|
||||||
|
|
||||||
|
@function[(Scheme_Object* scheme_make_false)]{
|
||||||
|
|
||||||
|
Returns @cppi{scheme_false}.
|
||||||
|
}
|
||||||
|
|
||||||
|
@function[(Scheme_Object* scheme_make_void)]{
|
||||||
|
|
||||||
|
Returns @cppi{scheme_void}.
|
||||||
|
}
|
||||||
|
|
||||||
@function[(Scheme_Object* scheme_make_char
|
@function[(Scheme_Object* scheme_make_char
|
||||||
[mzchar ch])]{
|
[mzchar ch])]{
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user