comparison lib/regcomp.c @ 17338:1fff19279ff9

regex: merge patches from libc 2013-02-26 Siddhesh Poyarekar <siddhesh@redhat.com> * lib/regex_internal.h (__attribute__): Rename from __attribute. All uses changed. (bitset_not, bitset_merge, bitset_mask, re_string_char_size_at) (re_string_wchar_at, re_string_elem_size_at): Mark function as possibly unused. 2013-02-12 Andreas Schwab <schwab@suse.de> [BZ #11561] * lib/regcomp.c (parse_bracket_exp) [_LIBC]: When looking up collating elements compare against the byte sequence of it, not its name.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 25 Feb 2013 22:56:12 -0800
parents 7be3e941fb5b
children cd38818bce4e
comparison
equal deleted inserted replaced
17337:cec099cbf54f 17338:1fff19279ff9
2833 const int32_t *symb_table; 2833 const int32_t *symb_table;
2834 const unsigned char *extra; 2834 const unsigned char *extra;
2835 2835
2836 /* Local function for parse_bracket_exp used in _LIBC environment. 2836 /* Local function for parse_bracket_exp used in _LIBC environment.
2837 Seek the collating symbol entry corresponding to NAME. 2837 Seek the collating symbol entry corresponding to NAME.
2838 Return the index of the symbol in the SYMB_TABLE. */ 2838 Return the index of the symbol in the SYMB_TABLE,
2839 or -1 if not found. */
2839 2840
2840 auto inline int32_t 2841 auto inline int32_t
2841 __attribute ((always_inline)) 2842 __attribute ((always_inline))
2842 seek_collating_symbol_entry (name, name_len) 2843 seek_collating_symbol_entry (const unsigned char *name, size_t name_len)
2843 const unsigned char *name; 2844 {
2844 size_t name_len; 2845 int32_t elem;
2845 { 2846
2846 int32_t hash = elem_hash ((const char *) name, name_len); 2847 for (elem = 0; elem < table_size; elem++)
2847 int32_t elem = hash % table_size; 2848 if (symb_table[2 * elem] != 0)
2848 if (symb_table[2 * elem] != 0) 2849 {
2849 { 2850 int32_t idx = symb_table[2 * elem + 1];
2850 int32_t second = hash % (table_size - 2) + 1; 2851 /* Skip the name of collating element name. */
2851 2852 idx += 1 + extra[idx];
2852 do 2853 if (/* Compare the length of the name. */
2853 { 2854 name_len == extra[idx]
2854 /* First compare the hashing value. */ 2855 /* Compare the name. */
2855 if (symb_table[2 * elem] == hash 2856 && memcmp (name, &extra[idx + 1], name_len) == 0)
2856 /* Compare the length of the name. */ 2857 /* Yep, this is the entry. */
2857 && name_len == extra[symb_table[2 * elem + 1]] 2858 return elem;
2858 /* Compare the name. */ 2859 }
2859 && memcmp (name, &extra[symb_table[2 * elem + 1] + 1], 2860 return -1;
2860 name_len) == 0)
2861 {
2862 /* Yep, this is the entry. */
2863 break;
2864 }
2865
2866 /* Next entry. */
2867 elem += second;
2868 }
2869 while (symb_table[2 * elem] != 0);
2870 }
2871 return elem;
2872 } 2861 }
2873 2862
2874 /* Local function for parse_bracket_exp used in _LIBC environment. 2863 /* Local function for parse_bracket_exp used in _LIBC environment.
2875 Look up the collation sequence value of BR_ELEM. 2864 Look up the collation sequence value of BR_ELEM.
2876 Return the value if succeeded, UINT_MAX otherwise. */ 2865 Return the value if succeeded, UINT_MAX otherwise. */
2877 2866
2878 auto inline unsigned int 2867 auto inline unsigned int
2879 __attribute ((always_inline)) 2868 __attribute ((always_inline))
2880 lookup_collation_sequence_value (br_elem) 2869 lookup_collation_sequence_value (bracket_elem_t *br_elem)
2881 bracket_elem_t *br_elem;
2882 { 2870 {
2883 if (br_elem->type == SB_CHAR) 2871 if (br_elem->type == SB_CHAR)
2884 { 2872 {
2885 /* 2873 /*
2886 if (MB_CUR_MAX == 1) 2874 if (MB_CUR_MAX == 1)
2904 if (nrules != 0) 2892 if (nrules != 0)
2905 { 2893 {
2906 int32_t elem, idx; 2894 int32_t elem, idx;
2907 elem = seek_collating_symbol_entry (br_elem->opr.name, 2895 elem = seek_collating_symbol_entry (br_elem->opr.name,
2908 sym_name_len); 2896 sym_name_len);
2909 if (symb_table[2 * elem] != 0) 2897 if (elem != -1)
2910 { 2898 {
2911 /* We found the entry. */ 2899 /* We found the entry. */
2912 idx = symb_table[2 * elem + 1]; 2900 idx = symb_table[2 * elem + 1];
2913 /* Skip the name of collating element name. */ 2901 /* Skip the name of collating element name. */
2914 idx += 1 + extra[idx]; 2902 idx += 1 + extra[idx];
2922 idx += sizeof (unsigned int) * 2910 idx += sizeof (unsigned int) *
2923 (1 + *(unsigned int *) (extra + idx)); 2911 (1 + *(unsigned int *) (extra + idx));
2924 /* Return the collation sequence value. */ 2912 /* Return the collation sequence value. */
2925 return *(unsigned int *) (extra + idx); 2913 return *(unsigned int *) (extra + idx);
2926 } 2914 }
2927 else if (symb_table[2 * elem] == 0 && sym_name_len == 1) 2915 else if (sym_name_len == 1)
2928 { 2916 {
2929 /* No valid character. Match it as a single byte 2917 /* No valid character. Match it as a single byte
2930 character. */ 2918 character. */
2931 return collseqmb[br_elem->opr.name[0]]; 2919 return collseqmb[br_elem->opr.name[0]];
2932 } 2920 }
2944 mbcset->range_ends, is a pointer argument since we may 2932 mbcset->range_ends, is a pointer argument since we may
2945 update it. */ 2933 update it. */
2946 2934
2947 auto inline reg_errcode_t 2935 auto inline reg_errcode_t
2948 __attribute ((always_inline)) 2936 __attribute ((always_inline))
2949 build_range_exp (sbcset, mbcset, range_alloc, start_elem, end_elem) 2937 build_range_exp (bitset_t sbcset, re_charset_t *mbcset, int *range_alloc,
2950 re_charset_t *mbcset; 2938 bracket_elem_t *start_elem, bracket_elem_t *end_elem)
2951 Idx *range_alloc;
2952 bitset_t sbcset;
2953 bracket_elem_t *start_elem, *end_elem;
2954 { 2939 {
2955 unsigned int ch; 2940 unsigned int ch;
2956 uint32_t start_collseq; 2941 uint32_t start_collseq;
2957 uint32_t end_collseq; 2942 uint32_t end_collseq;
2958 2943
3028 COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a 3013 COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a
3029 pointer argument since we may update it. */ 3014 pointer argument since we may update it. */
3030 3015
3031 auto inline reg_errcode_t 3016 auto inline reg_errcode_t
3032 __attribute ((always_inline)) 3017 __attribute ((always_inline))
3033 build_collating_symbol (sbcset, mbcset, coll_sym_alloc, name) 3018 build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset,
3034 re_charset_t *mbcset; 3019 Idx *coll_sym_alloc, const unsigned char *name)
3035 Idx *coll_sym_alloc;
3036 bitset_t sbcset;
3037 const unsigned char *name;
3038 { 3020 {
3039 int32_t elem, idx; 3021 int32_t elem, idx;
3040 size_t name_len = strlen ((const char *) name); 3022 size_t name_len = strlen ((const char *) name);
3041 if (nrules != 0) 3023 if (nrules != 0)
3042 { 3024 {
3043 elem = seek_collating_symbol_entry (name, name_len); 3025 elem = seek_collating_symbol_entry (name, name_len);
3044 if (symb_table[2 * elem] != 0) 3026 if (elem != -1)
3045 { 3027 {
3046 /* We found the entry. */ 3028 /* We found the entry. */
3047 idx = symb_table[2 * elem + 1]; 3029 idx = symb_table[2 * elem + 1];
3048 /* Skip the name of collating element name. */ 3030 /* Skip the name of collating element name. */
3049 idx += 1 + extra[idx]; 3031 idx += 1 + extra[idx];
3050 } 3032 }
3051 else if (symb_table[2 * elem] == 0 && name_len == 1) 3033 else if (name_len == 1)
3052 { 3034 {
3053 /* No valid character, treat it as a normal 3035 /* No valid character, treat it as a normal
3054 character. */ 3036 character. */
3055 bitset_set (sbcset, name[0]); 3037 bitset_set (sbcset, name[0]);
3056 return REG_NOERROR; 3038 return REG_NOERROR;