Skip to content

Commit 45fa8fd

Browse files
committed
Move maybe_print_custom_stack into libhl
1 parent b07f525 commit 45fa8fd

File tree

4 files changed

+24
-43
lines changed

4 files changed

+24
-43
lines changed

src/hl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ HL_API HL_NO_RETURN( void hl_null_access( void ) );
642642
HL_API void hl_setup_longjump( void *j );
643643
HL_API void hl_setup_exception( void *resolve_symbol, void *capture_stack );
644644
HL_API void hl_dump_stack( void );
645+
HL_API bool hl_maybe_print_custom_stack( vdynamic* ret );
645646
HL_API varray *hl_exception_stack( void );
646647
HL_API bool hl_detect_debugger( void );
647648

src/hlc_main.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,6 @@ static int throw_handler( int code ) {
148148
}
149149
#endif
150150

151-
bool maybe_print_custom_stack( vdynamic* ret ) {
152-
hl_type* exct = ret->t;
153-
while( exct->kind == HOBJ ) {
154-
if( exct->obj->super == NULL ) {
155-
if( ucmp(exct->obj->name, USTR("haxe.Exception")) == 0 ) {
156-
hl_field_lookup* f = hl_lookup_find(exct->obj->rt->lookup, exct->obj->rt->nlookup, hl_hash_gen(USTR("__customStack"), true));
157-
if( f == NULL || f->field_index < 0 ) break;
158-
vdynamic* customStack = *(vdynamic**)((char*)(ret) + f->field_index);
159-
if( customStack != NULL ) {
160-
uprintf(USTR("Custom stack:%s\n"), hl_to_string(customStack));
161-
return true;
162-
}
163-
}
164-
break;
165-
}
166-
exct = exct->obj->super;
167-
}
168-
return false;
169-
}
170-
171151
#ifdef HL_WIN_DESKTOP
172152
int wmain(int argc, uchar *argv[]) {
173153
#else
@@ -192,7 +172,7 @@ int main(int argc, char *argv[]) {
192172
ret = hl_dyn_call_safe(&cl, NULL, 0, &isExc);
193173
if( isExc ) {
194174
uprintf(USTR("Uncaught exception: %s\n"), hl_to_string(ret));
195-
if( !maybe_print_custom_stack(ret) ) {
175+
if( !hl_maybe_print_custom_stack(ret) ) {
196176
varray *a = hl_exception_stack();
197177
int i;
198178
for( i = 0; i < a->size; i++ )

src/main.c

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,6 @@ static void setup_handler() {
133133
}
134134
#endif
135135

136-
bool maybe_print_custom_stack( vdynamic* ret ) {
137-
hl_type* exct = ret->t;
138-
while( exct->kind == HOBJ ) {
139-
if( exct->obj->super == NULL ) {
140-
if( ucmp(exct->obj->name, USTR("haxe.Exception")) == 0 ) {
141-
hl_field_lookup* f = hl_lookup_find(exct->obj->rt->lookup, exct->obj->rt->nlookup, hl_hash_gen(USTR("__customStack"), true));
142-
if( f == NULL || f->field_index < 0 ) break;
143-
vdynamic* customStack = *(vdynamic**)((char*)(ret) + f->field_index);
144-
if( customStack != NULL ) {
145-
uprintf(USTR("Custom stack:%s\n"), hl_to_string(customStack));
146-
return true;
147-
}
148-
}
149-
break;
150-
}
151-
exct = exct->obj->super;
152-
}
153-
return false;
154-
}
155-
156136
#ifdef HL_WIN
157137
int wmain(int argc, pchar *argv[]) {
158138
#else
@@ -261,8 +241,8 @@ int main(int argc, pchar *argv[]) {
261241
hl_profile_end();
262242
if( isExc ) {
263243
uprintf(USTR("Uncaught exception: %s\n"), hl_to_string(ctx.ret));
264-
if( !maybe_print_custom_stack(ctx.ret) ) {
265-
varray* a = hl_exception_stack();
244+
if( !hl_maybe_print_custom_stack(ctx.ret) ) {
245+
varray *a = hl_exception_stack();
266246
int i;
267247
for( i = 0; i < a->size; i++ )
268248
uprintf(USTR("Called from %s\n"), hl_aptr(a, uchar*)[i]);

src/std/error.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,26 @@ HL_PRIM void hl_dump_stack() {
142142
fflush(stdout);
143143
}
144144

145+
HL_PRIM bool hl_maybe_print_custom_stack( vdynamic* ret ) {
146+
hl_type* exct = ret->t;
147+
while( exct->kind == HOBJ ) {
148+
if( exct->obj->super == NULL ) {
149+
if( ucmp(exct->obj->name, USTR("haxe.Exception")) == 0 ) {
150+
hl_field_lookup* f = hl_lookup_find(exct->obj->rt->lookup, exct->obj->rt->nlookup, hl_hash_gen(USTR("__customStack"), true));
151+
if( f == NULL || f->field_index < 0 ) break;
152+
vdynamic* customStack = *(vdynamic**)((char*)(ret) + f->field_index);
153+
if( customStack != NULL ) {
154+
uprintf(USTR("%s\n"), hl_to_string(customStack));
155+
return true;
156+
}
157+
}
158+
break;
159+
}
160+
exct = exct->obj->super;
161+
}
162+
return false;
163+
}
164+
145165
HL_PRIM varray *hl_exception_stack() {
146166
hl_thread_info *t = hl_get_thread();
147167
varray *a = hl_alloc_array(&hlt_bytes, t->exc_stack_count);

0 commit comments

Comments
 (0)