[postgis-tickets] [PostGIS] #3246: lwcollection_extract return object possibly referencing portions of argument

PostGIS trac at osgeo.org
Thu Nov 26 06:37:27 PST 2015


#3246: lwcollection_extract return object possibly referencing portions of
argument
----------------------+---------------------------
  Reporter:  strk     |      Owner:  pramsey
      Type:  defect   |     Status:  new
  Priority:  medium   |  Milestone:  PostGIS 2.1.9
 Component:  postgis  |    Version:  2.1.x
Resolution:           |   Keywords:
----------------------+---------------------------

Comment (by pramsey):

 So, the question is kind of whether we feel OK having those references or
 not. It's certainly a lot lighter weight to do them, and I confirmed that,
 in ordinary usage, shallow cloning works OK:
 {{{
 static void test_clone(void)
 {
         static char *wkt = "GEOMETRYCOLLECTION(MULTIPOLYGON(((0 0, 10 0,
 10 10, 0 10, 0 0))),POINT(1 1),LINESTRING(2 3,4 5))";
         LWGEOM *geom1 = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_ALL);
         LWGEOM *geom2;

         /* Free in "backwards" order */
         geom2 = lwgeom_clone(geom1);
         lwgeom_free(geom1);
         lwgeom_free(geom2);

         /* Free in "forewards" order */
         geom1 = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_ALL);
         geom2 = lwgeom_clone(geom1);
         lwgeom_free(geom2);
         lwgeom_free(geom1);
 }
 }}}
 Mind you, freeing the input and then *using* the output would fail, but in
 terms of freeing, the read-only guard works fine, there's no doublefree
 condition. Question is basically if we want to apply a "mutation implies
 copy" policy over the whole codebase or not, even when the mutation
 doesn't actually affect the coordinates (the biggest overhead of our
 memory use).

--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/3246#comment:1>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list