quipu mercurial repository
Revision | b83d33a615ecacba4a585a16aa18f3ed2bbfcaf7 (tree) |
---|---|
Time | 2020-04-09 07:00:02 |
Author | Agustina Arzille <avarzille@rise...> |
Commiter | Agustina Arzille |
Better error reporting for init ops
@@ -333,6 +333,7 @@ | ||
333 | 333 | DISPATCH (PKG, P); |
334 | 334 | DISPATCH (INSTANCE, W); |
335 | 335 | #undef DISPATCH |
336 | +#undef hash_W | |
336 | 337 | default: |
337 | 338 | return (raw_hash (obj)); |
338 | 339 | } |
@@ -11,10 +11,12 @@ | ||
11 | 11 | struct init_op_list |
12 | 12 | { |
13 | 13 | dlist ops; |
14 | + const char *errmsg; | |
14 | 15 | |
15 | 16 | init_op_list () |
16 | 17 | { |
17 | 18 | this->ops.init_head (); |
19 | + this->errmsg = nullptr; | |
18 | 20 | } |
19 | 21 | |
20 | 22 | inline void add (init_op *op); |
@@ -63,6 +65,12 @@ | ||
63 | 65 | init_op_list::global_ops().add (this); |
64 | 66 | } |
65 | 67 | |
68 | + static int fail (const char *msg) | |
69 | + { | |
70 | + init_op_list::global_ops().errmsg = msg; | |
71 | + return (init_op::result_failed); | |
72 | + } | |
73 | + | |
66 | 74 | int call (interpreter *interp) |
67 | 75 | { |
68 | 76 | if (this->state == st_wip) |
@@ -22,9 +22,17 @@ | ||
22 | 22 | main_interp->init (); |
23 | 23 | |
24 | 24 | if (!init_op_list::global_ops().call (main_interp)) |
25 | - return (false); | |
25 | + { | |
26 | + fputs ("init ops failed: ", stderr); | |
27 | + fputs (init_op_list::global_ops().errmsg, stderr); | |
28 | + return (false); | |
29 | + } | |
30 | + else if (atexit (memory_exit) != 0) | |
31 | + { | |
32 | + fputs ("could not install atexit handler", stderr); | |
33 | + return (false); | |
34 | + } | |
26 | 35 | |
27 | - atexit (memory_exit); | |
28 | 36 | gc_enable (); |
29 | 37 | return (true); |
30 | 38 | } |
@@ -623,7 +623,7 @@ | ||
623 | 623 | !as_symbol(s)->flagged_p (symbol::specform_flag)) |
624 | 624 | continue; |
625 | 625 | |
626 | - *pkg_lookup(interp, ap, symname (*it)) = *it; | |
626 | + *pkg_lookup(interp, ap, symname (s)) = s; | |
627 | 627 | if (ap->len * 75 <= ++syms_len(ap) * 100) |
628 | 628 | { |
629 | 629 | pkg_resize (interp, dstp, ap->len * 4); |
@@ -1325,7 +1325,7 @@ | ||
1325 | 1325 | } |
1326 | 1326 | |
1327 | 1327 | if (*sf) |
1328 | - return (init_op::result_failed); | |
1328 | + return (init_op::fail ("more special forms than expected")); | |
1329 | 1329 | |
1330 | 1330 | symbol::quote = find_sym (interp, "quote", 5); |
1331 | 1331 |
@@ -484,11 +484,11 @@ | ||
484 | 484 | { |
485 | 485 | HMODULE md = GetModuleHandleA ("ntdll.dll"); |
486 | 486 | if (!md) |
487 | - return (init_op::result_failed); | |
487 | + return (init_op::fail ("could not get a handle for ntdll.dll")); | |
488 | 488 | |
489 | 489 | setfh_info = (setfh_info_fn)GetProcAddress (md, "NtSetInformationFile"); |
490 | 490 | if (!setfh_info) |
491 | - return (init_op::result_failed); | |
491 | + return (init_op::fail ("could not find function in ntdll.dll")); | |
492 | 492 | |
493 | 493 | std_fhandles[0] = GetStdHandle (STD_INPUT_HANDLE); |
494 | 494 | std_fhandles[1] = GetStdHandle (STD_OUTPUT_HANDLE); |
@@ -499,11 +499,11 @@ | ||
499 | 499 | !fhandle_valid_p (std_fhandles[1]) || |
500 | 500 | !fhandle_valid_p (std_fhandles[2]) || |
501 | 501 | !fhandle_valid_p (interp->io_event)) |
502 | - return (init_op::result_failed); | |
502 | + return (init_op::fail ("could not initialize standard handles")); | |
503 | 503 | |
504 | 504 | WSADATA wsd; |
505 | 505 | if (WSAStartup (MAKEWORD (2, 2), &wsd) != 0) |
506 | - return (init_op::result_failed); | |
506 | + return (init_op::fail ("could not initialize socket subsystem")); | |
507 | 507 | |
508 | 508 | return (init_op::result_ok); |
509 | 509 | } |
@@ -361,16 +361,16 @@ | ||
361 | 361 | |
362 | 362 | #ifdef QP_PLATFORM_WINDOWS |
363 | 363 | if (!tp->handle) |
364 | - return (init_op::result_failed); | |
364 | + return (init_op::fail ("could not duplicate thread handle")); | |
365 | 365 | #endif |
366 | 366 | |
367 | 367 | #if !defined (QP_PLATFORM_LINUX) |
368 | 368 | if (!(tp->sleep_q = alloc_sleepq ())) |
369 | - return (init_op::result_failed); | |
369 | + return (init_op::fail ("could not allocate sleep queue")); | |
370 | 370 | #endif |
371 | 371 | |
372 | 372 | if (!futex_init (interp)) |
373 | - return (init_op::result_failed); | |
373 | + return (init_op::fail ("could not initialize futex subsystem")); | |
374 | 374 | |
375 | 375 | tp->join_ev = 0; |
376 | 376 |