TinyCircuits / TinyCircuits-Thumby-Code-Editor

https://code.thumby.us/
GNU General Public License v3.0
30 stars 20 forks source link

Fix emulator hanging for thumbySaves.saveData.getItem and delItem #63

Closed fuglaro closed 1 year ago

fuglaro commented 1 year ago

FIXES #62

micropython.native. For this code:

@micropython.native
def hang():
    try:
        pass
    except:
        pass

print(1)
hang()
print(2) # Never shows

I get this when running in FAST EXECUTE:

>>> 
1
2
>

BUT this when running in the emulator?!?!?!

>>> __import__('/sdfsdfsd')
1
masonova1 commented 1 year ago

Also posted on the issue post #63:

We might keep the native emitter if we can get rid of the exceptions. Try these changes and see if the problem is still reproduced:

    # Get entry from volatile dictionary
    @micropython.native
    def getItem(self, key):
        ret = self.volatileDict.get(key, None)
        if ret is None:
            # Look for a bytes item under the key
            ret = self.volatileDict.get("__b"+key, None)
            return (None if ret is None else b64dec(ret))
        return ret

    # Delete entry in volatile dictionary
    @micropython.native
    def delItem(self, key):
        ret = self.volatileDict.pop(key, None)
        if ret is None:
            ret = self.volatileDict.pop("__b"+key, None)
            return (None if ret is None else b64dec(ret))
        return ret
fuglaro commented 1 year ago

That's better and I tested it in the emulator and that fixes it and works great!