Re: [Chicken-users] large amount of data will break open-pipe

2008-05-05 Thread John Cowan
Lui Fungsin scripsit:

> For example, a typical C program will ignore SIGPIPE, and check for
> return code for every write/fprintf.

Most C programs don't seem to ignore SIGPIPE; in fact, the reason it exists
is to allow programs to be killed silently when their output is no longer
wanted by the next pipeline step.  Try  | more, get a page
of output, and hit 'q'; very few programs will report EPIPE ("svn log"
is the only one I know of).

-- 
A rabbi whose congregation doesn't want John Cowan
to drive him out of town isn't a rabbi, http://www.ccil.org/~cowan
and a rabbi who lets them do it [EMAIL PROTECTED]
isn't a man.--Jewish saying


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] large amount of data will break open-pipe

2008-05-05 Thread Lui Fungsin
Hi Felix,

>  Sorry for the overly late reply. I cannot reproduce this. Do you run
>  this code interpreted or compiled? Do I have to press any particular
>  key to provoke the sigpipe?

It is compiled. I tried this on Linux. You just need to enter a big
number (say over 5) so the chicken program will try to write enough
data to the sink (the pager).

Once the pager started, you press 'q' to quit the pager and the OS
will send a SIGPIPE to the chicken program, which will terminate it.

My question is, whether the WITH-OPEN-PIPE macro, as an abstraction,
should handle SIGPIPE (unlikely). If not, what's the preferred way to
do this handling properly in chicken?

For example, a typical C program will ignore SIGPIPE, and check for
return code for every write/fprintf.

#include 
#include 

void write_data (FILE * stream)
{
int i, rc;
for (i = 0; i < 1; i++) {
rc = fprintf(stream,
   "Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. %d\n", i);
if (rc <= -1) break;
}
if (ferror (stream)) {
fprintf (stderr, "Output to stream failed.\n");
}
}

int main (void)
{
FILE *output;

output = popen ("more", "w");
signal (SIGPIPE, SIG_IGN);
write_data (output);
if (pclose (output) != 0) {
/* chicken throws exception here */
fprintf (stderr, "Could not run more or other error.\n");
}
printf("exit normally\n");
return 0;
}


A similar chicken program

(declare (uses extras regex posix utils srfi-13))
(require-extension loop)
(require-extension miscmacros)

(define counter 0)

(define (command-loop)
  (loop for l = (let ((prompt (conc "Enter a number or `exit' :" counter "> ")))
  (display prompt) (read-line))
while (and l (not (eof-object? l)) (not (string= l "exit"))) do
(let ((n (ignore-errors (string->number l
  (when n
(with-output-to-pipe "more"
 (lambda ()
   (set! counter 0)
   (dotimes (i n)
 (print i " Lorem ipsum dolor sit amet,
consectetuer adipiscing elit.")
 (set! counter i

(set-signal-handler! signal/pipe #f);ignore sigpipe

(command-loop)

(print "exit normally")


Try entering a large number, say 5, then press 'q'.

Even though the pipe is broken, the chicken program will still try to
write to the pipe 5 times. This is a potential problem because
the body wrapped by with-output-to-pipe can be complex and time
consuming to execute.

I guess this has to do with how r5rs define the write procedure - it
will return an unspecified value, whether it succeeded or not.

After the loop, chicken will throw an exception (cannot close pipe).
If you try to handle this by wrapping a ignore-errors handler around
it, like

(ignore-errors (with-output-to-pipe "more" ..)

sometime it will hang the chicken program - I still need to
investigate why this happens.

I'm thinking whether we could register a sigpipe handler which when
triggered, will update the port sys-slot 8 (closed bool) to #f.

Then we could get behavior like this

#;> (define p (open-output-file "dummy.txt"))
#
#;> (close-output-port p)
#;> (display "hi" p)
Error: (display) port already closed: #

and the programmer can wrap a handler around the code that does output.

Without this, the only way to handle this now is to wrap a handler
around the whole (with-output-to-pipe ...) code block (and see the
ignore-errors problem described above).

I don't have much to contribute for now. I guess I have to read more
source code to understand the problem better.

Thanks!
-- fungsin


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] large amount of data will break open-pipe

2008-05-05 Thread felix winkelmann
On Tue, Apr 15, 2008 at 11:16 PM, Lui Fungsin <[EMAIL PROTECTED]> wrote:
> Is this a known limitation (similar to max string size of 0x00ff)?
>
>  I use pipe to connect through multiple processes (like grep / sort
>  /uniq,etc) and it is very handy.
>
>  I'm hoping that this is a bug and not a limitation...
>
>  Try the following code, enter 1500 is OK but if you enter 2000, the
>  program will abort with a broken pipe.
>

Hi, Fungsin!

Sorry for the overly late reply. I cannot reproduce this. Do you run
this code interpreted or compiled? Do I have to press any particular
key to provoke the sigpipe?


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Chicken OSless

2008-05-05 Thread felix winkelmann
On Thu, May 1, 2008 at 7:00 PM, John Van Enk <[EMAIL PROTECTED]> wrote:
> Hello All,
>
> I'm curious whether or not there's been work on running Chicken's binaries
> on a OSless piece of hardware. I've been trying to convince my boss that it
> would be worth while investigating dynamic languages for embedded systems.
>

I think this should generally be possible. You would have to reimplement
a bunch of libc functions, though (there are a number of macros in chicken.h
that are use to abstract that stuff). If you have a C compiler for a particular
platform, then chicken-generated code should be able to run, provided
the runtime support exists.


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users