772 Commits

Author SHA1 Message Date
Peter Zhu
58386814a7 Don't check for null pointer in calls to free
According to the C99 specification section 7.20.3.2 paragraph 2:

> If ptr is a null pointer, no action occurs.

So we do not need to check that the pointer is a null pointer.
2023-06-30 09:13:31 -04:00
Samuel Williams
a218ed5692
Hide the usage of rb_io_t where possible. (#7880)
This retries the compatible parts of the previously reverted PR so we can continue to update related code without breaking backwards compatibility.
2023-06-01 14:23:30 +09:00
NARUSE, Yui
85dcc4866d Revert "Hide most of the implementation of struct rb_io. (#6511)"
This reverts commit 18e55fc1e1ec20e8f3166e3059e76c885fc9f8f2.

fix [Bug #19704]
https://bugs.ruby-lang.org/issues/19704
This breaks compatibility for extension libraries. Such changes
need a discussion.
2023-06-01 08:43:22 +09:00
Samuel Williams
18e55fc1e1
Hide most of the implementation of struct rb_io. (#6511)
* Add rb_io_path and rb_io_open_descriptor.

* Use rb_io_open_descriptor to create PTY objects

* Rename FMODE_PREP -> FMODE_EXTERNAL and expose it

FMODE_PREP I believe refers to the concept of a "pre-prepared" file, but
FMODE_EXTERNAL is clearer about what the file descriptor represents and
aligns with language in the IO::Buffer module.

* Ensure that rb_io_open_descriptor closes the FD if it fails

If FMODE_EXTERNAL is not set, then it's guaranteed that Ruby will be
responsible for closing your file, eventually, if you pass it to
rb_io_open_descriptor, even if it raises an exception.

* Rename IS_EXTERNAL_FD -> RUBY_IO_EXTERNAL_P

* Expose `rb_io_closed_p`.

* Add `rb_io_mode` to get IO mode.

---------

Co-authored-by: KJ Tsanaktsidis <ktsanaktsidis@zendesk.com>
2023-05-30 10:02:40 +09:00
Samuel Williams
6d976eb534
Fix "runs a C function with the global lock unlocked and unlocks IO with the generic RUBY_UBF_IO" on Windows. (#7848)
* Enable borked spec.

* Ensure win32 wrappers are visible and used.

* Reorganise `read`/`write`/`pipe` in `thread_spec.c`.
2023-05-24 22:45:34 +09:00
Samuel Williams
28056a6d16
Add support for pread/pwrite on windows. (#7827) 2023-05-24 09:15:20 +09:00
Takashi Kokubun
2e875549a9 s/MJIT/RJIT/ 2023-03-06 23:44:01 -08:00
Takashi Kokubun
233ddfac54 Stop exporting symbols for MJIT 2023-03-06 21:59:23 -08:00
Nobuyoshi Nakada
ef00c6da88
Adjust else style to be consistent in each files [ci skip] 2023-02-26 13:20:43 +09:00
Lars Kanis
d0f5dc9eac Windows: Prefer USERPROFILE over HOMEPATH
HOMEPATH is set to "\WINDOWS\system32" when running per "runas" session.
This directory is not writable by ordinary users, leading to errors with many ruby tools.
Also config files in the home directory are not recognized.

Still keeping HOME at first which is not used by native Windows,
but by ruby specs and by MSYS2 environment.
2022-12-24 23:48:47 +09:00
NARUSE, Yui
9eb19a02ae Add more comments why CRuby uses __pioinfo 2022-12-15 00:14:00 +09:00
Nobuyoshi Nakada
1a47521c44
Use rb_sprintf instead of deprecated sprintf 2022-11-25 08:51:14 +09:00
Lars Kanis
439990318d Avoid warnings on MINGW:
win32/win32.c: In function 'rtc_error_handler':
win32/win32.c:691:5: warning: function 'rtc_error_handler' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
  691 |     rb_str_vcatf(str, fmt, ap);
      |     ^~~~~~~~~~~~

and

win32/win32.c:683:1: warning: 'rtc_error_handler' defined but not used [-Wunused-function]
  683 | rtc_error_handler(int e, const char *src, int line, const char *exe, const char *fmt, ...)
      | ^~~~~~~~~~~~~~~~~
2022-11-20 11:06:28 +09:00
Samuel Williams
ea8a7287e2
Add support for sockaddr_un on Windows. (#6513)
* Windows: Fix warning about undefined if_indextoname()

* Windows: Fix UNIXSocket on MINGW and make .pair more reliable

* Windows: Use nonblock=true for read tests with scheduler

* Windows: Move socket detection from File.socket? to File.stat

Add S_IFSOCK to Windows and interpret reparse points accordingly.
Enable tests that work now.

* Windows: Use wide-char functions to UNIXSocket

This fixes behaviour with non-ASCII characters.
It also fixes deletion of temporary UNIXSocket.pair files.

* Windows: Add UNIXSocket tests for specifics of Windows impl.

* Windows: fix VC build due to missing _snwprintf

Avoid usage of _snwprintf, since it fails linking ruby.dll like so:

  linking shared-library x64-vcruntime140-ruby320.dll
  x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol snwprintf
  x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol vsnwprintf_l

whereas linking miniruby.exe succeeds.

This patch uses snprintf on the UTF-8 string instead.

Also remove branch GetWindowsDirectoryW, since it doesn't work.

* Windows: Fix dangling symlink test failures

Co-authored-by: Lars Kanis <kanis@comcard.de>
2022-11-17 14:50:25 -08:00
Lars Kanis
7b1d23fd29
Windows: Readlink improvements (#6745)
* Windows: Use readlink emulation for File.readlink

This fixes readlink emulation for the ERROR_MORE_DATA case and general error reporting.
It now releases GVL while readlink IO operation.

The dedicated rb_readlink was introduced in commit 2ffb87995a33cdc7ba609a4b867f03f18da0c3b3
in order to improve encoding and buffer allocation.
However the encoding issues are solved since ruby-3.0 switched to UTF-8
and the buffer allocation will be improved in a later commit.

* Windows: Increase the default buffer size for reparse point info

So far nearly all queries of reparse points needed two attempts to get enough buffer.

* Windows: Remove declaration of rb_w32_wreadlink

It was removed in commit 2f6fdd3aebdee2ce04d003b206f6da78120e8235
2022-11-17 01:57:52 -08:00
YO4
28030f7b54 eliminate magic number 2022-09-09 00:45:56 +09:00
YO4
81e7573a64 win32.c additional fix: is_readable_console
classic console(conhost.exe) reports an input with ALT+NUMPAD as VK_MENU, KeyUp, and uChar!=0.
additional fix for #5634
2022-09-09 00:45:56 +09:00
YO4
7a849e1903 win32.c fix: is_readable_console
UnicodeChar with lower byte == 0 has dropped accidentaly
this is additional fix for #5634
2022-09-09 00:45:56 +09:00
Nobuyoshi Nakada
e2ccb316b4 [Bug #5317] Use rb_off_t instead of off_t
Get rid of the conflict with system-provided small `off_t`.
2022-09-08 23:01:07 +09:00
Nobuyoshi Nakada
58c8b6e862
Adjust styles [ci skip] 2022-08-06 10:13:20 +09:00
Takashi Kokubun
5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Jean Boussier
d084585f01 Rename ENCINDEX_ASCII to ENCINDEX_ASCII_8BIT
Otherwise it's way too easy to confuse it with US_ASCII.
2022-07-19 08:48:56 +02:00
Nobuyoshi Nakada
ee48c9cda6
[Win32] allow pipe in flock 2022-04-21 15:14:08 +09:00
Nobuyoshi Nakada
a0040af671 [Win32] Fix mode of character/pipe device stat [Bug #18732] 2022-04-15 17:14:29 +09:00
Nobuyoshi Nakada
7b1ece9b94
Get rid of type-punning pointer casts 2022-04-07 19:19:13 +09:00
YO4
5d90c60109
Avoid console input behavior in windows 10 [Bug #18588]
When ANSI versions of PeekConsoleInput read multibyte charactor
partially, subsequent ReadFile returns wrong data on newer Windows
10 versions (probably since Windows Terminal introduced).  To
avoid this, use Unicode version of of PeekConsoleInput/ReadConsole.
2022-03-16 10:28:35 +09:00
Yuta Saito
6729258839
include/ruby/win32.h: define HAVE_X for the missing prototypes (#5456) 2022-01-18 19:08:07 +09:00
nagachika
d5fc3fa4db win32/win32.c Fix PROT_EXEC bit flag check for FlushInstrucitonCache() 2021-12-30 21:16:29 +09:00
U.Nakamura
4e007d705c Fix some bornheads 2021-12-27 17:15:09 +09:00
U.Nakamura
85a426dc86 Tiny mmap emulation for Windows
- prerequisite of supporting YJIT with VC++.
- note that now can specfily `--yjit` on mswin64, but not enabled
  YJIT'ed code because of YJIT requires `OPT_DIRECT_THREADED_CODE`
  or `OPT_CALL_THREADED_CODE` in `rb_yjit_compile_iseq`.
2021-12-27 15:56:23 +09:00
xtkoba
0cf9197988 Clang never evaluates expr in __builtin_assume 2021-10-04 08:13:37 +09:00
Nobuyoshi Nakada
845c017e08
Reminders of the Windows versions each API is available [ci skip] 2021-09-24 12:31:20 +09:00
xtkoba (Tee KOBAYASHI)
e32fe3ce76 MINGW: _WIN64 is not defined on i386-mingw32 + ucrt. 2021-09-20 00:15:30 +09:00
xtkoba (Tee KOBAYASHI)
4705ebd907 MINGW: Fix build error on Windows UCRT 2021-09-20 00:15:30 +09:00
Jeremy Evans
7c31ecd3ac Add parentheses to avoid pointless condition
Pointed out by xtkoba (Tee KOBAYASHI).

Fixes [Bug #17946]
2021-06-23 21:48:42 +09:00
xtkoba
44cff500a0 _MSC_VER may not be defined 2021-05-04 20:38:25 -04:00
Nobuyoshi Nakada
e85bffc324
Increment global variables atomically 2021-03-08 17:46:07 +09:00
Nobuyoshi Nakada
b7d4dcf3a6
Make vm_exit_handler installation MT-safe 2021-03-08 17:46:07 +09:00
Nobuyoshi Nakada
9299703b39
Make uenvarea thread exclusive 2021-03-08 17:46:07 +09:00
Nobuyoshi Nakada
8c943e3be8
Make the flag in thread_exclusive unique 2021-03-08 17:46:07 +09:00
Nobuyoshi Nakada
1a00402987
Enclose crtitical sections in thread_exclusive block 2021-03-08 17:45:02 +09:00
Nobuyoshi Nakada
a12e950816
Revert "Enclose crtitical sections in thread_exclusive block"
19cc24b34b0490b7c2779eec521fe0089e05f183 and fixups.
2021-02-24 03:13:07 +09:00
Nobuyoshi Nakada
7563d542d6
Use the system getenv in setup_debug_log
As ruby_set_debug_option() is called before ruby_sysinit(),
CRITICAL_SECTIONs are not initialized yet.
2021-02-23 23:11:44 +09:00
Nobuyoshi Nakada
819dd464de
Fixed commit miss at 41eb4fbf86e7ae9c9ff993e07a19fa44eb74be9b 2021-02-23 21:23:46 +09:00
Nobuyoshi Nakada
5a4742a0b4
Make uenvarea thread exclusive 2021-02-23 21:19:25 +09:00
Nobuyoshi Nakada
41eb4fbf86
Fixed commit miss at 19cc24b34b0490b7c2779eec521fe0089e05f183 2021-02-23 20:46:40 +09:00
Nobuyoshi Nakada
da18d6f015
Constified possible data 2021-02-23 19:28:03 +09:00
Nobuyoshi Nakada
19cc24b34b Enclose crtitical sections in thread_exclusive block 2021-02-23 19:03:54 +09:00
Andrew Aladjev
0d76636117 added mutexes for socket and connection lists on win32 2021-02-23 16:20:01 +09:00
Nobuyoshi Nakada
67d2619463 Expand final path name buffer for namespace prefix
As final path name includes the namespace prefix, so expand room
for it in path name buffer.
2021-02-22 19:48:15 +09:00