comparison src/coding.c @ 90346:bba59a8cdae0

(encode_coding_ccl): Allocate destination dynamically when necessary.
author Kenichi Handa <handa@m17n.org>
date Sat, 04 Mar 2006 02:59:04 +0000
parents f0338dbf2276
children 60eaefb08cf7
comparison
equal deleted inserted replaced
90345:42139b4c2a78 90346:bba59a8cdae0
4535 int multibytep = coding->dst_multibyte; 4535 int multibytep = coding->dst_multibyte;
4536 int *charbuf = coding->charbuf; 4536 int *charbuf = coding->charbuf;
4537 int *charbuf_end = charbuf + coding->charbuf_used; 4537 int *charbuf_end = charbuf + coding->charbuf_used;
4538 unsigned char *dst = coding->destination + coding->produced; 4538 unsigned char *dst = coding->destination + coding->produced;
4539 unsigned char *dst_end = coding->destination + coding->dst_bytes; 4539 unsigned char *dst_end = coding->destination + coding->dst_bytes;
4540 unsigned char *adjusted_dst_end = dst_end - 1;
4541 int destination_charbuf[1024]; 4540 int destination_charbuf[1024];
4542 int i, produced_chars = 0; 4541 int i, produced_chars = 0;
4543 Lisp_Object attrs, charset_list; 4542 Lisp_Object attrs, charset_list;
4544 4543
4545 CODING_GET_INFO (coding, attrs, charset_list); 4544 CODING_GET_INFO (coding, attrs, charset_list);
4546 setup_ccl_program (&ccl, CODING_CCL_ENCODER (coding)); 4545 setup_ccl_program (&ccl, CODING_CCL_ENCODER (coding));
4547 4546
4548 ccl.last_block = coding->mode & CODING_MODE_LAST_BLOCK; 4547 ccl.last_block = coding->mode & CODING_MODE_LAST_BLOCK;
4549 ccl.dst_multibyte = coding->dst_multibyte; 4548 ccl.dst_multibyte = coding->dst_multibyte;
4550 4549
4551 while (charbuf < charbuf_end && dst < adjusted_dst_end) 4550 while (charbuf < charbuf_end)
4552 { 4551 {
4553 int dst_bytes = dst_end - dst;
4554 if (dst_bytes > 1024)
4555 dst_bytes = 1024;
4556
4557 ccl_driver (&ccl, charbuf, destination_charbuf, 4552 ccl_driver (&ccl, charbuf, destination_charbuf,
4558 charbuf_end - charbuf, dst_bytes, charset_list); 4553 charbuf_end - charbuf, 1024, charset_list);
4559 charbuf += ccl.consumed;
4560 if (multibytep) 4554 if (multibytep)
4561 for (i = 0; i < ccl.produced; i++) 4555 {
4562 EMIT_ONE_BYTE (destination_charbuf[i] & 0xFF); 4556 ASSURE_DESTINATION (ccl.produced * 2);
4557 for (i = 0; i < ccl.produced; i++)
4558 EMIT_ONE_BYTE (destination_charbuf[i] & 0xFF);
4559 }
4563 else 4560 else
4564 { 4561 {
4562 ASSURE_DESTINATION (ccl.produced);
4565 for (i = 0; i < ccl.produced; i++) 4563 for (i = 0; i < ccl.produced; i++)
4566 *dst++ = destination_charbuf[i] & 0xFF; 4564 *dst++ = destination_charbuf[i] & 0xFF;
4567 produced_chars += ccl.produced; 4565 produced_chars += ccl.produced;
4568 } 4566 }
4567 charbuf += ccl.consumed;
4568 if (ccl.status == CCL_STAT_QUIT
4569 || ccl.status == CCL_STAT_INVALID_CMD)
4570 break;
4569 } 4571 }
4570 4572
4571 switch (ccl.status) 4573 switch (ccl.status)
4572 { 4574 {
4573 case CCL_STAT_SUSPEND_BY_SRC: 4575 case CCL_STAT_SUSPEND_BY_SRC: