Hi Joachim, Joachim Zobel wrote: > Hi. > > I have an apache module that uses libxml2. I have found a (potential, no > reports yet) problem with its usage of xmlGcMemSetup. I need to call > this for my module to work correctly. If there are other modules using > libxml2 (mod_php does) and they call xmlGcMemSetup, one of the modules > will stop working. > PHP does not change the memory handling routines (although this had been a request early on but turned down). Doing so would start screwing around with other modules that use libxml2. I urge you not to do this if your module is for more than just some specific implementation and going to be distributed publicly. > The problem is not threads, the problem is that other parts of apache > may be using libxml2 globals independently. > There is pretty much a gentleman's agreement with the other module developers using libxml2 that I know not to abuse the globals. This allows for all the modules to co-exist peacefully. When problems are identified in other modules, everyone, so far at least, is amenable to altering their code to make sure they all play nice together.
- During module initialization, don't alter globals (as that impacts all other modules and also can be problematic depending upon order of module initialization). For example, I limit my call to xmlInitParser to insure it gets initialized in main thread. - Try not to use globals. Many functions have been added over the years that allow settings/options to be passed directly eliminating the need to use globals. - If having to use globals, make sure they do not persists over the request. Any changes to globals should be reset to previous state as soon as possible. > I have just found globals.c, but do not understand it yet. Are there any > examples on how to use this? > The globals are really not that difficult. Here is a small example of disabling empty tags I use when supporting older libxml2 versions (prior to being able to use the XML_SAVE_NO_EMPTY option). Notice that it is reset back to original value right after use. /* get curent setting and then set to 1 */ int saveempty = xmlSaveNoEmptyTags; xmlSaveNoEmptyTags = 1; ... /* your code here */ /* reset global to previous value */ xmlSaveNoEmptyTags = saveempty; Rob _______________________________________________ xml mailing list, project page http://xmlsoft.org/ [email protected] http://mail.gnome.org/mailman/listinfo/xml
