1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 20:25:14 +03:00
Commit Graph

89 Commits

Author SHA1 Message Date
Nick Wellnhofer
71931233cd threads: Use __libc_single_threaded if available
Fixes #427
2022-11-25 15:12:56 +01:00
Nick Wellnhofer
c73d464afb threads: Deprecate some internal functions 2022-11-25 15:12:56 +01:00
Nick Wellnhofer
65d381f32c threads: Allocate mutexes statically 2022-11-25 15:12:56 +01:00
Nick Wellnhofer
7010d8779b threads: Rework initialization
Make init/cleanup functions private. Merge xmlOnceInit into
xmlInitThreadsInternal.
2022-11-25 15:02:04 +01:00
Nick Wellnhofer
bffc67d15c threads: Remove check for pthread_equal
GCC 12 fixed -Waddress warnings for inline functions, resulting in
warnings when comparing pthread_equal with NULL. Simply remove the
check and assume that pthread_equal is available if all the other
functions are. This code is only enabled on Linux anyway.
2022-10-25 19:34:38 +02:00
Nick Wellnhofer
1e60c76821 Remove HAVE_WIN32_THREADS configuration flag
Check for LIBXML_THREAD_ENABLED and _WIN32 instead.
2022-09-04 01:49:41 +02:00
Nick Wellnhofer
13a6637815 Remove BeOS support
Haiku shouldn't be affected.
2022-09-04 01:05:51 +02:00
Nick Wellnhofer
38290ec103 Rework dlopen and pthread detection
Migrate to AC_SEARCH_LIBS. Remove check for ancient GCC 3.3.
2022-09-04 00:49:36 +02:00
Nick Wellnhofer
0f568c0b73 Consolidate private header files
Private functions were previously declared

- in header files in the root directory
- in public headers guarded with IN_LIBXML
- in libxml.h
- redundantly in source files that used them.

Consolidate all private header files in include/private.
2022-08-26 02:11:56 +02:00
Nick Wellnhofer
d70e548fe7 Fix xmlCleanupThreads on Windows
Fix #ifdef logic:

- Also free TLS key in static build.
- Always reset 'run_once' state.
2022-06-15 17:25:03 +02:00
Nick Wellnhofer
65f8a62040 Fix reinitialization of library on Windows
Reset the 'run_once' state in xmlCleanupThreads, so the global
variables can be reinitialized later.

While it's generally unsafe to call xmlCleanupParser and continue to
use the library afterwards, this fix should avoid an outright crash if
you do so on Windows. This should help with applications erroneously
calling xmlCleanupParser.

See #376.
2022-06-15 17:11:00 +02:00
Nick Wellnhofer
83d5a87e37 Revert "Simplify recursive pthread mutex"
This reverts commit 5ffe2981b7.
This reverts commit 4adb767763.

Recursive mutexes are an XSI extension, so better not rely on them.
2022-03-18 15:50:44 +01:00
Nick Wellnhofer
5ffe2981b7 Fix weak pthread symbols after commit 4adb7677
Add missing mutexattr symbols.
2022-03-06 19:27:19 +01:00
Nick Wellnhofer
b35c55282d Use critical sections as mutex on Windows
They're more lightweight than ordinary Windows mutexes. Also stop
counting recursive locks. This only hides potential locking bugs.
2022-03-06 16:01:59 +01:00
Nick Wellnhofer
4adb767763 Simplify recursive pthread mutex
Use a PTHREAD_MUTEX_RECURSIVE mutex instead of the hand-rolled approach.
2022-03-06 16:01:59 +01:00
Nick Wellnhofer
40483d0ce2 Deprecate module init and cleanup functions
These functions shouldn't be part of the public API. Most init
functions are only thread-safe when called from xmlInitParser. Global
variables should only be cleaned up by calling xmlCleanupParser.
2022-03-06 15:59:43 +01:00
Nick Wellnhofer
ebb1797030 Remove unneeded #includes 2022-03-04 22:11:49 +01:00
Nick Wellnhofer
776d15d383 Don't check for standard C89 headers
Don't check for

- ctype.h
- errno.h
- float.h
- limits.h
- math.h
- signal.h
- stdarg.h
- stdlib.h
- string.h
- time.h

Stop including non-standard headers

- malloc.h
- strings.h
2022-03-02 00:43:54 +01:00
Nick Wellnhofer
346c3a930c Remove elfgcchack.h
The same optimization can be enabled with -fno-semantic-interposition
since GCC 5. clang has always used this option by default.
2022-02-20 21:49:04 +01:00
Kevin Puetz
453bdfb95e Fix potentially-uninitialized critical section in Win32 DLL builds
If non-parser parts of libxml (e.g. xmlwriter) are used before a parser,
xmlOnceInit may have run (e.g. via the many paths to xmlGetGlobalState),
but not xmlInitThreads (which is called only by xmlInitParser)

Once globalkey != TLS_OUT_OF_INDEXES (which can happen in many ways),
DLLMAIN(DLL_THREAD_DETACH) may attempt to lock cleanup_helpers_cs
before it is valid. This may happen even if the thread whose exit
is triggering DllMain is from code which is not linked to libxml.

globalkey and cleanup_helpers_cs should be initialized together,
with cleanup_helpers_cs initialized first and deleted last.
2020-02-11 11:34:15 +01:00
Jared Yanovich
2a350ee9b4 Large batch of typo fixes
Closes #109.
2019-09-30 18:04:38 +02:00
Nick Wellnhofer
2677fbf4a4 Fix -Wtautological-pointer-compare warnings
Skip tautological pointer comparisons on pthread systems where we don't
use the weak symbols hack.
2017-11-27 14:35:29 +01:00
J. Peter Mugaas
f05af837bb Add declaration for DllMain
Fixes a compiler warning.
2017-10-21 14:51:35 +02:00
J. Peter Mugaas
882a165a3f Fix preprocessor conditional in threads.h
Make sure that the preprocessor conditions and types for xmlDllMain
match exactly in threads.h and threads.c.
2017-10-21 14:50:44 +02:00
Nick Wellnhofer
6472dfe337 Fix a couple of warnings in dict.c and threads.c
Only visible on Windows.
2017-10-09 16:52:15 +02:00
Nick Wellnhofer
e3890546d7 Fix the Windows header mess
Don't include windows.h and wsockcompat.h from config.h but only when
needed.

Don't define _WINSOCKAPI_ manually. This was apparently done to stop
windows.h from including winsock.h which is a problem if winsock2.h
wasn't included first. But on MinGW, this causes compiler warnings.
Define WIN32_LEAN_AND_MEAN instead which has the same effect.

Always use the compiler-defined _WIN32 macro instead of WIN32.
2017-10-09 14:35:40 +02:00
Nick Wellnhofer
2cdaaab11c Change preprocessor OS tests to __linux__
"linux" without leading underscores is deprecated and less reliable.
2017-09-14 21:30:51 +02:00
Nick Wellnhofer
1f09aea26d Fix compiler warnings in threads.c
Use '#pragma weak' to declare weak functions.
2017-06-17 15:05:34 +02:00
Steve Nairn
620a70615e Fix the fix to Windows locking
For https://bugzilla.gnome.org/show_bug.cgi?id=737851

Unfortunately this change has introduced a problem which results in
occasional hangs on Windows when running multi-threaded on a multi-core
host.

When locking the xmlRMutex the count field is increment inside the
critical section but when unlocking the count field is decremented
outside the critical section. The increment/decrement is not atomic so
this can result in the count field being updated incorrectly.

The solution is to change xmlRMutexUnlock to decrement the count field
before leaving the critical section rather than after.
2015-03-03 19:42:01 +08:00
Michael Heimpold
fff8a6b87e threads: use forward declarations only for glibc
Fixes bug #704908

The declarations of pthread functions, used to generate weak references
to them, fail to suppress macros. Thus, if any pthread function has
been provided as a macro, compiling threads.c will fail.
This breaks on musl libc, which defines pthread_equal as a macro (in
addition to providing the function, as required).

Prevent the declarations for e.g. musl libc by refining the condition.

The idea for this solution was borrowed from the alpine linux guys, see
http://git.alpinelinux.org/cgit/aports/tree/main/libxml2/libxml2-pthread.patch

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
2014-12-22 11:12:12 +08:00
Daniel Veillard
8854e46318 Windows Critical sections not released correctly
For https://bugzilla.gnome.org/show_bug.cgi?id=737851
Based on report from mike.vanduzee@caris.com , we were missing calling
LeaveCriticalSection() when count was down to 0 hence not freeing
adequately the related resource.
2014-10-13 15:03:58 +08:00
Daniel Veillard
5fe9e9ed1c Remove risk of lockup in dictionary initialization
Reported by Petr Sumbera <petr.sumbera@oracle.com>
Two threads entering xmlInitializeDict concurently could lead
to a lockup due to multiple initializations of the lock used.
To avoid this problem move this to a new private function
called from xmlOnceInit() and deprecate the old initalizer.
Since threaded programs must call xmlInitParser() and this
will lead to dereference of private data and the call to
xmlOnceInit() guaranteed to be unique this should be safe now.
2013-04-05 23:10:41 +08:00
Daniel Veillard
7457c67fb9 Remove potential calls to exit() 2012-10-11 12:25:51 +08:00
Friedrich Haubensak
3f6cfbd1d3 Fix a thread portability problem
cannot compile libxml2-2.9.0 using studio 12.1 compiler on solaris 10

I.M.O. structure initializer (as PTHREAD_ONCE_INIT) cannot be used in
a structure assignment anyway
2012-09-15 17:21:23 +08:00
Daniel Veillard
7a2215dbcd Fix reuse of xmlInitParser
While xmlCleanupParser() should not be used unless complete control
is insured over the programe making sure libxml2 is not in use anywhere
It should still be usable, and allow a sequence of
    xmlInitParser();
    xmlCleanupParser();
calls if needed, the problem is that the thread key wasn't reallocated
on subsequent xmlinitParser() calls leading to corruption of pthread
keys used by the program.

* threads.c: make sure xmlCleanupParser() reset the pthread_once()
             global variable driving thread key allocation.
2012-09-04 12:05:17 +08:00
Daniel Richard G
5706b6d876 Various "make distcheck" and portability fixups
Makefile.am:

* Don't use @VAR@, use $(VAR). Autoconf's AC_SUBST provides us the Make
   variable, it allows overriding the value at the command line, and
   (notably) it avoids a Make parse error in the libxml2_la_LDFLAGS
   assignment when @MODULE_PLATFORM_LIBS@ is empty

* Changed how the THREADS_W32 mechanism switches the build between
   testThreads.c and testThreadsWin32.c as appropriate; using AM_CONDITIONAL
   allows this to work cleanly and plays well with dependencies

* testapi.c should be specified as BUILT_SOURCES

* Create symlinks to the test/ and result/ subdirs so that the runtests
   target is usable in out-of-source-tree builds

* Don't do MAKEFLAGS+=--silent as this is not portable to non-GNU Makes

* Fixed incorrect find(1) syntax in the "cleanup" rule, and doing "rm -f"
   instead of just "rm" is good form

* (DIST)CLEANFILES needed a bit more coverage to allow "make distcheck" to
   pass

configure.in:

* Need AC_PROG_LN_S to create test/ and result/ symlinks in Makefile.am

* AC_LIBTOOL_WIN32_DLL and AM_PROG_LIBTOOL are obsolete; these have been
   superceded by LT_INIT

* Don't rebuild docs by default, as this requires GNU Make (as
   implemented)

* Check for uint32_t as some platforms don't provide it

* Check for some more functions, and undefine HAVE_MMAP if we don't also
   HAVE_MUNMAP (one system I tested on actually needed this)

* Changed THREADS_W32 from a filename insert into an Automake conditional

* The "Copyright" file will not be in the current directory if builddir !=
   srcdir

doc/Makefile.am:

* EXTRA_DIST cannot use wildcards when they refer to generated files; this
   breaks dependencies. What I did was define EXTRA_DIST_wc, which uses GNU
   Make $(wildcard) directives to build up a list of files, and EXTRA_DIST,
   as a literal expansion of EXTRA_DIST_wc. I also added a new rule,
   "check-extra-dist", to simplify checking that the two variables are
   equivalent. (Note that this works only when builddir == srcdir)

   (I can implement this differently if desired; this is just one way of
   doing it)

* Don't define an "all" target; this steps on Automake's toes

