void test__insert_into_hash_table_duplicate(void **state) { initializeHashTable(100); Oid o = 139753; int t = 'x'; int result = insertIntoHashTable(o, t); assert_true(result == 0); result = insertIntoHashTable(o, t); assert_true(result == -1); cleanUpTable(); }
void test__insert_into_hash_table_large_num_keys(void **state) { initializeHashTable(10); Oid o = 139753; int result = 0; int i = 0; for(; i < 20; i++) { result = insertIntoHashTable(o + i, 'x'); assert_true(result == 0); } for(i = 0; i < 20; i++) { result = removeNode(o + i); assert_true(result == 0); } for(i = 0; i < 20; i++) { char typstorage = getTypstorage(o + i); assert_true(typstorage == EMPTY_TYPSTORAGE); } cleanUpTable(); }
Res *setVariableValue(char *varName, Res *val, ruleExecInfo_t *rei, Env *env, rError_t *errmsg, Region *r) { int i; char *varMap; char errbuf[ERR_MSG_LEN]; if (varName[0] == '$') { if(TYPE(val)!=T_STRING) { snprintf(errbuf, ERR_MSG_LEN, "error: assign a nonstring value to session variable %s.", varName); addRErrorMsg(errmsg, RE_UNSUPPORTED_OP_OR_TYPE, errbuf); return newErrorRes(r, RE_UNSUPPORTED_OP_OR_TYPE); } i = getVarMap("", varName, &varMap, 0); if (i < 0) { snprintf(errbuf, ERR_MSG_LEN, "error: unsupported session variable \"%s\".",varName); addRErrorMsg(errmsg, RE_UNSUPPORTED_SESSION_VAR, errbuf); return newErrorRes(r, RE_UNSUPPORTED_SESSION_VAR); } setVarValue(varMap, rei, strdup(val->text)); return newIntRes(r, 0); } else if(varName[0] == '*') { if(lookupFromEnv(env, varName)==NULL) { /* new variable */ if(insertIntoHashTable(env->current, varName, val) == 0) { snprintf(errbuf, ERR_MSG_LEN, "error: unable to write to local variable \"%s\".",varName); addRErrorMsg(errmsg, RE_UNABLE_TO_WRITE_LOCAL_VAR, errbuf); return newErrorRes(r, RE_UNABLE_TO_WRITE_LOCAL_VAR); } } else { updateInEnv(env, varName, val); } return newIntRes(r, 0); } return newIntRes(r, 0); }
void updateInEnv(Env *env, char *varName, Res *res) { Env *defined = env; while(defined != NULL && lookupFromHashTable(defined->current, varName) == NULL) { defined = defined ->previous; } if(defined != NULL) { updateInHashTable(defined->current, varName, res); } else { insertIntoHashTable(env->current, varName, res); } }
void test__get_typstorage(void **state) { initializeHashTable(100); Oid o = 139753; int t = 'x'; int result = insertIntoHashTable(o, t); assert_true(result == 0); char typstorage = getTypstorage(o); assert_true(typstorage == t); cleanUpTable(); }
void prependRuleIntoAppIndex(RuleDesc *rule, int i, Region *r) { RuleIndexList *rd; FunctionDesc *fd = (FunctionDesc *)lookupFromHashTable(ruleEngineConfig.appFuncDescIndex->current, RULE_NAME(rule->node)); if(fd == NULL) { rd = newRuleIndexList(RULE_NAME(rule->node), i, r); fd = newRuleIndexListFD(rd, NULL, r); insertIntoHashTable(ruleEngineConfig.appFuncDescIndex->current, RULE_NAME(rule->node), fd); } else { rd = FD_RULE_INDEX_LIST(fd); prependRuleNodeToRuleIndexList(rd, i ,r); } }
execCmdOut_t *addCmdExecOutToEnv( Env *global, Region *r ) { execCmdOut_t *ruleExecOut = ( execCmdOut_t * )malloc( sizeof( execCmdOut_t ) ); memset( ruleExecOut, 0, sizeof( execCmdOut_t ) ); ruleExecOut->stdoutBuf.buf = strdup( "" ); ruleExecOut->stdoutBuf.len = 0; ruleExecOut->stderrBuf.buf = strdup( "" ); ruleExecOut->stderrBuf.len = 0; Res *execOutRes = newUninterpretedRes( r, ExecCmdOut_MS_T, ruleExecOut, NULL ); insertIntoHashTable( global->current, "ruleExecOut", execOutRes ); return ruleExecOut; }
void test__insert_into_hash_table(void **state) { initializeHashTable(90); Oid o = 139753; int t = 'x'; int result = insertIntoHashTable(o, t); assert_true(result == 0); result = getTypstorage(o); assert_true(result == 'x'); cleanUpTable(); }
void test__remove_node(void **state) { initializeHashTable(100); Oid o = 139753; int t = 'x'; int result = insertIntoHashTable(o, t); assert_true(result == 0); result = removeNode(o); assert_true(result == 0); char typstorage = getTypstorage(o); assert_true(typstorage == EMPTY_TYPSTORAGE); cleanUpTable(); }
ExprType *dupTypeAux(ExprType *ty, Region *r, Hashtable *varTable) { ExprType **paramTypes; int i; ExprType *newt; ExprType *exist; char *name; char buf[128]; switch(getNodeType(ty)) { case T_CONS: paramTypes = (ExprType **) region_alloc(r,sizeof(ExprType *)*T_CONS_ARITY(ty)); for(i=0;i<T_CONS_ARITY(ty);i++) { paramTypes[i] = dupTypeAux(T_CONS_TYPE_ARG(ty, i),r,varTable); } newt = newConsType(T_CONS_ARITY(ty), T_CONS_TYPE_NAME(ty), paramTypes, r); newt->option = ty->option; break; case T_TUPLE: paramTypes = (ExprType **) region_alloc(r,sizeof(ExprType *)*T_CONS_ARITY(ty)); for(i=0;i<T_CONS_ARITY(ty);i++) { paramTypes[i] = dupTypeAux(T_CONS_TYPE_ARG(ty, i),r,varTable); } newt = newTupleType(T_CONS_ARITY(ty), paramTypes, r); newt->option = ty->option; break; case T_VAR: name = getTVarName(T_VAR_ID(ty), buf); exist = (ExprType *)lookupFromHashTable(varTable, name); if(exist != NULL) newt = exist; else { newt = newTVar2(T_VAR_NUM_DISJUNCTS(ty), T_VAR_DISJUNCTS(ty), r); insertIntoHashTable(varTable, name, newt); } newt->option = ty->option; break; case T_FLEX: paramTypes = (ExprType **) region_alloc(r,sizeof(ExprType *)*1); paramTypes[0] = dupTypeAux(ty->subtrees[0],r,varTable); newt = newExprType(T_FLEX, 1, paramTypes, r); newt->option = ty->option; break; default: newt = ty; break; } return newt; }
ExprType* unifyTVarR(ExprType *type, ExprType* expected, Hashtable *varTypes, Region *r) { char buf[128]; if(T_VAR_NUM_DISJUNCTS(expected)==0) { /* free */ if(occursIn(expected, type)) { return NULL; } insertIntoHashTable(varTypes, getTVarName(T_VAR_ID(expected), buf), type); return dereference(expected, varTypes, r); } else { /* union type */ int i; ExprType *ty = NULL; for(i=0;i<T_VAR_NUM_DISJUNCTS(expected);i++) { if(getNodeType(type) == getNodeType(T_VAR_DISJUNCT(expected,i))) { /* union types can only include primitive types */ ty = type; } } if(ty != NULL) { insertIntoHashTable(varTypes, getTVarName(T_VAR_ID(expected), buf), ty); return dereference(expected, varTypes, r); } return ty; } }
void test__remove_node_not_present_in_list(void **state) { initializeHashTable(10); Oid o = 139753; int i = 0; int result = 0; for(; i < 20; i++) { result = insertIntoHashTable(o + i, 'x'); assert_true(result == 0); } result = removeNode(o + 21); assert_true(result == -1); cleanUpTable(); }
void test__clean_up_table(void **state) { initializeHashTable(100); Oid o = 123456; int i = 0; int result = 0; for(; i < 20; i++) { result = insertIntoHashTable(o + i, 'x'); assert_true(result == 0); } cleanUpTable(); assert_true(hash_table == NULL); assert_true(HASH_TABLE_SIZE == 0); }
int mknodLazyUploadBufferedFile(const char *path) { int status; lazyUploadFileInfo_t *lazyUploadFileInfo = NULL; char iRODSPath[MAX_NAME_LEN]; char bufferPath[MAX_NAME_LEN]; // convert input path to iRODSPath status = _getiRODSPath(path, iRODSPath); if(status < 0) { rodsLog (LOG_DEBUG, "mknodLazyUploadBufferedFile: failed to get iRODS path - %s", path); return status; } status = _getBufferPath(iRODSPath, bufferPath); if(status < 0) { rodsLog (LOG_DEBUG, "mknodLazyUploadBufferedFile: failed to get buffer path - %s", iRODSPath); return status; } LOCK(LazyUploadLock); // make dir makeParentDirs(bufferPath); // create an empty file rodsLog (LOG_DEBUG, "mknodLazyUploadBufferedFile: create a new Buffered file - %s", iRODSPath); int desc = open (bufferPath, O_RDWR|O_CREAT|O_TRUNC, 0755); close (desc); // add to hash table lazyUploadFileInfo = (lazyUploadFileInfo_t *)malloc(sizeof(lazyUploadFileInfo_t)); lazyUploadFileInfo->path = strdup(iRODSPath); lazyUploadFileInfo->accmode = 0; // clear lazyUploadFileInfo->localHandle = -1; // clear lazyUploadFileInfo->commitCount = 0; // clear lazyUploadFileInfo->curLocalOffsetStart = 0; // clear lazyUploadFileInfo->curOffset = 0; // clear INIT_STRUCT_LOCK((*lazyUploadFileInfo)); insertIntoHashTable(LazyUploadBufferedFileTable_Created, iRODSPath, lazyUploadFileInfo); UNLOCK(LazyUploadLock); return status; }
void appendRuleIntoExtIndex(RuleDesc *rule, int i, Region *r) { FunctionDesc *fd = (FunctionDesc *)lookupFromHashTable(ruleEngineConfig.extFuncDescIndex->current, RULE_NAME(rule->node)); RuleIndexList *rd; if(fd == NULL) { rd = newRuleIndexList(RULE_NAME(rule->node), i, r); fd = newRuleIndexListFD(rd, NULL, r); insertIntoHashTable(ruleEngineConfig.extFuncDescIndex->current, RULE_NAME(rule->node), fd); } else { if(getNodeType(fd)==N_FD_RULE_INDEX_LIST) { rd = FD_RULE_INDEX_LIST(fd); appendRuleNodeToRuleIndexList(rd, i ,r); } else if(getNodeType(fd) == N_FD_EXTERNAL) { /* combine N_FD_EXTERNAL with N_FD_RULE_LIST */ updateInHashTable(ruleEngineConfig.extFuncDescIndex->current, RULE_NAME(rule->node), newRuleIndexListFD(newRuleIndexList(RULE_NAME(rule->node), i, r),fd->exprType, r)); } else { /* todo error handling */ } } }
int generateRuleTypes( RuleSet *inRuleSet, Hashtable *symbol_type_table, Region *r ) { int i; for ( i = 0; i < inRuleSet->len; i++ ) { Node *ruleNode = inRuleSet->rules[i]->node; if ( ruleNode == NULL ) { continue; } char *key = ruleNode->subtrees[0]->text; int arity = RULE_NODE_NUM_PARAMS( ruleNode ); ExprType **paramTypes = ( ExprType** ) region_alloc( r, sizeof( ExprType * ) * arity ); int k; for ( k = 0; k < arity; k++ ) { paramTypes[k] = newTVar( r ); } ExprType *ruleType = newFuncTypeVarArg( arity, OPTION_VARARG_ONCE, paramTypes, newSimpType( T_INT, r ), r ); if ( insertIntoHashTable( symbol_type_table, key, ruleType ) == 0 ) { return 0; } } return 1; }
int openPreloadedFile (const char *path) { int status; char iRODSPath[MAX_NAME_LEN]; char preloadCachePath[MAX_NAME_LEN]; preloadFileHandleInfo_t *preloadFileHandleInfo = NULL; int desc; status = _getiRODSPath(path, iRODSPath); if(status < 0) { rodsLogError(LOG_ERROR, status, "openPreloadedFile: _getiRODSPath error."); rodsLog (LOG_ERROR, "openPreloadedFile: failed to get iRODS path - %s", path); return status; } status = _getCachePath(iRODSPath, preloadCachePath); if(status < 0) { rodsLogError(LOG_ERROR, status, "openPreloadedFile: _getCachePath error."); rodsLog (LOG_ERROR, "openPreloadedFile: failed to get cache path - %s", path); return status; } LOCK(PreloadLock); desc = -1; preloadFileHandleInfo = (preloadFileHandleInfo_t *)lookupFromHashTable(PreloadFileHandleTable, iRODSPath); if(preloadFileHandleInfo != NULL) { // has preload file handle opened if(preloadFileHandleInfo->handle > 0) { // reuse handle desc = preloadFileHandleInfo->handle; rodsLog (LOG_DEBUG, "openPreloadedFile: file is already opened - %s", iRODSPath); } else { // reuse handleinfo if(_hasCache(iRODSPath) >= 0) { desc = open (preloadCachePath, O_RDONLY); if(desc > 0) { preloadFileHandleInfo->handle = desc; rodsLog (LOG_DEBUG, "openPreloadedFile: opens a file handle - %s", iRODSPath); } } } } else { // if preloaded cache file is not opened // open new if(_hasCache(iRODSPath) >= 0) { desc = open (preloadCachePath, O_RDONLY); rodsLog (LOG_DEBUG, "openPreloadedFile: open a preloaded cache path - %s", iRODSPath); if(desc > 0) { preloadFileHandleInfo = (preloadFileHandleInfo_t *)malloc(sizeof(preloadFileHandleInfo_t)); preloadFileHandleInfo->path = strdup(iRODSPath); preloadFileHandleInfo->handle = desc; INIT_STRUCT_LOCK((*preloadFileHandleInfo)); insertIntoHashTable(PreloadFileHandleTable, iRODSPath, preloadFileHandleInfo); } } } UNLOCK(PreloadLock); return desc; }
int preloadFile (const char *path, struct stat *stbuf) { int status; preloadThreadInfo_t *existingThreadInfo = NULL; preloadThreadInfo_t *threadInfo = NULL; preloadThreadData_t *threadData = NULL; char iRODSPath[MAX_NAME_LEN]; off_t cacheSize; // convert input path to iRODSPath status = _getiRODSPath(path, iRODSPath); if(status < 0) { rodsLogError(LOG_ERROR, status, "preloadFile: _getiRODSPath error."); rodsLog (LOG_ERROR, "preloadFile: failed to get iRODS path - %s", path); return status; } // check the given file is already preloaded or preloading LOCK(PreloadLock); // check the given file is preloading existingThreadInfo = (preloadThreadInfo_t *)lookupFromHashTable(PreloadThreadTable, iRODSPath); if(existingThreadInfo != NULL) { rodsLog (LOG_DEBUG, "preloadFile: preloading is already running - %s", iRODSPath); UNLOCK(PreloadLock); return 0; } if(_hasValidCache(iRODSPath, stbuf) != 0) { // invalidate cache - this may fail if cache file does not exists // if old cache exists in local, invalidate it _invalidateCache(iRODSPath); if(stbuf->st_size < PreloadConfig.preloadMinSize) { rodsLog (LOG_DEBUG, "preloadFile: given file is smaller than preloadMinSize, canceling preloading - %s", iRODSPath); UNLOCK(PreloadLock); return (0); } // check whether preload cache exceeds limit if(PreloadConfig.cacheMaxSize > 0) { // cache max size is set if(stbuf->st_size > (off_t)PreloadConfig.cacheMaxSize) { rodsLog (LOG_DEBUG, "preloadFile: given file is bigger than cacheMaxSize, canceling preloading - %s", iRODSPath); UNLOCK(PreloadLock); return (0); } cacheSize = getFileSizeRecursive(PreloadConfig.cachePath); if((cacheSize + stbuf->st_size) > (off_t)PreloadConfig.cacheMaxSize) { // evict? status = _evictOldCache((cacheSize + stbuf->st_size) - (off_t)PreloadConfig.cacheMaxSize); if(status < 0) { rodsLog (LOG_ERROR, "preloadFile: failed to evict old cache"); UNLOCK(PreloadLock); return status; } } } // does not have valid cache. now, start a new preloading // create a new thread to preload threadInfo = (preloadThreadInfo_t *)malloc(sizeof(preloadThreadInfo_t)); threadInfo->path = strdup(iRODSPath); threadInfo->running = PRELOAD_THREAD_RUNNING; INIT_STRUCT_LOCK((*threadInfo)); insertIntoHashTable(PreloadThreadTable, iRODSPath, threadInfo); // prepare thread argument threadData = (preloadThreadData_t *)malloc(sizeof(preloadThreadData_t)); threadData->path = strdup(iRODSPath); memcpy(&threadData->stbuf, stbuf, sizeof(struct stat)); threadData->threadInfo = threadInfo; rodsLog (LOG_DEBUG, "preloadFile: start preloading - %s", iRODSPath); #ifdef USE_BOOST status = threadInfo->thread = new boost::thread(_preloadThread, (void *)threadData); #else status = pthread_create(&threadInfo->thread, NULL, _preloadThread, (void *)threadData); #endif } else { rodsLog (LOG_DEBUG, "preloadFile: given file is already preloaded - %s", iRODSPath); status = 0; } UNLOCK(PreloadLock); return status; }
ExprType *typeRuleSet( RuleSet *ruleset, rError_t *errmsg, Node **errnode, Region *r ) { Env *funcDesc = ruleEngineConfig.extFuncDescIndex; Hashtable *ruleType = newHashTable2( MAX_NUM_RULES * 2, r ); ExprType *res; int i; for ( i = 0; i < ruleset->len; i++ ) { RuleDesc *rule = ruleset->rules[i]; if ( rule->ruleType == RK_REL || rule->ruleType == RK_FUNC ) { List *typingConstraints = newList( r ); Hashtable *varTypes = newHashTable2( 100, r ); ExprType *restype = typeRule( rule, funcDesc, varTypes, typingConstraints, errmsg, errnode, r ); /*char buf[1024]; */ /*typingConstraintsToString(typingConstraints, buf, 1024); */ /*printf("rule %s, typing constraints: %s\n", ruleset->rules[i]->subtrees[0]->text, buf); */ if ( getNodeType( restype ) == T_ERROR ) { res = restype; char *errbuf = ( char * ) malloc( ERR_MSG_LEN * 1024 * sizeof( char ) ); errMsgToString( errmsg, errbuf, ERR_MSG_LEN * 1024 ); #ifdef DEBUG writeToTmp( "ruleerr.log", errbuf ); writeToTmp( "ruleerr.log", "\n" ); #endif rodsLog( LOG_ERROR, "%s", errbuf ); free( errbuf ); freeRErrorContent( errmsg ); RETURN; } /* check that function names are unique and do not conflict with system msis */ char errbuf[ERR_MSG_LEN]; char *ruleName = rule->node->subtrees[0]->text; FunctionDesc *fd; if ( ( fd = ( FunctionDesc * )lookupFromEnv( funcDesc, ruleName ) ) != NULL ) { if ( getNodeType( fd ) != N_FD_EXTERNAL && getNodeType( fd ) != N_FD_RULE_INDEX_LIST ) { char *err; switch ( getNodeType( fd ) ) { case N_FD_CONSTRUCTOR: err = "redefinition of constructor"; break; case N_FD_DECONSTRUCTOR: err = "redefinition of deconstructor"; break; case N_FD_FUNCTION: err = "redefinition of system microservice"; break; default: err = "redefinition of system symbol"; break; } generateErrMsg( err, NODE_EXPR_POS( rule->node ), rule->node->base, errbuf ); addRErrorMsg( errmsg, RE_FUNCTION_REDEFINITION, errbuf ); res = newErrorType( RE_FUNCTION_REDEFINITION, r ); *errnode = rule->node; RETURN; } } RuleDesc *rd = ( RuleDesc * )lookupFromHashTable( ruleType, ruleName ); if ( rd != NULL ) { if ( rule->ruleType == RK_FUNC || rd ->ruleType == RK_FUNC ) { generateErrMsg( "redefinition of function", NODE_EXPR_POS( rule->node ), rule->node->base, errbuf ); addRErrorMsg( errmsg, RE_FUNCTION_REDEFINITION, errbuf ); generateErrMsg( "previous definition", NODE_EXPR_POS( rd->node ), rd->node->base, errbuf ); addRErrorMsg( errmsg, RE_FUNCTION_REDEFINITION, errbuf ); res = newErrorType( RE_FUNCTION_REDEFINITION, r ); *errnode = rule->node; RETURN; } } else { insertIntoHashTable( ruleType, ruleName, rule ); } } } res = newSimpType( T_INT, r ); /* Although a rule set does not have type T_INT, return T_INT to indicate success. */ ret: return res; }
int processXMsg( int streamId, char *readmsg, RuleEngineEventParam *param, Node *node, Env *env, ruleExecInfo_t *rei ) { char myhdr[HEADER_TYPE_LEN]; char mymsg[MAX_NAME_LEN]; char *outStr = NULL; int i, n; int iLevel, wCnt; int ruleInx = 0; Region *r; Res *res; rError_t errmsg; errmsg.len = 0; errmsg.errMsg = NULL; r = make_region( 0, NULL ); ParserContext *context = newParserContext( &errmsg, r ); Pointer *e = newPointer2( readmsg ); int rulegen = 1; int found; int grdf[2]; int cmd = 0; int smallW; snprintf( myhdr, HEADER_TYPE_LEN - 1, "idbug:%s", param->actionName ); memset( mymsg, 0, sizeof( mymsg ) ); PARSER_BEGIN( DbgCmd ) TRY( DbgCmd ) TTEXT2( "n", "next" ); cmd = REDEBUG_STEP_OVER; OR( DbgCmd ) TTEXT2( "s", "step" ); cmd = REDEBUG_NEXT; OR( DbgCmd ) TTEXT2( "f", "finish" ); cmd = REDEBUG_STEP_OUT; OR( DbgCmd ) TTEXT2( "b", "break" ); TRY( Param ) TTYPE( TK_TEXT ); int breakPointsInx2; for ( breakPointsInx2 = 0; breakPointsInx2 < 100; breakPointsInx2++ ) { if ( breakPoints[breakPointsInx2].actionName == NULL ) { break; } } if ( breakPointsInx2 == 100 ) { _writeXMsg( streamId, myhdr, "Maximum breakpoint count reached. Breakpoint not set.\n" ); cmd = REDEBUG_WAIT; } else { breakPoints[breakPointsInx2].actionName = strdup( token->text ); char * base_ptr = NULL; TRY( loc ) TTYPE( TK_TEXT ); base_ptr = ( char * ) malloc( sizeof( token->text ) + 2 ); base_ptr[0] = 'f'; strcpy( base_ptr + 1, token->text ); TTEXT( ":" ); TTYPE( TK_INT ); breakPoints[breakPointsInx2].base = strdup( base_ptr ); breakPoints[breakPointsInx2].line = atoi( token->text ); rodsLong_t range[2]; char rulesFileName[MAX_NAME_LEN]; getRuleBasePath( base_ptr, rulesFileName ); FILE *file; /* char errbuf[ERR_MSG_LEN]; */ file = fopen( rulesFileName, "r" ); if ( file == NULL ) { free( context ); deletePointer( e ); free( base_ptr ); return RULES_FILE_READ_ERROR; } Pointer *p = newPointer( file, base_ptr ); if ( getLineRange( p, breakPoints[breakPointsInx2].line, range ) == 0 ) { breakPoints[breakPointsInx2].start = range[0]; breakPoints[breakPointsInx2].finish = range[1]; } else { breakPoints[breakPointsInx2].actionName = NULL; } deletePointer( p ); OR( loc ) TTYPE( TK_INT ); if ( node != NULL ) { breakPoints[breakPointsInx2].base = strdup( node->base ); breakPoints[breakPointsInx2].line = atoi( token->text ); rodsLong_t range[2]; Pointer *p = newPointer2( breakPoints[breakPointsInx2].base ); if ( getLineRange( p, breakPoints[breakPointsInx2].line, range ) == 0 ) { breakPoints[breakPointsInx2].start = range[0]; breakPoints[breakPointsInx2].finish = range[1]; } else { breakPoints[breakPointsInx2].actionName = NULL; } deletePointer( p ); } else { breakPoints[breakPointsInx2].actionName = NULL; } OR( loc ) /* breakPoints[breakPointsInx].base = NULL; */ END_TRY( loc ) free( base_ptr ); if ( breakPoints[breakPointsInx2].actionName != NULL ) snprintf( mymsg, MAX_NAME_LEN, "Breakpoint %i set at %s\n", breakPointsInx2, breakPoints[breakPointsInx2].actionName ); else { snprintf( mymsg, MAX_NAME_LEN, "Cannot set breakpoint, source not available\n" ); } _writeXMsg( streamId, myhdr, mymsg ); if ( breakPointsInx <= breakPointsInx2 ) { breakPointsInx = breakPointsInx2 + 1; } cmd = REDEBUG_WAIT; } OR( Param ) NEXT_TOKEN_BASIC; _writeXMsg( streamId, myhdr, "Unknown parameter type.\n" ); cmd = REDEBUG_WAIT; OR( Param ) _writeXMsg( streamId, myhdr, "Debugger command \'break\' requires at least one argument.\n" ); cmd = REDEBUG_WAIT; END_TRY( Param ) OR( DbgCmd ) TRY( Where ) TTEXT2( "w", "where" ); smallW = 1; OR( Where ) TTEXT2( "W", "Where" ); smallW = 0; END_TRY( Where ) wCnt = 20; OPTIONAL_BEGIN( Param ) TTYPE( TK_INT ); wCnt = atoi( token->text ); OPTIONAL_END( Param ) iLevel = 0; i = reDebugStackCurrPtr - 1; while ( i >= 0 && wCnt > 0 ) { if ( !smallW || ( reDebugPCType( ( RuleEngineEvent ) reDebugStackCurr[i].label ) & 1 ) != 0 ) { snprintf( myhdr, HEADER_TYPE_LEN - 1, "idbug: Level %3i", iLevel ); char msg[HEADER_TYPE_LEN - 1]; RuleEngineEventParam param; param.ruleIndex = 0; param.actionName = reDebugStackCurr[i].step; printRuleEngineEventLabel( msg, HEADER_TYPE_LEN - 1, ( RuleEngineEvent ) reDebugStackCurr[i].label, ¶m ); _writeXMsg( streamId, myhdr, msg ); if ( reDebugStackCurr[i].label != EXEC_ACTION_BEGIN ) { iLevel++; } wCnt--; } i--; } OR( DbgCmd ) TTEXT2( "l", "list" ); TRY( Param ) TTEXT2( "r", "rule" ); TRY( ParamParam ) TTYPE( TK_TEXT ); mymsg[0] = '\n'; mymsg[1] = '\0'; snprintf( myhdr, HEADER_TYPE_LEN - 1, "idbug: Listing %s", token->text ); RuleIndexListNode *node; found = 0; while ( findNextRule2( token->text, ruleInx, &node ) != NO_MORE_RULES_ERR ) { found = 1; if ( node->secondaryIndex ) { n = node->condIndex->valIndex->len; int i; for ( i = 0; i < n; i++ ) { Bucket *b = node->condIndex->valIndex->buckets[i]; while ( b != NULL ) { RuleDesc *rd = getRuleDesc( *( int * )b->value ); char buf[MAX_RULE_LEN]; ruleToString( buf, MAX_RULE_LEN, rd ); snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "%i: %s\n%s\n", node->ruleIndex, rd->node->base[0] == 's' ? "<source>" : rd->node->base + 1, buf ); b = b->next; } } } else { RuleDesc *rd = getRuleDesc( node->ruleIndex ); char buf[MAX_RULE_LEN]; ruleToString( buf, MAX_RULE_LEN, rd ); snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "\n %i: %s\n%s\n", node->ruleIndex, rd->node->base[0] == 's' ? "<source>" : rd->node->base + 1, buf ); } ruleInx ++; } if ( !found ) { snprintf( mymsg, MAX_NAME_LEN, "Rule %s not found\n", token->text ); } _writeXMsg( streamId, myhdr, mymsg ); cmd = REDEBUG_WAIT; OR( ParamParam ) _writeXMsg( streamId, myhdr, "Debugger command \'list rule\' requires one argument.\n" ); cmd = REDEBUG_WAIT; END_TRY( ParamParam ) OR( Param ) TTEXT2( "b", "breakpoints" ); snprintf( myhdr, HEADER_TYPE_LEN - 1, "idbug: Listing %s", token->text ); mymsg[0] = '\n'; mymsg[1] = '\0'; for ( i = 0; i < breakPointsInx; i++ ) { if ( breakPoints[i].actionName != NULL ) { if ( breakPoints[i].base != NULL ) { snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "Breaking at BreakPoint %i:%s %s:%d\n", i , breakPoints[i].actionName, breakPoints[i].base[0] == 's' ? "<source>" : breakPoints[i].base + 1, breakPoints[i].line ); } else { snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "Breaking at BreakPoint %i:%s\n", i , breakPoints[i].actionName ); } } } _writeXMsg( streamId, myhdr, mymsg ); cmd = REDEBUG_WAIT; OR( Param ) TTEXT( "*" ); snprintf( myhdr, HEADER_TYPE_LEN - 1, "idbug: Listing %s", token->text ); Env *cenv = env; mymsg[0] = '\n'; mymsg[1] = '\0'; found = 0; while ( cenv != NULL ) { n = cenv->current->size; for ( i = 0; i < n; i++ ) { Bucket *b = cenv->current->buckets[i]; while ( b != NULL ) { if ( b->key[0] == '*' ) { /* skip none * variables */ found = 1; char typeString[128]; typeToString( ( ( Res * )b->value )->exprType, NULL, typeString, 128 ); snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "%s of type %s\n", b->key, typeString ); } b = b->next; } } cenv = cenv->previous; } if ( !found ) { snprintf( mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ), "<empty>\n" ); } _writeXMsg( streamId, myhdr, mymsg ); cmd = REDEBUG_WAIT; OR( Param ) syncTokenQueue( e, context ); skipWhitespace( e ); ABORT( lookAhead( e, 0 ) != '$' ); snprintf( myhdr, HEADER_TYPE_LEN - 1, "idbug: Listing %s", token->text ); mymsg[0] = '\n'; mymsg[1] = '\0'; Hashtable *vars = newHashTable( 100 ); for ( i = 0; i < coreRuleVarDef .MaxNumOfDVars; i++ ) { if ( lookupFromHashTable( vars, coreRuleVarDef.varName[i] ) == NULL ) { snprintf( &mymsg[strlen( mymsg )], MAX_NAME_LEN - strlen( mymsg ), "$%s\n", coreRuleVarDef.varName[i] ); insertIntoHashTable( vars, coreRuleVarDef.varName[i], coreRuleVarDef.varName[i] ); } } deleteHashTable( vars, NULL ); _writeXMsg( streamId, myhdr, mymsg ); cmd = REDEBUG_WAIT; OR( Param ) NEXT_TOKEN_BASIC; _writeXMsg( streamId, myhdr, "Unknown parameter type.\n" ); cmd = REDEBUG_WAIT; OR( Param ) _writeXMsg( streamId, myhdr, "Debugger command \'list\' requires at least one argument.\n" ); cmd = REDEBUG_WAIT; END_TRY( Param ) OR( DbgCmd ) TTEXT2( "c", "continue" ); cmd = REDEBUG_STEP_CONTINUE; OR( DbgCmd ) TTEXT2( "C", "Continue" ); cmd = REDEBUG_CONTINUE_VERBOSE; OR( DbgCmd ) TTEXT2( "del", "delete" ); TRY( Param ) TTYPE( TK_INT ); n = atoi( token->text ); if ( breakPoints[n].actionName != NULL ) { free( breakPoints[n].actionName ); if ( breakPoints[n].base != NULL ) { free( breakPoints[n].base ); } breakPoints[n].actionName = NULL; breakPoints[n].base = NULL; snprintf( mymsg, MAX_NAME_LEN, "Breakpoint %i deleted\n", n ); } else { snprintf( mymsg, MAX_NAME_LEN, "Breakpoint %i has not been defined\n", n ); } _writeXMsg( streamId, myhdr, mymsg ); cmd = REDEBUG_WAIT; OR( Param ) _writeXMsg( streamId, myhdr, "Debugger command \'delete\' requires one argument.\n" ); cmd = REDEBUG_WAIT; END_TRY( Param ) OR( DbgCmd ) TTEXT2( "p", "print" ); Node *n = parseTermRuleGen( e, 1, context ); if ( getNodeType( n ) == N_ERROR ) { errMsgToString( context->errmsg, mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ) ); } else { snprintf( myhdr, HEADER_TYPE_LEN - 1, "idbug: Printing " ); char * ptr = myhdr + strlen( myhdr ); i = HEADER_TYPE_LEN - 1 - strlen( myhdr ); termToString( &ptr, &i, 0, MIN_PREC, n, 0 ); snprintf( ptr, i, "\n" ); if ( env != NULL ) { disableReDebugger( grdf ); res = computeNode( n, NULL, regionRegionCpEnv( env, r, ( RegionRegionCopyFuncType * ) regionRegionCpNode ), rei, 0, &errmsg, r ); enableReDebugger( grdf ); outStr = convertResToString( res ); snprintf( mymsg, MAX_NAME_LEN, "%s\n", outStr ); free( outStr ); if ( getNodeType( res ) == N_ERROR ) { errMsgToString( &errmsg, mymsg + strlen( mymsg ), MAX_NAME_LEN - strlen( mymsg ) ); } } else { snprintf( mymsg, MAX_NAME_LEN, "Runtime environment: <empty>\n" ); } } _writeXMsg( streamId, myhdr, mymsg ); cmd = REDEBUG_WAIT; OR( DbgCmd ) TTEXT2( "d", "discontinue" ); cmd = REDEBUG_WAIT; OR( DbgCmd ) snprintf( mymsg, MAX_NAME_LEN, "Unknown Action: %s", readmsg ); _writeXMsg( streamId, myhdr, mymsg ); cmd = REDEBUG_WAIT; END_TRY( DbgCmd ) PARSER_END( DbgCmd ) freeRErrorContent( &errmsg ); region_free( r ); deletePointer( e ); free( context ); return cmd; }
/** * return The most general common instance of type and expected if unifiable * NULL if false */ ExprType* unifyWith(ExprType *type, ExprType* expected, Hashtable *varTypes, Region *r) { if(getVararg(type) != getVararg(expected)) { return NULL; } char buf[128]; /* dereference types to get the most specific type */ /* as dereference only deref top level types, it is necessary to call dereference again */ /* when unification is needed for subexpressions of the types which can be performed by calling this function */ type = dereference(type, varTypes, r); expected = dereference(expected, varTypes, r); if(getNodeType(type) == T_UNSPECED) { return expected; } if(getNodeType(expected) == T_DYNAMIC) { return type; } if(getNodeType(type) == T_VAR && getNodeType(expected) == T_VAR) { if(T_VAR_ID(type) == T_VAR_ID(expected)) { /* if both dereference to the same tvar then do not modify var types table */ return type; } else if(T_VAR_NUM_DISJUNCTS(type) > 0 && T_VAR_NUM_DISJUNCTS(expected) > 0) { Node *c[10]; Node** cp = c; int i,k; for(k=0;k<T_VAR_NUM_DISJUNCTS(expected);k++) { for(i=0;i<T_VAR_NUM_DISJUNCTS(type);i++) { if(getNodeType(T_VAR_DISJUNCT(type,i)) == getNodeType(T_VAR_DISJUNCT(expected,k))) { *(cp++)=T_VAR_DISJUNCT(expected,k); break; } } } if(cp == c) { return NULL; } else { ExprType *gcd; if(cp-c==1) { gcd = *c; } else { gcd = newTVar2(cp-c, c, r); } updateInHashTable(varTypes, getTVarName(T_VAR_ID(type), buf), gcd); updateInHashTable(varTypes, getTVarName(T_VAR_ID(expected), buf), gcd); return gcd; } } else { if(T_VAR_NUM_DISJUNCTS(type)==0) { /* free */ insertIntoHashTable(varTypes, getTVarName(T_VAR_ID(type), buf), expected); return dereference(expected, varTypes, r); } else if(T_VAR_NUM_DISJUNCTS(expected)==0) { /* free */ insertIntoHashTable(varTypes, getTVarName(T_VAR_ID(expected), buf), type); return dereference(expected, varTypes, r); } else { /* error unreachable */ return NULL; } } } else if(getNodeType(type) == T_VAR) { return unifyTVarL(type, expected, varTypes, r); } else if(getNodeType(expected) == T_VAR) { return unifyTVarR(type, expected, varTypes, r); } else { return unifyNonTvars(type, expected, varTypes, r); } }
int openLazyUploadBufferedFile(const char *path, int accmode) { int status; lazyUploadFileInfo_t *lazyUploadFileInfo = NULL; char iRODSPath[MAX_NAME_LEN]; char bufferPath[MAX_NAME_LEN]; int desc; // convert input path to iRODSPath status = _getiRODSPath(path, iRODSPath); if(status < 0) { rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: failed to get iRODS path - %s", path); return status; } status = _getBufferPath(iRODSPath, bufferPath); if(status < 0) { rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: failed to get buffer path - %s", iRODSPath); return status; } LOCK(LazyUploadLock); desc = -1; // check the given file is Buffered lazyUploadFileInfo = (lazyUploadFileInfo_t *)lookupFromHashTable(LazyUploadBufferedFileTable_Opened, iRODSPath); if(lazyUploadFileInfo != NULL) { // has lazy upload file opened rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: same file is already opened for lazy-upload - %s", iRODSPath); UNLOCK(LazyUploadLock); return -EMFILE; } lazyUploadFileInfo = (lazyUploadFileInfo_t *)lookupFromHashTable(LazyUploadBufferedFileTable_Created, iRODSPath); if(lazyUploadFileInfo != NULL) { // has lazy upload file handle opened if(lazyUploadFileInfo->localHandle > 0) { rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: same file is already opened for lazy-upload - %s", iRODSPath); UNLOCK(LazyUploadLock); return -EMFILE; } else { // update file handle and access mode desc = open (bufferPath, O_RDWR|O_CREAT|O_TRUNC, 0755); if(desc > 0) { lazyUploadFileInfo->accmode = accmode; lazyUploadFileInfo->localHandle = desc; rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: opens a file handle - %s", iRODSPath); // move to opened hashtable deleteFromHashTable(LazyUploadBufferedFileTable_Created, iRODSPath); insertIntoHashTable(LazyUploadBufferedFileTable_Opened, iRODSPath, lazyUploadFileInfo); } } } else { rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: mknod is not called before opening - %s", iRODSPath); UNLOCK(LazyUploadLock); return -EBADF; } UNLOCK(LazyUploadLock); return desc; }