in reply to Re: XS/Inline::C concat *any* two SVs.
in thread XS/Inline::C concat *any* two SVs.
You make quite inconsistent thing in your C subroutine, at the very first step. You either replace SV *a with a new SV or do not, based on its constant-ness. Its a hole for scalar leaks.
I make a copy of the SV*a if it is readonly because otherwise I will get Modification of a read-only value attempted at c:\test\test.pl line 24. when I attempt to append to it. Otherwise, there is no need to copy rw scalars.
What will happen if you do not do "REFCNT_inc" exactly? Will the subroutine work for non-constant scalars?
If I do not increment the refcount, I get <c>
c:\test>test billfred fred billfred Attempt to free unreferenced scalar: SV 0x182445c, Perl interpreter: 0 +x2240d4 at c:\test\test.pl line 32. 1fred Attempt to free unreferenced scalar: SV 0x182445c, Perl interpreter: 0 +x2240d4 at c:\test\test.pl line 35. 1 Attempt to free unreferenced scalar: SV 0x182445c, Perl interpreter: 0 +x2240d4. Attempt to free unreferenced scalar: SV 0x182445c, Perl interpreter: 0 +x2240d4.
Why not write following way: ...
Using your version, which is close to where I started, I get the following results:
c:\test>test billfred Use of uninitialized value in subroutine entry at c:\test\test.pl line + 35. fred billfred 1fred 11
Note:
Ie. With my version, '1' becomes '1fred' becomes '1fred1'.
With yours, '1' becomes '1fred', then becomes '11'.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: XS/Inline::C concat *any* two SVs.
by vkon (Curate) on May 28, 2006 at 10:18 UTC | |
by BrowserUk (Patriarch) on May 28, 2006 at 14:24 UTC | |
by vkon (Curate) on May 28, 2006 at 22:08 UTC | |
by BrowserUk (Patriarch) on May 29, 2006 at 04:29 UTC | |
by vkon (Curate) on May 29, 2006 at 18:49 UTC | |
| |
|
Re^3: XS/Inline::C concat *any* two SVs.
by syphilis (Archbishop) on May 28, 2006 at 10:33 UTC | |
by BrowserUk (Patriarch) on May 28, 2006 at 14:15 UTC | |
by creamygoodness (Curate) on May 28, 2006 at 14:44 UTC | |
by BrowserUk (Patriarch) on May 28, 2006 at 15:20 UTC | |
by BrowserUk (Patriarch) on May 28, 2006 at 15:22 UTC | |
by creamygoodness (Curate) on May 28, 2006 at 15:30 UTC | |
|