# \#defines in Ruby's .c files

**URL:** <https://www.ruby-forum.com/t/defines-in-rubys-c-files/100027>\
**Category:** Ruby\
**Created:** [February 1, 2006, 11:37pm UTC](https://www.ruby-forum.com/t/defines-in-rubys-c-files/100027 "2006-02-01T23:37:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 1, 2006, 11:37pm UTC](https://www.ruby-forum.com/t/defines-in-rubys-c-files/100027/1 "2006-02-01T23:37:21Z")

</div>

I was talking to someone on irc who was trying to speed up sockets - he  
came up  
with a way to do it by modifying sysread() so that a new buffer doesn’t  
always  
have to be allocated on each call. (sped up sockets by 314x by his  
account, BTW  
🙂 However, he had to patch the Ruby source code to do this because he  
was not  
able to access a macro (READ\_DATA\_BUFFERED) from his extenstion code.  
Turns  
out that the macro READ\_DATA\_BUFFERED is defined in io.c, so you can’t  
use it  
from an extenstion.

So, I got to thinking that maybe #defines like that should go into .h  
files,  
not .c files (maybe it should be #define’d in rubyio.h) so that they are  
accessable in extenstions.

Would it be possible to move some of them to .h files for 1.8.5 (or at  
least  
before 2.0)?

Phil

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 2, 2006, 7:30am UTC](https://www.ruby-forum.com/t/defines-in-rubys-c-files/100027/2 "2006-02-02T07:30:13Z")

</div>

Hi,

In message “Re: #defines in Ruby’s .c files”  
on Thu, 2 Feb 2006 06:45:53 +0900, removed\_email\_address@domain.invalid (Phil T.)  
writes:  
|  
|I was talking to someone on irc who was trying to speed up sockets - he came up  
|with a way to do it by modifying sysread() so that a new buffer doesn’t always  
|have to be allocated on each call. (sped up sockets by 314x by his account, BTW  
|:) However, he had to patch the Ruby source code to do this because he was not  
|able to access a macro (READ\_DATA\_BUFFERED) from his extenstion code. Turns  
|out that the macro READ\_DATA\_BUFFERED is defined in io.c, so you can’t use it  
|from an extenstion.  
|  
|So, I got to thinking that maybe #defines like that should go into .h files,  
|not .c files (maybe it should be #define’d in rubyio.h) so that they are  
|accessable in extenstions.  
|  
|Would it be possible to move some of them to .h files for 1.8.5 (or at least  
|before 2.0)?

How about merging his patch to io.c? I would be very glad to apply if  
it increases io performance 314 times.

```
						matz.
```

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 2, 2006, 9:04am UTC](https://www.ruby-forum.com/t/defines-in-rubys-c-files/100027/3 "2006-02-02T09:04:12Z")

</div>

In article [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
Yukihiro M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> |out that the macro READ\_DATA\_BUFFERED is defined in io.c, so you can’t use it  
> it increases io performance 314 times.
> 
> ```
> matz.
> 
> ```

It looks like he found some other problems with that patch (core dumps).  
So  
the idea is being rethought.

Phil
