# New Ticket Created by  Lars Balker Rasmussen 
# Please include the string:  [perl #24867]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=24867 >


I have rewritten some more of the tests in t/src to use the "proper"
approach to doing resource-juggling.  The tests that I haven't touched
don't seem to be reliant on this.
-- 
Lars Balker Rasmussen                                        Consult::Perl

Index: t/src/extend.t
===================================================================
RCS file: /cvs/public/parrot/t/src/extend.t,v
retrieving revision 1.13
diff -u -a -r1.13 extend.t
--- t/src/extend.t	13 Dec 2003 15:01:19 -0000	1.13
+++ t/src/extend.t	10 Jan 2004 21:54:41 -0000
@@ -337,42 +337,56 @@
 
 c_output_is(<<'CODE', <<'OUTPUT', "call a parrot sub");
 
-#include <stdio.h>
-/* have to cheat because of missing extend interfaces */
-/* #include "parrot/extend.h" */
-#include "parrot/parrot.h"
-#include "parrot/embed.h"
-
-void Parrot_call(Parrot_Interp interpreter, PMC* sub,
-                 Parrot_Int argcount, ...);
-/* also both the test PASM and main print to stderr
- * so that buffering in PIO isn't and issue
+#include <parrot/parrot.h>
+#include <parrot/embed.h>
+
+static opcode_t *the_test(Parrot_Interp, opcode_t *, opcode_t *);
+
+int main(int argc, char* argv[])
+{
+    Parrot_Interp interpreter = Parrot_new(NULL);
+    if (!interpreter) {
+        return 1;
+    }
+    Parrot_init(interpreter);
+
+    Parrot_run_native(interpreter, the_test);
+
+    Parrot_exit(0);
+    return 0;
+}
+
+/* also both the test PASM and the_test() print to stderr
+ * so that buffering in PIO is not an issue
  */
 
-int main(int argc, char* argv[]) {
-    Parrot_Interp interpreter;
+static opcode_t*
+the_test(Parrot_Interp interpreter, opcode_t *cur_op, opcode_t *start)
+{
     struct PackFile *pf;
     PMC *key, *sub, *arg;
 
-    interpreter = Parrot_new(NULL);
     pf = Parrot_readbc(interpreter, "temp.pbc");
     Parrot_loadbc(interpreter, pf);
     key = key_new_cstring(interpreter, "_sub1");
     sub = VTABLE_get_pmc_keyed(interpreter,
-				interpreter->globals->stash_hash, key);
+			       interpreter->globals->stash_hash, key);
     Parrot_call(interpreter, sub, 0);
-    fprintf(stderr, "back\n");
-    fflush(stderr);	/* win32 seems to buffer stderr */
+    PIO_eprintf(interpreter, "back\n");
+
+    /* win32 seems to buffer stderr ? */ 
+    PIO_flush(interpreter, PIO_STDERR(interpreter)); 
 
     key = key_new_cstring(interpreter, "_sub2");
     sub = VTABLE_get_pmc_keyed(interpreter,
-				interpreter->globals->stash_hash, key);
+			       interpreter->globals->stash_hash, key);
     arg = pmc_new(interpreter, enum_class_PerlString);
     VTABLE_set_string_native(interpreter, arg,
-	    string_from_cstring(interpreter, "hello ", 0));
+			     string_from_cstring(interpreter, "hello ", 0));
     Parrot_call(interpreter, sub, 1, arg);
-    fprintf(stderr, "back\n");
-    return 0;
+    PIO_eprintf(interpreter, "back\n");
+
+    return NULL;
 }
 CODE
 in sub1
@@ -396,39 +410,53 @@
 
 c_output_is(<<'CODE', <<'OUTPUT', "call a parrot sub, catch exception");
 
