mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-10-31 08:22:16 +01:00 
			
		
		
		
	Avoid running in an assertion with small writes. (#343566, Chris Wilson)
2006-06-01 Matthias Clasen <mclasen@redhat.com> * glib/giochannel.c (g_io_channel_write_chars): Avoid running in an assertion with small writes. (#343566, Chris Wilson) * tests/iochannel-test.c: Add a testcase for small writes.
This commit is contained in:
		
				
					committed by
					
						 Matthias Clasen
						Matthias Clasen
					
				
			
			
				
	
			
			
			
						parent
						
							a5b4b8bfb1
						
					
				
				
					commit
					14538bb8d6
				
			| @@ -1,5 +1,11 @@ | |||||||
| 2006-06-01  Matthias Clasen  <mclasen@redhat.com> | 2006-06-01  Matthias Clasen  <mclasen@redhat.com> | ||||||
|  |  | ||||||
|  | 	* glib/giochannel.c (g_io_channel_write_chars): Avoid | ||||||
|  | 	running in an assertion with small writes.  (#343566, Chris | ||||||
|  | 	Wilson) | ||||||
|  |  | ||||||
|  | 	* tests/iochannel-test.c: Add a testcase for small writes. | ||||||
|  |  | ||||||
| 	* glib/glib.symbols:  | 	* glib/glib.symbols:  | ||||||
| 	* glib/ghash.h:  | 	* glib/ghash.h:  | ||||||
| 	* glib/ghash.c: Add g_hash_table_{remove,steal}_all to | 	* glib/ghash.c: Add g_hash_table_{remove,steal}_all to | ||||||
|   | |||||||
| @@ -1,5 +1,11 @@ | |||||||
| 2006-06-01  Matthias Clasen  <mclasen@redhat.com> | 2006-06-01  Matthias Clasen  <mclasen@redhat.com> | ||||||
|  |  | ||||||
|  | 	* glib/giochannel.c (g_io_channel_write_chars): Avoid | ||||||
|  | 	running in an assertion with small writes.  (#343566, Chris | ||||||
|  | 	Wilson) | ||||||
|  |  | ||||||
|  | 	* tests/iochannel-test.c: Add a testcase for small writes. | ||||||
|  |  | ||||||
| 	* glib/glib.symbols:  | 	* glib/glib.symbols:  | ||||||
| 	* glib/ghash.h:  | 	* glib/ghash.h:  | ||||||
| 	* glib/ghash.c: Add g_hash_table_{remove,steal}_all to | 	* glib/ghash.c: Add g_hash_table_{remove,steal}_all to | ||||||
|   | |||||||
| @@ -2009,7 +2009,7 @@ g_io_channel_write_chars (GIOChannel	*channel, | |||||||
|        * and never receiving an EAGAIN. |        * and never receiving an EAGAIN. | ||||||
|        */ |        */ | ||||||
|  |  | ||||||
|       if (channel->write_buf->len >= channel->buf_size) |       if (channel->write_buf->len >= channel->buf_size - MAX_CHAR_SIZE) | ||||||
|         { |         { | ||||||
|           gsize did_write = 0, this_time; |           gsize did_write = 0, this_time; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -11,6 +11,47 @@ | |||||||
|  |  | ||||||
| #define BUFFER_SIZE 1024 | #define BUFFER_SIZE 1024 | ||||||
|  |  | ||||||
|  | static void | ||||||
|  | test_small_writes (void) | ||||||
|  | { | ||||||
|  |   GIOChannel *io; | ||||||
|  |   GIOStatus status; | ||||||
|  |   guint cnt;  | ||||||
|  |   gchar tmp; | ||||||
|  |   GError *error = NULL; | ||||||
|  |  | ||||||
|  |   io = g_io_channel_new_file ("iochannel-test-outfile", "w", &error); | ||||||
|  |   if (error) | ||||||
|  |     { | ||||||
|  |       g_warning ("Unable to open file %s: %s",  | ||||||
|  | 		 "iochannel-test-outfile",  | ||||||
|  | 		 error->message); | ||||||
|  |       g_error_free (error); | ||||||
|  |        | ||||||
|  |       exit (1); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   g_io_channel_set_encoding (io, NULL, NULL); | ||||||
|  |   g_io_channel_set_buffer_size (io, 1022); | ||||||
|  |  | ||||||
|  |   cnt = 2 * g_io_channel_get_buffer_size (io); | ||||||
|  |   tmp = 0; | ||||||
|  |   | ||||||
|  |   while (cnt) | ||||||
|  |     { | ||||||
|  |       status = g_io_channel_write_chars (io, &tmp, 1, NULL, NULL); | ||||||
|  |       if (status == G_IO_STATUS_ERROR) | ||||||
|  | 	break; | ||||||
|  |       if (status == G_IO_STATUS_NORMAL) | ||||||
|  | 	cnt--; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |   g_assert (status == G_IO_STATUS_NORMAL); | ||||||
|  |  | ||||||
|  |   g_io_channel_unref (io); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| gint main (gint argc, gchar * argv[]) | gint main (gint argc, gchar * argv[]) | ||||||
| { | { | ||||||
|     GIOChannel *gio_r, *gio_w ; |     GIOChannel *gio_r, *gio_w ; | ||||||
| @@ -125,6 +166,8 @@ gint main (gint argc, gchar * argv[]) | |||||||
|  |  | ||||||
|     g_io_channel_unref(gio_r); |     g_io_channel_unref(gio_r); | ||||||
|     g_io_channel_unref(gio_w); |     g_io_channel_unref(gio_w); | ||||||
|  |  | ||||||
|  |     test_small_writes (); | ||||||
|      |      | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user