Forum: Ruby-Gnome 2 ideas for (small) internal code enhancement

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C838db9af1d90a87a828ecad8556b804?d=identicon&s=25 Guillaume Cottenceau (Guest)
on 2007-07-10 18:19
(Received via mailing list)
- Lately I have seen there are lots of places in the code where we have:

   return ...expression... ? Qtrue : Qfalse

I think all of these cases may be replaced by

   return CBOOL2RVAL(...expression...)

I can script the change if you agree, and even add some autotest at
build time to check there are no new such things[1]?

- I have replaced all "foo == Qnil" by "NIL_P(foo)". I think it might
be useful to add some autotest to keep that clean in the future, what
do you think?

- Recently, I have also fixed a method implemented with the variable
arguments list form but attached to the ruby class with a fixed
arguments list. I can script a check and add an autotest for it.

- Also, I have fixed a couple of memory leaks in gdk-pixbuf-scale, gtk
returned a newly allocated object and we need special magic on it; for
that, I would suggest to share the "special magic" with a special
macro, for example NEWGOBJ2RVAL; and also, I think we need an
automatized way to track all these memory leaks; what do you think of
making use of the scheme definitions used in pygtk? they use
"caller-owns-return #t" to indicate where a new allocation supposed to
be freed later is performed

- I have seen that when using RARRAY(foo)->ptr or other pointer
dereferencing on a Ruby array, often there is "Check_Type(foo,
T_ARRAY)" before. However, I cannot find "official" rb_check_type
documentation to understand what it does exactly (is there any ruby
development API documentation available? I repeatedly bump into that).
Anyway, I suppose Check_Type is a good thing(TM), so I'd like to also
add an autotest to check that all RARRAY(foo)->ptr use cases are
always following a Check_Type, what do you think?

Phew, enough rg2 brainstorming for today :)

[1] would that be ok to write these scripts in perl?

--
Guillaume Cottenceau - http://zarb.org/~gc/

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
9fe908f5593444a40be14a424c372e58?d=identicon&s=25 Masao Mutoh (Guest)
on 2007-07-11 17:45
(Received via mailing list)
Hi,

On Tue, 10 Jul 2007 18:18:58 +0200
"Guillaume Cottenceau" <gcottenc@gmail.com> wrote:

> - Lately I have seen there are lots of places in the code where we have:
>
>    return ...expression... ? Qtrue : Qfalse
>
> I think all of these cases may be replaced by
>
>    return CBOOL2RVAL(...expression...)

Agreed. It's been one of my  TODO for a long time :-|

> I can script the change if you agree, and even add some autotest at
> build time to check there are no new such things[1]?

perl !? why!?
Do you mean you add the test with perl in CVS?
If so, I don't agree with it.
Because, I don't think to install ActivePerl to my Windows machine
when I compile and test it on Windows.
It should work on every environment which we support unless additional
tools except ruby and gtk.
# That's the reason why I rewrote glib-mkenums.

If you mean you just make the converter and use it by youself only,
I don't mind what tools you use.

> - I have replaced all "foo == Qnil" by "NIL_P(foo)". I think it might
> be useful to add some autotest to keep that clean in the future, what
> do you think?

Agree, if you can.

> - Recently, I have also fixed a method implemented with the variable
> arguments list form but attached to the ruby class with a fixed
> arguments list. I can script a check and add an autotest for it.

What are "variable arugments list" and "fixed arguments list"?

> - Also, I have fixed a couple of memory leaks in gdk-pixbuf-scale, gtk
> returned a newly allocated object and we need special magic on it; for
> that, I would suggest to share the "special magic" with a special
> macro, for example NEWGOBJ2RVAL; and also, I think we need an
> automatized way to track all these memory leaks; what do you think of
> making use of the scheme definitions used in pygtk? they use
> "caller-owns-return #t" to indicate where a new allocation supposed to
> be freed later is performed

I don't agree. we don't need the macros of "Special cases".
In this case, you can define NEWGOBJ2RVAL  on the top of
rbgdk-pixbuf.c  like _SELF().

> - I have seen that when using RARRAY(foo)->ptr or other pointer
> dereferencing on a Ruby array, often there is "Check_Type(foo,
> T_ARRAY)" before. However, I cannot find "official" rb_check_type
> documentation to understand what it does exactly (is there any ruby
> development API documentation available? I repeatedly bump into that).

