More scratch-buffer cleanup
diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh
index 4647b9b..478bad0 100644
--- a/src/hb-buffer-private.hh
+++ b/src/hb-buffer-private.hh
@@ -186,7 +186,8 @@
HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out);
HB_INTERNAL bool shift_forward (unsigned int count);
- HB_INTERNAL int *get_scratch_buffer (unsigned int *int_size);
+ typedef int scratch_buffer_t;
+ HB_INTERNAL scratch_buffer_t *get_scratch_buffer (unsigned int *size);
inline void clear_context (unsigned int side) { context_len[side] = 0; }
};
diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc
index c5a74c3..df2ad73 100644
--- a/src/hb-buffer.cc
+++ b/src/hb-buffer.cc
@@ -152,8 +152,8 @@
return true;
}
-int *
-hb_buffer_t::get_scratch_buffer (unsigned int *int_size)
+hb_buffer_t::scratch_buffer_t *
+hb_buffer_t::get_scratch_buffer (unsigned int *size)
{
have_output = false;
have_positions = false;
@@ -161,9 +161,9 @@
out_len = 0;
out_info = info;
- ASSERT_STATIC (sizeof (pos[0]) % sizeof (int) == 0);
- *int_size = allocated * (sizeof (pos[0]) / sizeof (int));
- return (int *) pos;
+ ASSERT_STATIC (sizeof (pos[0]) % sizeof (scratch_buffer_t) == 0);
+ *size = allocated * sizeof (pos[0]) / sizeof (scratch_buffer_t);
+ return (scratch_buffer_t *) pos;
}
diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index eafa68e..ba80136 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -553,7 +553,7 @@
} HB_STMT_END;
unsigned int scratch_size;
- int *scratch = buffer->get_scratch_buffer (&scratch_size);
+ hb_buffer_t::scratch_buffer_t *scratch = buffer->get_scratch_buffer (&scratch_size);
#define ALLOCATE_ARRAY(Type, name, len) \
Type *name = (Type *) scratch; \
@@ -657,8 +657,7 @@
buffer->ensure (buffer->len + num_glyphs);
- unsigned int scratch_size;
- int *scratch = buffer->get_scratch_buffer (&scratch_size);
+ scratch = buffer->get_scratch_buffer (&scratch_size);
/* Testing indicates that CTRunGetGlyphsPtr, etc (almost?) always
* succeed, and so copying data to our own buffer will be rare. */
diff --git a/src/hb-graphite2.cc b/src/hb-graphite2.cc
index d1cd1dc..60d68d6 100644
--- a/src/hb-graphite2.cc
+++ b/src/hb-graphite2.cc
@@ -243,7 +243,7 @@
float curradvx = 0., curradvy = 0.;
unsigned int scratch_size;
- int *scratch = buffer->get_scratch_buffer (&scratch_size);
+ hb_buffer_t::scratch_buffer_t *scratch = buffer->get_scratch_buffer (&scratch_size);
uint32_t *chars = (uint32_t *) scratch;
diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc
index 4a93db8..fcb1aa6 100644
--- a/src/hb-uniscribe.cc
+++ b/src/hb-uniscribe.cc
@@ -729,13 +729,21 @@
retry:
unsigned int scratch_size;
- int *scratch = buffer->get_scratch_buffer (&scratch_size);
+ hb_buffer_t::scratch_buffer_t *scratch = buffer->get_scratch_buffer (&scratch_size);
- /* Allocate char buffers; they all fit */
+#define ALLOCATE_ARRAY(Type, name, len) \
+ Type *name = (Type *) scratch; \
+ { \
+ unsigned int _consumed = DIV_CEIL ((len) * sizeof (Type), sizeof (*scratch)); \
+ assert (_consumed <= scratch_size); \
+ scratch += _consumed; \
+ scratch_size -= _consumed; \
+ }
#define utf16_index() var1.u32
- WCHAR *pchars = (WCHAR *) scratch;
+ ALLOCATE_ARRAY (WCHAR, pchars, buffer->len * 2);
+
unsigned int chars_len = 0;
for (unsigned int i = 0; i < buffer->len; i++)
{
@@ -751,16 +759,6 @@
}
}
-#define ALLOCATE_ARRAY(Type, name, len) \
- Type *name = (Type *) scratch; \
- { \
- unsigned int _consumed = DIV_CEIL ((len) * sizeof (Type), sizeof (*scratch)); \
- assert (_consumed <= scratch_size); \
- scratch += _consumed; \
- scratch_size -= _consumed; \
- }
-
- ALLOCATE_ARRAY (WCHAR, wchars, chars_len);
ALLOCATE_ARRAY (WORD, log_clusters, chars_len);
ALLOCATE_ARRAY (SCRIPT_CHARPROP, char_props, chars_len);
@@ -817,7 +815,7 @@
bidi_state.uBidiLevel = HB_DIRECTION_IS_FORWARD (buffer->props.direction) ? 0 : 1;
bidi_state.fOverrideDirection = 1;
- hr = funcs->ScriptItemizeOpenType (wchars,
+ hr = funcs->ScriptItemizeOpenType (pchars,
chars_len,
MAX_ITEMS,
&bidi_control,
@@ -892,7 +890,7 @@
range_char_counts.array,
range_properties.array,
range_properties.len,
- wchars + chars_offset,
+ pchars + chars_offset,
item_chars_len,
glyphs_size - glyphs_offset,
/* out */
@@ -934,7 +932,7 @@
range_char_counts.array,
range_properties.array,
range_properties.len,
- wchars + chars_offset,
+ pchars + chars_offset,
log_clusters + chars_offset,
char_props + chars_offset,
item_chars_len,