aboutsummaryrefslogtreecommitdiffstats
path: root/sprintf.c
Commit message (Collapse)AuthorAgeFilesLines
* sprintf.c: remove redundant conditionnobu2017-05-261-2/+1
| | | | | | | * 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
* Raise ArgumentError if sprintf format string ends with %eregon2017-05-251-1/+4
| | | | | | | | * 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
* sprintf.c: remove unused variablenobu2017-04-281-2/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* sprintf.c: ruby_ultoanobu2017-04-281-5/+5
| | | | | | | * 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
* sprintf.c: format by utility functionsnobu2017-04-281-38/+38
| | | | | | | | | | * 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
* sprintf.c: fix one-off bugnobu2017-04-281-5/+5
| | | | | | | * 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
* Refactor "%f" % Inf/NaNnobu2017-04-231-18/+17
| | | | | | | * 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
* Fix space flag when Inf/NaN and width==3nobu2017-04-231-3/+1
| | | | | | | | * 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
* Avoid integer overflow in sprintf()nobu2017-03-201-1/+2
| | | | | | merged https://github.com/mruby/mruby/commit/ff03a9a61c62340cff62f8e0fdc1a1e8775b6f17 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58034 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* sprintf.c: string limitsnobu2017-03-201-3/+8
| | | | | | | * 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
* sprintf.c: use FILLnobu2017-03-191-24/+13
| | | | | | | * 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
* sprintf.c: fix out-of-bound accessnobu2017-03-131-0/+1
| | | | | | | * 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
* revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294]shyouhei2017-03-091-1/+5
| | | | | | | | | 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
* optimize FIXABLE macroshyouhei2017-03-061-5/+1
| | | | | | | | | | | | 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
* sprintf.c: avoid garbage in common (no exception) casenormal2017-01-311-2/+4
| | | | | | | | | | | 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
* sprintf.c: fix width underflownobu2016-12-171-2/+2
| | | | | | | * 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
* Use PRIuSIZE format specifier for size_t valuesrhe2016-09-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* ruby.h: RB_INTEGER_TYPE_Pnobu2016-05-181-1/+1
| | | | | | | | * 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
* [Feature #12005] Unify Fixnum and Bignum into Integerakr2016-05-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * [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
* sprintf.c: refactor Rational fnobu2016-03-271-25/+23
| | | | | | | * 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
* sprintf.c: fix buffer overflownobu2016-03-271-1/+1
| | | | | | | | * 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
* sprintf.c: simplifynobu2016-03-271-9/+2
| | | | | | * 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
* sprintf.c: Rational f by generic Integer functionsnobu2016-03-271-10/+7
| | | | | | | | * 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
* sprintf.c: exact numbernobu2016-01-141-3/+9
| | | | | | * 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
* sprintf.c: fix garbage inserted with Rationalnobu2015-12-031-7/+10
| | | | | | | | * 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
* symbol.c: rb_sym_internnobu2015-11-301-3/+3
| | | | | | | * 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
* sprintf.c: nil value is validnobu2015-11-111-6/+14
| | | | | | | | * 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
* sprintf.c: hash default valuenobu2015-11-111-5/+5
| | | | | | | | * 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
* vsnprintf.c: constifynobu2015-09-281-1/+1
| | | | | | * 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
* preserve encodings in error messagesnobu2015-09-281-0/+20
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* sprintf.c: rb_inspect returns a stringnobu2015-06-261-2/+6
| | | | | | | * 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
* sprintf.c: ruby specific functionsnobu2015-02-221-0/+33
| | | | | | | * 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
* util.c: hexdigitnobu2015-02-131-0/+2
| | | | | | * util.c (hexdigit): extract identical constants. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * internal.h: Gather declarations in non-header files.akr2014-11-181-2/+0
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * internal.h: Include ruby.h and ruby/encoding.h to beakr2014-11-151-3/+1
| | | | | | | | includable without prior inclusion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ruby.h: add mark to PRIsVALUEnobu2014-11-041-0/+3
| | | | | | | | | * 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
* sprintf.c: integer overflownobu2014-09-161-3/+3
| | | | | | | * 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
* sprintf.c: improve rational 'f' formatnobu2014-09-141-13/+39
| | | | | | | * 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
* sprintf.c: fix conditionnobu2014-08-191-1/+1
| | | | | | | * 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
* sprintf.c: rational 'f' formatnobu2014-08-181-0/+67
| | | | | | | * 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
* sprintf.c: remove magic numbersnobu2014-08-181-2/+3
| | | | | | | * 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
* * sprintf.c (rb_str_format): like r47006, get rid ofktsj2014-07-301-2/+2
| | | | | | function calls in RSTRING_PTR(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * parse.y: change Symbol <-> ID relationship to avoidko12014-07-091-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | exposing IDs from collectable symbols. [Bug #10014] Now, rb_check_id() returns 0 if corresponding symbol is pinned dynamic symbol. There is remaining intern_cstr_without_pindown(), it can return IDs from collectable symbols. We must be careful to use it (only used in parse.y). I think it should be removed if it does not have impact for performance. * parse.y: add: * STATIC_SYM2ID() * STATIC_ID2SYM() rename: * rb_pin_dynamic_symbol() -> dsymbol_pindown() * internal.h: remove: * rb_check_id_without_pindown() * rb_sym2id_without_pindown() add: * rb_check_symbol() * rb_check_symbol_cstr() * load.c: use rb_check_id() or rb_check_id_cstr(). * object.c: ditto. * struct.c: ditto. * thread.c: ditto. * vm_method.c: ditto. * string.c (sym_find): use only rb_check_symbol(). * sprintf.c (rb_str_format): use rb_check_symbol_cstr(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* sprintf.c: skip non-interned namenobu2014-07-081-7/+8
| | | | | | | * sprintf.c (rb_str_format): get rid of accessing by symbol of invalid ID, when the name is not interned. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* sprintf.c: check_name_argnobu2014-07-021-4/+12
| | | | | | * sprintf.c (check_name_arg): utility function for GETNAMEARG(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* sprintf.c: check_pos_argnobu2014-07-021-6/+17
| | | | | | * sprintf.c (check_pos_arg): utility function for GETPOSARG(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* sprintf.c: check_next_argnobu2014-07-021-4/+12
| | | | | | * sprintf.c (check_next_arg): utility function for GETNEXTARG(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* sprintf.c: get_numnobu2014-07-021-13/+21
| | | | | | * sprintf.c (get_num): utility function for GETNUM(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46656 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* sprintf.c: unnumbered asterisk with numbered argumentnobu2014-06-261-1/+4
| | | | | | | | * sprintf.c (GETASTER): should not use the numbered argument to be formatted, raise ArgumentError instead. [ruby-dev:48330] [Bug #9982] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* sprintf.c: remove extra parenthesesnobu2014-06-261-1/+1
| | | | | | | * sprintf.c (GETASTER): remove extra parentheses from the second argument so that the error message does not contain them. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e