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

1740 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada b419f90a8b
Tweaked `Process::Status.wait`
* revert `rb_last_status_set`
* renamed the new function as `rb_process_status_new`
* `rb_process_status_new` always freezes the return value
* marked `Process::Status.wait` as EXPERIMENTAL, as it has not
  been discussed totally yet.
2020-12-09 11:51:57 +09:00
Nobuyoshi Nakada 4f907a80f0
Removed declaration of non-existent symbol 2020-12-09 11:32:18 +09:00
Samuel Williams 2553c5f94a Add support for non-blocking `Process.wait`. 2020-12-09 08:55:35 +13:00
Kenta Murata 7e69296a2b
memory_view.c: Add rb_memory_view_extract_item_members (#3855) 2020-12-08 02:01:31 +09:00
Lars Kanis ca76337a00
Windows: Read ENV names and values as UTF-8 encoded Strings (#3818)
* Windows: Read ENV names and values as UTF-8 encoded Strings

Implements issue #12650: fix https://bugs.ruby-lang.org/issues/12650

This also removes the special encoding for ENV['PATH'] and some
complexity in the code that is unnecessary now.

* Windows: Improve readablity of getenv() encoding

getenv() did use the expected codepage as an implicit parameter of the macro.
This is mis-leading since include/ruby/win32.h has a different definition.
Using the "cp" variable explicit (like the other function calls) makes it
more readable and consistent.

* Windows: Change external C-API macros getenv() and execv() to use UTF-8

They used to process and return strings with locale encoding,
but since all ruby-internal spawn and environment functions use UTF-8,
it makes sense to change the C-API equally.
2020-12-08 02:00:39 +09:00
Nobuyoshi Nakada 7817a438eb Removed deprecated Time#succ 2020-12-07 18:38:59 +09:00
卜部昌平 cc36e499f9 Doxygen terminology update [ci skip]
Follow N2328 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2328.pdf
2020-12-07 14:20:44 +09:00
Masaki Matsushita 5d8bcc4870 Revert getaddrinfo_a()
getaddrinfo_a() gets stuck after fork().
To avoid this, we need 1 second sleep to wait for internal
worker threads of getaddrinfo_a() to be finished, but that is unacceptable.

[Bug #17220] [Feature #17134] [Feature #17187]
2020-12-07 13:33:53 +09:00
Kenta Murata 60eabb1aa7
Revert "memory_view.c: Add rb_memory_view_extract_item_members"
This reverts the following three commits.

- ce707079c1
- 1a76bb56b0
- 51500eedef
2020-12-07 00:38:19 +09:00
Kenta Murata 1a76bb56b0
memory_view.c: Fix the argument type of rb_memory_view_extract_item_members 2020-12-06 23:24:45 +09:00
Kenta Murata 51500eedef
memory_view.c: Add rb_memory_view_extract_item_members 2020-12-06 22:46:06 +09:00
Masaki Matsushita 76439eee68 Call cleanup function for getaddrinfo_a(3) only before fork()
Previously, rb_getaddrinfo_a_before_exec() is called from before_exec().
However, the function needs to be called only before fork().
The change moves it to before_fork().
2020-12-06 01:32:43 +09:00
Masaki Matsushita 94d49ed31c Add a hook before fork() for getaddrinfo_a()
We need stop worker threads in getaddrinfo_a() before fork().
This change adds a hook before fork() that cancel all outstanding requests
and wait for all ongoing requests. Then, it waits for all worker
threads to be finished.

Fixes [Bug #17220]
2020-12-04 23:31:51 +09:00
Kazuhiro NISHIYAMA 94b2323a68
Fix typos [ci skip] 2020-12-04 10:37:58 +09:00
卜部昌平 84eb2bfab9 include/ruby/internal/xmalloc.h: add doxygen
Thought it was not a bad idea to document these CAPI. [ci skip]
2020-12-03 12:07:56 +09:00
Alan Wu 56141d38a3 Fix docs about movement for rb_gc_register_mark_object()
This API in fact pins objects passed to it. See vm.c:2546.
2020-12-01 15:23:09 -05:00
Koichi Sasada 182fb73c40 rb_ext_ractor_safe() to declare ractor-safe ext
C extensions can violate the ractor-safety, so only ractor-safe
C extensions (C methods) can run on non-main ractors.
rb_ext_ractor_safe(true) declares that the successive
defined methods are ractor-safe. Otherwiwze, defined methods
checked they are invoked in main ractor and raise an error
if invoked at non-main ractors.

[Feature #17307]
2020-12-01 15:44:18 +09:00
Koichi Sasada 67693d8d80 ractor local storage C-API
To manage ractor-local data for C extension, the following APIs
are defined.

* rb_ractor_local_storage_value_newkey
* rb_ractor_local_storage_value
* rb_ractor_local_storage_value_set
* rb_ractor_local_storage_ptr_newkey
* rb_ractor_local_storage_ptr
* rb_ractor_local_storage_ptr_set

At first, you need to create a key of storage by
rb_ractor_local_(value|ptr)_newkey().
For ptr storage, it accepts the type of storage,
how to mark and how to free with ractor's lifetime.

rb_ractor_local_storage_value/set are used to access a VALUE
and rb_ractor_local_storage_ptr/set are used to access a pointer.

random.c uses this API.
2020-12-01 09:39:30 +09:00
Kenta Murata 73a337e214
Keep references of memory-view-exported objects (#3816)
* memory_view.c: remove a reference in view->obj at rb_memory_view_release

* memory_view.c: keep references of memory-view-exported objects

* Update common.mk

* memory_view.c: Use st_update
2020-11-30 14:53:13 +09:00
Nobuyoshi Nakada 039ba387aa
Use opaque struct pointer than void 2020-11-27 21:38:08 +09:00
Kazuhiro NISHIYAMA a776032ef1
Move the declaration into the function
instead of 'do not call it directly.' comment.
2020-11-18 10:52:56 +09:00
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