1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-27 04:55:04 +03:00
Commit Graph

107 Commits

Author SHA1 Message Date
Nick Wellnhofer
9c2c87b55d dict: Move local RNG state to global state
Don't use TLS variables directly.
2023-12-24 16:24:34 +01:00
Nick Wellnhofer
c9a46a91fe io: Rework initialization 2023-12-21 15:02:24 +01:00
Nick Wellnhofer
b2dbcc432b io: Rework default callbacks
Register a dummy callback struct for default callbacks. Handle them in a
separate function which will later allow to return meaningful error
codes.
2023-12-21 15:02:24 +01:00
Nick Wellnhofer
ecb4c9fb28 misc: Improve error handling
Remove calls to generic error handler or use stderr for

- legacy deprecation warnings
- nanohttp, nanoftp in standalone mode
- memory debug messages

Use xmlRaiseMemoryError.

Remove TODO macro.

Don't raise errors in xmlmodule.c.
2023-12-21 15:02:24 +01:00
Mike Dalessio
1ac88300c1 fix: pthread weak references in globals.c
Linking executables will fail on systems with glibc < 2.34 without
declaring these symbols as weak references.

In commit c19771c1f1 these references
were moved to globals.c from threads.c, but the `#pragma weak`
declarations were lost in the process.

Also removing unneeded weak declarations from threads.c.
2023-11-18 18:26:48 +00:00
Nick Wellnhofer
253f260bb1 threads: Fix --with-thread-alloc
Fixes #606.
2023-10-18 20:07:04 +02:00
Nick Wellnhofer
1425d8f67b dict: Separate RNG code 2023-09-29 00:15:40 +02:00
Nick Wellnhofer
b8961a75e9 parser: Fix reinitialization 2023-09-27 17:24:46 +02:00
Nick Wellnhofer
ecbd634c9f threads: Fix double-checked locking in xmlInitParser
Hopefully work around the classic problem with double-checked locking:
Another thread could read xmlParserInitialized == 1 but doesn't see
other initialization results yet due to compiler or hardware reordering.
While unlikely, this seems theoretically possible.

The solution is to add a memory barrier after initializing the data but
before setting xmlParserInitialized. It might be enough to use a second
initialization flag which is only used inside the locked section and
update xmlParserInitialized after unlocking. But I haven't seen this
approach in many articles discussing this issue, so it's possibly
flawed as well.
2023-09-20 22:06:49 +02:00
Nick Wellnhofer
f7a403c21f globals: Move xmlIsMainThread to globals.c
xmlIsMainThread is mainly needed for global variables.
2023-09-20 22:06:49 +02:00
Nick Wellnhofer
a07ec7c1a7 threads: Move library initialization code to threads.c
This allows to consolidate the initialization code since the global init
lock was already implemented in threads.c.
2023-09-19 17:35:12 +02:00
Nick Wellnhofer
4e1c13ebfd debug: Remove debugging code
This is barely useful these days and only clutters the code base.
2023-09-19 17:35:09 +02:00
Nick Wellnhofer
c19771c1f1 globals: Move code from threads.c to globals.c
Move all code that handles globals to the place where it belongs.
2023-09-19 17:34:38 +02:00
Nick Wellnhofer
2a4b811424 globals: Rename members of xmlGlobalState
This is a deliberate first step to remove some internals from the
public API and to avoid issues when redefining tokens.
2023-09-19 17:34:30 +02:00
Nick Wellnhofer
d6882f6454 threads: Fix startup crash with weak symbol hack
Fix another issue when running with older libc, threads and libpthread
not linked in.
2023-05-03 19:40:57 +02:00
Nick Wellnhofer
359313c1a7 threads: Really fix crash with weak pthread symbols
Fix more regressions from 7010d877 and 71931233.

Fixes #488.
2023-02-23 14:30:45 +01:00
Nick Wellnhofer
7bd77873db threads: Fix crash with weak pthread symbols
Regressed in 7010d877. Should fix #488.
2023-02-20 10:56:03 +01:00
Nick Wellnhofer
dd3569eaa5 Remove XMLDECL macro from .c files 2022-12-08 02:43:17 +01:00
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