- 
  Notifications
 You must be signed in to change notification settings 
- Fork 1.1k
ffilib: Initial version of wrapper for ffi module. #27
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
Conversation
You didn't run make_metadata.py script on this, did you? Its purpose is to generate setup.py from metatdata.txt.
There is a bit of code duplication here but I couldn't find a way to reduce it.
There's of course a way, possibly taking more heap space. But how it is should be good enough for v1.
I think I'd rather just allow a list of libs to be passed in and searched. It's much simpler.
Patching _libc.py with few lines was much simpler, but you decided to go a longer way ;-). There're various ways to tweak it, but as I said, should be good enough for v1. Possible tweaks: make "extra" a "wellknown", and start with them (that's to address your concern, I'm not sure it wouldn't be changed later again). Start with maxversion and down-count to 1. And well, you didn't even consider that on Windows, libpcre.so would likely be pcre.dll ;-)
So, again, this is good enough to go, once metadata is fixed. Let's make sure we know the next steps. And that would be adding a convenience method to load libc - as I mentioned, this new module is to replace _libc.py. So, suppose we add "libc()" function for that, which saves other modules from repeating params, us patching them in multiple places, and actually, it's quite adhoc matter (guess how libc is called under Windows).
What's next? On normal unix, socket API is part of normal API, but on windows, it's a separate DLL. So, need another convenience function in this module, which will return the same libc on unix, but adhoc lib on Windows. The idea is clear I hope. Thinking about naming convention for such functions beforehand may help then.
You didn't run make_metadata.py script on this, did you?
No, I just copied over from _libc/*. I guess the script should be called make_setup.py :)
There's of course a way, possibly taking more heap space.
Yeah, I didn't want to make an explicit list of all libs to try. But I just realised there is a way using generators:
def name_list():
 for ext in ('so', 'dylib', 'dll'):
 yield '%s.%s' % (name, ext)
 for i in range(maxver):
 yield '%s.so.%u' % (name, i)
 for n in extra:
 yield n
And of course you can use sys.platform to see if you're on linux and need to check the .so's. Generators are a bit pricey, but I think I like the above better than the way it currently is; what do you think?
Possible tweaks: make "extra" a "wellknown", and start with them
"extra" was supposed to be for corner cases that didn't fit the standard scheme.
Start with maxversion and down-count to 1.
That's probably better.
this new module is to replace _libc.py.
So does in need "bitness"?
Updated:
- now using yield pattern to iterate filenames
- checks for linux platform
- setup.py generated by make_metadata.py
Generators are a bit pricey, but I think I like the above better than the way it currently is; what do you think?
Yes, I meant a generator. But as I told above, even how it is is good enough for starters.
So does in need "bitness"?
Ah, so there's bitness... You see, _libc.py was already used as a catch-all. Currently, bitness is used only by select.py, but between moving it there and to ffilib, I think the latter is better. (Again, that can go as next action(s), to be done on demand).
Merged in 6dae7a2.
Pushed to pypi.
This library allows to search for an module to load with ffi. See issue #25 for background.
There is a bit of code duplication here but I couldn't find a way to reduce it.
I think I'd rather just allow a list of libs to be passed in and searched. It's much simpler.