# New Ticket Created by NotFound # Please include the string: [perl #55590] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=55590 >
This patch solves the casting problems that breaks or generates warnings in src/io/io_unix.c allowing clean compiling with C or C++, with or without --optimize. Also drops the const in argv in several main and main-alike functions, that can generate warnings or force const castings. And also changes lib/Parrot/Pmc2c/PMCEmitter.pm to avoid generating an empty class init block and to add a block around a mro initialization that declares a variable. -- Salu2
Index: src/pdb.c =================================================================== --- src/pdb.c (revisión: 28225) +++ src/pdb.c (copia de trabajo) @@ -111,7 +111,7 @@ #include "parrot/embed.h" static void PDB_printwelcome(void); -static void PDB_run_code(Parrot_Interp interp, int argc, const char *argv[]); +static void PDB_run_code(Parrot_Interp interp, int argc, char *argv[]); /* @@ -127,7 +127,7 @@ extern void imcc_init(Parrot_Interp interp); int -main(int argc, const char *argv[]) +main(int argc, char *argv[]) { Parrot_Interp debugger = Parrot_new(NULL); Parrot_Interp interp = Parrot_new(debugger); @@ -214,7 +214,7 @@ */ static void -PDB_run_code(Parrot_Interp interp, int argc, const char *argv[]) +PDB_run_code(Parrot_Interp interp, int argc, char *argv[]) { Parrot_exception exp; Index: src/embed.c =================================================================== --- src/embed.c (revisión: 28225) +++ src/embed.c (copia de trabajo) @@ -49,7 +49,7 @@ __attribute__nonnull__(1); PARROT_CANNOT_RETURN_NULL -static PMC* setup_argv(PARROT_INTERP, int argc, ARGIN(const char **argv)) +static PMC* setup_argv(PARROT_INTERP, int argc, ARGIN(char **argv)) __attribute__nonnull__(1) __attribute__nonnull__(3); @@ -563,7 +563,7 @@ PARROT_CANNOT_RETURN_NULL static PMC* -setup_argv(PARROT_INTERP, int argc, ARGIN(const char **argv)) +setup_argv(PARROT_INTERP, int argc, ARGIN(char **argv)) { INTVAL i; PMC *userargv; @@ -860,7 +860,7 @@ PARROT_API void -Parrot_runcode(PARROT_INTERP, int argc, ARGIN(const char **argv)) +Parrot_runcode(PARROT_INTERP, int argc, ARGIN(char **argv)) { PMC *userargv, *main_sub; Index: src/main.c =================================================================== --- src/main.c (revisión: 28225) +++ src/main.c (copia de trabajo) @@ -36,7 +36,7 @@ */ int -main(int argc, const char * argv[]) +main(int argc, char * argv[]) { const char *sourcefile; Interp *interp; Index: src/io/io_unix.c =================================================================== --- src/io/io_unix.c (revisión: 28225) +++ src/io/io_unix.c (copia de trabajo) @@ -825,12 +825,13 @@ PIO_unix_connect(SHIM_INTERP, SHIM(ParrotIOLayer *layer), ARGMOD(ParrotIO *io), ARGIN_NULLOK(STRING *r)) { + struct sockaddr_in * saddr = & io->remote; if (r) { memcpy(&io->remote, PObj_bufstart(r), sizeof (struct sockaddr_in)); } AGAIN: - if ((connect(io->fd, (const struct sockaddr_in *)&io->remote, - sizeof (struct sockaddr_in))) != 0) { + if ((connect(io->fd, (struct sockaddr *) saddr, + sizeof (struct sockaddr_in))) != 0) { switch (errno) { case EINTR: goto AGAIN; @@ -860,12 +861,13 @@ PIO_unix_bind(SHIM_INTERP, SHIM(ParrotIOLayer *layer), ARGMOD(ParrotIO *io), ARGMOD(STRING *l)) { + struct sockaddr_in * saddr = & io->local; if (!l) return -1; memcpy(&io->local, PObj_bufstart(l), sizeof (struct sockaddr_in)); - if ((bind(io->fd, (const struct sockaddr_in *)&io->local, + if ((bind(io->fd, (struct sockaddr *) saddr, sizeof (struct sockaddr_in))) == -1) { return -1; } @@ -912,8 +914,9 @@ ParrotIO * const newio = PIO_new(interp, PIO_F_SOCKET, 0, PIO_F_READ|PIO_F_WRITE); Parrot_Socklen_t addrlen = sizeof (struct sockaddr_in); + struct sockaddr_in * saddr = & newio->remote; const int newsock = accept(io->fd, - (struct sockaddr_in *)&newio->remote, &addrlen); + (struct sockaddr *)saddr, &addrlen); if (newsock == -1) { mem_sys_free(newio); Index: tools/dev/pbc_to_exe_gen.pl =================================================================== --- tools/dev/pbc_to_exe_gen.pl (revisión: 28225) +++ tools/dev/pbc_to_exe_gen.pl (copia de trabajo) @@ -194,7 +194,7 @@ .sub 'body' $S0 = <<'END_BODY' -int main(int argc, const char *argv[]) +int main(int argc, char *argv[]) { PackFile *pf; Parrot_Interp interp; Index: lib/Parrot/Pmc2c/PMCEmitter.pm =================================================================== --- lib/Parrot/Pmc2c/PMCEmitter.pm (revisión: 28225) +++ lib/Parrot/Pmc2c/PMCEmitter.pm (copia de trabajo) @@ -545,13 +545,14 @@ my $provides = join( " ", keys( %{ $self->{flags}{provides} } ) ); my $class_init_code = ""; - $class_init_code = $self->get_method('class_init')->body - if $self->has_method('class_init'); + if ($self->has_method('class_init')) { + $class_init_code = $self->get_method('class_init')->body; - $class_init_code =~ s/INTERP/interp/g; + $class_init_code =~ s/INTERP/interp/g; - # fix indenting - $class_init_code =~ s/^/ /mg; + # fix indenting + $class_init_code =~ s/^/ /mg; + } my %extra_vt; $extra_vt{ro} = $self->{ro} if $self->{ro}; @@ -675,23 +676,26 @@ } $cout .= <<"EOC"; - PMC *mro = pmc_new(interp, enum_class_ResizableStringArray); - VTABLE * const vt_clone = interp->vtables[entry]; + { + PMC *mro = pmc_new(interp, enum_class_ResizableStringArray); + VTABLE * const vt_clone = interp->vtables[entry]; - vt_clone->mro = mro; + vt_clone->mro = mro; - if (vt_clone->ro_variant_vtable) - vt_clone->ro_variant_vtable->mro = mro; + if (vt_clone->ro_variant_vtable) + vt_clone->ro_variant_vtable->mro = mro; EOC for my $isa ($classname, @isa) { $cout .= <<"EOC"; - VTABLE_push_string(interp, mro, CONST_STRING(interp, "$isa")); + VTABLE_push_string(interp, mro, CONST_STRING(interp, "$isa")); EOC } $cout .= <<"EOC"; + } + /* setup MRO and _namespace */ Parrot_create_mro(interp, entry); EOC @@ -725,10 +729,8 @@ } # include any class specific init code from the .pmc file - $cout .= <<"EOC"; + $cout .= <<"EOC" if $class_init_code; /* class_init */ -EOC - $cout .= <<"EOC" if $class_init_code; { $class_init_code } Index: include/parrot/embed.h =================================================================== --- include/parrot/embed.h (revisión: 28225) +++ include/parrot/embed.h (copia de trabajo) @@ -52,7 +52,7 @@ PARROT_API void Parrot_setup_opt(Parrot_Interp, int n, char *argv); -PARROT_API void Parrot_runcode(Parrot_Interp, int argc, const char **argv); +PARROT_API void Parrot_runcode(Parrot_Interp, int argc, char **argv); PARROT_API void Parrot_destroy(Parrot_Interp); Index: include/parrot/imcc.h =================================================================== --- include/parrot/imcc.h (revisión: 28225) +++ include/parrot/imcc.h (copia de trabajo) @@ -7,8 +7,8 @@ #define PARROT_IMCC_H_GUARD PARROT_API void imcc_initialize(PARROT_INTERP); -PARROT_API const char * parseflags(PARROT_INTERP, int *argc, const char **argv[]); -PARROT_API int imcc_run(PARROT_INTERP, const char *sourcefile, int argc, const char **argv); +PARROT_API const char * parseflags(PARROT_INTERP, int *argc, char **argv[]); +PARROT_API int imcc_run(PARROT_INTERP, const char *sourcefile, int argc, char **argv); #endif /* PARROT_IMCC_H_GUARD */ Index: compilers/imcc/main.c =================================================================== --- compilers/imcc/main.c (revisión: 28225) +++ compilers/imcc/main.c (copia de trabajo) @@ -79,7 +79,7 @@ int obj_file, ARGIN(const char *output_file), int argc, - ARGIN(const char **argv)) + ARGIN(char **argv)) __attribute__nonnull__(1) __attribute__nonnull__(3) __attribute__nonnull__(5); @@ -329,7 +329,7 @@ PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL const char * -parseflags(PARROT_INTERP, int *argc, const char **argv[]) +parseflags(PARROT_INTERP, int *argc, char **argv[]) { struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; int status; @@ -759,7 +759,7 @@ static void imcc_run_pbc(PARROT_INTERP, int obj_file, ARGIN(const char *output_file), - int argc, ARGIN(const char **argv)) + int argc, ARGIN(char **argv)) { if (IMCC_INFO(interp)->imcc_warn) PARROT_WARNINGS_on(interp, PARROT_WARNINGS_ALL_FLAG); @@ -990,7 +990,7 @@ int imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), int argc, - ARGIN(const char **argv)) + ARGIN(char **argv)) { int obj_file; yyscan_t yyscanner = IMCC_INFO(interp)->yyscanner; Index: examples/c/test_main.c =================================================================== --- examples/c/test_main.c (revisión: 28225) +++ examples/c/test_main.c (copia de trabajo) @@ -28,7 +28,7 @@ #define setopt(flag) Parrot_setflag(interp, (flag), (*argv)[0]+2); #define unsetopt(flag) Parrot_setflag(interp, (flag), 0) -char *parseflags(Parrot_Interp interp, int *argc, char **argv[]); +static char *parseflags(Parrot_Interp interp, int *argc, char **argv[]); #define OPT_GC_DEBUG 128 #define OPT_DESTROY_FLAG 129 @@ -105,7 +105,7 @@ */ -char * +static char * parseflags(Parrot_Interp interp, int *argc, char **argv[]) { struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;