mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-01 07:10:34 -08:00
Implement SI:MAKE-PIPE (By S. Gromoff). Eliminate OPEN-PIPE / CLOSE-PIPE.
This commit is contained in:
parent
faa259203e
commit
aa099a332a
5 changed files with 24 additions and 39 deletions
|
|
@ -136,6 +136,12 @@ ECL 0.9k:
|
|||
|
||||
- Accessors for low-level socket timeout attributes (by G. Carncross).
|
||||
|
||||
- The function EXT:OPEN-PIPE disappears, together with EXT:CLOSE-PIPE. Use
|
||||
EXT:RUN-PROCESS instead.
|
||||
|
||||
- New function EXT:MAKE-PIPE implements the equivalent of POSIX pipe() but
|
||||
producing a two-way stream.
|
||||
|
||||
* CLOS:
|
||||
|
||||
- When caching generic function calls, ECL now uses a thread-local hash table
|
||||
|
|
|
|||
|
|
@ -1079,7 +1079,6 @@ cl_symbols[] = {
|
|||
{SYS_ "CHAR-SET", SI_ORDINARY, si_char_set, 3, OBJNULL},
|
||||
{SYS_ "CHDIR", SI_ORDINARY, si_chdir, -1, OBJNULL},
|
||||
{SYS_ "CLEAR-COMPILER-PROPERTIES", SI_ORDINARY, cl_identity, 1, OBJNULL},
|
||||
{SYS_ "CLOSE-PIPE", SI_ORDINARY, si_close_pipe, 1, OBJNULL},
|
||||
{SYS_ "COERCE-TO-BASE-STRING", SI_ORDINARY, si_coerce_to_base_string, 1, OBJNULL},
|
||||
{SYS_ "COERCE-TO-EXTENDED-STRING", SI_ORDINARY, si_coerce_to_extended_string, 1, OBJNULL},
|
||||
{SYS_ "COERCE-TO-FILENAME", SI_ORDINARY, si_coerce_to_filename, 1, OBJNULL},
|
||||
|
|
@ -1141,7 +1140,7 @@ cl_symbols[] = {
|
|||
{SYS_ "MKDIR", SI_ORDINARY, si_mkdir, 2, OBJNULL},
|
||||
{SYS_ "MKSTEMP", SI_ORDINARY, si_mkstemp, 1, OBJNULL},
|
||||
{SYS_ "RMDIR", SI_ORDINARY, si_rmdir, 1, OBJNULL},
|
||||
{SYS_ "OPEN-PIPE", SI_ORDINARY, si_open_pipe, 1, OBJNULL},
|
||||
{SYS_ "MAKE-PIPE", SI_ORDINARY, si_make_pipe, 0, OBJNULL},
|
||||
{SYS_ "PACKAGE-LOCK", SI_ORDINARY, si_package_lock, 2, OBJNULL},
|
||||
{SYS_ "PACKAGE-HASH-TABLES", SI_ORDINARY, si_package_hash_tables, 1, OBJNULL},
|
||||
{SYS_ "PATHNAME-TRANSLATIONS", SI_ORDINARY, si_pathname_translations, -1, OBJNULL},
|
||||
|
|
|
|||
|
|
@ -1079,7 +1079,6 @@ cl_symbols[] = {
|
|||
{SYS_ "CHAR-SET","si_char_set"},
|
||||
{SYS_ "CHDIR","si_chdir"},
|
||||
{SYS_ "CLEAR-COMPILER-PROPERTIES","cl_identity"},
|
||||
{SYS_ "CLOSE-PIPE","si_close_pipe"},
|
||||
{SYS_ "COERCE-TO-BASE-STRING","si_coerce_to_base_string"},
|
||||
{SYS_ "COERCE-TO-EXTENDED-STRING","si_coerce_to_extended_string"},
|
||||
{SYS_ "COERCE-TO-FILENAME","si_coerce_to_filename"},
|
||||
|
|
@ -1141,7 +1140,7 @@ cl_symbols[] = {
|
|||
{SYS_ "MKDIR","si_mkdir"},
|
||||
{SYS_ "MKSTEMP","si_mkstemp"},
|
||||
{SYS_ "RMDIR","si_rmdir"},
|
||||
{SYS_ "OPEN-PIPE","si_open_pipe"},
|
||||
{SYS_ "MAKE-PIPE","si_make_pipe"},
|
||||
{SYS_ "PACKAGE-LOCK","si_package_lock"},
|
||||
{SYS_ "PACKAGE-HASH-TABLES","si_package_hash_tables"},
|
||||
{SYS_ "PATHNAME-TRANSLATIONS","si_pathname_translations"},
|
||||
|
|
|
|||
|
|
@ -49,44 +49,26 @@ si_getpid(void)
|
|||
}
|
||||
|
||||
cl_object
|
||||
si_open_pipe(cl_object cmd_string)
|
||||
si_make_pipe()
|
||||
{
|
||||
cl_object output;
|
||||
int fds[2], ret;
|
||||
#ifdef _MSC_VER
|
||||
FEerror("Pipes are not supported under Win32/MSVC", 0);
|
||||
ret = _pipe(fds, 4096, _O_BINARY);
|
||||
#else
|
||||
FILE *ptr;
|
||||
cl_object stream;
|
||||
cl_object cmd = si_copy_to_simple_base_string(cmd);
|
||||
ptr = popen(cmd->base_string.self, "r");
|
||||
if (ptr == NULL)
|
||||
@(return Cnil);
|
||||
stream = cl_alloc_object(t_stream);
|
||||
stream->stream.mode = smm_input;
|
||||
stream->stream.file = ptr;
|
||||
stream->stream.object0 = @'base-char';
|
||||
stream->stream.char_stream_p = 1;
|
||||
stream->stream.object1 = @'si::open-pipe';
|
||||
stream->stream.int0 = stream->stream.int1 = 0;
|
||||
si_set_buffering_mode(stream, @':line-buffered');
|
||||
@(return stream)
|
||||
ret = pipe(fds);
|
||||
#endif
|
||||
}
|
||||
|
||||
cl_object
|
||||
si_close_pipe(cl_object stream)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
FEerror("Pipes are not supported under Win32/MSVC", 0);
|
||||
#else
|
||||
if (type_of(stream) == t_stream &&
|
||||
stream->stream.object1 == @'si::open-pipe') {
|
||||
stream->stream.closed = 1;
|
||||
pclose(stream->stream.file);
|
||||
stream->stream.file = NULL;
|
||||
stream->stream.object0 = OBJNULL;
|
||||
if (ret < 0) {
|
||||
FElibc_error("Unable to create pipe", 0);
|
||||
output = Cnil;
|
||||
} else {
|
||||
cl_object fake_in_name = make_simple_base_string("PIPE-READ-ENDPOINT");
|
||||
cl_object in = ecl_make_stream_from_fd(fake_in_name, fds[0], smm_input);
|
||||
cl_object fake_out_name = make_simple_base_string("PIPE-WRITE-ENDPOINT");
|
||||
cl_object out = ecl_make_stream_from_fd(fake_out_name, fds[1], smm_output);
|
||||
output = cl_make_two_way_stream(in, out);
|
||||
}
|
||||
@(return)
|
||||
#endif
|
||||
@(return output)
|
||||
}
|
||||
|
||||
@(defun ext::run-program (command argv &key (input @':stream') (output @':stream')
|
||||
|
|
|
|||
|
|
@ -1530,8 +1530,7 @@ extern ECL_API cl_object si_trap_fpe(cl_object condition, cl_object flag);
|
|||
/* unixsys.c */
|
||||
|
||||
extern ECL_API cl_object si_system(cl_object cmd);
|
||||
extern ECL_API cl_object si_open_pipe(cl_object cmd);
|
||||
extern ECL_API cl_object si_close_pipe(cl_object stream);
|
||||
extern ECL_API cl_object si_make_pipe();
|
||||
extern ECL_API cl_object si_run_program _ARGS((cl_narg narg, cl_object command, cl_object args, ...));
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue