Example #1
0
static int cdefer_Deferred__set_debug_stack(cdefer_Deferred *self, char *name) {
    int rc;
    PyObject *stack;

    stack = PyObject_CallObject(format_stack, NULL);
    if (!stack) {
        return -1;
    }
    rc = PyObject_SetAttrString(self->debuginfo, name, stack);
    Py_DECREF(stack);
    if (-1 == rc) {
        return -1;
    }
    return 0;
}
Example #2
0
/* Implementation of kleckner1 */

static PyObject *__pyx_f_9kleckner1_f(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_9kleckner1_f(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_x = 0;
  PyObject *__pyx_r;
  static char *__pyx_argnames[] = {"x",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_x)) return 0;
  Py_INCREF(__pyx_v_x);

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

static void __pyx_f_9kleckner1_g(int __pyx_v_x) {

}

static struct PyMethodDef __pyx_methods[] = {
  {"f", (PyCFunction)__pyx_f_9kleckner1_f, METH_VARARGS|METH_KEYWORDS, 0},
  {0, 0, 0, 0}
};

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

PyMODINIT_FUNC initkleckner1(void); /*proto*/
PyMODINIT_FUNC initkleckner1(void) {
  __pyx_init_filenames();
  __pyx_m = Py_InitModule4("kleckner1", __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/Bugs/kleckner/kleckner1.pyx":4 */
  return;
  __pyx_L1:;
  __Pyx_AddTraceback("kleckner1");
}
Example #3
0
/** @private */
SRD_PRIV int srd_inst_start(struct srd_decoder_inst *di)
{
	PyObject *py_res;
	GSList *l;
	struct srd_decoder_inst *next_di;
	int ret;

	srd_dbg("Calling start() method on protocol decoder instance %s.",
			di->inst_id);

	/* Run self.start(). */
	if (!(py_res = PyObject_CallMethod(di->py_inst, "start", NULL))) {
		srd_exception_catch("Protocol decoder instance %s",
				di->inst_id);
		return SRD_ERR_PYTHON;
	}
	Py_DecRef(py_res);

	/* Set the initial pins based on self.initial_pins. */
	set_initial_pin_values(di);

	/* Set self.samplenum to 0. */
	PyObject_SetAttrString(di->py_inst, "samplenum", PyLong_FromLong(0));

	/* Set self.matches to None. */
	PyObject_SetAttrString(di->py_inst, "matches", Py_None);

	/* Start all the PDs stacked on top of this one. */
	for (l = di->next_di; l; l = l->next) {
		next_di = l->data;
		if ((ret = srd_inst_start(next_di)) != SRD_OK)
			return ret;
	}

	return SRD_OK;
}
Example #4
0
void PyComplex(char *name, double value, double value2)
{
    PyObject *obj;

    obj = PyComplex_FromDoubles(value, value2);
    
    if(list_level>=0 && List[list_level]) {
        PyList_Append(List[list_level], obj);
        Py_DECREF(obj);    
        return;
    }

    PyObject_SetAttrString(interpreter_state->main_module, name, obj);
    Py_DECREF(obj);
}
Example #5
0
    /* "/Users/baas/src/cgkit/pyrex/pyx/_pointcloud.pyx":131 */
    __pyx_v_n += 1;
  }

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("_pointcloud.writeDataPoints");
  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

static struct PyMethodDef __pyx_methods[] = {
  {"readDataPoints", (PyCFunction)__pyx_f_11_pointcloud_readDataPoints, METH_VARARGS|METH_KEYWORDS, __pyx_doc_11_pointcloud_readDataPoints},
  {"writeDataPoints", (PyCFunction)__pyx_f_11_pointcloud_writeDataPoints, METH_VARARGS|METH_KEYWORDS, __pyx_doc_11_pointcloud_writeDataPoints},
  {0, 0, 0, 0}
};

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

PyMODINIT_FUNC init_pointcloud(void); /*proto*/
PyMODINIT_FUNC init_pointcloud(void) {
  __pyx_init_filenames();
  __pyx_m = Py_InitModule4("_pointcloud", __pyx_methods, __pyx_mdoc, 0, PYTHON_API_VERSION);
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;};
  Py_INCREF(__pyx_m);
  __pyx_b = PyImport_AddModule("__builtin__");
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;};
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;};

  /* "/Users/baas/src/cgkit/pyrex/pyx/_pointcloud.pyx":90 */
  return;
  __pyx_L1:;
  __Pyx_AddTraceback("_pointcloud");
}
Example #6
0
void PyInteger(char *name, long value)
{
    PyObject *obj;

    obj = PyLong_FromLong(value);
    
    if(list_level>=0 && List[list_level]) {
        PyList_Append(List[list_level], obj);
        Py_DECREF(obj);        
        return;
    }

    PyObject_SetAttrString(interpreter_state->main_module, name, obj);
    Py_DECREF(obj);
}
Example #7
0
static void py_set_attrs(PyObject *mod)
{
   DECL_ATTR_RETRO(B);
   DECL_ATTR_RETRO(Y);
   DECL_ATTR_RETRO(SELECT);
   DECL_ATTR_RETRO(START);
   DECL_ATTR_RETRO(UP);
   DECL_ATTR_RETRO(DOWN);
   DECL_ATTR_RETRO(LEFT);
   DECL_ATTR_RETRO(RIGHT);
   DECL_ATTR_RETRO(A);
   DECL_ATTR_RETRO(X);
   DECL_ATTR_RETRO(L);
   DECL_ATTR_RETRO(R);
   DECL_ATTR_RETRO(L2);
   DECL_ATTR_RETRO(R2);
   DECL_ATTR_RETRO(L3);
   DECL_ATTR_RETRO(R3);

   PyObject_SetAttrString(mod, "ANALOG_LEFT", PyLong_FromLong(RETRO_DEVICE_INDEX_ANALOG_LEFT));
   PyObject_SetAttrString(mod, "ANALOG_RIGHT", PyLong_FromLong(RETRO_DEVICE_INDEX_ANALOG_RIGHT));
   PyObject_SetAttrString(mod, "ANALOG_X", PyLong_FromLong(RETRO_DEVICE_ID_ANALOG_X));
   PyObject_SetAttrString(mod, "ANALOG_Y", PyLong_FromLong(RETRO_DEVICE_ID_ANALOG_Y));
}
Example #8
0
void initMk4py() {
  PyObject *m = Py_InitModule4("Mk4py", Mk4Methods, mk4py_module_documentation,
    0, PYTHON_API_VERSION);
  PyObject_SetAttrString(m, "version", PyString_FromString("2.4.9.7"));
  PyObject_SetAttrString(m, "ViewType", (PyObject*) &PyViewtype);
  PyObject_SetAttrString(m, "ViewerType", (PyObject*) &PyViewertype);
  PyObject_SetAttrString(m, "ROViewerType", (PyObject*) &PyROViewertype);
  PyObject_SetAttrString(m, "RowRefType", (PyObject*) &PyRowReftype);
  PyObject_SetAttrString(m, "RORowRefType", (PyObject*) &PyRORowReftype);
}
Example #9
0
void delete_invalid_lists( PyObject* pobj )
{
    PyObject* pclass = NULL;
    PyObject* plist = NULL;
    PyObject* temp;
    int i, d, n;

    pclass = PyObject_GetAttrString( pobj, "__class__" );
    if ( pclass == NULL )
	goto done;

    plist = PyObject_GetAttrString( pclass, "invalid" );
    if ( plist == NULL )
	goto done;

    if ( !PyList_Check( plist ) ) goto done;

    n = PyList_Size( plist );
    if ( n == 0 ) goto done;
#if 0
    printf( "deleting old displaylists: " );
#endif
    for ( i = 0; i < n; ++i )
    {
	temp = PyList_GetItem( plist, i );
	if ( PyInt_Check( temp ) ) {
	    d = PyInt_AsLong( temp );
            glDeleteLists( d, 1 );
        } else if ( PyTuple_Check( temp ) ) {
	    d = PyInt_AsLong( PyTuple_GetItem( temp, 0 ) );
            glDeleteLists( d, 1 );
	} else { 
	    fprintf( stderr, "delete_invalid_lists:  bad cache value\n" );
        }
#if 0
	printf( " %d", d );
#endif
    }
#if 0
    printf( "\n" );
#endif

    PyObject_SetAttrString( pclass, "invalid", PyList_New(0) );
    
 done:
    Py_XDECREF( pclass );
    Py_XDECREF( plist );
}
Example #10
0
static PyObject *
pygpgme_context_genkey(PyGpgmeContext *self, PyObject *args)
{
    PyObject *py_pubkey = Py_None, *py_seckey = Py_None;
    const char *parms;
    gpgme_data_t pubkey = NULL, seckey = NULL;
    PyObject *result;
    gpgme_error_t err;

    if (!PyArg_ParseTuple(args, "z|OO", &parms, &py_pubkey, &py_seckey))
        return NULL;

    if (pygpgme_data_new(&pubkey, py_pubkey))
        return NULL;

    if (pygpgme_data_new(&seckey, py_seckey)) {
        gpgme_data_release(pubkey);
        return NULL;
    }

    Py_BEGIN_ALLOW_THREADS;
    err = gpgme_op_genkey(self->ctx, parms, pubkey, seckey);
    Py_END_ALLOW_THREADS;

    gpgme_data_release(seckey);
    gpgme_data_release(pubkey);
    result = pygpgme_genkey_result(self->ctx);

    if (pygpgme_check_error(err)) {
        PyObject *err_type, *err_value, *err_traceback;

        PyErr_Fetch(&err_type, &err_value, &err_traceback);
        PyErr_NormalizeException(&err_type, &err_value, &err_traceback);

        if (!PyErr_GivenExceptionMatches(err_type, pygpgme_error))
            goto end;

        if (result != NULL) {
            PyObject_SetAttrString(err_value, "result", result);
            Py_DECREF(result);
        }
    end:
        PyErr_Restore(err_type, err_value, err_traceback);
        return NULL;
    }

    return (PyObject *) result;
}
Example #11
0
static PyObject *
channel_read(SSH2_ChannelObj *self, PyObject *args)
{
	int ret;
	int bufsiz;
	int stream_id = 0;
	PyObject *buf;

	if (!PyArg_ParseTuple(args, "i|i:read", &bufsiz, &stream_id))
		return NULL;

	if (bufsiz < 0) {
		PyErr_SetString(PyExc_ValueError, "negative size");
		return NULL;
	}

	if ((buf = PyBytes_FromStringAndSize(NULL, bufsiz)) == NULL)
		return NULL;

	Py_BEGIN_ALLOW_THREADS
	ret = libssh2_channel_read_ex(self->channel, stream_id, PyBytes_AS_STRING(buf), bufsiz);
	Py_END_ALLOW_THREADS

	if (ret < 0) {
		Py_DECREF(buf);

		/* We have to work around a bug in libssh2, that _libssh2_error() is not
		 * called by libssh2_channel_read_ex() when the transport layer returns
		 * LIBSSH2_ERROR_EAGAIN. So in that case the last error is not set and
		 * the RAISE_SSH2_ERROR macro will not be able to raise the correct exception.
		 * Thanks to Daniel Stenberg, who has fixed that issue now (see 2db4863).
		 * However in order that our bindings work correctly with older versions
		 * of libssh2, we need the workaround below. */
		if (ret == LIBSSH2_ERROR_EAGAIN) {
			PyObject *exc;
			PyObject *value;

			exc = PyObject_CallFunction(SSH2_Error, "s", "Would block");
			value=Py_BuildValue("i", ret);
			PyObject_SetAttrString(exc, "errno", value);
			PyErr_SetObject(SSH2_Error, exc);
			Py_DECREF(exc);
			Py_DECREF(value);
			return NULL;
		}

		RAISE_SSH2_ERROR(self->session)
	}
Example #12
0
    /*else*/ {
      __pyx_6 = PyTuple_New(3); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;}
      Py_INCREF(__pyx_v_d2);
      PyTuple_SET_ITEM(__pyx_6, 0, __pyx_v_d2);
      Py_INCREF(__pyx_v_p21);
      PyTuple_SET_ITEM(__pyx_6, 1, __pyx_v_p21);
      Py_INCREF(__pyx_v_p22);
      PyTuple_SET_ITEM(__pyx_6, 2, __pyx_v_p22);
      __pyx_r = __pyx_6;
      __pyx_6 = 0;
      goto __pyx_L0;
    }
    __pyx_L16:;
  }
  __pyx_L2:;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_5);
  Py_XDECREF(__pyx_6);
  Py_XDECREF(__pyx_7);
  Py_XDECREF(__pyx_8);
  Py_XDECREF(__pyx_9);
  Py_XDECREF(__pyx_10);
  __Pyx_AddTraceback("closestpair.closest_pair");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_min_p1);
  Py_DECREF(__pyx_v_min_p2);
  Py_DECREF(__pyx_v_i);
  Py_DECREF(__pyx_v_point);
  Py_DECREF(__pyx_v_point2);
  Py_DECREF(__pyx_v_d);
  Py_DECREF(__pyx_v_split);
  Py_DECREF(__pyx_v_d1);
  Py_DECREF(__pyx_v_p11);
  Py_DECREF(__pyx_v_p12);
  Py_DECREF(__pyx_v_d2);
  Py_DECREF(__pyx_v_p21);
  Py_DECREF(__pyx_v_p22);
  Py_DECREF(__pyx_v_points_in_strip);
  Py_DECREF(__pyx_v_split_at);
  Py_DECREF(__pyx_v_max_i);
  Py_DECREF(__pyx_v_sd);
  Py_DECREF(__pyx_v_points);
  return __pyx_r;
}

static __Pyx_InternTabEntry __pyx_intern_tab[] = {
  {&__pyx_n_append, "append"},
  {&__pyx_n_closest_pair, "closest_pair"},
  {&__pyx_n_distance, "distance"},
  {&__pyx_n_min, "min"},
  {&__pyx_n_sort, "sort"},
  {0, 0}
};

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_k1p, __pyx_k1, sizeof(__pyx_k1)},
  {0, 0, 0}
};

static struct PyMethodDef __pyx_methods[] = {
  {"distance", (PyCFunction)__pyx_f_11closestpair_distance, METH_VARARGS|METH_KEYWORDS, __pyx_doc_11closestpair_distance},
  {"closest_pair", (PyCFunction)__pyx_f_11closestpair_closest_pair, METH_VARARGS|METH_KEYWORDS, __pyx_doc_11closestpair_closest_pair},
  {0, 0, 0, 0}
};

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

PyMODINIT_FUNC initclosestpair(void); /*proto*/
PyMODINIT_FUNC initclosestpair(void) {
  __pyx_init_filenames();
  __pyx_m = Py_InitModule4("closestpair", __pyx_methods, 0, 0, PYTHON_API_VERSION);
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; goto __pyx_L1;};
  Py_INCREF(__pyx_m);
  __pyx_b = PyImport_AddModule("__builtin__");
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; goto __pyx_L1;};
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; goto __pyx_L1;};
  if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; goto __pyx_L1;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; goto __pyx_L1;};

  /* "/home/andrew/Programs/cluster/clusterer/closestpair.pyx":6 */
  return;
  __pyx_L1:;
  __Pyx_AddTraceback("closestpair");
}
Example #13
0
PyMODINIT_FUNC
initgtop(void)
{
	PyObject* module;

	glibtop_init();

	Py_AtExit(gtop_at_exit);

	module = Py_InitModule("gtop", (PyMethodDef*) gtop_methods);
	PyType_Ready((PyTypeObject*) &StructType);
	PyObject_SetAttrString(module, "_Struct", (void*) &StructType);

	register_constants(module);
	PyModule_AddObject(module, "siglist", build_siglist());
}
Example #14
0
void
psyco_errors_set(PyObject *type)
{
    int i;
    char *name;

    for (i = 0; exctable[i].name; i++) {
        if (NULL == exctable[i].exc) { continue; }

        /* the name is the part after the last dot */
        name = strrchr(exctable[i].name, '.');
        name = name ? name + 1 : exctable[i].name;

        PyObject_SetAttrString(type, name, *exctable[i].exc);
    }
}
Example #15
0
void PyUnicodeString(char *name, unsigned short *value, long len)
{
    PyObject *obj;
    

    obj = PyUnicode_FromUnicode((unsigned short *)value, len);

    if(list_level>=0 && List[list_level]) {        
        PyList_Append(List[list_level], obj);
        Py_DECREF(obj);
        return;
    }

    PyObject_SetAttrString( interpreter_state->main_module, name, obj);
    Py_DECREF(obj);
}
Example #16
0
int
PP_Set_Member(PyObject *pobject, const char *attrname,
                  const char *argfmt,  ... /* arg,... */ )    /* convert to python */
{
    int result;
    PyObject *pval;
    va_list argslist;                             /* "pobject.attrname = v" */
    va_start(argslist, argfmt);
    Py_Initialize();                              /* init if first time */
    pval = Py_VaBuildValue(argfmt, argslist);     /* input: C->Python */
    if (pval == NULL) 
        return -1;
    result = PyObject_SetAttrString(pobject, attrname, pval);     /* setattr */
    Py_DECREF(pval); 
    return result;
}
Example #17
0
static PyObject *
iobase_close(PyObject *self, PyObject *args)
{
    PyObject *res;

    if (IS_CLOSED(self))
        Py_RETURN_NONE;

    res = PyObject_CallMethodObjArgs(self, _PyIO_str_flush, NULL);
    PyObject_SetAttrString(self, "__IOBase_closed", Py_True);
    if (res == NULL) {
        return NULL;
    }
    Py_XDECREF(res);
    Py_RETURN_NONE;
}
Example #18
0
/* Implementation of anonymousenum */

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

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

