Fedora and Python 2
Fedora and Python 2
Posted Apr 8, 2018 23:00 UTC (Sun) by mjblenner (subscriber, #53463)In reply to: Fedora and Python 2 by smurf
Parent article: Fedora and Python 2
Uh, no. The bit that gets the symbols from the dll is using bytes. This bit:
some_dll[b'c_function_name']
You can't refer to it in python by the same random bytes though (why would that matter?).
Posted Apr 11, 2018 22:06 UTC (Wed)
by togga (guest, #53103)
[Link] (7 responses)
Because scripting is mostly about automation. It's just broken in this case to convert these symbols to another representation. This is just one example of many in this theme since many of the libraries and third party extensions needs string representation.
In a glue language scenario (which has been a strong side of Python), if I want to grab symbol (or blob) X from system A, handle it and pass it to system B, I do not want to have Y=f(X) as intermediate representation and then do the inverse function before passing it to B.
Simple things such as reading from an UART or a socket has become a mine-field as soon as you want to use something in Python dealing with strings. Especially annoying when developing and things might not be that clean, nice and tidy.
This whole problem-domain is something Python3 has created. For me, Python itself lacks both in performance and multi-threading and doesn't really have anything language-wise (apart from lots of third party libraries) to compensate for this loss of productivity.
Posted Apr 11, 2018 23:52 UTC (Wed)
by smurf (subscriber, #17840)
[Link] (1 responses)
Well, all I can say is that my experience (both with Perl5 and Python2) is rather different. Our fight with Perl5, incrementally switching our corporate code base to UTF8 compatibility, was … ugly.
Thus I'm very happy about the fact that Python3 spews a large unfriendly stack dump to your terminal when I forget to specify how an external byte stream is encoded. While it's somewhat annoying when you JUST KNOW that all your data is UTF8, or latin1, or randombytes … things change, and when it "suddenly" isn't, you get mojibake. Or worse. No thanks.
Posted Apr 12, 2018 16:29 UTC (Thu)
by togga (guest, #53103)
[Link]
The latter sounds to me like utopia and an endless job for achieving nothing but explains lots of the attitudes of the Python community.
Posted Apr 12, 2018 1:12 UTC (Thu)
by mjblenner (subscriber, #53463)
[Link] (1 responses)
OK. I kind of get where you're coming from. Although I'm a bit confused. Or you're a bit confused.
ctypes is an ABI interface, so having the structure field be a different name to the function symbol is of no relevance for using python to glue various other C functions together (even when passing that structure around).
i.e. here:
> type('iface', (ctypes.Structure,), {'_fields_': [(b'c_string_symbol', ...
Anyway, the easy answer is to just use python strings there. ctypes function symbol lookup converts strings to utf-8, so 99%+ of the time, this will work.
Otherwise...
Decode the symbol name to a string with errors='surrogateescape' for use in python, and use the same error handler to decode back to the original bytes for getting the symbol out of the library.
Or you could add a layer of indirection between the structure field names and the function symbols.
Posted Apr 12, 2018 16:36 UTC (Thu)
by togga (guest, #53103)
[Link]
I'm not confused, I'm just experienced lots of issues I didn't have before Python3's software castle in the air.
> "the easy answer is to just use python strings"
Isn't this kind of bloated. These strings can come from anywhere and might not even be visible in Python code at all.
> "Decode the symbol name to a string with errors='surrogateescape' for use in python, and use the same error handler to decode back to the original bytes for getting the symbol out of the library."
You mean use Python3 and stick with tons of workarounds and issues just for it's sake? Change the whole world to Python3? I value my time much more than that.
Posted Apr 12, 2018 23:47 UTC (Thu)
by dvdeug (guest, #10998)
[Link] (2 responses)
If you're just passing something from system A to system B, you shouldn't have to change the data. But there's a fairly thin region where you can choose to not unmangle something and still expect to be able to do anything with it. Stuff not being clean, nice and tidy is all the more reason to make sure you know exactly how the data you're handling is formatted.
Posted Apr 15, 2018 15:13 UTC (Sun)
by togga (guest, #53103)
[Link] (1 responses)
1. Doesnt scale. Changing representation requires one additional pass over the data. Python is already slow to begin with.
Posted Apr 15, 2018 20:53 UTC (Sun)
by dvdeug (guest, #10998)
[Link]
We're not talking about human readable symbols; we're talking about "non-ASCII symbols in your program" that aren't Unicode. Even if the editor mangles it for you, how is bsymFFEAA9 worse than \xff\xea\xa9? Something slightly smarter than base64 would preserve human readable names and only mangle unreadable names, but the only case where not worrying about mangling is going to cause problems in Python 3 is when it's not human readable.
Fedora and Python 2
Fedora and Python 2
Fedora and Python 2
Fedora and Python 2
Fedora and Python 2
> "Or you could add a layer of indirection between the structure field names and the function symbols."
Fedora and Python 2
Fedora and Python 2
2. Accessing human readable symbols is convenient when needed by scripts, tests or debug.
Fedora and Python 2