# ----- Makefile.PL ----- use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'StringTest', 'VERSION_FROM' => 'StringTest.pm', 'PREREQ_PM' => {}, 'LIBS' => [], 'DEFINE' => '', 'INC' => '', ); # ----- StringTest.pm ----- package StringTest; require 5.00503; use strict; use warnings; require Exporter; require DynaLoader; our @ISA = qw(Exporter DynaLoader); our @EXPORT_OK = qw(set); our $VERSION = '1.00'; bootstrap StringTest $VERSION; 1; # ------ StringTest.xs ------ #include "EXTERN.h" #include "perl.h" #include "XSUB.h" MODULE = StringTest PACKAGE = StringTest SV *set(SV *s, IV l) CODE: { char *str = malloc(l); int i; memcpy(str, SvPVX(s, l), l); // OK // debug the copy printf("(l=%d) ", l); for (i=0;i