Skip to content

Commit

Permalink
Merge branch 'python' of https://github.com/JCoym/julea into python
Browse files Browse the repository at this point in the history
  • Loading branch information
JCoym committed Mar 23, 2020
2 parents faae5e1 + db56bb8 commit 2cb0a3c
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions include/core/jbackend-operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct JBackendOperationParam

typedef struct JBackendOperationParam JBackendOperationParam;

// FIXME this also needs to be allocated with alignment but appears to be large enough to the default allocator does the right thing
struct JBackendOperation
{
// Input parameters
Expand Down
1 change: 1 addition & 0 deletions include/core/jhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ guint32 j_helper_hash(gchar const*);
// FIXME get rid of GSocketConnection
void j_helper_set_nodelay(GSocketConnection*, gboolean);
gchar* j_helper_str_replace(gchar const*, gchar const*, gchar const*);
gpointer j_helper_alloc_aligned(gsize, gsize);

G_END_DECLS

Expand Down
16 changes: 16 additions & 0 deletions lib/core/jhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <netinet/in.h>
#include <netinet/tcp.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>

Expand Down Expand Up @@ -204,6 +205,21 @@ j_helper_hash(gchar const* str)
return hash;
}

gpointer
j_helper_alloc_aligned(gsize align, gsize len)
{
gpointer buf;

buf = aligned_alloc(align, len);

if (buf == NULL)
{
g_error("Failed to allocate %" G_GSIZE_FORMAT " bytes with %" G_GSIZE_FORMAT " byte alignment", len, align);
}

return buf;
}

/**
* @}
**/
4 changes: 2 additions & 2 deletions lib/db/jdb-entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ j_db_entry_new(JDBSchema* schema, GError** error)
g_return_val_if_fail(schema != NULL, NULL);
g_return_val_if_fail(error == NULL || *error == NULL, NULL);

entry = g_slice_new(JDBEntry);
entry = j_helper_alloc_aligned(128, sizeof(JDBEntry));

if (G_UNLIKELY(!j_bson_init(&entry->bson, error)))
{
Expand Down Expand Up @@ -95,7 +95,7 @@ j_db_entry_unref(JDBEntry* entry)
j_db_schema_unref(entry->schema);
j_bson_destroy(&entry->bson);
j_bson_destroy(&entry->id);
g_slice_free(JDBEntry, entry);
g_free(entry);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/db/jdb-internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ j_db_internal_query(JDBSchema* j_db_schema, JDBSelector* j_db_selector, JDBItera

g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

helper = g_slice_new(JDBIteratorHelper);
helper = j_helper_alloc_aligned(128, sizeof(JDBIteratorHelper));
helper->initialized = FALSE;
memset(&helper->bson, 0, sizeof(bson_t));
j_db_iterator->iterator = helper;
Expand Down Expand Up @@ -506,7 +506,7 @@ j_db_internal_iterate(JDBIterator* j_db_iterator, GError** error)
j_bson_destroy(&helper->bson);

error2:
g_slice_free(JDBIteratorHelper, helper);
g_free(helper);

return FALSE;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/db/jdb-iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ j_db_iterator_new(JDBSchema* schema, JDBSelector* selector, GError** error)
g_return_val_if_fail((selector == NULL) || (selector->schema == schema), NULL);
g_return_val_if_fail(error == NULL || *error == NULL, NULL);

iterator = g_slice_new(JDBIterator);
iterator = j_helper_alloc_aligned(128, sizeof(JDBIterator));
iterator->schema = j_db_schema_ref(schema);

if (G_UNLIKELY(!iterator->schema))
Expand Down Expand Up @@ -139,7 +139,7 @@ j_db_iterator_unref(JDBIterator* iterator)
j_bson_destroy(&iterator->bson);
}

g_slice_free(JDBIterator, iterator);
g_free(iterator);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/db/jdb-schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ j_db_schema_new(gchar const* namespace, gchar const* name, GError** error)

(void)error;

schema = g_slice_new(JDBSchema);
schema = j_helper_alloc_aligned(128, sizeof(JDBSchema));
schema->namespace = g_strdup(namespace);
schema->name = g_strdup(name);
schema->variables = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
Expand Down Expand Up @@ -107,7 +107,7 @@ j_db_schema_unref(JDBSchema* schema)
bson_destroy(&schema->bson_index);
}

g_slice_free(JDBSchema, schema);
g_free(schema);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/db/jdb-selector.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ j_db_selector_new(JDBSchema* schema, JDBSelectorMode mode, GError** error)

g_return_val_if_fail(error == NULL || *error == NULL, NULL);

selector = g_slice_new(JDBSelector);
selector = j_helper_alloc_aligned(128, sizeof(JDBSelector));
selector->ref_count = 1;
selector->mode = mode;
selector->bson_count = 0;
Expand Down Expand Up @@ -92,7 +92,7 @@ j_db_selector_unref(JDBSelector* selector)
{
j_db_schema_unref(selector->schema);
bson_destroy(&selector->bson);
g_slice_free(JDBSelector, selector);
g_free(selector);
}
}

Expand Down
3 changes: 1 addition & 2 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,7 @@ def configure(ctx):

if ctx.options.sanitize:
check_and_add_flags(ctx, '-fsanitize=address', False, ['cflags', 'ldflags'])
# FIXME enable ubsan?
# check_and_add_flags(ctx, '-fsanitize=undefined', False, ['cflags', 'ldflags'])
check_and_add_flags(ctx, '-fsanitize=undefined', False, ['cflags', 'ldflags'])

if ctx.options.coverage:
check_and_add_flags(ctx, '--coverage', True, ['cflags', 'ldflags'])
Expand Down

0 comments on commit 2cb0a3c

Please sign in to comment.