mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-09 13:30:26 +02:00
* ports.c (scm_c_port_for_each): New function, mostly copied from
scm_port_for_each. (scm_port_for_each): Reimplemented using scm_c_port_for_each. * ports.h (scm_c_port_for_each): New prototype.
This commit is contained in:
parent
a1a5dfa888
commit
c536b4b32e
2 changed files with 19 additions and 12 deletions
|
@ -724,21 +724,12 @@ SCM_DEFINE (scm_close_output_port, "close-output-port", 1, 0, 0,
|
|||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
SCM_DEFINE (scm_port_for_each, "port-for-each", 1, 0, 0,
|
||||
(SCM proc),
|
||||
"Apply @var{proc} to each port in the Guile port table\n"
|
||||
"in turn. The return value is unspecified. More specifically,\n"
|
||||
"@var{proc} is applied exactly once to every port that exists\n"
|
||||
"in the system at the time @var{port-for-each} is invoked.\n"
|
||||
"Changes to the port table while @var{port-for-each} is running\n"
|
||||
"have no effect as far as @var{port-for-each} is concerned.")
|
||||
#define FUNC_NAME s_scm_port_for_each
|
||||
void
|
||||
scm_c_port_for_each (void (*proc)(void *data, SCM p), void *data)
|
||||
{
|
||||
long i;
|
||||
SCM ports;
|
||||
|
||||
SCM_VALIDATE_PROC (1, proc);
|
||||
|
||||
/* Even without pre-emptive multithreading, running arbitrary code
|
||||
while scanning the port table is unsafe because the port table
|
||||
can change arbitrarily (from a GC, for example). So we build a
|
||||
|
@ -754,14 +745,29 @@ SCM_DEFINE (scm_port_for_each, "port-for-each", 1, 0, 0,
|
|||
|
||||
while (ports != SCM_EOL)
|
||||
{
|
||||
scm_call_1 (proc, SCM_CAR (ports));
|
||||
proc (data, SCM_CAR (ports));
|
||||
ports = SCM_CDR (ports);
|
||||
}
|
||||
}
|
||||
|
||||
SCM_DEFINE (scm_port_for_each, "port-for-each", 1, 0, 0,
|
||||
(SCM proc),
|
||||
"Apply @var{proc} to each port in the Guile port table\n"
|
||||
"in turn. The return value is unspecified. More specifically,\n"
|
||||
"@var{proc} is applied exactly once to every port that exists\n"
|
||||
"in the system at the time @var{port-for-each} is invoked.\n"
|
||||
"Changes to the port table while @var{port-for-each} is running\n"
|
||||
"have no effect as far as @var{port-for-each} is concerned.")
|
||||
#define FUNC_NAME s_scm_port_for_each
|
||||
{
|
||||
SCM_VALIDATE_PROC (1, proc);
|
||||
|
||||
scm_c_port_for_each ((void (*)(void*,SCM))scm_call_1, proc);
|
||||
return SCM_UNSPECIFIED;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
|
||||
/* Utter miscellany. Gosh, we should clean this up some time. */
|
||||
|
||||
|
|
|
@ -250,6 +250,7 @@ SCM_API SCM scm_close_input_port (SCM port);
|
|||
SCM_API SCM scm_close_output_port (SCM port);
|
||||
SCM_API SCM scm_close_port (SCM port);
|
||||
SCM_API SCM scm_port_for_each (SCM proc);
|
||||
SCM_API void scm_c_port_for_each (void (*proc)(void *data, SCM p), void *data);
|
||||
SCM_API SCM scm_input_port_p (SCM x);
|
||||
SCM_API SCM scm_output_port_p (SCM x);
|
||||
SCM_API SCM scm_port_p (SCM x);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue