Changeset: 8402866b2578 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/8402866b2578
Modified Files:
        sql/backends/monet5/sql_gencode.c
Branch: Jul2021
Log Message:

Avoid memory leak and reduce duplication.


diffs (138 lines):

diff --git a/sql/backends/monet5/sql_gencode.c 
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -1030,19 +1030,16 @@ static int
 backend_create_r_func(backend *be, sql_func *f)
 {
        (void)be;
+       _DELETE(f->mod);
+       _DELETE(f->imp);
+       f->mod = GDKstrdup("rapi");
        switch(f->type) {
        case  F_AGGR:
-               _DELETE(f->mod);
-               _DELETE(f->imp);
-               f->mod = GDKstrdup("rapi");
                f->imp = GDKstrdup("eval_aggr");
                break;
        case  F_PROC: /* no output */
        case  F_FUNC:
        default: /* ie also F_FILT and F_UNION for now */
-               _DELETE(f->mod);
-               _DELETE(f->imp);
-               f->mod = GDKstrdup("rapi");
                f->imp = GDKstrdup("eval");
                break;
        }
@@ -1054,25 +1051,19 @@ static int
 backend_create_py_func(backend *be, sql_func *f)
 {
        (void)be;
+       _DELETE(f->mod);
+       _DELETE(f->imp);
+       f->mod = GDKstrdup("pyapi3");
        switch(f->type) {
        case  F_AGGR:
-               _DELETE(f->mod);
-               _DELETE(f->imp);
-               f->mod = GDKstrdup("pyapi3");
                f->imp = GDKstrdup("eval_aggr");
                break;
        case F_LOADER:
-               _DELETE(f->mod);
-               _DELETE(f->imp);
-               f->mod = GDKstrdup("pyapi3");
                f->imp = GDKstrdup("eval_loader");
                break;
        case  F_PROC: /* no output */
        case  F_FUNC:
        default: /* ie also F_FILT and F_UNION for now */
-               _DELETE(f->mod);
-               _DELETE(f->imp);
-               f->mod = GDKstrdup("pyapi3");
                f->imp = GDKstrdup("eval");
                break;
        }
@@ -1083,60 +1074,38 @@ static int
 backend_create_map_py_func(backend *be, sql_func *f)
 {
        (void)be;
+       _DELETE(f->mod);
+       _DELETE(f->imp);
+       f->mod = GDKstrdup("pyapi3map");
        switch(f->type) {
        case  F_AGGR:
-               _DELETE(f->mod);
-               _DELETE(f->imp);
-               f->mod = GDKstrdup("pyapi3map");
                f->imp = GDKstrdup("eval_aggr");
                break;
        case  F_PROC: /* no output */
        case  F_FUNC:
        default: /* ie also F_FILT and F_UNION for now */
-               _DELETE(f->mod);
-               _DELETE(f->imp);
-               f->mod = GDKstrdup("pyapi3map");
                f->imp = GDKstrdup("eval");
                break;
        }
        return 0;
 }
 
-static int
-backend_create_py3_func(backend *be, sql_func *f)
-{
-       backend_create_py_func(be, f);
-       f->mod = GDKstrdup("pyapi3");
-       return 0;
-}
-
-static int
-backend_create_map_py3_func(backend *be, sql_func *f)
-{
-       backend_create_map_py_func(be, f);
-       f->mod = GDKstrdup("pyapi3map");
-       return 0;
-}
-
 /* Create the MAL block for a registered function and optimize it */
 static int
 backend_create_c_func(backend *be, sql_func *f)
 {
        (void)be;
+       _DELETE(f->mod);
+       _DELETE(f->imp);
+       f->mod = GDKstrdup("capi");
        switch(f->type) {
        case  F_AGGR:
-               _DELETE(f->mod);
-               _DELETE(f->imp);
-               f->mod = GDKstrdup("capi");
                f->imp = GDKstrdup("eval_aggr");
                break;
        case F_LOADER:
        case F_PROC: /* no output */
        case F_FUNC:
        default: /* ie also F_FILT and F_UNION for now */
-               _DELETE(f->mod);
-               _DELETE(f->imp);
-               f->mod = GDKstrdup("capi");
                f->imp = GDKstrdup("eval");
                break;
        }
@@ -1421,13 +1390,11 @@ backend_create_func(backend *be, sql_fun
        case FUNC_LANG_R:
                return backend_create_r_func(be, f);
        case FUNC_LANG_PY:
+       case FUNC_LANG_PY3:
                return backend_create_py_func(be, f);
        case FUNC_LANG_MAP_PY:
+       case FUNC_LANG_MAP_PY3:
                return backend_create_map_py_func(be, f);
-       case FUNC_LANG_PY3:
-               return backend_create_py3_func(be, f);
-       case FUNC_LANG_MAP_PY3:
-               return backend_create_map_py3_func(be, f);
        case FUNC_LANG_C:
        case FUNC_LANG_CPP:
                return backend_create_c_func(be, f);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to