Re: [PATCH] IO fixes for Win32

2004-02-19 Thread Goplat
--- Dan Sugalski [EMAIL PROTECTED] wrote:
 At 12:40 AM +0300 2/18/04, Vladimir Lipsky wrote:
 From: Goplat [EMAIL PROTECTED]
 
   --- Vladimir Lipsky [EMAIL PROTECTED] wrote:
From: Goplat [EMAIL PROTECTED]
   
 flags_to_win32 sets fdwShareMode to FILE_SHARE_DELETE, which is not
 supported in win98
   
A fix for that should be windows version specific and needs support
of the config subsystem.
 
   If you did that, a version compiled on NT wouldn't work on 9x. I'd say
   most 9x users don't compile perl themself, they just download a binary
   from ActiveState (who use NT)...
 
 Then there should be different binaries for different versions
 
 Yeah, I'm actually coming to that conclusion. Yes, it's sort of 
 easier to keep a single binary around from a packaging standpoint, 
 it's a hassle for everyone else because of it.

Where is the hassle? It's just a few lines of code to check windows version.
It's easier to code that than to make another configure option.


__
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools


Re: [PATCH] IO fixes for Win32

2004-02-19 Thread Melvin Smith
At 09:27 AM 2/19/2004 -0800, Goplat wrote:
--- Dan Sugalski [EMAIL PROTECTED] wrote:
 At 12:40 AM +0300 2/18/04, Vladimir Lipsky wrote:
 From: Goplat [EMAIL PROTECTED]
 
   --- Vladimir Lipsky [EMAIL PROTECTED] wrote:
From: Goplat [EMAIL PROTECTED]
   
 flags_to_win32 sets fdwShareMode to FILE_SHARE_DELETE, which is not
 supported in win98
   
A fix for that should be windows version specific and needs support
of the config subsystem.
 
   If you did that, a version compiled on NT wouldn't work on 9x. I'd say
   most 9x users don't compile perl themself, they just download a binary
   from ActiveState (who use NT)...
 
 Then there should be different binaries for different versions

 Yeah, I'm actually coming to that conclusion. Yes, it's sort of
 easier to keep a single binary around from a packaging standpoint,
 it's a hassle for everyone else because of it.
Where is the hassle? It's just a few lines of code to check windows version.
It's easier to code that than to make another configure option.
Then submit a patch.

I have no problem with that scenario. The code in question
is mine, but I don't have the ability to play with older versions
of Windows. I develop on XP, 2000, Linux and Solaris, and I
really don't claim to be much of a Windows programmer, outside
of Winsock.
-Melvin





Re: [PATCH] IO fixes for Win32

2004-02-19 Thread Goplat
--- Melvin Smith [EMAIL PROTECTED] wrote:
 At 09:27 AM 2/19/2004 -0800, Goplat wrote:
 --- Dan Sugalski [EMAIL PROTECTED] wrote:
   At 12:40 AM +0300 2/18/04, Vladimir Lipsky wrote:
   From: Goplat [EMAIL PROTECTED]
   
 --- Vladimir Lipsky [EMAIL PROTECTED] wrote:
  From: Goplat [EMAIL PROTECTED]
 
   flags_to_win32 sets fdwShareMode to FILE_SHARE_DELETE, which is
   not supported in win98
 
  A fix for that should be windows version specific and needs
  support of the config subsystem.
   
 If you did that, a version compiled on NT wouldn't work on 9x. I'd
 say most 9x users don't compile perl themself, they just download a
 binary from ActiveState (who use NT)...
   
   Then there should be different binaries for different versions
  
   Yeah, I'm actually coming to that conclusion. Yes, it's sort of
   easier to keep a single binary around from a packaging standpoint,
   it's a hassle for everyone else because of it.
 
 Where is the hassle? It's just a few lines of code to check windows
 version. It's easier to code that than to make another configure option.
 
 Then submit a patch.

Okay. (attached)


__
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools--- io/io_win32.c~  Wed Feb  4 07:46:48 2004
+++ io/io_win32.c   Tue Feb 17 08:21:16 2004
@@ -84,6 +84,20 @@
 flags_to_win32(INTVAL flags, DWORD * fdwAccess,
DWORD * fdwShareMode, DWORD * fdwCreate)
 {
+static DWORD dwDefaultShareMode;
+if (!dwDefaultShareMode) {
+OSVERSIONINFO osvi;
+osvi.dwOSVersionInfoSize = sizeof(osvi);
+GetVersionEx(osvi);
+if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
+dwDefaultShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
+}
+else {
+dwDefaultShareMode =
+FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+}
+}
+
 if ((flags  (PIO_F_WRITE | PIO_F_READ)) == (PIO_F_WRITE | PIO_F_READ)) {
 *fdwAccess = GENERIC_WRITE | GENERIC_READ;
 if (flags  PIO_F_TRUNC)
@@ -103,7 +117,7 @@
 *fdwCreate = OPEN_EXISTING;
 }
 
-*fdwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+*fdwShareMode = dwDefaultShareMode;
 if (flags  PIO_F_APPEND) {
 /* dealt with specially in _write and _puts */
 }
--- t/src/io.t~ Mon Feb  9 01:10:46 2004
+++ t/src/io.t  Mon Feb 16 11:00:26 2004
@@ -11,6 +11,7 @@
my $content = @_ ? shift : This is a test\n;
 
open(FILE, $name) or die Failed to create $name;
+   binmode FILE;
print FILE $content;
close(FILE);
 
