|
2 | 2 |
|
3 | 3 | Rubex is a language designed to keep you happy even when writing C extension. |
4 | 4 |
|
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** |
7 | 7 |
|
| 8 | +- [Rubex (RUBy EXtension Language)](#rubex-ruby-extension-language) |
| 9 | +- [Table of Contents](#table-of-contents) |
8 | 10 | - [Comments](#comments) |
9 | 11 | - [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) |
14 | 16 | - [Ruby Objects](#ruby-objects) |
15 | 17 | - [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) |
24 | 26 | - [C Functions and Ruby Methods](#c-functions-and-ruby-methods) |
25 | 27 | - [Ruby Constants](#ruby-constants) |
26 | 28 | - [The print statement](#the-print-statement) |
27 | 29 | - [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) |
30 | 32 | - [Conditionals](#conditionals) |
31 | | - - [Important Note](#important-note) |
| 33 | + - [Important Note](#important-note) |
32 | 34 | - [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) |
45 | 47 | - [Exception Handling](#exception-handling) |
46 | 48 | - ['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) |
55 | 57 | - [Typecast](#typecast) |
56 | 58 | - [Alias](#alias) |
57 | 59 | - [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) |
58 | 62 | - [C callbacks](#c-callbacks) |
59 | 63 | - [Inline C](#inline-c) |
60 | 64 | - [Handling Strings](#handling-strings) |
61 | 65 | - [Differences from C](#differences-from-c) |
62 | 66 | - [Differences from Ruby](#differences-from-ruby) |
63 | 67 | - [Limitations](#limitations) |
64 | 68 |
|
65 | | -<!-- /MarkdownTOC --> |
| 69 | +<!-- markdown-toc end --> |
66 | 70 |
|
67 | 71 | # Comments |
68 | 72 |
|
|
681 | 685 |
|
682 | 686 | # Conversions between Ruby and C data |
683 | 687 |
|
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 | + |
685 | 725 |
|
686 | 726 | # C callbacks |
687 | 727 |
|
@@ -750,4 +790,4 @@ It should be noted that strings MUST use the double quotation syntax (`""`) and |
750 | 790 | Most of the below limitations are temporary and will be taken care of in future versions: |
751 | 791 |
|
752 | 792 | * 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