Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rearrange some buffer macros. Implement Parrot_io_tell to match the o…

…ld behavior (which I don't think is right, but whatever)
  • Loading branch information...
commit 853122508a7d52b6ff70b47e92ba548776510254 1 parent df032cc
@Whiteknight Whiteknight authored
Showing with 40 additions and 13 deletions.
  1. +25 −5 src/io/api.c
  2. +0 −6 src/io/buffer.c
  3. +15 −2 src/io/io_private.h
View
30 src/io/api.c
@@ -884,6 +884,23 @@ Parrot_io_seek(PARROT_INTERP, ARGMOD(PMC *handle), PIOOFF_T offset, INTVAL w)
if (Parrot_io_is_closed(interp, handle))
return -1;
+ {
+ IO_VTABLE * const vtable = IO_GET_VTABLE(interp, handle);
+ IO_BUFFER * const read_buffer = IO_GET_READ_BUFFER(interp, handle);
+ IO_BUFFER * const write_buffer = IO_GET_WRITE_BUFFER(interp, handle);
+
+ /* If we have a write buffer, flush that out to disk before we attempt
+ to do any seek operation. We need the data there before we can
+ seek. */
+ if (write_buffer)
+ Parrot_io_buffer_flush(interp, write_buffer, handle, vtable);
+
+ /* If we have a read_buffer, we can try to seek inside the buffer.
+ maybe we can avoid touching the disk at all. */
+ if (read_buffer) {
+ if (
+ }
+
// TODO: This
return Parrot_io_seek_buffer(interp, handle, offset, w);
}
@@ -915,11 +932,14 @@ Parrot_io_tell(PARROT_INTERP, ARGMOD(PMC *handle))
ASSERT_ARGS(Parrot_io_tell)
if (Parrot_io_is_closed(interp, handle))
return -1;
-
- // TODO: This
- //return Parrot_io_get_file_position(interp, handle);
- return 0;
- /* return PIO_TELL(interp, os_handle); */
+ {
+ IO_VTABLE * const vtable = IO_GET_VTABLE(interp, handle);
+ /* TODO: We may have data in the read buffer, so this might not be
+ accurate. However, this is what the old system was doing so we
+ can stick with the same semantic until we come up with something
+ more sane. */
+ return vtable->tell(interp, handle);
+ }
}
/*
View
6 src/io/buffer.c
@@ -72,12 +72,6 @@ static size_t io_buffer_transfer_to_mem(PARROT_INTERP,
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
-#define BUFFER_IS_EMPTY(b) (b->buffer_start == b->buffer_end)
-#define BUFFER_IS_FULL(b) ((size_t)(b->buffer_end - b->buffer_start) == b->buffer_size)
-#define BUFFER_USED_SIZE(b) ((size_t)(b->buffer_end - b->buffer_start))
-#define BUFFER_AVAILABLE_SIZE(b) (b->buffer_size - ((size_t)(b->buffer_end - b->buffer_start)))
-#define BUFFER_CAN_BE_NORMALIZED(b) ((size_t)(b->buffer_start - b->buffer_ptr) > (b->buffer_size / 2))
-
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
IO_BUFFER *
View
17 src/io/io_private.h
@@ -123,10 +123,23 @@ struct _ParrotIOData {
#define _PIO_STDOUT(i) ((i)->piodata->table[PIO_STDOUT_FILENO])
#define _PIO_STDERR(i) ((i)->piodata->table[PIO_STDERR_FILENO])
-#define IO_VTABLE_UNIMPLEMENTED(i, v, s) Parrot_ex_throw_from_c_args((i), NULL, EXCEPTION_PIO_ERROR, "Method '%s' not implemented for type %s", s, v->name)
-
+/* Throw an exception if this vtable is not implemented. */
+#define IO_VTABLE_UNIMPLEMENTED(i, v, s) do { \
+ Parrot_ex_throw_from_c_args((i), NULL, EXCEPTION_PIO_ERROR, \
+ "Method '%s' not implemented for type %s", s, v->name); \
+ } while(0)
+
+/* Return value from IO_VTABLE->total_size if the total size of the stream
+ cannot be determined ahead of time */
#define PIO_UNKNOWN_SIZE (size_t)-1
+/* Buffer Macros */
+#define BUFFER_IS_EMPTY(b) (b->buffer_start == b->buffer_end)
+#define BUFFER_IS_FULL(b) ((size_t)(b->buffer_end - b->buffer_start) == b->buffer_size)
+#define BUFFER_USED_SIZE(b) ((size_t)(b->buffer_end - b->buffer_start))
+#define BUFFER_AVAILABLE_SIZE(b) (b->buffer_size - ((size_t)(b->buffer_end - b->buffer_start)))
+#define BUFFER_CAN_BE_NORMALIZED(b) ((size_t)(b->buffer_start - b->buffer_ptr) > (b->buffer_size / 2))
+
/* HEADERIZER BEGIN: src/io/utilities.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
Please sign in to comment.
Something went wrong with that request. Please try again.