Thread: 'PG_PRINTF_ATTRIBUTE' is an unrecognized format function type

'PG_PRINTF_ATTRIBUTE' is an unrecognized format function type

From
Andrea spanu
Date:
I'am began with a server side program on Windows with MinGW, and after linked everything I get this warning 'PG_PRINTF_ATTRIBUTE' is an unrecognized format function type' , but worst It doesn't recognize the functions declared as extern. Among the others palloc() and pfree(), or  the macro ereport()  Or better they doesn't get linked if I call those function from the server the server crashes.
the search directories are the followings:

Compiler:
C:\Program Files (x86)\PostgreSQL\9.6\include
C:\Program Files (x86)\PostgreSQL\9.6\include\server
C:\Program Files (x86)\PostgreSQL\9.6\include\server\win32
linker:
C:\Program Files (x86)\PostgreSQL\9.6\lib
C:\Program Files (x86)\PostgreSQL\9.6\bin

I get those libraryes linked:
C:\Program Files (x86)\PostgreSQL\9.6\lib\postgres.lib
C:\Program Files (x86)\PostgreSQL\9.6\lib\libpq.lib

It is not matter of code bacause also the tutorial example complex.c crashes.
To allow me to write the remaining code, I hacked as follow:

#define palloc(a) malloc(a)

but since I cannot free it, there is the risk of memory leakage.
I would ask if I missing some library or some path.

Then, but I do not know if the problems are related,
I convert the input cstring, I cannot use the macros for the varlena struct or the server also crashes:

typedef struct varlena Node;


PG_FUNCTION_INFO_V1(node_in);
Datum
node_in(PG_FUNCTION_ARGS)
{

    /*if (PG_NARGS()==0 )  //this is quoted since if call the ereport the server crashes
            ereport(ERROR,
                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                 errmsg("invalid input syntax for complex")));
*/
    char * s=PG_GETARG_CSTRING(0);

    int32 sz= strlen(s)+VARHDRSZ+1;
    Node *res=palloc(sz); ///this is currently replaced by malloc() through a macro

    SET_VARSIZE(res, sz-VARHDRSZ-1);
    strcpy(VARDATA(res),s);

    if (validate(res)==0)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                 errmsg("invalid input syntax for complex")));

    PG_RETURN_TEXT_P(res);
}

But for the output function, if I use PG_GETARG_TEXT_P(0),
the server also crashes
Currently I hacked as follow, all the quoted rows are the firsts attemps:

Datum
node_out(PG_FUNCTION_ARGS)
{
    Node* txt = PG_GETARG_CSTRING(0);
    /*char * targ=palloc(VARSIZE(res)-VARHDRSZ+1);
    strcpy(targ,VARDATA(res));*/
    PG_RETURN_CSTRING(txt->vl_dat);
}


Some Ideas?

Re: 'PG_PRINTF_ATTRIBUTE' is an unrecognized format function type

From
Tom Lane
Date:
Andrea spanu <spanu_andrea@yahoo.it> writes:
> I'am began with a server side program on Windows with MinGW, and after linked everything I get this warning
'PG_PRINTF_ATTRIBUTE'is an unrecognized format function type' , 

There's something messed up about your installation then.  My first guess
is that you're trying to use MinGW's gcc to build an extension, but
against a server that was built with MSVC and therefore the pg_config.h
file is meant for use with MSVC not gcc.  That's not going to work.
You should build the server and your extension with the same toolchain.

It may be that all the other issues you report trace to that same cause,
but in any case you should fix that first and then see what problems
remain.

            regards, tom lane