[C++-sig] void* cast to a specific type based on string name

Renato Araujo renatox at gmail.com
Fri Oct 3 23:38:11 CEST 2008


Hi thanks again, I found some e-mails about this, but my problem continue:

now I reimplemented the function to some like that:

void call_Pyfunction(int argc, char **types, void **args, PyObject *callbak)
{
    boost::python::list pyArgs;
    for (int i=0; i <= count; i++)
    {
        pyArgs.append(args[i]);
    }
    callback(pyArgs);
}

but the error still happen:
If i put the correct cast before "args[i]" this works fine;

..........
    for (int i=0; i <= count; i++)
    {
        pyArgs.append(*(int *)args[i]);
    }
..........

Thanks
Renato

On Fri, Oct 3, 2008 at 4:18 PM, Roman Yakovenko
<roman.yakovenko at gmail.com> wrote:
> On Fri, Oct 3, 2008 at 10:06 PM, Renato Araujo <renatox at gmail.com> wrote:
>> Hi thanks for your help, but I already tried this:
>>
>> This is the code:
>>
>> void call_Pyfunction(int argc, char **types, void **args, PyObject *callbak)
>> {
>>     PyObject *pyargs = PyTuple_New(argc);
>>     for (int i=0; i < argc; i++)
>>     {
>>        PyObject *o = boost::python::object(args[i]).ptr();
>>        PyTuple_SetItem(pyargs, i, boost::python::incref(o));
>>     }
>>     PyObject_Call(callback, pyargs, NULL);
>> }
>>
>> I got this error during the object creation:
>>
>> terminate called after throwing an instance of
>> 'boost::python::error_already_set'
>
> I would find out what cause the error.
>
> It seems that you are trying to implement functionality that already
> exists in trunk.
> Search this mailing list, there are few posts that discuss how to call
> any python function.
>
>
> --
> Roman Yakovenko
> C++ Python language binding
> http://www.language-binding.net/
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>



-- 
Renato Araujo Oliveira Filho



More information about the Cplusplus-sig mailing list