Change 2011 11 25
Note for me.
The idea was to get rid of XPCOM for always. There were several ways to do it. Replace XPCOM by JS-CTYPES is the hardest way, but the more performant way by far.
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++ and called from Javacript of 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 allows to declare functions and C types
- CData is an instantiation of a CTypes
- It is pure C
- Remove all the XPCOM code from the library, who was full of it.
- 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/deallocation
- 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.
- Check for 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 JS-CType declaration of the C function in the constructor
- A wrapper that does exactly the same than the old XPCOM C++ component and that call the JS-CTypes defined functions
Step 3 - test
After some try and error due to compilation, it works fine ??? I did not expected to be so lucky.
- correct the stuff that mozilla add-on asked me to do
- check what happens when the library is not there and take the needed action (go in online mode)
- try the same on Linux 32 bits.
- Publish this work.
- load the library from the firefox profile (done)