IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C Discussion :

Erreur d'allocation mémoire - GTK+


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2008
    Messages : 15
    Par défaut Erreur d'allocation mémoire - GTK+
    Bonjour tout le monde !

    je fait une application sur les polynomes avec interface graphique, GTK+ .

    Mon problème est que l'une des fonctionnalitées ( appelont la F ) ne marche uniquement si je ne lance pas l'interface graphique.

    /* F(int n, float* tx, float* ty) retourne le polynome de lagrange de deux series (x1 ... xn ) ( f(x1) ... f(xn) ) */

    pol.c contient les fonctions sur les polynomes
    callback.c contient les actions des boutons de l'interface
    win.c contient le code de l'interface

    F fonctionne lorsque je l'utilise sans interface ( sans utiliser les deux autres fichiers) même avec des polynomes de degre 20.

    Alors que F ne fonctionne avec l'interface que si le polynome est de degre <= 7.

    Si supérieur à 7 voici ce que j'obtien a l'éxecution :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    *** glibc detected *** ./prog: malloc(): memory corruption: 0x08216988 ***
    ======= Backtrace: =========
    /lib/tls/i686/cmov/libc.so.6[0xb7814356]
    /lib/tls/i686/cmov/libc.so.6(__libc_malloc+0x8d)[0xb7815cad]
    Backtrace du gdb :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
     
    Program terminated with signal 11, Segmentation fault.
    [New process 7094]
    #0  0xb78a80e8 in ?? () from /lib/tls/i686/cmov/libc.so.6
    (gdb) bt full
    #0  0xb78a80e8 in ?? () from /lib/tls/i686/cmov/libc.so.6
    No symbol table info available.
    #1  0xb78a9cad in malloc () from /lib/tls/i686/cmov/libc.so.6
    No symbol table info available.
    #2  0x0804999f in pol_alloc ()
    No locals.
    #3  0x08049f6f in pol_sum ()
    No locals.
    #4  0x0804b4fc in pol_lagrange_interpolation ()
    No locals.
    #5  0x0804c2bd in cb_start ()
    No locals.
    #6  0xb7a5baef in g_cclosure_marshal_VOID__VOID () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #7  0xb7a4e749 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #8  0xb7a62f7b in ?? () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #9  0xb7a64c0f in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #10 0xb7a64f59 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #11 0xb7c7801a in gtk_button_clicked () from /usr/lib/libgtk-x11-2.0.so.0
    No symbol table info available.
    #12 0xb7c79b7e in ?? () from /usr/lib/libgtk-x11-2.0.so.0
    No symbol table info available.
    #13 0xb7a5baef in g_cclosure_marshal_VOID__VOID () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #14 0xb7a4d069 in ?? () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #15 0xb7a4e749 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
    ---Type <return> to continue, or q <return> to quit---No symbol table info available.
    #16 0xb7a62bbb in ?? () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #17 0xb7a64c0f in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #18 0xb7a64f59 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #19 0xb7c780aa in gtk_button_released () from /usr/lib/libgtk-x11-2.0.so.0
    No symbol table info available.
    #20 0xb7c780d1 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
    No symbol table info available.
    #21 0xb7d518d4 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
    No symbol table info available.
    #22 0xb7a4d069 in ?? () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #23 0xb7a4e749 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #24 0xb7a6310a in ?? () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #25 0xb7a64937 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #26 0xb7a64f59 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
    No symbol table info available.
    #27 0xb7e70667 in ?? () from /usr/lib/libgtk-x11-2.0.so.0
    No symbol table info available.
    #28 0xb7d4ab21 in gtk_propagate_event () from /usr/lib/libgtk-x11-2.0.so.0
    No symbol table info available.
    #29 0xb7d4bd88 in gtk_main_do_event () from /usr/lib/libgtk-x11-2.0.so.0
    No symbol table info available.
    #30 0xb7bc4a9a in ?? () from /usr/lib/libgdk-x11-2.0.so.0
    No symbol table info available.
    ---Type <return> to continue, or q <return> to quit---#31 0xb79c2cf6 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
    No symbol table info available.
    #32 0xb79c60b3 in ?? () from /usr/lib/libglib-2.0.so.0
    No symbol table info available.
    #33 0xb79c6497 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
    No symbol table info available.
    #34 0xb7d4c264 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
    No symbol table info available.
    #35 0x0804d1c0 in main ()
    Donc apparement l'erreur se fait dans la librairie C.

    Toutes les autres fonctionnalitées marchent tres bien avec l'interface, fonctionnalitées qui sont plus gourmandes en calcul, donc ...

    Peut-on en conclure que GTK est la cause de cette erreur ?

    Je ne pense quand meme pas que la memoire allouée à l'interface + celle aux calculs soit trop élevée, j'ai 1GO de Ram.

    Voila, je vous demande votre avis car je ne sait vraiment pas ce qu'il se passe, si vous voulez le code du programme je vous ferais une petite archive !

    Merci à tous !

    Ciao & à bientôt !

  2. #2
    Membre confirmé
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Juillet 2005
    Messages
    147
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juillet 2005
    Messages : 147
    Par défaut
    Salut,

    Je ne suis pas du tout sur que ce que je vais te conseiller va marcher, mais souvent (toujours ?) j'obtiens cette erreur quand je libère de la mémoire, avec free.

    Tu peux commencer par retirer les free (ou les gfree) avec un define pour tout remplacer d'un coup, puis voir si ça fonctionne mieux. Si c'est le cas, c'est surement que tu essaies de libérer de la mémoire que tu n'as pas allouées. Vérifies donc tes malloc et tes free.

    Bon courage

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2008
    Messages : 15
    Par défaut
    Salut et merci pour ta réponse !

    Non, je sais ce que n'est pas un problème de libération étant donné que la fonction marche indépendament de l' interface !

    gdb a réussi a identifier l'appel provoquant l'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    (gdb) bt full
    #0  0xb7f4f410 in __kernel_vsyscall ()
    No symbol table info available.
    #1  0xb782b085 in raise () from /lib/tls/i686/cmov/libc.so.6
    No symbol table info available.
    #2  0xb782ca01 in abort () from /lib/tls/i686/cmov/libc.so.6
    No symbol table info available.
    #3  0xb7863b7c in ?? () from /lib/tls/i686/cmov/libc.so.6
    No symbol table info available.
    #4  0xb786c356 in ?? () from /lib/tls/i686/cmov/libc.so.6
    No symbol table info available.
    #5  0xb786dcad in malloc () from /lib/tls/i686/cmov/libc.so.6
    No symbol table info available.
    #6  0x08049ae6 in pol_alloc ()
    No locals.
    #7  0x0804a291 in pol_sum_and_destroy ()
    No locals.
    #8  0x0804b913 in pol_lagrange_interpolation ()
    No locals.
    #9  0x0804c6a5 in win_interpolation ()
    No locals.
    #10 0x0804c92a in cb_start ()
    C'est donc __kernel_vsyscall () qui provoque l'erreur... et vu son nom ça m'inquiète un peu

    __kernel_vsyscal is the method used by linux-gate.so (a part of the Linux kernel) to make a system call using the fastest available method, preferably the sysenter instruction.
    Je suis sur Ubuntu 8.04 Hardy LTS
    Je vais lire ceci

    Le programme marche quand je l'execute avec Valgrind... voila !

    Si quelqu'un a un avis sur le sujet il serait plus que bienvenu !

  4. #4
    Membre Expert Avatar de nicolas.sitbon
    Profil pro
    Inscrit en
    Août 2007
    Messages
    2 015
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 2 015
    Par défaut
    De toute façon, tant que tu ne posteras pas un code compilable qui reproduise le problème, tout le monde perdra son temps.

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2008
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2008
    Messages : 15
    Par défaut
    Bonjour également !

    Tu as raison, je met le code.

    Voici le code partiel (uniquement les méthodes utilisées lors de la provocation de l'erreur) :

    Voici la formule afin d'obenir le polynome de lagrange à partir de N points :
    X0, ..., X(n-1)
    f(X0) , ... , f(Xn-1)


    FICHIER POL.C Fonctions polynomiales

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
     
    /**************** P O L *****************/
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <fcntl.h>
    #include <math.h>
    #include <errno.h>
    #define epsilon 0.001
    #define Nmax 150
     
    /* check if equals zero */
    int is_zero(float x){
      if(fabs(x - 0) < epsilon)
        return 1;
      return -1;
    }
     
     
    /* Structure du polynome*/
    typedef struct pol{
      int degre;
      float* coef; // coef[0] = Cte ... coef[ degre + 1] = X^(degre)
    } pol;
     
     
     
     
    /* Allocation d'un polynome */
    pol* pol_alloc(int n){
      int i;
     
      pol* p = malloc(sizeof(pol));
      if(!p){
        perror("Malloc Failed");
        return NULL;
      }
     
      p->degre = n;
      p->coef = malloc(sizeof(float)*(n+1));
      if(!(p->coef)){
        perror("Malloc failed");
        return NULL;
      }
     
      for(i=0; i<=n; i++)
        p->coef[i] = 0;
      return p;
    }
     
     
    /* Affichage polynome */
    void pol_print(pol* p){
      int i;
      int n = p->degre;
      for(i=0; i<=n; i++)
        printf("%+5.3f * X^%d ",p->coef[i],i);
      printf("\n");
    }
     
     
     
    /*  Pol  to  string  */
    char* pol_toString(pol* p){
      int n = p->degre;
      char* res = malloc(sizeof(char)*((n+1)*(13)));
      char* pos = res;
      char*s;
      int i,nb;
      for(i=0; i<=n; i++){
        if(is_zero(p->coef[i])==1)
          continue;
        (i!=0)?(nb = sprintf(res," %+5.2f * X^%d ",p->coef[i],i)) : (nb = sprintf(res,"%5.2f",p->coef[i]));
        res+=nb;
      }
     
      s = strdup(pos);
      free(pos);
      return s;
    }
     
     
    /* Return real degre polynome ie: 1 + 2x + 3x² + 0x³ + 0(x^4) --> 1 + 2x + 3x²*/
    pol* real_degre(pol*p){
      pol* res;
      int n = p->degre;
      int i=n,j;
     
      if(n==0)
        return p;
     
      while(i>0 && is_zero(p->coef[i]) == 1){
        i--;
      }
     
      if( i == n)
        return p;
     
      res = pol_alloc(i);
      for(j=0; j<=i; j++)
        res->coef[j]=p->coef[j];
     
      pol_free(p);
      return res;
    }
     
     
    /* Somme de polynomes  */
    pol* pol_sum(pol* p,pol* q){
      int dp = p->degre;
      int dq = q->degre;
      int dres = max(dp,dq);
      printf("DEGRE SOMME : %d\n",dres);
     
      pol* res = pol_alloc(dres);
     
      printf("POL ALLOC Successfull ! \n");
      int i;
     
      if(dp>dq){  // p de degre supérieur
        for(i=0; i<=dq; i++)
          res->coef[i] = p->coef[i] + q->coef[i];   
        for(i=dq; i<=dres; i++)
          res->coef[i] = p->coef[i];
     
      }else if(dp<dq){ // q de degre superieur
        for(i=0; i<=dp; i++)
          res->coef[i] = p->coef[i] + q->coef[i];   
        for(i=dp; i<=dres; i++)
          res->coef[i] = q->coef[i];
      }
    else{ // p et q de meme degre
        for(i=0; i<=dp; i++)
          res->coef[i] = p->coef[i] + q->coef[i];  
      }
     
      //pol_print(res);
     
      return real_degre(res);
    }
     
     
     
    /* Produit de polynomes */
    pol* pol_product(pol* p,pol* q){
     
      int dp = p->degre , dq= q->degre , dres = dq+dp;
      pol* res = pol_alloc(dres);
      int i,j;
     
      for(i=0; i<=dp; i++){
        for(j=0; j<=dq; j++){
          res->coef[i+j] += p->coef[i] * q->coef[j];
        }
      }
     
      return real_degre(res);
    }
     
     
    /* pol newton read data series */
    int pol_read_series(char* path, void** tab){
      int n,i,l,nb=0;
      float** res = malloc(sizeof(float*)*2);
      FILE* f;
     
      if( (f = fopen(path , "r"))==NULL){
        perror("ERROR : File doesn't exist\n");
        errno = EEXIST;
        return -1;
     
      }else if( (nb = fscanf(f,"%d", &n))<1 ){
        perror("ERROR : Incorrect length of serie\n");
        return -2;
      }
      res[0] = malloc(sizeof(float)*n);
      res[1] = malloc(sizeof(float)*n);
      nb=0;
      for(i=0; i<n; i++){
        nb+= fscanf(f, "%f" , &(res[0][i]));
        printf("%d\n",nb);
      }
     
      for(i=0; i<n; i++){
        if(i<n-1)
          if(res[0][i] >= res[0][i+1]){
    	perror("ERROR : Incorrect X axis points\n");
    	return -3;
          }
        nb+= fscanf(f, "%f" , &(res[1][i]));
        printf("%d\n",nb);
      }
     
      if(nb != n*2){
        printf("%d   %d\n" , nb,n*2);
        perror("ERROR : Incorrect series integrity\n");
        return -4;
      }
     
      /**tab[0] = res[0];
       *tab[1] = res[1];*/
      *tab = res;
     
      fclose(f);
      return n;
    }
     
     
     
     
    /* pol lagrange interpolation 
       tx :  contient la suite des Xi
       ty :  contient la suite des f(xi)
    */
    pol* pol_lagrange_interpolation(int n, float* tx, float* ty){
     
      int i,j,k;
      float a,b;
      pol* mon; // pour tout j, contient le polynome de degre 1 a l'interieur du produit de la formule
      pol* sum; // Forme pas a pas le polynome P(x) de la formule
      pol* pi;    //  pour tout i, Forme pas a pas le polynome produit de la formule 
      mon = pol_alloc(1);
     
      sum = pol_alloc(n-1);
     
      for(i=0; i<n; i++){    
        pi = pol_alloc(0);
        pi->coef[0] = 1;
     
        for(j=0; j<n; j++){
          if(j!=i){
     
    	a = - ( tx[j] / ( tx[i] - tx[j] ) );
    	b = (float)1 / ( tx[i] - tx[j] ) ;
    	mon->coef[0] = a;
    	mon->coef[1] = b;
     
    	pi = pol_product(pi, mon);
     
          }
        } 
        for(k=0; k<=n-1; k++)
          pi->coef[k]*= ty[i];
     
        printf("\t----------------------------\n");
        pol_print(pi);
        pol_print(sum);
        sum = pol_sum(sum, pi);
     
      }
     
      return sum;
    }
    FICHIER CALLBACK.C Fonctions appellées par les boutons de l'interface

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
     
    /*   win interpolaion */
    void win_interpolation(){
      const gchar *s = gtk_entry_get_text(GTK_ENTRY(path_entry) );
     
      char* buf = malloc(sizeof(char)*512);
      char* pos;
      char* pols;
      pol* p;
      float** tab;
      char** t = malloc(sizeof(char*)*2);
      int nb=0,n;
     
      pos = buf;
      tab = malloc(sizeof(float*)*2);
      if(s==NULL){    
     
        gtk_label_set_text(GTK_LABEL(main_label) ,"ERROR : Enter a correct file 's path" );
     
      }else{
        n = pol_read_series( s , &tab);// on récupere les tableaux de float
        printf("%d\n",n);
        switch(n){
        case -1:gtk_label_set_text(GTK_LABEL(main_label) ,"ERROR : File doen't exists" ); break;
        case -2:gtk_label_set_text(GTK_LABEL(main_label) ,"ERROR : Incorrect lenght indication" );break;
        case -3:gtk_label_set_text(GTK_LABEL(main_label) ,"ERROR : Incorrect X axis points" );break;
        case -4:gtk_label_set_text(GTK_LABEL(main_label) ,"ERROR : Incorrect series's lenght" );break;
        default:break;
        }
     
        if(n>0){
          printf("----- N = 0 - Lagrange begins ------ \n");
          p = pol_lagrange_interpolation(n,tab[0],tab[1]); // on récupere le polynome de lagrange correspondant aux tableaux
     
          //fflush(stdout);
          printf("Inter Lagrange Passed\n");
          pol_print(p);
     
          nb = sprintf(buf, "I N T E R P O L A T I O N\n\n\n\n");buf+=nb;
     
          printf("*****************************  enter printing\n");
     
          t[0] = tab_toString(tab[0],n);
          t[1] = tab_toString(tab[1],n);
          pols = pol_toString(p);
     
          printf("TABS : %s\n%s\n" , t[0],t[1]);
          nb = sprintf(buf,"Points\t\t\t:\t%d\nX points\t\t:\t%s\nF(X)\t\t\t:\t%s\nLagrange Polynomial\t:\t%s\n", 
    	n , t[0], t[1] , pols);
     
     
          printf("***************************** exit printing\n");
     
          gtk_label_set_text(GTK_LABEL(main_label) ,pos);// on affiche dans le label le résultat
     
          /*free(pols);
          free(pos);
          pol_free(p);
          free(tab[0]);
          free(tab[1]);
          free(t[0]);
          free(t[1]);
          free(tab);
          free(t);*/
        }
     
      }
     
    }
     
     
     
     
    /*   Start button action  */
    void cb_start(){
      //gtk_misc_set_alignment(main_label, 0.25, 0.25);
     
     
     
      if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(eval_radio))){
     
        win_eval();
     
      }else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(roots_radio))){
     
        win_roots();
     
      }else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gcd_radio))){
     
        win_gcd();
     
      }else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(matrix_radio))){
        win_matrix();
     
      }
     
      // LA PARTIE QUI NOUS INTERESSE
      else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(interpolation_radio))){
        /*pol* p;
        int nb,n;
        
        float** t;
        
        n = pol_read_series("series",&t);
        p = pol_lagrange_interpolation(n,t[0],t[1]);
        pol_print(p);
        printf(" ALL CALUCALTIONS ARE FINISHED\n ");*/
        win_interpolation();
     
      }
    }
    FICHIER WIN.C Construction de l'interface

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
     
    #include <stdio.h>
    #include <unistd.h>
    #include <fcntl.h>
    #include <stdlib.h>
    #include <string.h>
    #include <gtk/gtk.h>
    #include <errno.h>
    #include "callback.h"
     
     
     
    GtkWidget *main_window;
     
    GtkWidget* main_table;
     
    GtkWidget *scroll;
     
     
    /* BOXES */
    GtkWidget* main_Vbox;
    GtkWidget* path_Hbox;
    GtkWidget* menu_Vbox;
    GtkWidget* eval_Hbox;
     
    /* BUTTONS */
    GtkWidget* quit_button;
    GtkWidget* start_button;
    GtkWidget* save_button;
     
    /* RADIOS */
    GtkWidget* eval_radio;
    GtkWidget* gcd_radio;
    GtkWidget* roots_radio;
    GtkWidget* interpolation_radio;
    GtkWidget* matrix_radio;
     
    /* ENTRYS */
    GtkWidget* path_entry;
    GtkWidget* eval_entry;
     
    /* LABELS */
    GtkWidget* main_label;
    GtkWidget* path_label;
    GtkWidget* options_label;
     
     
     
    /* Creation de la fenetre principale de notre application */
    void make_window(){
      main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_title(GTK_WINDOW(main_window) , "-= Polynomials &  Matrix by Pierre Broggi =-");
      gtk_window_set_position(GTK_WINDOW(main_window), GTK_WIN_POS_CENTER);
      g_signal_connect (G_OBJECT (main_window), "destroy", G_CALLBACK (cb_quit), NULL);
      gtk_window_maximize(GTK_WINDOW(main_window));
    }
     
     
    /* builds boxes */
    void make_boxes(){
      main_Vbox = gtk_vbox_new(FALSE, 0);
      menu_Vbox = gtk_vbox_new(TRUE, 0);
      path_Hbox = gtk_hbox_new(TRUE, 0);
      eval_Hbox = gtk_hbox_new(FALSE, 0);
    }
     
     
     
    /* Creation des elements */
    void make_elements(){
     
      main_table = gtk_table_new(1,2,FALSE);
     
      //buttons
      quit_button = gtk_button_new_from_stock(GTK_STOCK_QUIT);
      g_signal_connect(G_OBJECT(quit_button) , "clicked", G_CALLBACK(cb_quit), NULL );
     
      start_button = gtk_button_new_with_label("S T A R T");
      g_signal_connect(G_OBJECT(start_button) , "clicked" , G_CALLBACK(cb_start) , NULL);
     
      save_button = gtk_button_new_with_label("S A V E");
      g_signal_connect(G_OBJECT(save_button) , "clicked" , G_CALLBACK(cb_save) , NULL);
     
      //labels
      main_label = gtk_label_new("P O L Y N O M I A L S    &    M A T R I X         \n\n\n\tby Pierre Broggi");
      path_label = gtk_label_new("ENTER PATH(S) : ");
      options_label = gtk_label_new("\nOPTIONS : ");
     
      gtk_misc_set_alignment(options_label, 0.1,0);
     
      //entry
      path_entry = gtk_entry_new();
      eval_entry = gtk_entry_new();
     
      gtk_entry_set_width_chars(GTK_ENTRY(eval_entry),8);
     
      scroll = gtk_scrolled_window_new(NULL,NULL);
      gtk_scrolled_window_add_with_viewport(scroll, GTK_WIDGET(main_label));
      gtk_scrolled_window_set_policy (scroll, GTK_POLICY_AUTOMATIC , GTK_POLICY_AUTOMATIC );
     
      gtk_container_add(GTK_CONTAINER(main_window),main_table);
     
    }
     
     
    /*  Make radio  */
    void make_radios(){
      eval_radio = gtk_radio_button_new_with_label(NULL, "ESTIMATE");
      roots_radio = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (eval_radio) , "GET ROOTS");
      gcd_radio = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (eval_radio) , "GET GCD");
      interpolation_radio = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (eval_radio) , "INTERPOLATION");
      matrix_radio = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (eval_radio) , "SOLVE SYS");
     
    }
     
     
     /* Ajout des elements dans la box */
    void add_elements(){
     
      //main
      gtk_box_pack_start(GTK_BOX(main_Vbox) , scroll, TRUE,TRUE, 10);
      gtk_box_pack_start(GTK_BOX(main_Vbox) , path_Hbox, FALSE,FALSE, 0);
     
      //menu
      gtk_box_pack_start(GTK_BOX(menu_Vbox) , options_label,FALSE,FALSE, 0);
      gtk_box_pack_start(GTK_BOX(menu_Vbox) , eval_Hbox, TRUE,TRUE, 0);
      gtk_box_pack_start(GTK_BOX(menu_Vbox) , gcd_radio, TRUE,TRUE, 0);
      gtk_box_pack_start(GTK_BOX(menu_Vbox) , roots_radio, TRUE,TRUE, 0);
      gtk_box_pack_start(GTK_BOX(menu_Vbox) , interpolation_radio, TRUE,TRUE, 0);
      gtk_box_pack_start(GTK_BOX(menu_Vbox) , matrix_radio, TRUE,TRUE, 0);
      //gtk_box_pack_start(GTK_BOX(menu_Vbox) , quit_button , TRUE,FALSE, 0);
     
      //path
      gtk_box_pack_start(GTK_BOX(path_Hbox) , path_label , FALSE,FALSE, 0);
      gtk_box_pack_start(GTK_BOX(path_Hbox) , path_entry , TRUE,TRUE, 0);
      gtk_box_pack_start(GTK_BOX(path_Hbox) , start_button , FALSE,FALSE, 0);
      gtk_box_pack_start(GTK_BOX(path_Hbox) , save_button, FALSE,FALSE, 0);
     
      //eval
      gtk_box_pack_start(GTK_BOX(eval_Hbox) , eval_radio, FALSE,FALSE,0);
      gtk_box_pack_start(GTK_BOX(eval_Hbox) , eval_entry, FALSE,FALSE, 0);
    }
     
     
    void table_attach(){
      gtk_table_attach(main_table, menu_Vbox,0,1,0,1,GTK_SHRINK,GTK_EXPAND | GTK_FILL ,0,0 );
     
     
      gtk_table_attach_defaults(GTK_TABLE(main_table), main_Vbox ,1,2,0,1);
    }
     
     
    int main (int argc, char **argv){
     
     
      //Initialisation de GTK+ 
      gtk_init (&argc, &argv);
     
      make_window(); 
      make_elements();
      make_radios();
      make_boxes();
      add_elements();
      table_attach();
     
      //Affichage de la fenetre principale 
      gtk_widget_show_all(main_window);
     
      //Lancement de la boucle principale 
      gtk_main ();
     
     
     
      printf("Program exited successfully. Return Code : %d (OK)\n" , EXIT_SUCCESS);
      return EXIT_SUCCESS;
     
    }
    Voici une archive tar contenant tout le programme avec Makefile :
    Pol.tar.gz

    AVEC INTERFACE :

    'make' pour compiler
    'make clean' pour nettoyer
    ./prog pour lancer le programme

    Le fichier texte seriesOK contient les points à partir desquels le polynome est construit, ça marche.
    Idem pour le fichier texte seriesBUG sauf que là ça bug.

    Selectionner la radio_box 'Interpolation'
    Entrer 'seriesBUG' dans le champs de saisie de texte
    Clicker sur le bouton 'START'

    SANS INTERFACE : Dans le fichier pol.c
    Libérer le main des bornes de commentaires

    compilation : gcc pol.c -o pol -lm
    éxecution : ./pol ./series_bug

    Voila, j'espere que ça sera plus clair maintenant !

  6. #6
    Membre Expert Avatar de nicolas.sitbon
    Profil pro
    Inscrit en
    Août 2007
    Messages
    2 015
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 2 015
    Par défaut
    corrige ces erreurs et poste ta correction s'il te plaît:
    pol.c: In function \u2018pol_toString\u2019:

    pol.c:219: attention : incompatible implicit declaration of built-in function \u2018strdup\u2019

    pol.c: In function \u2018pol_get_roots\u2019:

    pol.c:822: attention : passing argument 2 of \u2018pol_set_sturm\u2019 from incompatible pointer type

    pol.c: In function \u2018pol_solution\u2019:

    pol.c:858: attention : passing argument 2 of \u2018pol_get_roots\u2019 from incompatible pointer type

    callback.c: In function \u2018win_eval\u2019:

    callback.c:38: attention : passing argument 1 of \u2018pol_read\u2019 discards qualifiers from pointer target type

    callback.c:52: attention : passing argument 2 of \u2018sprintf\u2019 makes pointer from integer without a cast

    callback.c:52: attention : le format n'est pas une cha\u00eene litt\u00e9rale et pas d'argument de format

    callback.c: In function \u2018win_roots\u2019:

    callback.c:75: attention : passing argument 1 of \u2018pol_read\u2019 discards qualifiers from pointer target type

    callback.c:82: attention : passing argument 2 of \u2018pol_get_roots\u2019 from incompatible pointer type

    callback.c:86: attention : format \u2018%s\u2019 expects type \u2018char *\u2019, but argument 3 has type \u2018int\u2019

    callback.c:95: attention : format \u2018%s\u2019 expects type \u2018char *\u2019, but argument 3 has type \u2018int\u2019

    callback.c: In function \u2018win_gcd\u2019:

    callback.c:147: attention : format \u2018%s\u2019 expects type \u2018char *\u2019, but argument 3 has type \u2018int\u2019

    callback.c:147: attention : format \u2018%s\u2019 expects type \u2018char *\u2019, but argument 4 has type \u2018int\u2019

    callback.c:147: attention : format \u2018%s\u2019 expects type \u2018char *\u2019, but argument 5 has type \u2018int\u2019

    callback.c: In function \u2018win_matrix\u2019:

    callback.c:169: attention : passing argument 1 of \u2018matrix_read\u2019 discards qualifiers from pointer target type

    callback.c: In function \u2018win_interpolation\u2019:

    callback.c:205: attention : passing argument 1 of \u2018pol_read_series\u2019 discards qualifiers from pointer target type

    callback.c:205: attention : passing argument 2 of \u2018pol_read_series\u2019 from incompatible pointer type

    callback.c:205: attention : assignment makes integer from pointer without a cast

    callback.c:229: attention : assignment makes pointer from integer without a cast

    callback.c: In function \u2018cb_save\u2019:

    callback.c:395: attention : passing argument 1 of \u2018cb_save_file\u2019 discards qualifiers from pointer target type

    callback.c:395: attention : passing argument 2 of \u2018cb_save_file\u2019 discards qualifiers from pointer target type

    win.c: In function \u2018make_elements\u2019:

    win.c:88: attention : passing argument 1 of \u2018gtk_misc_set_alignment\u2019 from incompatible pointer type

    win.c:97: attention : passing argument 1 of \u2018gtk_scrolled_window_add_with_viewport\u2019 from incompatible pointer type

    win.c:98: attention : passing argument 1 of \u2018gtk_scrolled_window_set_policy\u2019 from incompatible pointer type

    win.c: In function \u2018table_attach\u2019:

    win.c:145: attention : passing argument 1 of \u2018gtk_table_attach\u2019 from incompatible pointer type

Discussions similaires

  1. [WD12] Erreur allocation mémoire
    Par Christophe Charron dans le forum WinDev
    Réponses: 12
    Dernier message: 08/10/2012, 08h55
  2. Erreur d'allocation mémoire
    Par Sagee dans le forum Débuter
    Réponses: 5
    Dernier message: 18/04/2012, 12h03
  3. C++, erreur d'allocation dynamique de mémoire
    Par YuGiOhJCJ dans le forum C++
    Réponses: 8
    Dernier message: 20/02/2009, 11h51
  4. erreur d'allocation de mémoire?
    Par ulnar dans le forum C
    Réponses: 17
    Dernier message: 18/05/2007, 09h36
  5. Erreur Allocation mémoire
    Par Thordax dans le forum C++
    Réponses: 10
    Dernier message: 05/04/2006, 21h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo