Skip to content

Commit

Permalink
Replace the old do_panic function with a newer Parrot_x_panic_and_exi…
Browse files Browse the repository at this point in the history
…t. Rename the previous Parrot_x_panic_and_exit with Parrot_x_force_error_exit
  • Loading branch information
Whiteknight committed May 10, 2012
1 parent b1e9b39 commit e3ce02c
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 115 deletions.
12 changes: 0 additions & 12 deletions include/parrot/exceptions.h
Expand Up @@ -118,15 +118,6 @@ typedef enum {
/* HEADERIZER BEGIN: src/exceptions.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */

PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
void do_panic(
NULLOK_INTERP,
ARGIN_NULLOK(const char *message),
ARGIN_NULLOK(const char *file),
unsigned int line);

PARROT_EXPORT
PARROT_DOES_NOT_RETURN_WHEN_FALSE
void Parrot_assert(
Expand Down Expand Up @@ -234,7 +225,6 @@ STRING * Parrot_ex_build_complete_backtrace_string(PARROT_INTERP,
__attribute__nonnull__(2);

void Parrot_print_backtrace(void);
#define ASSERT_ARGS_do_panic __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_assert __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(condition_string) \
, PARROT_ASSERT_ARG(file))
Expand Down Expand Up @@ -280,8 +270,6 @@ void Parrot_print_backtrace(void);
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/exceptions.c */

#define PANIC(interp, message) do_panic((interp), (message), __FILE__, __LINE__)

/* having a modified version of PARROT_ASSERT which resolves as an integer
* rvalue lets us put ASSERT_ARGS() at the top of the list of local variables.
* Thus, we can catch bad pointers before any of the local initialization
Expand Down
24 changes: 23 additions & 1 deletion include/parrot/exit.h
Expand Up @@ -28,6 +28,18 @@ typedef struct _handler_node_t {
*/
#define PARROT_FORCE_EXIT(x) exit(x)

/* The DUMPCORE macro is defined for most platforms, but defined here if not
* found elsewhere, so we're sure it's safe to call. */
#ifndef DUMPCORE
# define DUMPCORE() do { \
fprintf(stderr, "Sorry, coredump is not yet implemented " \
"for this platform.\n\n"); \
PARROT_FORCE_EXIT(EXIT_FAILURE); \
} while(0)
#endif

#define PANIC(interp, message) Parrot_x_panic_and_exit((interp), (message), __FILE__, __LINE__)

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

Expand All @@ -54,7 +66,16 @@ void Parrot_x_on_exit(PARROT_INTERP,
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
void Parrot_x_panic_and_exit(
NULLOK_INTERP,
ARGIN_NULLOK(const char *message),
ARGIN_NULLOK(const char *file),
unsigned int line);

void Parrot_x_force_error_exit(
NULLOK_INTERP,
int exitcode,
ARGIN(const char * format),
Expand All @@ -70,7 +91,8 @@ void Parrot_x_panic_and_exit(
#define ASSERT_ARGS_Parrot_x_on_exit __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(function))
#define ASSERT_ARGS_Parrot_x_panic_and_exit __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
#define ASSERT_ARGS_Parrot_x_panic_and_exit __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_x_force_error_exit __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(format))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/exit.c */
Expand Down
4 changes: 2 additions & 2 deletions include/parrot/pmc_freeze.h
Expand Up @@ -61,7 +61,7 @@ typedef enum {
VTABLE_push_pmc((interp), (visit), (pmc)); \
break; \
default: \
do_panic((interp), "Bad VISIT_HOW in VISIT_PMC", __FILE__, __LINE__); \
Parrot_x_panic_and_exit((interp), "Bad VISIT_HOW in VISIT_PMC", __FILE__, __LINE__); \
} \
} \
} while (0)
Expand Down Expand Up @@ -92,7 +92,7 @@ typedef enum {
VTABLE_push_pmc((interp), (visit), _visit_pmc_attr); \
break; \
default: \
do_panic((interp), "Bad VISIT_HOW in VISIT_PMC_ATTR", __FILE__, __LINE__); \
Parrot_x_panic_and_exit((interp), "Bad VISIT_HOW in VISIT_PMC_ATTR", __FILE__, __LINE__); \
} \
} \
} while (0)
Expand Down
4 changes: 2 additions & 2 deletions src/alarm.c
Expand Up @@ -67,7 +67,7 @@ Parrot_alarm_init(void)
sa.sa_flags = SA_RESTART;

if (sigaction(SIGALRM, &sa, 0) == -1)
Parrot_x_panic_and_exit(NULL, 1, "sigaction failed in Parrot_timers_init");
Parrot_x_force_error_exit(NULL, 1, "sigaction failed in Parrot_timers_init");

