Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-07

UDF + FreePascal + Firebird 1.5

22 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Guto

I created a UDF, just to test and try to discovery what's wrong. I ill explain what I did step by step.

I created a teste.pas file like this:

----

library teste;
function intmax(a,b: Integer): Integer; stdcall; export;
begin
 if a>b then intmax:=a else intmax:=b;
end;
exports
 intmax;
end.

----

I compile with freepascal:
fpc teste

I moved to udf directory on firebird:
mv libteste.so /usr/local/firebird/UDF/

I changed permissions:
cd /usr/local/firebird/UDF
chown firebird:firebird libteste.so
chmod 550 libteste.so

I declared UDF:

DECLARE EXTERNAL FUNCTION INTMAX
INTEGER,
INTEGER
RETURNS INTEGER BY VALUE
ENTRY_POINT 'intmax' MODULE_NAME 'teste';

I test it:
select intmax(1,2) from rdb$database;

And I got this error message:
Invalid token.
invalid request BLR at offset 60.
function INTMAX is not defined.
module name or entrypoint could not be found.

Does anyone have any ideas?

Thanks in advance,
Guto

Reply by email

Marco van de Voort
to Guto
Show quoted text 51 lines
I created a UDF, just to test and try to discovery what's wrong. I ill explain what I did step by step. I created a teste.pas file like this: ---- library teste; function intmax(a,b: Integer): Integer; stdcall; export; begin if a>b then intmax:=a else intmax:=b; end; exports intmax; end. ---- I compile with freepascal: fpc teste I moved to udf directory on firebird: mv libteste.so /usr/local/firebird/UDF/ I changed permissions: cd /usr/local/firebird/UDF chown firebird:firebird libteste.so chmod 550 libteste.so I declared UDF: DECLARE EXTERNAL FUNCTION INTMAX INTEGER, INTEGER RETURNS INTEGER BY VALUE ENTRY_POINT 'intmax' MODULE_NAME 'teste'; I test it: select intmax(1,2) from rdb$database; And I got this error message: Invalid token. invalid request BLR at offset 60. function INTMAX is not defined. module name or entrypoint could not be found. Does anyone have any ideas?

Are you 100% sure it doesn't have to be cdecl; instead of stdcall on *nix?

Reply by email

Guto
to Marco van de Voort

I tried with both, but I get the same error...

I wrote the same lib in C, and works fine, but I wouldnt like to maintain a C version of all my libraries (actually written in Delphi)...

I believe thats a directive of something like that I must to use to works in FreePascal.

Any idea?

Thanks,
Guto

Marco van de Voort wrote 60 lines
> I created a UDF, just to test and try to discovery what's wrong. > I ill explain what I did step by step. > > I created a teste.pas file like this: > > ---- > > library teste; > > function intmax(a,b: Integer): Integer; stdcall; export; > begin > if a>b then intmax:=a else intmax:=b; > end; > > exports > intmax; > > end. > > ---- > > I compile with freepascal: > fpc teste > > I moved to udf directory on firebird: > mv libteste.so /usr/local/firebird/UDF/ > > I changed permissions: > cd /usr/local/firebird/UDF > chown firebird:firebird libteste.so > chmod 550 libteste.so > > I declared UDF: > > DECLARE EXTERNAL FUNCTION INTMAX > INTEGER, > INTEGER > RETURNS INTEGER BY VALUE > ENTRY_POINT 'intmax' MODULE_NAME 'teste'; > > I test it: > select intmax(1,2) from rdb$database; > > And I got this error message: > Invalid token. > invalid request BLR at offset 60. > function INTMAX is not defined. > module name or entrypoint could not be found. > > Does anyone have any ideas? > Are you 100% sure it doesn't have to be cdecl; instead of stdcall on *nix? _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Guto

Reply by email

Marco van de Voort
to Guto
Show quoted text 5 lines
I tried with both, but I get the same error... I wrote the same lib in C, and works fine, but I wouldnt like to maintain a C version of all my libraries (actually written in Delphi)...

How is the C stuff defined? With stdcall or cdecl?

I believe thats a directive of something like that I must to use to works in FreePascal.

Maybe it needs pic or so

Reply by email

Guto
to Marco van de Voort

I believe, thats "cdecl",
this is not explicit, and I get this example from
http://www.firebirdsql.org/index.php?op=useful&id=deatz_udf#linux

the function is:

int modulo(int *, int *);

int modulo(a, b)

     int *a;
     int *b;

{
if (*b == 0)

    return -1;
  else
    return *a % *b;

}

and I compiled with:

gcc -c -O -fpic -fwritable-strings testec.c
ld -G <your udf>.o -lm -lc -o testec.so
cp testec.so /usr/local/firebird/UDF

and I declared with:

declare external function f_Modulo
integer, integer
returns
integer by value

  entry_point 'modulo' module_name 'name of shared library';
Marco van de Voort wrote 19 lines
> I tried with both, but I get the same error... > > I wrote the same lib in C, and works fine, but I wouldnt like to > maintain a C version of all my libraries (actually written in > Delphi)... How is the C stuff defined? With stdcall or cdecl? > I believe thats a directive of something like that I must to use to > works in FreePascal. Maybe it needs pic or so _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Guto

Reply by email

Unknown author
to Guto: I tried with both, but I get the same error... I wrote the same lib in C, and works fine,…
Guto wrote
I tried with both, but I get the same error...

Nevertheless, the library can be loaded and used without problems by an FPC program, I tested this:

program testee;
function intmax (A,B : integer): integer; stdcall; external 'libteste' name
'intmax';
begin
  Writeln('Intmax 1,2 : ',intmax(1,2));
end.

And it correctly prints 2.

So the error must be in Firebird somewhere.

- I am confused about the changing of owner and permissions. Have you tried changing it to root, with permissions 755 ?

- About calling conventions:
Firebird will definitely expect 'cdecl' on Linux, but 'stdcall' on Windows.

A warning: 'integer' in standard FPC mode is 2 bytes, not 4, which is what Firebird expects. I suggest you add a {$mode objfpc} at the start of your code, which will make integer 4 bytes.

Show quoted text 9 lines
> > mv libteste.so /usr/local/firebird/UDF/ > > > > I changed permissions: > > cd /usr/local/firebird/UDF > > chown firebird:firebird libteste.so > > chmod 550 libteste.so > > > > I declared UDF: > >

This is the mistake you made:

DECLARE EXTERNAL FUNCTION INTMAX
INTEGER,
INTEGER
RETURNS INTEGER BY VALUE
ENTRY_POINT 'intmax' MODULE_NAME 'libteste';

You must explicitly add the 'lib'; firebird does not add it itself. Look at the standard libraries, they also miss the 'lib' prefix.

if you change it to the above, (with calling convention cdecl) it works correctly.

Michael.

Show quoted text 28 lines
> > > > I test it: > > select intmax(1,2) from rdb$database; > > > > And I got this error message: > > Invalid token. > > invalid request BLR at offset 60. > > function INTMAX is not defined. > > module name or entrypoint could not be found. > > > > Does anyone have any ideas? > > > > Are you 100% sure it doesn't have to be cdecl; instead of stdcall on *nix? > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > -- Guto _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Guto
to Unknown author
- I am confused about the changing of owner and permissions. Have you tried changing it to root, with permissions 755 ?

I copied the permissions from other firebird standard libraries...

Whell, Im do this now (and the error remains):

contents of teste.pas:

{$mode objfpc}
library teste;
function intmax(a,b: Integer): Integer; cdecl; export;
begin
  if a>b then intmax:=a else intmax:=b;
end;
exports
  intmax;
end.

-----

