c - Solve warning: passing 'const void *' to parameter of type 'AV *' -


compiling xs-module including libmba cannot solve warning beginners level experience in c:

helmut@helmuts-macbook-air:~/github/lcs-xs$ make "/users/helmut/perl5/perlbrew/perls/perl-5.18.2/bin/perl"    "/users/helmut/perl5/perlbrew/perls/perl-5.18.2/lib/5.18.2/extutils/xsubpp"  -typemap "/users/helmut/perl5/perlbrew/perls/perl-  5.18.2/lib/5.18.2/extutils/typemap"  xs.xs > xs.xsc && mv xs.xsc xs.c cc -c  -i. -fno-common -dperl_darwin -fno-strict-aliasing -pipe - fstack-protector -i/usr/local/include -i/opt/local/include -o3   - dversion=\"0.01\" -dxs_version=\"0.01\"  "- i/users/helmut/perl5/perlbrew/perls/perl-5.18.2/lib/5.18.2/darwin- 2level/core"   xs.c   xs.xs:55:26: warning: passing 'const void *' parameter of type 'av  *' (aka 'struct av *') discards qualifiers     [-wincompatible-pointer-types-discards-qualifiers]        sv *line = *av_fetch(a, idx, 0);                             ^ /users/helmut/perl5/perlbrew/perls/perl-5.18.2/lib/5.18.2/darwin- 2level/core/embed.h:51:46: note: expanded macro 'av_fetch' #define av_fetch(a,b,c)         perl_av_fetch(athx_ a,b,c)                                                     ^ /users/helmut/perl5/perlbrew/perls/perl-5.18.2/lib/5.18.2/darwin- 2level/core/proto.h:178:44: note: passing argument   parameter 'av' here     perl_callconv sv**      perl_av_fetch(pthx_ av *av, i32 key, i32 lval)                                                    ^ 1 warning generated. 

the compiled module working fine. there way code without warning?

the relevant parts in lcs/xs.xs:

#include "extern.h" #include "perl.h" #include "xsub.h"  #include "ppport.h"  #include <string.h>  #include <mba/diff.h> #include <mba/diff.c>  /* snipped */  inline static const void *  _av_idx(const void *a, int idx, void *context) {    //av *av = a;    sv *line = *av_fetch(a, idx, 0);    strlen klen;    char *key = svpvbyte(line, klen);    //printf("key: %s\n",key);    return key; }  /* snipped */  void lcs_lcs(obj, s1, s2)   sv *obj   av * s1   av * s2    preinit:     struct ctx *ctx = (struct ctx *)svivx(svrv(obj));    ppcode:     int d, sn, i;     struct varray *ses = varray_new(sizeof(struct diff_edit), null);      iv n;     iv m;     n = av_top_index(s1);     m = av_top_index(s2);      // call libmba::diff()     d = diff(s1, 0, n, s2, 0, m, &_av_idx, &_cmp_str,  null, 0, ses, &sn, null); 

the part of mba/diff.h

typedef const void *(*idx_fn)(const void *s, int idx, void *context); 

and in mba/diff.c:

int diff(const void *a, int aoff, int n,     const void *b, int boff, int m,     idx_fn idx, cmp_fn cmp, void *context, int dmax,     struct varray *ses, int *sn,     struct varray *buf) { 

is there practice solve warning without changing source of libmba?

solved:

inline static const void *  _av_idx(const void *a, int idx, void *context) {     sv *line = *av_fetch((av *)a, idx, 0);     //                   ^^^^^^     strlen klen;     char *key = svpvbyte(line, klen);      return key; } 

well ... in _av_idx promising not change contents of first parameter

inline static const void *_av_idx(const void *a, int idx, void *context) //                                ^^^^^ 

but proceed send parameter function (av_fetch(a, idx, 0)) not promise not change it. makes promise little strange.

just remove promise ...

inline static const void *_av_idx(void *a, int idx, void *context) //                       no const ^^^^^^^ 

edit

or copy argument local variable , pass that

inline static const void *  _av_idx(const void *a, int idx, void *context) {    av *a_copy;    deep_copy(a_copy, a);    if (a_copy != null) {        sv *line = *av_fetch(a_copy, idx, 0);        free(a_copy);    } else {        /* error */    }    strlen klen;    char *key = svpvbyte(line, klen);    //printf("key: %s\n",key);    return key; } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -