Debian Codegraph @

Contrib/Math/Source/plugin.c

raw
1 // Unicode support by Jim Park -- 08/22/2007
2
3 #include <windows.h>
4 #include "MyMath.h"
5 #include "Math.h"
6
7 #ifdef _DEBUG_LEAKS
8
9 #include <crtdbg.h>
10
11 int blocksnum = 0;
12 HGLOBAL blocks[100000];
13
14 HGLOBAL watchGlobalAlloc(UINT Flags, UINT size)
15 {
16 HGLOBAL block = GlobalAlloc(Flags, size);
17 blocks[blocksnum++] = block;
18 return block;
19 }
20
21 void watchGlobalFree(HGLOBAL block)
22 {
23 for (int i = 0; i < blocksnum; i++)
24 if (blocks[i] == block) blocks[i] = NULL;
25 GlobalFree(block);
26 }
27
28 void watchGlobal()
29 {
30 for (int i = 0; i < blocksnum; i++)
31 if (blocks[i] != NULL)
32 {
33 _RPT2(_CRT_WARN, _T("Memory leak %d at %8X\n"), i, blocks[i]);
34 }
35 }
36
37 #endif
38
39 TCHAR *AllocString()
40 {
41 return (TCHAR*) dbgGlobalAlloc(GPTR,g_stringsize*sizeof(TCHAR));
42 }
43
44 ExpressionItem *AllocItem()
45 {
46 ExpressionItem *item = (ExpressionItem*)dbgGlobalAlloc(GPTR,sizeof(ExpressionItem));
47 item->next = NULL;
48 item->type = IT_CONST | ITC_INT;
49 item->param1 = item->param2 = 0;
50 return item;
51 }
52
53 ExpressionItem *AllocArray(int s)
54 {
55 int size = DEFAULT_ARRAY_SIZE;
56 while (s > size) size*=2;
57
58 ExpressionItem *ai = (ExpressionItem*)dbgGlobalAlloc(GPTR,sizeof(ExpressionItem));
59 ai->type = IT_CONST | ITC_ARRAY;
60 ai->param1 = (EIPARAM) dbgGlobalAlloc(GPTR, sizeof(ArrayDesc));
61
62 ArrayDesc *ad = *((ArrayDesc**)&(ai->param1));
63 // initialize and clear the array memory
64 ad->array = (ExpressionItem**) dbgGlobalAlloc(GPTR, size*sizeof(ExpressionItem*));
65 ad->size = size;
66 ad->count = 0;
67 ad->references = 1;
68 return ai;
69 }
70
71 ExpressionItem *CopyItem(ExpressionItem *citem, int NeedConst)
72 {
73 if (!citem) return NULL;
74 ExpressionItem *item = NULL;
75 if ((NeedConst) && ((citem->type & ITEMTYPE) != IT_CONST))
76 {
77 // in case of non constant expression - flat it to const
78 RunTree(citem, item, RTO_NEEDCONST | ITC_INT | ITC_STRING | ITC_FLOAT | ITC_ARRAY);
79 if (item) return item;
80 }
81
82 item = AllocItem();
83 item->type = citem->type;
84 if ((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_CONST | ITC_STRING))
85 {
86 item->param1 = (EIPARAM) AllocString();
87 lstrcpy((LPTSTR) item->param1, (LPTSTR) citem->param1);
88 } else if (((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_CONST | ITC_ARRAY))
89 ||
90 ((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_VARIABLE | ITV_ARRITEM)))
91 {
92 item->param1 = citem->param1;
93 ArrayDesc *ad = (ArrayDesc*) item->param1;
94 ad->references++;
95 }
96 else item->param1 = citem->param1;
97 item->param2 = citem->param2;
98 item->next = NULL;
99 return item;
100 }