Changeset 14595 for lang/perl/arguments
- Timestamp:
- 06/25/08 16:51:22 (5 years ago)
- Location:
- lang/perl/arguments/trunk
- Files:
-
- 5 modified
-
Changes (modified) (1 diff)
-
Makefile.PL (modified) (1 diff)
-
arguments.xs (modified) (3 diffs)
-
lib/arguments.pm (modified) (2 diffs)
-
t/arguments.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/arguments/trunk/Changes
r10894 r14595 1 1 Revision history for Perl extension arguments. 2 3 0.03 Wed Jun 25 16:50:19 JST 2008 4 - fixed up 2 5 3 6 0.02 Thu May 1 22:04:15 JST 2008 -
lang/perl/arguments/trunk/Makefile.PL
r10886 r14595 2 2 WriteMakefile( 3 3 NAME => 'arguments', 4 VERSION_FROM => 'lib/arguments.pm', # finds $VERSION5 PREREQ_PM => {}, # e.g., Module::Name => 1.16 LIBS => [''], # e.g., '-lm'7 DEFINE => '', # e.g., '-DHAVE_SOMETHING'4 VERSION_FROM => 'lib/arguments.pm', 5 PREREQ_PM => {}, # e.g., Module::Name => 1.1 6 LIBS => [''], # e.g., '-lm' 7 DEFINE => '', # e.g., '-DHAVE_SOMETHING' 8 8 INC => '-I.', # e.g., '-I. -I/usr/include/other' 9 # Un-comment this if you add C files to link with later:10 # OBJECT => '$(O_FILES)', # link all the C files too11 9 ); -
lang/perl/arguments/trunk/arguments.xs
r10886 r14595 3 3 #include "XSUB.h" 4 4 5 /* copycode from PadWalker.xs */5 /* base xs code from PadWalker.xs */ 6 6 I32 7 dopoptosub_at(pTHX_ PERL_CONTEXT *cxstk, I32 startingblock)7 _dopoptosub_at(pTHX_ PERL_CONTEXT *cxstk, I32 starting_block) 8 8 { 9 9 dTHR; 10 10 I32 i; 11 11 PERL_CONTEXT *cx; 12 for (i = starting block; i >= 0; i--) {12 for (i = starting_block; i >= 0; i--) { 13 13 cx = &cxstk[i]; 14 14 switch (CxTYPE(cx)) { … … 16 16 continue; 17 17 case CXt_SUB: 18 /* In Perl 5.005, formats just used CXt_SUB */ 19 #ifdef CXt_FORMAT 20 case CXt_FORMAT: 18 #ifdef CXt_FORMAT /* In Perl 5.005, formats just used CXt_SUB */ 19 case CXt_FORMAT: 21 20 #endif 22 21 return i; … … 26 25 } 27 26 28 I3229 dopoptosub(pTHX_ I32 startingblock)30 {31 dTHR;32 return dopoptosub_at(aTHX_ cxstack, startingblock);33 }34 35 27 PERL_CONTEXT* 36 upcontext(I32 count, COP **cop_p, PERL_CONTEXT **ccstack_p, 37 I32 *cxix_from_p, I32 *cxix_to_p) 28 _upcontext(pTHX_ I32 count) 38 29 { 39 30 PERL_SI *top_si = PL_curstackinfo; 40 I32 cxix = dopoptosub(aTHX_cxstack_ix);31 I32 cxix = _dopoptosub_at(aTHX_ cxstack, cxstack_ix); 41 32 PERL_CONTEXT *ccstack = cxstack; 42 33 43 if (cxix_from_p) *cxix_from_p = cxstack_ix+1;44 if (cxix_to_p) *cxix_to_p = cxix;45 34 for (;;) { 46 /* we may be in a higher stacklevel, so dig down deeper */47 35 while (cxix < 0 && top_si->si_type != PERLSI_MAIN) { 48 36 top_si = top_si->si_prev; 49 37 ccstack = top_si->si_cxstack; 50 cxix = dopoptosub_at(aTHX_ ccstack, top_si->si_cxix); 51 if (cxix_to_p && cxix_from_p) *cxix_from_p = *cxix_to_p; 52 if (cxix_to_p) *cxix_to_p = cxix; 38 cxix = _dopoptosub_at(aTHX_ ccstack, top_si->si_cxix); 53 39 } 54 if (cxix < 0 && count == 0) { 55 if (ccstack_p) *ccstack_p = ccstack; 56 return (PERL_CONTEXT *)0; 57 } 58 else if (cxix < 0) 59 return (PERL_CONTEXT *)-1; 60 if (PL_DBsub && cxix >= 0 && 61 ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub)) 40 if (cxix < 0) { 41 return (PERL_CONTEXT *) NULL; 42 } 43 if (PL_DBsub && ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub)) 62 44 count++; 63 45 if (!count--) 64 46 break; 65 47 66 if (cop_p) *cop_p = ccstack[cxix].blk_oldcop; 67 cxix = dopoptosub_at(aTHX_ ccstack, cxix - 1); 68 if (cxix_to_p && cxix_from_p) *cxix_from_p = *cxix_to_p; 69 if (cxix_to_p) *cxix_to_p = cxix; 48 cxix = _dopoptosub_at(aTHX_ ccstack, cxix - 1); 70 49 } 71 if (ccstack_p) *ccstack_p = ccstack;72 50 return &ccstack[cxix]; 73 51 } 74 52 75 /* copycode from Devel-Caller/Caller.xs */53 /* base xs code from Devel-Caller/Caller.xs */ 76 54 77 55 MODULE = arguments PACKAGE = arguments 78 PROTOTYPES: DISABLE 56 PROTOTYPES: DISABLE 79 57 80 58 void 81 _upcontext(uplevel)59 upcontext(uplevel) 82 60 I32 uplevel 83 61 PPCODE: 84 XPUSHs(sv_2mortal(newSViv((IV)upcontext(aTHX_ uplevel, 0, 0, 0, 0)))); 62 PERL_CONTEXT *cx = _upcontext(aTHX_ uplevel); 63 if (!cx) { 64 ST(0) = sv_2mortal(newRV( (SV *) NULL) ); 65 } else { 66 if (cx->cx_type != CXt_SUB) 67 croak("cx_type is %d not CXt_SUB\n", cx->cx_type); 68 if (!cx->blk_sub.cv) 69 croak("Context has no CV!\n"); 70 ST(0) = (SV*) newRV_inc( (SV*) cx->blk_sub.cv ); 71 } 72 XSRETURN(1); 85 73 86 SV*87 _context_cv(context)88 SV* context;89 CODE:90 PERL_CONTEXT *cx = INT2PTR(PERL_CONTEXT *, SvIV(context));91 CV *cur_cv;92 93 if (cx->cx_type != CXt_SUB)94 croak("cx_type is %d not CXt_SUB\n", cx->cx_type);95 96 cur_cv = cx->blk_sub.cv;97 if (!cur_cv)98 croak("Context has no CV!\n");99 100 RETVAL = (SV*) newRV_inc( (SV*) cur_cv );101 OUTPUT:102 RETVAL103 104 -
lang/perl/arguments/trunk/lib/arguments.pm
r10894 r14595 4 4 use warnings; 5 5 6 our $VERSION = '0.0 2';6 our $VERSION = '0.03'; 7 7 8 8 use Exporter; 9 9 our @ISA = qw(Exporter); 10 our @EXPORT = qw(arguments );10 our @EXPORT = qw(arguments callee); 11 11 12 12 sub arguments { … … 26 26 27 27 sub callee { 28 my $cx = _upcontext(1);29 return unless $cx;30 return _context_cv($cx);28 my $cx = upcontext(1); 29 return sub {} unless $cx; 30 return $cx; 31 31 } 32 32 -
lang/perl/arguments/trunk/t/arguments.t
r10894 r14595 17 17 my $x = shift; 18 18 return 1 if ($x <= 1); 19 return $x * arguments::callee->($x - 1);19 return $x * (arguments::callee->($x - 1)); 20 20 }->(5); 21 21 ok($n == 120); 22 23 22 24 23 sub func {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)