1 #ifndef __MYDDAS_H__
2 #define __MYDDAS_H__
3 
4 #include "config.h"
5 #include <stdio.h>
6 
7 #ifdef MYDDAS_ODBC
8 #include <sql.h>
9 #endif
10 
11 #ifdef MYDDAS_MYSQL
12 #include <mysql/mysql.h>
13 #endif
14 
15 /* MYDDAS TYPES */
16 /* sizeof(MyddasPointer) Equal to the size of a integer on the given architecture */
17 /* sizeof(MyddasInt32) = 4 (Always) */
18 /* sizeof(MyddasUInt32) = 4 (Always) */
19 
20 #if SIZEOF_INT_P==4
21 
22 #  if SIZEOF_INT==4
23 /*   */ typedef int MyddasInt;
24 /*   */ typedef unsigned int MyddasUInt;
25 /*   */ typedef unsigned int MyddasPointer;
26 /*   */ typedef int MyddasInt32;
27 /*   */ typedef unsigned int MyddasUInt32;
28 #  elif SIZEOF_LONG_INT==4
29 /*   */ typedef long int MyddasInt;
30 /*   */ typedef unsigned long int MyddasUInt;
31 /*   */ typedef unsigned long int MyddasPointer;
32 /*   */ typedef long int MyddasInt32;
33 /*   */ typedef unsigned long int MyddasUInt32;
34 #  else
35 #	error MYDDAS require integer types of the same size as a pointer
36 #  endif
37 
38 #  if SIZEOF_SHORT_INT==2
39 /*   */ typedef short int MyddasSInt;
40 /*   */ typedef unsigned short int MyddasUSInt;
41 #  else
42 #	error MYDDAS requires integer types half the size of a pointer
43 #  endif
44 
45 #  if SIZEOF_LONG_INT==8
46 /*   */ typedef long int MyddasLInt;
47 /*   */ typedef unsigned long int MyddasULInt;
48 #  elif SIZEOF_LONG_LONG_INT==8
49 /*   */ typedef long long int MyddasLInt;
50 /*   */ typedef unsigned long long int MyddasULInt;
51 #  else
52 #	error MYDDAS requires integer types double the size of a pointer
53 #  endif
54 
55 #elif SIZEOF_INT_P==8
56 
57 #  if SIZEOF_INT==8
58 /*   */ typedef int MyddasInt;
59 /*   */ typedef unsigned int MyddasUInt;
60 /*   */ typedef int MyddasLInt;
61 /*   */ typedef unsigned int MyddasULInt;
62 /*   */ typedef unsigned int MyddasPointer;
63 #  elif SIZEOF_LONG_INT==8
64 /*   */ typedef long int MyddasInt;
65 /*   */ typedef unsigned long int MyddasUInt;
66 /*   */ typedef int MyddasLInt;
67 /*   */ typedef unsigned int MyddasULInt;
68 /*   */ typedef unsigned long int MyddasPointer;
69 #  elif SIZEOF_LONG_LONG_INT==8
70 /*   */ typedef long long int MyddasInt;
71 /*   */ typedef unsigned long long int MyddasUInt;
72 /*   */ typedef int MyddasLInt;
73 /*   */ typedef unsigned int MyddasULInt;
74 /*   */ typedef unsigned long long int MyddasPointer;
75 #  else
76 #	error MYDDAS requires integer types of the same size as a pointer
77 #  endif
78 
79 #   if SIZEOF_SHORT_INT==4
80 /*   */ typedef short int MyddasSInt;
81 /*   */ typedef unsigned short int MyddasUSInt;
82 /*   */ typedef short int MyddasInt32;
83 /*   */ typedef unsigned short int MyddasUInt32;
84 #   elif SIZEOF_INT==4
85 /*   */ typedef int MyddasSInt;
86 /*   */ typedef unsigned int MyddasUSInt;
87 /*   */ typedef int MyddasInt32;
88 /*   */ typedef unsigned int MyddasUInt32;
89 #   else
90 #	error MYDDAS requires integer types half the size of a pointer
91 #   endif
92 
93 #else
94 #   error MYDDAS requires pointers of size 4 or 8
95 #endif
96 
97 
98 
99 
100 /* Passar para o myddas_statictics.h ???????? */
101 #ifdef MYDDAS_STATS
102 #include <time.h>
103 #include <sys/time.h>
104 #endif
105 
106 typedef struct myddas_global *MYDDAS_GLOBAL;
107 typedef struct myddas_util_query *MYDDAS_UTIL_QUERY;
108 typedef struct myddas_list_connection *MYDDAS_UTIL_CONNECTION;
109 typedef struct myddas_list_preds *MYDDAS_UTIL_PREDICATE;
110 
111 #ifdef MYDDAS_STATS
112 typedef struct myddas_stats_time_struct *MYDDAS_STATS_TIME;
113 typedef struct myddas_global_stats *MYDDAS_GLOBAL_STATS;
114 typedef struct myddas_stats_struct *MYDDAS_STATS_STRUCT;
115 #endif
116 
117 #ifdef DEBUG
118 #define MYDDAS_MALLOC(POINTER,TYPE)                                \
119  {                                                                 \
120    POINTER = (TYPE *) malloc(sizeof(TYPE));                        \
121    Yap_REGS.MYDDAS_GLOBAL_POINTER->memory_allocated+=sizeof(TYPE); \
122    /*printf ("MALLOC %p %s %d\n",POINTER,__FILE__,__LINE__);*/ \
123    Yap_REGS.MYDDAS_GLOBAL_POINTER->malloc_called++;                \
124  }
125 #else
126 #define MYDDAS_MALLOC(POINTER,TYPE)                                \
127  {                                                                 \
128    POINTER = (TYPE *) malloc(sizeof(TYPE));                        \
129  }
130 #endif
131 
132 #ifdef DEBUG
133 #define MYDDAS_FREE(POINTER,TYPE)                                  \
134  {                                                                 \
135    Yap_REGS.MYDDAS_GLOBAL_POINTER->memory_freed+=sizeof(TYPE);     \
136    Yap_REGS.MYDDAS_GLOBAL_POINTER->free_called++;                  \
137    /*printf ("FREE   %p %s %d\n",POINTER,__FILE__,__LINE__);*/ \
138    free(POINTER);                                                  \
139  }
140 #else
141 #define MYDDAS_FREE(POINTER,TYPE)                                  \
142  {                                                                 \
143    free(POINTER);                                                  \
144  }
145 #endif
146 
147 #ifdef DEBUG
148 #define MYDDAS_MEMORY_MALLOC_NR(NUMBER)   \
149   NUMBER = Yap_REGS.MYDDAS_GLOBAL_POINTER->malloc_called;
150 #define MYDDAS_MEMORY_MALLOC_SIZE(NUMBER) \
151   NUMBER = Yap_REGS.MYDDAS_GLOBAL_POINTER->memory_allocated;
152 #define MYDDAS_MEMORY_FREE_NR(NUMBER)     \
153   NUMBER = Yap_REGS.MYDDAS_GLOBAL_POINTER->free_called;
154 #define MYDDAS_MEMORY_FREE_SIZE(NUMBER)   \
155   NUMBER = Yap_REGS.MYDDAS_GLOBAL_POINTER->memory_freed;
156 #endif
157 
158 
159 #endif /*__MYDDAS_H__*/
160