Bug in execute_from_str

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
BramPeeters
Posts: 49
Joined: Wed Jan 31, 2018 3:10 pm

Re: Bug in execute_from_str

Post by BramPeeters » Tue Sep 18, 2018 4:04 pm

Additional related question:
I just saw that the fix was modified again with the

Code: Select all

qstr src_name = 0/*MP_QSTR_*/;

vs

Code: Select all

qstr src_name = 1/*MP_QSTR_*/;


Which begs the question, why the direct hard coded value and not

Code: Select all

qstr src_name = MP_QSTR_; 


I just tried and it compiles and runs fine resolving to the correct value 1. And I can't immediately find a reason in the forum threads either (but i did not check all the qstr hits, returns a *lot* :) )

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Bug in execute_from_str

Post by jickster » Tue Sep 18, 2018 4:58 pm

BramPeeters wrote:
Tue Sep 18, 2018 4:04 pm
Additional related question:
I just saw that the fix was modified again with the

Code: Select all

qstr src_name = 0/*MP_QSTR_*/;

vs

Code: Select all

qstr src_name = 1/*MP_QSTR_*/;


Which begs the question, why the direct hard coded value and not

Code: Select all

qstr src_name = MP_QSTR_; 


I just tried and it compiles and runs fine resolving to the correct value 1. And I can't immediately find a reason in the forum threads either (but i did not check all the qstr hits, returns a *lot* :) )
This is 0 and 1

Code: Select all

QDEF(MP_QSTR_NULL, (const byte*)"\x00\x00\x00" "")
QDEF(MP_QSTR_, (const byte*)"\x05\x15\x00" "")
Makes more sense for default to be null.

BramPeeters
Posts: 49
Joined: Wed Jan 31, 2018 3:10 pm

Re: Bug in execute_from_str

Post by BramPeeters » Tue Sep 18, 2018 7:06 pm

I don't really have insight in which one would be better (empty string or NULL), but i am just wondering about the usage of the hard coded 0/1 value versus the 'named' values MP_QSTR_NULL/MP_QSTR_

Reason being that i need to pass an empty string object myself, so then I remembered this fix and I started wondering is there anything wrong with using MP_OBJ_NEW_QSTR(MP_QSTR_) versus MP_OBJ_NEW_QSTR(1) for some reason ? I would expect the former to be very, very much the preferred way.

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Bug in execute_from_str

Post by jickster » Tue Sep 18, 2018 7:09 pm

BramPeeters wrote:I don't really have insight in which one would be better (empty string or NULL), but i am just wondering about the usage of the hard coded 0/1 value versus the 'named' values MP_QSTR_NULL/MP_QSTR_

Reason being that i need to pass an empty string object myself, so then I remembered this fix and I started wondering is there anything wrong with using MP_OBJ_NEW_QSTR(MP_QSTR_) versus MP_OBJ_NEW_QSTR(1) for some reason ? I would expect the former to be very, very much the preferred way.
I agree. Using magic numbers is bad.


Sent from my iPhone using Tapatalk Pro

Post Reply