Skip to content

Commit

Permalink
Add Parrot_printf and Parrot_eprintf to the extend API
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/trunk@29171 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
NotFound committed Jul 8, 2008
1 parent 70ff4f1 commit 87909b3
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 7 deletions.
26 changes: 26 additions & 0 deletions include/parrot/extend.h
Expand Up @@ -116,10 +116,23 @@ Parrot_Int Parrot_call_sub_ret_int(PARROT_INTERP,
__attribute__nonnull__(1)
__attribute__nonnull__(3);

PARROT_API
int Parrot_eprintf(NULLOK_INTERP, ARGIN(const char *s), ...)
__attribute__nonnull__(2);

PARROT_API
PARROT_WARN_UNUSED_RESULT
Parrot_Language Parrot_find_language(SHIM_INTERP, SHIM(char *language));

PARROT_API
int Parrot_fprintf(PARROT_INTERP,
ARGIN(Parrot_PMC pio),
ARGIN(const char *s),
...)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);

PARROT_API
void Parrot_free_cstring(ARGIN_NULLOK(char *string));

Expand Down Expand Up @@ -359,6 +372,10 @@ Parrot_Int Parrot_PMC_typenum(PARROT_INTERP,
ARGIN_NULLOK(const char *_class))
__attribute__nonnull__(1);

PARROT_API
int Parrot_printf(NULLOK_INTERP, ARGIN(const char *s), ...)
__attribute__nonnull__(2);

PARROT_API
void Parrot_register_pmc(PARROT_INTERP, Parrot_PMC pmc)
__attribute__nonnull__(1);
Expand All @@ -385,6 +402,15 @@ PARROT_API
void Parrot_unregister_pmc(PARROT_INTERP, Parrot_PMC pmc)
__attribute__nonnull__(1);

PARROT_API
int Parrot_vfprintf(PARROT_INTERP,
ARGIN(Parrot_PMC pio),
ARGIN(const char *s),
va_list args)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);

/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/extend.c */

Expand Down
97 changes: 97 additions & 0 deletions src/extend.c
Expand Up @@ -65,6 +65,103 @@ can.

/*
=item C<int Parrot_vfprintf>
Writes a C string format with a varargs list to a PIO.
=item C<int Parrot_fprintf>
Writes a C string format with varargs to a PIO.
=item C<int Parrot_printf>
Writes a C string format with varargs to C<stdout>.
=item C<int Parrot_eprintf>
Writes a C string format with varargs to C<stderr>.
*/

PARROT_API
int
Parrot_vfprintf(PARROT_INTERP, ARGIN(Parrot_PMC pio),
ARGIN(const char *s), va_list args)
{
STRING * str;
INTVAL retval;

PARROT_CALLIN_START(interp);
str = Parrot_vsprintf_c(interp, s, args);
retval = PIO_putps(interp, pio, str);
PARROT_CALLIN_END(interp);

return retval;
}

PARROT_API
int
Parrot_fprintf(PARROT_INTERP, ARGIN(Parrot_PMC pio),
ARGIN(const char *s), ...)
{
va_list args;
INTVAL retval;

va_start(args, s);
retval = Parrot_vfprintf(interp, pio, s, args);
va_end(args);

return retval;
}

PARROT_API
int
Parrot_printf(NULLOK_INTERP, ARGIN(const char *s), ...)
{
va_list args;
INTVAL retval;
va_start(args, s);

if (interp) {
retval = Parrot_vfprintf(interp, PIO_STDOUT(interp), s, args);
}
else {
/* Be nice about this...
** XXX BD Should this use the default PIO_STDOUT or something?
*/
retval = vfprintf(stdout, s, args);
}
va_end(args);

return retval;
}

PARROT_API
int
Parrot_eprintf(NULLOK_INTERP, ARGIN(const char *s), ...)
{
va_list args;
INTVAL retval;

va_start(args, s);

if (interp) {
retval = Parrot_vfprintf(interp, PIO_STDERR(interp), s, args);
}
else {
/* Be nice about this...
** XXX BD Should this use the default PIO_STDOUT or something?
*/
retval=vfprintf(stderr, s, args);
}

va_end(args);

return retval;
}

/*
=item C<Parrot_String Parrot_PMC_get_string_intkey>
Return the integer keyed string value of the passed-in PMC
Expand Down
14 changes: 7 additions & 7 deletions t/src/extend.t
Expand Up @@ -102,7 +102,7 @@ main(int argc, char* argv[]) {
return 1;
output = Parrot_new_string(interp, "Test", 4, "iso-8859-1", 0);
PIO_eprintf(interp, "%S\n", output);
Parrot_eprintf(interp, "%S\n", output);
Parrot_exit(interp, 0);
return 0;
Expand Down Expand Up @@ -132,7 +132,7 @@ main(int argc, char* argv[]) {
Parrot_set_strreg(interp, parrot_reg, value);
new_value = Parrot_get_strreg(interp, parrot_reg);
PIO_eprintf(interp, "%S\n", new_value);
Parrot_eprintf(interp, "%S\n", new_value);
Parrot_exit(interp, 0);
return 0;
Expand Down Expand Up @@ -309,7 +309,7 @@ main(int argc, char* argv[]) {
Parrot_PMC_set_string(interp, testpmc, value);
new_value = Parrot_PMC_get_string(interp, testpmc);
PIO_eprintf(interp, "%S\n", new_value);
Parrot_eprintf(interp, "%S\n", new_value);
Parrot_exit(interp, 0);
return 0;
Expand Down Expand Up @@ -444,7 +444,7 @@ the_test(Parrot_Interp interp, opcode_t *cur_op, opcode_t *start)
Parrot_loadbc(interp, pf);
sub = Parrot_find_global_cur(interp, name);
Parrot_call_sub(interp, sub, "v");
PIO_eprintf(interp, "back\n");
Parrot_eprintf(interp, "back\n");
/* win32 seems to buffer stderr ? */
PIO_flush(interp, PIO_STDERR(interp));
Expand All @@ -457,7 +457,7 @@ the_test(Parrot_Interp interp, opcode_t *cur_op, opcode_t *start)
string_from_cstring(interp, "hello ", 0));
Parrot_call_sub(interp, sub, "vP", arg);
PIO_eprintf(interp, "back\n");
Parrot_eprintf(interp, "back\n");
return NULL;
}
Expand Down Expand Up @@ -520,7 +520,7 @@ the_test(Parrot_Interp interp, opcode_t *cur_op, opcode_t *start)
sub = Parrot_find_global_cur(interp, name);
if (setjmp(jb.destination)) {
PIO_eprintf(interp, "caught\n");
Parrot_eprintf(interp, "caught\n");
}
else {
/* pretend the EH was pushed by the sub call. */
Expand All @@ -530,7 +530,7 @@ the_test(Parrot_Interp interp, opcode_t *cur_op, opcode_t *start)
Parrot_call_sub(interp, sub, "v");
}
PIO_eprintf(interp, "back\n");
Parrot_eprintf(interp, "back\n");
return NULL;
}
Expand Down

0 comments on commit 87909b3

Please sign in to comment.