Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More iolayers work:

- rename the callback types
- move types and the call macros into iolayer.t
- move typedef for Imager__IO to imperl.h

so now io glue objects can be used from XS/Inline
  • Loading branch information...
commit 0778adbf7b008e7a3230bab32fc70d5ead0ed2b6 1 parent eda1622
Tony Cook authored
View
2  Imager.xs
@@ -17,8 +17,6 @@ extern "C" {
#include "regmach.h"
#include "imextdef.h"
-typedef io_glue* Imager__IO;
-
#if i_int_hlines_testing()
#include "imageri.h"
#endif
View
1  MANIFEST
@@ -88,6 +88,7 @@ imperl.h
io.c
iolayer.c
iolayer.h
+iolayert.h IO layer types
jpeg.c
lib/Imager/API.pm
lib/Imager/APIRef.pm API function reference
View
1  imdatatypes.h
@@ -516,6 +516,7 @@ enum {
i_dmeasure_limit = 2,
};
+#include "iolayert.h"
#endif
View
2  imperl.h
@@ -30,4 +30,6 @@ typedef FT2_Fonthandle* Imager__Font__FT2;
#define IFILL_DESTROY(fill) i_fill_destroy(fill);
typedef i_fill_t* Imager__FillHandle;
+typedef io_glue *Imager__IO;
+
#endif
View
15 iolayer.c
@@ -57,8 +57,8 @@ typedef struct {
off_t cpos; /* Offset within the current */
} io_ex_buffer;
-static void io_obj_setp_buffer(io_obj *io, char *p, size_t len, closebufp closecb, void *closedata);
-static void io_obj_setp_cb2 (io_obj *io, void *p, readl readcb, writel writecb, seekl seekcb, closel closecb, destroyl destroycb);
+static void io_obj_setp_buffer(io_obj *io, char *p, size_t len, i_io_closebufp_t closecb, void *closedata);
+static void io_obj_setp_cb2 (io_obj *io, void *p, i_io_readl_t readcb, i_io_writel_t writecb, i_io_seekl_t seekcb, i_io_closel_t closecb, i_io_destroyl_t destroycb);
/* turn current offset, file length, whence and offset into a new offset */
#define calc_seek_offset(curr_off, length, offset, whence) \
@@ -794,7 +794,7 @@ Sets an io_object for reading from a buffer source
*/
static void
-io_obj_setp_buffer(io_obj *io, char *p, size_t len, closebufp closecb,
+io_obj_setp_buffer(io_obj *io, char *p, size_t len, i_io_closebufp_t closecb,
void *closedata) {
io->buffer.type = BUFFER;
io->buffer.data = p;
@@ -822,7 +822,7 @@ Sets an io_object for reading from a source that uses callbacks
*/
static void
-io_obj_setp_cb2(io_obj *io, void *p, readl readcb, writel writecb, seekl seekcb, closel closecb, destroyl destroycb) {
+io_obj_setp_cb2(io_obj *io, void *p, i_io_readl_t readcb, i_io_writel_t writecb, i_io_seekl_t seekcb, i_io_closel_t closecb, i_io_destroyl_t destroycb) {
io->cb.type = CBSEEK;
io->cb.p = p;
io->cb.readcb = readcb;
@@ -936,7 +936,7 @@ from specified buffer. Note that the buffer is not copied.
*/
io_glue *
-io_new_buffer(char *data, size_t len, closebufp closecb, void *closedata) {
+io_new_buffer(char *data, size_t len, i_io_closebufp_t closecb, void *closedata) {
io_glue *ig;
io_ex_buffer *ieb = mymalloc(sizeof(io_ex_buffer));
@@ -997,8 +997,9 @@ io_new_fd(int fd) {
return ig;
}
-io_glue *io_new_cb(void *p, readl readcb, writel writecb, seekl seekcb,
- closel closecb, destroyl destroycb) {
+io_glue *io_new_cb(void *p, i_io_readl_t readcb, i_io_writel_t writecb,
+ i_io_seekl_t seekcb, i_io_closel_t closecb,
+ i_io_destroyl_t destroycb) {
io_glue *ig;
io_ex_rseek *ier = mymalloc(sizeof(io_ex_rseek));
View
99 iolayer.h
@@ -12,11 +12,7 @@
*/
-#include <stdio.h>
-#ifndef _MSC_VER
-#include <unistd.h>
-#endif
-#include <sys/types.h>
+#include "iolayert.h"
/* #define BBSIZ 1096 */
#define BBSIZ 16384
@@ -24,104 +20,15 @@
#define IO_TEMP_SEEK 1<<1L
-typedef enum { FDSEEK, FDNOSEEK, BUFFER, CBSEEK, CBNOSEEK, BUFCHAIN } io_type;
-
-#ifdef _MSC_VER
-typedef int ssize_t;
-#endif
-
-typedef struct i_io_glue_t i_io_glue_t;
-
-/* compatibility for now */
-typedef i_io_glue_t io_glue;
-
-/* Callbacks we give out */
-
-typedef ssize_t(*readp) (io_glue *ig, void *buf, size_t count);
-typedef ssize_t(*writep)(io_glue *ig, const void *buf, size_t count);
-typedef off_t (*seekp) (io_glue *ig, off_t offset, int whence);
-typedef void (*closep)(io_glue *ig);
-typedef ssize_t(*sizep) (io_glue *ig);
-
-typedef void (*closebufp)(void *p);
-typedef void (*i_io_destroy_t)(i_io_glue_t *ig);
-
-
-/* Callbacks we get */
-
-typedef ssize_t(*readl) (void *p, void *buf, size_t count);
-typedef ssize_t(*writel)(void *p, const void *buf, size_t count);
-typedef off_t (*seekl) (void *p, off_t offset, int whence);
-typedef void (*closel)(void *p);
-typedef void (*destroyl)(void *p);
-typedef ssize_t(*sizel) (void *p);
-
-extern char *io_type_names[];
-
-
-
-/* Structures to describe data sources */
-
-typedef struct {
- io_type type;
- int fd;
-} io_fdseek;
-
-typedef struct {
- io_type type; /* Must be first parameter */
- char *name; /* Data source name */
- char *data;
- size_t len;
- closebufp closecb; /* free memory mapped segment or decrement refcount */
- void *closedata;
-} io_buffer;
-
-typedef struct {
- io_type type; /* Must be first parameter */
- char *name; /* Data source name */
- void *p; /* Callback data */
- readl readcb;
- writel writecb;
- seekl seekcb;
- closel closecb;
- destroyl destroycb;
-} io_cb;
-
-typedef union {
- io_type type;
- io_fdseek fdseek;
- io_buffer buffer;
- io_cb cb;
-} io_obj;
-
-struct i_io_glue_t {
- io_obj source;
- int flags; /* Flags */
- void *exdata; /* Pair specific data */
- readp readcb;
- writep writecb;
- seekp seekcb;
- closep closecb;
- sizep sizecb;
- i_io_destroy_t destroycb;
-};
-
void io_glue_commit_types(io_glue *ig);
void io_glue_gettypes (io_glue *ig, int reqmeth);
-
/* XS functions */
io_glue *io_new_fd(int fd);
io_glue *io_new_bufchain(void);
-io_glue *io_new_buffer(char *data, size_t len, closebufp closecb, void *closedata);
-io_glue *io_new_cb(void *p, readl readcb, writel writecb, seekl seekcb, closel closecb, destroyl destroycb);
+io_glue *io_new_buffer(char *data, size_t len, i_io_closebufp_t closecb, void *closedata);
+io_glue *io_new_cb(void *p, i_io_readl_t readcb, i_io_writel_t writecb, i_io_seekl_t seekcb, i_io_closel_t closecb, i_io_destroyl_t destroycb);
size_t io_slurp(io_glue *ig, unsigned char **c);
void io_glue_destroy(io_glue *ig);
-#define i_io_type(ig) ((ig)->source.ig_type)
-#define i_io_read(ig, buf, size) ((ig)->readcb((ig), (buf), (size)))
-#define i_io_write(ig, data, size) ((ig)->writecb((ig), (data), (size)))
-#define i_io_seek(ig, offset, whence) ((ig)->seekcb((ig), (offset), (whence)))
-#define i_io_close(ig) ((ig)->closecb(ig))
-
#endif /* _IOLAYER_H_ */
View
98 iolayert.h
@@ -0,0 +1,98 @@
+#ifndef IMAGER_IOLAYERT_H
+#define IMAGER_IOLAYERT_H
+
+#ifndef _MSC_VER
+#include <unistd.h>
+#endif
+#include <sys/types.h>
+
+typedef enum { FDSEEK, FDNOSEEK, BUFFER, CBSEEK, CBNOSEEK, BUFCHAIN } io_type;
+
+#ifdef _MSC_VER
+typedef int ssize_t;
+#endif
+
+typedef struct i_io_glue_t i_io_glue_t;
+
+/* compatibility for now */
+typedef i_io_glue_t io_glue;
+
+/* Callbacks we give out */
+
+typedef ssize_t(*i_io_readp_t) (io_glue *ig, void *buf, size_t count);
+typedef ssize_t(*i_io_writep_t)(io_glue *ig, const void *buf, size_t count);
+typedef off_t (*i_io_seekp_t) (io_glue *ig, off_t offset, int whence);
+typedef void (*i_io_closep_t)(io_glue *ig);
+typedef ssize_t(*i_io_sizep_t) (io_glue *ig);
+
+typedef void (*i_io_closebufp_t)(void *p);
+typedef void (*i_io_destroyp_t)(i_io_glue_t *ig);
+
+
+/* Callbacks we get */
+
+typedef ssize_t(*i_io_readl_t) (void *p, void *buf, size_t count);
+typedef ssize_t(*i_io_writel_t)(void *p, const void *buf, size_t count);
+typedef off_t (*i_io_seekl_t) (void *p, off_t offset, int whence);
+typedef void (*i_io_closel_t)(void *p);
+typedef void (*i_io_destroyl_t)(void *p);
+typedef ssize_t(*i_io_sizel_t) (void *p);
+
+extern char *io_type_names[];
+
+
+
+/* Structures to describe data sources */
+
+typedef struct {
+ io_type type;
+ int fd;
+} io_fdseek;
+
+typedef struct {
+ io_type type; /* Must be first parameter */
+ char *name; /* Data source name */
+ char *data;
+ size_t len;
+ i_io_closebufp_t closecb; /* free memory mapped segment or decrement refcount */
+ void *closedata;
+} io_buffer;
+
+typedef struct {
+ io_type type; /* Must be first parameter */
+ char *name; /* Data source name */
+ void *p; /* Callback data */
+ i_io_readl_t readcb;
+ i_io_writel_t writecb;
+ i_io_seekl_t seekcb;
+ i_io_closel_t closecb;
+ i_io_destroyl_t destroycb;
+} io_cb;
+
+typedef union {
+ io_type type;
+ io_fdseek fdseek;
+ io_buffer buffer;
+ io_cb cb;
+} io_obj;
+
+struct i_io_glue_t {
+ io_obj source;
+ int flags; /* Flags */
+ void *exdata; /* Pair specific data */
+ i_io_readp_t readcb;
+ i_io_writep_t writecb;
+ i_io_seekp_t seekcb;
+ i_io_closep_t closecb;
+ i_io_sizep_t sizecb;
+ i_io_destroyp_t destroycb;
+};
+
+#define i_io_type(ig) ((ig)->source.ig_type)
+#define i_io_read(ig, buf, size) ((ig)->readcb((ig), (buf), (size)))
+#define i_io_write(ig, data, size) ((ig)->writecb((ig), (data), (size)))
+#define i_io_seek(ig, offset, whence) ((ig)->seekcb((ig), (offset), (whence)))
+#define i_io_close(ig) ((ig)->closecb(ig))
+
+
+#endif
Please sign in to comment.
Something went wrong with that request. Please try again.