mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Override libtommath allocation procedures
This commit is contained in:
@@ -1,5 +1,36 @@
|
|||||||
#include "libtommath/tommath.h"
|
#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
|
#ifndef MAX_BIG_INT_SHIFT
|
||||||
#define MAX_BIG_INT_SHIFT 1024
|
#define MAX_BIG_INT_SHIFT 1024
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+6
-6
@@ -849,8 +849,8 @@ void init_checker_info(CheckerInfo *i) {
|
|||||||
string_map_init(&i->files, a);
|
string_map_init(&i->files, a);
|
||||||
string_map_init(&i->packages, a);
|
string_map_init(&i->packages, a);
|
||||||
array_init(&i->variable_init_order, 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->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;
|
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->entity_queue, a, 1<<20);
|
||||||
mpmc_init(&i->definition_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_global_variable_queue, a, 1<<10);
|
||||||
|
mpmc_init(&i->required_foreign_imports_through_force_queue, a, 1<<10);
|
||||||
|
|
||||||
TIME_SECTION("checker info: mutexes");
|
TIME_SECTION("checker info: mutexes");
|
||||||
|
|
||||||
@@ -897,6 +898,7 @@ void destroy_checker_info(CheckerInfo *i) {
|
|||||||
mpmc_destroy(&i->entity_queue);
|
mpmc_destroy(&i->entity_queue);
|
||||||
mpmc_destroy(&i->definition_queue);
|
mpmc_destroy(&i->definition_queue);
|
||||||
mpmc_destroy(&i->required_global_variable_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_procs_mutex);
|
||||||
gb_mutex_destroy(&i->gen_types_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) {
|
for (Entity *e; mpmc_dequeue(&c->info.required_foreign_imports_through_force_queue, &e); /**/) {
|
||||||
Entity *e = c->info.required_foreign_imports_through_force[i];
|
array_add(&c->info.required_foreign_imports_through_force, e);
|
||||||
add_dependency_to_set(c, e);
|
add_dependency_to_set(c, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3793,9 +3795,7 @@ void check_add_foreign_import_decl(CheckerContext *ctx, Ast *decl) {
|
|||||||
AttributeContext ac = {};
|
AttributeContext ac = {};
|
||||||
check_decl_attributes(ctx, fl->attributes, foreign_import_decl_attribute, &ac);
|
check_decl_attributes(ctx, fl->attributes, foreign_import_decl_attribute, &ac);
|
||||||
if (ac.require_declaration) {
|
if (ac.require_declaration) {
|
||||||
mutex_lock(&ctx->info->foreign_mutex);
|
mpmc_enqueue(&ctx->info->required_foreign_imports_through_force_queue, e);
|
||||||
array_add(&ctx->info->required_foreign_imports_through_force, e);
|
|
||||||
mutex_unlock(&ctx->info->foreign_mutex);
|
|
||||||
add_entity_use(ctx, nullptr, e);
|
add_entity_use(ctx, nullptr, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-12
@@ -291,27 +291,27 @@ struct CheckerInfo {
|
|||||||
|
|
||||||
Array<Entity *> definitions;
|
Array<Entity *> definitions;
|
||||||
Array<Entity *> entities;
|
Array<Entity *> entities;
|
||||||
|
Array<Entity *> required_foreign_imports_through_force;
|
||||||
|
|
||||||
|
|
||||||
// Below are accessed within procedures
|
// Below are accessed within procedures
|
||||||
// NOTE(bill): If the semantic checker (check_proc_body) is to ever to be multithreaded,
|
// NOTE(bill): If the semantic checker (check_proc_body) is to ever to be multithreaded,
|
||||||
// these variables will be of contention
|
// these variables will be of contention
|
||||||
|
|
||||||
gbMutex gen_procs_mutex; // Possibly recursive
|
BlockingMutex deps_mutex; // NOT recursive & Only used in `check_proc_body`
|
||||||
gbMutex gen_types_mutex; // Possibly recursive
|
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 type_info_mutex; // NOT recursive
|
||||||
BlockingMutex deps_mutex; // NOT recursive & Only used in `check_proc_body`
|
Array<Type *> type_info_types;
|
||||||
BlockingMutex foreign_mutex; // NOT recursive
|
Map<isize> type_info_map; // Key: Type *
|
||||||
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 *
|
|
||||||
|
|
||||||
|
BlockingMutex foreign_mutex; // NOT recursive
|
||||||
StringMap<Entity *> foreigns;
|
StringMap<Entity *> foreigns;
|
||||||
Array<Entity *> required_foreign_imports_through_force;
|
|
||||||
|
|
||||||
// only used by 'odin query'
|
// only used by 'odin query'
|
||||||
bool allow_identifier_uses;
|
bool allow_identifier_uses;
|
||||||
@@ -323,6 +323,7 @@ struct CheckerInfo {
|
|||||||
MPMCQueue<Entity *> definition_queue;
|
MPMCQueue<Entity *> definition_queue;
|
||||||
MPMCQueue<Entity *> entity_queue;
|
MPMCQueue<Entity *> entity_queue;
|
||||||
MPMCQueue<Entity *> required_global_variable_queue;
|
MPMCQueue<Entity *> required_global_variable_queue;
|
||||||
|
MPMCQueue<Entity *> required_foreign_imports_through_force_queue;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -89,20 +89,20 @@ do { \
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* define heap macros */
|
/* define heap macros */
|
||||||
#ifndef MP_MALLOC
|
// #ifndef MP_MALLOC
|
||||||
/* default to libc stuff */
|
// /* default to libc stuff */
|
||||||
# include <stdlib.h>
|
// # include <stdlib.h>
|
||||||
# define MP_MALLOC(size) malloc(size)
|
// # define MP_MALLOC(size) malloc(size)
|
||||||
# define MP_REALLOC(mem, oldsize, newsize) realloc((mem), (newsize))
|
// # define MP_REALLOC(mem, oldsize, newsize) realloc((mem), (newsize))
|
||||||
# define MP_CALLOC(nmemb, size) calloc((nmemb), (size))
|
// # define MP_CALLOC(nmemb, size) calloc((nmemb), (size))
|
||||||
# define MP_FREE(mem, size) free(mem)
|
// # define MP_FREE(mem, size) free(mem)
|
||||||
#else
|
// #else
|
||||||
/* prototypes for our heap functions */
|
/* prototypes for our heap functions */
|
||||||
extern void *MP_MALLOC(size_t size);
|
extern void *MP_MALLOC(size_t size);
|
||||||
extern void *MP_REALLOC(void *mem, size_t oldsize, size_t newsize);
|
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_CALLOC(size_t nmemb, size_t size);
|
||||||
extern void MP_FREE(void *mem, size_t size);
|
extern void MP_FREE(void *mem, size_t size);
|
||||||
#endif
|
// #endif
|
||||||
|
|
||||||
/* feature detection macro */
|
/* feature detection macro */
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|||||||
Reference in New Issue
Block a user