~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to erts/emulator/beam/erl_binary.h

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2010-03-09 17:34:57 UTC
  • mfrom: (10.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100309173457-4yd6hlcb2osfhx31
Tags: 1:13.b.4-dfsg-3
Manpages in section 1 are needed even if only arch-dependent packages are
built. So, re-enabled them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * %CopyrightBegin%
3
 
 * 
4
 
 * Copyright Ericsson AB 2000-2009. All Rights Reserved.
5
 
 * 
 
3
 *
 
4
 * Copyright Ericsson AB 2000-2010. All Rights Reserved.
 
5
 *
6
6
 * The contents of this file are subject to the Erlang Public License,
7
7
 * Version 1.1, (the "License"); you may not use this file except in
8
8
 * compliance with the License. You should have received a copy of the
9
9
 * Erlang Public License along with this software. If not, it can be
10
10
 * retrieved online at http://www.erlang.org/.
11
 
 * 
 
11
 *
12
12
 * Software distributed under the License is distributed on an "AS IS"
13
13
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
 * the License for the specific language governing rights and limitations
15
15
 * under the License.
16
 
 * 
 
16
 *
17
17
 * %CopyrightEnd%
18
18
 */
19
19
 
150
150
 
151
151
void erts_init_binary(void);
152
152
 
153
 
byte* erts_get_aligned_binary_bytes(Eterm, byte**);
 
153
byte* erts_get_aligned_binary_bytes_extra(Eterm, byte**, unsigned extra);
154
154
 
155
155
#if defined(__i386__) || !defined(__GNUC__)
156
156
/*
166
166
#define ERTS_CHK_BIN_ALIGNMENT(B) \
167
167
  do { ASSERT(!(B) || (((Uint) &((Binary *)(B))->orig_bytes[0]) & ERTS_BIN_ALIGNMENT_MASK) == ((Uint) 0)) } while(0)
168
168
 
 
169
ERTS_GLB_INLINE byte* erts_get_aligned_binary_bytes(Eterm bin, byte** base_ptr);
169
170
ERTS_GLB_INLINE void erts_free_aligned_binary_bytes(byte* buf);
170
171
ERTS_GLB_INLINE Binary *erts_bin_drv_alloc_fnf(Uint size);
171
172
ERTS_GLB_INLINE Binary *erts_bin_drv_alloc(Uint size);
178
179
 
179
180
#if ERTS_GLB_INLINE_INCL_FUNC_DEF
180
181
 
 
182
#include <stddef.h> /* offsetof */
 
183
 
 
184
ERTS_GLB_INLINE byte*
 
185
erts_get_aligned_binary_bytes(Eterm bin, byte** base_ptr)
 
186
{
 
187
    return erts_get_aligned_binary_bytes_extra(bin, base_ptr, 0);
 
188
}
 
189
 
181
190
ERTS_GLB_INLINE void
182
191
erts_free_aligned_binary_bytes(byte* buf)
183
192
{
186
195
    }
187
196
}
188
197
 
 
198
/* Explicit extra bytes allocated to counter buggy drivers.
 
199
** These extra bytes where earlier (< R13B04) added by an alignment-bug
 
200
** in this code. Do we dare remove this in some major release (R14?) maybe?
 
201
*/
 
202
#ifdef DEBUG
 
203
#  define CHICKEN_PAD 0
 
204
#else
 
205
#  define CHICKEN_PAD (sizeof(void*) - 1)
 
206
#endif
 
207
 
189
208
ERTS_GLB_INLINE Binary *
190
209
erts_bin_drv_alloc_fnf(Uint size)
191
210
{
192
 
    Uint bsize = sizeof(Binary) - 1 + size;
 
211
    Uint bsize = ERTS_SIZEOF_Binary(size) + CHICKEN_PAD;
193
212
    void *res;
194
213
    res = erts_alloc_fnf(ERTS_ALC_T_DRV_BINARY, bsize);
195
214
    ERTS_CHK_BIN_ALIGNMENT(res);
199
218
ERTS_GLB_INLINE Binary *
200
219
erts_bin_drv_alloc(Uint size)
201
220
{
202
 
    Uint bsize = sizeof(Binary) - 1 + size;
 
221
    Uint bsize = ERTS_SIZEOF_Binary(size) + CHICKEN_PAD;
203
222
    void *res;
204
223
    res = erts_alloc(ERTS_ALC_T_DRV_BINARY, bsize);
205
224
    ERTS_CHK_BIN_ALIGNMENT(res);
210
229
ERTS_GLB_INLINE Binary *
211
230
erts_bin_nrml_alloc(Uint size)
212
231
{
213
 
    Uint bsize = sizeof(Binary) - 1 + size;
 
232
    Uint bsize = ERTS_SIZEOF_Binary(size) + CHICKEN_PAD;
214
233
    void *res;
215
234
    res = erts_alloc(ERTS_ALC_T_BINARY, bsize);
216
235
    ERTS_CHK_BIN_ALIGNMENT(res);
221
240
erts_bin_realloc_fnf(Binary *bp, Uint size)
222
241
{
223
242
    Binary *nbp;
224
 
    Uint bsize = sizeof(Binary) - 1 + size;
 
243
    Uint bsize = ERTS_SIZEOF_Binary(size) + CHICKEN_PAD;
225
244
    ASSERT((bp->flags & BIN_FLAG_MAGIC) == 0);
226
245
    if (bp->flags & BIN_FLAG_DRV)
227
246
        nbp = erts_realloc_fnf(ERTS_ALC_T_DRV_BINARY, (void *) bp, bsize);
235
254
erts_bin_realloc(Binary *bp, Uint size)
236
255
{
237
256
    Binary *nbp;
238
 
    Uint bsize = sizeof(Binary) - 1 + size;
 
257
    Uint bsize = ERTS_SIZEOF_Binary(size) + CHICKEN_PAD;
239
258
    ASSERT((bp->flags & BIN_FLAG_MAGIC) == 0);
240
259
    if (bp->flags & BIN_FLAG_DRV)
241
260
        nbp = erts_realloc_fnf(ERTS_ALC_T_DRV_BINARY, (void *) bp, bsize);
265
284
ERTS_GLB_INLINE Binary *
266
285
erts_create_magic_binary(Uint size, void (*destructor)(Binary *))
267
286
{
268
 
    Uint bsize = sizeof(Binary) - 1 + sizeof(ErtsBinaryMagicPart) - 1 + size;
 
287
    Uint bsize = ERTS_MAGIC_BIN_SIZE(size);
269
288
    Binary* bptr = erts_alloc_fnf(ERTS_ALC_T_BINARY, bsize);
270
289
    if (!bptr)
271
290
        erts_alloc_n_enomem(ERTS_ALC_T2N(ERTS_ALC_T_BINARY), bsize);
272
291
    ERTS_CHK_BIN_ALIGNMENT(bptr);
273
292
    bptr->flags = BIN_FLAG_MAGIC;
274
 
    bptr->orig_size = sizeof(ErtsBinaryMagicPart) - 1 + size;
 
293
    bptr->orig_size = ERTS_MAGIC_BIN_ORIG_SIZE(size);
275
294
    erts_refc_init(&bptr->refc, 0);
276
295
    ERTS_MAGIC_BIN_DESTRUCTOR(bptr) = destructor;
277
296
    return bptr;