#include <stdlib.h>
#include "runtime.h"
+#include "arch.h"
#include "malloc.h"
#include "go-alloc.h"
#include "go-defer.h"
if (p->__next != NULL)
{
__printpanics (p->__next);
- printf ("\t");
+ fprintf (stderr, "\t");
}
- printf ("panic: ");
- printany (p->__arg);
+ fprintf (stderr, "panic: ");
+ runtime_printany (p->__arg);
if (p->__was_recovered)
- printf (" [recovered]");
- putchar ('\n');
+ fprintf (stderr, " [recovered]");
+ fputc ('\n', stderr);
}
/* This implements __go_panic which is used for the panic
void
__go_panic (struct __go_empty_interface arg)
{
+ G *g;
struct __go_panic_stack *n;
- if (__go_panic_defer == NULL)
- __go_panic_defer = ((struct __go_panic_defer_struct *)
- __go_alloc (sizeof (struct __go_panic_defer_struct)));
+ g = runtime_g ();
n = (struct __go_panic_stack *) __go_alloc (sizeof (struct __go_panic_stack));
n->__arg = arg;
- n->__next = __go_panic_defer->__panic;
- __go_panic_defer->__panic = n;
+ n->__next = g->panic;
+ g->panic = n;
/* Run all the defer functions. */
struct __go_defer_stack *d;
void (*pfn) (void *);
- d = __go_panic_defer->__defer;
+ d = g->defer;
if (d == NULL)
break;
/* Some defer function called recover. That means that
we should stop running this panic. */
- __go_panic_defer->__panic = n->__next;
+ g->panic = n->__next;
__go_free (n);
/* Now unwind the stack by throwing an exception. The
*d->__frame = 0;
}
- __go_panic_defer->__defer = d->__next;
+ g->defer = d->__next;
__go_free (d);
}
/* The panic was not recovered. */
- __printpanics (__go_panic_defer->__panic);
-
- /* FIXME: We should dump a call stack here. */
- abort ();
-}
-
-/* This is used by the runtime library. */
-
-void
-__go_panic_msg (const char* msg)
-{
- size_t len;
- unsigned char *sdata;
- struct __go_string s;
- struct __go_empty_interface arg;
-
- len = __builtin_strlen (msg);
- sdata = runtime_mallocgc (len, FlagNoPointers, 0, 0);
- __builtin_memcpy (sdata, msg, len);
- s.__data = sdata;
- s.__length = len;
- newErrorString(s, &arg);
- __go_panic (arg);
+ runtime_startpanic ();
+ __printpanics (g->panic);
+ runtime_dopanic (0);
}