1
0
mirror of https://github.com/php/doc-en.git synced 2026-03-23 23:32:18 +01:00

ffi: fix XML to get remove of useless wrapping para tags

This commit is contained in:
Gina Peter Banyard
2026-01-16 05:47:33 +00:00
parent 399153faa0
commit 9626d496d6
7 changed files with 152 additions and 178 deletions

View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<chapter xml:id="ffi.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="ffi.examples">
&reftitle.examples;
<section xml:id="ffi.examples-basic">
<title>Basic FFI usage</title>
@@ -15,10 +14,9 @@
not work on systems where it is not available.
</para>
</note>
<para>
<example xml:id="ffi.examples.function">
<title>Calling a function from shared library</title>
<programlisting role="php">
<example xml:id="ffi.examples.function">
<title>Calling a function from shared library</title>
<programlisting role="php">
<![CDATA[
<?php
// create FFI object, loading libc and exporting function printf()
@@ -29,43 +27,41 @@ $ffi = FFI::cdef(
$ffi->printf("Hello %s!\n", "world");
?>
]]>
</programlisting>
&example.outputs;
<screen>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Hello world!
]]>
</screen>
</example>
</para>
</screen>
</example>
<note>
<para>
Note that some C functions need specific calling conventions, e.g. <literal>__fastcall</literal>,
<literal>__stdcall</literal> or <literal>,__vectorcall</literal>.
</para>
</note>
<para>
<example xml:id="ffi.examples.structure">
<title>Calling a function, returning a structure through an argument</title>
<programlisting role="php">
<example xml:id="ffi.examples.structure">
<title>Calling a function, returning a structure through an argument</title>
<programlisting role="php">
<![CDATA[
<?php
// create gettimeofday() binding
$ffi = FFI::cdef("
typedef unsigned int time_t;
typedef unsigned int suseconds_t;
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
struct timezone {
int tz_minuteswest;
int tz_dsttime;
};
int gettimeofday(struct timeval *tv, struct timezone *tz);
int gettimeofday(struct timeval *tv, struct timezone *tz);
", "libc.so.6");
// create C data structures
$tv = $ffi->new("struct timeval");
@@ -78,9 +74,9 @@ var_dump($tv->tv_sec);
var_dump($tz);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
int(0)
int(1555946835)
@@ -91,13 +87,11 @@ object(FFI\CData:struct timezone)#3 (2) {
int(0)
}
]]>
</screen>
</example>
</para>
<para>
<example xml:id="ffi.examples.variable-existing">
<title>Accessing existing C variables</title>
<programlisting role="php">
</screen>
</example>
<example xml:id="ffi.examples.variable-existing">
<title>Accessing existing C variables</title>
<programlisting role="php">
<![CDATA[
<?php
// create FFI object, loading libc and exporting errno variable
@@ -108,19 +102,17 @@ $ffi = FFI::cdef(
var_dump($ffi->errno);
?>
]]>
</programlisting>
&example.outputs;
<screen>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
int(0)
]]>
</screen>
</example>
</para>
<para>
<example xml:id="ffi.examples.variable-creating">
<title>Creating and Modifying C variables</title>
<programlisting role="php">
</screen>
</example>
<example xml:id="ffi.examples.variable-creating">
<title>Creating and Modifying C variables</title>
<programlisting role="php">
<![CDATA[
<?php
// create a new C int variable
@@ -136,17 +128,16 @@ $x->cdata += 2;
var_dump($x->cdata);
?>
]]>
</programlisting>
&example.outputs;
<screen>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
int(0)
int(5)
int(7)
]]>
</screen>
</example>
</para>
</screen>
</example>
<para>
<example xml:id="ffi.examples.array">
<title>Working with C arrays</title>
@@ -181,10 +172,9 @@ int(8192)
</screen>
</example>
</para>
<para>
<example xml:id="ffi.examples.enum">
<title>Working with C enums</title>
<programlisting role="php">
<example xml:id="ffi.examples.enum">
<title>Working with C enums</title>
<programlisting role="php">
<![CDATA[
<?php
$a = FFI::cdef('typedef enum _zend_ffi_symbol_kind {
@@ -199,17 +189,16 @@ var_dump($a->ZEND_FFI_SYM_CONST);
var_dump($a->ZEND_FFI_SYM_VAR);
?>
]]>
</programlisting>
&example.outputs;
<screen>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
int(0)
int(2)
int(3)
]]>
</screen>
</example>
</para>
</screen>
</example>
</section>
<section xml:id="ffi.examples-callback">
<title>PHP Callbacks</title>
@@ -225,9 +214,9 @@ $zend = FFI::cdef("
typedef int (*zend_write_func_t)(const char *str, size_t str_length);
extern zend_write_func_t zend_write;
");
echo "Hello World 1!\n";
$orig_zend_write = clone $zend->zend_write;
$zend->zend_write = function($str, $len) {
global $orig_zend_write;
@@ -287,7 +276,7 @@ opcache_compile_file(__DIR__ . "/dummy.php");
<![CDATA[
#define FFI_SCOPE "DUMMY"
#define FFI_LIB "libc.so.6"
int printf(const char *format, ...);
]]>
</programlisting>
@@ -321,7 +310,6 @@ $d->printf("Hello %s!\n", "world");
</informalexample>
</section>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="ffi.cast" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="ffi.cast">
<refnamediv>
<refname>FFI::cast</refname>
<refpurpose>Performs a C type cast</refpurpose>
@@ -55,26 +55,24 @@
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.3.0</entry>
<entry>
Calling <methodname>FFI::cast</methodname> statically is now deprecated.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.3.0</entry>
<entry>
Calling <methodname>FFI::cast</methodname> statically is now deprecated.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
</refentry>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="ffi.load" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="ffi.load">
<refnamediv>
<refname>FFI::load</refname>
<refpurpose>Loads C declarations from a C header file</refpurpose>
@@ -83,11 +83,9 @@
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>FFI::scope</methodname></member>
</simplelist>
</para>
<simplelist>
<member><methodname>FFI::scope</methodname></member>
</simplelist>
</refsect1>
</refentry>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="ffi.new" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="ffi.new">
<refnamediv>
<refname>FFI::new</refname>
<refpurpose>Creates a C data structure</refpurpose>
@@ -48,7 +48,7 @@
<term><parameter>persistent</parameter></term>
<listitem>
<para>
Whether to allocate the C data structure permanently on the system heap (using
Whether to allocate the C data structure permanently on the system heap (using
<function>malloc</function>), or on the PHP request heap (using <function>emalloc</function>).
</para>
</listitem>
@@ -66,26 +66,24 @@
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.3.0</entry>
<entry>
Calling <methodname>FFI::new</methodname> statically is now deprecated.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.3.0</entry>
<entry>
Calling <methodname>FFI::new</methodname> statically is now deprecated.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
</refentry>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="ffi.scope" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="ffi.scope">
<refnamediv>
<refname>FFI::scope</refname>
<refpurpose>Instantiates an FFI object with C declarations parsed during preloading</refpurpose>
@@ -44,11 +44,9 @@
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>FFI::load</methodname></member>
</simplelist>
</para>
<simplelist>
<member><methodname>FFI::load</methodname></member>
</simplelist>
</refsect1>
</refentry>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="ffi.type" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="ffi.type">
<refnamediv>
<refname>FFI::type</refname>
<refpurpose>Creates an FFI\CType object from a C declaration</refpurpose>
@@ -43,26 +43,24 @@
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.3.0</entry>
<entry>
Calling <methodname>FFI::type</methodname> statically is now deprecated.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.3.0</entry>
<entry>
Calling <methodname>FFI::type</methodname> statically is now deprecated.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
</refentry>

View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<chapter xml:id="ffi.setup" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="ffi.setup">
&reftitle.setup;
<section xml:id="ffi.requirements">
@@ -36,13 +35,13 @@
<entry><link linkend="ini.ffi.enable">ffi.enable</link></entry>
<entry>"preload"</entry>
<entry><constant>INI_SYSTEM</constant></entry>
<entry></entry>
<entry/>
</row>
<row>
<entry><link linkend="ini.ffi.preload">ffi.preload</link></entry>
<entry>""</entry>
<entry><constant>INI_SYSTEM</constant></entry>
<entry></entry>
<entry/>
</row>
</tbody>
</tgroup>
@@ -52,47 +51,44 @@
&ini.descriptions.title;
<para>
<variablelist>
<varlistentry xml:id="ini.ffi.enable">
<term>
<parameter>ffi.enable</parameter>
<type>string</type>
</term>
<listitem>
<para>
Allows enabling (<literal>"true"</literal>) or disabling
(<literal>"false"</literal>) FFI API usage, or restricting it only to
the CLI SAPI and preloaded files (<literal>"preload"</literal>).
</para>
<para>
The FFI API restrictions only affect the <classname>FFI</classname> class,
but not overloaded functions of <classname>FFI\CData</classname> objects.
This means that it is possible to create some <classname>FFI\CData</classname>
objects in preloaded files, and then to use these directly in PHP scripts.
</para>
</listitem>
</varlistentry>
<varlistentry xml:id="ini.ffi.preload">
<term>
<parameter>ffi.preload</parameter>
<type>string</type>
</term>
<listitem>
<para>
Allows preloading of FFI bindings during startup, which is not possible with <methodname>FFI::load</methodname>
if <link linkend="ini.opcache.preload-user">opcache.preload_user</link> is set.
This directive accepts a <constant>DIRECTORY_SEPARATOR</constant> delimited list of filenames.
The preloaded bindings can be accessed by calling <methodname>FFI::scope</methodname>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<variablelist>
<varlistentry xml:id="ini.ffi.enable">
<term>
<parameter>ffi.enable</parameter>
<type>string</type>
</term>
<listitem>
<para>
Allows enabling (<literal>"true"</literal>) or disabling
(<literal>"false"</literal>) FFI API usage, or restricting it only to
the CLI SAPI and preloaded files (<literal>"preload"</literal>).
</para>
<para>
The FFI API restrictions only affect the <classname>FFI</classname> class,
but not overloaded functions of <classname>FFI\CData</classname> objects.
This means that it is possible to create some <classname>FFI\CData</classname>
objects in preloaded files, and then to use these directly in PHP scripts.
</para>
</listitem>
</varlistentry>
<varlistentry xml:id="ini.ffi.preload">
<term>
<parameter>ffi.preload</parameter>
<type>string</type>
</term>
<listitem>
<para>
Allows preloading of FFI bindings during startup, which is not possible with <methodname>FFI::load</methodname>
if <link linkend="ini.opcache.preload-user">opcache.preload_user</link> is set.
This directive accepts a <constant>DIRECTORY_SEPARATOR</constant> delimited list of filenames.
The preloaded bindings can be accessed by calling <methodname>FFI::scope</methodname>.
</para>
</listitem>
</varlistentry>
</variablelist>
</section>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml