[前][次][番号順一覧][スレッド一覧]

ruby-changes:73484

From: Nobuyoshi <ko1@a...>
Date: Thu, 8 Sep 2022 23:01:24 +0900 (JST)
Subject: [ruby-changes:73484] e2ccb316b4 (master): [Bug #5317] Use `rb_off_t` instead of `off_t`

https://git.ruby-lang.org/ruby.git/commit/?id=e2ccb316b4

From e2ccb316b437104cd1734c378970d34f5305966d Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 5 Sep 2022 20:23:27 +0900
Subject: [Bug #5317] Use `rb_off_t` instead of `off_t`

Get rid of the conflict with system-provided small `off_t`.
---
 file.c                              |   8 +-
 include/ruby/fiber/scheduler.h      |   4 +-
 include/ruby/internal/intern/file.h |   2 +-
 include/ruby/io/buffer.h            |   6 +-
 include/ruby/win32.h                |  11 ++-
 io.c                                | 156 +++++++++++++++++-------------------
 io_buffer.c                         |  28 +++----
 scheduler.c                         |   4 +-
 win32/Makefile.sub                  |   4 +
 win32/win32.c                       |  16 ++--
 10 files changed, 117 insertions(+), 122 deletions(-)

diff --git a/file.c b/file.c
index 514dec341a..eb5851de7d 100644
--- a/file.c
+++ b/file.c
@@ -2517,7 +2517,7 @@ rb_file_birthtime(VALUE obj) https://github.com/ruby/ruby/blob/trunk/file.c#L2517
  *
  */
 
-off_t
+rb_off_t
 rb_file_size(VALUE file)
 {
     if (RB_TYPE_P(file, T_FILE)) {
@@ -5089,7 +5089,7 @@ rb_file_s_join(VALUE klass, VALUE args) https://github.com/ruby/ruby/blob/trunk/file.c#L5089
 #if defined(HAVE_TRUNCATE)
 struct truncate_arg {
     const char *path;
-    off_t pos;
+    rb_off_t pos;
 };
 
 static void *
@@ -5138,7 +5138,7 @@ rb_file_s_truncate(VALUE klass, VALUE path, VALUE len) https://github.com/ruby/ruby/blob/trunk/file.c#L5138
 #if defined(HAVE_FTRUNCATE)
 struct ftruncate_arg {
     int fd;
-    off_t pos;
+    rb_off_t pos;
 };
 
 static VALUE
@@ -6093,7 +6093,7 @@ rb_stat_z(VALUE obj) https://github.com/ruby/ruby/blob/trunk/file.c#L6093
 static VALUE
 rb_stat_s(VALUE obj)
 {
-    off_t size = get_stat(obj)->st_size;
+    rb_off_t size = get_stat(obj)->st_size;
 
     if (size == 0) return Qnil;
     return OFFT2NUM(size);
diff --git a/include/ruby/fiber/scheduler.h b/include/ruby/fiber/scheduler.h
index 9f67bd5bf6..d38651da5c 100644
--- a/include/ruby/fiber/scheduler.h
+++ b/include/ruby/fiber/scheduler.h
@@ -276,7 +276,7 @@ VALUE rb_fiber_scheduler_io_write(VALUE scheduler, VALUE io, VALUE buffer, size_ https://github.com/ruby/ruby/blob/trunk/include/ruby/fiber/scheduler.h#L276
  * @retval      RUBY_Qundef  `scheduler` doesn't have `#io_read`.
  * @return      otherwise    What `scheduler.io_read` returns.
  */
-VALUE rb_fiber_scheduler_io_pread(VALUE scheduler, VALUE io, VALUE buffer, size_t length, off_t offset);
+VALUE rb_fiber_scheduler_io_pread(VALUE scheduler, VALUE io, VALUE buffer, size_t length, rb_off_t offset);
 
 /**
  * Nonblocking write to the passed IO at the specified offset.
@@ -289,7 +289,7 @@ VALUE rb_fiber_scheduler_io_pread(VALUE scheduler, VALUE io, VALUE buffer, size_ https://github.com/ruby/ruby/blob/trunk/include/ruby/fiber/scheduler.h#L289
  * @retval      RUBY_Qundef  `scheduler` doesn't have `#io_write`.
  * @return      otherwise    What `scheduler.io_write` returns.
  */
-VALUE rb_fiber_scheduler_io_pwrite(VALUE scheduler, VALUE io, VALUE buffer, size_t length, off_t offset);
+VALUE rb_fiber_scheduler_io_pwrite(VALUE scheduler, VALUE io, VALUE buffer, size_t length, rb_off_t offset);
 
 /**
  * Nonblocking read from the passed IO using a native buffer.
diff --git a/include/ruby/internal/intern/file.h b/include/ruby/internal/intern/file.h
index 2dc60c7ba7..79820fdc61 100644
--- a/include/ruby/internal/intern/file.h
+++ b/include/ruby/internal/intern/file.h
@@ -206,7 +206,7 @@ int rb_is_absolute_path(const char *path); https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/intern/file.h#L206
  *              unpredictable.  POSIX's `<sys/stat.h>` states  that "the use of
  *              this field is unspecified" then.
  */
-off_t rb_file_size(VALUE file);
+rb_off_t rb_file_size(VALUE file);
 
 RBIMPL_SYMBOL_EXPORT_END()
 
diff --git a/include/ruby/io/buffer.h b/include/ruby/io/buffer.h
index 907fec20bb..bb83fe0be6 100644
--- a/include/ruby/io/buffer.h
+++ b/include/ruby/io/buffer.h
@@ -65,7 +65,7 @@ enum rb_io_buffer_endian { https://github.com/ruby/ruby/blob/trunk/include/ruby/io/buffer.h#L65
 };
 
 VALUE rb_io_buffer_new(void *base, size_t size, enum rb_io_buffer_flags flags);
-VALUE rb_io_buffer_map(VALUE io, size_t size, off_t offset, enum rb_io_buffer_flags flags);
+VALUE rb_io_buffer_map(VALUE io, size_t size, rb_off_t offset, enum rb_io_buffer_flags flags);
 
 VALUE rb_io_buffer_lock(VALUE self);
 VALUE rb_io_buffer_unlock(VALUE self);
@@ -82,9 +82,9 @@ void rb_io_buffer_clear(VALUE self, uint8_t value, size_t offset, size_t length) https://github.com/ruby/ruby/blob/trunk/include/ruby/io/buffer.h#L82
 
 // The length is the minimum required length.
 VALUE rb_io_buffer_read(VALUE self, VALUE io, size_t length);
-VALUE rb_io_buffer_pread(VALUE self, VALUE io, size_t length, off_t offset);
+VALUE rb_io_buffer_pread(VALUE self, VALUE io, size_t length, rb_off_t offset);
 VALUE rb_io_buffer_write(VALUE self, VALUE io, size_t length);
-VALUE rb_io_buffer_pwrite(VALUE self, VALUE io, size_t length, off_t offset);
+VALUE rb_io_buffer_pwrite(VALUE self, VALUE io, size_t length, rb_off_t offset);
 
 RBIMPL_SYMBOL_EXPORT_END()
 
diff --git a/include/ruby/win32.h b/include/ruby/win32.h
index ea460a5e46..93e6183ed9 100644
--- a/include/ruby/win32.h
+++ b/include/ruby/win32.h
@@ -195,7 +195,6 @@ struct stati128 { https://github.com/ruby/ruby/blob/trunk/include/ruby/win32.h#L195
   long st_ctimensec;
 };
 
-#define off_t __int64
 #define stat stati128
 #undef SIZEOF_STRUCT_STAT_ST_INO
 #define SIZEOF_STRUCT_STAT_ST_INO sizeof(unsigned __int64)
@@ -401,9 +400,9 @@ scalb(double a, long b) https://github.com/ruby/ruby/blob/trunk/include/ruby/win32.h#L400
 
 #define SUFFIX
 
-extern int rb_w32_ftruncate(int fd, off_t length);
-extern int rb_w32_truncate(const char *path, off_t length);
-extern int rb_w32_utruncate(const char *path, off_t length);
+extern int rb_w32_ftruncate(int fd, rb_off_t length);
+extern int rb_w32_truncate(const char *path, rb_off_t length);
+extern int rb_w32_utruncate(const char *path, rb_off_t length);
 
 #undef HAVE_FTRUNCATE
 #define HAVE_FTRUNCATE 1
@@ -722,7 +721,7 @@ int  rb_w32_fclose(FILE*); https://github.com/ruby/ruby/blob/trunk/include/ruby/win32.h#L721
 int  rb_w32_pipe(int[2]);
 ssize_t rb_w32_read(int, void *, size_t);
 ssize_t rb_w32_write(int, const void *, size_t);
-off_t  rb_w32_lseek(int, off_t, int);
+rb_off_t  rb_w32_lseek(int, rb_off_t, int);
 int  rb_w32_uutime(const char *, const struct utimbuf *);
 int  rb_w32_uutimes(const char *, const struct timeval *);
 int  rb_w32_uutimensat(int /* must be AT_FDCWD */, const char *, const struct timespec *, int /* must be 0 */);
@@ -815,7 +814,7 @@ double rb_w32_pow(double x, double y); https://github.com/ruby/ruby/blob/trunk/include/ruby/win32.h#L814
 #define MAP_ANON	0x1000
 #define MAP_ANONYMOUS	MAP_ANON
 
-extern void *rb_w32_mmap(void *, size_t, int, int, int, off_t);
+extern void *rb_w32_mmap(void *, size_t, int, int, int, rb_off_t);
 extern int rb_w32_munmap(void *, size_t);
 extern int rb_w32_mprotect(void *, size_t, int);
 
diff --git a/io.c b/io.c
index 1eb48dd19b..30165e1616 100644
--- a/io.c
+++ b/io.c
@@ -75,10 +75,6 @@ https://github.com/ruby/ruby/blob/trunk/io.c#L75
 #include <sys/fcntl.h>
 #endif
 
-#if !HAVE_OFF_T && !defined(off_t)
-# define off_t  long
-#endif
-
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
 #endif
@@ -149,10 +145,6 @@ https://github.com/ruby/ruby/blob/trunk/io.c#L145
 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
 #endif
 
-#if SIZEOF_OFF_T > SIZEOF_LONG && !defined(HAVE_LONG_LONG)
-# error off_t is bigger than long, but you have no long long...
-#endif
-
 #ifndef PIPE_BUF
 # ifdef _POSIX_PIPE_BUF
 #  define PIPE_BUF _POSIX_PIPE_BUF
@@ -620,7 +612,7 @@ raise_on_write(rb_io_t *fptr, int e, VALUE errinfo) https://github.com/ruby/ruby/blob/trunk/io.c#L612
 static void
 io_unread(rb_io_t *fptr)
 {
-    off_t r, pos;
+    rb_off_t r, pos;
     ssize_t read_size;
     long i;
     long newlines = 0;
@@ -859,7 +851,7 @@ rb_io_s_try_convert(VALUE dummy, VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L851
 static void
 io_unread(rb_io_t *fptr)
 {
-    off_t r;
+    rb_off_t r;
     rb_io_check_closed(fptr);
     if (fptr->rbuf.len == 0 || fptr->mode & FMODE_DUPLEX)
         return;
@@ -2224,7 +2216,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/io.c#L2216
 rb_io_tell(VALUE io)
 {
     rb_io_t *fptr;
-    off_t pos;
+    rb_off_t pos;
 
     GetOpenFile(io, fptr);
     pos = io_tell(fptr);
@@ -2237,7 +2229,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/io.c#L2229
 rb_io_seek(VALUE io, VALUE offset, int whence)
 {
     rb_io_t *fptr;
-    off_t pos;
+    rb_off_t pos;
 
     pos = NUM2OFFT(offset);
     GetOpenFile(io, fptr);
@@ -2348,7 +2340,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/io.c#L2340
 rb_io_set_pos(VALUE io, VALUE offset)
 {
     rb_io_t *fptr;
-    off_t pos;
+    rb_off_t pos;
 
     pos = NUM2OFFT(offset);
     GetOpenFile(io, fptr);
@@ -2884,8 +2876,8 @@ static long https://github.com/ruby/ruby/blob/trunk/io.c#L2876
 remain_size(rb_io_t *fptr)
 {
     struct stat st;
-    off_t siz = READ_DATA_PENDING_COUNT(fptr);
-    off_t pos;
+    rb_off_t siz = READ_DATA_PENDING_COUNT(fptr);
+    rb_off_t pos;
 
     if (fstat(fptr->fd, &st) == 0  && S_ISREG(st.st_mode)
 #if defined(__HAIKU__)
@@ -5662,7 +5654,7 @@ rb_io_sysseek(int argc, VALUE *argv, VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L5654
     VALUE offset, ptrname;
     int whence = SEEK_SET;
     rb_io_t *fptr;
-    off_t pos;
+    rb_off_t pos;
 
     if (rb_scan_args(argc, argv, "11", &offset, &ptrname) == 2) {
         whence = interpret_seek_whence(ptrname);
@@ -5790,7 +5782,7 @@ struct prdwr_internal_arg { https://github.com/ruby/ruby/blob/trunk/io.c#L5782
     int fd;
     void *buf;
     size_t count;
-    off_t offset;
+    rb_off_t offset;
 };
 #endif /* HAVE_PREAD || HAVE_PWRITE */
 
@@ -798 (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]