void * Mem_calloc(long count, long nbytes, const char *file, int line) {
    assert(count > 0);
    assert(nbytes > 0);

    void *ptr = Mem_alloc(count * nbytes, file, line);
    memset(ptr, '\0', count * nbytes);
    return ptr;
}
示例#2
0
void _clone_attr_array( oe_scalar *src, oe_scalar**clone_p ) {

    int sz;
    for (sz = 0; src[sz]; sz++) {
    }
    oe_scalar *clone;
    clone = Mem_alloc((sz + 1) * sizeof (char *), __FILE__, __LINE__);

    int i;
    for (i = 0; i < sz; i++) {
        oe_scalar str;
        str = Mem_alloc((strlen((char *) src[i]) + 1), __FILE__, __LINE__);
        strcpy((char *) str, (char *) src[i]);
        clone[i] = str;
    }
    clone[i] = NULL;

    *clone_p = clone;
}
void *Mem_resize(void *ptr,long nbytes,const char *file,int line)
{
	struct descriptor *bp;
	void *newptr;
	assert(ptr);
	assert(nbytes>0);
	if(((unsigned long)ptr)%(sizeof(union align))!=0||(bp=find(ptr))==NULL||bp->free)
		Except_raise(&Assert_Failed,file,line);

	newptr=Mem_alloc(nbytes,file,line);
	memcpy(newptr,ptr,nbytes<bp->size? nbytes:bp->size);
	Mem_free(ptr,file,line);
	return newptr;
}
void * Mem_resize(void *ptr, long nbytes, const char *file, int line) {
    assert(ptr);
    assert(nbytes > 0);

    struct descriptor *bp = find(ptr);
    if (((unsigned long long)ptr) % (sizeof(union align)) != 0 || bp == NULL || bp->free) {
        if (log_file) {
            fprintf(log_file, "** resizing unallocated memory\n"
                "Mem_resize(0x%p, %ld) called from %s:%d\n", \
                ptr, nbytes, file, line);
        }
        else
            Except_raise(&Assert_Failed, file, line);
    }
    void *newptr = Mem_alloc(nbytes, file, line);
    memcpy(newptr, ptr, nbytes < bp->size ? nbytes : bp->size);
    Mem_free(ptr, file, line);
    return newptr;
}
示例#5
0
//suite
int main(void) {

#ifndef OE_USE_THREADS
    printf("can not test threads with no thread support compiled in\n");
    return 0;
#endif
    //arena = Arena_new();
    //dispatcher = Oe_Thread_Dispatcher_new(2);
    dispatcher = Oe_Thread_Dispatcher_new(1);
    assert(dispatcher);
    Oe_Thread_Dispatcher_start(dispatcher);
    sleep(1);

    store = OeBdb_new(1, "data", true);
    assert(store);

    char *tname;
    int sz = 10;
    for (int j = 0; j < sz; j++) {
        tname = Mem_alloc(100, __FILE__, __LINE__);
        sprintf(tname, "id:%d", j);
        Oe_Thread_Dispatcher_exec(dispatcher, testPutOne, tname);
    }
    for (int j = 0; j < sz; j++) {
        //Oe_Thread_Dispatcher_exec(dispatcher, testTakeOne, 0); //ejs test tmp
    }
    printf("waiting ........................................... \n");
    sleep(3);
    printf("........................................... done\n");
    Oe_Thread_Dispatcher_stop(dispatcher);
    ////////////////////////////////////////////////
    ////////////////////////////////////////////////
    ////////////////////////////////////////////////
    /// THE BUGS have to be related to query obj ///
    ////////////////////////////////////////////////
    ////////////////////////////////////////////////
    ////////////////////////////////////////////////
    //int close_ret = OeStore_free(&store); //why does this not like to stop?
    //Oe_Thread_Dispatcher_free(&dispatcher);
    //Arena_dispose(&arena);
}
示例#6
0
void Oec_IdSet_put(T _this_, oe_id mid) {
    ID_ITEM *item;
    item = Mem_alloc(sizeof *item, __FILE__, __LINE__);
    item->mid = mid;
    Set_put(_this_->members, item);
}