Граф коммитов

226 Коммитов

Автор SHA1 Сообщение Дата
stomar 75e5a91e92 sprintf.c: fix typo
* sprintf.c: [DOC] fix typo.
  Patch by Lazarus Lazaridis (iridakos).  [Fix GH-1789]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-22 19:41:06 +00:00
nobu c05fa459bb quote symbols
* sprintf.c (ruby__sfvextra): quote symbols as identifiers.

* string.c (rb_id_quote_unprintable): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-14 02:35:51 +00:00
nobu d4d966f967 sprintf.c: overflow check
* sprintf.c (ruby_do_vsnprintf): pathologically, get rid of
  negative value when the result length exceeds INT_MAX.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-09 03:15:20 +00:00
nobu e9cb552ec9 internal.h: remove dependecy on ruby/encoding.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 06:24:11 +00:00
nobu 13f5dcb9f2 error.c: KeyError#receiver and KeyError#key
* error.c: new method KeyError#receiver and KeyError#key.
  [Feature #12063]

* hash.c: make KeyError object with receiver and key.

* sprintf.c: ditto.

Author:    ksss <co000ri@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-18 08:05:53 +00:00
nobu 067d9e9ce9 sprintf.c: NULL as str
* sprintf.c (ruby_vsnprintf, ruby_snprintf): allow NULL as str,
  just count the expected buffer size.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59789 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-09 09:16:59 +00:00
nobu 8238987903 suppress warnings when RUBY_USE_SETJMPEX
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59467 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-02 03:02:22 +00:00
kazu d9d2bbe4b9 Improve error message
ref [Bug #13761]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-31 03:35:22 +00:00
nobu 53737990fe sprintf.c: width too big
* sprintf.c (rb_str_format): explicitly reject too big negative
  width, instead of an empty string.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-23 09:44:48 +00:00
nobu c854fde373 sprintf.c: remove redundant condition
* sprintf.c (rb_str_format): when `t + 1 == end` (or `t < end`),
  `*t == '%'` is always true.  [ruby-core:80153] [Bug #13315]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-26 06:39:49 +00:00
eregon fd8df3ab3d Raise ArgumentError if sprintf format string ends with %
* Add tests and specs. See ruby/spec#401.
  Patch by Yuta Iwama and Shintaro Morikawa.
  [ruby-core:80153] [Bug #13315] [Fix GH-1560]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58890 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-25 15:33:28 +00:00
nobu 99a105c82f sprintf.c: remove unused variable
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-28 11:42:58 +00:00
nobu efdc6d78ac sprintf.c: ruby_ultoa
* sprintf.c (ruby_ultoa): prefixed to get rid of conflict with
  a MSVC library function.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-28 05:08:44 +00:00
nobu fb7c7d1e79 sprintf.c: format by utility functions
* sprintf.c (rb_str_format, fmt_setup): format by utility
  functions in vsnprintf.c instead of `snprintf`.

* sprintf.c (rb_str_format): format and append by `rb_str_catf`
  instead of formatting by `snprintf` and then copy.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-28 02:10:51 +00:00
nobu be2e146a55 sprintf.c: fix one-off bug
* sprintf.c (rb_str_format): `CHECK` just before `FILL_`, but
  after another `PUSH`.  fix one-off bug.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-28 02:05:54 +00:00
nobu be7309ddf6 Refactor "%f" % Inf/NaN
* sprintf.c (rb_str_format): as for non-finite float, calculate
  the exact needed size with the space flag.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-23 01:04:40 +00:00
nobu 6f8f950cc3 Fix space flag when Inf/NaN and width==3
* sprintf.c (rb_str_format): while `"% 2f"` and `"% 4f"` result in
  `" Inf"` and `" Inf"` respectively, `"% 3f"` results in
  `"Inf"` (no space).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-23 01:04:39 +00:00
nobu 57d6dd5a46 Avoid integer overflow in sprintf()
merged ff03a9a61c

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58034 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-20 01:36:08 +00:00
nobu f31bb33a3b sprintf.c: string limits
* sprintf.c (ruby__sfvwrite): use long instead of size_t due to
  string limits.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58033 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-20 01:33:08 +00:00
nobu f30ed02b8a sprintf.c: use FILL
* sprintf.c (rb_str_format): use FILL and FILL_ macros instead of
  while loop.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-19 12:46:31 +00:00
nobu a41d569e66 sprintf.c: fix out-of-bound access
* sprintf.c (rb_str_format): get rid of out-of-bound access when
  single % at the end.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-13 14:59:08 +00:00
shyouhei c56edb9a59 revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294]
This commit is auto-generated using following command:

svn diff -r57807:57788 include internal.h bignum.c numeric.c compile.c insns.def object.c sprintf.c | patch -p0


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-09 02:31:23 +00:00
shyouhei 74cdd893eb optimize FIXABLE macro
Looking at the source code, FIXABLE tends to be just before LOING2FIX
to check applicability of that operation.  Why not try computing first
then check for overflow, which should be optimial.

I also tried the same thing for unsigned types but resulted in slower
execution.  It seems RB_POSFIXABLE() is fast enough on modern CPUs.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57789 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-06 11:14:05 +00:00
normal ba5aa60668 sprintf.c: avoid garbage in common (no exception) case
Format strings which are dynamically-generated will benefit
from this.  This won't cover exceptions, but exceptions for
sprintf should be too uncommon to care about (unlike IO)

* sprintf.c (rb_str_format): use rb_str_tmp_frozen_{acquire,release}
* test/ruby/test_sprintf.rb (test_no_hidden_garbage): new test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-31 00:41:56 +00:00
nobu 0854193a68 sprintf.c: fix width underflow
* sprintf.c (rb_str_format): fix memory corruption by width
  underflow.  https://github.com/mruby/mruby/issues/3347

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-17 18:04:30 +00:00
rhe 2f551849c4 Use PRIuSIZE format specifier for size_t values
Use PRIuSIZE instead of PRIdSIZE. This fixes the exception message shown
on too large xmalloc2. This commit also fixes other incorrect use of
PRIdSIZE in other functions; though most of them are debug print.

* gc.c (heap_extend_pages, get_envparam_size, ruby_malloc_size_overflow,
  gc_profile_dump_on): Use PRIuSIZE instead of PRIdSIZE as the passed
  value is size_t, not ssize_t.

* iseq.c (get_line_info, rb_iseq_disasm_insn): Ditto.

* sprintf.c (rb_str_format): Ditto.

* thread_win32.c (native_thread_create): Ditto.

* vm.c (get_param): Ditto.

* ext/objspace/objspace_dump.c (dump_append_string_content,
  dump_object): Ditto.

* ext/socket/raddrinfo.c (host_str, port_str): Ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-13 12:33:13 +00:00
nobu 4a9705d6e3 ruby.h: RB_INTEGER_TYPE_P
* include/ruby/ruby.h (RB_INTEGER_TYPE_P): new macro and
  underlying inline function to check if the object is an
  Integer (Fixnum or Bignum).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-18 01:17:43 +00:00
akr f9727c12cc [Feature #12005] Unify Fixnum and Bignum into Integer
* [Feature #12005] Unify Fixnum and Bignum into Integer

* include/ruby/ruby.h (rb_class_of): Return rb_cInteger for fixnums.

* insns.def (INTEGER_REDEFINED_OP_FLAG): Unified from
  FIXNUM_REDEFINED_OP_FLAG and BIGNUM_REDEFINED_OP_FLAG.

* vm_core.h: Ditto.

* vm_insnhelper.c (opt_eq_func): Use INTEGER_REDEFINED_OP_FLAG instead
  of FIXNUM_REDEFINED_OP_FLAG.

* vm.c (vm_redefinition_check_flag): Use rb_cInteger instead of
  rb_cFixnum and rb_cBignum.
  (C): Use Integer instead of Fixnum and Bignum.

* numeric.c (fix_succ): Removed.
  (Init_Numeric): Define Fixnum as Integer.

* bignum.c (bignew): Use rb_cInteger instead of Rb_cBignum.
  (rb_int_coerce): replaced from rb_big_coerce and return fixnums
  as-is.
  (Init_Bignum): Define Bignum as Integer.
  Don't define ===.

* error.c (builtin_class_name): Return "Integer" for fixnums.

* sprintf.c (ruby__sfvextra): Use rb_cInteger instead of rb_cFixnum.

* ext/-test-/testutil: New directory to test.
  Currently it provides utilities for fixnum and bignum.

* ext/json/generator/generator.c: Define mInteger_to_json.

* lib/mathn.rb (Fixnum#/): Redefinition removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-17 06:53:48 +00:00
nobu 7d378a5b3a sprintf.c: refactor Rational f
* sprintf.c (rb_str_format): refactor floating point format of
  Rational by using gereric Integer functions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-27 23:19:50 +00:00
nobu 9ae4c2d590 sprintf.c: fix buffer overflow
* sprintf.c (rb_str_format): fix buffer overflow, length must be
  greater than precision.  reported by William Bowling <will AT
  wbowling.info>.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-27 23:18:52 +00:00
nobu d1e2d6a9c5 sprintf.c: simplify
* sprintf.c (rb_str_format): remove repeated calculations.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-27 03:55:08 +00:00
nobu ee2f3c6def sprintf.c: Rational f by generic Integer functions
* sprintf.c (rb_str_format): convert Rational to floating point
  format by using gereric Integer functions, not by methods which
  can be overwritten.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-27 03:13:39 +00:00
nobu 1301d1f5bc sprintf.c: exact number
* sprintf.c (rb_str_format): format exact number more exactly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-14 07:12:42 +00:00
nobu 77e9edc334 sprintf.c: fix garbage inserted with Rational
* sprintf.c (rb_str_format): fix wrong shifting position in
  Rational conversion when not at the beginning of the result.
  [ruby-core:71806] [Bug #11766]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-03 06:33:13 +00:00
nobu 51964bf995 symbol.c: rb_sym_intern
* symbol.c (rb_sym_intern): rename from rb_cstr_intern and add
  variants.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30 04:44:39 +00:00
nobu 56e3b49304 sprintf.c: nil value is valid
* sprintf.c (rb_str_format): look up the key, then get default
  value and raise KeyError if the returned value is nil.
  [ruby-dev:49338] [Ruby trunk - Bug #11677]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-11 09:30:31 +00:00
nobu def4370a55 sprintf.c: hash default value
* sprintf.c (rb_str_format): respect default value of a hash.  no
  longer raises KeyError unless the default value of the hash is
  nil.  [ruby-core:71354] [Bug #11661]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-11 00:03:15 +00:00
nobu 8007168baf vsnprintf.c: constify
* vsnprintf.c (FILE::vextra): constify the return value.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-28 16:11:41 +00:00
nobu 4191a6b90d preserve encodings in error messages
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-28 02:40:46 +00:00
nobu c47ef3dc13 sprintf.c: rb_inspect returns a string
* sprintf.c (rb_str_format): rb_inspect() always returns a string.
  rb_obj_as_string() has no more effect.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-26 08:58:00 +00:00
nobu 6c801fc58f sprintf.c: ruby specific functions
* sprintf.c (ruby_vsnprintf, ruby_snprintf): move ruby specific
  functions from vsnprintf.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-22 01:40:40 +00:00
nobu b4974e71dc util.c: hexdigit
* util.c (hexdigit): extract identical constants.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-13 07:07:39 +00:00
akr 2b9191e557 * internal.h: Gather declarations in non-header files.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-18 15:13:05 +00:00
akr 7cd76ab0c5 * internal.h: Include ruby.h and ruby/encoding.h to be
includable without prior inclusion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15 11:49:06 +00:00
nobu a9f3eb75de ruby.h: add mark to PRIsVALUE
* include/ruby/ruby.h (PRIsVALUE), vsnprintf.c (BSD_vfprintf): add
  RUBY_PRI_VALUE_MARK to reduce danger of accidental conflict with
  plain "%i".  binary incompatible with extension libraries using
  PRIsVALUE and built for 2.1 and earlier.  [EXPERIMENTAL]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-04 03:51:33 +00:00
nobu 57a1688743 sprintf.c: integer overflow
* sprintf.c (rb_str_format): fix a possible integer overflow and
  suppress implicit conversion warnings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47600 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-16 02:44:04 +00:00
nobu 230b845fa2 sprintf.c: improve rational 'f' format
* sprintf.c (rb_str_format): rational 'f' format works for more
  values.  [fix GH-717]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-14 23:13:36 +00:00
nobu 28dd61607e sprintf.c: fix condition
* sprintf.c (rb_str_format): fix condition to round.
  [ruby-core:64454] [Bug #10151]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-19 13:28:32 +00:00
nobu 1d196e0d2b sprintf.c: rational 'f' format
* sprintf.c (rb_str_format): support rational 'f' format.
  [ruby-core:64382] [Bug #10136]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-18 08:06:48 +00:00
nobu 22892ca6c2 sprintf.c: remove magic numbers
* sprintf.c (rb_str_format): name default float precision and
  remove unused initial value.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-18 08:06:37 +00:00