[Openmcl-devel] popen is not happy

Erann Gat eg at flownet.com
Wed Jun 4 20:39:17 UTC 2003

> I'm less convinced that it's safe to pass stack-allocated strings to
> #_popen; whether this works or not may depend on whether the forked
> child is able to use them before the parent deallocates them.  It
> looks very much like the exception you got here was in the child
> process; typing an "X" at the prompt killed the child process, and
> the pipe-based FILE* was returned to the parent process.

That's a good theory, but there are two problems.  First, you'd have the
same problem if you wrote the following C code:

  char * cmd = "ls";
  char * mode = "r+";
  return popen(cmd, mode);

and if that were going to be a problem I would think there's be a pretty
big warning in the popen man page.

The second problem is that the same thing happens with heap-allocated

? (setf s1 (CCL::%NEW-PTR 4 NIL))
#<A Mac Pointer #x41BC0>
? (setf s2 (CCL::%NEW-PTR 4 NIL))
#<A Mac Pointer #x41A80>
? (ccl::%cstr-pointer "ls" s1)
? (ccl::%cstr-pointer "r+" s2)
? (#_popen s1 s2)
#<A Null Mac Pointer>

Actually, this looks like a bug in OSX's popen -- or a bug in their man
page.  Popen does not normally support bidirectional I/O, but the
Jaguar man page says it does, but aparently it doesn't.  I get the same
results in Python and C. Bummer.

With a unidirectional popen and heap-allocated cstrs it works.


Openmcl-devel mailing list
Openmcl-devel at clozure.com

More information about the Openmcl-devel mailing list