Beispiel #1
0
PyObject* AUD_initPython()
{
	PyObject* module = PyInit_aud();
	PyModule_AddObject(module, "device", (PyObject*)PyCFunction_New(meth_getcdevice, NULL));
	PyModule_AddObject(module, "_sound_from_pointer", (PyObject*)PyCFunction_New(meth_sound_from_pointer, NULL));
	PyDict_SetItemString(PyImport_GetModuleDict(), "aud", module);

	return module;
}
Beispiel #2
0
void init_mergesort(void) {
    import_array();
    import_ufunc();
	m = Py_InitModule3("_mergesort", module_methods, "mergesort module for parallel mergesort");
	PyObject * mergefunc = PyCFunction_New(module_methods, NULL);
	PyObject * argmergefunc = PyCFunction_New(module_methods + 1, NULL);
	PyObject * permutefunc = PyCFunction_New(module_methods + 2, NULL);
	PyObject * reorderdtypefunc = PyCFunction_New(module_methods + 3, NULL);
	PyModule_AddObject(m, "merge", mergefunc);
	PyModule_AddObject(m, "argmerge", argmergefunc);
	PyModule_AddObject(m, "permute", permutefunc);
	PyModule_AddObject(m, "reorderdtype", reorderdtypefunc);
}
// Decorate the method now the arguments have been parsed.
static PyObject *decorate(Chimera::Signature *parsed_sig, PyObject *res_obj,
        const char *context)
{
    // Parse any result type.
    if (res_obj)
    {
        parsed_sig->result = Chimera::parse(res_obj);

        if (!parsed_sig->result)
        {
            Chimera::raiseParseException(res_obj, context);
            delete parsed_sig;
            return 0;
        }
    }

    // Wrap the parsed signature in a Python object.
    PyObject *sig_obj = Chimera::Signature::toPyObject(parsed_sig);

    if (!sig_obj)
        return 0;

    // Create the decorator function itself.  We stash the arguments in "self".
    // This may be an abuse, but it seems to be Ok.
    static PyMethodDef deco_method = {
        SIP_MLNAME_CAST("_deco"), decorator, METH_O, 0
    };

    PyObject *obj = PyCFunction_New(&deco_method, sig_obj);
    Py_DECREF(sig_obj);

    return obj;
}
Beispiel #4
0
void init_scope(void) {
  PyMethodDef *def;

  PyObject *module=Py_InitModule("_scope", ModuleMethods);
  PyObject *moduleDict=PyModule_GetDict(module);
  PyObject *classDict=PyDict_New();
  PyObject *className = PyString_FromString("Scopeable");
  PyObject *scopeableClass = PyClass_New(NULL, classDict, className);
  PyDict_SetItemString(moduleDict, "Scopeable", scopeableClass);
  Py_DECREF(classDict);
  Py_DECREF(className);
  Py_DECREF(scopeableClass);

  for (def = ScopeableMethods; def->ml_name != NULL; def++) {
    PyObject *func=PyCFunction_New(def, NULL);
    PyObject *method= PyMethod_New(func, NULL, scopeableClass);
    PyDict_SetItemString(classDict, def->ml_name, method);
    /* 
     * this would normally happen in PyClass_New() if the classDict
     * were already populated; but I'm passing it an empty dict
     */
    if (!strncmp(def->ml_name, "__getattr__", strlen("__getattr__"))) {
      ((PyClassObject *)scopeableClass)->cl_getattr=method;
    }
    Py_DECREF(func);
    Py_DECREF(method);
  }
}
Beispiel #5
0
	PyObject * function_python::create_function_adapter( const function_adapter_interface_ptr & _adapter, bool _native )
	{
		uint32_t arity = _adapter->getArity();
		
		PyMethodDef * method;
		
		if( _native == true )
		{
			method = &m_method_native;
		}
		else
		{
			if( arity > 0 )
			{
				method = &m_method_args;
			}
			else
			{
				method = &m_method_noargs;
			}
		}

		py_function_type * py_self = (py_function_type *)PyType_GenericAlloc( &m_function_type, 0 );

		stdex::intrusive_ptr_setup( py_self->iadapter, _adapter );

		PyObject * py_func = PyCFunction_New( method, (PyObject*)py_self );
		Py_DECREF( (PyObject *)py_self );

		return py_func;
	}
