* ext/iconv/iconv.c (iconv_try), ext/iconv/extconf.rb: get rid of meta

characters in command line option.  fixed: [ruby-talk:155369]

* ext/iconv/iconv.c: protoized.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9106 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2005-09-09 07:45:36 +00:00
parent f5451f4fca
commit b3d2a8aaed
3 changed files with 41 additions and 199 deletions

View File

@ -1,8 +1,13 @@
Fri Sep 9 16:35:04 2005 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri Sep 9 16:45:25 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_times): make empty strings to keep taintness, * string.c (rb_str_times): make empty strings to keep taintness,
and a little improvement. [ruby-dev:26900] and a little improvement. [ruby-dev:26900]
* ext/iconv/iconv.c (iconv_try), ext/iconv/extconf.rb: get rid of meta
characters in command line option. fixed: [ruby-talk:155369]
* ext/iconv/iconv.c: protoized.
Thu Sep 8 14:58:11 2005 Yukihiro Matsumoto <matz@ruby-lang.org> Thu Sep 8 14:58:11 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* merged a patch from Takahiro Kambe <taca@back-street.net> to * merged a patch from Takahiro Kambe <taca@back-street.net> to

View File

@ -21,9 +21,7 @@ if have_func("iconv", "iconv.h") or
/\bconst\b/ =~ second /\bconst\b/ =~ second
end end
end end
$defs.push('-DICONV_INPTR_CAST=""') $defs.push('-DICONV_INPTR_CONST')
else
$defs.push('-DICONV_INPTR_CAST="(char **)"')
end end
have_func("iconvlist", "iconv.h") have_func("iconvlist", "iconv.h")
if conf if conf

View File

