func_t *func_grad_eval(func_t *h) { int j,n=0; func_t *g=NULL,*f=NULL,*x=NULL; if(h==NULL || !func_is(h,"grad") || func_asize(h)<1 || func_asize(h)>2){ FUNC_ERROR_ARG1("func_grad_eval",h); } f=func_aget(h,0); if(func_asize(h)<2 && func_is_list(f)){ x=func_bigint_int(func_asize(f),1); } else if(func_asize(h)>1) { x=FR(func_aget(h,1)); } if (func_is_list(x)) { n=func_asize(x); } else if(func_bigint_is_integer(x)) { n=func_bigint_get_si(x); } else { FUNC_ERROR_ARG2("func_grad",f,x); } if(func_is_list(f)){ g=func_list(func_asize(f)); for(j=0; j<func_asize(f); j++){ func_aset(g,j,func_grad(FR(f->a[j]),FR(x))); } }else{ g=func_list(n); for(j=0; j<n; j++){ if(func_is_list(x)){ func_aset(g,j,func_diff(FR(f),FR(func_aget(x,j)))); } else { func_aset(g,j,func_diff(FR(f),func_var1(j,1))); } } } x=func_del(x); h=func_del(h); return g; }
void func_add_args_collect(func_t *f, func_is_t *fis) { int i,j; func_t *g=NULL; if(!func_is_add(f)){ FUNC_ERROR_ARG1("func_add_args_collect",f); } // convert args to split list for(i=0; i<func_asize(f); i++){ g=func_mul_split_list(FR(func_aget(f,i)),fis); func_aset(f,i,FR(g)); g=func_del(g); } // add a arg to same arg for(i=0; i<func_asize(f); i++){ for(j=i+1; func_aget(f,i)!=NULL && !func_is_one(func_aget(func_aget(f,i),1)) && j<func_asize(f); j++){ if(func_aget(f,j)!=NULL && func_cmp(func_aget(func_aget(f,i),1),func_aget(func_aget(f,j),1))==0){ g=func_list(2); func_aset(g,0,func_add(FR(func_aget(func_aget(f,i),0)),FR(func_aget(func_aget(f,j),0)))); func_aset(g,1,FR(func_aget(func_aget(f,i),1))); func_aset(f,i,FR(g)); func_adel(f,j); g=func_del(g); } } } // convert list to mul for(i=0; i<func_asize(f); i++){ if(func_aget(f,i)!=NULL){ g=func_mul(FR(func_aget(func_aget(f,i),0)),FR(func_aget(func_aget(f,i),1))); func_aset(f,i,FR(g)); g=func_del(g); } } func_a_rm_null(f); }
//h={q,r} func_t *func_poly_div_r_and_q(func_t *f, func_t *g) { func_t *h=NULL; h=func_list(2); h->a[0]=func_poly_div_q(FR(f),FR(g)); h->a[1]=func_poly_div_r(FR(f),FR(g)); f=func_del(f); g=func_del(g); return h; }
func_t *func_diff_list(func_t *f, int var) { int i; func_t *fx=NULL; if(!func_is_list(f)){ FUNC_ERROR_ARG1("func_diff_list",f); } fx=func_list(func_asize(f)); for(i=0; i<func_asize(f); i++){ fx->a[i]=func_diff(FR(f->a[i]),func_var1(var,1)); } f=func_del(f); return fx; }
func_t *func_expand_list(func_t *f) { int i; func_t *g=NULL; if(func_is_list(f)){ g=func_list(func_asize(f)); for(i=0; i<func_asize(f); i++){ g->a[i]=func_expand(FR(f->a[i])); } }else{ FUNC_ERROR_ARG1("func_expand_list",f); } f=func_del(f); return g; }
func_t *func_def_any_eval(func_t *f) { int i; func_t *g=NULL,*x=NULL; g=func_scope_find(0,func_op(f)); if(func_is_def(g) && func_aget(g,0)!=NULL){ g=FR(func_aget(g,0)); if(func_asize(f)>0){ x=func_list(func_asize(f)); for(i=0; i<func_asize(f); i++){ func_aset(x,i,FR(func_aget(f,i))); } g=func_maps(g,0,FR(x)); } f=func_del(f); }else{ g=f; } x=func_del(x); return g; }
Message Daemon::execute_command(const Message &msg) { if (!msg.Payload().size()) return Message(MessageType::Exception, "Unknown operation", msg); char command[MESSAGE_SIZE] = { 0 }; int arg_cnt; char * arg_val[MESSAGE_SIZE] = { NULL }; strcpy(command, msg.Payload().c_str()); arg_cnt = parse(command, arg_val); if (strcasecmp(command, "put") == 0) return func_put(arg_cnt, arg_val, msg); if (strcasecmp(command, "get") == 0) return func_get(arg_cnt, arg_val, msg); if (strcasecmp(command, "remove") == 0) return func_remove(arg_cnt, arg_val, msg); if (strcasecmp(command, "list") == 0) return func_list(arg_cnt, arg_val, msg); return Message(MessageType::Exception, "Unknown operation", msg); }
int Compiler::compile(bool compileOnly) { llvm::Target const *Target = NULL; llvm::TargetData *TD = NULL; llvm::TargetMachine *TM = NULL; std::string FeaturesStr; llvm::NamedMDNode const *PragmaMetadata; llvm::NamedMDNode const *ExportVarMetadata; llvm::NamedMDNode const *ExportFuncMetadata; llvm::NamedMDNode const *ObjectSlotMetadata; if (mModule == NULL) // No module was loaded return 0; // Create TargetMachine Target = llvm::TargetRegistry::lookupTarget(Triple, mError); if (hasError()) goto on_bcc_compile_error; if (!CPU.empty() || !Features.empty()) { llvm::SubtargetFeatures F; for (std::vector<std::string>::const_iterator I = Features.begin(), E = Features.end(); I != E; I++) { F.AddFeature(*I); } FeaturesStr = F.getString(); } #if defined(DEFAULT_X86_64_CODEGEN) // Data address in X86_64 architecture may reside in a far-away place TM = Target->createTargetMachine(Triple, CPU, FeaturesStr, llvm::Reloc::Static, llvm::CodeModel::Medium); #else // This is set for the linker (specify how large of the virtual addresses // we can access for all unknown symbols.) TM = Target->createTargetMachine(Triple, CPU, FeaturesStr, llvm::Reloc::Static, llvm::CodeModel::Small); #endif if (TM == NULL) { setError("Failed to create target machine implementation for the" " specified triple '" + Triple + "'"); goto on_bcc_compile_error; } // Get target data from Module TD = new llvm::TargetData(mModule); // Load named metadata ExportVarMetadata = mModule->getNamedMetadata(ExportVarMetadataName); ExportFuncMetadata = mModule->getNamedMetadata(ExportFuncMetadataName); PragmaMetadata = mModule->getNamedMetadata(PragmaMetadataName); ObjectSlotMetadata = mModule->getNamedMetadata(ObjectSlotMetadataName); // Perform link-time optimization if we have multiple modules if (mHasLinked) { runLTO(new llvm::TargetData(*TD), ExportVarMetadata, ExportFuncMetadata); } // Perform code generation #if USE_OLD_JIT if (runCodeGen(new llvm::TargetData(*TD), TM, ExportVarMetadata, ExportFuncMetadata) != 0) { goto on_bcc_compile_error; } #endif #if USE_MCJIT if (runMCCodeGen(new llvm::TargetData(*TD), TM) != 0) { goto on_bcc_compile_error; } if (compileOnly) return 0; // Load the ELF Object mRSExecutable = rsloaderCreateExec((unsigned char *)&*mEmittedELFExecutable.begin(), mEmittedELFExecutable.size(), &resolveSymbolAdapter, this); if (!mRSExecutable) { setError("Fail to load emitted ELF relocatable file"); goto on_bcc_compile_error; } if (ExportVarMetadata) { ScriptCompiled::ExportVarList &varList = mpResult->mExportVars; std::vector<std::string> &varNameList = mpResult->mExportVarsName; for (int i = 0, e = ExportVarMetadata->getNumOperands(); i != e; i++) { llvm::MDNode *ExportVar = ExportVarMetadata->getOperand(i); if (ExportVar != NULL && ExportVar->getNumOperands() > 1) { llvm::Value *ExportVarNameMDS = ExportVar->getOperand(0); if (ExportVarNameMDS->getValueID() == llvm::Value::MDStringVal) { llvm::StringRef ExportVarName = static_cast<llvm::MDString*>(ExportVarNameMDS)->getString(); varList.push_back( rsloaderGetSymbolAddress(mRSExecutable, ExportVarName.str().c_str())); varNameList.push_back(ExportVarName.str()); #if DEBUG_MCJIT_REFLECT LOGD("runMCCodeGen(): Exported Var: %s @ %p\n", ExportVarName.str().c_str(), varList.back()); #endif continue; } } varList.push_back(NULL); } } if (ExportFuncMetadata) { ScriptCompiled::ExportFuncList &funcList = mpResult->mExportFuncs; std::vector<std::string> &funcNameList = mpResult->mExportFuncsName; for (int i = 0, e = ExportFuncMetadata->getNumOperands(); i != e; i++) { llvm::MDNode *ExportFunc = ExportFuncMetadata->getOperand(i); if (ExportFunc != NULL && ExportFunc->getNumOperands() > 0) { llvm::Value *ExportFuncNameMDS = ExportFunc->getOperand(0); if (ExportFuncNameMDS->getValueID() == llvm::Value::MDStringVal) { llvm::StringRef ExportFuncName = static_cast<llvm::MDString*>(ExportFuncNameMDS)->getString(); funcList.push_back( rsloaderGetSymbolAddress(mRSExecutable, ExportFuncName.str().c_str())); funcNameList.push_back(ExportFuncName.str()); #if DEBUG_MCJIT_RELECT LOGD("runMCCodeGen(): Exported Func: %s @ %p\n", ExportFuncName.str().c_str(), funcList.back()); #endif } } } } #if DEBUG_MCJIT_DISASSEMBLER { // Get MC codegen emitted function name list size_t func_list_size = rsloaderGetFuncCount(mRSExecutable); std::vector<char const *> func_list(func_list_size, NULL); rsloaderGetFuncNameList(mRSExecutable, func_list_size, &*func_list.begin()); // Disassemble each function for (size_t i = 0; i < func_list_size; ++i) { void *func = rsloaderGetSymbolAddress(mRSExecutable, func_list[i]); if (func) { size_t size = rsloaderGetSymbolSize(mRSExecutable, func_list[i]); Disassemble(DEBUG_MCJIT_DISASSEMBLER_FILE, Target, TM, func_list[i], (unsigned char const *)func, size); } } } #endif #endif // Read pragma information from the metadata node of the module. if (PragmaMetadata) { ScriptCompiled::PragmaList &pragmaList = mpResult->mPragmas; for (int i = 0, e = PragmaMetadata->getNumOperands(); i != e; i++) { llvm::MDNode *Pragma = PragmaMetadata->getOperand(i); if (Pragma != NULL && Pragma->getNumOperands() == 2 /* should have exactly 2 operands */) { llvm::Value *PragmaNameMDS = Pragma->getOperand(0); llvm::Value *PragmaValueMDS = Pragma->getOperand(1); if ((PragmaNameMDS->getValueID() == llvm::Value::MDStringVal) && (PragmaValueMDS->getValueID() == llvm::Value::MDStringVal)) { llvm::StringRef PragmaName = static_cast<llvm::MDString*>(PragmaNameMDS)->getString(); llvm::StringRef PragmaValue = static_cast<llvm::MDString*>(PragmaValueMDS)->getString(); pragmaList.push_back( std::make_pair(std::string(PragmaName.data(), PragmaName.size()), std::string(PragmaValue.data(), PragmaValue.size()))); #if DEBUG_BCC_REFLECT LOGD("compile(): Pragma: %s -> %s\n", pragmaList.back().first.c_str(), pragmaList.back().second.c_str()); #endif } } } } if (ObjectSlotMetadata) { ScriptCompiled::ObjectSlotList &objectSlotList = mpResult->mObjectSlots; for (int i = 0, e = ObjectSlotMetadata->getNumOperands(); i != e; i++) { llvm::MDNode *ObjectSlot = ObjectSlotMetadata->getOperand(i); if (ObjectSlot != NULL && ObjectSlot->getNumOperands() == 1) { llvm::Value *SlotMDS = ObjectSlot->getOperand(0); if (SlotMDS->getValueID() == llvm::Value::MDStringVal) { llvm::StringRef Slot = static_cast<llvm::MDString*>(SlotMDS)->getString(); uint32_t USlot = 0; if (Slot.getAsInteger(10, USlot)) { setError("Non-integer object slot value '" + Slot.str() + "'"); goto on_bcc_compile_error; } objectSlotList.push_back(USlot); #if DEBUG_BCC_REFLECT LOGD("compile(): RefCount Slot: %s @ %u\n", Slot.str().c_str(), USlot); #endif } } } } on_bcc_compile_error: // LOGE("on_bcc_compiler_error"); if (TD) { delete TD; } if (TM) { delete TM; } if (mError.empty()) { return 0; } // LOGE(getErrorMessage()); return 1; }
/****************************************************************************** * * * Function: load_modules * * * * Purpose: load loadable modules (dynamic libraries) * * It skips a module in case of any errors * * * * Parameters: path - directory where modules are located * * file_names - list of module names * * timeout - timeout in seconds for processing of items by module * * verbose - output list of loaded modules * * * * Return value: SUCCEED - all modules is successfully loaded * * FAIL - loading of modules failed * * * ******************************************************************************/ int load_modules(const char *path, char **file_names, int timeout, int verbose) { const char *__function_name = "load_modules"; char **file_name, *buffer = NULL; void *lib; char full_name[MAX_STRING_LEN], error[MAX_STRING_LEN]; int (*func_init)(), (*func_version)(); ZBX_METRIC *(*func_list)(); void (*func_timeout)(); int i, ret = FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); for (file_name = file_names; NULL != *file_name; file_name++) { zbx_snprintf(full_name, sizeof(full_name), "%s/%s", path, *file_name); zabbix_log(LOG_LEVEL_DEBUG, "loading module \"%s\"", full_name); if (NULL == (lib = dlopen(full_name, RTLD_NOW))) { zabbix_log(LOG_LEVEL_CRIT, "cannot load module \"%s\": %s", *file_name, dlerror()); goto fail; } *(void **)(&func_version) = dlsym(lib, ZBX_MODULE_FUNC_API_VERSION); if (NULL == func_version) { zabbix_log(LOG_LEVEL_CRIT, "cannot find \"" ZBX_MODULE_FUNC_API_VERSION "()\"" " function in module \"%s\": %s", *file_name, dlerror()); dlclose(lib); goto fail; } if (ZBX_MODULE_API_VERSION_ONE != (i = func_version())) { zabbix_log(LOG_LEVEL_CRIT, "unsupported module \"%s\" version: %d", *file_name, i); dlclose(lib); goto fail; } *(void **)(&func_init) = dlsym(lib, ZBX_MODULE_FUNC_INIT); if (NULL == func_init) { zabbix_log(LOG_LEVEL_CRIT, "cannot find \"" ZBX_MODULE_FUNC_INIT "()\"" " function in module \"%s\": %s", *file_name, dlerror()); dlclose(lib); goto fail; } if (ZBX_MODULE_OK != func_init()) { zabbix_log(LOG_LEVEL_CRIT, "cannot initialize module \"%s\"", *file_name); dlclose(lib); goto fail; } /* the function is optional, zabbix will load the module ieven if it is missing */ *(void **)(&func_timeout) = dlsym(lib, ZBX_MODULE_FUNC_ITEM_TIMEOUT); if (NULL == func_timeout) { zabbix_log(LOG_LEVEL_DEBUG, "cannot find \"" ZBX_MODULE_FUNC_ITEM_TIMEOUT "()\"" " function in module \"%s\": %s", *file_name, dlerror()); } else func_timeout(timeout); *(void **)(&func_list) = dlsym(lib, ZBX_MODULE_FUNC_ITEM_LIST); if (NULL == func_list) { zabbix_log(LOG_LEVEL_WARNING, "cannot find \"" ZBX_MODULE_FUNC_ITEM_LIST "()\"" " function in module \"%s\": %s", *file_name, dlerror()); dlclose(lib); continue; } if (SUCCEED == register_module(lib)) { ZBX_METRIC *metrics; metrics = func_list(); for (i = 0; NULL != metrics[i].key; i++) { /* accept only CF_HAVEPARAMS flag from module items */ metrics[i].flags &= CF_HAVEPARAMS; /* the flag means that the items comes from a loadable module */ metrics[i].flags |= CF_MODULE; if (SUCCEED != add_metric(&metrics[i], error, sizeof(error))) { zabbix_log(LOG_LEVEL_CRIT, "cannot load module \"%s\": %s", *file_name, error); exit(EXIT_FAILURE); } } if (1 == verbose) { if (NULL != buffer) buffer = zbx_strdcat(buffer, ", "); buffer = zbx_strdcat(buffer, *file_name); } } } if (NULL != buffer) zabbix_log(LOG_LEVEL_WARNING, "loaded modules: %s", buffer); ret = SUCCEED; fail: zbx_free(buffer); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
int main(int argc, char *argv[]) { void (*OldSig)(int); OldSig=signal(SIGINT,SIG_IGN); printf("nn************************************************************rn"); printf("* zFTP *rn"); printf("************************************************************rn"); printf(" Copyright (c) 2005rn"); printf(" All rights reserved.rn"); printf(" By Ji Surn"); if(argc > 0) { printf("nPlease use 'connect <system name> <user>' command to connect to a FTPserverrn"); printf("For anonymous user, please leave <user> blank.rn"); } //Main loop starts; //Checks on keyboard i/o for interaction and socket communication. int exit=0; char command[1024]; printf("nzftp>"); while(!exit) { if( ReadCommand ) { printf("nzftp>"); fflush(stdout); } if( !CheckFds(command) ) continue; switch(check_cmd(command) ) { case READ: func_read(command); break; case WRITE: func_write(command); break; case BINARY: func_binary_mode(); break; case ASCII: func_ascii_mode(); break; case CLOSE: func_close(); break; case CONNECT: func_connect(command); break; case CD: func_cdir(command); break; case DELETE: func_delete(command); break; case PWD: func_pwd(command); break; case LS: func_list(command); break; case HELP: func_help(command); break; case SHELL: func_Shell_cmd(command); break; case EXIT: exit = 1; if( flag_connected ) func_close(); break; default: if(command[0] == 0 ) ; else printf("Invalid command: %sn",command); break; } } (void)signal(SIGINT,OldSig); return 0; }