Skip to content

Commit 55a4d3f

Browse files
committed
add section on gil removal in references and remake TOC
1 parent 3868c24 commit 55a4d3f

File tree

1 file changed

+80
-40
lines changed

1 file changed

+80
-40
lines changed

REFERENCE.md

Lines changed: 80 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,71 @@
22

33
Rubex is a language designed to keep you happy even when writing C extension.
44

5-
# Table of Contents
6-
<!-- MarkdownTOC autolink="true" bracket="round" depth="3"-->
5+
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-generate-toc again -->
6+
**Table of Contents**
77

8+
- [Rubex (RUBy EXtension Language)](#rubex-ruby-extension-language)
9+
- [Table of Contents](#table-of-contents)
810
- [Comments](#comments)
911
- [C data types](#c-data-types)
10-
- [Primitive data types](#primitive-data-types)
11-
- [C struct, union and enum](#c-struct-union-and-enum)
12-
- [Forward declarations](#forward-declarations)
13-
- [Pointers](#pointers)
12+
- [Primitive data types](#primitive-data-types)
13+
- [C struct, union and enum](#c-struct-union-and-enum)
14+
- [Forward declarations](#forward-declarations)
15+
- [Pointers](#pointers)
1416
- [Ruby Objects](#ruby-objects)
1517
- [Literals](#literals)
16-
- [Integer](#integer)
17-
- [Float](#float)
18-
- [Character](#character)
19-
- [String](#string)
20-
- [Ruby Literals](#ruby-literals)
21-
- [Ruby Symbol](#ruby-symbol)
22-
- [Ruby Array](#ruby-array)
23-
- [Ruby Hash](#ruby-hash)
18+
- [Integer](#integer)
19+
- [Float](#float)
20+
- [Character](#character)
21+
- [String](#string)
22+
- [Ruby Literals](#ruby-literals)
23+
- [Ruby Symbol](#ruby-symbol)
24+
- [Ruby Array](#ruby-array)
25+
- [Ruby Hash](#ruby-hash)
2426
- [C Functions and Ruby Methods](#c-functions-and-ruby-methods)
2527
- [Ruby Constants](#ruby-constants)
2628
- [The print statement](#the-print-statement)
2729
- [Loops](#loops)
28-
- [The while loop](#the-while-loop)
29-
- [The for loop](#the-for-loop)
30+
- [The while loop](#the-while-loop)
31+
- [The for loop](#the-for-loop)
3032
- [Conditionals](#conditionals)
31-
- [Important Note](#important-note)
33+
- [Important Note](#important-note)
3234
- [Interfacing C libraries with lib](#interfacing-c-libraries-with-lib)
33-
- [Basic Usage](#basic-usage)
34-
- [Supported declarations](#supported-declarations)
35-
- [Functions](#functions)
36-
- [Variables](#variables)
37-
- [Macros](#macros)
38-
- [Types](#types)
39-
- [Typedefs](#typedefs)
40-
- [Linking Libraries](#linking-libraries)
41-
- [Ready-to-use C functions](#ready-to-use-c-functions)
42-
- [Filename: "rubex/ruby"](#filename-rubexruby)
43-
- [Filename: "rubex/ruby/encoding"](#filename-rubexrubyencoding)
44-
- [Filename: "rubex/stdlib"](#filename-rubexstdlib)
35+
- [Basic Usage](#basic-usage)
36+
- [Supported declarations](#supported-declarations)
37+
- [Functions](#functions)
38+
- [Variables](#variables)
39+
- [Macros](#macros)
40+
- [Types](#types)
41+
- [Typedefs](#typedefs)
42+
- [Linking Libraries](#linking-libraries)
43+
- [Ready-to-use C functions](#ready-to-use-c-functions)
44+
- [Filename: "rubex/ruby"](#filename-rubexruby)
45+
- [Filename: "rubex/ruby/encoding"](#filename-rubexrubyencoding)
46+
- [Filename: "rubex/stdlib"](#filename-rubexstdlib)
4547
- [Exception Handling](#exception-handling)
4648
- ['Attach' Classes](#attach-classes)
47-
- [The attach keyword](#the-attach-keyword)
48-
- [The data$ variable](#the-data-variable)
49-
- [Special C functions in attach classes](#special-c-functions-in-attach-classes)
50-
- [deallocate](#deallocate)
51-
- [allocate](#allocate)
52-
- [memcount](#memcount)
53-
- [get_struct](#getstruct)
54-
- [gc_mark](#gcmark)
49+
- [The attach keyword](#the-attach-keyword)
50+
- [The data$ variable](#the-data-variable)
51+
- [Special C functions in attach classes](#special-c-functions-in-attach-classes)
52+
- [deallocate](#deallocate)
53+
- [allocate](#allocate)
54+
- [memcount](#memcount)
55+
- [get_struct](#getstruct)
56+
- [gc_mark](#gcmark)
5557
- [Typecast](#typecast)
5658
- [Alias](#alias)
5759
- [Conversions between Ruby and C data](#conversions-between-ruby-and-c-data)
60+
- [Releasing the Global Interpreter Lock](#releasing-the-global-interpreter-lock)
61+
- [Multi-file rubex programs](#multi-file-rubex-programs)
5862
- [C callbacks](#c-callbacks)
5963
- [Inline C](#inline-c)
6064
- [Handling Strings](#handling-strings)
6165
- [Differences from C](#differences-from-c)
6266
- [Differences from Ruby](#differences-from-ruby)
6367
- [Limitations](#limitations)
6468

65-
<!-- /MarkdownTOC -->
69+
<!-- markdown-toc end -->
6670

6771
# Comments
6872

@@ -681,7 +685,43 @@ end
681685

682686
# Conversions between Ruby and C data
683687

684-
Rubex will implicitly convert most primitive C types like `char`, `int` and `float` to their equivalent Ruby types and vice versa. However, types conversions for user defined types like structs and unions are not supported.
688+
Rubex will implicitly convert most primitive C types like `char`, `int` and `float`
689+
to their equivalent Ruby types and vice versa. However, types conversions for user
690+
defined types like structs and unions are not supported.
691+
692+
# Releasing the Global Interpreter Lock
693+
694+
Rubex can release the GIL a very simple `no_gil` construct. Some care must be taken when
695+
using other functions inside this block. As a rule you cannot use any Ruby objects
696+
inside a `no_gil` block. All data handling must be done _only_ by C data types.
697+
698+
Functions that are called inside the `no_gil` block cannot use any Ruby objects either, and
699+
must be tagged using the `no_gil` keyword. This will ensure that Rubex checks for Ruby
700+
objects inside these functions and raises an error if you accidentally use Ruby objects. Note
701+
that these checks are not exhaustive and the user should be careful.
702+
703+
Here's an example of using a `no_gil` block from a Ruby method:
704+
``` ruby
705+
cfunc void _work_without_gil(double n) no_gil
706+
while n > 0 do
707+
n ** 0.5 + 4
708+
n -= 1
709+
end
710+
end
711+
712+
def work_without_gil(n)
713+
double i = n
714+
no_gil
715+
_work_without_gil(i)
716+
end
717+
718+
return i
719+
end
720+
```
721+
722+
# Multi-file rubex programs
723+
724+
685725

686726
# C callbacks
687727

@@ -750,4 +790,4 @@ It should be noted that strings MUST use the double quotation syntax (`""`) and
750790
Most of the below limitations are temporary and will be taken care of in future versions:
751791

752792
* The `require` statement is currently not supported.
753-
* Multi-file Rubex programs are not yet possible.
793+
* Multi-file Rubex programs are not yet possible.

0 commit comments

Comments
 (0)