Improved modalqueue.c error handling. A bit dirty to have the same function in multiple Go files like this, but meh.

This commit is contained in:
Pietro Gagliardi 2014-08-25 21:17:09 -04:00
parent a952cfcc58
commit 35dcac92d6
5 changed files with 20 additions and 2 deletions

View File

@ -1,6 +1,8 @@
// 19 august 2014
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "modalqueue.h"
static struct {
@ -17,7 +19,7 @@ void beginModal(void)
mq.cap = 128;
mq.queue = (void **) malloc(mq.cap * sizeof (void *));
if (mq.queue == NULL)
abort();//TODO
modalPanic("error allocating modal queue", strerror(errno));
mq.len = 0;
}
}
@ -42,7 +44,7 @@ int queueIfModal(void *what)
mq.cap *= 2;
mq.queue = (void **) realloc(mq.queue, mq.cap * sizeof (void *));
if (mq.queue == NULL)
abort();//TODO
modalPanic("error growing modal queue", strerror(errno));
}
return 1;
}

View File

@ -6,3 +6,4 @@ extern int queueIfModal(void *);
/* needed by the above */
extern void doissue(void *);
extern void modalPanic(char *, char *);

View File

@ -39,3 +39,8 @@ func issue(f *func()) {
func doissue(fp unsafe.Pointer) {
perform(fp)
}
//export modalPanic
func modalPanic(reason *C.char, strerror *C.char) {
panic(fmt.Errorf("%s: %s", C.GoString(reason), C.GoString(strerror)))
}

View File

@ -53,3 +53,8 @@ func doissue(data unsafe.Pointer) {
// for the modal queue functions
perform(data)
}
//export modalPanic
func modalPanic(reason *C.char, strerror *C.char) {
panic(fmt.Errorf("%s: %s", C.GoString(reason), C.GoString(strerror)))
}

View File

@ -68,3 +68,8 @@ func makemsgwin() error {
func doissue(fp unsafe.Pointer) {
perform(fp)
}
//export modalPanic
func modalPanic(reason *C.char, strerror *C.char) {
panic(fmt.Errorf("%s: %s", C.GoString(reason), C.GoString(strerror)))
}