Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More robust variable handling #35

Merged
merged 1 commit into from
May 20, 2021

Conversation

cajfisher
Copy link
Contributor

Functions apply_transmat and change_transmat should take gpointers instead of gints
(Also tidied up a bit)

Functions apply_transmat and change_transmat should take gpointers instead of gints
(Also tidied up a bit)
@ovhpa
Copy link
Collaborator

ovhpa commented May 20, 2021

Hello again,

Making the cast from gpointer to gint inside the function is indeed more more compiler friendly.
I think it is similar to the idea with p_i and implicit cast when calling the function (but definitely, your solution is more explicit).

However, note that the problem was not really here but within the optimizing stages of clang: when compiling without optimization (-O0) it did compile fine with clang, and without any warning.
With higher optimization levels, optimization crashed, and clang complained about it.
In the optimization stage, when clang tried to unroll the loop
for(i=0;i<12;i++)
it then found that p_i is a pointer. In my understanding it then try to resolve the address, in case there is more optimization.
Then got address which is set with 0 (or 1,2,3,...,11) and doesn't know what to do with it. The implicit cast also didn't help ^^'

I think the "most robust" way to go is by passing a pointer that is really a pointer, ie. create a global:
const gint transmat_modes[12]={0,1,2,3,4,5,6,7,8,9,10,11};
Then use it directly to pass values, in the g_signal_connect
g_signal_connect(GTK_OBJECT(CEDIT.transmat[i]), "changed", GTK_SIGNAL_FUNC(change_transmat), &transmat_modes[i]);
The changes in change_transmat function would be trivial:
gint mode = *ptr;

What is your opinion? Can you implement such change?

Best,

@cajfisher
Copy link
Contributor Author

cajfisher commented May 20, 2021 via email

@ovhpa
Copy link
Collaborator

ovhpa commented May 20, 2021

Hi,

I know what GLIB says, but I am still inconfortable in setting a pointer that contains an integer value, and not points to an integer value (as pointer should do).
What I would prefer is to store an integer as an integer, and a pointer as a pointer, and if possible not use a trick to store an integer in or as a pointer.
But that may be a little too much, due to GKT limitation. I know, ... we did this a lot in GDIS :D

So I will pull your PR.
Let me some time to check ;)


If it were the case, then all the other instances where GINT_TO_POINTER is used would come up as errors also. (Not using GPOINTER_TO_INT in the receiver functions may well cause the compiler to stumble at higher optimizations).

The transmat case is specific because it lies on top of a loop that can be vectorized, which is not the case of any other GINT_TO_POINTER use. The pointer-containing-integer that is passed is then itself a candidate for variable vectorization.

For reference, in case something breaks due to new plateform / endianess / GLIB / clang etc, the global implementation:

@@ -61,6 +61,8 @@ extern struct elem_pak elements[];
 
 #define CEDIT (sysenv.cedit)
 
+gint transmat_index[12]={0,1,2,3,4,5,6,7,8,9,10,11};
+
 enum{AT_ANY, AT_SELECTED, AT_LATTICE};
 
 /*********************************************/
@@ -249,9 +251,11 @@ update_transmat();
 /********************************************/
 /* put text entry values into actual matrix */
 /********************************************/
-void change_transmat(GtkWidget *w, gint i)
+void change_transmat(GtkWidget *w, gpointer ptr)
 {
 const gchar *text;
+gint *ptr_i = ptr;
+gint i = *ptr_i;
 
 if(w==NULL) return;
 
@@ -2340,7 +2344,7 @@ reset_transmat();
 //                   GTK_SIGNAL_FUNC(change_transmat), p_i);
 for(i=0;i<12;i++)
        g_signal_connect(GTK_OBJECT(CEDIT.transmat[i]), "changed",
-                       GTK_SIGNAL_FUNC(change_transmat), GINT_TO_POINTER(i));
+                       GTK_SIGNAL_FUNC(change_transmat), &transmat_index[i]);
 }
 
 /***********************************************/

@ovhpa ovhpa merged commit e3141ed into arohl:master May 20, 2021
@cajfisher cajfisher deleted the transformation_maxtrix_bug_fix branch May 25, 2021 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants