[gimp-perl] Make plugin return values match PDB signature. Bug 728069



commit f0ee66515bd4f586669662487ced4d77468083eb
Author: Ed J <m8r-35s8eo mailinator com>
Date:   Sat Apr 12 00:48:23 2014 +0100

    Make plugin return values match PDB signature. Bug 728069

 Gimp/Fu.pm                 |    6 +++---
 Gimp/Lib.xs                |   16 ++++++++++++++--
 README                     |    2 +-
 examples/Perl-Server       |    7 ++++---
 examples/blended2          |    2 +-
 examples/example-fu        |    2 +-
 examples/goldenmean        |    2 +-
 examples/innerbevel        |   24 +++++++++++-------------
 examples/mirrorsplit       |    2 +-
 examples/repdup            |    2 +-
 examples/scratches         |    3 +--
 examples/selective_sharpen |    2 +-
 examples/stamps            |    2 +-
 examples/translogo         |    2 +-
 examples/webify            |    3 ++-
 examples/windify           |    5 +----
 t/perlplugin.t             |   43 +++++++++++++++++++++++++++++++++++++++----
 t/supplied.t               |    2 +-
 18 files changed, 85 insertions(+), 42 deletions(-)
---
diff --git a/Gimp/Fu.pm b/Gimp/Fu.pm
index b3f0e32..dc6ca2a 100644
--- a/Gimp/Fu.pm
+++ b/Gimp/Fu.pm
@@ -93,9 +93,9 @@ a starting point for your experiments)
 sub Gimp::RUN_FULLINTERACTIVE (){ Gimp::RUN_INTERACTIVE+100 }; # you don't want to know
 
 my %pf_type2string = (
-         &PF_INT8      => 'integer (0-255)',
-         &PF_INT16     => 'integer (0-32767)',
-         &PF_INT32     => 'integer (0-4294967295)',
+         &PF_INT8      => 'integer (8-bit)',
+         &PF_INT16     => 'integer (16-bit)',
+         &PF_INT32     => 'integer (32-bit)',
          &PF_FLOAT     => 'number',
          &PF_STRING    => 'string',
          &PF_BRUSH     => 'string',
diff --git a/Gimp/Lib.xs b/Gimp/Lib.xs
index 10232c1..cc26d77 100644
--- a/Gimp/Lib.xs
+++ b/Gimp/Lib.xs
@@ -1234,15 +1234,27 @@ static void pii_run(const gchar *name,
        // if one above is an array, this will be count, already set
        // by convert_sv2gimp (and no perl-stack var supplied) so skip
        continue;
+      if (--count < 0) {
+       err_msg = g_strdup_printf(
+         __("function '%s' got back too few return values; expected %d"),
+         name,
+         nreturn_vals - 1
+       );
+       goto error;
+      }
       convert_sv2gimp (errmsg, return_vals + i, POPs);
-      --count;
       if (errmsg [0]) {
        err_msg = g_strdup (errmsg);
        goto error;
       }
     }
 
-    while (count) { count--; (void) POPs; }
+    if (count) err_msg = g_strdup_printf(
+      __("function '%s' got back %d too many return values; expected %d"),
+      name,
+      count,
+      nreturn_vals - 1
+    );
   }
 
   gimp_destroy_paramdefs (return_defs, nreturn_vals - 1);
diff --git a/README b/README
index d1d792a..a958632 100644
--- a/README
+++ b/README
@@ -178,7 +178,7 @@ register
     [PF_SLIDER    , "width"       , "The image width"             , 360, [300, 500]],
     [PF_SPINNER   , "height"      , "The image height"            , 100, [100, 200]],
     [PF_STRING    , "text"        , "The message"                 , "example text"],
-    [PF_INT       , "bordersize"  , "The bordersize"              , 10],
+    [PF_INT32     , "bordersize"  , "The bordersize"              , 10],
     [PF_FLOAT     , "borderwidth" , "The borderwidth"             , 1/5],
     [PF_FONT      , "font"        , "The font family"             ],
     [PF_COLOUR    , "text_colour" , "The (foreground) text colour", [10,10,10]],
diff --git a/examples/Perl-Server b/examples/Perl-Server
index 9dac44d..34b7363 100755
--- a/examples/Perl-Server
+++ b/examples/Perl-Server
@@ -10,12 +10,13 @@ N_"/Xtns/Perl"; # workaround for i18n weirdnesses
 Gimp::set_trace(\$Gimp::Net::trace_res);
 Gimp::ignore_functions(qw(gimp_progress_init gimp_progress_update));
 
-Gimp::register_callback plug_in_perl_server => \&Gimp::Net::plug_in_perl_server;
+Gimp::register_callback
+  plug_in_perl_server => \&Gimp::Net::plug_in_perl_server;
 
 Gimp::on_query {
    Gimp->install_procedure(
-      "plug_in_perl_server", "Start the Gimp-Perl Server",
-      "This is the server for plug-ins written using the Gimp::Net module",
+      "plug_in_perl_server", "Gimp-Perl scripts net server",
+      "Allow scripting GIMP with Perl providing Gimp::Net server",
       "Marc Lehmann <pcg\ goof com>", "Marc Lehmann", "1999-12-02",
       N_"<Toolbox>/Xtns/Perl/Server", undef,
 #      &Gimp::EXTENSION,
diff --git a/examples/blended2 b/examples/blended2
index 68cb254..7c99d5d 100755
--- a/examples/blended2
+++ b/examples/blended2
@@ -102,7 +102,7 @@ sub my_innerbevel {
                $img->flatten;
        }
 #      gimp_display_new ($img);
-       $img;
+       ();
 }
 $help=<<EOF.$help;
 This script will produce a nice blended beveled logo from your alpha
diff --git a/examples/example-fu b/examples/example-fu
index 144761c..ba6a2e6 100755
--- a/examples/example-fu
+++ b/examples/example-fu
@@ -20,7 +20,7 @@ register "gimp_fu_example_script",                    # fill in a function name
           [PF_SLIDER   , "width"       , "The image width"             , 360, [300, 500]],
           [PF_SPINNER  , "height"      , "The image height"            , 100, [100, 200]],
           [PF_STRING   , "text"        , "The Message"                 , "example text"],
-          [PF_INT      , "bordersize"  , "The bordersize"              , 10],
+          [PF_INT32    , "bordersize"  , "The bordersize"              , 10],
           [PF_FLOAT    , "borderwidth" , "The borderwidth"             , 1/5],
           [PF_FONT     , "font"        , "The Font Family"             ],
           [PF_COLOUR   , "text_colour" , "The (foreground) text colour", [10,10,10]],
diff --git a/examples/goldenmean b/examples/goldenmean
index db46657..ff34e0f 100755
--- a/examples/goldenmean
+++ b/examples/goldenmean
@@ -27,7 +27,7 @@ sub goldenmean {
        $layer->gimp_edit_fill(BACKGROUND_FILL);
        Gimp::Context->pop();
 
-       return $img;
+       return;
 }
 
 register       "golden_mean",
diff --git a/examples/innerbevel b/examples/innerbevel
index 1c32230..e544340 100755
--- a/examples/innerbevel
+++ b/examples/innerbevel
@@ -23,7 +23,7 @@ $path = N_"<Image>/File/Create/Logos/Inner Bevel...";
 $shortdesc = "Perform an inner bevel on text";
 $longdesc = "This uses tigert's inner bevel method on text, which can be found with his other excellent 
tutorials at http://tigert.gimp.org/";;
 $date = "1999-03-23";
-$imgtypes = undef;
+$imgtypes = "";
 $author = "Seth Burgess <sjburges\ gimp org>";
 
 $regname = "inner_bevel";
@@ -31,15 +31,10 @@ $regname = "inner_bevel";
 $author =~ m/^(.*) </;
 $authorname = $1;
 
-sub gimp20_text_wh{
-   ($text, $fn) = ($_[0], $_[1]);
-   Gimp->text_get_extents_fontname($text,(split(/ /,$fn))[-1],PIXELS,$fn)
-   }
-
-
 register $regname, $shortdesc, $longdesc, $authorname, $author, $date, $path, $imgtypes,
   [
-   [PF_FONT, "font", "Font Name","URW Bookman L, Bold 80"],
+   [PF_FONT, "font", "Font Name","URW Bookman L, Bold"],
+   [PF_FLOAT, "fontsize", "Size of text", 80],
    [PF_STRING, "text", "Enter your text to be beveled", "INNERBEVEL"],
    [PF_COLOR, "top_color", "Blend to this color", $defaultcolor2],
    [PF_COLOR, "bottom_color", "Blend from this color", $defaultcolor1],
@@ -47,10 +42,13 @@ register $regname, $shortdesc, $longdesc, $authorname, $author, $date, $path, $i
    [PF_SLIDER, "shinyness", "How shiny the final image will be",30, [0,90,5]],
    [PF_SLIDER, "depth_shape", "Determines the final shape", 7 , [0,64,32]],
    [PF_RADIO, "map", "The type of Map to use(0=Linear,1=Spherical,2=Sinusoidal)", 2, [Linear => 0, Spherical 
=> 1, Sinusoidal => 2] ],
-  ],[],
+  ],
+  [
+   [PF_IMAGE, "image", "Return image", 0],
+  ],
   sub {
 
-my ($font, $text, $color1, $color2, $azimuth, $elevation, $depth, $maptype) = @_;
+my ($font, $fontsize, $text, $color1, $color2, $azimuth, $elevation, $depth, $maptype) = @_;
 
 # -- step 1 --
 Gimp::Context->push();
@@ -58,7 +56,7 @@ Gimp::Context->push();
 Gimp::Context->set_background($color1);
 Gimp::Context->set_foreground($color2);
 
- dims = gimp20_text_wh($text, $font);
+ dims = Gimp->text_get_extents_fontname($text, $fontsize, PIXELS,$font);
 
 $img = gimp_image_new($dims[0]+30, $dims[1]+10, RGB);
 
@@ -67,7 +65,7 @@ $img = gimp_image_new($dims[0]+30, $dims[1]+10, RGB);
 
 # -- step 2 --
 $img->add_new_layer(0,TRANSPARENT_FILL);
-$img->text_fontname(-1, 10, 10, $text, 0, 1, (split / /,$font)[-1], PIXELS, $font);
+$img->text_fontname(-1, 10, 10, $text, 0, 1, $fontsize, PIXELS, $font);
 Gimp::Display->new($img);  # display the image early
 $layer = $img->merge_visible_layers(EXPAND_AS_NECESSARY);
 @pt1 = ($layer->width * 0.5 -1, 0);
@@ -99,7 +97,7 @@ $img->add_new_layer(2);
 $img->gimp_selection_none();
 
 Gimp::Context->pop();
-return();
+return($img);
 };
 
 exit main;  # <-- This lil' bugger caused me much grief.
diff --git a/examples/mirrorsplit b/examples/mirrorsplit
index 30a9bba..37c70da 100755
--- a/examples/mirrorsplit
+++ b/examples/mirrorsplit
@@ -64,7 +64,7 @@ sub {
   gimp_selection_none($img);
 
   eval { $img->undo_group_end };
-  return $img;
+  return;
 };
 exit main;
 
diff --git a/examples/repdup b/examples/repdup
index 518cd2b..418946c 100755
--- a/examples/repdup
+++ b/examples/repdup
@@ -42,7 +42,7 @@ register      "repdup",
                        gimp_selection_none($img);
                }
                eval { $img->undo_group_end };
-               return $img;
+               return;
        };
 exit main;
 
diff --git a/examples/scratches b/examples/scratches
index cc67f25..6677cb4 100755
--- a/examples/scratches
+++ b/examples/scratches
@@ -37,7 +37,6 @@ register "scratches",
           [PF_SPINNER  , "smoothness"  , "The scratch smoothness"      ,  15, [  0, 400]],
           [PF_SPINNER  , "length"      , "The scratch length"          ,  10, [  0, 400]],
          ],
-         [],
          sub {
    my ($image,$drawable,$anglex,$angley,$gamma,$length,$width) = @_;
 
@@ -57,7 +56,7 @@ register "scratches",
 
    $image->undo_group_end;
 
-   $image;
+   ();
 };
 
 exit main;
diff --git a/examples/selective_sharpen b/examples/selective_sharpen
index 4fe4ffd..845488d 100755
--- a/examples/selective_sharpen
+++ b/examples/selective_sharpen
@@ -73,7 +73,7 @@ sub my_code {
     $img->remove_layer($edge_layer);
 
     $img->undo_group_end;
-    undef;
+    ();
 }
 
 register "selective_sharpen",
diff --git a/examples/stamps b/examples/stamps
index 08318b2..80b4934 100755
--- a/examples/stamps
+++ b/examples/stamps
@@ -38,7 +38,7 @@ sub stamps {
 
 # here, at last, comes the clever part! :-)
        $layer->offset(1, 0, -($diameter / 2), -($diameter / 2));
-       return $img;
+       return;
 }
 
 register       "stamps",
diff --git a/examples/translogo b/examples/translogo
index 1fcef01..16895c7 100755
--- a/examples/translogo
+++ b/examples/translogo
@@ -64,7 +64,7 @@ sub my_code {
        gimp_image_select_color ($img, CHANNEL_OP_ADD, $new, [255, 255, 255]);
        gimp_edit_clear ($new);
        gimp_selection_none ($img);
-       return ($img);
+       return;
 }
 $help=<<EOF.$help;
 This script aims to produce a transparent logo in an indexed image
diff --git a/examples/webify b/examples/webify
index c37fac6..f8b1506 100755
--- a/examples/webify
+++ b/examples/webify
@@ -24,6 +24,7 @@ register "webify",
           [PF_INT32,   "colors",       "how many colours to use (0 = don't convert to indexed)", 32],
           [PF_BOOL,    "autocrop",     "autocrop at end?", 1],
          ],
+        [ [PF_IMAGE, 'image', 'Output image', 0] ],
          sub {
    my($img,$drawable,$new,$alpha,$bg,$thresh,$colours,$autocrop)= _;
    $thresh /= 255;
@@ -45,7 +46,7 @@ register "webify",
 
    eval { $img->undo_group_end };
 
-   $new ? ($img->clean_all, $img) : ();
+   $new ? ($img->clean_all, $img) : ($img);
 };
 
 exit main;
diff --git a/examples/windify b/examples/windify
index 9199ccc..dd5c23d 100755
--- a/examples/windify
+++ b/examples/windify
@@ -1,8 +1,5 @@
 #!/usr/bin/perl
 
-eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
-    if 0; # not running under some shell
-
 # sent to me by Seth Burgess <sjburges gimp org>
 # small changes my Marc Lehmann <pcg goof com>
 # 2014/03/17 ported to GIMP 2.8.10 by Ed J:
@@ -59,7 +56,7 @@ sub windify {
        gimp_displays_flush();
         gimp_context_pop();
 
-       undef;
+       ();
        }
 
 register
diff --git a/t/perlplugin.t b/t/perlplugin.t
index 7d5bf95..e20bb3e 100644
--- a/t/perlplugin.t
+++ b/t/perlplugin.t
@@ -84,7 +84,37 @@ sub boilerplate_params {
     [ PF_FLOAT, "float", "Input float", ],
   ],
   [],
-  sub { 'verbiage' }
+  sub { }
+);
+
+&register(
+  "test_return_image",
+  boilerplate_params('return image', '<None>'),
+  [],
+  [
+    [ PF_IMAGE, "image", "Output image", ],
+  ],
+  sub { 1 }
+);
+
+&register(
+  "test_return_toomany",
+  boilerplate_params('return toomany', '<None>'),
+  [],
+  [
+    [ PF_IMAGE, "image", "Output image", ],
+  ],
+  sub { (1, 2) }
+);
+
+&register(
+  "test_return_toofew",
+  boilerplate_params('return toofew', '<None>'),
+  [],
+  [
+    [ PF_IMAGE, "image", "Output image", ],
+  ],
+  sub { }
 );
 
 &register(
@@ -109,17 +139,17 @@ sub boilerplate_params {
     my $tl = $i->text_layer_new("hi", "Arial", 8, 3);
     $i->insert_layer($tl, 0, 0);
     $tl->set_name($text);
-    return $i;
+    return;
   }
 );
 
 &register(
   "test_dialogs",
-  boilerplate_params('filter', '<None>'),
+  boilerplate_params('dialogs', '<None>'),
   [
     [ PF_COLOR, "colour", "Image colour", [255, 127, 0], ],
     [ PF_FONT, "font", "Font", 'Arial', ],
-    [ PF_INT, "size", "Size", 100],
+    [ PF_INT32, "size", "Size", 100],
   ],
   sub { }
 );
@@ -164,6 +194,11 @@ is_deeply(
   [ [1, 2], [3, 4] ],
   'return array'
 );
+is(ref(Gimp::Plugin->test_return_image), 'Gimp::Image', 'image ref');
+eval { Gimp::Plugin->test_return_toomany; };
+like($@, qr/too many/, 'too many return values is error');
+eval { Gimp::Plugin->test_return_toofew; };
+like($@, qr/too few/, 'too few return values is error');
 # if enable next line, brings up script dialog
 # color one works, font doesn't - speculate is due to being in "batch mode"
 #Gimp::Plugin->test_dialogs(RUN_INTERACTIVE, [0,0,0], "Arial", 150, );
diff --git a/t/supplied.t b/t/supplied.t
index beb76f0..72bf8d2 100644
--- a/t/supplied.t
+++ b/t/supplied.t
@@ -76,7 +76,7 @@ my @testbench = (
 ["guide_grid"          , 1, REQ_NONE , [24,14,0,0,0] ],
 ["guide_to_selection"  , 1, REQ_GUIDE, [CHANNEL_OP_REPLACE,0,0] ],
 ["highlight_edges"     , 1, REQ_ALPHA, [ 10] ],
-["inner_bevel"         , 0, REQ_NONE , ["URW Bookman L, Bold 80","INNERBEVEL",$color1,$color2,132,30,7,2] ],
+["inner_bevel"         , 0, REQ_NONE , ["URW Bookman L, Bold",80,"INNERBEVEL",$color1,$color2,132,30,7,2] ],
 ["layer_apply"         , 1, REQ_NONE , ['$d->gauss_rle($P*100+1,1,1)',""] ],
 ["layer_reorder"       , 3, REQ_ALPHA, [1,""] ],
 ["make_bevel_logos"    , 1, REQ_ALPHA, [$white,$color1,$color2,45,4,0] ],


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]