diff --git a/NEWS b/NEWS index a302db0f6b..8426a573f3 100644 --- a/NEWS +++ b/NEWS @@ -60,6 +60,8 @@ version 1.0. 1.0.3 ----- +- Fixed improper handling of string arguments in Fortran bindings + for MPI-IO functionality - Fixed segmentation fault with 64 bit applications on Solaris when using the shared memory transports. - Fixed MPI_COMM_SELF attributes to free properly at the beginning of diff --git a/ompi/mpi/f77/file_delete_f.c b/ompi/mpi/f77/file_delete_f.c index 35e38dea9d..6b3cb3d6de 100644 --- a/ompi/mpi/f77/file_delete_f.c +++ b/ompi/mpi/f77/file_delete_f.c @@ -19,6 +19,8 @@ #include "ompi_config.h" #include "ompi/mpi/f77/bindings.h" +#include "ompi/mpi/f77/strings.h" +#include "ompi/file/file.h" #if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILE_LAYER #pragma weak PMPI_FILE_DELETE = mpi_file_delete_f @@ -31,8 +33,8 @@ OMPI_GENERATE_F77_BINDINGS (PMPI_FILE_DELETE, pmpi_file_delete_, pmpi_file_delete__, pmpi_file_delete_f, - (char *filename, MPI_Fint *info, MPI_Fint *ierr), - (filename, info, ierr) ) + (char *filename, MPI_Fint *info, MPI_Fint *ierr, int filename_len), + (filename, info, ierr, filename_len) ) #endif #if OMPI_HAVE_WEAK_SYMBOLS @@ -48,8 +50,8 @@ OMPI_GENERATE_F77_BINDINGS (MPI_FILE_DELETE, mpi_file_delete_, mpi_file_delete__, mpi_file_delete_f, - (char *filename, MPI_Fint *info, MPI_Fint *ierr), - (filename, info, ierr) ) + (char *filename, MPI_Fint *info, MPI_Fint *ierr, int filename_len), + (filename, info, ierr, filename_len) ) #endif @@ -57,11 +59,23 @@ OMPI_GENERATE_F77_BINDINGS (MPI_FILE_DELETE, #include "ompi/mpi/f77/profile/defines.h" #endif -void mpi_file_delete_f(char *filename, MPI_Fint *info, MPI_Fint *ierr) +void mpi_file_delete_f(char *filename, MPI_Fint *info, MPI_Fint *ierr, int filename_len) { MPI_Info c_info; + char *c_filename; + int c_err, ret; c_info = MPI_Info_f2c(*info); + + /* Convert the fortran string */ + if (OMPI_SUCCESS != (ret = ompi_fortran_string_f2c(filename, filename_len, + &c_filename))) { + c_err = OMPI_ERRHANDLER_INVOKE(MPI_FILE_NULL, ret, "MPI_FILE_DELETE"); + *ierr = OMPI_INT_2_FINT(c_err); + return; + } *ierr = OMPI_INT_2_FINT(MPI_File_delete(filename, c_info)); + + free(c_filename); } diff --git a/ompi/mpi/f77/file_get_view_f.c b/ompi/mpi/f77/file_get_view_f.c index a7e2521a7b..2f69a36f74 100644 --- a/ompi/mpi/f77/file_get_view_f.c +++ b/ompi/mpi/f77/file_get_view_f.c @@ -19,6 +19,8 @@ #include "ompi_config.h" #include "ompi/mpi/f77/bindings.h" +#include "ompi/mpi/f77/strings.h" +#include "ompi/file/file.h" #if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILE_LAYER #pragma weak PMPI_FILE_GET_VIEW = mpi_file_get_view_f @@ -31,8 +33,8 @@ OMPI_GENERATE_F77_BINDINGS (PMPI_FILE_GET_VIEW, pmpi_file_get_view_, pmpi_file_get_view__, pmpi_file_get_view_f, - (MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, char *datarep, MPI_Fint *ierr), - (fh, disp, etype, filetype, datarep, ierr) ) + (MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, char *datarep, MPI_Fint *ierr, int datarep_len), + (fh, disp, etype, filetype, datarep, ierr, datarep_len) ) #endif #if OMPI_HAVE_WEAK_SYMBOLS @@ -48,8 +50,8 @@ OMPI_GENERATE_F77_BINDINGS (MPI_FILE_GET_VIEW, mpi_file_get_view_, mpi_file_get_view__, mpi_file_get_view_f, - (MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, char *datarep, MPI_Fint *ierr), - (fh, disp, etype, filetype, datarep, ierr) ) + (MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, char *datarep, MPI_Fint *ierr, int datarep_len), + (fh, disp, etype, filetype, datarep, ierr, datarep_len) ) #endif @@ -59,17 +61,19 @@ OMPI_GENERATE_F77_BINDINGS (MPI_FILE_GET_VIEW, void mpi_file_get_view_f(MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, - char *datarep, MPI_Fint *ierr) + char *datarep, MPI_Fint *ierr, int datarep_len) { MPI_File c_fh = MPI_File_f2c(*fh); MPI_Datatype c_etype, c_filetype; MPI_Offset c_disp; + char c_datarep[MPI_MAX_DATAREP_STRING]; *ierr = OMPI_INT_2_FINT(MPI_File_get_view(c_fh, &c_disp, &c_etype, - &c_filetype, datarep)); + &c_filetype, c_datarep)); if (MPI_SUCCESS == OMPI_FINT_2_INT(*ierr)) { *disp = (MPI_Fint) c_disp; *etype = MPI_Type_c2f(c_etype); *filetype = MPI_Type_c2f(c_filetype); + ompi_fortran_string_c2f(c_datarep, datarep, MPI_MAX_DATAREP_STRING); } } diff --git a/ompi/mpi/f77/file_open_f.c b/ompi/mpi/f77/file_open_f.c index 3d82f2080c..0bbd36fc9c 100644 --- a/ompi/mpi/f77/file_open_f.c +++ b/ompi/mpi/f77/file_open_f.c @@ -19,6 +19,8 @@ #include "ompi_config.h" #include "ompi/mpi/f77/bindings.h" +#include "ompi/mpi/f77/strings.h" +#include "ompi/file/file.h" #if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILE_LAYER #pragma weak PMPI_FILE_OPEN = mpi_file_open_f @@ -31,8 +33,8 @@ OMPI_GENERATE_F77_BINDINGS (PMPI_FILE_OPEN, pmpi_file_open_, pmpi_file_open__, pmpi_file_open_f, - (MPI_Fint *comm, char *filename, MPI_Fint *amode, MPI_Fint *info, MPI_Fint *fh, MPI_Fint *ierr), - (comm, filename, amode, info, fh, ierr) ) + (MPI_Fint *comm, char *filename, MPI_Fint *amode, MPI_Fint *info, MPI_Fint *fh, MPI_Fint *ierr, int name_len), + (comm, filename, amode, info, fh, ierr, name_len) ) #endif #if OMPI_HAVE_WEAK_SYMBOLS @@ -48,8 +50,8 @@ OMPI_GENERATE_F77_BINDINGS (MPI_FILE_OPEN, mpi_file_open_, mpi_file_open__, mpi_file_open_f, - (MPI_Fint *comm, char *filename, MPI_Fint *amode, MPI_Fint *info, MPI_Fint *fh, MPI_Fint *ierr), - (comm, filename, amode, info, fh, ierr) ) + (MPI_Fint *comm, char *filename, MPI_Fint *amode, MPI_Fint *info, MPI_Fint *fh, MPI_Fint *ierr, int name_len), + (comm, filename, amode, info, fh, ierr, name_len) ) #endif @@ -58,16 +60,28 @@ OMPI_GENERATE_F77_BINDINGS (MPI_FILE_OPEN, #endif void mpi_file_open_f(MPI_Fint *comm, char *filename, MPI_Fint *amode, - MPI_Fint *info, MPI_Fint *fh, MPI_Fint *ierr) + MPI_Fint *info, MPI_Fint *fh, MPI_Fint *ierr, int name_len) { MPI_Comm c_comm = MPI_Comm_f2c(*comm); MPI_Info c_info = MPI_Info_f2c(*info); MPI_File c_fh; + char *c_filename; + int c_err, ret; - *ierr = OMPI_INT_2_FINT(MPI_File_open(c_comm, filename, + /* Convert the fortran string */ + if (OMPI_SUCCESS != (ret = ompi_fortran_string_f2c(filename, name_len, + &c_filename))) { + c_err = OMPI_ERRHANDLER_INVOKE(MPI_FILE_NULL, ret, "MPI_FILE_OPEN"); + *ierr = OMPI_INT_2_FINT(c_err); + return; + } + + *ierr = OMPI_INT_2_FINT(MPI_File_open(c_comm, c_filename, OMPI_FINT_2_INT(*amode), c_info, &c_fh)); - if (MPI_SUCCESS == OMPI_FINT_2_INT(*ierr)) { + if (MPI_SUCCESS == OMPI_FINT_2_INT(*ierr)) { *fh = MPI_File_c2f(c_fh); - } + } + + free(c_filename); } diff --git a/ompi/mpi/f77/file_set_view_f.c b/ompi/mpi/f77/file_set_view_f.c index a02a1f0066..8368d0fd7b 100644 --- a/ompi/mpi/f77/file_set_view_f.c +++ b/ompi/mpi/f77/file_set_view_f.c @@ -19,6 +19,8 @@ #include "ompi_config.h" #include "ompi/mpi/f77/bindings.h" +#include "ompi/mpi/f77/strings.h" +#include "ompi/file/file.h" #if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILE_LAYER #pragma weak PMPI_FILE_SET_VIEW = mpi_file_set_view_f @@ -31,8 +33,8 @@ OMPI_GENERATE_F77_BINDINGS (PMPI_FILE_SET_VIEW, pmpi_file_set_view_, pmpi_file_set_view__, pmpi_file_set_view_f, - (MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, char *datarep, MPI_Fint *info, MPI_Fint *ierr), - (fh, disp, etype, filetype, datarep, info, ierr) ) + (MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, char *datarep, MPI_Fint *info, MPI_Fint *ierr, int datarep_len), + (fh, disp, etype, filetype, datarep, info, ierr, datarep_len) ) #endif #if OMPI_HAVE_WEAK_SYMBOLS @@ -48,8 +50,8 @@ OMPI_GENERATE_F77_BINDINGS (MPI_FILE_SET_VIEW, mpi_file_set_view_, mpi_file_set_view__, mpi_file_set_view_f, - (MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, char *datarep, MPI_Fint *info, MPI_Fint *ierr), - (fh, disp, etype, filetype, datarep, info, ierr) ) + (MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, char *datarep, MPI_Fint *info, MPI_Fint *ierr, int datarep_len), + (fh, disp, etype, filetype, datarep, info, ierr, datarep_len) ) #endif @@ -59,14 +61,27 @@ OMPI_GENERATE_F77_BINDINGS (MPI_FILE_SET_VIEW, void mpi_file_set_view_f(MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, - char *datarep, MPI_Fint *info, MPI_Fint *ierr) + char *datarep, MPI_Fint *info, MPI_Fint *ierr, + int datarep_len) { MPI_File c_fh = MPI_File_f2c(*fh); MPI_Datatype c_etype = MPI_Type_f2c(*etype); MPI_Datatype c_filetype = MPI_Type_f2c(*filetype); MPI_Info c_info = MPI_Info_f2c(*info); + char *c_datarep; + int c_err, ret; + + /* Convert the fortran string */ + if (OMPI_SUCCESS != (ret = ompi_fortran_string_f2c(datarep, datarep_len, + &c_datarep))) { + c_err = OMPI_ERRHANDLER_INVOKE(c_fh, ret, "MPI_FILE_SET_VIEW"); + *ierr = OMPI_INT_2_FINT(c_err); + return; + } *ierr = OMPI_INT_2_FINT(MPI_File_set_view(c_fh, (MPI_Offset) *disp, c_etype, c_filetype, - datarep, c_info)); + c_datarep, c_info)); + + free(c_datarep); } diff --git a/ompi/mpi/f77/prototypes_mpi.h b/ompi/mpi/f77/prototypes_mpi.h index 4d03b21714..f432dcfc85 100644 --- a/ompi/mpi/f77/prototypes_mpi.h +++ b/ompi/mpi/f77/prototypes_mpi.h @@ -127,9 +127,9 @@ PN(void, mpi_file_call_errhandler, MPI_FILE_CALL_ERRHANDLER, (MPI_Fint *fh, MPI_ PN(void, mpi_file_create_errhandler, MPI_FILE_CREATE_ERRHANDLER, (ompi_errhandler_fortran_handler_fn_t* function, MPI_Fint *errhandler, MPI_Fint *ierr)); PN(void, mpi_file_set_errhandler, MPI_FILE_SET_ERRHANDLER, (MPI_Fint *file, MPI_Fint *errhandler, MPI_Fint *ierr)); PN(void, mpi_file_get_errhandler, MPI_FILE_GET_ERRHANDLER, (MPI_Fint *file, MPI_Fint *errhandler, MPI_Fint *ierr)); -PN(void, mpi_file_open, MPI_FILE_OPEN, (MPI_Fint *comm, char *filename, MPI_Fint *amode, MPI_Fint *info, MPI_Fint *fh, MPI_Fint *ierr)); +PN(void, mpi_file_open, MPI_FILE_OPEN, (MPI_Fint *comm, char *filename, MPI_Fint *amode, MPI_Fint *info, MPI_Fint *fh, MPI_Fint *ierr, int name_len)); PN(void, mpi_file_close, MPI_FILE_CLOSE, (MPI_Fint *fh, MPI_Fint *ierr)); -PN(void, mpi_file_delete, MPI_FILE_DELETE, (char *filename, MPI_Fint *info, MPI_Fint *ierr)); +PN(void, mpi_file_delete, MPI_FILE_DELETE, (char *filename, MPI_Fint *info, MPI_Fint *ierr, int filename_len)); PN(void, mpi_file_set_size, MPI_FILE_SET_SIZE, (MPI_Fint *fh, MPI_Offset *size, MPI_Fint *ierr)); PN(void, mpi_file_preallocate, MPI_FILE_PREALLOCATE, (MPI_Fint *fh, MPI_Offset *size, MPI_Fint *ierr)); PN(void, mpi_file_get_size, MPI_FILE_GET_SIZE, (MPI_Fint *fh, MPI_Offset *size, MPI_Fint *ierr)); @@ -137,8 +137,8 @@ PN(void, mpi_file_get_group, MPI_FILE_GET_GROUP, (MPI_Fint *fh, MPI_Fint *group, PN(void, mpi_file_get_amode, MPI_FILE_GET_AMODE, (MPI_Fint *fh, MPI_Fint *amode, MPI_Fint *ierr)); PN(void, mpi_file_set_info, MPI_FILE_SET_INFO, (MPI_Fint *fh, MPI_Fint *info, MPI_Fint *ierr)); PN(void, mpi_file_get_info, MPI_FILE_GET_INFO, (MPI_Fint *fh, MPI_Fint *info_used, MPI_Fint *ierr)); -PN(void, mpi_file_set_view, MPI_FILE_SET_VIEW, (MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, char *datarep, MPI_Fint *info, MPI_Fint *ierr)); -PN(void, mpi_file_get_view, MPI_FILE_GET_VIEW, (MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, char *datarep, MPI_Fint *ierr)); +PN(void, mpi_file_set_view, MPI_FILE_SET_VIEW, (MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, char *datarep, MPI_Fint *info, MPI_Fint *ierr, int datarep_len)); +PN(void, mpi_file_get_view, MPI_FILE_GET_VIEW, (MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, char *datarep, MPI_Fint *ierr, int datarep_len)); PN(void, mpi_file_read_at, MPI_FILE_READ_AT, (MPI_Fint *fh, MPI_Offset *offset, char *buf, MPI_Fint *count, MPI_Fint *datatype, MPI_Fint *status, MPI_Fint *ierr)); PN(void, mpi_file_read_at_all, MPI_FILE_READ_AT_ALL, (MPI_Fint *fh, MPI_Offset *offset, char *buf, MPI_Fint *count, MPI_Fint *datatype, MPI_Fint *status, MPI_Fint *ierr)); PN(void, mpi_file_write_at, MPI_FILE_WRITE_AT, (MPI_Fint *fh, MPI_Offset *offset, char *buf, MPI_Fint *count, MPI_Fint *datatype, MPI_Fint *status, MPI_Fint *ierr)); @@ -249,7 +249,7 @@ PN(void, mpi_recv_init, MPI_RECV_INIT, (char *buf, MPI_Fint *count, MPI_Fint *da PN(void, mpi_recv, MPI_RECV, (char *buf, MPI_Fint *count, MPI_Fint *datatype, MPI_Fint *source, MPI_Fint *tag, MPI_Fint *comm, MPI_Fint *status, MPI_Fint *ierr)); PN(void, mpi_reduce, MPI_REDUCE, (char *sendbuf, char *recvbuf, MPI_Fint *count, MPI_Fint *datatype, MPI_Fint *op, MPI_Fint *root, MPI_Fint *comm, MPI_Fint *ierr)); PN(void, mpi_reduce_scatter, MPI_REDUCE_SCATTER, (char *sendbuf, char *recvbuf, MPI_Fint *recvcounts, MPI_Fint *datatype, MPI_Fint *op, MPI_Fint *comm, MPI_Fint *ierr)); -PN(void, mpi_register_datarep, MPI_REGISTER_DATAREP, (char *datarep, void *read_conversion_fn, void *write_conversion_fn, void *dtype_file_extent_fn, MPI_Fint *extra_state, MPI_Fint *ierr)); +PN(void, mpi_register_datarep, MPI_REGISTER_DATAREP, (char *datarep, void *read_conversion_fn, void *write_conversion_fn, void *dtype_file_extent_fn, MPI_Fint *extra_state, MPI_Fint *ierr, int datarep_len)); PN(void, mpi_request_free, MPI_REQUEST_FREE, (MPI_Fint *request, MPI_Fint *ierr)); PN(void, mpi_request_get_status, MPI_REQUEST_GET_STATUS, (MPI_Fint *request, MPI_Flogical *flag, MPI_Fint *status, MPI_Fint *ierr)); PN(void, mpi_rsend, MPI_RSEND, (char *ibuf, MPI_Fint *count, MPI_Fint *datatype, MPI_Fint *dest, MPI_Fint *tag, MPI_Fint *comm, MPI_Fint *ierr)); diff --git a/ompi/mpi/f77/register_datarep_f.c b/ompi/mpi/f77/register_datarep_f.c index 6eeb2c1a2d..460d73afc9 100644 --- a/ompi/mpi/f77/register_datarep_f.c +++ b/ompi/mpi/f77/register_datarep_f.c @@ -19,6 +19,8 @@ #include "ompi_config.h" #include "ompi/mpi/f77/bindings.h" +#include "ompi/mpi/f77/strings.h" +#include "ompi/file/file.h" #if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILE_LAYER #pragma weak PMPI_REGISTER_DATAREP = mpi_register_datarep_f @@ -31,8 +33,8 @@ OMPI_GENERATE_F77_BINDINGS (PMPI_REGISTER_DATAREP, pmpi_register_datarep_, pmpi_register_datarep__, pmpi_register_datarep_f, - (char *datarep, void *read_conversion_fn, void *write_conversion_fn, void *dtype_file_extent_fn, MPI_Fint *extra_state, MPI_Fint *ierr), - (datarep, read_conversion_fn, write_conversion_fn, dtype_file_extent_fn, extra_state, ierr) ) + (char *datarep, void *read_conversion_fn, void *write_conversion_fn, void *dtype_file_extent_fn, MPI_Fint *extra_state, MPI_Fint *ierr, int datarep_len), + (datarep, read_conversion_fn, write_conversion_fn, dtype_file_extent_fn, extra_state, ierr, datarep_len) ) #endif #if OMPI_HAVE_WEAK_SYMBOLS @@ -48,8 +50,8 @@ OMPI_GENERATE_F77_BINDINGS (MPI_REGISTER_DATAREP, mpi_register_datarep_, mpi_register_datarep__, mpi_register_datarep_f, - (char *datarep, void *read_conversion_fn, void *write_conversion_fn, void *dtype_file_extent_fn, MPI_Fint *extra_state, MPI_Fint *ierr), - (datarep, read_conversion_fn, write_conversion_fn, dtype_file_extent_fn, extra_state, ierr) ) + (char *datarep, void *read_conversion_fn, void *write_conversion_fn, void *dtype_file_extent_fn, MPI_Fint *extra_state, MPI_Fint *ierr, int datarep_len), + (datarep, read_conversion_fn, write_conversion_fn, dtype_file_extent_fn, extra_state, ierr, datarep_len) ) #endif @@ -66,18 +68,29 @@ union local_type_convert { void mpi_register_datarep_f(char *datarep, void *read_conversion_fn, void *write_conversion_fn, void *dtype_file_extent_fn, MPI_Fint *extra_state, - MPI_Fint *ierr) + MPI_Fint *ierr, int datarep_len) { + char *c_datarep; + int c_err, ret; + union local_type_convert a, b, c; + + /* Convert the fortran string */ + if (OMPI_SUCCESS != (ret = ompi_fortran_string_f2c(datarep, datarep_len, + &c_datarep))) { + c_err = OMPI_ERRHANDLER_INVOKE(MPI_FILE_NULL, ret, "MPI_FILE_SET_VIEW"); + *ierr = OMPI_INT_2_FINT(c_err); + return; + } + /* Do a little type shifting so that we don't get compiler warnings */ - - union local_type_convert a, b, c; - a.voidp = read_conversion_fn; b.voidp = write_conversion_fn; c.voidp = dtype_file_extent_fn; - *ierr = OMPI_INT_2_FINT(MPI_Register_datarep(datarep, a.convertp, + *ierr = OMPI_INT_2_FINT(MPI_Register_datarep(c_datarep, a.convertp, b.convertp, c.extentp, extra_state)); + + free(c_datarep); }