Skip to content

Commit a240f9e

Browse files
author
Jean-Denis Vauget
committed
chapitre 3 en progression :)
git-svn-id: http://rhg.rubyforge.org/svn@62 2ba632a7-620d-0410-bd84-d74392fff1da
1 parent f4b2790 commit a240f9e

File tree

1 file changed

+71
-63
lines changed

1 file changed

+71
-63
lines changed

fr/chapitre03.txt

Lines changed: 71 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,9 @@ la taille sera augmentée.
486486

487487
h3. `st_insert()`
488488

489-
`st_insert()` is nothing more than a combination of `st_add_direct()` and
490-
`st_lookup()`, so if you understand those two, this will be easy.
489+
`st_insert()` n'est rien de plus qu'une combinaison de `st_add_direct()` et
490+
`st_lookup()`, aussi si vous comprenez ces deux fonctions, tout sera on ne
491+
peut plus clair.
491492

492493
▼ `st_insert()`
493494
<pre class="longlist">
@@ -516,25 +517,25 @@ h3. `st_insert()`
516517
(st.c)
517518
</pre>
518519

519-
It checks if the element is already registered in the table. Only when it is
520-
not registered will it be added. If there is a insertion, return 0. If there is
521-
no insertion, return a 1.
520+
La fonction vérifie si l'élément est déjà présent dans la table. Il ne sera
521+
ajouté que si ce n'est pas le cas. S'il y a effectivement insertion, la valeur
522+
de retour sera 0 ; sinon, 1.
522523

523-
h2. `ID` and Symbols
524+
h2. `ID` et Symboles
524525

525-
I've already discussed what an `ID` is. It is a correspondence between an
526-
arbitrary string of characters and a value. It is used to declare various
527-
names. The actual data type is `unsigned int`.
526+
J'ai déjà expliqué ce qu'était un `ID`. C'est une correspondance entre une
527+
chaîne de caractères arbitraire et une valeur. On l'utilise pour déclarer
528+
différents noms, et le type de données sous-jacent est `unsigned int`.
528529

529-
h3. From `char*` to `ID`
530+
h3. De `char*` à `ID`
530531

531-
The conversion from string to `ID` is executed by `rb_intern()`. This function
532-
is rather long, so let's omit the middle.
532+
La conversion d'une chaîne en `ID` est réalisée par `rb_intern()`. Cette
533+
fonction est plutôt longue, aussi va t-on en omettre la partie centrale.
533534

534-
▼ `rb_intern()` (simplified)
535+
▼ `rb_intern()` (simplifiée)
535536
<pre class="longlist">
536-
5451 static st_table *sym_tbl; /* char* to ID */
537-
5452 static st_table *sym_rev_tbl; /* ID to char* */
537+
5451 static st_table *sym_tbl; /* char* en ID */
538+
5452 static st_table *sym_rev_tbl; /* ID en char* */
538539

539540
5469 ID
540541
5470 rb_intern(name)
@@ -544,14 +545,13 @@ is rather long, so let's omit the middle.
544545
5474 ID id;
545546
5475 int last;
546547
5476
547-
/* If for a name, there is a corresponding ID that is already
548-
registered, then return that ID */
548+
/* S'il y a déjà un ID correspondant au nom, le retourner */
549549
5477 if (st_lookup(sym_tbl, name, &id))
550550
5478 return id;
551551

552-
/* omitted ... create a new ID */
552+
/* partie omise ... crée un nouvel ID */
553553

554-
/* register the name and ID relation */
554+
/* enregistre le nom et l'ID correspondant */
555555
5538 id_regist:
556556
5539 name = strdup(name);
557557
5540 st_add_direct(sym_tbl, name, id);
@@ -562,24 +562,27 @@ is rather long, so let's omit the middle.
562562
(parse.y)
563563
</pre>
564564

565-
The string and `ID` correspondence relationship can be accomplished by using the
566-
`st_table`. There probably isn't any especially difficult part here.
565+
La relation de correspondance entre la chaîne et l'`ID` peut être sauvegardée
566+
dans une table `st_table`. Il n'y a _a priori_ aucune difficulté particulière
567+
ici.
567568

568-
What is the omitted section doing? It is treating global variable names and
569-
instance variables names as special and flagging them. This is because in the
570-
parser, it is necessary to know the variable's classification from the `ID`.
571-
However, the fundamental part of `ID` is unrelated to this, so I won't explain
572-
it here.
569+
Que fait la section cachée ? Elle traite les noms de variables de globales et
570+
de variables d'instances d'une façon spéciale et les marque d'un drapeau. La
571+
raison en est que, au sein du parseur, il est nécessaire de connaître à partir
572+
de l'`ID` la classification de la variable traitée. Cependant, la principale
573+
partie de `ID` n'est pas liée à tout cela, aussi ne vais-je pas l'expliquer
574+
ici.
573575

574-
h3. From `ID` to `char*`
576+
h3. De `ID` vers `char*`
575577

576-
The reverse of `rb_intern()` is `rb_id2name()`, which takes an `ID` and
577-
generates a `char*`. You probably know this, but the 2 in `id2name` is "to".
578-
"To" and "two" have the same pronounciation, so "2" is used for "to". This
579-
syntax is often seen.
578+
Le méchanisme inverse de `rb_intern()` est assuré par `rb_id2name()`, une
579+
fonction qui prend en argument un `ID` et génère un `char*`. Vous le savez
580+
certainemetn déjà, mais le 2 dans `id2name` signifie "_to_" (NDT(Note du traducteur) : vers).
581+
"_To_" et "_two_" ayant la même prononciation, le chiffre est utilisé comme
582+
raccourci, une syntaxe très courante.
580583