* Fixed up the "libxml2-api.xml ..." rule by using $(wildcard) for
   dependencies (as Make doesn't process the wildcards otherwise) and
   qualifying appropriate files with $(srcdir)

   (Note that $(srcdir) is not needed in the dependencies, thanks to VPATH,
   which we can count on as this is GNU-Make-only code anyway)

doc/devhelp/Makefile.am:

* Qualified appropriate files with $(srcdir)

* Added an "uninstall-local" rule so that "make distcheck" passes

doc/examples/Makefile.am:

* Rather than use a wildcard that doesn't work, use a substitution that
   most Make programs can handle

doc/examples/index.py:

* Do the same here

include/libxml/nanoftp.h:

* Some platforms (e.g. MSVC 6) already #define INVALID_SOCKET:

     user@host:/cygdrive/c/Program Files/Microsoft Visual Studio/VC98/\
     Include$ grep -R INVALID_SOCKET .
     ./WINSOCK.H:#define INVALID_SOCKET  (SOCKET)(~0)
     ./WINSOCK2.H:#define INVALID_SOCKET  (SOCKET)(~0)

include/libxml/xmlversion.h.in:

* Support ancient GCCs (I was actually able to build the library with 2.5
   but for this bit)

python/Makefile.am:

* Expanded CLEANFILES to allow "make distcheck" to pass

python/tests/Makefile.am:

* Define CLEANFILES instead of a "clean" rule, and added tmp.xml to allow
   "make distcheck" to pass

testRelax.c:

* Use HAVE_MMAP instead of the less explicit HAVE_SYS_MMAN_H (as some
   systems have the header but not the function)

testSchemas.c:

* Use HAVE_MMAP instead of the less explicit HAVE_SYS_MMAN_H

testapi.c:

* Don't use putenv() if it's not available

threads.c:

* This fixes the following build error on Solaris 8:

     libtool: compile:  cc -DHAVE_CONFIG_H -I. -I./include -I./include \
     -D_REENTRANT -D__EXTENSIONS__ -D_REENTRANT -Dsparc -Xa -mt -v \
     -xarch=v9 -xcrossfile -xO5 -c threads.c  -KPIC -DPIC -o threads.o
     "threads.c", line 442: controlling expressions must have scalar type
     "threads.c", line 512: controlling expressions must have scalar type
     cc: acomp failed for threads.c
     *** Error code 1

trio.c:

* Define isascii() if the system doesn't provide it

trio.h:

* The trio library's HAVE_CONFIG_H header is not the same as LibXML2's
   HAVE_CONFIG_H header; this change is needed to avoid a double-inclusion

win32/configure.js:

* Added support for the LZMA compression option

win32/Makefile.{bcb,mingw,msvc}:

* Added appropriate bits to support WITH_LZMA=1

* Install the header files under $(INCPREFIX)\libxml2\libxml instead of
   $(INCPREFIX)\libxml, to mirror the install location on Unix+Autotools

xml2-config.in:

* @MODULE_PLATFORM_LIBS@ (usually "-ldl") needs to be in there in order for
   `xml2-config --libs` to provide a complete set of dependencies

xmllint.c:

* Use HAVE_MMAP instead of the less-explicit HAVE_SYS_MMAN_H
2012-08-06 11:32:54 +08:00
Mike Hommey
e6f05099e8 Fix a potential segfault due to weak symbols on pthreads
In xmlInitParser, both __xmlGlobalInitMutexLock and xmlInitGlobals are
called before xmlInitThreads, and both use pthread symbols.
__xmlGlobalInitMutexLock does so directly, without checking if the symbol
exists, and xmlInitGlobals calls xmlNewMutex, which correctly depends on
libxml_is_threaded... except libxml_is_threaded is still -1 by then...
And again, when releasing the global mutex in __xmlGlobalInitMutexUnlock,
the pthread function is called directly.

The patch changes the initialization order and make sure the functions
are available before calling them
2010-10-15 19:50:03 +02:00
Eric Zurcher
243b034d45 Minor patch for conditional defines in threads.c
Portability problem with CodeGear ("Borland") compiler 2007 on Windows
* threads.c: use 'defined' after #elif
2009-10-01 00:13:07 +02:00
Daniel Veillard
d87c5d1c4f 593857 try to work around thread pbm MinGW 4.4
* threads.c: try to cope with HAVE_PTHREAD_H and HAVE_WIN32_THREADS
  being both defined and pthread_t being a non integer
2009-09-10 17:46:07 +02:00
Daniel Veillard
7dd7080ad7 * parser.c threads.c: change the threading initialization sequence
as suggested by Igor Novoseltsev to avoid crash if xmlInitParser()
  is called from a thread which is not the main one, should fix
  #584605
daniel
2009-06-04 11:08:39 +02:00
Daniel Veillard
01101204f6 more warnings about xmlCleanupThreads and xmlCleanupParser to avoid
* threads.c parser.c: more warnings about xmlCleanupThreads and
  xmlCleanupParser to avoid troubles like #571409
daniel

svn path=/trunk/; revision=3818
2009-02-21 09:22:04 +00:00
Daniel Veillard
f63085de5e port patch from Marcus Meissner to add gcc checking for printf like
* include/libxml/parser.h include/libxml/xmlwriter.h
  include/libxml/relaxng.h include/libxml/xmlversion.h.in
  include/libxml/xmlwin32version.h.in include/libxml/valid.h
  include/libxml/xmlschemas.h include/libxml/xmlerror.h:
  port patch from Marcus Meissner to add gcc checking for
  printf like functions parameters, should fix #65068
* doc/apibuild.py doc/*: modified the script accordingly
  and regenerated
* xpath.c xmlmemory.c threads.c: fix a few warnings
Daniel

svn path=/trunk/; revision=3813
2009-01-18 20:53:59 +00:00
Daniel Veillard
d4a3f2418a also remove pthread key when stopping thread support, patch based on Alex
* threads.c: also remove pthread key when stopping thread
  support, patch based on Alex Ott one should fix #564723
daniel

svn path=/trunk/; revision=3810
2009-01-18 15:41:30 +00:00
Daniel Veillard
bf2ebff0f1 patch from Daniel Zimmermann fixing a memory leak in an edge case, solves
* threads.c: patch from Daniel Zimmermann fixing a memory leak
  in an edge case, solves #562230
Daniel

svn path=/trunk/; revision=3809
2009-01-18 14:57:04 +00:00
Daniel Veillard
2cba415895 fix a small initialization problem raised by Ashwin increase testing
* threads.c: fix a small initialization problem raised by Ashwin
* testapi.c gentest.py: increase testing especially for document
  with an internal subset, and entities
* tree.c: fix a deallocation issue when unlinking entities from
  a document.
* valid.c: fix a missing entry point test not found previously.
* doc/*: regenerated the APIs, docs etc.
daniel

svn path=/trunk/; revision=3778
2008-08-27 11:45:41 +00:00
Daniel Veillard
dee23485f6 added new function xmlSchemaValidCtxtGetParserCtxt based on Holger
* include/libxml/xmlschemas.h xmlschemas.c: added new function
  xmlSchemaValidCtxtGetParserCtxt based on Holger Kaelberer patch
* doc/apibuild.py doc/*: regenerated the doc, chased why the new
  function didn't got any documentation, added more checking in the
  generator
* include/libxml/relaxng.h include/libxml/schematron.h
  include/libxml/xmlschemas.h include/libxml/c14n.h
  include/libxml/xmlregexp.h include/libxml/globals.h
  include/libxml/xmlreader.h threads.c xmlschemas.c: various changes
  and cleanups following the new reports
Daniel

svn path=/trunk/; revision=3738
2008-04-11 12:58:43 +00:00
Daniel Veillard
14d465de48 check some allocation with Ashwin patch Daniel
* threads.c: check some allocation with Ashwin patch
Daniel

svn path=/trunk/; revision=3711
2008-03-24 11:12:55 +00:00
Daniel Veillard
ddbe38b4f1 check some malloc returns with Ashwin patch, add error messages and
* threads.c: check some malloc returns with Ashwin patch, add
  error messages and reindent the module.
Daniel

svn path=/trunk/; revision=3709
2008-03-18 08:24:25 +00:00
Daniel Veillard
5fce6d6870 remove unused variable in __xmlGlobalInitMutexLock reported by Hannes Eder
* threads.c: remove unused variable in __xmlGlobalInitMutexLock
  reported by Hannes Eder
Daniel

svn path=/trunk/; revision=3666
2007-11-23 10:46:55 +00:00
Rob Richards
91eb560c7c __xmlGlobalInitMutexDestroy() will free global_init_lock on Win32. Patch
* globals.c threads.c include/libxml/threads.h: 
  __xmlGlobalInitMutexDestroy() will free global_init_lock on Win32.
  Patch from Marc-Antoine Ruel.

svn path=/trunk/; revision=3664
2007-11-16 10:54:59 +00:00