Skip to content

Commit

Permalink
Fix headerizer declarations so the public sprintf-related functions a…
Browse files Browse the repository at this point in the history
…re declared in string_funcs.h instead of misc.h. Change the sprintf engine to use a StringBuilder instead of repeated (wasteful) string concats.
  • Loading branch information
Whiteknight committed May 20, 2012
1 parent 49f6a6e commit 0783a03
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 181 deletions.
147 changes: 0 additions & 147 deletions include/parrot/misc.h
Expand Up @@ -125,153 +125,6 @@ void Parrot_util_quicksort(PARROT_INTERP,
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/utils.c */


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

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

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

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

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
STRING * Parrot_psprintf(PARROT_INTERP,
ARGIN(STRING *pat),
ARGOUT(PMC *ary))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*ary);

PARROT_EXPORT
PARROT_IGNORABLE_RESULT
int /*@alt void@*/
Parrot_secret_snprintf(
ARGOUT(char *buffer),
size_t len,
ARGIN(const char *format),
...)
__attribute__nonnull__(1)
__attribute__nonnull__(3)
FUNC_MODIFIES(*buffer);

PARROT_EXPORT
void Parrot_snprintf(PARROT_INTERP,
ARGOUT(char *targ),
size_t len,
ARGIN(const char *pat),
...)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(4)
FUNC_MODIFIES(*targ);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
STRING * Parrot_sprintf_c(PARROT_INTERP, ARGIN(const char *pat), ...)
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
STRING * Parrot_sprintf_s(PARROT_INTERP, ARGIN(STRING *pat), ...)
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_EXPORT
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);

PARROT_EXPORT
void Parrot_vsnprintf(PARROT_INTERP,
ARGMOD(char *targ),
size_t len,
ARGIN(const char *pat),
va_list args)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(4)
FUNC_MODIFIES(*targ);

PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
STRING * Parrot_vsprintf_c(PARROT_INTERP,
ARGIN(const char *pat),
va_list args)
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
STRING * Parrot_vsprintf_s(PARROT_INTERP, ARGIN(STRING *pat), va_list args)
__attribute__nonnull__(1)
__attribute__nonnull__(2);

#define ASSERT_ARGS_Parrot_eprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_Parrot_fprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pio) \
, PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_Parrot_printf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_Parrot_psprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pat) \
, PARROT_ASSERT_ARG(ary))
#define ASSERT_ARGS_Parrot_secret_snprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(buffer) \
, PARROT_ASSERT_ARG(format))
#define ASSERT_ARGS_Parrot_snprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(targ) \
, PARROT_ASSERT_ARG(pat))
#define ASSERT_ARGS_Parrot_sprintf_c __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pat))
#define ASSERT_ARGS_Parrot_sprintf_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pat))
#define ASSERT_ARGS_Parrot_vfprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pio) \
, PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_Parrot_vsnprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(targ) \
, PARROT_ASSERT_ARG(pat))
#define ASSERT_ARGS_Parrot_vsprintf_c __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pat))
#define ASSERT_ARGS_Parrot_vsprintf_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pat))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/misc.c */

#endif /* PARROT_MISC_H_GUARD */

/*
Expand Down
146 changes: 146 additions & 0 deletions include/parrot/string_funcs.h
Expand Up @@ -678,6 +678,152 @@ STRING * Parrot_str_new_from_cstring(PARROT_INTERP,
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/string/api.c */

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

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

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

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

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
STRING * Parrot_psprintf(PARROT_INTERP,
ARGIN(STRING *pat),
ARGOUT(PMC *ary))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*ary);

PARROT_EXPORT
PARROT_IGNORABLE_RESULT
int /*@alt void@*/
Parrot_secret_snprintf(
ARGOUT(char *buffer),
size_t len,
ARGIN(const char *format),
...)
__attribute__nonnull__(1)
__attribute__nonnull__(3)
FUNC_MODIFIES(*buffer);

PARROT_EXPORT
void Parrot_snprintf(PARROT_INTERP,
ARGOUT(char *targ),
size_t len,
ARGIN(const char *pat),
...)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(4)
FUNC_MODIFIES(*targ);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
STRING * Parrot_sprintf_c(PARROT_INTERP, ARGIN(const char *pat), ...)
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
STRING * Parrot_sprintf_s(PARROT_INTERP, ARGIN(STRING *pat), ...)
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_EXPORT
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);

PARROT_EXPORT
void Parrot_vsnprintf(PARROT_INTERP,
ARGMOD(char *targ),
size_t len,
ARGIN(const char *pat),
va_list args)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(4)
FUNC_MODIFIES(*targ);

PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
STRING * Parrot_vsprintf_c(PARROT_INTERP,
ARGIN(const char *pat),
va_list args)
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
STRING * Parrot_vsprintf_s(PARROT_INTERP, ARGIN(STRING *pat), va_list args)
__attribute__nonnull__(1)
__attribute__nonnull__(2);

#define ASSERT_ARGS_Parrot_eprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_Parrot_fprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pio) \
, PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_Parrot_printf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_Parrot_psprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pat) \
, PARROT_ASSERT_ARG(ary))
#define ASSERT_ARGS_Parrot_secret_snprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(buffer) \
, PARROT_ASSERT_ARG(format))
#define ASSERT_ARGS_Parrot_snprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(targ) \
, PARROT_ASSERT_ARG(pat))
#define ASSERT_ARGS_Parrot_sprintf_c __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pat))
#define ASSERT_ARGS_Parrot_sprintf_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pat))
#define ASSERT_ARGS_Parrot_vfprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pio) \
, PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_Parrot_vsnprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(targ) \
, PARROT_ASSERT_ARG(pat))
#define ASSERT_ARGS_Parrot_vsprintf_c __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pat))
#define ASSERT_ARGS_Parrot_vsprintf_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pat))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/string/sprintf.c */

#endif /* PARROT_IN_CORE */
#endif /* PARROT_STRING_FUNCS_H_GUARD */

Expand Down
4 changes: 2 additions & 2 deletions src/string/spf_private.h
Expand Up @@ -72,7 +72,7 @@ struct sprintf_obj {
extern SPRINTF_OBJ pmc_core;
extern const SPRINTF_OBJ va_core;

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

PARROT_WARN_UNUSED_RESULT
Expand All @@ -90,6 +90,6 @@ STRING * Parrot_sprintf_format(PARROT_INTERP,
, PARROT_ASSERT_ARG(pat) \
, PARROT_ASSERT_ARG(obj))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/spf_render.c */
/* HEADERIZER END: src/string/spf_render.c */

#endif /* PARROT_STRING_PRIVATE_H */

0 comments on commit 0783a03

Please sign in to comment.