PyMODINIT_FUNC initanonymousenum(void); /*proto*/
PyMODINIT_FUNC initanonymousenum(void) {
  __pyx_init_filenames();
  __pyx_m = Py_InitModule4("anonymousenum", __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/7/anonymousenum.pyx":6 */
  __pyx_v_13anonymousenum_i = __pyx_e_13anonymousenum_spam;
  return;
  __pyx_L1:;
  __Pyx_AddTraceback("anonymousenum");
}
Example #19
0
void
PyErr_SyntaxLocation(const char *filename, int lineno)
{
	PyObject *exc, *v, *tb, *tmp;

	/* add attributes for the line number and filename for the error */
	PyErr_Fetch(&exc, &v, &tb);
	PyErr_NormalizeException(&exc, &v, &tb);
	/* XXX check that it is, indeed, a syntax error */
	tmp = PyInt_FromLong(lineno);
	if (tmp == NULL)
		PyErr_Clear();
	else {
		if (PyObject_SetAttrString(v, "lineno", tmp))
			PyErr_Clear();
		Py_DECREF(tmp);
	}
	if (filename != NULL) {
		tmp = PyString_FromString(filename);
		if (tmp == NULL)
			PyErr_Clear();
		else {
			if (PyObject_SetAttrString(v, "filename", tmp))
				PyErr_Clear();
			Py_DECREF(tmp);
		}

		tmp = PyErr_ProgramText(filename, lineno);
		if (tmp) {
			PyObject_SetAttrString(v, "text", tmp);
			Py_DECREF(tmp);
		}
	}
	if (PyObject_SetAttrString(v, "offset", Py_None)) {
		PyErr_Clear();
	}
	if (exc != PyExc_SyntaxError) {
		if (!PyObject_HasAttrString(v, "msg")) {
			tmp = PyObject_Str(v);
			if (tmp) {
				if (PyObject_SetAttrString(v, "msg", tmp))
					PyErr_Clear();
				Py_DECREF(tmp);
			} else {
				PyErr_Clear();
			}
		}
		if (!PyObject_HasAttrString(v, "print_file_and_line")) {
			if (PyObject_SetAttrString(v, "print_file_and_line",
						   Py_None))
				PyErr_Clear();
		}
	}
	PyErr_Restore(exc, v, tb);
}
Example #20
0
PyObject *
unpickle(PyObject *obj, int *offset)
{
	// Return value: New Reference
	PyObject *input = NULL;
	PyObject *cPickle = NULL;
	PyObject *unpickler = NULL;
	PyObject *result = NULL;

	cPickle = PyImport_ImportModule("cPickle");
	if(!cPickle)
		return NULL;

	input = PycStringIO->NewInput(obj);
	if(!input)
		goto fail;

	unpickler = PyObject_CallMethod(cPickle, "Unpickler", "(O)", input);
	if(!unpickler)
		goto fail;

	if(!find_global_func)
	{
		PyErr_SetString(PyExc_RuntimeError, "No find_global function set. Use _set_find_global_func()");
		goto fail;
	}

	if(PyObject_SetAttrString(unpickler, "find_global", find_global_func) == -1)
	{
		PyErr_SetString(PyExc_RuntimeError, "Unpickler initialization failed");
		goto fail;
	}

	if(*offset)
	{
		// seek to desired position.
		Py_XDECREF(PyObject_CallMethod(cPickle, "seek", "(i)", *offset));
	}

	result = PyObject_CallMethod(unpickler, "load", NULL);

fail:
	Py_XDECREF(cPickle);
	Py_XDECREF(input);
	Py_XDECREF(unpickler);
	return result;
}
Example #21
0
/**
 * z_policy_call_object:
 * @func: Python method to call
 * @args: Arguments to pass to @func
 * @session_id: Session ID for logging
 *
 * Calls @func with @args, and if an error happened, sends log messages
 * (containing @session_id) to the log.
 *
 * Returns:
 * The return value of @func
 */
PyObject *
z_policy_call_object(PyObject *func, PyObject *args, gchar *session_id)
{
  PyObject *res;
  
  PyErr_Clear();
  res = PyObject_CallObject(func, args);
  
  Py_XDECREF(args);
  
  if (!res)
    {
      PyObject *m = PyImport_AddModule("sys");
      
      if (!PyString_Check(PyErr_Occurred()))
        {
          PyErr_Print();
        }
      else
        {
          PyObject *exc, *value, *tb, *str;
          
          PyErr_Fetch(&exc, &value, &tb);
          PyErr_NormalizeException(&exc, &value, &tb);
          
          str = PyObject_Str(value);
          if (!str)
            {
              /*NOLOG*/
              z_log(session_id, CORE_ERROR, 3, "%s;", PyString_AsString(exc));
            }
          else
            {
              /*NOLOG*/
              z_log(session_id, CORE_ERROR, 3, "%s; reason='%s'", PyString_AsString(exc), PyString_AsString(str));
            }
          
          Py_XDECREF(exc);
          Py_XDECREF(value);
          Py_XDECREF(tb);
          Py_XDECREF(str);
        }
      PyObject_SetAttrString(m, "last_traceback", Py_None); 
    }

  return res;
}
Example #22
0
// Replace inspect functions with ones that accept compiled types too.
static void patchInspectModule( void )
{
#if PYTHON_VERSION >= 300
#ifdef _NUITKA_EXE
    // May need to import the "site" module, because otherwise the patching can
    // fail with it being unable to load it.
    if ( Py_NoSiteFlag == 0 )
    {
        try
        {
            IMPORT_MODULE( const_str_plain_site, Py_None, Py_None, const_tuple_empty, const_int_0 );
        }
        catch( PythonException & )
        {
            PyErr_Clear();
            // Ignore ImportError, site is not a must.
        }
    }
#endif

    try
    {
        module_inspect = IMPORT_MODULE( const_str_plain_inspect, Py_None, Py_None, const_tuple_empty, const_int_0 );
    }
    catch( PythonException &e )
    {
        e.toPython();

        PyErr_PrintEx( 0 );
        Py_Exit( 1 );
    }
    assertObject( module_inspect );

    // Patch "inspect.getgeneratorstate" unless it is already patched.
    old_getgeneratorstate = PyObject_GetAttrString( module_inspect, "getgeneratorstate" );
    assertObject( old_getgeneratorstate );

    if ( PyFunction_Check( old_getgeneratorstate ) )
    {
        PyObject *inspect_getgeneratorstate_replacement = PyCFunction_New( &_method_def_inspect_getgeneratorstate_replacement, NULL );
        assertObject( inspect_getgeneratorstate_replacement );

        PyObject_SetAttrString( module_inspect, "getgeneratorstate", inspect_getgeneratorstate_replacement );
    }
#endif

}
Example #23
0
	PyTypeObject* import_type(PyObject* target, PyObject* source, const char* name) {
		PyObject* type = PyObject_GetAttrString(source, name);
		if (!type) {
			return NULL;
		}
		if (!PyType_Check(type)) {
			PyErr_Format(PyExc_TypeError, "%s is not a type ", name);
			return NULL;
		}

		if (PyObject_SetAttrString(target, name, type) < 0) {
			return NULL;
		}

		Py_DECREF(type);
		return (PyTypeObject*)type;
	}
Example #24
0
/* 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");
}
Example #25
0
//-------------------------------------------------------------------------------------
bool Script::installExtraModule(const char* moduleName)
{
	PyObject *m = PyImport_AddModule("__main__");
	extraModule_ = PyImport_AddModule(moduleName);								// 添加一个脚本扩展模块
	if (extraModule_ == NULL)
		return false;
	
	PyObject *module_ = PyImport_AddModule(moduleName);							// 初始化扩展模块
	if (module_ == NULL)
		return false;

	PyObject_SetAttrString(m, moduleName, extraModule_);						// 将扩展模块对象加入main

	INFO_MSG(boost::format("Script::install %1% is successfully!\n") 
		% moduleName);

	return true;
}
Example #26
0
/* Implementation of concatcstrings */

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

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

PyMODINIT_FUNC initconcatcstrings(void); /*proto*/
PyMODINIT_FUNC initconcatcstrings(void) {
  PyObject *__pyx_1 = 0;
  __pyx_init_filenames();
  __pyx_m = Py_InitModule4("concatcstrings", __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;};
  __pyx_1 = PyNumber_Add(__pyx_k1p, __pyx_k2p); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_spam, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  return;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("concatcstrings");
}
Example #27
0
PyObject* init() {
	PyObject *m;

	m = Py_InitModule("Wt", WtMethods);
	if (m == NULL) return 0;

	PythonApplication::setWtModule(m);


#include "gwt_TypeDecl.h"
#include "TemplateTypes.h"
#include "gwt_includeEnums.h"

	PyType_Ready(&JSignalTypeProviderType);
	PyObject_SetAttrString(m, "JSignal", (PyObject*)PyObject_New(JSignalTypeProviderObject, &JSignalTypeProviderType));

	return m;
}
Example #28
0
void PySymbol(char *name, char *value)
{
    PyObject *obj;
    
    if(!strncmp(value, "Null", 4))
        obj = Py_None;
    else if(!strncmp(value, "True", 4))
        obj = Py_True;
    else if(!strncmp(value, "False", 5))
        obj = Py_False;

    if(list_level>=0 && List[list_level]) {        
        PyList_Append(List[list_level], obj);
        return;
    }

    PyObject_SetAttrString( interpreter_state->main_module, name, obj);
}
Example #29
0
static PyObject *
csv_register_dialect(PyObject *module, PyObject *args)
{
        PyObject *name_obj, *dialect_obj;

	if (!PyArg_UnpackTuple(args, "", 2, 2, &name_obj, &dialect_obj))
                return NULL;
        if (!PyString_Check(name_obj)
#ifdef Py_USING_UNICODE
&& !PyUnicode_Check(name_obj)
#endif
) {
                PyErr_SetString(PyExc_TypeError, 
                                "dialect name must be a string or unicode");
                return NULL;
        }
        Py_INCREF(dialect_obj);
        /* A class rather than an instance? Instanciate */
        if (PyObject_TypeCheck(dialect_obj, &PyClass_Type)) {
                PyObject * new_dia;
                new_dia = PyObject_CallFunction(dialect_obj, "");
                Py_DECREF(dialect_obj);
                if (new_dia == NULL)
                        return NULL;
                dialect_obj = new_dia;
        }
        /* Make sure we finally have an instance */
        if (!PyInstance_Check(dialect_obj)) {
                PyErr_SetString(PyExc_TypeError, "dialect must be an instance");
                Py_DECREF(dialect_obj);
                return NULL;
        }
        if (PyObject_SetAttrString(dialect_obj, "_name", name_obj) < 0) {
                Py_DECREF(dialect_obj);
                return NULL;
        }
        if (PyDict_SetItem(dialects, name_obj, dialect_obj) < 0) {
                Py_DECREF(dialect_obj);
                return NULL;
        }
        Py_DECREF(dialect_obj);
        Py_INCREF(Py_None);
        return Py_None;
}
Example #30
0
bool PyViewer::SetItem(int row_, int col_, const c4_Bytes &buf_) {
  const c4_Property &prop = _template.NthProperty(col_);
  c4_Row one;
  prop(one).SetData(buf_);

  PyRowRef r(one); // careful, stack-based temp
  PyObject *item = r.asPython(prop);

  if (_byPos) {
    PWOSequence item(_data[row_]);
    item[col_] = item;
  } else if (PyDict_Check((PyObject*)_data))
    PyDict_SetItemString(_data, (char*)prop.Name(), item);
  else
    PyObject_SetAttrString(_data, (char*)prop.Name(), item);

  Py_DECREF(item);
  return true;
}