[Refactoring... WIP] Implement CPython-compatible gzip.decompress, restore uzlib. Enable both for atmel-samd#1274
[Refactoring... WIP] Implement CPython-compatible gzip.decompress, restore uzlib. Enable both for atmel-samd#1274klardotsh wants to merge 3 commits intoadafruit:masterfrom
Conversation
There was a problem hiding this comment.
Can you use uzlib_gzip_parse_header() to do the parsing?
There was a problem hiding this comment.
Had I known that function existed, yep, probably could have. It'd require a bit more tinkering to moduzlib.c to rebase to that, but... seems sane to me. Looks like they do the same "discard most everything" logic I do.
There was a problem hiding this comment.
This refactor was WAY easier than I thought and the final implementation is significantly cleaner, thank you for this!
There was a problem hiding this comment.
Do you need this? I can't see that they are used outside the module.
There was a problem hiding this comment.
I basically copied this file from some other module so this header file existing is mostly a leftover. Not really needed I don't think?
There was a problem hiding this comment.
Look like you've copied mod_binascii_crc32() here.
I think you can just use mod_binascii_crc32_obj() directly instead protected by MICROPY_PY_UBINASCII_CRC32.
There was a problem hiding this comment.
I did copy that function directly - I made this separate so there'd be no config clashing (if MICROPY_PY_UBINASCII_CRC32 is defined, it shouldn't impact something in uzlib, I guess?)
Happy to refactor this out to a generic crc32 function that both modules use behind their own mpconfigport.h flags, though.
There was a problem hiding this comment.
Admittedly this function isn't even used by my gzip implementation - it was used in my Python prototype of importing gzipped Python modules. Can also just... rip this out, though it seems nice to have in uzlib for compatibility with CPython's zlib
There was a problem hiding this comment.
I suppose you forgot to remove this debug option before committing.
|
Would you mind refactoring this into the CircuitPython shared-bindings and common-hal structure? That way it'll list with all of our other modules in the docs. time, os and struct have already been done here: https://github.com/adafruit/circuitpython/tree/master/shared-bindings I think for making uzlib a subset of CPython's zlib you'll need to remove DecompIO or move it to a new module. While you do that I'll make some space for you in the CPX crickit build. |
|
Now that I think about this more, let's make it M4 only. The M0 is quickly running out of code space and can't hold much code in memory anyway. Thanks! |
|
Sorry for the over a month of radio silence on this - burned out for a bit there on OSS work (and the project this PR was ultimately to be in support of). I'm back and plan to fix this branch up some time in the next week or two - looks like the only conflicts to merge in are localization-related, thankfully. |
|
@klardotsh no rush :) whenever you're ready - take breaks whenever ya need! |
8609f47 to
45258d7
Compare
|
The cause of the build failures is that flash is too full on circuitplayground_express_crickit -- disabling the new feature for that specific board might allow the build to be green. The translations need to be refreshed again (no surprise there) and there are conflict(s) in mpconfigport.h to be resolved which shouldn't be too subtle. |
7295768 to
bf3ff73
Compare
|
I'm going to close this. Please reopen when the refactoring is complete. Thanks! |
This on its own is likely of only marginal use (though I'm sure someone will find a use for it). My real motivation for this PR lies in KMKfw/kmk_firmware#52 (comment), where I'd eventually like to be able to both import a single gzipped Python module (this one is arguably less useful, but again, I'm sure some advanced user would find use for it - this functionality is not part of this pull request), and eventually import modules from a ZIP folder. Since compressed ZIPs and GZIP files use the same algo under the hood (
DEFLATE), this felt like a great starting point to both get an understanding of CircuitPython's internals (and especially the buffer system), as well as contribute a useful CPython backport to the project.An example of this in use is below. The file sizes are also listed here for giggles.