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
Provide memory manager overriding api #325
Conversation
This provides a new interface for creating compress and decompress streams with an already initialized memory manager. By adding a new function this doesn't break compatability with old clients. The new api assumes that either mem has been initialized and is ready to go or that it is NULL and will be initialized as normal. Without this it is problematic to actually fully override the default memory manager. The main issue is that the memory manager is that the jpeg_create_* functions initialize the default memory manager and then use it to allocate some items before returning. If the memory manager is replaced after this the original memory manager will never have the destruct called. If the destruct is called manually it will free memory that is still in use by structures in cinfo.
I strongly dislike the introduction of new *_create_* functions. That's just poor API design, but due to the aforementioned lack of project funding, I don't have the resources right now to dig into this issue and figure out a better solution. Do you really need to override the entire memory manager? Or are you just trying to override Also refer to my comments in #311 and #313 regarding the fact that the libjpeg API is very old and brittle, and I'm largely uninterested in any disruptive modifications to it. I would be much more interested in extending the TurboJPEG API to cover the necessary features of the libjpeg API that it doesn't already cover. That being said, I think there is probably a way to solve this problem by extending the libjpeg API with a single function that allows a custom memory manager to be specified. It just may require restructuring a few things. Given that the newly-established general fund only pays for about 8 hours of labor a month, and that has already been exhausted for this month, it may be a while before I can look at this in more detail. |
Overriding I do think that exposing the memory manager would be more powerful than just Ideally I would have just liked the current |
Unless I'm missing something, I see no reason why the call to |
Agreed deferring it for Compress would be a reasonable solution but I don't know what could be done for Decompress where allocation occurs in the create. |
I need to look at that, because I'm the one who moved that allocation into the |
I'm closing this request because I will no longer be working for the company I logged this on behalf of in a weeks time and I don't have any personal interest in this particular change to pursue it any further. |
This issue is of general interest. You aren't the first person who has requested it. |
f79d239
to
c8e5274
Compare
This issue was introduced in 5557fd2 due to an oversight, so it has existed in libjpeg-turbo since the project's inception. However, the issue is effectively a non-issue. Although #325 proposes allowing programs to override jpeg_get_*() and jpeg_free_*() externally, there is currently no way to override those functions without modifying the libjpeg-turbo source code. libjpeg-turbo only includes the malloc()/free() memory manager from libjpeg, and the implementation of jpeg_free_*() in that memory manager ignores the size argument. libjpeg had several additional memory managers for legacy systems (MS-DOS, System 7, etc.), but those memory managers ignored the size argument to jpeg_free_*() as well. Thus, this issue would have only potentially affected custom memory managers in downstream libjpeg-turbo forks, and since no one has complained until now, apparently those are rare. Fixes #542
This issue was introduced in 5557fd2 due to an oversight, so it has existed in libjpeg-turbo since the project's inception. However, the issue is effectively a non-issue. Although #325 proposes allowing programs to override jpeg_get_*() and jpeg_free_*() externally, there is currently no way to override those functions without modifying the libjpeg-turbo source code. libjpeg-turbo only includes the malloc()/free() memory manager from libjpeg, and the implementation of jpeg_free_*() in that memory manager ignores the size argument. libjpeg had several additional memory managers for legacy systems (MS-DOS, System 7, etc.), but those memory managers ignored the size argument to jpeg_free_*() as well. Thus, this issue would have only potentially affected custom memory managers in downstream libjpeg-turbo forks, and since no one has complained until now, apparently those are rare. Fixes #542
I know that, with the state of funding for this project at the moment, this might
not be considered but I thought I would share this anyway.
This provides a new interface for creating compress and decompress
streams with an already initialized memory manager. By adding a new
function this doesn't break compatability with old clients. The new api
assumes that either mem has been initialized and is ready to go or that
it is NULL and will be initialized as normal.
Without this it is problematic to actually fully override the default
memory manager. The main issue is that the memory manager is that the
jpeg_create_* functions initialize the default memory manager and then
use it to allocate some items before returning. If the memory manager is
replaced after this the original memory manager will never have the
destruct called. If the destruct is called manually it will free memory
that is still in use by structures in cinfo.