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

370 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 9e67a38fde
Fallback to built-in UTF-8 for miniruby
Source code encoding is defaulted to UTF-8 now too.
2020-05-16 17:36:30 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
Nobuyoshi Nakada 5d430c1b34
Added more NORETURN declarations 2020-05-11 00:40:14 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Nobuyoshi Nakada fce667ed08
Get rid of warnings/exceptions at cleanup
After the encoding index instance variable is removed when all
instance variables are removed in `obj_free`, then `rb_str_free`
causes uninitialized instance variable warning and nil-to-integer
conversion exception.  Both cases result in object allocation
during GC, and crashes.
2020-02-13 12:46:48 +09:00
卜部昌平 f83781c8c1 rb_enc_str_asciionly_p expects T_STRING
This `str2` variable can be non-string (regexp etc.) but the previous
code passed it directly to rb_enc_str_asciionly_p(), which expects its
argument be a string.  Let's enforce that constraint.
2020-02-10 12:19:30 +09:00
卜部昌平 115fec062c more on NULL versus functions.
Function pointers are not void*.  See also
ce4ea956d2
8427fca49b
2020-02-07 14:24:19 +09:00
Lars Kanis a4fca28b80 Fix description of Encoding.default_(in|ex)ternal
Data written to files is not transcoded per default, but only
when default_internal is set.

The default for default_internal is nil and doesn't depend on the
source file encoding.
2020-02-03 08:42:01 -08:00
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
QuestionDriven 54be15f325 [Doc] Fix sample in Encoding#names 2019-12-22 23:01:45 +09:00
QuestionDriven 9654241d5d [Doc] Fix wrong example in Encoding.aliases 2019-12-22 23:01:45 +09:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
This removes the related tests, and puts the related specs behind
version guards.  This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
2019-11-18 01:00:25 +02:00
Jeremy Evans c5c05460ac Warn on access/modify of $SAFE, and remove effects of modifying $SAFE
This removes the security features added by $SAFE = 1, and warns for access
or modification of $SAFE from Ruby-level, as well as warning when calling
all public C functions related to $SAFE.

This modifies some internal functions that took a safe level argument
to no longer take the argument.

rb_require_safe now warns, rb_require_string has been added as a
version that takes a VALUE and does not warn.

One public C function that still takes a safe level argument and that
this doesn't warn for is rb_eval_cmd.  We may want to consider
adding an alternative method that does not take a safe level argument,
and warn for rb_eval_cmd.
2019-11-18 01:00:25 +02:00
Nobuyoshi Nakada 8869384367
Moved Init_encoding from wrong place [Bug #16292] 2019-11-05 10:28:01 +09:00
卜部昌平 7e0ae1698d avoid overflow in integer multiplication
This changeset basically replaces `ruby_xmalloc(x * y)` into
`ruby_xmalloc2(x, y)`.  Some convenient functions are also
provided for instance `rb_xmalloc_mul_add(x, y, z)` which allocates
x * y + z byes.
2019-10-09 12:12:28 +09:00
Lars Kanis 9311656914
Better wording for __ENCODING__
"locale encoding" is misleading since it doesn't mean Encoding.find("locale")
but the encoding used to interpret the script file. It's therefore better to
call it "script encoding" as in the paragraphs above.
Closes: https://github.com/ruby/ruby/pull/1611
2019-08-04 09:03:46 +09:00
Lourens Naudé 009ec37a47
Let the index boundary check in rb_enc_from_index be flagged as unlikely
[Misc #15806]

Closes: https://github.com/ruby/ruby/pull/2128
2019-07-23 16:45:54 +09:00
Lourens Naudé 6546aed475
Explicitly initialise encodings on init to remove branches on encoding lookup
[Misc #15806]

Closes: https://github.com/ruby/ruby/pull/2128
2019-07-23 16:45:54 +09:00
Koichi Sasada 8ac1c6eb48 respect RUBY_DEBUG too 2019-07-15 12:06:25 +09:00
Yusuke Endoh 76bad330aa encoding.c (enc_table_expand): prefer xrealloc to realloc
And raise an exception when failed to register an encoding
2019-07-15 12:01:22 +09:00
nobu 56557ec28a [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-22 11:04:59 +00:00
nobu e040465153 encoding.c: check external encoding
* encoding.c (rb_enc_get_index): external encoding may not be Data
  object.  [ruby-core:89016] [Bug #15122]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64753 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-15 16:27:06 +00:00
eregon a2c7d0cea9 encoding.c (rb_enc_get_index): return -1 for non-encoding capable objects
* Clarify logic and add spec.
* Now passes test-all with the JSON fix.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-03 15:11:49 +00:00
eregon bd58361e58 Revert "encoding.c (rb_enc_get_index): return -1 for non-encoding capable objects"
* This reverts commit fb253d2032.
* The CI is failing, this seems a bug in the JSON C extension.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-03 14:31:39 +00:00
eregon fb253d2032 encoding.c (rb_enc_get_index): return -1 for non-encoding capable objects
* Clarify logic and add spec.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-03 13:52:26 +00:00
eregon 080d700e1d encoding.c (enc_set_index): raise instead of rb_bug() for non-encoding capable objects
* Add spec.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-03 13:52:13 +00:00
ko1 d0fb73a0f0 check enc_capable.
* encoding.c (rb_enc_capable): make it extern to check enc_capable.
  enc_index can be set to limited types such as T_STRING, T_REGEX
  and so on. This function check an object is this kind of types.

* include/ruby/encoding.h: ditto.

* encoding.c (enc_set_index): check a given object is enc_capable.

* include/ruby/encoding.h (PUREFUNC):

* marshal.c (encoding_name): check `rb_enc_capable` first.

* marshal.c (r_ivar): ditto. If it is not enc_capable, it should be
  malformed data.

* spec/ruby/optional/capi/encoding_spec.rb: remove tests depending
  on the wrong feature: all objects can set enc_index.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-28 08:35:48 +00:00
normal 4e730838a0 encoding.c: remove rb_gc_mark_encodings
rb_gc_mark_encodings has been empty for a decade
(since r17875 / 28b216ac45).
Just remove it and its only caller in gc.c

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-05 22:01:43 +00:00
normal 7c8b79755b load.c: use fstring instead of OBJ_FREEZE
These strings already exist (or will exist soon) in the fstring
table, so avoid the duplicate, sooner.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-24 22:39:56 +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 e2479cc43f encoding.c: rb_enc_find_index2
* string.c (str_undump): use rb_enc_find_index2 to find encoding
  by unterminated string.  check the format before encoding name.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-22 01:03:17 +00:00
rhe 201972ac4c encoding.c: handle needmore error from rb_enc_precise_mbclen()
rb_enc_ascget() erroneously reports success even if the given byte
sequence is incomplete, for non-ASCII compatible encoding strings.

rb_enc_precise_mbclen() may return a negative value on error, and thus
rb_enc_ascget() must not store the return value in 'unsigned int';
otherwise the subsequent MBCLEN_CHARFOUND_P() check won't catch the
error.  [ruby-core:78646] [Bug #13034]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57078 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-14 12:32:42 +00:00
ngoto 5eff15d1bd * string.c (rb_str_change_terminator_length): New function to change
termlen and resize heap for the terminator. This is split from
  rb_str_fill_terminator (str_fill_term) because filling terminator
  and changing terminator length are different things. [Bug #12536]

* internal.h: declaration for rb_str_change_terminator_length.

* string.c (str_fill_term): Simplify only to zero-fill the terminator.
  For non-shared strings, it assumes that (capa + termlen) bytes of
  heap is allocated. This partially reverts r55557.

* encoding.c (rb_enc_associate_index): rb_str_change_terminator_length
  is used, and it should be called whenever the termlen is changed.

* string.c (str_capacity): New static function to return capacity
  of a string with the given termlen, because the termlen may
  sometimes be different from TERM_LEN(str) especially during
  changing termlen or filling terminator with specific termlen.

* string.c (rb_str_capacity): Use str_capacity.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-05 10:45:23 +00:00
hsbt 0e382a3dd8 * encoding.c: Fix return value of `Encoding::ISO8859_1.name`
[Bug #12313][ruby-core:75147][ci skip]
* ext/bigdecimal/bigdecimal.c: Fix code sample of `BigDecimal.new`

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54755 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-25 02:17:54 +00:00
naruse 723241fcb9 * include/ruby/ruby.h (rb_isupper, rb_islower, rb_isalpha, rb_isdigit,
rb_isalnum, rb_isxdigit, rb_isblank, rb_isspace, rb_isblank,
  rb_iscntrl, rb_isprint, rb_ispunct, rb_isgraph,
  rb_tolower, rb_toupper): use inline function to avoid function call.

* include/ruby/ruby.h (rb_isascii): use inline function to clarify
  the logic.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-29 10:24:05 +00:00
nobu 439224a590 RUBY_ASSERT
* error.c (rb_assert_failure): assertion with stack dump.
* ruby_assert.h (RUBY_ASSERT): new header for the assertion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-22 08:33:55 +00:00
ko1 3dbb390180 * introduce new ISeq binary format serializer/de-serializer
and a pre-compilation/runtime loader sample.
  [Feature #11788]

* iseq.c: add new methods:
  * RubyVM::InstructionSequence#to_binary_format(extra_data = nil)
  * RubyVM::InstructionSequence.from_binary_format(binary)
  * RubyVM::InstructionSequence.from_binary_format_extra_data(binary)

* compile.c: implement body of this new feature.

* load.c (rb_load_internal0), iseq.c (rb_iseq_load_iseq):
  call RubyVM::InstructionSequence.load_iseq(fname) with
  loading script name if this method is defined.

  We can return any ISeq object as a result value.
  Otherwise loading will be continue as usual.

  This interface is not matured and is not extensible.
  So that we don't guarantee the future compatibility of this method.
  Basically, you should'nt use this method.

* iseq.h: move ISEQ_MAJOR/MINOR_VERSION (and some definitions)
  from iseq.c.

* encoding.c (rb_data_is_encoding), internal.h: added.

* vm_core.h: add several supports for lazy load.
  * add USE_LAZY_LOAD macro to specify enable or disable of
    this feature.
  * add several fields to rb_iseq_t.
  * introduce new macro rb_iseq_check().

* insns.def: some check for lazy loading feature.

* vm_insnhelper.c: ditto.

* proc.c: ditto.

* vm.c: ditto.

* test/lib/iseq_loader_checker.rb: enabled iff suitable
  environment variables are provided.

* test/runner.rb: enable lib/iseq_loader_checker.rb.

* sample/iseq_loader.rb: add sample compiler and loader.

    $ ruby sample/iseq_loader.rb [dir]

  will compile all ruby scripts in [dir].
  With default setting, this compile creates *.rb.yarb files
  in same directory of target .rb scripts.

    $ ruby -r sample/iseq_loader.rb [app]

  will run with enable to load compiled binary data.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 13:58:50 +00:00
nobu e86f66b33f encoding.c: make fstring
* encoding.c (enc_name, rb_enc_name_list_i, rb_enc_aliases_enc_i):
  make fstring instead of making each copies.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-02 08:00:56 +00:00
nobu 2a66cc554d encoding.c: defer finding encoding
* encoding.c (enc_m_loader): defer finding encoding object not to
  be infected by marshal source.  [ruby-core:71793] [Bug #11760]
* marshal.c (r_object0): enable compatible loader on USERDEF
  class.  the loader function is called with the class itself,
  instead of an allocated object, and the loaded data.
* marshal.c (compat_allocator_table): intialize
  compat_allocator_tbl on demand.
* object.c (rb_undefined_alloc): extract from rb_obj_alloc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-02 07:27:22 +00:00
nobu 4bef8cffa3 encoding.c: use rb_check_arity
* encoding.c (enc_dump): use rb_check_arity to just check number
  of arguments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-02 06:48:51 +00:00
nobu d8a27d374a ENC_ASSERT
* encoding.c (ENC_ASSERT): make an expression, and prevent the
  argument from further expansions.

* encoding.c (rb_enc_check_str): assert before using.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-29 14:31:48 +00:00
nobu 4e1ea795aa indent
* encoding.c (enc_compatible_latter): adjust indent.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-29 14:01:13 +00:00
ko1 05b9b42918 * encoding.c (rb_enc_check_str): add for performance.
This function only accept T_STRING (and T_REGEXP).

  This patch improves performance of a tiny_segmenter benchmark
  (num=2) 2.54sec -> 2.42sec on my machine.
  https://github.com/chezou/TinySegmenter.jl/blob/master/benchmark/benchmark.rb

* encoding.c: add ENC_DEBUG and ENC_ASSERT() macros.

* internal.h: add a decl. of rb_enc_check_str().

* string.c (rb_str_plus): use rb_enc_check_str().

* string.c (rb_str_subpat_set): ditto.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-29 09:10:32 +00:00
ko1 56eee285be revert r52336 (commit miss)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-29 05:30:50 +00:00
ko1 106f033b89 * gc.c (gc_mark_ptr): remove debug code for #11244.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-29 05:10:06 +00:00
nobu 078b6c9838 encindex.h: ENCINDEX
* encindex.h: separate encoding index constants from internal.h.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-15 05:49:20 +00:00
nobu 09421c5da1 localeinit.c: locale_charmap rdoc [ci skip]
* localeinit.c (rb_locale_charmap): [RDOC] move
  Encoding.locale_charmap rdoc from encoding.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-07 05:47:34 +00:00
nobu c16523e67b encoding.c: fix document [ci skip]
* encoding.c (rb_enc_unicode_p): fix document.  predicate
  functions may return non-zero values other than 1 as true.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-30 08:32:37 +00:00
nobu 7a89049a76 encoding.c: find encoding index
* encoding.c (rb_locale_encindex): find encoding index without
  making a string object every time.  [ruby-core:58160] [Bug #9080]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-24 07:01:22 +00:00