You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here the `rb_load()` that is called is in fact the real form of the
468
-
Ruby level load.
469
-
470
-
さてここで呼んでいる`rb_load()`、これは実はRubyレベルの`load`の実体である。
467
+
The `rb_load()` which is called here is actually the "meat" of the
468
+
Ruby-level `load`.
471
469
ということは探索がもう一回必要になるわけで、同じ作業をもう一回見るなん
472
470
てやっていられない。そこでその部分は以下では省略してある。
471
+
472
+
And since the second argument (`wrap`) passed to `rb_load` in the above code is 0, the call is wrapped in 0. (*** What is this supposed to mean??? That the nesting level is 0?)
(A) In practice, the try to open using `fopen()` is to check if the
599
+
(A) The call to `fopen()` is to check if the
600
600
file can be opened. If there is no problem, it's immediately closed.
601
601
It may seem a little useless but it's an extremely simple and yet
602
602
highly portable and reliable way to do it.
603
603
604
604
(B) The file is opened once again, this time using the Ruby level
605
605
library `File.open`. The file was not opened with `File.open` from the
606
-
beginning not to raise any Ruby exception if the file cannot be
606
+
beginning so as not to raise any Ruby exception if the file cannot be
607
607
opened. Here if any exception occurred we would like to have a
608
608
loading error, but getting the errors related to `open`, for example
609
609
`Errno::ENOENT`, `Errno::EACCESS`..., would be problematic. We are in
@@ -638,14 +638,13 @@ can be open, but in fact during the loading process other functions
638
638
like for example `rb_find_file_ext()` also do checks using `open`. How
639
639
many times is `open()` called in the whole process?
640
640
641
-
と思ったら実際に数えてみるのが正しいプログラマのありかただ。システムコー
642
-
ルトレーサを使えば簡単に数えられる。そのためのツールはLinuxなら
643
-
`strace`、Solarisなら`truss`、BSD系なら`ktrace`か`truss`、
641
+
If you're wondering that, it's just a matter of having the right program available to count and see. You can easily find out using a system call tracer. On Linux, the tool to use would be `strace`; on Solaris, `truss`; or on BSD, `ktrace` or `truss`.
642
+
644
643
というように
645
644
OSによって名前がてんでバラバラなのだが、Googleで検索すればすぐ見付かる
646
-
はずだ。WindowsならたいていIDEにトレーサが付いている。
647
645
648
-
Well, as my main environment is Linux, I looked using `strace`.
646
+
If you're using Windows, probably your IDE will have a tracer built in. Well, as my main environment is Linux, I looked using `strace`.
647
+
649
648
The output is done on `stderr` so it was redirected using `2>&1`.
650
649
651
650
<pre class="screen">
@@ -694,10 +693,10 @@ part about locking anymore so it was removed.
694
693
(eval.c)
695
694
</pre>
696
695
697
-
もはやほとんど目新しいものはない。タグはイディオム通りの使いかた
696
+
By now, there is very little here which is novel. タグはイディオム通りの使いかた
698
697
しかしていないし、可視性スコープの退避・復帰も見慣れた手法だ。
699
-
残るのは`dln_load()`だけである。これはいったい何をしているのだろう。
700
-
というところで次に続く。
698
+
All that remains is `dln_load()`. What on earth is that for? For the answer, continue to the next section.
By the way, what is `gcc` actually doing here? Usually we just say is "compiles", but actually it...
729
727
730
-
# プリプロセス(`cpp`)
731
-
# C言語をアセンブラにコンパイル(`cc`)
732
-
# アセンブラを機械語にアセンブル(`as`)
733
-
# リンク(`ld`)
728
+
# Preprocesses (`cpp`)
729
+
# Compiles C into assembly (`cc`)
730
+
# Assembles the assembly language into machine code (`as`)
731
+
# Links (`ld`)
734
732
735
733
という四つの段階を通っている。このうちプリプロセス・コンパイル・アセン
736
734
ブルまではいろいろなところで説明を見掛けるのだが、なぜかリンクの段階だ
@@ -798,16 +796,10 @@ Hello, World!
798
796
799
797
h3. 真にダイナミックなリンク
800
798
801
-
さてそろそろ本題に入ろう。ダイナミックリンクの「ダイナミック」は当然
802
-
「実行時にやる」という意味だが、普通に言うところのダイナミックリンクだ
803
-
と実はコンパイル時にかなりの部分が決まっている。例えば必要な関数の名前
804
-
は決まっているだろうし、それがどこのライブラリにあるかということももう
805
-
わかっている。例えば`cos()`なら`libm`にあるから`gcc -lm`という
806
-
感じでリ
807
-
ンクするわけだ。コンパイル時にそれを指定しなかったらリンクエラーになる。
799
+
And finally we get into our main topic. The "dynamic" in "dynamic linking" naturally means it "occurs at execution time", but what people usually refer to as "dynamic linking" is pretty much decided already at compile time. For example, the names of the needed functions, and which library they can be found in, are already known. For instance, if you need `cos()`, you know it's in `libm`, so you use `gcc -lm`. If you didn't specify the correct library at compile time, you'd get a link error.
808
800
809
-
しかし拡張ライブラリの場合は違う。必要な関数の名前も、リンクするライブ
810
-
ラリの名前すらもコンパイル時には決まっていない。文字列をプログラムの実
801
+
But extension libraries are different. Neither the names of the needed functions, or the name of the library which defines them are known at compile time.
802
+
文字列をプログラムの実
811
803
行中に組み立ててロード・リンクしなければいけないのである。つまり先程の
812
804
言葉で言う「論理結合」すらも全て実行時に行わなければならない。そのため
813
805
には普通に言うところのダイナミックリンクとはまた少し違う仕組みが必要に
@@ -910,7 +902,7 @@ dln_load(file)
910
902
911
903
h3. `dln_load()`-`dlopen()`
912
904
913
-
まず`dlopen`系のAPIのコードから行こう。
905
+
First, let's start with the API code for the `dlopen` series.
0 commit comments