Perl XS modules and CPAN testers


This page is a collection of the sometimes mysterious error messages from CPAN testers when compiling or running XS modules.

Free to wrong pool

This happens when C malloc is used with the Perl free. It occurs with a Perl built with threads for Windows (MSWin32-x86-multi-thread). One solution of the problem is to use Perl's memory allocators Newx and Safefree as described in perlclib. Another solution may be to undefine Perl's redefinition of "free". See [Win32] "Free to wrong pool ..." error at Perlmonks.

Example 1

Not a CODE reference

This is caused on some systems by giving a value to CCFLAGS in Makefile.PL.

Example 1

error: too few arguments to function 'Perl_vwarn'

This is caused by using the prefix Perl_ when calling functions such as Perl_vwarn and Perl_croak. It can be resolved by using vwarn and croak.

Example 1

Undefined PLT symbol "_Unwind_Resume" (symnum = 166)

This is an error which occurs on the NetBSD operating system. It requires -lgcc_s to be added to the compile line.

Example 1

perl: fatal: relocation error

This is a known error with Perl on Solaris related to the use of different assemblers. See perlsolaris. This error seems to indicate something wrong with the testing computer rather than the program, and is probably not resolvable by the module programmer.

Example 1

Unknown error - dlerror() not implemented

This seems to happen on Linux. The error string is on line 138 of DynaLoader.xs.

Example 1

error: 'my_perl' undeclared


Related to this?


Example 1 Example 2

error C2143: syntax error : missing ';' before 'type'

This is an error of the Microsoft C compiler. It is caused by having a variable declared in the CODE: section of an XS file. Use the PREINIT: section of the XS file instead.

warning: passing argument 3 of 'Perl_sv_2pv_flags' from incompatible pointer type

This bubbles up from uses of the SvPV macro when the programmer uses a non-STRLEN variable for the length of a string on a 64-bit computer:

char * x;
unsigned xlen;
x = SvPV (sv, xlen);

It's actually possible to cause segmentation violation and other memory errors with some combinations of compilers and interpreters, so be diligent about using STRLEN for string lengths:

char * x;
STRLEN xlen;
x = SvPV (sv, xlen);

Example 1

wstat 1280, 0x500

wstat is just the exit status multiplied by 256, which is the number of failed tests multiplied by 256. In the above case there are 5 failed tests, so wstat is 1280.

Example 1

Non-zero wait status: 138

This error occurs in OpenBSD tests of XS modules.

The "non-zero wait status" seems to be 128 + the signal which killed the child process during a call to the system call "wait". So the signal is 10, which means "bus error". In other words, a memory error occurred during the execution which halted the test process and returned this status to the calling process.


Example 1 Example 2

Non-zero wait status: 139

This indicates a segmentation fault error on BSD operating systems.

Bizarre copy of hash in subroutine entry

"Bizarre copy of ... " errors may be caused by a variety of conditions. It's actually an error from the file sv.c where it looks at a variable's type. This fatal error happens when Perl examines a scalar and cannot work out what to do with it.

Generally this indicates some kind of corruption has occurred.

For example, this has happened to me by putting a badly-formatted reference on the stack before calling a Perl routine from C. See perlcall.

Another way this has happened to me is by taking a pointer in the C to a Perl scalar, but forgetting to increment its reference count with SvREFCNT_inc, then when the scalar was eventually used, it had been overwritten, causing this error to occur.

... in subroutine entry

An error with its location given as "in subroutine entry" is occuring within your XS or C code rather than in Perl and the Perl interpreter cannot give the line number. The best it can do is say that the error occurred somewhere after the subroutine that it points to.


error: 'PerlMem_malloc' undeclared here (not in a function); did you mean 'Perl_malloc'?

Macros clash with Windows header files


The solution is to add

#ifdef WIN32
#undef malloc
#undef free
#endif /* def WIN32 */

Example 1

At the time of creating this page, the CPAN testers website was not indexable by Google (it was forbidden or heavily dampened by "robots.txt"). That means when a module author who uses Perl XS to write a module received a bug report with an obscure message like "Free to wrong pool", it was hard to find distributions with similar bugs.

Web links

Copyright © Ben Bullock 2009-2021. All rights reserved. For comments, questions, and corrections, please email Ben Bullock ( or use the discussion group at Google Groups. News about the site. / Privacy / Disclaimer