This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add typedefs for bfd_openr_iovec functions


Hi.

This patch adds typedefs for the functions passed to bfd_openr_iovec.
I'm working on a patch to use them in gdb, but this is a clean up in
its own right so I'm submitting it now.

Ok to check in?

Notes:

- gdb uses _ftype suffix as a convention for function typedefs,
  but I gather bfd uses _type so I went with that.

- I put the CODE_FRAGMENT in its own comment, not sure whether there
  were any conventions to do otherwise.  Let me know if/how you'd like
  this done differently.

2014-08-05  Doug Evans  <dje@google.com>

	* opncls.c (bfd_openr_iovec_open_type): New typedef.
	(bfd_openr_iovec_close_type): New typedef.
	(bfd_openr_iovec_pread_type): New typedef.
	(bfd_openr_iovec_stat_type): New typedef.
	(struct opncls, bfd_openr_iovec): Update to use them.
	* bfd-in2.h: Regenerate.

diff --git a/bfd/opncls.c b/bfd/opncls.c
index a2a35f4..2e09c70 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -408,24 +408,34 @@ bfd_openstreamr (const char *filename, const char *target, void *streamarg)
 }
 
 /*
+CODE_FRAGMENT
+.{* The type of the "open" function to pass to bfd_openr_iovec.  *}
+.typedef void *(bfd_openr_iovec_open_type) (struct bfd *nbfd,
+.                                           void *open_closure);
+.{* The type of the "close" function to pass to bfd_openr_iovec.  *}
+.typedef int (bfd_openr_iovec_close_type) (struct bfd *nbfd, void *stream);
+.{* The type of the "pread" function to pass to bfd_openr_iovec.  *}
+.typedef file_ptr (bfd_openr_iovec_pread_type) (struct bfd *nbfd, void *stream,
+.                                               void *buf,
+.                                               file_ptr nbytes,
+.                                               file_ptr offset);
+.{* The type of the "stat" function to pass to bfd_openr_iovec.  *}
+.typedef int (bfd_openr_iovec_stat_type) (struct bfd *nbfd, void *stream,
+.                                         struct stat *sb);
+.
+*/
+
+/*
 FUNCTION
 	bfd_openr_iovec
 
 SYNOPSIS
         bfd *bfd_openr_iovec (const char *filename, const char *target,
-                              void *(*open_func) (struct bfd *nbfd,
-                                                  void *open_closure),
+                              bfd_openr_iovec_open_type *open_func,
                               void *open_closure,
-                              file_ptr (*pread_func) (struct bfd *nbfd,
-                                                      void *stream,
-                                                      void *buf,
-                                                      file_ptr nbytes,
-                                                      file_ptr offset),
-                              int (*close_func) (struct bfd *nbfd,
-                                                 void *stream),
-			      int (*stat_func) (struct bfd *abfd,
-					        void *stream,
-					        struct stat *sb));
+                              bfd_openr_iovec_pread_type *pread_func,
+                              bfd_openr_iovec_close_type *close_func,
+                              bfd_openr_iovec_stat_type *stat_func);
 
 DESCRIPTION
 
@@ -467,10 +477,9 @@ DESCRIPTION
 struct opncls
 {
   void *stream;
-  file_ptr (*pread) (struct bfd *abfd, void *stream, void *buf,
-		     file_ptr nbytes, file_ptr offset);
-  int (*close) (struct bfd *abfd, void *stream);
-  int (*stat) (struct bfd *abfd, void *stream, struct stat *sb);
+  bfd_openr_iovec_pread_type *pread;
+  bfd_openr_iovec_close_type *close;
+  bfd_openr_iovec_stat_type *stat;
   file_ptr where;
 };
 
@@ -564,12 +573,11 @@ static const struct bfd_iovec opncls_iovec = {
 
 bfd *
 bfd_openr_iovec (const char *filename, const char *target,
-		 void *(*open_p) (struct bfd *, void *),
+		 bfd_openr_iovec_open_type *open_p,
 		 void *open_closure,
-		 file_ptr (*pread_p) (struct bfd *, void *, void *,
-				      file_ptr, file_ptr),
-		 int (*close_p) (struct bfd *, void *),
-		 int (*stat_p) (struct bfd *, void *, struct stat *))
+		 bfd_openr_iovec_pread_type *pread_p,
+		 bfd_openr_iovec_close_type *close_p,
+		 bfd_openr_iovec_stat_type *stat_p)
 {
   bfd *nbfd;
   const bfd_target *target_vec;
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 8c77c81..83a569f 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -1033,20 +1033,26 @@ bfd *bfd_fdopenr (const char *filename, const char *target, int fd);
 
 bfd *bfd_openstreamr (const char * filename, const char * target, void * stream);
 
+/* The type of the "open" function to pass to bfd_openr_iovec.  */
+typedef void *(bfd_openr_iovec_open_type) (struct bfd *nbfd,
+                                           void *open_closure);
+/* The type of the "close" function to pass to bfd_openr_iovec.  */
+typedef int (bfd_openr_iovec_close_type) (struct bfd *nbfd, void *stream);
+/* The type of the "pread" function to pass to bfd_openr_iovec.  */
+typedef file_ptr (bfd_openr_iovec_pread_type) (struct bfd *nbfd, void *stream,
+                                               void *buf,
+                                               file_ptr nbytes,
+                                               file_ptr offset);
+/* The type of the "stat" function to pass to bfd_openr_iovec.  */
+typedef int (bfd_openr_iovec_stat_type) (struct bfd *nbfd, void *stream,
+                                         struct stat *sb);
+
 bfd *bfd_openr_iovec (const char *filename, const char *target,
-    void *(*open_func) (struct bfd *nbfd,
-    void *open_closure),
+    bfd_openr_iovec_open_type *open_func,
     void *open_closure,
-    file_ptr (*pread_func) (struct bfd *nbfd,
-    void *stream,
-    void *buf,
-    file_ptr nbytes,
-    file_ptr offset),
-    int (*close_func) (struct bfd *nbfd,
-    void *stream),
-    int (*stat_func) (struct bfd *abfd,
-    void *stream,
-    struct stat *sb));
+    bfd_openr_iovec_pread_type *pread_func,
+    bfd_openr_iovec_close_type *close_func,
+    bfd_openr_iovec_stat_type *stat_func);
 
 bfd *bfd_openw (const char *filename, const char *target);
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]