ext: use rb_sprintf() and rb_vsprintf() with PRIsVALUE

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-01-12 08:11:36 +00:00
Родитель 4240685237
Коммит 9bd672f668
8 изменённых файлов: 48 добавлений и 59 удалений

Просмотреть файл

@ -391,9 +391,8 @@ rb_dlptr_inspect(VALUE self)
char str[1024];
TypedData_Get_Struct(self, struct ptr_data, &dlptr_data_type, data);
snprintf(str, 1023, "#<%s:%p ptr=%p size=%ld free=%p>",
rb_class2name(CLASS_OF(self)), data, data->ptr, data->size, data->free);
return rb_str_new2(str);
return rb_sprintf("#<%"PRIsVALUE":%p ptr=%p size=%ld free=%p>",
CLASS_OF(self), data, data->ptr, data->size, data->free);
}
/*

Просмотреть файл

@ -427,12 +427,10 @@ static VALUE
rb_fiddle_ptr_inspect(VALUE self)
{
struct ptr_data *data;
char str[1024];
TypedData_Get_Struct(self, struct ptr_data, &fiddle_ptr_data_type, data);
snprintf(str, 1023, "#<%s:%p ptr=%p size=%ld free=%p>",
rb_class2name(CLASS_OF(self)), data, data->ptr, data->size, data->free);
return rb_str_new2(str);
return rb_sprintf("#<%"PRIsVALUE":%p ptr=%p size=%ld free=%p>",
CLASS_OF(self), data, data->ptr, data->size, data->free);
}
/*

Просмотреть файл

@ -294,10 +294,9 @@ ossl_to_der_if_possible(VALUE obj)
static VALUE
ossl_make_error(VALUE exc, const char *fmt, va_list args)
{
char buf[BUFSIZ];
VALUE str = Qnil;
const char *msg;
long e;
int len = 0;
#ifdef HAVE_ERR_PEEK_LAST_ERROR
e = ERR_peek_last_error();
@ -305,14 +304,19 @@ ossl_make_error(VALUE exc, const char *fmt, va_list args)
e = ERR_peek_error();
#endif
if (fmt) {
len = vsnprintf(buf, BUFSIZ, fmt, args);
str = rb_vsprintf(fmt, args);
}
if (len < BUFSIZ && e) {
if (e) {
if (dOSSL == Qtrue) /* FULL INFO */
msg = ERR_error_string(e, NULL);
else
msg = ERR_reason_error_string(e);
len += snprintf(buf+len, BUFSIZ-len, "%s%s", (len ? ": " : ""), msg);
if (NIL_P(str)) {
str = rb_str_new_cstr(msg);
}
else {
rb_str_cat2(rb_str_cat2(str, ": "), msg);
}
}
if (dOSSL == Qtrue){ /* show all errors on the stack */
while ((e = ERR_get_error()) != 0){
@ -321,8 +325,8 @@ ossl_make_error(VALUE exc, const char *fmt, va_list args)
}
ERR_clear_error();
if(len > BUFSIZ) len = rb_long2int(strlen(buf));
return rb_exc_new(exc, buf, len);
if (NIL_P(str)) str = rb_str_new(0, 0);
return rb_exc_new3(exc, str);
}
void

Просмотреть файл

@ -613,7 +613,7 @@ static void
raise_from_check(rb_pid_t pid, int status)
{
const char *state;
char buf[1024];
VALUE msg;
VALUE exc;
#if defined(WIFSTOPPED)
@ -631,8 +631,8 @@ raise_from_check(rb_pid_t pid, int status)
else {
state = "exited";
}
snprintf(buf, sizeof(buf), "pty - %s: %ld", state, (long)pid);
exc = rb_exc_new2(eChildExited, buf);
msg = rb_sprintf("pty - %s: %ld", state, (long)pid);
exc = rb_exc_new_str(eChildExited, msg);
rb_iv_set(exc, "status", rb_last_status_get());
rb_exc_raise(exc);
}

Просмотреть файл

