예제 #1
0
javacall_result bt_push_update_record(bt_sddbid_t sddbid,
        const bt_record_t *record)
{
    bt_push_t *push = g_registry;
    while (push != NULL) {
        bt_record_t *rec = &push->record;
        if (rec->id == sddbid) {
            rec->id = record->id;
            rec->classes = record->classes;
            if (rec->size != record->size) {
                void *data = pcsl_mem_realloc(rec->data, record->size);
                if (data == NULL) {
                    return JAVACALL_FAIL;
                }
                rec->data = data;
                rec->size = record->size;
            }
            memcpy(rec->data, record->data, record->size);
            push_save();
            return JAVACALL_OK;
        }
        push = push->next;
    }
    return JAVACALL_FAIL;
}
예제 #2
0
/*
 * Test pcsl_mem_realloc, and use it to free memory
 *
 * This test ensures that after a pcsl_mem_malloc call for 1000 bytes
 * and a pcsl_mem_realloc call for 1500 bytes that heap size available 
 * is reduced by 1500 bytes.
 * note: acutally, the heap pcsl_memory.c impl adds 4 guard bytes, so
 * we have to take that into account in our error checking...
 */
void testRealloc() {
    int spcBefore;
    int spcAfter;

    void * buffer;

    spcBefore = pcsl_mem_get_free_heap();

    buffer = pcsl_mem_malloc(1000);
    assertTrue("failed to allocate a 1000 byte buffer", 
	       (buffer != NULL));

    spcAfter = pcsl_mem_get_free_heap();

    if (spcAfter != -1) {
        assertTrue("pcsl_mem_malloc & heap_size_available mis-match",
		   (spcBefore - 1004 == spcAfter ||
		    spcBefore - 1000 == spcAfter));
    }

    spcBefore = spcAfter;

    buffer = pcsl_mem_realloc(buffer, 1500);

    spcAfter = pcsl_mem_get_free_heap();

    if (spcAfter != -1) {
        assertTrue("pcsl_mem_realloc & heap_size_available mis-match",
		   (spcBefore - 504 == spcAfter ||
		    spcBefore - 500 == spcAfter));
    }
    spcBefore = spcAfter;

    pcsl_mem_realloc(buffer, 0);

    spcAfter = pcsl_mem_get_free_heap();

    if (spcAfter != -1) {
        assertTrue("pcsl_mem_realloc (free) & heap_size_available mis-match",
		   (spcBefore + 1504 == spcAfter ||
		    spcBefore + 1500 == spcAfter));
    }
}