2 Copyright (C) 2001-2009, Parrot Foundation.
7 src/warnings.c - Warning and error reporting
11 Parrot C<STRING> and C string versions of a function to print warning/error
20 #include "parrot/parrot.h"
22 #include "pmc/pmc_context.h"
26 /* HEADERIZER HFILE: include/parrot/warnings.h */
28 /* HEADERIZER BEGIN: static */
29 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
31 static INTVAL
print_warning(PARROT_INTERP
, ARGIN_NULLOK(STRING
*msg
))
32 __attribute__nonnull__(1);
34 #define ASSERT_ARGS_print_warning __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
35 PARROT_ASSERT_ARG(interp))
36 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
37 /* HEADERIZER END: static */
41 =item C<void print_pbc_location(PARROT_INTERP)>
43 Prints the bytecode location of the warning or error to C<Parrot_io_STDERR>.
51 print_pbc_location(PARROT_INTERP
)
53 ASSERT_ARGS(print_pbc_location
)
54 Interp
* const tracer
= (interp
->pdb
&& interp
->pdb
->debugger
) ?
55 interp
->pdb
->debugger
:
57 Parrot_io_eprintf(tracer
, "%Ss\n",
58 Parrot_Context_infostr(interp
, CURRENT_CONTEXT(interp
)));
63 =item C<static INTVAL print_warning(PARROT_INTERP, STRING *msg)>
65 Prints the warning message and the bytecode location.
72 print_warning(PARROT_INTERP
, ARGIN_NULLOK(STRING
*msg
))
74 ASSERT_ARGS(print_warning
)
76 Parrot_io_puts(interp
, Parrot_io_STDERR(interp
), "Unknown warning\n");
78 Parrot_io_putps(interp
, Parrot_io_STDERR(interp
), msg
);
79 if (string_ord(interp
, msg
, -1) != '\n')
80 Parrot_io_eprintf(interp
, "%c", '\n');
82 print_pbc_location(interp
);
90 =head2 Parrot Warnings Interface
94 =item C<INTVAL Parrot_warn(PARROT_INTERP, INTVAL warnclass, const char *message,
97 The Parrot C string warning/error reporter.
99 Returns 2 on error, 1 on success.
101 C<message, ..> can be a C<Parrot_vsprintf_c()> format with arguments.
108 PARROT_IGNORABLE_RESULT
110 Parrot_warn(PARROT_INTERP
, INTVAL warnclass
,
111 ARGIN(const char *message
), ...)
113 ASSERT_ARGS(Parrot_warn
)
114 if (!PARROT_WARNINGS_test(interp
, warnclass
))
120 va_start(args
, message
);
121 targ
= Parrot_vsprintf_c(interp
, message
, args
);
123 return print_warning(interp
, targ
);
133 F<include/parrot/warnings.h>.
142 * c-file-style: "parrot"
144 * vim: expandtab shiftwidth=4: