Override libtommath allocation procedures

This commit is contained in:
gingerBill
2021-07-14 23:36:23 +01:00
parent e15858e2be
commit 10f4d8df32
4 changed files with 59 additions and 27 deletions
+31
View File
@@ -1,5 +1,36 @@
#include "libtommath/tommath.h"
#if 0
void *MP_MALLOC(size_t size) {
return malloc(size);
}
void *MP_REALLOC(void *mem, size_t oldsize, size_t newsize) {
return realloc(mem, newsize);
}
void *MP_CALLOC(size_t nmemb, size_t size) {
return calloc(nmemb, size);
}
void MP_FREE(void *mem, size_t size) {
free(mem);
}
#else
void *MP_MALLOC(size_t size) {
return gb_alloc(permanent_allocator(), cast(isize)size);
}
void *MP_REALLOC(void *mem, size_t oldsize, size_t newsize) {
return gb_resize(permanent_allocator(), mem, cast(isize)oldsize, cast(isize)newsize);
}
void *MP_CALLOC(size_t nmemb, size_t size) {
size_t total = nmemb*size;
return gb_alloc(permanent_allocator(), cast(isize)total);
}
void MP_FREE(void *mem, size_t size) {
// DO NOTHING
}
#endif
#ifndef MAX_BIG_INT_SHIFT
#define MAX_BIG_INT_SHIFT 1024
#endif
+6 -6
View File
@@ -849,8 +849,8 @@ void init_checker_info(CheckerInfo *i) {
string_map_init(&i->files, a);
string_map_init(&i->packages, a);
array_init(&i->variable_init_order, a);
array_init(&i->required_foreign_imports_through_force, a);
array_init(&i->testing_procedures, a, 0, 0);
array_init(&i->required_foreign_imports_through_force, a, 0, 0);
i->allow_identifier_uses = build_context.query_data_set_settings.kind == QueryDataSet_GoToDefinitions;
@@ -864,6 +864,7 @@ void init_checker_info(CheckerInfo *i) {
mpmc_init(&i->entity_queue, a, 1<<20);
mpmc_init(&i->definition_queue, a, 1<<20);
mpmc_init(&i->required_global_variable_queue, a, 1<<10);
mpmc_init(&i->required_foreign_imports_through_force_queue, a, 1<<10);
TIME_SECTION("checker info: mutexes");
@@ -897,6 +898,7 @@ void destroy_checker_info(CheckerInfo *i) {
mpmc_destroy(&i->entity_queue);
mpmc_destroy(&i->definition_queue);
mpmc_destroy(&i->required_global_variable_queue);
mpmc_destroy(&i->required_foreign_imports_through_force_queue);
gb_mutex_destroy(&i->gen_procs_mutex);
gb_mutex_destroy(&i->gen_types_mutex);
@@ -1893,8 +1895,8 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) {
}
}
for_array(i, c->info.required_foreign_imports_through_force) {
Entity *e = c->info.required_foreign_imports_through_force[i];
for (Entity *e; mpmc_dequeue(&c->info.required_foreign_imports_through_force_queue, &e); /**/) {
array_add(&c->info.required_foreign_imports_through_force, e);
add_dependency_to_set(c, e);
}
@@ -3793,9 +3795,7 @@ void check_add_foreign_import_decl(CheckerContext *ctx, Ast *decl) {
AttributeContext ac = {};
check_decl_attributes(ctx, fl->attributes, foreign_import_decl_attribute, &ac);
if (ac.require_declaration) {
mutex_lock(&ctx->info->foreign_mutex);
array_add(&ctx->info->required_foreign_imports_through_force, e);
mutex_unlock(&ctx->info->foreign_mutex);
mpmc_enqueue(&ctx->info->required_foreign_imports_through_force_queue, e);
add_entity_use(ctx, nullptr, e);
}
}
+13 -12
View File
@@ -291,27 +291,27 @@ struct CheckerInfo {
Array<Entity *> definitions;
Array<Entity *> entities;
Array<Entity *> required_foreign_imports_through_force;
// Below are accessed within procedures
// NOTE(bill): If the semantic checker (check_proc_body) is to ever to be multithreaded,
// these variables will be of contention
gbMutex gen_procs_mutex; // Possibly recursive
gbMutex gen_types_mutex; // Possibly recursive
BlockingMutex deps_mutex; // NOT recursive & Only used in `check_proc_body`
BlockingMutex scope_mutex; // NOT recursive & Only used in `create_scope`
gbMutex gen_procs_mutex; // Possibly recursive
gbMutex gen_types_mutex; // Possibly recursive
Map<Array<Entity *> > gen_procs; // Key: Ast * | Identifier -> Entity
Map<Array<Entity *> > gen_types; // Key: Type *
BlockingMutex type_info_mutex; // NOT recursive
BlockingMutex deps_mutex; // NOT recursive & Only used in `check_proc_body`
BlockingMutex foreign_mutex; // NOT recursive
BlockingMutex scope_mutex; // NOT recursive & Only used in `create_scope`
Map<Array<Entity *> > gen_procs; // Key: Ast * | Identifier -> Entity
Map<Array<Entity *> > gen_types; // Key: Type *
Array<Type *> type_info_types;
Map<isize> type_info_map; // Key: Type *
Array<Type *> type_info_types;
Map<isize> type_info_map; // Key: Type *
BlockingMutex foreign_mutex; // NOT recursive
StringMap<Entity *> foreigns;
Array<Entity *> required_foreign_imports_through_force;
// only used by 'odin query'
bool allow_identifier_uses;
@@ -323,6 +323,7 @@ struct CheckerInfo {
MPMCQueue<Entity *> definition_queue;
MPMCQueue<Entity *> entity_queue;
MPMCQueue<Entity *> required_global_variable_queue;
MPMCQueue<Entity *> required_foreign_imports_through_force_queue;
};
+9 -9
View File
@@ -89,20 +89,20 @@ do { \
#endif
/* define heap macros */
#ifndef MP_MALLOC
/* default to libc stuff */
# include <stdlib.h>
# define MP_MALLOC(size) malloc(size)
# define MP_REALLOC(mem, oldsize, newsize) realloc((mem), (newsize))
# define MP_CALLOC(nmemb, size) calloc((nmemb), (size))
# define MP_FREE(mem, size) free(mem)
#else
// #ifndef MP_MALLOC
// /* default to libc stuff */
// # include <stdlib.h>
// # define MP_MALLOC(size) malloc(size)
// # define MP_REALLOC(mem, oldsize, newsize) realloc((mem), (newsize))
// # define MP_CALLOC(nmemb, size) calloc((nmemb), (size))
// # define MP_FREE(mem, size) free(mem)
// #else
/* prototypes for our heap functions */
extern void *MP_MALLOC(size_t size);
extern void *MP_REALLOC(void *mem, size_t oldsize, size_t newsize);
extern void *MP_CALLOC(size_t nmemb, size_t size);
extern void MP_FREE(void *mem, size_t size);
#endif
// #endif
/* feature detection macro */
#ifdef _MSC_VER