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-01-13 20:07:21 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           6 : MANUALcreateOverview(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      26             : {
      27             :         BAT *mod, *fcn, *sig, *adr, *com;
      28           6 :         bat *mx = getArgReference_bat(stk,pci,0);
      29           6 :         bat *fx = getArgReference_bat(stk,pci,1);
      30           6 :         bat *sx = getArgReference_bat(stk,pci,2);
      31           6 :         bat *ax = getArgReference_bat(stk,pci,3);
      32           6 :         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           6 :         mod = COLnew(0, TYPE_str, 0, TRANSIENT);
      42           6 :         fcn = COLnew(0, TYPE_str, 0, TRANSIENT);
      43           6 :         sig = COLnew(0, TYPE_str, 0, TRANSIENT);
      44           6 :         adr = COLnew(0, TYPE_str, 0, TRANSIENT);
      45           6 :         com = COLnew(0, TYPE_str, 0, TRANSIENT);
      46           6 :         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           6 :         list[top++] = cntxt->usermodule;
      56           6 :         getModuleList(&moduleList, &length);
      57           6 :         if (moduleList == NULL)
      58           0 :                 goto bailout;
      59         444 :         while (top < 256 && top <= length) {
      60         438 :                 list[top] = moduleList[top - 1];
      61         438 :                 top++;
      62             :         }
      63           6 :         freeModuleList(moduleList);
      64             : 
      65         450 :         for (k = 0; k < top; k++) {
      66         444 :                 s = list[k];
      67         444 :                 if (s->space) {
      68      114108 :                         for (j = 0; j < MAXSCOPE; j++) {
      69      113664 :                                 if (s->space[j]) {
      70       81203 :                                         for (t = s->space[j]; t != NULL; t = t->peer) {
      71       78033 :                                                 if (t->def->stmt[0]->fcnname[0] == '#')
      72           6 :                                                         continue;
      73       78027 :                                                 (void) fcnDefinition(t->def, getInstrPtr(t->def, 0), buf, TRUE, buf, sizeof(buf));
      74       78027 :                                                 tt = strstr(buf, "address ");
      75       78027 :                                                 if (tt) {
      76       77451 :                                                         *tt = 0;
      77       77451 :                                                         tt += 8;
      78             :                                                 }
      79      156054 :                                                 if (BUNappend(mod, t->def->stmt[0]->modname, false) != GDK_SUCCEED ||
      80      156054 :                                                         BUNappend(fcn, t->def->stmt[0]->fcnname, false) != GDK_SUCCEED ||
      81      156054 :                                                         BUNappend(com, t->def->help ? t->def->help : "", false) != GDK_SUCCEED ||
      82      156054 :                                                         BUNappend(sig,buf,false) != GDK_SUCCEED ||
      83       78603 :                                                         BUNappend(adr, tt ? tt : "", false) != GDK_SUCCEED) {
      84           0 :                                                         goto bailout;
      85             :                                                 }
      86             :                                         }
      87             :                                 }
      88             :                         }
      89             :                 }
      90             :         }
      91             : 
      92           6 :         BBPkeepref( *mx = mod->batCacheid);
      93           6 :         BBPkeepref( *fx = fcn->batCacheid);
      94           6 :         BBPkeepref( *sx = sig->batCacheid);
      95           6 :         BBPkeepref( *ax = adr->batCacheid);
      96           6 :         BBPkeepref( *cx = com->batCacheid);
      97             :         (void)mb;
      98           6 :         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         255 : LIB_STARTUP_FUNC(init_manual_mal)
     120         255 : { mal_module("manual", NULL, manual_init_funcs); }

Generated by: LCOV version 1.14