Changeset 14595 for lang/perl/arguments

Show
Ignore:
Timestamp:
06/25/08 16:51:22 (5 months ago)
Author:
takesako
Message:

fixed up for shibuya.pm#9 XS Nite

Location:
lang/perl/arguments/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/arguments/trunk/Changes

    r10894 r14595  
    11Revision history for Perl extension arguments. 
     2 
     30.03  Wed Jun 25 16:50:19 JST 2008 
     4        - fixed up 
    25 
    360.02  Thu May  1 22:04:15 JST 2008 
  • lang/perl/arguments/trunk/Makefile.PL

    r10886 r14595  
    22WriteMakefile( 
    33    NAME              => 'arguments', 
    4     VERSION_FROM      => 'lib/arguments.pm', # finds $VERSION 
    5     PREREQ_PM         => {}, # e.g., Module::Name => 1.1 
    6     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' 
    88    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 too 
    119); 
  • lang/perl/arguments/trunk/arguments.xs

    r10886 r14595  
    33#include "XSUB.h" 
    44 
    5 /* copy code from PadWalker.xs */ 
     5/* base xs code from PadWalker.xs */ 
    66I32 
    7 dopoptosub_at(pTHX_ PERL_CONTEXT *cxstk, I32 startingblock) 
     7_dopoptosub_at(pTHX_ PERL_CONTEXT *cxstk, I32 starting_block) 
    88{ 
    99    dTHR; 
    1010    I32 i; 
    1111    PERL_CONTEXT *cx; 
    12     for (i = startingblock; i >= 0; i--) { 
     12    for (i = starting_block; i >= 0; i--) { 
    1313        cx = &cxstk[i]; 
    1414        switch (CxTYPE(cx)) { 
     
    1616            continue; 
    1717        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: 
    2120#endif 
    2221            return i; 
     
    2625} 
    2726 
    28 I32 
    29 dopoptosub(pTHX_ I32 startingblock) 
    30 { 
    31     dTHR; 
    32     return dopoptosub_at(aTHX_ cxstack, startingblock); 
    33 } 
    34  
    3527PERL_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)  
    3829{ 
    3930    PERL_SI *top_si = PL_curstackinfo; 
    40     I32 cxix = dopoptosub(aTHX_ cxstack_ix); 
     31    I32 cxix = _dopoptosub_at(aTHX_ cxstack, cxstack_ix); 
    4132    PERL_CONTEXT *ccstack = cxstack; 
    4233 
    43     if (cxix_from_p) *cxix_from_p = cxstack_ix+1; 
    44     if (cxix_to_p)   *cxix_to_p   = cxix; 
    4534    for (;;) { 
    46         /* we may be in a higher stacklevel, so dig down deeper */ 
    4735        while (cxix < 0 && top_si->si_type != PERLSI_MAIN) { 
    4836            top_si  = top_si->si_prev; 
    4937            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); 
    5339        } 
    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)) 
    6244            count++; 
    6345        if (!count--) 
    6446            break; 
    6547 
    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); 
    7049    } 
    71     if (ccstack_p) *ccstack_p = ccstack; 
    7250    return &ccstack[cxix]; 
    7351} 
    7452 
    75 /* copy code from Devel-Caller/Caller.xs */ 
     53/* base xs code from Devel-Caller/Caller.xs */ 
    7654 
    7755MODULE = arguments              PACKAGE = arguments 
    78 PROTOTYPES: DISABLE   
     56PROTOTYPES: DISABLE 
    7957 
    8058void 
    81 _upcontext(uplevel) 
     59upcontext(uplevel) 
    8260I32 uplevel 
    8361  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); 
    8573 
    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     RETVAL 
    103  
    104  
  • lang/perl/arguments/trunk/lib/arguments.pm

    r10894 r14595  
    44use warnings; 
    55 
    6 our $VERSION = '0.02'; 
     6our $VERSION = '0.03'; 
    77 
    88use Exporter; 
    99our @ISA = qw(Exporter); 
    10 our @EXPORT = qw(arguments); 
     10our @EXPORT = qw(arguments callee); 
    1111 
    1212sub arguments { 
     
    2626 
    2727sub 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; 
    3131} 
    3232 
  • lang/perl/arguments/trunk/t/arguments.t

    r10894 r14595  
    1717  my $x = shift; 
    1818  return 1 if ($x <= 1); 
    19   return $x * arguments::callee->($x - 1); 
     19  return $x * (arguments::callee->($x - 1)); 
    2020}->(5); 
    2121ok($n == 120); 
    22  
    2322 
    2423sub func {