Commit Graph

110 Commits

Author SHA1 Message Date
Ole André Vadla Ravnås
0ab51f8d4e gwin32: Always use unicode APIs
Instead of the legacy ANSI ones. This also means GLib behaves correctly
when built with unicode preprocessor defines.
2021-01-05 21:42:59 +01:00
Nirbheek Chauhan
c3c2c31335 glib: Use g_getenv everywhere instead of getenv
`getenv()` doesn't work well on Windows, f.ex., it can't fetch env
vars set with `SetEnvironmentVariable()`. This also means that it
doesn't work at all when targeting UWP since that's the only way to
set env vars in that case.
2020-07-23 13:57:59 +05:30
Marc-André Lureau
f9be7d2bb5 win32: spelling fix
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-06-15 20:33:16 +04:00
Philip Withnall
00bfb3ab44 tree: Fix various typos and outdated terminology
This was mostly machine generated with the following command:
```
codespell \
    --builtin clear,rare,usage \
    --skip './po/*' --skip './.git/*' --skip './NEWS*' \
    --write-changes .
```
using the latest git version of `codespell` as per [these
instructions](https://github.com/codespell-project/codespell#user-content-updating).

Then I manually checked each change using `git add -p`, made a few
manual fixups and dropped a load of incorrect changes.

There are still some outdated or loaded terms used in GLib, mostly to do
with git branch terminology. They will need to be changed later as part
of a wider migration of git terminology.

If I’ve missed anything, please file an issue!

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-06-12 15:01:08 +01:00
Nirbheek Chauhan
0cfbe8f3b0 gwin32: Do not register a crash handler unless requested
Fixes https://gitlab.gnome.org/GNOME/glib/issues/2025
2020-02-18 23:24:52 +05:30
Nirbheek Chauhan
6919a719c1 gwin32: Do not ignore exceptions when running under a debugger
We're supposed to return `EXCEPTION_CONTINUE_SEARCH` here to tell the
vectored exception handler (VEH) to move on to the next exception
handler instead of skipping them all and trying to continue execution.

Swallowing exceptions messes up CLR exception processing and breaks C#
code. For more details, see:
https://blogs.msdn.microsoft.com/jmstall/2006/05/24/beware-of-the-vectored-exception-handler-and-managed-code/

Fixes https://gitlab.gnome.org/GNOME/glib/issues/2025
2020-02-18 23:24:52 +05:30
Christoph Reiter
6095b9bd3c win32: don't assume the format specifier for the stdlib printf/scanf like functions
When using the mingw printf shims for C99 compat the msvc format specifiers don't work
and the build fails.

Ideally we would use glib functions which abstract this away, but in the error handler context
we shouldn't call back into glib. And for scanf we don't have a glib wrapper.

Instead call the "secure" versions provided by the win32 API (_snprintf_s/fprintf_s/sscanf_s)
which mingw doesn't replace.
2019-08-10 21:56:33 +02:00
Andrea Azzarone
7bc21392e1 gwin32: Fix comment for g_win32_veh_handler 2019-03-07 10:38:24 +00:00
Руслан Ижбулатов
025a346728 W32: Add a simple exception handler
Install a Vectored Exception Handler[0]. Its sole purpose is to catch
some exceptions (access violations, stack overflows, illegal
instructions and debug breaks - by default, but it can be made to catch
any exception for which a code is known) and run a debugger in response.

This allows W32 glib applications to be run without a debugger,
but at the same time allows a debugger to be attached in case
something happens.

The debugger is run with a new console, unless an environment variable
is set to allow it to inherit the console of the crashing process.

The short list of handleable exceptions is there to ensure that
this handler won't run a debugger to "handle" utility exceptions,
such as the one that is used to communicate thread names to a debugger.

The handler is installed to be called last, and shouldn't interfere
with any user-installed handlers.

There's nothing fancy about the way it runs a debugger (it doesn't even
support unicode in paths), and it deliberately avoids using glib code.

The handler will also print a bit of information about the exception
that it caught, and even more information for well-known exceptions,
such as access violation.

The whole scheme is similar to AeDebug[1] and, in fact, the signal-event
gdb command was originally implemented for this very purpose.

[0]: https://docs.microsoft.com/en-us/windows/desktop/debug/vectored-exception-handling
[1]: https://docs.microsoft.com/en-us/windows/desktop/debug/configuring-automatic-debugging
2019-03-06 11:41:56 +00:00
Руслан Ижбулатов
460cc723ad W32: add std stream redirection envvar options
This commit adds two W32-only environmental variable checks:
* G_WIN32_ALLOC_CONSOLE, if set to 1, will force glib to create
  a new console if the process has no console by itself.
  This option is for GUI apps that are launched from GUI
  processes, in which case there's no console anywhere near them.
* G_WIN32_ATTACH_CONSOLE, if set to a comma-separated list of
  standard stream names (stdint, stdout, stderr), will reopen
  a given std stream and tie it to the console (using existing console
  or parent console).
  This works either with the other option (to create a console),
  or if the app is launched from a console process (often the
  case for developers).
  The redirection is done with freopen(), dup() and dup2().
  If everything goes well, C file descriptors 0, 1 or 2 will
  be bound to stdin, stdout and stderr respectively (only for
  streams listed in the envrionmental variable), and so will
  be stdio streams by the same names.

With these it's possible to see the output of g_log*() functions
when running GTK4 applications, which are linked as GUI applications,
and thus do not get a console by default.

https://bugzilla.gnome.org/show_bug.cgi?id=790857

Fixes issue #1304
2018-06-20 10:53:30 +00:00
Nirbheek Chauhan
a9fe62aa2c gwin32: Fix detection of MinGW32 vs MinGW-w64
__MINGW32__ is defined on all MinGW variants including MinGW-w64.
__MINGW64_VERSION_MAJOR is only defined on MinGW-w64.

This difference is important because on MinGW-w64 we must #include
winternl.h because including ntdef.h results in compiler errors
about symbol redefinition, and the header warns that it is deprecated
and may be removed in the future.

https://bugzilla.gnome.org/show_bug.cgi?id=795849
2018-05-16 11:07:30 +01:00
Руслан Ижбулатов
75fa8c2afb W32 - don't use gettext & gcov during gettext init
Non-representable characters during UTF16->locale conversion
will cause gcov code to return an error, for which it will try
to use gettext, so that the error message is localized.

If such call is made while gettext is being initialized
(there's a g_once_init_enter up the stack), the thread will hang forever.

To solve this, use W32 API to do the UTF16->locale conversion
and don't use gettext when it returns an error.

Also optimize g_win32_locale_filename_from_utf8() a bit,
as we need more UTF16 and less UTF8 now.

https://bugzilla.gnome.org/show_bug.cgi?id=784579
2017-07-13 01:49:38 +00:00
Sébastien Wilmet
f9faac7661 glib/: LGPLv2+ -> LGPLv2.1+
All glib/*.{c,h} files have been processed, as well as gtester-report.

12 of those files are not licensed under LGPL:

	gbsearcharray.h
	gconstructor.h
	glibintl.h
	gmirroringtable.h
	gscripttable.h
	gtranslit-data.h
	gunibreak.h
	gunichartables.h
	gunicomp.h
	gunidecomp.h
	valgrind.h
	win_iconv.c

Some of them are generated files, some are licensed under a BSD-style
license and win_iconv.c is in the public domain.

Sub-directories inside glib/:

	deprecated/: processed in a previous commit
	glib-mirroring-tab/: already LGPLv2.1+
	gnulib/: not modified, the code is copied from gnulib
	libcharset/: a copy
	pcre/: a copy
	tests/: processed in a previous commit

https://bugzilla.gnome.org/show_bug.cgi?id=776504
2017-05-24 11:58:19 +02:00
Christoph Reiter
5067d25a74 gwin32: Remove old win32 codepage ABI compat code
Makes new code link against the normal symbol names again.
Variants with utf8 suffix are there for existing binaries/ABI compat.

https://bugzilla.gnome.org/show_bug.cgi?id=780634
2017-04-06 19:25:09 +02:00
Christian Hergert
18a33f72db introspection: use (nullable) or (optional) instead of (allow-none)
If we have an input parameter (or return value) we need to use (nullable).
However, if it is an (inout) or (out) parameter, (optional) is sufficient.

It looks like (nullable) could be used for everything according to the
Annotation documentation, but (optional) is more specific.
2016-11-22 14:14:37 -08:00
Marc-André Lureau
37ebc83f7f win32: use wide-char for constants
Use the appropriate type for comparisons and assignment of wide chars.

Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>

https://bugzilla.gnome.org/show_bug.cgi?id=762202
2016-03-15 11:14:57 +01:00
Marc-André Lureau
622748680c win32: fix indentation
Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>

https://bugzilla.gnome.org/show_bug.cgi?id=762202
2016-03-15 11:14:57 +01:00
Marc-André Lureau
5be8cab966 win32: use wcslen() return type
Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>

https://bugzilla.gnome.org/show_bug.cgi?id=762202
2016-03-15 11:14:57 +01:00
Marc-André Lureau
a1bcd1e45a win32: fix off-by-one length check
Laszlo Ersek said: "The length check is off by one (in the safe direction); it
should be (nchars >= 2). The processing should be active for the wide string
L"\r\n" -- resulting in the empty wide string --, I believe."

Reported-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>

https://bugzilla.gnome.org/show_bug.cgi?id=762202
2016-03-15 11:14:57 +01:00
Chun-wei Fan
dfd74a271d gwin32.c: Avoid a GCC warning
Add a pair of braces to make things more clear, to avoid a warning
when -Wparentheses is used.

Reported by Ignacio Casel Quinteiro.
2016-01-28 15:55:11 +08:00
Chun-wei Fan
786b4c8b87 gwin32.c: Fix build on MinGW
Apparently unlike mingw-w64 and Visual Studio, MinGW does not come with
winternl.h, which defines NTSTATUS, so we need to include ntdef.h instead
on MinGW for NTSTATUS.

Based on patch by Cédric Krier.

https://bugzilla.gnome.org/show_bug.cgi?id=756875
2016-01-05 15:15:38 +08:00
Chun-wei Fan
d52625a94a gwin32.c: Fix g_win32_check_windows_version() on 32-bit
The Windows API function RtlGetVersion() is actually a function that is
decorated by WINAPI (i.e. __stdcall), so we need to correct this so that
the symbol can be loaded correctly from ntdll.dll, so that we won't crash as
a result.  Should fix the crash due to stack overflow on 32-bit builds.

https://bugzilla.gnome.org/show_bug.cgi?id=756179
2015-10-27 09:28:10 +08:00
Chun-wei Fan
556705cb9c gwin32.c: Fix build on Visual Studio
ntdef.h is a header that is normally only shipped with MinGW, not Visual
Studio, which broke the build in commit 975cb91.  Fix this by including
winternl.h, which typedef's the NTSTATUS type in question on both Visual
Studio and MinGW/mingw-w64, as well as pre-2008 Visual Studio.

Clean up this inclusion part a little bit as well.
2015-10-24 11:05:27 +08:00
Sebastian Dröge
975cb91085 win32: Include ntdef.h for NTSTATUS
https://bugzilla.gnome.org/show_bug.cgi?id=756875
2015-10-20 20:47:07 +03:00
Chun-wei Fan
46a20470fa gwin32.c: Avoid deprecated Win32 API usage
The VerifyVersionInfo() Win32 API has been deprecated in Windows 10, and
there is no direct replacement for it, except by using a lower-level
RtlGetVersion() that we aquire from the Windows DDK or from ntdll.dll.

Switch g_win32_check_windows_version() to use RtlGetVersion(), and
compare its results with the input parameters.

https://bugzilla.gnome.org/show_bug.cgi?id=756179
2015-10-07 20:46:31 +08:00
TingPing
b65287fea5 win32: Fix leak in g_win32_get_command_line()
https://bugzilla.gnome.org/show_bug.cgi?id=741822
2015-07-23 04:22:59 -04:00
Chun-wei Fan
bcbf80c355 gwin32: Add g_win32_check_windows_version() API
This adds a public API where one can use to see whether the running version
of Windows where the code is run is at least the specified version, service
pack level, and the type (non-server, server, any) of the running Windows
OS.

This API is done as:
-GetVersion()/GetVersionEx() changed in the way they work since Windows 8.1
 [1][2], so a newer mechanism to check the version of the running Windows
 operating system is needed.  MSDN also states that GetVersion() might be
 further changed or removed after Windows 8.1.  This provides a wrapper for
 VerfyVersionInfo() as well in GLib for most cases, which was recommended
 in place of g_win32_get_windows_version() for more detailed Windows
 version checking.
-Provides an OS-level functionality check, for those that we don't need to
 venture into GetProcAddress(), and also to determine system API behavior
 changes due to differences in OS versions.

Also added a note for the g_win32_get_windows_version() API that since the
behavior of GetVersion() which it uses, is changed since Windows 8.1, users
of the API should be aware.

[1]:
http://msdn.microsoft.com/zh-tw/library/windows/desktop/ms724451%28v=vs.85%29.aspx
[2]:
http://msdn.microsoft.com/zh-tw/library/windows/desktop/ms724451%28v=vs.85%29.aspx

https://bugzilla.gnome.org/show_bug.cgi?id=741895
2015-01-27 12:17:14 +08:00
Ignacio Casal Quinteiro
786590fe93 win32: improve the package installation dir lookup
As an example, the core of gedit is in a private library
placed in %INSTALLDIR%/lib/gedit/libgedit.dll

Before this patch we would get %INSTALLDIR%/lib/gedit as the
installation package dir, while what we actually want is to get
%INSTALLDIR%

https://bugzilla.gnome.org/show_bug.cgi?id=733934
2014-07-31 13:04:56 +02:00
Dan Winship
3da5d59078 gio: move Winsock error mapping to g_io_error_from_win32_error()
Rather than having special code in gsocket.c, handle Winsock errors
along with other Win32 errors in gioerror.c

Also, reference g_win32_error_message() from the
g_io_error_from_win32_error() docs, and update the
g_win32_error_message() docs to clarify that it works with Winsock
error codes too.
2014-03-30 11:55:47 -04:00
William Jon McCann
20f4d1820b docs: use "Returns:" consistently
Instead of "Return value:".
2014-02-19 19:41:52 -05:00
Matthias Clasen
35066ed6c6 Docs: Drop entities, switch away from sgml mode
Since all element markup is now gone from the doc comments,
we can turn off the gtk-doc sgml mode, which means that from
now on, docbook markup is no longer allowed in doc comments.

To make this possible, we have to replace all remaining
entities in doc comments by their replacement text, &amp; -> &
and so on.
2014-02-09 02:07:26 -05:00
Matthias Clasen
3232425785 Docs: replace <literal> by ` 2014-02-06 08:07:16 -05:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01:00
Matthias Clasen
b4474c0b6b Avoid a deprecation warning
https://bugzilla.gnome.org/show_bug.cgi?id=711547
2014-01-19 08:21:50 -05:00
Ryan Lortie
673ee54cdd win32: add g_win32_get_command_line()
This returns the command line in GLib filename encoding format (ie:
UTF-8) for use with g_option_context_parse_strv().

This will allow parsing of Unicode commandline arguments on Windows,
even if the characters in those arguments fall outside of the range of
the system codepage.

https://bugzilla.gnome.org/show_bug.cgi?id=722025
2014-01-17 20:04:44 -05:00
Chun-wei Fan
6011d0a4ae glib/gwin32.c: Silence a Deprecation Warning
Since we are already building a deprecated function for compatibility
reasons, we don't really need to see a warning when it uses another
deprecated GLib function.
2013-12-13 16:21:00 +08:00
Robert Ancell
4143842eb4 Add missing allow-none annotations for function parameters.
Found using:
find . -name '*.c' | xargs grep 'or %NULL' | grep ' \* @' | grep -v '@error' | grep -v allow-none
2012-03-31 20:34:28 +11:00
Ryan Lortie
47444dacc0 Deprecate g_thread_init()
Move the last few things that needed thread-safe initialisation to a
global ctor.

https://bugzilla.gnome.org/show_bug.cgi?id=660744
2011-10-04 15:31:49 -04:00
Ryan Lortie
80109acef5 win32: remove version init from g_thread_init_glib
Instead, make this use g_once_init_enter() in the usual way.
2011-09-09 13:17:42 -04:00
Matthias Clasen
1b28408b8b Spelling fixes
Spelling fixes in comments and docs, provided by
Kjartan Maraas in bug 657336.
2011-08-29 14:49:32 -04:00
Ryan Lortie
2e53e50244 glib/: fully remove galias hacks 2010-07-07 19:34:35 -04:00
Javier Jardón
73ca6f7019 [docs] Fix 'Deprecated' tag on some win32 functions
Fix g_win32_get_package_installation_directory() and
g_win32_get_package_installation_subdirectory_utf8()
2009-12-28 02:04:01 +01:00
Tor Lillqvist
98d2cdd9e6 Drop the code in the else branch of #if GLIB_CHECK_VERSION (2, 19, 0).
2009-01-21  Tor Lillqvist  <tml@novell.com>

	* glib/gwin32.c (g_win32_locale_filename_from_utf8): Drop the code
	in the else branch of #if GLIB_CHECK_VERSION (2, 19, 0). Drop
	unused variables.


svn path=/trunk/; revision=7826
2009-01-21 16:18:39 +00:00
Tor Lillqvist
f5b5154a88 Cosmetics.
svn path=/trunk/; revision=7795
2009-01-09 10:39:00 +00:00
Tor Lillqvist
eeb4d5939d Bug 567138 - get_package_directory_from_module() does not free its lock
2009-01-09  Tor Lillqvist  <tml@iki.fi>

	Bug 567138 - get_package_directory_from_module() does not free its
	lock when failing

	* glib/gwin32.c (get_package_directory_from_module): Obvious fix.


svn path=/trunk/; revision=7794
2009-01-09 10:37:31 +00:00
Tor Lillqvist
e55fca9533 glib/gutils.h Deprecate G_WIN32_DLLMAIN_FOR_DLL_NAME(),
2008-09-13  Tor Lillqvist  <tml@novell.com>

	* glib/gutils.h
	* glib/gwin32.h: Deprecate G_WIN32_DLLMAIN_FOR_DLL_NAME(),
	g_win32_get_package_installation_directory() and
	g_win32_get_package_installation_subdirectory() as their
	documentation has warned for a while. Sorry that I forgot to do
	this before 2.18.0.

	* glib/gwin32.c (g_win32_get_package_installation_directory):
	Print a warning if a non-NULL package parameter is passed to this
	function, as that is deprecated usage, as the documentation says.


svn path=/trunk/; revision=7480
2008-09-13 20:23:17 +00:00
Tor Lillqvist
80ecc30841 glib/glib.symbols glib/gconvert.c glib/gdir.c glib/gfileutils.c
2008-07-27  Tor Lillqvist  <tml@novell.com>

	* glib/glib.symbols
	* glib/gconvert.c
	* glib/gdir.c
	* glib/gfileutils.c
	* glib/giowin32.c
	* glib/gspawn-win32.c
	* glib/gutils.c
	* glib/gwin32.c: Bypass the Windows "ABI compatibility" symbols on
	_WIN64. As there hasn't been any widely deployed 64-bit Windows
	builds of the really old GLib (pre-2.8.1) versions those refer to,
	there is no need to have the "ABI compatibility" versions in the
	DLL.

	* glib/makegalias.pl: Handle #ifndef _WIN64: Just output it, too.


svn path=/trunk/; revision=7257
2008-07-27 17:15:16 +00:00
Tor Lillqvist
8d5927996d Fix Cygwin breakage. Patch by Lieven van der Heide.
2008-03-31  Tor Lillqvist  <tml@novell.com>

	* glib/gwin32.c
	(g_win32_get_package_installation_directory_of_module): Fix Cygwin
	breakage. Patch by Lieven van der Heide.


svn path=/trunk/; revision=6790
2008-03-31 13:41:03 +00:00
Matthias Clasen
36de18e662 2.15.6
svn path=/trunk/; revision=6593
2008-02-25 19:32:42 +00:00
Tor Lillqvist
3af00194ea New function. Supersedes g_win32_get_package_installation_directory() and
2008-02-24  Tor Lillqvist  <tml@novell.com>

	* glib/gwin32.c
	(g_win32_get_package_installation_directory_of_module): New
	function. Supersedes g_win32_get_package_installation_directory()
	and g_win32_get_package_installation_directory().

	It makes more sense to have the function for this functionality
	take a HMODULE as parameter instead of DLL name. The typical use
	scenario has been to have a DllMain() function that retrieves the
	full pathname for the DLL in question, and saves just the basename
	of that. Then later code passes that saved dll basename to
	g_win32_get_package_installation_directory(), which retrieves the
	corresponding DLL handle, and then retrieves up its full
	pathname. (Which DLlMain() already had.) It is less convoluted to
	have a DllMain() that just saves the DLL handle, and then when
	needed call this function to get the corresponding installation
	folder.

	(get_package_directory_from_module): Use
	g_win32_get_package_installation_directory_of_module().

	(g_win32_get_package_installation_directory)
	(g_win32_get_package_installation_subdirectory): Mention these
	functions will be deprecated and recommend using
	g_win32_get_package_installation_directory_of_module() instead.
	
	* glib/gwin32.h: Declare
	g_win32_get_package_installation_directory_of_module().

	* glib/glib.symbols: Add it.


svn path=/trunk/; revision=6569
2008-02-24 00:38:01 +00:00