Am Samstag, den 05.05.2007, 07:06 -0400 schrieb Rob Richards: > - 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.
I would prefer not to use globals. The problem I have to deal with is that my module calls the SAX2 callbacks (from SAX2.c). These callbacks assume the memory that is passed to them has been allocated by libxml2, which is (mostly) not the case. So I might do a lot of memcpying in a lot of places, never beeing shure that libxml2 will really free this. What I actually do is setting the libxml2 memory functions. The free function assumes that a long below the memory it frees is readable and checks for a mark, that has been put there by the alloc funtions. > - 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'll have to do it that way. > /* get curent setting and then set to 1 */ > int saveempty = xmlSaveNoEmptyTags; > xmlSaveNoEmptyTags = 1; > > ... /* your code here */ > > /* reset global to previous value */ > xmlSaveNoEmptyTags = saveempty; > It looks as if globals.c provides helpers for the implementation of the above that are setting and resetting all globals. Sincerely, Joachim _______________________________________________ xml mailing list, project page http://xmlsoft.org/ [email protected] http://mail.gnome.org/mailman/listinfo/xml
