static void t_bootstrap(void *boot_raw) { struct bootstate *boot = (struct bootstate *) boot_raw; PyThreadState *tstate; PyObject *res; tstate = PyThreadState_New(boot->interp); PyEval_AcquireThread(tstate); res = PyEval_CallObjectWithKeywords( boot->func, boot->args, boot->keyw); Py_DECREF(boot->func); Py_DECREF(boot->args); Py_XDECREF(boot->keyw); PyMem_DEL(boot_raw); if (res == NULL) { if (PyErr_ExceptionMatches(PyExc_SystemExit)) PyErr_Clear(); else { PySys_WriteStderr("Unhandled exception in thread:\n"); PyErr_PrintEx(0); } } else Py_DECREF(res); PyThreadState_Clear(tstate); PyThreadState_DeleteCurrent(); PyThread_exit_thread(); }
static PyObject * Exclusion_Any_Obj(void) { PyObject *py_o, *py_kwds; int r; assert(g_type_Name); py_kwds = PyDict_New(); JUMP_IF_NULL(py_kwds, error); py_o = PyLong_FromLong(NAME_TYPE_ANY); JUMP_IF_NULL(py_o, error); r = PyDict_SetItemString(py_kwds, "name_type", py_o); Py_DECREF(py_o); JUMP_IF_NEG(r, error); py_o = PyEval_CallObjectWithKeywords(g_type_Name, NULL, py_kwds); Py_CLEAR(py_kwds); return py_o; error: Py_XDECREF(py_kwds); return NULL; }
static PyObject * wrap_call(PyObject *self, PyObject *args, PyObject *kw) { if (kw) return PyEval_CallObjectWithKeywords(Proxy_GET_OBJECT(self), args, kw); else return PyObject_CallObject(Proxy_GET_OBJECT(self), args); }
int PlayerObject::setPlaying(bool playing) { PlayerObject* player = this; bool oldplayingstate = false; PyScopedGIL gil; { PyScopedGIUnlock gunlock; player->workerThread.start(); // if not running yet, start if(!player->outStream.get()) player->outStream.reset(new OutStream(this)); assert(player->outStream.get() != NULL); if(soundcardOutputEnabled) { if(playing && !player->outStream->stream) { if(!player->outStream->open()) playing = false; } } oldplayingstate = player->playing; if(soundcardOutputEnabled && player->outStream.get() && player->outStream->isOpen() && oldplayingstate != playing) fader.init(playing ? 1 : -1, outSamplerate); player->playing = playing; } if(!PyErr_Occurred() && player->dict) { Py_INCREF(player->dict); PyObject* onPlayingStateChange = PyDict_GetItemString(player->dict, "onPlayingStateChange"); if(onPlayingStateChange && onPlayingStateChange != Py_None) { Py_INCREF(onPlayingStateChange); PyObject* kwargs = PyDict_New(); assert(kwargs); PyDict_SetItemString_retain(kwargs, "oldState", PyBool_FromLong(oldplayingstate)); PyDict_SetItemString_retain(kwargs, "newState", PyBool_FromLong(playing)); PyObject* retObj = PyEval_CallObjectWithKeywords(onPlayingStateChange, NULL, kwargs); Py_XDECREF(retObj); // errors are not fatal from the callback, so handle it now and go on if(PyErr_Occurred()) PyErr_Print(); Py_DECREF(kwargs); Py_DECREF(onPlayingStateChange); } Py_DECREF(player->dict); } return PyErr_Occurred() ? -1 : 0; }
int python_client_script(const std::string & package, const std::string & func, const std::map<std::string, std::string> & keywords) { PyObject * module = Get_PyModule(package); if (module == NULL) { return -1; } PyObject * function = PyObject_GetAttrString(module, (char *)func.c_str()); Py_DECREF(module); if (function == NULL) { std::cerr << "Could not find " << func << " function" << std::endl << std::flush; PyErr_Print(); return -1; } if (PyCallable_Check(function) == 0) { std::cerr << "It does not seem to be a function at all" << std::endl << std::flush; Py_DECREF(function); return -1; } PyObject * args = Py_BuildValue("()"); PyObject * kwds = PyDict_New(); std::map<std::string, std::string>::const_iterator I = keywords.begin(); std::map<std::string, std::string>::const_iterator Iend = keywords.end(); for (; I != Iend; ++I) { PyObject * v = PyString_FromString(I->second.c_str()); PyDict_SetItemString(kwds, I->first.c_str(), v); Py_DECREF(v); } PyObject * pyob = PyEval_CallObjectWithKeywords(function, args, kwds); Py_DECREF(kwds); Py_DECREF(args); if (pyob == NULL) { if (PyErr_Occurred() == NULL) { std::cerr << "Could not call function" << std::endl << std::flush; } else { std::cerr << "Reporting python error" << std::endl << std::flush; PyErr_Print(); } } Py_DECREF(function); return 0; }
static PyObject * classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds) { STACKLESS_GETARG(); PyObject *func, *result; func = PyCFunction_New(descr->d_method, (PyObject *)descr->d_type); if (func == NULL) return NULL; STACKLESS_PROMOTE_ALL(); result = PyEval_CallObjectWithKeywords(func, args, kwds); STACKLESS_ASSERT(); Py_DECREF(func); return result; }
static PyObject * wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds) { STACKLESS_GETARG(); Py_ssize_t argc; PyObject *self, *func, *result; /* Make sure that the first argument is acceptable as 'self' */ assert(PyTuple_Check(args)); argc = PyTuple_GET_SIZE(args); if (argc < 1) { PyErr_Format(PyExc_TypeError, "descriptor '%.300s' of '%.100s' " "object needs an argument", descr_name((PyDescrObject *)descr), descr->d_type->tp_name); return NULL; } self = PyTuple_GET_ITEM(args, 0); if (!PyObject_IsInstance(self, (PyObject *)(descr->d_type))) { PyErr_Format(PyExc_TypeError, "descriptor '%.200s' " "requires a '%.100s' object " "but received a '%.100s'", descr_name((PyDescrObject *)descr), descr->d_type->tp_name, self->ob_type->tp_name); return NULL; } func = PyWrapper_New((PyObject *)descr, self); if (func == NULL) return NULL; args = PyTuple_GetSlice(args, 1, argc); if (args == NULL) { Py_DECREF(func); return NULL; } STACKLESS_PROMOTE_ALL(); result = PyEval_CallObjectWithKeywords(func, args, kwds); STACKLESS_ASSERT(); Py_DECREF(args); Py_DECREF(func); return result; }
static void t_bootstrap(void *boot_raw) { struct bootstate *boot = (struct bootstate *) boot_raw; PyThreadState *tstate; PyObject *res; tstate = boot->tstate; tstate->thread_id = PyThread_get_thread_ident(); _PyThreadState_Init(tstate); PyEval_AcquireThread(tstate); res = PyEval_CallObjectWithKeywords( boot->func, boot->args, boot->keyw); if (res == NULL) { if (PyErr_ExceptionMatches(PyExc_SystemExit)) PyErr_Clear(); else { PyObject *file; PySys_WriteStderr( "Unhandled exception in thread started by "); file = PySys_GetObject("stderr"); if (file != NULL && file != Py_None) PyFile_WriteObject(boot->func, file, 0); else PyObject_Print(boot->func, stderr, 0); PySys_WriteStderr("\n"); PyErr_PrintEx(0); } } else Py_DECREF(res); Py_DECREF(boot->func); Py_DECREF(boot->args); Py_XDECREF(boot->keyw); PyMem_DEL(boot_raw); PyThreadState_Clear(tstate); PyThreadState_DeleteCurrent(); PyThread_exit_thread(); }
/** * As freeswitch runs with a smaller than normal stack size (240K instead of the usual value .. 1 or 2 MB), * we must decrease the default python recursion limit accordingly. Otherwise, python can easily blow * up the stack and the whole switch crashes. See modlang-134 */ static void set_max_recursion_depth(void) { // assume that a stack frame is approximately 1K, so divide thread stack size (eg, 240K) by // 1K to get the approx number of stack frames we can hold before blowing up. int newMaxRecursionDepth = SWITCH_THREAD_STACKSIZE / 1024; PyObject *sysModule = PyImport_ImportModule("sys"); PyObject *setRecursionLimit = PyObject_GetAttrString(sysModule, "setrecursionlimit"); PyObject *recLimit = Py_BuildValue("(i)", newMaxRecursionDepth); PyObject *setrecursion_result = PyEval_CallObjectWithKeywords(setRecursionLimit, recLimit, (PyObject *) NULL); if (setrecursion_result) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set python recursion limit to %d\n", newMaxRecursionDepth); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set recursion limit to %d\n", newMaxRecursionDepth); PyErr_Print(); PyErr_Clear(); PyRun_SimpleString("python_makes_sense"); PyGC_Collect(); } }
static int GREENLET_NOINLINE(g_initialstub)(void* mark) { int err; PyObject *o, *run; PyObject *exc, *val, *tb; PyObject *run_info; PyGreenlet* self = ts_target; PyObject* args = ts_passaround_args; PyObject* kwargs = ts_passaround_kwargs; /* save exception in case getattr clears it */ PyErr_Fetch(&exc, &val, &tb); /* self.run is the object to call in the new greenlet */ run = PyObject_GetAttrString((PyObject*) self, "run"); if (run == NULL) { Py_XDECREF(exc); Py_XDECREF(val); Py_XDECREF(tb); return -1; } /* restore saved exception */ PyErr_Restore(exc, val, tb); /* recheck the state in case getattr caused thread switches */ if (!STATE_OK) { Py_DECREF(run); return -1; } /* recheck run_info in case greenlet reparented anywhere above */ run_info = green_statedict(self); if (run_info == NULL || run_info != ts_current->run_info) { Py_DECREF(run); PyErr_SetString(PyExc_GreenletError, run_info ? "cannot switch to a different thread" : "cannot switch to a garbage collected greenlet"); return -1; } /* by the time we got here another start could happen elsewhere, * that means it should now be a regular switch */ if (PyGreenlet_STARTED(self)) { Py_DECREF(run); ts_passaround_args = args; ts_passaround_kwargs = kwargs; return 1; } /* start the greenlet */ self->stack_start = NULL; self->stack_stop = (char*) mark; if (ts_current->stack_start == NULL) { /* ts_current is dying */ self->stack_prev = ts_current->stack_prev; } else { self->stack_prev = ts_current; } self->top_frame = NULL; self->exc_type = NULL; self->exc_value = NULL; self->exc_traceback = NULL; self->recursion_depth = PyThreadState_GET()->recursion_depth; /* restore arguments in case they are clobbered */ ts_target = self; ts_passaround_args = args; ts_passaround_kwargs = kwargs; /* perform the initial switch */ err = g_switchstack(); /* returns twice! The 1st time with err=1: we are in the new greenlet The 2nd time with err=0: back in the caller's greenlet */ if (err == 1) { /* in the new greenlet */ PyGreenlet* origin; #if GREENLET_USE_TRACING PyObject* tracefunc; #endif PyObject* result; PyGreenlet* parent; self->stack_start = (char*) 1; /* running */ /* grab origin while we still can */ origin = ts_origin; ts_origin = NULL; /* now use run_info to store the statedict */ o = self->run_info; self->run_info = green_statedict(self->parent); Py_INCREF(self->run_info); Py_XDECREF(o); #if GREENLET_USE_TRACING if ((tracefunc = PyDict_GetItem(self->run_info, ts_tracekey)) != NULL) { Py_INCREF(tracefunc); if (g_calltrace(tracefunc, args ? ts_event_switch : ts_event_throw, origin, self) < 0) { /* Turn trace errors into switch throws */ Py_CLEAR(kwargs); Py_CLEAR(args); } Py_DECREF(tracefunc); } #endif Py_DECREF(origin); if (args == NULL) { /* pending exception */ result = NULL; } else { /* call g.run(*args, **kwargs) */ result = PyEval_CallObjectWithKeywords( run, args, kwargs); Py_DECREF(args); Py_XDECREF(kwargs); } Py_DECREF(run); result = g_handle_exit(result); /* jump back to parent */ self->stack_start = NULL; /* dead */ for (parent = self->parent; parent != NULL; parent = parent->parent) { result = g_switch(parent, result, NULL); /* Return here means switch to parent failed, * in which case we throw *current* exception * to the next parent in chain. */ assert(result == NULL); } /* We ran out of parents, cannot continue */ PyErr_WriteUnraisable((PyObject *) self); Py_FatalError("greenlets cannot continue"); } /* back in the parent */ if (err < 0) { /* start failed badly, restore greenlet state */ self->stack_start = NULL; self->stack_stop = NULL; self->stack_prev = NULL; } return err; }
static foreign_t python_apply(term_t tin, term_t targs, term_t keywds, term_t tf) { PyObject *pF; PyObject *pArgs, *pKeywords; PyObject *pValue; int i, arity; atom_t aname; foreign_t out; term_t targ = PL_new_term_ref(); pF = term_to_python(tin, true); PyErr_Clear(); if (pF == NULL) { { return false; } } if (PL_is_atom(targs)) { pArgs = NULL; } else { if (!PL_get_name_arity(targs, &aname, &arity)) { { return false; } } if (arity == 1 && PL_get_arg(1, targs, targ) && PL_is_variable(targ)) { /* ignore (_) */ pArgs = NULL; } else { pArgs = PyTuple_New(arity); if (!pArgs) { return false; } for (i = 0; i < arity; i++) { PyObject *pArg; if (!PL_get_arg(i + 1, targs, targ)) { return false; } pArg = term_to_python(targ, true); if (pArg == NULL) { return false; } /* pArg reference stolen here: */ PyTuple_SetItem(pArgs, i, pArg); } } } if (PL_is_atom(keywds)) { pKeywords = NULL; } else { pKeywords = term_to_python(keywds, true); } if (PyCallable_Check(pF)) { pValue = PyEval_CallObjectWithKeywords(pF, pArgs, pKeywords); // PyObject_Print(pF,stderr,0);fprintf(stderr, "\n"); // PyObject_Print(pArgs,stderr,0);fprintf(stderr, " "); // PyObject_Print(pKeywords,stderr,0);fprintf(stderr, "\n"); if (!pValue) PyErr_Print(); else Py_IncRef(pValue); } else if (pArgs == NULL) { pValue = pF; if (pF) { Py_IncRef(pValue); } } else { PyErr_Print(); { return false; } } if (pArgs) Py_DECREF(pArgs); Py_DECREF(pF); if (pValue == NULL) { return false; } out = python_to_ptr(pValue, tf); return out; }
int launch_py_user_action(PyVCScanvas_Object *self, #ifdef X11WM Window window, XEvent event, #elif defined (QTWM) QEvent event, #endif struct data_point info, int ipoint[2]) { #ifdef X11WM Window parent; #endif int x,y,w,h,bw,dpth; int line; PyObject *canvas, *funcs, *func, *args, *kargs, *kval; #ifdef X11WM XGetGeometry(self->connect_id.display,window,&parent,&x,&y,&w,&h,&bw,&dpth) ; #elif defined (QTWM) vcs_legacy_Qt_get_window_dimensions_by_id(self->connect_id.wkst_id,&x,&y,&w,&h); #else fprintf(stderr,"insert here your WM getgeometry function\n"); #endif if ((x<BUTTON_X) && (BUTTON_X<x+w) && (y<BUTTON_Y) && (BUTTON_Y<y+h)) { PY_ENTER_THREADS; PY_GRAB_THREAD; canvas = getPyCanvas( self->canvas_id ); kargs = PyDict_New(); if (info.x!=-999.) { kval = Py_BuildValue("d",info.x); } else { Py_INCREF(Py_None); kval = Py_None; } PyDict_SetItemString(kargs,"datawc_x",kval); Py_DECREF(kval); if (info.y!=-999.) { kval = Py_BuildValue("d",info.y); } else { Py_INCREF(Py_None); kval = Py_None; } PyDict_SetItemString(kargs,"datawc_y",kval); Py_DECREF(kval); if (info.value!=-999.) { kval = Py_BuildValue("d",info.value); } else { Py_INCREF(Py_None); kval = Py_None; } PyDict_SetItemString(kargs,"value",kval); Py_DECREF(kval); if (info.value2!=-999.) { kval = Py_BuildValue("d",info.value2); } else { Py_INCREF(Py_None); kval = Py_None; } PyDict_SetItemString(kargs,"value2",kval); Py_DECREF(kval); if (info.x_index!=-999) { kval = Py_BuildValue("i",info.x_index); } else { Py_INCREF(Py_None); kval = Py_None; } PyDict_SetItemString(kargs,"index_x",kval); Py_DECREF(kval); if (info.y_index!=-999) { kval = Py_BuildValue("i",info.y_index); } else { Py_INCREF(Py_None); kval = Py_None; } PyDict_SetItemString(kargs,"index_y",kval); Py_DECREF(kval); if (info.color!=-999.) { kval = Py_BuildValue("i",info.color); } else { Py_INCREF(Py_None); kval = Py_None; } PyDict_SetItemString(kargs,"color",kval); Py_DECREF(kval); kval = Py_BuildValue("i",ipoint[0]); PyDict_SetItemString(kargs,"XW_x",kval); Py_DECREF(kval); kval = Py_BuildValue("i",ipoint[1]); PyDict_SetItemString(kargs,"XW_y",kval); Py_DECREF(kval); PyDict_SetItemString(kargs,"canvas",canvas); funcs = PyObject_GetAttrString(canvas,"user_actions_names"); if (PyList_Check(funcs)) { line = (BUTTON_Y-y)*PyList_Size(funcs)/h; } else line=1; Py_DECREF(funcs); /* Set the line number as argument */ args = Py_BuildValue("()",line); /* following is for direct call of func */ funcs = PyObject_GetAttrString(canvas,"user_actions"); /* decref ? */ if (PyList_Check(funcs)) { func = PyList_GetItem(funcs,line); if (PyCallable_Check(func)) { PY_RELEASE_THREAD; PY_LEAVE_THREADS; PY_ENTER_THREADS; PY_GRAB_THREAD; kval = PyEval_CallObjectWithKeywords(func,args,kargs); Py_DECREF(kargs); Py_DECREF(args); Py_XDECREF(kval); PY_RELEASE_THREAD; PY_LEAVE_THREADS; } else { PY_RELEASE_THREAD PY_LEAVE_THREADS return 1; } } else {
NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, struct provision_settings *settings, struct provision_result *result) { char *configfile; PyObject *provision_mod, *provision_dict, *provision_fn, *py_result, *parameters; DEBUG(0,("Provision for Become-DC test using python\n")); py_load_samba_modules(); Py_Initialize(); py_update_path("bin"); /* FIXME: Can't assume this is always the case */ provision_mod = PyImport_Import(PyString_FromString("samba.provision")); if (provision_mod == NULL) { PyErr_Print(); DEBUG(0, ("Unable to import provision Python module.\n")); return NT_STATUS_UNSUCCESSFUL; } provision_dict = PyModule_GetDict(provision_mod); if (provision_dict == NULL) { DEBUG(0, ("Unable to get dictionary for provision module\n")); return NT_STATUS_UNSUCCESSFUL; } provision_fn = PyDict_GetItemString(provision_dict, "provision_become_dc"); if (provision_fn == NULL) { PyErr_Print(); DEBUG(0, ("Unable to get provision_become_dc function\n")); return NT_STATUS_UNSUCCESSFUL; } DEBUG(0,("New Server in Site[%s]\n", settings->site_name)); DEBUG(0,("DSA Instance [%s]\n" "\tinvocationId[%s]\n", settings->ntds_dn_str, settings->invocation_id == NULL?"None":GUID_string(mem_ctx, settings->invocation_id))); DEBUG(0,("Pathes under targetdir[%s]\n", settings->targetdir)); parameters = PyDict_New(); configfile = lp_configfile(lp_ctx); if (configfile != NULL) { PyDict_SetItemString(parameters, "smbconf", PyString_FromString(configfile)); } PyDict_SetItemString(parameters, "rootdn", PyString_FromString(settings->root_dn_str)); if (settings->targetdir != NULL) PyDict_SetItemString(parameters, "targetdir", PyString_FromString(settings->targetdir)); PyDict_SetItemString(parameters, "setup_dir", PyString_FromString("setup")); PyDict_SetItemString(parameters, "hostname", PyString_FromString(settings->netbios_name)); PyDict_SetItemString(parameters, "domain", PyString_FromString(settings->domain)); PyDict_SetItemString(parameters, "realm", PyString_FromString(settings->realm)); if (settings->root_dn_str) PyDict_SetItemString(parameters, "rootdn", PyString_FromString(settings->root_dn_str)); if (settings->domain_dn_str) PyDict_SetItemString(parameters, "domaindn", PyString_FromString(settings->domain_dn_str)); if (settings->schema_dn_str) PyDict_SetItemString(parameters, "schemadn", PyString_FromString(settings->schema_dn_str)); if (settings->config_dn_str) PyDict_SetItemString(parameters, "configdn", PyString_FromString(settings->config_dn_str)); if (settings->server_dn_str) PyDict_SetItemString(parameters, "serverdn", PyString_FromString(settings->server_dn_str)); if (settings->site_name) PyDict_SetItemString(parameters, "sitename", PyString_FromString(settings->site_name)); PyDict_SetItemString(parameters, "machinepass", PyString_FromString(settings->machine_password)); py_result = PyEval_CallObjectWithKeywords(provision_fn, NULL, parameters); Py_DECREF(parameters); if (py_result == NULL) { PyErr_Print(); PyErr_Clear(); return NT_STATUS_UNSUCCESSFUL; } result->domaindn = talloc_strdup(mem_ctx, PyString_AsString(PyObject_GetAttrString(py_result, "domaindn"))); /* FIXME paths */ result->lp_ctx = lp_from_py_object(PyObject_GetAttrString(py_result, "lp")); result->samdb = PyLdb_AsLdbContext(PyObject_GetAttrString(py_result, "samdb")); return NT_STATUS_OK; }
int PlayerObject::setPlaying(bool playing) { PlayerObject* player = this; bool oldplayingstate = false; PyScopedGIL gil; { PyScopedGIUnlock gunlock; player->workerThread.start(); // if not running yet, start if(!player->outStream.get()) player->outStream.reset(new OutStream(this)); assert(player->outStream.get() != NULL); if(playing && !player->outStream->stream) { PaError ret; ret = Pa_OpenDefaultStream( &player->outStream->stream, 0, player->outNumChannels, // numOutputChannels paInt16, // sampleFormat player->outSamplerate, // sampleRate AUDIO_BUFFER_SIZE / 2, // framesPerBuffer, &paStreamCallback, player //void *userData ); if(ret != paNoError) { PyErr_SetString(PyExc_RuntimeError, "Pa_OpenDefaultStream failed"); if(player->outStream->stream) player->outStream->close(); playing = 0; } } if(playing) { player->needRealtimeReset = 1; Pa_StartStream(player->outStream->stream); } else player->outStream->stop(); oldplayingstate = player->playing; player->playing = playing; } if(!PyErr_Occurred() && player->dict) { Py_INCREF(player->dict); PyObject* onPlayingStateChange = PyDict_GetItemString(player->dict, "onPlayingStateChange"); if(onPlayingStateChange && onPlayingStateChange != Py_None) { Py_INCREF(onPlayingStateChange); PyObject* kwargs = PyDict_New(); assert(kwargs); PyDict_SetItemString_retain(kwargs, "oldState", PyBool_FromLong(oldplayingstate)); PyDict_SetItemString_retain(kwargs, "newState", PyBool_FromLong(playing)); PyObject* retObj = PyEval_CallObjectWithKeywords(onPlayingStateChange, NULL, kwargs); Py_XDECREF(retObj); // errors are not fatal from the callback, so handle it now and go on if(PyErr_Occurred()) PyErr_Print(); Py_DECREF(kwargs); Py_DECREF(onPlayingStateChange); } Py_DECREF(player->dict); } return PyErr_Occurred() ? -1 : 0; }
static void eval_some_python(const char *funcname, char *args, switch_core_session_t *session, switch_stream_handle_t *stream, switch_event_t *params, char **str, struct switch_py_thread *pt) { PyThreadState *tstate = NULL; char *dupargs = NULL; char *argv[2] = { 0 }; int argc; char *script = NULL; PyObject *module = NULL, *sp = NULL, *stp = NULL, *eve = NULL; PyObject *function = NULL; PyObject *arg = NULL; PyObject *result = NULL; char *p; if (str) { *str = NULL; } if (args) { dupargs = strdup(args); } else { return; } assert(dupargs != NULL); if (!(argc = switch_separate_string(dupargs, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No module name specified!\n"); goto done; } script = strdup(switch_str_nil(argv[0])); if ((p = strstr(script, "::"))) { *p = '\0'; p += 2; if (p) { funcname = p; } } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Invoking py module: %s\n", script); tstate = PyThreadState_New(mainThreadState->interp); if (!tstate) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error acquiring tstate\n"); goto done; } /* Save state in thread struct so we can terminate it later if needed */ if (pt) pt->tstate = tstate; // swap in thread state PyEval_AcquireThread(tstate); init_freeswitch(); // import the module module = PyImport_ImportModule((char *) script); if (!module) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error importing module\n"); PyErr_Print(); PyErr_Clear(); goto done_swap_out; } // reload the module module = PyImport_ReloadModule(module); if (!module) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error reloading module\n"); PyErr_Print(); PyErr_Clear(); goto done_swap_out; } // get the handler function to be called function = PyObject_GetAttrString(module, (char *) funcname); if (!function) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Module does not define %s\n", funcname); PyErr_Print(); PyErr_Clear(); goto done_swap_out; } if (session) { sp = mod_python_conjure_session(module, session); } if (params) { eve = mod_python_conjure_event(params); } if (stream) { stp = mod_python_conjure_stream(stream); if (stream->param_event) { eve = mod_python_conjure_event(stream->param_event); } } if (sp && eve && stp) { arg = Py_BuildValue("(OOOs)", sp, stp, eve, switch_str_nil(argv[1])); } else if (eve && stp) { arg = Py_BuildValue("(sOOs)", "na", stp, eve, switch_str_nil(argv[1])); } else if (eve) { arg = Py_BuildValue("(Os)", eve, switch_str_nil(argv[1])); } else if (sp) { arg = Py_BuildValue("(Os)", sp, switch_str_nil(argv[1])); } else { arg = Py_BuildValue("(s)", switch_str_nil(argv[1])); } // invoke the handler switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call python script \n"); result = PyEval_CallObjectWithKeywords(function, arg, (PyObject *) NULL); Py_DECREF(function); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Finished calling python script \n"); // check the result and print out any errors if (result) { if (str) { *str = strdup((char *) PyString_AsString(result)); } } else if (!PyErr_ExceptionMatches(PyExc_SystemExit)) { // Print error, but ignore SystemExit switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error calling python script\n"); PyErr_Print(); PyErr_Clear(); PyRun_SimpleString("python_makes_sense"); PyGC_Collect(); } done_swap_out: if (arg) { Py_DECREF(arg); } if (sp) { Py_DECREF(sp); } if (tstate) { // thread state must be cleared explicitly or we'll get memory leaks PyThreadState_Clear(tstate); PyEval_ReleaseThread(tstate); PyThreadState_Delete(tstate); } done: switch_safe_free(dupargs); switch_safe_free(script); }
PyObject * PyEval_CallObject(PyObject *func, PyObject *arg) { return PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL); }
// python_apply implements the function call: // (python-apply ("module.submodule" 'obj 'func) // (arg1 arg2 arg3) // (('keyword1 . val4) ('keyword2 . val5)) // sargtemplate // skwtemplate) // which is the basic way to invoke a Python function. // // sfunc specifies the function to be invoked. The possibilities // are: // String - denotes a top level function ("func" means __main__.func). // pysmob - assumed to be a callable object. // ("module.submodule" ...) - a List of strings/symbols/keywords // in which the first item must be a string denotes: // Module "module.submodule" (which should have already been imported // using python-import) // followed by name of object in that module, followed by attribute,..., // until the final callable attribute. // (pysmob ...) - a List starting with pysmob followed by // strings/symbols/keywords - processed similarly, except that the // pysmob stands for the module. // sarg is a list of arguments (in Python it's *arg) // skw is an alist (in Python it's **kw). // sargtemplate - specifies how to convert sarg - optional argument. // skwtemplate - specifies how to convert skw - optional argument. // srestemplate - specifies how to convert the result back into // SCM - optional argument. SCM python_apply(SCM sfunc, SCM sarg, SCM skw, SCM sargtemplate, SCM skwtemplate, SCM srestemplate) { PyObject *pfunc = NULL; PyObject *parg = NULL; PyObject *pkw = NULL; PyObject *pfuncobj = NULL; PyObject *pres = NULL; SCM sres = SCM_UNDEFINED; if (SCM_UNBNDP(sargtemplate)) { //(sargtemplate == SCM_UNDEFINED) // SCM_UNSPECIFIED sargtemplate = sargtemplate_default; } if (SCM_UNBNDP(skwtemplate)) { skwtemplate = skwtemplate_default; } if (SCM_UNBNDP(srestemplate)) { srestemplate = srestemplate_default; } // Retrieve the function object. pfunc = guile2python(sfunc,SCM_UNSPECIFIED); if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYTHON_APPLY)) { char *preprfunc = PyString_AsString(PyObject_Repr(pfunc)); scm_simple_format(scm_current_output_port(),scm_makfrom0str("# python_apply: decoded pfunc ~S\n"),scm_list_1(scm_makfrom0str(preprfunc))); } if (NULL == pfunc) { scm_misc_error("python-apply","conversion failure (~S)", scm_list_1(SCM_CDR(sfunc))); } // If it is a string, prepend it with "__main__". if (PyString_CheckExact(pfunc)) { // Convert it into a List of two items, to unify // subsequent treatment. PyObject *plist = PyList_New(2); if (NULL == plist) { Py_DECREF(pfunc); // NOT COVERED BY TESTS scm_memory_error("python-apply"); // NOT COVERED BY TESTS } if (-1 == PyList_SetItem(plist,0,PyString_FromString("__main__"))) { Py_DECREF(pfunc); // NOT COVERED BY TESTS Py_DECREF(plist); // NOT COVERED BY TESTS scm_misc_error("python-apply","PyList_SetItem 0 failure (~S)", // NOT COVERED BY TESTS scm_list_1(SCM_CAR(sfunc))); } if (-1 == PyList_SetItem(plist,1,pfunc)) { Py_DECREF(pfunc); // NOT COVERED BY TESTS Py_DECREF(plist); // NOT COVERED BY TESTS scm_misc_error("python-apply","PyList_SetItem 1 failure (~S)", // NOT COVERED BY TESTS scm_list_1(SCM_CAR(sfunc))); } pfunc = plist; // plist stole previous pfunc's value's reference. } else if (IS_PYSMOBP(sfunc)) { // We check the SCM object because guile2python() destroys // the indication whether the SCM was originally a pysmob, when it // converts it into PyObject. PyObject *plist1 = PyList_New(1); if (NULL == plist1) { Py_DECREF(pfunc); // NOT COVERED BY TESTS scm_memory_error("python-apply"); // NOT COVERED BY TESTS } if (-1 == PyList_SetItem(plist1,0,pfunc)) { Py_DECREF(pfunc); // NOT COVERED BY TESTS Py_DECREF(plist1); // NOT COVERED BY TESTS scm_misc_error("python-apply","PyList_SetItem 0 failure (~S)", // NOT COVERED BY TESTS scm_list_1(SCM_CAR(sfunc))); } pfunc = plist1; // plist1 stole previous pfunc's value's reference. // Now pfunc is an 1-member list, and this member is // expected to be callable. } else if (!PyList_CheckExact(pfunc)) { // Now, the qualified function name must be a proper list. scm_wrong_type_arg("python-apply",SCM_ARG1,sfunc); } if (1 > PyList_Size(pfunc)) { // The list must consist of at least one callable module name/object. scm_misc_error("python-apply", "first argument must contain at least one callable object (~S)", scm_list_1(SCM_CAR(sfunc))); } if (PyString_CheckExact(PyList_GetItem(pfunc,0))) { // If it is a string, we assume it to be the name of a module // which has already been imported. // Due to the existence of dots, // we don't allow it to be symbol or keyword. pfuncobj = PyImport_AddModule(PyString_AsString(PyList_GetItem(pfunc,0))); if (NULL == pfuncobj) { Py_DECREF(pfunc); scm_misc_error("python-apply", "module ~S could not be accessed - probably not imported", scm_list_1(SCM_CAR(sfunc))); } Py_INCREF(pfuncobj); } else { // We assume that it is a callable or object with attributes. pfuncobj = PyList_GetItem(pfunc,0); if (NULL == pfuncobj) { Py_DECREF(pfunc); scm_misc_error("python-apply", "could not access object starting ~S", scm_list_1(sfunc)); } Py_INCREF(pfuncobj); } // Here we dereference attributes (if any). int listsize = PyList_Size(pfunc); int ind; for (ind = 1; ind < listsize; ++ind) { PyObject *pnextobj = PyObject_GetAttr(pfuncobj,PyList_GetItem(pfunc,ind)); if (NULL == pnextobj) { PyObject *pexception = PyErr_Occurred(); Py_DECREF(pfunc); Py_DECREF(pfuncobj); if (pexception) { PyErr_Clear(); // An AttributeError exception is expected here. if (!PyErr_GivenExceptionMatches(pexception,PyExc_AttributeError)) { PyObject *prepr = PyObject_Repr(pexception); if (NULL == prepr) { scm_misc_error("python-apply", "python exception - could not be identified", SCM_UNSPECIFIED); } else { int strlength = PyString_Size(prepr); char *pstr = PyString_AsString(prepr); SCM srepr = scm_list_1(scm_mem2string(pstr,strlength)); Py_DECREF(prepr); scm_misc_error("python-apply", "Python exception (~A) while dereferencing object attribute", srepr); } } // else we got the expected AttributeError exception. } // else we got NULL==pnextobj without Python exception. scm_misc_error("python-apply", "could not dereference ~Ath level attribute in ~S", scm_list_2(scm_long2num(ind),sfunc)); } Py_INCREF(pnextobj); Py_DECREF(pfuncobj); pfuncobj = pnextobj; } Py_DECREF(pfunc); // We do not need it anymore. pfuncobj points at // the function actually to be invoked. if (!PyCallable_Check(pfuncobj)) { Py_DECREF(pfuncobj); scm_misc_error("python-apply","function denoted by ~S is not callable",scm_list_1(sfunc)); } if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYTHON_APPLY)) { char *preprfuncobj = PyString_AsString(PyObject_Repr(pfuncobj)); scm_simple_format(scm_current_output_port(), scm_makfrom0str("# python_apply: decoded function actually to be invoked: ~S\n"), scm_list_1(scm_makfrom0str(preprfuncobj))); } // Retrieve positional arguments parg = g2p_apply(sarg,sargtemplate); if (NULL == parg) { Py_DECREF(pfuncobj); scm_misc_error("python-apply","positional arguments conversion failure (~S)", scm_list_1(sarg)); } // Validate that it is indeed a tuple. if (!PyTuple_CheckExact(parg)) { Py_DECREF(pfuncobj); Py_DECREF(parg); scm_wrong_type_arg("python-apply",SCM_ARG2,sarg); } if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYTHON_APPLY)) { char *pposarg = PyString_AsString(PyObject_Repr(parg)); scm_simple_format(scm_current_output_port(),scm_makfrom0str("# python_apply: decoded positional arguments ~S\n"),scm_list_1(scm_makfrom0str(pposarg))); } // Retrieve keyword arguments. pkw = guileassoc2pythondict(skw,skwtemplate); if (NULL == pkw) { // Seems that PyDict_CheckExact() does not handle NULL argument gracefully. Py_DECREF(pfuncobj); Py_DECREF(parg); scm_misc_error("python-apply","keyword arguments conversion failure (~S)", scm_list_1(skw)); } if (!PyDict_CheckExact(pkw)) { Py_DECREF(pfuncobj); Py_DECREF(parg); Py_DECREF(pkw); scm_misc_error("python-apply", "keyword arguments (~S) not properly converted into Python Dict", scm_list_1(skw)); } if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYTHON_APPLY)) { char *pkwarg = PyString_AsString(PyObject_Repr(pkw)); scm_simple_format(scm_current_output_port(),scm_makfrom0str("# python_apply: decoded keyword arguments ~S\n"),scm_list_1(scm_makfrom0str(pkwarg))); } // Ready to invoke the function. pres = PyEval_CallObjectWithKeywords(pfuncobj,parg,pkw); PyObject *pexception = PyErr_Occurred(); if (pexception) { PyObject *prepr = PyObject_Repr(pexception); Py_DECREF(pfuncobj); Py_DECREF(parg); Py_DECREF(pkw); Py_XDECREF(pres); PyErr_Clear(); if (NULL == prepr) { scm_misc_error("python-apply", "python exception - could not be identified", SCM_UNSPECIFIED); } else { int strlength = PyString_Size(prepr); char *pstr = PyString_AsString(prepr); SCM srepr = scm_list_1(scm_mem2string(pstr,strlength)); Py_DECREF(prepr); scm_misc_error("python-apply","Python exception: ~A", srepr); } } if (NULL != pres) { sres = p2g_apply(pres,srestemplate); if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYTHON_APPLY)) { char *presstr = PyString_AsString(PyObject_Repr(pres)); scm_simple_format(scm_current_output_port(),scm_makfrom0str("# python_apply: decoded results:\n# Python: ~S\n# Scheme: ~S\n"),scm_list_2(scm_makfrom0str(presstr),sres)); } } else { // else sres remains SCM_UNDEFINED. if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYTHON_APPLY)) { scm_simple_format(scm_current_output_port(),scm_makfrom0str("# python_apply: Python code returned <NULL>\n"),SCM_EOL); } } return(sres); }
static int GREENLET_NOINLINE(g_initialstub)(void* mark) { int err; PyObject *o, *run; PyObject *exc, *val, *tb; PyGreenlet* self = ts_target; PyObject* args = ts_passaround_args; PyObject* kwargs = ts_passaround_kwargs; /* save exception in case getattr clears it */ PyErr_Fetch(&exc, &val, &tb); /* self.run is the object to call in the new greenlet */ run = PyObject_GetAttrString((PyObject*) self, "run"); if (run == NULL) { Py_XDECREF(exc); Py_XDECREF(val); Py_XDECREF(tb); return -1; } /* restore saved exception */ PyErr_Restore(exc, val, tb); /* recheck the state in case getattr caused thread switches */ if (!STATE_OK) { Py_DECREF(run); return -1; } /* by the time we got here another start could happen elsewhere, * that means it should now be a regular switch */ if (PyGreenlet_STARTED(self)) { Py_DECREF(run); ts_passaround_args = args; ts_passaround_kwargs = kwargs; return 1; } /* restore arguments in case they are clobbered */ ts_target = self; ts_passaround_args = args; ts_passaround_kwargs = kwargs; /* now use run_info to store the statedict */ o = self->run_info; self->run_info = green_statedict(self->parent); Py_INCREF(self->run_info); Py_XDECREF(o); /* start the greenlet */ self->stack_start = NULL; self->stack_stop = (char*) mark; if (ts_current->stack_start == NULL) { /* ts_current is dying */ self->stack_prev = ts_current->stack_prev; } else { self->stack_prev = ts_current; } self->top_frame = NULL; self->exc_type = NULL; self->exc_value = NULL; self->exc_traceback = NULL; self->recursion_depth = PyThreadState_GET()->recursion_depth; err = g_switchstack(); /* returns twice! The 1st time with err=1: we are in the new greenlet The 2nd time with err=0: back in the caller's greenlet */ if (err == 1) { /* in the new greenlet */ PyObject* result; PyGreenlet* parent; self->stack_start = (char*) 1; /* running */ if (args == NULL) { /* pending exception */ result = NULL; } else { /* call g.run(*args, **kwargs) */ result = PyEval_CallObjectWithKeywords( run, args, kwargs); Py_DECREF(args); Py_XDECREF(kwargs); } Py_DECREF(run); result = g_handle_exit(result); /* jump back to parent */ self->stack_start = NULL; /* dead */ for (parent = self->parent; parent != NULL; parent = parent->parent) { result = g_switch(parent, result, NULL); /* Return here means switch to parent failed, * in which case we throw *current* exception * to the next parent in chain. */ } /* We ran out of parents, cannot continue */ PyErr_WriteUnraisable((PyObject *) self); Py_FatalError("greenlets cannot continue"); } /* back in the parent */ return err; }
/* Implementation of setup */ static char __pyx_k_4[] = "create_deformation.py"; static char __pyx_k_7[] = "cython_code.pyx"; static char __pyx_k___main__[] = "__main__"; static PyObject *__pyx_kp___main__; static char __pyx_k_1[] = "distutils.core"; static PyObject *__pyx_kp_1; static char __pyx_k_setup[] = "setup"; static PyObject *__pyx_kp_setup; static char __pyx_k_2[] = "distutils.extension"; static PyObject *__pyx_kp_2; static char __pyx_k_Extension[] = "Extension"; static PyObject *__pyx_kp_Extension; static char __pyx_k_3[] = "Cython.Distutils"; static PyObject *__pyx_kp_3; static char __pyx_k_build_ext[] = "build_ext"; static PyObject *__pyx_kp_build_ext; static char __pyx_k_numpy[] = "numpy"; static PyObject *__pyx_kp_numpy; static char __pyx_k_scripts[] = "scripts"; static PyObject *__pyx_kp_scripts; static char __pyx_k_cmdclass[] = "cmdclass"; static PyObject *__pyx_kp_cmdclass; static char __pyx_k_5[] = "build_ext"; static PyObject *__pyx_kp_5; static char __pyx_k_ext_modules[] = "ext_modules"; static PyObject *__pyx_kp_ext_modules; static char __pyx_k_6[] = "cython_code"; static PyObject *__pyx_kp_6; static char __pyx_k_include_dirs[] = "include_dirs"; static PyObject *__pyx_kp_include_dirs; static char __pyx_k_get_include[] = "get_include"; static PyObject *__pyx_kp_get_include; static PyObject *__pyx_kp_4; static PyObject *__pyx_kp_7; static struct PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; static void __pyx_init_filenames(void); /*proto*/ #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef __pyx_moduledef = { PyModuleDef_HEAD_INIT, __Pyx_NAMESTR("setup"), 0, /* m_doc */ -1, /* m_size */ __pyx_methods /* m_methods */, NULL, /* m_reload */ NULL, /* m_traverse */ NULL, /* m_clear */ NULL /* m_free */ }; #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp___main__, __pyx_k___main__, sizeof(__pyx_k___main__), 1, 1, 1}, {&__pyx_kp_1, __pyx_k_1, sizeof(__pyx_k_1), 1, 1, 1}, {&__pyx_kp_setup, __pyx_k_setup, sizeof(__pyx_k_setup), 1, 1, 1}, {&__pyx_kp_2, __pyx_k_2, sizeof(__pyx_k_2), 1, 1, 1}, {&__pyx_kp_Extension, __pyx_k_Extension, sizeof(__pyx_k_Extension), 1, 1, 1}, {&__pyx_kp_3, __pyx_k_3, sizeof(__pyx_k_3), 1, 1, 1}, {&__pyx_kp_build_ext, __pyx_k_build_ext, sizeof(__pyx_k_build_ext), 1, 1, 1}, {&__pyx_kp_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 1, 1, 1}, {&__pyx_kp_scripts, __pyx_k_scripts, sizeof(__pyx_k_scripts), 1, 1, 1}, {&__pyx_kp_cmdclass, __pyx_k_cmdclass, sizeof(__pyx_k_cmdclass), 1, 1, 1}, {&__pyx_kp_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 1, 0}, {&__pyx_kp_ext_modules, __pyx_k_ext_modules, sizeof(__pyx_k_ext_modules), 1, 1, 1}, {&__pyx_kp_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 1, 0}, {&__pyx_kp_include_dirs, __pyx_k_include_dirs, sizeof(__pyx_k_include_dirs), 1, 1, 1}, {&__pyx_kp_get_include, __pyx_k_get_include, sizeof(__pyx_k_get_include), 1, 1, 1}, {&__pyx_kp_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 0}, {&__pyx_kp_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 0}, {0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { return 0; return -1; } static int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; return 0; __pyx_L1_error:; return -1; } #if PY_MAJOR_VERSION < 3 PyMODINIT_FUNC initsetup(void); /*proto*/ PyMODINIT_FUNC initsetup(void) #else PyMODINIT_FUNC PyInit_setup(void); /*proto*/ PyMODINIT_FUNC PyInit_setup(void) #endif { PyObject *__pyx_1 = 0; PyObject *__pyx_2 = 0; PyObject *__pyx_3 = 0; PyObject *__pyx_4 = 0; PyObject *__pyx_5 = 0; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; #ifdef CYTHON_REFNANNY void* __pyx_refchk = NULL; __Pyx_Refnanny = __Pyx_ImportRefcountAPI("refnanny"); if (!__Pyx_Refnanny) { PyErr_Clear(); __Pyx_Refnanny = __Pyx_ImportRefcountAPI("Cython.Runtime.refnanny"); if (!__Pyx_Refnanny) Py_FatalError("failed to import refnanny module"); } __pyx_refchk = __Pyx_Refnanny->NewContext("PyMODINIT_FUNC PyInit_setup(void)", __LINE__, __FILE__); #endif __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Library function declarations ---*/ __pyx_init_filenames(); /*--- Threads initialization code ---*/ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS #ifdef WITH_THREAD /* Python build with threading support? */ PyEval_InitThreads(); #endif #endif /*--- Initialize various global constants etc. ---*/ if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Module creation code ---*/ #if PY_MAJOR_VERSION < 3 __pyx_m = Py_InitModule4(__Pyx_NAMESTR("setup"), __pyx_methods, 0, 0, PYTHON_API_VERSION); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #if PY_MAJOR_VERSION < 3 Py_INCREF(__pyx_m); #endif __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; if (__pyx_module_is_main_setup) { if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_kp___main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; } /*--- Builtin init code ---*/ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_skip_dispatch = 0; /*--- Global init code ---*/ /*--- Function export code ---*/ /*--- Type init code ---*/ /*--- Type import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ /* "/micehome/matthijs/bazaar/assess-registration/scripts/setup.py":3 * #!/usr/bin/env python * * from distutils.core import setup # <<<<<<<<<<<<<< * from distutils.extension import Extension * from Cython.Distutils import build_ext */ __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_INCREF(__pyx_kp_setup); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_kp_setup); __Pyx_GIVEREF(__pyx_kp_setup); __pyx_1 = __Pyx_Import(__pyx_kp_1, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_1); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_kp_setup); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_2); if (PyObject_SetAttr(__pyx_m, __pyx_kp_setup, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_2); __pyx_2 = 0; __Pyx_DECREF(__pyx_1); __pyx_1 = 0; /* "/micehome/matthijs/bazaar/assess-registration/scripts/setup.py":4 * * from distutils.core import setup * from distutils.extension import Extension # <<<<<<<<<<<<<< * from Cython.Distutils import build_ext * import numpy */ __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_INCREF(__pyx_kp_Extension); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_kp_Extension); __Pyx_GIVEREF(__pyx_kp_Extension); __pyx_1 = __Pyx_Import(__pyx_kp_2, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_1); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_kp_Extension); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_2); if (PyObject_SetAttr(__pyx_m, __pyx_kp_Extension, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_2); __pyx_2 = 0; __Pyx_DECREF(__pyx_1); __pyx_1 = 0; /* "/micehome/matthijs/bazaar/assess-registration/scripts/setup.py":5 * from distutils.core import setup * from distutils.extension import Extension * from Cython.Distutils import build_ext # <<<<<<<<<<<<<< * import numpy * */ __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_INCREF(__pyx_kp_build_ext); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_kp_build_ext); __Pyx_GIVEREF(__pyx_kp_build_ext); __pyx_1 = __Pyx_Import(__pyx_kp_3, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_1); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_kp_build_ext); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_2); if (PyObject_SetAttr(__pyx_m, __pyx_kp_build_ext, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_2); __pyx_2 = 0; __Pyx_DECREF(__pyx_1); __pyx_1 = 0; /* "/micehome/matthijs/bazaar/assess-registration/scripts/setup.py":6 * from distutils.extension import Extension * from Cython.Distutils import build_ext * import numpy # <<<<<<<<<<<<<< * * setup( */ __pyx_1 = __Pyx_Import(__pyx_kp_numpy, 0); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_1); if (PyObject_SetAttr(__pyx_m, __pyx_kp_numpy, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_1); __pyx_1 = 0; /* "/micehome/matthijs/bazaar/assess-registration/scripts/setup.py":8 * import numpy * * setup( # <<<<<<<<<<<<<< * scripts=["create_deformation.py"], * cmdclass = {'build_ext': build_ext}, */ __pyx_2 = __Pyx_GetName(__pyx_m, __pyx_kp_setup); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_2); __pyx_1 = PyDict_New(); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_1)); /* "/micehome/matthijs/bazaar/assess-registration/scripts/setup.py":9 * * setup( * scripts=["create_deformation.py"], # <<<<<<<<<<<<<< * cmdclass = {'build_ext': build_ext}, * ext_modules = [Extension("cython_code", ["cython_code.pyx"], */ __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_INCREF(__pyx_kp_4); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_kp_4); __Pyx_GIVEREF(__pyx_kp_4); if (PyDict_SetItem(__pyx_1, __pyx_kp_scripts, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; /* "/micehome/matthijs/bazaar/assess-registration/scripts/setup.py":10 * setup( * scripts=["create_deformation.py"], * cmdclass = {'build_ext': build_ext}, # <<<<<<<<<<<<<< * ext_modules = [Extension("cython_code", ["cython_code.pyx"], * include_dirs = [numpy.get_include()])] */ __pyx_3 = PyDict_New(); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_3)); __pyx_4 = __Pyx_GetName(__pyx_m, __pyx_kp_build_ext); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_4); if (PyDict_SetItem(__pyx_3, __pyx_kp_5, __pyx_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_4); __pyx_4 = 0; if (PyDict_SetItem(__pyx_1, __pyx_kp_cmdclass, ((PyObject *)__pyx_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_3)); __pyx_3 = 0; /* "/micehome/matthijs/bazaar/assess-registration/scripts/setup.py":11 * scripts=["create_deformation.py"], * cmdclass = {'build_ext': build_ext}, * ext_modules = [Extension("cython_code", ["cython_code.pyx"], # <<<<<<<<<<<<<< * include_dirs = [numpy.get_include()])] * ) */ __pyx_4 = __Pyx_GetName(__pyx_m, __pyx_kp_Extension); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_4); __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_INCREF(__pyx_kp_7); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_kp_7); __Pyx_GIVEREF(__pyx_kp_7); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_kp_6); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_6); __Pyx_GIVEREF(__pyx_kp_6); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_3 = PyDict_New(); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_3)); /* "/micehome/matthijs/bazaar/assess-registration/scripts/setup.py":12 * cmdclass = {'build_ext': build_ext}, * ext_modules = [Extension("cython_code", ["cython_code.pyx"], * include_dirs = [numpy.get_include()])] # <<<<<<<<<<<<<< * ) */ __pyx_5 = __Pyx_GetName(__pyx_m, __pyx_kp_numpy); if (unlikely(!__pyx_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_5); __pyx_t_1 = PyObject_GetAttr(__pyx_5, __pyx_kp_get_include); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_5); __pyx_5 = 0; __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_3, __pyx_kp_include_dirs, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_t_1 = PyEval_CallObjectWithKeywords(__pyx_4, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_4); __pyx_4 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_3)); __pyx_3 = 0; __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; if (PyDict_SetItem(__pyx_1, __pyx_kp_ext_modules, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyEval_CallObjectWithKeywords(__pyx_2, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_2); __pyx_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_1)); __pyx_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_1); __Pyx_XDECREF(__pyx_2); __Pyx_XDECREF(__pyx_3); __Pyx_XDECREF(__pyx_4); __Pyx_XDECREF(__pyx_5); __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("setup"); Py_DECREF(__pyx_m); __pyx_m = 0; __pyx_L0:; __Pyx_FinishRefcountContext(); #if PY_MAJOR_VERSION < 3 return; #else return __pyx_m; #endif }