# New Ticket Created by NotFound # Please include the string: [perl #56440] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=56440 >
This patch adds the functions Parrot_vfprintf, Parrot_fprintf, Parrot_printf and Parrot_eprintf functions to extend.c The rationale is to have functions not dependant of io.h being included and usable from extensions and embedders without restrictions. -- Salu2
Index: src/extend.c =================================================================== --- src/extend.c (revisión: 28791) +++ src/extend.c (copia de trabajo) @@ -65,6 +65,103 @@ /* +=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 Index: include/parrot/extend.h =================================================================== --- include/parrot/extend.h (revisión: 28791) +++ include/parrot/extend.h (copia de trabajo) @@ -117,10 +117,23 @@ __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)); PARROT_API @@ -360,6 +373,10 @@ __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); @@ -385,6 +402,15 @@ 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 */ Index: t/src/extend.t =================================================================== --- t/src/extend.t (revisión: 28791) +++ t/src/extend.t (copia de trabajo) @@ -102,7 +102,7 @@ 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; @@ -132,7 +132,7 @@ 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; @@ -309,7 +309,7 @@ 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; @@ -444,7 +444,7 @@ 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)); @@ -457,7 +457,7 @@ 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; } @@ -520,7 +520,7 @@ 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. */ @@ -530,7 +530,7 @@ Parrot_call_sub(interp, sub, "v"); } - PIO_eprintf(interp, "back\n"); + Parrot_eprintf(interp, "back\n"); return NULL; }