[mpich2-commits] r5607 - mpich2/trunk/src/util/info
goodell at mcs.anl.gov
goodell at mcs.anl.gov
Wed Oct 28 18:24:47 CDT 2009
Author: goodell
Date: 2009-10-28 18:24:46 -0500 (Wed, 28 Oct 2009)
New Revision: 5607
Modified:
mpich2/trunk/src/util/info/info_create.c
mpich2/trunk/src/util/info/info_dup.c
mpich2/trunk/src/util/info/info_set.c
mpich2/trunk/src/util/info/infoutil.c
mpich2/trunk/src/util/info/mpiinfo.h
Log:
Fix MPI_Info object allocation/deallocation.
Also, refactor/simplify some of the MPI_Info handling code.
Reviewed by buntinas at .
Modified: mpich2/trunk/src/util/info/info_create.c
===================================================================
--- mpich2/trunk/src/util/info/info_create.c 2009-10-28 23:24:45 UTC (rev 5606)
+++ mpich2/trunk/src/util/info/info_create.c 2009-10-28 23:24:46 UTC (rev 5607)
@@ -67,18 +67,15 @@
# endif /* HAVE_ERROR_CHECKING */
/* ... body of routine ... */
-
- info_ptr = (MPID_Info *)MPIU_Handle_obj_alloc( &MPID_Info_mem );
- MPIU_ERR_CHKANDJUMP1((!info_ptr), mpi_errno, MPI_ERR_OTHER, "**nomem", "**nomem %s", "MPI_Info");
+ mpi_errno = MPIU_Info_alloc(&info_ptr);
+ if (mpi_errno) MPIU_ERR_POP(mpi_errno);
+
*info = info_ptr->handle;
/* (info_ptr)->cookie = MPIR_INFO_COOKIE; */
- info_ptr->key = 0;
- info_ptr->value = 0;
- info_ptr->next = 0;
- /* this is the first structure in this linked list. it is
+ /* this is the first structure in this linked list. it is
always kept empty. new (key,value) pairs are added after it. */
-
+
/* ... end of body of routine ... */
fn_exit:
Modified: mpich2/trunk/src/util/info/info_dup.c
===================================================================
--- mpich2/trunk/src/util/info/info_dup.c 2009-10-28 23:24:45 UTC (rev 5606)
+++ mpich2/trunk/src/util/info/info_dup.c 2009-10-28 23:24:46 UTC (rev 5607)
@@ -96,23 +96,20 @@
may want to add an "allocate n elements" routine and execute this
it two steps: count and then allocate */
/* FIXME : multithreaded */
- curr_new = (MPID_Info *)MPIU_Handle_obj_alloc( &MPID_Info_mem );
- curr_new->key = 0;
- curr_new->value = 0;
- curr_new->next = 0;
+ mpi_errno = MPIU_Info_alloc(&curr_new);
+ if (mpi_errno) MPIU_ERR_POP(mpi_errno);
*newinfo = curr_new->handle;
- curr_old = info_ptr->next;
+ curr_old = info_ptr->next;
while (curr_old)
{
- curr_new->next = (MPID_Info *)MPIU_Handle_obj_alloc( &MPID_Info_mem );
- MPIU_ERR_CHKANDJUMP1((!curr_new->next), mpi_errno, MPI_ERR_OTHER, "**nomem", "**nomem %s", "MPI_Info");
+ mpi_errno = MPIU_Info_alloc(&curr_new->next);
+ if (mpi_errno) MPIU_ERR_POP(mpi_errno);
curr_new = curr_new->next;
curr_new->key = MPIU_Strdup(curr_old->key);
curr_new->value = MPIU_Strdup(curr_old->value);
- curr_new->next = 0;
-
+
curr_old = curr_old->next;
}
Modified: mpich2/trunk/src/util/info/info_set.c
===================================================================
--- mpich2/trunk/src/util/info/info_set.c 2009-10-28 23:24:45 UTC (rev 5606)
+++ mpich2/trunk/src/util/info/info_set.c 2009-10-28 23:24:46 UTC (rev 5607)
@@ -118,15 +118,13 @@
if (!curr_ptr) {
/* Key not present, insert value */
- curr_ptr = (MPID_Info *)MPIU_Handle_obj_alloc( &MPID_Info_mem );
+ mpi_errno = MPIU_Info_alloc(&curr_ptr);
+ if (mpi_errno) MPIU_ERR_POP(mpi_errno);
- MPIU_ERR_CHKANDJUMP1((!curr_ptr), mpi_errno, MPI_ERR_OTHER, "**nomem", "**nomem %s", "MPI_Info" );
-
/*printf( "Inserting new elm %x at %x\n", curr_ptr->id, prev_ptr->id );*/
prev_ptr->next = curr_ptr;
curr_ptr->key = MPIU_Strdup(key);
curr_ptr->value = MPIU_Strdup(value);
- curr_ptr->next = 0;
}
/* ... end of body of routine ... */
Modified: mpich2/trunk/src/util/info/infoutil.c
===================================================================
--- mpich2/trunk/src/util/info/infoutil.c 2009-10-28 23:24:45 UTC (rev 5606)
+++ mpich2/trunk/src/util/info/infoutil.c 2009-10-28 23:24:46 UTC (rev 5607)
@@ -22,13 +22,19 @@
/* Free an info structure. In the multithreaded case, this routine
relies on the SINGLE_CS in the info routines (particularly MPI_Info_free) */
+#undef FUNCNAME
+#define FUNCNAME MPIU_Info_free
+#undef FCNAME
+#define FCNAME MPIU_QUOTE(FUNCNAME)
void MPIU_Info_free( MPID_Info *info_ptr )
{
MPID_Info *curr_ptr, *last_ptr;
curr_ptr = info_ptr->next;
- last_ptr = info_ptr;
+ last_ptr = NULL;
+ MPIU_Handle_obj_free(&MPID_Info_mem, info_ptr);
+
/* printf( "Returning info %x\n", info_ptr->id ); */
/* First, free the string storage */
while (curr_ptr) {
@@ -36,9 +42,29 @@
MPIU_Free(curr_ptr->value);
last_ptr = curr_ptr;
curr_ptr = curr_ptr->next;
+ MPIU_Handle_obj_free(&MPID_Info_mem, last_ptr);
}
+}
- /* Return info to the avail list */
- last_ptr->next = (MPID_Info *)MPID_Info_mem.avail;
- MPID_Info_mem.avail = (void *)info_ptr;
+/* Allocate and initialize an MPID_Info object.
+ *
+ * Returns MPICH2 error codes */
+#undef FUNCNAME
+#define FUNCNAME MPIU_Info_alloc
+#undef FCNAME
+#define FCNAME MPIU_QUOTE(FUNCNAME)
+int MPIU_Info_alloc(MPID_Info **info_p_p)
+{
+ int mpi_errno = MPI_SUCCESS;
+ *info_p_p = (MPID_Info *)MPIU_Handle_obj_alloc(&MPID_Info_mem);
+ MPIU_ERR_CHKANDJUMP1(!*info_p_p, mpi_errno, MPI_ERR_OTHER, "**nomem", "**nomem %s", "MPI_Info");
+
+ MPIU_Object_set_ref(*info_p_p, 0);
+ (*info_p_p)->next = NULL;
+ (*info_p_p)->key = NULL;
+ (*info_p_p)->value = NULL;
+
+fn_fail:
+ return mpi_errno;
}
+
Modified: mpich2/trunk/src/util/info/mpiinfo.h
===================================================================
--- mpich2/trunk/src/util/info/mpiinfo.h 2009-10-28 23:24:45 UTC (rev 5606)
+++ mpich2/trunk/src/util/info/mpiinfo.h 2009-10-28 23:24:46 UTC (rev 5607)
@@ -4,3 +4,4 @@
* See COPYRIGHT in top-level directory.
*/
extern void MPIU_Info_free( MPID_Info *info_ptr );
+extern int MPIU_Info_alloc(MPID_Info **info_p_p);
More information about the mpich2-commits
mailing list