581-
This function also sets the `ID` classification flags so it is long. Let me
582-
simplify it.
584+
Cette fonction initialise également le drapeau de classification `ID`, elle
585+
est donc relativement longue. Je vais la simplifier.
583586

584587
▼ `rb_id2name()` (simplified)
585588
<pre class="longlist">
@@ -595,25 +598,27 @@ rb_id2name(id)
595598
}
596599
</pre>
597600

598-
Maybe it seems that it is a little over-simplified, but in reality if we remove
599-
the details it really becomes this simple.
601+
Bon, elle semble peut-être simplifiée à l'extrême, mais il est vrai que si
602+
on en supprime les raffinements, elle est vraiment aussi simple.
600603

601-
The point I want to emphasize is that the found `name` is not copied. The
602-
`ruby` API does not require (or rather, it forbids) the `free()`-ing of the
603-
return value. Also, when parameters are passed, it always
604-
copies them. In other words, the creation and release is
605-
completed by one side, either by the user or by `ruby`.
604+
Le point sur lequel je veux insister est que le `name` trouvé n'est pas copié.
605+
L'API de `ruby` ne requière pas (en fait, il interdit même) la libération
606+
(NDT(Note du traducteur) : `free`) de la valeur de retour. Par ailleurs, quand
607+
les paramètres sont passés, ils sont toujours copiés. En d'autres termes, la
608+
création et la libération se fait globalement, d'un seul coté, soit celui de
609+
l'utilisateur, soit de `ruby`.
606610

607-
So then, when creation and release cannot be accomplished (when passed it is
608-
not returned) on a value, then a Ruby object is used. I have not yet discussed
609-
it, but a Ruby object is automatically released when it is no longer needed,
610-
even if we are not taking care of the object.
611+
Donc, par la suite, quand la création et la libération d'une valeur ne peuvent
612+
être accomplies (quand, une fois la valeur passée, rien n'est retourné), c'est
613+
un objet Ruby qui est utilisé. Je n'ai pas encore abordé ça, mais un objet Ruby
614+
est libérer automatiquement une fois qu'il est devenu inutile, même si on ne
615+
fait rien de spécial pour le gérer.
611616

612-
h3. Converting `VALUE` and `ID`
617+
h3. Conversion de `VALUE` et `ID`
613618

614-
`ID` is shown as an instance of the `Symbol` class at the Ruby level.
615-
And it can be obtained like so: `"string".intern`. The implementation of
616-
`String#intern` is `rb_str_intern()`.
619+
`ID` est exposé comme une instance de la classe `Symbol` au niveau de Ruby.
620+
On peut d'ailleurs l'obtenir comme ceci : `"string".intern`. L'implémentation
621+
de `String#intern` est `rb_str_intern()`.
617622

618623
▼ `rb_str_intern()`
619624
<pre class="longlist">
@@ -635,16 +640,18 @@ And it can be obtained like so: `"string".intern`. The implementation of
635640
(string.c)
636641
</pre>
637642

638-
This function is quite reasonable as a `ruby` class library code example.
639-
Please pay attention to the part where `RSTRING()` is used and casted, and
640-
where the data structure's member is accessed.
643+
Cette fonction est somme toute très raisonnable comme exemple de code d'une
644+
classe d'une librairie de `ruby`. Concentrez s'il-vous-plaît votre attention
645+
sur à la partie où `RSTRING()` est utilisé et casté, et dans laquelle on accède
646+
au membre de la structure de données.
641647

642-
Let's read the code. First, `rb_raise()` is merely error handling so we ignore
643-
it for now. The `rb_intern()` we previously examined is here, and also ID2SYM
644-
is here. `ID2SYM()` is a macro that converts `ID` to `Symbol`.
648+
Lisons le code. Tout d'abord, `rb_raise()`, qui est simplement là pour gérer
649+
les erreurs ; ignorons-le. Le `rb_intern()` que nous avons examiné plus tôt
650+
est présent, et également ID2SYM. Pour rappel, `ID2SYM()` est une macro qui
651+
convertit un `ID` en `Symbol`.
645652

646-
And the reverse operation is accomplished using `Symbol#to_s` and such.
647-
The implementation is in `sym_to_s`.
653+
L'opération inverse est accomplie par `Symbol#to_s` ; son implémentation est
654+
`sym_to_s`.
648655

649656
▼ `sym_to_s()`
650657
<pre class="longlist">
@@ -658,11 +665,12 @@ The implementation is in `sym_to_s`.
658665
(object.c)
659666
</pre>
660667

661-
`SYM2ID()` is the macro that converts `Symbol` (`VALUE`) to an `ID`.
668+
`SYM2ID()` est la macro qui convertit un `Symbol` (`VALUE`) en `ID`.
662669

663-
It looks like the function is not doing anything unreasonable. However, it
664-
is probably necessary to pay attention to the area around the memory handling.
665-
`rb_id2name()` returns a `char*` that must not be `free()`. `rb_str_new2()`
666-
copies the parameter's `char*` and uses the copy (and does not change the
667-
parameter). In this way the policy is consistent, which allows the line to be
668-
written just by chaining the functions.
670+
Il semble bien que la fonction ne fait rien de déraisonnable. Toutefois, il
671+
n'est pas inutile de faire attention à la partie autour de la gestion mémoire.
672+
`rb_id2name()` retourne un `char*` qui ne doit pas être libéré par `free()`.
673+
`rb_str_new2()` copie le `char*` du paramètre et utilise la copie (si bien
674+
que la paramètre original n'est pas modifié). De cette façon, notre politique
675+
de gestion mémoire reste cohérente, ce qui nous autorise à écrire une seule
676+
ligne consistant en le chaînage des fonctions.

0 commit comments

Comments
 (0)