in reply to Re: What difference between malloc and Newx, how attach a C string to SV directly?
in thread What difference between malloc and Newx, how attach a C string to SV directly?
#!/usr/bin/perl -- use strict; use warnings; use Inline C => Config => BUILD_NOISY => 1, CLEAN_AFTER_BUILD => 0; use Inline 'C' => <<'CODE', NAME => 'xiaoyafeng'; int ddd(SV* x){ printf("SV* x is %p \n", x); SvUTF8_off(x); SvGROW(x,8); SvCUR_set(x, 8); printf("SvPV(x) is p(%p) \n", SvPV_nolen(x)); printf("SvPV(x) is s(%s) \n", SvPV_nolen(x)); char*buff = SvPV_nolen(x); Copy( "dddddddd", buff , 8, char); printf("SvPV(x) is p(%p) \n", SvPV_nolen(x)); printf("SvPV(x) is s(%s) \n", SvPV_nolen(x)); printf("string buff is p(%p) \n", buff); printf("string buff is s(%s) \n", buff); SvSETMAGIC(x); return 0; } CODE use Devel::Peek qw/ Dump /; my $x = ""; Dump $x; ddd($x); Dump $x; exit( 0 ); __END__ SV = PV(0x3f7a8c) at 0x99bca4 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0xb2ac54 ""\0 CUR = 0 LEN = 12 SV* x is 0099BCA4 SvPV(x) is p(00B2AC54) SvPV(x) is s() SvPV(x) is p(00B2AC54) SvPV(x) is s(ddddddddng) string buff is p(00B2AC54) string buff is s(ddddddddng) SV = PV(0x3f7a8c) at 0x99bca4 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0xb2ac54 "dddddddd" CUR = 8 LEN = 12
|
|---|