Beispiel #6
0
//-------------------------------------------------------------------------------------
void EntityMailbox::onInstallScript(PyObject* mod)
{
	static PyMethodDef __unpickle__Method = {"Mailbox", (PyCFunction)&EntityMailbox::__unpickle__, METH_VARARGS, 0};
	PyObject* pyFunc = PyCFunction_New(&__unpickle__Method, NULL);
	script::Pickler::registerUnpickleFunc(pyFunc, "Mailbox");
	Py_DECREF(pyFunc);
}
Beispiel #7
0
static PyObject *ffi_callback(FFIObject *self, PyObject *args, PyObject *kwds)
{
    PyObject *c_decl, *python_callable = Py_None, *error = Py_None;
    PyObject *res, *onerror = Py_None;
    static char *keywords[] = {"cdecl", "python_callable", "error",
                               "onerror", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OOO", keywords,
                                     &c_decl, &python_callable, &error,
                                     &onerror))
        return NULL;

    c_decl = (PyObject *)_ffi_type(self, c_decl, ACCEPT_STRING | ACCEPT_CTYPE |
                                                 CONSIDER_FN_AS_FNPTR);
    if (c_decl == NULL)
        return NULL;

    args = Py_BuildValue("(OOOO)", c_decl, python_callable, error, onerror);
    if (args == NULL)
        return NULL;

    if (python_callable != Py_None) {
        res = b_callback(NULL, args);
    }
    else {
        static PyMethodDef md = {"callback_decorator",
                                 (PyCFunction)_ffi_callback_decorator, METH_O};
        res = PyCFunction_New(&md, args);
    }
    Py_DECREF(args);
    return res;
}
Beispiel #8
0
PyObject *
Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name)
{
    if (name[0] == '_' && name[1] == '_') {
        if (strcmp(name, "__methods__") == 0) {
            if (PyErr_WarnPy3k("__methods__ not supported in 3.x",
                               1) < 0)
                return NULL;
            return listmethodchain(chain);
        }
        if (strcmp(name, "__doc__") == 0) {
            const char *doc = self->ob_type->tp_doc;
            if (doc != NULL)
                return PyString_FromString(doc);
        }
    }
    while (chain != NULL) {
        PyMethodDef *ml = chain->methods;
        for (; ml->ml_name != NULL; ml++) {
            if (name[0] == ml->ml_name[0] &&
                strcmp(name+1, ml->ml_name+1) == 0)
                /* XXX */
                return PyCFunction_New(ml, self);
        }
        chain = chain->link;
    }
    PyErr_SetString(PyExc_AttributeError, name);
    return NULL;
}
Beispiel #9
0
void
init_Missing(void)
{
  PyObject *m, *d;

  if(! ((vname=PyString_FromString("V"))
	&& (Missing_dot_Value=PyString_FromString("Missing.Value"))
	&& (empty_string=PyString_FromString(""))
	)) return;

  /* Create the module and add the functions */
  m = Py_InitModule4("_Missing", Module_Level__methods,
		     Missing_module_documentation,
		     (PyObject*)NULL,PYTHON_API_VERSION);

  /* Add some symbolic constants to the module */
  d = PyModule_GetDict(m);

  PyExtensionClass_Export(d,"Missing",MissingType);

  theValue = PyObject_CallObject((PyObject*)&MissingType, NULL);
  notMissing = PyObject_CallObject((PyObject*)&MissingType, NULL);
  reduce=PyCFunction_New(reduce_ml, theValue);

  PyDict_SetItemString(d, "Value", theValue);
  PyDict_SetItemString(d, "V", theValue);
  PyDict_SetItemString(d, "MV", theValue);
  PyDict_SetItemString(d, "notMissing", notMissing);
}
Beispiel #10
0
//-------------------------------------------------------------------------------------
void FixedArray::onInstallScript(PyObject* mod)
{
	static PyMethodDef __unpickle__Method = {"FixedArray", (PyCFunction)&FixedArray::__unpickle__, METH_VARARGS, 0};
	PyObject* pyFunc = PyCFunction_New(&__unpickle__Method, NULL);
	script::Pickler::registerUnpickleFunc(pyFunc, "FixedArray");
	Py_DECREF(pyFunc);
}
Beispiel #11
0
PyObject *
rpcErrorClass(void)
{
	PyObject	*klass,
			*dict,
			*func,
			*meth;
	PyMethodDef	*method;

	dict = PyDict_New();
	if (dict == NULL)
		return (NULL);
	klass = PyErr_NewException("xmlrpc.error", NULL, dict);
	if (klass == NULL)
		return (NULL);
	for (method = rpcErrorMethods; method->ml_name != NULL; method++) {
		func = PyCFunction_New(method, NULL);
		if (func == NULL)
			return (NULL);
		meth = PyMethod_New(func, NULL, klass);
		if (meth == NULL)
			return (NULL);
		if (PyDict_SetItemString(dict, method->ml_name, meth))
			return (NULL);
		Py_DECREF(meth);
		Py_DECREF(func);
	}
	return (klass);
}
Beispiel #12
0
static PyObject *ffi_new_allocator(FFIObject *self, PyObject *args,
                                   PyObject *kwds)
{
    PyObject *allocator, *result;
    PyObject *my_alloc = Py_None, *my_free = Py_None;
    int should_clear_after_alloc = 1;
    static char *keywords[] = {"alloc", "free", "should_clear_after_alloc",
                               NULL};
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOi:new_allocator", keywords,
                                     &my_alloc, &my_free,
                                     &should_clear_after_alloc))
        return NULL;

    if (my_alloc == Py_None && my_free != Py_None) {
        PyErr_SetString(PyExc_TypeError, "cannot pass 'free' without 'alloc'");
        return NULL;
    }

    allocator = PyTuple_Pack(4,
                             (PyObject *)self,
                             my_alloc,
                             my_free,
                             PyBool_FromLong(should_clear_after_alloc));
    if (allocator == NULL)
        return NULL;

    {
        static PyMethodDef md = {"allocator",
                                 (PyCFunction)_ffi_new_with_allocator,
                                 METH_VARARGS | METH_KEYWORDS};
        result = PyCFunction_New(&md, allocator);
    }
    Py_DECREF(allocator);
    return result;
}
Beispiel #13
0
/**
 * Exports the different atk_role* functions into the module.
 */
