Thread: Postgres 8.3.3 & MSVC2005 (full edition)

Postgres 8.3.3 & MSVC2005 (full edition)

From
el dorado
Date:
Hello.
Have I an opportunity to get working dll using MSVC2005 (full edition) for compilation at all?
I just tried to compile the following code. This is full text. Project options are below in the letter.
-----------------------------------------
#include "postgres.h"
#include "fmgr.h"
#include "executor/executor.h"
#include "utils/timestamp.h"
#include "utils/builtins.h"
#include "utils/formatting.h"

#define BUILDING_DLL 1

#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif

PG_FUNCTION_INFO_V1(add_one);

Datum
add_one(PG_FUNCTION_ARGS)
{
    int32   arg = PG_GETARG_INT32(0);
    PG_RETURN_INT32(arg + 1);
}
-------------------------------------------------------
CREATE FUNCTION "service"."add_one"() RETURNS integer
     AS '$libdir/my_dll', 'pg_finfo_add_one'
     LANGUAGE C STRICT;

Result:
Query OK (0,11 sec)
Return Value: 32593236

Even if I do the following:
PG_FUNCTION_INFO_V1(add_one);

Datum
add_one(PG_FUNCTION_ARGS)
{
    PG_RETURN_INT32(10);
}

I get the same result - Return Value: 32593236

Have I forget some important option? Or I can't use the FULL version for compilation at all - only express edition?

By the way - there is a directory 'D:\pgsql83\include\server\port\win32_msvc'. But I can't use it instead of
'D:\pgsql83\include\server\port\win32'(should I ?) - there is an error due to lack of file 'netdb.h' and some others in
thisdirectory. 


Thanks in advance, Marina.


-----Original Message-----
From: el dorado <do_ra_do@mail.ru>
To: pgsql-general@postgresql.org
Date: Fri, 18 Jul 2008 11:17:51 +0400
Subject: [GENERAL] C-procedure crashed in Postgres 8.3.3 when using 'text' variable (WinXP) - additional

>
> Hello.
> I'm trying to create a C-procedure returning text variable - again :).
> Postgres 8.3.3 (standard binaries - so built by means of MSVC), WinXP SP2.
> I also use MSVC 2005 for compilation my library.
> Configuration type - Dynamic Library (.dll)
> Additional include directories - D:\pgsql83\include;D:\pgsql83\include\server;D:\pgsql83\include\server\port\win32
> Additional library directories - D:\pgsql83\lib
> Additional dependencies - postgres.lib
> Compile as C Code (/TC)
> Detect 64-bit portability issues - No
>
> So, here is the code:
> --------------------------------------------------
> include "postgres.h"
> #include "fmgr.h"
> #include "executor/executor.h"
> #include "utils/timestamp.h"
> #include "utils/builtins.h"
> #include "utils/formatting.h"
>
> #ifdef PG_MODULE_MAGIC
> PG_MODULE_MAGIC;
> #endif
>
> #define GET_TEXT(cstrp) DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstrp)))
>
> PG_FUNCTION_INFO_V1(getTimeFromApplication);
> Datum
> getTimeFromApplication(PG_FUNCTION_ARGS)
> {
>     PG_RETURN_TEXT_P(GET_TEXT("success"));
> }
>
> I can compile it and get the library, but there are some warnings:
> 1>d:\pgsql83\getstring\c_getstring.c(10) : warning C4273: 'Pg_magic_func' : inconsistent dll linkage
> 1>        d:\pgsql83\getstring\c_getstring.c(10) : see previous definition of 'Pg_magic_func'
> 1>d:\pgsql83\getstring\c_getstring.c(24) : warning C4273: 'pg_finfo_getTimeFromApplication' : inconsistent dll
linkage
> 1>        d:\pgsql83\getstring\c_getstring.c(24) : see previous definition of 'pg_finfo_getTimeFromApplication'
> -------------------------------------------------------
> Then I put the library into 'lib' directory and create the stored procedure:
> CREATE OR REPLACE FUNCTION "service"."get_app_time" () RETURNS text AS
>      '$libdir/getstring', 'pg_finfo_getTimeFromApplication'
>      LANGUAGE C STRICT;
>
> Then I try to run it:
> select * from "service"."get_app_time" ();
>
> And get an error:
> ERROR:  invalid memory alloc request size 4294967293
>
> What did I wrong?
>
> Thanks in advance, Marina.
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

Re: Postgres 8.3.3 & MSVC2005 (full edition)

From
Craig Ringer
Date:
el dorado wrote:

> Have I forget some important option? Or I can't use the FULL version for compilation at all - only express edition?

They use the same compiler, and will produce compatible object code, so
the full or express editions will be fine.

> By the way - there is a directory 'D:\pgsql83\include\server\port\win32_msvc'. But I can't use it instead of
'D:\pgsql83\include\server\port\win32'(should I ?) - there is an error due to lack of file 'netdb.h' and some others in
thisdirectory. 

That probably won't work well. IIRC it is necessary to put the
win32_msvc directory first in the header search path, followed by the
win32 directory.

 From memory I had to create a dummy header for libintl as well - it's
not really needed for basic plugins, but is required for compilation of
the Pg headers. That dummy header should be floating around in the
mailing list archives.

There were very similar issues discussed some months ago, so I strongly
recommend that you search the archives.

On a side note, personally I think the `port/win32' subdir should be
renamed to `port/win32_mingw' and any truly shared files should be put
in `port/win32' ... but that's just me.

--
Craig Ringer