This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/myddas/myddas_initialization.c

114 lines
2.8 KiB
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
2015-02-09 10:19:15 +00:00
#if MYDDAS_SQLITE3
#include <sqlite3.h>
#endif
#include "Yap.h"
#include "myddas.h"
#ifdef MYDDAS_STATS
#include "myddas_statistics.h"
#endif
MYDDAS_GLOBAL
2016-01-03 02:06:09 +00:00
myddas_init_initialize_myddas(void) {
MYDDAS_GLOBAL global = NULL;
/* We cannot call MYDDAS_MALLOC were because the global
register isn't yet initialized */
2016-01-03 02:06:09 +00:00
global = (MYDDAS_GLOBAL)malloc(sizeof(struct myddas_global));
2015-02-14 11:35:07 +00:00
#ifdef DEBUGX
2016-01-03 02:06:09 +00:00
printf("MALLOC %p %s %d\n", global, __FILE__, __LINE__);
#endif
global->myddas_top_connections = NULL;
#ifdef MYDDAS_TOP_LEVEL
global->myddas_top_level_connection = NULL;
#endif
#ifdef MYDDAS_STATS
2016-01-03 02:06:09 +00:00
global->myddas_statistics =
(MYDDAS_GLOBAL_STATS)malloc(sizeof(struct myddas_global_stats));
#ifdef DEBUG
2016-01-03 02:06:09 +00:00
printf("MALLOC %p %s %d\n", global->myddas_statistics, __FILE__, __LINE__);
#endif
global->myddas_statistics->stats = NULL;
#endif
#ifdef DEBUG
2016-01-03 02:06:09 +00:00
/* We first malloc for this struct and the stats struct */
#ifdef MYDDAS_STATS
global->malloc_called = 2;
2016-01-03 02:06:09 +00:00
global->memory_allocated =
sizeof(struct myddas_global) + sizeof(struct myddas_global_stats);
#else
global->malloc_called = 1;
global->memory_allocated = sizeof(struct myddas_global);
#endif /* MYDDAS_STATS */
global->free_called = 0;
global->memory_freed = 0;
#endif
return global;
}
/* Inserts the new node on the front of the list */
MYDDAS_UTIL_CONNECTION
2016-01-03 02:06:09 +00:00
myddas_init_initialize_connection(void *conn, void *enviromment, MYDDAS_API api,
MYDDAS_UTIL_CONNECTION next) {
CACHE_REGS
MYDDAS_UTIL_CONNECTION new = NULL;
2016-01-03 02:06:09 +00:00
MYDDAS_MALLOC(new, struct myddas_list_connection);
2016-01-03 02:06:09 +00:00
if (new == NULL) {
return NULL;
}
2015-02-14 11:35:07 +00:00
new->api = api;
2016-01-03 02:06:09 +00:00
new->predicates = NULL;
new->connection = conn;
new->odbc_enviromment = enviromment;
/* It saves n queries, doing at once n+1 queries */
2016-01-03 02:06:09 +00:00
new->total_number_queries = 0; // Default
new->actual_number_queries = 0;
new->queries = NULL;
/* List integrity */
2016-01-03 02:06:09 +00:00
new->next = next;
new->previous = NULL;
/* If there's already at least one node
on the list */
if (next != NULL)
2016-01-03 02:06:09 +00:00
next->previous = new;
#ifdef MYDDAS_STATS
new->stats = NULL;
new->stats = myddas_stats_initialize_connection_stats();
#endif
return new;
}
MYDDAS_UTIL_PREDICATE
2015-06-19 01:19:48 +01:00
myddas_init_initialize_predicate(const char *pred_name, int pred_arity,
2016-01-03 02:06:09 +00:00
const char *pred_module,
MYDDAS_UTIL_PREDICATE next) {
CACHE_REGS
MYDDAS_UTIL_PREDICATE new = NULL;
2016-01-03 02:06:09 +00:00
MYDDAS_MALLOC(new, struct myddas_list_preds);
2016-01-03 02:06:09 +00:00
if (new == NULL) {
return NULL;
}
new->pred_name = pred_name;
new->pred_arity = pred_arity;
new->pred_module = pred_module;
/* List integrity */
2016-01-03 02:06:09 +00:00
new->next = next;
new->previous = NULL;
/* If there's already at least one node
on the list */
if (next != NULL)
2016-01-03 02:06:09 +00:00
next->previous = new;
return new;
}