コード例 #1
0
ファイル: test-appendcb.c プロジェクト: unsecured/copri
// **TODO**: Add an test. This function shows only the usage of `append_cb`.
static char * test_single() {

	mpz_t a, b;
	mpz_array array1, array2, array_expect;
	mpz_pool pool;

	pool_init(&pool, 0);
	array_init(&array1, 3);
	array_init(&array2, 3);
	array_init(&array_expect, 3);

	// primes: 577, 727, 863
	mpz_init_set_str(a, "577", 10);
	array_add(&array_expect, a);
	mpz_set_str(a, "727", 10);
	array_add(&array_expect, a);
	mpz_set_str(a, "863", 10);
	array_add(&array_expect, a);

	// `a = 727 * 577 = 419479`
	// `b = 727 * 863 = 627401`
	mpz_set_str(a, "419479", 10);
	mpz_init_set_str(b, "627401", 10);

	append_cb(&pool, &array1, a, b);
	if (mpz_cmp_ui(a, 419479) != 0) {
		return "append_cb has changed the input value a!";
	}
	if (mpz_cmp_ui(b, 627401) != 0) {
		return "append_cb has changed the input value b!";
	}

	array_msort(&array1);
	if (!array_equal(&array_expect, &array1)) {
		return "array1 and array_expect differ!";
	}

	append_cb(&pool, &array2, b, a);
	if (mpz_cmp_ui(a, 419479) != 0) {
		return "append_cb has changed the input value a!";
	}
	if (mpz_cmp_ui(b, 627401) != 0) {
		return "append_cb has changed the input value b!";
	}

	array_msort(&array2);
	if (!array_equal(&array_expect, &array2)) {
		return "array2 and array_expect differ!";
	}

	mpz_clear(a);
	mpz_clear(b);
	array_clear(&array1);
	array_clear(&array2);
	array_clear(&array_expect);
	pool_clear(&pool);

	return 0;
}
コード例 #2
0
ファイル: http.c プロジェクト: noelbk/bklib
int
http_header_clear(http_header_t *http) {
    pool_t *pool = http->pool; /* save the pool! */
    pool_clear(http->pool);
    memset(http, 0, sizeof(*http));
    http->pool = pool;
    return 0;
}
コード例 #3
0
	Slot *pool_create ( unsigned int size )
	{
		Slot *pool = (Slot *) ::malloc(sizeof(Slot) + size);
		pool->size = size;

		pool_clear(pool);

		return pool;
	}
コード例 #4
0
ファイル: test-cbmerge.c プロジェクト: unsecured/copri
// **Test `test`**.
static char * test() {

	mpz_array in1, in2, out, array_expect;
	mpz_t b;
	mpz_pool pool;

	pool_init(&pool, 0);
	array_init(&in1, 2);
	array_init(&in2, 2);
	array_init(&out, 5);
	array_init(&array_expect, 5);

	mpz_init_set_str(b, "317", 10);
	array_add(&array_expect, b);
	mpz_set_str(b, "577", 10);
	array_add(&array_expect, b);
	mpz_set_str(b, "727", 10);
	array_add(&array_expect, b);
	mpz_set_str(b, "196463", 10);
	array_add(&array_expect, b);
	mpz_set_str(b, "346063", 10);
	array_add(&array_expect, b);

	// primes: 401, [577], 727, 863
	// `a = 727 * 577 = 419479`
	// `b = 401 * 863 = 346063`
	mpz_set_str(b, "419479", 10);
	array_add(&in1, b);

	mpz_set_str(b, "346063", 10);
	array_add(&in1, b);

	// primes: 317, 223, [577], 881
	// `a = 317 * 577 = 182909`
	// `b = 223 * 881 = 196463`
	mpz_set_str(b, "182909", 10);
	array_add(&in2, b);

	mpz_set_str(b, "196463", 10);
	array_add(&in2, b);

	cbmerge(&pool, &out, &in1, &in2);

	array_msort(&out);
	if (!array_equal(&array_expect, &out)) {
		return "out and array_expect differ!";
	}

	array_clear(&in1);
	array_clear(&in2);
	array_clear(&out);
	array_clear(&array_expect);
	mpz_clear(b);
	pool_clear(&pool);

	return 0;
}
コード例 #5
0
ファイル: pooltest.c プロジェクト: LinHu2016/omr
static int32_t
testPoolClear(OMRPortLibrary *portLib, J9Pool *currentPool)
{
	uintptr_t expectedCapacityAfterClear = pool_capacity(currentPool);

	pool_clear(currentPool);

	if (0 != pool_numElements(currentPool)) {
		return -1;
	} else if (expectedCapacityAfterClear != pool_capacity(currentPool)) {
		return -2;
	}
	return 0;
}
コード例 #6
0
ファイル: test-appendcb.c プロジェクト: unsecured/copri
// **TODO**: Add an test. This function shows only the usage of `append_cb`.
static char * test_multiple() {

	mpz_t a, b;
	mpz_array array1, array2, array_expect;
	mpz_pool pool;

	pool_init(&pool, 0);
	array_init(&array1, 3);
	array_init(&array2, 3);
	array_init(&array_expect, 3);

	// `30997 = 139 * 223`
	// `627401 = 727 * 863`
	// `182909 = 317 * 577`
	mpz_init_set_str(a, "30997", 10);
	array_add(&array_expect, a);
	mpz_set_str(a, "182909", 10);
	array_add(&array_expect, a);
	mpz_set_str(a, "627401", 10);
	array_add(&array_expect, a);

	// primes: 139, 223, 317, 577, 727, 863
	// `a = 139 * 223 * 317 * 577 = 5669630273`
	// `b = 317 * 577 * 727 * 863 = 114757289509`
	mpz_set_str(a, "5669630273", 10);
	mpz_init_set_str(b, "114757289509", 10);

	append_cb(&pool, &array1, a, b);
	array_msort(&array1);
	if (!array_equal(&array_expect, &array1)) {
		return "array1 and array_expect differ!";
	}

	append_cb(&pool, &array2, b, a);
	array_msort(&array2);
	if (!array_equal(&array_expect, &array2)) {
		return "array2 and array_expect differ!";
	}

	mpz_clear(a);
	mpz_clear(b);
	array_clear(&array1);
	array_clear(&array2);
	array_clear(&array_expect);
	pool_clear(&pool);

	return 0;
}
コード例 #7
0
	char *pop_item ( jack_nframes_t *time, size_t *size )
	{
		char *item = NULL;

		if (m_count > 0) {
			if (m_dirty > 0) {
				::qsort(m_items, m_count, sizeof(char *), sort_item);
				m_dirty = 0;
			}
			item = m_items[--m_count];
			if (time) *time = pool_slot_key(item);
			if (size) *size = pool_slot_size(item);
		}
		else pool_clear(m_pool);

		return item;
	}
コード例 #8
0
void pool_destroy(pool_t *pool)
{
    if (pool->parent) {
        pool_t *p = pool->parent->child;

        if (p == pool) {
            pool->parent->child = pool->prev_sibling;
        } else {
            while (p->prev_sibling != pool)
                p = p->prev_sibling;

            p->prev_sibling = pool->prev_sibling;
        }
    }

    pool_clear(pool);
    free(pool);
}
コード例 #9
0
ファイル: o.c プロジェクト: yhcting/ylib
static void
mexit(void) {
        pool_clear();
        ypool_destroy(_pool);
}
コード例 #10
0
ファイル: o.c プロジェクト: yhcting/ylib
/*
 * This function is used for testing and debugging.
 */
void
o_clear(void) {
	pool_clear();
}
コード例 #11
0
	// Queue cleanup.
	void clear ()
	{
		pool_clear(m_pool);
		m_count = 0;
		m_dirty = 0;
	}
コード例 #12
0
ファイル: agent.c プロジェクト: HankMa/netcwmp
int cwmp_agent_analyse_session(cwmp_session_t * session)
{
    pool_t * doctmppool  = NULL;
    char * xmlbuf;
    cwmp_uint32_t len;
    xmldoc_t *  doc;
    char * method;
    xmldoc_t *   newdoc = NULL;
    int rc;

    static char * xml_fault = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:cwmp=\"urn:dslforum-org:cwmp-1-0\" xmlns=\"urn:dslforum-org:cwmp-1-0\"><SOAP-ENV:Body SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"  id=\"_0\"><SOAP-ENV:Fault>Error Message</SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>";

    cwmp_uint32_t msglength = cwmp_chunk_length(session->readers);

    
    if (msglength<= 0)
    {
        session->newdata = CWMP_NO;
        cwmp_log_debug("analyse receive length is 0");
	goto eventcheck;
//        return CWMP_ERROR;
    }
    
    doctmppool = pool_create(POOL_DEFAULT_SIZE);

    xmlbuf = pool_palloc(doctmppool, msglength+32);

    len = sprintf(xmlbuf,"<cwmp>");
    cwmp_chunk_copy(xmlbuf + len, session->readers, msglength);
    strcpy(xmlbuf+len+msglength, "</cwmp>");

    cwmp_log_debug("agent analyse xml: \n%s", xmlbuf);

    doc = XmlParseBuffer(doctmppool, xmlbuf);
    if (!doc)
    {
        cwmp_log_debug("analyse create doc null\n");
        cwmp_chunk_write_string(session->writers, xml_fault, TRstrlen(xml_fault), session->envpool);
        goto finished;

    }

    method = cwmp_get_rpc_method_name(doc);
    cwmp_log_debug("analyse method is: %s\n", method);



 

    cwmp_chunk_clear(session->writers);
    pool_clear(session->envpool);


    if (TRstrcmp(method, CWMP_RPC_GETRPCMETHODS) == 0)
    {
        newdoc = cwmp_session_create_getrpcmethods_response_message(session, doc, doctmppool);
    }
    else if (TRstrcmp(method, CWMP_RPC_INFORMRESPONSE) == 0)
    {
        newdoc = NULL;
    }
    else if (TRstrcmp(method, CWMP_RPC_GETPARAMETERNAMES) == 0)
    {
        newdoc = cwmp_session_create_getparameternames_response_message(session, doc, doctmppool);
    }
    else if (TRstrcmp(method, CWMP_RPC_GETPARAMETERVALUES) == 0)
    {
        newdoc = cwmp_session_create_getparametervalues_response_message(session, doc, doctmppool);
    }
    else if (TRstrcmp(method, CWMP_RPC_SETPARAMETERVALUES) == 0)
    {
        newdoc = cwmp_session_create_setparametervalues_response_message(session, doc, doctmppool);
    }
    else if (TRstrcmp(method, CWMP_RPC_DOWNLOAD) == 0)
    {
        newdoc = cwmp_session_create_download_response_message(session, doc, doctmppool);
    }
    else if (TRstrcmp(method, CWMP_RPC_UPLOAD) == 0)
    {
        newdoc = cwmp_session_create_upload_response_message(session, doc, doctmppool);
    }
   else if (TRstrcmp(method, CWMP_RPC_TRANSFERCOMPLETERESPONSE) == 0)
    {
        newdoc = NULL;
    }
    else if (TRstrcmp(method, CWMP_RPC_REBOOT) == 0)
    {
        newdoc = cwmp_session_create_reboot_response_message(session, doc, doctmppool);
    }
    else if (TRstrcmp(method, CWMP_RPC_ADDOBJECT) == 0)
    {
        newdoc = cwmp_session_create_addobject_response_message(session, doc, doctmppool);
    }
    else if (TRstrcmp(method, CWMP_RPC_DELETEOBJECT) == 0)
    {
        newdoc = cwmp_session_create_deleteobject_response_message(session, doc, doctmppool);
    }
    
    else if (TRstrcmp(method, CWMP_RPC_FACTORYRESET) == 0)
    {
        newdoc = cwmp_session_create_factoryreset_response_message(session, doc, doctmppool);
    }
	
    else
    {
    	//check event queue
    	//newdoc = cwmp_session_create_event_response_message(session, doc, doctmppool);

    }


    cwmp_t * cwmp = session->cwmp;
    if(newdoc == NULL)
    {
        cwmp_log_debug("agent analyse newdoc is null. ");
		
eventcheck:
	{
	   	
		cwmp_log_debug("agent analyse begin check global event, %d", cwmp->event_global.event_flag);
		
		//check global event for transfercomplete
	
		if(cwmp->event_global.event_flag & EVENT_REBOOT_TRANSFERCOMPLETE_FLAG)
		{
			cwmp->event_global.event_flag &=  ~EVENT_REBOOT_TRANSFERCOMPLETE_FLAG;
			if(!doctmppool)
			{
				doctmppool = pool_create(POOL_DEFAULT_SIZE);
			}
			event_code_t ec;
			ec.event = INFORM_TRANSFERCOMPLETE;
			TRstrncpy(ec.command_key, cwmp->event_global.event_key, COMMAND_KEY_LEN);
			ec.fault_code = cwmp->event_global.fault_code;
			ec.start = cwmp->event_global.start;
			ec.end = cwmp->event_global.end;
			newdoc = cwmp_session_create_transfercomplete_message(session, &ec, doctmppool);	

		}
		
	}

    }


    cwmp_log_debug("newdoc %p, msglength: %d", newdoc, msglength );
    if((newdoc != NULL) || (newdoc == NULL && msglength != 0)) // || (newdoc == NULL && msglength == 0 && session->retry_count < 2))
    {
        session->newdata = CWMP_YES;
        cwmp_write_doc_to_chunk(newdoc, session->writers,  session->envpool);
	rc = CWMP_OK;
    }
    else
    {  	
	rc = CWMP_ERROR;
    }
	
finished:
	if(doctmppool  != NULL)
	{
	    pool_destroy(doctmppool);
	}
	
    return rc;
}
コード例 #13
0
ファイル: pool.c プロジェクト: broftkd/historic-mess
void pool_free(memory_pool *pool)
{
	pool_clear(pool);
	free(pool);
}