From: Nicholas Clark Date: Tue, 5 Apr 2005 21:30:21 +0000 (+0000) Subject: Add casting to allow g++ (3.3.5) to compile the core code. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=07409e015252427f5ec1d8889bbfb78cf39d061d;p=p5sagit%2Fp5-mst-13.2.git Add casting to allow g++ (3.3.5) to compile the core code. A C++ compiler produces lots of warnings that are probably valid concerns to investigate. p4raw-id: //depot/perl@24170 --- diff --git a/doio.c b/doio.c index 26079cb..47eb516 100644 --- a/doio.c +++ b/doio.c @@ -1830,16 +1830,17 @@ nothing in the core. if (sp - mark > 2) { #if defined(I_UTIME) || defined(VMS) struct utimbuf utbuf; + struct utimbuf *utbufp = &utbuf; #else struct { Time_t actime; Time_t modtime; } utbuf; + void *utbufp = &utbuf; #endif SV* accessed = *++mark; SV* modified = *++mark; - void * utbufp = &utbuf; /* Be like C, and if both times are undefined, let the C * library figure out what to do. This usually means diff --git a/ext/B/B.xs b/ext/B/B.xs index 107d3a6..32556ec 100644 --- a/ext/B/B.xs +++ b/ext/B/B.xs @@ -1653,7 +1653,7 @@ CvXSUBANY(cv) B::CV cv CODE: ST(0) = CvCONST(cv) ? - make_sv_object(aTHX_ sv_newmortal(),CvXSUBANY(cv).any_ptr) : + make_sv_object(aTHX_ sv_newmortal(),(SV *)CvXSUBANY(cv).any_ptr) : sv_2mortal(newSViv(CvXSUBANY(cv).any_iv)); MODULE = B PACKAGE = B::CV diff --git a/ext/Cwd/Cwd.xs b/ext/Cwd/Cwd.xs index 97c583f..e7323ab 100644 --- a/ext/Cwd/Cwd.xs +++ b/ext/Cwd/Cwd.xs @@ -417,7 +417,7 @@ PPCODE: char *path; char buf[MAXPATHLEN]; - path = pathsv ? SvPV_nolen(pathsv) : "."; + path = pathsv ? SvPV_nolen(pathsv) : (char *)"."; if (bsd_realpath(path, buf)) { sv_setpvn(TARG, buf, strlen(buf)); diff --git a/ext/Devel/DProf/DProf.xs b/ext/Devel/DProf/DProf.xs index 8202142..10d4172 100644 --- a/ext/Devel/DProf/DProf.xs +++ b/ext/Devel/DProf/DProf.xs @@ -373,7 +373,7 @@ prof_mark(pTHX_ opcode ptype) gv = CvGV(cv); pname = ((GvSTASH(gv) && HvNAME(GvSTASH(gv))) ? HvNAME(GvSTASH(gv)) - : "(null)"); + : (char *) "(null)"); gname = GvNAME(gv); set_cv_key(aTHX_ cv, pname, gname); diff --git a/gv.c b/gv.c index f85b5fd..16cdd48 100644 --- a/gv.c +++ b/gv.c @@ -122,7 +122,9 @@ Perl_gv_init(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, int multi) GvGP(gv) = gp_ref(gp); GvSV(gv) = NEWSV(72,0); GvLINE(gv) = CopLINE(PL_curcop); - GvFILE(gv) = CopFILE(PL_curcop) ? CopFILE(PL_curcop) : ""; + /* XXX Ideally this cast would be replaced with a change to const char* + in the struct. */ + GvFILE(gv) = CopFILE(PL_curcop) ? CopFILE(PL_curcop) : (char *) ""; GvCVGEN(gv) = 0; GvEGV(gv) = gv; sv_magic((SV*)gv, (SV*)gv, PERL_MAGIC_glob, Nullch, 0); diff --git a/perl.c b/perl.c index 9c859a4..6d948e7 100644 --- a/perl.c +++ b/perl.c @@ -186,7 +186,7 @@ perl_alloc(void) my_perl = (PerlInterpreter*)PerlMem_malloc(sizeof(PerlInterpreter)); S_init_tls_and_interp(my_perl); - return ZeroD(my_perl, 1, PerlInterpreter); + return (PerlInterpreter *) ZeroD(my_perl, 1, PerlInterpreter); } #endif /* PERL_IMPLICIT_SYS */ diff --git a/perl.h b/perl.h index fe62755..410846e 100644 --- a/perl.h +++ b/perl.h @@ -4273,7 +4273,7 @@ typedef struct am_table_short AMTS; new_chunk_size = (chunk_size); \ if (new_chunk_size > PL_nice_chunk_size) { \ if (PL_nice_chunk) Safefree(PL_nice_chunk); \ - PL_nice_chunk = new_chunk; \ + PL_nice_chunk = (char *) new_chunk; \ PL_nice_chunk_size = new_chunk_size; \ } else { \ Safefree(chunk); \ diff --git a/pp_pack.c b/pp_pack.c index 34dffb7..00a7da2 100644 --- a/pp_pack.c +++ b/pp_pack.c @@ -197,8 +197,8 @@ S_mul128(pTHX_ SV *sv, U8 m) # define DO_BO_UNPACK(var, type) # define DO_BO_PACK(var, type) -# define DO_BO_UNPACK_PTR(var, type, pre_cast) -# define DO_BO_PACK_PTR(var, type, pre_cast) +# define DO_BO_UNPACK_PTR(var, type, pre_cast, post_cast) +# define DO_BO_PACK_PTR(var, type, pre_cast, post_cast) # define DO_BO_UNPACK_N(var, type) # define DO_BO_PACK_N(var, type) # define DO_BO_UNPACK_P(var) @@ -229,28 +229,28 @@ S_mul128(pTHX_ SV *sv, U8 m) } \ } STMT_END -# define DO_BO_UNPACK_PTR(var, type, pre_cast) \ +# define DO_BO_UNPACK_PTR(var, type, pre_cast, post_cast) \ STMT_START { \ switch (TYPE_ENDIANNESS(datumtype)) { \ case TYPE_IS_BIG_ENDIAN: \ - var = (void *) my_betoh ## type ((pre_cast) var); \ + var = (post_cast*) my_betoh ## type ((pre_cast) var); \ break; \ case TYPE_IS_LITTLE_ENDIAN: \ - var = (void *) my_letoh ## type ((pre_cast) var); \ + var = (post_cast *) my_letoh ## type ((pre_cast) var); \ break; \ default: \ break; \ } \ } STMT_END -# define DO_BO_PACK_PTR(var, type, pre_cast) \ +# define DO_BO_PACK_PTR(var, type, pre_cast, post_cast) \ STMT_START { \ switch (TYPE_ENDIANNESS(datumtype)) { \ case TYPE_IS_BIG_ENDIAN: \ - var = (void *) my_htobe ## type ((pre_cast) var); \ + var = (post_cast *) my_htobe ## type ((pre_cast) var); \ break; \ case TYPE_IS_LITTLE_ENDIAN: \ - var = (void *) my_htole ## type ((pre_cast) var); \ + var = (post_cast *) my_htole ## type ((pre_cast) var); \ break; \ default: \ break; \ @@ -274,11 +274,15 @@ S_mul128(pTHX_ SV *sv, U8 m) } STMT_END # if PTRSIZE == INTSIZE -# define DO_BO_UNPACK_P(var) DO_BO_UNPACK_PTR(var, i, int) -# define DO_BO_PACK_P(var) DO_BO_PACK_PTR(var, i, int) +# define DO_BO_UNPACK_P(var) DO_BO_UNPACK_PTR(var, i, int, void) +# define DO_BO_PACK_P(var) DO_BO_PACK_PTR(var, i, int, void) +# define DO_BO_UNPACK_PC(var) DO_BO_UNPACK_PTR(var, i, int, char) +# define DO_BO_PACK_PC(var) DO_BO_PACK_PTR(var, i, int, char) # elif PTRSIZE == LONGSIZE -# define DO_BO_UNPACK_P(var) DO_BO_UNPACK_PTR(var, l, long) -# define DO_BO_PACK_P(var) DO_BO_PACK_PTR(var, l, long) +# define DO_BO_UNPACK_P(var) DO_BO_UNPACK_PTR(var, l, long, void) +# define DO_BO_PACK_P(var) DO_BO_PACK_PTR(var, l, long, void) +# define DO_BO_UNPACK_PC(var) DO_BO_UNPACK_PTR(var, l, long, char) +# define DO_BO_PACK_PC(var) DO_BO_PACK_PTR(var, l, long, char) # else # define DO_BO_UNPACK_P(var) BO_CANT_DOIT(unpack, pointer) # define DO_BO_PACK_P(var) BO_CANT_DOIT(pack, pointer) @@ -1078,7 +1082,7 @@ need_utf8(const char *pat, const char *patend) while (pat < patend) { if (pat[0] == '#') { pat++; - pat = memchr(pat, '\n', patend-pat); + pat = (char *) memchr(pat, '\n', patend-pat); if (!pat) return FALSE; } else if (pat[0] == 'U') { if (first || pat[1] == '0') return TRUE; @@ -1093,7 +1097,7 @@ first_symbol(const char *pat, const char *patend) { while (pat < patend) { if (pat[0] != '#') return pat[0]; pat++; - pat = memchr(pat, '\n', patend-pat); + pat = (char *) memchr(pat, '\n', patend-pat); if (!pat) return 0; pat++; } @@ -1936,7 +1940,7 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, char *s, char *strbeg, char *strend, char while (len-- > 0) { char *aptr; SHIFT_VAR(utf8, s, strend, aptr, datumtype); - DO_BO_UNPACK_P(aptr); + DO_BO_UNPACK_PC(aptr); /* newSVpv generates undef if aptr is NULL */ PUSHs(sv_2mortal(newSVpv(aptr, 0))); } @@ -1991,7 +1995,7 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, char *s, char *strbeg, char *strend, char if (sizeof(char*) <= strend - s) { char *aptr; SHIFT_VAR(utf8, s, strend, aptr, datumtype); - DO_BO_UNPACK_P(aptr); + DO_BO_UNPACK_PC(aptr); /* newSVpvn generates undef if aptr is NULL */ PUSHs(sv_2mortal(newSVpvn(aptr, len))); } @@ -3492,7 +3496,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist ) else aptr = SvPV_force_flags(fromstr, n_a, 0); } - DO_BO_PACK_P(aptr); + DO_BO_PACK_PC(aptr); PUSH_VAR(utf8, cur, aptr); } break; diff --git a/scope.c b/scope.c index 315fdc0..50f73c1 100644 --- a/scope.c +++ b/scope.c @@ -287,7 +287,9 @@ Perl_save_gp(pTHX_ GV *gv, I32 empty) GvGP(gv) = gp_ref(gp); GvSV(gv) = NEWSV(72,0); GvLINE(gv) = CopLINE(PL_curcop); - GvFILE(gv) = CopFILE(PL_curcop) ? CopFILE(PL_curcop) : ""; + /* XXX Ideally this cast would be replaced with a change to const char* + in the struct. */ + GvFILE(gv) = CopFILE(PL_curcop) ? CopFILE(PL_curcop) : (char *) ""; GvEGV(gv) = gv; } else { diff --git a/sv.c b/sv.c index 97e76d2..df7e7fa 100644 --- a/sv.c +++ b/sv.c @@ -8427,9 +8427,11 @@ Returns a string describing what the SV is a reference to. char * Perl_sv_reftype(pTHX_ const SV *sv, int ob) { + /* The fact that I don't need to downcast to char * everywhere, only in ?: + inside return suggests a const propagation bug in g++. */ if (ob && SvOBJECT(sv)) { char *name = HvNAME(SvSTASH(sv)); - return name ? name : "__ANON__"; + return name ? name : (char *) "__ANON__"; } else { switch (SvTYPE(sv)) { @@ -8449,11 +8451,11 @@ Perl_sv_reftype(pTHX_ const SV *sv, int ob) else return "SCALAR"; - case SVt_PVLV: return SvROK(sv) ? "REF" + case SVt_PVLV: return (char *) (SvROK(sv) ? "REF" /* tied lvalues should appear to be * scalars for backwards compatitbility */ : (LvTYPE(sv) == 't' || LvTYPE(sv) == 'T') - ? "SCALAR" : "LVALUE"; + ? "SCALAR" : "LVALUE"); case SVt_PVAV: return "ARRAY"; case SVt_PVHV: return "HASH"; case SVt_PVCV: return "CODE"; diff --git a/toke.c b/toke.c index 1189b29..912e224 100644 --- a/toke.c +++ b/toke.c @@ -10519,7 +10519,7 @@ S_scan_formline(pTHX_ register char *s) } } if (PL_in_eval && !PL_rsfp) { - eol = memchr(s,'\n',PL_bufend-s); + eol = (char *) memchr(s,'\n',PL_bufend-s); if (!eol++) eol = PL_bufend; } diff --git a/util.c b/util.c index 010507d..53e2e7b 100644 --- a/util.c +++ b/util.c @@ -796,10 +796,10 @@ Perl_savepvn(pTHX_ const char *pv, register I32 len) if (pv) { /* might not be null terminated */ newaddr[len] = '\0'; - return CopyD(pv,newaddr,len,char); + return (char *) CopyD(pv,newaddr,len,char); } else { - return ZeroD(newaddr,len+1,char); + return (char *) ZeroD(newaddr,len+1,char); } } @@ -845,7 +845,7 @@ Perl_savesvpv(pTHX_ SV *sv) ++len; New(903,newaddr,len,char); - return CopyD(pv,newaddr,len,char); + return (char *) CopyD(pv,newaddr,len,char); } diff --git a/x2p/walk.c b/x2p/walk.c index 63ceb47..de1743f 100644 --- a/x2p/walk.c +++ b/x2p/walk.c @@ -1,7 +1,7 @@ /* $RCSfile: walk.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:31 $ * * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1997, 1998, 1999, - * 2000, 2001, 2002, by Larry Wall and others + * 2000, 2001, 2002, 2005 by Larry Wall and others * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. @@ -858,7 +858,7 @@ sub Pick {\n\ } *d = '\0'; str_set(tmp2str,tokenbuf); - s = gsub ? "/g" : "/"; + s = (char *) (gsub ? "/g" : "/"); } else { tmp2str=walk(1,level,ops[node+2].ival,&numarg,P_MIN); @@ -866,7 +866,7 @@ sub Pick {\n\ str_scat(tmp3str,tmp2str); str_cat(tmp3str,").'\"') =~ s/&/\\$&/g, "); str_set(tmp2str,"eval $s_"); - s = gsub ? "/ge" : "/e"; + s = (char *) (gsub ? "/ge" : "/e"); i++; } str_cat(tmp2str,s);