about summary refs log tree commit diff
path: root/iconv/loop.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-06-12 19:47:50 +0000
committerUlrich Drepper <drepper@redhat.com>2000-06-12 19:47:50 +0000
commit55985355ade2a038b567dd9b58153a98384ae703 (patch)
treeb6252e23490e6d10d55ae926e30e32173f504190 /iconv/loop.c
parenta5b97402f70a3cd43ffee9ccb71560457b4cd88c (diff)
downloadglibc-55985355ade2a038b567dd9b58153a98384ae703.tar.gz
glibc-55985355ade2a038b567dd9b58153a98384ae703.tar.xz
glibc-55985355ade2a038b567dd9b58153a98384ae703.zip
Update.
2000-06-12  Ulrich Drepper  <drepper@redhat.com>

	* Rules (%.out): Define GCONV_PATH in the environment.
	* assert/Depend: New file.
	* iconvdata/Depend: New file.
	* intl/Depend: New file.
	* timezone/Makefile (build-testdata): Add GCONV_PATH to environment.
	* intl/tst-gettext.sh: Likewise.
	* iconv/Makefile (routines): Add gconv_trans.
	* iconv/gconv_trans.c: New file.
	* iconv/gconv.h (struct __gconv_trans_data): New type.
	(__gconv_fct): New parameter with starting position in output buffer.
	(__gconv_trans_fct, __gconv_trans_context_fct, __gconv_trans_query_fct,
	__gconv_trans_init_fct, __gconv_trans_end_fct): New types.
	(struct __gconv_step): Add new member __trans.
	* iconv/gconv_int.h: Pretty print prototypes.
	(gconv_transliterate): New prototype.
	(__BUILTIN_TRANS): Update for new conversion function interface.
	* iconv/gconv.c (__gconv): Pass new parameter to conversion function.
	* iconv/gconv_open.c (__gconv_open): Recognize error handling suffix
	in names, find appropriate function, and install in the conversion
	steps it can be used.
	* iconv/skeleton.c: Add additional parameter for beginning of output
	buffer.  Change calls of downstream functions.
	* iconv/loop.c: Change loop function interface completely.  Pass in
	step and step_data structure.  Remove optimization for BODY with
	NEED_LENGTH_TEST == 0.
	* iconv/gconv_simple.c: Update interfaces of functions.  Insert
	appropriate error handling code to use transliteration steps.  Remove
	optimization for BODY with NEED_LENGTH_TEST == 0.
	* iconvdata/8bit-gap.c: Likewise.
	* iconvdata/8bit-generic.c: Likewise.
	* iconvdata/ansi_x3.110.c: Likewise.
	* iconvdata/big5.c: Likewise.
	* iconvdata/big5hkscs.c: Likewise.
	* iconvdata/euc-cn.c: Likewise.
	* iconvdata/euc-jp.c: Likewise.
	* iconvdata/euc-kr.c: Likewise.
	* iconvdata/euc-tw.c: Likewise.
	* iconvdata/gbgbk.c: Likewise.
	* iconvdata/gbk.c: Likewise.
	* iconvdata/iso-2022-cn.c: Likewise.
	* iconvdata/iso-2022-jp.c: Likewise.
	* iconvdata/iso-2022-kr.c: Likewise.
	* iconvdata/iso646.c: Likewise.
	* iconvdata/iso8859-1.c: Likewise.
	* iconvdata/iso_6937-2.c: Likewise.
	* iconvdata/iso_6937.c: Likewise.
	* iconvdata/johab.c: Likewise.
	* iconvdata/sjis.c: Likewise.
	* iconvdata/t.61.c: Likewise.
	* iconvdata/uhc.c: Likewise.
	* iconvdata/unicode.c: Likewise.
	* iconvdata/utf-16.c: Likewise.
	* libio/iofwide.c: Adjust to new interface of gconv functions.  Use
	DL_CALL_FCT.
	* wcsmbs/btowc.c: Likewise.
	* wcsmbs/mbrtowc.c: Likewise.
	* wcsmbs/mbsnrtowcs.c: Likewise.
	* wcsmbs/mbsrtowcs.c: Likewise.
	* wcsmbs/wcrtomb.c: Likewise.
	* wcsmbs/wcsnrtombs.c: Likewise.
	* wcsmbs/wcsrtombs.c: Likewise.
	* wcsmbs/wctob.c: Likewise.
