[uim-commit] r1954 - branches/r5rs/sigscheme
yamaken at freedesktop.org
yamaken at freedesktop.org
Thu Nov 3 01:53:47 PST 2005
Author: yamaken
Date: 2005-11-03 01:53:43 -0800 (Thu, 03 Nov 2005)
New Revision: 1954
Modified:
branches/r5rs/sigscheme/baseport.h
branches/r5rs/sigscheme/fileport.c
branches/r5rs/sigscheme/mbcport.c
branches/r5rs/sigscheme/operations-srfi6.c
branches/r5rs/sigscheme/read.c
branches/r5rs/sigscheme/sbcport.c
branches/r5rs/sigscheme/strport.c
Log:
* sigscheme/baseport.h
- (SCM_PORT_DYNAMIC_CAST): Add port-class arg
- (SCM_CHARPORT_DYNAMIC_CAST, SCM_BYTEPORT_DYNAMIC_CAST): New macro
- (SCM_PORT_TRY_DYNAMIC_CAST): New macro
* sigscheme/mbcport.c
- (mbcport_dyn_cast): Remove exception handling
* sigscheme/sbcport.c
- (basecport_dyn_cast, sbcport_dyn_cast): Ditto
* sigscheme/fileport.c
- (fileport_dyn_cast): Ditto
* sigscheme/strport.c
- (istrport_dyn_cast, ostrport_dyn_cast): Ditto
- (ScmInputStrPort_ref_opaque, ScmOutputStrPort_str,
ScmOutputStrPort_ref_opaque): Fix exception handling
* sigscheme/operations-srfi6.c
- (ScmOp_SRFI6_get_output_string): Fix incorrect exception handling
and error message
* sigscheme/read.c
- (read_list): Fix unwanted termination
Modified: branches/r5rs/sigscheme/baseport.h
===================================================================
--- branches/r5rs/sigscheme/baseport.h 2005-11-03 08:14:47 UTC (rev 1953)
+++ branches/r5rs/sigscheme/baseport.h 2005-11-03 09:53:43 UTC (rev 1954)
@@ -85,10 +85,17 @@
/*
* To allow safe method invocation (contains from subclasses), all non-standard
- * method must call SCM_PORT_DYNAMIC_CAST() explicitly.
+ * method must call SCM_PORT_*DYNAMIC_CAST() explicitly.
*/
-#define SCM_PORT_DYNAMIC_CAST(type, obj) \
- ((type *)(*(obj)->vptr->dyn_cast)((obj), type##_vptr))
+#define SCM_CHARPORT_DYNAMIC_CAST(type, obj) \
+ (SCM_PORT_DYNAMIC_CAST(CHAR, type, obj))
+#define SCM_BYTEPORT_DYNAMIC_CAST(type, obj) \
+ (SCM_PORT_DYNAMIC_CAST(BYTE, type, obj))
+#define SCM_PORT_DYNAMIC_CAST(klass, type, obj) \
+ ((SCM_PORT_TRY_DYNAMIC_CAST(type, obj)) ? \
+ ((type *)(obj)) : (SCM_PORT_ERROR_INVALID_TYPE(klass, obj, type), NULL))
+#define SCM_PORT_TRY_DYNAMIC_CAST(type, obj) \
+ ((type *)(*(obj)->vptr->dyn_cast)((obj), type##_vptr))
#define SCM_CHARPORT_CLOSE(cport) ((*(cport)->vptr->close)(cport))
#define SCM_CHARPORT_ENCODING(cport) ((*(cport)->vptr->encoding)(cport))
Modified: branches/r5rs/sigscheme/fileport.c
===================================================================
--- branches/r5rs/sigscheme/fileport.c 2005-11-03 08:14:47 UTC (rev 1953)
+++ branches/r5rs/sigscheme/fileport.c 2005-11-03 09:53:43 UTC (rev 1954)
@@ -168,10 +168,7 @@
static ScmBytePort *
fileport_dyn_cast(ScmBytePort *bport, const ScmBytePortVTbl *dst_vptr)
{
- if (dst_vptr != ScmFilePort_vptr)
- SCM_PORT_ERROR_INVALID_TYPE(BYTE, bport, ScmFilePort);
-
- return bport;
+ return (dst_vptr == ScmFilePort_vptr) ? bport : NULL;
}
static int
Modified: branches/r5rs/sigscheme/mbcport.c
===================================================================
--- branches/r5rs/sigscheme/mbcport.c 2005-11-03 08:14:47 UTC (rev 1953)
+++ branches/r5rs/sigscheme/mbcport.c 2005-11-03 09:53:43 UTC (rev 1954)
@@ -148,11 +148,8 @@
static ScmCharPort *
mbcport_dyn_cast(ScmCharPort *cport, const ScmCharPortVTbl *dst_vptr)
{
- if (dst_vptr != ScmBaseCharPort_vptr
- && dst_vptr != ScmMultiByteCharPort_vptr)
- SCM_PORT_ERROR_INVALID_TYPE(CHAR, cport, ScmMultiByteCharPort);
-
- return cport;
+ return (dst_vptr == ScmBaseCharPort_vptr
+ || dst_vptr == ScmMultiByteCharPort_vptr) ? cport : NULL;
}
static const char *
Modified: branches/r5rs/sigscheme/operations-srfi6.c
===================================================================
--- branches/r5rs/sigscheme/operations-srfi6.c 2005-11-03 08:14:47 UTC (rev 1953)
+++ branches/r5rs/sigscheme/operations-srfi6.c 2005-11-03 09:53:43 UTC (rev 1954)
@@ -114,10 +114,8 @@
ASSERT_PORTP(port);
SCM_ASSERT_LIVE_PORT(port);
- cport = SCM_PORT_DYNAMIC_CAST(ScmBaseCharPort, SCM_PORT_IMPL(port));
- if (!cport)
- SCM_PORT_ERROR_INVALID_TYPE(CHAR,
- SCM_PORT_IMPL(port), ScmBaseCharPort);
+ cport = SCM_CHARPORT_DYNAMIC_CAST(ScmBaseCharPort, SCM_PORT_IMPL(port));
+
return Scm_NewStringCopying(ScmOutputStrPort_str(cport->bport));
}
Modified: branches/r5rs/sigscheme/read.c
===================================================================
--- branches/r5rs/sigscheme/read.c 2005-11-03 08:14:47 UTC (rev 1953)
+++ branches/r5rs/sigscheme/read.c 2005-11-03 09:53:43 UTC (rev 1954)
@@ -258,7 +258,8 @@
char *token = NULL;
CDBG((SCM_DBG_PARSER, "read_list"));
- basecport = SCM_PORT_DYNAMIC_CAST(ScmBaseCharPort, SCM_PORT_IMPL(port));
+ basecport = SCM_PORT_TRY_DYNAMIC_CAST(ScmBaseCharPort,
+ SCM_PORT_IMPL(port));
if (basecport)
start_line = ScmBaseCharPort_line_number(basecport);
Modified: branches/r5rs/sigscheme/sbcport.c
===================================================================
--- branches/r5rs/sigscheme/sbcport.c 2005-11-03 08:14:47 UTC (rev 1953)
+++ branches/r5rs/sigscheme/sbcport.c 2005-11-03 09:53:43 UTC (rev 1954)
@@ -150,10 +150,7 @@
static ScmCharPort *
basecport_dyn_cast(ScmCharPort *cport, const ScmCharPortVTbl *dst_vptr)
{
- if (dst_vptr != ScmBaseCharPort_vptr)
- SCM_PORT_ERROR_INVALID_TYPE(CHAR, cport, ScmBaseCharPort);
-
- return cport;
+ return (dst_vptr == ScmBaseCharPort_vptr) ? cport : NULL;
}
static int
@@ -263,11 +260,8 @@
static ScmCharPort *
sbcport_dyn_cast(ScmCharPort *cport, const ScmCharPortVTbl *dst_vptr)
{
- if (dst_vptr != ScmBaseCharPort_vptr
- && dst_vptr != ScmSingleByteCharPort_vptr)
- SCM_PORT_ERROR_INVALID_TYPE(CHAR, cport, ScmSingleByteCharPort);
-
- return cport;
+ return (dst_vptr == ScmBaseCharPort_vptr
+ || dst_vptr == ScmSingleByteCharPort_vptr) ? cport : NULL;
}
static const char *
Modified: branches/r5rs/sigscheme/strport.c
===================================================================
--- branches/r5rs/sigscheme/strport.c 2005-11-03 08:14:47 UTC (rev 1953)
+++ branches/r5rs/sigscheme/strport.c 2005-11-03 09:53:43 UTC (rev 1954)
@@ -205,9 +205,7 @@
{
ScmInputStrPort *port;
- port = SCM_PORT_DYNAMIC_CAST(ScmInputStrPort, bport);
- if (!port)
- SCM_PORT_ERROR_INVALID_TYPE(BYTE, bport, ScmInputStrPort);
+ port = SCM_BYTEPORT_DYNAMIC_CAST(ScmInputStrPort, bport);
return &port->opaque;
}
@@ -215,10 +213,7 @@
static ScmBytePort *
istrport_dyn_cast(ScmBytePort *bport, const ScmBytePortVTbl *dst_vptr)
{
- if (dst_vptr != ScmInputStrPort_vptr)
- SCM_PORT_ERROR_INVALID_TYPE(BYTE, bport, ScmInputStrPort);
-
- return bport;
+ return (dst_vptr == ScmInputStrPort_vptr) ? bport : NULL;
}
static int
@@ -309,9 +304,7 @@
{
ScmOutputStrPort *port;
- port = SCM_PORT_DYNAMIC_CAST(ScmOutputStrPort, bport);
- if (!port)
- SCM_PORT_ERROR_INVALID_TYPE(BYTE, bport, ScmOutputStrPort);
+ port = SCM_BYTEPORT_DYNAMIC_CAST(ScmOutputStrPort, bport);
return port->str;
}
@@ -321,9 +314,7 @@
{
ScmOutputStrPort *port;
- port = SCM_PORT_DYNAMIC_CAST(ScmOutputStrPort, bport);
- if (!port)
- SCM_PORT_ERROR_INVALID_TYPE(BYTE, bport, ScmOutputStrPort);
+ port = SCM_BYTEPORT_DYNAMIC_CAST(ScmOutputStrPort, bport);
return &port->opaque;
}
@@ -331,10 +322,7 @@
static ScmBytePort *
ostrport_dyn_cast(ScmBytePort *bport, const ScmBytePortVTbl *dst_vptr)
{
- if (dst_vptr != ScmOutputStrPort_vptr)
- SCM_PORT_ERROR_INVALID_TYPE(BYTE, bport, ScmOutputStrPort);
-
- return bport;
+ return (dst_vptr == ScmOutputStrPort_vptr) ? bport : NULL;
}
static int
More information about the uim-commit
mailing list