… | |
… | |
8 | # define CHK(x) if (!(x)) croak("FATAL, CHK: " #x) |
8 | # define CHK(x) if (!(x)) croak("FATAL, CHK: " #x) |
9 | #endif |
9 | #endif |
10 | |
10 | |
11 | #define MAY_FLUSH /* increases codesize */ |
11 | #define MAY_FLUSH /* increases codesize */ |
12 | |
12 | |
13 | #define SUB_INIT "Coro::State::coroutine_initialization" |
13 | #define SUB_INIT "Coro::State::initialize" |
14 | |
14 | |
15 | #define SAVE_DEFAV 0x00000001 |
15 | #define SAVE_DEFAV 0x00000001 |
16 | #define SAVE_DEFSV 0x00000002 |
16 | #define SAVE_DEFSV 0x00000002 |
17 | #define SAVE_ERRSV 0x00000004 |
17 | #define SAVE_ERRSV 0x00000004 |
18 | |
18 | |
… | |
… | |
302 | save_state(pTHX_ Coro__State c, int flags) |
302 | save_state(pTHX_ Coro__State c, int flags) |
303 | { |
303 | { |
304 | { |
304 | { |
305 | dSP; |
305 | dSP; |
306 | I32 cxix = cxstack_ix; |
306 | I32 cxix = cxstack_ix; |
|
|
307 | PERL_CONTEXT *ccstk = cxstack; |
307 | PERL_SI *top_si = PL_curstackinfo; |
308 | PERL_SI *top_si = PL_curstackinfo; |
308 | PERL_CONTEXT *ccstk = cxstack; |
|
|
309 | |
309 | |
310 | /* |
310 | /* |
311 | * the worst thing you can imagine happens first - we have to save |
311 | * the worst thing you can imagine happens first - we have to save |
312 | * (and reinitialize) all cv's in the whole callchain :( |
312 | * (and reinitialize) all cv's in the whole callchain :( |
313 | */ |
313 | */ |
314 | |
314 | |
315 | PUSHs (Nullsv); |
315 | PUSHs (Nullsv); |
316 | /* this loop was inspired by pp_caller */ |
316 | /* this loop was inspired by pp_caller */ |
317 | for (;;) |
317 | for (;;) |
318 | { |
318 | { |
319 | do |
319 | do |
320 | { |
320 | { |
321 | PERL_CONTEXT *cx = &ccstk[cxix--]; |
321 | PERL_CONTEXT *cx = &ccstk[cxix--]; |
322 | |
322 | |
323 | if (CxTYPE(cx) == CXt_SUB) |
323 | if (CxTYPE(cx) == CXt_SUB) |
324 | { |
324 | { |
… | |
… | |
366 | } |
366 | } |
367 | |
367 | |
368 | c->defav = flags & SAVE_DEFAV ? (AV *)SvREFCNT_inc (GvAV (PL_defgv)) : 0; |
368 | c->defav = flags & SAVE_DEFAV ? (AV *)SvREFCNT_inc (GvAV (PL_defgv)) : 0; |
369 | c->defsv = flags & SAVE_DEFSV ? SvREFCNT_inc (DEFSV) : 0; |
369 | c->defsv = flags & SAVE_DEFSV ? SvREFCNT_inc (DEFSV) : 0; |
370 | c->errsv = flags & SAVE_ERRSV ? SvREFCNT_inc (ERRSV) : 0; |
370 | c->errsv = flags & SAVE_ERRSV ? SvREFCNT_inc (ERRSV) : 0; |
|
|
371 | |
|
|
372 | /* I have not the slightest idea of why av_reify is necessary */ |
|
|
373 | /* but if it's missing the defav contents magically get replaced sometimes */ |
|
|
374 | if (c->defav) |
|
|
375 | av_reify (c->defav); |
371 | |
376 | |
372 | c->dowarn = PL_dowarn; |
377 | c->dowarn = PL_dowarn; |
373 | |
378 | |
374 | c->curstackinfo = PL_curstackinfo; |
379 | c->curstackinfo = PL_curstackinfo; |
375 | c->curstack = PL_curstack; |
380 | c->curstack = PL_curstack; |
… | |
… | |
508 | MODULE = Coro::State PACKAGE = Coro::State |
513 | MODULE = Coro::State PACKAGE = Coro::State |
509 | |
514 | |
510 | PROTOTYPES: ENABLE |
515 | PROTOTYPES: ENABLE |
511 | |
516 | |
512 | BOOT: |
517 | BOOT: |
513 | { /* {} necessary for stoopid perl-5.6.x */ |
518 | { /* {} necessary for stoopid perl-5.6.x */ |
514 | HV * stash = gv_stashpvn("Coro::State", 10, TRUE); |
519 | HV * stash = gv_stashpvn("Coro::State", 10, TRUE); |
515 | |
520 | |
516 | newCONSTSUB (stash, "SAVE_DEFAV", newSViv (SAVE_DEFAV)); |
521 | newCONSTSUB (stash, "SAVE_DEFAV", newSViv (SAVE_DEFAV)); |
517 | newCONSTSUB (stash, "SAVE_DEFSV", newSViv (SAVE_DEFSV)); |
522 | newCONSTSUB (stash, "SAVE_DEFSV", newSViv (SAVE_DEFSV)); |
518 | newCONSTSUB (stash, "SAVE_ERRSV", newSViv (SAVE_ERRSV)); |
523 | newCONSTSUB (stash, "SAVE_ERRSV", newSViv (SAVE_ERRSV)); |
… | |
… | |
539 | RETVAL = coro; |
544 | RETVAL = coro; |
540 | OUTPUT: |
545 | OUTPUT: |
541 | RETVAL |
546 | RETVAL |
542 | |
547 | |
543 | void |
548 | void |
544 | transfer(prev, next, flags = SAVE_DEFAV) |
549 | transfer(prev, next, flags = SAVE_ALL) |
545 | Coro::State_or_hashref prev |
550 | Coro::State_or_hashref prev |
546 | Coro::State_or_hashref next |
551 | Coro::State_or_hashref next |
547 | int flags |
552 | int flags |
548 | PROTOTYPE: @ |
553 | PROTOTYPE: @ |
549 | CODE: |
554 | CODE: |
… | |
… | |
576 | flush_padlist_cache (); |
581 | flush_padlist_cache (); |
577 | #endif |
582 | #endif |
578 | |
583 | |
579 | MODULE = Coro::State PACKAGE = Coro::Cont |
584 | MODULE = Coro::State PACKAGE = Coro::Cont |
580 | |
585 | |
581 | # this is dirty and should be in it's own .xs |
586 | # this is dirty (do you hear me?) and should be in it's own .xs |
582 | |
587 | |
583 | void |
588 | void |
584 | result(...) |
589 | result(...) |
585 | PROTOTYPE: @ |
590 | PROTOTYPE: @ |
586 | CODE: |
591 | CODE: |
… | |
… | |
590 | struct coro *prev, *next; |
595 | struct coro *prev, *next; |
591 | |
596 | |
592 | if (!returnstk) |
597 | if (!returnstk) |
593 | returnstk = SvRV (get_sv ("Coro::Cont::return", FALSE)); |
598 | returnstk = SvRV (get_sv ("Coro::Cont::return", FALSE)); |
594 | |
599 | |
595 | /* set up @_ */ |
600 | /* set up @_ -- ugly */ |
596 | av_clear (defav); |
601 | av_clear (defav); |
597 | av_fill (defav, items - 1); |
602 | av_fill (defav, items - 1); |
598 | while (items--) |
603 | while (items--) |
599 | av_store (defav, items, SvREFCNT_inc (ST(items))); |
604 | av_store (defav, items, SvREFCNT_inc (ST(items))); |
600 | |
605 | |