Subject | Re: [ib-support] malloc / free_it questions (was: Using UDF: "Connection Lost to Database") |
---|---|
Author | Frank Schlottmann-Goedde |
Post date | 2002-11-10T11:31:25Z |
Frank Ingermann schrieb:
it is much safer to use 'RETURNS PARAMETER X' as FB/IB allocates and
disposes the necessary memory for you.
Very simple example: (Note the declaration as procedure, as the result
is returned in the third parameter.)
...
procedure str_cat(a,b,buf:pchar);cdecl;export;
begin
strcopy(buf,a);
strcat(buf,b);
end;
...
exports
str_cat name 'str_cat';
SQL-Declaration
/* concatenates the two input strings, null values are
handled as empty strings */
DECLARE EXTERNAL FUNCTION str_cat
cstring(254),cstring(254),cstring(512)
RETURNS PARAMETER 3
ENTRY_POINT 'str_cat' MODULE_NAME 'libfpc_udf_str';
and usage:
SELECT
RDB$SECURITY_CLASS||'test' as test_Returning_Null,
str_cat(RDB$SECURITY_CLASS,'test') as test_Cat,
str_cat('Free',' Pascal')
FROM RDB$DATABASE;
Frank
--
"Fascinating creatures, phoenixes, they can carry immensely heavy loads,
their tears have healing powers and they make highly faithful pets."
- J.K. Rowling
> Hi Raymond,Avoid it if possible. You will need ib_util to use it,
>
> Raymond Kennington wrote:
>
>>>declare external function f_lrTrim
>>> cstring(254)
>>> returns
>>> cstring(254) /* free_it */
>>> entry_point 'lrTrim' module_name 'FreeUDFLib.dll';
>>
>>Why is /* free_it */ commented out?
it is much safer to use 'RETURNS PARAMETER X' as FB/IB allocates and
disposes the necessary memory for you.
Very simple example: (Note the declaration as procedure, as the result
is returned in the third parameter.)
...
procedure str_cat(a,b,buf:pchar);cdecl;export;
begin
strcopy(buf,a);
strcat(buf,b);
end;
...
exports
str_cat name 'str_cat';
SQL-Declaration
/* concatenates the two input strings, null values are
handled as empty strings */
DECLARE EXTERNAL FUNCTION str_cat
cstring(254),cstring(254),cstring(512)
RETURNS PARAMETER 3
ENTRY_POINT 'str_cat' MODULE_NAME 'libfpc_udf_str';
and usage:
SELECT
RDB$SECURITY_CLASS||'test' as test_Returning_Null,
str_cat(RDB$SECURITY_CLASS,'test') as test_Cat,
str_cat('Free',' Pascal')
FROM RDB$DATABASE;
Frank
--
"Fascinating creatures, phoenixes, they can carry immensely heavy loads,
their tears have healing powers and they make highly faithful pets."
- J.K. Rowling