-#include <stdio.h>
-/* have to cheat because of missing extend interfaces */
-/* #include "parrot/extend.h" */
-#include "parrot/parrot.h"
-#include "parrot/embed.h"
-
-void Parrot_call(Parrot_Interp interpreter, PMC* sub,
-                 Parrot_Int argcount, ...);
-/* also both the test PASM and main print to stderr
- * so that buffering in PIO isn't and issue
+
+#include <parrot/parrot.h>
+#include <parrot/embed.h>
+
+static opcode_t *the_test(Parrot_Interp, opcode_t *, opcode_t *);
+
+int main(int argc, char* argv[])
+{
+    Parrot_Interp interpreter = Parrot_new(NULL);
+    if (!interpreter) {
+        return 1;
+    }
+    Parrot_init(interpreter);
+
+    Parrot_run_native(interpreter, the_test);
+
+    Parrot_exit(0);
+    return 0;
+}
+
+/* also both the test PASM and the_test() print to stderr
+ * so that buffering in PIO is not an issue
  */
 
-int main(int argc, char* argv[]) {
-    Parrot_Interp interpreter;
+static opcode_t*
+the_test(Parrot_Interp interpreter, opcode_t *cur_op, opcode_t *start)
+{
     struct PackFile *pf;
     PMC *key, *sub;
     Parrot_exception jb;
 
-    interpreter = Parrot_new(NULL);
     pf = Parrot_readbc(interpreter, "temp.pbc");
     Parrot_loadbc(interpreter, pf);
     key = key_new_cstring(interpreter, "_sub1");
     sub = VTABLE_get_pmc_keyed(interpreter,
-				interpreter->globals->stash_hash, key);
+			       interpreter->globals->stash_hash, key);
+
     if (setjmp(jb.destination)) {
-	fprintf(stderr, "caught\n");
+	PIO_eprintf(interpreter, "caught\n");
     }
     else {
 	push_new_c_exception_handler(interpreter, &jb);
 	Parrot_call(interpreter, sub, 0);
     }
-    fprintf(stderr, "back\n");
-    return 0;
+    PIO_eprintf(interpreter, "back\n");
+
+    return NULL;
 }
 CODE
 in sub1
Index: t/src/io.t
===================================================================
RCS file: /cvs/public/parrot/t/src/io.t,v
retrieving revision 1.8
diff -u -a -r1.8 io.t
--- t/src/io.t	13 Dec 2003 15:01:19 -0000	1.8
+++ t/src/io.t	10 Jan 2004 21:54:41 -0000
@@ -25,46 +25,53 @@
 	die "Failed to delete $name"if -e $name;
 }
 
-###############################################################################
-
-c_output_is(<<'CODE', <<'OUTPUT', "hello world");
+my $main = <<'CODE';
 #include <parrot/parrot.h>
 #include <parrot/embed.h>
-#include <parrot/io.h>
 
-int
-main ()
-{
-    struct Parrot_Interp *interpreter;
+static opcode_t *the_test(Parrot_Interp, opcode_t *, opcode_t *);
 
-    interpreter = Parrot_new(NULL);
+int main(int argc, char* argv[])
+{
+    Parrot_Interp interpreter = Parrot_new(NULL);
+    if (!interpreter) {
+        return 1;
+    }
     Parrot_init(interpreter);
 
-    PIO_printf(interpreter, "Hello, World!\n");
+    Parrot_run_native(interpreter, the_test);
 
+    Parrot_exit(0);
     return 0;
 }
+
+CODE
+
+###############################################################################
+
+c_output_is($main . <<'CODE', <<'OUTPUT', "hello world");
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	opcode_t *cur_op, opcode_t *start)
+{
+    PIO_printf(interpreter, "Hello, World!\n");
+
+    return NULL;
+}
 CODE
 Hello, World!
 OUTPUT
 
 ###############################################################################
 
-c_output_is(<<'CODE', <<'OUTPUT', "write");
-#include <parrot/parrot.h>
-#include <parrot/embed.h>
-#include <parrot/io.h>
-
-int
-main ()
+c_output_is($main . <<'CODE', <<'OUTPUT', "write");
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	opcode_t *cur_op, opcode_t *start)
 {
-    struct Parrot_Interp *interpreter;
     ParrotIO *io;
     char *p;
 
-    interpreter = Parrot_new(NULL);
-    Parrot_init(interpreter);
-
     io = PIO_STDOUT(interpreter);
     PIO_write(interpreter, io, "Hello, World!\n", 14);
 
@@ -74,7 +81,7 @@
     }
     PIO_close(interpreter, io);
 
