Prototype of g_io_channel_write() and gnet_iochennel_writen()



I didn't find a mailing list for glib, so I'm sending here.

These are the current prototypes:

    GIOError  g_io_channel_write    (GIOChannel    *channel,
                                     gchar         *buf,
                                     guint          count,
                                     guint         *bytes_written);

    GIOError gnet_io_channel_writen (GIOChannel    *channel, 
                                     gchar         *buf, 
                                     guint          len,
                                     guint         *bytes_written);

I propose they ought to be:

    GIOError  g_io_channel_write    (GIOChannel    *channel,
                                     const gchar    *buf,
                                     guint          count,
                                     guint         *bytes_written);

    GIOError gnet_io_channel_writen (GIOChannel    *channel, 
                                     const gchar   *buf, 
                                     guint          len,
                                     guint         *bytes_written);

because the contents of buf shouldn't change.

I came across this annoyance when I was using gnet in a C++ program, and
wanted to pass a std::string's contents using somestring.c_str(), which
is a const char*. I can't do this without using a <const_cast>.

I've attached a patch for gnet. I'd do the same for glib, but I don't
know how to get the stable glib from cvs. Doing a "cvs -z3 co glib" gets
me the devel version (which is already fixed).

    = Loban


Index: iochannel.c
===================================================================
RCS file: /cvs/gnome/gnet/src/iochannel.c,v
retrieving revision 1.9
diff -u -r1.9 iochannel.c
--- iochannel.c	2001/05/22 02:29:53	1.9
+++ iochannel.c	2001/07/26 22:45:07
@@ -45,13 +45,13 @@
  **/
 GIOError
 gnet_io_channel_writen (GIOChannel    *channel, 
-			gchar         *buf, 
+			const gchar   *buf, 
 			guint          len,
 			guint         *bytes_written)
 {
   guint nleft;
   guint nwritten;
-  gchar* ptr;
+  const gchar* ptr;
   GIOError error = G_IO_ERROR_NONE;
 
   ptr = buf;
Index: iochannel.h
===================================================================
RCS file: /cvs/gnome/gnet/src/iochannel.h,v
retrieving revision 1.9
diff -u -r1.9 iochannel.h
--- iochannel.h	2001/05/21 03:52:54	1.9
+++ iochannel.h	2001/07/26 22:45:07
@@ -28,7 +28,7 @@
 
 
 GIOError gnet_io_channel_writen (GIOChannel    *channel, 
-				 gchar         *buf, 
+				 const gchar   *buf, 
 				 guint          len,
 				 guint         *bytes_written);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]