0

I created a very simple UDF, compiles fine but when I try to use it, it gives the following error:

root@chii:/data/database/bot# /opt/firebird/bin/isql chii.fdb
Database: chii.fdb, User: SYSDBA
SQL> select YKUDF_PERLWRAPPER('/bin/ls' , '-al') from rdb$database;
/opt/firebird/bin/isql: symbol lookup error: /opt/firebird /UDF/YKUDFPerlWrapper: undefined symbol: ib_util_malloc

This is my sql declaration:

declare external function YKUDF_PERLWRAPPER
cstring(1024), cstring(1024)
returns cstring(16384) free_it
entry_point 'perlwrapper' module_name '/opt/firebird/UDF/YKUDFPerlWrapper';

my function.c:

#include <stdio.h>
#include <ctype.h>
#include "functions.h"
#include "ibase.h"
#include "ib_util.h"


extern void * ib_util_malloc(long);


char * perlwrapper (file, input)
     char * file;
     int * input;
{

  FILE *fp;
  char merged[1024];

  strcpy(merged, file);
  strcat(merged, " \"");
  strcat(merged, input);
  strcat(merged, "\"");

  fp = popen(merged, "r");    /* Issue the command.   */


  /* Read a line      */
  char line[1024];      /* line of data from unix command*/
  char output[16382];
  strcpy(output," ");

  while ( fgets( line, sizeof line, fp))
  {
    strcat(output,line);
  }
  pclose(fp);

  int i;
  int len = strlen(output);
  char * result = (char *) ib_util_malloc (len + 1);

  for (i = 0 ; i < len ; i++)
    result[i] = output[i];
  result[i] = (char) 0;

  return result;
}

my function.h:

#define PROTO_LIST(list) ()

char * perlwrapper PROTO_LIST ((char *, char *));

And my compiler:

gcc functions.c -DIB60 -fpic -O -c -w -shared -I/opt/firebird/include -L/opt/firebird/lib -lib_util -lstdc++ -lm -lc -o functions.o
ld functions.o -o YKUDFPerlWrapper -G -Bsymbolic -lgds -lm -lc 

Tried to search the net about ib_util_malloc but most questions were left unanswered.

Mark Rotteveel
  • 82,132
  • 136
  • 114
  • 158
Sophia
  • 82
  • 10
  • I've never written UDFs, but I think you need to remove the line `extern void * ib_util_malloc(long);` because it overwrites the definition in `ib_util.h`. – Mark Rotteveel Jun 25 '16 at 17:54
  • My original code doesn't have that line, but a forum post said to try putting that, and still doesn't work. Thanks for trying to help though. Because of time constraint, I just used a workaround which doesn't require allocating memory from the external code and instead allocated it from the function call from within firebird. – Sophia Jun 27 '16 at 08:42
  • I suggest you also post a message on the firebird-support mailinglist; you might get more eyes on your problem. – Mark Rotteveel Jun 27 '16 at 09:19

0 Answers0