static c_type createTopicKeyType ( c_type messageType, const c_char *keyExpr) { c_string typeName; c_char *name; c_long length; c_type keyType; c_array keyList; c_bool proceed; keyList = NULL; proceed = createMessageKeyList(messageType, keyExpr, &keyList); if (proceed) { typeName = c_metaName(c_metaObject(messageType)); length = strlen(typeName) + strlen(keyExpr) + 3; name = os_alloca(length); snprintf(name,length,"%s<%s>",typeName,keyExpr); keyType = createKeyType(name,keyList); c_free(typeName); os_freea(name); } else { keyType = NULL; } c_free(keyList); return keyType; }
static c_bool isGroupMatched( c_string expr, c_voidp args) { char* str; unsigned int partitionLength, topicLength; c_string partition, topic; struct groupMatched* data; data = (struct groupMatched*)args; /* Retrieve partition- & topicname and their lengths */ partition = v_entity(data->group->partition)->name; topic = v_entity(data->group->topic)->name; partitionLength = strlen(partition); topicLength = strlen(topic); /* Allocate temporary string on stack */ str = os_alloca(partitionLength + topicLength + 1 + 1); /* include '.' */ /* Build string */ os_strcpy(str, partition); str[partitionLength] = '.'; os_strcpy(str + partitionLength + 1, topic); /* Match string with pattern */ if(ut_patternMatch(str, expr)) { data->matched = 1; } /* Because not all platforms properly support alloca.. */ os_freea(str); return (!data->matched); }
static void determineSampleInfoView ( readerViewActionArg *info) { gapi_unsigned_long i; v_readerSampleSeq *samples = info->samples; gapi_unsigned_long length; gapi_dataSampleSeq dataSamples; gapi_dataSample onePlaceBuffer; gapi_boolean onHeap = FALSE; gapi_boolean onStack = FALSE; assert(samples->_length > 0); length = samples->_length; if ( length == 1 ) { dataSamples._buffer = &onePlaceBuffer; } else if ( length < MAX_DATASAMPLESEQ_SIZE_ON_STACK ) { dataSamples._buffer = (gapi_dataSample *)os_alloca(length*sizeof(gapi_dataSample)); if ( dataSamples._buffer ) { onStack = TRUE; } else { dataSamples._buffer = (gapi_dataSample *)os_malloc(length*sizeof(gapi_dataSample)); onHeap = TRUE; } } else { dataSamples._buffer = (gapi_dataSample *)os_malloc(length*sizeof(gapi_dataSample)); onHeap = TRUE; } if ( dataSamples._buffer ) { dataSamples._length = length; dataSamples._maximum = length; dataSamples._release = FALSE; for ( i = 0; i < length; i++ ) { v_dataViewSampleTemplate viewSample = v_dataViewSampleTemplate(samples->_buffer[i]); v_dataReaderSampleTemplate sample = v_dataReaderSampleTemplate(viewSample->sample); v_message message = sample->message; dataSamples._buffer[i].data = (void *)C_DISPLACE(message, info->datareaderview->datareader->userdataOffset); copySampleInfoView(v_readerSample(viewSample), message, &dataSamples._buffer[i].info); } computeGenerationRanksView(samples, &dataSamples); info->readerCopy(&dataSamples, info->readerInfo); if ( onStack ) { os_freea(dataSamples._buffer); } else { if ( onHeap ) { os_free(dataSamples._buffer); } } } else { info->result = GAPI_RETCODE_OUT_OF_RESOURCES; } }
void v_indexInit( v_index index, c_type instanceType, c_array keyList, v_reader reader) { c_property keyProperty; c_structure keyStructure; c_char fieldName[16]; c_char *keyExpr; c_size i,nrOfKeys,totalSize; assert(index != NULL); assert(C_TYPECHECK(index,v_index)); assert(C_TYPECHECK(instanceType,c_type)); keyProperty = c_property(c_metaResolve(c_metaObject(instanceType),"key")); if (keyProperty) { keyStructure = c_structure(keyProperty->type); nrOfKeys = c_arraySize(keyStructure->members); c_free(keyProperty); } else { nrOfKeys = 0; } if (nrOfKeys>0) { totalSize = nrOfKeys * strlen("key.field0,"); if (nrOfKeys > 9) { /* For each key number greater than one digit * i.e. number of keys > 9 add one additional * character space to the total size. */ totalSize += (nrOfKeys-9); if (nrOfKeys > 99) { /* For each key number greater than two digits * i.e. number of keys > 99 add one additional * character space to the total size. */ totalSize += (nrOfKeys-99); } } keyExpr = (char *)os_alloca(totalSize); keyExpr[0] = 0; for (i=0;i<nrOfKeys;i++) { os_sprintf(fieldName,"key.field%d",i); os_strcat(keyExpr,fieldName); if (i<(nrOfKeys-1)) { os_strcat(keyExpr,","); } } } else { keyExpr = NULL; } index->reader = reader; index->sourceKeyList = createKeyList(instanceType, keyList); index->messageKeyList = c_keep(keyList); /* keyList is either topic->messageKeyList or a user-defined keylist */ index->objects = c_tableNew(instanceType,keyExpr); index->notEmptyList = c_tableNew(instanceType,keyExpr); if(keyExpr){ os_freea(keyExpr); } index->objectType = c_keep(instanceType); }
static c_type createInstanceType ( v_topic topic, c_char *keyExpr, c_array *keyListRef) { c_metaObject o; c_type instanceType, baseType, foundType; c_type sampleType, keyType, keyInstanceType; c_base base; c_char *name; os_size_t length; int sres; assert(C_TYPECHECK(topic,v_topic)); foundType = NULL; if (keyExpr) { keyType = v_topicKeyTypeCreate(topic,keyExpr,keyListRef); } else { keyExpr = v_topicKeyExpr(topic); keyType = v_topicKeyType(topic); *keyListRef = c_keep(v_topicMessageKeyList(topic)); } sampleType = sampleTypeNew(topic); if (sampleType) { base = c_getBase(topic); baseType = v_dataReaderInstance_t(base); instanceType = c_type(c_metaDefine(c_metaObject(base),M_CLASS)); if (instanceType != NULL) { c_class(instanceType)->extends = c_keep(c_class(baseType)); o = c_metaDeclare(c_metaObject(instanceType), "sample",M_ATTRIBUTE); c_property(o)->type = c_keep(sampleType); c_free(o); o = c_metaDeclare(c_metaObject(instanceType), "oldest",M_ATTRIBUTE); c_property(o)->type = (c_type)c_metaResolveType(c_metaObject(base), "c_voidp"); assert(c_property(o)->type); c_free(o); c_metaFinalize(c_metaObject(instanceType)); #define INSTANCE_NAME "v_indexInstance<v_indexSample<>>" #define INSTANCE_FORMAT "v_indexInstance<v_indexSample<%s>>" /* The sizeof contains \0 */ length = sizeof(INSTANCE_NAME) + strlen(v_topicName(topic)); name = os_alloca(length); sres = snprintf(name,length,INSTANCE_FORMAT,v_topicName(topic)); assert(sres >= 0 && (os_size_t) sres == (length-1)); OS_UNUSED_ARG(sres); #undef INSTANCE_NAME #undef INSTANCE_FORMAT foundType = c_type(c_metaBind(c_metaObject(base), name, c_metaObject(instanceType))); if (foundType == NULL) { OS_REPORT(OS_ERROR, "v_index::createInstanceType",V_RESULT_INTERNAL_ERROR, "Could not create instance type"); } os_freea(name); if (keyType != NULL) { keyInstanceType = c_type(c_metaDefine(c_metaObject(base),M_CLASS)); if (keyInstanceType) { c_class(keyInstanceType)->extends = c_keep(c_class(instanceType)); o = c_metaDeclare(c_metaObject(keyInstanceType), "key",M_ATTRIBUTE); c_property(o)->type = c_keep(keyType); c_free(o); c_metaFinalize(c_metaObject(keyInstanceType)); #define INSTANCE_NAME "v_indexKeyInstance<v_indexSample<>,>" #define INSTANCE_FORMAT "v_indexKeyInstance<v_indexSample<%s>,%s>" /* The sizeof contains \0 */ length = sizeof(INSTANCE_NAME) + strlen(v_topicName(topic)) + strlen(keyExpr); name = os_alloca(length); sres = snprintf(name, length, INSTANCE_FORMAT, v_topicName(topic), keyExpr); assert(sres >= 0 && (os_size_t) sres == (length-1)); OS_UNUSED_ARG(sres); #undef INSTANCE_NAME #undef INSTANCE_FORMAT c_free(foundType); /* Will be overwritten, so free */ foundType = c_type(c_metaBind(c_metaObject(base), name, c_metaObject(keyInstanceType))); if (foundType == NULL) { OS_REPORT(OS_ERROR, "v_index::createInstanceType",V_RESULT_INTERNAL_ERROR, "Could not create key instance type"); } os_freea(name); c_free(keyInstanceType); } c_free(keyType); } c_free(instanceType); c_free(baseType); } else { foundType = baseType; /* transfer refCount to caller */ } c_free(sampleType); } return foundType; }