示例#1
0
文件: main.c 项目: RuliLG/makehuman
int main(int argc, char *argv[])
{
    int err;

#ifdef __WIN32__
    //Let's make sure we're in the directory where the executable
    //is since this is required for Makehuman to function on Windows
    //Makehuman will fail to start if you're not in the same directory
    //as the executable
    TCHAR exepath[MAX_PATH];
    if (0 == GetModuleFileName(0, exepath, MAX_PATH)) {
	fprintf(stderr, "coulnd't get executable path\n");
    }
    else {
	PathRemoveFileSpec(exepath);
	SetCurrentDirectory(exepath);
    }
#endif

    Py_SetProgramName(argv[0]);
#if 0
    Py_SetPythonHome(".");
#endif
    Py_Initialize();

    if (!Py_IsInitialized())
    {
        fprintf(stderr, "Could not initialize Python\n");
        exit(EXIT_FAILURE);
    }

    PySys_SetArgv(argc, argv);

    PyEval_InitThreads();

    err = PyRun_SimpleString("execfile('makehuman.py')");

    if (err != 0)
    {
        fprintf(stderr, "Could not run main Python script\n");
        getchar();
        exit(EXIT_FAILURE);
    }

    Py_Finalize();

    return 0;
}
示例#2
0
void embed_init_python(void)
{
    FENTER;

#ifndef PYTHON_SO_LIB
#error "Python version needs passing in with -DPYTHON_SO_VERSION=libpython<ver>.so"
#else
#define PY_SO_LIB xstr(PYTHON_SO_LIB)
#endif

    // Don't initialise python if already running
    if (gtstate)
        return;

    void * ret = utils_dyn_open(PY_SO_LIB);
    if (!ret) {
        fprintf(stderr, "Failed to find python lib\n");
    }

    Py_SetProgramName(progname);
    Py_Initialize();                    /* Initialize the interpreter */
    PySys_SetArgvEx(1, argv, 0);
    PyEval_InitThreads();               /* Create (and acquire) the interpreter lock */

    /* Swap out and return current thread state and release the GIL */
    gtstate = PyEval_SaveThread();

    /* Before returning we check if the user wants pause the simulator thread
       such that they can attach */
    const char *pause = getenv("COCOTB_ATTACH");
    if (pause) {
        long sleep_time = strtol(pause, NULL, 10);
        if (errno == ERANGE && (sleep_time == LONG_MAX || sleep_time == LONG_MIN)) {
            fprintf(stderr, "COCOTB_ATTACH only needs to be set to ~30 seconds");
            goto out;
        }
        if ((errno != 0 && sleep_time == 0) ||
            (sleep_time <= 0)) {
            fprintf(stderr, "COCOTB_ATTACH must be set to an integer base 10 or omitted");
            goto out;
        }

        fprintf(stderr, "Waiting for %lu seconds - Attach to %d\n", sleep_time, getpid());
        sleep(sleep_time);
    }
out:
    FEXIT;
}
示例#3
0
mraa_init()
{
    /** Once more board definitions have been added,
     *  A method for detecting them will need to be devised.
     */
    if (plat != NULL) {
        return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
    }
#ifdef SWIGPYTHON
    // Initialise python threads, this allows use to grab the GIL when we are
    // required to do so
    Py_InitializeEx(0);
    PyEval_InitThreads();
#endif
    // detect a galileo gen2 board
    char *line = NULL;
    // let getline allocate memory for *line
    size_t len = 0;
    FILE *fh = fopen("/sys/devices/virtual/dmi/id/board_name", "r");
    if (fh != NULL) {
        if (getline(&line, &len, fh) != -1) {
            if (strncmp(line, "GalileoGen2", 10) == 0) {
                platform_type = MRAA_INTEL_GALILEO_GEN2;
            } else {
                platform_type = MRAA_INTEL_GALILEO_GEN1;
            }
            free(line);
        }
        fclose(fh);
    }

    advance_func = (mraa_adv_func_t*) malloc(sizeof(mraa_adv_func_t));
    memset(advance_func, 0, sizeof(mraa_adv_func_t));

    switch(platform_type) {
        case MRAA_INTEL_GALILEO_GEN2:
            plat = mraa_intel_galileo_gen2();
            break;
        case MRAA_INTEL_GALILEO_GEN1:
            plat = mraa_intel_galileo_rev_d();
            break;
        default:
            plat = mraa_intel_galileo_rev_d();
            fprintf(stderr, "Platform not found, initialising MRAA_INTEL_GALILEO_GEN1\n");
    }

    return MRAA_SUCCESS;
}
示例#4
0
static void
_py_init_interpreter(void)
{
  if (!interpreter_initialized)
    {
      python_debugger_append_inittab();

      Py_Initialize();

      PyEval_InitThreads();
      python_log_message_init();
      PyEval_SaveThread();

      interpreter_initialized = TRUE;
    }
}
示例#5
0
static PyObject *
thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
{
	PyObject *func, *args, *keyw = NULL;
	struct bootstate *boot;
	long ident;

	if (!PyArg_UnpackTuple(fargs, "start_new_thread", 2, 3,
		               &func, &args, &keyw))
		return NULL;
	if (!PyCallable_Check(func)) {
		PyErr_SetString(PyExc_TypeError,
				"first arg must be callable");
		return NULL;
	}
	if (!PyTuple_Check(args)) {
		PyErr_SetString(PyExc_TypeError,
				"2nd arg must be a tuple");
		return NULL;
	}
	if (keyw != NULL && !PyDict_Check(keyw)) {
		PyErr_SetString(PyExc_TypeError,
				"optional 3rd arg must be a dictionary");
		return NULL;
	}
	boot = PyMem_NEW(struct bootstate, 1);
	if (boot == NULL)
		return PyErr_NoMemory();
	boot->interp = PyThreadState_GET()->interp;
	boot->func = func;
	boot->args = args;
	boot->keyw = keyw;
	Py_INCREF(func);
	Py_INCREF(args);
	Py_XINCREF(keyw);
	PyEval_InitThreads(); /* Start the interpreter's thread-awareness */
	ident = PyThread_start_new_thread(t_bootstrap, (void*) boot);
	if (ident == -1) {
		PyErr_SetString(ThreadError, "can't start new thread");
		Py_DECREF(func);
		Py_DECREF(args);
		Py_XDECREF(keyw);
		PyMem_DEL(boot);
		return NULL;
	}
	return PyInt_FromLong(ident);
}
void annoy(int count)
{
    count = std::max(count, 0);

    if (!PyEval_ThreadsInitialized())
    {
        PyEval_InitThreads();
    }

#ifdef PRINT_DEBUG_MESSAGES
    std::cout << "checking thread pool for removal" << std::endl;
#endif
    while(count < threads.size())
    {
#ifdef PRINT_DEBUG_MESSAGES
        std::cout << "stopping thread" << std::endl;
#endif
        auto& back = threads.back();
        back.second->quit = true;
        back.first.join();
#ifdef PRINT_DEBUG_MESSAGES
        std::cout << "removing thread" << std::endl;
#endif
        threads.pop_back();
    }

#ifdef PRINT_DEBUG_MESSAGES
    std::cout << "checking thread pool for additions" << std::endl;
#endif
    while(count > threads.size())
    {
#ifdef PRINT_DEBUG_MESSAGES
        std::cout << "creating thread" << std::endl;
#endif
        threads.push_back(thread_data{});
#ifdef PRINT_DEBUG_MESSAGES
        std::cout << "setting thread" << std::endl;
#endif
        auto& back = threads.back();
        back.second = std::make_shared<thread_parms>();
        back.second->quit = false;
#ifdef PRINT_DEBUG_MESSAGES
        std::cout << "launching thread" << std::endl;
#endif
        back.first = std::thread(worker, back.second);
    }
}
示例#7
0
int main(int argc, char* argv[])
{
    PyEval_InitThreads();
    Py_Initialize();
    PyObject* sysPath = PySys_GetObject((char*) "path");
    PyList_Append(sysPath, PyString_FromString("."));

    PyObject *pModule = NULL, *pClass = NULL, *pInst = NULL;
    do
    {
        PyGILState_STATE state = PyGILState_Ensure();
        {
            pModule = PyImport_ImportModule("worker");
            if (pModule == NULL) break;

            pClass = PyObject_GetAttrString(pModule, "ThreadManager");
            if (pClass == NULL) break;

            pInst = PyObject_CallObject(pClass, NULL);
            if (pInst == NULL) break;

            PyObject_CallMethod(pInst, "start_thread", NULL);
        }
        PyGILState_Release(state);

        for (int i = 0; i < 5; i++)
        {
            printf("main thread is running\n");
            sleep(1);
        }

        state = PyGILState_Ensure();
        {
            PyObject_CallMethod(pInst, "stop_thread", NULL);
        }
        PyGILState_Release(state);

        printf("finish\n");
    } while (0);

    Py_XDECREF(pInst);
    Py_XDECREF(pClass);
    Py_XDECREF(pModule);

    Py_Finalize();
    return 0;
}
示例#8
0
PyMODINIT_FUNC
initaudiodev(void)
{
    PyObject *m;
    
    PyEval_InitThreads();

    m = Py_InitModule3("audiodev", Module_methods, "portable audio device module based on the RtAudio project");
    if (m == NULL)
        return;

    _rtaudio = new RtAudio();
    
    ModuleError = PyErr_NewException("audiodev.error", NULL, NULL);
    Py_INCREF(ModuleError);
    PyModule_AddObject(m, "error", ModuleError);
}
PyMODINIT_FUNC
initrtaudio(void) 
{
  PyEval_InitThreads();
  import_libnumarray();
  import_libnumeric();

  PyObject* module;
  
  if (PyType_Ready(&RtAudio_type) < 0)
    return;
  
  module = Py_InitModule3("rtaudio", rtaudio_methods,
			  "RtAudio wrapper.");

  PyRTAUDIO_SINT8 = PyLong_FromUnsignedLong(RTAUDIO_SINT8);
  PyModule_AddObject(module, "RTAUDIO_SINT8", PyRTAUDIO_SINT8);
  Py_INCREF(PyRTAUDIO_SINT8);

  PyRTAUDIO_SINT16 = PyLong_FromUnsignedLong(RTAUDIO_SINT16);
  PyModule_AddObject(module, "RTAUDIO_SINT16", PyRTAUDIO_SINT16);
  Py_INCREF(PyRTAUDIO_SINT16);

  PyRTAUDIO_SINT24 = PyLong_FromUnsignedLong(RTAUDIO_SINT24);
  PyModule_AddObject(module, "RTAUDIO_SINT24", PyRTAUDIO_SINT24);
  Py_INCREF(PyRTAUDIO_SINT24);

  PyRTAUDIO_SINT32 = PyLong_FromUnsignedLong(RTAUDIO_SINT32);
  PyModule_AddObject(module, "RTAUDIO_SINT32", PyRTAUDIO_SINT32);
  Py_INCREF(PyRTAUDIO_SINT32);

  PyRTAUDIO_FLOAT32 = PyLong_FromUnsignedLong(RTAUDIO_FLOAT32);
  PyModule_AddObject(module, "RTAUDIO_FLOAT32", PyRTAUDIO_FLOAT32);
  Py_INCREF(PyRTAUDIO_FLOAT32);

  PyRTAUDIO_FLOAT64 = PyLong_FromUnsignedLong(RTAUDIO_FLOAT64);
  PyModule_AddObject(module, "RTAUDIO_FLOAT64", PyRTAUDIO_FLOAT64);
  Py_INCREF(PyRTAUDIO_FLOAT64);
  
  Py_INCREF(&RtAudio_type);
  PyModule_AddObject(module, "RtAudio", (PyObject *)&RtAudio_type);
  
  RtAudioError = PyErr_NewException("rtaudio.RtError", NULL, NULL);
  PyModule_AddObject(module, "RtError", RtAudioError);
  Py_INCREF(RtAudioError);
}
示例#10
0
PyMODINIT_FUNC init_jpype()
{
	Py_Initialize();
	PyEval_InitThreads();
	  
	PyObject* module = Py_InitModule("_jpype", jpype_methods);  
	Py_INCREF(module);
	hostEnv = new PythonHostEnvironment();
	  
	JPEnv::init(hostEnv);

	PyJPMonitor::initType(module);	
	PyJPMethod::initType(module);	
	PyJPBoundMethod::initType(module);	
	PyJPClass::initType(module);	
	PyJPField::initType(module);	
}
示例#11
0
文件: embed.c 项目: Plombo/dega
void MPyEmbed_Init(void) {
	if (!PythonAvailable) {
		PythonAvailable = initlinkage();
	}
	if (!PythonAvailable) {
		return;
	}
	PyEval_InitThreads();
	Py_Initialize();

	initpydega();

	PySys_SetArgv(argc, argv);
	mainstate = PyEval_SaveThread();
	memset(threaddata, 0, sizeof(threaddata));
	threaddatalock = PyThread_allocate_lock();
}
示例#12
0
// @pymethod |PyCWinThread|CreateThread|Creates the actual thread behind the thread object.
static PyObject *
ui_thread_create_thread(PyObject *self, PyObject *args)
{
	DWORD createFlags = 0;
	UINT stackSize = 0;
	if (!PyArg_ParseTuple(args, "|li:CreateThread", &createFlags, &stackSize))
		return NULL;
	CWinThread *pThread = GetCWinThreadPtr(self);
	if (!pThread) return NULL;
	PyEval_InitThreads();
	GUI_BGN_SAVE;
	BOOL ok = pThread->CreateThread(createFlags, stackSize);
	GUI_END_SAVE;
	if (!ok)
		RETURN_ERR("CreateThread failed");
	RETURN_NONE;
}
示例#13
0
文件: mraa.c 项目: zBMNForks/mraa
mraa_init()
{
    if (plat != NULL) {
        return MRAA_ERROR_PLATFORM_ALREADY_INITIALISED;
    }

    uid_t proc_euid = geteuid();
    struct passwd* proc_user = getpwuid(proc_euid);

#ifdef DEBUG
    setlogmask(LOG_UPTO(LOG_DEBUG));
#else
    setlogmask(LOG_UPTO(LOG_NOTICE));
#endif

    openlog("libmraa", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
    syslog(LOG_NOTICE, "libmraa version %s initialised by user '%s' with EUID %d",
           mraa_get_version(), (proc_user != NULL) ? proc_user->pw_name : "<unknown>", proc_euid);

#ifdef SWIGPYTHON
    // Initialise python threads, this allows use to grab the GIL when we are
    // required to do so
    Py_InitializeEx(0);
    PyEval_InitThreads();
#endif
    advance_func = (mraa_adv_func_t*) malloc(sizeof(mraa_adv_func_t));
    memset(advance_func, 0, sizeof(mraa_adv_func_t));

#if defined(X86PLAT)
    // Use runtime x86 platform detection
    platform_type = mraa_x86_platform();
#elif defined(ARMPLAT)
    // Use runtime ARM platform detection
    platform_type = mraa_arm_platform();
#else
#error mraa_ARCH NOTHING
#endif

    if (plat == NULL) {
        printf("mraa: FATAL error, failed to initialise platform\n");
        return MRAA_ERROR_PLATFORM_NOT_INITIALISED;
    }

    syslog(LOG_INFO, "libmraa initialised for platform '%s' of type %d", mraa_get_platform_name(), platform_type);
    return MRAA_SUCCESS;
}
示例#14
0
initvisit(void)
{
    if(moduleState == NULL)
    {
        moduleState = (VisItModuleState*)malloc(sizeof(VisItModuleState));
        memset(moduleState, 0, sizeof(VisItModuleState));
    }

    /* Make sure that threads are init'd */
    PyEval_InitThreads();

    /* Add the VisIt module to Python. Note that we're passing just a
     * couple of methods and then the interface that we load will
     * get the rest of the functions.
     */
    Py_InitModule("visit", visit_methods);
}
示例#15
0
文件: python.c 项目: liexusong/NXWEB
static int on_startup() {
  struct stat fi;
  if (!project_app || !*project_app) {
    nxweb_log_error("python wsgi app not specified; skipping python initialization");
    return 0;
  }
  static const char* prog_name="python/nxwebpy.py";
  if (stat(prog_name, &fi)==-1) {

#ifdef NXWEB_LIBDIR
    prog_name=NXWEB_LIBDIR "/nxwebpy.py";
    if (stat(prog_name, &fi)==-1) {
#endif

      nxweb_log_error("%s is missing; skipping python initialization", prog_name);
      return 0;

#ifdef NXWEB_LIBDIR
    }
#endif

  }

  Py_SetProgramName((char*)prog_name);
  // initialize thread support
  PyEval_InitThreads();
  Py_Initialize();
  char *a[]={(char*)prog_name, (char*)project_root, (char*)project_app, (char*)virtualenv_path};
  PySys_SetArgv(4, a);
  PyObject* py_module_name=PyString_FromString(MODULE_NAME);
  assert(py_module_name);
  // save a pointer to the main PyThreadState object
  py_main_thread_state=PyThreadState_Get();
  py_module=PyImport_Import(py_module_name);
  if (!py_module || !PyModule_Check(py_module)) {
    fprintf(stderr, "can't load python module %s; check parse errors:\n", MODULE_NAME);
    PyErr_Print();
    exit(0);
  }
  Py_DECREF(py_module_name);
  py_nxweb_on_request_func=PyObject_GetAttrString(py_module, FUNC_NAME);
  assert(py_nxweb_on_request_func && PyCallable_Check(py_nxweb_on_request_func));
  // release the lock
  PyEval_ReleaseLock();
  return 0;
}
示例#16
0
// Construct the C++ plugin.
PyQt5QmlPlugin::PyQt5QmlPlugin(QObject *parent) : QQmlExtensionPlugin(parent),
        py_plugin_obj(0), sip(0)
{
    // Make sure the interpreter is initialised.
    if (!Py_IsInitialized())
    {
        Py_Initialize();

        getSipAPI();

#ifdef WITH_THREAD
        // Make sure we don't have the GIL.
        PyEval_InitThreads();
        PyEval_SaveThread();
#endif
    }
}
示例#17
0
文件: withgil.c 项目: jwilk/Pyrex
/* Implementation of withgil */

static void __pyx_f_7withgil_f(void) {
  PyObject *__pyx_v_x;
  PyObject *__pyx_1 = 0;
  PyGILState_STATE _save = PyGILState_Ensure();
  __pyx_v_x = Py_None; Py_INCREF(Py_None);
  __pyx_1 = PyInt_FromLong(42); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; goto __pyx_L1;}
  Py_DECREF(__pyx_v_x);
  __pyx_v_x = __pyx_1;
  __pyx_1 = 0;

  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_WriteUnraisable("withgil.f");
  __pyx_L0:;
  Py_DECREF(__pyx_v_x);
  PyGILState_Release(_save);
}

