Ideas for (small) internal code enhancement

  • 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™, 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 :slight_smile:

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


Guillaume C. - 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/

Hi,

On Tue, 10 Jul 2007 18:18:58 +0200
“Guillaume C.” [email protected] 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 :expressionless:

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™, 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 :slight_smile:

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


.:% Masao M.[email protected]


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/

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 :slight_smile:

  • 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 C. - Guillaume Cottenceau


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/

Hi,

On Wed, 11 Jul 2007 23:04:23 +0200
“Guillaume C.” [email protected] 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 M.[email protected]


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/