Diffstat (limited to 'iconv/loop.c')
-rw-r--r--iconv/loop.c129
1 files changed, 54 insertions, 75 deletions
diff --git a/iconv/loop.c b/iconv/loop.c
index c01e52040e..ebbc1362b3 100644
--- a/iconv/loop.c
+++ b/iconv/loop.c
@@ -175,88 +175,57 @@
 
 /* The function returns the status, as defined in gconv.h.  */
 static inline int
-FCTNAME (LOOPFCT) (const unsigned char **inptrp, const unsigned char *inend,
+FCTNAME (LOOPFCT) (struct __gconv_step *step,
+		   struct __gconv_step_data *step_data,
+		   const unsigned char **inptrp, const unsigned char *inend,
 		   unsigned char **outptrp, unsigned char *outend,
-		   mbstate_t *state, int flags, void *data,
 		   size_t *irreversible EXTRA_LOOP_DECLS)
 {
-  int result = __GCONV_OK;
+#ifdef LOOP_NEED_STATE
+  mbstate_t *state = step_data->__statep;
+#endif
+#ifdef LOOP_NEED_FLAGS
+  int flags = step_data->__flags;
+#endif
+#ifdef LOOP_NEED_DATA
+  void *data = step->__data;
+#endif
+  int result = __GCONV_EMPTY_INPUT;
   const unsigned char *inptr = *inptrp;
   unsigned char *outptr = *outptrp;
 
-  /* We run one loop where we avoid checks for underflow/overflow of the
-     buffers to speed up the conversion a bit.  */
-  size_t min_in_rounds = (inend - inptr) / MAX_NEEDED_INPUT;
-  size_t min_out_rounds = (outend - outptr) / MAX_NEEDED_OUTPUT;
-  size_t min_rounds = MIN (min_in_rounds, min_out_rounds);
-
 #ifdef INIT_PARAMS
   INIT_PARAMS;
 #endif
 
-#undef NEED_LENGTH_TEST
-#define NEED_LENGTH_TEST	0
-  while (min_rounds-- > 0)
+  while (inptr != inend)
     {
-      /* Here comes the body the user provides.  It can stop with RESULT
-	 set to GCONV_INCOMPLETE_INPUT (if the size of the input characters
-	 vary in size), GCONV_ILLEGAL_INPUT, or GCONV_FULL_OUTPUT (if the
-	 output characters vary in size.  */
-      BODY
-    }
-
-  if (result == __GCONV_OK)
-    {
-#if MIN_NEEDED_INPUT == MAX_NEEDED_INPUT \
-    && MIN_NEEDED_OUTPUT == MAX_NEEDED_OUTPUT
-      /* We don't need to start another loop since we were able to determine
-	 the maximal number of characters to copy in advance.  What remains
-	 to be determined is the status.  */
-      if (inptr == inend)
-	/* No more input.  */
-	result = __GCONV_EMPTY_INPUT;
-      else if ((MIN_NEEDED_OUTPUT != 1 && outptr + MIN_NEEDED_OUTPUT > outend)
-	       || (MIN_NEEDED_OUTPUT == 1 && outptr >= outend))
-	/* Overflow in the output buffer.  */
-	result = __GCONV_FULL_OUTPUT;
-      else
-	/* We have something left in the input buffer.  */
-	result = __GCONV_INCOMPLETE_INPUT;
-#else
-      result = __GCONV_EMPTY_INPUT;
-
-# undef NEED_LENGTH_TEST
-# define NEED_LENGTH_TEST	1
-      while (inptr != inend)
+      /* `if' cases for MIN_NEEDED_OUTPUT ==/!= 1 is made to help the
+	 compiler generating better code.  It will optimized away
+	 since MIN_NEEDED_OUTPUT is always a constant.  */
+      if ((MIN_NEEDED_OUTPUT != 1
+	   && __builtin_expect (outptr + MIN_NEEDED_OUTPUT > outend, 0))
+	  || (MIN_NEEDED_OUTPUT == 1
+	      && __builtin_expect (outptr >= outend, 0)))
+	{
+	  /* Overflow in the output buffer.  */
+	  result = __GCONV_FULL_OUTPUT;
+	  break;
+	}
+      if (MIN_NEEDED_INPUT > 1
+	  && __builtin_expect (inptr + MIN_NEEDED_INPUT > inend, 0))
 	{
-	  /* `if' cases for MIN_NEEDED_OUTPUT ==/!= 1 is made to help the
-	     compiler generating better code.  It will optimized away
-	     since MIN_NEEDED_OUTPUT is always a constant.  */
-	  if ((MIN_NEEDED_OUTPUT != 1
-	       && __builtin_expect (outptr + MIN_NEEDED_OUTPUT > outend, 0))
-	      || (MIN_NEEDED_OUTPUT == 1
-		  && __builtin_expect (outptr >= outend, 0)))
-	    {
-	      /* Overflow in the output buffer.  */
-	      result = __GCONV_FULL_OUTPUT;
-	      break;
-	    }
-	  if (MIN_NEEDED_INPUT > 1
-	      && __builtin_expect (inptr + MIN_NEEDED_INPUT > inend, 0))
-	    {
-	      /* We don't have enough input for another complete input
-		 character.  */
-	      result = __GCONV_INCOMPLETE_INPUT;
-	      break;
-	    }
-
-	  /* Here comes the body the user provides.  It can stop with
-	     RESULT set to GCONV_INCOMPLETE_INPUT (if the size of the
-	     input characters vary in size), GCONV_ILLEGAL_INPUT, or
-	     GCONV_FULL_OUTPUT (if the output characters vary in size).  */
-	  BODY
+	  /* We don't have enough input for another complete input
+	     character.  */
+	  result = __GCONV_INCOMPLETE_INPUT;
+	  break;
 	}
-#endif	/* Input and output charset are not both fixed width.  */
+
+      /* Here comes the body the user provides.  It can stop with
+	 RESULT set to GCONV_INCOMPLETE_INPUT (if the size of the
+	 input characters vary in size), GCONV_ILLEGAL_INPUT, or
+	 GCONV_FULL_OUTPUT (if the output characters vary in size).  */
+      BODY
     }
 
   /* Update the pointers pointed to by the parameters.  */
@@ -291,11 +260,19 @@ FCTNAME (LOOPFCT) (const unsigned char **inptrp, const unsigned char *inend,
 # define SINGLE(fct) SINGLE2 (fct)
 # define SINGLE2(fct) fct##_single
 static inline int
-SINGLE(LOOPFCT) (const unsigned char **inptrp, const unsigned char *inend,
+SINGLE(LOOPFCT) (struct __gconv_step *step,
+		 struct __gconv_step_data *step_data,
+		 const unsigned char **inptrp, const unsigned char *inend,
 		 unsigned char **outptrp, unsigned char *outend,
-		 mbstate_t *state, int flags, void *data, size_t *irreversible
-		 EXTRA_LOOP_DECLS)
+		 size_t *irreversible EXTRA_LOOP_DECLS)
 {
+  mbstate_t *state = step_data->__statep;
+#ifdef LOOP_NEED_FLAGS
+  int flags = step_data->__flags;
+#endif
+#ifdef LOOP_NEED_DATA
+  void *data = step->__data;
+#endif
   int result = __GCONV_OK;
   unsigned char bytebuf[MAX_NEEDED_INPUT];
   const unsigned char *inptr = *inptrp;
@@ -347,8 +324,7 @@ SINGLE(LOOPFCT) (const unsigned char **inptrp, const unsigned char *inend,
 
   inptr = bytebuf;
   inend = &bytebuf[inlen];
-#undef NEED_LENGTH_TEST
-#define NEED_LENGTH_TEST	1
+
   do
     {
       BODY
@@ -410,9 +386,12 @@ SINGLE(LOOPFCT) (const unsigned char **inptrp, const unsigned char *inend,
 #undef EXTRA_LOOP_DECLS
 #undef INIT_PARAMS
 #undef UPDATE_PARAMS
+#undef UNPACK_BYTES
+#undef LOOP_NEED_STATE
+#undef LOOP_NEED_FLAGS
+#undef LOOP_NEED_DATA
 #undef get16
 #undef get32
 #undef put16
 #undef put32
 #undef unaligned
-#undef UNPACK_BYTES