fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / src / warnings.c
blob82f8fe60a6b2fea1aa7b53cababcf079aae9c4f8
1 /*
2 Copyright (C) 2001-2010, Parrot Foundation.
3 $Id$
5 =head1 NAME
7 src/warnings.c - Warning and error reporting
9 =head1 DESCRIPTION
11 Parrot C<STRING> and C string versions of a function to print warning/error
12 messages.
14 =over 4
16 =cut
20 #include "parrot/parrot.h"
22 #include <stdarg.h>
24 /* HEADERIZER HFILE: include/parrot/warnings.h */
26 /* HEADERIZER BEGIN: static */
27 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
29 static INTVAL print_warning(PARROT_INTERP, ARGIN_NULLOK(STRING *msg))
30 __attribute__nonnull__(1);
32 #define ASSERT_ARGS_print_warning __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
33 PARROT_ASSERT_ARG(interp))
34 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
35 /* HEADERIZER END: static */
39 =item C<void print_pbc_location(PARROT_INTERP)>
41 Prints the bytecode location of the warning or error to C<Parrot_io_STDERR>.
43 =cut
47 PARROT_EXPORT
48 void
49 print_pbc_location(PARROT_INTERP)
51 ASSERT_ARGS(print_pbc_location)
52 Interp * const tracer = (interp->pdb && interp->pdb->debugger) ?
53 interp->pdb->debugger :
54 interp;
55 Parrot_io_eprintf(tracer, "%Ss\n",
56 Parrot_Context_infostr(interp, CURRENT_CONTEXT(interp)));
61 =item C<static INTVAL print_warning(PARROT_INTERP, STRING *msg)>
63 Prints the warning message and the bytecode location.
65 =cut
69 static INTVAL
70 print_warning(PARROT_INTERP, ARGIN_NULLOK(STRING *msg))
72 ASSERT_ARGS(print_warning)
73 if (!msg)
74 Parrot_io_puts(interp, Parrot_io_STDERR(interp), "Unknown warning\n");
75 else {
76 Parrot_io_putps(interp, Parrot_io_STDERR(interp), msg);
77 if (string_ord(interp, msg, -1) != '\n')
78 Parrot_io_eprintf(interp, "%c", '\n');
80 print_pbc_location(interp);
81 return 1;
86 =back
88 =head2 Parrot Warnings Interface
90 =over 4
92 =item C<INTVAL Parrot_warn(PARROT_INTERP, INTVAL warnclass, const char *message,
93 ...)>
95 The Parrot C string warning/error reporter.
97 Returns 2 on error, 1 on success.
99 C<message, ..> can be a C<Parrot_vsprintf_c()> format with arguments.
101 =cut
105 PARROT_EXPORT
106 PARROT_IGNORABLE_RESULT
107 INTVAL
108 Parrot_warn(PARROT_INTERP, INTVAL warnclass,
109 ARGIN(const char *message), ...)
111 ASSERT_ARGS(Parrot_warn)
112 if (!PARROT_WARNINGS_test(interp, warnclass))
113 return 2;
114 else {
115 STRING *targ;
116 va_list args;
118 va_start(args, message);
119 targ = Parrot_vsprintf_c(interp, message, args);
120 va_end(args);
121 return print_warning(interp, targ);
127 =item C<void Parrot_warn_deprecated(PARROT_INTERP, const char *message)>
129 Warn about use of a deprecated feature
131 C<message> is a C string.
133 =cut
137 PARROT_EXPORT
138 void
139 Parrot_warn_deprecated(PARROT_INTERP, ARGIN(const char *message))
141 ASSERT_ARGS(Parrot_warn_deprecated)
143 if (PARROT_WARNINGS_test(interp, PARROT_WARNINGS_DEPRECATED_FLAG)) {
144 STRING *msg = Parrot_sprintf_c(interp, "WARNING: %s\n", message);
145 print_warning(interp, msg);
151 =back
153 =head1 SEE ALSO
155 F<include/parrot/warnings.h>.
157 =cut
163 * Local variables:
164 * c-file-style: "parrot"
165 * End:
166 * vim: expandtab shiftwidth=4: