Commit Graph

93 Commits

Author SHA1 Message Date
Luca Bacci cbcb9181d0 Add gimp_bind_text_domain () utility function
On UNIX it's just a stub calling bindtextdomain () directly;
on Windows it converts the path to UTF-16 and calls wbindtextdomain ().
2023-01-24 14:48:44 +00:00
Luca Bacci 0657b85202 Use GLib to convert between UTF-8 and UTF-16 2023-01-24 14:48:44 +00:00
Jehan 9b94e347bc Issue #7539: Opening some images lock GIMP.
In some conditions, and only with some installations, the called GDB
ends up hanging and never returning. Worse, even if you use non-blocking
functions such as poll() or select() with a timeout, in order to wait
for the debugger output, these block anyway and never return.

We are currently unsure what exactly causes such problem, but not using
the thread command in gdb avoids it for now.

This is a bit of a regression, though most of the time anyway the useful
traces are the main thread ones (I think ever since I implemented this,
there must not have been more than 2 or 3 cases where we actually needed
the secondary traces). So it's acceptable, at least for now.
2021-12-01 18:37:18 +01:00
Jehan 7c99fa02f9 libgimpbase: read up to 255 bytes into a 256 bytes buffer.
Otherwise if we add a NUL byte after the last byte, we might right past
the allocated memory. Thanks to Massimo for reporting this error raised
by Address Sanitizer and valgrind (cf. #7539).
2021-11-25 09:53:00 +01:00
Jehan 8d5008d76f libgimp, libgimpbase, libgimpwidgets: new gimp_range_estimate_settings()
Similar code was used in 2 places basically (GimpLabelSpin and
GimpProcedureDialog) so just make it an utils function. It's good anyway
to have a generic function to estimate suitable increments and decimal
places depending on a range.

As a consequence also gimp_label_spin_new() now takes a gint digits
(instead of guint), with -1 meaning we want digits computed from the
range.
Similarly gimp_prop_scale_entry_new() docs adds the -1 meaning too.
2020-11-25 01:34:36 +01:00
Niels De Graef 842dc7535f gir: (skip) functions with varargs
Bindings can't handle these, so they are not introspectable.
2020-05-21 13:49:38 +02:00
Niels De Graef 7f58f2d6e5 gir: Add more missing (array) and (out) annotations 2020-05-04 21:29:42 +02:00
Niels De Graef 52a146604b gir: Add some missing (array length) annotations
This will make sure that bindings can generate a more "native" API so
they don't have to pass the length explicitly.
2020-05-03 18:11:29 +02:00
Niels De Graef 8c7a2b42e6 gir: (optional) tag requires a (out) annotation 2020-05-03 15:31:46 +02:00
Niels De Graef 85d9730936 Add some missing (nullable) annotations
Fixes https://gitlab.gnome.org/GNOME/gimp/-/issues/4750
2020-05-01 15:34:56 +02:00
Michael Natterer e6d662e352 libgimp*: various doc fixes 2019-08-10 12:32:25 +02:00
Michael Natterer 31b8ea4a90 libgimpbase: add lots of const to GimpEnumDesc and GimpFlagsDesc APIs 2019-08-09 13:29:34 +02:00
Michael Natterer 2f3a83754f libgimpbase: add gboolean gimp_is_canonical_identifier() 2019-08-05 23:22:06 +02:00
Niels De Graef 1dda60154c Use "Returns:" to annotate return values
To be able to annotate return values through GObject-introspection, you
need to make sure it is tagged with `Returns:` and not something else.
2019-08-03 07:53:47 +00:00
Niels De Graef 746a72b956 Make sure to use % for constants
Documentation-wise in C, this doesn't matter a lot, but it allows
GObject-Introspection based bindings to use their built-in versions when
they want to render any kind of documentation (for example, docs for
Python plugins can render `%NULL` as `None`).
2019-08-03 07:53:47 +00:00
Félix Piédallu fc8303dd0a (source modifs) Fix: Rename macros as it conflicts with Mingw headers.
* DATADIR -> GIMPDATADIR
* SYSCONFDIR -> GIMPSYSCONFDIR
* DATADIR -> SYSDATADIR (tools/)
2019-01-25 19:08:28 +00:00
Jehan 8e0135362e libgimpbase: display thread id of the calling thread as hexadecimal...
... on macOS.
The debugger running on macOS is usually lldb and (from the reports we
get) it looks like lldb displays the tid as hexadecimal on macOS
(whereas lldb displays decimal tid on Linux! I know, it's confusing, yet
consistent with crash report experience!). So let's just do the same,
making it easy to quickly copy-search in order to look up the crashing
thread (without having to convert from decimal to hexa).
This is a bit of an approximation as I imagine we could have gdb on
macOS or whatever edge case. Let's say it's good for the common case and
still not an error otherwise (just a base conversion away).
2019-01-25 12:19:44 +01:00
Jehan 04bbe941d5 Issue #1999: Opening the Preferences dialogue triggers Xcode warning.
It seems that calling `lldb` when it is absent triggers some popup
proposing to install Xcode on macOS. This is obviously not good. Let's
check presence with g_find_program_in_path() instead. I was refraining
from doing so until now, because this function allocates memory, hence
may not do well during a crash.
Fortunately we don't need to check for lldb during crash (unlike gdb
which has some unacceptable behavior for older versions, at least on
FreeBSD) so that should be ok.
2018-08-11 00:25:45 +02:00
Michael Natterer 5f700549e7 Change the license URL from http://www.gnu.org/licenses/ to https:// 2018-07-11 23:29:46 +02:00
Jehan 49b4b1a5c2 libgimpbase: fix declaration after statement and reset safecheck...
... after each successful read().
I completely missed this declaration after a statement during the review
of !13 even though I saw another similar issue!

Also let's reset the error counter to 0 each time a successful read()
happens so that we can continue reading even if a lot of EINTR were to
happen, as long as we globally go forward. Only consecutive errors
increment the counter.

Finally add a small comment to explain why we let EINTR pass instead of
breaking directly.
2018-06-25 01:14:15 +02:00
Alex Samorukov 559d9b89e3 Fix empty lldb backtrace on OSX
When lldb attaching to the process it triggers few "-1" errors on read with
EINTR error. After 1-2 errors read() call works again.
Also this patch fixing TID detection, syscall SYS_gettid is oficially deprecated
now and does not work. Also adding safecheck to avoid enldless loop.
2018-06-24 22:42:40 +00:00
Ting-Wei Lan 077036273c libgimpbase: Find thread ID on FreeBSD with thr_self
https://bugzilla.gnome.org/show_bug.cgi?id=795510
2018-04-28 17:09:34 +02:00
Jehan 106fc9309f Bug 795510 - SYS_gettid is not available on non-Linux system.
I could not find for sure what to use on FreeBSD instead, so let's just
not get this information there. It is quite useful information to know
where thread traces were asked from, but it is more important to make
sure the program can be compiled everywhere. Also we can just check
which thread has gimp_stack_trace*() calls. Thus it can be seen as
redundant information in any case.

SYS_gettid is apparently defined as a macro, so let's simply check for
it being defined.
2018-04-25 00:28:23 +02:00
Jehan ae6a7bf98f libgimpbase: improve multi-threaded stack traces.
Since commit bb52431cdd, we get multi-thread traces in functions
gimp_stack_trace_*(). Adding now the LLDB equivalent improvement.

Also adding the process and thread id information, from which the trace
order was made, atop the listing, as well as the thread list. This would
allow to easily find and associate the threads.
The problem is that sometimes the thread where we got a trace from may
not matter (for instance signals, even such as SIGABRT or SIGSEGV, seem
to sent a bit randomly to either the thread which provoked them or the
main thread; there is a bit of contradictory info on this when reading
on the topic, in my case I experienced this), in such case, getting all
thread stack is important to find the origin of the signal.
Other times it will highly matter, in particular when getting a trace
for a WARNING or CRITICAL. This information will help to discriminate
between thread traces.
2018-04-10 14:48:44 +02:00
Jehan ab7c3d2b24 libgimpbase: oups, I lost the "full" option in my backtrace.
Quite useful to get values of local variables when possible.
2018-04-09 04:40:48 +02:00
Jehan bb52431cdd libgimpbase: gimp_stack_trace_*() should get backtraces for all threads.
Now that GIMP core is multi-threaded, let's get traces for all threads,
otherwise we may get some useless traces in some cases.
2018-04-09 02:18:20 +02:00
Ell 86939d847f libgimpbase: in gimp_stack_trace_print(), shuffle some code around
Reap the child *after* we're done reading its output, so that we
can disable ptracing after reading, but before reaping.  This
avoids a window during which the child is gone, but ptracing using
its PID is still allowed.
2018-03-05 02:34:13 -05:00
Ell a1a126c308 libgimpbase: in gimp_stack_trace_print(), clear ptrace permission on exit
Clear the ptrace permission given to the child after it terminates,
so that a future process that happens to have the same PID the
child had can't ptrace us.
2018-03-05 02:24:37 -05:00
Ell 0f2c966c5f libgimpbase: in gimp_stack_trace_print(), enable ptrace under Yama
On Linux, when /proc/sys/kernel/yama/ptrace_scope is 1, a process
may only ptrace its descendants by default, which prevents the GDB
process spawned by gimp_stack_trace_print() from attaching to, and
producing a backtrace for, the calling process.

Use prctl() with PR_SET_PTRACER, when available, in the parent
process, to allow the child process to ptrace it.
2018-03-05 01:55:40 -05:00
Michael Natterer 374fee451c libgimpbase: consistent gimp_stack_trace namespace for stack trace functions
Change the rest of the source accordingly.
2018-02-22 12:35:43 +01:00
Jehan 6975188d6f Bug 793514 - Adding version check for gdb.
It seems that older GDB (under version 7) are not handling very well
some common debug information format, in particular DWARF > 3. Such
version of GDB is usually not a problem since it is quite old (more than
10 years old, it would seem) so you don't see it anymore on any modern
GNU/Linux distribution. On FreeBSD on the other hand, it is still
available (probably for license reasons) and even installed by default!
As a consequence, it makes debugging fail, even though LLDB is also
installed by default.

That is even more of a problem because it would seem that GIMP is killed
(most likely by FreeBSD kernel according to the reporter tests) as a
side-effect of GDB failing, which is seriously bad, in particular since
we also use the debug dialog for non-fatal errors (which could therefore
end up killing GIMP as side effect of a bad GDB!).

So I add some GDB version check. I implement this without any dynamic
memory management, as usual, since this needs to happen also during
crash handling where the state is unstable and prone to memory
allocation failure.
I also add gimp_utils_backtrace_available() public API which can be used
by the Preferences.
2018-02-22 05:05:24 +01:00
Jehan 9e8e321d62 libgimpbase: rename FILE * argument to stream instead of fd.
As noted in bug 793494, my naming was unfortunate. A FILE pointer is not
a file descriptor (which is why we use fileno() on it).
2018-02-15 21:32:58 +01:00
Ting-Wei Lan 7b6756af8e libgimpbase: Cast fd to FILE* before calling fileno
It is required if the system implements fileno as a macro doing direct
struct member access.

https://bugzilla.gnome.org/show_bug.cgi?id=793494
2018-02-15 21:29:14 +01:00
Jehan 1282a95e6b Bug 793393 - gimputils.c compilation error under Win32.
The header sys/wait.h is not for Win32.
2018-02-12 18:22:16 +01:00
Jehan 4e293a8696 libgimpbase: allow NULL prog_name in gimp_print_stack_trace().
The only debugger command which uses this value currently is gdb. And
even there, it doesn't look mandatory. The alternative call using "-p"
option does not require the program name. The manual doesn't say if
calling with the program name has any advantage (but I don't see why it
would, the PID is enough to find a process). Just in case, I leave the
prog_name parameter (because it's easier to make a parameter useless
than changing a libgimp* API) but simply allows setting it to NULL.
2018-02-12 01:50:19 +01:00
Jehan 040533249c libgimpbase: use backtrace_symbols_fd() rather than...
... backtrace_symbols() when possible.
When we allocate a new string, anyway we have memory allocation. But
when we just print to a file descriptor, this version of the API is
guaranteed without any memory allocation and therefore should always
work. This is important since allocations may fail in particular after
memory errors.
2018-02-11 23:31:26 +01:00
Jehan 276f07521c app, libgimpbase: move the debug functions to libgimpbase.
This will allow to use them on plug-ins later on.
2018-02-09 01:57:03 +01:00
Ell 4dab0ac0ac libgimpbase: fix gettext invocation for enum/flags desc/abbrev 2017-12-04 09:58:50 -05:00
Ell 7df427583f libgimpbase: add gimp_{enum,flags}_value_get_abbrev()
Add support for specifying an abbreviated description for enum/
flags values, which can be used in contexts where the full
description is too long.

Since the exact layout and size of Gimp{Enum,Flags}Desc is part of
the ABI, we can't simply add a field to these structs to hold the
abbreviated description.  Instead, we use the fact that entries
with a repeated value in the value descriptions array are ignored,
and that the array is NULL terminated (in particular, that all non-
NULL entries are followed by at least one additional entry), and
specify the abbreviation in the "value_desc" field of the entry
that immediately follows the initial entry for a given value,
setting the "value" field of both entries to the same value.

Right now this behavior is undocumented, so there is no proper way
to specify abbreviated descriptions in the API, and is only meant
to be used in generated enum files.
2017-11-30 03:10:13 -05:00
Richard Kreckel dd9b0fc55b Bug 768044 - Fix many typos
This fixes many typos in comments and one in a user-visible string (msgid
"center abscisse" changed to "center abscissa" in affected po files. too).
2016-06-26 00:35:24 +02:00
Michael Natterer 8005eea835 Remove the "GIMP" from all "Since: GIMP 2.x" API doc comments
because it confuses gtk-doc and breaks some links. Also change the
"Index of new symbols in GIMP 2.x" sections to be what seems to be the
modern standard (looked at the GLib and GTK+ docs), and update some
other stuff.
2015-05-31 21:18:09 +02:00
Michael Natterer d91ff74820 libgimpbase: more API doc fixes 2015-05-31 19:44:39 +02:00
Mukund Sivaraman c61e89a6ff libgimpbase: Remove function names from user visible strings 2015-02-27 12:16:02 +05:30
Mukund Sivaraman d794d8a26b Add Windows implementation for gimp_file_show_in_file_manager() 2015-02-26 20:48:36 -05:00
Kristian Rietveld 97a9d1c53f libgimpbase: implement show in file manager for OS X platform 2015-02-19 21:39:05 +01:00
Michael Natterer e448cc3173 libgimpbase, app: implement File -> Show in File Manager
Add gimp_file_show_in_file_manager() to libgimpbase and a menu item
in app which shows the image's file (if any) in the file manager.

Implemented calling the org.freedesktop.FileManager1 interface
and dropped snippets found on stackoverflow for somebody to
turn into working code for OSX and Windows.
2015-02-16 18:40:26 +01:00
Michael Natterer dae366bb6e configure.ac, *: require GLib 2.40.0
Remove gimp_output_stream_[v]printf() and use the new functions from
GLib instead. Use memmove() instead of the deprecated g_memmove().
2014-08-12 15:30:19 +02:00
Michael Natterer 6209b1f571 libgimpbase, app: move gimp_file_has_extension() to libgimpbase
and use it in GimpModuleDB.
2014-08-03 20:47:37 +02:00
Michael Natterer 776a79792d libgimpbase: add gimp_file_get_utf8_name()
Which works like gimp_filename_to_utf8() and returns a displayable
UTF-8 encoded name of a GFile that does not need to be freed, which
makes a lot of code more readable and compact.
2014-07-01 14:11:30 +02:00
Michael Natterer 99937ddfce libgimpbase: add gimp_output_stream_[v]printf()
Temporary, to be removed when we depend on glib 2.40, which will
clearly be before gimp 2.10
2013-11-28 00:29:43 +01:00