SlideShare a Scribd company logo
1 of 39
Download to read offline
The Perl Conference 2019 June 16-21
Overloading Perl OPs using XS
ℕicolas ℝ. @atoomic
The Perl Conference 2019 June 16-21
ℕicolas ℝ.
The Perl Conference 2019 June 16-21
ℕicolas ℝ. @atoomic
The Perl Conference 2019 June 16-21
ℕicolas ℝ. @atoomic
The Perl Conference 2019 June 16-21
Overloading Perl OPs using XS
ℕicolas ℝ. @atoomic
Overloading
Perl OPs
using XS
Overloading…
a.k.a. mocking
Overloading
Overloading
…Perl OPs…
sample OP Tree
Printing the OPTree - B::Terse
> perl -MO=Terse,-exec -e '$a = $b + 42’
| perl -p -e 's/(.*)//';
-e syntax OK
OP enter
COP nextstate
SVOP *b
SVOP 42
BINOP add [1]
SVOP *a
BINOP sassign
LISTOP leave [1]
Printing the OPTree - B::Concise
> perl -MO=Concise,-exec -e '$a = $b + 42'
1 <0> enter
2 <;> nextstate(main 1 -e:1) v:{
3 <$> gvsv(*b) s
4 <$> const(IV 42) s
5 <2> add[t1] sK/2
6 <$> gvsv(*a) s
7 <2> sassign vKS/2
8 <@> leave[1 ref] vKP/REFC
-e syntax OK
Perl OPs
> perl -MO=Concise,-exec -e '$f'
1 <0> enter
2 <;> nextstate(main 1 -e:1) v:{
3 <$> gvsv(*f) s
4 <1> srefgen vK/1
5 <@> leave[1 ref] vKP/REFC
Perl OPs - opnames.h
Perl OPs: opcode.h
PP ?
Push / Pop
pp ("push/pop") functions execute the opcodes 

A typical pp function

- expects to find its arguments on the stack, 

- and usually pushes its results onto the stack, 

- hence the 'pp' terminology. 

- Each OP structure contains a pointer to the relevant pp_foo() function.
Perl_PP_ ?
> grep 'PP(' pp.c | sort | head
PP(pp_abs)
PP(pp_aeach)
PP(pp_akeys)
PP(pp_anoncode)
PP(pp_anonconst)
PP(pp_anonhash)
PP(pp_anonlist)
PP(pp_argcheck)
PP(pp_argdefelem)
PP(pp_argelem)
Perl_PP_ ?
Perl OPs
> perl -MO=Concise,-exec -e '$f'
1 <0> enter
2 <;> nextstate(main 1 -e:1) v:{
3 <$> gvsv(*f) s
4 <1> srefgen vK/1
5 <@> leave[1 ref] vKP/REFC
Perl OPs
> perl -MO=Concise,-exec -e '$f'
1 <0> enter
2 <;> nextstate(main 1 -e:1) v:{
3 <$> gvsv(*f) s
4 <1> srefgen vK/1
5 <@> leave[1 ref] vKP/REFC
Overloading
Perl OPs…
…using XS
the glue between C and Perl API
Overloading Perl OPs using XS
Why ? Why ? Why ? Why ? Why ?
OP_DIE
pp_sys.c:456:PP(pp_die)
opnames.h:209: OP_DIE = 192,
*GLOBAL::CORE::die
OP_DIE
> perl die.pl
This is the end at die.pl line 8.
OP_DIE
> perl -MO=Terse,-exec die.pl | perl -pe ’s/(.*)/t/'
OP enter
COP nextstate
LOOP enterloop
REDO =>
COP nextstate
SVOP
UNOP srefgen
SVOP *CORE::GLOBAL::die
UNOP rv2gv
BINOP sassign
LAST =>
BINOP leaveloop
COP nextstate
OP pushmark
SVOP "This is the end"
LISTOP die [2]
COP nextstate
OP pushmark
SVOP "...or not"
LISTOP say
LISTOP leave [1]
OP_DIE
> perl die.pl
Still Alive...
...or not
OP_DIE
> perl -MO=Terse,-exec die.pl | perl -pe ’s/(.*)/t/'
OP enter
COP nextstate
OP pushmark
SVOP "This is the end"
SVOP *CORE::GLOBAL::die
UNOP entersub
COP nextstate
OP pushmark
SVOP "...or not"
LISTOP say
LISTOP leave [1]
Not all OPs can be mocked using
CORE::GLOBAL::*
How to mock ‘-e’? -X?
Not all OPs can be mocked using
CORE::GLOBAL::*
Overloading `-e` check
github.com/atoomic/Overload-FileCheck/tree/demo
Code Demo
-r File is readable by effective uid/gid.
-w File is writable by effective uid/gid.
-x File is executable by effective uid/gid.
-o File is owned by effective uid.
-R File is readable by real uid/gid.
-W File is writable by real uid/gid.
-X File is executable by real uid/gid.
-O File is owned by real uid.
-e File exists.
-z File has zero size (is empty).
-s File has nonzero size (returns size in bytes).
-f File is a plain file.
-d File is a directory.
-l File is a symbolic link (false if symlinks aren't
supported by the file system).
-p File is a named pipe (FIFO), or Filehandle is a pipe.
-S File is a socket.
-b File is a block special file.
-c File is a character special file.
-t Filehandle is opened to a tty.
-u File has setuid bit set.
-g File has setgid bit set.
-k File has sticky bit set.
-T File is an ASCII or UTF-8 text file (heuristic guess).
-B File is a "binary" file (opposite of -T).
-M Script start time minus file modification time, in days.
-A Same for access time.
-C Same for inode change time
> perldoc -f -X
perldoc.perl.org/functions/-X.html
Overload::FileCheck -X
Overload::FileCheck -X
-r -w -x -o -R -W -X
-O -e -z -s -f -d -l -p
-S -b -c -t -u -g -k
-T -B -M -A -C
* boolean / integer
* using stat
* stat($f) && -e _
Overload::FileCheck
github.com/atoomic/Slides-Overload-FileCheck
Bonus Slides
slides…
Test::MockFile -Todd Rinaldo
use Test::MockFile;
# Be sure to assign the output of mocks / scoped
my $mock_file = Test::MockFile->file(
"/foo/bar", “contents"
);
# Does not actually open the file on disk.
open( my $fh, "<", “/foo/bar" ) or die;
say "ok" if -e $fh;
close $fh;
say "ok" if -e "/foo/bar";
Test::MockFile strict mode
use Test::MockFile qw/strict/;
 
# This will not die.
my $file = Test::MockFile->file("/bar", "...");
my $symlink = Test::MockFile->symlink("/foo", "/bar");
-l "/foo" or print "okn";
open(my $fh, ">", "/foo");
 
# All of these will die
open(my $fh, ">", "/unmocked/file"); # Dies
sysopen(my $fh, "/other/file", O_RDONLY);
opendir(my $fh, "/dir");
-e "/file";
-l "/file"
✤ better knowledge of PerlOPs
✤ mocking filesystem for testing
✤ B::C Lazy OPs
✤ B::C Lazy RegExp
✤ p5p improvement for CV
Lessons learned
The Perl Conference 2019 June 16-21
Images: Pixabay License, free for commercial use
Overloading Perl OPs using XS
ℕicolas ℝ.
@atoomic
thank you

More Related Content

What's hot

Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Tom Paulus
 
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Parkpointstechgeeks
 
Stream or not to Stream?

Stream or not to Stream?
Stream or not to Stream?

Stream or not to Stream?
Lukasz Byczynski
 
File handling complete programs in c++
File handling complete programs in c++File handling complete programs in c++
File handling complete programs in c++zain ul hassan
 
C: A Humbling Language
C: A Humbling LanguageC: A Humbling Language
C: A Humbling Languageguestaa63aa
 
Writing and using php streams and sockets
Writing and using php streams and socketsWriting and using php streams and sockets
Writing and using php streams and socketsElizabeth Smith
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS charsbar
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersKirk Kimmel
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Aheadthinkphp
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)julien pauli
 
Value protocols and codables
Value protocols and codablesValue protocols and codables
Value protocols and codablesFlorent Vilmart
 
Debugging concurrency programs in go
Debugging concurrency programs in goDebugging concurrency programs in go
Debugging concurrency programs in goAndrii Soldatenko
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程Weber Tsai
 
Parse, scale to millions
Parse, scale to millionsParse, scale to millions
Parse, scale to millionsFlorent Vilmart
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)charsbar
 

What's hot (20)

Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
 
The Stack and Buffer Overflows
The Stack and Buffer OverflowsThe Stack and Buffer Overflows
The Stack and Buffer Overflows
 
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Park
 
2015 555 kharchenko_ppt
2015 555 kharchenko_ppt2015 555 kharchenko_ppt
2015 555 kharchenko_ppt
 
Stream or not to Stream?

Stream or not to Stream?
Stream or not to Stream?

Stream or not to Stream?

 
File handling complete programs in c++
File handling complete programs in c++File handling complete programs in c++
File handling complete programs in c++
 
Sp ch05
Sp ch05Sp ch05
Sp ch05
 
C: A Humbling Language
C: A Humbling LanguageC: A Humbling Language
C: A Humbling Language
 
Writing and using php streams and sockets
Writing and using php streams and socketsWriting and using php streams and sockets
Writing and using php streams and sockets
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS
 
Php client libray
Php client librayPhp client libray
Php client libray
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Ahead
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
 
Value protocols and codables
Value protocols and codablesValue protocols and codables
Value protocols and codables
 
Debugging concurrency programs in go
Debugging concurrency programs in goDebugging concurrency programs in go
Debugging concurrency programs in go
 
groovy & grails - lecture 4
groovy & grails - lecture 4groovy & grails - lecture 4
groovy & grails - lecture 4
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
 
Parse, scale to millions
Parse, scale to millionsParse, scale to millions
Parse, scale to millions
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)
 

Similar to Overloading Perl OPs using XS

One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them Allegypt
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaewout2
 
2010 Smith Scripting101
2010 Smith Scripting1012010 Smith Scripting101
2010 Smith Scripting101bokonen
 
Happy porting x86 application to android
Happy porting x86 application to androidHappy porting x86 application to android
Happy porting x86 application to androidOwen Hsu
 
03 - Refresher on buffer overflow in the old days
03 - Refresher on buffer overflow in the old days03 - Refresher on buffer overflow in the old days
03 - Refresher on buffer overflow in the old daysAlexandre Moneger
 
Will iPython replace Bash?
Will iPython replace Bash?Will iPython replace Bash?
Will iPython replace Bash?Babel
 
Will iPython replace bash?
Will iPython replace bash?Will iPython replace bash?
Will iPython replace bash?Roberto Polli
 
101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirectsAcácio Oliveira
 
PL/Perl - New Features in PostgreSQL 9.0 201012
PL/Perl - New Features in PostgreSQL 9.0 201012PL/Perl - New Features in PostgreSQL 9.0 201012
PL/Perl - New Features in PostgreSQL 9.0 201012Tim Bunce
 
Perl Tidy Perl Critic
Perl Tidy Perl CriticPerl Tidy Perl Critic
Perl Tidy Perl Criticolegmmiller
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from insidejulien pauli
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MoreMatt Harrison
 
Im trying to run make qemu-nox In a putty terminal but it.pdf
Im trying to run  make qemu-nox  In a putty terminal but it.pdfIm trying to run  make qemu-nox  In a putty terminal but it.pdf
Im trying to run make qemu-nox In a putty terminal but it.pdfmaheshkumar12354
 
Use PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language ParserUse PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language ParserYodalee
 
101 3.2 process text streams using filters
101 3.2 process text streams using filters101 3.2 process text streams using filters
101 3.2 process text streams using filtersAcácio Oliveira
 
101 3.2 process text streams using filters
101 3.2 process text streams using filters101 3.2 process text streams using filters
101 3.2 process text streams using filtersAcácio Oliveira
 

Similar to Overloading Perl OPs using XS (20)

One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
2010 Smith Scripting101
2010 Smith Scripting1012010 Smith Scripting101
2010 Smith Scripting101
 
Happy porting x86 application to android
Happy porting x86 application to androidHappy porting x86 application to android
Happy porting x86 application to android
 
03 - Refresher on buffer overflow in the old days
03 - Refresher on buffer overflow in the old days03 - Refresher on buffer overflow in the old days
03 - Refresher on buffer overflow in the old days
 
Perl Intro 4 Debugger
Perl Intro 4 DebuggerPerl Intro 4 Debugger
Perl Intro 4 Debugger
 
Will iPython replace Bash?
Will iPython replace Bash?Will iPython replace Bash?
Will iPython replace Bash?
 
Will iPython replace bash?
Will iPython replace bash?Will iPython replace bash?
Will iPython replace bash?
 
101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects
 
PL/Perl - New Features in PostgreSQL 9.0 201012
PL/Perl - New Features in PostgreSQL 9.0 201012PL/Perl - New Features in PostgreSQL 9.0 201012
PL/Perl - New Features in PostgreSQL 9.0 201012
 
Membrane protein-ligand tutorial with GROMACS.pdf
Membrane protein-ligand tutorial with GROMACS.pdfMembrane protein-ligand tutorial with GROMACS.pdf
Membrane protein-ligand tutorial with GROMACS.pdf
 
Perl Tidy Perl Critic
Perl Tidy Perl CriticPerl Tidy Perl Critic
Perl Tidy Perl Critic
 
Perl Moderno
Perl ModernoPerl Moderno
Perl Moderno
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
 
Im trying to run make qemu-nox In a putty terminal but it.pdf
Im trying to run  make qemu-nox  In a putty terminal but it.pdfIm trying to run  make qemu-nox  In a putty terminal but it.pdf
Im trying to run make qemu-nox In a putty terminal but it.pdf
 
Use PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language ParserUse PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language Parser
 
effective_r27
effective_r27effective_r27
effective_r27
 
101 3.2 process text streams using filters
101 3.2 process text streams using filters101 3.2 process text streams using filters
101 3.2 process text streams using filters
 
101 3.2 process text streams using filters
101 3.2 process text streams using filters101 3.2 process text streams using filters
101 3.2 process text streams using filters
 

More from ℕicolas ℝ.

2018 Perl Retrospective at Houston.pm
2018 Perl Retrospective at Houston.pm2018 Perl Retrospective at Houston.pm
2018 Perl Retrospective at Houston.pmℕicolas ℝ.
 
Lightning Talk Perl Test mock module
Lightning Talk Perl Test mock moduleLightning Talk Perl Test mock module
Lightning Talk Perl Test mock moduleℕicolas ℝ.
 
Introduction to Perl Internals
Introduction to Perl InternalsIntroduction to Perl Internals
Introduction to Perl Internalsℕicolas ℝ.
 
YAPC::EU 2015 - Perl Conferences
YAPC::EU 2015 - Perl ConferencesYAPC::EU 2015 - Perl Conferences
YAPC::EU 2015 - Perl Conferencesℕicolas ℝ.
 

More from ℕicolas ℝ. (8)

2018 Perl Retrospective at Houston.pm
2018 Perl Retrospective at Houston.pm2018 Perl Retrospective at Houston.pm
2018 Perl Retrospective at Houston.pm
 
Lightning Talk Perl Test mock module
Lightning Talk Perl Test mock moduleLightning Talk Perl Test mock module
Lightning Talk Perl Test mock module
 
Perl XS by example
Perl XS by examplePerl XS by example
Perl XS by example
 
Introduction to Perl Internals
Introduction to Perl InternalsIntroduction to Perl Internals
Introduction to Perl Internals
 
grep.metacpan.org
grep.metacpan.orggrep.metacpan.org
grep.metacpan.org
 
Amazon::Dash::Button
Amazon::Dash::ButtonAmazon::Dash::Button
Amazon::Dash::Button
 
YAPC::EU 2015 - Perl Conferences
YAPC::EU 2015 - Perl ConferencesYAPC::EU 2015 - Perl Conferences
YAPC::EU 2015 - Perl Conferences
 
Perl object ?
Perl object ?Perl object ?
Perl object ?
 

Recently uploaded

VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Roomdivyansh0kumar0
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts servicesonalikaur4
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...aditipandeya
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneRussian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneCall girls in Ahmedabad High profile
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Roomishabajaj13
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 

Recently uploaded (20)

VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service ThaneRussian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
Russian Call Girls Thane Swara 8617697112 Independent Escort Service Thane
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
 

Overloading Perl OPs using XS

  • 1. The Perl Conference 2019 June 16-21 Overloading Perl OPs using XS ℕicolas ℝ. @atoomic
  • 2. The Perl Conference 2019 June 16-21 ℕicolas ℝ.
  • 3. The Perl Conference 2019 June 16-21 ℕicolas ℝ. @atoomic
  • 4. The Perl Conference 2019 June 16-21 ℕicolas ℝ. @atoomic
  • 5. The Perl Conference 2019 June 16-21 Overloading Perl OPs using XS ℕicolas ℝ. @atoomic
  • 11. Printing the OPTree - B::Terse > perl -MO=Terse,-exec -e '$a = $b + 42’ | perl -p -e 's/(.*)//'; -e syntax OK OP enter COP nextstate SVOP *b SVOP 42 BINOP add [1] SVOP *a BINOP sassign LISTOP leave [1]
  • 12. Printing the OPTree - B::Concise > perl -MO=Concise,-exec -e '$a = $b + 42' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> gvsv(*b) s 4 <$> const(IV 42) s 5 <2> add[t1] sK/2 6 <$> gvsv(*a) s 7 <2> sassign vKS/2 8 <@> leave[1 ref] vKP/REFC -e syntax OK
  • 13. Perl OPs > perl -MO=Concise,-exec -e '$f' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> gvsv(*f) s 4 <1> srefgen vK/1 5 <@> leave[1 ref] vKP/REFC
  • 14. Perl OPs - opnames.h
  • 16. PP ? Push / Pop pp ("push/pop") functions execute the opcodes A typical pp function - expects to find its arguments on the stack, - and usually pushes its results onto the stack, - hence the 'pp' terminology. - Each OP structure contains a pointer to the relevant pp_foo() function.
  • 17. Perl_PP_ ? > grep 'PP(' pp.c | sort | head PP(pp_abs) PP(pp_aeach) PP(pp_akeys) PP(pp_anoncode) PP(pp_anonconst) PP(pp_anonhash) PP(pp_anonlist) PP(pp_argcheck) PP(pp_argdefelem) PP(pp_argelem)
  • 19. Perl OPs > perl -MO=Concise,-exec -e '$f' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> gvsv(*f) s 4 <1> srefgen vK/1 5 <@> leave[1 ref] vKP/REFC
  • 20. Perl OPs > perl -MO=Concise,-exec -e '$f' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> gvsv(*f) s 4 <1> srefgen vK/1 5 <@> leave[1 ref] vKP/REFC
  • 22. …using XS the glue between C and Perl API
  • 23. Overloading Perl OPs using XS Why ? Why ? Why ? Why ? Why ?
  • 25. OP_DIE > perl die.pl This is the end at die.pl line 8.
  • 26. OP_DIE > perl -MO=Terse,-exec die.pl | perl -pe ’s/(.*)/t/' OP enter COP nextstate LOOP enterloop REDO => COP nextstate SVOP UNOP srefgen SVOP *CORE::GLOBAL::die UNOP rv2gv BINOP sassign LAST => BINOP leaveloop COP nextstate OP pushmark SVOP "This is the end" LISTOP die [2] COP nextstate OP pushmark SVOP "...or not" LISTOP say LISTOP leave [1]
  • 27. OP_DIE > perl die.pl Still Alive... ...or not
  • 28. OP_DIE > perl -MO=Terse,-exec die.pl | perl -pe ’s/(.*)/t/' OP enter COP nextstate OP pushmark SVOP "This is the end" SVOP *CORE::GLOBAL::die UNOP entersub COP nextstate OP pushmark SVOP "...or not" LISTOP say LISTOP leave [1]
  • 29. Not all OPs can be mocked using CORE::GLOBAL::* How to mock ‘-e’? -X?
  • 30. Not all OPs can be mocked using CORE::GLOBAL::*
  • 32. -r File is readable by effective uid/gid. -w File is writable by effective uid/gid. -x File is executable by effective uid/gid. -o File is owned by effective uid. -R File is readable by real uid/gid. -W File is writable by real uid/gid. -X File is executable by real uid/gid. -O File is owned by real uid. -e File exists. -z File has zero size (is empty). -s File has nonzero size (returns size in bytes). -f File is a plain file. -d File is a directory. -l File is a symbolic link (false if symlinks aren't supported by the file system). -p File is a named pipe (FIFO), or Filehandle is a pipe. -S File is a socket. -b File is a block special file. -c File is a character special file. -t Filehandle is opened to a tty. -u File has setuid bit set. -g File has setgid bit set. -k File has sticky bit set. -T File is an ASCII or UTF-8 text file (heuristic guess). -B File is a "binary" file (opposite of -T). -M Script start time minus file modification time, in days. -A Same for access time. -C Same for inode change time > perldoc -f -X perldoc.perl.org/functions/-X.html Overload::FileCheck -X
  • 33. Overload::FileCheck -X -r -w -x -o -R -W -X -O -e -z -s -f -d -l -p -S -b -c -t -u -g -k -T -B -M -A -C * boolean / integer * using stat * stat($f) && -e _
  • 36. Test::MockFile -Todd Rinaldo use Test::MockFile; # Be sure to assign the output of mocks / scoped my $mock_file = Test::MockFile->file( "/foo/bar", “contents" ); # Does not actually open the file on disk. open( my $fh, "<", “/foo/bar" ) or die; say "ok" if -e $fh; close $fh; say "ok" if -e "/foo/bar";
  • 37. Test::MockFile strict mode use Test::MockFile qw/strict/;   # This will not die. my $file = Test::MockFile->file("/bar", "..."); my $symlink = Test::MockFile->symlink("/foo", "/bar"); -l "/foo" or print "okn"; open(my $fh, ">", "/foo");   # All of these will die open(my $fh, ">", "/unmocked/file"); # Dies sysopen(my $fh, "/other/file", O_RDONLY); opendir(my $fh, "/dir"); -e "/file"; -l "/file"
  • 38. ✤ better knowledge of PerlOPs ✤ mocking filesystem for testing ✤ B::C Lazy OPs ✤ B::C Lazy RegExp ✤ p5p improvement for CV Lessons learned
  • 39. The Perl Conference 2019 June 16-21 Images: Pixabay License, free for commercial use Overloading Perl OPs using XS ℕicolas ℝ. @atoomic thank you