# fpc teste.pas
# mv libteste.so teste.so
# mv teste.so /usr/local/firebird/UDF/

(I not change the permissions this time)
# ls -l teste.so
-rwxr-xr-x 1 root wheel 223551 24 Jul 13:56 teste.so*

in the IBExpert:

DECLARE EXTERNAL FUNCTION INTMAX
INTEGER,
INTEGER
RETURNS INTEGER BY VALUE
ENTRY_POINT 'intmax' MODULE_NAME 'teste';

select intmax(3, 2) from rdb$database;

and the error:
Invalid token.
invalid request BLR at offset 60.
function INTMAX is not defined.
module name or entrypoint could not be found.

Reply by email

Marco van de Voort
to Guto
Show quoted text 9 lines
intmax; end. ----- # fpc teste.pas # mv libteste.so teste.so # mv teste.so /usr/local/firebird/UDF/

try:

fpc teste.pp -Xp
ld -shared -soname libteste.so.1 -o libteste.so.1.0 -lc teste.o

Reply by email

Unknown author
to Guto: I copied the permissions from other firebird standard libraries... Whell, Im do this now…
Guto wrote 42 lines
> - I am confused about the changing of owner and permissions. Have you tried > changing it to root, with permissions 755 ? I copied the permissions from other firebird standard libraries... Whell, Im do this now (and the error remains): contents of teste.pas: {$mode objfpc} library teste; function intmax(a,b: Integer): Integer; cdecl; export; begin if a>b then intmax:=a else intmax:=b; end; exports intmax; end. ----- # fpc teste.pas # mv libteste.so teste.so # mv teste.so /usr/local/firebird/UDF/ (I not change the permissions this time) # ls -l teste.so -rwxr-xr-x 1 root wheel 223551 24 Jul 13:56 teste.so* in the IBExpert: DECLARE EXTERNAL FUNCTION INTMAX INTEGER, INTEGER RETURNS INTEGER BY VALUE ENTRY_POINT 'intmax' MODULE_NAME 'teste'; select intmax(3, 2) from rdb$database;

Very strange. I tried it here, and it works fine for me. I have Firebird 1.5 installed, so....

What version of FPC did you use ?

Michael.

Reply by email

Guto
to Unknown author
What version of FPC did you use ?

1.9.2

Show quoted text 60 lines
On Sat, 24 Jul 2004, Guto wrote: > > - I am confused about the changing of owner and permissions. Have you tried > > changing it to root, with permissions 755 ? > > I copied the permissions from other firebird standard libraries... > > Whell, Im do this now (and the error remains): > > contents of teste.pas: > > {$mode objfpc} > > library teste; > > function intmax(a,b: Integer): Integer; cdecl; export; > begin > if a>b then intmax:=a else intmax:=b; > end; > > exports > intmax; > > end. > > ----- > > # fpc teste.pas > # mv libteste.so teste.so > # mv teste.so /usr/local/firebird/UDF/ > > (I not change the permissions this time) > # ls -l teste.so > -rwxr-xr-x 1 root wheel 223551 24 Jul 13:56 teste.so* > > in the IBExpert: > > DECLARE EXTERNAL FUNCTION INTMAX > INTEGER, > INTEGER > RETURNS INTEGER BY VALUE > ENTRY_POINT 'intmax' MODULE_NAME 'teste'; > > select intmax(3, 2) from rdb$database; Very strange. I tried it here, and it works fine for me. I have Firebird 1.5 installed, so.... What version of FPC did you use ? Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Guto

Reply by email

Guto
to Marco van de Voort
Marco van de Voort wrote 11 lines
> On Sat, 24 Jul 2004 19:43:45 +0200 (CEST), Marco van de Voort > wrote: > > > try: > > > > fpc teste.pp -Xp > > ld -shared -soname libteste.so.1 -o libteste.so.1.0 -lc teste.o > > Whell, doesnt work too... Well, what doesn't work.

I receive the same errors on Firebird that I received before: "module name or entrypoint could not be found"

Thanks,

Guto

Reply by email

Michael Van Canneyt
to Guto: On Sun, 25 Jul 2004 00:12:15 +0200 (CEST), Do you test on FreeBSD? I tried with…
Guto wrote 11 lines
On Sun, 25 Jul 2004 00:12:15 +0200 (CEST), wrote: > Very strange. I tried it here, and it works fine for me. I have Firebird 1.5 > installed, so.... > > What version of FPC did you use ? > > Michael. Do you test on FreeBSD? I tried with FreePascal 1.0.10, 1.9.2 and 1.9.4, always with the same results...

I tested on Linux. I have no FreeBSD.

Michael.

Reply by email

Michael Van Canneyt
to Guto: On Thu, 29 Jul 2004 16:23:51 +0200 (CEST), Marco van de Voort I receive the same errors…
Guto wrote 16 lines
On Thu, 29 Jul 2004 16:23:51 +0200 (CEST), Marco van de Voort wrote: > > On Sat, 24 Jul 2004 19:43:45 +0200 (CEST), Marco van de Voort > > wrote: > > > > > try: > > > > > > fpc teste.pp -Xp > > > ld -shared -soname libteste.so.1 -o libteste.so.1.0 -lc teste.o > > > > Whell, doesnt work too... > > Well, what doesn't work. I receive the same errors on Firebird that I received before: "module name or entrypoint could not be found"

Can you at least dump the entry points of the library ? if you see the maxint (or was it intmax) listed there, you know that it is firebird which does not find the library.

Michael.

Reply by email

Guto
to Michael Van Canneyt

i list the entry points with nm -g
the entry point was there....

I really dont know whats happen...

Guto

Michael Van Canneyt wrote 35 lines
On Thu, 29 Jul 2004, Guto wrote: > On Thu, 29 Jul 2004 16:23:51 +0200 (CEST), Marco van de Voort > wrote: > > > On Sat, 24 Jul 2004 19:43:45 +0200 (CEST), Marco van de Voort > > > wrote: > > > > > > > try: > > > > > > > > fpc teste.pp -Xp > > > > ld -shared -soname libteste.so.1 -o libteste.so.1.0 -lc teste.o > > > > > > Whell, doesnt work too... > > > > Well, what doesn't work. > > I receive the same errors on Firebird that I received before: > "module name or entrypoint could not be found" Can you at least dump the entry points of the library ? if you see the maxint (or was it intmax) listed there, you know that it is firebird which does not find the library. Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Guto

Reply by email

Unknown author
to Guto
Guto wrote
i list the entry points with nm -g the entry point was there.... I really dont know whats happen...

Did you try loading the library explicitly in a FPC test program and calling the function (I believe I posted a program where this was done)

Because if that works, then it is a Firebird issue.

Michael.

Reply by email

Guto
to Unknown author

I used in a FPC program and in a C program and works... I write a UDF in C and used it on Firebird and works too... Only not works a FPC UDF in Firebird...
I really dont know whats happen...
I believe that FPC dont generate a lib in a format that Firebird understands....

Thanks
Guto

Show quoted text 22 lines
On Thu, 29 Jul 2004, Guto wrote: > i list the entry points with nm -g > the entry point was there.... > > I really dont know whats happen... Did you try loading the library explicitly in a FPC test program and calling the function (I believe I posted a program where this was done) Because if that works, then it is a Firebird issue. Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Guto

Reply by email

Unknown author
to Guto
Guto wrote 5 lines
I used in a FPC program and in a C program and works... I write a UDF in C and used it on Firebird and works too... Only not works a FPC UDF in Firebird... I really dont know whats happen... I believe that FPC dont generate a lib in a format that Firebird understands....

This is not correct, because I have a working version here.

Have you tried writing the same library using C and see if that works ?

Michael.

Reply by email