Forums » Saxon/C Help and Discussions »
Attempt to use PHP extension function with SaxonC 11.2 EE and PHP 7.4 core dumps
Added by Martin Honnen almost 3 years ago
So I felt adventurous and looked for a complete example of an extension function for XSLT 3 written in PHP code, the documentation contains some snippets, the samples as well, but I couldn't find a complete working example.
Based on the documentation I produced a short sample that seems to be compiled fine but core dumps on execution:
PHP Code is
<?php
function f1($p1, $p2) {
return $p2 * 2;
}
$saxon = new saxon\SaxonProcessor();
print('Using Saxon ' . $saxon->version());
$saxon->registerPHPFunctions('/usr/lib/php/20190902/saxon');
$transformer = $saxon->newXslt30Processor();
print('Created XSLT30Processor');
$executable = $transformer->compileFromString('<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" version="3.0" expand-text="yes" exclude-result-prefixes="#all"><xsl:output indent="yes"/><xsl:template name="xsl:initial-template"><root><xpath>{current-dateTime()}</xpath><php>{php:function("f1", ["p1", 2])}</php></root></xsl:template></xsl:stylesheet>');
print('Compiled stylesheet');
$result = $executable->callTemplateReturningValue();
print(result);
Output with PHP 7.4.25 is
Using Saxon SaxonC-EE 11.2 from SaxonicaCreated XSLT30ProcessorCompiled stylesheet
JET RUNTIME HAS DETECTED UNRECOVERABLE ERROR: runtime error
===============================
An error occurred in xTable starting with bytes `0x0e170301fc000409` of method with the following frame descriptor:
0x00007f727e722570: [0x00007f727b825c00, 0x00007f727b826650] Class: com/excelsior/jet/runtime/jni/calls/JNIMetaCall; Method: __aj__call0__Lcom_excelsior_jet_runtime_jni_defs_jmethodID_2Lcom_excelsior_jet_runtime_jni_calls_CallKind_2Lcom_excelsior_jet_runtime_jni_defs_jclass_2Lcom_excelsior_jet_runtime_jni_defs_jobject_2Lcom_excelsior_jet_runtime_jni_calls_ArgsKind_2Lcom_excelsior_aj_lang_VarArgs_2Lcom_excelsior_aj_lang_ArrayOfFlat_2(JJIJJIJJ)J
Error details:
Block containing xRegion with offset 112 was not found.
===============================
Please, contact the vendor of the application.
Core dump will be written to "/home/mh/libsaxon-EEC-11.2/samples/php/core"
Extra information about error is saved in the "jet_err_4116.txt" file.
Aborted (core dumped)
Replies (4)
Please register to reply
RE: Attempt to use PHP extension function with SaxonC 11.2 EE and PHP 7.4 core dumps - Added by Martin Honnen almost 3 years ago
I spiced the test case a bit up with print statements to see what is going on:
<?php
function f1($p1, $p2) {
print('gettype($p1): ' . gettype($p1) . "\n");
print('gettype($p2): ' . gettype($p2) . "\n");
return $p2 * 2;
}
f1('foo', 2);
$saxon = new saxon\SaxonProcessor();
print("Using Saxon " . $saxon->version() . "\n");
$saxon->registerPHPFunctions('/usr/lib/php/20190902/saxon');
$transformer = $saxon->newXslt30Processor();
print("Created XSLT 3 Processor\n");
$executable = $transformer->compileFromString('<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" version="3.0" expand-text="yes" exclude-result-prefixes="#all"><xsl:output indent="yes"/><xsl:template name="xsl:initial-template"><root><xpath>{current-dateTime()}</xpath><php>{php:function("f1", ["p1", 2])}</php></root></xsl:template></xsl:stylesheet>');
print("Compiled stylesheet\n");
print("Compilation errors: " . $transformer->getErrorMessage() . "\n");
$result = $executable->callTemplateReturningValue();
print(result);
?>
but that only shows that the PHP function is called twice correctly and that both the direct PHP call as well as the attempt to call it from XSLT and Saxon pass in the same type of arguments:
gettype($p1): string
gettype($p2): integer
Using Saxon SaxonC-EE 11.2 from Saxonica
Created XSLT 3 Processor
Compiled stylesheet
Compilation errors:
gettype($p1): string
gettype($p2): integer
JET RUNTIME HAS DETECTED UNRECOVERABLE ERROR: runtime error
===============================
An error occurred in xTable starting with bytes `0x0e170301fc000409` of method with the following frame descriptor:
0x00007f51cb53f570: [0x00007f51c8642c00, 0x00007f51c8643650] Class: com/excelsior/jet/runtime/jni/calls/JNIMetaCall; Method: __aj__call0__Lcom_excelsior_jet_runtime_jni_defs_jmethodID_2Lcom_excelsior_jet_runtime_jni_calls_CallKind_2Lcom_excelsior_jet_runtime_jni_defs_jclass_2Lcom_excelsior_jet_runtime_jni_defs_jobject_2Lcom_excelsior_jet_runtime_jni_calls_ArgsKind_2Lcom_excelsior_aj_lang_VarArgs_2Lcom_excelsior_aj_lang_ArrayOfFlat_2(JJIJJIJJ)J
Error details:
Block containing xRegion with offset 112 was not found.
===============================
Please, contact the vendor of the application.
Core dump will be written to "/home/mh/libsaxon-EEC-11.2/samples/php/core"
Extra information about error is saved in the "jet_err_4310.txt" file.
Aborted (core dumped)
So far the only PHP function I have managed to call from XSLT is one not taking any argument.
RE: Attempt to use PHP extension function with SaxonC 11.2 EE and PHP 7.4 core dumps - Added by O'Neil Delpratt almost 3 years ago
Sorry I currently still stuck away from home after a cancelled flight. But I will try to help with advice where possible.
This looks like a bug.
In the SaxonProcessor.h you can enable the DEBUG
preprocessor directive and run the php from the commandl-line which may give clues to what is happening.
Also, please try running it with gdb from the command-line. Something like the following:
gdb php
handle SIG35 noprint nostop
run filename.php
bt
Please print the output.
RE: Attempt to use PHP extension function with SaxonC 11.2 EE and PHP 7.4 core dumps - Added by Martin Honnen over 2 years ago
Here is the gdb output, I have no clue what is means:
(gdb) handle SIG35 noprint nostop
Signal Stop Print Pass to program Description
SIG35 No No Yes Real-time event 35
(gdb) run xslt30PHPFunctionTest3.php
Starting program: /usr/bin/php xslt30PHPFunctionTest3.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
gettype($p1): string
gettype($p2): integer
[New Thread 0x7fffeda80700 (LWP 4894)]
[New Thread 0x7fffed27f700 (LWP 4895)]
[Thread 0x7fffed27f700 (LWP 4895) exited]
[New Thread 0x7fffeca7e700 (LWP 4896)]
[New Thread 0x7fffec860700 (LWP 4897)]
[New Thread 0x7fffec600700 (LWP 4898)]
[New Thread 0x7fffec5e2700 (LWP 4899)]
[New Thread 0x7fffec5c4700 (LWP 4900)]
[New Thread 0x7fffec5a6700 (LWP 4901)]
[New Thread 0x7fffec588700 (LWP 4902)]
[New Thread 0x7fffec56a700 (LWP 4903)]
[New Thread 0x7fffec54c700 (LWP 4904)]
[New Thread 0x7fffec52e700 (LWP 4905)]
[New Thread 0x7fffec510700 (LWP 4906)]
[New Thread 0x7ff30bfff700 (LWP 4907)]
[New Thread 0x7ff303ff9700 (LWP 4908)]
[New Thread 0x7ff2f3fff700 (LWP 4909)]
[New Thread 0x7ff2e3fff700 (LWP 4910)]
Using Saxon SaxonC-EE 11.2 from Saxonica
[New Thread 0x7ff2d3fff700 (LWP 4911)]
Created XSLT 3 Processor
Compiled stylesheet
Compilation errors:
gettype($p1): string
gettype($p2): integer
Thread 1 "php" received signal SIGSEGV, Segmentation fault.
0x00007fffedad3c70 in ?? () from /usr/lib/libsaxoneec.so
(gdb) bt
#0 0x00007fffedad3c70 in ?? () from /usr/lib/libsaxoneec.so
#1 0x00007ffff09d0570 in ?? ()
#2 0x0000000000000000 in ?? ()
You will have time dealing with this once you manage to get a flight home as there is no urgency to this issue and as I myself will be away on a hospital "holiday"/check-up from Wednesday anyway.
RE: Attempt to use PHP extension function with SaxonC 11.2 EE and PHP 7.4 core dumps - Added by Martin Honnen over 2 years ago
I have also tried to set that DEBUG preprocessor directive and recompile/rebuild but while there is some debug output inserted I can't say it tells me anything; to make it more simple I used a simpler PHP function:
<?php
function f1($p1, $p2) {
print('gettype($p1): ' . gettype($p1) . "\n");
print('gettype($p2): ' . gettype($p2) . "\n");
return $p1 + $p2;
}
print(f1(3, 2) . "\n");
$saxon = new saxon\SaxonProcessor();
print("Using Saxon " . $saxon->version() . "\n");
$saxon->registerPHPFunctions('/usr/lib/php/20190902/saxon');
$transformer = $saxon->newXslt30Processor();
print("Created XSLT 3 Processor\n");
$executable = $transformer->compileFromString('<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" version="3.0" expand-text="yes" exclude-result-prefixes="#all"><xsl:output indent="yes"/><xsl:template name="xsl:initial-template"><root><xpath>{current-dateTime()}</xpath><php>{php:function("f1", [3, 2])}</php></root></xsl:template></xsl:stylesheet>');
print("Compiled stylesheet\n");
print("Compilation errors: " . $transformer->getErrorMessage() . "\n");
$result = $executable->callTemplateReturningValue();
print(result);
?>
The output now is
mh@DESKTOP-TMRJML3:~/libsaxon-EEC-11.2/samples/php$ php xslt30PHPFunctionTest4.php
gettype($p1): integer
gettype($p2): integer
5
SaxonProc constructor(l) called
Using Saxon SaxonC-EE 11.2 from Saxonica
New processor created, Processor: -3800432
Xslt30Processor constructor1(proc, l), Processor: -3800432
Xslt30Processor1-1(l), Processor: function libraries added
Created XSLT 3 Processor
Properties size: 0
Parameter size: 0
Compiled stylesheet
Compilation errors:
Properties size: 1
Parameter size: 0
PHPCall.call: function name: f1 Argument length: 2
Phpcall.call: Before call to _phpCall
SaxonProc constructor: jvm exists! jvmCreatedCPP=1
SaxonProc constructor(l) called
gettype($p1): integer
gettype($p2): integer
JET RUNTIME HAS DETECTED UNRECOVERABLE ERROR: runtime error
===============================
An error occurred in xTable starting with bytes `0x0e170301fc000409` of method with the following frame descriptor:
0x00007fbdb613d570: [0x00007fbdb3240c00, 0x00007fbdb3241650] Class: com/excelsior/jet/runtime/jni/calls/JNIMetaCall; Method: __aj__call0__Lcom_excelsior_jet_runtime_jni_defs_jmethodID_2Lcom_excelsior_jet_runtime_jni_calls_CallKind_2Lcom_excelsior_jet_runtime_jni_defs_jclass_2Lcom_excelsior_jet_runtime_jni_defs_jobject_2Lcom_excelsior_jet_runtime_jni_calls_ArgsKind_2Lcom_excelsior_aj_lang_VarArgs_2Lcom_excelsior_aj_lang_ArrayOfFlat_2(JJIJJIJJ)J
Error details:
Block containing xRegion with offset 112 was not found.
===============================
Please, contact the vendor of the application.
Core dump will be written to "/home/mh/libsaxon-EEC-11.2/samples/php/core"
Extra information about error is saved in the "jet_err_2943.txt" file.
Aborted (core dumped)
Please register to reply