Discussion:
Compilation failure on FreeBSD
(too old to reply)
Marvin Humphrey
2005-10-29 18:51:26 UTC
Permalink
Greets,

I've just gotten an RT ticket for my CPAN distribution
Sort::External, a mostly-perl module with a couple functions in XS.
The XS fails to compile "for perl v5.8.2 built for i386-freebsd."
Looking at the errors thrown by make, I'm at a bit of a loss.
bash-2.05b# make
cc -c -DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.2/BSDPAN" -
DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -I/usr/
local/include -O -pipe -march=pentiumpro -DVERSION=\"0.12\" -
DXS_VERSION=\"0.12\" -DPIC -fPIC "-I/usr/local/lib/perl5/5.8.2/mach/
CORE" External.c
External.xs:58: syntax error before `char'
External.xs:61: `encoded_len' undeclared (first use in this function)
External.xs:61: (Each undeclared identifier is reported only once
External.xs:61: for each function it appears in.)
External.xs:91: syntax error before `char'
External.xs:104: `amount_read' undeclared (first use in this function)
External.xs:108: `item_length' undeclared (first use in this function)
External.xs:110: `check' undeclared (first use in this function)
External.xs:110: `read_buf' undeclared (first use in this function)
External.xs:142: `num_items' undeclared (first use in this function)
*** Error code 1
Stop in /usr/local/src/Search-Kinosearch-0.021/Sort-External-0.12.
The line in question is a declaration, preceded by an SvPV macro.

aUV = string_len;
string = SvPV(thing_sv, string_len);

char* encoded_len = end_of_buf; /* <-- line 58 */

(The full function is below, for reference.) Now, what could be
causing a syntax error in the .xs file there?

The second "syntax error" is another declaration, this time following
a New macro, and baffles me for the same reasons. Is this a ppport.h
problem? or ??

Thanks,

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/

#------------------------------------------------------

