From d910f4b0e821681f670601e7de4dadfd00679f69 Mon Sep 17 00:00:00 2001 From: neil Date: Thu, 19 Mar 2015 00:32:54 +0000 Subject: [PATCH] - Made memSize argument an IPTR (like other memory functions). - No longer skips reallocation with AllocAbs() if the AllocMem()-returned address is aligned: the size will be wrong for later deallocation. - Improved AutoDoc. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@50211 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- compiler/alib/liballocaligned.c | 31 ++++++++++++++----------------- compiler/include/clib/alib_protos.h | 4 ++-- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/compiler/alib/liballocaligned.c b/compiler/alib/liballocaligned.c index 0ddc617452..cc1a7d907b 100644 --- a/compiler/alib/liballocaligned.c +++ b/compiler/alib/liballocaligned.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012, The AROS Development Team + * Copyright (C) 2012-2015, The AROS Development Team * All right reserved. * Author: Jason S. McMullan * @@ -16,11 +16,14 @@ APTR LibAllocAligned ( /* SYNOPSIS */ - ULONG memSize, + IPTR memSize, ULONG requirements, IPTR alignBytes) /* FUNCTION + Allocate a memory block with a start address and size that are + multiples of a power-of-two. The returned memory must be freed using + FreeMem(). INPUTS memSize - Size in bytes of the aligned area @@ -29,14 +32,10 @@ This must be a power of 2! RESULT - - Pointer to the newly alloctated area, or - NULL if no saisfying memory can be found. - - Free this pointer using FreeMem(..., memSize) + Pointer to the newly allocated area, or NULL if no satisfying memory + can be found. NOTES - If alignBytes is not a power of two, NULL is returned. If memSize is not a multiple of alignBytes, NULL is returned. @@ -46,11 +45,10 @@ BUGS SEE ALSO + exec.library/AllocMem, exec.library/FreeMem(). INTERNALS - HISTORY - ******************************************************************************/ { APTR ptr; @@ -66,14 +64,13 @@ alignMask = alignBytes - 1; - if ((ptr = AllocMem(memSize + alignMask, requirements))) { + if ((ptr = AllocMem(memSize + alignMask, requirements))) + { APTR aptr = (APTR)((((IPTR)ptr) + alignMask) & ~alignMask); - if (aptr != ptr) { - Forbid(); - FreeMem(ptr, memSize + alignMask); - ptr = AllocAbs(memSize, aptr); - Permit(); - } + Forbid(); + FreeMem(ptr, memSize + alignMask); + ptr = AllocAbs(memSize, aptr); + Permit(); } return ptr; diff --git a/compiler/include/clib/alib_protos.h b/compiler/include/clib/alib_protos.h index 38cf05ffff..7b340131c3 100644 --- a/compiler/include/clib/alib_protos.h +++ b/compiler/include/clib/alib_protos.h @@ -2,7 +2,7 @@ #define CLIB_ALIB_PROTOS_H /* - Copyright © 1995-2011, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Prototypes for amiga.lib @@ -121,7 +121,7 @@ APTR LibAllocPooled (APTR poolHeader, ULONG memSize); void LibFreePooled (APTR poolHeader, APTR memory, ULONG memSize); /* Aligned */ -APTR LibAllocAligned (ULONG memSize, ULONG requirements, IPTR alignBytes); +APTR LibAllocAligned (IPTR memSize, ULONG requirements, IPTR alignBytes); /* Hook Support */ AROS_UFP3(IPTR, HookEntry, -- 2.11.4.GIT