[svn:parrot] r39759 - in branches/io_cleanups: include/parrot src/io src/pmc
whiteknight at svn.parrot.org
whiteknight at svn.parrot.org
Thu Jun 25 00:11:34 UTC 2009
Author: whiteknight
Date: Thu Jun 25 00:11:31 2009
New Revision: 39759
URL: https://trac.parrot.org/parrot/changeset/39759
Log:
[io_cleanups] back out the changes to Handle. It's the right idea to solve the problem, but wrong implementation
Modified:
branches/io_cleanups/include/parrot/io.h
branches/io_cleanups/include/parrot/io_portable.h
branches/io_cleanups/include/parrot/io_unix.h
branches/io_cleanups/include/parrot/io_win32.h
branches/io_cleanups/src/io/api.c
branches/io_cleanups/src/io/buffer.c
branches/io_cleanups/src/io/filehandle.c
branches/io_cleanups/src/io/portable.c
branches/io_cleanups/src/io/socket_api.c
branches/io_cleanups/src/io/socket_unix.c
branches/io_cleanups/src/io/unix.c
branches/io_cleanups/src/io/win32.c
branches/io_cleanups/src/pmc/filehandle.pmc
branches/io_cleanups/src/pmc/handle.pmc
branches/io_cleanups/src/pmc/socket.pmc
branches/io_cleanups/src/pmc/stringhandle.pmc
Modified: branches/io_cleanups/include/parrot/io.h
==============================================================================
--- branches/io_cleanups/include/parrot/io.h Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/include/parrot/io.h Thu Jun 25 00:11:31 2009 (r39759)
@@ -198,17 +198,6 @@
FUNC_MODIFIES(*pmc);
PARROT_EXPORT
-PIOHANDLE Parrot_io_get_os_handle(PARROT_INTERP, ARGIN(PMC * pmc))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_EXPORT
-PARROT_CANNOT_RETURN_NULL
-PMC * Parrot_io_get_os_handle_pmc(PARROT_INTERP, ARGIN(PMC * pmc))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PIOHANDLE Parrot_io_getfd(PARROT_INTERP, ARGMOD(PMC *pmc))
__attribute__nonnull__(1)
@@ -234,11 +223,6 @@
PIOOFF_T Parrot_io_make_offset(INTVAL offset);
PARROT_EXPORT
-PARROT_CANNOT_RETURN_NULL
-PMC * Parrot_io_make_os_handle_pmc(PARROT_INTERP)
- __attribute__nonnull__(1);
-
-PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_io_new_pmc(PARROT_INTERP, INTVAL flags)
@@ -315,13 +299,6 @@
FUNC_MODIFIES(*pmc);
PARROT_EXPORT
-void Parrot_io_set_os_handle(PARROT_INTERP,
- ARGIN(PMC * pmc),
- PIOHANDLE os_handle)
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_io_STDERR(PARROT_INTERP)
@@ -394,12 +371,6 @@
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(pmc) \
|| PARROT_ASSERT_ARG(s)
-#define ASSERT_ARGS_Parrot_io_get_os_handle __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(pmc)
-#define ASSERT_ARGS_Parrot_io_get_os_handle_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(pmc)
#define ASSERT_ARGS_Parrot_io_getfd __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(pmc)
@@ -410,8 +381,6 @@
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(pmc)
#define ASSERT_ARGS_Parrot_io_make_offset __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
-#define ASSERT_ARGS_Parrot_io_make_os_handle_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_io_new_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_io_open __attribute__unused__ int _ASSERT_ARGS_CHECK = \
@@ -439,9 +408,6 @@
#define ASSERT_ARGS_Parrot_io_seek __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(pmc)
-#define ASSERT_ARGS_Parrot_io_set_os_handle __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(pmc)
#define ASSERT_ARGS_Parrot_io_STDERR __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_io_stdhandle __attribute__unused__ int _ASSERT_ARGS_CHECK = \
@@ -473,10 +439,10 @@
__attribute__nonnull__(2)
FUNC_MODIFIES(*filehandle);
-INTVAL Parrot_io_flush_buffer(PARROT_INTERP, ARGMOD(PMC *handle))
+INTVAL Parrot_io_flush_buffer(PARROT_INTERP, ARGMOD(PMC *filehandle))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
- FUNC_MODIFIES(*handle);
+ FUNC_MODIFIES(*filehandle);
INTVAL Parrot_io_init_buffer(PARROT_INTERP)
__attribute__nonnull__(1);
@@ -540,7 +506,7 @@
|| PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_flush_buffer __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(handle)
+ || PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_init_buffer __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_io_peek_buffer __attribute__unused__ int _ASSERT_ARGS_CHECK = \
@@ -622,27 +588,23 @@
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
-unsigned char * Parrot_io_get_buffer_end(PARROT_INTERP,
- ARGIN_NULLOK(PMC *filehandle))
- __attribute__nonnull__(1);
+unsigned char * Parrot_io_get_buffer_end(SHIM_INTERP,
+ ARGIN_NULLOK(PMC *filehandle));
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
-unsigned char * Parrot_io_get_buffer_next(PARROT_INTERP,
+unsigned char * Parrot_io_get_buffer_next(SHIM_INTERP,
ARGIN(PMC *filehandle))
- __attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
-unsigned char * Parrot_io_get_buffer_start(PARROT_INTERP,
+unsigned char * Parrot_io_get_buffer_start(SHIM_INTERP,
ARGIN(PMC *filehandle))
- __attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
-PIOOFF_T Parrot_io_get_file_position(PARROT_INTERP, ARGIN(PMC *filehandle))
- __attribute__nonnull__(1)
+PIOOFF_T Parrot_io_get_file_position(SHIM_INTERP, ARGIN(PMC *filehandle))
__attribute__nonnull__(2);
PARROT_EXPORT
@@ -651,9 +613,12 @@
__attribute__nonnull__(2);
PARROT_EXPORT
-PIOOFF_T Parrot_io_get_last_file_position(PARROT_INTERP,
+PIOOFF_T Parrot_io_get_last_file_position(SHIM_INTERP,
ARGIN(PMC *filehandle))
- __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_EXPORT
+PIOHANDLE Parrot_io_get_os_handle(SHIM_INTERP, ARGIN(PMC *filehandle))
__attribute__nonnull__(2);
PARROT_EXPORT
@@ -678,10 +643,9 @@
__attribute__nonnull__(1);
PARROT_EXPORT
-void Parrot_io_set_file_position(PARROT_INTERP,
+void Parrot_io_set_file_position(SHIM_INTERP,
ARGIN(PMC *filehandle),
PIOOFF_T file_pos)
- __attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
@@ -691,19 +655,22 @@
__attribute__nonnull__(1)
__attribute__nonnull__(2);
+PARROT_EXPORT
+void Parrot_io_set_os_handle(SHIM_INTERP,
+ ARGIN(PMC *filehandle),
+ PIOHANDLE file_descriptor)
+ __attribute__nonnull__(2);
+
PARROT_CAN_RETURN_NULL
-void Parrot_io_clear_buffer(PARROT_INTERP, ARGIN(PMC *filehandle))
- __attribute__nonnull__(1)
+void Parrot_io_clear_buffer(SHIM_INTERP, ARGIN(PMC *filehandle))
__attribute__nonnull__(2);
PARROT_CAN_RETURN_NULL
-INTVAL Parrot_io_get_buffer_flags(PARROT_INTERP, ARGIN(PMC *filehandle))
- __attribute__nonnull__(1)
+INTVAL Parrot_io_get_buffer_flags(SHIM_INTERP, ARGIN(PMC *filehandle))
__attribute__nonnull__(2);
PARROT_CAN_RETURN_NULL
-size_t Parrot_io_get_buffer_size(PARROT_INTERP, ARGIN(PMC *filehandle))
- __attribute__nonnull__(1)
+size_t Parrot_io_get_buffer_size(SHIM_INTERP, ARGIN(PMC *filehandle))
__attribute__nonnull__(2);
PARROT_WARN_UNUSED_RESULT
@@ -715,34 +682,29 @@
__attribute__nonnull__(2)
FUNC_MODIFIES(*buf);
-void Parrot_io_set_buffer_end(PARROT_INTERP,
+void Parrot_io_set_buffer_end(SHIM_INTERP,
ARGIN(PMC *filehandle),
ARGIN_NULLOK(unsigned char *new_end))
- __attribute__nonnull__(1)
__attribute__nonnull__(2);
-void Parrot_io_set_buffer_flags(PARROT_INTERP,
+void Parrot_io_set_buffer_flags(SHIM_INTERP,
ARGIN(PMC *filehandle),
INTVAL new_flags)
- __attribute__nonnull__(1)
__attribute__nonnull__(2);
-void Parrot_io_set_buffer_next(PARROT_INTERP,
+void Parrot_io_set_buffer_next(SHIM_INTERP,
ARGIN(PMC *filehandle),
ARGIN_NULLOK(unsigned char *new_next))
- __attribute__nonnull__(1)
__attribute__nonnull__(2);
-void Parrot_io_set_buffer_size(PARROT_INTERP,
+void Parrot_io_set_buffer_size(SHIM_INTERP,
ARGIN(PMC *filehandle),
size_t new_size)
- __attribute__nonnull__(1)
__attribute__nonnull__(2);
-void Parrot_io_set_buffer_start(PARROT_INTERP,
+void Parrot_io_set_buffer_start(SHIM_INTERP,
ARGIN(PMC *filehandle),
ARGIN_NULLOK(unsigned char *new_start))
- __attribute__nonnull__(1)
__attribute__nonnull__(2);
#define ASSERT_ARGS_Parrot_io_close_filehandle __attribute__unused__ int _ASSERT_ARGS_CHECK = \
@@ -751,24 +713,21 @@
#define ASSERT_ARGS_Parrot_io_flush_filehandle __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(pmc)
-#define ASSERT_ARGS_Parrot_io_get_buffer_end __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp)
+#define ASSERT_ARGS_Parrot_io_get_buffer_end __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
#define ASSERT_ARGS_Parrot_io_get_buffer_next __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(filehandle)
+ PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_get_buffer_start __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(filehandle)
+ PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_get_file_position __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(filehandle)
+ PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_get_flags __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_get_last_file_position \
__attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(filehandle)
+ PARROT_ASSERT_ARG(filehandle)
+#define ASSERT_ARGS_Parrot_io_get_os_handle __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_is_closed_filehandle \
__attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
@@ -780,38 +739,31 @@
#define ASSERT_ARGS_Parrot_io_parse_open_flags __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_io_set_file_position __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(filehandle)
+ PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_set_flags __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
+#define ASSERT_ARGS_Parrot_io_set_os_handle __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_clear_buffer __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(filehandle)
+ PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_get_buffer_flags __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(filehandle)
+ PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_get_buffer_size __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(filehandle)
+ PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_make_string __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(buf)
#define ASSERT_ARGS_Parrot_io_set_buffer_end __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(filehandle)
+ PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_set_buffer_flags __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(filehandle)
+ PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_set_buffer_next __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(filehandle)
+ PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_set_buffer_size __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(filehandle)
+ PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_set_buffer_start __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(filehandle)
+ PARROT_ASSERT_ARG(filehandle)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/io/filehandle.c */
Modified: branches/io_cleanups/include/parrot/io_portable.h
==============================================================================
--- branches/io_cleanups/include/parrot/io_portable.h Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/include/parrot/io_portable.h Thu Jun 25 00:11:31 2009 (r39759)
@@ -36,21 +36,11 @@
__attribute__nonnull__(2)
FUNC_MODIFIES(*filehandle);
-INTVAL Parrot_io_flush_handle_portable(PARROT_INTERP, ARGMOD(PMC * handle))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(* handle);
-
INTVAL Parrot_io_flush_portable(SHIM_INTERP, SHIM(PMC *filehandle));
INTVAL Parrot_io_getblksize_portable(PIOHANDLE fptr);
INTVAL Parrot_io_init_portable(PARROT_INTERP)
__attribute__nonnull__(1);
-INTVAL Parrot_io_is_closed_handle_portable(PARROT_INTERP,
- ARGIN(PMC* handle))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
INTVAL Parrot_io_is_closed_portable(PARROT_INTERP, ARGIN(PMC *filehandle))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
@@ -100,7 +90,7 @@
__attribute__nonnull__(2);
size_t Parrot_io_write_portable(PARROT_INTERP,
- ARGIN(PMC *handle),
+ ARGIN(PMC *filehandle),
ARGMOD(STRING *s))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
@@ -113,18 +103,10 @@
#define ASSERT_ARGS_Parrot_io_fdopen_portable __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
-#define ASSERT_ARGS_Parrot_io_flush_handle_portable \
- __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(handle)
#define ASSERT_ARGS_Parrot_io_flush_portable __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
#define ASSERT_ARGS_Parrot_io_getblksize_portable __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
#define ASSERT_ARGS_Parrot_io_init_portable __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
-#define ASSERT_ARGS_Parrot_io_is_closed_handle_portable \
- __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(handle)
#define ASSERT_ARGS_Parrot_io_is_closed_portable __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
@@ -149,7 +131,7 @@
|| PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_write_portable __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(handle) \
+ || PARROT_ASSERT_ARG(filehandle) \
|| PARROT_ASSERT_ARG(s)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/io/portable.c */
@@ -163,7 +145,6 @@
Parrot_io_open_pipe_portable((interp), (pmc), (file), (flags))
#define PIO_CLOSE(interp, pmc) Parrot_io_close_portable((interp), (pmc))
#define PIO_IS_CLOSED(interp, pmc) Parrot_io_is_closed_portable((interp), (pmc))
-#define PIO_IS_CLOSED_HANDLE(interp, pmc) Parrot_io_is_closed_handle_portable((interp), (pmc))
#define PIO_READ(interp, pmc, buf) Parrot_io_read_portable((interp), (pmc), (buf))
#define PIO_WRITE(interp, pmc, str) Parrot_io_write_portable((interp), (pmc), (str))
#define PIO_SEEK(interp, pmc, offset, start) \
@@ -171,7 +152,6 @@
#define PIO_TELL(interp, pmc) Parrot_io_tell_portable((interp), (pmc))
#define PIO_PEEK(interp, pmc, buf) Parrot_io_peek_portable((interp), (pmc), (buf))
#define PIO_FLUSH(interp, pmc) Parrot_io_flush_portable((interp), (pmc))
-#define PIO_FLUSH_HANDLE(interp, pmc) Parrot_io_flush_handle_portable((interp), (pmc))
#define PIO_GETBLKSIZE(handle) Parrot_io_getblksize_portable((handle))
#endif /* PARROT_IO_PORTABLE_H_GUARD */
Modified: branches/io_cleanups/include/parrot/io_unix.h
==============================================================================
--- branches/io_cleanups/include/parrot/io_unix.h Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/include/parrot/io_unix.h Thu Jun 25 00:11:31 2009 (r39759)
@@ -46,11 +46,6 @@
__attribute__nonnull__(2)
FUNC_MODIFIES(*filehandle);
-INTVAL Parrot_io_flush_handle_unix(PARROT_INTERP, ARGMOD(PMC * handle))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(* handle);
-
INTVAL Parrot_io_flush_unix(PARROT_INTERP, ARGMOD(PMC *filehandle))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
@@ -60,10 +55,6 @@
INTVAL Parrot_io_init_unix(PARROT_INTERP)
__attribute__nonnull__(1);
-INTVAL Parrot_io_is_closed_handle_unix(PARROT_INTERP, ARGIN(PMC* handle))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
INTVAL Parrot_io_is_closed_unix(PARROT_INTERP, ARGIN(PMC *filehandle))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
@@ -126,7 +117,7 @@
FUNC_MODIFIES(*filehandle);
size_t Parrot_io_write_unix(PARROT_INTERP,
- ARGIN(PMC *handle),
+ ARGIN(PMC *filehandle),
ARGMOD(STRING *s))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
@@ -144,19 +135,12 @@
#define ASSERT_ARGS_Parrot_io_fdopen_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
-#define ASSERT_ARGS_Parrot_io_flush_handle_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(handle)
#define ASSERT_ARGS_Parrot_io_flush_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_getblksize_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
#define ASSERT_ARGS_Parrot_io_init_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
-#define ASSERT_ARGS_Parrot_io_is_closed_handle_unix \
- __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(handle)
#define ASSERT_ARGS_Parrot_io_is_closed_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
@@ -184,7 +168,7 @@
|| PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_write_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(handle) \
+ || PARROT_ASSERT_ARG(filehandle) \
|| PARROT_ASSERT_ARG(s)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/io/unix.c */
@@ -217,17 +201,15 @@
__attribute__nonnull__(3)
FUNC_MODIFIES(*socket);
-INTVAL Parrot_io_listen_unix(PARROT_INTERP, ARGMOD(PMC *socket), INTVAL sec)
- __attribute__nonnull__(1)
+INTVAL Parrot_io_listen_unix(SHIM_INTERP, ARGMOD(PMC *socket), INTVAL sec)
__attribute__nonnull__(2)
FUNC_MODIFIES(*socket);
-INTVAL Parrot_io_poll_unix(PARROT_INTERP,
+INTVAL Parrot_io_poll_unix(SHIM_INTERP,
ARGMOD(PMC *socket),
int which,
int sec,
int usec)
- __attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*socket);
@@ -240,10 +222,9 @@
FUNC_MODIFIES(*socket)
FUNC_MODIFIES(*s);
-INTVAL Parrot_io_send_unix(PARROT_INTERP,
+INTVAL Parrot_io_send_unix(SHIM_INTERP,
ARGMOD(PMC *socket),
ARGMOD(STRING *s))
- __attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*socket)
@@ -277,18 +258,15 @@
|| PARROT_ASSERT_ARG(socket) \
|| PARROT_ASSERT_ARG(r)
#define ASSERT_ARGS_Parrot_io_listen_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(socket)
+ PARROT_ASSERT_ARG(socket)
#define ASSERT_ARGS_Parrot_io_poll_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(socket)
+ PARROT_ASSERT_ARG(socket)
#define ASSERT_ARGS_Parrot_io_recv_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(socket) \
|| PARROT_ASSERT_ARG(s)
#define ASSERT_ARGS_Parrot_io_send_unix __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(socket) \
+ PARROT_ASSERT_ARG(socket) \
|| PARROT_ASSERT_ARG(s)
#define ASSERT_ARGS_Parrot_io_sockaddr_in __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
@@ -311,7 +289,6 @@
#define PIO_CLOSE(interp, pmc) Parrot_io_close_unix((interp), (pmc))
#define PIO_CLOSE_PIOHANDLE(interp, handle) Parrot_io_close_piohandle_unix((interp), (handle))
#define PIO_IS_CLOSED(interp, pmc) Parrot_io_is_closed_unix((interp), (pmc))
-#define PIO_IS_CLOSED_HANDLE(interp, pmc) Parrot_io_is_closed_handle_unix((interp), (pmc))
#define PIO_READ(interp, pmc, buf) Parrot_io_read_unix((interp), (pmc), (buf))
#define PIO_WRITE(interp, pmc, str) Parrot_io_write_unix((interp), (pmc), (str))
#define PIO_SEEK(interp, pmc, offset, start) \
@@ -319,7 +296,6 @@
#define PIO_TELL(interp, pmc) Parrot_io_tell_unix((interp), (pmc))
#define PIO_PEEK(interp, pmc, buf) Parrot_io_peek_unix((interp), (pmc), (buf))
#define PIO_FLUSH(interp, pmc) Parrot_io_flush_unix((interp), (pmc))
-#define PIO_FLUSH_HANDLE(interp, pmc) Parrot_io_flush_handle_unix((interp), (pmc))
#define PIO_GETBLKSIZE(handle) Parrot_io_getblksize_unix((handle))
#define PIO_POLL(interp, pmc, which, sec, usec) \
Modified: branches/io_cleanups/include/parrot/io_win32.h
==============================================================================
--- branches/io_cleanups/include/parrot/io_win32.h Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/include/parrot/io_win32.h Thu Jun 25 00:11:31 2009 (r39759)
@@ -38,11 +38,6 @@
__attribute__nonnull__(1)
FUNC_MODIFIES(*filehandle);
-INTVAL Parrot_io_flush_handle_win32(PARROT_INTERP, ARGMOD(PMC * handle))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(* handle);
-
INTVAL Parrot_io_flush_win32(PARROT_INTERP, ARGMOD(PMC *filehandle))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
@@ -52,10 +47,6 @@
INTVAL Parrot_io_init_win32(PARROT_INTERP)
__attribute__nonnull__(1);
-INTVAL Parrot_io_is_closed_handle_win32(PARROT_INTERP, ARGIN(PMC* handle))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
INTVAL Parrot_io_is_closed_win32(PARROT_INTERP, ARGIN(PMC *filehandle))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
@@ -118,7 +109,7 @@
__attribute__nonnull__(2);
size_t Parrot_io_write_win32(PARROT_INTERP,
- ARGIN(PMC *handle),
+ ARGIN(PMC *filehandle),
ARGIN(STRING *s))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
@@ -132,19 +123,12 @@
|| PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_fdopen_win32 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
-#define ASSERT_ARGS_Parrot_io_flush_handle_win32 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(handle)
#define ASSERT_ARGS_Parrot_io_flush_win32 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_getblksize_win32 __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
#define ASSERT_ARGS_Parrot_io_init_win32 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
-#define ASSERT_ARGS_Parrot_io_is_closed_handle_win32 \
- __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(handle)
#define ASSERT_ARGS_Parrot_io_is_closed_win32 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(filehandle)
@@ -173,7 +157,7 @@
|| PARROT_ASSERT_ARG(filehandle)
#define ASSERT_ARGS_Parrot_io_write_win32 __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(handle) \
+ || PARROT_ASSERT_ARG(filehandle) \
|| PARROT_ASSERT_ARG(s)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/io/win32.c */
@@ -290,7 +274,6 @@
#define PIO_CLOSE(interp, pmc) Parrot_io_close_win32((interp), (pmc))
#define PIO_CLOSE_PIOHANDLE(interp, handle) Parrot_io_close_piohandle_win32((interp), (handle))
#define PIO_IS_CLOSED(interp, pmc) Parrot_io_is_closed_win32((interp), (pmc))
-#define PIO_IS_CLOSED_HANDLE(interp, pmc) Parrot_io_is_closed_handle_win32((interp), (pmc))
#define PIO_READ(interp, pmc, buf) Parrot_io_read_win32((interp), (pmc), (buf))
#define PIO_WRITE(interp, pmc, str) Parrot_io_write_win32((interp), (pmc), (str))
#define PIO_SEEK(interp, pmc, offset, start) \
@@ -298,7 +281,6 @@
#define PIO_TELL(interp, pmc) Parrot_io_tell_win32((interp), (pmc))
#define PIO_PEEK(interp, pmc, buf) Parrot_io_peek_win32((interp), (pmc), (buf))
#define PIO_FLUSH(interp, pmc) Parrot_io_flush_win32((interp), (pmc))
-#define PIO_FLUSH_HANDLE(interp, pmc) Parrot_io_flush_handle_win32((interp), (pmc))
#define PIO_GETBLKSIZE(handle) Parrot_io_getblksize_win32((handle))
#define PIO_POLL(interp, pmc, which, sec, usec) \
Modified: branches/io_cleanups/src/io/api.c
==============================================================================
--- branches/io_cleanups/src/io/api.c Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/src/io/api.c Thu Jun 25 00:11:31 2009 (r39759)
@@ -19,6 +19,10 @@
The C<FileHandle> PMC provides the class-based interface for filehandles that
is used in Parrot ops.
+TODO: Where possible, extract some of the filehandle-related details into
+src/io/filehandle.c, and extract the stringhandle details into
+src/io/io_string.c.
+
=cut
*/
@@ -29,7 +33,6 @@
#include "../pmc/pmc_filehandle.h"
#include "../pmc/pmc_stringhandle.h"
#include "../pmc/pmc_socket.h"
-#include "../pmc/pmc_handle.h"
#include <stdarg.h>
@@ -214,11 +217,13 @@
}
else if (pmc->vtable->base_type == enum_class_StringHandle)
SETATTR_StringHandle_read_offset(interp, pmc, 0);
- else if (pmc->vtable->base_type == enum_class_Socket) {
- const PIOHANDLE os_handle = Parrot_io_get_os_handle(interp, pmc);
+ else if (pmc->vtable->base_type == enum_class_Socket)
+ {
+ PIOHANDLE os_handle;
+ GETATTR_Socket_os_handle(interp, pmc, os_handle);
if (os_handle != PIO_INVALID_HANDLE)
result = Parrot_io_close_piohandle(interp, os_handle);
- Parrot_io_set_os_handle(interp, pmc, PIO_INVALID_HANDLE);
+ SETATTR_Socket_os_handle(interp, pmc, PIO_INVALID_HANDLE);
}
else
Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "close"), "->I", &result);
@@ -304,8 +309,9 @@
if (pmc->vtable->base_type == enum_class_FileHandle)
Parrot_io_flush_filehandle(interp, pmc);
- else if (pmc->vtable->base_type == enum_class_StringHandle)
+ else if (pmc->vtable->base_type == enum_class_StringHandle) {
SETATTR_StringHandle_stringhandle(interp, pmc, NULL);
+ }
else
Parrot_PCCINVOKE(interp, pmc, CONST_STRING(interp, "flush"), "->");
}
@@ -916,93 +922,6 @@
return VTABLE_get_integer(interp, pmc);
}
-/*
-
-=item C<PMC * Parrot_io_make_os_handle_pmc(PARROT_INTERP)>
-
-Initialize a new low-level handle type
-
-=cut
-
-*/
-
-PARROT_EXPORT
-PARROT_CANNOT_RETURN_NULL
-PMC *
-Parrot_io_make_os_handle_pmc(PARROT_INTERP)
-{
- PMC * handle = pmc_new_noinit(interp, enum_class_Handle);
- Parrot_Handle_attributes *ds = mem_allocate_typed(Parrot_Handle_attributes);
- ds->os_handle = (PIOHANDLE) PIO_INVALID_HANDLE;
- ds->buffer_size = 0;
- ds->buffer_flags = 0;
- ds->buffer_start = NULL;
- ds->buffer_next = NULL;
- ds->buffer_end = NULL;
- ds->file_pos = piooffsetzero;
- ds->last_pos = piooffsetzero;
- PMC_data(handle) = ds;
- PObj_active_destroy_SET(handle);
- return handle;
-}
-
-/*
-
-=item C<PMC * Parrot_io_get_os_handle_pmc(PARROT_INTERP, PMC * pmc)>
-
-Get the Handle PMC that encapsulates the low-level OS handle for the given
-IO PMC
-
-=item C<PIOHANDLE Parrot_io_get_os_handle(PARROT_INTERP, PMC * pmc)>
-
-Get the low-level OS handle from the given IO PMC
-
-=item C<void Parrot_io_set_os_handle(PARROT_INTERP, PMC * pmc, PIOHANDLE
-os_handle)>
-
-Set he low-level OS handle to the given IO PMC
-
-=cut
-
-*/
-
-PARROT_EXPORT
-PARROT_CANNOT_RETURN_NULL
-PMC *
-Parrot_io_get_os_handle_pmc(PARROT_INTERP, ARGIN(PMC * pmc))
-{
- PMC * handle = PMCNULL;
- switch (pmc->vtable->base_type) {
- case enum_class_FileHandle:
- GETATTR_FileHandle_os_handle(interp, pmc, handle);
- break;
- case enum_class_Socket:
- GETATTR_Socket_os_handle(interp, pmc, handle);
- break;
- }
- if (PMC_IS_NULL(handle))
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
- "Could not obtain Handle from IO pmc");
- return handle;
-}
-
-PARROT_EXPORT
-PIOHANDLE
-Parrot_io_get_os_handle(PARROT_INTERP, ARGIN(PMC * pmc))
-{
- const PMC * const handle = Parrot_io_get_os_handle_pmc(interp, pmc);
- /* TODO: If we don't have a valid handle at this point, throw a
- meaningful exception */
- return PARROT_HANDLE(handle)->os_handle;
-}
-
-PARROT_EXPORT
-void
-Parrot_io_set_os_handle(PARROT_INTERP, ARGIN(PMC * pmc), PIOHANDLE os_handle)
-{
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, pmc);
- PARROT_HANDLE(handle)->os_handle = os_handle;
-}
/*
Modified: branches/io_cleanups/src/io/buffer.c
==============================================================================
--- branches/io_cleanups/src/io/buffer.c Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/src/io/buffer.c Thu Jun 25 00:11:31 2009 (r39759)
@@ -20,7 +20,6 @@
#include "parrot/parrot.h"
#include "io_private.h"
-#include "../pmc/pmc_handle.h"
/* HEADERIZER HFILE: include/parrot/io.h */
/* HEADERIZER BEGIN: static */
@@ -72,7 +71,6 @@
Parrot_io_setbuf(PARROT_INTERP, ARGMOD(PMC *filehandle), size_t bufsize)
{
ASSERT_ARGS(Parrot_io_setbuf)
- PMC * handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
INTVAL filehandle_flags = Parrot_io_get_flags(interp, filehandle);
INTVAL buffer_flags = Parrot_io_get_buffer_flags(interp, filehandle);
unsigned char *buffer_start = Parrot_io_get_buffer_start(interp, filehandle);
@@ -81,7 +79,7 @@
/* If there is already a buffer, make sure we flush before modifying it. */
if (buffer_start)
- Parrot_io_flush_buffer(interp, handle);
+ Parrot_io_flush_buffer(interp, filehandle);
/* Choose an appropriate buffer size for caller */
switch (bufsize) {
@@ -163,33 +161,30 @@
/*
-=item C<INTVAL Parrot_io_flush_buffer(PARROT_INTERP, PMC *handle)>
+=item C<INTVAL Parrot_io_flush_buffer(PARROT_INTERP, PMC *filehandle)>
-Flush the I/O buffer for a given Handle PMC
+Flush the I/O buffer for a given filehandle object.
=cut
*/
INTVAL
-Parrot_io_flush_buffer(PARROT_INTERP, ARGMOD(PMC *handle))
+Parrot_io_flush_buffer(PARROT_INTERP, ARGMOD(PMC *filehandle))
{
ASSERT_ARGS(Parrot_io_flush_buffer)
long wrote;
size_t to_write;
STRING fake;
- /* TODO: Encapsulate all this better */
- Parrot_Handle_attributes *data_struct = PARROT_HANDLE(handle);
- unsigned char *buffer_start = data_struct->buffer_start;
- unsigned char *buffer_next = data_struct->buffer_next;
- INTVAL buffer_flags = data_struct->buffer_flags;
- INTVAL flags = data_struct->flags;
+ unsigned char *buffer_start = Parrot_io_get_buffer_start(interp, filehandle);
+ unsigned char *buffer_next = Parrot_io_get_buffer_next(interp, filehandle);
+ INTVAL buffer_flags = Parrot_io_get_buffer_flags(interp, filehandle);
/*
* Either buffering is null, disabled, or empty.
*/
if (!buffer_start
- || (flags & (PIO_F_BLKBUF | PIO_F_LINEBUF)) == 0
+ || (Parrot_io_get_flags(interp, filehandle) & (PIO_F_BLKBUF | PIO_F_LINEBUF)) == 0
|| (buffer_flags & (PIO_BF_WRITEBUF | PIO_BF_READBUF)) == 0)
return 0;
/*
@@ -201,11 +196,11 @@
/* Flush to next layer */
fake.strstart = (char *)buffer_start;
fake.bufused = to_write;
- wrote = PIO_WRITE(interp, handle, &fake);
+ wrote = PIO_WRITE(interp, filehandle, &fake);
if (wrote == (long)to_write) {
- data_struct->buffer_next = buffer_start;
+ Parrot_io_set_buffer_next(interp, filehandle, buffer_start);
/* Release buffer */
- data_struct->buffer_flags = (buffer_flags & ~PIO_BF_WRITEBUF);
+ Parrot_io_set_buffer_flags(interp, filehandle, (buffer_flags & ~PIO_BF_WRITEBUF));
return 0;
}
else {
@@ -217,9 +212,9 @@
* Read flush
*/
else if (buffer_flags & PIO_BF_READBUF) {
- data_struct->buffer_next = buffer_start;
+ Parrot_io_set_buffer_next(interp, filehandle, buffer_start);
/* Release buffer */
- data_struct->buffer_flags = (buffer_flags & ~PIO_BF_READBUF);
+ Parrot_io_set_buffer_flags(interp, filehandle, (buffer_flags & ~PIO_BF_READBUF));
}
return -1;
}
@@ -287,7 +282,6 @@
STRING *s;
size_t len;
size_t current = 0;
- PMC * handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
INTVAL buffer_flags = Parrot_io_get_buffer_flags(interp, filehandle);
/* write buffer flush */
@@ -418,12 +412,11 @@
unsigned char *buffer_next;
STRING * const s = Parrot_io_make_string(interp, buf, 1);
UINTVAL len = 1;
- PMC * handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
INTVAL buffer_flags = Parrot_io_get_buffer_flags(interp, filehandle);
/* write buffer flush */
if (buffer_flags & PIO_BF_WRITEBUF) {
- Parrot_io_flush_buffer(interp, handle);
+ Parrot_io_flush_buffer(interp, filehandle);
buffer_flags = Parrot_io_get_buffer_flags(interp, filehandle);
}
@@ -579,7 +572,6 @@
{
ASSERT_ARGS(Parrot_io_write_buffer)
void * const buffer = s->strstart;
- PMC * handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
unsigned char * const buffer_start = Parrot_io_get_buffer_start(interp, filehandle);
unsigned char * buffer_next = Parrot_io_get_buffer_next(interp, filehandle);
const size_t buffer_size = Parrot_io_get_buffer_size(interp, filehandle);
@@ -631,8 +623,8 @@
long wrote;
/* Write through, skip buffer. */
- Parrot_io_flush_buffer(interp, handle);
- wrote = PIO_WRITE(interp, handle, s);
+ Parrot_io_flush_buffer(interp, filehandle);
+ wrote = PIO_WRITE(interp, filehandle, s);
if (wrote == (long)len) {
Parrot_io_set_file_position(interp, filehandle, (wrote +
@@ -666,7 +658,7 @@
Parrot_io_set_buffer_next(interp, filehandle, buffer_next);
Parrot_io_set_file_position(interp, filehandle, (avail +
Parrot_io_get_file_position(interp, filehandle)));
- Parrot_io_flush_buffer(interp, handle);
+ Parrot_io_flush_buffer(interp, filehandle);
buffer_flags |= PIO_BF_WRITEBUF;
Parrot_io_set_buffer_flags(interp, filehandle, buffer_flags);
@@ -699,7 +691,6 @@
PIOOFF_T offset, INTVAL whence)
{
ASSERT_ARGS(Parrot_io_seek_buffer)
- PMC * handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
PIOOFF_T newpos;
PIOOFF_T file_pos = Parrot_io_get_file_position(interp, filehandle);
unsigned char *buffer_start = Parrot_io_get_buffer_start(interp, filehandle);
@@ -727,7 +718,7 @@
if ((newpos < file_pos - (buffer_next - buffer_start))
|| (newpos >= file_pos + (buffer_end - buffer_next))) {
- Parrot_io_flush_buffer(interp, handle);
+ Parrot_io_flush_buffer(interp, filehandle);
newpos = PIO_SEEK(interp, filehandle, newpos, SEEK_SET);
}
else {
Modified: branches/io_cleanups/src/io/filehandle.c
==============================================================================
--- branches/io_cleanups/src/io/filehandle.c Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/src/io/filehandle.c Thu Jun 25 00:11:31 2009 (r39759)
@@ -18,7 +18,6 @@
#include "parrot/parrot.h"
#include "io_private.h"
#include "../pmc/pmc_filehandle.h"
-#include "../pmc/pmc_handle.h"
/* HEADERIZER HFILE: include/parrot/io.h */
@@ -132,6 +131,59 @@
}
}
+
+/*
+
+=item C<void Parrot_io_set_os_handle(PARROT_INTERP, PMC *filehandle, PIOHANDLE
+file_descriptor)>
+
+Sets the C<os_handle> attribute of the FileHandle object, which stores the
+low-level filehandle for the OS.
+
+Currently, this pokes directly into the C struct of the FileHandle PMC. This
+needs to change to a general interface that can be used by all subclasses and
+polymorphic equivalents of FileHandle. For now, hiding it behind a function, so
+it can be cleanly changed later.
+
+Possibly, this function should reset some characteristics of the object (like
+buffer and file positions) to their default values.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+void
+Parrot_io_set_os_handle(SHIM_INTERP, ARGIN(PMC *filehandle), PIOHANDLE file_descriptor)
+{
+ ASSERT_ARGS(Parrot_io_set_os_handle)
+ PARROT_FILEHANDLE(filehandle)->os_handle = file_descriptor;
+}
+
+/*
+
+=item C<PIOHANDLE Parrot_io_get_os_handle(PARROT_INTERP, PMC *filehandle)>
+
+Retrieve the C<os_handle> attribute of the FileHandle object, which stores the
+low-level filehandle for the OS.
+
+Currently, this pokes directly into the C struct of the FileHandle PMC. This
+needs to change to a general interface that can be used by all subclasses and
+polymorphic equivalents of FileHandle. For now, hiding it behind a function, so
+it can be cleanly changed later.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PIOHANDLE
+Parrot_io_get_os_handle(SHIM_INTERP, ARGIN(PMC *filehandle))
+{
+ ASSERT_ARGS(Parrot_io_get_os_handle)
+ return PARROT_FILEHANDLE(filehandle)->os_handle;
+}
+
/*
=item C<void Parrot_io_set_flags(PARROT_INTERP, PMC *filehandle, INTVAL flags)>
@@ -153,9 +205,7 @@
Parrot_io_set_flags(PARROT_INTERP, ARGIN(PMC *filehandle), INTVAL flags)
{
ASSERT_ARGS(Parrot_io_set_flags)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
SETATTR_FileHandle_flags(interp, filehandle, flags);
- SETATTR_Handle_flags(interp, handle, flags);
}
/*
@@ -202,12 +252,11 @@
*/
void
-Parrot_io_set_buffer_start(PARROT_INTERP, ARGIN(PMC *filehandle),
+Parrot_io_set_buffer_start(SHIM_INTERP, ARGIN(PMC *filehandle),
ARGIN_NULLOK(unsigned char *new_start))
{
ASSERT_ARGS(Parrot_io_set_buffer_start)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- PARROT_HANDLE(handle)->buffer_start = new_start;
+ PARROT_FILEHANDLE(filehandle)->buffer_start = new_start;
}
/*
@@ -230,11 +279,10 @@
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
unsigned char *
-Parrot_io_get_buffer_start(PARROT_INTERP, ARGIN(PMC *filehandle))
+Parrot_io_get_buffer_start(SHIM_INTERP, ARGIN(PMC *filehandle))
{
ASSERT_ARGS(Parrot_io_get_buffer_start)
- PMC * handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- return PARROT_HANDLE(handle)->buffer_start;
+ return PARROT_FILEHANDLE(filehandle)->buffer_start;
}
/*
@@ -257,11 +305,10 @@
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
unsigned char *
-Parrot_io_get_buffer_next(PARROT_INTERP, ARGIN(PMC *filehandle))
+Parrot_io_get_buffer_next(SHIM_INTERP, ARGIN(PMC *filehandle))
{
ASSERT_ARGS(Parrot_io_get_buffer_next)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- return PARROT_HANDLE(handle)->buffer_next;
+ return PARROT_FILEHANDLE(filehandle)->buffer_next;
}
/*
@@ -282,12 +329,11 @@
*/
void
-Parrot_io_set_buffer_next(PARROT_INTERP, ARGIN(PMC *filehandle),
+Parrot_io_set_buffer_next(SHIM_INTERP, ARGIN(PMC *filehandle),
ARGIN_NULLOK(unsigned char *new_next))
{
ASSERT_ARGS(Parrot_io_set_buffer_next)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- PARROT_HANDLE(handle)->buffer_next = new_next;
+ PARROT_FILEHANDLE(filehandle)->buffer_next = new_next;
}
/*
@@ -310,11 +356,10 @@
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
unsigned char *
-Parrot_io_get_buffer_end(PARROT_INTERP, ARGIN_NULLOK(PMC *filehandle))
+Parrot_io_get_buffer_end(SHIM_INTERP, ARGIN_NULLOK(PMC *filehandle))
{
ASSERT_ARGS(Parrot_io_get_buffer_end)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- return PARROT_HANDLE(handle)->buffer_end;
+ return PARROT_FILEHANDLE(filehandle)->buffer_end;
}
/*
@@ -335,12 +380,11 @@
*/
void
-Parrot_io_set_buffer_end(PARROT_INTERP, ARGIN(PMC *filehandle),
+Parrot_io_set_buffer_end(SHIM_INTERP, ARGIN(PMC *filehandle),
ARGIN_NULLOK(unsigned char *new_end))
{
ASSERT_ARGS(Parrot_io_set_buffer_end)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- PARROT_HANDLE(handle)->buffer_end = new_end;
+ PARROT_FILEHANDLE(filehandle)->buffer_end = new_end;
}
/*
@@ -361,11 +405,10 @@
PARROT_CAN_RETURN_NULL
INTVAL
-Parrot_io_get_buffer_flags(PARROT_INTERP, ARGIN(PMC *filehandle))
+Parrot_io_get_buffer_flags(SHIM_INTERP, ARGIN(PMC *filehandle))
{
ASSERT_ARGS(Parrot_io_get_buffer_flags)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- return PARROT_HANDLE(handle)->buffer_flags;
+ return PARROT_FILEHANDLE(filehandle)->buffer_flags;
}
/*
@@ -386,11 +429,10 @@
*/
void
-Parrot_io_set_buffer_flags(PARROT_INTERP, ARGIN(PMC *filehandle), INTVAL new_flags)
+Parrot_io_set_buffer_flags(SHIM_INTERP, ARGIN(PMC *filehandle), INTVAL new_flags)
{
ASSERT_ARGS(Parrot_io_set_buffer_flags)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- PARROT_HANDLE(handle)->buffer_flags = new_flags;
+ PARROT_FILEHANDLE(filehandle)->buffer_flags = new_flags;
}
/*
@@ -411,11 +453,10 @@
PARROT_CAN_RETURN_NULL
size_t
-Parrot_io_get_buffer_size(PARROT_INTERP, ARGIN(PMC *filehandle))
+Parrot_io_get_buffer_size(SHIM_INTERP, ARGIN(PMC *filehandle))
{
ASSERT_ARGS(Parrot_io_get_buffer_size)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- return PARROT_HANDLE(handle)->buffer_size;
+ return PARROT_FILEHANDLE(filehandle)->buffer_size;
}
/*
@@ -436,11 +477,10 @@
*/
void
-Parrot_io_set_buffer_size(PARROT_INTERP, ARGIN(PMC *filehandle), size_t new_size)
+Parrot_io_set_buffer_size(SHIM_INTERP, ARGIN(PMC *filehandle), size_t new_size)
{
ASSERT_ARGS(Parrot_io_set_buffer_size)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- PARROT_HANDLE(handle)->buffer_size = new_size;
+ PARROT_FILEHANDLE(filehandle)->buffer_size = new_size;
}
/*
@@ -460,13 +500,11 @@
PARROT_CAN_RETURN_NULL
void
-Parrot_io_clear_buffer(PARROT_INTERP, ARGIN(PMC *filehandle))
+Parrot_io_clear_buffer(SHIM_INTERP, ARGIN(PMC *filehandle))
{
ASSERT_ARGS(Parrot_io_clear_buffer)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- const INTVAL flags = PARROT_FILEHANDLE(filehandle)->flags;
- Parrot_Handle_attributes * io = PARROT_HANDLE(handle);
- if (io->buffer_start && (flags & PIO_BF_MALLOC)) {
+ Parrot_FileHandle_attributes *io = PARROT_FILEHANDLE(filehandle);
+ if (io->buffer_start && (io->flags & PIO_BF_MALLOC)) {
mem_sys_free(io->buffer_start);
io->buffer_start = NULL;
}
@@ -490,11 +528,10 @@
PARROT_EXPORT
PIOOFF_T
-Parrot_io_get_file_position(PARROT_INTERP, ARGIN(PMC *filehandle))
+Parrot_io_get_file_position(SHIM_INTERP, ARGIN(PMC *filehandle))
{
ASSERT_ARGS(Parrot_io_get_file_position)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- return PARROT_HANDLE(handle)->file_pos;
+ return PARROT_FILEHANDLE(filehandle)->file_pos;
}
/*
@@ -516,11 +553,10 @@
PARROT_EXPORT
PIOOFF_T
-Parrot_io_get_last_file_position(PARROT_INTERP, ARGIN(PMC *filehandle))
+Parrot_io_get_last_file_position(SHIM_INTERP, ARGIN(PMC *filehandle))
{
ASSERT_ARGS(Parrot_io_get_last_file_position)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- return PARROT_HANDLE(handle)->last_pos;
+ return PARROT_FILEHANDLE(filehandle)->last_pos;
}
/*
@@ -543,11 +579,10 @@
PARROT_EXPORT
void
-Parrot_io_set_file_position(PARROT_INTERP, ARGIN(PMC *filehandle), PIOOFF_T file_pos)
+Parrot_io_set_file_position(SHIM_INTERP, ARGIN(PMC *filehandle), PIOOFF_T file_pos)
{
ASSERT_ARGS(Parrot_io_set_file_position)
- PMC * const handle = Parrot_io_get_os_handle_pmc(interp, filehandle);
- Parrot_Handle_attributes *handle_struct = PARROT_HANDLE(handle);
+ Parrot_FileHandle_attributes *handle_struct = PARROT_FILEHANDLE(filehandle);
handle_struct->last_pos = handle_struct->file_pos;
handle_struct->file_pos = file_pos;
}
@@ -603,13 +638,12 @@
{
ASSERT_ARGS(Parrot_io_close_filehandle)
INTVAL result;
- PMC * handle = Parrot_io_get_os_handle_pmc(interp, pmc);
if (Parrot_io_is_closed_filehandle(interp, pmc))
return -1;
- Parrot_io_flush_buffer(interp, handle);
- PIO_FLUSH_HANDLE(interp, handle);
+ Parrot_io_flush_buffer(interp, pmc);
+ PIO_FLUSH(interp, pmc);
result = PIO_CLOSE(interp, pmc);
Parrot_io_clear_buffer(interp, pmc);
@@ -650,12 +684,11 @@
Parrot_io_flush_filehandle(PARROT_INTERP, ARGMOD(PMC *pmc))
{
ASSERT_ARGS(Parrot_io_flush_filehandle)
- PMC * handle = Parrot_io_get_os_handle_pmc(interp, pmc);
if (Parrot_io_is_closed(interp, pmc))
return;
- Parrot_io_flush_buffer(interp, handle);
- PIO_FLUSH_HANDLE(interp, handle);
+ Parrot_io_flush_buffer(interp, pmc);
+ PIO_FLUSH(interp, pmc);
}
/*
Modified: branches/io_cleanups/src/io/portable.c
==============================================================================
--- branches/io_cleanups/src/io/portable.c Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/src/io/portable.c Thu Jun 25 00:11:31 2009 (r39759)
@@ -25,7 +25,6 @@
#include <stdio.h>
#include "parrot/parrot.h"
#include "io_private.h"
-#include "../pmc/pmc_handle.h"
#ifdef PIO_OS_STDIO
@@ -247,10 +246,6 @@
Tests whether the filehandle has been closed.
-=item C<INTVAL Parrot_io_is_closed_handle_portable(PARROT_INTERP, PMC* handle)>
-
-Tests whether the Handle has been closed.
-
=cut
*/
@@ -265,14 +260,6 @@
return 0;
}
-INTVAL
-Parrot_io_is_closed_handle_portable(PARROT_INTERP, ARGIN(PMC* handle))
-{
- ASSERT_ARGS(Parrot_io_is_closed_handle_portable)
- if (PARROT_HANDLE(handle)->os_handle == (PIOHANDLE)NULL)
- return 1;
- return 0;
-}
/*
@@ -357,10 +344,6 @@
Flushes the underlying file descriptor of the given IO PMC.
-=item C<INTVAL Parrot_io_flush_handle_portable(PARROT_INTERP, PMC * handle)>
-
-Flushes the underlying file descriptor of the Handle PMC.
-
=cut
*/
@@ -372,15 +355,6 @@
return fflush((FILE *)Parrot_io_get_os_handle(interp, filehandle));
}
-INTVAL
-Parrot_io_flush_handle_portable(PARROT_INTERP, ARGMOD(PMC * handle))
-{
- ASSERT_ARGS(Parrot_io_flush_handle_unix)
- PIOHANDLE fd = PARROT_HANDLE(handle)->os_handle;
- return FlushFileBuffers(fd);
-}
-
-
/*
@@ -419,7 +393,8 @@
/*
-=item C<size_t Parrot_io_write_portable(PARROT_INTERP, PMC *handle, STRING *s)>
+=item C<size_t Parrot_io_write_portable(PARROT_INTERP, PMC *filehandle, STRING
+*s)>
Writes the given STRING to the provided IO PMC.
@@ -428,12 +403,12 @@
*/
size_t
-Parrot_io_write_portable(PARROT_INTERP, ARGIN(PMC *handle), ARGMOD(STRING *s))
+Parrot_io_write_portable(PARROT_INTERP, ARGIN(PMC *filehandle), ARGMOD(STRING *s))
{
ASSERT_ARGS(Parrot_io_write_portable)
void * const buffer = s->strstart;
- FILE * file = PARROT_HANDLE(handle)->os_handle;
- return fwrite(buffer, 1, s->bufused, file);
+ return fwrite(buffer, 1, s->bufused,
+ (FILE *)Parrot_io_get_os_handle(interp, filehandle));
}
Modified: branches/io_cleanups/src/io/socket_api.c
==============================================================================
--- branches/io_cleanups/src/io/socket_api.c Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/src/io/socket_api.c Thu Jun 25 00:11:31 2009 (r39759)
@@ -113,7 +113,8 @@
Parrot_io_socket_is_closed(PARROT_INTERP, ARGMOD(PMC *socket))
{
ASSERT_ARGS(Parrot_io_socket_is_closed)
- PIOHANDLE os_handle = Parrot_io_get_os_handle(interp, socket);
+ PIOHANDLE os_handle;
+ GETATTR_Socket_os_handle(interp, socket, os_handle);
#ifdef PIO_OS_WIN32
return (os_handle == (PIOHANDLE)INVALID_HANDLE_VALUE);
#endif
Modified: branches/io_cleanups/src/io/socket_unix.c
==============================================================================
--- branches/io_cleanups/src/io/socket_unix.c Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/src/io/socket_unix.c Thu Jun 25 00:11:31 2009 (r39759)
@@ -156,7 +156,7 @@
Parrot_io_connect_unix(PARROT_INTERP, ARGMOD(PMC *socket), ARGIN(PMC *r))
{
ASSERT_ARGS(Parrot_io_connect_unix)
- const PIOHANDLE os_handle = Parrot_io_get_os_handle(interp, socket);
+ Parrot_Socket_attributes * io = PARROT_SOCKET(socket);
if (!r)
return -1;
@@ -164,7 +164,7 @@
PARROT_SOCKET(socket)->remote = r;
AGAIN:
- if ((connect(os_handle, (struct sockaddr *)SOCKADDR_REMOTE(socket),
+ if ((connect(io->os_handle, (struct sockaddr *)SOCKADDR_REMOTE(socket),
sizeof (struct sockaddr_in))) != 0) {
switch (errno) {
case EINTR:
@@ -195,7 +195,7 @@
Parrot_io_bind_unix(PARROT_INTERP, ARGMOD(PMC *socket), ARGMOD(PMC *sockaddr))
{
ASSERT_ARGS(Parrot_io_bind_unix)
- const PIOHANDLE os_handle = Parrot_io_get_os_handle(interp, socket);
+ Parrot_Socket_attributes * io = PARROT_SOCKET(socket);
struct sockaddr_in * saddr;
if (!sockaddr)
@@ -205,7 +205,7 @@
saddr = SOCKADDR_LOCAL(socket);
- if ((bind(os_handle, (struct sockaddr *) saddr,
+ if ((bind(io->os_handle, (struct sockaddr *) saddr,
sizeof (struct sockaddr_in))) == -1) {
return -1;
}
@@ -225,11 +225,11 @@
*/
INTVAL
-Parrot_io_listen_unix(PARROT_INTERP, ARGMOD(PMC *socket), INTVAL sec)
+Parrot_io_listen_unix(SHIM_INTERP, ARGMOD(PMC *socket), INTVAL sec)
{
ASSERT_ARGS(Parrot_io_listen_unix)
- const PIOHANDLE os_handle = Parrot_io_get_os_handle(interp, socket);
- if ((listen(os_handle, sec)) == -1) {
+ Parrot_Socket_attributes * io = PARROT_SOCKET(socket);
+ if ((listen(io->os_handle, sec)) == -1) {
return -1;
}
return 0;
@@ -251,7 +251,7 @@
Parrot_io_accept_unix(PARROT_INTERP, ARGMOD(PMC *socket))
{
ASSERT_ARGS(Parrot_io_accept_unix)
- const PIOHANDLE os_handle = Parrot_io_get_os_handle(interp, socket);
+ Parrot_Socket_attributes * io = PARROT_SOCKET(socket);
PMC * newio = Parrot_io_new_socket_pmc(interp,
PIO_F_SOCKET | PIO_F_READ|PIO_F_WRITE);
Parrot_Socklen_t addrlen = sizeof (struct sockaddr_in);
@@ -262,13 +262,13 @@
PARROT_SOCKET(newio)->remote = pmc_new(interp, enum_class_Sockaddr);
saddr = SOCKADDR_REMOTE(newio);
- newsock = accept(os_handle, (struct sockaddr *)saddr, &addrlen);
+ newsock = accept(io->os_handle, (struct sockaddr *)saddr, &addrlen);
if (newsock == -1) {
return PMCNULL;
}
- Parrot_io_set_os_handle(interp, newio, newsock);
+ PARROT_SOCKET(newio)->os_handle = newsock;
/* XXX FIXME: Need to do a getsockname and getpeername here to
* fill in the sockaddr_in structs for local and peer */
@@ -290,11 +290,11 @@
*/
INTVAL
-Parrot_io_send_unix(PARROT_INTERP, ARGMOD(PMC *socket), ARGMOD(STRING *s))
+Parrot_io_send_unix(SHIM_INTERP, ARGMOD(PMC *socket), ARGMOD(STRING *s))
{
ASSERT_ARGS(Parrot_io_send_unix)
int error, bytes, byteswrote;
- const PIOHANDLE os_handle = Parrot_io_get_os_handle(interp, socket);
+ Parrot_Socket_attributes * io = PARROT_SOCKET(socket);
bytes = s->bufused;
byteswrote = 0;
@@ -302,7 +302,7 @@
/*
* Ignore encoding issues for now.
*/
- if ((error = send(os_handle, (char *)s->strstart + byteswrote,
+ if ((error = send(io->os_handle, (char *)s->strstart + byteswrote,
bytes, 0)) >= 0) {
byteswrote += error;
bytes -= error;
@@ -324,7 +324,7 @@
# endif
case EPIPE:
/* XXX why close it here and not below */
- close(os_handle);
+ close(io->os_handle);
return -1;
default:
return -1;
@@ -349,10 +349,10 @@
int error;
unsigned int bytesread = 0;
char buf[2048];
- const PIOHANDLE os_handle = Parrot_io_get_os_handle(interp, socket);
+ Parrot_Socket_attributes * io = PARROT_SOCKET(socket);
AGAIN:
- if ((error = recv(os_handle, buf, 2048, 0)) >= 0) {
+ if ((error = recv(io->os_handle, buf, 2048, 0)) >= 0) {
bytesread += error;
/* The charset should probably be 'binary', but right now httpd.pir
* only works with 'ascii'
@@ -373,11 +373,11 @@
# endif
case ECONNRESET:
/* XXX why close it on err return result is -1 anyway */
- close(os_handle);
+ close(io->os_handle);
*s = Parrot_str_new_noinit(interp, enum_stringrep_one, 0);
return -1;
default:
- close(os_handle);
+ close(io->os_handle);
*s = Parrot_str_new_noinit(interp, enum_stringrep_one, 0);
return -1;
}
@@ -406,27 +406,27 @@
*/
INTVAL
-Parrot_io_poll_unix(PARROT_INTERP, ARGMOD(PMC *socket), int which, int sec,
+Parrot_io_poll_unix(SHIM_INTERP, ARGMOD(PMC *socket), int which, int sec,
int usec)
{
ASSERT_ARGS(Parrot_io_poll_unix)
fd_set r, w, e;
struct timeval t;
- const PIOHANDLE os_handle = Parrot_io_get_os_handle(interp, socket);
+ Parrot_Socket_attributes * io = PARROT_SOCKET(socket);
t.tv_sec = sec;
t.tv_usec = usec;
FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
/* These should be defined in header */
- if (which & 1) FD_SET(os_handle, &r);
- if (which & 2) FD_SET(os_handle, &w);
- if (which & 4) FD_SET(os_handle, &e);
+ if (which & 1) FD_SET(io->os_handle, &r);
+ if (which & 2) FD_SET(io->os_handle, &w);
+ if (which & 4) FD_SET(io->os_handle, &e);
AGAIN:
- if ((select(os_handle+1, &r, &w, &e, &t)) >= 0) {
+ if ((select(io->os_handle+1, &r, &w, &e, &t)) >= 0) {
int n;
- n = (FD_ISSET(os_handle, &r) ? 1 : 0);
- n |= (FD_ISSET(os_handle, &w) ? 2 : 0);
- n |= (FD_ISSET(os_handle, &e) ? 4 : 0);
+ n = (FD_ISSET(io->os_handle, &r) ? 1 : 0);
+ n |= (FD_ISSET(io->os_handle, &w) ? 2 : 0);
+ n |= (FD_ISSET(io->os_handle, &e) ? 4 : 0);
return n;
}
else {
Modified: branches/io_cleanups/src/io/unix.c
==============================================================================
--- branches/io_cleanups/src/io/unix.c Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/src/io/unix.c Thu Jun 25 00:11:31 2009 (r39759)
@@ -30,7 +30,6 @@
#include "parrot/parrot.h"
#include "io_private.h"
-#include "../pmc/pmc_handle.h"
#ifdef PIO_OS_UNIX
@@ -383,10 +382,6 @@
Test whether the filehandle has been closed.
-=item C<INTVAL Parrot_io_is_closed_handle_unix(PARROT_INTERP, PMC* handle)>
-
-Test whether the Handle has been closed
-
=cut
*/
@@ -401,15 +396,6 @@
return 0;
}
-INTVAL
-Parrot_io_is_closed_handle_unix(PARROT_INTERP, ARGIN(PMC* handle))
-{
- ASSERT_ARGS(Parrot_io_is_closed_handle_unix)
- if (PARROT_HANDLE(handle)->os_handle == -1)
- return 1;
- return 0;
-}
-
/*
=item C<static INTVAL io_is_tty_unix(PIOHANDLE fd)>
@@ -482,10 +468,6 @@
XXX: Is it necessary to C<sync()> here?
-=item C<INTVAL Parrot_io_flush_handle_unix(PARROT_INTERP, PMC * handle)>
-
-Flush the Handle at the lowest level.
-
=cut
*/
@@ -498,14 +480,6 @@
return fsync(file_descriptor);
}
-INTVAL
-Parrot_io_flush_handle_unix(PARROT_INTERP, ARGMOD(PMC * handle))
-{
- ASSERT_ARGS(Parrot_io_flush_handle_unix)
- PIOHANDLE fd = PARROT_HANDLE(handle)->os_handle;
- return fsync(fd);
-}
-
/*
=item C<size_t Parrot_io_read_unix(PARROT_INTERP, PMC *filehandle, STRING
@@ -557,7 +531,7 @@
/*
-=item C<size_t Parrot_io_write_unix(PARROT_INTERP, PMC *handle, STRING *s)>
+=item C<size_t Parrot_io_write_unix(PARROT_INTERP, PMC *filehandle, STRING *s)>
Calls C<write()> to write C<len> bytes from the memory starting at
C<buffer> to the file descriptor in C<*io>.
@@ -567,10 +541,10 @@
*/
size_t
-Parrot_io_write_unix(PARROT_INTERP, ARGIN(PMC *handle), ARGMOD(STRING *s))
+Parrot_io_write_unix(PARROT_INTERP, ARGIN(PMC *filehandle), ARGMOD(STRING *s))
{
ASSERT_ARGS(Parrot_io_write_unix)
- PIOHANDLE file_descriptor = PARROT_HANDLE(handle)->os_handle;
+ PIOHANDLE file_descriptor = Parrot_io_get_os_handle(interp, filehandle);
const char * const buffer = s->strstart;
const char * ptr = buffer;
Modified: branches/io_cleanups/src/io/win32.c
==============================================================================
--- branches/io_cleanups/src/io/win32.c Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/src/io/win32.c Thu Jun 25 00:11:31 2009 (r39759)
@@ -28,7 +28,6 @@
#include "parrot/parrot.h"
#include "io_private.h"
-#include "../pmc/pmc_handle.h"
#ifdef PIO_OS_WIN32
@@ -353,10 +352,6 @@
Test whether the filehandle has been closed.
-=item C<INTVAL Parrot_io_is_closed_handle_win32(PARROT_INTERP, PMC* handle)>
-
-Test whether the Handle has been closed.
-
=cut
*/
@@ -371,15 +366,6 @@
return 0;
}
-INTVAL
-Parrot_io_is_closed_handle_win32(PARROT_INTERP, ARGIN(PMC* handle))
-{
- ASSERT_ARGS(Parrot_io_is_closed_handle_portable)
- if (PARROT_HANDLE(handle)->os_handle = INVALID_HANDLE_VALUE)
- return 1;
- return 0;
-}
-
/*
=item C<static INTVAL io_is_tty_win32(PIOHANDLE fd)>
@@ -405,10 +391,6 @@
Calls C<FlushFileBuffers()> to flush C<*io>'s file descriptor.
-=item C<INTVAL Parrot_io_flush_handle_win32(PARROT_INTERP, PMC * handle)>
-
-Flushes the low-level file descriptor from a Handle PMC.
-
=cut
*/
@@ -432,14 +414,6 @@
return FlushFileBuffers(Parrot_io_get_os_handle(interp, filehandle));
}
-INTVAL
-Parrot_io_flush_handle_win32(PARROT_INTERP, ARGMOD(PMC * handle))
-{
- ASSERT_ARGS(Parrot_io_flush_handle_unix)
- PIOHANDLE fd = PARROT_HANDLE(handle)->os_handle;
- return FlushFileBuffers(fd);
-}
-
/*
=item C<size_t Parrot_io_read_win32(PARROT_INTERP, PMC *filehandle, STRING
@@ -490,7 +464,7 @@
/*
-=item C<size_t Parrot_io_write_win32(PARROT_INTERP, PMC *handle, STRING *s)>
+=item C<size_t Parrot_io_write_win32(PARROT_INTERP, PMC *filehandle, STRING *s)>
Calls C<WriteFile()> to write C<len> bytes from the memory starting at
C<buffer> to C<*io>'s file descriptor. Returns C<(size_t)-1> on
@@ -502,7 +476,7 @@
size_t
Parrot_io_write_win32(PARROT_INTERP,
- ARGIN(PMC *handle),
+ ARGIN(PMC *filehandle),
ARGIN(STRING *s))
{
ASSERT_ARGS(Parrot_io_write_win32)
@@ -510,17 +484,15 @@
DWORD err;
void * const buffer = s->strstart;
DWORD len = (DWORD) s->bufused;
- PIOHANDLE os_handle = PARROT_HANDLE(handle)->os_handle;
- INTVAL flags = PARROT_HANDLE(handle)->flags;
+ PIOHANDLE os_handle = Parrot_io_get_os_handle(interp, filehandle);
/* do it by hand, Win32 hasn't any specific flag */
- if (flags & PIO_F_APPEND) {
+ if (Parrot_io_get_flags(interp, filehandle) & PIO_F_APPEND) {
LARGE_INTEGER p;
p.LowPart = 0;
p.HighPart = 0;
p.LowPart = SetFilePointer(os_handle, p.LowPart,
&p.HighPart, FILE_END);
- /* XXX: This doesn't look right. We set p.LowPart to 0 above */
if (p.LowPart == 0xFFFFFFFF && (GetLastError() != NO_ERROR)) {
/* Error - exception */
return (size_t)-1;
Modified: branches/io_cleanups/src/pmc/filehandle.pmc
==============================================================================
--- branches/io_cleanups/src/pmc/filehandle.pmc Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/src/pmc/filehandle.pmc Thu Jun 25 00:11:31 2009 (r39759)
@@ -31,12 +31,18 @@
#endif
#endif
-pmclass FileHandle {
- ATTR PMC *os_handle; /* encapsulated OS handle */
+pmclass FileHandle extends Handle {
ATTR INTVAL flags; /* Filehandle flags */
ATTR STRING *filename; /* The opened path and filename */
ATTR STRING *mode; /* The mode string used in open */
ATTR STRING *encoding; /* The encoding for read/write */
+ ATTR PIOOFF_T file_pos; /* Current real file pointer */
+ ATTR PIOOFF_T last_pos; /* Last file position */
+ ATTR size_t buffer_size; /* Buffer size */
+ ATTR INTVAL buffer_flags; /* Buffer flags */
+ ATTR unsigned char *buffer_start; /* Start of buffer */
+ ATTR unsigned char *buffer_end; /* End of buffer */
+ ATTR unsigned char *buffer_next; /* Current read/write pointer */
/*
@@ -57,9 +63,16 @@
data_struct->filename = NULL;
data_struct->mode = NULL;
data_struct->encoding = NULL;
+ data_struct->file_pos = piooffsetzero;
+ data_struct->last_pos = piooffsetzero;
+ data_struct->buffer_size = 0;
+ data_struct->buffer_flags = 0;
+ data_struct->buffer_start = NULL;
+ data_struct->buffer_end = NULL;
+ data_struct->buffer_next = NULL;
- /* Create the handle pmc */
- data_struct->os_handle = Parrot_io_make_os_handle_pmc(INTERP);
+ /* Initialize the os_handle to the platform-specific value for closed. */
+ data_struct->os_handle = (PIOHANDLE) PIO_INVALID_HANDLE;
PObj_custom_mark_SET(SELF);
PObj_active_destroy_SET(SELF);
@@ -80,7 +93,7 @@
PMC * const copy = Parrot_io_new_pmc(interp, old_struct->flags);
Parrot_FileHandle_attributes * const data_struct = PARROT_FILEHANDLE(copy);
- data_struct->os_handle = VTABLE_clone(INTERP, old_struct->os_handle);
+ data_struct->os_handle = Parrot_dup(old_struct->os_handle);
return copy;
}
@@ -103,8 +116,6 @@
Parrot_gc_mark_PObj_alive(interp, (PObj *)data_struct->filename);
if (data_struct->encoding)
Parrot_gc_mark_PObj_alive(interp, (PObj *)data_struct->encoding);
- if (data_struct->os_handle)
- Parrot_gc_mark_PObj_alive(interp, (PObj *)data_struct->os_handle);
}
/*
@@ -119,7 +130,18 @@
VTABLE void destroy() {
if (PARROT_FILEHANDLE(SELF)) {
Parrot_FileHandle_attributes *data_struct = PARROT_FILEHANDLE(SELF);
- mem_sys_free(data_struct);
+
+ if (!Parrot_io_is_closed_filehandle(INTERP, SELF)) {
+ if (data_struct->flags & PIO_F_SHARED)
+ Parrot_io_flush_filehandle(INTERP, SELF);
+ else
+ Parrot_io_close_filehandle(INTERP, SELF);
+ }
+
+ if (data_struct->buffer_start)
+ mem_sys_free(data_struct->buffer_start);
+
+ mem_sys_free(PARROT_FILEHANDLE(SELF));
PMC_data(SELF) = NULL;
}
}
@@ -594,7 +616,7 @@
METHOD get_fd() {
#ifndef PIO_OS_STDIO
INTVAL os_handle;
- os_handle = Parrot_io_get_os_handle(INTERP, SELF);
+ GET_ATTR_os_handle(INTERP, SELF, os_handle);
RETURN(INTVAL os_handle);
#endif /*PIO_OS_STDIO*/
Modified: branches/io_cleanups/src/pmc/handle.pmc
==============================================================================
--- branches/io_cleanups/src/pmc/handle.pmc Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/src/pmc/handle.pmc Thu Jun 25 00:11:31 2009 (r39759)
@@ -25,50 +25,18 @@
#include "parrot/parrot.h"
#include "../src/io/io_private.h"
-pmclass Handle {
+pmclass Handle provides Handle {
+ /* TODO: Consider encapsulating PIOHANDLE as a PMC type, for subclassing */
ATTR PIOHANDLE os_handle; /* Low level OS descriptor */
- ATTR PIOOFF_T file_pos; /* Current real file pointer */
- ATTR PIOOFF_T last_pos; /* Last file position */
- ATTR INTVAL flags; /* A copy of the flags */
- ATTR size_t buffer_size; /* Buffer size */
- ATTR INTVAL buffer_flags; /* Buffer flags */
- ATTR unsigned char *buffer_start; /* Start of buffer */
- ATTR unsigned char *buffer_end; /* End of buffer */
- ATTR unsigned char *buffer_next; /* Current read/write pointer */
VTABLE void init() {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "Handle cannot be instantiated directly from PIR.");
+ "Handle cannot be instantiated directly.");
}
VTABLE void init_pmc(PMC * init) {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "Handle cannot be instantiated directly from PIR.");
- }
-
- VTABLE PMC* clone() {
- PMC * const newhandle = Parrot_io_make_os_handle_pmc(INTERP);
- PARROT_HANDLE(newhandle)->os_handle = Parrot_dup(PARROT_HANDLE(SELF)->os_handle);
- return newhandle;
- }
-
- VTABLE void destroy() {
- Parrot_Handle_attributes * data_struct = PARROT_HANDLE(SELF);
- if (data_struct) {
- if (!PIO_IS_CLOSED_HANDLE(INTERP, SELF)) {
- Parrot_io_flush_buffer(INTERP, SELF);
- PIO_FLUSH_HANDLE(INTERP, SELF);
- if (!(data_struct->flags & PIO_F_SHARED))
- Parrot_io_close_piohandle(INTERP, data_struct->os_handle);
- }
-
- if (data_struct->buffer_start) {
- mem_sys_free(data_struct->buffer_start);
- data_struct->buffer_start = NULL;
- }
- mem_sys_free(data_struct);
- PMC_data(SELF) = NULL;
- }
+ "Handle cannot be instantiated directly.");
}
}
Modified: branches/io_cleanups/src/pmc/socket.pmc
==============================================================================
--- branches/io_cleanups/src/pmc/socket.pmc Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/src/pmc/socket.pmc Thu Jun 25 00:11:31 2009 (r39759)
@@ -20,10 +20,9 @@
#include "../src/io/io_private.h"
-pmclass Socket {
+pmclass Socket extends Handle {
ATTR PMC *local; /* Local addr */
ATTR PMC *remote; /* Remote addr */
- ATTR PMC *os_handle; /* encapuslated handle type */
/*
@@ -42,7 +41,6 @@
PMC_data(SELF) = data_struct;
data_struct->local = PMCNULL;
data_struct->remote = PMCNULL;
- data_struct->os_handle = Parrot_io_make_os_handle_pmc(INTERP);
PObj_custom_mark_destroy_SETALL(SELF);
}
@@ -87,9 +85,6 @@
if (data->remote)
Parrot_gc_mark_PObj_alive(interp, (PObj *)data->remote);
-
- if (data->os_handle)
- Parrot_gc_mark_PObj_alive(interp, (PObj *)data->os_handle);
}
}
/*
@@ -102,8 +97,13 @@
*/
VTABLE void destroy() {
- if (PARROT_SOCKET(SELF))
- mem_sys_free(PARROT_SOCKET(SELF));
+ if (PARROT_SOCKET(SELF)) {
+ Parrot_Socket_attributes *data_struct = PARROT_SOCKET(SELF);
+
+ if (data_struct->os_handle != PIO_INVALID_HANDLE)
+ Parrot_io_close_piohandle(interp, data_struct->os_handle);
+ data_struct->os_handle = PIO_INVALID_HANDLE;
+ }
}
/*
Modified: branches/io_cleanups/src/pmc/stringhandle.pmc
==============================================================================
--- branches/io_cleanups/src/pmc/stringhandle.pmc Wed Jun 24 10:52:28 2009 (r39758)
+++ branches/io_cleanups/src/pmc/stringhandle.pmc Thu Jun 25 00:11:31 2009 (r39759)
@@ -46,7 +46,7 @@
return Parrot_str_equal(interp, s, CONST_STRING(interp, "utf8"));
}
-pmclass StringHandle need_ext {
+pmclass StringHandle extends Handle need_ext {
ATTR INTVAL flags; /* Filehandle flags */
ATTR STRING *stringhandle; /* The string data */
ATTR STRING *mode; /* The mode string used in open */
More information about the parrot-commits
mailing list