Ejemplo n.º 1
0
char *int_new_string (int size)
#endif
{
    malloc_block_t *mbt;

#if 0
    if (!size) {
        the_null_string_blocks[0].ref++;
        ADD_NEW_STRING(0, sizeof(malloc_block_t));
        return the_null_string;
    }
#endif
    
    mbt = (malloc_block_t *)DXALLOC(size + sizeof(malloc_block_t) + 1, TAG_MALLOC_STRING, tag);
    if (size < USHRT_MAX) {
        mbt->size = size;
        ADD_NEW_STRING(size, sizeof(malloc_block_t));
    } else {
        mbt->size = USHRT_MAX;
        ADD_NEW_STRING(USHRT_MAX, sizeof(malloc_block_t));
    }
    mbt->ref = 1;
    ADD_STRING(mbt->size);
    CHECK_STRING_STATS;
    return (char *)(mbt + 1);
}
Ejemplo n.º 2
0
char *int_string_unlink P1(char *, str)
#endif
{
    malloc_block_t *mbt, *newmbt;

    mbt = ((malloc_block_t *)str) - 1;
    mbt->ref--;
    
    if (mbt->size == USHRT_MAX) {
	int l = strlen(str + USHRT_MAX) + USHRT_MAX; /* ouch */

	newmbt = (malloc_block_t *)DXALLOC(l + sizeof(malloc_block_t) + 1, TAG_MALLOC_STRING, desc);
	memcpy((char *)(newmbt + 1), (char *)(mbt + 1), l+1);
	newmbt->size = USHRT_MAX;
	ADD_NEW_STRING(USHRT_MAX, sizeof(malloc_block_t));
    } else {
	newmbt = (malloc_block_t *)DXALLOC(mbt->size + sizeof(malloc_block_t) + 1, TAG_MALLOC_STRING, desc);
	memcpy((char *)(newmbt + 1), (char *)(mbt + 1), mbt->size+1);
	newmbt->size = mbt->size;
	ADD_NEW_STRING(mbt->size, sizeof(malloc_block_t));
    }
    newmbt->ref = 1;
    CHECK_STRING_STATS;
    
    return (char *)(newmbt + 1);
}
Ejemplo n.º 3
0
INLINE_STATIC block_t *
alloc_new_string (const char * string, int h)
{
    block_t *b;
    int len = strlen(string);
    int size;

    if (len > max_string_length) {
        len = max_string_length;
    }
    size = sizeof(block_t) + len + 1;
    b = (block_t *) DXALLOC(size, TAG_SHARED_STRING, "alloc_new_string");
    strncpy(STRING(b), string, len);
    STRING(b)[len] = '\0';      /* strncpy doesn't put on \0 if 'from' too
                                 * long */
    SIZE(b) = (len > USHRT_MAX ? USHRT_MAX : len);
    REFS(b) = 1;
    NEXT(b) = base_table[h];
    base_table[h] = b;
    ADD_NEW_STRING(SIZE(b), sizeof(block_t));
    ADD_STRING(SIZE(b));
    return (b);
}