Hello everyone
I am trying to integrate two server side test functions with Postgres the first
one, nimAddOne (int): int works fine integrate it like this:
# AddOne adds one to the given arg and retuns it
proc nimAddOne (i: cint): cint {.exportc.} =
result = i + 1
Run
I made the call from C this way:
#include "postgres.h"
#include "fmgr.h"
#undef HAVE_STDINT_H
#include "converter.h"
PG_FUNCTION_INFO_V1 (c_addone);
Datum
c_addone (PG_FUNCTION_ARGS)
{
int32 arg = PG_GETARG_INT32 (0);
int32 result = nimAddOne (arg);
PG_RETURN_INT32 (result);
}
Run
But when I pass strings to another function like this:
# ConcatName concat name and last name
proc nimConcatName (name, last: cstring): cstring {.exportc.} =
var r: cstring
r = $ name & "" & $ last
result = r
Run
And calling it from C like this
#include "postgres.h"
#include "fmgr.h"
#include "utilities.h"
#undef HAVE_STDINT_H
#include "converter.h"
PG_FUNCTION_INFO_V1 (c_fullname);
Datum
c_fullname (PG_FUNCTION_ARGS)
{
text * ptrName = PG_GETARG_TEXT_PP (0);
text * ptrLast = PG_GETARG_TEXT_PP (1);
const char * name = GetStringFromText (ptrName);
const char * last = GetStringFromText (ptrLast);
char * result = nimConcatName ((char *) name, (char *) last);
elog (INFO, "% s", result);
text * ptrResult = (text *) GetTextFromString (result);
PG_RETURN_TEXT_P (ptrResult);
}
Run
Postgres server goes down hopelessly
Could you tell me what I do wrong in the second function?
Thank you!
NOTES: "converter.h" contains the base NIM types after compiling the
"converter.nim" file that contains both functions