
Tony Cook
Recent Actions
-
Commented on Learning XS - Closures
That should work, you might want to set any_ptr to NULL. An option to automatically manage the lifetime of your self object would be to store it in MAGIC. See https://metacpan.org/release/PEVANS/Future-XS-0.13/source/hax/cv_set_anysv_refcounted.c.inc for an example for code that uses CvREFCOUNTED_ANYSV_on() when...
-
Commented on Learning XS - Closures
Another interesting post. HV * stash = newHV(); hv_store(stash, "name", 4, newSVsv(name), 0); hv_store(stash, "happiness", 9, items > 1 ? newSVsv(ST(1)) : newSViv(5), 0); hv_store(stash, "hunger", 6, items > 2 ? newSVsv(ST(2)) : newSViv(5), 0); CvXSUBANY(kitty).any_ptr = (void *)stash; where...
-
Commented on Writing a 1GB file in perl
close $fhandl; system 'sync', 'somefile'; # alternatively use File::Sync on cpan, Or flush and sync the file before closing: $fhandle->flush; $fhandle->sync; $fhandle->close;...
-
Commented on Once more unto the Wide character (U+XXXX) in substitution (s///)
$ perl -Mlocale -MPOSIX=setlocale,LC_ALL \ -We 'setlocale(LC_ALL, "en_AU.iso8859-1"); $_ = "\x{100}"; s/\w//' Wide character (U+100) in substitution (s///) at -e line 1. Wide character (U+100) in substitution (s///) at -e line 1. It warns because the locale in this case...
-
Commented on When Laziness Isn't
The $$ in $$ARGV[0] is being replaced when the alias is created: tony@venus:~$ alias u="perl -le 'system q(uuidgen) for 1..$$ARGV[0]'" tony@venus:~$ alias alias u='perl -le '\''system q(uuidgen) for 1..95370ARGV[0]'\''' The shell doesn't use @ here so @ARGV[0] works. The single...
-
Commented on The Day Perl Stood Still: Unveiling A Hidden Power Over C
Perl uses malloc() to allocate PVs for SVs. If you're using constants with "x" to create the PVs: my $x = "x" x 10000; # constants then that's done at compile-time, and assigning to another SV: my $x = "x"...
-
Commented on Perl 5 Porters Mailing List Summary: October 5th-11th
The issue with globbing isn't that File::Glob shells out, but with miniperl (which can't load File::Glob) or -DPERL_EXTERNAL_GLOB builds, which use csh or perlglob.exe on Win32 to perform glob(). Unfortunately the subject for #126271 is misleading. For #31923, the issue...
-
Commented on Imager from Image::Magick: Trial Run
Could you please open an Imager rt.cpan ticket with the output of: perl Makefile.PL --verbose with some details about the environment variables you had pointing at the headers and libraries? Thanks. WRT ellipses - it's mosly a case of me...
-
Posted Perl 5.18: getline and $/ = \N to Tony Cook
Perl 5.18 will ship with a change in behaviour when using
getline()
(aka the<$handle>
operator) on handles marked as returning Unicode where$/
is a reference to an integer. -
Commented on Perl I/O on scalars for 5.18
This is intended to be part of 5.18 (and I've updated the title). See https://rt.perl.org/rt3/Ticket/Display.html?id=109828 for the discussion....
-
Commented on A perl devops mailing list
There's already one, see: http://lists.perl.org/list/perl-devops.html...
-
Posted Perl I/O on scalars for 5.18 to Tony Cook
From perl 5.17.9, the following:
my $scalar; ... open my $fh, "<", \$scalar or die;
will fail unless
$scalar
contains only code points 0xFF or lower - ie. they can be represented as bytes.Perl's I/O …

Comment Threads
-
Robert Acock commented on
Learning XS - Closures
I have only been learning C/XS for a short period of time, I have touched typemaps but would need to 'experiment' with them more before I could write a post. My current understanding to what they allow you todo is more transparently handle C data types with your XSUBs. For an example you can return your type and then the PTR2IV and INT2PTR logic is done 'automagically' for you.
Cat *
cat_name
Cat *kitty
CODE:
char *name = kitty->name;
...
As for the flaws in my code I guess I need to explicitly destroy the… -
Robert Acock commented on
Learning XS - Closures
Is this the correct way to free the HV?
```
void
euthanase(kitty)
CV * kitty
CODE:
SvREFCNT_dec(CvXSUBANY(kitty).any_ptr);
``` -
Leon Timmermans commented on
Learning XS - Closures
I agree with Tony, using typemaps can make handling C datatypes much easier.
-
bulk88 commented on
Learning XS - Closures
There are SV*/CV* memory and refcnt leaks in this code, see https://www.nntp.perl.org/group/perl.perl5.porters/2025/06/msg270057.html
"XSANY" macro, which is better written as "CvXSUBANY(kitty).any_ptr" or "CvXSUBANY(kitty)" is the correct way to attach and store random private data to a CV*, aslong as the private data's type is <= sizeof(void*). A example of what can not be stuffed inside CvXSUBANY(), is a type NV or a type double, since those are min 8/10/12/16 max bytes long dependi… -
bulk88 commented on
Learning XS - Closures
Nitpicks:
SV * name = *hv_fetch(self, "name", 4, 0);
never hand count a string with your finger or cursor unless there is no other tool in the world available
Perl API has this call for "" string literals that auto calcs the length for you of your string literal
hv_fetchs(stash, "_tie_it", 0);
Next:
RETVAL = newSVpvf("%s curls up and waits for attention", SvPV(name, retlen));
Use type "const char *" and "SvPV_const()" macro where-ever po…

About blogs.perl.org
blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.