string_utils: revert changes and merge with upstream
This commit is contained in:
@@ -284,7 +284,7 @@ phrase_t search_address_dictionaries_suffix(char *str, size_t len, char *lang) {
|
|||||||
bool address_dictionary_init(void) {
|
bool address_dictionary_init(void) {
|
||||||
if (address_dict != NULL) return false;
|
if (address_dict != NULL) return false;
|
||||||
|
|
||||||
address_dict = malloc(sizeof(address_dictionary_t));
|
address_dict = calloc(1, sizeof(address_dictionary_t));
|
||||||
if (address_dict == NULL) return false;
|
if (address_dict == NULL) return false;
|
||||||
|
|
||||||
address_dict->canonical = cstring_array_new();
|
address_dict->canonical = cstring_array_new();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ static address_parser_t *parser = NULL;
|
|||||||
|
|
||||||
|
|
||||||
address_parser_t *address_parser_new(void) {
|
address_parser_t *address_parser_new(void) {
|
||||||
address_parser_t *parser = malloc(sizeof(address_parser_t));
|
address_parser_t *parser = calloc(1, sizeof(address_parser_t));
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ averaged_perceptron_t *averaged_perceptron_read(FILE *f) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
averaged_perceptron_t *perceptron = malloc(sizeof(averaged_perceptron_t));
|
averaged_perceptron_t *perceptron = calloc(1, sizeof(averaged_perceptron_t));
|
||||||
|
|
||||||
if (!file_read_uint32(f, &perceptron->num_features) ||
|
if (!file_read_uint32(f, &perceptron->num_features) ||
|
||||||
!file_read_uint32(f, &perceptron->num_classes) ||
|
!file_read_uint32(f, &perceptron->num_classes) ||
|
||||||
@@ -216,4 +216,4 @@ void averaged_perceptron_destroy(averaged_perceptron_t *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(self);
|
free(self);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -389,7 +389,7 @@ bool averaged_perceptron_trainer_train_example(averaged_perceptron_trainer_t *se
|
|||||||
}
|
}
|
||||||
|
|
||||||
averaged_perceptron_trainer_t *averaged_perceptron_trainer_new(void) {
|
averaged_perceptron_trainer_t *averaged_perceptron_trainer_new(void) {
|
||||||
averaged_perceptron_trainer_t *self = malloc(sizeof(averaged_perceptron_trainer_t));
|
averaged_perceptron_trainer_t *self = calloc(1, sizeof(averaged_perceptron_trainer_t));
|
||||||
|
|
||||||
if (self == NULL) return NULL;
|
if (self == NULL) return NULL;
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ int bloom_filter_add(bloom_filter_t *self, const char *key, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bloom_filter_t *bloom_filter_new(uint64_t capacity, double error) {
|
bloom_filter_t *bloom_filter_new(uint64_t capacity, double error) {
|
||||||
bloom_filter_t *bloom = malloc(sizeof(bloom_filter_t));
|
bloom_filter_t *bloom = calloc(1, sizeof(bloom_filter_t));
|
||||||
|
|
||||||
if (bloom == NULL) {
|
if (bloom == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -220,4 +220,4 @@ void bloom_filter_destroy(bloom_filter_t *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(self);
|
free(self);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ void geodb_destroy(geodb_t *self) {
|
|||||||
geodb_t *geodb_init(char *dir) {
|
geodb_t *geodb_init(char *dir) {
|
||||||
if (dir == NULL) return NULL;
|
if (dir == NULL) return NULL;
|
||||||
|
|
||||||
geodb_t *gdb = malloc(sizeof(geodb_t));
|
geodb_t *gdb = calloc(1, sizeof(geodb_t));
|
||||||
|
|
||||||
if (gdb == NULL) return NULL;
|
if (gdb == NULL) return NULL;
|
||||||
|
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ void geodb_builder_destroy(geodb_builder_t *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
geodb_builder_t *geodb_builder_new(char *log_filename) {
|
geodb_builder_t *geodb_builder_new(char *log_filename) {
|
||||||
geodb_builder_t *builder = malloc(sizeof(geodb_builder_t));
|
geodb_builder_t *builder = calloc(1, sizeof(geodb_builder_t));
|
||||||
|
|
||||||
if (builder == NULL) return NULL;
|
if (builder == NULL) return NULL;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
|
|
||||||
graph_t *graph_new_dims(graph_type_t type, uint32_t m, uint32_t n, size_t nnz, bool fixed_rows) {
|
graph_t *graph_new_dims(graph_type_t type, uint32_t m, uint32_t n, size_t nnz, bool fixed_rows) {
|
||||||
graph_t *graph = malloc(sizeof(graph_t));
|
graph_t *graph = calloc(1, sizeof(graph_t));
|
||||||
graph->m = m;
|
graph->m = m;
|
||||||
graph->fixed_rows = fixed_rows;
|
graph->fixed_rows = fixed_rows;
|
||||||
graph->n = n;
|
graph->n = n;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ void language_classifier_destroy(language_classifier_t *self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
language_classifier_t *language_classifier_new(void) {
|
language_classifier_t *language_classifier_new(void) {
|
||||||
language_classifier_t *language_classifier = malloc(sizeof(language_classifier_t));
|
language_classifier_t *language_classifier = calloc(1, sizeof(language_classifier_t));
|
||||||
return language_classifier;
|
return language_classifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ numex_table_t *numex_table_init(void) {
|
|||||||
numex_table_t *numex_table = get_numex_table();
|
numex_table_t *numex_table = get_numex_table();
|
||||||
|
|
||||||
if (numex_table == NULL) {
|
if (numex_table == NULL) {
|
||||||
numex_table = malloc(sizeof(numex_table_t));
|
numex_table = calloc(1, sizeof(numex_table_t));
|
||||||
|
|
||||||
if (numex_table == NULL) return NULL;
|
if (numex_table == NULL) return NULL;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "klib/ksort.h"
|
#include "klib/ksort.h"
|
||||||
|
|
||||||
sparse_matrix_t *sparse_matrix_new_shape(size_t m, size_t n) {
|
sparse_matrix_t *sparse_matrix_new_shape(size_t m, size_t n) {
|
||||||
sparse_matrix_t *matrix = malloc(sizeof(sparse_matrix_t));
|
sparse_matrix_t *matrix = calloc(1, sizeof(sparse_matrix_t));
|
||||||
if (matrix == NULL) return NULL;
|
if (matrix == NULL) return NULL;
|
||||||
matrix->m = m;
|
matrix->m = m;
|
||||||
matrix->n = n;
|
matrix->n = n;
|
||||||
|
|||||||
@@ -711,16 +711,17 @@ cstring_array *cstring_array_new_size(size_t size) {
|
|||||||
|
|
||||||
cstring_array *cstring_array_from_char_array(char_array *str) {
|
cstring_array *cstring_array_from_char_array(char_array *str) {
|
||||||
cstring_array *array = malloc(sizeof(cstring_array));
|
cstring_array *array = malloc(sizeof(cstring_array));
|
||||||
if (array == NULL || str==NULL || str->n==0) return NULL;
|
if (array == NULL || str == NULL) return NULL;
|
||||||
|
|
||||||
array->str = str;
|
array->str = str;
|
||||||
array->indices = uint32_array_new_size(1);
|
array->indices = uint32_array_new_size(1);
|
||||||
uint32_array_push(array->indices, 0);
|
uint32_array_push(array->indices, 0);
|
||||||
char *ptr = str->a;
|
char *ptr = str->a;
|
||||||
uint32_t i = 0;
|
if (str->n > 0) {
|
||||||
for (i = 0; i < str->n - 1; i++, ptr++) {
|
for (uint32_t i = 0; i < str->n - 1; i++, ptr++) {
|
||||||
if (*ptr == '\0') {
|
if (*ptr == '\0') {
|
||||||
uint32_array_push(array->indices, i + 1);
|
uint32_array_push(array->indices, i + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
|
|||||||
@@ -1087,7 +1087,7 @@ transliteration_table_t *transliteration_table_init(void) {
|
|||||||
transliteration_table_t *trans_table = get_transliteration_table();
|
transliteration_table_t *trans_table = get_transliteration_table();
|
||||||
|
|
||||||
if (trans_table == NULL) {
|
if (trans_table == NULL) {
|
||||||
trans_table = malloc(sizeof(transliteration_table_t));
|
trans_table = calloc(1, sizeof(transliteration_table_t));
|
||||||
|
|
||||||
trans_table->trie = trie_new();
|
trans_table->trie = trie_new();
|
||||||
if (trans_table->trie == NULL) {
|
if (trans_table->trie == NULL) {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ Constructors
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static trie_t *trie_new_empty(uint8_t *alphabet, uint32_t alphabet_size) {
|
static trie_t *trie_new_empty(uint8_t *alphabet, uint32_t alphabet_size) {
|
||||||
trie_t *self = malloc(sizeof(trie_t));
|
trie_t *self = calloc(1, sizeof(trie_t));
|
||||||
if (!self)
|
if (!self)
|
||||||
goto exit_no_malloc;
|
goto exit_no_malloc;
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ static inline void _aligned_free(void *p)
|
|||||||
name *array = malloc(sizeof(name)); \
|
name *array = malloc(sizeof(name)); \
|
||||||
if (array == NULL) return NULL; \
|
if (array == NULL) return NULL; \
|
||||||
array->n = array->m = 0; \
|
array->n = array->m = 0; \
|
||||||
array->a = malloc(size * sizeof(type)); \
|
array->a = malloc((size > 0 ? size : 1) * sizeof(type)); \
|
||||||
if (array->a == NULL) return NULL; \
|
if (array->a == NULL) return NULL; \
|
||||||
array->m = size; \
|
array->m = size; \
|
||||||
return array; \
|
return array; \
|
||||||
|
|||||||
Reference in New Issue
Block a user