Dan Nelson noted the following in the chat:
6:39 Genesys interesting. my amd64 pikefarm 7.8 fails the following test: return equal(Gmp.mpz(13)->gcdext(19), ({1, 3, -2})); 6:40 Genesys it returns ({ 1, -16, 11 }), which seems to be a correct answer if I do the math
Det är GMP-4.3 som beter sig lite annorlunda mot tidigare versioner. gcd och gcdext är ju helt utbyta där. Och det var visst en mindre bug i gcdext i 4.3.0, som är fixad i 4.3.1.
*switching back to English*
Both are correct. The documentation for gmp_gcdext does not define the "correct" answer uniquely. It computes g, s and t such that
g = gcd(a,b) = s a + t b
and |s| <= |b| and |t| <= |a|
If you, for example, want s to never be nonegative, you can do something like
if (s < 0) { s += b; t -= a }
(and then there are some additional borderline cases when you can have s = b or s = 0).
Then the testcase should check that these four conditions hold, rather than comparing to a fixed result.
I think you forgot about the check that g == gcd(a,b) (in this case 1), though. The current test would allow an incorrect result such as ({32,1,1}).
Why do we have a testsuite then?
I think that we should either check that the result is correct, or not check it at all. Currently two thirds of the result is checked.
To test that we can communicate with the Gmp lib. For most functions that is done by comparing with a predefined value, but if that can't be done, just testing that the returned value is reasonable is enough. E.g. we don't test that the returned value of random() is actually random.
And if the method returns ({32,1,1}) then it should that we can communicate with the library, but not if it returns ({1,2,3})?
I just found a bug in the GTK2.Container:
object a=GTK2.Window(GTK2.WindowToplevel); object b=GTK2.Button(); a->add(b); object c=GTK2.Label("text"); b->add(c);
c->add(b);
(Pike GTK:31904): Gtk-CRITICAL **: gtk_container_add: assertion `GTK_IS_WIDGET (widget)' failed
But, GTK2.Label is a GTK2.Widget. (it inherits form GTK2.Misc, which inherits from GTK2.Widget).
I may have to customize the add() method to do some checks and allow the add, rather than autogenerating the code.
This is a patch for the GTK2.Container bug I found today. I tested and it works. If everybody is okay with it, I will commit it.
diff -u -r1.7 gtkcontainer.pre --- gtkcontainer.pre 19 Jan 2008 15:09:07 -0000 1.7 +++ gtkcontainer.pre 25 Jun 2009 21:44:07 -0000 @@ -22,10 +22,19 @@ //! padding around the container. //! Calling this function might result in a resize of the container.
-void add(GTK2.Widget widget); +void add(GTK2.Widget widget) //! Add a subwidget to the container. Don't forget to call show() in //! the subwidget. Some (even most) containers can only contain one child. //! Calling this function might result in a resize of the container. +{ + pgtk2_verify_inited(); + { + struct object *o1; + get_all_args("add",args,"%o",&o1); + gtk_container_add(GTK_CONTAINER(THIS->obj),GTK_WIDGET(get_gobject(o1))); + } + RETURN_THIS(); +}
void remove(GTK2.Widget widget); //! Remove a child from the container. The argument is the child to remove.
----- Original Message ---- From: Lance Dillon riffraff169@yahoo.com To: pike-devel@lists.lysator.liu.se Sent: Thursday, June 25, 2009 2:41:23 PM Subject: GTK2.Container
I just found a bug in the GTK2.Container:
object a=GTK2.Window(GTK2.WindowToplevel); object b=GTK2.Button(); a->add(b); object c=GTK2.Label("text"); b->add(c);
c->add(b);
(Pike GTK:31904): Gtk-CRITICAL **: gtk_container_add: assertion `GTK_IS_WIDGET (widget)' failed
But, GTK2.Label is a GTK2.Widget. (it inherits form GTK2.Misc, which inherits from GTK2.Widget).
I may have to customize the add() method to do some checks and allow the add, rather than autogenerating the code.
Hm, how does this differ from the generated code? Maybe the code generation is wrong?
That is a good question. I'm doing a test now. I knew what the problem was, and my solution fixed it, but I didn't look at the generated code.
----- Original Message ---- From: "Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum" 10353@lyskom.lysator.liu.se To: pike-devel@lists.lysator.liu.se Sent: Thursday, June 25, 2009 7:00:02 PM Subject: Re: GTK2.Container
Hm, how does this differ from the generated code? Maybe the code generation is wrong?
This is the generated code:
void pgtk2_container_add( INT32 args ) #line 25 "/home/riffraff/src/Pike-v7.8.306/src/post_modules/GTK2/source/gtkcontainer.pre" { GtkWidget *a0; if( args < 1 ) Pike_error(/* "Too few arguments, %d required, got %d\n" */ (PSTR+0x2e), 1, args);
if( Pike_sp[ 0 - args ].type != PIKE_T_OBJECT ) a0 = NULL; else a0 = GTK_WIDGET(get_pg2object(Pike_sp[0-args].u.object, pgtk2_widget_program)); pgtk2_verify_inited(); gtk_container_add( GTK_CONTAINER(THIS->obj), GTK_WIDGET(a0) ); RETURN_THIS(); }
The only real difference I see is the call to get_pg2object, pgtk2_widget_program above vice pg2_object_program for my fix (because get_gobject() gets an object as a pg2_object_program).
I could rewrite my fix to grab pgtk2_widget_program instead and see what happens.
----- Original Message ---- From: Lance Dillon riffraff169@yahoo.com To: pike-devel@lists.lysator.liu.se Sent: Thursday, June 25, 2009 9:16:32 PM Subject: Re: GTK2.Container
That is a good question. I'm doing a test now. I knew what the problem was, and my solution fixed it, but I didn't look at the generated code.
----- Original Message ---- From: "Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum" 10353@lyskom.lysator.liu.se To: pike-devel@lists.lysator.liu.se Sent: Thursday, June 25, 2009 7:00:02 PM Subject: Re: GTK2.Container
Hm, how does this differ from the generated code? Maybe the code generation is wrong?
It is very probable that the answering entity was a GMP -- but knock yourself out, if you want to be really sure it's a non-buggy GMP too.
I, for one, would find it rather cool if we had a thorough-test-suite that would attacks the random function too, subjecting its randomness to scrutiny, estimating the amount of entropy we get out of it and the like, but I doubt anyone in this community would go to the effort to craft it.
It is very probable that the answering entity was a GMP -- but knock yourself out, if you want to be really sure it's a non-buggy GMP too.
But what I want to know is why it is more probable that the entity is GMP if the answer if ({32,1,1}) than if the answer is ({1,2,3}), i.e. why should we treat one incorrect answer as an error, but not another one? If all we're interrested in is that we get an answer, and don't care if it is correct or not, we should accept any answer (within the range of the function).
Keep in mind that the glue code can also be buggy. Correctness of GMP's C API does not magically imply correctness of the corresponding Pike functionality.
To me, it makes a lot of sense that the testsuite makes as strict correctness checks on the returned data as is practical (say, less than 20 lines of code and less than 100 ms execution time on a reasonable development machine).
Whenever a problems is detected, it should be fairly easy to determine if the bug is in the testsuite, in the glue code, or in GMP itself.
When you have g, s and t, which are claimed to satisfy
g = gcd(a, b) = s * a + t * b
then a sufficient test (besides the range checks) would be that
g == s*a + t * b a % g == 0 b % g == 0
Then it follows that g = gcd(a, b);
Or we could test if g is 1, since we already know this to be the gcd of 13 and 19... ;-)
pike-devel@lists.lysator.liu.se