LCOV - code coverage report
Current view: top level - sql/server - rel_proto_loader.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 20 28 71.4 %
Date: 2025-03-26 20:06:40 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : #include "monetdb_config.h"
      14             : #include "rel_proto_loader.h"
      15             : 
      16             : #define NR_PROTO_LOADERS 255
      17             : static proto_loader_t proto_loaders[NR_PROTO_LOADERS] = { 0 };
      18             : 
      19             : proto_loader_t*
      20        2192 : pl_find(const char *name)
      21             : {
      22        2192 :         if (!name)
      23             :                 return NULL;
      24      267761 :         for (int i = 0; i < NR_PROTO_LOADERS; i++) {
      25      266725 :                 if (proto_loaders[i].name && strcmp(proto_loaders[i].name, name) == 0)
      26        1156 :                         return proto_loaders+i;
      27             :         }
      28             :         return NULL;
      29             : }
      30             : 
      31             : int
      32        1036 : pl_register(const char *name, pl_add_types_fptr add_types, pl_load_fptr load)
      33             : {
      34        1036 :         proto_loader_t *fl = pl_find(name);
      35        1036 :         if (fl) {
      36           0 :                 TRC_WARNING(SQL_TRANS,"proto_loader re-registering %s\n", name);
      37           0 :                 GDKfree(fl->name);
      38           0 :                 fl->name = NULL;
      39             :         }
      40             : 
      41        2074 :         for (int i = 0; i < NR_PROTO_LOADERS; i++) {
      42        2074 :                 if (proto_loaders[i].name == NULL) {
      43        1036 :                         proto_loaders[i].name = GDKstrdup(name);
      44        1036 :                         proto_loaders[i].add_types = add_types;
      45        1036 :                         proto_loaders[i].load = load;
      46        1036 :                         return 0;
      47             :                 }
      48             :         }
      49             : 
      50             :         /* all proto_loaders array locations are occupied */
      51             :         return -1;      /* could not register proto_loader */
      52             : }
      53             : 
      54             : void
      55        1033 : pl_unregister(const char *name)
      56             : {
      57        1033 :         proto_loader_t *fl = pl_find(name);
      58        1033 :         if (fl) {
      59        1033 :                 GDKfree(fl->name);
      60        1033 :                 fl->name = NULL;
      61             :         }
      62        1033 : }
      63             : 
      64             : void
      65           0 : pl_exit(void)
      66             : {
      67           0 :         for (int i = 0; i < NR_PROTO_LOADERS; i++) {
      68           0 :                 if (proto_loaders[i].name)
      69           0 :                         GDKfree(proto_loaders[i].name);
      70             :         }
      71           0 : }

Generated by: LCOV version 1.14