In ruby tar-ball, there is README.EXT and Check_Type is described in it.

> Anyway, I suppose Check_Type is a good thing(TM), so I'd like to also
> add an autotest to check that all RARRAY(foo)->ptr use cases are
> always following a Check_Type, what do you think?

Agreed.

> Phew, enough rg2 brainstorming for today :)

Sure. It's good idea to iterate this kind of discussions.

--
.:% Masao Mutoh<mutoh@highway.ne.jp>


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
C838db9af1d90a87a828ecad8556b804?d=identicon&s=25 Guillaume Cottenceau (Guest)
on 2007-07-11 23:04
(Received via mailing list)
Hi Masao,

Thanks for your reply.

> > I can script the change if you agree, and even add some autotest at
> > build time to check there are no new such things[1]?
>
> perl !? why!?

Simply because I feel more comfortable writing small file parsing and
modification oriented scripts in perl.

> Do you mean you add the test with perl in CVS?

Yes, that was the plan.

> If so, I don't agree with it.
> Because, I don't think to install ActivePerl to my Windows machine
> when I compile and test it on Windows.

Ah, ok. I wasn't aware you used windows that much. On linux, perl is a
no-cost.
Then it should not be much more difficult to write it in ruby. And
I'll get more training for small file-oriented scripts in ruby :)

> > - Recently, I have also fixed a method implemented with the variable
> > arguments list form but attached to the ruby class with a fixed
> > arguments list. I can script a check and add an autotest for it.
>
> What are "variable arugments list" and "fixed arguments list"?

A function with parameters "argc, argv, self", which then needs to be
binded with rb_define_method with -1 as last parameter. I have noticed
that if if is binded with 2 or whatever as last parameter, it is an
error which is unnoticed.

> In this case, you can define NEWGOBJ2RVAL  on the top of
> rbgdk-pixbuf.c  like _SELF().

It might not be too special. I can grep 71 "caller-owns-return #t' in
*.defs from pygtk (many of them seem to be additional constructors
though). Also, a newly-allocated GObject* returned by a function,
seems to be not a special to gdk-pixbuf case, so I thought it made
more sense at the GObject level.

> > - I have seen that when using RARRAY(foo)->ptr or other pointer
> > dereferencing on a Ruby array, often there is "Check_Type(foo,
> > T_ARRAY)" before. However, I cannot find "official" rb_check_type
> > documentation to understand what it does exactly (is there any ruby
> > development API documentation available? I repeatedly bump into that).
>
> In ruby tar-ball, there is README.EXT and Check_Type is described in it.

Thanks!

--
Guillaume Cottenceau - http://zarb.org/~gc/

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
9fe908f5593444a40be14a424c372e58?d=identicon&s=25 Masao Mutoh (Guest)
on 2007-07-13 17:43
(Received via mailing list)
Hi,

On Wed, 11 Jul 2007 23:04:23 +0200
"Guillaume Cottenceau" <gcottenc@gmail.com> wrote:

> > > - Recently, I have also fixed a method implemented with the variable
> > > arguments list form but attached to the ruby class with a fixed
> > > arguments list. I can script a check and add an autotest for it.
> >
> > What are "variable arugments list" and "fixed arguments list"?
>
> A function with parameters "argc, argv, self", which then needs to be
> binded with rb_define_method with -1 as last parameter. I have noticed
> that if if is binded with 2 or whatever as last parameter, it is an
> error which is unnoticed.

Ah, yes. Good idea.

> > In this case, you can define NEWGOBJ2RVAL  on the top of
> > rbgdk-pixbuf.c  like _SELF().
>
> It might not be too special. I can grep 71 "caller-owns-return #t' in
> *.defs from pygtk (many of them seem to be additional constructors
> though). Also, a newly-allocated GObject* returned by a function,
> seems to be not a special to gdk-pixbuf case, so I thought it made
> more sense at the GObject level.

Start with gdk-piixbuf.c and some other libraries. It's really general,
then move the macro to ruby-glib2.

--
.:% Masao Mutoh<mutoh@highway.ne.jp>


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
This topic is locked and can not be replied to.