thread safe php make ffi callback error(ext ffi)
オープン
まだ誰も着手していません。
Bug
Extension: ffi
Status: Needs Triage
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.2k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 96
説明
Description
<?php
$ffi = FFI::cdef("
typedef void (*log_message_callback_t)(int level, const char* msg);
int test_start_str(const char* oldP, int id, log_message_callback_t log_callback);
", "test_lib.dll");
$log_callback = function($level, $msg) {
echo "Log (level $level): " . $msg . "\n";
};
$result = $ffi->test_start_str("example_parameter", 42, $log_callback);
echo "Result: $result\n";
this is the c code
#include <stdio.h>
#include <pthread.h>
#ifdef _WIN32
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT
#endif
typedef void (*log_message_callback_t)(int level, const char* msg);
typedef struct {
const char* oldP;
log_message_callback_t log_callback;
} thread_data_t;
void* thread_function(void* arg) {
thread_data_t* data = (thread_data_t*) arg;
const char* oldP = data->oldP;
log_message_callback_t log_callback = data->log_callback;
char message[256];
snprintf(message, sizeof(message), "Thread running with parameter %s", oldP);
if (log_callback) {
log_callback(1, message);
} else {
fprintf(stderr, "Log callback not set in thread\n");
}
return NULL;
}
DLL_EXPORT int test_start_str(const char* oldP, int id, log_message_callback_t log_callback) {
thread_data_t* data = (thread_data_t*) malloc(sizeof(thread_data_t));
if (!data) {
return -1;
}
data->oldP = oldP;
data->log_callback = log_callback;
pthread_t thread;
int result = pthread_create(&thread, NULL, thread_function, (void*) data);
if (result != 0) {
free(data);
return -1;
}
pthread_detach(thread);
return 0;
}
PHP Version
php 8.3.7
Operating System
windows10
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、Windows 10 上の PHP 8.3.7 で、提供された PHP FFI および C pthread の例を再現し、正確な callback エラーとその発生時点を記録します。スレッド化された callback の動作を同期呼び出しパスと比較します。失敗を再現でき、期待されるスレッドセーフ性の動作または必要な修正が明確に確立されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, php
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100