Hello everyone,
I apologize for my long absence from this list, but things unfortunately
became rather busy for me after my trip to Europe. I've recently had the
opportunity to pick up this work again, and have put together a patch
against the [relocated] SVN source that addresses some remaining issues.
First, the big ones:
* I've normalized how config.h is handled. Previously, pcre_internal.h
would #include it, some .c/.cc files #included it and others didn't,
sometimes "#ifdef HAVE_CONFIG_H" would be used and other times it
wouldn't, sometimes it preceded the other #includes and other times it
didn't... it was all quite hit-or-miss.
Now, *all* the .c/.cc files (and none of the .h files) have as the first
thing in the file (save for comments) the fragment
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
which is the proper form. This especially affects some of the C++ source
files, as those were not picking up PCRE_STATIC when that was #defined.
* Added all the Windows DLL-export rigmarole to pcrecpp.
One of the issues that the second change brings up, however, is what the
#include behavior of the pcrecpp headers should be. Before, you could pull
in e.g. pcre_stringpiece.h without bothering with pcrecpp.h at all. But
now, pcre_stringpiece.h uses PCRECPP_EXP_DEFN, which is #defined in
pcrecpp.h, and you need that definition. So maybe pcre_stringpiece.h should
#include pcrecpp.h. But currently, pcrecpp.h #includes pcre_stringpiece.h
for convenience purposes, and changing that behavior may or may not be
disruptive. I just went with adding extra #include directives to the
appropriate .cc files.
So, someone who can speak authoritatively for pcrecpp will need to look
over my changes, and massage them in with informed consideration. I just
got it to where everything compiles with minimal warnings and messiness.
Also, on a side note... Philip, have you built PCRE without recursion and
without UTF-8 support recently?
pcre_exec.c: In function 'match':
pcre_exec.c:4184: error: label 'L_RM46' used but not defined
pcre_exec.c:4184: error: label 'L_RM45' used but not defined
pcre_exec.c:4184: error: label 'L_RM44' used but not defined
pcre_exec.c:4184: error: label 'L_RM42' used but not defined
[maybe 15 more of these...]
This is from the unmodified 7.2 source, and I get it from SVN as well.
Anyway. My patch is attached, and below follows a walk-through of the
changes therein. The highly repetitive bits have been elided.
==> pcrecpp.h
* Added bits to #define PCRECPP_EXP_{DECL,DEFN} appropriately
* Added PCRECPP_EXP_{DECL,DEFN} to variable and class declarations
==> pcrecpp.c
* Quashed a handful of "missing initializer for ..." warnings
==> pcreposix.h
* We need export directives here too, for when we build pcreposix.dll
==> dftables.c
* Added the proper config.h bit to the generated code output
==> pcre_internal.h
* Removed the config.h bit, as that belongs in the .c/.cc files
* #Define PCRE_DEFINITION, to activate dllexport directives
* Tossed the DLL_EXPORT bits, and replaced them with PCRE_STATIC---those
two symbols basically serve the same purpose
* Removed a bogus empty preprocessor line
==> pcre_compile.c
* Quashed an integer-signedness warning
==> CMakeLists.txt
* It was building PCRE without recursion by default! This has been fixed.
* Tweaked the install paths slightly
==> pcregrep.c
* Quashed some integer-signedness warnings
--Daniel
--
NAME = Daniel Richard G. ## Remember, skunks _\|/_ meef?
EMAIL1 = skunk@??? ## don't smell bad--- (/o|o\) /
EMAIL2 = skunk@??? ## it's the people who < (^),>
WWW = http://www.******.org/ ## annoy them that do! / \
--
(****** = site not yet online)
Index: pcrecpp.h
===================================================================
--- pcrecpp.h (revision 190)
+++ pcrecpp.h (working copy)
@@ -331,6 +331,30 @@
#include <string>
+
+/* When an application links to a PCRE DLL in Windows, the symbols that are
+imported have to be identified as such. When building PCRE, the appropriate
+export settings are needed. */
+
+#ifdef _WIN32
+# ifndef PCRE_STATIC
+# ifdef PCRE_DEFINITION
+# define PCRECPP_EXP_DECL extern __declspec(dllexport)
+# define PCRECPP_EXP_DEFN __declspec(dllexport)
+# else
+# define PCRECPP_EXP_DECL extern __declspec(dllimport)
+# define PCRECPP_EXP_DEFN __declspec(dllimport)
+# endif
+# endif
+#endif
+
+/* By default, we use the standard "extern" declarations. */
+
+#ifndef PCRECPP_EXP_DECL
+# define PCRECPP_EXP_DECL extern
+# define PCRECPP_EXP_DEFN
+#endif
+
#include <pcrecpparg.h> // defines the Arg class
// These aren't technically needed here, but we include them
// anyway so folks who include pcrecpp.h don't have to include
@@ -348,7 +372,7 @@
(all_options_ & o) == o
// We convert user-passed pointers into special Arg objects
-extern Arg no_arg;
+PCRECPP_EXP_DECL Arg no_arg;
/***** Compiling regular expressions: the RE class *****/
@@ -356,7 +380,7 @@
// along with other options we put on top of pcre.
// Only 9 modifiers, plus match_limit and match_limit_recursion,
// are supported now.
-class RE_Options {
+class PCRECPP_EXP_DEFN RE_Options {
public:
// constructor
RE_Options() : match_limit_(0), match_limit_recursion_(0), all_options_(0) {}
@@ -488,7 +512,7 @@
// Interface for regular expression matching. Also corresponds to a
// pre-compiled regular expression. An "RE" object is safe for
// concurrent use by multiple threads.
-class RE {
+class PCRECPP_EXP_DEFN RE {
public:
// We provide implicit conversions from strings so that users can
// pass in a string or a "const char*" wherever an "RE" is expected.
Index: pcre_scanner_unittest.cc
===================================================================
--- pcre_scanner_unittest.cc (revision 190)
+++ pcre_scanner_unittest.cc (working copy)
@@ -32,9 +32,14 @@
// Unittest for scanner, especially GetNextComments and GetComments()
// functionality.
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <stdio.h>
#include <string>
#include <vector>
+#include <pcrecpp.h>
#include <pcre_stringpiece.h>
#include <pcre_scanner.h>
Index: pcre_scanner.cc
===================================================================
--- pcre_scanner.cc (revision 190)
+++ pcre_scanner.cc (working copy)
@@ -29,9 +29,13 @@
//
// Author: Sanjay Ghemawat
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <vector>
#include <assert.h>
-#include "config.h"
+#define PCRE_DEFINITION
#include "pcre_scanner.h"
using std::vector;
Index: pcre_ord2utf8.c
===================================================================
--- pcre_ord2utf8.c (revision 190)
+++ pcre_ord2utf8.c (working copy)
@@ -42,6 +42,10 @@
character value into a UTF8 string. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
Index: pcre_fullinfo.c
===================================================================
--- pcre_fullinfo.c (revision 190)
+++ pcre_fullinfo.c (working copy)
@@ -42,6 +42,10 @@
information about a compiled pattern. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
Index: pcre_version.c
===================================================================
--- pcre_version.c (revision 190)
+++ pcre_version.c (working copy)
@@ -42,6 +42,10 @@
string that identifies the PCRE version that is in use. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
Index: pcre_refcount.c
===================================================================
--- pcre_refcount.c (revision 190)
+++ pcre_refcount.c (working copy)
@@ -43,6 +43,10 @@
pattern data block. This might be helpful in applications where the block is
shared by different users. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
Index: pcrecpp.cc
===================================================================
--- pcrecpp.cc (revision 190)
+++ pcrecpp.cc (working copy)
@@ -45,8 +45,8 @@
// from pcre_internal.h. It would probably be better just to include that.
#define PCRE_DEFINITION /* Win32 __declspec(export) trigger for .dll */
#include <pcre.h>
-#include "pcre_stringpiece.h"
#include "pcrecpp.h"
+#include "pcre_stringpiece.h"
namespace pcrecpp {
@@ -56,7 +56,7 @@
static const int kVecSize = (1 + kMaxArgs) * 3; // results + PCRE workspace
// Special object that stands-in for no argument
-Arg no_arg((void*)NULL);
+PCRECPP_EXP_DEFN Arg no_arg((void*)NULL);
// If a regular expression has no error, its error_ field points here
static const string empty_string;
@@ -463,7 +463,7 @@
return 0;
}
- pcre_extra extra = { 0 };
+ pcre_extra extra = { 0, 0, 0, 0, 0, 0 };
if (options_.match_limit() > 0) {
extra.flags |= PCRE_EXTRA_MATCH_LIMIT;
extra.match_limit = options_.match_limit();
Index: pcrecpparg.h.in
===================================================================
--- pcrecpparg.h.in (revision 190)
+++ pcrecpparg.h.in (working copy)
@@ -51,7 +51,7 @@
}
};
-class Arg {
+class PCRECPP_EXP_DEFN Arg {
public:
// Empty constructor so we can declare arrays of Arg
Arg();
Index: pcre_info.c
===================================================================
--- pcre_info.c (revision 190)
+++ pcre_info.c (working copy)
@@ -43,6 +43,10 @@
deprecated, as it has been superseded by pcre_fullinfo(). */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
Index: pcre_scanner.h
===================================================================
--- pcre_scanner.h (revision 190)
+++ pcre_scanner.h (working copy)
@@ -52,7 +52,7 @@
namespace pcrecpp {
-class Scanner {
+class PCRECPP_EXP_DEFN Scanner {
public:
Scanner();
explicit Scanner(const std::string& input);
Index: pcreposix.c
===================================================================
--- pcreposix.c (revision 190)
+++ pcreposix.c (working copy)
@@ -42,6 +42,11 @@
functions. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <pcre.h>
#include "pcre_internal.h"
#include "pcreposix.h"
#include "stdlib.h"
Index: pcre_valid_utf8.c
===================================================================
--- pcre_valid_utf8.c (revision 190)
+++ pcre_valid_utf8.c (working copy)
@@ -42,6 +42,10 @@
strings. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
Index: pcreposix.h
===================================================================
--- pcreposix.h (revision 190)
+++ pcreposix.h (working copy)
@@ -110,9 +110,14 @@
export settings are needed. */
#ifdef _WIN32
-# ifndef PCREPOSIX_STATIC
-# define PCREPOSIX_EXP_DECL extern __declspec(dllimport)
-# define PCREPOSIX_EXP_DEFN __declspec(dllimport)
+# ifndef PCRE_STATIC
+# ifdef PCRE_DEFINITION
+# define PCREPOSIX_EXP_DECL extern __declspec(dllexport)
+# define PCREPOSIX_EXP_DEFN __declspec(dllexport)
+# else
+# define PCREPOSIX_EXP_DECL extern __declspec(dllimport)
+# define PCREPOSIX_EXP_DEFN __declspec(dllimport)
+# endif
# endif
#endif
Index: pcre_study.c
===================================================================
--- pcre_study.c (revision 190)
+++ pcre_study.c (working copy)
@@ -42,6 +42,10 @@
supporting functions. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
Index: pcre_tables.c
===================================================================
--- pcre_tables.c (revision 190)
+++ pcre_tables.c (working copy)
@@ -44,6 +44,10 @@
clashes with the library. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
Index: dftables.c
===================================================================
--- dftables.c (revision 190)
+++ dftables.c (working copy)
@@ -43,6 +43,10 @@
locale. Now that pcre_maketables is a function visible to the outside world, we
make use of its code from here in order to be consistent. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <ctype.h>
#include <stdio.h>
#include <string.h>
@@ -105,6 +109,9 @@
"Pulling in the header ensures that the array gets flagged as \"someone\n"
"outside this compilation unit might reference this\" and so it will always\n"
"be supplied to the linker. */\n\n"
+ "#ifdef HAVE_CONFIG_H\n"
+ "# include <config.h>\n"
+ "#endif\n\n"
"#include \"pcre_internal.h\"\n\n");
fprintf(f,
"const unsigned char _pcre_default_tables[] = {\n\n"
Index: pcre_stringpiece_unittest.cc
===================================================================
--- pcre_stringpiece_unittest.cc (revision 190)
+++ pcre_stringpiece_unittest.cc (working copy)
@@ -1,9 +1,14 @@
// Copyright 2003 and onwards Google Inc.
// Author: Sanjay Ghemawat
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <stdio.h>
#include <map>
#include <algorithm> // for make_pair
+#include <pcrecpp.h>
#include <pcre_stringpiece.h>
// CHECK dies with a fatal error if condition is not true. It is *not*
Index: pcre_internal.h
===================================================================
--- pcre_internal.h (revision 190)
+++ pcre_internal.h (working copy)
@@ -67,10 +67,6 @@
#endif
-/* Get the definitions provided by running "configure" */
-
-#include "config.h"
-
/* Standard C headers plus the external interface definition. The only time
setjmp and stdarg are used is when NO_RECURSE is set. */
@@ -83,6 +79,8 @@
#include <stdlib.h>
#include <string.h>
+#define PCRE_DEFINITION
+
/* When compiling a DLL for Windows, the exported symbols have to be declared
using some MS magic. I found some useful information on this web page:
http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the
@@ -112,7 +110,7 @@
#ifndef PCRE_EXP_DECL
# ifdef _WIN32
-# ifdef DLL_EXPORT
+# ifndef PCRE_STATIC
# define PCRE_EXP_DECL extern __declspec(dllexport)
# define PCRE_EXP_DEFN __declspec(dllexport)
# define PCRE_EXP_DATA_DEFN __declspec(dllexport)
@@ -121,7 +119,6 @@
# define PCRE_EXP_DEFN
# define PCRE_EXP_DATA_DEFN
# endif
-#
# else
# ifdef __cplusplus
# define PCRE_EXP_DECL extern "C"
Index: pcre_exec.c
===================================================================
--- pcre_exec.c (revision 190)
+++ pcre_exec.c (working copy)
@@ -42,6 +42,10 @@
pattern matching using an NFA algorithm, trying to mimic Perl as closely as
possible. There are also some static supporting functions. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#define NLBLOCK md /* Block containing newline information */
#define PSSTART start_subject /* Field containing processed string start */
#define PSEND end_subject /* Field containing processed string end */
Index: pcre_stringpiece.h.in
===================================================================
--- pcre_stringpiece.h.in (revision 190)
+++ pcre_stringpiece.h.in (working copy)
@@ -54,7 +54,7 @@
namespace pcrecpp {
-class StringPiece {
+class PCRECPP_EXP_DEFN StringPiece {
private:
const char* ptr_;
int length_;
Index: pcre_compile.c
===================================================================
--- pcre_compile.c (revision 190)
+++ pcre_compile.c (working copy)
@@ -42,6 +42,10 @@
supporting internal functions that are not used by other modules. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#define NLBLOCK cd /* Block containing newline information */
#define PSSTART start_pattern /* Field containing processed string start */
#define PSEND end_pattern /* Field containing processed string end */
@@ -701,7 +705,7 @@
*negptr = TRUE;
ptr++;
}
- for (i = 0; i < sizeof(name) - 1; i++)
+ for (i = 0; i < (int)sizeof(name) - 1; i++)
{
c = *(++ptr);
if (c == 0) goto ERROR_RETURN;
Index: pcre_xclass.c
===================================================================
--- pcre_xclass.c (revision 190)
+++ pcre_xclass.c (working copy)
@@ -43,6 +43,10 @@
pcre_exec() and pcre_def_exec(). */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
Index: pcre_newline.c
===================================================================
--- pcre_newline.c (revision 190)
+++ pcre_newline.c (working copy)
@@ -47,6 +47,10 @@
http://unicode.org/unicode/reports/tr18/. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
Index: pcre_config.c
===================================================================
--- pcre_config.c (revision 190)
+++ pcre_config.c (working copy)
@@ -41,6 +41,10 @@
/* This module contains the external function pcre_config(). */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
Index: pcre_maketables.c
===================================================================
--- pcre_maketables.c (revision 190)
+++ pcre_maketables.c (working copy)
@@ -45,7 +45,10 @@
#ifndef DFTABLES
-#include "pcre_internal.h"
+# ifdef HAVE_CONFIG_H
+# include <config.h>
+# endif
+# include "pcre_internal.h"
#endif
Index: pcre_ucp_searchfuncs.c
===================================================================
--- pcre_ucp_searchfuncs.c (revision 190)
+++ pcre_ucp_searchfuncs.c (working copy)
@@ -41,6 +41,10 @@
/* This module contains code for searching the table of Unicode character
properties. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
#include "ucp.h" /* Category definitions */
Index: pcre_get.c
===================================================================
--- pcre_get.c (revision 190)
+++ pcre_get.c (working copy)
@@ -43,6 +43,10 @@
for these functions came from Scott Wimer. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
Index: pcre_stringpiece.cc
===================================================================
--- pcre_stringpiece.cc (revision 190)
+++ pcre_stringpiece.cc (working copy)
@@ -30,8 +30,13 @@
// Author: wilsonh@??? (Wilson Hsieh)
//
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <iostream>
-#include "config.h"
+#define PCRE_DEFINITION
+#include "pcrecpp.h"
#include "pcre_stringpiece.h"
std::ostream& operator<<(std::ostream& o, const pcrecpp::StringPiece& piece) {
Index: pcretest.c
===================================================================
--- pcretest.c (revision 190)
+++ pcretest.c (working copy)
@@ -36,6 +36,10 @@
*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <ctype.h>
#include <stdio.h>
#include <string.h>
Index: pcre_try_flipped.c
===================================================================
--- pcre_try_flipped.c (revision 190)
+++ pcre_try_flipped.c (working copy)
@@ -43,6 +43,10 @@
auxiliary local function to flip the appropriate bytes. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
Index: pcre_globals.c
===================================================================
--- pcre_globals.c (revision 190)
+++ pcre_globals.c (working copy)
@@ -46,6 +46,10 @@
all threads. However, when compiling for Virtual Pascal, things are done
differently, and global variables are not used (see pcre.in). */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
#ifndef VPCOMPAT
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt (revision 190)
+++ CMakeLists.txt (working copy)
@@ -58,7 +58,7 @@
SET(PCRE_NEWLINE "LF" CACHE STRING
"What to recognize as a newline (one of CR, LF, CRLF, ANY).")
-SET(PCRE_NO_RECURSE ON CACHE BOOL
+SET(PCRE_NO_RECURSE OFF CACHE BOOL
"If ON, then don't use stack recursion when matching. See NO_RECURSE in config.h.in for details.")
SET(PCRE_POSIX_MALLOC_THRESHOLD "10" CACHE STRING
@@ -218,7 +218,6 @@
ADD_DEFINITIONS(-DHAVE_CONFIG_H)
IF(WIN32)
- # What about -DDLL_EXPORT?
ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
ENDIF(WIN32)
@@ -317,7 +316,10 @@
FILE(GLOB man3 ${CMAKE_SOURCE_DIR}/doc/*.3)
IF(PCRE_BUILD_PCRECPP)
- INSTALL(TARGETS pcrecpp DESTINATION lib)
+ INSTALL(TARGETS pcrecpp
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)
INSTALL(FILES ${PCRECPP_HEADERS} DESTINATION include)
ELSE(PCRE_BUILD_PCRECPP)
# Remove pcrecpp.3
@@ -332,6 +334,6 @@
INSTALL(FILES ${man1} DESTINATION man/man1)
INSTALL(FILES ${man3} DESTINATION man/man3)
-INSTALL(FILES ${html} DESTINATION doc/html)
+INSTALL(FILES ${html} DESTINATION share/doc/pcre/html)
# end CMakeLists.txt
Index: pcrecpp_unittest.cc
===================================================================
--- pcrecpp_unittest.cc (revision 190)
+++ pcrecpp_unittest.cc (working copy)
@@ -33,10 +33,13 @@
//
// TODO: Test extractions for PartialMatch/Consume
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <stdio.h>
#include <cassert>
#include <vector>
-#include "config.h"
#include "pcrecpp.h"
using pcrecpp::StringPiece;
Index: pcre_dfa_exec.c
===================================================================
--- pcre_dfa_exec.c (revision 190)
+++ pcre_dfa_exec.c (working copy)
@@ -44,6 +44,10 @@
applications. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#define NLBLOCK md /* Block containing newline information */
#define PSSTART start_subject /* Field containing processed string start */
#define PSEND end_subject /* Field containing processed string end */
Index: pcregrep.c
===================================================================
--- pcregrep.c (revision 190)
+++ pcregrep.c (working copy)
@@ -855,7 +855,7 @@
t = end_of_line(t, endptr, &endlinelength);
linelength = t - ptr - endlinelength;
- length = multiline? endptr - ptr : linelength;
+ length = multiline? (size_t)(endptr - ptr) : linelength;
/* Extra processing for Jeffrey Friedl's debugging. */
@@ -1625,7 +1625,7 @@
else /* Special case xxx=data */
{
int oplen = equals - op->long_name;
- int arglen = (argequals == NULL)? strlen(arg) : argequals - arg;
+ int arglen = (argequals == NULL)? (int)strlen(arg) : argequals - arg;
if (oplen == arglen && strncmp(arg, op->long_name, oplen) == 0)
{
option_data = arg + arglen;
Index: pcre_chartables.c.dist
===================================================================
--- pcre_chartables.c.dist (revision 190)
+++ pcre_chartables.c.dist (working copy)
@@ -20,6 +20,10 @@
header ensures that the array gets flagged as "someone outside this compilation
unit might reference this" and so it will always be supplied to the linker. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include "pcre_internal.h"
const unsigned char _pcre_default_tables[] = {