Ejemplo n.º 1
0
bool BlackMakeMoveFirstTest()
{
	char* moduleName = getModule();
	char board[BUFFER_SIZE+1];
	board[BUFFER_SIZE]='\0'; // <---- might be redundant but i cant leave it like that! it's a disturbia
	int a;
	int b;
	int status;
	int pid1 = fork();
	if(pid1 == 0) {
		//player 1 (white)
		char nextMove = DOWN;
		a=open(moduleName, O_RDWR);
		ASSERT(a>=0);

		doLongTask();
		doLongTask();

		int writeval = write(a, &nextMove, 1);	
		//ASSERT(writeval == 1);

		//board after move
		int readRes = read(a, board, BUFFER_SIZE);
		printf("\n\n[readRes=%d, BUFFER_SIZE=%d]\n\n", readRes, BUFFER_SIZE);
		ASSERT(readRes == BUFFER_SIZE);
		printf("board after move is:\n");
		printBoard(board);

		doLongTask();
		close(a);
		_exit(0);
	} else {
		int pid2 = fork();
		if(pid2 == 0) {
			char nextMove = UP;
			doLongTask();
			//player 2 (black)
			b=open(moduleName, O_RDWR); 
			ASSERT(b>=0);

			int writeval = write(b, &nextMove, 1);	
			//ASSERT(writeval == 1);

			doLongTask();
			close(b);
			_exit(0);
		} else {
			wait(&status);
		}
		wait(&status);
	}	
    return true;
}
Ejemplo n.º 2
0
llvm::Function* Array::getReallocFunc()
{
	if (auto func = getModule()->getFunction("ext_realloc"))
		return func;

	llvm::Type* reallocArgTypes[] = {Type::BytePtr, Type::Size};
	auto reallocFunc = llvm::Function::Create(llvm::FunctionType::get(Type::BytePtr, reallocArgTypes, false), llvm::Function::ExternalLinkage, "ext_realloc", getModule());
	reallocFunc->setDoesNotThrow();
	reallocFunc->setDoesNotAlias(0);
	reallocFunc->setDoesNotCapture(1);
	return reallocFunc;
}
bool DroidObjectImplementation::sendConversationStartTo(SceneObject* player) {
	if (!player->isPlayerCreature() || isDead())
		return false;

	BaseDroidModuleComponent* m = getModule("personality_chip");
	if (m == NULL) {
		return false;
	}

	DroidPersonalityModuleDataComponent* personality = dynamic_cast<DroidPersonalityModuleDataComponent*>(m);
	if (personality == NULL) {
		return false;
	}

	if (personality->getPersonalityConversationTemplate() == 0) {
		return false;
	}

	//Face player.
	faceObject(player);

	PatrolPoint current(coordinates.getPosition(), getParent().get());

	broadcastNextPositionUpdate(&current);

	CreatureObject* playerCreature = cast<CreatureObject*>( player);
	StartNpcConversation* conv = new StartNpcConversation(playerCreature, getObjectID(), "");
	player->sendMessage(conv);

	SortedVector<ManagedReference<Observer*> > observers = getObservers(ObserverEventType::STARTCONVERSATION);

	for (int i = 0;  i < observers.size(); ++i) {
		if (dynamic_cast<ConversationObserver*>(observers.get(i).get()) != NULL) {
			return true;
		}
	}
	//Create conversation observer.
	ConversationObserver* conversationObserver = ConversationManager::instance()->getConversationObserver(personality->getPersonalityConversationTemplate());

	if (conversationObserver != NULL) {
		//Register observers.
		registerObserver(ObserverEventType::CONVERSE, conversationObserver);
		registerObserver(ObserverEventType::STARTCONVERSATION, conversationObserver);
		registerObserver(ObserverEventType::SELECTCONVERSATION, conversationObserver);
		registerObserver(ObserverEventType::STOPCONVERSATION, conversationObserver);
	} else {
		error("Could not create conversation observer.");
		return false;
	}

	return true;
}
Ejemplo n.º 4
0
 /** Changes the current module and test element. If they don't
  *  exist, the function creates them and adds them to their respective 
  *  lists.
  *  \param[in] mod name of the module
  *  \param[in] ele name of the element
  */
 void 
 CRL_ErrReport::START(const char* mod, const char* ele)
 {
   std::string moduleName = std::string(mod); 
   currentModule = getModule(moduleName);
   if (currentModule == NULL)               
     currentModule = addModule(moduleName);
   
   std::string fctName = std::string(ele);   
   currentElement = currentModule->getElement(fctName);
   if (currentElement == NULL)  
     currentElement = currentModule->addElement(fctName);
 }