static PyObject *__pyx_f_7withgil_g(PyObject *__pyx_v_x) {
  PyObject *__pyx_r;
  PyGILState_STATE _save = PyGILState_Ensure();
  Py_INCREF(__pyx_v_x);

  __pyx_r = Py_None; Py_INCREF(Py_None);
  Py_DECREF(__pyx_v_x);
  PyGILState_Release(_save);
  return __pyx_r;
}

static struct PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

static void __pyx_init_filenames(void); /*proto*/

PyMODINIT_FUNC initwithgil(void); /*proto*/
PyMODINIT_FUNC initwithgil(void) {
  #if PY_VERSION_HEX < 0x02040000 && defined(WITH_THREAD)
    PyEval_InitThreads();
  #endif
  __pyx_init_filenames();
  __pyx_m = Py_InitModule4("withgil", __pyx_methods, 0, 0, PYTHON_API_VERSION);
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
  Py_INCREF(__pyx_m);
  __pyx_b = PyImport_AddModule("__builtin__");
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;};

  /* "/Local/Projects/D/Pyrex/Source/Tests/9/withgil.pyx":4 */
  return;
  __pyx_L1:;
  __Pyx_AddTraceback("withgil");
}
示例#18
0
/*
    This routine is required by the OllyDBG plugin engine! 
*/
extc int __cdecl ODBG2_Pluginquery(int ollydbgversion, ulong *features, wchar_t pluginname[SHORTNAME], wchar_t pluginversion[SHORTNAME])
{
    // Yeah, the plugin interface in the v1/v2 are different
    if(ollydbgversion < 201)
        return 0;

    // Set plugin name and version
    wcscpy_s(pluginname, SHORTNAME, L"python-loader");
    wcscpy_s(pluginversion, SHORTNAME, L"v0.1");

    // Initialize the python environment, prepare the hooks
    Py_Initialize();
    PyEval_InitThreads();

    Addtolist(0x31337, RED, NAME_PLUGIN L" Plugin fully initialized.");

    return PLUGIN_VERSION;
}
示例#19
0
initgtask (void)
{
	PyObject *m, *d;

	PyEval_InitThreads ();
	init_pygobject ();

	m = Py_InitModule ("gtask", pygtask_functions);
	d = PyModule_GetDict (m);

	pygtask_register_classes (d);
	pygtask_add_constants (m, "G_");

	if (PyErr_Occurred ())
		Py_FatalError ("Error initializing module GTask");

	pyg_enable_threads ();
}
示例#20
0
// Python 2.7
PyMODINIT_FUNC initxormasker(void)
{
#ifdef WITH_THREAD /* Python build with threading support? */
    PyEval_InitThreads();
#endif

    /* Create the module */
    PyObject *module = Py_InitModule3("xormasker", utf8validator_methods, "xormasker module");

    if (!module)
    {
        // TODO: Add some error message
        return;
    }

    /* Register the Exception used in the module */
    XorMaskerException = PyErr_NewException("autobahn.xormasker.XorMaskerException", NULL, NULL);

    /* Fill in missing slots in type XorMaskerNullType */
    XorMaskerNullType.tp_new = PyType_GenericNew;

    if (PyType_Ready(&XorMaskerNullType) < 0)
    {
        // TODO: Add some error message
        return;
    }

    /* Add the type XorMaskerNullType to the module */
    Py_INCREF(&XorMaskerNullType);
    PyModule_AddObject(module, "XorMaskerNull", (PyObject*) &XorMaskerNullType);

    /* Fill in missing slots in type XorMaskerSimpleType */
    XorMaskerSimpleType.tp_new = PyType_GenericNew;

    if (PyType_Ready(&XorMaskerSimpleType) < 0)
    {
        // TODO: Add some error message
        return;
    }

    /* Add the type XorMaskerSimpleType to the module */
    Py_INCREF(&XorMaskerSimpleType);
    PyModule_AddObject(module, "XorMaskerSimple", (PyObject*) &XorMaskerSimpleType);
}
示例#21
0
文件: main.cpp 项目: negtise/pydroid
extern "C" int pydroid_main(int argc,char *argv[])
{
    printf("+++++++++++argc %d \n",argc);

    Py_InitializeEx(0);
    PyEval_InitThreads();
    
    initPyDroid();

    initandroidlog();

	android::ProcessState::self()->startThreadPool();


/*
    PyRun_SimpleString(
        "import sys, posix\n" \
        "import androidlog\n" \
        "class LogFile(object):\n" \
        "    def __init__(self):\n" \
        "        self.buffer = ''\n" \
        "    def write(self, s):\n" \
        "        s = self.buffer + s\n" \
        "        lines = s.split(\"\\n\")\n" \
        "        for l in lines[:-1]:\n" \
        "            pylog.i(l)\n" \
        "        self.buffer = lines[-1]\n" \
        "    def flush(self):\n" \
        "        return\n" \
        "sys.stdout = sys.stderr = LogFile()\n");
*/
    
    if(argc <= 1)
    {
        return PyRun_SimpleString(
            "import main\n" \
            "main.run()\n"
            );
    }
    else
    {
        return Py_Main(argc,argv);
    }
}
示例#22
0
文件: uca-camera.c 项目: miq/libuca
static void
uca_camera_init (UcaCamera *camera)
{
    GValue val = {0};

    camera->grab_func = NULL;

    camera->priv = UCA_CAMERA_GET_PRIVATE(camera);
    camera->priv->cancelling_recording = FALSE;
    camera->priv->is_recording = FALSE;
    camera->priv->is_readout = FALSE;
    camera->priv->transfer_async = FALSE;
    camera->priv->trigger_source = UCA_CAMERA_TRIGGER_SOURCE_AUTO;
    camera->priv->trigger_type = UCA_CAMERA_TRIGGER_TYPE_EDGE;
    camera->priv->buffered = FALSE;
    camera->priv->num_buffers = 4;
    camera->priv->ring_buffer = NULL;

    g_value_init (&val, G_TYPE_UINT);
    g_value_set_uint (&val, 1);

    uca_camera_set_property_unit (camera_properties[PROP_SENSOR_WIDTH], UCA_UNIT_PIXEL);
    uca_camera_set_property_unit (camera_properties[PROP_SENSOR_HEIGHT], UCA_UNIT_PIXEL);
    uca_camera_set_property_unit (camera_properties[PROP_SENSOR_PIXEL_WIDTH], UCA_UNIT_METER);
    uca_camera_set_property_unit (camera_properties[PROP_SENSOR_PIXEL_HEIGHT], UCA_UNIT_METER);
    uca_camera_set_property_unit (camera_properties[PROP_SENSOR_BITDEPTH], UCA_UNIT_COUNT);
    uca_camera_set_property_unit (camera_properties[PROP_SENSOR_HORIZONTAL_BINNING], UCA_UNIT_PIXEL);
    uca_camera_set_property_unit (camera_properties[PROP_SENSOR_VERTICAL_BINNING], UCA_UNIT_PIXEL);
    uca_camera_set_property_unit (camera_properties[PROP_EXPOSURE_TIME], UCA_UNIT_SECOND);
    uca_camera_set_property_unit (camera_properties[PROP_FRAMES_PER_SECOND], UCA_UNIT_COUNT);
    uca_camera_set_property_unit (camera_properties[PROP_ROI_X], UCA_UNIT_PIXEL);
    uca_camera_set_property_unit (camera_properties[PROP_ROI_Y], UCA_UNIT_PIXEL);
    uca_camera_set_property_unit (camera_properties[PROP_ROI_WIDTH], UCA_UNIT_PIXEL);
    uca_camera_set_property_unit (camera_properties[PROP_ROI_HEIGHT], UCA_UNIT_PIXEL);
    uca_camera_set_property_unit (camera_properties[PROP_ROI_WIDTH_MULTIPLIER], UCA_UNIT_PIXEL);
    uca_camera_set_property_unit (camera_properties[PROP_ROI_HEIGHT_MULTIPLIER], UCA_UNIT_PIXEL);
    uca_camera_set_property_unit (camera_properties[PROP_RECORDED_FRAMES], UCA_UNIT_COUNT);

#ifdef WITH_PYTHON_MULTITHREADING
    if (!PyEval_ThreadsInitialized ()) {
        PyEval_InitThreads ();
    }
#endif
}
示例#23
0
bool CPythonEngine::InitMainInterp(void)
{
	// ensure only 1 engine/thread initialises this only
	CSLock l(m_initLock);
	if (!m_haveInit) {
		PyGILState_STATE old_state;
		if (Py_IsInitialized())
			old_state = PyGILState_Ensure();
		else {
			Py_Initialize();
			old_state = PyGILState_UNLOCKED;
		}
		PyEval_InitThreads();
	
		if (!g_IsFrozen) {
			TCHAR *dll_path = GetModulePath();
			AddToPythonPath(dll_path);
			free(dll_path);
			PyErr_Clear();
			}
	
		// isapidllhandle to match dllhandle, frozendllhandle, etc :)  Also a 
		// nice way for a program to know they are in an ISAPI context.
		PyObject *obh = PyLong_FromVoidPtr(g_hInstance);
		PySys_SetObject("isapidllhandle", obh);
		Py_XDECREF(obh);
		// Locate the special exception we use to trigger a reload.
		PyObject *isapi_package = PyImport_ImportModule("isapi");
		if (isapi_package)
			m_reload_exception = PyObject_GetAttrString(isapi_package,
			                             "InternalReloadException");
		Py_XDECREF(isapi_package);

		// ready our types.
		InitExtensionTypes();
		InitFilterTypes();

		PyGILState_Release(old_state);
		FindModuleName();
		m_haveInit = true;
	}
	return true;
}
示例#24
0
    PyMODINIT_FUNC
    initrtaudio(void) 
    {
        PyEval_InitThreads();

        if (PyType_Ready(&RtAudio_type) < 0)
            return;

        PyObject* module = Py_InitModule3("rtaudio", NULL, "RtAudio wrapper.");
        if (module == NULL)
            return;

        Py_INCREF(&RtAudio_type);
        PyModule_AddObject(module, "RtAudio", (PyObject *)&RtAudio_type);

        RtAudioError = PyErr_NewException("rtaudio.RtError", NULL, NULL);
        Py_INCREF(RtAudioError);
        PyModule_AddObject(module, "RtError", RtAudioError);
    }