void
atkrole_export_funcs (PyObject *module)
{
    int i = 0;
    PyObject *func;

    static PyMethodDef methods[] = { 
        { "atk_role_get_name", _role_get_name, METH_VARARGS,
          "atk_role_get_name (role) -> string\n\n"
          "Gets the description string describing the AtkRole role." },
        { "atk_role_get_localized_name", _role_get_localized_name,
          METH_VARARGS,
          "atk_role_get_localized_name (role) -> string\n\n"
          "Gets the localized description string describing the AtkRole role."
        },
        { "atk_role_for_name", _role_for_name, METH_VARARGS,
          "atk_role_for_name (name) -> int\n\n"
          "Get the AtkRole type corresponding to a role name." },
        { "atk_role_register", _role_register, METH_VARARGS,
          "atk_role_register (name) -> int\n\n"
          "Registers the role specified by name." },
        { NULL, NULL, 0, NULL }
    };

    while (methods[i].ml_name != NULL)
    {
        func = PyCFunction_New (&methods[i], NULL);
        PyObject_SetAttrString (module, methods[i].ml_name, func);
        i++;
    }
}
Beispiel #14
0
PyObject *GPU_initPython(void)
{
	PyObject *module = PyInit_gpu();
	PyModule_AddObject(module, "export_shader", (PyObject *)PyCFunction_New(meth_export_shader, NULL));
	PyDict_SetItemString(PyImport_GetModuleDict(), "gpu", module);

	return module;
}
Beispiel #15
0
void BPY_atexit_register(void)
{
	/* atexit module owns this new function reference */
	BLI_assert(func_bpy_atregister == NULL);

	func_bpy_atregister= (PyObject *)PyCFunction_New(&meth_bpy_atexit, NULL);
	atexit_func_call("register", func_bpy_atregister);
}
Beispiel #16
0
int BPY_rna_id_collection_module(PyObject *mod_par)
{
	static PyMethodDef user_map = {
	    "user_map", (PyCFunction)bpy_user_map, METH_VARARGS | METH_KEYWORDS, bpy_user_map_doc};

	PyModule_AddObject(mod_par, "_rna_id_collection_user_map", PyCFunction_New(&user_map, NULL));

	return 0;
}
Beispiel #17
0
/* 'builtins' is most likely PyEval_GetBuiltins() */
void bpy_import_init(PyObject *builtins)
{
	PyObject *item;
	PyObject *mod;

	PyDict_SetItemString(builtins, "__import__", item = PyCFunction_New(&bpy_import_meth, NULL)); Py_DECREF(item);

	/* move reload here
	 * XXX, use import hooks */
	mod = PyImport_ImportModuleLevel((char *)"imp", NULL, NULL, NULL, 0);
	if (mod) {
		PyDict_SetItemString(PyModule_GetDict(mod), "reload", item = PyCFunction_New(&bpy_reload_meth, NULL)); Py_DECREF(item);
		Py_DECREF(mod);
	}
	else {
		BLI_assert(!"unable to load 'imp' module.");
	}
}
Beispiel #18
0
static PyObject *
method_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type)
{
	PyObject *res;

	if (descr_check((PyDescrObject *)descr, obj, &res))
		return res;
	return PyCFunction_New(descr->d_method, obj);
}
Beispiel #19
0
//-------------------------------------------------------------------------------------
void ScriptVector2::onInstallScript(PyObject* mod)
{
	static PyMethodDef __unpickle__Method = {"Vector2", (PyCFunction)&ScriptVector2::__unpickle__, METH_VARARGS, 0};
	PyObject* pyFunc = PyCFunction_New(&__unpickle__Method, NULL);
	script::Pickler::registerUnpickleFunc(pyFunc, "Vector2");
	Py_DECREF(pyFunc);
	ScriptVector2::_scriptType.tp_as_number = &ScriptVector2::numberMethods;
	// ScriptVector2::_scriptType.tp_reserved = tp_compare;
	ScriptVector2::_scriptType.tp_name = "Vector2";
}
Beispiel #20
0
static PyObject *PythonQtClassWrapper_getattro(PyObject *obj, PyObject *name)
{
  const char *attributeName;
  PythonQtClassWrapper *wrapper = (PythonQtClassWrapper *)obj;

#ifdef PY3K
  if ((attributeName = PyUnicode_AsUTF8(name)) == NULL) {
#else
  if ((attributeName = PyString_AsString(name)) == NULL) {
#endif
    return NULL;
  }
  if (obj == (PyObject*)&PythonQtInstanceWrapper_Type) {
    return NULL;
  }

  if (qstrcmp(attributeName, "__dict__")==0) {
    PyObject* objectDict  = ((PyTypeObject *)wrapper)->tp_dict;
    if (!wrapper->classInfo()) {
      Py_INCREF(objectDict);
      return objectDict;
    }
    PyObject* dict = PyDict_New();
      
    QStringList l = wrapper->classInfo()->memberList();
    Q_FOREACH (QString name, l) {
      PyObject* o = PyObject_GetAttrString(obj, name.toLatin1().data());
      if (o) {
        PyDict_SetItemString(dict, name.toLatin1().data(), o);
        Py_DECREF(o);
      } else {
        // it must have been a property or child, which we do not know as a class object...
        PyErr_Clear();
      }
    }
    if (wrapper->classInfo()->constructors()) {
#ifdef PY3K
      PyObject* initName = PyUnicode_FromString("__init__");
#else
      PyObject* initName = PyString_FromString("__init__");
#endif
      PyObject* func = PyType_Type.tp_getattro(obj, initName);
      Py_DECREF(initName);
      PyDict_SetItemString(dict, "__init__", func);
      Py_DECREF(func);
    }
    for (int i = 0; PythonQtClassWrapper_methods[i].ml_name != NULL; i++) {
      PyObject* func = PyCFunction_New(&PythonQtClassWrapper_methods[i], obj);
      PyDict_SetItemString(dict, PythonQtClassWrapper_methods[i].ml_name, func);
      Py_DECREF(func);
    }

    PyDict_Update(dict, objectDict);
    return dict;
  }
Beispiel #21
0
int start(int argc, wchar_t **argv)
{
	int rc;
	PyObject *mod;
	PySys_SetArgvEx(argc, argv, 0);

	mod = PyImport_ImportModule("sys");
	if (mod) {
		PyObject_SetAttrString(mod,
				       method[0].ml_name,
				       PyCFunction_New(&method[0], NULL));
		PyObject_SetAttrString(mod,
				       method[1].ml_name,
				       PyCFunction_New(&method[1], NULL));
	}

	rc = run_script();
	fini();
	return rc;
}
Beispiel #22
0
void
LDAPadd_methods( PyObject* d, PyMethodDef* methods ) 
{
    PyMethodDef *meth;

    for( meth = methods; meth->ml_meth; meth++ ) {
        PyObject *f = PyCFunction_New( meth, NULL );
        PyDict_SetItemString( d, meth->ml_name, f );
        Py_DECREF(f);
    }
}
Beispiel #23
0
int BPY_library_write_module(PyObject *mod_par)
{
	static PyMethodDef write_meth = {
		"write", (PyCFunction)bpy_lib_write,
		METH_STATIC | METH_VARARGS | METH_KEYWORDS,
		bpy_lib_write_doc,
	};

	PyModule_AddObject(mod_par, "_library_write", PyCFunction_New(&write_meth, NULL));

	return 0;
}
VOID binding_insert_command(const char* commandName)
{
	static PyMethodDef def;
	dprintf("[PYTHON] inserting command %s", commandName);
	def.ml_name = commandName;
	def.ml_meth = binding_invoke;
	def.ml_flags = METH_VARARGS;
	def.ml_doc = NULL;

	PyObject* fun = PyCFunction_New(&def, gMeterpreterModule);
	PyModule_AddObject(gMeterpreterModule, commandName, fun);
}
Beispiel #25
0
/**
 * Binds the AtkStreamableContent methods to the passed object instance.
 */
void
atkstreamableiface_add_methods (PyObject *self)
{
    int i = 0;
    PyObject *func;
    
    while (_atkstreamableiface_methods[i].ml_name != NULL)
    {
        func = PyCFunction_New (&_atkstreamableiface_methods[i], NULL);
        PyObject_SetAttrString (self, _atkstreamableiface_methods[i].ml_name,
                                func);
        i++;
    }
}
Beispiel #26
0
/*
 * The descriptor's descriptor get slot.
 */
static PyObject *sipMethodDescr_descr_get(PyObject *self, PyObject *obj,
        PyObject *type)
{
    sipMethodDescr *md = (sipMethodDescr *)self;

    (void)type;

    if (obj == Py_None)
        obj = NULL;
    else if (md->mixin_name != NULL)
        obj = PyObject_GetAttr(obj, md->mixin_name);

    return PyCFunction_New(md->pmd, obj);
}
Beispiel #27
0
/**
 * \note to the discerning developer, yes - this is nasty
 * monkey-patching our own import into Python's builtin 'imp' module.
 *
 * However Python's alternative is to use import hooks,
 * which are implemented in a way that we can't use our own importer as a
 * fall-back (instead we must try and fail - raise an exception every time).
 * Since importing from blenders text-blocks is not the common case
 * I prefer to use Pythons import by default and fall-back to
 * Blenders - which we can only do by intercepting import calls I'm afraid.
 * - Campbell
 */
void bpy_import_init(PyObject *builtins)
{
	PyObject *item;
	PyObject *mod;

	PyDict_SetItemString(builtins, "__import__", item = PyCFunction_New(&bpy_import_meth, NULL)); Py_DECREF(item);

	/* move reload here
	 * XXX, use import hooks */
	mod = PyImport_ImportModuleLevel("importlib", NULL, NULL, NULL, 0);
	if (mod) {
		PyObject *mod_dict = PyModule_GetDict(mod);

		/* blender owns the function */
		imp_reload_orig = PyDict_GetItemString(mod_dict, "reload");
		Py_INCREF(imp_reload_orig);

		PyDict_SetItemString(mod_dict, "reload", item = PyCFunction_New(&bpy_reload_meth, NULL)); Py_DECREF(item);
		Py_DECREF(mod);
	}
	else {
		BLI_assert(!"unable to load 'importlib' module.");
	}
}
Beispiel #28
0
static PyObject *ffi_new_allocator(FFIObject *self, PyObject *args,
                                   PyObject *kwds)
{
    PyObject *allocator, *result;
    PyObject *my_alloc = Py_None, *my_free = Py_None;
    int should_clear_after_alloc = 1;
    static char *keywords[] = {"alloc", "free", "should_clear_after_alloc",
                               NULL};
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOi:new_allocator", keywords,
                                     &my_alloc, &my_free,
                                     &should_clear_after_alloc))
        return NULL;

    if (my_alloc == Py_None && my_free != Py_None) {
        PyErr_SetString(PyExc_TypeError, "cannot pass 'free' without 'alloc'");
        return NULL;
    }

    allocator = PyTuple_New(4);
    if (allocator == NULL)
        return NULL;

    Py_INCREF(self);
    PyTuple_SET_ITEM(allocator, 0, (PyObject *)self);

    if (my_alloc != Py_None) {
        Py_INCREF(my_alloc);
        PyTuple_SET_ITEM(allocator, 1, my_alloc);
    }
    if (my_free != Py_None) {
        Py_INCREF(my_free);
        PyTuple_SET_ITEM(allocator, 2, my_free);
    }
    if (!should_clear_after_alloc) {
        PyObject *my_true = Py_True;
        Py_INCREF(my_true);
        PyTuple_SET_ITEM(allocator, 3, my_true);  /* dont_clear_after_alloc */
    }

    {
        static PyMethodDef md = {"allocator",
                                 (PyCFunction)_ffi_new_with_allocator,
                                 METH_VARARGS | METH_KEYWORDS};
        result = PyCFunction_New(&md, allocator);
    }
    Py_DECREF(allocator);
    return result;
}
Beispiel #29
0
int fsb_dx_addmethods(PyObject *m, PyMethodDef *methods, PyObject *passthrough) {
    PyObject *d, *v;
	PyMethodDef *ml;
	d = PyModule_GetDict(m);
	for (ml = methods; ml->ml_name != NULL; ml++) {
		v = PyCFunction_New(ml, passthrough);
		if (v == NULL)
			return -1;
		if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {
			Py_DECREF(v);
			return -1;
		}
		Py_DECREF(v);
	}
    return 0;
}
Beispiel #30
0
int bpy_lib_init(PyObject *mod_par)
{
	static PyMethodDef load_meth = {"load", (PyCFunction)bpy_lib_load,
	                               METH_STATIC|METH_VARARGS|METH_KEYWORDS,
	                               bpy_lib_load_doc};

	PyModule_AddObject(mod_par, "_library_load", PyCFunction_New(&load_meth, NULL));

	/* some compilers dont like accessing this directly, delay assignment */
	bpy_lib_Type.tp_getattro = PyObject_GenericGetAttr;

	if (PyType_Ready(&bpy_lib_Type) < 0)
		return -1;

	return 0;
}