Ejemplo n.º 5
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void
LuaType::addMethod(const std::string& _name, const std::string& _docString, Scripting::I_ScriptMethod* _function)
{
    unsigned item = sm_methodItem++;

    std::cout << "Adding method " << item << ": " << _name << " to class " << m_name << " in module "
            << getModule().getName() << std::endl;


    (*sm_methodTable[item].m_ppMethod) = new LuaMethod(this, _name, _docString, _function, sm_methodTable[item].m_cFunction);

    m_methods.push_back(*sm_methodTable[item].m_ppMethod);
}
void ModuleManagerWithDebug::modulesStore(std::ostream& outstream)
{
  naoth::Configuration& config = naoth::Platform::getInstance().theConfiguration;
  for(std::list<std::string>::const_iterator name=getExecutionList().begin();
    name != getExecutionList().end(); name++)
  {
    config.setBool("modules", *name, getModule(*name)->isEnabled());
  }//end for

  // write the config to file
  config.save();
  outstream << "modules saved to private/modules.cfg" << std::endl;
}//end modulesStore
Ejemplo n.º 7
0
Archivo: dsymbol.c Proyecto: olgk/ldc
char *Dsymbol::locToChars()
{
    OutBuffer buf;

    if (!loc.filename)  // avoid bug 5861.
    {
        Module *m = getModule();

        if (m && m->srcfile)
            loc.filename = m->srcfile->toChars();
    }
    return loc.toChars();
}
Ejemplo n.º 8
0
    Model &Backend::getModel(std::string name)
    {
        if (!models.count(name)) {
            if (modules.count(name)) {
                Model model = loadModelSTL_string(getModule(name)->openscad("stl"));
                models[name] = model;
            } else {
                models[name] = Model();
            }
        }

        return models[name];
    }
Ejemplo n.º 9
0
Value* IRCompiler::compileAddition(KT_Addition *add) {
	debug("compiling a KT_Addition");

	Value* vl = compileExpression(add->getLExpression());
	Value* vg = compileExpression(add->getRExpression());

	vl = BasicInstructionGenerator::stripVal(vl, getCurrentBlock());
	vg = BasicInstructionGenerator::stripVal(vg, getCurrentBlock());

	Type *t = PrimitiveValueConverter::dominatingType(vl->getType(), vg->getType());

	return PrimitiveBinaryOperationGenerator::createAdd(getModule(), t, vl, vg, getCurrentBlock());
}
Ejemplo n.º 10
0
/**
* This function is called
**/
void traceInst(INS ins, VOID*)
{
    ADDRINT address = INS_Address(ins);

    std::string mod_name = getModule( address );
    RegList regs;

    for ( UINT32 i = 0; i < INS_OperandCount(ins); i++ )
    {
        if ( INS_OperandIsReg(ins, i) )
        {
            REG x = INS_OperandReg(ins, i);
            if ( x != REG_INVALID() )
                regs.push_back( x );
        }
    }

    if (isUnknownAddress(address))
    {
        // The address is an address that does not belong to any loaded module.
        // This is potential shellcode. For these instructions a callback
        // function is inserted that dumps information to the trace file when
        // the instruction is actually executed.

        INS_InsertCall(ins, IPOINT_BEFORE, AFUNPTR(dump_shellcode),
                       IARG_PTR, new std::string(dumpInstruction(ins)),
                       IARG_PTR, &regs,
                       IARG_CONTEXT, IARG_END
            );
    }
    else
    {
        if ( !modlist.empty() && (modlist.find(mod_name) == modlist.end()) ) // not concerned
            return;

        // The address is a legit address, meaning it is probably not part of
        // any shellcode. In this case we just log the instruction to dump it
        // later to show when control flow was transfered from legit code to
        // shellcode.

        legitInstructions.push_back(dumpInstruction(ins));

        if (legitInstructions.size() > KnobMaxLegitInsLogSize.Value())
        {
            // Log only up to KnobMaxLegitInsLogSize.Value() instructions or the whole
            // program before the shellcode will be dumped.

            legitInstructions.pop_front();
        }
    }
}
Ejemplo n.º 11
0
 void visitIf(If* curr) {
   // if the condition is a constant, just apply it
   // we can just return the ifTrue or ifFalse.
   if (auto* value = curr->condition->dynCast<Const>()) {
     if (value->value.getInteger()) {
       replaceCurrent(curr->ifTrue);
       return;
     } else {
       if (curr->ifFalse) {
         replaceCurrent(curr->ifFalse);
       } else {
         ExpressionManipulator::nop(curr);
       }
       return;
     }
   }
   if (curr->ifFalse) {
     if (curr->ifFalse->is<Nop>()) {
       curr->ifFalse = nullptr;
     } else if (curr->ifTrue->is<Nop>()) {
       curr->ifTrue = curr->ifFalse;
       curr->ifFalse = nullptr;
       curr->condition = Builder(*getModule()).makeUnary(EqZInt32, curr->condition);
     } else if (curr->ifTrue->is<Drop>() && curr->ifFalse->is<Drop>()) {
       // instead of dropping both sides, drop the if
       curr->ifTrue = curr->ifTrue->cast<Drop>()->value;
       curr->ifFalse = curr->ifFalse->cast<Drop>()->value;
       curr->finalize();
       replaceCurrent(Builder(*getModule()).makeDrop(curr));
     }
   } else {
     // no else
     if (curr->ifTrue->is<Nop>()) {
       // no nothing
       replaceCurrent(Builder(*getModule()).makeDrop(curr->condition));
     }
   }
 }
Ejemplo n.º 12
0
 void visitStore(Store* curr) {
   if (isDead(curr->ptr)) {
     replaceCurrent(curr->ptr);
     return;
   }
   if (isDead(curr->value)) {
     auto* block = getModule()->allocator.alloc<Block>();
     block->list.resize(2);
     block->list[0] = curr->ptr;
     block->list[1] = curr->value;
     block->finalize();
     replaceCurrent(block);
   }
 }
Ejemplo n.º 13
0
void GasMeter::countExp(llvm::Value* _exponent)
{
	// Additional cost is 1 per significant byte of exponent
	// lz - leading zeros
	// cost = ((256 - lz) + 7) / 8

	// OPT: Can gas update be done in exp algorithm?
	auto ctlz = llvm::Intrinsic::getDeclaration(getModule(), llvm::Intrinsic::ctlz, Type::Word);
	auto lz256 = m_builder.CreateCall(ctlz, {_exponent, m_builder.getInt1(false)});
	auto lz = m_builder.CreateTrunc(lz256, Type::Gas, "lz");
	auto sigBits = m_builder.CreateSub(m_builder.getInt64(256), lz, "sigBits");
	auto sigBytes = m_builder.CreateUDiv(m_builder.CreateAdd(sigBits, m_builder.getInt64(7)), m_builder.getInt64(8));
	count(m_builder.CreateNUWMul(sigBytes, m_builder.getInt64(c_expByteGas)));
}
Ejemplo n.º 14
0
void FunctionSym::callers( WVList & list )
//----------------------------------------
{
    int i;

    getModule()->findRefSyms( &list, this );

    for( i = 0; i < list.count(); i += 1 ) {
        Symbol * sym = (Symbol *) list[ i ];
        if( sym->symtype() != DR_SYM_FUNCTION ) {
            list.removeAt( i );
        }
    }
}
Ejemplo n.º 15
0
bool MakeMoveCrashWallTest()
{
	char* moduleName = getModule();
	char board[BUFFER_SIZE+1];
	board[BUFFER_SIZE]='\0'; // <---- might be redundant but i cant leave it like that! it's a disturbia
	char nextMove = UP;
	int a;
	int b;
	int status;
	int pid1 = fork();
	if(pid1 == 0) {
		//player 1 (white)
		a=open(moduleName, O_RDWR);
		ASSERT(a>=0);

		//board before
		int readRes = read(a, board, BUFFER_SIZE);	
		ASSERT(readRes == BUFFER_SIZE);

		int writeval = write(a, &nextMove, 1);
		printf("\n\n[writeval=%d, should be=1]\n\n", writeval);
		//ASSERT(writeval == 1); // <---- should be 1 according to the metargelim

		//board after illigal move
		readRes = read(a, board, BUFFER_SIZE);	
		ASSERT(readRes == BUFFER_SIZE); // <---- should success according to the metargelim even if the game over

		doLongTask();
		close(a);
		_exit(0);
	} else {
		int pid2 = fork();
		if(pid2 == 0) {
			doLongTask();
			//player 2 (black)
			b=open(moduleName, O_RDWR); 
			ASSERT(b>=0);

			doLongTask();
			doLongTask();
			doLongTask();
			close(b);
			_exit(0);
		} else {
			wait(&status);
		}
		wait(&status);
	}	
    return true;
}
Ejemplo n.º 16
0
 void visitBinary(Binary* curr) {
   if (isDead(curr->left)) {
     replaceCurrent(curr->left);
     return;
   }
   if (isDead(curr->right)) {
     auto* block = getModule()->allocator.alloc<Block>();
     block->list.resize(2);
     block->list[0] = curr->left;
     block->list[1] = curr->right;
     block->finalize();
     replaceCurrent(block);
   }
 }
Ejemplo n.º 17
0
 void visitExpression(Expression* curr) {
   if (curr->is<Const>()) return;
   // try to evaluate this into a const
   Flow flow;
   try {
     flow = StandaloneExpressionRunner().visit(curr);
   } catch (StandaloneExpressionRunner::NonstandaloneException& e) {
     return;
   }
   if (flow.breaking()) return; // TODO: can create a break as a replacement in some cases (not NONSTANDALONE)
   if (isConcreteWasmType(flow.value.type)) {
     replaceCurrent(Builder(*getModule()).makeConst(flow.value));
   }
 }
Ejemplo n.º 18
0
int AggregateDeclaration::hasPrivateAccess(Dsymbol *smember)
{
    if (smember)
    {   AggregateDeclaration *cd = NULL;
        Dsymbol *smemberparent = smember->toParent();
        if (smemberparent)
            cd = smemberparent->isAggregateDeclaration();

#if LOG
        printf("AggregateDeclaration::hasPrivateAccess(class %s, member %s)\n",
                toChars(), smember->toChars());
#endif

        if (this == cd)         // smember is a member of this class
        {
#if LOG
            printf("\tyes 1\n");
#endif
            return 1;           // so we get private access
        }

        // If both are members of the same module, grant access
        while (1)
        {   Dsymbol *sp = smember->toParent();
            if (sp->isFuncDeclaration() && smember->isFuncDeclaration())
                smember = sp;
            else
                break;
        }
        if (!cd && toParent() == smember->toParent())
        {
#if LOG
            printf("\tyes 2\n");
#endif
            return 1;
        }
        if (!cd && getModule() == smember->getModule())
        {
#if LOG
            printf("\tyes 3\n");
#endif
            return 1;
        }
    }
#if LOG
    printf("\tno\n");
#endif
    return 0;
}
Ejemplo n.º 19
0
static Pothos::Object blockRegistryMake(const std::string &path, const Pothos::Object *args, const size_t numArgs)
{
    const auto pluginPath = Pothos::PluginPath("/blocks").join(path.substr(1));
    const auto plugin = Pothos::PluginRegistry::get(pluginPath);
    const auto factory = plugin.getObject().extract<Pothos::Callable>();

    if (factory.type(-1) == typeid(Pothos::Block*))
    {
        auto element = factory.opaqueCall(args, numArgs).extract<Pothos::Block *>();
        if (element->getName().empty()) element->setName(path); //a better name
        element->holdRef(Pothos::Object(plugin.getModule()));
        return Pothos::Object(std::shared_ptr<Pothos::Block>(element));
    }

    if (factory.type(-1) == typeid(Pothos::Topology*))
    {
        auto element = factory.opaqueCall(args, numArgs).extract<Pothos::Topology *>();
        if (element->getName().empty()) element->setName(path); //a better name
        element->holdRef(Pothos::Object(plugin.getModule()));
        return Pothos::Object(std::shared_ptr<Pothos::Topology>(element));
    }

    throw Pothos::IllegalStateException("Pothos::BlockRegistry::make("+path+")", factory.toString());
}
Ejemplo n.º 20
0
void
ReplicationManager::onInsertedDataObject(Event *e) 
{
    if (getState() > MANAGER_STATE_RUNNING) {
        HAGGLE_DBG("In shutdown, ignoring send data object fail results\n");
        return;
    }

    if (!e || !e->hasData()) {
        return;
    }

    DataObjectRef& dObj = e->getDataObject();
    getModule()->notifyInsertDataObject(dObj);
}
Ejemplo n.º 21
0
 void visitStore(Store* curr) {
   if (ExpressionAnalyzer::isResultUsed(expressionStack, getFunction())) {
     Index index = getFunction()->getNumLocals();
     getFunction()->vars.emplace_back(curr->type);
     Builder builder(*getModule());
     replaceCurrent(builder.makeSequence(
       builder.makeSequence(
         builder.makeSetLocal(index, curr->value),
         curr
       ),
       builder.makeGetLocal(index, curr->type)
     ));
     curr->value = builder.makeGetLocal(index, curr->type);
   }
 }
Ejemplo n.º 22
0
Archivo: dsymbol.c Proyecto: olgk/ldc
void Dsymbol::error(const char *format, ...)
{
    //printf("Dsymbol::error()\n");
    if (!loc.filename)  // avoid bug 5861.
    {
        Module *m = getModule();

        if (m && m->srcfile)
            loc.filename = m->srcfile->toChars();
    }
    va_list ap;
    va_start(ap, format);
    verror(loc, format, ap);
    va_end(ap);
}
Ejemplo n.º 23
0
void QtApp::handleApplicationQuit() {
    PyScopedGIL gil;

    printf("about to quit ...\n");

    PyObject* guiMod = getModule("gui"); // borrowed
    if(!guiMod) {
        printf("QtApp::handleApplicationQuit: gui module not found");
        return;
    }

    PyObject* ret = PyObject_CallMethod(guiMod, (char*)"handleApplicationQuit", NULL);
    if(!ret && PyErr_Occurred()) PyErr_Print();
    Py_XDECREF(ret);
}
Ejemplo n.º 24
0
void MirandaSkinnedDialog::getSettting(const char *name, const char *defVal, std::string &ret, bool global)
{
	char setting[SETTING_NAME_SIZE];
	getSettingName(setting, name, global);

	DBVARIANT dbv = {0};
	if (DBGetContactSettingString(NULL, getModule(), setting, &dbv))
	{
		ret = defVal;
		return;
	}

	ret = dbv.pszVal;
	DBFreeVariant(&dbv);
}
Ejemplo n.º 25
0
/*
 * Searching the scope structure.
 * Finding a scope is unrestricted. For modules we explicitly look for
 * the start of a new module scope.
 * All core modules are accessed through the jumptable.
 * The 'user' module is an alias for the scope attached
 * to the current user.
 */
