{"action":"created","issue":{"url":"https://api.github.com/repos/micropython/micropython/issues/1761","labels_url":"https://api.github.com/repos/micropython/micropython/issues/1761/labels{/name}","comments_url":"https://api.github.com/repos/micropython/micropython/issues/1761/comments","events_url":"https://api.github.com/repos/micropython/micropython/issues/1761/events","html_url":"https://github.com/micropython/micropython/issues/1761","id":124637264,"number":1761,"title":"uctypes: segfaults with an array of structs?","user":{"login":"dhylands","id":127500,"avatar_url":"https://avatars.githubusercontent.com/u/127500?v=3","gravatar_id":"","url":"https://api.github.com/users/dhylands","html_url":"https://github.com/dhylands","followers_url":"https://api.github.com/users/dhylands/followers","following_url":"https://api.github.com/users/dhylands/following{/other_user}","gists_url":"https://api.github.com/users/dhylands/gists{/gist_id}","starred_url":"https://api.github.com/users/dhylands/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhylands/subscriptions","organizations_url":"https://api.github.com/users/dhylands/orgs","repos_url":"https://api.github.com/users/dhylands/repos","events_url":"https://api.github.com/users/dhylands/events{/privacy}","received_events_url":"https://api.github.com/users/dhylands/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-03T08:35:33Z","updated_at":"2016-01-03T08:43:39Z","closed_at":null,"body":"I ran into this just before I went to bed, so I haven't had a chance to look into it yet. I created the following simplfied file:\r\n```python\r\nimport uctypes\r\n\r\ndesc = {\r\n    'f1': (uctypes.ARRAY | 0, 8, {\r\n        'b1': uctypes.UINT8 | 0,\r\n        'b2': uctypes.UINT8 | 1,\r\n    })\r\n}\r\n\r\nbuf = bytearray(b'0123456789ABCDEF')\r\n\r\nS = uctypes.struct(uctypes.addressof(buf), desc, uctypes.LITTLE_ENDIAN)\r\n\r\nfor i in range(4):\r\n    print('f1[%d].b1 =' % i, hex(S.f1[i].b1));\r\n    print('f1[%d].b2 =' % i, hex(S.f1[i].b2));\r\n```\r\nand it segfaults using unix micropython.\r\n\r\nIf I change LITTLE_ENDIAN to NATIVE then it seems to work fine."},"comment":{"url":"https://api.github.com/repos/micropython/micropython/issues/comments/168478997","html_url":"https://github.com/micropython/micropython/issues/1761#issuecomment-168478997","issue_url":"https://api.github.com/repos/micropython/micropython/issues/1761","id":168478997,"user":{"login":"dhylands","id":127500,"avatar_url":"https://avatars.githubusercontent.com/u/127500?v=3","gravatar_id":"","url":"https://api.github.com/users/dhylands","html_url":"https://github.com/dhylands","followers_url":"https://api.github.com/users/dhylands/followers","following_url":"https://api.github.com/users/dhylands/following{/other_user}","gists_url":"https://api.github.com/users/dhylands/gists{/gist_id}","starred_url":"https://api.github.com/users/dhylands/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhylands/subscriptions","organizations_url":"https://api.github.com/users/dhylands/orgs","repos_url":"https://api.github.com/users/dhylands/repos","events_url":"https://api.github.com/users/dhylands/events{/privacy}","received_events_url":"https://api.github.com/users/dhylands/received_events","type":"User","site_admin":false},"created_at":"2016-01-03T08:43:38Z","updated_at":"2016-01-03T08:43:38Z","body":"Although even with NATIVE, I get a segfault if I use bitfields:\r\n```python\r\nimport uctypes\r\n\r\ndesc = {\r\n    'f2': (uctypes.ARRAY | 4, 8, {\r\n        'b1': uctypes.UINT8 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,\r\n        'b2': uctypes.UINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,\r\n    })\r\n}\r\n\r\nbuf = bytearray(b'0123456789ABCDEF')\r\n\r\nS = uctypes.struct(uctypes.addressof(buf), desc, uctypes.NATIVE)\r\n\r\nfor i in range(4):\r\n    print('f2[%d].b1 =' % i, hex(S.f2[i].b1));\r\n    print('f2[%d].b2 =' % i, hex(S.f2[i].b2));\r\n```"}}