# C Extension: mirco RUBY\_VM

**URL:** <https://www.ruby-forum.com/t/c-extension-mirco-ruby-vm/123513>\
**Category:** Ruby\
**Created:** [December 18, 2007, 11:13am UTC](https://www.ruby-forum.com/t/c-extension-mirco-ruby-vm/123513 "2007-12-18T11:13:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lianliming](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b38774/32.png) [@lianliming](https://www.ruby-forum.com/u/lianliming)\
**Post date:** [December 18, 2007, 11:13am UTC](https://www.ruby-forum.com/t/c-extension-mirco-ruby-vm/123513/1 "2007-12-18T11:13:34Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![lianliming](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b38774/32.png) [@lianliming](https://www.ruby-forum.com/u/lianliming)\
**Post date:** [December 18, 2007, 3:58pm UTC](https://www.ruby-forum.com/t/c-extension-mirco-ruby-vm/123513/2 "2007-12-18T15:58:03Z")

</div>

Hi Liming,

On Dec 18, 2007 6:35 PM, lianliming [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![lianliming](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b38774/32.png) [@lianliming](https://www.ruby-forum.com/u/lianliming)\
**Post date:** [December 18, 2007, 9:34pm UTC](https://www.ruby-forum.com/t/c-extension-mirco-ruby-vm/123513/3 "2007-12-18T21:34:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lianliming](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b38774/32.png) [@lianliming](https://www.ruby-forum.com/u/lianliming)\
**Post date:** [December 19, 2007, 12:19am UTC](https://www.ruby-forum.com/t/c-extension-mirco-ruby-vm/123513/4 "2007-12-19T00:19:23Z")

</div>

On Dec 19, 2007 5:33 AM, Paul B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![lianliming](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b38774/32.png) [@lianliming](https://www.ruby-forum.com/u/lianliming)\
**Post date:** [December 19, 2007, 4:05am UTC](https://www.ruby-forum.com/t/c-extension-mirco-ruby-vm/123513/5 "2007-12-19T04:05:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lianliming](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b38774/32.png) [@lianliming](https://www.ruby-forum.com/u/lianliming)\
**Post date:** [December 23, 2007, 2:56pm UTC](https://www.ruby-forum.com/t/c-extension-mirco-ruby-vm/123513/6 "2007-12-23T14:56:56Z")

</div>

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' and`code 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.
