Why you should use ppport.h in your XS code modules
The answer comes down to two words: Security and Reliability.
As a bonus, less work on your part.
It's surprising to find that there are modules on CPAN that aren't using
ppport.h that could stand to benefit from it.
ppport.h is a file that is part of the Devel::PPPort distribution. As you
know, Perl has evolved over the years, adding new features, and new API for XS
writers to use. Some of that is to support the new features, and some to make
tasks easier to accomplish. ppport.h implements portions of the API that
people have found desirable to have when a module gets installed in a Perl that
was released before that API element was created. You can write your module
using the latest API, and have it automatically work on old Perls, simply by
#including ppport.h in your XS code. ppport.h generally provides support for
an API element as is reasonably practicable, with many supported to 5.03007.
Importantly, but often overlooked, ppport.h can override buggy early Perl
implementations of an API element. By using it, you get fixed, proper
behavior. That sure beats trying to reproduce a reported problem in your
module that only happens in some ancient Perl, and then try to come up with a
workaround in an area you aren't familiar with.
This is especially important if your XS code interacts with Unicode in any way.
Early versions of the Unicode standard and early Perls allowed things that we
now know are potential attack vectors. Right now, someone could be using your
module to hack into systems, so you are actually being negligent if you don't
If your XS code has preprocessor #if statements that check for the existence of
functions, macros, etc, that are only in later perls, you can generally avoid
that by simply using ppport.h
ppport.h is now being actively developed and supported by perl5 porters, with
hundreds of new commits since we took it over.
If you have had to backport something that isn't currently in ppport.h, send a
pull request so you can stop it from cluttering up your code, and others can
benefit from effort you've already done. I'm eager to get these to improve
ppport.h. The link is
We examine these, and potentially think of edge cases that you didn't, which
will save you headaches down the road.
To use ppport.h, drop a copy of the latest version into your module each time
you release it, and #include it in you XS code.
For more information, see https://metacpan.org/pod/Devel::PPPort
That contains a section "Start using Devel::PPPort for XS projects"
which gives steps to easily fix up your files.