[pcre-dev] Patch and vacation

Top Page
Delete this message
Author: Daniel Richard G.
Date:  
To: pcre-dev
Subject: [pcre-dev] Patch and vacation
Hi everyone,

I have one more patch to submit for now, and then I must take leave of you
for two weeks starting on the 1st. I will be out of the country,
vacationing in beautiful Europe.

I've fixed up several issues with the CMake support on Windows, and it is
to the point where everything builds properly. Two caveats, however:

1. Only static libraries can be built at the moment. The DLL import/export
library-interface support foobaz isn't there yet.

2. The test suite does not yet work. Actual CMake program bugs seem to be
the issue, but I won't have time right now to get a minimal test case
and submit a bug report.

Neither of these apply on Unix. There, everything's peachy.


Anyway, a walk-through of the patch:


==== pcre_scanner_unittest.cc ====

* Windows doesn't have snprintf() but _snprintf(), so we work around that

==== config-cmake.h.in ====

* Need to have PCRE_STATIC in there

==== pcre_exec.c, pcre_dfa_exec.c ====

* The cast makes a signedness warning go away (on Linux)

==== RunTest.bat ====

* Revision of the DOS test script. It now accepts the environment
variables %srcdir% and %pcretest% (and uses reasonable defaults if those
are not set), and actually compares the test output against the
reference.

Still to be done: Non-zero exit status on test failure, deactivation of
relevant tests if UTF-8/UCP/etc. is not available, etc.

Something to consider, too: writing a test script in CTest, CMake's
testing framework. This way, the tests could be invoked cleanly on any
platform supported by CMake.

==== CMakeLists.txt ====

* Various fixes and touchups

* Added PCRE_STATIC handling

* Added in the C++ unit test programs

* Write out a CTestCustom.ctest file to pass environment variables to the
test scripts

==== Makefile.am ====

* Added a rule to generate/update pcre.h.generic as needed

Note: Philip, don't forget to add config.h.generic to the repository!

* Need "dist_" prefix on noinst_SCRIPTS to get those files into the tarball


--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: pcre_scanner_unittest.cc
===================================================================
--- pcre_scanner_unittest.cc    (revision 142)
+++ pcre_scanner_unittest.cc    (working copy)
@@ -38,6 +38,10 @@
 #include <pcre_stringpiece.h>
 #include <pcre_scanner.h>


+#ifdef _WIN32
+# define snprintf _snprintf
+#endif
+
#define FLAGS_unittest_stack_size 49152

 // Dies with a fatal error if the two values are not equal.
Index: config-cmake.h.in
===================================================================
--- config-cmake.h.in    (revision 142)
+++ config-cmake.h.in    (working copy)
@@ -11,6 +11,8 @@
 #cmakedefine HAVE_MEMMOVE
 #cmakedefine HAVE_STRERROR


+#cmakedefine PCRE_STATIC
+
 #cmakedefine SUPPORT_UTF8
 #cmakedefine SUPPORT_UCP
 #cmakedefine EBCDIC
Index: pcre_exec.c
===================================================================
--- pcre_exec.c    (revision 142)
+++ pcre_exec.c    (working copy)
@@ -3831,7 +3831,7 @@
 /* Handle different types of newline. The three bits give eight cases. If
 nothing is set at run time, whatever was used at compile time applies. */


-switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : options) &
+switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : (pcre_uint32)options) &
        PCRE_NEWLINE_BITS)
   {
   case 0: newline = NEWLINE; break;   /* Compile-time default */
Index: RunTest.bat
===================================================================
--- RunTest.bat    (revision 142)
+++ RunTest.bat    (working copy)
@@ -1,20 +1,34 @@
-rem This file was contributed by Ralf Junker.
-rem
-rem MS Windows batch file to run pcretest on testfiles with the correct options.
-rem
-rem Assumes that this file as well as pcretest.exe is located in the PCRE root folder.
-rem
-rem Output written to a newly generated subfolder named "testdata".
+@rem  This file was contributed by Ralf Junker, and touched up by
+@rem  Daniel Richard G.
+@rem
+@rem  MS Windows batch file to run pcretest on testfiles with the correct
+@rem  options.
+@rem
+@rem  Output is written to a newly created subfolder named "testdata".


-if not exist .\testout\ md .\testout\
+setlocal

-pcretest -q      testdata\testinput1 > testout\testoutput1
-pcretest -q      testdata\testinput2 > testout\testoutput2
-pcretest -q      testdata\testinput3 > testout\testoutput3
-pcretest -q      testdata\testinput4 > testout\testoutput4
-pcretest -q      testdata\testinput5 > testout\testoutput5
-pcretest -q      testdata\testinput6 > testout\testoutput6
-pcretest -q -dfa testdata\testinput7 > testout\testoutput7
-pcretest -q -dfa testdata\testinput8 > testout\testoutput8
-pcretest -q -dfa testdata\testinput9 > testout\testoutput9
+if [%srcdir%]==[]   set srcdir=.
+if [%pcretest%]==[] set pcretest=pcretest


+if not exist testout md testout
+
+%pcretest% -q      %srcdir%\testdata\testinput1 > testout\testoutput1
+%pcretest% -q      %srcdir%\testdata\testinput2 > testout\testoutput2
+%pcretest% -q      %srcdir%\testdata\testinput3 > testout\testoutput3
+%pcretest% -q      %srcdir%\testdata\testinput4 > testout\testoutput4
+%pcretest% -q      %srcdir%\testdata\testinput5 > testout\testoutput5
+%pcretest% -q      %srcdir%\testdata\testinput6 > testout\testoutput6
+%pcretest% -q -dfa %srcdir%\testdata\testinput7 > testout\testoutput7
+%pcretest% -q -dfa %srcdir%\testdata\testinput8 > testout\testoutput8
+%pcretest% -q -dfa %srcdir%\testdata\testinput9 > testout\testoutput9
+
+fc /n %srcdir%\testdata\testoutput1 testout\testoutput1
+fc /n %srcdir%\testdata\testoutput2 testout\testoutput2
+rem fc /n %srcdir%\testdata\testoutput3 testout\testoutput3
+fc /n %srcdir%\testdata\testoutput4 testout\testoutput4
+fc /n %srcdir%\testdata\testoutput5 testout\testoutput5
+fc /n %srcdir%\testdata\testoutput6 testout\testoutput6
+fc /n %srcdir%\testdata\testoutput7 testout\testoutput7
+fc /n %srcdir%\testdata\testoutput8 testout\testoutput8
+fc /n %srcdir%\testdata\testoutput9 testout\testoutput9
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt    (revision 142)
+++ CMakeLists.txt    (working copy)
@@ -38,12 +38,12 @@
 # (Note: CMakeSetup displays these in alphabetical order, regardless of
 # the order we use here)


-SET(BUILD_SHARED_LIBS "SHARED" CACHE STRING
-    "What type of libraries to build. Set to SHARED or STATIC.")
+SET(BUILD_SHARED_LIBS OFF CACHE BOOL
+    "Build shared libraries instead of static ones.")


OPTION(PCRE_BUILD_PCRECPP "Build the PCRE C++ library (pcrecpp)." ON)

-SET(PCRE_EBCDIC FALSE CACHE BOOL
+SET(PCRE_EBCDIC OFF CACHE BOOL
     "Use EBCDIC coding instead of ASCII. (This is rarely used outside of mainframe systems)")


 SET(PCRE_LINK_SIZE "2" CACHE STRING
@@ -58,16 +58,16 @@
 SET(PCRE_NEWLINE "LF" CACHE STRING
     "What to recognize as a newline (one of CR, LF, CRLF, ANY).")


-SET(PCRE_NO_RECURSE TRUE CACHE BOOL
+SET(PCRE_NO_RECURSE ON 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
     "Threshold for malloc() usage. See POSIX_MALLOC_THRESHOLD in config.h.in for details.")


-SET(PCRE_SUPPORT_UNICODE_PROPERTIES FALSE CACHE BOOL
+SET(PCRE_SUPPORT_UNICODE_PROPERTIES OFF CACHE BOOL
     "Enable support for Unicode properties. (If set, UTF-8 support will be enabled as well)")


-SET(PCRE_SUPPORT_UTF8 FALSE CACHE BOOL
+SET(PCRE_SUPPORT_UTF8 OFF CACHE BOOL
     "Enable support for the Unicode UTF-8 encoding.")


 # Prepare build configuration
@@ -94,6 +94,10 @@
     SET(pcre_have_ulong_long 1)
 ENDIF(HAVE_UNSIGNED_LONG_LONG)


+IF(NOT BUILD_SHARED_LIBS)
+    SET(PCRE_STATIC 1)
+ENDIF(NOT BUILD_SHARED_LIBS)
+
 IF(PCRE_SUPPORT_UTF8 OR PCRE_SUPPORT_UNICODE_PROPERTIES)
     SET(SUPPORT_UTF8 1)
 ENDIF(PCRE_SUPPORT_UTF8 OR PCRE_SUPPORT_UNICODE_PROPERTIES)
@@ -102,23 +106,24 @@
     SET(SUPPORT_UCP 1)
 ENDIF(PCRE_SUPPORT_UNICODE_PROPERTIES)


+SET(NEWLINE "")
+
 IF(PCRE_NEWLINE STREQUAL "LF")
-  SET(NEWLINE "10")
-ELSE(PCRE_NEWLINE STREQUAL "LF")
-  IF(PCRE_NEWLINE STREQUAL "CR")
-    SET(NEWLINE "13")
-  ELSE(PCRE_NEWLINE STREQUAL "CR")
-    IF(PCRE_NEWLINE STREQUAL "CRLF")
-      SET(NEWLINE "3338")
-    ELSE(PCRE_NEWLINE STREQUAL "CRLF")
-      IF(PCRE_NEWLINE STREQUAL "ANY")
+    SET(NEWLINE "10")
+ENDIF(PCRE_NEWLINE STREQUAL "LF")
+IF(PCRE_NEWLINE STREQUAL "CR")
+    SET(NEWLINE "13")
+ENDIF(PCRE_NEWLINE STREQUAL "CR")
+IF(PCRE_NEWLINE STREQUAL "CRLF")
+    SET(NEWLINE "3338")
+ENDIF(PCRE_NEWLINE STREQUAL "CRLF")
+IF(PCRE_NEWLINE STREQUAL "ANY")
     SET(NEWLINE "-1")
-      ELSE(PCRE_NEWLINE STREQUAL "ANY")
+ENDIF(PCRE_NEWLINE STREQUAL "ANY")
+
+IF(NEWLINE STREQUAL "")
     MESSAGE(FATAL_ERROR "The PCRE_NEWLINE variable must be set to one of the following values: \"LF\", \"CR\", \"CRLF\", \"ANY\".")
-      ENDIF(PCRE_NEWLINE STREQUAL "ANY")
-    ENDIF(PCRE_NEWLINE STREQUAL "CRLF")
-  ENDIF(PCRE_NEWLINE STREQUAL "CR")
-ENDIF(PCRE_NEWLINE STREQUAL "LF")
+ENDIF(NEWLINE STREQUAL "")


 IF(PCRE_EBCDIC)
     SET(EBCDIC 1)
@@ -244,18 +249,57 @@
 ADD_EXECUTABLE(pcregrep pcregrep.c)
 TARGET_LINK_LIBRARIES(pcregrep pcreposix)


+IF(PCRE_BUILD_PCRECPP)
+    ADD_EXECUTABLE(pcrecpp_unittest pcrecpp_unittest.cc)
+    TARGET_LINK_LIBRARIES(pcrecpp_unittest pcrecpp)
+
+    ADD_EXECUTABLE(pcre_scanner_unittest pcre_scanner_unittest.cc)
+    TARGET_LINK_LIBRARIES(pcre_scanner_unittest pcrecpp)
+
+    ADD_EXECUTABLE(pcre_stringpiece_unittest pcre_stringpiece_unittest.cc)
+    TARGET_LINK_LIBRARIES(pcre_stringpiece_unittest pcrecpp)
+ENDIF(PCRE_BUILD_PCRECPP)
+
 # Testing


ENABLE_TESTING()

+GET_TARGET_PROPERTY(PCREGREP_EXE pcregrep DEBUG_LOCATION)
+GET_TARGET_PROPERTY(PCRETEST_EXE pcretest DEBUG_LOCATION)
+
+# Write out a CTest configuration file that sets some needed environment
+# variables for the test scripts.
+#
+FILE(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.ctest
+"# This is a generated file.
+SET(ENV{srcdir} ${CMAKE_SOURCE_DIR})
+SET(ENV{pcregrep} ${PCREGREP_EXE})
+SET(ENV{pcretest} ${PCRETEST_EXE})
+")
+
 IF(UNIX)
-    ADD_TEST(test1 sh -c "srcdir=${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/RunTest")
-    ADD_TEST(test2 sh -c "srcdir=${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/RunGrepTest")
-ELSE(UNIX)
-  IF(WIN32)
-    ADD_TEST(test1 ${CMAKE_SOURCE_DIR}/RunTest.bat ${CMAKE_SOURCE_DIR})
-  ENDIF(WIN32)
+    ADD_TEST(pcre_test      ${CMAKE_SOURCE_DIR}/RunTest)
+    ADD_TEST(pcre_grep_test ${CMAKE_SOURCE_DIR}/RunGrepTest)
 ENDIF(UNIX)
+IF(WIN32)
+    ADD_TEST(pcre_test cmd /C ${CMAKE_SOURCE_DIR}/RunTest.bat)
+ENDIF(WIN32)
+
+GET_TARGET_PROPERTY(PCRECPP_UNITTEST_EXE
+                    pcrecpp_unittest
+                    DEBUG_LOCATION)
+
+GET_TARGET_PROPERTY(PCRE_SCANNER_UNITTEST_EXE
+                    pcre_scanner_unittest
+                    DEBUG_LOCATION)
+
+GET_TARGET_PROPERTY(PCRE_STRINGPIECE_UNITTEST_EXE
+                    pcre_stringpiece_unittest
+                    DEBUG_LOCATION)
+
+ADD_TEST(pcrecpp_test          ${PCRECPP_UNITTEST_EXE})
+ADD_TEST(pcre_scanner_test     ${PCRE_SCANNER_UNITTEST_EXE})
+ADD_TEST(pcre_stringpiece_test ${PCRE_STRINGPIECE_UNITTEST_EXE})


# Installation

Index: pcre_dfa_exec.c
===================================================================
--- pcre_dfa_exec.c    (revision 142)
+++ pcre_dfa_exec.c    (working copy)
@@ -2166,7 +2166,7 @@
 /* Handle different types of newline. The three bits give eight cases. If
 nothing is set at run time, whatever was used at compile time applies. */


-switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : options) &
+switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : (pcre_uint32)options) &
          PCRE_NEWLINE_BITS)
   {
   case 0: newline = NEWLINE; break;   /* Compile-time default */
Index: Makefile.am
===================================================================
--- Makefile.am    (revision 142)
+++ Makefile.am    (working copy)
@@ -63,7 +63,7 @@
 # TESTS is for binary unit tests, check_SCRIPTS for script-based tests
 TESTS =
 check_SCRIPTS =
-noinst_SCRIPTS =
+dist_noinst_SCRIPTS =


# Some of the binaries we make are to be installed, and others are
# (non-user-visible) helper programs needed to build libpcre.
@@ -106,6 +106,12 @@
pcre.h.generic \
config.h.generic

+pcre.h.generic: configure.ac
+    rm -f $@
+    cp -p pcre.h $@
+
+MAINTAINERCLEANFILES += pcre.h.generic
+
 # These are the header files we'll install. We do not distribute pcre.h because
 # it is generated from pcre.h.in.
 nodist_include_HEADERS = \
@@ -231,14 +237,14 @@
 # ways. We install these test binaries in case folks find it helpful.


TESTS += RunTest
-noinst_SCRIPTS += RunTest
+dist_noinst_SCRIPTS += RunTest
EXTRA_DIST += RunTest.bat
bin_PROGRAMS += pcretest
pcretest_SOURCES = pcretest.c
pcretest_LDADD = libpcreposix.la

TESTS += RunGrepTest
-noinst_SCRIPTS += RunGrepTest
+dist_noinst_SCRIPTS += RunGrepTest
bin_PROGRAMS += pcregrep
pcregrep_SOURCES = pcregrep.c
pcregrep_LDADD = libpcreposix.la