Changeset d221460a632fc089092b34dcfb215f8296a9b713
- Timestamp:
- 08/03/08 19:06:58
(5 years ago)
- Author:
- Theo Schlossnagle <jesus@omniti.com>
- git-committer:
- Theo Schlossnagle <jesus@omniti.com> 1217790418 +0000
- git-parent:
[fda4621228eace5666578fde08eceae320d9100b]
- git-author:
- Theo Schlossnagle <jesus@omniti.com> 1217790418 +0000
- Message:
supposedly garbage collecting the coro should be enough to do the trick -- resuming it causes accessing freed memory (due to the gc), refs #47
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rfda4621 |
rd221460 |
|
| 46 | 46 | } |
|---|
| 47 | 47 | |
|---|
| | 48 | void |
|---|
| | 49 | cancel_coro(noit_lua_check_info_t *ci) { |
|---|
| | 50 | lua_getglobal(ci->lmc->lua_state, "noit_coros"); |
|---|
| | 51 | luaL_unref(ci->lmc->lua_state, -1, ci->coro_state_ref); |
|---|
| | 52 | lua_pop(ci->lmc->lua_state, 1); |
|---|
| | 53 | lua_gc(ci->lmc->lua_state, LUA_GCCOLLECT, 0); |
|---|
| | 54 | noit_hash_delete(&noit_coros, |
|---|
| | 55 | (const char *)&ci->coro_state, sizeof(ci->coro_state), |
|---|
| | 56 | NULL, NULL); |
|---|
| | 57 | } |
|---|
| | 58 | |
|---|
| 48 | 59 | noit_lua_check_info_t * |
|---|
| 49 | 60 | get_ci(lua_State *L) { |
|---|
| 50 | 61 | noit_lua_check_info_t *v = NULL; |
|---|
| 51 | | if(noit_hash_retrieve(&noit_coros, (const char *)&L, sizeof(L), (void **)&v)) { |
|---|
| | 62 | if(noit_hash_retrieve(&noit_coros, (const char *)&L, sizeof(L), (void **)&v)) |
|---|
| 52 | 63 | return v; |
|---|
| 53 | | } |
|---|
| 54 | 64 | return NULL; |
|---|
| 55 | 65 | } |
|---|
| … | … | |
| 495 | 505 | int |
|---|
| 496 | 506 | noit_lua_resume(noit_lua_check_info_t *ci, int nargs) { |
|---|
| 497 | | int result, base; |
|---|
| | 507 | int result = -1, base; |
|---|
| 498 | 508 | noit_check_t *check; |
|---|
| 499 | 509 | check = ci->check; |
|---|
| … | … | |
| 528 | 538 | break; |
|---|
| 529 | 539 | } |
|---|
| 530 | | lua_getglobal(ci->lmc->lua_state, "noit_coros"); |
|---|
| 531 | | luaL_unref(ci->lmc->lua_state, -1, ci->coro_state_ref); |
|---|
| 532 | | lua_pop(ci->lmc->lua_state, 1); |
|---|
| 533 | | lua_gc(ci->lmc->lua_state, LUA_GCCOLLECT, 0); |
|---|
| | 540 | cancel_coro(ci); |
|---|
| 534 | 541 | |
|---|
| 535 | 542 | noit_lua_log_results(ci->self, ci->check); |
|---|
| … | … | |
| 555 | 562 | * it, garbage collect it and then ensure that it failes a resume |
|---|
| 556 | 563 | */ |
|---|
| 557 | | lua_getglobal(ci->lmc->lua_state, "noit_coros"); |
|---|
| 558 | | luaL_unref(ci->lmc->lua_state, -1, ci->coro_state_ref); |
|---|
| 559 | | lua_pop(ci->lmc->lua_state, 1); |
|---|
| 560 | | lua_gc(ci->lmc->lua_state, LUA_GCCOLLECT, 0); |
|---|
| 561 | | assert(2 == noit_lua_resume(ci, 0)); |
|---|
| 562 | | } else { |
|---|
| 563 | | noit_lua_log_results(ci->self, ci->check); |
|---|
| 564 | | noit_lua_module_cleanup(ci->self, ci->check); |
|---|
| 565 | | check->flags &= ~NP_RUNNING; |
|---|
| 566 | | } |
|---|
| | 564 | cancel_coro(ci); |
|---|
| | 565 | } |
|---|
| | 566 | |
|---|
| | 567 | noit_lua_log_results(ci->self, ci->check); |
|---|
| | 568 | noit_lua_module_cleanup(ci->self, ci->check); |
|---|
| | 569 | check->flags &= ~NP_RUNNING; |
|---|
| | 570 | |
|---|
| 567 | 571 | if(int_cl->free) int_cl->free(int_cl); |
|---|
| 568 | 572 | return 0; |
|---|
| … | … | |
| 570 | 574 | static int |
|---|
| 571 | 575 | noit_lua_initiate(noit_module_t *self, noit_check_t *check) { |
|---|
| 572 | | lua_State **coro_state_copy; |
|---|
| 573 | 576 | LMC_DECL(L, self); |
|---|
| 574 | 577 | struct nl_intcl *int_cl; |
|---|
| … | … | |
| 606 | 609 | eventer_add(e); |
|---|
| 607 | 610 | |
|---|
| 608 | | noitL(nldeb, "initiate gettop => %d\n", lua_gettop(L)); |
|---|
| 609 | 611 | ci->lmc = lmc; |
|---|
| 610 | 612 | lua_getglobal(L, "noit_coros"); |
|---|
| … | … | |
| 612 | 614 | ci->coro_state_ref = luaL_ref(L, -2); |
|---|
| 613 | 615 | lua_pop(L, 1); /* pops noit_coros */ |
|---|
| 614 | | |
|---|
| 615 | | coro_state_copy = malloc(sizeof(*coro_state_copy)); |
|---|
| 616 | | *coro_state_copy = ci->coro_state; |
|---|
| 617 | | noit_hash_replace(&noit_coros, |
|---|
| 618 | | (const char *)coro_state_copy, sizeof(*coro_state_copy), |
|---|
| 619 | | ci, free, NULL); |
|---|
| | 616 | noit_hash_store(&noit_coros, |
|---|
| | 617 | (const char *)&ci->coro_state, sizeof(ci->coro_state), |
|---|
| | 618 | ci); |
|---|
| 620 | 619 | |
|---|
| 621 | 620 | SETUP_CALL(ci->coro_state, "initiate", goto fail); |
|---|