File: plugin.c

package info (click to toggle)
nsis 3.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,496 kB
  • sloc: cpp: 39,326; ansic: 27,284; python: 1,386; asm: 712; xml: 409; pascal: 231; makefile: 225; javascript: 67
file content (100 lines) | stat: -rwxr-xr-x 2,642 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Unicode support by Jim Park -- 08/22/2007

#include <windows.h>
#include "MyMath.h"
#include "Math.h"

#ifdef _DEBUG_LEAKS

#include <crtdbg.h>

int blocksnum = 0;
HGLOBAL blocks[100000];

HGLOBAL watchGlobalAlloc(UINT Flags, UINT size)
{
    HGLOBAL block = GlobalAlloc(Flags, size);
    blocks[blocksnum++] = block;
    return block;
}

void watchGlobalFree(HGLOBAL block)
{
    for (int i = 0; i < blocksnum; i++)
        if (blocks[i] == block) blocks[i] = NULL;
    GlobalFree(block);
}

void watchGlobal()
{
    for (int i = 0; i < blocksnum; i++)
        if (blocks[i] != NULL)
        {
            _RPT2(_CRT_WARN, _T("Memory leak %d at %8X\n"), i, blocks[i]);
        }
}

#endif

TCHAR *AllocString()
{
    return (TCHAR*) dbgGlobalAlloc(GPTR,g_stringsize*sizeof(TCHAR));
}

ExpressionItem *AllocItem()
{
    ExpressionItem *item = (ExpressionItem*)dbgGlobalAlloc(GPTR,sizeof(ExpressionItem));
    item->next = NULL;
    item->type = IT_CONST | ITC_INT;
    item->param1 = item->param2 = 0;
    return item;
}

ExpressionItem *AllocArray(int s)
{
    int size = DEFAULT_ARRAY_SIZE;
    while (s > size) size*=2;

    ExpressionItem *ai = (ExpressionItem*)dbgGlobalAlloc(GPTR,sizeof(ExpressionItem));
    ai->type = IT_CONST | ITC_ARRAY;
    ai->param1 = (EIPARAM) dbgGlobalAlloc(GPTR, sizeof(ArrayDesc));

    ArrayDesc *ad = *((ArrayDesc**)&(ai->param1));
    // initialize and clear the array memory
    ad->array = (ExpressionItem**) dbgGlobalAlloc(GPTR, size*sizeof(ExpressionItem*));
    ad->size = size;
    ad->count = 0;
    ad->references = 1;
    return ai;
}

ExpressionItem *CopyItem(ExpressionItem *citem, int NeedConst)
{
    if (!citem) return NULL;
    ExpressionItem *item = NULL;
    if ((NeedConst) && ((citem->type & ITEMTYPE) != IT_CONST))
    {
        // in case of non constant expression - flat it to const
        RunTree(citem, item, RTO_NEEDCONST | ITC_INT | ITC_STRING | ITC_FLOAT | ITC_ARRAY);
        if (item) return item;
    }

    item = AllocItem();
    item->type = citem->type;
    if ((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_CONST | ITC_STRING))
    {
        item->param1 = (EIPARAM) AllocString();
        lstrcpy((LPTSTR) item->param1, (LPTSTR) citem->param1);
    } else if (((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_CONST | ITC_ARRAY))
        ||
        ((item->type & (ITEMTYPE | ITEMSUBTYPE)) == (IT_VARIABLE | ITV_ARRITEM)))
    {
        item->param1 = citem->param1;
        ArrayDesc *ad = (ArrayDesc*) item->param1;
        ad->references++;
    }
    else item->param1 = citem->param1;
    item->param2 = citem->param2;
    item->next = NULL;
    return item;
}