Forums

Gtk warning: obsolete delete?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Gtk warning: obsolete delete?

Postby callisto » Tue Nov 08, 2011 4:11 pm

Hi,

I'm getting a warning message from Cobra which I don't understand and can't seem to get rid of. The warning is about the 'delete' method on the buffer of a Gtk.TextView:

# @args -pkg:gtk-sharp-2.0 # uncomment this

use Gtk

class MainWindow
def main
text = TextView()
text.buffer.delete(text.buffer.startIter, text.buffer.endIter)


The warning message when compiling the above is:

Code: Select all
$ cobra -c textview.cobra
textview.cobra(8): warning: "Gtk.TextBuffer.Delete(Gtk.TextIter, Gtk.TextIter)" is obsolete: "Replaced by "ref TextIter, ref TextIter" overload"
Compilation succeeded - 1 warning


If I use '@help text.buffer' to list all the available methods (a great facility, by the way!), I find only one 'delete' method, with signature: def delete(start as inout TextIter, end as inout TextIter)

Any ideas as to how to get rid of the warning? (Apart from the warning, the method seems to work as intended.)
callisto
 
Posts: 10

Re: Gtk warning: obsolete delete?

Postby Charles » Wed Nov 09, 2011 11:23 am

Try putting "inout" before each argument like so:
text.buffer.delete(inout text.buffer.startIter, inout text.buffer.endIter)


You can also try adding "# .no-warnings." to the end of the line.

Although I'm curious why the .delete method would want to modify the iters... I'll take a closer look at all of this later.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Gtk warning: obsolete delete?

Postby callisto » Wed Nov 09, 2011 1:20 pm

Thanks for the suggestions, however:

Charles wrote:Try putting "inout" before each argument like so:
text.buffer.delete(inout text.buffer.startIter, inout text.buffer.endIter)


That gives a different error message:
textview.cobra(8): error: A property cannot be passed as an "inout" parameter.


Charles wrote:You can also try adding "# .no-warnings." to the end of the line.


Sorry, but that didn't change anything. (Although "#.no-warnings." does work for me for different warnings.)

Charles wrote:Although I'm curious why the .delete method would want to modify the iters... I'll take a closer look at all of this later.


From the documentation "Because the buffer is modified, all outstanding iterators become invalid after calling this function; however, the start and end will be re-initialized to point to the location where text was deleted." So it's reinitialising the iterators (which are properties of the underlying text buffer).

It's just an annoyance, so please don't spend too much time on it. I thought there might be something straightforward I was missing, using a 'ref' or similar.

The API documentation (at http://docs.go-mono.com) does define two 'delete' methods on TextBuffer:

public void Delete (ref TextIter start, ref TextIter end)
public void Delete (TextIter start, TextIter end)

I seem to be using the second one, which is obsolete and triggering the warning. I've not managed to make Cobra call the first.

In case it affects things, "CLI binding for the GTK+ toolkit 2.12" and:

$ cobra -version
svn:2624 (post 0.8) / 2011-10-29 on Mono CLR v2.0.50727
callisto
 
Posts: 10

Re: Gtk warning: obsolete delete?

Postby Charles » Wed Nov 09, 2011 1:31 pm

Ah, the warning is coming from the C# back-end which apparently the "no-warnings" directive is not affecting.

I'll have to look closer to learn why Cobra sees the one method and not the other.

I had forgotten that inout cannot modify a property. You can try this:
start = text.buffer.startIter
end_ = text.buffer.endIter
text.buffer.delete(inout start, inout end_)

Otherwise, just live with the status quo until I figure it out more. I use GTK# too so I'll definitely get to it.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 42 guests