comparison src/regex.c @ 1726:a8d8f419b459

[xemacs-hg @ 2003-09-30 15:26:34 by james] Add type information to xfree to avoid alias creation.
author james
date Tue, 30 Sep 2003 15:27:01 +0000
parents 0ad2242c43a4
children 35540b6052a9
comparison
equal deleted inserted replaced
1725:7ff8f4d70aec 1726:a8d8f419b459
264 264
265 #ifndef emacs 265 #ifndef emacs
266 #define ALLOCA alloca 266 #define ALLOCA alloca
267 #define xmalloc malloc 267 #define xmalloc malloc
268 #define xrealloc realloc 268 #define xrealloc realloc
269 #define xfree free 269 #define xfree(x,type) free (x)
270 #endif 270 #endif
271 271
272 #ifdef emacs 272 #ifdef emacs
273 #define ALLOCA_GARBAGE_COLLECT() \ 273 #define ALLOCA_GARBAGE_COLLECT() \
274 do \ 274 do \
347 #define REGEX_REALLOCATE(source, osize, nsize) \ 347 #define REGEX_REALLOCATE(source, osize, nsize) \
348 (destination = (char *) ALLOCA (nsize), \ 348 (destination = (char *) ALLOCA (nsize), \
349 memmove (destination, source, osize), \ 349 memmove (destination, source, osize), \
350 destination) 350 destination)
351 351
352 /* No need to do anything to free, after alloca. */ 352 /* No need to do anything to free, after alloca.
353 #define REGEX_FREE(arg) ((void)0) /* Do nothing! But inhibit gcc warning. */ 353 Do nothing! But inhibit gcc warning. */
354 #define REGEX_FREE(arg,type) ((void)0)
354 355
355 #endif /* REGEX_MALLOC */ 356 #endif /* REGEX_MALLOC */
356 357
357 /* Define how to allocate the failure stack. */ 358 /* Define how to allocate the failure stack. */
358 359
368 369
369 #ifdef REGEX_MALLOC 370 #ifdef REGEX_MALLOC
370 371
371 #define REGEX_ALLOCATE_STACK xmalloc 372 #define REGEX_ALLOCATE_STACK xmalloc
372 #define REGEX_REALLOCATE_STACK(source, osize, nsize) xrealloc (source, nsize) 373 #define REGEX_REALLOCATE_STACK(source, osize, nsize) xrealloc (source, nsize)
373 #define REGEX_FREE_STACK xfree 374 #define REGEX_FREE_STACK(arg) xfree (arg, fail_stack_elt_t *)
374 375
375 #else /* not REGEX_MALLOC */ 376 #else /* not REGEX_MALLOC */
376 377
377 #define REGEX_ALLOCATE_STACK ALLOCA 378 #define REGEX_ALLOCATE_STACK ALLOCA
378 379
2099 2100
2100 The `fastmap' and `newline_anchor' fields are neither 2101 The `fastmap' and `newline_anchor' fields are neither
2101 examined nor set. */ 2102 examined nor set. */
2102 2103
2103 /* Return, freeing storage we allocated. */ 2104 /* Return, freeing storage we allocated. */
2104 #define FREE_STACK_RETURN(value) \ 2105 #define FREE_STACK_RETURN(value) \
2105 do \ 2106 do \
2106 { \ 2107 { \
2107 xfree (compile_stack.stack); \ 2108 xfree (compile_stack.stack, compile_stack_elt_t *); \
2108 return value; \ 2109 return value; \
2109 } while (0) 2110 } while (0)
2110 2111
2111 static reg_errcode_t 2112 static reg_errcode_t
2112 regex_compile (re_char *pattern, int size, reg_syntax_t syntax, 2113 regex_compile (re_char *pattern, int size, reg_syntax_t syntax,
2113 struct re_pattern_buffer *bufp) 2114 struct re_pattern_buffer *bufp)
3407 /* If we don't want backtracking, force success 3408 /* If we don't want backtracking, force success
3408 the first time we reach the end of the compiled pattern. */ 3409 the first time we reach the end of the compiled pattern. */
3409 if (syntax & RE_NO_POSIX_BACKTRACKING) 3410 if (syntax & RE_NO_POSIX_BACKTRACKING)
3410 BUF_PUSH (succeed); 3411 BUF_PUSH (succeed);
3411 3412
3412 xfree (compile_stack.stack); 3413 xfree (compile_stack.stack, compile_stack_elt_t *);
3413 3414
3414 /* We have succeeded; set the length of the buffer. */ 3415 /* We have succeeded; set the length of the buffer. */
3415 bufp->used = buf_end - bufp->buffer; 3416 bufp->used = buf_end - bufp->buffer;
3416 3417
3417 #ifdef DEBUG 3418 #ifdef DEBUG
4672 #define WORDCHAR_P(ch) \ 4673 #define WORDCHAR_P(ch) \
4673 (SYNTAX (BUFFER_MIRROR_SYNTAX_TABLE (lispbuf), ch) == Sword) 4674 (SYNTAX (BUFFER_MIRROR_SYNTAX_TABLE (lispbuf), ch) == Sword)
4674 4675
4675 /* Free everything we malloc. */ 4676 /* Free everything we malloc. */
4676 #ifdef MATCH_MAY_ALLOCATE 4677 #ifdef MATCH_MAY_ALLOCATE
4677 #define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL 4678 #define FREE_VAR(var,type) if (var) REGEX_FREE (var, type); var = NULL
4678 #define FREE_VARIABLES() \ 4679 #define FREE_VARIABLES() \
4679 do { \ 4680 do { \
4680 UNBIND_REGEX_MALLOC_CHECK (); \ 4681 UNBIND_REGEX_MALLOC_CHECK (); \
4681 REGEX_FREE_STACK (fail_stack.stack); \ 4682 REGEX_FREE_STACK (fail_stack.stack); \
4682 FREE_VAR (regstart); \ 4683 FREE_VAR (regstart, re_char **); \
4683 FREE_VAR (regend); \ 4684 FREE_VAR (regend, re_char **); \
4684 FREE_VAR (old_regstart); \ 4685 FREE_VAR (old_regstart, re_char **); \
4685 FREE_VAR (old_regend); \ 4686 FREE_VAR (old_regend, re_char **); \
4686 FREE_VAR (best_regstart); \ 4687 FREE_VAR (best_regstart, re_char **); \
4687 FREE_VAR (best_regend); \ 4688 FREE_VAR (best_regend, re_char **); \
4688 FREE_VAR (reg_info); \ 4689 FREE_VAR (reg_info, register_info_type *); \
4689 FREE_VAR (reg_dummy); \ 4690 FREE_VAR (reg_dummy, re_char **); \
4690 FREE_VAR (reg_info_dummy); \ 4691 FREE_VAR (reg_info_dummy, register_info_type *); \
4691 } while (0) 4692 } while (0)
4692 #else /* not MATCH_MAY_ALLOCATE */ 4693 #else /* not MATCH_MAY_ALLOCATE */
4693 #define FREE_VARIABLES() \ 4694 #define FREE_VARIABLES() \
4694 do { \ 4695 do { \
4695 UNBIND_REGEX_MALLOC_CHECK (); \ 4696 UNBIND_REGEX_MALLOC_CHECK (); \
6947 pmatch[r].rm_eo = regs.end[r]; 6948 pmatch[r].rm_eo = regs.end[r];
6948 } 6949 }
6949 } 6950 }
6950 6951
6951 /* If we needed the temporary register info, free the space now. */ 6952 /* If we needed the temporary register info, free the space now. */
6952 xfree (regs.start); 6953 xfree (regs.start, regoff_t *);
6953 xfree (regs.end); 6954 xfree (regs.end, regoff_t *);
6954 } 6955 }
6955 6956
6956 /* We want zero return to mean success, unlike `re_search'. */ 6957 /* We want zero return to mean success, unlike `re_search'. */
6957 return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH; 6958 return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH;
6958 } 6959 }
7000 7001
7001 void 7002 void
7002 regfree (regex_t *preg) 7003 regfree (regex_t *preg)
7003 { 7004 {
7004 if (preg->buffer != NULL) 7005 if (preg->buffer != NULL)
7005 xfree (preg->buffer); 7006 xfree (preg->buffer, unsigned char *);
7006 preg->buffer = NULL; 7007 preg->buffer = NULL;
7007 7008
7008 preg->allocated = 0; 7009 preg->allocated = 0;
7009 preg->used = 0; 7010 preg->used = 0;
7010 7011
7011 if (preg->fastmap != NULL) 7012 if (preg->fastmap != NULL)
7012 xfree (preg->fastmap); 7013 xfree (preg->fastmap, char *);
7013 preg->fastmap = NULL; 7014 preg->fastmap = NULL;
7014 preg->fastmap_accurate = 0; 7015 preg->fastmap_accurate = 0;
7015 7016
7016 if (preg->translate != NULL) 7017 if (preg->translate != NULL)
7017 xfree (preg->translate); 7018 xfree (preg->translate, RE_TRANSLATE_TYPE);
7018 preg->translate = NULL; 7019 preg->translate = NULL;
7019 } 7020 }
7020 7021
7021 #endif /* not emacs */ 7022 #endif /* not emacs */
7022 7023