Next: , Previous: Ptob Cells, Up: Data Types


6.1.7 Defining Ptobs

ptobs are similar to smobs but define new types of port to which SCM procedures can read or write. The following functions are defined in the ptobfuns:

     typedef struct {
       SCM   (*mark)P((SCM ptr));
       int   (*free)P((FILE *p));
       int   (*print)P((SCM exp, SCM port, int writing));
       SCM   (*equalp)P((SCM, SCM));
       int   (*fputc)P((int c, FILE *p));
       int   (*fputs)P((char *s, FILE *p));
       sizet (*fwrite)P((char *s, sizet siz, sizet num, FILE *p));
       int   (*fflush)P((FILE *stream));
       int   (*fgetc)P((FILE *p));
       int   (*fclose)P((FILE *p));
     } ptobfuns;

The .free component to the structure takes a FILE * or other C construct as its argument, unlike .free in a smob, which takes the whole smob cell. Often, .free and .fclose can be the same function. See fptob and pipob in sys.c for examples of how to define ptobs. Ptobs that must allocate blocks of memory should use, for example, must_malloc rather than malloc See Allocating memory.