diff --git a/src/libpostal.c b/src/libpostal.c index 05002c39..f3931d6f 100644 --- a/src/libpostal.c +++ b/src/libpostal.c @@ -429,7 +429,7 @@ void add_affix_expansions(string_tree_t *tree, char *str, char *lang, token_t to char_array *key = char_array_new_size(token.len); char *expansion; - uint64_t num_strings = 0; + size_t num_strings = 0; char *root_word = NULL; size_t root_len; token_t root_token; @@ -751,7 +751,7 @@ void expand_alternative(cstring_array *strings, khash_t(str_set) *unique_strings -char **expand_address(char *input, normalize_options_t options, uint64_t *n) { +char **expand_address(char *input, normalize_options_t options, size_t *n) { options.address_components |= ADDRESS_ANY; uint64_t normalize_string_options = 0; diff --git a/src/libpostal.h b/src/libpostal.h index 17ab9468..1f15d53a 100644 --- a/src/libpostal.h +++ b/src/libpostal.h @@ -85,7 +85,7 @@ static normalize_options_t LIBPOSTAL_DEFAULT_OPTIONS = { .roman_numerals = 1 }; -char **expand_address(char *input, normalize_options_t options, uint64_t *n); +char **expand_address(char *input, normalize_options_t options, size_t *n); /* Address parser diff --git a/src/vector.h b/src/vector.h index c431165c..e2952f52 100644 --- a/src/vector.h +++ b/src/vector.h @@ -5,6 +5,31 @@ #define DEFAULT_VECTOR_SIZE 8 +#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__) +#include +#else +#include +static inline void *_aligned_malloc(size_t size, size_t alignment) +{ + void *p; + int ret = posix_memalign(&p, alignment, size); + return (ret == 0) ? p : 0; +} +static inline void _aligned_free(void *p) +{ + free(p); +} +#endif + +#ifdef _MSC_VER +#define MIE_ALIGN(x) __declspec(align(x)) +#else +#define MIE_ALIGN(x) __attribute__((aligned(x))) +#endif + +#define CONST_128D(var, val) \ + MIE_ALIGN(16) static const double var[2] = {(val), (val)} + // Based kvec.h, dynamic vectors of any type #define __VECTOR_BASE(name, type) typedef struct { size_t n, m; type *a; } name; \ static inline name *name##_new_size(size_t size) { \ @@ -19,6 +44,15 @@ static inline name *name##_new(void) { \ return name##_new_size(DEFAULT_VECTOR_SIZE); \ } \ + static inline name *name##_new_aligned(size_t size, size_t alignment) { \ + name *array = malloc(sizeof(name)); \ + if (array == NULL) return NULL; \ + array->n = array->m = 0; \ + array->a = _aligned_malloc(size * sizeof(type), alignment); \ + if (array->a == NULL) return NULL; \ + array->m = size; \ + return array; \ + } \ static inline void name##_resize(name *array, size_t size) { \ if (size <= array->m) return; \ type *ptr = realloc(array->a, sizeof(type) * size); \ @@ -59,7 +93,6 @@ return cpy; \ } - #define __VECTOR_DESTROY(name, type) \ static inline void name##_destroy(name *array) { \ if (array == NULL) return; \