[HarfBuzz] harfbuzz-ng: Branch 'master' - 9 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Wed May 11 18:35:49 PDT 2011
TODO | 4 +-
src/hb-buffer.cc | 6 ++++
src/hb-buffer.h | 3 ++
src/hb-common.h | 1
src/hb-font.cc | 18 +++++++++++++
src/hb-font.h | 9 ++++++
src/hb-mutex-private.hh | 65 ++++++++++++++++++++++++++++--------------------
src/hb-private.hh | 8 +++++
src/hb-unicode.cc | 6 ++++
src/hb-unicode.h | 3 ++
src/test.cc | 9 ++++--
test/test-blob.c | 1
test/test-buffer.c | 7 +++++
test/test-object.c | 36 ++++++++++++++++++++++++--
test/test-unicode.c | 10 +++++++
15 files changed, 152 insertions(+), 34 deletions(-)
New commits:
commit daa446f184fa27c9764ff7f8a2444d47cf34d986
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed May 11 21:31:25 2011 -0400
Fix compile with no mutex available
diff --git a/src/hb-mutex-private.hh b/src/hb-mutex-private.hh
index 24b6d9a..4ff4b32 100644
--- a/src/hb-mutex-private.hh
+++ b/src/hb-mutex-private.hh
@@ -69,12 +69,12 @@ typedef CRITICAL_SECTION hb_mutex_impl_t;
#warning "Could not find any system to define platform macros, library will NOT be thread-safe"
-typedef struct { volatile int m; } hb_mutex_impl_t;
+typedef volatile int hb_mutex_impl_t;
#define HB_MUTEX_IMPL_INIT 0
-#define hb_mutex_impl_init(M) ((void) ((M)->m = 0))
-#define hb_mutex_impl_lock(M) ((void) ((M)->m = 1))
-#define hb_mutex_impl_unlock(M) ((void) ((M)->m = 0))
-#define hb_mutex_impl_free(M) ((void) ((M)-M = 2))
+#define hb_mutex_impl_init(M) ((void) (*(M) = 0))
+#define hb_mutex_impl_lock(M) ((void) (*(M) = 1))
+#define hb_mutex_impl_unlock(M) ((void) (*(M) = 0))
+#define hb_mutex_impl_free(M) ((void) (*(M) = 2))
#endif
commit 1e56c476c10577fe319fe553c5ced000bd740940
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed May 11 21:28:01 2011 -0400
Free static mutex'es
diff --git a/src/hb-mutex-private.hh b/src/hb-mutex-private.hh
index be0f687..24b6d9a 100644
--- a/src/hb-mutex-private.hh
+++ b/src/hb-mutex-private.hh
@@ -100,6 +100,7 @@ struct hb_mutex_t
struct hb_static_mutex_t : hb_mutex_t
{
hb_static_mutex_t (void) { this->init (); }
+ ~hb_static_mutex_t (void) { this->free (); }
private:
NO_COPY (hb_static_mutex_t);
commit 831886a9b4073cfe27f7e1db0e957cbd5913fd31
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed May 11 21:27:52 2011 -0400
Streamline mutex stuff
diff --git a/src/hb-mutex-private.hh b/src/hb-mutex-private.hh
index 49750d5..be0f687 100644
--- a/src/hb-mutex-private.hh
+++ b/src/hb-mutex-private.hh
@@ -45,49 +45,64 @@ HB_BEGIN_DECLS
#include <glib.h>
-typedef GStaticMutex hb_mutex_t;
-#define HB_MUTEX_INIT G_STATIC_MUTEX_INIT
-#define hb_mutex_init(M) g_static_mutex_init (M)
-#define hb_mutex_lock(M) g_static_mutex_lock (M)
-#define hb_mutex_unlock(M) g_static_mutex_unlock (M)
-#define hb_mutex_free(M) g_static_mutex_free (M)
+typedef GStaticMutex hb_mutex_impl_t;
+#define HB_MUTEX_IMPL_INIT G_STATIC_MUTEX_INIT
+#define hb_mutex_impl_init(M) g_static_mutex_init (M)
+#define hb_mutex_impl_lock(M) g_static_mutex_lock (M)
+#define hb_mutex_impl_unlock(M) g_static_mutex_unlock (M)
+#define hb_mutex_impl_free(M) g_static_mutex_free (M)
#elif defined(_MSC_VER)
#include <Windows.h>
-typedef CRITICAL_SECTION hb_mutex_t;
-#define HB_MUTEX_INIT { NULL, 0, 0, NULL, NULL, 0 }
-#define hb_mutex_init(M) InitializeCriticalSection (M)
-#define hb_mutex_lock(M) EnterCriticalSection (M)
-#define hb_mutex_unlock(M) LeaveCriticalSection (M)
-#define hb_mutex_free(M) DeleteCriticalSection (M)
+typedef CRITICAL_SECTION hb_mutex_impl_t;
+#define HB_MUTEX_IMPL_INIT { NULL, 0, 0, NULL, NULL, 0 }
+#define hb_mutex_impl_init(M) InitializeCriticalSection (M)
+#define hb_mutex_impl_lock(M) EnterCriticalSection (M)
+#define hb_mutex_impl_unlock(M) LeaveCriticalSection (M)
+#define hb_mutex_impl_free(M) DeleteCriticalSection (M)
#else
#warning "Could not find any system to define platform macros, library will NOT be thread-safe"
-typedef struct { volatile int m; } hb_mutex_t;
-#define HB_MUTEX_INIT 0
-#define hb_mutex_init(M) ((void) ((M)->m = 0))
-#define hb_mutex_lock(M) ((void) ((M)->m = 1))
-#define hb_mutex_unlock(M) ((void) ((M)->m = 0))
-#define hb_mutex_free(M) ((void) ((M)-M = 2))
+typedef struct { volatile int m; } hb_mutex_impl_t;
+#define HB_MUTEX_IMPL_INIT 0
+#define hb_mutex_impl_init(M) ((void) ((M)->m = 0))
+#define hb_mutex_impl_lock(M) ((void) ((M)->m = 1))
+#define hb_mutex_impl_unlock(M) ((void) ((M)->m = 0))
+#define hb_mutex_impl_free(M) ((void) ((M)-M = 2))
#endif
+struct hb_mutex_t
+{
+ hb_mutex_impl_t m;
+
+ inline void init (void) { hb_mutex_impl_init (&m); }
+ inline void lock (void) { hb_mutex_impl_lock (&m); }
+ inline void unlock (void) { hb_mutex_impl_unlock (&m); }
+ inline void free (void) { hb_mutex_impl_free (&m); }
+};
+
+#define HB_MUTEX_INIT {HB_MUTEX_IMPL_INIT}
+#define hb_mutex_init(M) (M)->init ()
+#define hb_mutex_lock(M) (M)->lock ()
+#define hb_mutex_unlock(M) (M)->unlock ()
+#define hb_mutex_free(M) (M)->free ()
+
+
struct hb_static_mutex_t : hb_mutex_t
{
- hb_static_mutex_t (void) {
- hb_mutex_init (this);
- }
+ hb_static_mutex_t (void) { this->init (); }
- inline void lock (void) { hb_mutex_lock (this); }
- inline void unlock (void) { hb_mutex_unlock (this); }
+ private:
+ NO_COPY (hb_static_mutex_t);
};
diff --git a/src/hb-private.hh b/src/hb-private.hh
index 215ef96..09f7bc1 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -494,6 +494,14 @@ static inline unsigned char TOLOWER (unsigned char c)
((const char *) s)[3]))
+/* C++ helpers */
+
+/* Makes class uncopyable. Use in private: section. */
+#define NO_COPY(T) \
+ T (const T &o); \
+ T &operator = (const T &o);
+
+
/* Debug */
#ifndef HB_DEBUG
commit 438c4eee353ddf0de66171d84c6ef9b21cbdf8f6
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed May 11 21:14:34 2011 -0400
Remove unused hb_mutex_trylock()
diff --git a/src/hb-mutex-private.hh b/src/hb-mutex-private.hh
index 3cc47e9..49750d5 100644
--- a/src/hb-mutex-private.hh
+++ b/src/hb-mutex-private.hh
@@ -49,7 +49,6 @@ typedef GStaticMutex hb_mutex_t;
#define HB_MUTEX_INIT G_STATIC_MUTEX_INIT
#define hb_mutex_init(M) g_static_mutex_init (M)
#define hb_mutex_lock(M) g_static_mutex_lock (M)
-#define hb_mutex_trylock(M) g_static_mutex_trylock (M)
#define hb_mutex_unlock(M) g_static_mutex_unlock (M)
#define hb_mutex_free(M) g_static_mutex_free (M)
@@ -62,7 +61,6 @@ typedef CRITICAL_SECTION hb_mutex_t;
#define HB_MUTEX_INIT { NULL, 0, 0, NULL, NULL, 0 }
#define hb_mutex_init(M) InitializeCriticalSection (M)
#define hb_mutex_lock(M) EnterCriticalSection (M)
-#define hb_mutex_trylock(M) TryEnterCriticalSection (M)
#define hb_mutex_unlock(M) LeaveCriticalSection (M)
#define hb_mutex_free(M) DeleteCriticalSection (M)
@@ -75,7 +73,6 @@ typedef struct { volatile int m; } hb_mutex_t;
#define HB_MUTEX_INIT 0
#define hb_mutex_init(M) ((void) ((M)->m = 0))
#define hb_mutex_lock(M) ((void) ((M)->m = 1))
-#define hb_mutex_trylock(M) ((M)->m = 1, 1)
#define hb_mutex_unlock(M) ((void) ((M)->m = 0))
#define hb_mutex_free(M) ((void) ((M)-M = 2))
commit b8477e1da2785708f3232f8f2577f602a5d320d1
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed May 11 21:12:44 2011 -0400
[test] Add tests for _get_empty() funcs
diff --git a/test/test-blob.c b/test/test-blob.c
index 22d40b7..beb23a5 100644
--- a/test/test-blob.c
+++ b/test/test-blob.c
@@ -52,6 +52,7 @@ test_blob_empty (void)
g_assert (hb_blob_is_immutable (hb_blob_get_empty ()));
g_assert (hb_blob_get_empty () != NULL);
+ g_assert (hb_blob_get_empty () == hb_blob_create (NULL, 0, HB_MEMORY_MODE_READONLY, NULL, NULL));
blob = hb_blob_get_empty ();
g_assert (blob == hb_blob_get_empty ());
diff --git a/test/test-buffer.c b/test/test-buffer.c
index 2b1c7b7..0cbb8e0 100644
--- a/test/test-buffer.c
+++ b/test/test-buffer.c
@@ -711,6 +711,12 @@ test_buffer_utf16_conversion (void)
hb_buffer_destroy (b);
}
+static void
+test_buffer_empty (void)
+{
+ g_assert (hb_buffer_get_empty ());
+ g_assert (hb_buffer_create (-1) == hb_buffer_get_empty ());
+}
int
main (int argc, char **argv)
@@ -734,6 +740,7 @@ main (int argc, char **argv)
hb_test_add (test_buffer_utf8_conversion);
hb_test_add (test_buffer_utf8_validity);
hb_test_add (test_buffer_utf16_conversion);
+ hb_test_add (test_buffer_empty);
return hb_test_run();
}
diff --git a/test/test-unicode.c b/test/test-unicode.c
index f5aae10..2e15e95 100644
--- a/test/test-unicode.c
+++ b/test/test-unicode.c
@@ -550,6 +550,15 @@ test_unicode_properties_nil (void)
hb_unicode_funcs_destroy (uf);
}
+static void
+test_unicode_properties_empty (void)
+{
+ hb_unicode_funcs_t *uf = hb_unicode_funcs_get_empty ();
+
+ g_assert (hb_unicode_funcs_is_immutable (uf));
+ _test_unicode_properties_nil (uf);
+}
+
static void
test_unicode_chainup (void)
@@ -777,6 +786,7 @@ main (int argc, char **argv)
hb_test_init (&argc, &argv);
hb_test_add (test_unicode_properties_nil);
+ hb_test_add (test_unicode_properties_empty);
hb_test_add_data_flavor (hb_unicode_funcs_get_default (), "default", test_unicode_properties);
hb_test_add_data_flavor ((gconstpointer) script_roundtrip_default, "default", test_unicode_script_roundtrip);
commit 3994be3ded40e5a3da0e187ad421b19a78865e02
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed May 11 21:08:31 2011 -0400
[TODO] Update
diff --git a/TODO b/TODO
index 16a2199..7d38803 100644
--- a/TODO
+++ b/TODO
@@ -14,8 +14,6 @@ API issues to fix before 1.0:
- Figure out how many .so objects, how to link, etc
-- Real subclassing support for vfunc vectors
-
- Add hb-cairo glue
- Add sanitize API
@@ -26,6 +24,8 @@ API issues to fix before 1.0:
API to add (maybe after 1.0):
============================
+- Add hb_face_get_glyph_count()?
+
- Add hb_font_create_linear()?
- Add hb_shape_plan()/hb_shape_execute()
commit 80a6833b032bc63b4e8c3da6489d3767af1168f3
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed May 11 18:14:44 2011 -0400
[API] Add hb_*_get_empty() for all objects
diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc
index 6d0d4d4..7e79eef 100644
--- a/src/hb-buffer.cc
+++ b/src/hb-buffer.cc
@@ -153,6 +153,12 @@ hb_buffer_create (unsigned int pre_alloc_size)
}
hb_buffer_t *
+hb_buffer_get_empty (void)
+{
+ return &_hb_buffer_nil;
+}
+
+hb_buffer_t *
hb_buffer_reference (hb_buffer_t *buffer)
{
return hb_object_reference (buffer);
diff --git a/src/hb-buffer.h b/src/hb-buffer.h
index 47a2123..020a120 100644
--- a/src/hb-buffer.h
+++ b/src/hb-buffer.h
@@ -63,6 +63,9 @@ hb_buffer_t *
hb_buffer_create (unsigned int pre_alloc_size);
hb_buffer_t *
+hb_buffer_get_empty (void);
+
+hb_buffer_t *
hb_buffer_reference (hb_buffer_t *buffer);
void
diff --git a/src/hb-font.cc b/src/hb-font.cc
index 6cd436d..bb8f84c 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -160,6 +160,12 @@ hb_font_funcs_create (void)
}
hb_font_funcs_t *
+hb_font_funcs_get_empty (void)
+{
+ return &_hb_font_funcs_nil;
+}
+
+hb_font_funcs_t *
hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
{
return hb_object_reference (ffuncs);
@@ -404,6 +410,12 @@ hb_face_create_for_data (hb_blob_t *blob,
(hb_destroy_func_t) _hb_face_for_data_closure_destroy);
}
+hb_face_t *
+hb_face_get_empty (void)
+{
+ return &_hb_face_nil;
+}
+
hb_face_t *
hb_face_reference (hb_face_t *face)
@@ -534,6 +546,12 @@ hb_font_create_sub_font (hb_font_t *parent)
}
hb_font_t *
+hb_font_get_empty (void)
+{
+ return &_hb_font_nil;
+}
+
+hb_font_t *
hb_font_reference (hb_font_t *font)
{
return hb_object_reference (font);
diff --git a/src/hb-font.h b/src/hb-font.h
index ce81985..7f05144 100644
--- a/src/hb-font.h
+++ b/src/hb-font.h
@@ -53,6 +53,9 @@ hb_face_create_for_tables (hb_get_table_func_t get_table,
hb_destroy_func_t destroy);
hb_face_t *
+hb_face_get_empty (void);
+
+hb_face_t *
hb_face_reference (hb_face_t *face);
void
@@ -88,6 +91,9 @@ hb_font_funcs_t *
hb_font_funcs_create (void);
hb_font_funcs_t *
+hb_font_funcs_get_empty (void);
+
+hb_font_funcs_t *
hb_font_funcs_reference (hb_font_funcs_t *ffuncs);
void
@@ -207,6 +213,9 @@ hb_font_t *
hb_font_create_sub_font (hb_font_t *parent);
hb_font_t *
+hb_font_get_empty (void);
+
+hb_font_t *
hb_font_reference (hb_font_t *font);
void
diff --git a/src/hb-unicode.cc b/src/hb-unicode.cc
index 943d7a7..c2d7311 100644
--- a/src/hb-unicode.cc
+++ b/src/hb-unicode.cc
@@ -126,6 +126,12 @@ hb_unicode_funcs_create (hb_unicode_funcs_t *parent)
}
hb_unicode_funcs_t *
+hb_unicode_funcs_get_empty (void)
+{
+ return &_hb_unicode_funcs_nil;
+}
+
+hb_unicode_funcs_t *
hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs)
{
return hb_object_reference (ufuncs);
diff --git a/src/hb-unicode.h b/src/hb-unicode.h
index 9e590d8..e7a2005 100644
--- a/src/hb-unicode.h
+++ b/src/hb-unicode.h
@@ -54,6 +54,9 @@ hb_unicode_funcs_t *
hb_unicode_funcs_create (hb_unicode_funcs_t *parent);
hb_unicode_funcs_t *
+hb_unicode_funcs_get_empty (void);
+
+hb_unicode_funcs_t *
hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs);
void
diff --git a/test/test-object.c b/test/test-object.c
index 1abe65c..1ad3b88 100644
--- a/test/test-object.c
+++ b/test/test-object.c
@@ -43,7 +43,7 @@ create_blob (void)
static void *
create_blob_inert (void)
{
- return hb_blob_get_empty ();
+ return hb_blob_create (NULL, 0, HB_MEMORY_MODE_DUPLICATE, NULL, NULL);
}
static void *
@@ -68,7 +68,7 @@ create_face (void)
static void *
create_face_inert (void)
{
- return hb_face_create_for_data ((hb_blob_t *) create_blob_inert (), 0);
+ return hb_face_create_for_data (hb_blob_get_empty (), 0);
}
static void *
@@ -82,7 +82,7 @@ create_font (void)
static void *
create_font_inert (void)
{
- return hb_font_create (create_face_inert ());
+ return hb_font_create (hb_face_get_empty ());
}
static void *
@@ -124,6 +124,7 @@ typedef hb_bool_t (*is_immutable_func_t) (void *obj);
typedef struct {
create_func_t create;
create_func_t create_inert;
+ create_func_t get_empty;
reference_func_t reference;
destroy_func_t destroy;
set_user_data_func_t set_user_data;
@@ -137,6 +138,7 @@ typedef struct {
{ \
(create_func_t) create_##name, \
(create_func_t) create_##name##_inert, \
+ (create_func_t) hb_##name##_get_empty, \
(reference_func_t) hb_##name##_reference, \
(destroy_func_t) hb_##name##_destroy, \
(set_user_data_func_t) hb_##name##_set_user_data, \
@@ -149,6 +151,7 @@ typedef struct {
{ \
(create_func_t) create_##name, \
(create_func_t) create_##name##_inert, \
+ (create_func_t) hb_##name##_get_empty, \
(reference_func_t) hb_##name##_reference, \
(destroy_func_t) hb_##name##_destroy, \
(set_user_data_func_t) hb_##name##_set_user_data, \
@@ -308,10 +311,37 @@ test_object (void)
{
data_t data[2] = {{MAGIC0, FALSE}, {MAGIC1, FALSE}};
+ g_test_message ("->get_empty()");
+ obj = o->get_empty ();
+ g_assert (obj);
+
+ g_assert (obj == o->reference (obj));
+ o->destroy (obj);
+
+ if (o->is_immutable)
+ g_assert (o->is_immutable (obj));
+
+ g_assert (!o->set_user_data (obj, &key[0], &data[0], free_up0));
+ g_assert (!o->get_user_data (obj, &key[0]));
+
+ o->destroy (obj);
+ o->destroy (obj);
+ o->destroy (obj);
+ o->destroy (obj);
+ o->destroy (obj);
+
+ g_assert (!data[0].freed);
+ }
+
+ {
+ data_t data[2] = {{MAGIC0, FALSE}, {MAGIC1, FALSE}};
+
g_test_message ("->create_inert()");
obj = o->create_inert ();
if (!obj)
continue;
+ if (obj == o->get_empty ())
+ continue; /* Tested already */
g_assert (obj == o->reference (obj));
o->destroy (obj);
commit d3b30be378c1dec0259a626d9a408bb9ca1b71ac
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed May 11 18:06:12 2011 -0400
[API] Add HB_UNTAG()
Useful in C API only.
diff --git a/src/hb-common.h b/src/hb-common.h
index 9546b21..a30587a 100644
--- a/src/hb-common.h
+++ b/src/hb-common.h
@@ -74,6 +74,7 @@ typedef union _hb_var_int_t {
typedef uint32_t hb_tag_t;
#define HB_TAG(a,b,c,d) ((hb_tag_t)((((uint8_t)(a))<<24)|(((uint8_t)(b))<<16)|(((uint8_t)(c))<<8)|((uint8_t)(d))))
+#define HB_UNTAG(tag) ((uint8_t)((tag)>>24)), ((uint8_t)((tag)>>16)), ((uint8_t)((tag)>>8)), ((uint8_t)(tag))
#define HB_TAG_NONE HB_TAG(0,0,0,0)
commit 3cc6e9dcb42551761c3a1a9d3c25b1f1bcdc2419
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed May 11 18:02:48 2011 -0400
Minor
diff --git a/src/test.cc b/src/test.cc
index c185430..79d7841 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -57,6 +57,7 @@ main (int argc, char **argv)
unsigned int len;
hb_destroy_func_t destroy;
void *user_data;
+ hb_memory_mode_t mm;
#ifdef HAVE_GLIB
GMappedFile *mf = g_mapped_file_new (argv[1], FALSE, NULL);
@@ -64,6 +65,7 @@ main (int argc, char **argv)
len = g_mapped_file_get_length (mf);
destroy = (hb_destroy_func_t) g_mapped_file_unref;
user_data = (void *) mf;
+ mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE;
#else
FILE *f = fopen (argv[1], "rb");
fseek (f, 0, SEEK_END);
@@ -75,13 +77,14 @@ main (int argc, char **argv)
destroy = free;
user_data = (void *) font_data;
fclose (f);
+ mm = HB_MEMORY_MODE_WRITABLE;
#endif
- blob = hb_blob_create (font_data, len,
- HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE,
- user_data, destroy);
+ blob = hb_blob_create (font_data, len, mm, user_data, destroy);
}
+ printf ("Opened font file %s: %u bytes long\n", argv[1], hb_blob_get_length (blob));
+
/* Create the face */
face = hb_face_create_for_data (blob, 0 /* first face */);
More information about the HarfBuzz
mailing list