Skip to content

Commit 0f4a834

Browse files
committed
wip
1 parent ba33bc1 commit 0f4a834

File tree

2 files changed

+45
-36
lines changed

2 files changed

+45
-36
lines changed

reference/ffi/book.xml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<!-- $Revision$ -->
33
<!-- EN-Revision: 46a9cdd2dbef4ec89bf65fad9930e2feb78bbb98 Maintainer: nsfisis Status: working -->
44

5-
!!!
65
<book xml:id="book.ffi" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
76
<?phpdoc extension-membership="bundled" ?>
87
<title>外部関数インターフェース</title>
@@ -11,26 +10,26 @@
1110
<preface xml:id="intro.ffi">
1211
&reftitle.intro;
1312
<para>
14-
This extension allows the loading of shared libraries (<filename>.DLL</filename> or
15-
<filename>.so</filename>), calling of C functions and accessing of C data structures
16-
in pure PHP, without having to have deep knowledge of the Zend extension API, and
17-
without having to learn a third “intermediate” language.
18-
The public API is implemented as a single class <classname>FFI</classname> with
19-
several static methods (some of them may be called dynamically), and overloaded object
20-
methods, which perform the actual interaction with C data.
13+
この拡張は、Zend 拡張 API の深い知識が無くとも、あるいは第三の中間言語を学ぶことをせずとも、
14+
純粋な PHP で共有ライブラリ (<filename>.DLL</filename> または <filename>.so</filename>)
15+
を読み込んだり、C の関数を呼び出したり、C のデータ構造にアクセスしたりすることを
16+
可能とします。
17+
公開 API は単一のクラス <classname>FFI</classname> として実装されています。
18+
このクラスの静的メソッド (そのうちのいくつかは非静的メソッドとしても呼び出せます) や
19+
オーバーロードされたオブジェクトメソッドが、実際の C のデータとのやり取りを行います。
2120
</para>
2221
<caution>
2322
<para>
24-
FFI is dangerous, since it allows to interface with the system on a very low level.
25-
The FFI extension should only be used by developers having a working knowledge of C
26-
and the used C APIs. To minimize the risk, the FFI API usage may be restricted
27-
with the <link linkend="ini.ffi.enable">ffi.enable</link> &php.ini; directive.
23+
FFI は、システムと低レベルでやり取りできるため危険です。
24+
FFI 拡張は、C 言語と使われる C の API についての実用的な知識を持つ開発者のみによって
25+
用いられるべきです。リスクを最小化するため、FFI API の使用は
26+
<link linkend="ini.ffi.enable">ffi.enable</link> &php.ini; ディレクティブによって制限できます。
2827
</para>
2928
</caution>
3029
<note>
3130
<para>
32-
The FFI extension does not render the classic PHP extension API obsolete; it is merely
33-
provided for ad-hoc interfacing with C functions and data structures.
31+
FFI 拡張は、古くからある PHP 拡張の API を廃止しようとしているわけではありません。
32+
これは C の関数やデータ構造へのアドホックなインターフェースを提供するにすぎないのです。
3433
</para>
3534
</note>
3635
<tip>

