SPUG: Inline doesn't like my code

Brian Ingerson briani at activestate.com
Fri Dec 1 18:55:47 CST 2000


Richard,

No need to make a "science project" out of it ;^)

This works:

--------------------------------------8<-------------------------------------
print map {"$_\n"} get_localtime(time);

use Inline C => <<'END_OF_C_CODE';

#include <time.h>

void get_localtime(int utc) {
  struct tm *ltime = localtime(&utc);
  Inline_Stack_Vars;

  Inline_Stack_Reset;
  Inline_Stack_Push(newSViv(ltime->tm_year));
  Inline_Stack_Push(newSViv(ltime->tm_mon));
  Inline_Stack_Push(newSViv(ltime->tm_mday));
  Inline_Stack_Push(newSViv(ltime->tm_hour));
  Inline_Stack_Push(newSViv(ltime->tm_min));
  Inline_Stack_Push(newSViv(ltime->tm_sec));
  Inline_Stack_Push(newSViv(ltime->tm_isdst));
  Inline_Stack_Done;
}
END_OF_C_CODE
--------------------------------------8<-------------------------------------

Any questions?

Brian

starfire at zipcon.net wrote:
> 
> I'm a first-time user of Inline.pm.  The following code generates a
> segmentation fault.  If I step through it with the Perl debugger, the error
> message is "Signal SEGV: No such file or directory".
> 
> Any suggestions?
> 
>    use Inline C => <<'END_OF_C_CODE';
> 
>    #include <time.h>
> 
>    void get_localtime(int utc) {
> 
>       Inline_Stack_Vars;
>       int *utc, seconds;
>       struct tm *ltime;
>       SV* return_value;
> 
>       seconds = Inline_Stack_Item(0);
>       utc = &seconds;
>       ltime = localtime(utc);
> 
>       Inline_Stack_Reset;
>       return_value = ltime->tm_year;
>       Inline_Stack_Push(return_value);
>       return_value = ltime->tm_mon;
>       Inline_Stack_Push(return_value);
>       return_value = ltime->tm_mday;
>       Inline_Stack_Push(return_value);
>       return_value = ltime->tm_hour;
>       Inline_Stack_Push(return_value);
>       return_value = ltime->tm_min;
>       Inline_Stack_Push(return_value);
>       return_value = ltime->tm_sec;
>       Inline_Stack_Push(return_value);
>       return_value = ltime->tm_isdst;
>       Inline_Stack_Push(return_value);
>       Inline_Stack_Done;
>    }
> END_OF_C_CODE
> 
> Richard Anderson                  www.rayCosoft.com                             RayCosoft                         Richard.Anderson at rayCosoft.com
> 
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
>       Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
>   Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
>  For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
>   Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/

-- 
perl -le 'use Inline C=>q{SV*JAxH(char*x){return newSVpvf
("Just Another %s Hacker",x);}};print JAxH+Perl'

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list