Alignment fixes.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1612 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
meep-eep
2005-04-07 20:30:57 +00:00
parent 19373652b1
commit 88f29b3b46
3 changed files with 32 additions and 6 deletions
+11
View File
@@ -73,5 +73,16 @@ typedef DWORD (*PDWORDFUNC) (void);
#define LOWORD(x) ((UWORD) ((DWORD) (x)))
#define HIWORD(x) ((UWORD) ((DWORD) (x) >> 16))
// _ALIGNED_ANY specifies an alignment suitable for any type
// _ALIGNED_ON specifies a caller-supplied alignment (should be a power of 2)
#if defined(__GNUC__)
# define _ALIGNED_ANY __attribute__((aligned))
# define _ALIGNED_ON(bytes) __attribute__((aligned(bytes)))
#elif defined(_MSC_VER)
# define _ALIGNED_ANY
# define _ALIGNED_ON(bytes) __declspec(align(bytes))
#endif
#endif /* _COMPILER_H */
+7
View File
@@ -97,6 +97,13 @@ typedef UWORD MEM_FLAGS;
#define HIGHEST_MEM_PRIORITY (MEM_PRIORITY)1
#define LOWEST_MEM_PRIORITY (MEM_PRIORITY)100
typedef struct mem_header {
MEM_HANDLE handle;
} MEM_HEADER _ALIGNED_ANY;
#define GET_MEM_HEADER(addr) ((MEM_HEADER *) \
(((char *) addr) - sizeof (MEM_HEADER)))
//Newer verion from w_memlib.c to follow...
/*
extern MEM_BOOL mem_init (MEM_SIZE core_size, PMEM_SIZE pmin_addressable,
+14 -6
View File
@@ -596,12 +596,12 @@ _alloc_mem (int size)
void *p;
int h;
h = mem_allocate (size + sizeof (int),0,0,0);
h = mem_allocate (sizeof (MEM_HEADER) + size, 0, 0, 0);
p = (void *)mem_simple_access (h);
if (p)
{
*(int *)p = h;
p = (int *)p + 1;
((MEM_HEADER *) p)->handle = h;
p = (char *)p + sizeof (MEM_HEADER);
}
return (p);
@@ -630,9 +630,11 @@ HFree (void *p)
{
if (p)
{
int h;
MEM_HEADER *hdr;
MEM_HANDLE h;
h = *(int *)((int *)p - 1);
hdr = GET_MEM_HEADER(p);
h = hdr->handle;
mem_simple_unaccess (h);
mem_release (h);
}
@@ -658,7 +660,12 @@ HRealloc (void *p, int size)
if ((np = _alloc_mem (size)) && p)
{
osize = mem_get_size (*(int *)((int *)p - 1)) - sizeof (int);
MEM_HEADER *hdr;
MEM_HANDLE h;
hdr = GET_MEM_HEADER (p);
h = hdr->handle;
osize = mem_get_size (h) - sizeof (MEM_HEADER);
if (size > osize)
size = osize;
memcpy (np, p, size);
@@ -667,3 +674,4 @@ HRealloc (void *p, int size)
return (np);
}