--- a/perl/gplugin-perl-loader.c Thu Jul 18 01:13:19 2019 +0000
+++ b/perl/gplugin-perl-loader.c Thu Jul 18 20:34:36 2019 -0500
@@ -28,10 +28,106 @@
G_DEFINE_DYNAMIC_TYPE(GPluginPerlLoader, gplugin_perl_loader, GPLUGIN_TYPE_LOADER);
-/* I can't believe I have to use this variable name... */
static PerlInterpreter *my_perl = NULL;
/******************************************************************************
+ *****************************************************************************/ +extern void boot_DynaLoader(pTHX_ CV* cv); +gplugin_perl_loader_xs_init(pTHX) { + newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__); +gplugin_perl_loader_init_perl(void) { + gchar *args[] = { "", }; + gchar **argv = (gchar **)args; + PERL_SYS_INIT(&argc, &argv); + my_perl = perl_alloc(); + PERL_SET_CONTEXT(my_perl); + PL_exit_flags |= PERL_EXIT_DESTRUCT_END; + perl_construct(my_perl); +gplugin_perl_loader_uninit_perl(void) { + PERL_SET_CONTEXT(my_perl); + perl_destruct(my_perl); +static GPluginPluginInfo * +gplugin_perl_loader_call_gplugin_query(PerlInterpreter *interpreter, GError **error) { + GPluginPluginInfo *info = NULL; + PERL_SET_CONTEXT(interpreter); + ret = call_pv("gplugin_query", G_EVAL | G_NOARGS); + g_warning("ret: %d", ret); + g_set_error(error, GPLUGIN_DOMAIN, 0, "gplugin_query did not return a GPluginPluginInfo"); + const gchar *errmsg = "unknown error"; + errmsg = SvPVutf8_nolen(ERRSV); + g_set_error_literal(error, GPLUGIN_DOMAIN, 0, errmsg); + g_message("sv_info: %p", sv_info); +gplugin_perl_loader_call_gplugin_load(PerlInterpreter *interpreter) { + PERL_SET_CONTEXT(interpreter); + call_pv("gplugin_load", G_EVAL | G_SCALAR); +/****************************************************************************** * GPluginLoaderInterface API
*****************************************************************************/
@@ -41,63 +137,78 @@
gplugin_perl_loader_query(GPluginLoader *loader,
+ GPluginPluginInfo *info = NULL; + PerlInterpreter *interpreter = NULL; const gchar *args[] = { "", filename };
gchar **argv = (gchar **)args;
+ gint argc = 2, ret = 0; + g_message("querying %s", filename); + interpreter = perl_alloc(); + PERL_SET_CONTEXT(interpreter); + PL_perl_destruct_level = 1; + perl_construct(interpreter); + ret = perl_parse(interpreter, gplugin_perl_loader_xs_init, argc, argv, NULL); + const gchar *errmsg = "unknown error"; + errmsg = SvPVutf8_nolen(ERRSV); + g_set_error_literal(error, GPLUGIN_DOMAIN, 0, errmsg); + perl_destruct(interpreter); + perl_free(interpreter); - perl_parse(my_perl, NULL, argc, argv, NULL);
+ ret = perl_run(interpreter); + const gchar *errmsg = "unknown error"; + errmsg = SvPVutf8_nolen(ERRSV); - call_argv("gplugin_plugin_query", G_DISCARD | G_NOARGS, argv);
+ g_set_error_literal(error, GPLUGIN_DOMAIN, 0, errmsg); + perl_destruct(interpreter); + perl_free(interpreter); + info = gplugin_perl_loader_call_gplugin_query(interpreter, error); + g_message("info: %p", info); gplugin_perl_loader_load(GPluginLoader *loader,
gplugin_perl_loader_unload(GPluginLoader *loader,
/******************************************************************************
- *****************************************************************************/
-gplugin_perl_loader_init_perl(void) {
- gchar *args[] = { "", };
- gchar **argv = (gchar **)args;
- PERL_SYS_INIT(&argc, &argv);
- my_perl = perl_alloc();
- PERL_SET_CONTEXT(my_perl);
- PL_perl_destruct_level = 1;
- perl_construct(my_perl);
-gplugin_perl_loader_uninit_perl(void) {
- perl_destruct(my_perl);
-/******************************************************************************
*****************************************************************************/
--- a/perl/meson.build Thu Jul 18 01:13:19 2019 +0000
+++ b/perl/meson.build Thu Jul 18 20:34:36 2019 -0500
@@ -14,24 +14,30 @@
+ # make sure we have the perl executable, we need it to figrue out the PERL = find_program('perl')
- PERL_CFLAGS = run_command(PERL, '-MExtUtils::Embed', '-e', 'ccopts').stdout()
- PERL_LDFLAGS = run_command(PERL, '-MExtUtils::Embed', '-e', 'ldopts').stdout()
- message('PERL_CFLAGS ' + PERL_CFLAGS)
- message('PERL_LDFLAGS ' + PERL_LDFLAGS)
+ # make sure we have the gobject introspection perl module. + '-e use Glib::Object::Introspection;', - PERL_CFLAGS = PERL_CFLAGS.split()
- PERL_LDFLAGS = PERL_LDFLAGS.split()
+ perl_dep = declare_dependency( + compile_args : run_command(PERL, '-MExtUtils::Embed', '-e', 'ccopts', check : true).stdout().split(), + link_args : run_command(PERL, '-MExtUtils::Embed', '-e', 'ldopts', check : true).stdout().split(), shared_library('gplugin-perl',
- link_args : PERL_LDFLAGS,
- dependencies : [gplugin_dep],
+ dependencies : [gplugin_dep, perl_dep], install_dir : join_paths(get_option('libdir'), 'gplugin')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/perl/tests/meson.build Thu Jul 18 20:34:36 2019 -0500
@@ -0,0 +1,13 @@
+e = executable('test-perl-loader', 'test-perl-loader.c', + '-DPERL_LOADER_DIR="@0@/perl"'.format(meson.build_root()), + '-DPERL_PLUGIN_DIR="@0@/plugins"'.format( + meson.current_source_dir()), + link_with : gplugin_loader_tests, + dependencies : [GLIB, GOBJECT, gplugin_dep, perl_dep]) --- a/perl/tests/plugins/basic.pl Thu Jul 18 01:13:19 2019 +0000
+++ b/perl/tests/plugins/basic.pl Thu Jul 18 20:34:36 2019 -0500
@@ -1,5 +1,4 @@
-# Copyright (C) 2011-2014 Gary Kramlich <grim@reaperworld.com>
+# Copyright (C) 2011-2019 Gary Kramlich <grim@reaperworld.com> # This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -20,9 +19,9 @@
Glib::Object::Introspection->setup(basename => "GPlugin", version => "0.0", package=> "GPlugin");
-sub gplugin_plugin_query() {
return GPlugin::PluginInfo->new(
- id => "gplugin-perl/basic-plugin",
+ id => "gplugin/perl-basic-plugin", abi_version => 0x01000001,
authors => ("Gary Kramlich <grim\@reaperworld.com>"),
@@ -35,15 +34,18 @@
-sub gplugin_plugin_load() {
-sub gplugin_plugin_unload() {
+my $d = &{gplugin_query}; +foreach my $key (keys %{$p}) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/perl/tests/plugins/dependent.pl Thu Jul 18 20:34:36 2019 -0500
@@ -0,0 +1,36 @@
+# Copyright (C) 2011-2019 Gary Kramlich <grim@reaperworld.com> +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, see <http://www.gnu.org/licenses/>. +use Glib::Object::Introspection; +Glib::Object::Introspection->setup(basename => "GPlugin", version => "0.0", package=> "GPlugin"); + return GPlugin::PluginInfo->new( + id => "gplugin/perl-dependent-plugin", + dependencies => ['dependency1', 'dependenc2'], --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/perl/tests/plugins/load-exception.pl Thu Jul 18 20:34:36 2019 -0500
@@ -0,0 +1,37 @@
+# Copyright (C) 2011-2019 Gary Kramlich <grim@reaperworld.com> +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, see <http://www.gnu.org/licenses/>. +use Glib::Object::Introspection; +Glib::Object::Introspection->setup(basename => "GPlugin", version => "0.0", package=> "GPlugin"); + return GPlugin::PluginInfo->new( + id => "gplugin/perl-load-exception", --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/perl/tests/plugins/load-failed.pl Thu Jul 18 20:34:36 2019 -0500
@@ -0,0 +1,35 @@
+# Copyright (C) 2011-2019 Gary Kramlich <grim@reaperworld.com> +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, see <http://www.gnu.org/licenses/>. +use Glib::Object::Introspection; +Glib::Object::Introspection->setup(basename => "GPlugin", version => "0.0", package=> "GPlugin"); + return GPlugin::PluginInfo->new( + id => "gplugin/perl-load-failed", --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/perl/tests/plugins/unload-failed.pl Thu Jul 18 20:34:36 2019 -0500
@@ -0,0 +1,35 @@
+# Copyright (C) 2011-2019 Gary Kramlich <grim@reaperworld.com> +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, see <http://www.gnu.org/licenses/>. +use Glib::Object::Introspection; +Glib::Object::Introspection->setup(basename => "GPlugin", version => "0.0", package=> "GPlugin"); + return GPlugin::PluginInfo->new( + id => "gplugin/perl-unload-failed", --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/perl/tests/test-perl-loader.c Thu Jul 18 20:34:36 2019 -0500
@@ -0,0 +1,31 @@
+ * Copyright (C) 2011-2019 Gary Kramlich <grim@reaperworld.com> + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see <http://www.gnu.org/licenses/>. +#include <gplugin/gplugin-loader-tests.h> +main(gint argc, gchar **argv) { + g_test_init(&argc, &argv, NULL); + gplugin_loader_tests_main(PERL_LOADER_DIR, PERL_PLUGIN_DIR, "pl");