私はCのポインタが苦手です)
PHP拡張機能のメモリ割り当てに問題があります。floatの配列を返す関数を呼び出そうとしています。
私はCで小さなテストスクリプトを書きました、そしてそれは動作します。
基本的には、
float *fld;
...
ier = c_fstluk(fld, key, &ni, &nj, &nk);
...
// Read the array as a 2d field
for (i=0; i<ni; i++) {
for (j=0; j<nj; j++) {
// Values come transposed..
printf("%15.6E", *(fld+(ni*j)+i));
if (j<nj-1) printf(", ");
}
printf("\n");
}
(完全なコード)
malloc
ここでは何もする必要はありませんfree
。(少なくとも私はそうは思いません。このコードと関数のFortranバージョンでは、allocate()
最初にfldする必要があります。)
しかし、私のPHP拡張機能では、同じコードがセグメンテーション違反を返します。
を呼び出す前に私emalloc
とefree
(またはちょうどmalloc
と)fldを実行すると、動作しますが、大量のメモリエラーが発生します。free
c_fstluk
[Wed Jan 9 15:34:33 2013] Script: '/Users/matt/aurams/trunk/web/php/php-src/ext/fstd/fstd.php'
/Users/matt/aurams/trunk/web/php/php-src/Zend/zend_API.c(1295) : Freeing 0x10D953060 (72 bytes), script=/Users/matt/aurams/trunk/web/php/php-src/ext/fstd/fstd.php
/Users/matt/aurams/trunk/web/php/php-src/Zend/zend_hash.c(412) : Actual location (location was relayed)
Last leak repeated 779 times
[Wed Jan 9 15:34:33 2013] Script: '/Users/matt/aurams/trunk/web/php/php-src/ext/fstd/fstd.php'
/Users/matt/aurams/trunk/web/php/php-src/Zend/zend_API.c(1292) : Freeing 0x10D9531A0 (32 bytes), script=/Users/matt/aurams/trunk/web/php/php-src/ext/fstd/fstd.php
Last leak repeated 779 times
[Wed Jan 9 15:34:33 2013] Script: '/Users/matt/aurams/trunk/web/php/php-src/ext/fstd/fstd.php'
ext/fstd/fstd.c(414) : Freeing 0x10D9538D0 (72 bytes), script=/Users/matt/aurams/trunk/web/php/php-src/ext/fstd/fstd.php
/Users/matt/aurams/trunk/web/php/php-src/Zend/zend_API.c(982) : Actual location (location was relayed)
Last leak repeated 29 times
[Wed Jan 9 15:34:33 2013] Script: '/Users/matt/aurams/trunk/web/php/php-src/ext/fstd/fstd.php'
/Users/matt/aurams/trunk/web/php/php-src/Zend/zend_hash.c(450) : Freeing 0x10D954C08 (256 bytes), script=/Users/matt/aurams/trunk/web/php/php-src/ext/fstd/fstd.php
Last leak repeated 29 times
=== Total 1620 memory leaks detected ===
(コメントアウトされた完全なコードemalloc
、行〜398)
私はここで簡単な何かが欠けているに違いない。
要約すると、スタンドアロンのCプログラムでは、割り当てなしで機能します。PHP拡張機能では、スペースを割り当てると機能しますが、メモリエラーが発生します。スペースを割り当てないと、セグメンテーション違反が発生します。
ヘルプ?ありがとう!