@ -118,19 +118,13 @@ static VALUE charset_map;
* *
* Returns the map from canonical name to system dependent name. * Returns the map from canonical name to system dependent name.
*/ */
static VALUE charset_map_get _((void)) static VALUE charset_map_get(void)
{ {
return charset_map; return charset_map;
} }
static char * static char *
map_charset map_charset(VALUE *code)
#ifdef HAVE_PROTOTYPES
(VALUE *code)
#else /* HAVE_PROTOTYPES */
(code)
VALUE *code;
#endif /* HAVE_PROTOTYPES */
{ {
VALUE val = *code; VALUE val = *code;
@ -145,14 +139,7 @@ map_charset
} }
static iconv_t static iconv_t
iconv_create iconv_create(VALUE to, VALUE from)
#ifdef HAVE_PROTOTYPES
(VALUE to, VALUE from)
#else /* HAVE_PROTOTYPES */
(to, from)
VALUE to;
VALUE from;
#endif /* HAVE_PROTOTYPES */
{ {
const char* tocode = map_charset(&to); const char* tocode = map_charset(&to);
const char* fromcode = map_charset(&from); const char* fromcode = map_charset(&from);
@ -187,13 +174,7 @@ iconv_create
} }
static void static void
iconv_dfree iconv_dfree(void *cd)
#ifdef HAVE_PROTOTYPES
(void *cd)
#else /* HAVE_PROTOTYPES */
(cd)
void *cd;
#endif /* HAVE_PROTOTYPES */
{ {
iconv_close(VALUE2ICONV(cd)); iconv_close(VALUE2ICONV(cd));
} }
@ -201,13 +182,7 @@ iconv_dfree
#define ICONV_FREE iconv_dfree #define ICONV_FREE iconv_dfree
static VALUE static VALUE
iconv_free iconv_free(VALUE cd)
#ifdef HAVE_PROTOTYPES
(VALUE cd)
#else /* HAVE_PROTOTYPES */
(cd)
VALUE cd;
#endif /* HAVE_PROTOTYPES */
{ {
if (cd && iconv_close(VALUE2ICONV(cd)) == -1) if (cd && iconv_close(VALUE2ICONV(cd)) == -1)
rb_sys_fail("iconv_close"); rb_sys_fail("iconv_close");
@ -215,13 +190,7 @@ iconv_free
} }
static VALUE static VALUE
check_iconv check_iconv(VALUE obj)
#ifdef HAVE_PROTOTYPES
(VALUE obj)
#else /* HAVE_PROTOTYPES */
(obj)
VALUE obj;
#endif /* HAVE_PROTOTYPES */
{ {
Check_Type(obj, T_DATA); Check_Type(obj, T_DATA);
if (RDATA(obj)->dfree != ICONV_FREE) { if (RDATA(obj)->dfree != ICONV_FREE) {
@ -231,18 +200,13 @@ check_iconv
} }
static VALUE static VALUE
iconv_try iconv_try(iconv_t cd, const char **inptr, size_t *inlen, char **outptr, size_t *outlen)
#ifdef HAVE_PROTOTYPES
(iconv_t cd, const char **inptr, size_t *inlen, char **outptr, size_t *outlen)
#else /* HAVE_PROTOTYPES */
(cd, inptr, inlen, outptr, outlen)
iconv_t cd;
const char **inptr;
size_t *inlen;
char **outptr;
size_t *outlen;
#endif /* HAVE_PROTOTYPES */
{ {
#ifdef ICONV_INPTR_CONST
#define ICONV_INPTR_CAST
#else
#define ICONV_INPTR_CAST (char **)
#endif
size_t ret = iconv(cd, ICONV_INPTR_CAST inptr, inlen, outptr, outlen); size_t ret = iconv(cd, ICONV_INPTR_CAST inptr, inlen, outptr, outlen);
if (ret == (size_t)-1) { if (ret == (size_t)-1) {
if (!*inlen) if (!*inlen)
@ -271,13 +235,7 @@ iconv_try
#define FAILED_MAXLEN 16 #define FAILED_MAXLEN 16
static VALUE iconv_failure_initialize static VALUE iconv_failure_initialize(VALUE error, VALUE mesg, VALUE success, VALUE failed)
#ifdef HAVE_PROTOTYPES
(VALUE error, VALUE mesg, VALUE success, VALUE failed)
#else /* HAVE_PROTOTYPES */
(error, mesg, success, failed)
VALUE error, mesg, success, failed;
#endif /* HAVE_PROTOTYPES */
{ {
rb_call_super(1, &mesg); rb_call_super(1, &mesg);
rb_ivar_set(error, rb_success, success); rb_ivar_set(error, rb_success, success);
@ -286,15 +244,7 @@ static VALUE iconv_failure_initialize
} }
static VALUE static VALUE
iconv_fail iconv_fail(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg)
#ifdef HAVE_PROTOTYPES
(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg)
#else /* HAVE_PROTOTYPES */
(error, success, failed, env, mesg)
VALUE error, success, failed;
struct iconv_env_t *env;
const char *mesg;
#endif /* HAVE_PROTOTYPES */
{ {
VALUE args[3]; VALUE args[3];
@ -324,15 +274,7 @@ iconv_fail
} }
static VALUE static VALUE
rb_str_derive rb_str_derive(VALUE str, const char* ptr, int len)
#ifdef HAVE_PROTOTYPES
(VALUE str, const char* ptr, int len)
#else /* HAVE_PROTOTYPES */
(str, ptr, len)
VALUE str;
const char *ptr;
int len;
#endif /* HAVE_PROTOTYPES */
{ {
VALUE ret; VALUE ret;
@ -349,17 +291,7 @@ rb_str_derive
} }
static VALUE static VALUE
iconv_convert iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* env)
#ifdef HAVE_PROTOTYPES
(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* env)
#else /* HAVE_PROTOTYPES */
(cd, str, start, length, env)
iconv_t cd;
VALUE str;
int start;
int length;
struct iconv_env_t *env;
#endif /* HAVE_PROTOTYPES */
{ {
VALUE ret = Qfalse; VALUE ret = Qfalse;
VALUE error = Qfalse; VALUE error = Qfalse;
@ -493,13 +425,7 @@ iconv_convert
} }
static VALUE static VALUE
iconv_s_allocate iconv_s_allocate(VALUE klass)
#ifdef HAVE_PROTOTYPES
(VALUE klass)
#else /* HAVE_PROTOTYPES */
(klass)
VALUE klass;
#endif /* HAVE_PROTOTYPES */
{ {
return Data_Wrap_Struct(klass, 0, ICONV_FREE, 0); return Data_Wrap_Struct(klass, 0, ICONV_FREE, 0);
} }
@ -523,15 +449,7 @@ iconv_s_allocate
* SystemCallError:: if <tt>iconv_open(3)</tt> fails * SystemCallError:: if <tt>iconv_open(3)</tt> fails
*/ */
static VALUE static VALUE
iconv_initialize iconv_initialize(VALUE self, VALUE to, VALUE from)
#ifdef HAVE_PROTOTYPES
(VALUE self, VALUE to, VALUE from)
#else /* HAVE_PROTOTYPES */
(self, to, from)
VALUE self;
VALUE to;
VALUE from;
#endif /* HAVE_PROTOTYPES */
{ {
iconv_free(check_iconv(self)); iconv_free(check_iconv(self));
DATA_PTR(self) = NULL; DATA_PTR(self) = NULL;
@ -548,15 +466,7 @@ iconv_initialize
* returned from the block. * returned from the block.
*/ */
static VALUE static VALUE
iconv_s_open iconv_s_open(VALUE self, VALUE to, VALUE from)
#ifdef HAVE_PROTOTYPES
(VALUE self, VALUE to, VALUE from)
#else /* HAVE_PROTOTYPES */
(self, to, from)
VALUE self;
VALUE to;
VALUE from;
#endif /* HAVE_PROTOTYPES */
{ {
VALUE cd = ICONV2VALUE(iconv_create(to, from)); VALUE cd = ICONV2VALUE(iconv_create(to, from));
@ -570,13 +480,7 @@ iconv_s_open
} }
static VALUE static VALUE
iconv_s_convert iconv_s_convert(struct iconv_env_t* env)
#ifdef HAVE_PROTOTYPES
(struct iconv_env_t* env)
#else /* HAVE_PROTOTYPES */
(env)
struct iconv_env_t *env;
#endif /* HAVE_PROTOTYPES */
{ {
VALUE last = 0; VALUE last = 0;
@ -613,15 +517,7 @@ iconv_s_convert
* Exceptions thrown by Iconv.new, Iconv.open and Iconv#iconv. * Exceptions thrown by Iconv.new, Iconv.open and Iconv#iconv.
*/ */
static VALUE static VALUE
iconv_s_iconv iconv_s_iconv(int argc, VALUE *argv, VALUE self)
#ifdef HAVE_PROTOTYPES
(int argc, VALUE *argv, VALUE self)
#else /* HAVE_PROTOTYPES */
(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
#endif /* HAVE_PROTOTYPES */
{ {
struct iconv_env_t arg; struct iconv_env_t arg;
@ -645,13 +541,7 @@ iconv_s_iconv
* See Iconv.iconv. * See Iconv.iconv.
*/ */
static VALUE static VALUE
iconv_s_conv iconv_s_conv(VALUE self, VALUE to, VALUE from, VALUE str)
#ifdef HAVE_PROTOTYPES
(VALUE self, VALUE to, VALUE from, VALUE str)
#else /* HAVE_PROTOTYPES */
(self, to, from, str)
VALUE self, to, from, str;
#endif /* HAVE_PROTOTYPES */
{ {
struct iconv_env_t arg; struct iconv_env_t arg;
@ -671,20 +561,15 @@ iconv_s_conv
*/ */
#ifdef HAVE_ICONVLIST #ifdef HAVE_ICONVLIST
struct iconv_name_list { struct iconv_name_list
{
unsigned int namescount; unsigned int namescount;
const char *const *names; const char *const *names;
VALUE array; VALUE array;
}; };
static VALUE static VALUE
list_iconv_i list_iconv_i(VALUE ptr)
#ifdef HAVE_PROTOTYPES
(VALUE ptr)
#else /* HAVE_PROTOTYPES */
(ptr)
VALUE ptr;
#endif /* HAVE_PROTOTYPES */
{ {
struct iconv_name_list *p = (struct iconv_name_list *)ptr; struct iconv_name_list *p = (struct iconv_name_list *)ptr;
unsigned int i, namescount = p->namescount; unsigned int i, namescount = p->namescount;
@ -701,15 +586,7 @@ list_iconv_i
} }
static int static int
list_iconv list_iconv(unsigned int namescount, const char *const *names, void *data)
#ifdef HAVE_PROTOTYPES
(unsigned int namescount, const char *const *names, void *data)
#else /* HAVE_PROTOTYPES */
(namescount, names, data)
unsigned int namescount;
const char *const *names;
void *data;
#endif /* HAVE_PROTOTYPES */
{ {
int *state = data; int *state = data;
struct iconv_name_list list; struct iconv_name_list list;
@ -723,7 +600,7 @@ list_iconv
#endif #endif
static VALUE static VALUE
iconv_s_list _((void)) iconv_s_list(void)
{ {
#ifdef HAVE_ICONVLIST #ifdef HAVE_ICONVLIST
int state; int state;
@ -752,25 +629,13 @@ iconv_s_list _((void))
* its initial shift state. * its initial shift state.
*/ */
static VALUE static VALUE
iconv_init_state iconv_init_state(VALUE cd)
#ifdef HAVE_PROTOTYPES
(VALUE cd)
#else /* HAVE_PROTOTYPES */
(cd)
VALUE cd;
#endif /* HAVE_PROTOTYPES */
{ {
return iconv_convert(VALUE2ICONV(cd), Qnil, 0, 0, NULL); return iconv_convert(VALUE2ICONV(cd), Qnil, 0, 0, NULL);
} }
static VALUE static VALUE
iconv_finish iconv_finish(VALUE self)
#ifdef HAVE_PROTOTYPES
(VALUE self)
#else /* HAVE_PROTOTYPES */
(self)
VALUE self;
#endif /* HAVE_PROTOTYPES */
{ {
VALUE cd = check_iconv(self); VALUE cd = check_iconv(self);
@ -808,15 +673,7 @@ iconv_finish
* See the Iconv documentation. * See the Iconv documentation.
*/ */
static VALUE static VALUE
iconv_iconv iconv_iconv(int argc, VALUE *argv, VALUE self)
#ifdef HAVE_PROTOTYPES
(int argc, VALUE *argv, VALUE self)
#else /* HAVE_PROTOTYPES */
(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
#endif /* HAVE_PROTOTYPES */
{ {
VALUE str, n1, n2; VALUE str, n1, n2;
VALUE cd = check_iconv(self); VALUE cd = check_iconv(self);
@ -846,13 +703,7 @@ iconv_iconv
* failure and the last element is string on the way. * failure and the last element is string on the way.
*/ */
static VALUE static VALUE
iconv_failure_success iconv_failure_success(VALUE self)
#ifdef HAVE_PROTOTYPES
(VALUE self)
#else /* HAVE_PROTOTYPES */
(self)
VALUE self;
#endif /* HAVE_PROTOTYPES */
{ {
return rb_attr_get(self, rb_success); return rb_attr_get(self, rb_success);
} }
@ -865,13 +716,7 @@ iconv_failure_success
* character caused the exception. * character caused the exception.
*/ */
static VALUE static VALUE
iconv_failure_failed iconv_failure_failed(VALUE self)
#ifdef HAVE_PROTOTYPES
(VALUE self)
#else /* HAVE_PROTOTYPES */
(self)
VALUE self;
#endif /* HAVE_PROTOTYPES */
{ {
return rb_attr_get(self, rb_failed); return rb_attr_get(self, rb_failed);
} }
@ -883,13 +728,7 @@ iconv_failure_failed
* Returns inspected string like as: #<_class_: _success_, _failed_> * Returns inspected string like as: #<_class_: _success_, _failed_>
*/ */
static VALUE static VALUE
iconv_failure_inspect iconv_failure_inspect(VALUE self)
#ifdef HAVE_PROTOTYPES
(VALUE self)
#else /* HAVE_PROTOTYPES */
(self)
VALUE self;
#endif /* HAVE_PROTOTYPES */
{ {
char *cname = rb_class2name(CLASS_OF(self)); char *cname = rb_class2name(CLASS_OF(self));
VALUE success = rb_attr_get(self, rb_success); VALUE success = rb_attr_get(self, rb_success);
@ -930,7 +769,7 @@ iconv_failure_inspect
*/ */
void void
Init_iconv _((void)) Init_iconv(void)
{ {
VALUE rb_cIconv = rb_define_class("Iconv", rb_cData); VALUE rb_cIconv = rb_define_class("Iconv", rb_cData);