C Extension: mirco RUBY_VM

Hi all,

I am hacking some existing Ruby c extension, and found code like
following:

#ifdef RUBY_VM

#endif

I want to know the meaning of micro RUBY_VM. I have read some
documents about Ruby C extension like the README.EXT in Ruby source
code. But I can’t find anywhere talking about usage of this micro.
Google search only shows me some code using this micro without any
explanation on why and when to use this micro.

Any hints? or is there any online article documenting this micro?

Thanks in advance!

Hi Liming,

On Dec 18, 2007 6:35 PM, lianliming [email protected] wrote:

Hi all,

I am hacking some existing Ruby c extension, and found code like
following:

#ifdef RUBY_VM

#endif

This will be code in ruby-oci8 trunk.
There is no article documenting RUBY_VM.
I use it to check whether the ruby’s thread model is green or native,
in other words, whether the ruby version is 1.8 or 1.9.

#ifdef RUBY_VM
code for ruby 1.9
#else
code for ruby 1.8
#endif

I want RUBY_VERSION_MAJOR, RUBY_VERSION_MINOR and so on.
But there is no macro describing ruby version. I use RUBY_VM instead.

On Tue, Dec 18, 2007 at 11:56:34PM +0900, KUBO Takehiro wrote:

I want RUBY_VERSION_MAJOR, RUBY_VERSION_MINOR and so on.
But there is no macro describing ruby version. I use RUBY_VM instead.

In version.h there is:

#define RUBY_VERSION_CODE 190

#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 9
#define RUBY_VERSION_TEENY 0

But unfortunately version.h doesn’t get included automatically (IMO it
should – and it should have include guards as well).

Paul

On Dec 19, 2007 5:33 AM, Paul B. [email protected] wrote:

#define RUBY_VERSION_TEENY 0
Thanks. I grepped sub directories under ‘include’ in ruby 1.9
source tree. But version.h is found on the top directory. I have not
noticed it.

But unfortunately version.h doesn’t get included automatically (IMO it
should – and it should have include guards as well).

In addition, version.h is installed on ruby 1.8. but not on 1.9. I
cannot
use it.

Hi kubo,

Thanks for your reply. I didn’t realize this macro is ruby-oci8
specific. I asked here because I thought it is a common micro in ruby
c library.

Hi,

At Tue, 18 Dec 2007 23:56:34 +0900,
KUBO Takehiro wrote in [ruby-talk:284006]:

I use it to check whether the ruby’s thread model is green or native,
in other words, whether the ruby version is 1.8 or 1.9.

#ifdef RUBY_VM
code for ruby 1.9
#else
code for ruby 1.8
#endif

They should be code for ruby with VM' andcode for ruby
without VM’.

I want RUBY_VERSION_MAJOR, RUBY_VERSION_MINOR and so on.
But there is no macro describing ruby version. I use RUBY_VM instead.

Check if a feature you want to use is supported. You should
not rely on cryptic version number check.