Subversion Repositories QNX 8.QNX8 IFS tool

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
26 pmbaty 1
/* ACC -- Automatic Compiler Configuration
2
 
3
   Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
4
   All Rights Reserved.
5
 
6
   This software is a copyrighted work licensed under the terms of
7
   the GNU General Public License. Please consult the file "ACC_LICENSE"
8
   for details.
9
 
10
   Markus F.X.J. Oberhumer
11
   <markus@oberhumer.com>
12
   http://www.oberhumer.com/
13
 */
14
 
15
 
16
#define __ACCLIB_HALLOC_CH_INCLUDED 1
17
#if !defined(ACCLIB_PUBLIC)
18
#  define ACCLIB_PUBLIC(r,f)    r __ACCLIB_FUNCNAME(f)
19
#endif
20
 
21
 
22
#if (ACC_HAVE_MM_HUGE_PTR)
23
#if 1 && (ACC_OS_DOS16 && defined(BLX286))
24
#  define __ACCLIB_HALLOC_USE_DAH 1
25
#elif 1 && (ACC_OS_DOS16 && defined(DOSX286))
26
#  define __ACCLIB_HALLOC_USE_DAH 1
27
#elif 1 && (ACC_OS_OS216)
28
#  define __ACCLIB_HALLOC_USE_DAH 1
29
#elif 1 && (ACC_OS_WIN16)
30
#  define __ACCLIB_HALLOC_USE_GA 1
31
#elif 1 && (ACC_OS_DOS16) && (ACC_CC_BORLANDC) && defined(__DPMI16__)
32
#  define __ACCLIB_HALLOC_USE_GA 1
33
#endif
34
#endif
35
 
36
 
37
#if (__ACCLIB_HALLOC_USE_DAH)
38
#if 0 && (ACC_OS_OS216)
39
#include <os2.h>
40
#else
41
ACC_EXTERN_C unsigned short __far __pascal DosAllocHuge(unsigned short, unsigned short, unsigned short __far *, unsigned short, unsigned short);
42
ACC_EXTERN_C unsigned short __far __pascal DosFreeSeg(unsigned short);
43
#endif
44
#endif
45
 
46
#if (__ACCLIB_HALLOC_USE_GA)
47
#if 0
48
#define STRICT 1
49
#include <windows.h>
50
#else
51
ACC_EXTERN_C const void __near* __far __pascal GlobalAlloc(unsigned, unsigned long);
52
ACC_EXTERN_C const void __near* __far __pascal GlobalFree(const void __near*);
53
ACC_EXTERN_C unsigned long __far __pascal GlobalHandle(unsigned);
54
ACC_EXTERN_C void __far* __far __pascal GlobalLock(const void __near*);
55
ACC_EXTERN_C int __far __pascal GlobalUnlock(const void __near*);
56
#endif
57
#endif
58
 
59
 
60
/***********************************************************************
61
// halloc
62
************************************************************************/
63
 
64
ACCLIB_PUBLIC(acc_hvoid_p, acc_halloc) (acc_hsize_t size)
65
{
66
    acc_hvoid_p p = 0;
67
 
68
    if (size <= 0)
69
        return p;
70
 
71
#if 0 && defined(__palmos__)
72
    p = MemPtrNew(size);
73
#elif !defined(ACC_HAVE_MM_HUGE_PTR)
74
    if (size < (size_t) -1)
75
        p = malloc((size_t) size);
76
#else
77
    if ((long)size <= 0)
78
        return p;
79
{
80
#if (__ACCLIB_HALLOC_USE_DAH)
81
    unsigned short sel = 0;
82
    if (DosAllocHuge((unsigned short)(size >> 16), (unsigned short)size, &sel, 0, 0) == 0)
83
        p = (acc_hvoid_p) ACC_MK_FP(sel, 0);
84
#elif (__ACCLIB_HALLOC_USE_GA)
85
    const void __near* h = GlobalAlloc(2, size);
86
    if (h) {
87
        p = GlobalLock(h);
88
        if (p && ACC_FP_OFF(p) != 0) {
89
            GlobalUnlock(h);
90
            p = 0;
91
        }
92
        if (!p)
93
            GlobalFree(h);
94
    }
95
#elif (ACC_CC_MSC && (_MSC_VER >= 700))
96
    p = _halloc(size, 1);
97
#elif (ACC_CC_MSC || ACC_CC_WATCOMC)
98
    p = halloc(size, 1);
99
#elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
100
    p = farmalloc(size);
101
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
102
    p = farmalloc(size);
103
#elif defined(ACC_CC_AZTECC)
104
    p = lmalloc(size);
105
#else
106
    if (size < (size_t) -1)
107
        p = malloc((size_t) size);
108
#endif
109
}
110
#endif
111
 
112
    return p;
113
}
114
 
115
 
116
ACCLIB_PUBLIC(void, acc_hfree) (acc_hvoid_p p)
117
{
118
    if (!p)
119
        return;
120
 
121
#if 0 && defined(__palmos__)
122
    MemPtrFree(p);
123
#elif !defined(ACC_HAVE_MM_HUGE_PTR)
124
    free(p);
125
#else
126
#if (__ACCLIB_HALLOC_USE_DAH)
127
    if (ACC_FP_OFF(p) == 0)
128
        DosFreeSeg((unsigned short) ACC_FP_SEG(p));
129
#elif (__ACCLIB_HALLOC_USE_GA)
130
    if (ACC_FP_OFF(p) == 0) {
131
        const void __near* h = (const void __near*) (unsigned) GlobalHandle(ACC_FP_SEG(p));
132
        if (h) {
133
            GlobalUnlock(h);
134
            GlobalFree(h);
135
        }
136
    }
137
#elif (ACC_CC_MSC && (_MSC_VER >= 700))
138
    _hfree(p);
139
#elif (ACC_CC_MSC || ACC_CC_WATCOMC)
140
    hfree(p);
141
#elif (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
142
    farfree((void __far*) p);
143
#elif (ACC_CC_BORLANDC || ACC_CC_TURBOC)
144
    farfree((void __far*) p);
145
#elif defined(ACC_CC_AZTECC)
146
    lfree(p);
147
#else
148
    free(p);
149
#endif
150
#endif
151
}
152
 
153
 
154
 
155
/*
156
vi:ts=4:et
157
*/