6 void set_flag (void *data
);
11 void check_flag1 (const char *msg
, void (*func
)(void), int val
);
12 SCM
check_flag1_body (void *data
);
13 SCM
return_tag (void *data
, SCM tag
, SCM args
);
14 void check_cont (int rewindable
);
15 SCM
check_cont_body (void *data
);
16 void close_port (SCM port
);
17 void delete_file (void *data
);
18 void check_ports (void);
19 void check_fluid (void);
21 int flag1
, flag2
, flag3
;
30 /* FUNC1 should leave flag1 zero.
38 scm_frame_unwind_handler (set_flag
, &flag1
, 0);
42 /* FUNC2 should set flag1.
50 scm_frame_unwind_handler (set_flag
, &flag1
, SCM_F_WIND_EXPLICITLY
);
54 /* FUNC3 should set flag1.
62 scm_frame_unwind_handler (set_flag
, &flag1
, 0);
63 scm_misc_error ("func3", "gratuitous error", SCM_EOL
);
67 /* FUNC4 should set flag1.
75 scm_frame_unwind_handler (set_flag
, &flag1
, SCM_F_WIND_EXPLICITLY
);
76 scm_misc_error ("func4", "gratuitous error", SCM_EOL
);
81 check_flag1_body (void *data
)
83 void (*f
)(void) = (void (*)(void))data
;
85 return SCM_UNSPECIFIED
;
89 return_tag (void *data
, SCM tag
, SCM args
)
95 check_flag1 (const char *tag
, void (*func
)(void), int val
)
97 scm_internal_catch (SCM_BOOL_T
,
98 check_flag1_body
, func
,
102 printf ("%s failed\n", tag
);
108 check_cont_body (void *data
)
110 scm_t_frame_flags flags
= (data
? SCM_F_FRAME_REWINDABLE
: 0);
114 scm_frame_begin (flags
);
116 val
= scm_make_continuation (&first
);
122 check_cont (int rewindable
)
126 res
= scm_internal_catch (SCM_BOOL_T
,
127 check_cont_body
, (void *)(long)rewindable
,
130 /* RES is now either the created continuation, the value passed to
131 the continuation, or a catch-tag, such as 'misc-error.
134 if (scm_is_true (scm_procedure_p (res
)))
136 /* a continuation, invoke it */
137 scm_call_1 (res
, SCM_BOOL_F
);
139 else if (scm_is_false (res
))
141 /* the result of invoking the continuation, frame must be
145 printf ("continuation not blocked\n");
150 /* the catch tag, frame must not have been rewindable. */
153 printf ("continuation didn't work\n");
159 close_port (SCM port
)
161 scm_close_port (port
);
165 delete_file (void *data
)
167 unlink ((char *)data
);
173 char filename
[] = "/tmp/check-ports.XXXXXX";
175 if (mktemp (filename
) == NULL
)
180 SCM port
= scm_open_file (scm_from_locale_string (filename
),
181 scm_from_locale_string ("w"));
182 scm_frame_unwind_handler_with_scm (close_port
, port
,
183 SCM_F_WIND_EXPLICITLY
);
185 scm_frame_current_output_port (port
);
186 scm_write (scm_version (), SCM_UNDEFINED
);
192 SCM port
= scm_open_file (scm_from_locale_string (filename
),
193 scm_from_locale_string ("r"));
195 scm_frame_unwind_handler_with_scm (close_port
, port
,
196 SCM_F_WIND_EXPLICITLY
);
197 scm_frame_unwind_handler (delete_file
, filename
, SCM_F_WIND_EXPLICITLY
);
199 scm_frame_current_input_port (port
);
200 res
= scm_read (SCM_UNDEFINED
);
201 if (scm_is_false (scm_equal_p (res
, scm_version ())))
203 printf ("ports didn't work\n");
213 SCM f
= scm_make_fluid ();
216 scm_fluid_set_x (f
, scm_from_int (12));
219 scm_frame_fluid (f
, scm_from_int (13));
220 x
= scm_fluid_ref (f
);
223 if (!scm_is_eq (x
, scm_from_int (13)))
225 printf ("setting fluid didn't work\n");
229 if (!scm_is_eq (scm_fluid_ref (f
), scm_from_int (12)))
231 printf ("resetting fluid didn't work\n");
237 inner_main (void *data
, int argc
, char **argv
)
239 check_flag1 ("func1", func1
, 0);
240 check_flag1 ("func2", func2
, 1);
241 check_flag1 ("func3", func3
, 1);
242 check_flag1 ("func4", func4
, 1);
255 main (int argc
, char **argv
)
257 scm_boot_guile (argc
, argv
, inner_main
, 0);