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 : /*
14 : * (c) Martin Kersten
15 : * This module provides a wrapping of the help function in the .../mal/mal_modules.c
16 : * and the list of all MAL functions for analysis using SQL.
17 : */
18 : #include "monetdb_config.h"
19 : #include "gdk.h"
20 : #include <time.h>
21 : #include "mal_resolve.h"
22 : #include "mal_client.h"
23 : #include "mal_exception.h"
24 : #include "mal_interpreter.h"
25 : #include "mal_namespace.h"
26 :
27 : static str
28 12 : MANUALcreateOverview(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
29 : {
30 12 : BAT *mod, *fcn, *sig, *adr, *com;
31 12 : bat *mx = getArgReference_bat(stk, pci, 0);
32 12 : bat *fx = getArgReference_bat(stk, pci, 1);
33 12 : bat *sx = getArgReference_bat(stk, pci, 2);
34 12 : bat *ax = getArgReference_bat(stk, pci, 3);
35 12 : bat *cx = getArgReference_bat(stk, pci, 4);
36 12 : Module *moduleList;
37 12 : int length;
38 12 : int top = 0;
39 12 : Module list[256];
40 :
41 12 : mod = COLnew(0, TYPE_str, 0, TRANSIENT);
42 12 : fcn = COLnew(0, TYPE_str, 0, TRANSIENT);
43 12 : sig = COLnew(0, TYPE_str, 0, TRANSIENT);
44 12 : adr = COLnew(0, TYPE_str, 0, TRANSIENT);
45 12 : com = COLnew(0, TYPE_str, 0, TRANSIENT);
46 12 : if (mod == NULL || fcn == NULL || sig == NULL || adr == NULL || com == NULL) {
47 0 : BBPreclaim(mod);
48 0 : BBPreclaim(fcn);
49 0 : BBPreclaim(sig);
50 0 : BBPreclaim(adr);
51 0 : BBPreclaim(com);
52 0 : throw(MAL, "manual.functions", SQLSTATE(HY013) MAL_MALLOC_FAIL);
53 : }
54 :
55 12 : list[top++] = cntxt->usermodule;
56 12 : getModuleList(&moduleList, &length);
57 12 : if (moduleList == NULL)
58 0 : goto bailout;
59 834 : while (top < 256 && top <= length) {
60 822 : list[top] = moduleList[top - 1];
61 822 : top++;
62 : }
63 12 : freeModuleList(moduleList);
64 :
65 846 : for (int k = 0; k < top; k++) {
66 834 : Module s = list[k];
67 214338 : for (int j = 0; j < MAXSCOPE; j++) {
68 213504 : if (s->space[j]) {
69 128727 : for (Symbol t = s->space[j]; t != NULL; t = t->peer) {
70 122895 : if (t->def->stmt[0]->fcnname[0] == '#')
71 12 : continue;
72 122883 : char buf[1024];
73 122883 : (void) fcnDefinition(t->def, getInstrPtr(t->def, 0),
74 : buf, TRUE, buf, sizeof(buf));
75 122883 : char *tt = strstr(buf, "address ");
76 122883 : if (tt) {
77 122871 : *tt = 0;
78 122871 : tt += 8;
79 : }
80 122883 : if (BUNappend(mod, t->def->stmt[0]->modname, false) != GDK_SUCCEED
81 122883 : || BUNappend(fcn, t->def->stmt[0]->fcnname,
82 : false) != GDK_SUCCEED
83 186006 : || BUNappend(com, t->def->help ? t->def->help : "",
84 : false) != GDK_SUCCEED
85 122883 : || BUNappend(sig, buf, false) != GDK_SUCCEED
86 122895 : || BUNappend(adr, tt ? tt : "",
87 : false) != GDK_SUCCEED) {
88 0 : goto bailout;
89 : }
90 : }
91 : }
92 : }
93 : }
94 :
95 12 : *mx = mod->batCacheid;
96 12 : BBPkeepref(mod);
97 12 : *fx = fcn->batCacheid;
98 12 : BBPkeepref(fcn);
99 12 : *sx = sig->batCacheid;
100 12 : BBPkeepref(sig);
101 12 : *ax = adr->batCacheid;
102 12 : BBPkeepref(adr);
103 12 : *cx = com->batCacheid;
104 12 : BBPkeepref(com);
105 12 : (void) mb;
106 12 : return MAL_SUCCEED;
107 :
108 0 : bailout:
109 0 : BBPreclaim(mod);
110 0 : BBPreclaim(fcn);
111 0 : BBPreclaim(sig);
112 0 : BBPreclaim(adr);
113 0 : BBPreclaim(com);
114 0 : throw(MAL, "manual.functions", GDK_EXCEPTION);
115 : }
116 :
117 : #include "mel.h"
118 : mel_func manual_init_funcs[] = {
119 : pattern("manual", "functions", MANUALcreateOverview, false, "Produces a table with all MAL functions known", args(5,5, batarg("mod",str),batarg("fcn",str),batarg("sig",str),batarg("adr",str),batarg("com",str))),
120 : { .imp=NULL }
121 : };
122 : #include "mal_import.h"
123 : #ifdef _MSC_VER
124 : #undef read
125 : #pragma section(".CRT$XCU",read)
126 : #endif
127 329 : LIB_STARTUP_FUNC(init_manual_mal)
128 329 : { mal_module("manual", NULL, manual_init_funcs); }
|