Weird inheritance assertion difference between embedded library and interpreter

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
yanh
Posts: 4
Joined: Mon Oct 11, 2021 4:53 pm

Weird inheritance assertion difference between embedded library and interpreter

Post by yanh » Tue Dec 14, 2021 8:30 am

Hey all,

I am trying to use the static library in example/embedding to try and run on a unix system.

When I do so, the following code throws an assertion error:

Code: Select all

class _Environ(dict):

    def __init__(self):
        dict.__init__(self) <------ That is the line that fails   :_(   :_(
        env = uctypes.struct(_environ_ptr.get(), _ENV_STRUCT)
        for i in range(4096):
            if int(env.arr[i]) == 0:
                break
            s = uctypes.bytes_at(env.arr[i]).decode()
            k, v = s.split("=", 1)
            dict.__setitem__(self, k, v)

    def __setitem__(self, k, v):
        putenv(k, v)
        dict.__setitem__(self, k, v)


environ = _Environ()
The assertion that occurs is on py/objdict.c - line 375,

Code: Select all

mp_check_self(mp_obj_is_dict_or_ordereddict(..))
When I run this with the `port/unix` however, this works just fine...


Can anyone please shed some light on this?
Last edited by yanh on Tue Dec 14, 2021 9:23 am, edited 1 time in total.

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: Weird inheritance assertion difference between embedded library and interpreter

Post by stijn » Tue Dec 14, 2021 9:01 am

Don't you need super().__init__(self) instead of dict.__init__(self)? (apart from that: not sure if subclassing builtins is actually fully supported)

Post Reply