Parrot_alarm_unmask(NULL);
#endif
Expand Down Expand Up @@ -107,7 +107,7 @@ posix_alarm_set(FLOATVAL wait)
Parrot_alarm_callback(SIGALRM);
}
else
Parrot_x_panic_and_exit(NULL, 1, "setitimer failed in set_posix_alarm");
Parrot_x_force_error_exit(NULL, 1, "setitimer failed in set_posix_alarm");
}
#endif
}
Expand Down
66 changes: 0 additions & 66 deletions src/exceptions.c
Expand Up @@ -656,72 +656,6 @@ Parrot_print_backtrace(void)
#endif /* ifdef PARROT_HAS_BACKTRACE */
}

/* The DUMPCORE macro is defined for most platforms, but defined here if not
* found elsewhere, so we're sure it's safe to call. */

#ifndef DUMPCORE
# define DUMPCORE() \
fprintf(stderr, "Sorry, coredump is not yet implemented " \
"for this platform.\n\n"); \
exit(EXIT_FAILURE);
#endif

/*
=item C<void do_panic(NULLOK_INTERP, const char *message, const char *file,
unsigned int line)>
Panic handler. Things have gone very wrong in an unexpected way. Print out an
error message and instructions for the user to report the error to the
developers
=cut
*/

PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
void
do_panic(NULLOK_INTERP, ARGIN_NULLOK(const char *message),
ARGIN_NULLOK(const char *file), unsigned int line)
{
ASSERT_ARGS(do_panic)
/* Note: we can't format any floats in here--Parrot_sprintf
** may panic because of floats.
** and we don't use Parrot_sprintf or such, because we are
** already in panic --leo
*/
fprintf(stderr, "Parrot VM: PANIC: %s!\n",
message ? message : "(no message available)");

fprintf(stderr, "C file %s, line %u\n",
file ? file : "(not available)", line);

fprintf(stderr, "Parrot file (not available), ");
fprintf(stderr, "line (not available)\n");

fprintf(stderr, "\n\
We highly suggest you notify the Parrot team if you have not been working on\n\
Parrot. Use parrotbug (located in parrot's root directory) or send an\n\
e-mail to parrot-dev@lists.parrot.org.\n\
Include the entire text of this error message and the text of the script that\n\
generated the error. If you've made any modifications to Parrot, please\n\
describe them as well.\n\n");

fprintf(stderr, "Version : %s\n", PARROT_VERSION);
fprintf(stderr, "Configured : %s\n", PARROT_CONFIG_DATE);
fprintf(stderr, "Architecture: %s\n", PARROT_ARCHNAME);
if (interp)
fprintf(stderr, "Interp Flags: %#x\n", (unsigned int)interp->flags);
else
fprintf(stderr, "Interp Flags: (no interpreter)\n");
fprintf(stderr, "Exceptions : %s\n", "(missing from core)");
fprintf(stderr, "\nDumping Core...\n");

DUMPCORE();
}

/*
=item C<static void Parrot_ex_update_for_rethrow(PARROT_INTERP, PMC * ex)>
Expand Down
60 changes: 58 additions & 2 deletions src/exit.c
Expand Up @@ -140,9 +140,9 @@ Parrot_x_execute_on_exit_handlers(PARROT_INTERP, int status)
}

void
Parrot_x_panic_and_exit(NULLOK_INTERP, int exitcode, ARGIN(const char * format), ...)
Parrot_x_force_error_exit(NULLOK_INTERP, int exitcode, ARGIN(const char * format), ...)
{
ASSERT_ARGS(Parrot_x_panic_and_exit)
ASSERT_ARGS(Parrot_x_force_error_exit)

va_list arglist;
va_start(arglist, format);
Expand All @@ -154,6 +154,62 @@ Parrot_x_panic_and_exit(NULLOK_INTERP, int exitcode, ARGIN(const char * format),
Parrot_x_jump_out(interp, exitcode);
}

/*
=item C<void Parrot_x_full_panic(NULLOK_INTERP, const char *message, const char *file,
unsigned int line)>
Panic handler. Things have gone very wrong in an unexpected way. Print out an
error message and instructions for the user to report the error to the
developers
=cut
*/

PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
void
Parrot_x_panic_and_exit(NULLOK_INTERP, ARGIN_NULLOK(const char *message),
ARGIN_NULLOK(const char *file), unsigned int line)
{
ASSERT_ARGS(Parrot_x_panic_and_exit)
/* Note: we can't format any floats in here--Parrot_sprintf
** may panic because of floats.
** and we don't use Parrot_sprintf or such, because we are
** already in panic --leo
*/
fprintf(stderr, "Parrot VM: PANIC: %s!\n",
message ? message : "(no message available)");

fprintf(stderr, "C file %s, line %u\n",
file ? file : "(not available)", line);

fprintf(stderr, "Parrot file (not available), ");
fprintf(stderr, "line (not available)\n");

fprintf(stderr, "\n\
We highly suggest you notify the Parrot team if you have not been working on\n\
Parrot. Use parrotbug (located in parrot's root directory) or send an\n\
e-mail to parrot-dev@lists.parrot.org.\n\
Include the entire text of this error message and the text of the script that\n\
generated the error. If you've made any modifications to Parrot, please\n\
describe them as well.\n\n");

fprintf(stderr, "Version : %s\n", PARROT_VERSION);
fprintf(stderr, "Configured : %s\n", PARROT_CONFIG_DATE);
fprintf(stderr, "Architecture: %s\n", PARROT_ARCHNAME);
if (interp)
fprintf(stderr, "Interp Flags: %#x\n", (unsigned int)interp->flags);
else
fprintf(stderr, "Interp Flags: (no interpreter)\n");
fprintf(stderr, "Exceptions : %s\n", "(missing from core)");
fprintf(stderr, "\nDumping Core...\n");

DUMPCORE();
}


/*
Expand Down
3 changes: 1 addition & 2 deletions src/extend.c
Expand Up @@ -187,8 +187,7 @@ restore_context(PARROT_INTERP, ARGIN(Parrot_Context * const initialctx))
Parrot_pop_context(interp);
curctx = CONTEXT(interp);
if (curctx == NULL)
do_panic((interp), "cannot restore context",
__FILE__, __LINE__);
PANIC(interp, "cannot restore context");
} while (curctx != initialctx);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/gc/alloc_memory.c
Expand Up @@ -273,7 +273,7 @@ panic_failed_allocation(unsigned int line, unsigned long size)
ASSERT_ARGS(panic_failed_allocation)

fprintf(stderr, "Failed allocation of %lu bytes\n", size);
do_panic(NULL, "Out of mem", __FILE__, line);
Parrot_x_panic_and_exit(NULL, "Out of mem", __FILE__, line);
}

/*
Expand All @@ -294,7 +294,7 @@ panic_zero_byte_allocation(unsigned int line, ARGIN(const char *func))
ASSERT_ARGS(panic_zero_byte_allocation)

fprintf(stderr, "Zero-byte allocation not allowed in %s", func);
do_panic(NULL, "Out of mem", __FILE__, line);
Parrot_x_panic_and_exit(NULL, "Out of mem", __FILE__, line);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/gc/gc_gms.c
Expand Up @@ -1893,7 +1893,7 @@ failed_allocation(unsigned int line, size_t size)
{
ASSERT_ARGS(failed_allocation)
fprintf(stderr, "Failed allocation of %lu bytes\n", (unsigned long)size);
do_panic(NULL, "Out of mem", __FILE__, line);
Parrot_x_panic_and_exit(NULL, "Out of mem", __FILE__, line);
}


Expand Down
2 changes: 1 addition & 1 deletion src/gc/gc_inf.c
Expand Up @@ -590,7 +590,7 @@ failed_allocation(unsigned int line, unsigned long size)
{
ASSERT_ARGS(failed_allocation)
fprintf(stderr, "Failed allocation of %lu bytes\n", size);
do_panic(NULL, "Out of mem", __FILE__, line);
Parrot_x_panic_and_exit(NULL, "Out of mem", __FILE__, line);
}


Expand Down
2 changes: 1 addition & 1 deletion src/gc/gc_ms.c
Expand Up @@ -385,7 +385,7 @@ static void
failed_allocation(unsigned int line, unsigned long size)
{
fprintf(stderr, "Failed allocation of %lu bytes\n", size);
do_panic(NULL, "Out of mem", __FILE__, line);
Parrot_x_panic_and_exit(NULL, "Out of mem", __FILE__, line);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/gc/gc_ms2.c
Expand Up @@ -1470,7 +1470,7 @@ failed_allocation(unsigned int line, unsigned long size)
{
ASSERT_ARGS(failed_allocation)
fprintf(stderr, "Failed allocation of %lu bytes\n", size);
do_panic(NULL, "Out of mem", __FILE__, line);
Parrot_x_panic_and_exit(NULL, "Out of mem", __FILE__, line);
}


Expand Down
2 changes: 1 addition & 1 deletion src/packfile/api.c
Expand Up @@ -1265,7 +1265,7 @@ PackFile_set_header(ARGOUT(PackFile_Header *header))
# if (NUMVAL_SIZE == 16)
header->floattype = FLOATTYPE_16;
# else
Parrot_x_panic_and_exit(NULL, 1,
Parrot_x_force_error_exit(NULL, 1,
"PackFile_set_header: Unsupported floattype NUMVAL_SIZE=%d,"
" PARROT_BIGENDIAN=%s\n", NUMVAL_SIZE,
PARROT_BIGENDIAN ? "big-endian" : "little-endian");
Expand Down

0 comments on commit e3ce02c

Please sign in to comment.