Thread: C functions, dll, server fall down
Hi there Need help, I just took the example from Postgres help, code: #include "postgres.h" #include "fmgr.h" #ifdef PG_MODULE_MAGIC PG_MODULE_MAGIC; #endif PG_FUNCTION_INFO_V1(add_one); __declspec (dllexport) Datum add_one(PG_FUNCTION_ARGS) { int32 arg = PG_GETARG_INT32(0); PG_RETURN_INT32(arg + 1); } PG_FUNCTION_INFO_V1(fo); __declspec (dllexport) Datum fo(PG_FUNCTION_ARGS) { float8 arg = PG_GETARG_FLOAT8(0); PG_RETURN_FLOAT8(arg+1); } CREATE OR REPLACE FUNCTION "public"."add_one_f"(double precision) RETURN double precision AS 'dll_c.dll','fo' LANGUAGE C STRICT Select add_one_f(99) server closed the connection unexpectedly This probably means the server terminated abnormally before OR while processing the request. Server falling down in a simple function. WinXP, server - Postgres 8.3, binaries for compile dll - 8.3.5 build in Dev-cpp (mingw) PS. Function for int32( add_one(integer) ) is working -- View this message in context: http://old.nabble.com/C-functions%2C-dll%2C-server-fall-down-tp26710234p26710234.html Sent from the PostgreSQL - general mailing list archive at Nabble.com.
On Wed, Dec 9, 2009 at 8:33 AM, AlexeyChe <alexey.chernushev@gmail.com> wrote: > > Hi there > Need help, I just took the example from Postgres help, code: > > #include "postgres.h" > #include "fmgr.h" > > #ifdef PG_MODULE_MAGIC > PG_MODULE_MAGIC; > #endif > > PG_FUNCTION_INFO_V1(add_one); > > __declspec (dllexport) Datum add_one(PG_FUNCTION_ARGS) > { > int32 arg = PG_GETARG_INT32(0); > > PG_RETURN_INT32(arg + 1); > } > > PG_FUNCTION_INFO_V1(fo); > > __declspec (dllexport) Datum fo(PG_FUNCTION_ARGS) > { > float8 arg = PG_GETARG_FLOAT8(0); > > PG_RETURN_FLOAT8(arg+1); > } > > > > CREATE OR REPLACE FUNCTION "public"."add_one_f"(double precision) RETURN > double precision AS > 'dll_c.dll','fo' > LANGUAGE C STRICT > > Select add_one_f(99) > > > server closed the connection unexpectedly > This probably means the server terminated abnormally > before OR while processing the request. > > Server falling down in a simple function. > WinXP, server - Postgres 8.3, binaries for compile dll - 8.3.5 > build in Dev-cpp (mingw) > > PS. Function for int32( add_one(integer) ) is working hm. I wonder if this is confusion between value/reference datums. Can you do a quick check to see exactly where it's crashing (either before you get into the function, at the getarg, or in the return)? you can elog(WARNING, msg) to print out debug info from inside the function. merlin
>hm. I wonder if this is confusion between value/reference datums. Can >you do a quick check to see exactly where it's crashing (either before >you get into the function, at the getarg, or in the return)? > >you can elog(WARNING, msg) to print out debug info from inside the function. > >merlin It's crashing exactly in the return At first time I had some problem with linking dll - linker could not found function "PG_RETURN_FLOAT8" - undefined reference to `Float8GetDatum' but I had solve this problem with adding "c:\pgsql\lib"-lpostgres Maybe I was wrong in this? -- View this message in context: http://old.nabble.com/C-functions%2C-dll%2C-server-fall-down-tp26710234p26810029.html Sent from the PostgreSQL - general mailing list archive at Nabble.com.
>hm. I wonder if this is confusion between value/reference datums. Can >you do a quick check to see exactly where it's crashing (either before >you get into the function, at the getarg, or in the return)? > >you can elog(WARNING, msg) to print out debug info from inside the function. > >merlin It's crashing exactly in the return At first time I had some problem with linking dll - linker could not found function "PG_RETURN_FLOAT8" - undefined reference to `Float8GetDatum' but I had solve this problem with adding "c:\pgsql\lib"-lpostgres Maybe I was wrong in this? -- View this message in context: http://old.nabble.com/C-functions%2C-dll%2C-server-fall-down-tp26710234p26810029.html Sent from the PostgreSQL - general mailing list archive at Nabble.com.