Nick Bowler [Sun, 9 Feb 2020 02:20:16 +0000 (21:20 -0500)]
Use G_ADD_PRIVATE et al. when available.
As of GLib 2.58, using g_type_class_add_private has been deprecated;
it seems that type implementations are expected to use the G_ADD_PRIVATE
or G_ADD_PRIVATE_DYNAMIC macros.
Now that we use G_DEFINE_TYPE_xxx, it is reasonably straightforward
to do this. Fall back to the old method for older GLib where these
macros are not available.
Nick Bowler [Sun, 9 Feb 2020 01:04:26 +0000 (20:04 -0500)]
Use G_DEFINE_xxx type macros in output files.
The G_DEFINE_TYPE_EXTENDED and G_DEFINE_DYNAMIC_TYPE_EXTENDED can be
used to produce the default get_type implementations. They produce
almost identical code to what we already generate in GOB, except that
we can now automatically pick up any improvements made in GLib. For
example, with modern GLib the G_DEFINE_TYPE_EXTENDED will produce a
thread-safe get_type implementation which is a nice bonus.
These macros do not support the "prealloc" attribute so setting this
in gob will no longer do anything. According to the documentation, this
has been a no-op in GLib itself since 2.10, and it appears to just be
for performance tuning anyway, so I doubt anyone cares.
The generated output will fall back to the original method when these
macros are not available.
Nick Bowler [Sat, 8 Feb 2020 17:06:09 +0000 (12:06 -0500)]
Clean up get_type implementations a bit.
To simplify future code using the G_DEFINE_TYPE_xxx macros, move all
the interface registration out of the get_type/register_type functions
and into a separate function.
And while we are doing this, factor out some common code between the
different add_xxx_get_type functions.
Nick Bowler [Sat, 8 Feb 2020 15:51:25 +0000 (10:51 -0500)]
Minor testsuite cleanup.
In the interface tests we have a macro to generate the GTypeModule for
a dynamic type, let's make that usable for the dynamic type registration
test as well.
Nick Bowler [Fri, 7 Feb 2020 04:20:16 +0000 (23:20 -0500)]
Ensure all sources include <config.h> first.
Best practice with Autoconf is that <config.h> must be included before
any standard header, because configure tests may define macros to
influence those headers.
Now that we depend on flex we can use a %top block to achieve this in
the scanner.
Nick Bowler [Fri, 7 Feb 2020 03:26:38 +0000 (22:26 -0500)]
Require flex to build the scanner.
There is not much point in compatibility with various lex incarnations,
since the generated files are distributed and the user does not need
any lex tool to simply build from a tarball.
This additionally avoids a problem with AC_PROG_LEX which can hard-fail
the configure run when the selected lex command is not working, even
if the tool is not needed for the build. Now, a fatal error will only
be generated if the tool is required at make time.
Nick Bowler [Fri, 7 Feb 2020 02:30:00 +0000 (21:30 -0500)]
Add missing <stdlib.h> includes in test cases.
It seems that current versions of GLib expose EXIT_FAILURE and
EXIT_SUCCESS (possibly via indirect <stdlib.h> includes). But this
is not the case in older versions and some tests fail as a result
due to the missing macro definitions. Easily fixed.
Nick Bowler [Fri, 7 Feb 2020 02:27:40 +0000 (21:27 -0500)]
Avoid GLib deprecation warnings when building gob.
The g_strdown functions are deprecated in GLib, we already have a
gob_strdown function which does the same thing with g_ascii_tolower,
but it seems a couple spots were missed.
There is also a call to g_strcasecmp which can be replaced by
g_ascii_strcasecmp.
Nick Bowler [Thu, 6 Feb 2020 05:08:08 +0000 (00:08 -0500)]
Implement chaining of interface methods.
GObject interface methods are very similar to virtual methods. A class
may wish to override some or all of the interface methods implemented
in a parent class. When doing so, it can be useful to call the parent
class implementation to offload some of the work.
For ordinary virtual methods, using the "override" keyword causes a
PARENT_HANDLER macro to be defined which can call up to the parent
class implementation. Let's do exactly the same thing for interface
methods, and expose the parent interface structures (in case the user
wishes to call up to different methods).
Nick Bowler [Thu, 6 Feb 2020 05:07:44 +0000 (00:07 -0500)]
Fix dynamic interface implementation.
When a dynamic type implements an interface and derives from a type
which implements the same interface, the g_type_module_add_interface
function does not actually work: no interface will be added to the
dynamic type in this case.
The bug is in the GTypeModule class implementation in gobject,
the actual type system has no such limitation. It is reasonably
straightforward to hack around the problem in GOB.
Nick Bowler [Thu, 6 Feb 2020 05:05:59 +0000 (00:05 -0500)]
Expand the interface implementation test cases.
Test interface implementation for both dynamic and static types,
and test implementing the same interface in two classes, when one
class derives from another.
The cases where a dynamic class derives from another and both
implement the same interface are currently xfailing, as this
functionality is actually busted.
Nick Bowler [Tue, 4 Feb 2020 05:12:51 +0000 (00:12 -0500)]
Generate ChangeLog from git at packaging time.
Import the gitlog-to-changelog script from gnulib and add rules to
generate an up-to-date changelog from the git history, if available,
when running 'make dist'.
The ChangeLog is otherwise taken from srcdir as usual, so that
modified versions can be prepared from a release tarball without
requiring the full git history. In this scenario, the ChangeLog
would have to be manually edited.
In case the ChangeLog generation fails, a distcheck-hook is added to
hopefully catch issues before releasing tarballs with a broken
ChangeLog.
Nick Bowler [Mon, 25 Feb 2019 04:56:34 +0000 (23:56 -0500)]
Add support for simple dynamic types.
Defining types in runtime-loaded modules requires a slightly different
get_type implementation, and the type registration is done explicitly
using a different API. It's an extra pile of GObject boilerplate which
is a good fit for GOB to generate.
Add a (dynamic) flag which can be put on any class definition which
causes gob to spit out these alternate implementations.
Nick Bowler [Thu, 21 Feb 2019 16:26:58 +0000 (11:26 -0500)]
Pull in dxcommon for library tests.
Use the glib tests from dxcommon and hook up an initial Autotest-based
test suite which attempts to replicate the functionality of the old
(very basic) test functions.
Nick Bowler [Thu, 21 Feb 2019 16:15:06 +0000 (11:15 -0500)]
Build with libtool.
We link against glib, which is built using libtool, so using libtool
ourselves gives better results "out of the box". For example, if glib
is installed to a non-standard location libtool will automatically add
appropriate rpath options when linking.
Nick Bowler [Tue, 19 Feb 2019 21:40:10 +0000 (16:40 -0500)]
Modernize build system a bit.
Mostly rewrite the build system bits with the following changes:
- Convert to a non-recursive Automake setup.
- Convert to standard Automake variables where practical.
- Add rules to regenerate treefuncs as required.
- Avoid BUILT_SOURCES by adding accurate prerequisites.
- Remove NOINSTGLOB functionality as it seems pointless.
- Properly hook generated HTML documentation into Automake.
- Remove test bits for now, will be reintroduced later.
- Simplify configure.ac.