SV*
_print_to_sortfile (...)
PPCODE:
{
/* get the filehandle we'll print to */
SV* fh_sv_ref = ST(0);
PerlIO* fh = IoOFP( sv_2io(fh_sv_ref) );

int i, check;
SV* thing_sv;
char* string;
STRLEN string_len;
UV aUV;
char buf[(sizeof(UV)*8)/7 + 1];
char* end_of_buf = buf + sizeof(buf);


/* encode len as a BER integer, print len . string */
for (i = 1; i < items; i++) {
thing_sv = ST(i);
string_len = SvCUR(thing_sv);
aUV = string_len;
string = SvPV(thing_sv, string_len);

char* encoded_len = end_of_buf;

do {
*--encoded_len = (char)((aUV & 0x7f) | 0x80);
aUV >>= 7;
} while (aUV);
*(end_of_buf - 1) &= 0x7f;

check = PerlIO_write(fh, encoded_len, (end_of_buf -
encoded_len));
check_io_error(check);
check = PerlIO_write(fh, string, string_len);
check_io_error(check);
}
}
Scott T. Hildreth
2005-10-29 19:03:58 UTC
Permalink
Try moving that declaration to the top of the for loop. I think this
is a gcc version problem. In other words variables have to be declared
before code in the block. Maybe not, give it a try. :-)
Post by Marvin Humphrey
Greets,
I've just gotten an RT ticket for my CPAN distribution
Sort::External, a mostly-perl module with a couple functions in XS.
The XS fails to compile "for perl v5.8.2 built for i386-freebsd."
Looking at the errors thrown by make, I'm at a bit of a loss.
bash-2.05b# make
cc -c -DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.2/BSDPAN" -
DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -I/usr/
local/include -O -pipe -march=pentiumpro -DVERSION=\"0.12\" -
DXS_VERSION=\"0.12\" -DPIC -fPIC "-I/usr/local/lib/perl5/5.8.2/mach/
CORE" External.c
External.xs:58: syntax error before `char'
External.xs:61: `encoded_len' undeclared (first use in this function)
External.xs:61: (Each undeclared identifier is reported only once
External.xs:61: for each function it appears in.)
External.xs:91: syntax error before `char'
External.xs:104: `amount_read' undeclared (first use in this function)
External.xs:108: `item_length' undeclared (first use in this function)
External.xs:110: `check' undeclared (first use in this function)
External.xs:110: `read_buf' undeclared (first use in this function)
External.xs:142: `num_items' undeclared (first use in this function)
*** Error code 1
Stop in /usr/local/src/Search-Kinosearch-0.021/Sort-External-0.12.
The line in question is a declaration, preceded by an SvPV macro.
aUV = string_len;
string = SvPV(thing_sv, string_len);
char* encoded_len = end_of_buf; /* <-- line 58 */
(The full function is below, for reference.) Now, what could be
causing a syntax error in the .xs file there?
The second "syntax error" is another declaration, this time following
a New macro, and baffles me for the same reasons. Is this a ppport.h
problem? or ??
Thanks,
Marvin Humphrey
Rectangular Research
http://www.rectangular.com/
#------------------------------------------------------
SV*
_print_to_sortfile (...)
{
/* get the filehandle we'll print to */
SV* fh_sv_ref = ST(0);
PerlIO* fh = IoOFP( sv_2io(fh_sv_ref) );
int i, check;
SV* thing_sv;
char* string;
STRLEN string_len;
UV aUV;
char buf[(sizeof(UV)*8)/7 + 1];
char* end_of_buf = buf + sizeof(buf);
/* encode len as a BER integer, print len . string */
for (i = 1; i < items; i++) {
thing_sv = ST(i);
string_len = SvCUR(thing_sv);
aUV = string_len;
string = SvPV(thing_sv, string_len);
char* encoded_len = end_of_buf;
do {
*--encoded_len = (char)((aUV & 0x7f) | 0x80);
aUV >>= 7;
} while (aUV);
*(end_of_buf - 1) &= 0x7f;
check = PerlIO_write(fh, encoded_len, (end_of_buf -
encoded_len));
check_io_error(check);
check = PerlIO_write(fh, string, string_len);
check_io_error(check);
}
}
--
Scott T. Hildreth <***@sbcglobal.net>
Muppet
2005-10-30 14:08:52 UTC
Permalink
Post by Scott T. Hildreth
Try moving that declaration to the top of the for loop. I think this
is a gcc version problem. In other words variables have to be declared
before code in the block. Maybe not, give it a try. :-)
Specifically, C89 requires all variables to be declared before any
code in a block, but C99 allows C++-style "declare anywhere"
variables. Newer versions of GCC started allowing this by default.

There are two ways to be safe, both illustrated here:

int
my_xsub (char * foo)
PREINIT:
/* safe place for variable declarations. */
int bar;
char * p;
CODE:
{
/* declare a new block to allow more variable
declarations.
* these may reference things that were initialized
from args. */
int baz = strlen (foo);
...
}
OUTPUT:
RETVAL

To see how this all works together, compare the XS input with the
generated C and you'll get the idea.


--
He's so good, you're gonna rock, and if you don't rock, it's your own
fault.
-- kk, describing the perks of having a very good drummer.
Marvin Humphrey
2005-10-31 12:43:03 UTC
Permalink
On Oct 29, 2005, at 3:03 PM, Scott T. Hildreth wrote:

( a bunch of good stuff )

On Oct 30, 2005, at 6:08 AM, muppet wrote:

( a bunch more good stuff )

Thanks, folks! I just got word from the person who reported the bug
that a version of the file with all the declarations moved to the
PREINIT: section has solved the problem.

I went back to my C text (the Steve Oualline O'Reilly book, copyright
1997), to see how I'd missed this, and it's just not played up.
Maybe if there had been a "C for Perl Programmers" book...

Cheers,

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/

Loading...