ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/State.xs
(Generate patch)

Comparing Coro/Coro/State.xs (file contents):
Revision 1.178 by root, Wed Oct 3 01:48:06 2007 UTC vs.
Revision 1.180 by root, Wed Oct 3 17:12:20 2007 UTC

383{ 383{
384#define VAR(name,type) PL_ ## name = c->name; 384#define VAR(name,type) PL_ ## name = c->name;
385# include "state.h" 385# include "state.h"
386#undef VAR 386#undef VAR
387 387
388 GvSV (PL_defgv) = c->defsv; 388 GvSV (PL_defgv) = c->defsv;
389 GvAV (PL_defgv) = c->defav; 389 GvAV (PL_defgv) = c->defav;
390 GvSV (PL_errgv) = c->errsv; 390 GvSV (PL_errgv) = c->errsv;
391 GvIOp(PL_defoutgv) = c->deffh; 391 PL_defoutgv = c->deffh;
392 PL_rs = c->irssv; 392 PL_rs = c->irssv;
393 GvSV (irsgv) = c->irssv_sv; 393 GvSV (irsgv) = c->irssv_sv;
394 394
395 { 395 {
396 dSP; 396 dSP;
397 CV *cv; 397 CV *cv;
398 398
459 } 459 }
460 460
461 c->defav = GvAV (PL_defgv); 461 c->defav = GvAV (PL_defgv);
462 c->defsv = DEFSV; 462 c->defsv = DEFSV;
463 c->errsv = ERRSV; 463 c->errsv = ERRSV;
464 c->deffh = GvIOp (PL_defoutgv); 464 c->deffh = PL_defoutgv;
465 c->irssv = PL_rs; 465 c->irssv = PL_rs;
466 c->irssv_sv = GvSV (irsgv); 466 c->irssv_sv = GvSV (irsgv);
467 467
468#define VAR(name,type)c->name = PL_ ## name; 468#define VAR(name,type)c->name = PL_ ## name;
469# include "state.h" 469# include "state.h"
582} 582}
583 583
584/** coroutine stack handling ************************************************/ 584/** coroutine stack handling ************************************************/
585 585
586static void 586static void
587setup_coro (pTHX_ struct coro *coro) 587coro_setup (pTHX_ struct coro *coro)
588{ 588{
589 /* 589 /*
590 * emulate part of the perl startup here. 590 * emulate part of the perl startup here.
591 */ 591 */
592 coro_init_stacks (aTHX); 592 coro_init_stacks (aTHX);
601 PL_restartop = 0; 601 PL_restartop = 0;
602 602
603 GvSV (PL_defgv) = NEWSV (0, 0); 603 GvSV (PL_defgv) = NEWSV (0, 0);
604 GvAV (PL_defgv) = coro->args; coro->args = 0; 604 GvAV (PL_defgv) = coro->args; coro->args = 0;
605 GvSV (PL_errgv) = NEWSV (0, 0); 605 GvSV (PL_errgv) = NEWSV (0, 0);
606 GvSV (irsgv) = newSVsv (PL_rs); 606 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0);
607 PL_rs = newSVpvn ("\n", 1); 607 PL_rs = newSVsv (GvSV (irsgv));
608 608
609 { 609 {
610 IO *io = newIO (); 610 IO *io = newIO ();
611 PL_defoutgv = newGVgen ("Coro");
611 GvIOp(PL_defoutgv) = io; 612 GvIOp(PL_defoutgv) = io;
612 IoTYPE (io) = IoTYPE_WRONLY; 613 IoTYPE (io) = IoTYPE_WRONLY;
613 IoOFP (io) = IoIFP (io) = PerlIO_stdout (); 614 IoOFP (io) = IoIFP (io) = PerlIO_stdout ();
614 IoFLAGS (io) |= IOf_FLUSH; 615 IoFLAGS (io) |= IOf_FLUSH;
615 } 616 }
632 633
633 ENTER; /* necessary e.g. for dounwind */ 634 ENTER; /* necessary e.g. for dounwind */
634} 635}
635 636
636static void 637static void
637destroy_coro (pTHX_ struct coro *coro) 638coro_destroy (pTHX_ struct coro *coro)
638{ 639{
639 if (!IN_DESTRUCT) 640 if (!IN_DESTRUCT)
640 { 641 {
641 /* restore all saved variables and stuff */ 642 /* restore all saved variables and stuff */
642 LEAVE_SCOPE (0); 643 LEAVE_SCOPE (0);
654 } 655 }
655 656
656 SvREFCNT_dec (GvSV (PL_defgv)); 657 SvREFCNT_dec (GvSV (PL_defgv));
657 SvREFCNT_dec (GvAV (PL_defgv)); 658 SvREFCNT_dec (GvAV (PL_defgv));
658 SvREFCNT_dec (GvSV (PL_errgv)); 659 SvREFCNT_dec (GvSV (PL_errgv));
659 SvREFCNT_dec (GvIOp(PL_defoutgv)); 660 SvREFCNT_dec (PL_defoutgv);
660 SvREFCNT_dec (PL_rs); 661 SvREFCNT_dec (PL_rs);
661 SvREFCNT_dec (GvSV (irsgv)); 662 SvREFCNT_dec (GvSV (irsgv));
662 663
663 coro_destroy_stacks (aTHX); 664 coro_destroy_stacks (aTHX);
664} 665}
1017 /* need to start coroutine */ 1018 /* need to start coroutine */
1018 next->flags &= ~CF_NEW; 1019 next->flags &= ~CF_NEW;
1019 /* first get rid of the old state */ 1020 /* first get rid of the old state */
1020 save_perl (aTHX_ prev); 1021 save_perl (aTHX_ prev);
1021 /* setup coroutine call */ 1022 /* setup coroutine call */
1022 setup_coro (aTHX_ next); 1023 coro_setup (aTHX_ next);
1023 } 1024 }
1024 else 1025 else
1025 { 1026 {
1026 /* coroutine already started */ 1027 /* coroutine already started */
1027 save_perl (aTHX_ prev); 1028 save_perl (aTHX_ prev);
1095 croak ("FATAL: tried to destroy currently running coroutine"); 1096 croak ("FATAL: tried to destroy currently running coroutine");
1096 1097
1097 save_perl (aTHX_ &temp); 1098 save_perl (aTHX_ &temp);
1098 load_perl (aTHX_ coro); 1099 load_perl (aTHX_ coro);
1099 1100
1100 destroy_coro (aTHX_ coro); 1101 coro_destroy (aTHX_ coro);
1101 1102
1102 load_perl (aTHX_ &temp); /* this will get rid of defsv etc.. */ 1103 load_perl (aTHX_ &temp); /* this will get rid of defsv etc.. */
1103 1104
1104 coro->mainstack = 0; 1105 coro->mainstack = 0;
1105 } 1106 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines