Commit Graph

180 Commits

Author SHA1 Message Date
John Ralls
e22a57ad26 Merge John Ralls's 'asan' into stable. 2023-12-08 14:56:29 -08:00
John Ralls
6834cb5025 Implement coverage option
To use pass -DCMAKE_BUILD_TYPE=Debug or Asan -DCOVERAGE=ON and build as
usual, then do ninja lcov-initialize && ninja check && ninja
lcov-collect. The result will be a directory, <Builddir>/Coverage
containing lcov tracefiles, including an aggregate file gnucash.info
which you can use for further processing. It will also report an overall summary.
Note that only C/C++ files are included.

There's one more target, lcov-generate-html, that you can run after
lcov-collect. It will generate a simple website in
<Builddir>/Coverage-HTML showing coverage by source directory (the
directories in <Builddir> have coverage for generated files). Each
directory path is a clickable link to a page that shows coverage for
each source file; the filenames link to a page for each showing which
lines have been exercised.
2023-12-08 14:53:02 -08:00
Adam Wight
fbc183a544 Always return an allocated gchar*
Returning the literal string will cause the caller to free unallocated
memory.
2023-11-05 23:58:01 +01:00
Richard Cohen
d808fddc95 Valgrind: fix "definitely lost" memory in test - test-userdata-dir-invalid-home
==66427== 128 bytes in 1 blocks are definitely lost in loss record 22 of 25
==66427==    at 0x4843738: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==66427==    by 0x49B85EF: g_realloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1)
==66427==    by 0x49D6EF1: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1)
==66427==    by 0x49D6F6F: g_string_sized_new (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1)
==66427==    by 0x499AB00: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1)
==66427==    by 0x499B2D8: g_build_filename (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1)
==66427==    by 0x10A498: main (test-userdata-dir-invalid-home.c:74)
==66427==
2023-07-19 10:21:30 +01:00
Richard Cohen
378dc40585 Valgrind: fix "definitely lost" memory in test - test-resolve-file-path
==91379== 19 bytes in 1 blocks are definitely lost in loss record 2 of 9
==91379==    at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==91379==    by 0x48D1948: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1)
==91379==    by 0x48ED5B0: g_strconcat (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1)
==91379==    by 0x48B845F: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1)
==91379==    by 0x48B869E: g_dir_make_tmp (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1)
==91379==    by 0x10935E: main (test-resolve-file-path.c:71)
2023-07-19 10:21:30 +01:00
Richard Cohen
66c5e398ae Change g_assert() -> g_assert_true() in tests
g_assert() can be compiled out, so should not be used for tests

g_assert_true was removed
to fis https://bugs.gnucash.org/show_bug.cgi?id=792008 because
g_assert_true was introduced in glib-2.38 and at the time GnuCash required
only glib-2.26. GnuCash has required glib >= 2.40 since 8acbc41c6 so
g_assert_true can be restored.
2023-07-16 10:09:12 -07:00
Christopher Lam
89f7e8933b gnc_list_all_paths returns std::vector instead of GList of EnvPaths
because its consumers are now cpp there's no need to return a GList.
2023-05-22 09:45:33 +08:00
John Ralls
9b95419608 Fix glib include. 2023-05-11 11:56:23 -07:00
John Ralls
d696f0cfcb Bug 798885 - Accented character in folder name on Account Export (bis)
Pass a boost::filesystem's c_str() rv to the ofstream constructor to
keep libstdc++ from transcoding it back to UTF8 and creating a broken
name or failing to match the directory name. Implemented in
gnc-filepath-utils to avoid spreading the boost::filesystem dependency
throughout the code base.

See https://github.com/boostorg/filesystem/issues/181 for why other
approaches don't work.
2023-05-08 13:35:21 -07:00
Maarten Bosmans
6be682b645 Store allocated temporaries in a variable so they can be freed
If a function that returns an allocated pointer is passed directly into
something that does not take ownership of the pointer, the allocation is
leaked.  This can be fixed by assigning the pointer to a new variable
and freeing it after operation on the memory.
2023-04-29 11:51:43 -07:00
Maarten Bosmans
ed3fe00880 [test] Use test fixture to initialize and destroy resources 2023-04-02 21:12:50 +02:00
Richard Cohen
6ba5bb326a Fix dereference of expired temporaries.
Reported by clang 15.0.7, which will be in Ubuntu 23.04, -Wdangling-gsl
2023-03-31 11:27:33 -07:00
Christopher Lam
dd0d65d861 [1/2] [gnc-filepath-utils.cpp] gnc_filename_is_backup|datafile
uses std::regex to test filename
2023-03-16 18:01:09 +08:00
Richard Cohen
7b47c07f8e Don't use extern "C" around #includes
Some I missed the first time. Some are new.
2023-03-03 18:55:42 +00:00
Richard Cohen
bddb4468fa Import GLIB2 as a target, and use it to simplify the CMakeLists 2023-02-21 12:59:42 +00:00
Richard Cohen
4eb022c7a2 [-Wunused-variable] - remove 2023-02-16 09:20:59 +00:00
Richard Cohen
bd8e81f35c Move an unused variable into an #ifdef where it is used 2023-02-06 14:20:31 +00:00
Richard Cohen
ea2d3be217 Remove some unused variables with obviously no side effects 2023-02-06 14:19:22 +00:00
Richard Cohen
d8f45f2443 Use const references for for-loops to avoid unnecessary copies
Found by clazy - clazy-range-loop-reference
2023-01-31 14:44:57 +00:00
Richard Cohen
a2ffc7fe75 Fix memory leak in binreloc function _br_find_exe()
Ironically, it seems to be in a code path that
is only followed when using valgrind
2023-01-26 14:36:43 +00:00
John Ralls
f6919e60a7 Merge Richard Cohen's 'cleanup' into master. 2023-01-24 12:05:47 -08:00
Richard Cohen
925fcbc3fd Remove unused gnc-jalali.{c,h} 2023-01-24 13:36:23 +00:00
Richard Cohen
1cec0cb3f3 Use internal extern "C" { ... } for C++
- removes warnings compiling swig engine
...
[ 10%] Generating swig-engine.cpp
.../libgnucash/engine/engine-helpers.h:31: Warning 313: Unrecognized extern type "C++".
.../libgnucash/engine/gnc-date.h:83: Warning 313: Unrecognized extern type "C++".
.../libgnucash/engine/qofquery.h:90: Warning 302: Identifier 'QofQuery' redefined (ignored),
.../libgnucash/engine/gnc-option.hpp:55: Warning 302: previous definition of 'QofQuery'.
.../libgnucash/engine/gnc-commodity.h:56: Warning 313: Unrecognized extern type "C++".
.../libgnucash/engine/gncBusiness.h:40: Warning 313: Unrecognized extern type "C++".
.../libgnucash/engine/gncEntry.h:37: Warning 313: Unrecognized extern type "C++".
2023-01-23 18:40:01 +00:00
Geert Janssens
734f90bd36 Replace string literal 'gnucash' with PROJECT_NAME parameter where it makes sense
The idea behind this is to not assume the project is always built
as "gnucash" exactly.
One example where it can be useful to use a different project name
would be when building multiple development versions of the project
on the same system and don't want these different versions share
the same settings in GSettings or the same stored passwords.
2022-12-19 22:18:12 +01:00
John Ralls
b8c0673526 Merge branch 'maint' 2022-12-19 12:11:32 -08:00
John Ralls
091d4aff22 Bug 798657 - Import Summary language is wrong
Root cause is using boost::locale::translate because it ignores
the LANGUAGES environment variable and doesn't support different
values for LC_MESSAGES, LC_DATE, LC_MONETARY, and LC_NUMERIC.
That makes it impossible to configure a user environment that
presents translated strings in a different locale from the one
applied to formatting dates and numbers.

