~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to erts/emulator/beam/binary.c

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "erl_binary.h"
31
31
#include "erl_bits.h"
32
32
 
33
 
erts_atomic_t erts_allocated_binaries;
34
 
 
35
33
#ifdef DEBUG
36
34
static int list_to_bitstr_buf(Eterm obj, char* buf, int len);
37
35
#else
42
40
void
43
41
erts_init_binary(void)
44
42
{
45
 
    erts_atomic_init(&erts_allocated_binaries, 0);
46
 
 
47
43
    /* Verify Binary alignment... */
48
44
    if ((((Uint) &((Binary *) 0)->orig_bytes[0]) % ((Uint) 8)) != 0) {
49
45
        /* I assume that any compiler should be able to optimize this
104
100
    return make_binary(pb);
105
101
}
106
102
 
 
103
/* 
 
104
 * When heap binary is not desired...
 
105
 */
 
106
 
 
107
Eterm erts_new_mso_binary(Process *p, byte *buf, int len)
 
108
{
 
109
    ProcBin* pb;
 
110
    Binary* bptr;
 
111
 
 
112
    /*
 
113
     * Allocate the binary struct itself.
 
114
     */
 
115
    bptr = erts_bin_nrml_alloc(len);
 
116
    bptr->flags = 0;
 
117
    bptr->orig_size = len;
 
118
    erts_refc_init(&bptr->refc, 1);
 
119
    if (buf != NULL) {
 
120
        sys_memcpy(bptr->orig_bytes, buf, len);
 
121
    }
 
122
 
 
123
    /*
 
124
     * Now allocate the ProcBin on the heap.
 
125
     */
 
126
    pb = (ProcBin *) HAlloc(p, PROC_BIN_SIZE);
 
127
    pb->thing_word = HEADER_PROC_BIN;
 
128
    pb->size = len;
 
129
    pb->next = MSO(p).mso;
 
130
    MSO(p).mso = pb;
 
131
    pb->val = bptr;
 
132
    pb->bytes = (byte*) bptr->orig_bytes;
 
133
    pb->flags = 0;
 
134
 
 
135
    /*
 
136
     * Miscellanous updates. Return the tagged binary.
 
137
     */
 
138
    MSO(p).overhead += pb->size / BINARY_OVERHEAD_FACTOR / sizeof(Eterm);
 
139
    return make_binary(pb);
 
140
}
 
141
 
107
142
/*
108
143
 * Create a brand new binary from scratch on the heap.
109
144
 */