Re: [pcre-dev] Calculated match recursion stack size

Top Page
Delete this message
Author: Graycode
Date:  
To: pcre-dev
Subject: Re: [pcre-dev] Calculated match recursion stack size
On Sat, 21 Jan 2012, Philip Hazel wrote:

> But wait: pcretest.c includes the line
>
> #include "pcre_tables.c"
>
> so why do you need it externally as well? It must be a bit more
> complicated...



Oh I didn't see that at all. The key must be that the link errors
originate from the object of pcre_printint vs. pcretest.

pcre_printint.obj : error LNK2001: unresolved external symbol __pcre_OP_lengths
pcre_printint.obj : error LNK2001: unresolved external symbol __pcre_utf8_table3
pcre_printint.obj : error LNK2001: unresolved external symbol __pcre_utf8_table4

pcretest.exe : fatal error LNK1120: 3 unresolved externals

Those missing tables were only missing by the compilation of
pcre_printint.c. Your instincts are keen, it is more complicated than
I'd assumed.

I think the root cause is a few lines above the #include you showed
above from pcretest.c:

#define PCRE_INCLUDED
#undef PRIV
#define PRIV(name) name

#include "pcre_tables.c"


So PRIV(utf8_table3) within a compile of pcretest.c (and its included
pcre_tables.c) would be just 'utf8_table3'.

But pcre_printint.c has no redefinition of PRIV(), it carries the
definition from pcre_internal.h:

#ifdef COMPILE_PCRE8
#define PUBL(name) pcre_##name
#define PRIV(name) _pcre_##name
#else
#ifdef COMPILE_PCRE16
#define PUBL(name) pcre16_##name
#define PRIV(name) _pcre16_##name
#else
#error Unsupported compiling mode
#endif /* COMPILE_PCRE16 */
#endif /* COMPILE_PCRE8 */

So in _printint a reference to PRIV(utf8_table3) expands into being
'_pcre_utf8_table3' or '_pcre16_utf8_table3', which is a different
name than in pcretest.c. That's why an additional compilation of
pcre_tables is needed in order for the linker to resolve the
same-named variables when pcre_printint.c is compiled independently.

Prior versions had a #include of pcre_printint.SRC in pcretest.c,
maybe this was the reason ??


Regards,
Graycode