From 577c1116493d785d3455626612f97dabb383abf0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 4 Aug 2009 19:31:02 -0400 Subject: [PATCH] [HB] Shuffle code around --- src/hb-open-types-private.hh | 127 ++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 62 deletions(-) diff --git a/src/hb-open-types-private.hh b/src/hb-open-types-private.hh index 8429179..fb7dca5 100644 --- a/src/hb-open-types-private.hh +++ b/src/hb-open-types-private.hh @@ -52,68 +52,6 @@ /* - * Sanitize - */ - -typedef struct _hb_sanitize_context_t hb_sanitize_context_t; -struct _hb_sanitize_context_t -{ - const char *start, *end; - int edit_count; - hb_blob_t *blob; -}; - -static HB_GNUC_UNUSED void -hb_sanitize_init (hb_sanitize_context_t *context, - hb_blob_t *blob) -{ - context->blob = blob; - context->start = hb_blob_lock (blob); - context->end = context->start + hb_blob_get_length (blob); - context->edit_count = 0; -} - -static HB_GNUC_UNUSED void -hb_sanitize_fini (hb_sanitize_context_t *context, bool unlock) -{ - if (unlock) - hb_blob_unlock (context->blob); -} - -static HB_GNUC_UNUSED bool -hb_sanitize_edit (hb_sanitize_context_t *context) -{ - bool perm = hb_blob_try_writeable_inplace (context->blob); - if (perm) - context->edit_count++; - return perm; -} - -#define SANITIZE_ARG_DEF \ - hb_sanitize_context_t *context -#define SANITIZE_ARG \ - context - -#define SANITIZE(X) HB_LIKELY ((X).sanitize (SANITIZE_ARG)) -#define SANITIZE2(X,Y) (SANITIZE (X) && SANITIZE (Y)) - -#define SANITIZE_THIS(X) HB_LIKELY ((X).sanitize (SANITIZE_ARG, CONST_CHARP(this))) -#define SANITIZE_THIS2(X,Y) (SANITIZE_THIS (X) && SANITIZE_THIS (Y)) -#define SANITIZE_THIS3(X,Y,Z) (SANITIZE_THIS (X) && SANITIZE_THIS (Y) && SANITIZE_THIS(Z)) - -#define SANITIZE_BASE(X,B) HB_LIKELY ((X).sanitize (SANITIZE_ARG, B)) -#define SANITIZE_BASE2(X,Y,B) (SANITIZE_BASE (X,B) && SANITIZE_BASE (Y,B)) - -#define SANITIZE_SELF() SANITIZE_OBJ (*this) -#define SANITIZE_OBJ(X) SANITIZE_MEM(&(X), sizeof (X)) -#define SANITIZE_GET_SIZE() SANITIZE_SELF() && SANITIZE_MEM (this, this->get_size ()) - -#define SANITIZE_MEM(B,L) HB_LIKELY (context->start <= CONST_CHARP(B) && CONST_CHARP(B) + (L) <= context->end) /* XXX overflow */ - -#define NEUTER(Var, Val) (SANITIZE_OBJ (Var) && hb_sanitize_edit (context) && ((Var) = (Val), true)) - - -/* * Array types */ @@ -169,6 +107,7 @@ hb_sanitize_edit (hb_sanitize_context_t *context) inline const Type& get_##name (unsigned int i) const { return (this+name##List)[i]; } \ inline unsigned int get_##name##_count (void) const { return (this+name##List).len; } + /* * Tag types */ @@ -203,6 +142,8 @@ hb_sanitize_edit (hb_sanitize_context_t *context) return Null(Type); \ } + + /* * Class features */ @@ -258,6 +199,68 @@ struct Null \ } +/* + * Sanitize + */ + +typedef struct _hb_sanitize_context_t hb_sanitize_context_t; +struct _hb_sanitize_context_t +{ + const char *start, *end; + int edit_count; + hb_blob_t *blob; +}; + +static HB_GNUC_UNUSED void +hb_sanitize_init (hb_sanitize_context_t *context, + hb_blob_t *blob) +{ + context->blob = blob; + context->start = hb_blob_lock (blob); + context->end = context->start + hb_blob_get_length (blob); + context->edit_count = 0; +} + +static HB_GNUC_UNUSED void +hb_sanitize_fini (hb_sanitize_context_t *context, bool unlock) +{ + if (unlock) + hb_blob_unlock (context->blob); +} + +static HB_GNUC_UNUSED bool +hb_sanitize_edit (hb_sanitize_context_t *context) +{ + bool perm = hb_blob_try_writeable_inplace (context->blob); + if (perm) + context->edit_count++; + return perm; +} + +#define SANITIZE_ARG_DEF \ + hb_sanitize_context_t *context +#define SANITIZE_ARG \ + context + +#define SANITIZE(X) HB_LIKELY ((X).sanitize (SANITIZE_ARG)) +#define SANITIZE2(X,Y) (SANITIZE (X) && SANITIZE (Y)) + +#define SANITIZE_THIS(X) HB_LIKELY ((X).sanitize (SANITIZE_ARG, CONST_CHARP(this))) +#define SANITIZE_THIS2(X,Y) (SANITIZE_THIS (X) && SANITIZE_THIS (Y)) +#define SANITIZE_THIS3(X,Y,Z) (SANITIZE_THIS (X) && SANITIZE_THIS (Y) && SANITIZE_THIS(Z)) + +#define SANITIZE_BASE(X,B) HB_LIKELY ((X).sanitize (SANITIZE_ARG, B)) +#define SANITIZE_BASE2(X,Y,B) (SANITIZE_BASE (X,B) && SANITIZE_BASE (Y,B)) + +#define SANITIZE_SELF() SANITIZE_OBJ (*this) +#define SANITIZE_OBJ(X) SANITIZE_MEM(&(X), sizeof (X)) +#define SANITIZE_GET_SIZE() SANITIZE_SELF() && SANITIZE_MEM (this, this->get_size ()) + +#define SANITIZE_MEM(B,L) HB_LIKELY (context->start <= CONST_CHARP(B) && CONST_CHARP(B) + (L) <= context->end) /* XXX overflow */ + +#define NEUTER(Var, Val) (SANITIZE_OBJ (Var) && hb_sanitize_edit (context) && ((Var) = (Val), true)) + + /* * -- 2.7.4