pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedUser defined type in C
3+ messages / 2 participants
[nested] [flat]
* User defined type in C
@ 2004-05-10 10:20 Armel HERVE <ah.pgsql@laposte.net>
2004-05-10 11:50 ` Re: User defined type in C Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Armel HERVE @ 2004-05-10 10:20 UTC (permalink / raw)
To: pgsql-admin
Hi everybody,
Sorry if it's not the good forum and for my poor English.
I'm trying to create a new type in C for postgreSQL (7.3.4).
This type is a structure of 4 fields including a variable length field.
When I try to insert record ino a table using this type, postgre server
crashes:
LOG: server process (pid 10838) was terminated by signal 11
LOG: terminating any other active server processes
WARNING: Message from PostgreSQL backend:
The Postmaster has informed me that some other backend
died abnormally and possibly corrupted shared memory.
I have rolled back the current transaction and am
going to terminate your database system connection and exit.
Please reconnect to the database system and repeat your query.
WARNING: Message from PostgreSQL backend:
The Postmaster has informed me that some other backend
died abnormally and possibly corrupted shared memory.
I have rolled back the current transaction and am
going to terminate your database system connection and exit.
Please reconnect to the database system and repeat your query.
WARNING: Message from PostgreSQL backend:
The Postmaster has informed me that some other backend
died abnormally and possibly corrupted shared memory.
I have rolled back the current transaction and am
going to terminate your database system connection and exit.
Please reconnect to the database system and repeat your query.
LOG: all server processes terminated; reinitializing shared memory and
semaphores
LOG: database system was interrupted at 2004-05-10 12:25:55 CEST
LOG: checkpoint record is at 0/627BE1DC
LOG: redo record is at 0/627BE1DC; undo record is at 0/0; shutdown TRUE
LOG: next transaction id: 2026530; next oid: 342157
LOG: database system was not properly shut down; automatic recovery in
progress
LOG: redo starts at 0/627BE21C
LOG: ReadRecord: record with zero length at 0/627DD5F4
LOG: redo done at 0/627DD5D0
LOG: database system is ready
Does anybody can help me ???
Thanks for your answers,
Armel HERVE
This is the C code:
#include "postgres.h"
#define KEY_SIZE 31
typedef struct {
int4 globalSize;
int64 fileSize;
char fileKey[KEY_SIZE + 1];
char fileName[1];
} Psfile;
#define PSFILE_BASIC_SIZE (4 + sizeof(int64) + KEY_SIZE + 1)
/**
*
* char *str : string representation of a psfile.
* must be formatted as follow :
* xxx,yyy,zzz
* with xxx : the name of the file
* yyy : the size of the file
* zzz : the key associated with the file.
*/
Psfile *psfile_in(char *str) {
Psfile *retValue = NULL;
int nameSize = 0;
// In first, we look for the size of the name
for(nameSize = 0; str[nameSize] != ',' && str[nameSize] != 0;
nameSize++) {
// Nothing to do in this block...
}
if(str[nameSize] == 0) {
// We are at the end of the string... Something is wrong!!
elog(ERROR, "psfile_in: string representation of a psfile :
name,size,key \"%s\"", str);
return NULL;
}
// Now, we have the size, so we can allocate memory for the global
structure
retValue = (Psfile *)palloc(PSFILE_BASIC_SIZE + nameSize + 1);
char format[15];
sprintf(format, "%%%ds,%%li,%%s", nameSize);
char *fileName = retValue->fileName;
char *fileKey = retValue->fileKey;
int64 *fileSize = &(retValue->fileSize);
if(sscanf(str, format, fileName, fileSize, fileKey) != 3) {
// Something is wrong : the number of parameters found must
be 3
pfree(retValue);
elog(ERROR, "psfile_in: string representation of a psfile :
name,size,key \"%s\"", str);
return NULL;
}
return retValue;
}
char *psfile_out(Psfile *psfile) {
elog(LOG, "psfile_out");
if(psfile == NULL) return NULL;
char *retValue = NULL;
char size[30];
sprintf(size, "%ld", psfile->fileSize);
retValue = (char *)palloc(strlen(psfile->fileName) + 1 +
strlen(size) + 1 + strlen(psfile->fileKey) + 1);
sprintf(retValue, "%s,%s,%s", psfile->fileName, size,
psfile->fileKey);
return retValue;
}
And this is the type declaration :
CREATE FUNCTION psfile_in(cstring)
RETURNS psfile
AS '/usr/include/pgsql/server/pslib/pslib'
LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION psfile_out(psfile)
RETURNS cstring
AS '/usr/include/pgsql/server/pslib/pslib'
LANGUAGE C IMMUTABLE STRICT;
CREATE TYPE psfile(
internallength = valiable,
input = psfile_in,
output = psfile_out,
alignment = int4
);
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: User defined type in C
2004-05-10 10:20 User defined type in C Armel HERVE <ah.pgsql@laposte.net>
@ 2004-05-10 11:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-05-10 12:22 ` Re: User defined type in C Armel HERVE <ah.pgsql@laposte.net>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2004-05-10 11:50 UTC (permalink / raw)
To: Armel HERVE <ah.pgsql@laposte.net>; +Cc: pgsql-admin
"Armel HERVE" <ah.pgsql@laposte.net> writes:
> I'm trying to create a new type in C for postgreSQL (7.3.4).
> This type is a structure of 4 fields including a variable length field.
Variable-size values must start with an integer indicating their total
size (this count must include itself, btw). Perhaps your globalSize
field is intended to serve that purpose, but if so, you forgot to set it.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: User defined type in C
2004-05-10 10:20 User defined type in C Armel HERVE <ah.pgsql@laposte.net>
2004-05-10 11:50 ` Re: User defined type in C Tom Lane <tgl@sss.pgh.pa.us>
@ 2004-05-10 12:22 ` Armel HERVE <ah.pgsql@laposte.net>
0 siblings, 0 replies; 3+ messages in thread
From: Armel HERVE @ 2004-05-10 12:22 UTC (permalink / raw)
To: pgsql-admin
You're right... I'm confuse...
I'm sorry, it's the bug which I'm looking for a while...
Thanks
Armel
-----Message d'origine-----
De : Tom Lane [mailto:tgl@sss.pgh.pa.us]
Envoyé : lundi 10 mai 2004 13:51
À : Armel HERVE
Cc : pgsql-admin@postgresql.org
Objet : Re: [ADMIN] User defined type in C
"Armel HERVE" <ah.pgsql@laposte.net> writes:
> I'm trying to create a new type in C for postgreSQL (7.3.4).
> This type is a structure of 4 fields including a variable length field.
Variable-size values must start with an integer indicating their total
size (this count must include itself, btw). Perhaps your globalSize
field is intended to serve that purpose, but if so, you forgot to set it.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2004-05-10 12:22 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-05-10 10:20 User defined type in C Armel HERVE <ah.pgsql@laposte.net>
2004-05-10 11:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-05-10 12:22 ` Armel HERVE <ah.pgsql@laposte.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox