Mercurial > pytave
comparison @pyobject/pyobject.m @ 349:140e37e8e95a
Don't create pyobjects within the pyobject ctor
It seems to work, but maybe there are subtle bugs.
* @pyobject/pyobject.m: Use an insert function.
author | Colin Macdonald <cbm@m.fsf.org> |
---|---|
date | Thu, 11 Aug 2016 10:15:26 -0700 |
parents | 7f039ffe501b |
children | e89a8a37fd8a |
comparison
equal
deleted
inserted
replaced
348:d4744d829ee0 | 349:140e37e8e95a |
---|---|
48 ## Ensure _InOctave dict exists | 48 ## Ensure _InOctave dict exists |
49 cmd = [ "if not getattr(__import__('__main__'), '_InOctave', None):\n" ... | 49 cmd = [ "if not getattr(__import__('__main__'), '_InOctave', None):\n" ... |
50 " __import__('__main__')._InOctave = dict()" ]; | 50 " __import__('__main__')._InOctave = dict()" ]; |
51 pyexec (cmd); | 51 pyexec (cmd); |
52 | 52 |
53 ## XXX: perhaps not the ideal implementation! | 53 ## Function to insert and return the hex id |
54 vars = pyeval ("__import__('__main__').__dict__"); | 54 cmd = [ "def _in_octave_insert(x):\n" ... |
55 ## this is vars{"_temp"} = x | 55 " h = hex(id(x))\n" ... |
56 idx = struct ("type", "{}", "subs", {{"_temp"}}); | 56 " __import__('__main__')._InOctave[h] = x\n" ... |
57 vars = subsasgn (vars, idx, x); | 57 " return h" ]; |
58 | 58 pyexec (cmd); |
59 pyexec ("__import__('__main__')._InOctave[hex(id(_temp))] = _temp") | 59 |
60 id = pyeval (["hex(id(_temp))"]); | 60 id = pycall ("_in_octave_insert", x); |
61 obj = pyobject (0, id); | 61 obj = pyobject (0, id); |
62 endif | 62 endif |
63 return | 63 return |
64 endif | 64 endif |
65 | 65 |