11<?xml version =" 1.0" encoding =" utf-8" ?>
22<!-- $Revision$ -->
3- <!-- EN-Revision: 8859c8b96cd9e80652813f7bcf561432a5e9f934 Maintainer: nsfisis Status: ready -->
4-
5- <chapter xml : id =" ffi.examples" xmlns =" http://docbook.org/ns/docbook" xmlns : xlink =" http://www.w3.org/1999/xlink" >
3+ <!-- EN-Revision: 9626d496d692241a3530eac1efe2ac4fe8bdce1a Maintainer: nsfisis Status: ready -->
4+ <chapter xmlns =" http://docbook.org/ns/docbook" xmlns : xlink =" http://www.w3.org/1999/xlink" xml : id =" ffi.examples" >
65 &reftitle.examples;
76 <section xml : id =" ffi.examples-basic" >
87 <title >FFI の基本的な使い方</title >
1615 それらは、このライブラリが利用できないシステムでは動きません。
1716 </para >
1817 </note >
19- <para >
20- <example xml : id =" ffi.examples.function" >
21- <title >共有ライブラリの関数を呼ぶ</title >
22- <programlisting role =" php" >
18+ <example xml : id =" ffi.examples.function" >
19+ <title >共有ライブラリの関数を呼ぶ</title >
20+ <programlisting role =" php" >
2321<![CDATA[
2422<?php
2523// FFI オブジェクトを作成し、libc を読み込んで printf() 関数をエクスポートする
@@ -30,43 +28,41 @@ $ffi = FFI::cdef(
3028$ffi->printf("Hello %s!\n", "world");
3129?>
3230]]>
33- </programlisting >
34- &example.outputs;
35- <screen >
31+ </programlisting >
32+ &example.outputs;
33+ <screen >
3634<![CDATA[
3735Hello world!
3836]]>
39- </screen >
40- </example >
41- </para >
37+ </screen >
38+ </example >
4239 <note >
4340 <para >
4441 C の関数のうちのいくつかは、特定の呼び出し規約 (例: <literal >__fastcall</literal >、
4542 <literal >__stdcall</literal >、<literal >,__vectorcall</literal > など) を必要とすることに注意してください。
4643 </para >
4744 </note >
48- <para >
49- <example xml : id =" ffi.examples.structure" >
50- <title >関数を呼び出し、構造体を引数経由で返す</title >
51- <programlisting role =" php" >
45+ <example xml : id =" ffi.examples.structure" >
46+ <title >関数を呼び出し、構造体を引数経由で返す</title >
47+ <programlisting role =" php" >
5248<![CDATA[
5349<?php
5450// gettimeofday() のバインディングを作成する
5551$ffi = FFI::cdef("
5652 typedef unsigned int time_t;
5753 typedef unsigned int suseconds_t;
58-
54+
5955 struct timeval {
6056 time_t tv_sec;
6157 suseconds_t tv_usec;
6258 };
63-
59+
6460 struct timezone {
6561 int tz_minuteswest;
6662 int tz_dsttime;
6763 };
68-
69- int gettimeofday(struct timeval *tv, struct timezone *tz);
64+
65+ int gettimeofday(struct timeval *tv, struct timezone *tz);
7066", "libc.so.6");
7167// C のデータ構造を作成する
7268$tv = $ffi->new("struct timeval");
@@ -79,9 +75,9 @@ var_dump($tv->tv_sec);
7975var_dump($tz);
8076?>
8177]]>
82- </programlisting >
83- &example.outputs.similar;
84- <screen >
78+ </programlisting >
79+ &example.outputs.similar;
80+ <screen >
8581<![CDATA[
8682int(0)
8783int(1555946835)
@@ -92,13 +88,11 @@ object(FFI\CData:struct timezone)#3 (2) {
9288 int(0)
9389}
9490]]>
95- </screen >
96- </example >
97- </para >
98- <para >
99- <example xml : id =" ffi.examples.variable-existing" >
100- <title >既存の C の変数にアクセスする</title >
101- <programlisting role =" php" >
91+ </screen >
92+ </example >
93+ <example xml : id =" ffi.examples.variable-existing" >
94+ <title >既存の C の変数にアクセスする</title >
95+ <programlisting role =" php" >
10296<![CDATA[
10397<?php
10498// FFI オブジェクトを作成し、libc を読み込んで errno 変数をエクスポートする
@@ -109,19 +103,17 @@ $ffi = FFI::cdef(
109103var_dump($ffi->errno);
110104?>
111105]]>
112- </programlisting >
113- &example.outputs;
114- <screen >
106+ </programlisting >
107+ &example.outputs;
108+ <screen >
115109<![CDATA[
116110int(0)
117111]]>
118- </screen >
119- </example >
120- </para >
121- <para >
122- <example xml : id =" ffi.examples.variable-creating" >
123- <title >C の変数を作成して書き換える</title >
124- <programlisting role =" php" >
112+ </screen >
113+ </example >
114+ <example xml : id =" ffi.examples.variable-creating" >
115+ <title >C の変数を作成して書き換える</title >
116+ <programlisting role =" php" >
125117<![CDATA[
126118<?php
127119// 新しい C の int 変数を作成する
@@ -137,17 +129,16 @@ $x->cdata += 2;
137129var_dump($x->cdata);
138130?>
139131]]>
140- </programlisting >
141- &example.outputs;
142- <screen >
132+ </programlisting >
133+ &example.outputs;
134+ <screen >
143135<![CDATA[
144136int(0)
145137int(5)
146138int(7)
147139]]>
148- </screen >
149- </example >
150- </para >
140+ </screen >
141+ </example >
151142 <para >
152143 <example xml : id =" ffi.examples.array" >
153144 <title >C の配列を扱う</title >
@@ -182,10 +173,9 @@ int(8192)
182173 </screen >
183174 </example >
184175 </para >
185- <para >
186- <example xml : id =" ffi.examples.enum" >
187- <title >C の enum を扱う</title >
188- <programlisting role =" php" >
176+ <example xml : id =" ffi.examples.enum" >
177+ <title >C の enum を扱う</title >
178+ <programlisting role =" php" >
189179<![CDATA[
190180<?php
191181$a = FFI::cdef('typedef enum _zend_ffi_symbol_kind {
@@ -200,17 +190,16 @@ var_dump($a->ZEND_FFI_SYM_CONST);
200190var_dump($a->ZEND_FFI_SYM_VAR);
201191?>
202192]]>
203- </programlisting >
204- &example.outputs;
205- <screen >
193+ </programlisting >
194+ &example.outputs;
195+ <screen >
206196<![CDATA[
207197int(0)
208198int(2)
209199int(3)
210200]]>
211- </screen >
212- </example >
213- </para >
201+ </screen >
202+ </example >
214203 </section >
215204 <section xml : id =" ffi.examples-callback" >
216205 <title >PHP のコールバック</title >
@@ -226,9 +215,9 @@ $zend = FFI::cdef("
226215 typedef int (*zend_write_func_t)(const char *str, size_t str_length);
227216 extern zend_write_func_t zend_write;
228217");
229-
218+
230219echo "Hello World 1!\n";
231-
220+
232221$orig_zend_write = clone $zend->zend_write;
233222$zend->zend_write = function($str, $len) {
234223 global $orig_zend_write;
@@ -288,7 +277,7 @@ opcache_compile_file(__DIR__ . "/dummy.php");
288277<![CDATA[
289278#define FFI_SCOPE "DUMMY"
290279#define FFI_LIB "libc.so.6"
291-
280+
292281int printf(const char *format, ...);
293282]]>
294283 </programlisting >
@@ -322,7 +311,6 @@ $d->printf("Hello %s!\n", "world");
322311 </informalexample >
323312 </section >
324313</chapter >
325-
326314<!-- Keep this comment at the end of the file
327315Local variables:
328316mode: sgml
0 commit comments