Author: petdance
Date: Sat Jun 9 23:49:30 2007
New Revision: 18905
Modified:
trunk/config/gen/makefiles/root.in
trunk/include/parrot/exceptions.h
trunk/include/parrot/pmc.h
trunk/src/exceptions.c
trunk/src/pmc/resizablepmcarray.pmc
Log:
exceptions.c is now headerized. Added some consting and NNing in a coupleof
other files, too.
Modified: trunk/config/gen/makefiles/root.in
==============================================================================
--- trunk/config/gen/makefiles/root.in (original)
+++ trunk/config/gen/makefiles/root.in Sat Jun 9 23:49:30 2007
@@ -1830,6 +1830,7 @@
HEADERIZER_O_FILES = \
src/datatypes.o \
src/byteorder.o \
+ src/exceptions.o \
src/gc/dod.o \
src/gc/memory.o \
src/gc/register.o \
Modified: trunk/include/parrot/exceptions.h
==============================================================================
--- trunk/include/parrot/exceptions.h (original)
+++ trunk/include/parrot/exceptions.h Sat Jun 9 23:49:30 2007
@@ -17,23 +17,6 @@
#include "parrot/compiler.h"
/* Prototypes */
-void Parrot_init_exceptions(Interp *interp);
-
-PARROT_API void internal_exception(int exitcode, const char *format, ...)
- __attribute__nonnull__(2)
- __attribute__noreturn__;
-PARROT_API void real_exception(Interp *interp,
- void *ret_addr, int exitcode, const char *format, ...)
- __attribute__nonnull__(4)
- __attribute__noreturn__;
-PARROT_API void do_panic(Interp *interp, const char *message,
- const char *file, int line)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3)
- __attribute__noreturn__;
-
-#define PANIC(message)\
- do_panic(interp, message, __FILE__, __LINE__)
/* Exception Types
* the first types are real exceptions and have Python exception
@@ -165,40 +148,91 @@
long system; /* what is this? */
} Parrot_exception;
-/*
- * user level exception handling
- */
-PARROT_API void push_exception(Parrot_Interp, PMC *);
-PARROT_API void pop_exception(Parrot_Interp);
-PARROT_API opcode_t * throw_exception(Parrot_Interp, PMC *, void *);
-PARROT_API opcode_t * rethrow_exception(Parrot_Interp, PMC *);
-
-PARROT_API size_t handle_exception(Parrot_Interp);
-
-PARROT_API PMC* new_c_exception_handler(Parrot_Interp, Parrot_exception *jb);
-PARROT_API void push_new_c_exception_handler(Parrot_Interp, Parrot_exception
*jb);
-PARROT_API void rethrow_c_exception(Parrot_Interp interp)
+/* HEADERIZER BEGIN: src/exceptions.c */
+
+PARROT_API void do_exception( Interp *interp /*NN*/,
+ INTVAL severity,
+ long error )
+ __attribute__nonnull__(1)
__attribute__noreturn__;
-/*
- * internal exception handling
- */
-PARROT_API void do_exception(Parrot_Interp, INTVAL severity, long error)
+PARROT_API void free_internal_exception( Interp *interp );
+PARROT_API size_t handle_exception( Interp *interp /*NN*/ )
+ __attribute__nonnull__(1);
+
+PARROT_API void internal_exception(
+ int exitcode,
+ const char *format /*NN*/,
+ ... )
+ __attribute__nonnull__(2)
__attribute__noreturn__;
-PARROT_API void new_internal_exception(Parrot_Interp);
-PARROT_API void free_internal_exception(Parrot_Interp);
-/*
- * control stack marks and action
- */
+PARROT_API PMC* new_c_exception_handler( Interp *interp /*NN*/,
+ Parrot_exception *jb )
+ __attribute__nonnull__(1);
+
+PARROT_API void new_internal_exception( Interp *interp /*NN*/ )
+ __attribute__nonnull__(1);
+
+PARROT_API void Parrot_pop_mark( Interp *interp /*NN*/, INTVAL mark )
+ __attribute__nonnull__(1);
+
+PARROT_API void Parrot_push_action( Interp *interp /*NN*/, PMC *sub )
+ __attribute__nonnull__(1);
+
+PARROT_API void Parrot_push_mark( Interp *interp /*NN*/, INTVAL mark )
+ __attribute__nonnull__(1);
+
+PARROT_API void pop_exception( Interp *interp /*NN*/ )
+ __attribute__nonnull__(1);
+
+PARROT_API void push_exception( Interp *interp /*NN*/, PMC *handler /*NN*/ )
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_API void push_new_c_exception_handler( Interp *interp /*NN*/,
+ Parrot_exception *jb )
+ __attribute__nonnull__(1);
+
+PARROT_API opcode_t * rethrow_exception( Interp *interp /*NN*/,
+ PMC *exception /*NN*/ )
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_API opcode_t * throw_exception( Interp *interp,
+ PMC *exception,
+ void *dest );
+
+void destroy_exception_list( Interp *interp /*NN*/ )
+ __attribute__nonnull__(1);
+
+void do_panic( Interp *interp /*NULLOK*/,
+ const char *message /*NULLOK*/,
+ const char *file /*NULLOK*/,
+ int line )
+ __attribute__noreturn__;
+
+void Parrot_init_exceptions( Interp *interp /*NN*/ )
+ __attribute__nonnull__(1);
+
+void real_exception( Interp *interp /*NN*/,
+ void *ret_addr,
+ int exitcode,
+ const char *format /*NN*/,
+ ... )
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(4);
+
+void really_destroy_exception_list( Parrot_exception *e /*NULLOK*/ );
+void rethrow_c_exception( Interp *interp /*NN*/ )
+ __attribute__nonnull__(1)
+ __attribute__noreturn__;
+
+/* HEADERIZER END: src/exceptions.c */
+
+#define PANIC(message)\
+ do_panic(interp, message, __FILE__, __LINE__)
-PARROT_API void Parrot_push_mark(Interp *, INTVAL mark);
-PARROT_API void Parrot_pop_mark(Interp *, INTVAL mark);
-PARROT_API void Parrot_push_action(Interp *, PMC *sub);
-
-/* global cleanup */
-void destroy_exception_list(Interp *interp);
-void really_destroy_exception_list(Parrot_exception *e);
#endif /* PARROT_EXCEPTIONS_H_GUARD */
Modified: trunk/include/parrot/pmc.h
==============================================================================
--- trunk/include/parrot/pmc.h (original)
+++ trunk/include/parrot/pmc.h Sat Jun 9 23:49:30 2007
@@ -37,9 +37,13 @@
PARROT_API void Parrot_create_pmc_proxy( Interp* interp /*NN*/, int type_num )
__attribute__nonnull__(1);
-PARROT_API PMC * pmc_new( Interp *interp, INTVAL base_type );
+PARROT_API PMC * pmc_new( Interp *interp /*NN*/, INTVAL base_type )
+ __attribute__nonnull__(1);
+
PARROT_API PMC * pmc_new_init( Interp *interp, INTVAL base_type, PMC *init );
-PARROT_API PMC * pmc_new_noinit( Interp *interp, INTVAL base_type );
+PARROT_API PMC * pmc_new_noinit( Interp *interp /*NN*/, INTVAL base_type )
+ __attribute__nonnull__(1);
+
PARROT_API INTVAL pmc_register( Interp* interp /*NN*/, STRING *name )
__attribute__nonnull__(1);
Modified: trunk/src/exceptions.c
==============================================================================
--- trunk/src/exceptions.c (original)
+++ trunk/src/exceptions.c Sat Jun 9 23:49:30 2007
@@ -24,21 +24,18 @@
=head2 Functions
-=over 4
-
-=cut
-
*/
#include "parrot/parrot.h"
#include "parrot/exceptions.h"
+/* HEADER: include/parrot/exceptions.h */
+
#include <stdarg.h>
/*
-=item C<void
-internal_exception(int exitcode, const char *format, ...)>
+FUNCDOC: internal_exception
Signal a fatal exception. This involves printing an error message to stderr,
and calling C<Parrot_exit> to invoke exit handlers and exit the process with
the
@@ -47,12 +44,12 @@
stack unwinding is done, so the exit handlers run in the current dynamic
environment.
-=cut
-
*/
+PARROT_API
void
-internal_exception(int exitcode, const char *format, ...)
+internal_exception(int exitcode, const char *format /*NN*/, ...)
+ /* NORETURN */
{
va_list arglist;
va_start(arglist, format);
@@ -80,19 +77,16 @@
/*
-=item C<void
-do_panic(Interp *interp, const char *message,
- const char *file, int line)>
+FUNCDOC: do_panic
Panic handler.
-=cut
-
*/
void
-do_panic(Interp *interp, const char *message,
- const char *file, int line)
+do_panic(Interp *interp /*NULLOK*/, const char *message /*NULLOK*/,
+ const char *file /*NULLOK*/, int line)
+ /* NORETURN */
{
/* Note: we can't format any floats in here--Parrot_sprintf
** may panic because of floats.
@@ -132,28 +126,27 @@
/*
-=item C<void push_exception(Interp * interp, PMC *handler)>
+FUNCDOC: push_exception
Add the exception handler on the stack.
-=item C<void Parrot_push_action(Interp * interp, PMC *sub)>
+FUNCDOC: Parrot_push_action
Push an action handler onto the dynamic environment.
-=item C<void Parrot_push_mark(Interp * interp, INTVAL mark)>
+FUNCDOC: Parrot_push_mark
Push a cleanup mark onto the dynamic environment.
-=item C<void Parrot_pop_mark(Interp * interp, INTVAL mark)>
+FUNCDOC: Parrot_pop_mark
Pop items off the dynamic environment up to the mark.
-=cut
-
*/
+PARROT_API
void
-push_exception(Interp *interp, PMC *handler)
+push_exception(Interp *interp /*NN*/, PMC *handler /*NN*/)
{
if (handler->vtable->base_type != enum_class_Exception_Handler)
PANIC("Tried to set_eh a non Exception_Handler");
@@ -172,8 +165,9 @@
Parrot_runops_fromc_args(interp, sub, "vI", 0);
}
+PARROT_API
void
-Parrot_push_action(Interp *interp, PMC *sub)
+Parrot_push_action(Interp *interp /*NN*/, PMC *sub)
{
if (!VTABLE_isa(interp, sub,
const_string(interp, "Sub"))) {
@@ -183,15 +177,17 @@
STACK_ENTRY_ACTION, run_cleanup_action);
}
+PARROT_API
void
-Parrot_push_mark(Interp *interp, INTVAL mark)
+Parrot_push_mark(Interp *interp /*NN*/, INTVAL mark)
{
stack_push(interp, &interp->dynamic_env, &mark,
STACK_ENTRY_MARK, STACK_CLEANUP_NULL);
}
+PARROT_API
void
-Parrot_pop_mark(Interp *interp, INTVAL mark)
+Parrot_pop_mark(Interp *interp /*NN*/, INTVAL mark)
{
do {
const Stack_Entry_t * const e
@@ -210,17 +206,14 @@
/*
-=item C<static PMC *
-find_exception_handler(Interp * interp, PMC *exception)>
+FUNCDOC: find_exception_handler
Find the exception handler for C<exception>.
-=cut
-
*/
static PMC *
-find_exception_handler(Interp *interp, PMC *exception)
+find_exception_handler(Interp *interp /*NN*/, PMC *exception)
{
char *m;
int exit_status, print_location;
@@ -299,17 +292,15 @@
/*
-=item C<void
-pop_exception(Interp * interp)>
+FUNCDOC: pop_exception
Pops the topmost exception handler off the stack.
-=cut
-
*/
+PARROT_API
void
-pop_exception(Interp *interp)
+pop_exception(Interp *interp /*NN*/)
{
Stack_entry_type type;
Parrot_cont *cc;
@@ -334,19 +325,17 @@
/*
-=item C<PMC*
-new_c_exception_handler(Interp *interp, Parrot_exception *jb)>
+FUNCDOC: new_c_exception_handler
Generate an exception handler, that catches PASM level exceptions inside
a C function. This could be a separate class too, for now just a private
flag bit is set.
-=cut
-
*/
+PARROT_API
PMC*
-new_c_exception_handler(Interp *interp, Parrot_exception *jb)
+new_c_exception_handler(Interp *interp /*NN*/, Parrot_exception *jb)
{
PMC * const handler = pmc_new(interp, enum_class_Exception_Handler);
/*
@@ -359,32 +348,28 @@
/*
-=item C<void
-push_new_c_exception_handler(Interp *interp, Parrot_exception *jb)>
+FUNCDOC: push_new_c_exception_handler
Pushes an new C exception handler onto the stack.
-=cut
-
*/
+PARROT_API
void
-push_new_c_exception_handler(Interp *interp, Parrot_exception *jb)
+push_new_c_exception_handler(Interp *interp /*NN*/, Parrot_exception *jb)
{
push_exception(interp, new_c_exception_handler(interp, jb));
}
/*
-=item C<opcode_t *
-throw_exception(Interp *interp, PMC *exception, void *dest)>
+FUNCDOC: throw_exception
Throw the exception.
-=cut
-
*/
+PARROT_API
opcode_t *
throw_exception(Interp *interp, PMC *exception, void *dest)
{
@@ -407,17 +392,15 @@
/*
-=item C<opcode_t *
-rethrow_exception(Interp *interp, PMC *exception)>
+FUNCDOC: rethrow_exception
Rethrow the exception.
-=cut
-
*/
+PARROT_API
opcode_t *
-rethrow_exception(Interp *interp, PMC *exception)
+rethrow_exception(Interp *interp /*NN*/, PMC *exception /*NN*/)
{
PMC *handler;
opcode_t *address;
@@ -432,18 +415,16 @@
/*
-=item C<void
-rethrow_c_exception(Interp *interp)>
+FUNCDOC: rethrow_c_exception
Return back to runloop, assumes exception is still in C<TODO> and
that this is called from within a handler setup with C<new_c_exception>.
-=cut
-
*/
void
-rethrow_c_exception(Interp *interp)
+rethrow_c_exception(Interp *interp /*NN*/)
+ /* NORETURN */
{
Parrot_exception * const the_exception = interp->exceptions;
@@ -466,18 +447,16 @@
/*
-=item C<static size_t
-dest2offset(Interp *interp, const opcode_t *dest)>
+FUNCDOC: dest2offset
Translate an absolute bytecode location to an offset used for resuming
after an exception had occurred.
-=cut
-
*/
static size_t
-dest2offset(Interp *interp, const opcode_t *dest)
+dest2offset(Interp *interp /*NN*/, const opcode_t *dest /*NN*/)
+ /* WARN_UNUSED */
{
size_t offset;
/* translate an absolute location in byte_code to an offset
@@ -497,17 +476,14 @@
/*
-=item C<static opcode_t *
-create_exception(Interp *interp)>
+FUNCDOC: create_exception
Create an exception.
-=cut
-
*/
static opcode_t *
-create_exception(Interp *interp)
+create_exception(Interp *interp /*NN*/)
{
PMC *exception; /* exception object */
opcode_t *dest; /* absolute address of handler */
@@ -544,16 +520,15 @@
/*
-=item C<size_t handle_exception(Interp *interp)>
+FUNCDOC: handle_exception
Handle an exception.
-=cut
-
*/
+PARROT_API
size_t
-handle_exception(Interp *interp)
+handle_exception(Interp *interp /*NN*/)
{
/* absolute address of handler */
const opcode_t * const dest = create_exception(interp);
@@ -563,18 +538,16 @@
/*
-=item C<void
-new_internal_exception(Interp *interp)>
+FUNCDOC: new_internal_exception
Create a new internal exception buffer, either by allocating it or by
getting one from the free list.
-=cut
-
*/
+PARROT_API
void
-new_internal_exception(Interp *interp)
+new_internal_exception(Interp *interp /*NN*/)
{
Parrot_exception *the_exception;
@@ -592,15 +565,13 @@
/*
-=item C<void
-free_internal_exception(Interp *interp)>
+FUNCDOC: free_internal_exception
Place internal exception buffer back on the free list.
-=cut
-
*/
+PARROT_API
void
free_internal_exception(Interp *interp)
{
@@ -611,14 +582,14 @@
}
void
-destroy_exception_list(Interp *interp)
+destroy_exception_list(Interp *interp /*NN*/)
{
really_destroy_exception_list(interp->exceptions);
really_destroy_exception_list(interp->exc_free_list);
}
void
-really_destroy_exception_list(Parrot_exception *e)
+really_destroy_exception_list(Parrot_exception *e /*NULLOK*/)
{
while (e != NULL) {
Parrot_exception * const prev = e->prev;
@@ -629,19 +600,18 @@
/*
-=item C<void
-do_exception(Interp *interp,
- exception_severity severity, long error)>
+FUNCDOC: do_exception
Called from interrupt code. Does a C<longjmp> in front of the runloop,
which calls C<handle_exception()>, returning the handler address where
execution then resumes.
-=cut
-
*/
+
+PARROT_API
void
-do_exception(Interp *interp, INTVAL severity, long error)
+do_exception(Interp *interp /*NN*/, INTVAL severity, long error)
+ /* NORETURN */
{
Parrot_exception * const the_exception = interp->exceptions;
@@ -654,9 +624,7 @@
/*
-=item C<void
-real_exception(Interp *interp, void *ret_addr,
- int exitcode, const char *format, ...)>
+FUNCDOC: real_exception
Throws a real exception, with an error message constructed from the format
string and arguments. C<ret_addr> is the address from which to resume, if some
@@ -666,13 +634,11 @@
See also C<internal_exception()>, which signals fatal errors, and
C<throw_exception>, which calls the handler.
-=cut
-
*/
void
-real_exception(Interp *interp, void *ret_addr,
- int exitcode, const char *format, ...)
+real_exception(Interp *interp /*NN*/, void *ret_addr,
+ int exitcode, const char *format /*NN*/, ...)
{
STRING *msg;
Parrot_exception * const the_exception = interp->exceptions;
@@ -681,10 +647,10 @@
* if profiling remember end time of lastop and
* generate entry for exception
*/
- if (interp->profile &&
- Interp_flags_TEST(interp, PARROT_PROFILE_FLAG)) {
- RunProfile * const profile = interp->profile;
+ RunProfile * const profile = interp->profile;
+ if (profile && Interp_flags_TEST(interp, PARROT_PROFILE_FLAG)) {
const FLOATVAL now = Parrot_floatval_time();
+
profile->data[profile->cur_op].time += now - profile->starttime;
profile->cur_op = PARROT_PROF_EXCEPTION;
profile->starttime = now;
@@ -733,14 +699,14 @@
/*
-=item C<void Parrot_init_exceptions(Interp *interp)>
+FUNCDOC: Parrot_init_exceptions
Create exception objects.
*/
void
-Parrot_init_exceptions(Interp *interp) {
+Parrot_init_exceptions(Interp *interp /*NN*/) {
int i;
interp->exception_list = (PMC **)mem_sys_allocate(
@@ -754,14 +720,10 @@
/*
-=back
-
=head1 SEE ALSO
F<include/parrot/exceptions.h>.
-=cut
-
*/
Modified: trunk/src/pmc/resizablepmcarray.pmc
==============================================================================
--- trunk/src/pmc/resizablepmcarray.pmc (original)
+++ trunk/src/pmc/resizablepmcarray.pmc Sat Jun 9 23:49:30 2007
@@ -679,8 +679,8 @@
*/
void splice(PMC* value, INTVAL offset, INTVAL count) {
- INTVAL length = VTABLE_elements(INTERP, SELF);
- INTVAL elems = VTABLE_elements(INTERP, value);
+ const INTVAL length = VTABLE_elements(INTERP, SELF);
+ const INTVAL elems = VTABLE_elements(INTERP, value);
INTVAL shift = elems - count;
INTVAL i;