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.119 by root, Sat Dec 2 15:41:28 2006 UTC vs.
Revision 1.123 by root, Mon Dec 4 21:56:00 2006 UTC

90 90
91#define NOINLINE attribute ((noinline)) 91#define NOINLINE attribute ((noinline))
92 92
93#include "CoroAPI.h" 93#include "CoroAPI.h"
94 94
95#define TRANSFER_SET_STACKLEVEL 0x8bfbfbfb /* magic cookie */
96
97#ifdef USE_ITHREADS 95#ifdef USE_ITHREADS
98static perl_mutex coro_mutex; 96static perl_mutex coro_mutex;
99# define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0) 97# define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0)
100# define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0) 98# define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0)
101#else 99#else
102# define LOCK (void)0 100# define LOCK (void)0
103# define UNLOCK (void)0 101# define UNLOCK (void)0
104#endif 102#endif
105 103
104struct io_state
105{
106 int errorno;
107 I32 laststype;
108 int laststatval;
109 Stat_t statcache;
110};
111
106static struct CoroAPI coroapi; 112static struct CoroAPI coroapi;
107static AV *main_mainstack; /* used to differentiate between $main and others */ 113static AV *main_mainstack; /* used to differentiate between $main and others */
108static HV *coro_state_stash, *coro_stash; 114static HV *coro_state_stash, *coro_stash;
109static SV *coro_mortal; /* will be freed after next transfer */ 115static SV *coro_mortal; /* will be freed after next transfer */
110 116
143 coro_cctx *cctx; 149 coro_cctx *cctx;
144 150
145 /* data associated with this coroutine (initial args) */ 151 /* data associated with this coroutine (initial args) */
146 AV *args; 152 AV *args;
147 int refcnt; 153 int refcnt;
148 int flags; 154 int save; /* CORO_SAVE flags */
155 int flags; /* CF_ flags */
149 156
150 /* optionally saved, might be zero */ 157 /* optionally saved, might be zero */
151 AV *defav; 158 AV *defav; /* @_ */
152 SV *defsv; 159 SV *defsv; /* $_ */
153 SV *errsv; 160 SV *errsv; /* $@ */
161 SV *irssv; /* $/ */
162 SV *irssv_sv; /* real $/ cache */
154 163
155#define VAR(name,type) type name; 164#define VAR(name,type) type name;
156# include "state.h" 165# include "state.h"
157#undef VAR 166#undef VAR
158 167
281} 290}
282 291
283#define SB do { 292#define SB do {
284#define SE } while (0) 293#define SE } while (0)
285 294
286#define LOAD(state) load_state ((state))
287#define SAVE(state,flags) save_state ((state),(flags))
288
289#define REPLACE_SV(sv,val) SB SvREFCNT_dec (sv); (sv) = (val); (val) = 0; SE 295#define REPLACE_SV(sv,val) SB SvREFCNT_dec (sv); (sv) = (val); (val) = 0; SE
290 296
291static void 297static void
292load_state (Coro__State c) 298load_perl (Coro__State c)
293{ 299{
294#define VAR(name,type) PL_ ## name = c->name; 300#define VAR(name,type) PL_ ## name = c->name;
295# include "state.h" 301# include "state.h"
296#undef VAR 302#undef VAR
297 303
298 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); 304 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav);
299 if (c->defsv) REPLACE_SV (DEFSV , c->defsv); 305 if (c->defsv) REPLACE_SV (DEFSV , c->defsv);
300 if (c->errsv) REPLACE_SV (ERRSV , c->errsv); 306 if (c->errsv) REPLACE_SV (ERRSV , c->errsv);
307 if (c->irssv)
308 {
309 if (c->irssv == PL_rs || sv_eq (PL_rs, c->irssv))
310 SvREFCNT_dec (c->irssv);
311 else
312 {
313 REPLACE_SV (PL_rs, c->irssv);
314 if (!c->irssv_sv) c->irssv_sv = get_sv ("/", 0);
315 sv_setsv (c->irssv_sv, PL_rs);
316 }
317 }
301 318
302 { 319 {
303 dSP; 320 dSP;
304 CV *cv; 321 CV *cv;
305 322
314 PUTBACK; 331 PUTBACK;
315 } 332 }
316} 333}
317 334
318static void 335static void
319save_state (Coro__State c, int flags) 336save_perl (Coro__State c)
320{ 337{
321 { 338 {
322 dSP; 339 dSP;
323 I32 cxix = cxstack_ix; 340 I32 cxix = cxstack_ix;
324 PERL_CONTEXT *ccstk = cxstack; 341 PERL_CONTEXT *ccstk = cxstack;
372 } 389 }
373 390
374 PUTBACK; 391 PUTBACK;
375 } 392 }
376 393
377 c->defav = flags & TRANSFER_SAVE_DEFAV ? (AV *)SvREFCNT_inc (GvAV (PL_defgv)) : 0; 394 c->defav = c->save & CORO_SAVE_DEFAV ? (AV *)SvREFCNT_inc (GvAV (PL_defgv)) : 0;
378 c->defsv = flags & TRANSFER_SAVE_DEFSV ? SvREFCNT_inc (DEFSV) : 0; 395 c->defsv = c->save & CORO_SAVE_DEFSV ? SvREFCNT_inc (DEFSV) : 0;
379 c->errsv = flags & TRANSFER_SAVE_ERRSV ? SvREFCNT_inc (ERRSV) : 0; 396 c->errsv = c->save & CORO_SAVE_ERRSV ? SvREFCNT_inc (ERRSV) : 0;
397 c->irssv = c->save & CORO_SAVE_IRSSV ? SvREFCNT_inc (PL_rs) : 0;
380 398
381#define VAR(name,type)c->name = PL_ ## name; 399#define VAR(name,type)c->name = PL_ ## name;
382# include "state.h" 400# include "state.h"
383#undef VAR 401#undef VAR
384} 402}
497 515
498 { 516 {
499 dSP; 517 dSP;
500 LOGOP myop; 518 LOGOP myop;
501 519
502 /* I have no idea why this is needed, but it is */
503 PUSHMARK (SP);
504
505 SvREFCNT_dec (GvAV (PL_defgv)); 520 SvREFCNT_dec (GvAV (PL_defgv));
506 GvAV (PL_defgv) = coro->args; coro->args = 0; 521 GvAV (PL_defgv) = coro->args; coro->args = 0;
507 522
508 Zero (&myop, 1, LOGOP); 523 Zero (&myop, 1, LOGOP);
509 myop.op_next = Nullop; 524 myop.op_next = Nullop;
510 myop.op_flags = OPf_WANT_VOID; 525 myop.op_flags = OPf_WANT_VOID;
511 526
512 PL_op = (OP *)&myop;
513
514 PUSHMARK (SP); 527 PUSHMARK (SP);
515 XPUSHs ((SV *)get_cv ("Coro::State::_coro_init", FALSE)); 528 XPUSHs ((SV *)get_cv ("Coro::State::_coro_init", FALSE));
516 PUTBACK; 529 PUTBACK;
530 PL_op = (OP *)&myop;
517 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); 531 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX);
518 SPAGAIN; 532 SPAGAIN;
519 } 533 }
520 534
521 ENTER; /* necessary e.g. for dounwind */ 535 ENTER; /* necessary e.g. for dounwind */
529 SvREFCNT_dec (coro_mortal); 543 SvREFCNT_dec (coro_mortal);
530 coro_mortal = 0; 544 coro_mortal = 0;
531 } 545 }
532} 546}
533 547
548/* inject a fake call to Coro::State::_cctx_init into the execution */
534static void NOINLINE 549static void NOINLINE
535prepare_cctx (coro_cctx *cctx) 550prepare_cctx (coro_cctx *cctx)
536{ 551{
537 dSP; 552 dSP;
538 LOGOP myop; 553 LOGOP myop;
539 554
540 Zero (&myop, 1, LOGOP); 555 Zero (&myop, 1, LOGOP);
541 myop.op_next = PL_op; 556 myop.op_next = PL_op;
542 myop.op_flags = OPf_WANT_VOID; 557 myop.op_flags = OPf_WANT_VOID | OPf_STACKED;
543
544 sv_setiv (get_sv ("Coro::State::_cctx", FALSE), PTR2IV (cctx));
545 558
546 PUSHMARK (SP); 559 PUSHMARK (SP);
560 EXTEND (SP, 2);
561 PUSHs (sv_2mortal (newSViv (PTR2IV (cctx))));
547 XPUSHs ((SV *)get_cv ("Coro::State::_cctx_init", FALSE)); 562 PUSHs ((SV *)get_cv ("Coro::State::_cctx_init", FALSE));
548 PUTBACK; 563 PUTBACK;
564 PL_op = (OP *)&myop;
549 PL_restartop = PL_ppaddr[OP_ENTERSUB](aTHX); 565 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX);
550 SPAGAIN; 566 SPAGAIN;
551} 567}
552 568
553static void 569static void
554coro_run (void *arg) 570coro_run (void *arg)
555{ 571{
556 /* coro_run is the alternative epilogue of transfer() */ 572 /* coro_run is the alternative tail of transfer(), so unlock here. */
557 UNLOCK; 573 UNLOCK;
558 574
559 /* 575 /*
560 * this is a _very_ stripped down perl interpreter ;) 576 * this is a _very_ stripped down perl interpreter ;)
561 */ 577 */
563 579
564 /* inject call to cctx_init */ 580 /* inject call to cctx_init */
565 prepare_cctx ((coro_cctx *)arg); 581 prepare_cctx ((coro_cctx *)arg);
566 582
567 /* somebody will hit me for both perl_run and PL_restartop */ 583 /* somebody will hit me for both perl_run and PL_restartop */
584 PL_restartop = PL_op;
568 perl_run (PL_curinterp); 585 perl_run (PL_curinterp);
569 586
570 fputs ("FATAL: C coroutine fell over the edge of the world, aborting. Did you call exit in a coroutine?\n", stderr); 587 fputs ("FATAL: C coroutine fell over the edge of the world, aborting. Did you call exit in a coroutine?\n", stderr);
571 abort (); 588 abort ();
572} 589}
581 New (0, cctx, 1, coro_cctx); 598 New (0, cctx, 1, coro_cctx);
582 599
583#if HAVE_MMAP 600#if HAVE_MMAP
584 601
585 cctx->ssize = ((STACKSIZE * sizeof (long) + PAGESIZE - 1) / PAGESIZE + STACKGUARD) * PAGESIZE; 602 cctx->ssize = ((STACKSIZE * sizeof (long) + PAGESIZE - 1) / PAGESIZE + STACKGUARD) * PAGESIZE;
586 /* mmap suppsedly does allocate-on-write for us */ 603 /* mmap supposedly does allocate-on-write for us */
587 cctx->sptr = mmap (0, cctx->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); 604 cctx->sptr = mmap (0, cctx->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
588 605
589 if (cctx->sptr == (void *)-1) 606 if (cctx->sptr == (void *)-1)
590 { 607 {
591 perror ("FATAL: unable to mmap stack for coroutine"); 608 perror ("FATAL: unable to mmap stack for coroutine");
681 cctx_first = cctx; 698 cctx_first = cctx;
682} 699}
683 700
684/* never call directly, always through the coro_state_transfer global variable */ 701/* never call directly, always through the coro_state_transfer global variable */
685static void NOINLINE 702static void NOINLINE
686transfer (struct coro *prev, struct coro *next, int flags) 703transfer (struct coro *prev, struct coro *next)
687{ 704{
688 dSTACKLEVEL; 705 dSTACKLEVEL;
689 706
690 /* sometimes transfer is only called to set idle_sp */ 707 /* sometimes transfer is only called to set idle_sp */
691 if (flags == TRANSFER_SET_STACKLEVEL) 708 if (!next)
692 ((coro_cctx *)prev)->idle_sp = STACKLEVEL; 709 ((coro_cctx *)prev)->idle_sp = STACKLEVEL;
693 else if (prev != next) 710 else if (prev != next)
694 { 711 {
695 coro_cctx *prev__cctx; 712 coro_cctx *prev__cctx;
696 713
718 if (next->flags & CF_NEW) 735 if (next->flags & CF_NEW)
719 { 736 {
720 /* need to start coroutine */ 737 /* need to start coroutine */
721 next->flags &= ~CF_NEW; 738 next->flags &= ~CF_NEW;
722 /* first get rid of the old state */ 739 /* first get rid of the old state */
723 SAVE (prev, -1); 740 save_perl (prev);
724 /* setup coroutine call */ 741 /* setup coroutine call */
725 setup_coro (next); 742 setup_coro (next);
726 /* need a new stack */ 743 /* need a new stack */
727 assert (!next->stack); 744 assert (!next->stack);
728 } 745 }
729 else 746 else
730 { 747 {
731 /* coroutine already started */ 748 /* coroutine already started */
732 SAVE (prev, flags); 749 save_perl (prev);
733 LOAD (next); 750 load_perl (next);
734 } 751 }
735 752
736 prev__cctx = prev->cctx; 753 prev__cctx = prev->cctx;
737 754
738 /* possibly "free" the cctx */ 755 /* possibly "free" the cctx */
768} 785}
769 786
770struct transfer_args 787struct transfer_args
771{ 788{
772 struct coro *prev, *next; 789 struct coro *prev, *next;
773 int flags;
774}; 790};
775 791
776#define TRANSFER(ta) transfer ((ta).prev, (ta).next, (ta).flags) 792#define TRANSFER(ta) transfer ((ta).prev, (ta).next)
777 793
778static void 794static void
779coro_state_destroy (struct coro *coro) 795coro_state_destroy (struct coro *coro)
780{ 796{
781 if (coro->refcnt--) 797 if (coro->refcnt--)
782 return; 798 return;
783 799
784 if (coro->mainstack && coro->mainstack != main_mainstack) 800 if (coro->mainstack && coro->mainstack != main_mainstack)
785 { 801 {
786 struct coro temp; 802 struct coro temp;
803 Zero (&temp, 1, struct coro);
804 temp.save = CORO_SAVE_ALL;
787 805
788 if (coro->flags & CF_RUNNING) 806 if (coro->flags & CF_RUNNING)
789 croak ("FATAL: tried to destroy currently running coroutine"); 807 croak ("FATAL: tried to destroy currently running coroutine");
790 808
791 SAVE ((&temp), TRANSFER_SAVE_ALL); 809 save_perl (&temp);
792 LOAD (coro); 810 load_perl (coro);
793 811
794 coro_destroy_stacks (); 812 coro_destroy_stacks ();
795 813
796 LOAD ((&temp)); /* this will get rid of defsv etc.. */ 814 load_perl (&temp); /* this will get rid of defsv etc.. */
797 815
798 coro->mainstack = 0; 816 coro->mainstack = 0;
799 } 817 }
800 818
801 cctx_destroy (coro->cctx); 819 cctx_destroy (coro->cctx);
856 assert (mg->mg_type == PERL_MAGIC_ext); 874 assert (mg->mg_type == PERL_MAGIC_ext);
857 return (struct coro *)mg->mg_ptr; 875 return (struct coro *)mg->mg_ptr;
858} 876}
859 877
860static void 878static void
861prepare_transfer (struct transfer_args *ta, SV *prev, SV *next, int flags) 879prepare_transfer (struct transfer_args *ta, SV *prev_sv, SV *next_sv)
862{ 880{
863 ta->prev = SvSTATE (prev); 881 ta->prev = SvSTATE (prev_sv);
864 ta->next = SvSTATE (next); 882 ta->next = SvSTATE (next_sv);
865 ta->flags = flags;
866} 883}
867 884
868static void 885static void
869api_transfer (SV *prev, SV *next, int flags) 886api_transfer (SV *prev_sv, SV *next_sv)
870{ 887{
871 struct transfer_args ta; 888 struct transfer_args ta;
872 889
873 prepare_transfer (&ta, prev, next, flags); 890 prepare_transfer (&ta, prev_sv, next_sv);
874 TRANSFER (ta); 891 TRANSFER (ta);
892}
893
894static int
895api_save (SV *coro_sv, int new_save)
896{
897 struct coro *coro = SvSTATE (coro_sv);
898 int old_save = coro->save;
899
900 if (new_save >= 0)
901 coro->save = new_save;
902
903 return old_save;
875} 904}
876 905
877/** Coro ********************************************************************/ 906/** Coro ********************************************************************/
878 907
879#define PRIO_MAX 3 908#define PRIO_MAX 3
988 assert (!SvROK(prev));//D 1017 assert (!SvROK(prev));//D
989 assert (!SvROK(next));//D 1018 assert (!SvROK(next));//D
990 1019
991 ta->prev = SvSTATE (prev); 1020 ta->prev = SvSTATE (prev);
992 ta->next = SvSTATE (next); 1021 ta->next = SvSTATE (next);
993 ta->flags = TRANSFER_SAVE_ALL;
994 1022
995 assert (ta->flags & CF_READY); 1023 assert (ta->next->flags & CF_READY);
996 ta->next->flags &= ~CF_READY; 1024 ta->next->flags &= ~CF_READY;
997} 1025}
998 1026
999static void 1027static void
1000prepare_cede (struct transfer_args *ta) 1028prepare_cede (struct transfer_args *ta)
1033#endif 1061#endif
1034 BOOT_PAGESIZE; 1062 BOOT_PAGESIZE;
1035 1063
1036 coro_state_stash = gv_stashpv ("Coro::State", TRUE); 1064 coro_state_stash = gv_stashpv ("Coro::State", TRUE);
1037 1065
1038 newCONSTSUB (coro_state_stash, "SAVE_DEFAV", newSViv (TRANSFER_SAVE_DEFAV)); 1066 newCONSTSUB (coro_state_stash, "SAVE_DEFAV", newSViv (CORO_SAVE_DEFAV));
1039 newCONSTSUB (coro_state_stash, "SAVE_DEFSV", newSViv (TRANSFER_SAVE_DEFSV)); 1067 newCONSTSUB (coro_state_stash, "SAVE_DEFSV", newSViv (CORO_SAVE_DEFSV));
1040 newCONSTSUB (coro_state_stash, "SAVE_ERRSV", newSViv (TRANSFER_SAVE_ERRSV)); 1068 newCONSTSUB (coro_state_stash, "SAVE_ERRSV", newSViv (CORO_SAVE_ERRSV));
1069 newCONSTSUB (coro_state_stash, "SAVE_IRSSV", newSViv (CORO_SAVE_IRSSV));
1070 newCONSTSUB (coro_state_stash, "SAVE_ALL", newSViv (CORO_SAVE_ALL));
1041 1071
1042 main_mainstack = PL_mainstack; 1072 main_mainstack = PL_mainstack;
1043 1073
1044 coroapi.ver = CORO_API_VERSION; 1074 coroapi.ver = CORO_API_VERSION;
1045 coroapi.transfer = api_transfer; 1075 coroapi.transfer = api_transfer;
1055 HV *hv; 1085 HV *hv;
1056 int i; 1086 int i;
1057 1087
1058 Newz (0, coro, 1, struct coro); 1088 Newz (0, coro, 1, struct coro);
1059 coro->args = newAV (); 1089 coro->args = newAV ();
1090 coro->save = CORO_SAVE_ALL;
1060 coro->flags = CF_NEW; 1091 coro->flags = CF_NEW;
1061 1092
1062 hv = newHV (); 1093 hv = newHV ();
1063 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro, 0)->mg_flags |= MGf_DUP; 1094 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro, 0)->mg_flags |= MGf_DUP;
1064 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 1095 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
1065 1096
1066 for (i = 1; i < items; i++) 1097 for (i = 1; i < items; i++)
1067 av_push (coro->args, newSVsv (ST (i))); 1098 av_push (coro->args, newSVsv (ST (i)));
1068} 1099}
1069 OUTPUT: 1100 OUTPUT:
1101 RETVAL
1102
1103int
1104save (SV *coro, int new_save = -1)
1105 CODE:
1106 RETVAL = api_save (coro, new_save);
1107 OUTPUT:
1070 RETVAL 1108 RETVAL
1071 1109
1072void 1110void
1073_set_stacklevel (...) 1111_set_stacklevel (...)
1074 ALIAS: 1112 ALIAS:
1082 switch (ix) 1120 switch (ix)
1083 { 1121 {
1084 case 0: 1122 case 0:
1085 ta.prev = (struct coro *)INT2PTR (coro_cctx *, SvIV (ST (0))); 1123 ta.prev = (struct coro *)INT2PTR (coro_cctx *, SvIV (ST (0)));
1086 ta.next = 0; 1124 ta.next = 0;
1087 ta.flags = TRANSFER_SET_STACKLEVEL;
1088 break; 1125 break;
1089 1126
1090 case 1: 1127 case 1:
1091 if (items != 3) 1128 if (items != 2)
1092 croak ("Coro::State::transfer (prev,next,flags) expects three arguments, not %d", items); 1129 croak ("Coro::State::transfer (prev,next) expects two arguments, not %d", items);
1093 1130
1094 prepare_transfer (&ta, ST (0), ST (1), SvIV (ST (2))); 1131 prepare_transfer (&ta, ST (0), ST (1));
1095 break; 1132 break;
1096 1133
1097 case 2: 1134 case 2:
1098 prepare_schedule (&ta); 1135 prepare_schedule (&ta);
1099 break; 1136 break;
1162 1199
1163 { 1200 {
1164 SV *sv = perl_get_sv("Coro::API", 1); 1201 SV *sv = perl_get_sv("Coro::API", 1);
1165 1202
1166 coroapi.schedule = api_schedule; 1203 coroapi.schedule = api_schedule;
1204 coroapi.save = api_save;
1167 coroapi.cede = api_cede; 1205 coroapi.cede = api_cede;
1168 coroapi.ready = api_ready; 1206 coroapi.ready = api_ready;
1169 coroapi.is_ready = api_is_ready; 1207 coroapi.is_ready = api_is_ready;
1170 coroapi.nready = &coro_nready; 1208 coroapi.nready = &coro_nready;
1171 coroapi.current = coro_current; 1209 coroapi.current = coro_current;
1173 GCoroAPI = &coroapi; 1211 GCoroAPI = &coroapi;
1174 sv_setiv (sv, (IV)&coroapi); 1212 sv_setiv (sv, (IV)&coroapi);
1175 SvREADONLY_on (sv); 1213 SvREADONLY_on (sv);
1176 } 1214 }
1177} 1215}
1216
1217void
1218_set_current (SV *current)
1219 PROTOTYPE: $
1220 CODE:
1221 SvREFCNT_dec (SvRV (coro_current));
1222 SvRV_set (coro_current, SvREFCNT_inc (SvRV (current)));
1178 1223
1179int 1224int
1180prio (Coro::State coro, int newprio = 0) 1225prio (Coro::State coro, int newprio = 0)
1181 ALIAS: 1226 ALIAS:
1182 nice = 1 1227 nice = 1
1218 CODE: 1263 CODE:
1219 RETVAL = coro_nready; 1264 RETVAL = coro_nready;
1220 OUTPUT: 1265 OUTPUT:
1221 RETVAL 1266 RETVAL
1222 1267
1223void
1224_set_current (SV *current)
1225 PROTOTYPE: $
1226 CODE:
1227 SvREFCNT_dec (SvRV (coro_current));
1228 SvRV_set (coro_current, SvREFCNT_inc (SvRV (current)));
1229
1230MODULE = Coro::State PACKAGE = Coro::AIO 1268MODULE = Coro::State PACKAGE = Coro::AIO
1231 1269
1232SV * 1270SV *
1233_get_state () 1271_get_state ()
1234 CODE: 1272 CODE:
1235{ 1273{
1236 struct { 1274 struct io_state *data;
1237 int errorno;
1238 int laststype;
1239 int laststatval;
1240 Stat_t statcache;
1241 } data;
1242 1275
1276 RETVAL = newSV (sizeof (struct io_state));
1277 data = (struct io_state *)SvPVX (RETVAL);
1278 SvCUR_set (RETVAL, sizeof (struct io_state));
1279 SvPOK_only (RETVAL);
1280
1243 data.errorno = errno; 1281 data->errorno = errno;
1244 data.laststype = PL_laststype; 1282 data->laststype = PL_laststype;
1245 data.laststatval = PL_laststatval; 1283 data->laststatval = PL_laststatval;
1246 data.statcache = PL_statcache; 1284 data->statcache = PL_statcache;
1247
1248 RETVAL = newSVpvn ((char *)&data, sizeof data);
1249} 1285}
1250 OUTPUT: 1286 OUTPUT:
1251 RETVAL 1287 RETVAL
1252 1288
1253void 1289void
1254_set_state (char *data_) 1290_set_state (char *data_)
1255 PROTOTYPE: $ 1291 PROTOTYPE: $
1256 CODE: 1292 CODE:
1257{ 1293{
1258 struct { 1294 struct io_state *data = (void *)data_;
1259 int errorno;
1260 int laststype;
1261 int laststatval;
1262 Stat_t statcache;
1263 } *data = (void *)data_;
1264 1295
1265 errno = data->errorno; 1296 errno = data->errorno;
1266 PL_laststype = data->laststype; 1297 PL_laststype = data->laststype;
1267 PL_laststatval = data->laststatval; 1298 PL_laststatval = data->laststatval;
1268 PL_statcache = data->statcache; 1299 PL_statcache = data->statcache;
1269} 1300}
1301

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines