зеркало из https://github.com/github/ruby.git
Fix onigmo name table without st
Co-authored-by: Adam Hess <HParker@github.com>
This commit is contained in:
Родитель
8b02de8f41
Коммит
5cff4c5aa3
|
@ -5729,7 +5729,7 @@ onig_reg_copy(regex_t** nreg, regex_t* oreg)
|
|||
goto err_repeat_range;
|
||||
}
|
||||
if (IS_NOT_NULL(reg->name_table)) {
|
||||
if (IS_NULL(reg->name_table = st_copy(reg->name_table)))
|
||||
if (onig_names_copy(reg, oreg))
|
||||
goto err_name_table;
|
||||
}
|
||||
if (IS_NOT_NULL(reg->chain)) {
|
||||
|
@ -5740,7 +5740,7 @@ onig_reg_copy(regex_t** nreg, regex_t* oreg)
|
|||
# undef COPY_FAILED
|
||||
|
||||
err_chain:
|
||||
onig_st_free_table(reg->name_table);
|
||||
onig_names_free(reg);
|
||||
err_name_table:
|
||||
xfree(reg->repeat_range);
|
||||
err_repeat_range:
|
||||
|
|
87
regparse.c
87
regparse.c
|
@ -251,7 +251,7 @@ bitset_copy(BitSetRef dest, BitSetRef bs)
|
|||
|
||||
#if defined(USE_NAMED_GROUP) && !defined(USE_ST_LIBRARY)
|
||||
extern int
|
||||
onig_strncmp(const UChar* s1, const UChar* s2, int n)
|
||||
onig_strncmp(const UChar* s1, const UChar* s2, size_t n)
|
||||
{
|
||||
int x;
|
||||
|
||||
|
@ -551,6 +551,17 @@ onig_names_free(regex_t* reg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern int
|
||||
onig_names_copy(regex_t* reg, regex_t* oreg)
|
||||
{
|
||||
NameTable* table = oreg->name_table;
|
||||
if (table) {
|
||||
NameTable* t = st_copy(table);
|
||||
reg->name_table = t;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static NameEntry*
|
||||
name_find(regex_t* reg, const UChar* name, const UChar* name_end)
|
||||
{
|
||||
|
@ -736,10 +747,52 @@ onig_names_free(regex_t* reg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern int
|
||||
onig_names_copy(regex_t* reg, regex_t* oreg)
|
||||
{
|
||||
NameTable* ot = oreg->name_table;
|
||||
if (ot) {
|
||||
OnigEncoding enc = oreg->enc;
|
||||
int i, num = ot->num;
|
||||
NameTable* t = xmalloc(sizeof(*t));
|
||||
CHECK_NULL_RETURN_MEMERR(t);
|
||||
*t = *ot;
|
||||
t->e = xmalloc(t->alloc * sizeof(t->e[0]));
|
||||
if (IS_NULL(t->e)) {
|
||||
xfree(t);
|
||||
return ONIGERR_MEMORY;
|
||||
}
|
||||
t->num = 0;
|
||||
reg->name_table = t;
|
||||
for (i = 0; i < num; t->num = ++i) {
|
||||
NameEntry* oe = &(ot->e[i]);
|
||||
NameEntry* e = &(t->e[i]);
|
||||
*e = *oe;
|
||||
e->name = NULL;
|
||||
e->back_refs = NULL;
|
||||
e->name = strdup_with_null(enc, oe->name, oe->name + e->name_len);
|
||||
if (IS_NULL(e->name)) {
|
||||
onig_names_free(reg);
|
||||
return ONIGERR_MEMORY;
|
||||
}
|
||||
e->back_refs = xmalloc(e->back_alloc * sizeof(e->back_refs[0]));
|
||||
if (IS_NULL(e->back_refs)) {
|
||||
xfree(e->name);
|
||||
onig_names_free(reg);
|
||||
return ONIGERR_MEMORY;
|
||||
}
|
||||
memcpy(e->back_refs, oe->back_refs, e->back_num * sizeof(e->back_refs[0]));
|
||||
e->back_ref1 = e->back_refs[0];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static NameEntry*
|
||||
name_find(regex_t* reg, const UChar* name, const UChar* name_end)
|
||||
{
|
||||
int i, len;
|
||||
int i;
|
||||
size_t len;
|
||||
NameEntry* e;
|
||||
NameTable* t = (NameTable* )reg->name_table;
|
||||
|
||||
|
@ -774,6 +827,30 @@ onig_foreach_name(regex_t* reg,
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern int
|
||||
onig_renumber_name_table(regex_t* reg, GroupNumRemap* map)
|
||||
{
|
||||
int i, j;
|
||||
NameEntry* e;
|
||||
NameTable* t = (NameTable* )reg->name_table;
|
||||
|
||||
if (IS_NOT_NULL(t)) {
|
||||
for (i = 0; i < t->num; i++) {
|
||||
e = &(t->e[i]);
|
||||
|
||||
if (e->back_num > 1) {
|
||||
for (j = 0; j < e->back_num; j++) {
|
||||
e->back_refs[j] = map[e->back_refs[j]].new_val;
|
||||
}
|
||||
}
|
||||
else if (e->back_num == 1) {
|
||||
e->back_ref1 = map[e->back_ref1].new_val;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int
|
||||
onig_number_of_names(const regex_t* reg)
|
||||
{
|
||||
|
@ -976,6 +1053,12 @@ onig_number_of_names(const regex_t* reg)
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int
|
||||
onig_names_copy(regex_t* reg, regex_t* oreg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif /* else USE_NAMED_GROUP */
|
||||
|
||||
extern int
|
||||
|
|
|
@ -339,7 +339,7 @@ typedef struct {
|
|||
extern int onig_renumber_name_table(regex_t* reg, GroupNumRemap* map);
|
||||
#endif
|
||||
|
||||
extern int onig_strncmp(const UChar* s1, const UChar* s2, int n);
|
||||
extern int onig_strncmp(const UChar* s1, const UChar* s2, size_t n);
|
||||
extern void onig_strcpy(UChar* dest, const UChar* src, const UChar* end);
|
||||
extern void onig_scan_env_set_error_string(ScanEnv* env, int ecode, UChar* arg, UChar* arg_end);
|
||||
extern int onig_scan_unsigned_number(UChar** src, const UChar* end, OnigEncoding enc);
|
||||
|
@ -356,6 +356,7 @@ extern Node* onig_node_list_add(Node* list, Node* x);
|
|||
extern Node* onig_node_new_alt(Node* left, Node* right);
|
||||
extern void onig_node_str_clear(Node* node);
|
||||
extern int onig_names_free(regex_t* reg);
|
||||
extern int onig_names_copy(regex_t* reg, regex_t* oreg);
|
||||
extern int onig_parse_make_tree(Node** root, const UChar* pattern, const UChar* end, regex_t* reg, ScanEnv* env);
|
||||
extern int onig_free_shared_cclass_table(void);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче