Exemplo n.º 1
0
ModulePtr loadProgram(const string &fileName, vector<string> *sourceFiles) {
    globalMainModule = parse("", loadFile(fileName, sourceFiles));
    ModulePtr prelude = loadPrelude(sourceFiles);
    loadDependents(globalMainModule, sourceFiles);
    installGlobals(globalMainModule);
    initModule(prelude);
    initModule(globalMainModule);
    return globalMainModule;
}
Exemplo n.º 2
0
Arquivo: loader.cpp Projeto: Blei/clay
ModulePtr loadProgram(llvm::StringRef fileName, vector<string> *sourceFiles, bool verbose, bool repl) {
    globalMainModule = parse("", loadFile(fileName, sourceFiles));
    ModulePtr prelude = loadPrelude(sourceFiles, verbose, repl);
    loadDependents(globalMainModule, sourceFiles, verbose);
    installGlobals(globalMainModule);
    initModule(prelude);
    initModule(globalMainModule);
    return globalMainModule;
}
Exemplo n.º 3
0
ModulePtr loadProgramSource(const string &name, const string &source) {
    globalMainModule = parse("", new Source(name,
        const_cast<char*>(source.c_str()),
        source.size())
    );
    // Don't keep track of source files for -e script
    ModulePtr prelude = loadPrelude(NULL);
    loadDependents(globalMainModule, NULL);
    installGlobals(globalMainModule);
    initModule(prelude);
    initModule(globalMainModule);
    return globalMainModule;
}
Exemplo n.º 4
0
// The "main" of the medusa module world - this is what gets called to actually do the work
int go(sLogin* logins, int argc, char *argv[])
{
  int i;
  char *strtok_ptr, *pOpt, *pOptTmp;
  _MODULE_DATA *psSessionData;
  psSessionData = malloc(sizeof(_MODULE_DATA));
  memset(psSessionData, 0, sizeof(_MODULE_DATA));

  if ( !(0 <= argc <= 2) )
  {
    // Show usage information
    writeError(ERR_ERROR, "%s: Incorrect number of parameters passed to module.", MODULE_NAME);
    return FAILURE;
  } 
  else 
  {
    // Parameters are good - make module go now
    writeError(ERR_DEBUG_MODULE, "OMG teh %s module has been called!!", MODULE_NAME);

    for (i=0; i<argc; i++) {
      pOptTmp = malloc( strlen(argv[i]) + 1);
      memset(pOptTmp, 0, strlen(argv[i]) + 1);
      strncpy(pOptTmp, argv[i], strlen(argv[i]));
      writeError(ERR_DEBUG_MODULE, "Processing complete option: %s", pOptTmp);
      pOpt = strtok_r(pOptTmp, ":", &strtok_ptr);
      writeError(ERR_DEBUG_MODULE, "Processing option: %s", pOpt);
      FREE(pOptTmp);
    }

    initModule(psSessionData, logins);
  }  

  FREE(psSessionData);
  return SUCCESS;
}
Exemplo n.º 5
0
int Script_init(const char* script)
{
	Py_Initialize();
	
	initModule();
  
    pName = PyString_FromString(script);
	
    if (!(pModule = PyImport_Import(pName)))
	{
        PyErr_Print();
		BREAK_ERROR;
	}
    pDict = PyModule_GetDict(pModule);

    pMain = PyDict_GetItemString(pDict, "main");
	
    if (!PyCallable_Check(pMain)) 
	{
        PyErr_Print();
		fprintf(stderr, "Could not find 'main' python function.\n");
		BREAK_ERROR;
    }
	
	return 0;
}
Exemplo n.º 6
0
void CDgnAppSupport::reloadPython()
{
	// free our reference to the Python modules
	Py_XDECREF( m_pNatLinkMain );

	// terminate the Python subsystem
	Py_Finalize();

	// load and initialize the Python system
	Py_Initialize();

	// load the natlink module into Python
	initModule();

	// load the Python code which does most of the work
	m_pDragCode->setDuringInit( TRUE );
	m_pNatLinkMain = PyImport_ImportModule( "natlinkmain" );
	m_pDragCode->setDuringInit( FALSE );
	
	if( m_pNatLinkMain == NULL )
	{
		OutputDebugString(
			"NatLink: an exception occurred loading 'natlinkmain' module" );
		m_pDragCode->displayText(
			"An exception occurred loading 'natlinkmain' module\r\n", TRUE );
		m_pDragCode->displayText(
			"No more error information is available\r\n", TRUE );
	}
}
Exemplo n.º 7
0
PyObject *
PyInit__rpm(void)
{
    PyObject * m;
    if (!prepareInitModule()) return NULL;
    m = PyModule_Create(&moduledef);
    initModule(m);
    return m;
}
Exemplo n.º 8
0
Arquivo: loader.cpp Projeto: Blei/clay
ModulePtr loadProgramSource(llvm::StringRef name, llvm::StringRef source, bool verbose, bool repl) {
    SourcePtr mainSource = new Source(name,
        llvm::MemoryBuffer::getMemBufferCopy(source));
    if (llvmDIBuilder != NULL) {
        mainSource->debugInfo = (llvm::MDNode*)llvmDIBuilder->createFile(
            "-e",
            "");
    }

    globalMainModule = parse("", mainSource);
    // Don't keep track of source files for -e script
    ModulePtr prelude = loadPrelude(NULL, verbose, repl);
    loadDependents(globalMainModule, NULL, verbose);
    installGlobals(globalMainModule);
    initModule(prelude);
    initModule(globalMainModule);
    return globalMainModule;
}
Exemplo n.º 9
0
void PinkEngine::changeScene() {
	setCursor(kLoadingCursor);
	_director->clear();

	if (!_nextModule.empty() && _nextModule != _module->getName())
		initModule(_nextModule, _nextPage, nullptr);
	else
		_module->changePage(_nextPage);
}
Exemplo n.º 10
0
/*
  Do any common preliminary work before python 2 vs python 3 module creation:
*/
static int prepareInitModule(void)
{
    return 1;
}

static int initModule(PyObject *m)
{
    return 1;
}

static PyMethodDef modMethods[] = {
    { "addSign", (PyCFunction) addSign, METH_VARARGS|METH_KEYWORDS, NULL },
    { "delSign", (PyCFunction) delSign, METH_VARARGS|METH_KEYWORDS, NULL },
    { NULL },
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {
    PyModuleDef_HEAD_INIT,
    "_rpms",     /* m_name */
    rpms__doc__, /* m_doc */
    0,           /* m_size */
    modMethods,  /* m_methods */
    NULL,        /* m_reload */
    NULL,        /* m_traverse */
    NULL,        /* m_clear */
    NULL         /* m_free */
};

PyObject * PyInit__rpms(void);	/* XXX eliminate gcc warning */
PyObject * PyInit__rpms(void)
{
    PyObject *m;

    if (!prepareInitModule())
        return NULL;
    m = PyModule_Create(&moduledef);
    if (m == NULL || !initModule(m)) {
        Py_XDECREF(m);
        m = NULL;
    }
    return m;
}
#else
void init_rpms(void);	/* XXX eliminate gcc warning */
void init_rpms(void)
{
    PyObject *m;
  
    if (!prepareInitModule())
        return;

    m = Py_InitModule3("_rpms", modMethods, rpms__doc__);
    if (m) initModule(m);
}
Exemplo n.º 11
0
/*
  Do any common preliminary work before python 2 vs python 3 module creation:
*/
static int prepareInitModule(void)
{
    if (PyType_Ready(&hdr_Type) < 0) return 0;
    if (PyType_Ready(&rpmarchive_Type) < 0) return 0;
    if (PyType_Ready(&rpmds_Type) < 0) return 0;
    if (PyType_Ready(&rpmfd_Type) < 0) return 0;
    if (PyType_Ready(&rpmfi_Type) < 0) return 0;
    if (PyType_Ready(&rpmfile_Type) < 0) return 0;
    if (PyType_Ready(&rpmfiles_Type) < 0) return 0;
    if (PyType_Ready(&rpmKeyring_Type) < 0) return 0;
    if (PyType_Ready(&rpmmi_Type) < 0) return 0;
    if (PyType_Ready(&rpmii_Type) < 0) return 0;
    if (PyType_Ready(&rpmProblem_Type) < 0) return 0;
    if (PyType_Ready(&rpmPubkey_Type) < 0) return 0;
    if (PyType_Ready(&rpmstrPool_Type) < 0) return 0;
#if 0
    if (PyType_Ready(&rpmtd_Type) < 0) return 0;
#endif
    if (PyType_Ready(&rpmte_Type) < 0) return 0;
    if (PyType_Ready(&rpmts_Type) < 0) return 0;

    return 1;
}
static int initModule(PyObject *m);

#if PY_MAJOR_VERSION >= 3
static int rpmModuleTraverse(PyObject *m, visitproc visit, void *arg) {
    Py_VISIT(pyrpmError);
    return 0;
}

static int rpmModuleClear(PyObject *m) {
    Py_CLEAR(pyrpmError);
    return 0;
}

static struct PyModuleDef moduledef = {
    PyModuleDef_HEAD_INIT,
    "_rpm",            /* m_name */
    rpm__doc__,        /* m_doc */
    0,                 /* m_size */
    rpmModuleMethods,
    NULL,              /* m_reload */
    rpmModuleTraverse,
    rpmModuleClear,
    NULL               /* m_free */
};

PyObject *
PyInit__rpm(void);

PyObject *
PyInit__rpm(void)
{
    PyObject * m;
    if (!prepareInitModule()) return NULL;
    m = PyModule_Create(&moduledef);
    initModule(m);
    return m;
}
#else
void init_rpm(void);	/* XXX eliminate gcc warning */
void init_rpm(void)
{
    PyObject * m;

    if (!prepareInitModule()) return;
    m = Py_InitModule3("_rpm", rpmModuleMethods, rpm__doc__);
    if (m == NULL)
	return;
    initModule(m);
}
Exemplo n.º 12
0
// The "main" of the medusa module world - this is what gets called to actually do the work
int go(sLogin* logins, int argc, char *argv[])
{
  int i;

  char *strtok_ptr, *pOpt, *pOptTmp;
  _MODULE_DATA *psSessionData;

  psSessionData = malloc(sizeof(_MODULE_DATA));
  memset(psSessionData, 0, sizeof(_MODULE_DATA));

  if ((argc < 0) || (argc > 1))
  {
    writeError(ERR_ERROR, "%s: Incorrect number of parameters passed to module (%d). Use \"-q\" option to display module usage.", MODULE_NAME, argc);
    return FAILURE;
  } 
  else 
  {
    writeError(ERR_DEBUG_MODULE, "OMG teh %s module has been called!!", MODULE_NAME);
 
    for (i=0; i<argc; i++) {
      pOptTmp = malloc( strlen(argv[i]) + 1);
      memset(pOptTmp, 0, strlen(argv[i]) + 1);
      strncpy(pOptTmp, argv[i], strlen(argv[i]));
      writeError(ERR_DEBUG_MODULE, "Processing complete option: %s", pOptTmp);
      pOpt = strtok_r(pOptTmp, ":", &strtok_ptr);
      writeError(ERR_DEBUG_MODULE, "Processing option: %s", pOpt);

      if (strcmp(pOpt, "MODE") == 0)
      {
        pOpt = strtok_r(NULL, "\0", &strtok_ptr);
        writeError(ERR_DEBUG_MODULE, "Processing option parameter: %s", pOpt);

        if (pOpt == NULL)
          writeError(ERR_WARNING, "Method MODE requires value to be set.");
        else if (strcmp(pOpt, "EXPLICIT") == 0)
          psSessionData->nAuthType = AUTH_EXPLICIT;
        else if (strcmp(pOpt, "IMPLICIT") == 0)
          psSessionData->nAuthType = AUTH_IMPLICIT;
        else if (strcmp(pOpt, "NORMAL") == 0)
          psSessionData->nAuthType = AUTH_NORMAL;
        else
          writeError(ERR_WARNING, "Invalid value for method MODE.");
      }
      else
         writeError(ERR_WARNING, "Invalid method: %s.", pOpt);

      free(pOptTmp);
    }

    initModule(logins, psSessionData);
  }  

  FREE(psSessionData);
  return SUCCESS;
}
Exemplo n.º 13
0
 static void loadImports(llvm::ArrayRef<ImportPtr> imports)
 {
     for (size_t i = 0; i < imports.size(); ++i) {
         module->imports.push_back(imports[i]);
     }
     for (size_t i = 0; i < imports.size(); ++i) {
         loadDependent(module, NULL, imports[i], false);
     }
     for (size_t i = 0; i < imports.size(); ++i) {
         initModule(imports[i]->module);
     }
 }
Exemplo n.º 14
0
// The "main" of the medusa module world - this is what gets called to actually do the work
int go(sLogin* logins, int argc, char *argv[])
{
  int i;
  char *strtok_ptr = NULL, *pOpt = NULL, *pOptTmp = NULL;
  _MYSQL_DATA *psSessionData;

  psSessionData = malloc(sizeof(_MYSQL_DATA));
  memset(psSessionData, 0, sizeof(_MYSQL_DATA));
  psSessionData->protoFlag = PROTO_NEW;

  if ((argc < 0) || (argc > 1))
  {
    writeError(ERR_ERROR, "%s: Incorrect number of parameters passed to module (%d). Use \"-q\" option to display module usage.", MODULE_NAME, argc);
    return FAILURE;
  }
  else 
  {
    writeError(ERR_DEBUG_MODULE, "OMG teh %s module has been called!!", MODULE_NAME);

    psSessionData->hashFlag = PASSWORD;

    for (i=0; i<argc; i++) {
      pOptTmp = malloc( strlen(argv[i]) + 1);
      memset(pOptTmp, 0, strlen(argv[i]) + 1);
      strncpy(pOptTmp, argv[i], strlen(argv[i]));
      writeError(ERR_DEBUG_MODULE, "Processing complete option: %s", pOptTmp);
      pOpt = strtok_r(pOptTmp, ":", &strtok_ptr);
      writeError(ERR_DEBUG_MODULE, "Processing option: %s", pOpt);

      if (strcmp(pOpt, "PASS") == 0) {
        pOpt = strtok_r(NULL, "\0", &strtok_ptr);
        writeError(ERR_DEBUG_MODULE, "Processing option parameter: %s", pOpt);

        if (pOpt == NULL)
          writeError(ERR_WARNING, "Method PASS requires value to be set.");
        else if (strcmp(pOpt, "PASSWORD") == 0)
          psSessionData->hashFlag = PASSWORD;
        else if (strcmp(pOpt, "HASH") == 0)
          psSessionData->hashFlag = HASH;
        else
          writeError(ERR_WARNING, "Invalid value for method PASS.");
      }

      free(pOptTmp);
    }

    initModule(logins, psSessionData);
  }  

  FREE(psSessionData);
  return SUCCESS;
}
Exemplo n.º 15
0
/*
  Do any common preliminary work before python 2 vs python 3 module creation:
*/
static int prepareInitModule(void)
{
    return 1;
}

static int initModule(PyObject *m)
{
    return 1;
}

static PyMethodDef modMethods[] = {
    { "addSign", (PyCFunction) addSign, METH_VARARGS|METH_KEYWORDS, NULL },
    { "delSign", (PyCFunction) delSign, METH_VARARGS|METH_KEYWORDS, NULL },
    { NULL },
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {
    PyModuleDef_HEAD_INIT,
    "_rpms",     /* m_name */
    rpms__doc__, /* m_doc */
    0,           /* m_size */
    modMethods,  /* m_methods */
    NULL,        /* m_reload */
    NULL,        /* m_traverse */
    NULL,        /* m_clear */
    NULL         /* m_free */
};

PyObject * PyInit__rpms(void);	/* XXX eliminate gcc warning */
PyObject * PyInit__rpms(void)
{
    PyObject *m;

    if (!prepareInitModule())
        return NULL;
    m = PyModule_Create(&moduledef);
    if (m == NULL || !initModule(m)) {
        Py_XDECREF(m);
        m = NULL;
    }
    return m;
}
Exemplo n.º 16
0
// The "main" of the medusa module world - this is what gets called to actually do the work
int go(sLogin* logins, int argc, char *argv[])
{
  int i;
  char *strtok_ptr, *pOpt, *pOptTmp;
  _MODULE_DATA *psSessionData;
  
  psSessionData = malloc(sizeof(_MODULE_DATA));
  memset(psSessionData, 0, sizeof(_MODULE_DATA));

  if ( !(0 <= argc <= 3) )
  {
    // Show usage information
    writeError(ERR_ERROR, "%s is expecting 0 parameters, but it was passed %d", MODULE_NAME, argc);
  } 
  else 
  {
    writeError(ERR_DEBUG_MODULE, "OMG teh %s module has been called!!", MODULE_NAME);

    for (i=0; i<argc; i++) {
      pOptTmp = malloc( strlen(argv[i]) + 1);
      memset(pOptTmp, 0, strlen(argv[i]) + 1);
      strncpy(pOptTmp, argv[i], strlen(argv[i]));
      writeError(ERR_DEBUG_MODULE, "Processing complete option: %s", pOptTmp);
      pOpt = strtok_r(pOptTmp, ":", &strtok_ptr);
      writeError(ERR_DEBUG_MODULE, "Processing option: %s", pOpt);

      if (strcmp(pOpt, "EHLO") == 0)
      {
        pOpt = strtok_r(NULL, "\0", &strtok_ptr);
        writeError(ERR_DEBUG_MODULE, "Processing option parameter: %s", pOpt);

        if ( pOpt )
        {
          psSessionData->szEHLO = malloc(strlen(pOpt) + 1);
          memset(psSessionData->szEHLO, 0, strlen(pOpt) + 1);
          strncpy((char *)psSessionData->szEHLO, pOpt, strlen(pOpt));
        }
        else
          writeError(ERR_WARNING, "Method EHLO requires value to be set.");
      }
      else
         writeError(ERR_WARNING, "Invalid method: %s.", pOpt);

      free(pOptTmp);
    }

    initModule(logins, psSessionData);
  }  

  return 0;
}
Exemplo n.º 17
0
static void initModule(ModulePtr m) {
    if (m->initialized) return;
    m->initialized = true;
    vector<ImportPtr>::iterator ii, iend;
    for (ii = m->imports.begin(), iend = m->imports.end(); ii != iend; ++ii)
        initModule((*ii)->module);

    if (m->declaration != NULL) {
        if (m->moduleName == "")
            m->moduleName = toKey(m->declaration->name);
        else if (m->moduleName != toKey(m->declaration->name))
            error(m->declaration,
                "module imported by name " + m->moduleName
                + " but declared with name " + toKey(m->declaration->name)
            );
    } else if (m->moduleName == "")
        m->moduleName = "__main__";

    verifyAttributes(m);

    const vector<TopLevelItemPtr> &items = m->topLevelItems;
    vector<TopLevelItemPtr>::const_iterator ti, tend;
    for (ti = items.begin(), tend = items.end(); ti != tend; ++ti) {
        Object *obj = ti->ptr();
        switch (obj->objKind) {
        case OVERLOAD :
            initOverload((Overload *)obj);
            break;
        case INSTANCE :
            initVariantInstance((Instance *)obj);
            break;
        }
    }

    if (llvmDIBuilder != NULL) {
        llvm::DIFile file = m->location == NULL
            ? llvm::DIFile(NULL)
            : m->location->source->getDebugInfo();
        m->debugInfo = (llvm::MDNode*)llvmDIBuilder->createNameSpace(
            llvm::DICompileUnit(llvmDIBuilder->getCU()), // scope
            m->moduleName, // name
            file, // file
            1 // line
            );
    }
}
Exemplo n.º 18
0
bool
Extension::scanAndLoad(as_object& where)
{
//    GNASH_REPORT_FUNCTION;
    
    if (_modules.empty()) {
        scanDir(_pluginsdir);
    }
    
    std::vector<std::string>::iterator it;
    for (it = _modules.begin(); it != _modules.end(); it++) {
        const std::string& mod = *it;
        log_security(_("Loading module: %s from %s"), mod, _pluginsdir);
        initModule(mod, where);
    }
    return true;
}
Exemplo n.º 19
0
Common::Error PinkEngine::init() {
	debugC(10, kPinkDebugGeneral, "PinkEngine init");
	initGraphics(640, 480);

	Common::PEResources exeResources;
	Common::String fileName = isPeril() ? "pptp.exe" : "hpp.exe";
	if (!exeResources.loadFromEXE(fileName)) {
		return Common::kNoGameDataFoundError;
	}

	_console = new Console(this);
	_director = new Director();

	initMenu(exeResources);

	Common::String orbName;
	Common::String broName;
	if (isPeril()) {
		orbName = "PPTP.ORB";
		broName = "PPTP.BRO";
		_bro = new BroFile;
	} else {
		orbName = "HPP.ORB";
	}

	if (!_orb.open(orbName) || (_bro && !_bro->open(broName) && _orb.getTimestamp() == _bro->getTimestamp()))
		return Common::kNoGameDataFoundError;

	if (!loadCursors(exeResources))
		return Common::kNoGameDataFoundError;

	setCursor(kLoadingCursor);

	_orb.loadGame(this);
	debugC(6, kPinkDebugGeneral, "Modules are loaded");

	syncSoundSettings();

	if (ConfMan.hasKey("save_slot"))
		loadGameState(ConfMan.getInt("save_slot"));
	else
		initModule(_modules[0]->getName(), "", nullptr);

	return Common::kNoError;
}
Exemplo n.º 20
0
STDMETHODIMP CDgnAppSupport::Register( IServiceProvider * pIDgnSite )
{
	BOOL bSuccess;

	// load and initialize the Python system
	Py_Initialize();

	// load the natlink module into Python and return a pointer to the
	// shared CDragonCode object
	m_pDragCode = initModule();
	m_pDragCode->setAppClass( this );

	// simulate calling natlink.natConnect() except share the site object
	bSuccess = m_pDragCode->natConnect( pIDgnSite ,TRUE);

	if( !bSuccess )
	{
		OutputDebugString(
			"NatLink: failed to initialize NatSpeak interfaces" );
		m_pDragCode->displayText(
			"Failed to initialize NatSpeak interfaces\r\n", TRUE );
		return S_OK;
	}

	// now load the Python code which does most of the work
	m_pDragCode->setDuringInit( TRUE );
	m_pNatLinkMain = PyImport_ImportModule( "natlinkmain" );
	
	// until natlink has been loaded, we restrict some of the function
	// callbacks into DragCode to avoid deadlock.
	m_pDragCode->setDuringInit( FALSE );

	if( m_pNatLinkMain == NULL )
	{
		OutputDebugString(
			"NatLink: an exception occurred loading 'natlinkmain' module" );
		m_pDragCode->displayText(
			"An exception occurred loading 'natlinkmain' module\r\n", TRUE );
		m_pDragCode->displayText(
			"No more error information is available\r\n", TRUE );
		return S_OK;
	}

	return S_OK;
}
Exemplo n.º 21
0
// The "main" of the medusa module world - this is what gets called to actually do the work
int go(sLogin* logins, int argc, char *argv[])
{
  int i;

  if ( !(0 <= argc <= 3) )
  {
    // Show usage information
    writeError(ERR_ERROR, "%s is expecting 0 parameters, but it was passed %d", MODULE_NAME, argc);
  } 
  else 
  {
    writeError(ERR_DEBUG_MODULE, "OMG teh %s module has been called!!", MODULE_NAME);
 
    initModule(logins);
  }  

  return SUCCESS;
}
Exemplo n.º 22
0
AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
    switch (msg) {
    case AcRx::kInitAppMsg:
		if (!acrxClassDictionary->at("AcBrEntity"))
			acrxDynamicLinker->loadModule("acbr16.dbx", 1);
        initModule();
        acrxUnlockApplication(pkt); // try to allow unloading
		acrxRegisterAppMDIAware(pkt);
        break ;
    case AcRx::kUnloadAppMsg:
		unloadModule();
        break ;
    default:
        break ;
    }
    return AcRx::kRetOK;
}
Exemplo n.º 23
0
void scripting_run_python(wchar_t *script, wchar_t **argv) {
	// Execute script as a Python script.
	global_argv = argv;
	Py_Initialize();
	initModule();
	g_Py_False = PyBool_FromLong(0);
	g_Py_True = PyBool_FromLong(1);
	PyRun_SimpleString("import praat");
	PyRun_SimpleString("praat.argv = praat.getargv()");
	PyRun_SimpleString("from praat import *");
	PyRun_SimpleString("import sys");
	PyRun_SimpleString("sys.stdout = InfoWindow()");
	PyRun_SimpleString("sys.stderr = InfoWindow()");
	PyRun_SimpleString("sys.path = ['.'] + sys.path");
		
	char *cscript = wc2c(script, 0);
	PyRun_SimpleString(cscript);
	free(cscript);
		
	Py_Finalize();
}
Exemplo n.º 24
0
	void PythonLanguage::init(int argc, char **argv) {
#ifdef IS_PY3K
		// insert our module into the init tab
		PyImport_AppendInittab("opde", &initModule);
#endif
		Py_Initialize();

#ifndef IS_PY3K
		initModule();
#endif

		if (PyErr_Occurred()) {
			// TODO: Do something useful here, or forget it
			PyErr_Print();
			PyErr_Clear();
		}

#warning Fix this for python3!
#ifndef IS_PY3K
		PySys_SetArgv(argc, argv);
#endif
	}
Exemplo n.º 25
0
void
CArchNetworkWinsock::init()
{
	static const char* s_library[] = { "ws2_32.dll" };

	assert(WSACleanup_winsock == NULL);
	assert(s_networkModule    == NULL);

	// try each winsock library
	for (size_t i = 0; i < sizeof(s_library) / sizeof(s_library[0]); ++i) {
		try {
			initModule((HMODULE)::LoadLibrary(s_library[i]));
			m_mutex = ARCH->newMutex();
			return;
		}
		catch (XArchNetwork&) {
			// ignore
		}
	}

	// can't initialize any library
	throw XArchNetworkSupport("Cannot load winsock library");
}
Exemplo n.º 26
0
/* Demande au serveur de s'enregistrer */
myModule *init() {
  return initModule(MODULE_VERSION,  /* module version     */
                   &createHandler,   /* handlers           */
                   "listModule",     /* module Name        */
                   MODDESC);         /* module Description */
}
Exemplo n.º 27
0
Arquivo: loader.cpp Projeto: Blei/clay
static void initModule(ModulePtr m, llvm::ArrayRef<string>  importChain) {
    if (m->initState == Module::DONE) return;

    if (m->declaration != NULL) {
        if (m->moduleName == "")
            m->moduleName = toKey(m->declaration->name);
        else if (m->moduleName != toKey(m->declaration->name))
            error(m->declaration,
                "module imported by name " + m->moduleName
                + " but declared with name " + toKey(m->declaration->name)
            );
    } else if (m->moduleName == "")
        m->moduleName = "__main__";


    if (m->initState == Module::RUNNING && !importChain.empty()) {
        // allow prelude to import self
        if (importChain.back() == m->moduleName) {
            return;
        }
    }

    vector<string> importChainNext = importChain;
    importChainNext.push_back(m->moduleName);

    if (m->initState == Module::RUNNING) {
        circularImportsError(importChainNext);
    }

    m->initState = Module::RUNNING;

    vector<ImportPtr>::iterator ii, iend;
    for (ii = m->imports.begin(), iend = m->imports.end(); ii != iend; ++ii)
        initModule((*ii)->module, importChainNext);

    m->initState = Module::DONE;

    verifyAttributes(m);

    llvm::ArrayRef<TopLevelItemPtr> items = m->topLevelItems;
    TopLevelItemPtr const *ti, *tend;
    for (ti = items.begin(), tend = items.end(); ti != tend; ++ti) {
        Object *obj = ti->ptr();
        switch (obj->objKind) {
        case OVERLOAD :
            initOverload((Overload *)obj);
            break;
        case INSTANCE_DECL :
            initVariantInstance((InstanceDecl *)obj);
            break;
        case STATIC_ASSERT_TOP_LEVEL:
            checkStaticAssert((StaticAssertTopLevel *)obj);
            break;
        default:
            break;
        }
    }

    if (llvmDIBuilder != NULL) {
        llvm::DIFile file = m->location.ok()
            ? m->location.source->getDebugInfo()
            : llvm::DIFile(NULL);
        m->debugInfo = (llvm::MDNode*)llvmDIBuilder->createNameSpace(
            llvm::DICompileUnit(llvmDIBuilder->getCU()), // scope
            m->moduleName, // name
            file, // file
            1 // line
            );
    }
}
Exemplo n.º 28
0
Arquivo: loader.cpp Projeto: Blei/clay
void initModule(ModulePtr m) {
    initModule(m, vector<string>());
}
Exemplo n.º 29
0
// The "main" of the medusa module world - this is what gets called to actually do the work
int go(sLogin* logins, int argc, char *argv[])
{
  int i;
  char *strtok_ptr, *pOpt, *pOptTmp;
  _MODULE_DATA *psSessionData;
  psSessionData = malloc(sizeof(_MODULE_DATA));
  memset(psSessionData, 0, sizeof(_MODULE_DATA));

  if ( !(0 <= argc <= 2) )
  {
    // Show usage information
    writeError(ERR_ERROR, "%s: Incorrect number of parameters passed to module.", MODULE_NAME);
    return FAILURE;
  } 
  else 
  {
    // Parameters are good - make module go now
    writeError(ERR_DEBUG_MODULE, "OMG teh %s module has been called!!", MODULE_NAME);

    for (i=0; i<argc; i++) {
      pOptTmp = malloc( strlen(argv[i]) + 1);
      memset(pOptTmp, 0, strlen(argv[i]) + 1);
      strncpy(pOptTmp, argv[i], strlen(argv[i]));
      writeError(ERR_DEBUG_MODULE, "Processing complete option: %s", pOptTmp);
      pOpt = strtok_r(pOptTmp, ":", &strtok_ptr);
      writeError(ERR_DEBUG_MODULE, "Processing option: %s", pOpt);

      if (strcmp(pOpt, "TAG") == 0)
      {
        pOpt = strtok_r(NULL, "\0", &strtok_ptr);
        writeError(ERR_DEBUG_MODULE, "Processing option parameter: %s", pOpt);

        if ( pOpt )
        {
          psSessionData->szTag = malloc(strlen(pOpt) + 1);
          memset(psSessionData->szTag, 0, strlen(pOpt) + 1);
          strncpy(psSessionData->szTag, pOpt, strlen(pOpt) + 1);
        }
        else
          writeError(ERR_WARNING, "Method TAG requires value to be set.");
      }
      else if (strcmp(pOpt, "AUTH") == 0)
      {
        pOpt = strtok_r(NULL, "\0", &strtok_ptr);
        writeError(ERR_DEBUG_MODULE, "Processing option parameter: %s", pOpt);

        if (strcmp(pOpt, "LOGIN") == 0)
          psSessionData->nAuthType = AUTH_LOGIN;
        else if (strcmp(pOpt, "PLAIN") == 0)
          psSessionData->nAuthType = AUTH_PLAIN;
        else if (strcmp(pOpt, "NTLM") == 0)
          psSessionData->nAuthType = AUTH_NTLM;
        else
          writeError(ERR_WARNING, "Invalid value for method AUTH.");
      }
      else if (strcmp(pOpt, "DOMAIN") == 0)
      {
        pOpt = strtok_r(NULL, "\0", &strtok_ptr);
        writeError(ERR_DEBUG_MODULE, "Processing option parameter: %s", pOpt);

        if ( pOpt )
        {
          psSessionData->szDomain = malloc(strlen(pOpt) + 1);
          memset(psSessionData->szDomain, 0, strlen(pOpt) + 1); 
          strncpy((char *) psSessionData->szDomain, pOpt, strlen(pOpt));
        }
        else
          writeError(ERR_WARNING, "Method DOMAIN requires value to be set.");
      }
      else
      {
        writeError(ERR_WARNING, "Invalid method: %s.", pOpt);
      }

      free(pOptTmp);
    }

    initModule(psSessionData, logins);
  }  

  FREE(psSessionData);
  return SUCCESS;
}
Exemplo n.º 30
0
int main()
{
    VisionCam * gCam = NULL;
    entryIndex index = 0;
    module_t handle = NULL;
    status_e ret = STATUS_SUCCESS;

#if defined(SOSAL_RUNTIME_DEBUG)
    debug_get_zone_mask("SOSAL_ZONE_MASK", &sosal_zone_mask);
#endif

#if defined(DVP_RUNTIME_DEBUG)
    debug_get_zone_mask("DVP_ZONE_MASK", &dvp_zone_mask);
#endif

    handle =  initModule( &gCam );
#ifdef VCAM_AS_SHARED
    if( handle == NULL )
        return -1;
#endif

    if( gCam )
    {
        setInitialValues( gCam );
        ret = startServices( gCam );
    }
    else
    {
        ret = STATUS_CATASTROPHIC;
    }

    if( ret !=  STATUS_SUCCESS )
    {
        ret = deinitModule( handle, &gCam );
    }
    else
    {
        while( 1 )
        {
            index = Menu( menu );
            if( index == -1 )
            {
                continue;
            }

            /// 'q' button (quit) is pressed
            if( menu[ index ]->ID == VCAM_CMD_QUIT )
            {
                index = getEntryIndex( menu , KEY_PREVIEW_STOP );
                ret = executeEntry( menu[ index ], gCam );
                break;
            }
            ret = executeEntry( menu[ index ] , gCam );
        }
        ret = stopServices( gCam );
        ret = deinitModule( handle, &gCam );
    }

    printf("\tvcam_test exiting with %d.\n", ret);

    if( STATUS_SUCCESS != ret )
        puts("\tTerminating application.");

    return ret;
}