To correct this replace all use of boost::locale::translate
with GNU gettext.
2022-12-16 15:34:10 -08:00
John Ralls
1a906b00aa [price-quotes] Enable gnucash-cli to retrieve preferences on macOS.
By embedding a minimal Info.plist with a bundle ID into the executable.
This necessitated a change to binreloc because the unix-style install
depended on there being a bundle ID only when the program was run from
an application bundle.
2022-10-17 10:06:21 -07:00
Geert Janssens
7765e13704 Bindings - move log wrappers into the swig interface files
They are only used for guile (and possibly python, so there's
no need to carry them around in core-utils.
2022-10-02 11:50:26 -07:00
Geert Janssens
e5c6f6026b Remove support code that was only used by price-quotes.scm 2022-10-02 11:50:26 -07:00
luz paz
ba94730a23 Fix various typos
Found via `codespell`
2022-09-06 10:44:29 -04:00
Christopher Lam
ecd2cdf425 [gnc-glib-utils] gnc_g_list_stringjoin skips NULL data 2022-09-06 18:14:15 +08:00
Christopher Lam
263f007d5c [gnc-filepath-utils] new: gnc_list_all_paths 2022-07-10 23:44:13 +08:00
Christopher Lam
3dfdf60608 [gnc-glib-utils] Define and export gnc_list_length_cmp 2021-11-02 23:34:25 +08:00
Christopher Lam
73ad5b1265 [gnc-glib-utils] use g_stpcpy instead of gnc_strcat
g_stpcpy will use stpcpy wherever available.
2021-09-15 21:09:01 +08:00
John Ralls
1d8983191d Fix runaway sed error. 2021-09-14 16:24:28 -07:00
John Ralls
74d0630867 Bug 798237 - Logging during XML file loading degrades performance...
significantly

Modify the DEBUG and PINFO macros to return unless qof_log_check is
true. Replace almost all direct calls to g_debug and g_message with
DEBUG and PINFO respectively.

Track the highest logging level sent to qof_log_set_level to provide a
short-circuit return in qof_log_check. Remove setting GNC_MOD_TESTS to
QOF_LOG_DEBUG so that the short-circuit threshold isn't defeated by
always being DEBUG.

Net result: 33% improvement in xml load times.
2021-09-14 15:15:11 -07:00
Christopher Lam
e84549926b [gnc-glib-utils] gnc_g_list_stringjoin to join a GList of strings
It traverses the GList twice (once to calculate the length) but
allocates only once.

Includes snippet from
https://www.joelonsoftware.com/2001/12/11/back-to-basics/
2021-08-12 09:19:34 +08:00
Christopher Lam
23bd716451 g_free gnc-path's gchar* intermediate strings 2021-08-03 12:14:12 +08:00
Christopher Lam
292deb0a11 [binreloc.c] free strings
subdir, prefix are not consistently freed.
2021-05-29 07:55:26 +08:00
Frank H. Ellenberger
93e2829ee5 Merge PR #899 into maint 2021-03-02 01:17:26 +01:00
luz paz
16b4976381 Fix typos in libgnucash/
Found via `codespell -q 3 -L ans,ba,parm,parms,numer`
2021-03-02 01:15:32 +01:00
Christopher Lam
b2b8792110 prepend-and-reverse instead of O(N^2) append 2021-02-24 09:08:25 +08:00
John Ralls
7a7c26f87e Move glib and gtk includes out of extern C for tests.
Needed to compile with glib 2.67 and later.
2021-02-16 13:23:48 -08:00
Bill Nottingham
c0f2c3ae25 Fix build with glib2 2.67.x.
glib headers should not be included with 'extern "C"'.
2021-02-16 13:23:16 -08:00
John Ralls
7a8a0f40b1 Fix missing space in warning message. 2020-11-29 10:59:25 -08:00
Bill Nottingham
06110e2abd Fix warning about misleading indentation from recent gcc.
Patch by <law@redhat.com>
2020-10-15 08:38:00 +08:00
Gaming4JC
cca4524055
Fix warnings: missing sentinel in function calls
When compiling with -Werror, GNUCash fails to build due to various error: missing sentinel in function call.
This patch resolves the issue by passing nullptr instead of C-style casting NULL.
2020-09-06 00:50:54 -04:00
Geert Janssens
f749f136ce Drop unused boost::locale::generator instantiations
We now have one single case in gnc-locale-utils and all code
uses gnc_get_boost_locale to get the proper locale.
2020-06-09 23:10:43 +02:00
Geert Janssens
69a04be353 Fix translations using boost::locale::translate
This requires a std::locale generated from a boost::locale::generator
The examples already in our code base used the wrong message_path while
creating the generator and as a result our message catalogs weren't found.

As with the std::locale I have added code to create a locale via
boost::locale only once instead of having each c++ file redo the work.

This code expects a message_path to set for the boost generator.
An earlier attempt queried for this path directly from within
gnc-locale-utils using gnc_get_locale_dir (from gnc-path.h).

That however broke several c++ tests depending on gnc_locale_utils as those
then also needed to be linked against gnc-path.o. I couldn't get the linker
to do this properly so I worked around it for now by splitting the boost_locale
functionality in two steps:
- an initializer step that takes the messages_path as a string and will
  generate the locale
- a getter to get the locale.

The initializer should only be run once, and before the getter is called.
It won't hurt though if the initializer is called more often.
If the getter is called before the initializer it will still
generate a std::locale but without setting a messages_path. It will then
also log a warning explaining translations may not be properly found.
2020-06-09 22:58:06 +02:00
John Ralls
fde6be6e01 Fix binreloc compile error with gcc. 2020-05-25 08:01:47 -07:00