-    return 0;
+    return NULL;
 }
 CODE
 Hello, World!
@@ -88,22 +95,15 @@
 
 ###############################################################################
 
-c_output_is(<<'CODE', <<'OUTPUT', 'read');
-#include <parrot/parrot.h>
-#include <parrot/embed.h>
-#include <parrot/io.h>
-
-int
-main ()
+c_output_is($main . <<'CODE', <<'OUTPUT', 'read');
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	opcode_t *cur_op, opcode_t *start)
 {
-    struct Parrot_Interp *interpreter;
     ParrotIO *io;
     char buf[1024];
     UINTVAL len;
 
-    interpreter = Parrot_new(NULL);
-    Parrot_init(interpreter);
-
     io = PIO_open(interpreter, NULL, "temp.file", "<");
     len = PIO_read(interpreter, io, buf, sizeof(buf)-1);
     PIO_close(interpreter, io);
@@ -122,7 +122,7 @@
         PIO_printf(interpreter, "%d: %s\n", len, len ? buf : "EOF");
     } while (len > 0);
 
-    return 0;
+    return NULL;
 }
 CODE
 Hello, World!
@@ -137,25 +137,18 @@
 
 ###############################################################################
 
-c_output_is(<<'CODE', '', 'append');
-#include <parrot/parrot.h>
-#include <parrot/embed.h>
-#include <parrot/io.h>
-
-int
-main ()
+c_output_is($main . <<'CODE', '', 'append');
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	opcode_t *cur_op, opcode_t *start)
 {
-    struct Parrot_Interp *interpreter;
     ParrotIO *io;
 
-    interpreter = Parrot_new(NULL);
-    Parrot_init(interpreter);
-
     io = PIO_open(interpreter, NULL, "temp.file", ">>");
     PIO_write(interpreter, io, "Parrot flies.\n", 14);
     PIO_close(interpreter, io);
 
-    return 0;
+    return NULL;
 }
 CODE
 
@@ -168,22 +161,15 @@
 
 ###############################################################################
 
-c_output_is(<<'CODE', <<'OUTPUT', 'readline');
-#include <parrot/parrot.h>
-#include <parrot/embed.h>
-#include <parrot/io.h>
-
-int
-main ()
+c_output_is($main . <<'CODE', <<'OUTPUT', 'readline');
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	opcode_t *cur_op, opcode_t *start)
 {
-    struct Parrot_Interp *interpreter;
     ParrotIO *io;
     size_t len;
     char buf[1024];
 
-    interpreter = Parrot_new(NULL);
-    Parrot_init(interpreter);
-
     io = PIO_open(interpreter, NULL, "temp.file", "<");
     PIO_setlinebuf(interpreter, io);
 
@@ -193,9 +179,9 @@
         PIO_printf(interpreter, "%d: %s", len, len ? buf : "EOF");
     } while (len > 0);
 
-   PIO_printf(interpreter, "\n");
+    PIO_printf(interpreter, "\n");
 
-    return 0;
+    return NULL;
 }
 CODE
 14: Hello, World!
@@ -205,32 +191,37 @@
 
 ###############################################################################
 
-c_output_is(<<'CODE', <<'OUTPUT', "PIO_parse_open_flags");
-#include <stdio.h>
-#include "parrot/parrot.h"
-#include "parrot/embed.h"
+c_output_is($main . <<'CODE', <<'OUTPUT', "PIO_parse_open_flags");
 #include "../io/io_private.h"
 
