TPython: Python function returning string incorrectly

I’m having trouble running the examples in the TPython documentation page. I create a file called

[code]print 'creating class MyPyClass … ’

class MyPyClass:
def init( self ):
print ‘in MyPyClass.init

def gime( self, what ):
return what
and, then run ROOT (5.26/00b) and do:

mwilliam@lxplus303:~/ > root -l root [0] TPython::LoadMacro( "" ); creating class MyPyClass ... root [1] MyPyClass m; in MyPyClass.__init__ root [2] char* s = m.gime( "aap" ); root [3] s (char* 0x3057140)"D@��*"
As you can see this is not returning “aap” but rather a random (presumably Unicode-type) string. In fact if I run the whole sequence again I get a different result of “�?)�S” or “�_��^” etc.

Given that I am running the example exactly as it is written I can’t see why this isn’t working. I’ve tried saving the .py file with different encodings such as UTF-8 and ASCII but it doesn’t seem to make a difference. Does anyone have any idea why this might be happening?



seems that something has changed in that CINT no longer calls the conversion operator of the TPyReturn class, apparently since CINT does no longer recognize the return result as a TPyReturn (it’s not clear to me though what it does think it is, though).

Making things more explicit does work:char* s = (const char*)(*(TPyReturn*)m.gime( "aap" )); I’ll see whether I can unearth where things go wrong.



that code needed some cleaning to catch up with recent change. Now in trunk. Thanks for reporting! (The unit test was using the full explicit cast so it didn’t pick this up.)


Thank you. The implicit cast does indeed work as it should and it’s good to know this will be fixed in ROOT proper.