[gimp-perl] Plugin empty input params fixed. Bug 726488
- From: Kevin Cozens <kcozens src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp-perl] Plugin empty input params fixed. Bug 726488
- Date: Wed, 26 Mar 2014 19:49:37 +0000 (UTC)
commit fe8ca4c6cdaabfaf06ec1001158e39e9fc009070
Author: Ed J <m8r-35s8eo mailinator com>
Date: Mon Mar 17 06:34:39 2014 +0000
Plugin empty input params fixed. Bug 726488
Gimp/Lib.xs | 42 +++++++++++++++++++++++++-----------------
Net/Net.xs | 26 --------------------------
Perl-Server | 5 +----
t/gimpsetup.pl | 19 +++++++++++--------
t/perlplugin.t | 44 ++++++++++++++++++++++++++++++++++++++------
t/run.t | 2 ++
6 files changed, 77 insertions(+), 61 deletions(-)
---
diff --git a/Gimp/Lib.xs b/Gimp/Lib.xs
index 629a7d3..a5dcf3e 100644
--- a/Gimp/Lib.xs
+++ b/Gimp/Lib.xs
@@ -1485,9 +1485,9 @@ PPCODE:
)
croak (__("gimp procedure '%s' not found"), proc_name);
- int runmode = nparams
+ int runmode_firstparam = nparams
&& params[0].type == GIMP_PDB_INT32
- && ( !strcmp (params[0].name, "run_mode") || !strcmp (params[0].name, "run-mode"));
+ && (!strcmp (params[0].name, "run_mode") || !strcmp (params[0].name, "run-mode"));
g_free (proc_blurb);
g_free (proc_help);
g_free (proc_author);
@@ -1497,22 +1497,30 @@ PPCODE:
if (nparams)
args = (GimpParam *) g_new0 (GimpParam, nparams);
- for (i = 0, j = 1; i < nparams && j < items; i++) {
+ if (runmode_firstparam) {
+ /* If it's a valid value for the run mode, and # of parameters
+ are consistent with this, we assume the user explicitly passed the run
+ mode parameter */
+ args[0].type = params[0].type;
+ if (
+ nparams==(items-1) &&
+ (SvIV(ST(j))==GIMP_RUN_INTERACTIVE || SvIV(ST(j))==GIMP_RUN_NONINTERACTIVE)
+ ) {
+ args->data.d_int32 = SvIV(ST(1)); // ST(0) = proc_name
+ j = 2; // because ST(0) is proc_name, ST(1) is runmode
+ } else {
+ args->data.d_int32 = GIMP_RUN_NONINTERACTIVE;
+ j = 1; // because ST(0) is proc_name
+ }
+ i = 1; // first proc input param to put stack entries into
+ } else {
+ i = 0; // first proc input param to put stack entries into
+ j = 1; // because ST(0) is proc_name
+ }
+
+ for (; i < nparams && j < items; i++) {
args[i].type = params[i].type;
- if (i == 0 && runmode) {
- /* If it's a valid value for the run mode, and # of parameters
- are correct we assume the user explicitly included the run
- mode parameter */
- if (
- nparams==(items-1) &&
- (SvIV(ST(j))==GIMP_RUN_INTERACTIVE || SvIV(ST(j))==GIMP_RUN_NONINTERACTIVE)
- ) {
- args->data.d_int32 = SvIV(ST(j));
- j++;
- } else {
- args->data.d_int32 = GIMP_RUN_NONINTERACTIVE;
- }
- } else if (
+ if (
(!SvROK(ST(j)) || i >= nparams-1 || !is_array (params[i+1].type))
) {
convert_sv2gimp(croak_str, &args[i], ST(j)) && j++;
diff --git a/Net/Net.xs b/Net/Net.xs
index 0c6fc5b..8be0a01 100644
--- a/Net/Net.xs
+++ b/Net/Net.xs
@@ -22,32 +22,6 @@
#include "../perl-intl.h"
-#if HAVE_PDL
-
-# include <pdlcore.h>
-
-#if 0
-/* hack, undocumented, argh! */
-static Core* PDL; /* Structure hold core C functions */
-
-/* get pointer to PDL structure. */
-static void need_pdl (void)
-{
- SV *CoreSV;
-
- if (!PDL)
- {
- /* Get pointer to structure of core shared C routines */
- if (!(CoreSV = perl_get_sv("PDL::SHARE",FALSE)))
- Perl_croak(__("gimp-perl-pixel functions require the PDL::Core module"));
-
- PDL = (Core*) SvIV(CoreSV);
- }
-}
-#endif
-
-#endif
-
#define is_dynamic(sv) \
(strEQ ((sv), "Gimp::Tile") \
|| strEQ ((sv), "Gimp::PixelRgn") \
diff --git a/Perl-Server b/Perl-Server
index 43baeb4..efc4266 100755
--- a/Perl-Server
+++ b/Perl-Server
@@ -171,11 +171,8 @@ sub extension_perl_server {
while(!$server_quit and !eof($fh)) {
last unless handle_request($fh);
}
-# Gimp::gimp_quit(0); # borken in libgimp #d#FIXME#
- kill 'KILL',getppid(); # borken do not do this.. #d#FIXME#
+ Gimp::gimp_quit(0);
exit(0);
-# close $fh;
- return;
}
} else {
$run_mode=&Gimp::RUN_INTERACTIVE;
diff --git a/t/gimpsetup.pl b/t/gimpsetup.pl
index 01ff49f..1ee64a6 100644
--- a/t/gimpsetup.pl
+++ b/t/gimpsetup.pl
@@ -3,6 +3,7 @@
# use Test::*; # to make available ok()
# use Gimp qw(:auto);
# our $dir;
+# our $myplugins; # if want to write_plugin to right place!
# if encounters problems, does a die()
use strict;
@@ -15,20 +16,22 @@ our $DEBUG = 0 unless defined $DEBUG;
our %cfg;
require './config.pl';
-my $plugins = $cfg{gimpplugindir} . '/plug-ins';
-die "plugins dir: $!" unless -d $plugins;
-die "script-fu not executable: $!" unless-x "$plugins/script-fu";
+my $sysplugins = $cfg{gimpplugindir} . '/plug-ins';
+die "plugins dir: $!" unless -d $sysplugins;
+die "script-fu not executable: $!" unless-x "$sysplugins/script-fu";
our $dir = File::Temp->newdir($DEBUG ? (CLEANUP => 0) : ());;#
-my $perlserver = "$dir/Perl-Server";
+our $myplugins = "$dir/plug-ins";
+die "mkdir $myplugins: $!\n" unless mkdir $myplugins;
+my $perlserver = "$myplugins/Perl-Server";
my $s = io("Perl-Server")->all or die "unable to read the Perl-Server: $!";
$s =~ s/^(#!).*?(\n)/$Config{startperl}$2/;
write_plugin($DEBUG, $perlserver, $s);
-die "symlink script-fu: $!"
- unless symlink("$plugins/script-fu", "$dir/script-fu");
-die "symlink sharpen: $!" unless symlink("$plugins/sharpen", "$dir/sharpen");
+map {
+ die "symlink $_: $!" unless symlink("$sysplugins/$_", "$myplugins/$_");
+} qw(script-fu sharpen);
die "output gimprc: $!"
- unless io("$dir/gimprc")->print("(plug-in-path \"$dir\")\n");
+ unless io("$dir/gimprc")->print("(plug-in-path \"$myplugins\")\n");
map { die "mkdir $dir/$_: $!" unless mkdir "$dir/$_"; }
qw(palettes gradients patterns brushes dynamics);
diff --git a/t/perlplugin.t b/t/perlplugin.t
index 15639da..cba266b 100644
--- a/t/perlplugin.t
+++ b/t/perlplugin.t
@@ -5,10 +5,11 @@ use Gimp qw(:auto);
use Config;
our $dir;
+our $myplugins;
our $DEBUG = 0;
require 't/gimpsetup.pl';
-my $plugin = "$dir/test_perl_filter";
+my $plugin = "$myplugins/test_perl_filter";
write_plugin($DEBUG, $plugin, $Config{startperl}.<<'EOF');
use strict;
@@ -59,6 +60,27 @@ sub boilerplate_params {
);
®ister(
+ "test_return_int32array",
+ boilerplate_params('returning array', '<None>'),
+ [],
+ [
+ [ PDB_INT32ARRAY, "array1", "Output array1", ],
+ [ PDB_INT32ARRAY, "array2", "Output array1", ],
+ ],
+ sub { ([1, 2], [3, 4]) }
+);
+
+®ister(
+ "test_no_params",
+ boilerplate_params('no params', '<None>'),
+ [],
+ [
+ [ PF_INT32, "int", "Output int", ],
+ ],
+ sub { 1 }
+);
+
+®ister(
"test_perl_filter",
boilerplate_params('filter', '<Image>/Filters'),
[ [PF_STRING, "text", "Text to name layer", "hello"], ],
@@ -89,15 +111,25 @@ ok(!$i->insert_layer($l0,0,0), 'insert layer');
ok(!$i->test_perl_filter(undef, 'value'), 'call filter'); # 1st param drawable
my ($tl) = $i->get_layers;
is('value', $tl->get_name, 'layer name');
-is(Gimp::Plugin->test_return_text('text'), 'text', 'call return text');
-is(Gimp::Plugin->test_return_text(undef), 'default', 'test default on plugin');
-ok((my $c = Gimp::Plugin->test_return_colour([6, 6, 6])), 'return colour');
+is(Gimp::Plugin->test_return_text('text'), 'text', 'return text');
+my $incolour = [6, 6, 6, 1];
+is_deeply(
+ Gimp::Plugin->test_return_colour($incolour),
+ Gimp::canonicalize_color($incolour),
+ 'return colour'
+);
my $send_text = 'exception';
eval { Gimp::Plugin->test_dies($send_text); };
is($@, "$send_text\n", 'exception returned correctly');
eval { is(Gimp::Plugin->test_pf_adjustment('text'), 'text', 'adj'); };
like($@, qr/INT32/, 'pf_adjustment dies on non-INT32');
-is(Gimp::Plugin->test_pf_adjustment(17), 17, 'test adj return');
-is(Gimp::Plugin->test_pf_adjustment(undef), 100, 'test adj default');
+is(Gimp::Plugin->test_pf_adjustment(17), 17, 'adj return');
+is(Gimp::Plugin->test_pf_adjustment(undef), 100, 'adj default');
+is(Gimp::Plugin->test_no_params, 1, 'no params');
+is_deeply(
+ [ Gimp::Plugin->test_return_int32array ],
+ [ [1, 2], [3, 4] ],
+ 'return array'
+);
done_testing;
diff --git a/t/run.t b/t/run.t
index da1b29a..483fbbd 100644
--- a/t/run.t
+++ b/t/run.t
@@ -1,11 +1,13 @@
use strict;
use Test::More tests => 15;
+#BEGIN { $Gimp::verbose = 1; }
use Gimp qw(:auto);
our $dir;
our $DEBUG = 0;
require 't/gimpsetup.pl';
+#Gimp::set_trace(TRACE_ALL);
Gimp::init("spawn/");
ok((my $i = new Image(10,10,RGB)), 'OO Syntax for new image');
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]