Skip to content

Commit

Permalink
Fix various SEGV
Browse files Browse the repository at this point in the history
See GH #87.
Fixes Function()() (empty closure or method), Error() (empty error message),
Lobby cmp 0 (compare with Lobby is always 1, unless with Lobby which is 0).

string of Compiled() (proto_string) not yet fixed
  • Loading branch information
Reini Urban committed Oct 27, 2015
1 parent 9733e29 commit e99d65b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions core/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ PN potion_delegated(Potion *P, PN closure, PN self) {

PN potion_call(Potion *P, PN cl, PN_SIZE argc, PN * volatile argv) {
vPN(Closure) c = PN_CLOSURE(cl);
if (!c || !c->method) {
//return PN_NIL;
return potion_error(P, PN_STR("Error: Empty closure or method"), 0, 0, 0);
}
switch (argc) {
case 0:
return c->method(P, cl, cl);
Expand Down Expand Up @@ -240,6 +244,8 @@ PN potion_error(Potion *P, PN msg, long lineno, long charno, PN excerpt) {

PN potion_error_string(Potion *P, PN cl, PN self) {
vPN(Error) e = (struct PNError *)self;
if (!e || !e->message)
return potion_str_format(P, "** Error\n");
if (e->excerpt == PN_NIL)
return potion_str_format(P, "** %s\n", PN_STR_PTR(e->message));
return potion_str_format(P, "** %s\n"
Expand Down
4 changes: 3 additions & 1 deletion core/primitive.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ static PN potion_any_is_nil(Potion *P, PN closure, PN self) {
\param value PN
\return PNInteger -1 if less, 0 if equal or 1 if greater */
PN potion_any_cmp(Potion *P, PN cl, PN self, PN value) {
return potion_send(self, PN_cmp, value);
return (self == P->lobby)
? ((value == P->lobby) ? PN_NUM(0) : PN_NUM(1)) // Lobby is greater than anything
: potion_send(self, PN_cmp, value);
}
/** memberof NilKind
"cmp" method. nil is 0 or "" or FALSE as cmp context
Expand Down

0 comments on commit e99d65b

Please sign in to comment.