Change 2011 11 25
Note for me.
The idea was to get rid of XPCOM for always. There were several ways to do it. I choosed probably the hardest way, but the more performant way, it is to replace XPCOM by JS-CTYPES.
What was XPCOM ?
- XPCOM was an way to build component who exposes nice interface writen in IDL, while the code of the component could be written in C++.
- So, it was a very object relational system. Based on pure C++.
- It is past now, since Firefox 4 has unfrozen his XPCOM glue interface, what caused binary incompatibilities of binaries between each version of Firefox.
- This means for me, recompile each new Firefox version and then the XPCOM component of Tidy each 6/8 weeks -> a nightmare.
What is the JS-CTYPES
- Ctypes allow to declare functions and C types
- CData is an instantiation of a CTypes
- It is pure C call
- I have to remove all the XPCOM code from the library, who was full of it.
- And replace all C++ interfaces by simple C functions exported from a dynamic library
- Keep in mind to use Unicode everywhere
- Keep in mind memory allocation
- The result is that very surprisingly it works fine.
Step 1 - dynamic library
- removed all the Firefox header
- removed all the Firefox memory allocation call and replaced them by the lib of Tidy
- removed all the Firefox dependencies
- exported a C function (with extern "C"}for each function of XPCOM interface
- changed the build system to build a library and not a component
- got a library and checked the result with depends22_x86.
- I see C functions like "libTidyGetErrorDescription", ...
- Added a function to free memory
- removed the creation of the XPCOM component and created a new class TidyLib
- created 2 items for each C dynamic libray exported functions
- a declaration of the C function in the constructor
- a wrapper that has the same function name than the old XPCOM and that call the JS-CTypes defined functions
Step 3 - test
After some try and error due to compilation, it works nearly from the first test. I did not expected to be so lucky.
1. correct the stuff that mozilla add-on asked me to do 2. check what happens when the library is not there and take the needed action (go in online mode) 3. load the library from the firefox profile 4. try the same on Linux 32 bits. 5. Publish this work.