Loading modules from files through C++

Roland Plüss roland at rptd.ch
Tue Jul 8 21:18:21 CEST 2014


> On Wed, May 21, 2014 at 3:17 AM, Roland Plüss <roland at rptd.ch> wrote:
>> The important part are the last two lines. An important module is
>> lacking the __builtins__ dictionary member so I had to add it.
>>
>> Hopefully this works also in Py3 should I switch some time later. But I
>> guess it should seeing how simple the import now became.
> An interesting omission, I'm a little surprised at that. But if your
> switch to Py3 is a serious (or even half-serious) possibility, I
> recommend tossing a quick comment against that line of code. Check to
> see if you actually need it, and if you still do, see if there's a
> change there. The module has been renamed (from __builtin__ to
> builtins, although the global reference to it is still __builtins__),
> so you may need to adjust something there, too. But mainly, see if you
> can drop that line of code in Py3.
>
>> Furthermore I had to call the string runner with moduleDict both as
>> global and local dictionary. With that change the virtual script is
>> properly loaded and working as it should.
> This part does make sense, though. Normally, module-level code runs
> with the same locals and globals:
>
>>>> locals() is globals()
> True
>
> And that doesn't change in Py3, so I would expect that your C++ code
> also won't change.
>
> ChrisA
I changed now a couple of things and it looks like the segfault happens
somewhere inside PyErr_Print(). So I've programatically loaded a script
into a new module using load_module and a module created by hand. If now
in this script I've loaded an error is located the crash happens. The
situation thus looks like this. Let's say Script.py is my script. The
call chain would be something like this for example:

someNativeClass.cpp : someFunction()
Script.py : def run()
main.cpp

The error is due to a
    if( ! PyArg_ParseTuple( args, "iiii", &x1, &y1, &x2, &y2 ) ){
        return NULL;
    }

Thus the PyErr_Print() would have to print in the stack trace two C++
class, one in the someNativeClass and one generated for the loaded
Script.py . It looks like Python 3 expects something from the C++
classes not written in the documentation.

What could a C++ class require to be working being included in a stack
trace like this?

-- 
Yours sincerely
Plüss Roland

Leader and Head Programmer
- Game: Epsylon ( http://www.indiedb.com/games/epsylon )
- Game Engine: Drag[en]gine ( http://www.indiedb.com/engines/dragengine
, http://dragengine.rptd.ch/wiki )
- Normal Map Generator: DENormGen ( http://epsylon.rptd.ch/denormgen.php )
- As well as various Blender export scripts und game tools

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 246 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20140708/26b4c5d0/attachment.sig>


More information about the Python-list mailing list