http://qs321.pair.com?node_id=667963

nobull has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to install Net::SSLeay.

It is failing to test correctly and I've traced the problem to the following.

sub AUTOLOAD { # This AUTOLOAD is used to 'autoload' constants from the constant( +) # XS function. If a constant is not found then control is passed # to the AUTOLOAD in AutoLoader. my $constname; ($constname = $AUTOLOAD) =~ s/.*:://; my $val = constant($constname); if ($! != 0) { if ($! =~ /((Invalid)|(not valid))/i || $!{EINVAL}) { $AutoLoader::AUTOLOAD = $AUTOLOAD; goto &AutoLoader::AUTOLOAD; } else { croak "Your vendor has not defined SSLeay macro $constname"; } } eval "sub $AUTOLOAD { $val }"; goto &$AUTOLOAD; }
Where constant is defined in C as
static double constant(char* name) { errno = 0; switch (*name) { case 'A': if (strEQ(name, "AT_MD5_WITH_RSA_ENCRYPTION")) #ifdef SSL_AT_MD5_WITH_RSA_ENCRYPTION return SSL_AT_MD5_WITH_RSA_ENCRYPTION; #else goto not_there; #endif break; /* Snip similar for B..Z */ case '_': if (strEQ(name, "_TEST_INVALID_CONSTANT")) goto not_there; } errno = EINVAL; return 0; not_there: errno = ENOENT; return 0; }

The problem is that setting errno within the XS code is not propagated to the Perl $! variable.

The build process does keep warning me...

*** Be sure to use the same compiler and options to compile your OpenSSL, perl, and Net::SSLeay. Mixing and matching compilers is not supported.

I guess I shouldn't have ignored that warning. Or rather I shouldn't have thought it meant I should mix GCC v Microsoft v Intel compilers.

My Perl build is a binary from ActiveState, v5.8.8 MSWin32-x86-multi-thread build 820. This was built using the Microsoft compiler. My compiler is Microsoft 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86. I'm guessing these are sufficiently "different" that the errno symbol ends up bound to different variables in auto/Net/SSLeay.dll from it is in perl58.dll. My OpenSSL is a binary download from somewhere.

I've noticed that a lot of people (not just Perl users) seem to use Windows, and many of them download programs/libraries as compiled binaries rather than source. (Indeed I've even noticed that Windows doesn't install the C compiler be default). So how do people get away with such reckless behaviour if Microsoft's compilers are so grossly incompatible between versions?

I've hacked the code of Net::SSLeay so that it doesn't attempt to pass information from the XS code to the Perl via errno and if I get it working I may submit a patch but I can't help wondering if I'm doing the wrong thing.