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:
@@ -73,5 +73,16 @@ typedef DWORD (*PDWORDFUNC) (void);
|
|||||||
#define LOWORD(x) ((UWORD) ((DWORD) (x)))
|
#define LOWORD(x) ((UWORD) ((DWORD) (x)))
|
||||||
#define HIWORD(x) ((UWORD) ((DWORD) (x) >> 16))
|
#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 */
|
#endif /* _COMPILER_H */
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,13 @@ typedef UWORD MEM_FLAGS;
|
|||||||
#define HIGHEST_MEM_PRIORITY (MEM_PRIORITY)1
|
#define HIGHEST_MEM_PRIORITY (MEM_PRIORITY)1
|
||||||
#define LOWEST_MEM_PRIORITY (MEM_PRIORITY)100
|
#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...
|
//Newer verion from w_memlib.c to follow...
|
||||||
/*
|
/*
|
||||||
extern MEM_BOOL mem_init (MEM_SIZE core_size, PMEM_SIZE pmin_addressable,
|
extern MEM_BOOL mem_init (MEM_SIZE core_size, PMEM_SIZE pmin_addressable,
|
||||||
|
|||||||
@@ -596,12 +596,12 @@ _alloc_mem (int size)
|
|||||||
void *p;
|
void *p;
|
||||||
int h;
|
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);
|
p = (void *)mem_simple_access (h);
|
||||||
if (p)
|
if (p)
|
||||||
{
|
{
|
||||||
*(int *)p = h;
|
((MEM_HEADER *) p)->handle = h;
|
||||||
p = (int *)p + 1;
|
p = (char *)p + sizeof (MEM_HEADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (p);
|
return (p);
|
||||||
@@ -630,9 +630,11 @@ HFree (void *p)
|
|||||||
{
|
{
|
||||||
if (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_simple_unaccess (h);
|
||||||
mem_release (h);
|
mem_release (h);
|
||||||
}
|
}
|
||||||
@@ -658,7 +660,12 @@ HRealloc (void *p, int size)
|
|||||||
|
|
||||||
if ((np = _alloc_mem (size)) && p)
|
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)
|
if (size > osize)
|
||||||
size = osize;
|
size = osize;
|
||||||
memcpy (np, p, size);
|
memcpy (np, p, size);
|
||||||
@@ -667,3 +674,4 @@ HRealloc (void *p, int size)
|
|||||||
|
|
||||||
return (np);
|
return (np);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user