[C++-sig] Re: Problem with embedding python with boost.python

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Mon Jul 7 11:56:43 CEST 2003


I copied it just because the PyRun_String command take a "char *" and 
that latin1 returns a "const char*" ... si you have to copy it !

For my other problem, I just solved it ... the solution is to replace 
the AppendInittab by :
PyImport_AppendInittab("editor", initeditor)

and ti define initeditor with :

extern "C" void initeditor();

... when testing I forgot the 'extern "C"' !

Now it works and I'm working on your recommandations to retrieve the 
output !

Tanks !

Dirk Gerrits wrote:

> Dirk Gerrits wrote:
>
>> command.latin1() is not null-terminated I think, which would make the 
>> strcpy fail. (Not sure, I don't use Qt.) Wouldn't it be easier and 
>> safer to do:
>>
>> QString cmd = command + '\0';
>> ...
>> PyObject *obj = PyRun_String(cmd.latin1(), Py_file_input,
>>     main_namespace.ptr(), main_namespace.ptr());
>>
>> ?
>
>
> Ah I just read that latin1() DOES provide a null-terminated string. 
> Sorry.
>
> But then I don't understand why you were copying it in the first 
> place. Care to elaborate?
>
> Regards,
> Dirk Gerrits
>
>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>


-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68 






More information about the Cplusplus-sig mailing list