General Bug Report: using of user defined types in language C - Mailing list pgsql-bugs

From Unprivileged user
Subject General Bug Report: using of user defined types in language C
Date
Msg-id 199902061653.LAA01651@hub.org
Whole thread Raw
List pgsql-bugs
============================================================================
                        POSTGRESQL BUG REPORT TEMPLATE
============================================================================


Your name        : Petr Danecek
Your email address    : petr@ics.cas.cz

Category        : runtime: back-end: SQL
Severity        : critical

Summary: using of user defined types in language C

System Configuration
--------------------
  Operating System   : SunOS sun4u sparc

  PostgreSQL version : 6.4.2

  Compiler used      : gcc 2.7.2

Hardware:
---------
SunOS academy 5.5.1 Generic_103640-20 sun4u sparc

Versions of other tools:
------------------------
flex version 2.5.4
GNU Make version 3.75


--------------------------------------------------------------------------

Problem Description:
--------------------
When I define my own type in language C or C++,
it is not possible to work with it (except in one rare case,
that I will describe below).
Psql (or also my own interface) halts (may be doing an
infinite loop? - in earlier versions of postgres it
core dumped).

I do not observe this situation, when the new type
is in the postgres table as the *last* one.
But when it is followed with anything, it crashes.
I can define the type, I can insert into table, but the
query "SELECT * FROM table" will never succeed.

I prepared a very simple type, so I may be pretty sure
that I did not make any mistake. Then I compile it (using
the example from the documentation), run postgres,
create new table, function and insert values in it.

From debug outputs from my _in and _out functions I now
my code runs correctly.
The problem comes when my function is left. Postmaster
writes: "NOTICE:  PortalHeapMemoryFree: 0x1a32d0 not in alloc set!"

--------------------------------------------------------------------------

Test Case:
----------
Here is my example.
First the C code:

---------------------------------
#include <string.h>
#include <malloc.h>

typedef struct mComplex {
    double      x;
    double      y;
} mComplex;

mComplex *
mcomplex_in(char *str) {
    double x, y;
    mComplex *result = NULL;

    result = malloc (sizeof(mComplex));
    result->x = 1;
    result->y = 2;
    return (result);
}

char *
mcomplex_out(mComplex *mcomplex) {
    char *result = NULL;

    result = strdup ("(2,3)");
    return(result);
}
----------------------------------------

Then what I send to backend:
----------------------------------------
CREATE FUNCTION mcomplex_in(opaque)
RETURNS mcomplex
AS '/export/home/gis/projekt/mapa/date/libpgdate.so'
LANGUAGE 'c';

CREATE FUNCTION mcomplex_out(opaque)
RETURNS opaque
AS '/export/home/gis/projekt/mapa/date/libpgdate.so'
LANGUAGE 'c';

CREATE TYPE mcomplex (
internallength = 16,
input = mcomplex_in,
output = mcomplex_out
);

create table pok3 (co mcomplex, jmeno varchar);
insert into pok3 (co,jmeno) values ('pok','pok');
select * from pok3;
-------------------------------------

The C code I compile as:
gcc -fPIC -shared -c file.c
ld -dc -dp -Bdynamic -o libpgdate.so file.o


--------------------------------------------------------------------------

Solution:
---------


--------------------------------------------------------------------------


pgsql-bugs by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [BUGS] General Bug Report: Manpage for pgbuiltin(3) missing
Next
From: bugsbuny@elsop.com
Date:
Subject: Re: info