LCOV - code coverage report
Current view: top level - monetdb5/modules/mal - manual.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 45 60 75.0 %
Date: 2021-10-13 02:24:04 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : /*
      10             :  * (c) Martin Kersten
      11             :  * This module provides a wrapping of the help function in the .../mal/mal_modules.c
      12             :  * and the list of all MAL functions for analysis using SQL.
      13             :  */
      14             : #include "monetdb_config.h"
      15             : #include "gdk.h"
      16             : #include <time.h>
      17             : #include "mal_resolve.h"
      18             : #include "mal_client.h"
      19             : #include "mal_exception.h"
      20             : #include "mal_debugger.h"
      21             : #include "mal_interpreter.h"
      22             : #include "mal_namespace.h"
      23             : 
      24             : static str
      25          10 : MANUALcreateOverview(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      26             : {
      27             :         BAT *mod, *fcn, *sig, *adr, *com;
      28          10 :         bat *mx = getArgReference_bat(stk,pci,0);
      29          10 :         bat *fx = getArgReference_bat(stk,pci,1);
      30          10 :         bat *sx = getArgReference_bat(stk,pci,2);
      31          10 :         bat *ax = getArgReference_bat(stk,pci,3);
      32          10 :         bat *cx = getArgReference_bat(stk,pci,4);
      33             :         Module s;
      34             :         Module* moduleList;
      35             :         int length;
      36             :         int j, k, top = 0;
      37             :         Symbol t;
      38             :         Module list[256];
      39             :         char buf[BUFSIZ], *tt;
      40             : 
      41          10 :         mod = COLnew(0, TYPE_str, 0, TRANSIENT);
      42          10 :         fcn = COLnew(0, TYPE_str, 0, TRANSIENT);
      43          10 :         sig = COLnew(0, TYPE_str, 0, TRANSIENT);
      44          10 :         adr = COLnew(0, TYPE_str, 0, TRANSIENT);
      45          10 :         com = COLnew(0, TYPE_str, 0, TRANSIENT);
      46          10 :         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          10 :         list[top++] = cntxt->usermodule;
      56          10 :         getModuleList(&moduleList, &length);
      57          10 :         if (moduleList == NULL)
      58           0 :                 goto bailout;
      59         726 :         while (top < 256 && top <= length) {
      60         716 :                 list[top] = moduleList[top - 1];
      61         716 :                 top++;
      62             :         }
      63          10 :         freeModuleList(moduleList);
      64             : 
      65         736 :         for (k = 0; k < top; k++) {
      66         726 :                 s = list[k];
      67         726 :                 if (s->space) {
      68      186582 :                         for (j = 0; j < MAXSCOPE; j++) {
      69      185856 :                                 if (s->space[j]) {
      70      136361 :                                         for (t = s->space[j]; t != NULL; t = t->peer) {
      71      131067 :                                                 if (t->def->stmt[0]->fcnname[0] == '#')
      72          10 :                                                         continue;
      73      131057 :                                                 (void) fcnDefinition(t->def, getInstrPtr(t->def, 0), buf, TRUE, buf, sizeof(buf));
      74      131057 :                                                 tt = strstr(buf, "address ");
      75      131057 :                                                 if (tt) {
      76      130077 :                                                         *tt = 0;
      77      130077 :                                                         tt += 8;
      78             :                                                 }
      79      262114 :                                                 if (BUNappend(mod, t->def->stmt[0]->modname, false) != GDK_SUCCEED ||
      80      262114 :                                                         BUNappend(fcn, t->def->stmt[0]->fcnname, false) != GDK_SUCCEED ||
      81      319881 :                                                         BUNappend(com, t->def->help ? t->def->help : "", false) != GDK_SUCCEED ||
      82      262114 :                                                         BUNappend(sig,buf,false) != GDK_SUCCEED ||
      83      132037 :                                                         BUNappend(adr, tt ? tt : "", false) != GDK_SUCCEED) {
      84           0 :                                                         goto bailout;
      85             :                                                 }
      86             :                                         }
      87             :                                 }
      88             :                         }
      89             :                 }
      90             :         }
      91             : 
      92          10 :         BBPkeepref( *mx = mod->batCacheid);
      93          10 :         BBPkeepref( *fx = fcn->batCacheid);
      94          10 :         BBPkeepref( *sx = sig->batCacheid);
      95          10 :         BBPkeepref( *ax = adr->batCacheid);
      96          10 :         BBPkeepref( *cx = com->batCacheid);
      97             :         (void)mb;
      98          10 :         return MAL_SUCCEED;
      99             : 
     100           0 :   bailout:
     101           0 :         BBPreclaim(mod);
     102           0 :         BBPreclaim(fcn);
     103           0 :         BBPreclaim(sig);
     104           0 :         BBPreclaim(adr);
     105           0 :         BBPreclaim(com);
     106           0 :         throw(MAL, "manual.functions", GDK_EXCEPTION);
     107             : }
     108             : 
     109             : #include "mel.h"
     110             : mel_func manual_init_funcs[] = {
     111             :  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))),
     112             :  { .imp=NULL }
     113             : };
     114             : #include "mal_import.h"
     115             : #ifdef _MSC_VER
     116             : #undef read
     117             : #pragma section(".CRT$XCU",read)
     118             : #endif
     119         259 : LIB_STARTUP_FUNC(init_manual_mal)
     120         259 : { mal_module("manual", NULL, manual_init_funcs); }

Generated by: LCOV version 1.14