-int main(int argc, char* argv[]) {
-    char *flags[] = {"<", ">", ">>", "+<", "+>", "", ";-)", "<<<<<<<<<", "+", "<-:"};
-    INTVAL expected[] = {PIO_F_READ, (PIO_F_WRITE | PIO_F_TRUNC), (PIO_F_WRITE | PIO_F_APPEND), (PIO_F_WRITE | PIO_F_READ), (PIO_F_WRITE | PIO_F_READ | PIO_F_TRUNC), 0, 0, 0, 0, 0};
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	 opcode_t *cur_op, opcode_t *start)
+{
+    char *flags[] = {"<", ">", ">>", "+<", "+>", 
+		     "", ";-)", "<<<<<<<<<", "+", "<-:"};
+    INTVAL expected[] = {PIO_F_READ,
+			 (PIO_F_WRITE | PIO_F_TRUNC),
+			 (PIO_F_WRITE | PIO_F_APPEND),
+			 (PIO_F_WRITE | PIO_F_READ),
+			 (PIO_F_WRITE | PIO_F_READ | PIO_F_TRUNC),
+			 0, 0, 0, 0, 0};
     INTVAL got;
     int i;
 
-	for (i = 0; i < 10; i++)
-	{
-		got = PIO_parse_open_flags(flags[i]);
-
-		if ( got != expected[i] )
-		{
-			printf("\"%s\" should have parsed to %i not %i\n",
-				flags[i], expected[i], got);
-		}
+    for (i = 0; i < 10; i++) {
+	got = PIO_parse_open_flags(flags[i]);
+	
+	if ( got != expected[i] ) {
+	    PIO_printf(interpreter,
+		       "\"%s\" should have parsed to %i not %i\n",
+		       flags[i], expected[i], got);
 	}
+    }
 
-    printf("done\n");
+    PIO_printf(interpreter, "done\n");
 
-    return 0;
+    return NULL;
 }
 CODE
 done
@@ -240,12 +231,11 @@
 
 setup();
 
-c_output_is(<<'CODE', <<'OUTPUT', "PIO_open");
-#include <stdio.h>
-#include "parrot/parrot.h"
-#include "parrot/embed.h"
-
-int main(int argc, char* argv[]) {
+c_output_is($main . <<'CODE', <<'OUTPUT', "PIO_open");
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	 opcode_t *cur_op, opcode_t *start)
+{
     char *file[] = {"", "temp.file", "does_not_exist"};
     char *flags[] = {"<", ">", ">>", "+<", "+>", "", ";-)"};
     int expected[][7] = {
@@ -253,33 +243,24 @@
     	{1, 1, 1, 1, 1, 0, 0},
     	{0, 1, 1, 1, 1, 0, 0},
     };
-    Interp* interpreter;
     PMC *io;
     int i, j;
 
-    interpreter = Parrot_new(NULL);
-
-    if ( interpreter == NULL ) return 1;
-
-    Parrot_init(interpreter);
-
-	for (i = 0; i < 3; i++)
-	{
-		for (j = 0; j < 7; j++)
-		{
-			io = PIO_open(interpreter, NULL, file[i], flags[j]);
-
-			if ( (PIO_eof(interpreter, io) ? 0:1) != expected[i][j] )
-			{
-				printf("\"%s\" \"%s\" should%s have opened\n",
-					file[i], flags[j], expected[i][j] ? "" : " not");
-			}
-		}
+    for (i = 0; i < 3; i++) {
+	for (j = 0; j < 7; j++) {
+	    io = PIO_open(interpreter, NULL, file[i], flags[j]);
+	    
+	    if ( (PIO_eof(interpreter, io) ? 0:1) != expected[i][j] ) {
+		PIO_printf(interpreter, 
+			   "\"%s\" \"%s\" should%s have opened\n",
+			   file[i], flags[j], expected[i][j] ? "" : " not");
+	    }
 	}
+    }
+    
+    PIO_printf(interpreter, "done\n");
 
-    printf("done\n");
-
-    return 0;
+    return NULL;
 }
 CODE
 done
@@ -291,34 +272,25 @@
 
 setup("temp.file", "This is a test.");
 
-c_output_is(<<'CODE', <<'OUTPUT', "PIO_read");
-#include <stdio.h>
-#include "parrot/parrot.h"
-#include "parrot/embed.h"
-
-int main(int argc, char* argv[]) {
+c_output_is($main . <<'CODE', <<'OUTPUT', "PIO_read");
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	 opcode_t *cur_op, opcode_t *start)
+{
     int len[] = {0, 9, 5, 100};
     char *str[] = {"", "This is a", " test", "."};
     int i, n;
-    Interp* interpreter;
     PMC *io;
     char *buffer;
 
-    interpreter = Parrot_new(NULL);
-
-    if ( interpreter == NULL ) return 1;
-
-    Parrot_init(interpreter);
-
-	io = PIO_open(interpreter, NULL, "temp.file", "<");
+    io = PIO_open(interpreter, NULL, "temp.file", "<");
 
-	if ( PIO_eof(interpreter, io) )
-	{
-		printf("PIO_open failed\n");
-		return 1;
-	}
+    if ( PIO_eof(interpreter, io) ) {
+	PIO_printf(interpreter, "PIO_open failed\n");
+	return NULL;
+    }
 
-    for (i = 0; i < 4; i++)	{
+    for (i = 0; i < 4; i++) {
         /* alloc enough space including '\0' */
         buffer = malloc((len[i] + 1) * sizeof(char));
 
@@ -326,20 +298,22 @@
         buffer[n] = '\0';
 
         if ( n != strlen(str[i]) ) {
-            printf("read: %i expected: %i\n", n, strlen(str[i]));
+            PIO_printf(interpreter, 
+		       "read: %i expected: %i\n", n, strlen(str[i]));
         }
 
         if ( strcmp(buffer, str[i]) ) {
-            printf("should have read \"%s\" not \"%s\"", str[i], buffer);
+            PIO_printf(interpreter,
+		       "should have read \"%s\" not \"%s\"", str[i], buffer);
         }
 
         /* buffer no longer needed */
         free(buffer);
     }
 
-    printf("done\n");
+    PIO_printf(interpreter, "done\n");
 
-	return 0;
+    return NULL;
 }
 CODE
 done
@@ -351,36 +325,27 @@
 
 setup("temp.file", ("x" x 65533) . "yz");
 
-c_output_is(<<'CODE', <<'OUTPUT', "PIO_read larger file");
-#include <stdio.h>
-#include "parrot/parrot.h"
-#include "parrot/embed.h"
-
-int main(int argc, char* argv[]) {
-    Interp* interpreter;
+c_output_is($main . <<'CODE', <<'OUTPUT', "PIO_read larger file");
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	 opcode_t *cur_op, opcode_t *start)
+{
     PMC *io;
     char *buffer;
 
-    interpreter = Parrot_new(NULL);
-
-    if ( interpreter == NULL ) return 1;
-
-    Parrot_init(interpreter);
-
-	io = PIO_open(interpreter, NULL, "temp.file", "<");
+    io = PIO_open(interpreter, NULL, "temp.file", "<");
 
-	if ( !io )
-	{
-		printf("PIO_open failed\n");
-		return 1;
-	}
+    if ( !io ) {
+	PIO_printf(interpreter, "PIO_open failed\n");
+	return NULL;
+    }
 
-	buffer = malloc(65536 * sizeof(char));
-	buffer[65535] = '\0';
-	printf("%i\n", PIO_read(interpreter, io, buffer, 65535));
-	printf("%s\n", &buffer[65532]);
+    buffer = malloc(65536 * sizeof(char));
+    buffer[65535] = '\0';
+    printf("%i\n", PIO_read(interpreter, io, buffer, 65535));
+    printf("%s\n", &buffer[65532]);
 
-    return 0;
+    return NULL;
 }
 CODE
 65535
@@ -391,68 +356,51 @@
 
 ###############################################################################
 
-c_output_is(<<'CODE', <<'OUTPUT', "PIO_write");
-#include <stdio.h>
-#include "parrot/parrot.h"
-#include "parrot/embed.h"
-
-int main(int argc, char* argv[]) {
-    Interp* interpreter;
+c_output_is($main . <<'CODE', <<'OUTPUT', "PIO_write");
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	 opcode_t *cur_op, opcode_t *start)
+{
     PMC *io;
 
-    interpreter = Parrot_new(NULL);
-
-    if ( interpreter == NULL ) return 1;
-
-    Parrot_init(interpreter);
-
-	io = PIO_open(interpreter, NULL, "temp.file", ">");
+    io = PIO_open(interpreter, NULL, "temp.file", ">");
 
-	if ( !io )
-	{
-		printf("PIO_open failed\n");
-		return 1;
-	}
+    if ( !io ) {
+	PIO_printf(interpreter, "PIO_open failed\n");
+	return NULL;
+    }
 
-    printf("%i\n", PIO_write(interpreter, io, "This is a test\n", 15));
+    PIO_printf(interpreter, 
+	       "%i\n", PIO_write(interpreter, io, "This is a test\n", 15));
 
-    return 0;
+    return NULL;
 }
 CODE
 15
 OUTPUT
 
 ###############################################################################
-# PIO_unix_close and PIO_win32_close return 0.
+# PIO_unix_close and PIO_win32_close return NULL.
 
 setup();
 
-c_output_is(<<'CODE', <<'OUTPUT', "PIO_close");
-#include <stdio.h>
-#include "parrot/parrot.h"
-#include "parrot/embed.h"
-
-int main(int argc, char* argv[]) {
-    Interp* interpreter;
+c_output_is($main . <<'CODE', <<'OUTPUT', "PIO_close");
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	 opcode_t *cur_op, opcode_t *start)
+{
     PMC *io;
 
-    interpreter = Parrot_new(NULL);
-
-    if ( interpreter == NULL ) return 1;
-
-    Parrot_init(interpreter);
-
-	io = PIO_open(interpreter, NULL, "temp.file", "<");
+    io = PIO_open(interpreter, NULL, "temp.file", "<");
 
-	if ( !io )
-	{
-		printf("PIO_open failed\n");
-		return 1;
-	}
+    if ( !io ) {
+	PIO_printf(interpreter, "PIO_open failed\n");
+	return NULL;
+    }
 
-	printf("%i\n", PIO_close(interpreter, io));
+    PIO_printf(interpreter, "%i\n", PIO_close(interpreter, io));
 
-    return 0;
+    return NULL;
 }
 CODE
 0
@@ -462,31 +410,29 @@
 
 ###############################################################################
 
-c_output_is(<<'CODE', <<'OUTPUT', "PIO_make_offset");
-#include <stdio.h>
-#include "parrot/parrot.h"
-#include "parrot/embed.h"
-
-int main(int argc, char* argv[]) {
+c_output_is($main . <<'CODE', <<'OUTPUT', "PIO_make_offset");
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	 opcode_t *cur_op, opcode_t *start)
+{
     INTVAL intval[] = {0, 1, -1, 100, -100};
     PIOOFF_T expected[] = {0, 1, -1, 100, -100};
     PIOOFF_T offset;
     int i;
 
-	for (i = 0; i < 5; i++)
-	{
+    for (i = 0; i < 5; i++) {
         offset = PIO_make_offset(intval[i]);
 
-	    if ( offset != expected[i] )
-        {
-            printf("offset for %i should have been %i not %i\n",
-                intval[i], (int)expected[i], (int)offset);
+	if ( offset != expected[i] ) {
+            PIO_printf(interpreter,
+		       "offset for %i should have been %i not %i\n",
+		       intval[i], (int)expected[i], (int)offset);
         }
     }
 
-    printf("done\n");
+    PIO_printf(interpreter, "done\n");
 
-    return 0;
+    return NULL;
 }
 CODE
 done
@@ -496,37 +442,29 @@
 
 setup("temp.file", "abcdefg");
 
-c_output_is(<<'CODE', <<'OUTPUT', "PIO_seek");
-#include <stdio.h>
-#include "parrot/parrot.h"
-#include "parrot/embed.h"
+c_output_is($main . <<'CODE', <<'OUTPUT', "PIO_seek");
 #include "../io/io_private.h"
 
-int main(int argc, char* argv[]) {
-	INTVAL fixture[][3] = {
-		{1, SEEK_SET},
-		{2, SEEK_CUR},
-		{-2, SEEK_CUR},
-		{-3, SEEK_END}
-	};
-    Interp* interpreter;
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	 opcode_t *cur_op, opcode_t *start)
+{
+    INTVAL fixture[][3] = {
+	{1, SEEK_SET},
+	{2, SEEK_CUR},
+	{-2, SEEK_CUR},
+	{-3, SEEK_END}
+    };
     PMC *io;
     char *buffer;
     int i;
     int got;
 
-    interpreter = Parrot_new(NULL);
-
-    if ( interpreter == NULL ) return 1;
-
-    Parrot_init(interpreter);
-
     io = PIO_open(interpreter, NULL, "temp.file", "<");
 
-    if ( !io )
-    {
-        printf("PIO_open failed\n");
-        return 1;
+    if ( !io ) {
+        PIO_printf(interpreter, "PIO_open failed\n");
+        return NULL;
     }
 
     for (i = 0; i < 4; i++) {
@@ -537,17 +475,18 @@
             buffer = malloc(2 * sizeof(char));
             buffer[1] = '\0';
             PIO_read(interpreter, io, buffer, 1);
-            printf("%s", buffer);
+            PIO_printf(interpreter, "%s", buffer);
             free(buffer);
         }
         else {
-            printf("seek %i %i failed\n", fixture[i][0], fixture[i][1]);
+            PIO_printf(interpreter, 
+		       "seek %i %i failed\n", fixture[i][0], fixture[i][1]);
         }
     }
 
-    printf("\ndone\n");
+    PIO_printf(interpreter, "\ndone\n");
 
-    return 0;
+    return NULL;
 }
 CODE
 bede
@@ -560,26 +499,18 @@
 
 SKIP: {
     skip ("fdopen does not handle illegal modes correct", 1);
-c_output_is(<<'CODE', <<'OUTPUT', "PIO_fdopen");
-#include <stdio.h>
-#include "parrot/parrot.h"
-#include "parrot/embed.h"
-
-int main(int argc, char* argv[]) {
+c_output_is($main . <<'CODE', <<'OUTPUT', "PIO_fdopen");
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	 opcode_t *cur_op, opcode_t *start)
+{
     char *flags[] = {"<", ">", ">>", "+<", "+>", "", ";-)"};
     int expected[] = {1, 1, 1, 1, 1, 0, 0};
     int i;
-    Interp* interpreter;
     PMC *iostdout;
     PIOHANDLE fd;
     PMC *io;
 
-    interpreter = Parrot_new(NULL);
-
-    if ( interpreter == NULL ) return 1;
-
-    Parrot_init(interpreter);
-
     for (i = 0; i < 7; i++)
     {
         iostdout = PIO_STDOUT(interpreter);
@@ -588,14 +519,15 @@
 
         if ( ( io != NULL ) != expected[i] )
         {
-            printf("stdout should%s have opened with \"%s\" flags\n",
-                expected[i] ? "" : " not", flags[i]);
+            PIO_printf(interpreter, 
+		       "stdout should%s have opened with \"%s\" flags\n",
+		       expected[i] ? "" : " not", flags[i]);
         }
-	}
+    }
 
-    printf("done\n");
+    PIO_printf(interpreter, "done\n");
 
-    return 0;
+    return NULL;
 }
 CODE
 done
@@ -604,27 +536,20 @@
 
 ###############################################################################
 
-c_output_is(<<'CODE', <<'OUTPUT', 'stdio-layer');
-#include "parrot/parrot.h"
-
-extern ParrotIOLayer pio_stdio_layer;
-
-int main()
+c_output_is($main . <<'CODE', <<'OUTPUT', 'stdio-layer');
+static opcode_t*
+the_test(struct Parrot_Interp *interpreter,
+	 opcode_t *cur_op, opcode_t *start)
 {
-    Interp *interpreter;
-    PMC *io;
-
-    interpreter = Parrot_new(NULL);
-
-    if ( interpreter == NULL ) return 1;
+    extern ParrotIOLayer pio_stdio_layer;
 
-    Parrot_init(interpreter);
+    PMC *io;
 
     io = PIO_fdopen(interpreter, &pio_stdio_layer, (PIOHANDLE)stdout, ">");
     PIO_puts(interpreter, io, "Hello, World\n");
     PIO_flush(interpreter, io);
 
-    return 0;
+    return NULL;
 }
 CODE
 Hello, World

Reply via email to