/** * Function to put a new entry in the queue. * @param invoc an initialized StoredInvoc. * */ static jboolean invocPut(StoredInvoc* invoc) { StoredLink *link, *last; link = (StoredLink*) pcsl_mem_calloc(1, sizeof(StoredLink)); if (link == NULL) return PCSL_FALSE; link->invoc = invoc; if (invocQueue == NULL) { invocQueue = link; } else { for (last = invocQueue; last->flink != NULL; last = last->flink); link->blink = last; last->flink = link; } return PCSL_TRUE; }
/** * Fills output result structure with handler data. * @param handler handler reduced data. * @param result output result structure. * @return operation status. */ jsr211_result jsr211_fillHandler(const JSR211_CH* ch, /*OUT*/ JSR211_RESULT_CH* result) { if (ch == NULL) { result->len = 0; result->buf = NULL; } else { result->len = getSerializedCHSize(ch); result->buf = (jchar*)pcsl_mem_calloc(result->len, sizeof(jchar)); if (result->buf == NULL) { result->len = 0; KNI_ThrowNew(midpOutOfMemoryError, "No memory for handler data"); return JSR211_FAILED; } appendSerializedCH(ch, result->buf); } return JSR211_OK; }
/* * Test the Calloc method. * Try allocating space for some structs and ensure that the * fields are initialized to zero */ void testCalloc() { struct point { int x; int y; }; struct point *start; struct point *pt; start = pcsl_mem_calloc(sizeof(struct point), 10); pt = start; assertTrue("pcsl_mem_calloc failed to zero allocated bytes", (pt->x == 0) && (pt->y ==0)); pt += 9; assertTrue("pcsl_mem_calloc failed to zero allocated bytes", (pt->x == 0) && (pt->y ==0)); pcsl_mem_free(start); }
/** * Implementation of native method to queue a new Invocation. * The state of the InvocationImpl is copied to the heap * and inserted in the head of the invocation queue. * An StoredInvoc struct is allocated on the native heap and * the non-null strings for each field of the InvocationImpl class * are copied to the heap. * A new transaction ID is assigned to this Invocation * and returned in the tid field of the InvocationImpl. * @param invoc the InvocationImpl to store * @throws OutOfMemoryError if the memory allocation fails * @see StoredInvoc * @see #invocQueue */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_content_InvocationStore_put0(void) { StoredInvoc* invoc = NULL; KNI_StartHandles(4); KNI_DeclareHandle(invocObj); KNI_DeclareHandle(classObj); KNI_DeclareHandle(argsObj); KNI_DeclareHandle(str); KNI_GetParameterAsObject(1, invocObj); init(invocObj, classObj); do { /* On any error break out of this block */ /* Allocate a new zero'ed struct to save the values in */ invoc = (StoredInvoc*) pcsl_mem_calloc(1, sizeof (StoredInvoc)); if (invoc == NULL) { KNI_ThrowNew(midpOutOfMemoryError, "InvocationStore_put0 no memory for [invoc]"); break; } /* Assign a new transaction id and set it */ invoc->tid = invocNextTid(); KNI_SetIntField(invocObj, tidFid, invoc->tid); /* * Copy all the parameters to native * Includes ID, type,url, action, args, data */ if (KNI_TRUE != setParamsFromObj(invoc, invocObj, str, argsObj)) break; invoc->previousTid = KNI_GetIntField(invocObj, previousTidFid); invoc->status = KNI_GetIntField(invocObj, statusFid); invoc->responseRequired = KNI_GetBooleanField(invocObj, responseRequiredFid); invoc->suiteId = KNI_GetIntField(invocObj, suiteIdFid); KNI_GetObjectField(invocObj, classnameFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->classname)) break; KNI_GetObjectField(invocObj, invokingAuthorityFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->invokingAuthority)) break; KNI_GetObjectField(invocObj, invokingAppNameFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->invokingAppName)) break; invoc->invokingSuiteId = KNI_GetIntField(invocObj, invokingSuiteIdFid); KNI_GetObjectField(invocObj, invokingClassnameFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->invokingClassname)) break; KNI_GetObjectField(invocObj, invokingIDFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->invokingID)) break; KNI_GetObjectField(invocObj, usernameFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->username)) break; KNI_GetObjectField(invocObj, passwordFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->password)) break; /* Insert the new Invocation at the end of the queue */ if (!invocPut(invoc)) break; unblockWaitingThreads(STATUS_OK); /* Clear to skip cleanup and throwing exception */ invoc = NULL; } while (0); if (invoc != NULL) { /* An allocation error occurred; free any remaining */ invocFree(invoc); KNI_ThrowNew(midpOutOfMemoryError, "invocStore.c allocation failed"); } KNI_EndHandles(); KNI_ReturnVoid(); }