示例#25
0
/* Initialize yade, loading given plugins */
void yadeInitialize(boost::python::list& pp, const std::string& confDir){

	PyEval_InitThreads();

	Omega& O(Omega::instance());
	O.init();
	O.origArgv=NULL; O.origArgc=0; // not needed, anyway
	O.confDir=confDir;
	O.initTemps();
	#ifdef YADE_DEBUG
		ofstream gdbBatch;
		O.gdbCrashBatch=O.tmpFilename();
		gdbBatch.open(O.gdbCrashBatch.c_str()); gdbBatch<<"attach "<<boost::lexical_cast<string>(getpid())<<"\nset pagination off\nthread info\nthread apply all backtrace\ndetach\nquit\n"; gdbBatch.close();
		signal(SIGABRT,crashHandler);
		signal(SIGSEGV,crashHandler);
	#endif
	vector<string> ppp; for(int i=0; i<boost::python::len(pp); i++) ppp.push_back(boost::python::extract<string>(pp[i]));
	Omega::instance().loadPlugins(ppp);
}
示例#26
0
PyMODINIT_FUNC initlibpy_myqtt_tls_10 (void)
{
	PyObject * module;

	/* call to initilize threading API and to acquire the lock */
	PyEval_InitThreads();

	/* register myqtt module */
	module = Py_InitModule3 ("libpy_myqtt_tls_10", py_myqtt_tls_methods, 
				 "MQTT LTS Support for MyQtt");
	if (module == NULL) {
		py_myqtt_log (PY_MYQTT_CRITICAL, "failed to create tls module");
		return;
	} /* end if */

	py_myqtt_log (PY_MYQTT_DEBUG, "Tls module started");

	return;
}
示例#27
0
//-------------------------------------------------------------------------
// Initialize the Python environment
bool HexraysPython_Init(void)
{
    // Already initialized?
    if ( g_initialized  )
        return true;

    if( !init_hexrays_plugin(0) ) {
        hexdsp = NULL;
        return false;
    }

    {
        const char *hxver = get_hexrays_version();
        msg("hexrays-python: Hex-rays version %s has been detected\n", hxver);
    }

#ifdef Py_DEBUG
    msg("HexraysPython: Python compiled with DEBUG enabled.\n");
#endif

    // Start the interpreter
    Py_Initialize();

    if ( !Py_IsInitialized() )
    {
        warning("hexrays-python: Py_Initialize() failed");
        return false;
    }

    // Enable multi-threading support
    if ( !PyEval_ThreadsInitialized() )
        PyEval_InitThreads();

    // Init the SWIG wrapper
    init_hexrays();

    // Import hexrays in python the dirty way until we can do better.
    PyRun_SimpleString("import hexrays; from hexrays import *;");

    g_initialized = true;

    return true;
}
示例#28
0
void
python_env_init(void)
{
    Py_Initialize();
    PyEval_InitThreads();
    python_api_init();

    GString *path = g_string_new("import sys\n");
    g_string_append(path, "sys.path.append(\"");
    gchar *plugins_dir = plugins_get_dir();
    g_string_append(path, plugins_dir);
    g_free(plugins_dir);
    g_string_append(path, "/\")\n");

    PyRun_SimpleString(path->str);

    g_string_free(path, TRUE);
    allow_python_threads();
}
示例#29
0
void PythonEngine::init()
{
    m_isScriptRunning = false;
    m_isExpressionRunning = false;

    // init python
    PyEval_InitThreads();
    Py_Initialize();

    // args
    /// \todo Better
    int argc = 1;
    char ** argv = new char*[1];
    argv[0] = new char[1]();
    PySys_SetArgv(argc, argv);
    delete [] argv[0];
    delete [] argv;

    // read pythonlab functions
    addFunctions(readFileContent(datadir() + "/resources/python/functions_pythonlab.py"));
    addCustomFunctions();

    // m_dict = PyDict_New();
    // PyDict_SetItemString(m_dict, "__builtins__", PyEval_GetBuiltins());

    PyObject *main = PyImport_ImportModule("__main__");
    Py_INCREF(main);
    m_dict = PyModule_GetDict(main);
    Py_INCREF(m_dict);

    // init engine extensions
    Py_InitModule("pythonlab", pythonEngineFuntions);

    addCustomExtensions();

    // custom modules
    PyObject *import = PyRun_String(QString("import sys; sys.path.insert(0, \"" + datadir() + "/resources/python" + "\")").toLatin1().data(), Py_file_input, m_dict, m_dict);
    Py_XDECREF(import);

    // functions.py
    PyObject *func = PyRun_String(m_functions.toLatin1().data(), Py_file_input, m_dict, m_dict);
    Py_XDECREF(func);
}
示例#30
0
文件: jcc.cpp 项目: ahua/java
static void _PythonVM_init(JNIEnv *vm_env, jobject self,
                           jstring programName, jobjectArray args)
{
    const char *str = vm_env->GetStringUTFChars(programName, JNI_FALSE);
#ifdef linux
    char buf[32];

    // load python runtime for other .so modules to link (such as _time.so)
    sprintf(buf, "libpython%d.%d.so", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    dlopen(buf, RTLD_NOW | RTLD_GLOBAL);
#endif

    Py_SetProgramName((char *) str);

    PyEval_InitThreads();
    Py_Initialize();

    if (args)
    {
        int argc = vm_env->GetArrayLength(args);
        char **argv = (char **) calloc(argc + 1, sizeof(char *));

        argv[0] = (char *) str;
        for (int i = 0; i < argc; i++) {
            jstring arg = (jstring) vm_env->GetObjectArrayElement(args, i);
            argv[i + 1] = (char *) vm_env->GetStringUTFChars(arg, JNI_FALSE);
        }

        PySys_SetArgv(argc + 1, argv);

        for (int i = 0; i < argc; i++) {
            jstring arg = (jstring) vm_env->GetObjectArrayElement(args, i);
            vm_env->ReleaseStringUTFChars(arg, argv[i + 1]);
        }
        free(argv);
    }
    else
        PySys_SetArgv(1, (char **) &str);

    vm_env->ReleaseStringUTFChars(programName, str);
    PyEval_ReleaseLock();
}