[#25936] [Bug:1.9] [rubygems] $LOAD_PATH includes bin directory — Nobuyoshi Nakada <nobu@...>

Hi,

10 messages 2009/10/05

[#25943] Disabling tainting — Tony Arcieri <tony@...>

Would it make sense to have a flag passed to the interpreter on startup that

16 messages 2009/10/05

[#26028] [Bug #2189] Math.atanh(1) & Math.atanh(-1) should not raise an error — Marc-Andre Lafortune <redmine@...>

Bug #2189: Math.atanh(1) & Math.atanh(-1) should not raise an error

14 messages 2009/10/10

[#26222] [Bug #2250] IO::for_fd() objects' finalization dangerously closes underlying fds — Mike Pomraning <redmine@...>

Bug #2250: IO::for_fd() objects' finalization dangerously closes underlying fds

11 messages 2009/10/22

[#26244] [Bug #2258] Kernel#require inside rb_require() inside rb_protect() inside SysV context fails — Suraj Kurapati <redmine@...>

Bug #2258: Kernel#require inside rb_require() inside rb_protect() inside SysV context fails

24 messages 2009/10/22

[#26361] [Feature #2294] [PATCH] ruby_bind_stack() to embed Ruby in coroutine — Suraj Kurapati <redmine@...>

Feature #2294: [PATCH] ruby_bind_stack() to embed Ruby in coroutine

42 messages 2009/10/27

[#26371] [Bug #2295] segmentation faults — tomer doron <redmine@...>

Bug #2295: segmentation faults

16 messages 2009/10/27

[ruby-core:26251] Why Ruby doesn't have multiplatform design?

From: vondruch@...
Date: 2009-10-23 13:53:10 UTC
List: ruby-core #26251
Hello everybody,

While browsing through Ruby code (especially IO), I'm really curious why 
Ruby does not have any real platform specific implementations. I see on 
every place #ifdef _WIN32, #elif defined __APPLE__ and so on, but why 
there is no just one place which will include code for specific platform 
just one time? The real intention of author is lost somewhere in between 
ifdefs. For example, code like this seems to me hackish:

/* define system APIs */
#ifdef _WIN32
#define STAT(p, s)      rb_w32_ustati64(p, s)
#undef lstat
#define lstat(p, s)     rb_w32_ustati64(p, s)
#undef access
#define access(p, m)    rb_w32_uaccess(p, m)
#undef chmod
#define chmod(p, m)     rb_w32_uchmod(p, m)
#undef chown
#define chown(p, o, g)  rb_w32_uchown(p, o, g)
#undef utime
#define utime(p, t)     rb_w32_uutime(p, t)
#undef link
#define link(f, t)      rb_w32_ulink(f, t)
#undef unlink
#define unlink(p)       rb_w32_uunlink(p)
#undef rename
#define rename(f, t)    rb_w32_urename(f, t)
#else
#define STAT(p, s)      stat(p, s)
#endif

Nobody can see at first look, that chown is not actually library function, 
but some macro. There were times when Usaku tried to introduce something a 
bit nicer:

/* define system APIs */
#ifdef _WIN32
#define STAT(p, s)      rb_w32_wstati64((WCHAR *)(p), s)
#define LSTAT(p, s)     rb_w32_wstati64((WCHAR *)(p), s)
#define ACCESS(p, m)    _waccess((WCHAR *)(p), m)
#define CHMOD(p, m)     _wchmod((WCHAR *)(p), m)
#define CHOWN(p, o, g)  rb_w32_wchown((WCHAR *)(p), o, g)
#define UTIME(p, t)     rb_w32_wutime((WCHAR *)(p), t)
#define LINK(f, t)      rb_w32_wlink((WCHAR *)(f), (WCHAR *)(t))
#define UNLINK(p)       rb_w32_wunlink((WCHAR *)(p))
#define RENAME(f, t)    _wrename((WCHAR *)(f), (WCHAR *)(t))
#else
#define STAT(p, s)      stat(p, s)
#define LSTAT(p, s)     lstat(p, s)
#define ACCESS(p, m)    access(p, m)
#define CHMOD(p, m)     chmod(p, m)
#define CHOWN(p, o, g)  chown(p, o, g)
#define UTIME(p, t)     utime(p, t)
#define LINK(f, t)      link(f, t)
#define UNLINK(p)       unlink(p)
#define RENAME(f, t)    rename(f, t)
#endif

At least it was warning: "Be aware, something strange is going on here", 
but from my point of view, his intention was never finished. This defines 
should be extracted into dedicated files, i.e. into something like 
win32/file.h and posix/file.h which could be later included by following 
few lines of code:

/* define system APIs */
#ifdef _WIN32
#include "win32/file.h"
#else
#include "posix/file.h"
#endif

I (as an Windows developer) feel not welcomed in such code (Posix). Could 
you please comment?

Vit





PS: Sorry if I offended some author of used examples. It really was not my 
intention.

In This Thread

Prev Next