Ticket #4450: shitty_pcre2.patch

File shitty_pcre2.patch, 8.2 KB (added by broly, 13 months ago)

fix patch corruption issue.

  • config.h.in

     
    66/* Define to enable showing configure arguments in help */ 
    77#undef ENABLE_CONFIGURE_ARGS 
    88 
    9 /* Define to enable support for ext2fs attributes */ 
    10 #undef ENABLE_EXT2FS_ATTR 
    11  
    129/* Define to 1 if translation of program messages to the user's native 
    1310   language is requested. */ 
    1411#undef ENABLE_NLS 
     
    208205/* Define to 1 if you have the <OS.h> header file. */ 
    209206#undef HAVE_OS_H 
    210207 
     208/* Define to 1 if PCRE2 is found */ 
     209#undef HAVE_PCRE2 
     210 
    211211/* Define to 1 if you have the `pmap_getmaps' function. */ 
    212212#undef HAVE_PMAP_GETMAPS 
    213213 
  • lib/search/internal.h

     
    66#ifdef SEARCH_TYPE_GLIB 
    77#define mc_search_regex_t GRegex 
    88#else 
     9#ifdef HAVE_PCRE2 
     10#define mc_search_regex_t pcre2_code 
     11#else 
    912#define mc_search_regex_t pcre 
    1013#endif 
     14#endif 
    1115 
    1216/*** enums ***************************************************************************************/ 
    1317 
  • lib/search/regex.c

     
    342342    } 
    343343    lc_mc_search->num_results = g_match_info_get_match_count (lc_mc_search->regex_match_info); 
    344344#else /* SEARCH_TYPE_GLIB */ 
     345#ifdef HAVE_PCRE2 
     346    lc_mc_search->num_results = pcre2_match (regex,  
     347                                            (unsigned char *) search_str->str, search_str->len, 0, 0, 
     348                                           lc_mc_search->regex_match_info, NULL); 
     349#else 
    345350    lc_mc_search->num_results = pcre_exec (regex, lc_mc_search->regex_match_info, 
    346351                                           search_str->str, search_str->len, 0, 0, 
    347                                            lc_mc_search->iovector, MC_SEARCH__NUM_REPLACE_ARGS); 
     352                                           lc_mc_search->iovector, mc_search__num_replace_args); 
     353#endif 
    348354    if (lc_mc_search->num_results < 0) 
    349355    { 
    350356        return COND__NOT_FOUND; 
     
    832838            return; 
    833839        } 
    834840#else /* SEARCH_TYPE_GLIB */ 
     841#ifdef HAVE_PCRE2 
     842        int errcode; 
     843        char *error = calloc(128, sizeof(char)); 
     844        size_t erroffset; 
     845#else 
    835846        const char *error; 
    836847        int erroffset; 
    837         int pcre_options = PCRE_EXTRA | PCRE_MULTILINE; 
     848#endif 
    838849 
     850        int pcre_options =  
     851#ifdef HAVE_PCRE2 
     852                PCRE2_MULTILINE; 
     853#else            
     854                PCRE_EXTRA | PCRE_MULTILINE; 
     855#endif 
    839856        if (str_isutf8 (charset) && mc_global.utf8_display) 
    840857        { 
    841             pcre_options |= PCRE_UTF8; 
     858            pcre_options |=  
     859#ifdef HAVE_PCRE2 
     860                    PCRE2_UTF; 
     861#else 
     862                    PCRE_UTF8; 
     863#endif 
    842864            if (!lc_mc_search->is_case_sensitive) 
    843                 pcre_options |= PCRE_CASELESS; 
     865                pcre_options |=  
     866#ifdef HAVE_PCRE2 
     867                        PCRE2_CASELESS; 
     868#else 
     869                        PCRE_CASELESS; 
     870#endif 
    844871        } 
    845872        else if (!lc_mc_search->is_case_sensitive) 
    846873        { 
     
    851878            g_string_free (tmp, TRUE); 
    852879        } 
    853880 
     881#ifdef HAVE_PCRE2 
    854882        mc_search_cond->regex_handle = 
     883            pcre2_compile ((unsigned char *) mc_search_cond->str->str, PCRE2_ZERO_TERMINATED, pcre_options, &errcode, &erroffset, NULL); 
     884#else 
     885        mc_search_cond->regex_handle = 
    855886            pcre_compile (mc_search_cond->str->str, pcre_options, &error, &erroffset, NULL); 
     887#endif 
    856888        if (mc_search_cond->regex_handle == NULL) 
    857889        { 
     890#ifdef HAVE_PCRE2 
     891            pcre2_get_error_message(errcode, (unsigned char *) error,128); 
     892#endif 
    858893            mc_search_set_error (lc_mc_search, MC_SEARCH_E_REGEX_COMPILE, "%s", error); 
    859894            return; 
    860895        } 
     896#ifdef HAVE_PCRE2 
     897        if(pcre2_jit_compile(mc_search_cond->regex_handle, PCRE2_JIT_COMPLETE) && strlen(error)) 
     898#else 
    861899        lc_mc_search->regex_match_info = pcre_study (mc_search_cond->regex_handle, 0, &error); 
    862900        if (lc_mc_search->regex_match_info == NULL && error != NULL) 
     901#endif 
    863902        { 
    864903            mc_search_set_error (lc_mc_search, MC_SEARCH_E_REGEX_COMPILE, "%s", error); 
    865904            MC_PTR_FREE (mc_search_cond->regex_handle); 
     905#ifdef HAVE_PCRE2 
     906            MC_PTR_FREE (error); 
     907#endif 
    866908            return; 
    867909        } 
    868910#endif /* SEARCH_TYPE_GLIB */ 
  • lib/search/search.c

     
    6767    mc_search_cond = g_malloc0 (sizeof (mc_search_cond_t)); 
    6868    mc_search_cond->str = mc_g_string_dup (str); 
    6969    mc_search_cond->charset = g_strdup (charset); 
    70  
     70#ifdef HAVE_PCRE2 
     71    lc_mc_search->regex_match_info= pcre2_match_data_create(MC_SEARCH__NUM_REPLACE_ARGS, NULL); 
     72    lc_mc_search->iovector = pcre2_get_ovector_pointer(lc_mc_search->regex_match_info); 
     73#endif 
    7174    switch (lc_mc_search->search_type) 
    7275    { 
    7376    case MC_SEARCH_T_GLOB: 
  • lib/search.h

     
    88#include <sys/types.h> 
    99 
    1010#ifdef SEARCH_TYPE_PCRE 
     11#ifdef HAVE_PCRE2 
     12#define PCRE2_CODE_UNIT_WIDTH 8 
     13#include <pcre2.h> 
     14#else 
    1115#include <pcre.h> 
    1216#endif 
    13  
     17#endif 
    1418/*** typedefs(not structures) and defined constants **********************************************/ 
    1519 
    1620typedef enum mc_search_cbret_t mc_search_cbret_t; 
     
    2428#ifdef SEARCH_TYPE_GLIB 
    2529#define mc_search_matchinfo_t GMatchInfo 
    2630#else 
     31#ifdef HAVE_PCRE2  
     32/* no pcre_extra in PCRE2. pcre2_jit_compile (equivalent of pcre_study) handles  
     33 * all of this internally. but we can use this to hold the pcre2_matches data 
     34 * until the search is complete */ 
     35#define mc_search_matchinfo_t pcre2_match_data 
     36#else 
    2737#define mc_search_matchinfo_t pcre_extra 
    2838#endif 
     39#endif 
    2940 
    3041/*** enums ***************************************************************************************/ 
    3142 
     
    102113    mc_search_matchinfo_t *regex_match_info; 
    103114    GString *regex_buffer; 
    104115#ifdef SEARCH_TYPE_PCRE 
     116#ifdef HAVE_PCRE2 
     117    /* pcre2 will provide a pointer to a match_data structure that can be manipulated like an iovector*/ 
     118    size_t *iovector; 
     119#else 
    105120    int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2]; 
     121#endif 
    106122#endif                          /* SEARCH_TYPE_PCRE */ 
    107123 
    108124    /* private data */ 
  • m4.include/ax_path_lib_pcre.m4

     
    3737 
    3838     OLDLDFLAGS="$LDFLAGS" ; LDFLAGS="$LDFLAGS $test_PCRE_LIBS" 
    3939     OLDCPPFLAGS="$CPPFLAGS" ; CPPFLAGS="$CPPFLAGS $test_PCRE_CPPFLAGS" 
     40      
     41     AC_CHECK_LIB(pcre2-8, pcre2_compile_8, [#define PCRE2_CODE_UNIT_WIDTH 8]) 
    4042 
    41      AC_CHECK_LIB(pcre, pcre_compile) 
     43     if test x"$ac_cv_lib_pcre2_8_pcre2_compile_8" = x"yes" ; then 
     44        AC_MSG_RESULT(setting PCRE_LIBS -L$with_pcre/lib -lpcre2-8) 
    4245 
    43      if test x"$ac_cv_lib_pcre_pcre_compile" = x"yes" ; then 
    44         AC_MSG_RESULT(setting PCRE_LIBS -L$with_pcre/lib -lpcre) 
    45  
    4646        PCRE_LIBS=$test_PCRE_LIBS 
    4747        PCRE_CPPFLAGS=$test_PCRE_CPPFLAGS 
    4848 
    49         AC_MSG_CHECKING([lib pcre]) 
     49        AC_MSG_CHECKING([lib pcre2-8]) 
    5050        AC_MSG_RESULT([$PCRE_LIBS]) 
     51        AC_DEFINE(HAVE_PCRE2, 1, [Define to 1 if PCRE2 is found]) 
    5152        m4_ifval($1,$1) 
    5253     else 
    53         AC_MSG_CHECKING([lib pcre]) 
     54        AC_MSG_CHECKING([lib pcre2-8]) 
    5455        AC_MSG_RESULT([no, (WARNING)]) 
    55         m4_ifval($2,$2) 
    56      fi 
    5756 
     57        AC_CHECK_LIB(pcre, pcre_compile) 
     58 
     59        if test x"$ac_cv_lib_pcre_pcre_compile" = x"yes" ; then 
     60            AC_MSG_RESULT(setting PCRE_LIBS -L$with_pcre/lib -lpcre) 
     61 
     62            PCRE_LIBS=$test_PCRE_LIBS 
     63            PCRE_CPPFLAGS=$test_PCRE_CPPFLAGS 
     64 
     65            AC_MSG_CHECKING([lib pcre]) 
     66            AC_MSG_RESULT([$PCRE_LIBS]) 
     67            m4_ifval($1,$1) 
     68        else 
     69            AC_MSG_CHECKING([lib pcre]) 
     70            AC_MSG_RESULT([no, (WARNING)]) 
     71            m4_ifval($2,$2) 
     72        fi 
     73    fi 
    5874     CPPFLAGS="$OLDCFPPLAGS" 
    5975     LDFLAGS="$OLDLDFLAGS" 
    6076