diff options
Diffstat (limited to 'erts/emulator/beam/erl_binary.h')
-rw-r--r-- | erts/emulator/beam/erl_binary.h | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/erts/emulator/beam/erl_binary.h b/erts/emulator/beam/erl_binary.h index dc5539faad..21d4e3fdfd 100644 --- a/erts/emulator/beam/erl_binary.h +++ b/erts/emulator/beam/erl_binary.h @@ -1,19 +1,19 @@ /* * %CopyrightBegin% - * - * Copyright Ericsson AB 2000-2009. All Rights Reserved. - * + * + * Copyright Ericsson AB 2000-2010. All Rights Reserved. + * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in * compliance with the License. You should have received a copy of the * Erlang Public License along with this software. If not, it can be * retrieved online at http://www.erlang.org/. - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. - * + * * %CopyrightEnd% */ @@ -150,7 +150,7 @@ do { \ void erts_init_binary(void); -byte* erts_get_aligned_binary_bytes(Eterm, byte**); +byte* erts_get_aligned_binary_bytes_extra(Eterm, byte**, unsigned extra); #if defined(__i386__) || !defined(__GNUC__) /* @@ -166,6 +166,7 @@ byte* erts_get_aligned_binary_bytes(Eterm, byte**); #define ERTS_CHK_BIN_ALIGNMENT(B) \ do { ASSERT(!(B) || (((Uint) &((Binary *)(B))->orig_bytes[0]) & ERTS_BIN_ALIGNMENT_MASK) == ((Uint) 0)) } while(0) +ERTS_GLB_INLINE byte* erts_get_aligned_binary_bytes(Eterm bin, byte** base_ptr); ERTS_GLB_INLINE void erts_free_aligned_binary_bytes(byte* buf); ERTS_GLB_INLINE Binary *erts_bin_drv_alloc_fnf(Uint size); ERTS_GLB_INLINE Binary *erts_bin_drv_alloc(Uint size); @@ -178,6 +179,14 @@ ERTS_GLB_INLINE Binary *erts_create_magic_binary(Uint size, #if ERTS_GLB_INLINE_INCL_FUNC_DEF +#include <stddef.h> /* offsetof */ + +ERTS_GLB_INLINE byte* +erts_get_aligned_binary_bytes(Eterm bin, byte** base_ptr) +{ + return erts_get_aligned_binary_bytes_extra(bin, base_ptr, 0); +} + ERTS_GLB_INLINE void erts_free_aligned_binary_bytes(byte* buf) { @@ -189,7 +198,7 @@ erts_free_aligned_binary_bytes(byte* buf) ERTS_GLB_INLINE Binary * erts_bin_drv_alloc_fnf(Uint size) { - Uint bsize = sizeof(Binary) - 1 + size; + Uint bsize = ERTS_SIZEOF_Binary(size); void *res; res = erts_alloc_fnf(ERTS_ALC_T_DRV_BINARY, bsize); ERTS_CHK_BIN_ALIGNMENT(res); @@ -199,7 +208,7 @@ erts_bin_drv_alloc_fnf(Uint size) ERTS_GLB_INLINE Binary * erts_bin_drv_alloc(Uint size) { - Uint bsize = sizeof(Binary) - 1 + size; + Uint bsize = ERTS_SIZEOF_Binary(size); void *res; res = erts_alloc(ERTS_ALC_T_DRV_BINARY, bsize); ERTS_CHK_BIN_ALIGNMENT(res); @@ -210,7 +219,7 @@ erts_bin_drv_alloc(Uint size) ERTS_GLB_INLINE Binary * erts_bin_nrml_alloc(Uint size) { - Uint bsize = sizeof(Binary) - 1 + size; + Uint bsize = ERTS_SIZEOF_Binary(size); void *res; res = erts_alloc(ERTS_ALC_T_BINARY, bsize); ERTS_CHK_BIN_ALIGNMENT(res); @@ -221,7 +230,7 @@ ERTS_GLB_INLINE Binary * erts_bin_realloc_fnf(Binary *bp, Uint size) { Binary *nbp; - Uint bsize = sizeof(Binary) - 1 + size; + Uint bsize = ERTS_SIZEOF_Binary(size); ASSERT((bp->flags & BIN_FLAG_MAGIC) == 0); if (bp->flags & BIN_FLAG_DRV) nbp = erts_realloc_fnf(ERTS_ALC_T_DRV_BINARY, (void *) bp, bsize); @@ -235,7 +244,7 @@ ERTS_GLB_INLINE Binary * erts_bin_realloc(Binary *bp, Uint size) { Binary *nbp; - Uint bsize = sizeof(Binary) - 1 + size; + Uint bsize = ERTS_SIZEOF_Binary(size); ASSERT((bp->flags & BIN_FLAG_MAGIC) == 0); if (bp->flags & BIN_FLAG_DRV) nbp = erts_realloc_fnf(ERTS_ALC_T_DRV_BINARY, (void *) bp, bsize); @@ -265,13 +274,13 @@ erts_bin_free(Binary *bp) ERTS_GLB_INLINE Binary * erts_create_magic_binary(Uint size, void (*destructor)(Binary *)) { - Uint bsize = sizeof(Binary) - 1 + sizeof(ErtsBinaryMagicPart) - 1 + size; + Uint bsize = ERTS_MAGIC_BIN_SIZE(size); Binary* bptr = erts_alloc_fnf(ERTS_ALC_T_BINARY, bsize); if (!bptr) erts_alloc_n_enomem(ERTS_ALC_T2N(ERTS_ALC_T_BINARY), bsize); ERTS_CHK_BIN_ALIGNMENT(bptr); bptr->flags = BIN_FLAG_MAGIC; - bptr->orig_size = sizeof(ErtsBinaryMagicPart) - 1 + size; + bptr->orig_size = ERTS_MAGIC_BIN_ORIG_SIZE(size); erts_refc_init(&bptr->refc, 0); ERTS_MAGIC_BIN_DESTRUCTOR(bptr) = destructor; return bptr; |