@@ -69,7 +70,7 @@
 the_test(struct Parrot_Interp *interpreter,
opcode_t *cur_op, opcode_t *start)
 {
-ParrotIO *io;
+PMC *io;
 char *p;
 
 io = PIO_STDOUT(interpreter);
@@ -100,15 +101,15 @@
 the_test(struct Parrot_Interp *interpreter,
opcode_t *cur_op, opcode_t *start)
 {
-ParrotIO *io;
+PMC *io;
 char buf[1024];
-UINTVAL len;
+INTVAL len;
 
 io = PIO_open(interpreter, NULL, temp.file, );
 len = PIO_read(interpreter, io, buf, sizeof(buf)-1);
 PIO_close(interpreter, io);
 
-buf[len] = '\0';
+buf[len  0 ? 0 : len] = '\0';
 PIO_printf(interpreter, %s, buf);
 
 io = PIO_open(interpreter, NULL, temp.file, );
@@ -117,8 +118,8 @@
 
 do {
 len = PIO_read(interpreter, io, buf, 3);
-buf[len] = '\0';
-   /* dont write trailing spaces */
+buf[len  0 ? 0 : len] = '\0';
+/* don't write trailing spaces */
 PIO_printf(interpreter, %d: %s\n, len, len ? buf : EOF);
 } while (len  0);
 
@@ -142,7 +143,7 @@
 the_test(struct Parrot_Interp *interpreter,
opcode_t *cur_op, opcode_t *start)
 {
-ParrotIO *io;
+PMC *io;
 
 io = PIO_open(interpreter, NULL, temp.file, );
 PIO_write(interpreter, io, Parrot flies.\n, 14);
@@ -166,8 +167,8 @@
 the_test(struct Parrot_Interp *interpreter,
opcode_t *cur_op, opcode_t *start)
 {
-ParrotIO *io;
-size_t len;
+PMC *io;
+INTVAL len;
 char buf[1024];
 
 io = PIO_open(interpreter, NULL, temp.file, );
@@ -175,7 +176,7 @@
 
 do {
 len = PIO_read(interpreter, io, buf, sizeof(buf)-1);
-buf[len] = '\0';
+buf[len  0 ? 0 : len] = '\0';
 PIO_printf(interpreter, %d: %s, len, len ? buf : EOF);
 } while (len  0);
 


Re: [PATCH] IO fixes for Win32

2004-02-19 Thread Melvin Smith
At 10:02 AM 2/19/2004 -0800, Goplat wrote:
--- Melvin Smith [EMAIL PROTECTED] wrote:
 Where is the hassle? It's just a few lines of code to check windows
 version. It's easier to code that than to make another configure option.

 Then submit a patch.
Okay. (attached)


Very good, thank you sir. I see
you also addressed another outstanding issue with
the negative return val to read (into an unsigned).
Did you run the test suite and get successes?
If so, I will apply.
-Melvin




Re: [PATCH] IO fixes for Win32

2004-02-19 Thread Goplat
--- Melvin Smith [EMAIL PROTECTED] wrote:
 At 10:02 AM 2/19/2004 -0800, Goplat wrote:
 --- Melvin Smith [EMAIL PROTECTED] wrote:
   Where is the hassle? It's just a few lines of code to check windows
   version. It's easier to code that than to make another configure
 option.
  
   Then submit a patch.
 
 Okay. (attached)
 
 Very good, thank you sir. I see
 you also addressed another outstanding issue with
 the negative return val to read (into an unsigned).
 
 Did you run the test suite and get successes?
 If so, I will apply.

Failed Test   Stat Wstat Total Fail  Failed  List of Failed

imcc/t/syn/file.t1   256121   8.33%  11
t/pmc/env.t  3   768 63  50.00%  3 5-6
t/pmc/perlarray.t1   256261   3.85%  26
t/pmc/sub.t  3   768493   6.12%  36-38
t/pmc/tqueue.t   2   512 52  40.00%  2-3
2 tests and 69 subtests skipped.
Failed 5/94 test scripts, 94.68% okay. 10/1320 subtests failed, 99.24% okay.

Not exactly success, but it's just the same failures I got before applying
it. At least the IO stuff succeeded this time (imcc/t/syn/file.t fails
because of shell issues).

__
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools


Re: [PATCH] IO fixes for Win32

2004-02-19 Thread Melvin Smith
At 11:57 AM 2/19/2004 -0800, Goplat wrote:
Failed Test   Stat Wstat Total Fail  Failed  List of Failed

imcc/t/syn/file.t1   256121   8.33%  11
t/pmc/env.t  3   768 63  50.00%  3 5-6
t/pmc/perlarray.t1   256261   3.85%  26
t/pmc/sub.t  3   768493   6.12%  36-38
t/pmc/tqueue.t   2   512 52  40.00%  2-3
2 tests and 69 subtests skipped.
Failed 5/94 test scripts, 94.68% okay. 10/1320 subtests failed, 99.24% okay.
Not exactly success, but it's just the same failures I got before applying
it. At least the IO stuff succeeded this time (imcc/t/syn/file.t fails
because of shell issues).
Works for me, applied, thanks.

-Melvin




Re: [PATCH] IO fixes for Win32

2004-02-17 Thread Vladimir Lipsky
From: Goplat [EMAIL PROTECTED]

 flags_to_win32 sets fdwShareMode to FILE_SHARE_DELETE, which is not
supported
 in win98 and will cause the CreateFile to fail, so the ParrotIO is NULL,
and

A fix for that should be windows version specific and needs support of the
config subsystem.

The logic is as follows:

In the config subsystem ...

1) run a test which defines the os version
2) set the compiler option up

if version is windows 95
add  -D_WIN32_WINDOWS=0x0400 to cflags

else if version is windows 98 then
add  -D_WIN32_WINDOWS=0x0410 to cflags

else if version is windows Me then
add  -D_WIN32_WINDOWS=0x0500 to cflags

else if version is winnt 4.0 then
add  -D_WIN32_WINNT=0x0400 to cflags

else if version is windows 2000 then
add  -D_WIN32_WINNT=0x0500 to cflags

else if version is windows XP then
add  -D_WIN32_WINNT=0x0501 to cflags

else if version is windows server 2003 then
add  -D_WIN32_WINNT=0x0502 to cflags

end

In io.h ...

#ifdef _WIN32
#  if defined(_WIN32_WINDOWS)  (_WIN32_WINDOWS = 0x0500)
#define PIO_WIN32_SHARE_MODE (FILE_SHARE_READ  |\
# FILE_SHARE_WRITE)
#  else
#define PIO_WIN32_SHARE_MODE (FILE_SHARE_READ  |\
# FILE_SHARE_WRITE |\
# FILE_SHARE_DELETE)
#endif

0x4C56



Re: [PATCH] IO fixes for Win32

2004-02-17 Thread Vladimir Lipsky
From: Vladimir Lipsky [EMAIL PROTECTED]

 A fix for that should be windows version specific and needs support of the
 config subsystem.

And 0f course in io_win32.c

*fdwShareMode = PIO_WIN32_SHARE_MODE;

 0x4C56

0x4C56



Re: [PATCH] IO fixes for Win32

2004-02-17 Thread Goplat
--- Vladimir Lipsky [EMAIL PROTECTED] wrote:
 From: Goplat [EMAIL PROTECTED]
 
  flags_to_win32 sets fdwShareMode to FILE_SHARE_DELETE, which is not
  supported in win98
 
 A fix for that should be windows version specific and needs support of the
 config subsystem.

If you did that, a version compiled on NT wouldn't work on 9x. I'd say most
9x users don't compile perl themself, they just download a binary from
ActiveState (who use NT)...

If you really need FILE_SHARE_DELETE that badly, the check would have to be
done at runtime. I don't think it's all that necessary though... in fact perl
5 only uses FILE_SHARE_READ, and that only if the file's not opened for write/append.

__
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html--- io_win32.c~ Wed Feb  4 07:46:48 2004
+++ io_win32.c  Tue Feb 17 08:21:16 2004
@@ -84,6 +84,20 @@
 flags_to_win32(INTVAL flags, DWORD * fdwAccess,
DWORD * fdwShareMode, DWORD * fdwCreate)
 {
+static DWORD dwDefaultShareMode;
+if (!dwDefaultShareMode) {
+OSVERSIONINFO osvi;
+osvi.dwOSVersionInfoSize = sizeof(osvi);
+GetVersionEx(osvi);
+if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
+dwDefaultShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
+}
+else {
+dwDefaultShareMode =
+FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+}
+}
+
 if ((flags  (PIO_F_WRITE | PIO_F_READ)) == (PIO_F_WRITE | PIO_F_READ)) {
 *fdwAccess = GENERIC_WRITE | GENERIC_READ;
 if (flags  PIO_F_TRUNC)
@@ -103,7 +117,7 @@
 *fdwCreate = OPEN_EXISTING;
 }
 
-*fdwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+*fdwShareMode = dwDefaultShareMode;
 if (flags  PIO_F_APPEND) {
 /* dealt with specially in _write and _puts */
 }
--- io.t~   Mon Feb  9 01:10:46 2004
+++ io.tMon Feb 16 11:00:26 2004
@@ -11,6 +11,7 @@
my $content = @_ ? shift : This is a test\n;
 
open(FILE, $name) or die Failed to create $name;
+   binmode FILE;
print FILE $content;
close(FILE);
 
@@ -69,7 +70,7 @@
 the_test(struct Parrot_Interp *interpreter,
opcode_t *cur_op, opcode_t *start)
 {
-ParrotIO *io;
+PMC *io;
 char *p;
 
 io = PIO_STDOUT(interpreter);
@@ -100,15 +101,15 @@
 the_test(struct Parrot_Interp *interpreter,
opcode_t *cur_op, opcode_t *start)
 {
-ParrotIO *io;
+PMC *io;
 char buf[1024];
-UINTVAL len;
+INTVAL len;
 
 io = PIO_open(interpreter, NULL, temp.file, );
 len = PIO_read(interpreter, io, buf, sizeof(buf)-1);
 PIO_close(interpreter, io);
 
-buf[len] = '\0';
+buf[len  0 ? 0 : len] = '\0';
 PIO_printf(interpreter, %s, buf);
 
 io = PIO_open(interpreter, NULL, temp.file, );
@@ -117,8 +118,8 @@
 
 do {
 len = PIO_read(interpreter, io, buf, 3);
-buf[len] = '\0';
-   /* dont write trailing spaces */
+buf[len  0 ? 0 : len] = '\0';
+/* don't write trailing spaces */
 PIO_printf(interpreter, %d: %s\n, len, len ? buf : EOF);
 } while (len  0);
 
@@ -142,7 +143,7 @@
 the_test(struct Parrot_Interp *interpreter,
opcode_t *cur_op, opcode_t *start)
 {
-ParrotIO *io;
+PMC *io;
 
 io = PIO_open(interpreter, NULL, temp.file, );
 PIO_write(interpreter, io, Parrot flies.\n, 14);
@@ -166,8 +167,8 @@
 the_test(struct Parrot_Interp *interpreter,
opcode_t *cur_op, opcode_t *start)
 {
-ParrotIO *io;
-size_t len;
+PMC *io;
+INTVAL len;
 char buf[1024];
 
 io = PIO_open(interpreter, NULL, temp.file, );
@@ -175,7 +176,7 @@
 
 do {
 len = PIO_read(interpreter, io, buf, sizeof(buf)-1);
-buf[len] = '\0';
+buf[len  0 ? 0 : len] = '\0';
 PIO_printf(interpreter, %d: %s, len, len ? buf : EOF);
 } while (len  0);
 


Re: [PATCH] IO fixes for Win32

2004-02-17 Thread Vladimir Lipsky
From: Goplat [EMAIL PROTECTED]

 --- Vladimir Lipsky [EMAIL PROTECTED] wrote:
  From: Goplat [EMAIL PROTECTED]
 
   flags_to_win32 sets fdwShareMode to FILE_SHARE_DELETE, which is not
   supported in win98
 
  A fix for that should be windows version specific and needs support of
the
  config subsystem.

 If you did that, a version compiled on NT wouldn't work on 9x. I'd say
most
 9x users don't compile perl themself, they just download a binary from
 ActiveState (who use NT)...

Then there should be different binaries for different versions

 If you really need FILE_SHARE_DELETE that badly, the check would have to
be

Yeah and async I/O, and other stuff that aren't avaible in perl5 and windows
95/98/Me/CE. If we didn't yet distinguish windows versions, it's the time to
do so.

 done at runtime. I don't think it's all that necessary though... in fact
perl
 5 only uses FILE_SHARE_READ, and that only if the file's not opened for
write/append.

Does perl5 use FILE_SHARE_READ when + and + modes are specified? In any
case what you said sounds like a bug to me, since this policy restricts
other threads(even threads of the same process) to access the file in the
indentical mode.



Re: [PATCH] IO fixes for Win32

2004-02-17 Thread Dan Sugalski
At 12:40 AM +0300 2/18/04, Vladimir Lipsky wrote:
From: Goplat [EMAIL PROTECTED]

 --- Vladimir Lipsky [EMAIL PROTECTED] wrote:
  From: Goplat [EMAIL PROTECTED]
 
   flags_to_win32 sets fdwShareMode to FILE_SHARE_DELETE, which is not
   supported in win98
 
  A fix for that should be windows version specific and needs support of
the
  config subsystem.

 If you did that, a version compiled on NT wouldn't work on 9x. I'd say
most
 9x users don't compile perl themself, they just download a binary from
 ActiveState (who use NT)...
Then there should be different binaries for different versions
Yeah, I'm actually coming to that conclusion. Yes, it's sort of 
easier to keep a single binary around from a packaging standpoint, 
it's a hassle for everyone else because of it.

We talked ages ago about having the system identification ops let you 
know the sub-version of whichever OS you were on, and I think it's 
time to get that dusted off. That'll help with this a bit.

The one downside is the whole minimum capability issue. A Win9x 
binary, if built for Win9x, will run on WinXP yet lack all the 
crunchy WinXP features. Not that this is exclusive to windows as it's 
a problem on any system with any amount of backwards compatibility 
(or in some cases if we restrict operations with privs), so I'm OK 
with making it a non-issue here. We just need to think about ways to 
present interpreter capabilities so programs can query them if they 
need to.
--
Dan

--it's like this---
Dan Sugalski  even samurai
[EMAIL PROTECTED] have teddy bears and even
  teddy bears get drunk


Re: [PATCH] IO fixes for Win32

2004-02-17 Thread Vladimir Lipsky
From: Goplat [EMAIL PROTECTED]

 If you really need FILE_SHARE_DELETE that badly, the check would have to
be
 done at runtime. I don't think it's all that necessary though... in fact
perl
 5 only uses FILE_SHARE_READ, and that only if the file's not opened for
write/append.

What's more, a value of the parameter CdwDesiredAccess doesn't depend on a
value the parameter CdwShareMode and shouldn't do.

0x4C56



[PATCH] IO fixes for Win32

2004-02-16 Thread Goplat
flags_to_win32 sets fdwShareMode to FILE_SHARE_DELETE, which is not supported
in win98 and will cause the CreateFile to fail, so the ParrotIO is NULL, and
subsequent PIO_read on its io PMC will return -1. When len is -1, some tests
in t/src/io.t will think it's positive since it has it as a UINTVAL (should
be an INTVAL) causing it to loop forever. Also using -1 as an index into the
buffer could overwrite that len variable, making it actually positive. And it
uses ParrotIO* where it should be using PMC* (dosen't really matter but it's
nice to use the right type of pointer). Furthermore, test 13 fails since it
expects a 6 byte file, but actually creates one larger than that because
of \n - \r\n translation.

__
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html--- io/io_win32.c~  Wed Feb  4 07:46:48 2004
+++ io/io_win32.c   Mon Feb 16 10:41:18 2004
@@ -103,7 +103,7 @@
 *fdwCreate = OPEN_EXISTING;
 }
 
-*fdwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+*fdwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
 if (flags  PIO_F_APPEND) {
 /* dealt with specially in _write and _puts */
 }
--- io.t~   Mon Feb  9 01:10:46 2004
+++ io.tMon Feb 16 11:00:26 2004
@@ -11,6 +11,7 @@
my $content = @_ ? shift : This is a test\n;
 
open(FILE, $name) or die Failed to create $name;
+   binmode FILE;
print FILE $content;
close(FILE);
 
@@ -69,7 +70,7 @@
 the_test(struct Parrot_Interp *interpreter,
opcode_t *cur_op, opcode_t *start)
 {
-ParrotIO *io;
+PMC *io;
 char *p;
 
 io = PIO_STDOUT(interpreter);
@@ -100,15 +101,15 @@
 the_test(struct Parrot_Interp *interpreter,
opcode_t *cur_op, opcode_t *start)
 {
-ParrotIO *io;
+PMC *io;
 char buf[1024];
-UINTVAL len;
+INTVAL len;
 
 io = PIO_open(interpreter, NULL, temp.file, );
 len = PIO_read(interpreter, io, buf, sizeof(buf)-1);
 PIO_close(interpreter, io);
 
-buf[len] = '\0';
+buf[len  0 ? 0 : len] = '\0';
 PIO_printf(interpreter, %s, buf);
 
 io = PIO_open(interpreter, NULL, temp.file, );
@@ -117,8 +118,8 @@
 
 do {
 len = PIO_read(interpreter, io, buf, 3);
-buf[len] = '\0';
-   /* dont write trailing spaces */
+buf[len  0 ? 0 : len] = '\0';
+/* don't write trailing spaces */
 PIO_printf(interpreter, %d: %s\n, len, len ? buf : EOF);
 } while (len  0);
 
@@ -142,7 +143,7 @@
 the_test(struct Parrot_Interp *interpreter,
opcode_t *cur_op, opcode_t *start)
 {
-ParrotIO *io;
+PMC *io;
 
 io = PIO_open(interpreter, NULL, temp.file, );
 PIO_write(interpreter, io, Parrot flies.\n, 14);
@@ -166,8 +167,8 @@
 the_test(struct Parrot_Interp *interpreter,
opcode_t *cur_op, opcode_t *start)
 {
-ParrotIO *io;
-size_t len;
+PMC *io;
+INTVAL len;
 char buf[1024];
 
 io = PIO_open(interpreter, NULL, temp.file, );
@@ -175,7 +176,7 @@
 
 do {
 len = PIO_read(interpreter, io, buf, sizeof(buf)-1);
-buf[len] = '\0';
+buf[len  0 ? 0 : len] = '\0';
 PIO_printf(interpreter, %d: %s, len, len ? buf : EOF);
 } while (len  0);