-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
mp_ prefix collision #704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Why don't you submit requests to those libraries asking them to change their prefixes? |
I think that would be fair. Trouble is many users already use them, so it would require to change a large code base, whereas micropython is fairly new, so there is a small opportunity window it does not bother to many people - yet. It will be the same issue with micropython in a couple of weeks/months. This was just an early warning, I do not mind that much as I already locally changed some of the micropython's |
What particular libraries clashed with your build of uPy? Ultimately, with C, there is no proper solution to this problem. We could wrap all externally exported identifiers in some macro, which prefixes some long (and configurable) name to all ids. Some projects do this (I think...) but it's a pretty extreme solution. Else, we choose a longer (and more unique) name. But one day it will clash again. A different solution is to provide a script which renames the source automagically. |
ctaocrypt, from WolfSSL http://www.yassl.com/yaSSL/Products-cyassl.html I agree there is no universal solution :-( The shorter it is, the more likely the collisions. For ex, "googling" mp_init give 94K results, mpy_init gives 72, but none with this lower case syntax. The script/renaming is a solution can make upstream merges/diffs a nightmare. |
Why we, they should do it! ;-) Seriously, I agree that this is an issue, and it would be nice to resolve it. I comment in such way because IMHO we already made some naming choices with look-back at the other projects, which restrained uPy. And now this potential change breaking "git blame" usage all around, while, as @dpgeorge says, sooner or later someone won't be satisfied again anyway. |
Another approach would be to just create a header which #defines the mp_foo There are linker games that can be played as well.
|
All projects that aim to be embedded should do it this way :) Options:
I'm thinking that you need to wrap everything: functions, global vars (not many of those), types, constants, macros, etc. But maybe we can get away with just function names and global vars?? |
We can also switch to C++ sooner rather than later (hey, we're going to switch to C++, right? ;-) ). So, we could start with just using namespaces. One problem is that the stupid thing doesn't support named structure initializers... |
Such mechanism is important to get stable Python functioning, because Python function calling is handled with C stack. The idea is to sprinkle STACK_CHECK() calls in places where there can be C recursion. TODO: Add more STACK_CHECK()'s.
I give this good thought-over these months, and think that this request makes sense after all. We should support uPy embedding in other projects, and make people's like who doing this as easy as possible. So, if some prefix is indeed reported to be used by many different projects, up to causing real-world collisions, we should do something about that. But we indeed cannot flip name prefixes again and again, so some planning is required:
Thoughts? |
+1 from me. How about a macro wrapper around all public API functions and types so that the prefix can be configured by a #define? Eg: MICROPY_TYPE(int) val = MICROPY_API(obj_get_int, obj_in);
if (MICROPY_API(obj_is_list, obj_in)) { ... } Yes, it's a pain to write it out for every call, but that's the price you pay for a 100% bullet-proof solution (except for name-collision of macros...). Additional benefit of wrapping every call is that we then have the option to use macro-magic to change the calling conventions (to some extent). For example, adding a global/thread state argument to each function. This could be a compile time option, enabled for ports that need it. Otherwise I would suggest using |
I would call it over-engineering at this stage ;-I.
That's tempting, but I still think it's premature at this stage. If/when we'd come to that, that may be a separate change. But anyway, you have better outlook, so if you think that's the right way to go right away, feel free to. But
Yes, apparently that's more robust than |
Agree... actually, it doesn't improve the situation more than prefixing with
It is, and maybe we should just go for the long version from the beginning, so we don't run into this issue again. But then it's going to get ugly, eg: micropy_obj_t micropy_obj_list_sort(micropy_uint_t n_args, const micropy_obj_t *args, micropy_map_t *kwargs); |
Well, I've been thinking mostly about symbols, but yes, there're types too... Well, the above certainly looks long (as a line) and micropy_uint_t looks funny, but it's not something which cannot be gotten used to. Bute we should collect more opinions from other folks. |
It's a tough one. |
Yes, I don't think we should mix C++ into this. I'd love to see C++ being used, but for template metaprogramming to achieve super-efficiency, rather than aux hacks like namespaces. We're long way from that though, and getting C code right (like we discuss here) is on critical path to it. And switching to C++ makes to become FUD target from unwise people, like http://harmful.cat-v.org/software/c++/linus Other ideas are good, except make @dpgeorge's choice even harder ;-). |
My take on this is that the only place we really have to worry about conflicts is with the linker. If we switch to traditional headers, and turf the plan-9 stuff then it essentially becomes trivial to have a header file which maps all/some/just the conflicting symbols into something else. Once you can map the symbols to be arbitrary, then I think we should just stick with what we have. Has anybody embedded micropython yet, let alone had conflicts? If it ain't broke don't fix it. |
I had conflicts, with CyaSSL/ctaocrypt (now WolfSSL). The issue can be "fixed" with macros or linker rules, but it usually makes the code harder to read at debug time. micropython seems quite obtrusive, upy_ seems unique (in C language) |
I think we should be "conservative" and provide a better solution than linker/macro tricks. For example, if someone wants to use both uPy and some other library (which has Options so far:
We should do a survey of code to see if |
Note: we should probably rename the py/ directory to match the chosen prefix. |
Also, reword purpose to avoid impression that uPy supports just one microcontroller.
upy_. It seems like many here use uPy to refer to the project. (upython was my first google search for this project when someone told me verbally that I should check it out.) |
This appears to have a relatively small impact on flash usage but fixes some pathological slow behavior putting floats in dicts or sets. Closes: micropython#704
Nearly 10 years have passed, and the practical problems from this seem to have been pretty small. Perhaps it is OK the way it is? :) |
FWIW, there are many libraries out there that use the
mp_
prefix. For example,ctaocrypt
, a library with big number primitives used for cryptography and SSL implementation from CyaSSL/WolfSSL dedicated to embedded targets. A quick search on Google shows thatmp_
is used in many libraries.On embedded targets, especially with static linking, this creates name collision at link time.
Maybe it would be worth using a less common prefix, such as
mpy_
?It is likely that micropython becomes highly popular as it deserves to. Linking with other 3rd party libraries - hence collision occurences would grow.
The text was updated successfully, but these errors were encountered: