Mercurial > pytave
changeset 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 | d4744d829ee0 |
children | e89a8a37fd8a |
files | @pyobject/pyobject.m |
diffstat | 1 files changed, 7 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/@pyobject/pyobject.m Wed Aug 10 15:41:05 2016 -0700 +++ b/@pyobject/pyobject.m Thu Aug 11 10:15:26 2016 -0700 @@ -50,14 +50,14 @@ " __import__('__main__')._InOctave = dict()" ]; pyexec (cmd); - ## XXX: perhaps not the ideal implementation! - vars = pyeval ("__import__('__main__').__dict__"); - ## this is vars{"_temp"} = x - idx = struct ("type", "{}", "subs", {{"_temp"}}); - vars = subsasgn (vars, idx, x); + ## Function to insert and return the hex id + cmd = [ "def _in_octave_insert(x):\n" ... + " h = hex(id(x))\n" ... + " __import__('__main__')._InOctave[h] = x\n" ... + " return h" ]; + pyexec (cmd); - pyexec ("__import__('__main__')._InOctave[hex(id(_temp))] = _temp") - id = pyeval (["hex(id(_temp))"]); + id = pycall ("_in_octave_insert", x); obj = pyobject (0, id); endif return