[cig-commits] r21736 - in short/3D/PyLith/trunk: libsrc/pylith/topology modulesrc/topology
brad at geodynamics.org
brad at geodynamics.org
Fri Apr 5 15:22:33 PDT 2013
Author: brad
Date: 2013-04-05 15:22:33 -0700 (Fri, 05 Apr 2013)
New Revision: 21736
Modified:
short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.cc
short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.hh
short/3D/PyLith/trunk/modulesrc/topology/Mesh.i
Log:
Fix interface for Mesh::groups(). Need to use char*** to allow SWIG to deallocate strings.
Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.cc 2013-04-05 22:21:56 UTC (rev 21735)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.cc 2013-04-05 22:22:33 UTC (rev 21736)
@@ -136,7 +136,7 @@
// Return the names of all vertex groups.
void
pylith::topology::Mesh::groups(int* numNames,
- const char*** names) const
+ char*** names) const
{ // groups
PYLITH_METHOD_BEGIN;
@@ -152,9 +152,21 @@
err = DMPlexGetNumLabels(_newMesh, &numLabels);CHECK_PETSC_ERROR(err);
*numNames = numLabels;
- *names = new const char*[numLabels];
+ *names = new char*[numLabels];
for (int iLabel=0; iLabel < numLabels; ++iLabel) {
- err = DMPlexGetLabelName(_newMesh, iLabel, &(*names)[iLabel]);CHECK_PETSC_ERROR(err);
+ const char* namestr = NULL;
+ err = DMPlexGetLabelName(_newMesh, iLabel, &namestr);CHECK_PETSC_ERROR(err);
+ // Must return char* that SWIG can deallocate.
+ const char len = strlen(namestr);
+ char* newName = 0;
+ if (len > 0) {
+ newName = new char[len+1];
+ strncpy(newName, namestr, len+1);
+ } else {
+ newName = new char[1];
+ newName[0] ='\0';
+ } // if/else
+ (*names)[iLabel] = newName;
} // for
} // if
Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.hh 2013-04-05 22:21:56 UTC (rev 21735)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Mesh.hh 2013-04-05 22:22:33 UTC (rev 21736)
@@ -223,7 +223,7 @@
* @param names Names of fields.
*/
void groups(int* numNames,
- const char*** names) const;
+ char*** names) const;
/** Return the size of a group.
*
Modified: short/3D/PyLith/trunk/modulesrc/topology/Mesh.i
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/Mesh.i 2013-04-05 22:21:56 UTC (rev 21735)
+++ short/3D/PyLith/trunk/modulesrc/topology/Mesh.i 2013-04-05 22:22:33 UTC (rev 21736)
@@ -134,7 +134,7 @@
* @param values Values of field values [output].
*/
void groups(int* numValues,
- const char*** values) const;
+ char*** values) const;
/** Return the size of a group.
*
More information about the CIG-COMMITS
mailing list