reference/ffi/examples.xml

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@
66
<chapter xml:id="ffi.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
77
&reftitle.examples;
88
<section xml:id="ffi.examples-basic">
9-
<title>Basic FFI usage</title>
9+
<title>FFI の基本的な使い方</title>
1010
<para>
11-
Before diving into the details of the FFI API, lets take a look at a few examples
12-
demonstrating the simplicity of the FFI API usage for regular tasks.
11+
FFI API の詳細に深く立ち入る前に、よくあるタスクに対する FFI API の使い方が
12+
どれほど簡単かを示す例をいくつか見てみましょう。
1313
</para>
1414
<note>
1515
<para>
16-
Some of these examples require <filename>libc.so.6</filename> and as such will
17-
not work on systems where it is not available.
16+
これらの例の中には、<filename>libc.so.6</filename> を必要とするものがあります。
17+
それらは、このライブラリが利用できないシステムでは動きません。
1818
</para>
1919
</note>
2020
<para>
2121
<example xml:id="ffi.examples.function">
22-
<title>Calling a function from shared library</title>
22+
<title>共有ライブラリの関数を呼ぶ</title>
2323
<programlisting role="php">
2424
<![CDATA[
2525
<?php
26-
// create FFI object, loading libc and exporting function printf()
26+
// FFI オブジェクトを作成し、libc を読み込んで printf() 関数をエクスポートする
2727
$ffi = FFI::cdef(
28-
"int printf(const char *format, ...);", // this is a regular C declaration
28+
"int printf(const char *format, ...);", // ここは通常の C の宣言
2929
"libc.so.6");
30-
// call C's printf()
30+
// C の printf() を呼ぶ
3131
$ffi->printf("Hello %s!\n", "world");
3232
?>
3333
]]>
@@ -42,17 +42,17 @@ Hello world!
4242
</para>
4343
<note>
4444
<para>
45-
Note that some C functions need specific calling conventions, e.g. <literal>__fastcall</literal>,
46-
<literal>__stdcall</literal> or <literal>,__vectorcall</literal>.
45+
C の関数のうちのいくつかは、特定の呼び出し規約 (例: <literal>__fastcall</literal>
46+
<literal>__stdcall</literal><literal>,__vectorcall</literal> など) を必要とすることに注意してください。
4747
</para>
4848
</note>
4949
<para>
5050
<example xml:id="ffi.examples.structure">
51-
<title>Calling a function, returning a structure through an argument</title>
51+
<title>関数を呼び出し、構造体を引数経由で返す</title>
5252
<programlisting role="php">
5353
<![CDATA[
5454
<?php
55-
// create gettimeofday() binding
55+
// gettimeofday() のバインディングを作成する
5656
$ffi = FFI::cdef("
5757
typedef unsigned int time_t;
5858
typedef unsigned int suseconds_t;
@@ -69,14 +69,14 @@ $ffi = FFI::cdef("
6969
7070
int gettimeofday(struct timeval *tv, struct timezone *tz);
7171
", "libc.so.6");
72-
// create C data structures
72+
// C のデータ構造を作成する
7373
$tv = $ffi->new("struct timeval");
7474
$tz = $ffi->new("struct timezone");
75-
// call C's gettimeofday()
75+
// C の gettimeofday() を呼ぶ
7676
var_dump($ffi->gettimeofday(FFI::addr($tv), FFI::addr($tz)));
77-
// access field of C data structure
77+
// C のデータ構造のフィールドにアクセスする
7878
var_dump($tv->tv_sec);
79-
// print the whole C data structure
79+
// C のデータ構造全体を出力する
8080
var_dump($tz);
8181
?>
8282
]]>
@@ -98,7 +98,8 @@ object(FFI\CData:struct timezone)#3 (2) {
9898
</para>
9999
<para>
100100
<example xml:id="ffi.examples.variable-existing">
101-
<title>Accessing existing C variables</title>
101+
<title>既存の C の変数にアクセスする</title>
102+
!!!
102103
<programlisting role="php">
103104
<![CDATA[
104105
<?php
@@ -121,7 +122,8 @@ int(0)
121122
</para>
122123
<para>
123124
<example xml:id="ffi.examples.variable-creating">
124-
<title>Creating and Modifying C variables</title>
125+
<title>C の変数を作成して書き換える</title>
126+
!!!
125127
<programlisting role="php">
126128
<![CDATA[
127129
<?php
@@ -151,7 +153,8 @@ int(7)
151153
</para>
152154
<para>
153155
<example xml:id="ffi.examples.array">
154-
<title>Working with C arrays</title>
156+
<title>C の配列を扱う</title>
157+
!!!
155158
<programlisting role="php">
156159
<![CDATA[
157160
<?php
@@ -185,7 +188,8 @@ int(8192)
185188
</para>
186189
<para>
187190
<example xml:id="ffi.examples.enum">
188-
<title>Working with C enums</title>
191+
<title>C の enum を扱う</title>
192+
!!!
189193
<programlisting role="php">
190194
<![CDATA[
191195
<?php
@@ -214,12 +218,15 @@ int(3)
214218
</para>
215219
</section>
216220
<section xml:id="ffi.examples-callback">
217-
<title>PHP Callbacks</title>
221+
<title>PHP のコールバック</title>
222+
!!!
218223
<para>
219224
It is possible to assign a PHP closure to a native variable of function pointer type
220225
or to pass it as a function argument:
221226
<example>
227+
!!!
222228
<title>Assigning a PHP <classname>Closure</classname> to a C function pointer</title>
229+
!!!
223230
<programlisting role="php">
224231
<![CDATA[
225232
<?php
@@ -255,17 +262,20 @@ Hello World 3!
255262
]]>
256263
</screen>
257264
</example>
265+
!!!
258266
Although this works, this functionality is not supported on all libffi platforms, is not efficient
259267
and leaks resources by the end of request.
260268
<tip>
261269
<simpara>
270+
!!!
262271
It is therefore recommended to minimize the usage of PHP callbacks.
263272
</simpara>
264273
</tip>
265274
</para>
266275
</section>
267276

268277
<section xml:id="ffi.examples-complete">
278+
!!!
269279
<title>A Complete PHP/FFI/preloading Example</title>
270280
<informalexample>
271281
<simpara><filename>php.ini</filename></simpara>

0 commit comments

Comments
 (0)