@ -1155,37 +1155,32 @@ static VALUE
strscan_inspect(VALUE self)
{
struct strscanner *p;
char buf[BUFSIZE];
long len;
VALUE a, b;
p = check_strscan(self);
if (NIL_P(p->str)) {
len = snprintf(buf, BUFSIZE, "#<%s (uninitialized)>",
rb_class2name(CLASS_OF(self)));
return infect(rb_str_new(buf, len), p);
a = rb_sprintf("#<%"PRIsVALUE" (uninitialized)>", CLASS_OF(self));
return infect(a, p);
}
if (EOS_P(p)) {
len = snprintf(buf, BUFSIZE, "#<%s fin>",
rb_class2name(CLASS_OF(self)));
return infect(rb_str_new(buf, len), p);
a = rb_sprintf("#<%"PRIsVALUE" fin>", CLASS_OF(self));
return infect(a, p);
}
if (p->curr == 0) {
b = inspect2(p);
len = snprintf(buf, BUFSIZE, "#<%s %ld/%ld @ %s>",
rb_class2name(CLASS_OF(self)),
p->curr, S_LEN(p),
RSTRING_PTR(b));
return infect(rb_str_new(buf, len), p);
b = inspect2(p);
a = rb_sprintf("#<%"PRIsVALUE" %ld/%ld @ %"PRIsVALUE">",
CLASS_OF(self),
p->curr, S_LEN(p),
b);
return infect(a, p);
}
a = inspect1(p);
b = inspect2(p);
len = snprintf(buf, BUFSIZE, "#<%s %ld/%ld %s @ %s>",
rb_class2name(CLASS_OF(self)),
p->curr, S_LEN(p),
RSTRING_PTR(a),
RSTRING_PTR(b));
return infect(rb_str_new(buf, len), p);
a = rb_sprintf("#<%"PRIsVALUE" %ld/%ld %"PRIsVALUE" @ %"PRIsVALUE">",
CLASS_OF(self),
p->curr, S_LEN(p),
a, b);
return infect(a, p);
}
static VALUE
@ -1210,21 +1205,19 @@ inspect1(struct strscanner *p)
static VALUE
inspect2(struct strscanner *p)
{
char buf[BUFSIZE];
char *bp = buf;
VALUE str;
long len;
if (EOS_P(p)) return rb_str_new2("");
len = S_LEN(p) - p->curr;
if (len > INSPECT_LENGTH) {
len = INSPECT_LENGTH;
memcpy(bp, CURPTR(p), len); bp += len;
strcpy(bp, "..."); bp += 3;
str = rb_str_new(CURPTR(p), INSPECT_LENGTH);
rb_str_cat2(str, "...");
}
else {
memcpy(bp, CURPTR(p), len); bp += len;
str = rb_str_new(CURPTR(p), len);
}
return rb_str_dump(rb_str_new(buf, bp - buf));
return rb_str_dump(str);
}
/* =======================================================================

Просмотреть файл

@ -848,15 +848,14 @@ create_ip_exc(interp, exc, fmt, va_alist)
#endif
{
va_list args;
char buf[BUFSIZ];
VALUE msg;
VALUE einfo;
struct tcltkip *ptr = get_ip(interp);
va_init_list(args,fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
buf[BUFSIZ - 1] = '\0';
msg = rb_vsprintf(fmt, args);
va_end(args);
einfo = rb_exc_new2(exc, buf);
einfo = rb_exc_new_str(exc, msg);
rb_ivar_set(einfo, ID_at_interp, interp);
if (ptr) {
Tcl_ResetResult(ptr->ip);

Просмотреть файл

@ -1209,19 +1209,18 @@ static void
ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZ];
VALUE msg;
VALUE err_msg;
va_init_list(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
msg = rb_vsprintf(fmt, args);
va_end(args);
err_msg = ole_hresult2msg(hr);
if(err_msg != Qnil) {
rb_raise(ecs, "%s\n%s", buf, StringValuePtr(err_msg));
}
else {
rb_raise(ecs, "%s", buf);
rb_str_cat2(msg, "\n");
rb_str_append(msg, err_msg);
}
rb_exc_raise(rb_exc_new_str(ecs, msg));
}
void

Просмотреть файл

@ -337,11 +337,8 @@ raise_zlib_error(int err, const char *msg)
rb_sys_fail(msg);
/* no return */
default:
{
char buf[BUFSIZ];
snprintf(buf, BUFSIZ, "unknown zlib error %d: %s", err, msg);
exc = rb_exc_new2(cZError, buf);
}
exc = rb_exc_new_str(cZError,
rb_sprintf("unknown zlib error %d: %s", err, msg));
}
rb_exc_raise(exc);