in reply to Yet Another XS Tutorial
Problems:
Your code won't always compile. PPCODE cannot start with variable declarations as it can be preceded by non-declarations.
should bePPCODE: int i; f();
orPREINIT: int i; PPCODE: f();
PPCODE: { int i; f(); }
Your snippets don't handle magical variables (e.g. $1, %ENV) except sometimes by chance. e.g.
say lengths1(substr("abc", 0, 1)); # 0
lengths1 uses SvLEN when it should be usingSvCUR. e.g.
say lengths1("abc"); # 16
Your snippets suffer from The Unicode bug. e.g. After fixing the above problems,
$_="\x{A0}"; say lengths1($_), "=", length($_); # 1=1 $_="\x{A0}\x{2660}"; chop; say lengths1($_), "=", length($_); # 2=1
lengths1 uses type-based polymorphism —something which should be avoided in Perl— and does it "poorly". e.g. After fixing the above problems,
say lengths1(456), "=", length(456); # 0=3
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Yet Another XS Tutorial
by cdybedahl (Acolyte) on Dec 14, 2013 at 11:34 UTC | |
by ikegami (Patriarch) on Dec 24, 2013 at 16:09 UTC |