This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
I need some help with my port type. It's for the PostgreSQL interface. I hope someone can spare a few minutes to read this rather long message. I make a new port type to provide access to large objects. Because the interface I'm using is not buffered, I implement a buffer for read/write in the `glue layer'. I have a structure which contains the buffer space and various buffer pointers and whatnot. The structure looks like this: #define LOB_BUFLEN 512 typedef struct lob_stream_tag { char buf[LOB_BUFLEN]; int ptr; int len; int mode; SCM conn; Oid oid; int fd; } lob_stream; Then, following the fports implementation, I keep a pointer to this structure in the port table using SCM_SETSTREAM(cell, (SCM) ptr) Here's my function to make a new port (I call this from the 'open large object' and 'create large object' functions): static SCM lob_mklobport (SCM conn, Oid oid, int fd, long modes, char *caller) { SCM z; lob_stream *lobp; struct scm_port_table *pt; lobp = (lob_stream *) scm_must_malloc(sizeof(lob_stream), "PG_LOB port"); SCM_NEWCELL (z); SCM_DEFER_INTS; (void) memset (lobp->buf, '\0', (size_t) LOB_BUFLEN); lobp->ptr = 0; lobp->len = 0; lobp->mode = 0; lobp->conn = conn; lobp->oid = oid; lobp->fd = fd; pt = scm_add_to_port_table (z); SCM_SETCAR (z, lob_ptype | modes); SCM_SETPTAB_ENTRY (z, pt); SCM_SETSTREAM (z, (SCM) lobp); SCM_ALLOW_INTS; return z; } Then later, wherever I need to access the underlying file-descriptor or the buffer I use code like this: SCM scm_some_port_fn (port) { struct lob_stream *lobp = (lob_stream *) SCM_STREAM(port); . . . } The trouble I have is that something horrible is going wrong somewhere and I end up writing on the stack instead of into the buf[] array in the stream structure. I'm hoping it's because I've done something unutterably stupid and obviously wrong, and that someone will be able to tell me what this is from the above. The alternative is that I've done something stupid and hidden it behind a cast ... I've looked long and hard for this but not found anything. :-( The complete source is available via http from http://www.damtp.cam.ac.uk/user/ig206/guile-pg/ As far as I know, everything other than the large-object ports works. The only way to use large objects is to import them from, and export them to, files (this doesn't use the scheme port type.) Many thanks in advance Ian