summaryrefslogtreecommitdiff
path: root/libguile/ports.h
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2016-05-13 18:23:47 +0200
committerAndy Wingo <wingo@pobox.com>2016-05-13 18:31:29 +0200
commitcd51ce81d047a10c55c450ea7b2bf5ab8b8340be (patch)
tree408738ccb0b6cc19d465a58420e8fc9e548a285d /libguile/ports.h
parent17f90360b6057034135ec93ffae340fa514208af (diff)
downloadguile-cd51ce81d047a10c55c450ea7b2bf5ab8b8340be.tar.gz
Use heap-allocated port types instead of ptobnums
This removes a limitation on the number of port types, simplifies the API, and removes a central point of coordination. * libguile/ports-internal.h (struct scm_t_port_type): Rename from scm_t_ptob_descriptor, now that it's private. Add GOOPS class fields. (struct scm_t_port): Rename from struct scm_port, especially considering that deprecated.h redefines scm_port using the preprocessor :(. * libguile/ports.h: Add definitions of SCM_PORT and SCM_PORT_TYPE, though the scm_t_port and scm_t_port_type types are incomplete. (SCM_TC2PTOBNUM, SCM_PTOBNUM, SCM_PTOBNAME): Remove, as there are no more typecodes for port types. (scm_c_num_port_types, scm_c_port_type_ref, scm_c_port_type_add_x): Remove. (scm_make_port_type): Return a scm_t_port_type*. All methods adapted to take a scm_t_port_type* instead of a ptobnum. (scm_c_make_port_with_encoding, scm_c_make_port): Take a port type pointer instead of a tag. (scm_new_port_table_entry): Remove; not useful. * libguile/ports.c: Remove things related to the port kind table. Adapt uses of SCM_PORT_DESCRIPTOR / scm_t_ptob_descriptor to use SCM_PORT_TYPE and scm_t_port_type. * libguile/deprecated.c: * libguile/deprecated.h: * libguile/filesys.c: * libguile/fports.c: * libguile/fports.h: * libguile/print.c: * libguile/r6rs-ports.c: * libguile/strports.c: * libguile/strports.h: * libguile/tags.h: * libguile/vports.c: * test-suite/standalone/test-scm-c-read.c: Adapt to change. * libguile/goops.c (scm_class_of, make_port_classes) (scm_make_port_classes, create_port_classes): Adapt to store the classes in the ptob.
Diffstat (limited to 'libguile/ports.h')
-rw-r--r--libguile/ports.h46
1 files changed, 22 insertions, 24 deletions
diff --git a/libguile/ports.h b/libguile/ports.h
index 18de70f65..709086c90 100644
--- a/libguile/ports.h
+++ b/libguile/ports.h
@@ -70,48 +70,47 @@ SCM_INTERNAL SCM scm_i_port_weak_set;
#define SCM_CLR_PORT_OPEN_FLAG(p) \
SCM_SET_CELL_WORD_0 ((p), SCM_CELL_WORD_0 (p) & ~SCM_OPN)
+typedef struct scm_t_port_type scm_t_port_type;
+typedef struct scm_t_port scm_t_port;
+
#define SCM_STREAM(port) (SCM_CELL_WORD_1 (port))
#define SCM_SETSTREAM(port, stream) (SCM_SET_CELL_WORD_1 (port, stream))
+#define SCM_PORT(x) ((scm_t_port *) SCM_CELL_WORD_2 (x))
+#define SCM_PORT_TYPE(port) ((scm_t_port_type *) SCM_CELL_WORD_3 (port))
/* Maximum number of port types. */
#define SCM_I_MAX_PORT_TYPE_COUNT 256
-
-
-typedef struct scm_t_ptob_descriptor scm_t_ptob_descriptor;
-#define SCM_TC2PTOBNUM(x) (0x0ff & ((x) >> 8))
-#define SCM_PTOBNUM(x) (SCM_TC2PTOBNUM (SCM_CELL_TYPE (x)))
-/* SCM_PTOBNAME can be 0 if name is missing */
-#define SCM_PTOBNAME(ptobnum) (scm_c_port_type_ref (ptobnum)->name)
+
/* Port types, and their vtables. */
-SCM_INTERNAL long scm_c_num_port_types (void);
-SCM_API scm_t_ptob_descriptor* scm_c_port_type_ref (long ptobnum);
-SCM_API long scm_c_port_type_add_x (scm_t_ptob_descriptor *desc);
-SCM_API scm_t_bits scm_make_port_type
+SCM_API scm_t_port_type *scm_make_port_type
(char *name,
size_t (*read) (SCM port, SCM dst, size_t start, size_t count),
size_t (*write) (SCM port, SCM src, size_t start, size_t count));
-SCM_API void scm_set_port_scm_read (scm_t_bits tc, SCM read);
-SCM_API void scm_set_port_scm_write (scm_t_bits tc, SCM write);
-SCM_API void scm_set_port_print (scm_t_bits tc,
+SCM_API void scm_set_port_scm_read (scm_t_port_type *ptob, SCM read);
+SCM_API void scm_set_port_scm_write (scm_t_port_type *ptob, SCM write);
+SCM_API void scm_set_port_print (scm_t_port_type *ptob,
int (*print) (SCM exp,
SCM port,
scm_print_state *pstate));
-SCM_API void scm_set_port_close (scm_t_bits tc, void (*close) (SCM));
-SCM_API void scm_set_port_needs_close_on_gc (scm_t_bits tc, int needs_close_p);
-SCM_API void scm_set_port_seek (scm_t_bits tc,
+SCM_API void scm_set_port_close (scm_t_port_type *ptob, void (*close) (SCM));
+SCM_API void scm_set_port_needs_close_on_gc (scm_t_port_type *ptob,
+ int needs_close_p);
+SCM_API void scm_set_port_seek (scm_t_port_type *ptob,
scm_t_off (*seek) (SCM port,
scm_t_off OFFSET,
int WHENCE));
-SCM_API void scm_set_port_truncate (scm_t_bits tc,
+SCM_API void scm_set_port_truncate (scm_t_port_type *ptob,
void (*truncate) (SCM port,
scm_t_off length));
-SCM_API void scm_set_port_input_waiting (scm_t_bits tc, int (*input_waiting) (SCM));
+SCM_API void scm_set_port_input_waiting (scm_t_port_type *ptob,
+ int (*input_waiting) (SCM));
SCM_API void scm_set_port_get_natural_buffer_sizes
- (scm_t_bits tc, void (*get_natural_buffer_sizes) (SCM, size_t *, size_t *));
-SCM_API void scm_set_port_random_access_p (scm_t_bits tc,
+ (scm_t_port_type *ptob,
+ void (*get_natural_buffer_sizes) (SCM, size_t *, size_t *));
+SCM_API void scm_set_port_random_access_p (scm_t_port_type *ptob,
int (*random_access_p) (SCM port));
/* The input, output, error, and load ports. */
@@ -138,14 +137,13 @@ SCM_API long scm_mode_bits (char *modes);
SCM_API SCM scm_port_mode (SCM port);
/* Low-level constructors. */
-SCM_API SCM scm_c_make_port_with_encoding (scm_t_bits tag,
+SCM_API SCM scm_c_make_port_with_encoding (scm_t_port_type *ptob,
unsigned long mode_bits,
SCM encoding,
SCM conversion_strategy,
scm_t_bits stream);
-SCM_API SCM scm_c_make_port (scm_t_bits tag, unsigned long mode_bits,
+SCM_API SCM scm_c_make_port (scm_t_port_type *ptob, unsigned long mode_bits,
scm_t_bits stream);
-SCM_API SCM scm_new_port_table_entry (scm_t_bits tag);
/* Predicates. */
SCM_API SCM scm_port_p (SCM x);