1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-12 06:41:13 +02:00

Make scm_t_port private

* libguile/ports-internal.h (enum scm_port_encoding_mode): Remove unused
  enum.
  (scm_t_port_internal, scm_t_port): Make encoding and
  conversion_strategy private. Instead of scm_t_port_internal containing
  scm_t_port, now that all members are private, we can store the user's
  "stream" in a word in the port object itself and make the whole of
  scm_t_port private.  The next commit will remove scm_t_port_internal.
  (SCM_PTAB_ENTRY, SCM_PORT_DESCRIPTOR): Make private.
* libguile/ports.c (scm_c_make_port_with_encoding): Adapt to new port
  layout.
  (scm_port_print): Use SCM_PTAB_ENTRY when printing.
* libguile/ports.h: Remove scm_t_port definition.
* libguile/ioext.c (get_matching_port): Simplify.
* libguile/fports.c (scm_i_evict_port): Simplify.
This commit is contained in:
Andy Wingo 2016-05-13 11:21:41 +02:00
parent 9a9e0cceae
commit e5d2f4e566
5 changed files with 32 additions and 63 deletions

View file

@ -83,16 +83,9 @@ scm_i_evict_port (void *closure, SCM port)
{ {
int fd = * (int*) closure; int fd = * (int*) closure;
if (SCM_FPORTP (port)) if (SCM_OPFPORTP (port))
{ {
scm_t_port *p; scm_t_fport *fp = SCM_FSTREAM (port);
scm_t_fport *fp;
/* XXX: In some cases, we can encounter a port with no associated ptab
entry. */
p = SCM_PTAB_ENTRY (port);
fp = (p != NULL) ? (scm_t_fport *) p->stream : NULL;
if ((fp != NULL) && (fp->fdes == fd)) if ((fp != NULL) && (fp->fdes == fd))
{ {
fp->fdes = dup (fd); fp->fdes = dup (fd);

View file

@ -276,10 +276,8 @@ static SCM
get_matching_port (void *closure, SCM port, SCM result) get_matching_port (void *closure, SCM port, SCM result)
{ {
int fd = * (int *) closure; int fd = * (int *) closure;
scm_t_port *entry = SCM_PTAB_ENTRY (port);
if (SCM_OPFPORTP (port) if (SCM_OPFPORTP (port) && SCM_FSTREAM (port)->fdes == fd)
&& ((scm_t_fport *) entry->stream)->fdes == fd)
result = scm_cons (port, result); result = scm_cons (port, result);
return result; return result;

View file

@ -231,14 +231,6 @@ scm_port_buffer_putback (SCM buf, const scm_t_uint8 *src, size_t count)
src, count); src, count);
} }
enum scm_port_encoding_mode {
SCM_PORT_ENCODING_MODE_UTF8,
SCM_PORT_ENCODING_MODE_LATIN1,
SCM_PORT_ENCODING_MODE_ICONV
};
typedef enum scm_port_encoding_mode scm_t_port_encoding_mode;
/* This is a separate object so that only those ports that use iconv /* This is a separate object so that only those ports that use iconv
cause finalizers to be registered. */ cause finalizers to be registered. */
struct scm_iconv_descriptors struct scm_iconv_descriptors
@ -257,10 +249,8 @@ struct scm_iconv_descriptors
typedef struct scm_iconv_descriptors scm_t_iconv_descriptors; typedef struct scm_iconv_descriptors scm_t_iconv_descriptors;
struct scm_port_internal struct scm_port
{ {
scm_t_port pt;
/* Source location information. */ /* Source location information. */
SCM file_name; SCM file_name;
long line_number; long line_number;
@ -284,13 +274,21 @@ struct scm_port_internal
and so on. */ and so on. */
int rw_random; int rw_random;
/* Character encoding support. */
SCM encoding; /* A symbol of upper-case ASCII. */
SCM conversion_strategy; /* A symbol; either substitute, error, or escape. */
unsigned at_stream_start_for_bom_read : 1; unsigned at_stream_start_for_bom_read : 1;
unsigned at_stream_start_for_bom_write : 1; unsigned at_stream_start_for_bom_write : 1;
scm_t_iconv_descriptors *iconv_descriptors; scm_t_iconv_descriptors *iconv_descriptors;
SCM alist; SCM alist;
}; };
typedef struct scm_port_internal scm_t_port_internal; typedef struct scm_port scm_t_port;
typedef scm_t_port scm_t_port_internal;
#define SCM_PTAB_ENTRY(x) ((scm_t_port *) SCM_CELL_WORD_2 (x))
#define SCM_PORT_DESCRIPTOR(port) ((scm_t_ptob_descriptor *) SCM_CELL_WORD_3 (port))
#define SCM_UNICODE_BOM 0xFEFFUL /* Unicode byte-order mark */ #define SCM_UNICODE_BOM 0xFEFFUL /* Unicode byte-order mark */

View file

@ -55,7 +55,7 @@
#include "libguile/strings.h" #include "libguile/strings.h"
#include "libguile/mallocs.h" #include "libguile/mallocs.h"
#include "libguile/validate.h" #include "libguile/validate.h"
#include "libguile/ports.h" //#include "libguile/ports.h"
#include "libguile/ports-internal.h" #include "libguile/ports-internal.h"
#include "libguile/vectors.h" #include "libguile/vectors.h"
#include "libguile/weak-set.h" #include "libguile/weak-set.h"
@ -716,28 +716,26 @@ scm_c_make_port_with_encoding (scm_t_bits tag, unsigned long mode_bits,
scm_t_bits stream) scm_t_bits stream)
{ {
SCM ret; SCM ret;
scm_t_port *entry; scm_t_port *pt;
scm_t_port_internal *pti;
scm_t_ptob_descriptor *ptob; scm_t_ptob_descriptor *ptob;
pti = scm_gc_typed_calloc (scm_t_port_internal); pt = scm_gc_typed_calloc (scm_t_port);
entry = &pti->pt;
ptob = scm_c_port_type_ref (SCM_TC2PTOBNUM (tag)); ptob = scm_c_port_type_ref (SCM_TC2PTOBNUM (tag));
ret = scm_words (tag | mode_bits, 3); ret = scm_words (tag | mode_bits, 4);
SCM_SET_CELL_WORD_1 (ret, (scm_t_bits) entry); SCM_SET_CELL_WORD_1 (ret, stream);
SCM_SET_CELL_WORD_2 (ret, (scm_t_bits) ptob); SCM_SET_CELL_WORD_2 (ret, (scm_t_bits) pt);
SCM_SET_CELL_WORD_3 (ret, (scm_t_bits) ptob);
entry->stream = stream; pt->encoding = encoding;
entry->encoding = encoding; pt->conversion_strategy = conversion_strategy;
entry->conversion_strategy = conversion_strategy; pt->file_name = SCM_BOOL_F;
pti->file_name = SCM_BOOL_F; pt->iconv_descriptors = NULL;
pti->iconv_descriptors = NULL;
pti->at_stream_start_for_bom_read = 1; pt->at_stream_start_for_bom_read = 1;
pti->at_stream_start_for_bom_write = 1; pt->at_stream_start_for_bom_write = 1;
pti->alist = SCM_EOL; pt->alist = SCM_EOL;
if (SCM_PORT_DESCRIPTOR (ret)->flags & SCM_PORT_TYPE_NEEDS_CLOSE_ON_GC) if (SCM_PORT_DESCRIPTOR (ret)->flags & SCM_PORT_TYPE_NEEDS_CLOSE_ON_GC)
{ {
@ -747,7 +745,7 @@ scm_c_make_port_with_encoding (scm_t_bits tag, unsigned long mode_bits,
initialize_port_buffers (ret); initialize_port_buffers (ret);
pti->rw_random = ptob->random_access_p (ret); pt->rw_random = ptob->random_access_p (ret);
return ret; return ret;
} }
@ -3098,7 +3096,7 @@ scm_port_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
scm_print_port_mode (exp, port); scm_print_port_mode (exp, port);
scm_puts (type, port); scm_puts (type, port);
scm_putc (' ', port); scm_putc (' ', port);
scm_uintprint (SCM_CELL_WORD_1 (exp), 16, port); scm_uintprint ((scm_t_bits) SCM_PTAB_ENTRY (exp), 16, port);
scm_putc ('>', port); scm_putc ('>', port);
return 1; return 1;
} }

View file

@ -41,22 +41,6 @@
/* An internal-only structure defined in ports-internal.h. */
struct scm_port_internal;
/* C representation of a Scheme port. */
typedef struct
{
/* Data for the underlying port implementation as a raw C value. */
scm_t_bits stream;
/* Character encoding support. */
SCM encoding; /* A symbol of upper-case ASCII. */
SCM conversion_strategy; /* A symbol; either substitute, error, or escape. */
} scm_t_port;
SCM_INTERNAL SCM scm_i_port_weak_set; SCM_INTERNAL SCM scm_i_port_weak_set;
@ -86,11 +70,9 @@ SCM_INTERNAL SCM scm_i_port_weak_set;
#define SCM_CLR_PORT_OPEN_FLAG(p) \ #define SCM_CLR_PORT_OPEN_FLAG(p) \
SCM_SET_CELL_WORD_0 ((p), SCM_CELL_WORD_0 (p) & ~SCM_OPN) SCM_SET_CELL_WORD_0 ((p), SCM_CELL_WORD_0 (p) & ~SCM_OPN)
#define SCM_PTAB_ENTRY(x) ((scm_t_port *) SCM_CELL_WORD_1 (x)) #define SCM_STREAM(port) (SCM_CELL_WORD_1 (port))
#define SCM_PORT_DESCRIPTOR(port) ((scm_t_ptob_descriptor *) SCM_CELL_WORD_2 (port)) #define SCM_SETSTREAM(port, stream) (SCM_SET_CELL_WORD_1 (port, stream))
#define SCM_SETPTAB_ENTRY(x, ent) (SCM_SET_CELL_WORD_1 ((x), (scm_t_bits) (ent)))
#define SCM_STREAM(x) (SCM_PTAB_ENTRY(x)->stream)
#define SCM_SETSTREAM(x, s) (SCM_PTAB_ENTRY(x)->stream = (scm_t_bits) (s))
/* Maximum number of port types. */ /* Maximum number of port types. */
#define SCM_I_MAX_PORT_TYPE_COUNT 256 #define SCM_I_MAX_PORT_TYPE_COUNT 256