[geos-commits] r2286 - trunk/capi
svn_geos at osgeo.org
svn_geos at osgeo.org
Fri Mar 20 21:37:22 EDT 2009
Author: mloskot
Date: 2009-03-20 21:37:22 -0400 (Fri, 20 Mar 2009)
New Revision: 2286
Modified:
trunk/capi/geos_ts_c.cpp
Log:
capi/geos_ts_c.cpp: added gstrdup and gstrdup_s helper functions to get rid of bloated code in future. Started eliminating redundant return expressions.
Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp 2009-03-21 01:10:45 UTC (rev 2285)
+++ trunk/capi/geos_ts_c.cpp 2009-03-21 01:37:22 UTC (rev 2286)
@@ -117,6 +117,25 @@
extern "C" {
+char* gstrdup_s(const char* str, const std::size_t size)
+{
+ char* out = static_cast<char*>(std::malloc(size + 1));
+ if (0 != out)
+ {
+ // as no strlen call necessary, memcpy may be faster than strcpy
+ std::memcpy(out, str, size + 1);
+ }
+
+ assert(0 != out);
+ return out;
+}
+
+char* gstrdup(std::string const& str)
+{
+ return gstrdup_s(str.c_str(), str.size());
+}
+
+
GEOSContextHandle_t
initGEOS_r(GEOSMessageHandler nf, GEOSMessageHandler ef)
{
@@ -174,13 +193,13 @@
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return 2;
}
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return 2;
}
+
+ return 2;
}
char
@@ -302,13 +321,13 @@
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return 2;
}
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return 2;
}
+
+ return 2;
}
// call g1->contains(g2)
@@ -338,13 +357,13 @@
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return 2;
}
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return 2;
}
+
+ return 2;
}
char
@@ -370,13 +389,13 @@
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return 2;
}
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return 2;
}
+
+ return 2;
}
@@ -408,13 +427,13 @@
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
- return 2;
}
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
- return 2;
}
+
+ return 2;
}
char *
@@ -436,16 +455,15 @@
{
using geos::geom::IntersectionMatrix;
- IntersectionMatrix *im = g1->relate(g2);
- if (im == NULL)
- return NULL;
-
- std::string s(im->toString());
- char *result = NULL;
- result = (char*) std::malloc( s.length() + 1);
- std::strcpy(result, s.c_str() );
+ IntersectionMatrix* im = g1->relate(g2);
+ if (0 == im)
+ {
+ return 0;
+ }
+
+ char *result = gstrdup(im->toString());
+
delete im;
-
return result;
}
catch (const std::exception &e)
More information about the geos-commits
mailing list