error when create dll for postgres‏

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

error when create dll for postgres‏

eehab hamzeh


hello, thanks for your help.
i was being able to create the lib for the first function as below. the compiler work when the variable are int, if i declare any other variable like below, i start to recive erros. please see below the code and the recieved errors

#include "postgres.h"
#include <string.h>
#include "fmgr.h"

#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif

/* by value */

PG_FUNCTION_INFO_V1(add_one);
         
Datum
add_one(PG_FUNCTION_ARGS)
{
    int32   arg = PG_GETARG_INT32(0);

    PG_RETURN_INT32(arg + 1);
}

/* by reference, fixed length */

PG_FUNCTION_INFO_V1(add_one_float8);

Datum
add_one_float8(PG_FUNCTION_ARGS)
{
    /* The macros for FLOAT8 hide its pass-by-reference nature. */
    float8   arg = PG_GETARG_FLOAT8(0);

    PG_RETURN_FLOAT8(arg + 1.0);
}

PG_FUNCTION_INFO_V1(makepoint);

Datum
makepoint(PG_FUNCTION_ARGS)
{
    /* Here, the pass-by-reference nature of Point is not hidden. */
    Point     *pointx = PG_GETARG_POINT_P(0);
    Point     *pointy = PG_GETARG_POINT_P(1);
    Point     *new_point = (Point *) palloc(sizeof(Point));

    new_point->x = pointx->x;
    new_point->y = pointy->y;
       
    PG_RETURN_POINT_P(new_point);
}

/* by reference, variable length */

PG_FUNCTION_INFO_V1(copytext);

Datum
copytext(PG_FUNCTION_ARGS)
{
    text     *t = PG_GETARG_TEXT_P(0);
    /*
     * VARSIZE is the total size of the struct in bytes.
     */
    text     *new_t = (text *) palloc(VARSIZE(t));
    VARATT_SIZEP(new_t) = VARSIZE(t);
    /*
     * VARDATA is a pointer to the data region of the struct.
     */
    memcpy((void *) VARDATA(new_t), /* destination */
           (void *) VARDATA(t),     /* source */
           VARSIZE(t)-VARHDRSZ);    /* how many bytes */
    PG_RETURN_TEXT_P(new_t);
}

PG_FUNCTION_INFO_V1(concat_text);

Datum
concat_text(PG_FUNCTION_ARGS)
{
    text  *arg1 = PG_GETARG_TEXT_P(0);
    text  *arg2 = PG_GETARG_TEXT_P(1);
    int32 new_text_size = VARSIZE(arg1) + VARSIZE(arg2) - VARHDRSZ;
    text *new_text = (text *) palloc(new_text_size);

    VARATT_SIZEP(new_text) = new_text_size;
    memcpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1)-VARHDRSZ);
    memcpy(VARDATA(new_text) + (VARSIZE(arg1)-VARHDRSZ),
           VARDATA(arg2), VARSIZE(arg2)-VARHDRSZ);
    PG_RETURN_TEXT_P(new_text);
}


the error

in function 'makepoint':
error: 'Point' undeclared (first use in this function)
error: (each undeclared identifier is reported only one
error: for each function it appears in.)
error: 'pointx' undeclared (first use in ´this function)
error: 'pointy' undeclared (first use in his fnction)
error 'new_point' undeclared (first use in his function)
error: syntax error befre ')' oken
in function 'copy text':
error: 'invalid lvalue in assinment
In function 'concat_text'
error: invalid lvalue in assignement
warning no new line at end of file

Please any direction of how to solve the problem

thanks


What can you do with the new Windows Live? Find out
------------------------------------------------------------------------------

_______________________________________________
Mingw-msys mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mingw-msys
Reply | Threaded
Open this post in threaded view
|

Re: error when create dll for postgres‏

Keith Marshall-3
This is the wrong list for this question; it is not related to MSYS.  You
should be using the MinGW-users list.

On Monday 30 March 2009 20:46:03 eehab hamzeh wrote:

> [...]
> makepoint(PG_FUNCTION_ARGS)
> {
>     /* Here, the pass-by-reference nature of Point is not hidden. */
>     Point     *pointx = PG_GETARG_POINT_P(0);
>     Point     *pointy = PG_GETARG_POINT_P(1);
>     Point     *new_point = (Point *) palloc(sizeof(Point));
>
> [...]
>
> the error
>
> in function 'makepoint':
> error: 'Point' undeclared (first use in this function)
> error: (each undeclared identifier is reported only one
> error: for each function it appears in.)

This pretty much says it all; the compiler has no idea what a `Point' is.
*You* have to tell it, by an appropriate typedef, of by including some
header which contains such a typedef.

> error: 'pointx' undeclared (first use in ´this function)
> error: 'pointy' undeclared (first use in his fnction)
> error 'new_point' undeclared (first use in his function)
> error: syntax error befre ')' oken

These are consequences of the above.

> in function 'copy text':
> error: 'invalid lvalue in assinment

The entity on the LHS of an assignment operator, (equals sign), isn't
something you can assign a value to; I suspect:

>   VARATT_SIZEP(new_t) = VARSIZE(t);

is the offending statement.

> In function 'concat_text'
> error: invalid lvalue in assignement

Same again; I suspect:

>   VARATT_SIZEP(new_text) = new_text_size;

In both of these cases, it may be that the macro VARATT_SIZEP should
expand to a valid lvalue, but the compiler doesn't know this, (because
you are missing a required header), so it interprets those references as
function calls, which are not valid in this context.

> warning no new line at end of file

Your source file is not properly structured; there is no line terminator
at the end of the last line.  This is not allowed by the C/C++ standards.

This is your second or third time of asking this question, and it had been
partially answered already.  Perhaps you should look for a good beginners
reference for C/C++ programming.

Also, when you post an error transcript, you should copy and paste it; it
is fairly obvious that you didn't, because the compiler doesn't make the
myriad spelling errors seen here, and it usually also includes line
numbers, to pinpoint the location of errors.  You should also reduce your
sample code to a minimal, self-contained, fully compilable test case; I
can't compile your example, so I can't help you further.

And finally, please stop posting multipart MIME, with an embedded HTML
copy of your text cluttering our bandwidth; if you can't say what you
need to, in plain text only, then you have nothing worth saying.

--

Regards,
Keith.

------------------------------------------------------------------------------
_______________________________________________
Mingw-msys mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mingw-msys