Changeset: ef8f6f8dc44b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ef8f6f8dc44b
Branch: resource_management
Log Message:

merge upstream


diffs (truncated from 765 to 300 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -572,12 +572,10 @@ void ma_destroy(allocator *sa);
 void ma_free(allocator *sa, void *);
 exception_buffer *ma_get_eb(allocator *sa) __attribute__((__pure__));
 allocator *ma_get_parent(const allocator *sa);
-allocator *ma_get_ta(allocator *sa);
 const char *ma_name(allocator *sa);
 allocator_state *ma_open(allocator *sa);
 void *ma_realloc(allocator *sa, void *ptr, size_t sz, size_t osz);
 allocator *ma_reset(allocator *sa);
-void ma_set_ta(allocator *sa, allocator *ta);
 size_t ma_size(allocator *sa);
 char *ma_strconcat(allocator *sa, const char *s1, const char *s2);
 char *ma_strdup(allocator *sa, const char *s);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1755,9 +1755,6 @@ gdk_export void ma_free(allocator *sa, v
 gdk_export exception_buffer *ma_get_eb(allocator *sa)
        __attribute__((__pure__));
 
-gdk_export void ma_set_ta(allocator *sa,  allocator *ta);
-gdk_export allocator *ma_get_ta(allocator *sa);
-
 #define MA_NEW( sa, type )                             ((type*)ma_alloc( sa, 
sizeof(type)))
 #define MA_ZNEW( sa, type )                            ((type*)ma_zalloc( sa, 
sizeof(type)))
 #define MA_NEW_ARRAY( sa, type, size )                 (type*)ma_alloc( sa, 
((size)*sizeof(type)))
diff --git a/gdk/gdk_system_private.h b/gdk/gdk_system_private.h
--- a/gdk/gdk_system_private.h
+++ b/gdk/gdk_system_private.h
@@ -50,7 +50,6 @@ struct freebats *MT_thread_getfreebats(v
 
 struct allocator {
        struct allocator *pa;
-       struct allocator *ta;
        size_t size;     /* size of the allocator in terms of blocks */
        size_t nr;       /* number of blocks allocated */
        char **blks;
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -2095,21 +2095,6 @@ ma_alloc(allocator *sa, size_t sz)
        return sa_fill_in_header(r, sz);
 }
 
-void
-ma_set_ta(allocator *sa, allocator *ta)
-{
-       assert(ta);
-       assert(sa->ta == NULL);
-       sa->ta = ta;
-}
-
-allocator *
-ma_get_ta(allocator *sa)
-{
-       assert(sa->ta);
-       return sa->ta;
-}
-
 allocator *
 create_allocator(allocator *pa, const char *name, bool use_lock)
 {
@@ -2132,7 +2117,6 @@ create_allocator(allocator *pa, const ch
                .blks = blks,
                .first_blk = first_blk,
                .pa = pa,
-               .ta = NULL,
                .nr = 1,
                .usedmem = SA_BLOCK_SIZE,
                .blk_size = SA_BLOCK_SIZE,
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -158,7 +158,7 @@ wkbCollectAggrSubGroupedCand(Client ctx,
                                        collection = 
GEOSGeom_createCollection_r(geoshandle, geomCollectionType, unionGroup, 
(unsigned int) geomCount);
                                        GEOSSetSRID_r(geoshandle, 
collection,srid);
                                        //Save collection to unions array as wkb
-                                       unions[lastGrp] = geos2wkb(ma, 
collection);
+                                       unions[lastGrp] = geos2wkb(ma, 
&(wkb*){NULL}, &(size_t){0}, collection);
 
                                        GEOSGeom_destroy_r(geoshandle, 
collection);
                                        //GDKfree(unionGroup);
@@ -188,7 +188,7 @@ wkbCollectAggrSubGroupedCand(Client ctx,
                //Last collection
                collection = GEOSGeom_createCollection_r(geoshandle, 
geomCollectionType, unionGroup, (unsigned int) geomCount);
                GEOSSetSRID_r(geoshandle, collection,srid);
-               unions[lastGrp] = geos2wkb(ma, collection);
+               unions[lastGrp] = geos2wkb(ma, &(wkb*){NULL}, &(size_t){0}, 
collection);
 
                GEOSGeom_destroy_r(geoshandle, collection);
                //GDKfree(unionGroup);
@@ -275,7 +275,7 @@ wkbCollectAggr(Client ctx, wkb **out, co
        collection = GEOSGeom_createCollection_r(geoshandle, 
geomCollectionType, unionGroup, (unsigned int) count);
        GEOSSetSRID_r(geoshandle, collection,srid);
        //Result
-       (*out) = geos2wkb(ma, collection);
+       (*out) = geos2wkb(ma, &(wkb*){NULL}, &(size_t){0}, collection);
        if (*out == NULL)
                msg = createException(MAL, "geom.ConvexHull", SQLSTATE(38000) 
"Geos operation geos2wkb failed");
 
@@ -313,7 +313,7 @@ wkbCollect(Client ctx, wkb **out, wkb * 
        else
                collection = GEOSGeom_createCollection_r(geoshandle, 
GEOS_GEOMETRYCOLLECTION, geoms, (unsigned int) 2);
 
-       if ((*out = geos2wkb(ma, collection)) == NULL)
+       if ((*out = geos2wkb(ma, &(wkb*){NULL}, &(size_t){0}, collection)) == 
NULL)
                err = createException(MAL, "geom.Collect", SQLSTATE(38000) 
"Geos operation geos2wkb failed");
 
        GEOSGeom_destroy_r(geoshandle, collection);
@@ -741,7 +741,7 @@ wkbTransform(Client ctx, wkb **transform
                /* set the new srid */
                GEOSSetSRID_r(geoshandle, transformedGeosGeometry, *srid_dst);
                /* get the wkb */
-               if ((*transformedWKB = geos2wkb(ma, transformedGeosGeometry)) 
== NULL)
+               if ((*transformedWKB = geos2wkb(ma, &(wkb*){NULL}, 
&(size_t){0}, transformedGeosGeometry)) == NULL)
                        ret = createException(MAL, "geom.Transform", 
SQLSTATE(38000) "Geos operation geos2wkb failed");
                /* destroy the geos geometries */
                GEOSGeom_destroy_r(geoshandle, transformedGeosGeometry);
@@ -1064,7 +1064,7 @@ wkbForceDim(Client ctx, wkb **outWKB, wk
 
        GEOSSetSRID_r(geoshandle, outGeometry, GEOSGetSRID_r(geoshandle, 
geosGeometry));
 
-       *outWKB = geos2wkb(ma, outGeometry);
+       *outWKB = geos2wkb(ma, &(wkb*){NULL}, &(size_t){0}, outGeometry);
 
        GEOSGeom_destroy_r(geoshandle, geosGeometry);
        GEOSGeom_destroy_r(geoshandle, outGeometry);
@@ -1451,7 +1451,7 @@ wkbSegmentize(Client ctx, wkb **outWKB, 
 
        GEOSSetSRID_r(geoshandle, outGeometry, GEOSGetSRID_r(geoshandle, 
geosGeometry));
 
-       *outWKB = geos2wkb(ma, outGeometry);
+       *outWKB = geos2wkb(ma, &(wkb*){NULL}, &(size_t){0}, outGeometry);
 
        GEOSGeom_destroy_r(geoshandle, geosGeometry);
        GEOSGeom_destroy_r(geoshandle, outGeometry);
@@ -1774,7 +1774,7 @@ wkbTranslate(Client ctx, wkb **outWKB, w
 
        GEOSSetSRID_r(geoshandle, outGeometry, GEOSGetSRID_r(geoshandle, 
geosGeometry));
 
-       *outWKB = geos2wkb(ma, outGeometry);
+       *outWKB = geos2wkb(ma, &(wkb*){NULL}, &(size_t){0}, outGeometry);
 
        GEOSGeom_destroy_r(geoshandle, geosGeometry);
        GEOSGeom_destroy_r(geoshandle, outGeometry);
@@ -1809,7 +1809,7 @@ wkbDelaunayTriangles(Client ctx, wkb **o
                throw(MAL, "geom.DelaunayTriangles", SQLSTATE(38000) "Geos 
operation GEOSDelaunayTriangulation failed");
        }
 
-       *outWKB = geos2wkb(ma, outGeometry);
+       *outWKB = geos2wkb(ma, &(wkb*){NULL}, &(size_t){0}, outGeometry);
        GEOSGeom_destroy_r(geoshandle, outGeometry);
 
        if (*outWKB == NULL)
@@ -1845,7 +1845,7 @@ wkbPointOnSurface(Client ctx, wkb **resW
        //set the srid of the point the same as the srid of the input geometry
        GEOSSetSRID_r(geoshandle, resGeosGeometry, GEOSGetSRID_r(geoshandle, 
geosGeometry));
 
-       *resWKB = geos2wkb(ma, resGeosGeometry);
+       *resWKB = geos2wkb(ma, &(wkb*){NULL}, &(size_t){0}, resGeosGeometry);
 
        GEOSGeom_destroy_r(geoshandle, geosGeometry);
        GEOSGeom_destroy_r(geoshandle, resGeosGeometry);
@@ -1863,7 +1863,7 @@ dumpGeometriesSingle(BAT *idBAT, BAT *ge
        assert(ma);
        char *newPath = NULL;
        size_t pathLength = strlen(path);
-       wkb *singleWKB = geos2wkb(ma, geosGeometry);
+       wkb *singleWKB = geos2wkb(ma, &(wkb*){NULL}, &(size_t){0}, 
geosGeometry);
        str err = MAL_SUCCEED;
 
        if (singleWKB == NULL)
@@ -2048,7 +2048,7 @@ dumpPointsPoint(allocator *ma, BAT *idBA
 {
        char *newPath = NULL;
        size_t pathLength = strlen(path);
-       wkb *pointWKB = geos2wkb(ma, geosGeometry);
+       wkb *pointWKB = geos2wkb(ma, &(wkb*){NULL}, &(size_t){0}, geosGeometry);
        const int lvlDigitsNum = 10;    //MAX_UNIT = 4,294,967,295
        str err = MAL_SUCCEED;
 
@@ -2083,7 +2083,7 @@ dumpPointsLineString(Client ctx, BAT *id
        int check = 0;
        unsigned int lvl = 0;
        allocator *ma = ctx->curprg->def->ma;
-       wkb *geomWKB = geos2wkb(ma, geosGeometry);
+       wkb *geomWKB = geos2wkb(ma, &(wkb*){NULL}, &(size_t){0}, geosGeometry);
 
        err = wkbNumPoints(ctx, &pointsNum, &geomWKB, &check);
        ////GDKfree(geomWKB);
@@ -2327,7 +2327,7 @@ geom_2_geom(Client ctx, wkb **resWKB, wk
        }
 
        /* get the wkb from the geosGeometry */
-       *resWKB = geos2wkb(ma, geosGeometry);
+       *resWKB = geos2wkb(ma, &(wkb*){NULL}, &(size_t){0}, geosGeometry);
        GEOSGeom_destroy_r(geoshandle, geosGeometry);
 
        if (*resWKB == NULL)
@@ -2409,16 +2409,22 @@ geom_epilogue(Client ctx, void *ret)
  * the input geosGeometry should not be altered by this function
  * return NULL on error */
 wkb *
-geos2wkb(allocator *ma, const GEOSGeometry *geosGeometry)
+geos2wkb(allocator *ma, wkb **geomWKB, size_t *len, const GEOSGeometry 
*geosGeometry)
 {
        assert(ma);
        size_t wkbLen = 0;
        unsigned char *w = NULL;
-       wkb *geomWKB;
 
        // if the geosGeometry is NULL create a NULL WKB
        if (geosGeometry == NULL) {
-               return wkbNULLcopy(ma);
+               if (*len < sizeof(wkb_nil)) {
+                       *len = sizeof(wkb_nil);
+                       *geomWKB = ma_alloc(ma, *len);
+               }
+               if (!*geomWKB)
+                       return NULL;
+               **geomWKB = wkb_nil;
+               return *geomWKB;
        }
 
        GEOS_setWKBOutputDims_r(geoshandle, 
GEOSGeom_getCoordinateDimension_r(geoshandle, geosGeometry));
@@ -2429,19 +2435,19 @@ geos2wkb(allocator *ma, const GEOSGeomet
 
        assert(wkbLen <= GDK_int_max);
 
-       geomWKB = ma_alloc(ma, wkb_size(wkbLen));
+       *geomWKB = ma_alloc(ma, wkb_size(wkbLen));
        //If malloc failed create a NULL wkb
-       if (geomWKB == NULL) {
+       if (*geomWKB == NULL) {
                GEOSFree_r(geoshandle, w);
                return NULL;
        }
 
-       geomWKB->len = (int) wkbLen;
-       geomWKB->srid = GEOSGetSRID_r(geoshandle, geosGeometry);
-       memcpy(&geomWKB->data, w, wkbLen);
+       (*geomWKB)->len = (int) wkbLen;
+       (*geomWKB)->srid = GEOSGetSRID_r(geoshandle, geosGeometry);
+       memcpy(&(*geomWKB)->data, w, wkbLen);
        GEOSFree_r(geoshandle, w);
 
-       return geomWKB;
+       return *geomWKB;
 }
 
 /* gets the mbr from the geometry */
@@ -2586,15 +2592,19 @@ decit(char hex)
 }
 
 str
-wkbFromBinary(Client ctx, wkb **geomWKB, const char **inStr)
-{
-       allocator *ma = ctx ? ctx->curprg->def->ma : MT_thread_getallocator();
+wkbFromBinaryWithBuffer(allocator *ma, wkb **geomWKB, size_t *len, const char 
**inStr)
+{
        size_t strLength, wkbLength, i;
        wkb *w;
 
        if (strNil(*inStr)) {
-               if ((*geomWKB = wkbNULLcopy(ma)) == NULL)
+               if (*len < sizeof(wkb_nil)) {
+                       *len = sizeof(wkb_nil);
+                       *geomWKB = ma_alloc(ma, *len);
+               }
+               if (*geomWKB == NULL)
                        throw(MAL, "geom.FromBinary", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+               **geomWKB = wkb_nil;
                return MAL_SUCCEED;
        }
 
@@ -2605,16 +2615,18 @@ wkbFromBinary(Client ctx, wkb **geomWKB,
        wkbLength = strLength / 2;
        assert(wkbLength <= GDK_int_max);
 
-       w = ma_alloc(ma, wkb_size(wkbLength));
-       if (w == NULL)
-               throw(MAL, "geom.FromBinary", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+       if (!*geomWKB || *len < wkb_size(wkbLength)) {
+               *len = wkb_size(wkbLength);
+               *geomWKB = w = ma_alloc(ma, *len);
+               if (w == NULL)
+                       throw(MAL, "geom.FromBinary", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+       }
 
        //compute the value for s
        for (i = 0; i < strLength; i += 2) {
                int firstHalf = decit((*inStr)[i]);
                int secondHalf = decit((*inStr)[i + 1]);
                if (firstHalf == -1 || secondHalf == -1) {
-                       //GDKfree(w);
                        throw(MAL, "geom.FromBinary", SQLSTATE(38000) "Geos 
incorrectly formatted input string");
                }
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to