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

1719 Коммитов

Автор SHA1 Сообщение Дата
Koichi Sasada 5e3259ea74 fix public interface
To make some kind of Ractor related extensions, some functions
should be exposed.

* include/ruby/thread_native.h
  * rb_native_mutex_*
  * rb_native_cond_*
* include/ruby/ractor.h
  * RB_OBJ_SHAREABLE_P(obj)
  * rb_ractor_shareable_p(obj)
  * rb_ractor_std*()
  * rb_cRactor

and rm ractor_pub.h
and rename srcdir/ractor.h to srcdir/ractor_core.h
    (to avoid conflict with include/ruby/ractor.h)
2020-11-18 03:52:41 +09:00
Jean Boussier ef19fb111a Expose the rb_interned_str_* family of functions
Fixes [Feature #13381]
2020-11-17 09:39:25 +09:00
Alan Wu f234f2740d Add docs for some C extension GC APIs 2020-11-06 09:55:26 -08:00
Alan Wu 670e288d65 Add warning for str_new_static functions
Many functions in string.c assume that capa + termlen to be readable
memory. Add comment in header to communicate this to extension authors.

See also: comment in str_fill_term()
2020-10-30 19:47:14 -04:00
Koichi Sasada 2f50936cb9 Ractor.make_shareable(obj)
Introduce new method Ractor.make_shareable(obj) which tries to make
obj shareable object. Protocol is here.

(1) If obj is shareable, it is shareable.
(2) If obj is not a shareable object and if obj can be shareable
    object if it is frozen, then freeze obj. If obj has reachable
    objects (rs), do rs.each{|o| Ractor.make_shareable(o)}
    recursively (recursion is not Ruby-level, but C-level).
(3) Otherwise, raise Ractor::Error. Now T_DATA is not a shareable
    object even if the object is frozen.

If the method finished without error, given obj is marked as
a sharable object.

To allow makng a shareable frozen T_DATA object, then set
`RUBY_TYPED_FROZEN_SHAREABLE` as type->flags. On default,
this flag is not set. It means user defined T_DATA objects are
not allowed to become shareable objects when it is frozen.

You can make any object  shareable by setting FL_SHAREABLE flag,
so if you know that the T_DATA object is shareable (== thread-safe),
set this flag, at creation time for example. `Ractor` object is one
example, which is not a frozen, but a shareable object.
2020-10-21 07:59:24 +09:00
Kenta Murata a6a8576e87
Feature #16812: Allow slicing arrays with ArithmeticSequence (#3241)
* Support ArithmeticSequence in Array#slice

* Extract rb_range_component_beg_len

* Use rb_range_values to check Range object

* Fix ary_make_partial_step

* Fix for negative step cases

* range.c: Describe the role of err argument in rb_range_component_beg_len

* Raise a RangeError when an arithmetic sequence refers the outside of an array

[Feature #16812]
2020-10-21 02:40:18 +09:00
Koichi Sasada 91ec5f9e39 remove rb_obj_iv_index_tbl
(1) nobody uses it (gem-codesearch)
(2) the data strucuture will be changed.
2020-10-17 08:18:04 +09:00
Nobuyoshi Nakada 62abdbadf2
Revert "Don't export rb_callable_receiver"
This reverts commit c839168b11.
`rb_callable_receiver` does not need to be exposed under include.
2020-10-07 11:27:30 +09:00
Chris Seaton c839168b11 Don't export rb_callable_receiver 2020-10-06 15:41:47 -07:00
卜部昌平 2d20e68fb7 include/ruby/memory_view.h: annotate functions 2020-10-06 14:20:10 +09:00
卜部昌平 62ddbfe2b9 rb_memory_view_is_contiguous: convert into an inline function 2020-10-06 14:20:10 +09:00
卜部昌平 7d594399f6 memory_view.h: use bool
Because `bool` is already used in the header there is no reason to
hesitate.
2020-10-06 14:20:10 +09:00
卜部昌平 81068b1090 RB_RANDOM_DATA_INIT_PARENT: convert into an inline function
Bit readable to me.
2020-10-06 14:20:10 +09:00
卜部昌平 78e27ced97 rb_rand_if: convert into an inline function
This adds more room for assertions.
2020-10-06 14:20:10 +09:00
卜部昌平 56a45456ac include/ruby/random.h: eliminate extern "C"
cf: 99add25857
2020-10-06 14:20:10 +09:00
Nobuyoshi Nakada 68d24bc045
Moved rb_callable_receiver internal 2020-10-06 10:11:51 +09:00
Kenta Murata c827cacde1
memory_view.c: Use ssize_t for ndim in memory_view (#3615)
* memory_view.c: Use ssize_t for ndim in memory_view

* include/ruby/memory_view.h: Fix the type of item_size argument
2020-10-02 08:04:25 +09:00
卜部昌平 06099e4ee1 fix typo [ci skip]
Reported by Mau Magnaguagno See: https://github.com/ruby/ruby/pull/3570#discussion_r495465903
2020-09-29 09:57:47 +09:00
Jeremy Evans 346301e232 Add rb_category_warn{,ing} for warning messages with categories
This adds the following C-API functions that can be used to emit
warnings with categories included:

```c
void rb_category_warn(const char *, const char*, ...)
void rb_category_warning(const char*, const char*, ...)
```

Internally in error.c, there is an rb_warn_category function
that will call Warning.warn with the string and the category
keyword if it doesn't have an arity of 1, and will call
Warning.warn with just the string if it has an arity of 1.
This refactors the rb_warn_deprecated{,_to_remove} functions
to use rb_warn_category.

This makes Kernel#warn accept a category keyword and pass it
to Warning.warn, so that Ruby methods can more easily emit
warnings with categories.  rb_warn_category makes sure that
the passed category is a already defined category symbol
before calling Warning.warn.

The only currently defined warning category is :deprecated,
since that is what is already used.  More categories can be
added in later commits.
2020-09-28 08:38:06 -07:00
卜部昌平 722a1e479f RBIMPL_ALIGNAS: reorder #ifdef blocks
Since r63443, `-std=gnu99 -D_XOPEN_SOUCE=x00` is added to Solaris'
`CPPFLAGS`.  `CPPFLAGS` is shared among `CC` / `CXX`.  This results in
both `__STDC_VERSION__` and `__cplusplus` to be defined at the same time
for a C++ compilation, only on Solaris.

It seems the `CPPFLAGS` addition is intentional.  We sould not touch
that part.  Instead we need to reroute this by always check for
`__cplusplus` first.
2020-09-26 00:30:36 +09:00
Kenta Murata c04c34df47
memory_view.h: brush up the description in the comment 2020-09-25 21:32:00 +09:00
Kenta Murata 890bc2cdde
Buffer protocol proposal (#3261)
* Add buffer protocol

* Modify for some review comments

* Per-object buffer availability

* Rename to MemoryView from Buffer and make compilable

* Support integral repeat count in memory view format

* Support 'x' for padding bytes

* Add rb_memory_view_parse_item_format

* Check type in rb_memory_view_register

* Update dependencies in common.mk

* Add test of MemoryView

* Add test of rb_memory_view_init_as_byte_array

* Add native size format test

* Add MemoryView test utilities

* Add test of rb_memory_view_fill_contiguous_strides

* Skip spaces in format string

* Support endianness specifiers

* Update documentation

* Support alignment

* Use RUBY_ALIGNOF

* Fix format parser to follow the pack format

* Support the _ modifier

* Parse count specifiers in get_format_size function.

* Use STRUCT_ALIGNOF

* Fix test

* Fix test

* Fix total size for the case with tail padding

* Fix rb_memory_view_get_item_pointer

* Fix rb_memory_view_parse_item_format again
2020-09-25 20:32:02 +09:00
Koichi Sasada fde136152e should not check taint flag on rubyspec.
Now taint flag is obsolete and it is used fro shareaable flag.
So we should not check this flag.
2020-09-25 12:52:53 +09:00
卜部昌平 c6c241e49c enrich comment
Added description and URL about nested flexible array member.
2020-09-25 11:38:33 +09:00
卜部昌平 e75aed7abb RBIMPL_ALIGNOF: do not use constexpr
Was definitely a bad idea to use constexpr.  It is not ubiquitous.
2020-09-25 11:38:33 +09:00
卜部昌平 873fb1aa4c ALLOCA_N: do not use RUBY_ALIGNOF
Now that RUBY_ALIGNOF behaves like C11's _Alignof.  This is not
necessarily the best stack arrangement.  We can just give up using
__builtin_alloca_with_align(), and let alloca choose what is optimal.
2020-09-25 11:38:33 +09:00
卜部昌平 e9fb2bc873 RBIMPL_ALIGNOF: do not use __alignof__
It is reported that on a system of i386 System V ABI, GCC returns 8 for
__alignof__(double).  OTOH the ABI defines alignments of double to be 4,
and ISO/IEC 9899:2011 reads that _Alignof(double) shall return 4 on such
machine.  What we want in ruby is 4 instead of 8 there.  We cannot use
__alignof__.

Additionally, both old GCC / old clang return 8 for _Alignof(double) on
such platforms.  They are their bugs, and already fixed in recent
versions.  But we have to support older compilers for a while.  Shall
check sanity of _Alignof.
2020-09-25 11:38:33 +09:00
Hiroshi SHIBATA e380f78851 Removed rb_find_file_ext_safe and rb_find_file_safe 2020-09-23 09:09:36 +09:00
Chris Seaton 8e173d8b27 Warn on a finalizer that captures the object to be finalized
Also improve specs and documentation for finalizers and more clearly
recommend a safe code pattern to use them.
2020-09-16 13:52:24 -07:00
Samuel Williams 7fca274198 Rework console to use `rb_io_wait`. 2020-09-14 16:44:09 +12:00
Samuel Williams 701dcbb3ca Add support for hooking `IO#read`. 2020-09-14 16:44:09 +12:00
Samuel Williams d387029f39 Standardised scheduler interface. 2020-09-14 16:44:09 +12:00
Samuel Williams 905e9c8093 Simplify bitmasks for IO events. 2020-09-14 16:44:09 +12:00
Samuel Williams 6747cb5754 Add RB_ prefix to `GetOpenFile` and `MakeOpenFile`. 2020-09-14 16:44:09 +12:00
Nobuyoshi Nakada 2b07b24bdf Added `rb_random_base_init`
To enclose the initialization of Random::Base part.
2020-09-07 20:08:01 +09:00
Nobuyoshi Nakada 4924011262 Added WITH_REAL macros
Added `WITH_REAL` versions to `RB_RANDOM_INTERFACE` macros.  Also
these macros including "without real" versions no longer contain
the terminator (semicolon and comma).
2020-09-07 20:08:01 +09:00
Nobuyoshi Nakada d6ec0ef59b Added `get_real` interface 2020-09-07 20:08:01 +09:00
Nobuyoshi Nakada c449b9b02f Added rb_int_pair_to_real 2020-09-07 20:08:01 +09:00
Nobuyoshi Nakada af5e87ab21 separate rb_random_t
* random.c: separate abstract rb_random_t and rb_random_mt_t for
  Mersenne Twister implementation.

* include/ruby/random.h: the interface for extensions of Random
  class.

* DLL imported symbol reference is not constant on Windows.

* check if properly initialized.
2020-09-07 20:08:01 +09:00
Samuel Williams c12b2703bc Add `RB_` prefix for size_t to number conversion. 2020-09-06 15:37:54 +12:00
Koichi Sasada 79df14c04b Introduce Ractor mechanism for parallel execution
This commit introduces Ractor mechanism to run Ruby program in
parallel. See doc/ractor.md for more details about Ractor.
See ticket [Feature #17100] to see the implementation details
and discussions.

[Feature #17100]

This commit does not complete the implementation. You can find
many bugs on using Ractor. Also the specification will be changed
so that this feature is experimental. You will see a warning when
you make the first Ractor with `Ractor.new`.

I hope this feature can help programmers from thread-safety issues.
2020-09-03 21:11:06 +09:00
Yukihiro "Matz" Matsumoto 21c62fb670
Version number bumped to 3.0.0 from 2.8.0 (tentative).
We have decided to go forward to 3.0 this year.
2020-08-31 16:38:13 +09:00
Kazuhiro NISHIYAMA c2011d1a51
Fix a typo [ci skip] 2020-08-29 12:31:05 +09:00
卜部昌平 5ca44076f4 include/ruby/backward/2/rmodule.h: deprecate
Only one function in only one file uses contents of this public header.
That is not a wise idea.  Let's just free the header's soul.
2020-08-27 16:42:06 +09:00
卜部昌平 1035a3b202 RUBY_SHOW_COPYRIGHT_TO_DIE: flip the default
Commit 7aab062ef3 says:

> ruby_show_version() will no longer exits the process, if
> RUBY_SHOW_COPYRIGHT_TO_DIE is set to 0.  This will be the default in
> the future.

3.0 is a good timing for that "future".
2020-08-27 15:04:00 +09:00
卜部昌平 cd1d6d9029 include/ruby/backward/2/r_cast.h: deprecate
Remove all usages of RCAST() so that the header file can be excluded
from ruby/ruby.h's dependency.
2020-08-27 15:03:36 +09:00
卜部昌平 442525527e improve deprecation warning
We should not recommend RBIMPL_*.
2020-08-27 15:02:52 +09:00
卜部昌平 21b3bc10d3 DEPRECATED_TYPE: is deprecated
Nobody uses this macro any longer.
2020-08-27 15:02:52 +09:00
卜部昌平 3437e6247d RClassDeprecated: delete
It has been deprecated for 5 years since 1f22556040.
2020-08-27 15:02:52 +09:00
卜部昌平 5ae2c1b093 git rm include/ruby/backward/rubyio.h 2020-08-27 14:27:21 +09:00