bool KviKvsObjectClass::save(const QString & szFileName) { if(!m_pParentClass) return false; if(isBuiltin()) return false; QString szBuffer = QString("# Automatically generated KVS class dump\n\nclass(\"%1\",\"%2\")\n{\n").arg(m_szName,m_pParentClass->name()); KviPointerHashTableIterator<QString,KviKvsObjectFunctionHandler> it(*m_pFunctionHandlers); while(KviKvsObjectFunctionHandler * h = it.current()) { if(h->isScriptHandler() && !h->isClone()) { szBuffer += " "; if(h->flags() & KviKvsObjectFunctionHandler::Internal) szBuffer += "internal "; szBuffer += "function "; szBuffer += it.currentKey(); szBuffer += "("+h->reminder()+")\n"; QString szCode = h->scriptHandlerCode(); KviCommandFormatter::blockFromBuffer(szCode); KviCommandFormatter::indent(szCode); szBuffer += szCode; szBuffer += "\n"; } ++it; } szBuffer += "}\n"; return KviFileUtils::writeFile(szFileName,szBuffer); }
as_object* as_function::construct(as_object& newobj, const as_environment& env, fn_call::Args& args) { const int swfversion = getSWFVersion(env); // Add a __constructor__ member to the new object visible from version 6. const int flags = PropFlags::dontEnum | PropFlags::onlySWF6Up; newobj.init_member(NSV::PROP_uuCONSTRUCTORuu, this, flags); if (swfversion < 7) { newobj.init_member(NSV::PROP_CONSTRUCTOR, this, PropFlags::dontEnum); } // Don't set a super so that it will be constructed only if required // by the function. fn_call fn(&newobj, env, args, 0, true); as_value ret; try { ret = call(fn); } catch (const GnashException& ex) { // Catching a std::exception here can mask all sorts of bad // behaviour, as (for instance) a poorly constructed string may // smash the stack, throw an exception, but not abort. // This is very effective at confusing debugging tools. // We only throw GnashExceptions. A std::bad_alloc may also be // reasonable, but anything else shouldn't be caught here. log_debug("Native function called as constructor threw exception: " "%s", ex.what()); // If a constructor throws an exception, throw it back to the // caller. This is the only way to signal that a constructor // did not return anything. throw; } // Some built-in constructors do things properly and operate on the // 'this' pointer. Others return a new object. This is to handle those // cases. if (isBuiltin() && ret.is_object()) { as_object* fakeobj = toObject(ret, getVM(env)); fakeobj->init_member(NSV::PROP_uuCONSTRUCTORuu, as_value(this), flags); // Also for SWF5+ only? if (swfversion < 7) { fakeobj->init_member(NSV::PROP_CONSTRUCTOR, as_value(this), PropFlags::dontEnum); } return fakeobj; } return &newobj; }
int execSimple(simpleCmd* cmd, int* pipeIn, int* pipeOut) { if (strcmp(cmd->name, CD_STR) == 0 || strcmp(cmd->name, SET_STR) == 0) { executeBuiltin(cmd); return getpid(); } else { int pid = fork(); if (pid == 0) { if(pipeIn != NULL) { dup2(pipeIn[0], STDIN_FILENO); close(pipeIn[0]); close(pipeIn[1]); } if(pipeOut != NULL) { dup2(pipeOut[1], STDOUT_FILENO); close(pipeOut[0]); close(pipeOut[1]); } if(isBuiltin(cmd)) { executeBuiltin(cmd); } else { // use execvp -- automatically finds based on $PATH if (execvp(cmd->name, cmd->args) < 0) { fprintf(stderr, "Something went wrong!\n"); if (errno == ENOENT) { fprintf(stderr, "command not found: %s\n", cmd->name); } } printf("This is the exec call's return value: %d\n", execv(cmd->name, cmd->args)); printf("With errno=%d\n",errno); } exit(0); } else if (pipeIn != NULL) { close(pipeIn[0]); close(pipeIn[1]); } return pid; } };
bool Func::byRef(int32 arg) const { // Super special case. A handful of builtins are varargs functions where the // (not formally declared) varargs are pass-by-reference. psychedelic-kitten if (arg >= m_numParams && isBuiltin() && (info()->attribute & (ClassInfo::RefVariableArguments | ClassInfo::MixedVariableArguments))) { return true; } int qword = arg / kBitsPerQword; int bit = arg % kBitsPerQword; bool retval = arg < m_numParams && (m_refBitVec[qword] & (1ull << bit)) != 0; return retval; }
bool Func::mustBeRef(int32 arg) const { // return true if the argument is required to be a reference // (and thus should be an lvalue) if (arg >= m_numParams && isBuiltin() && (info()->attribute & (ClassInfo::RefVariableArguments | ClassInfo::MixedVariableArguments) == ClassInfo::RefVariableArguments)) { return true; } int qword = arg / kBitsPerQword; int bit = arg % kBitsPerQword; bool retval = arg < m_numParams && (m_refBitVec[qword] & (1ull << bit)) != 0; return retval; }
bool HHVM_FUNCTION(class_alias, const String& original, const String& alias, bool autoload /* = true */) { auto const origClass = autoload ? Unit::loadClass(original.get()) : Unit::lookupClass(original.get()); if (!origClass) { raise_warning("Class %s not found", original.data()); return false; } if (origClass->isBuiltin()) { raise_warning( "First argument of class_alias() must be a name of user defined class"); return false; } return Unit::aliasClass(origClass, alias.get()); }
bool Func::isNameBindingImmutable(const Unit* fromUnit) const { if (RuntimeOption::EvalJitEnableRenameFunction || m_attrs & AttrDynamicInvoke) { return false; } if (isBuiltin()) { return true; } if (isUnique() && RuntimeOption::RepoAuthoritative) { return true; } // Defined at top level, in the same unit as the caller. This precludes // conditionally defined functions and cross-module calls -- both phenomena // can change name->Func mappings during the lifetime of a TC. return top() && (fromUnit == m_unit); }
int runCmd(char **cmd) { pid_t pid; int status,pipes; //Check if given command is a built-in int builtinType; if(builtinType=isBuiltin(cmd[0])) return runBuiltin(cmd,builtinType); iodata io = {STDIN_FILENO,STDOUT_FILENO}; //check if background process int bg=0,i; for(i=0;cmd[i]!=NULL;i++) if(strcmp(cmd[i],"&")==0) { bg=1; cmd[i]=NULL; } if((pid = fork()) == 0) { pipes=numPipes(cmd); //let plumber handle the pipes plumber(pipes,cmd,io); } else if(pid < 0) { perror("shelldon"); } else { if(!bg) //don't wait if background process do { waitpid(pid, &status, WUNTRACED); } while(!WIFEXITED(status) && WIFSIGNALED(status)); /*waits for the child to return by exiting normally or due to some unhandled signal*/ } return 1; }
void FunctionInliningPass::_getFunctionsToInline(ir::IRKernel& k) { report(" Finding functions that are eligible for inlining..."); for(auto block = k.cfg()->begin(); block != k.cfg()->end(); ++block) { bool linked = false; for(auto instruction = block->instructions.begin(); instruction != block->instructions.end(); ++instruction) { auto ptx = static_cast<ir::PTXInstruction&>(**instruction); if(ptx.opcode != ir::PTXInstruction::Call) continue; report(" Examining " << ptx.toString()); if(ptx.a.addressMode != ir::PTXOperand::FunctionName) { report(" skipping because it is an indirect call."); continue; } // Get the kernel being called if it is in this module auto calledKernel = k.module->getKernel(ptx.a.identifier); // Skip kernels in another module if(calledKernel == 0) { report(" skipping because it is in a different module."); continue; } // Skip kernels that are built-in functions if(isBuiltin(ptx.a.identifier)) { report(" skipping because it is a reserved keyword."); continue; } // Skip kernels that are too large to inline if(calledKernel->cfg()->instructionCount() > thresholdToInline) { report(" skipping because it is too large (" << calledKernel->cfg()->instructionCount() << " > " << thresholdToInline << ")."); continue; } report(" it is eligible for inlining!"); if(linked) { _calls.back().linked = true; } _calls.push_back(FunctionCallDescriptor( instruction, block, calledKernel)); linked = true; } } }
CELL * p_replace(CELL * params) { CELL * keyCell; CELL * repCell; CELL * funcCell = NULL; CELL * list; CELL * cell; CELL * newList; char * keyStr; char * buff; char * newBuff; UINT cnt; size_t newLen; long options; UINT * resultIdxSave; SYMBOL * refSymbol; keyCell = copyCell(evaluateExpression(params)); pushResult(keyCell); params = getEvalDefault(params->next, &cell); newList = cell; refSymbol = symbolCheck; if(symbolCheck && (isProtected(symbolCheck->flags) || isBuiltin(symbolCheck->flags))) return(errorProcExt2(ERR_SYMBOL_PROTECTED, stuffSymbol(symbolCheck))); cnt = 0; resultIdxSave = resultStackIdx; if(isList(cell->type)) { cell->aux = (UINT)nilCell; /* undo last element optimization */ list = (CELL *)cell->contents; if(params != nilCell) { repCell = params; if(params->next != nilCell) funcCell = evaluateExpression(params->next); } else repCell = NULL; COMPARE_START: if(compareFunc(keyCell, list, funcCell) == 0) { if(repCell != NULL) { /* take out usage of sysSymbol0] in 10.2 should only be used for regex replacements then $it doesn't need to be a copy */ deleteList((CELL*)sysSymbol[0]->contents); itSymbol->contents = (UINT)copyCell(list); sysSymbol[0]->contents = itSymbol->contents; cell->contents = (UINT)copyCell(evaluateExpression(repCell)); cell = (CELL*)cell->contents; cell->next = list->next; } else /* remove mode */ cell->contents = (UINT)list->next; list->next = nilCell; deleteList(list); cnt++; if(repCell != NULL) list = cell; else /* remove mode */ { list = (CELL*)cell->contents; if(list != nilCell) goto COMPARE_START; } } while(list->next != nilCell) { if(compareFunc(keyCell, list->next, funcCell) == 0) { cell = list->next; /* cell = old elmnt */ if(repCell != NULL) { /* take out usage of sysSymbol0] in 10.2 should only be used for regex replacements */ deleteList((CELL*)sysSymbol[0]->contents); itSymbol->contents = (UINT)copyCell(cell); sysSymbol[0]->contents = itSymbol->contents; list->next = copyCell(evaluateExpression(repCell)); list = list->next; } list->next = cell->next; cell->next = nilCell; deleteList(cell); cnt++; } else list = list->next; cleanupResults(resultIdxSave); } deleteList((CELL*)sysSymbol[0]->contents); /* sysSymbol[0] should not be used here, introduce $count */ sysSymbol[0]->contents = (UINT)stuffInteger(cnt); itSymbol->contents = (UINT)nilCell; symbolCheck = refSymbol; pushResultFlag = FALSE; return(newList); } if(cell->type == CELL_STRING) { if(keyCell->type != CELL_STRING) return(errorProc(ERR_STRING_EXPECTED)); keyStr = (char *)keyCell->contents; buff = (char *)cell->contents; repCell = params; if(repCell == nilCell) return(errorProc(ERR_MISSING_ARGUMENT)); options = -1; if(repCell->next != nilCell) getInteger(repCell->next, (UINT*)&options); newBuff = replaceString(keyStr, keyCell->aux - 1, buff, (size_t)cell->aux -1, repCell, &cnt, options, &newLen); if(newBuff != NULL) { freeMemory(buff); cell->contents = (UINT)newBuff; cell->aux = newLen + 1; } deleteList((CELL*)sysSymbol[0]->contents); sysSymbol[0]->contents = (UINT)stuffInteger(cnt); symbolCheck = refSymbol; pushResultFlag = FALSE; return(cell); } return(errorProcExt(ERR_LIST_OR_STRING_EXPECTED, cell)); }