Module findModule(Module scope, str name){
	Module def = scope;
	Module m;
	if (name == NULL) return scope;

#ifdef _DEBUG_MODULE_
	fprintf(stderr,"Locate module %s in scope %s\n", name,scope->name);
#endif
	m = getModule(name);
	if (m) return m;

	/* default is always matched with current */
	if (def->name == NULL) return NULL;
	return def;
}
Ejemplo n.º 26
0
bool ModuleManager::reloadModule(const std::string& id) {
	Module* module = getModule(id);

	Module::Type type = module->type;
	std::string file = module->file;
	std::map<std::string, std::string> params = module->params;

	unloadModule(module);
	if(type==Module::BINARY) {
		return loadModuleBinary(id, file, params);
	}
	else if(type==Module::SCRIPT) {
		return loadModuleScript(id, file, params);
	}
}
Ejemplo n.º 27
0
//**********************************************************************************************
//******************************           Операции генерации             **********************
        PolynomN6& PolynomN6::Generate()
        {
                _a1.Generate(getModule());
                _a2.Generate(getModule());
                _a3.Generate(getModule());
                _a4.Generate(getModule());
                _a5.Generate(getModule());
                _a6.Generate(getModule());
                return *this;
        }
Ejemplo n.º 28
0
ViewPtr<module::Module> Simulation::useModule(const String& nameSrc, String storePath)
{
    String name = nameSrc;

    // Find ':' in name - old definition
    auto pos = nameSrc.find(':');

    if (pos != String::npos)
    {
        name = nameSrc.substr(0, pos);
        storePath = nameSrc.substr(pos + 1);
    }

    if (storePath.empty())
        storePath = name;

    // Module exists, return the existing one
    if (hasModule(storePath))
        return getModule(storePath);

    Log::debug("Loading library: ", name);

    // Load only library
    Log::debug("Create module '", name, "'");

    // Create module with given name
    auto module = getPluginContext().createModule(name, *this);

    // Register module
    if (module)
    {
        if (storePath != name)
        {
            Log::info("Using module '", name, "' as '", storePath, "'");
        }
        else
        {
            Log::info("Using module '", name, "'");
        }

        return addModule(storePath, std::move(module));
    }

    Log::warning("Unable to create module '", name, "' (unsupported by library?)");

    return nullptr;
}
Ejemplo n.º 29
0
void
ReplicationManager::onDeletedDataObject(Event *e)
{
    if (getState() > MANAGER_STATE_RUNNING) {
        HAGGLE_DBG("In shutdown, ignoring send data object fail results\n");
        return;
    }

    if (!e || !e->hasData()) {
        return;
    }

    DataObjectRefList dObjs = e->getDataObjectList();
    for (DataObjectRefList::iterator it = dObjs.begin(); it != dObjs.end(); it++) {
        getModule()->notifyDeleteDataObject((*it));
    }
}
void DialogModuleFilterScalarInterp::OnOK() 
{
	// TODO: この位置にその他の検証用のコードを追加してください
	char	string[256];
	float	value1, value2;

	GetDlgItemText(IDC_VALUE1, string, 255);
	if (sscanf(string, "%f", &value1) == 1) {
		GetDlgItemText(IDC_VALUE2, string, 255);
		if (sscanf(string, "%f", &value2) == 1) {
			sprintf(string, "%g-%g", value1, value2);
			getModule()->setValue(string);
		}
	}
	
	CDialog::OnOK();
}