* Red Hat Author(s): Behdad Esfahbod
*/
-#ifndef HB_OPEN_TYPES_PRIVATE_HH
-#define HB_OPEN_TYPES_PRIVATE_HH
+#ifndef HB_OPEN_TYPE_PRIVATE_HH
+#define HB_OPEN_TYPE_PRIVATE_HH
#include "hb-private.h"
#include "hb-blob.h"
+HB_BEGIN_DECLS
+HB_END_DECLS
/*
*/
/* Global nul-content Null pool. Enlarge as necessary. */
-static const void *_NullPool[16 / sizeof (void *)];
+static const void *_NullPool[64 / sizeof (void *)];
/* Generic nul-content Null objects. */
template <typename Type>
-static inline const Type& Null () {
+static inline const Type& Null (void) {
ASSERT_STATIC (Type::min_size <= sizeof (_NullPool));
return *CastP<Type> (_NullPool);
}
#define DEFINE_NULL_DATA(Type, data) \
static const char _Null##Type[Type::min_size + 1] = data; /* +1 is for nul-termination in data */ \
template <> \
-inline const Type& Null<Type> () { \
+inline const Type& Null<Type> (void) { \
return *CastP<Type> (_Null##Type); \
} /* The following line really exists such that we end in a place needing semicolon */ \
ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type))
this->debug_depth = 0;
if (HB_DEBUG_SANITIZE)
- fprintf (stderr, "sanitize %p init [%p..%p] (%u bytes)\n",
- this->blob, this->start, this->end, this->end - this->start);
+ fprintf (stderr, "sanitize %p init [%p..%p] (%lu bytes)\n",
+ this->blob, this->start, this->end,
+ (unsigned long) (this->end - this->start));
}
inline void finish (void)
inline bool check_array (const void *base, unsigned int record_size, unsigned int len) const
{
const char *p = (const char *) base;
- bool overflows = len >= ((unsigned int) -1) / record_size;
+ bool overflows = record_size > 0 && len >= ((unsigned int) -1) / record_size;
if (HB_DEBUG_SANITIZE && (int) this->debug_depth < (int) HB_DEBUG_SANITIZE)
fprintf (stderr, "SANITIZE(%p) %-*d-> array [%p..%p] (%d*%d=%ld bytes) in [%p..%p] -> %s\n", \
/* TODO is_sane() stuff */
+ if (!blob)
+ return hb_blob_create_empty ();
+
retry:
if (HB_DEBUG_SANITIZE)
fprintf (stderr, "Sanitizer %p start %s\n", blob, HB_FUNC);
class BEInt<Type, 2>
{
public:
- inline class BEInt<Type,2>& operator = (Type i) { hb_be_uint16_put (v,i); return *this; }
- inline operator Type () const { return hb_be_uint16_get (v); }
+ inline void set (Type i) { hb_be_uint16_put (v,i); }
+ inline operator Type (void) const { return hb_be_uint16_get (v); }
inline bool operator == (const BEInt<Type, 2>& o) const { return hb_be_uint16_cmp (v, o.v); }
inline bool operator != (const BEInt<Type, 2>& o) const { return !(*this == o); }
private: uint8_t v[2];
class BEInt<Type, 4>
{
public:
- inline class BEInt<Type,4>& operator = (Type i) { hb_be_uint32_put (v,i); return *this; }
- inline operator Type () const { return hb_be_uint32_get (v); }
+ inline void set (Type i) { hb_be_uint32_put (v,i); }
+ inline operator Type (void) const { return hb_be_uint32_get (v); }
inline bool operator == (const BEInt<Type, 4>& o) const { return hb_be_uint32_cmp (v, o.v); }
inline bool operator != (const BEInt<Type, 4>& o) const { return !(*this == o); }
private: uint8_t v[4];
template <typename Type>
struct IntType
{
- inline void set (Type i) { v = i; }
+ inline void set (Type i) { v.set (i); }
inline operator Type(void) const { return v; }
inline bool operator == (const IntType<Type> &o) const { return v == o.v; }
inline bool operator != (const IntType<Type> &o) const { return v != o.v; }
+ inline int cmp (Type a) const { Type b = v; return a < b ? -1 : a == b ? 0 : +1; }
inline bool sanitize (hb_sanitize_context_t *c) {
TRACE_SANITIZE ();
return likely (c->check_struct (this));
typedef IntType<uint32_t> ULONG; /* 32-bit unsigned integer. */
typedef IntType<int32_t> LONG; /* 32-bit signed integer. */
+/* Date represented in number of seconds since 12:00 midnight, January 1,
+ * 1904. The value is represented as a signed 64-bit integer. */
+struct LONGDATETIME
+{
+ inline bool sanitize (hb_sanitize_context_t *c) {
+ TRACE_SANITIZE ();
+ return likely (c->check_struct (this));
+ }
+ private:
+ LONG major;
+ ULONG minor;
+ public:
+ DEFINE_SIZE_STATIC (8);
+};
+
/* Array of four uint8s (length = 32 bits) used to identify a script, language
* system, feature, or baseline */
struct Tag : ULONG
if (unlikely (i >= len)) return Null(Type);
return array[i];
}
- inline unsigned int get_size () const
+ inline unsigned int get_size (void) const
{ return len.static_size + len * Type::static_size; }
inline bool sanitize (hb_sanitize_context_t *c) {
if (unlikely (i >= len || !i)) return Null(Type);
return array[i-1];
}
- inline unsigned int get_size () const
+ inline unsigned int get_size (void) const
{ return len.static_size + (len ? len - 1 : 0) * Type::static_size; }
inline bool sanitize_shallow (hb_sanitize_context_t *c) {
};
+/* An array with sorted elements. Supports binary searching. */
+template <typename Type>
+struct SortedArrayOf : ArrayOf<Type> {
+
+ template <typename SearchType>
+ inline int search (const SearchType &x) const {
+ class Cmp {
+ public: static int cmp (const SearchType *a, const Type *b) { return b->cmp (*a); }
+ };
+ const Type *p = (const Type *) bsearch (&x, this->array, this->len, sizeof (this->array[0]), (hb_compare_func_t) Cmp::cmp);
+ return p ? p - this->array : -1;
+ }
+};
+
+
+HB_BEGIN_DECLS
+HB_END_DECLS
+
#endif /* HB_OPEN_TYPE_PRIVATE_HH */