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 2198 : pl_find(const char *name) 21 : { 22 2198 : if (!name) 23 : return NULL; 24 268535 : for (int i = 0; i < NR_PROTO_LOADERS; i++) { 25 267496 : if (proto_loaders[i].name && strcmp(proto_loaders[i].name, name) == 0) 26 1159 : return proto_loaders+i; 27 : } 28 : return NULL; 29 : } 30 : 31 : int 32 1039 : pl_register(const char *name, pl_add_types_fptr add_types, pl_load_fptr load) 33 : { 34 1039 : proto_loader_t *fl = pl_find(name); 35 1039 : 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 2080 : for (int i = 0; i < NR_PROTO_LOADERS; i++) { 42 2080 : if (proto_loaders[i].name == NULL) { 43 1039 : proto_loaders[i].name = GDKstrdup(name); 44 1039 : proto_loaders[i].add_types = add_types; 45 1039 : proto_loaders[i].load = load; 46 1039 : 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 1036 : pl_unregister(const char *name) 56 : { 57 1036 : proto_loader_t *fl = pl_find(name); 58 1036 : if (fl) { 59 1036 : GDKfree(fl->name); 60 1036 : fl->name = NULL; 61 : } 62 1036 : } 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 : }