I've already discussed this on the "Problem with library images on Windows (again)" [yeah, there's a word reversal on the subject that I didn't notice till now], but I'm doing a reprise there so I can get feedback and fix the problem ASAP.
Problem: Image functions that load JPEG and PNG images from a FILE * can crash Emacs on Windows. In particular: - MSVC builds of Emacs crash when using either MinGW or MSVC builds of the libraries - MinGW builds of Emacs crash when using MSVC builds of the libraries Cause: Documentation for the JPEG library states: " Microsoft C cannot pass file pointers between applications and DLLs. (See Microsoft Knowledge Base, PSS ID Number Q50336.) " I've been unable to find article Q50336, probably because it is very old, but the description of the problem seems to fit what I find. Moreover, tracing calls all the way through NTDLL shows that the Windows library is receiving an non-valid FILE * (but the image DLLs are receiving a valid one, so it is not a problem in Emacs). Fix: Both libraries (jpeglib and libpng) allow setting up custom reading functions. This allows the libraries to call back into program space, where the FILE * can be safely used. The fix for libpng is almost trivial, just adding one tiny function; jpeglib has a slightly more complex protocol and requires defining a bunch of functions for initializing the data source, filling the temporary buffer and skipping unwanted input data. Problems: - With the PNG fix, there should be none. My patch changes the method for reading from FILE * for all platforms, because it seems better to have one single code and the callback method should work fine everywhere. However, I can make this change conditional to HAVE_NTGUI if deemed necessary. - With the JPEG fix: none technical. However, the code I've used is lifted from jdatasrc.c on the jpeglib distribution, so there could be legal problems. Datapoints: - The code is pretty much jdatasrc.c, with only a few names changed and little more. - It is similar to the already installed code for jpeg_memory_src, installed by Gerd on 1999-12-31. - Documentation for the problem I'm trying to fix explicitly states: "So jdatasrc.c and jdatadst.c don't work if you open a file in your application and then pass the pointer to the DLL. One workaround is to make jdatasrc.c/jdatadst.c part of your main application rather than part of the DLL." - Jpeglib docs have this bit of legalese: "(1) If any part of the source code for this software is distributed, then this README file must be included, with this copyright and no-warranty notice unaltered; and any additions, deletions, or changes to the original files must be clearly indicated in accompanying documentation." Actions: I'm sending the two fixes as separate patches, so people can give feedback on them separately. - With regard to the PNG patch, I'd like an answer about making it the only way to read PNG image from files, or using it only for Windows. - On the JPEG front: Richard should make a comment about the legal issues. If the code cannot be included as is, I'd like for someone who's not been "tainted" by looking at jdatasrc.c to reimplement it. The patches follow in the next messages on this thread. Thanks, /L/e/k/t/u _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel