After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 160136 - img.add_layer fails silently
img.add_layer fails silently
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: Gimp-Python
2.1.x
Other Linux
: Normal minor
: Future
Assigned To: Manish Singh
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2004-12-01 20:36 UTC by pepster
Modified: 2005-03-03 08:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
diff for proposed patch (684 bytes, patch)
2004-12-02 03:23 UTC, pepster
none Details | Review
diff for proposed patch (629 bytes, patch)
2004-12-03 19:57 UTC, pepster
needs-work Details | Review

Description pepster 2004-12-01 20:36:40 UTC
In pygimp, img.add_layer(l, -1) silently fails with an incorrect k, while
pdb.gimp_image_add_layer(l, -1) returns an execution error.

(l was a layer from some operation, not created by
pdb.gimp_layer_new_from_drawable due to my inexpereince)
Comment 1 pepster 2004-12-01 20:45:39 UTC
Here is a fix (in plug-ins/pygimp/pygimp-image.c). 
(However, this bug applies to many other calls as well)

static PyObject *
img_add_layer(PyGimpImage *self, PyObject *args)
{
    PyGimpLayer *lay;
    int pos = -1;
	
    if (!PyArg_ParseTuple(args, "O!|i:add_layer", &PyGimpLayer_Type, &lay,
			  &pos))
	return NULL;
    
    {
	int s = gimp_image_add_layer(self->ID, lay->ID, pos);
	if( s ) {
	    return PyInt_FromLong(s);
	}
    }
    PyErr_SetString(pygimp_error, "layer add failed");
    return NULL;
}

Comment 2 Sven Neumann 2004-12-02 00:11:34 UTC
Perhaps you could attach a diff (diff -u). That would make it a lot easier to
review the proposed changes.
Comment 3 pepster 2004-12-02 03:23:17 UTC
Created attachment 34386 [details] [review]
diff for proposed patch
Comment 4 Michael Natterer 2004-12-03 15:25:19 UTC
That diff still doesn't show the changes. Please use "diff -u".

Comment 5 pepster 2004-12-03 19:57:52 UTC
Created attachment 34464 [details] [review]
diff for proposed patch
Comment 6 Sven Neumann 2004-12-05 18:43:21 UTC
That change doesn't look very correct. gimp_image_add_layer() returns a
gboolean, not an integer. However, since I'm not involved with pygimp, I might
just misinterpret the code.
Comment 7 pepster 2004-12-05 18:53:19 UTC
The return status from gimp_image_add_layer is what is returned in the current
code. It is an int with possible values 0/1.

My change is that 0 is never returned - instead python returns an "error state".
This is more in line with the failure you get when you try to do the same thing
using pdb.gimp_image_add_layer directly. right now if you forget to check the
return status, you never know an error occured.

If you are saying one can simply return 1, I guess this is right too. I wanted
to suggest a minimal change.

Comment 8 Sven Neumann 2004-12-05 19:10:17 UTC
I guess a larger change is needed then. Neither 0 nor 1 make any sense here as
return values.
Comment 9 Dave Neary 2005-01-24 08:17:09 UTC
Comment on attachment 34464 [details] [review]
diff for proposed patch

neo, do you mean that TRUE and FALSE are better return values?

If not, I don't follow your last comment.
Comment 10 Sven Neumann 2005-01-24 19:49:40 UTC
Well, I don't understand the Python bindings good enough but this code doesn't
look right to me. It would return PyInt_FromLong(s) where s is the boolean
return value from gimp_image_add_layer(). Does that make sense to you?
Comment 11 Dave Neary 2005-01-24 20:11:10 UTC
If Python has a boolean type, that would certainly be better.

Dave.
Comment 12 Manish Singh 2005-01-24 21:17:24 UTC
This would make more sense:

static PyObject *
img_add_layer(PyGimpImage *self, PyObject *args)
{
    PyGimpLayer *lay;
    int pos = -1;

    if (!PyArg_ParseTuple(args, "O!|i:add_layer", &PyGimpLayer_Type, &lay,     
                     
                          &pos))
        return NULL;

    if (!gimp_image_add_layer(self->ID, lay->ID, pos)) {
        PyErr_SetString(pygimp_error, "could not add layer to image");
        return NULL;
    }

    Py_INCREF(Py_True);
    return Py_True;
}

However, I'm not sure such a change should be made in the stable branch, as it
does change current behavior.
Comment 13 Manish Singh 2005-03-03 08:44:04 UTC
I'm calling this FIXED, since the original request is fulfilled. Other API needs
to be taken care of the same way still though.

2005-03-03  Manish Singh  <yosh@gimp.org>

        * plug-ins/pygimp/gimpmodule.c
        * plug-ins/pygimp/pygimp-display.c
        * plug-ins/pygimp/pygimp-drawable.c
        * plug-ins/pygimp/pygimp-image.c
        * plug-ins/pygimp/pygimp-parasite.c
        * plug-ins/pygimp/pygimp-pdb.c
        * plug-ins/pygimp/pygimp-tile.c: Throw exceptions on failures for
        libgimp wrappers (fixes bug #160136), and make the exception strings   
     
        a lot more descriptive to aid debugging. Also return proper Bools when
        appropriate. Some new API wrapped as well. Still a work in progress.