The R Project SVN R

Rev

Rev 4394 | Rev 5429 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4394 Rev 4606
Line 1... Line 1...
1
/*
1
/*
2
 *
2
 *
3
 *  R : A Computer Language for Statistical Data Analysis
3
 *  R : A Computer Language for Statistical Data Analysis
4
 *  file console.c
4
 *  file winalloc.c
5
 *  Copyright (C) 1999  Guido Masarotto
5
 *  Copyright (C) 1999  Guido Masarotto
6
 *
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  the Free Software Foundation; either version 2 of the License, or
Line 18... Line 18...
18
 *  along with this program; if not, write to the Free Software
18
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
 */
20
 */
21
/*
21
/*
22
   Win32 Api version of malloc and friends
22
   Win32 Api version of malloc and friends
23
   
23
 
24
   This file is an add-on  to GraphApp, a cross-platform C graphics library.
24
   This file is an add-on  to GraphApp, a cross-platform C graphics library.
25
 */
25
 */
26
 
26
 
27
#include <winbase.h>
27
#include <winbase.h>
28
#include "ga.h"
28
#include "ga.h"
29
 
29
 
30
void *winmalloc(long size) {
30
void *winmalloc(size_t size)
-
 
31
{
31
   void *u = NULL;
32
    void *u = NULL;
32
   HGLOBAL h = GlobalAlloc(GMEM_MOVEABLE|GMEM_DISCARDABLE,(DWORD)size);
33
    HGLOBAL h = GlobalAlloc(GMEM_MOVEABLE | GMEM_DISCARDABLE, (DWORD)size);
33
   if (h) u = (void *)GlobalLock(h);
34
    if (h) u = (void *)GlobalLock(h);
34
   return u;
35
    return u;
35
}
36
}
36
 
37
 
37
void winfree(void *u) {
38
void winfree(void *u)
-
 
39
{
38
   HGLOBAL h;
40
    HGLOBAL h;
39
   if (u && (h = GlobalHandle((LPCVOID) u))) {
41
    if (u && (h = GlobalHandle((LPCVOID) u))) {
40
       GlobalUnlock(h); 
42
	GlobalUnlock(h);
41
       GlobalFree(h);
43
	GlobalFree(h);
42
   }
44
    }
43
}
45
}
44
   
-
 
45
 
46
 
46
void *winrealloc(void *u,long newsize) {
47
void *winrealloc(void *u, size_t newsize)
-
 
48
{
47
   HGLOBAL hold,hnew;
49
    HGLOBAL hold, hnew;
48
   void *nu = NULL;
50
    void *nu = NULL;
49
   if (!u) return winmalloc(newsize);
51
    if (!u) return winmalloc(newsize);
50
   if (!(hold = GlobalHandle((LPCVOID) u))) return NULL;
52
    if (!(hold = GlobalHandle((LPCVOID) u))) return NULL;
51
   hnew = GlobalReAlloc(hold,(DWORD) newsize,GMEM_MOVEABLE);
53
    hnew = GlobalReAlloc(hold, (DWORD) newsize, GMEM_MOVEABLE);
52
   if (hnew) nu = (void *) GlobalLock(hnew);
54
    if (hnew) nu = (void *) GlobalLock(hnew);
53
   return nu;
55
    return nu;
-
 
56
}
-
 
57
 
-
 
58
char *winstrdup(char *s)
-
 
59
{
-
 
60
    char *new = winmalloc(strlen(s) + 1);
-
 
61
    if (new) strcpy(new, s);
-
 
62
    return new;
54
}
63
}
55
 
64
 
-
 
65
#ifdef DANGER
56
 
66
 
57
char *winstrdup(char *s) {
67
void *malloc(size_t size)
-
 
68
{
58
   char *new = winmalloc(strlen(s)+1);
69
    return winmalloc(size);
59
   if (new) strcpy(new,s);
-
 
60
   return new;
-
 
61
}
70
}
-
 
71
 
-
 
72
void free(void *u)
-
 
73
{
-
 
74
    winfree(u);
-
 
75
}
-
 
76
 
-
 
77
void *realloc(void *u, size_t newsize)
-
 
78
{
-
 
79
    return winrealloc(u, newsize);
-
 
80
}
-
 
81
 
-
 
82
void *calloc(size_t n, size_t m)
-
 
83
{
-
 
84
    size_t size = n * m;
-
 
85
    void   *u   = winmalloc(size);
-
 
86
    if (u) ZeroMemory( (PVOID) u, (DWORD) size);
-
 
87
    return u; 
-
 
88
}
-
 
89
#endif
-
 
90