This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


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

gconv_open patch (3)


gconv_open has some code duplicated, once for all steps except the
last and once for the last step. This makes the code hard to
read. Here is a patch to unify the two. Quite trivial, no functional
changes.


2000-07-12  Bruno Haible  <haible@clisp.cons.org>

	* iconv/gconv_open.c (__gconv_open): Merge duplicated code.

*** glibc-20000706/iconv/gconv_open.c	Wed Jul 12 02:18:32 2000
--- glibc-20000706/iconv/gconv_open.c.new	Wed Jul 12 02:26:30 2000
***************
*** 184,197 ****
  
  	  /* Call all initialization functions for the transformation
  	     step implementations.  */
! 	  for (cnt = 0; cnt < nsteps - 1; ++cnt)
  	    {
  	      size_t size;
  
- 	      /* If this is the last step we must not allocate an
- 		 output buffer.  */
- 	      result->__data[cnt].__flags = conv_flags;
- 
  	      /* Would have to be done if we would not clear the whole
                   array above.  */
  #if 0
--- 184,193 ----
  
  	  /* Call all initialization functions for the transformation
  	     step implementations.  */
! 	  for (cnt = 0; cnt < nsteps; ++cnt)
  	    {
  	      size_t size;
  
  	      /* Would have to be done if we would not clear the whole
                   array above.  */
  #if 0
***************
*** 205,220 ****
  	      /* We use the `mbstate_t' member in DATA.  */
  	      result->__data[cnt].__statep = &result->__data[cnt].__state;
  
- 	      /* Allocate the buffer.  */
- 	      size = (GCONV_NCHAR_GOAL * steps[cnt].__max_needed_to);
- 
- 	      result->__data[cnt].__outbuf = (char *) malloc (size);
- 	      if (result->__data[cnt].__outbuf == NULL)
- 		goto bail;
- 
- 	      result->__data[cnt].__outbufend =
- 		result->__data[cnt].__outbuf + size;
- 
  	      /* Now see whether we can use any of the transliteration
  		 modules for this step.  */
  	      for (runp = trans; runp != NULL; runp = runp->next)
--- 201,206 ----
***************
*** 257,315 ****
  		    }
  
  	      result->__steps[cnt].__data = &result->__data[cnt];
- 	    }
  
! 	  /* Now handle the last entry.  */
! 	  result->__data[cnt].__flags = conv_flags | __GCONV_IS_LAST;
! 	  /* Would have to be done if we would not clear the whole
! 	     array above.  */
! #if 0
! 	  result->__data[cnt].__invocation_counter = 0;
! 	  result->__data[cnt].__internal_use = 0;
! #endif
! 	  result->__data[cnt].__statep = &result->__data[cnt].__state;
  
! 	  /* Now see whether we can use the transliteration module
! 	     for this step.  */
! 	  for (runp = trans; runp != NULL; runp = runp->next)
! 	    for (n = 0; n < runp->ncsnames; ++n)
! 	      if (__strcasecmp (steps[cnt].__from_name, runp->csnames[n]) == 0)
  		{
! 		  void *data = NULL;
  
- 		  /* Match!  Now try the initializer.  */
- 		  if (runp->trans_init_fct == NULL
- 		      || (runp->trans_init_fct (data, steps[cnt].__to_name)
- 			  == __GCONV_OK))
- 		    {
- 		      /* Append at the end of the list.  */
- 		      struct __gconv_trans_data *newp;
- 		      struct __gconv_trans_data *endp;
- 		      struct __gconv_trans_data *lastp;
- 
- 		      newp = (struct __gconv_trans_data *)
- 			malloc (sizeof (struct __gconv_trans_data));
- 		      if (newp == NULL)
- 			goto bail;
- 
- 		      newp->__trans_fct = runp->trans_fct;
- 		      newp->__trans_context_fct = runp->trans_context_fct;
- 		      newp->__trans_end_fct = runp->trans_end_fct;
- 
- 		      lastp = NULL;
- 		      for (endp = result->__data[cnt].__trans;
- 			   endp != NULL; endp = endp->__next)
- 			lastp = endp;
- 
- 		      if (lastp == NULL)
- 			result->__data[cnt].__trans = newp;
- 		      else
- 			lastp->__next = newp;
- 		    }
  		  break;
  		}
! 
! 	  result->__steps[cnt].__data = &result->__data[cnt];
  	}
  
        if (res != __GCONV_OK)
--- 243,273 ----
  		    }
  
  	      result->__steps[cnt].__data = &result->__data[cnt];
  
! 	      /* If this is the last step we must not allocate an
! 		 output buffer.  */
! 	      if (cnt < nsteps - 1)
! 		{
! 		  result->__data[cnt].__flags = conv_flags;
! 
! 		  /* Allocate the buffer.  */
! 		  size = (GCONV_NCHAR_GOAL * steps[cnt].__max_needed_to);
  
! 		  result->__data[cnt].__outbuf = (char *) malloc (size);
! 		  if (result->__data[cnt].__outbuf == NULL)
! 		    goto bail;
! 
! 		  result->__data[cnt].__outbufend =
! 		    result->__data[cnt].__outbuf + size;
! 		}
! 	      else
  		{
! 		  /* Handle the last entry.  */
! 		  result->__data[cnt].__flags = conv_flags | __GCONV_IS_LAST;
  
  		  break;
  		}
! 	    }
  	}
  
        if (res != __GCONV_OK)

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