在Delphi XE中Apache方法apr_pool_create_ex的正确使用是什么?

发布于 2024-10-26 20:43:12 字数 1375 浏览 1 评论 0原文

在Delphi XE中Apache方法apr_pool_create_ex的正确使用是什么?

我之前创建过 Apache 模块,但都是处理程序。现在我正在开发一个服务提供商。框架模块已创建,并且 Apache 正在调用我的 child_init 回调方法。在 child_init 方法中,我成功调用 ap_pool_create_ex* (返回 APR_SUCCESS),但是在离开 child_it 调用之后,我在 (httpd.exe) 生成第三个或第四个工作线程期间收到访问冲突(第三个显示在事件中)日志)。

procedure provider_child_init(pchild: Papr_pool_t; s: Pserver_rec); cdecl;
var
  rv  : apr_status_t;
  mypool : Papr_pool_t;
begin
  rv := -1;
  rv := apr_pool_create_ex(@mypool,pchild,nil,nil);
end;

AV消息是:

“项目C:\Apache2.2\bin\http.exe 连续筹集太多 异常:'访问冲突 0x00000000:读取地址 0x00000000'。进程已停止。使用步骤 或运行以继续”

事件日志:

…
Thread Start: Thread ID: 5652. Process httpd.exe (4212)
Thread Start: Thread ID: 5132. Process httpd.exe (4212)
Thread Start: Thread ID: 5988. Process httpd.exe (4212) 

注意:AV 发生在线程 ID 5988 和 4212 中,是父 httpd.exe 进程。

  • Windows“libapr-1.dll”不包含“apr_pool_create”,这就是我使用“_ex”版本的原因。知道为什么 apr_pool_create 丢失吗?我看到 apr_pool_create 被用在其他成功的模块中,尽管它们都是用“C”写的。

操作系统:Windows 7 Enterprise 64 位

阿帕奇:2.2.17.0

IDE:Delphi XE

What is proper use of Apache method apr_pool_create_ex in Delphi XE?

I’ve created Apache modules before, but all were Handlers. Now I’m working on developing a Service provider. A skeleton module has been created and my child_init call back method is being called by Apache. In the child_init method I call ap_pool_create_ex* successfully (returns APR_SUCCESS), but after leaving the child_it call, I receive an access violation either during the (httpd.exe) spawning of the third or the fourth worker thread (third is showing in the event log).

procedure provider_child_init(pchild: Papr_pool_t; s: Pserver_rec); cdecl;
var
  rv  : apr_status_t;
  mypool : Papr_pool_t;
begin
  rv := -1;
  rv := apr_pool_create_ex(@mypool,pchild,nil,nil);
end;

The AV message is:

“Project C:\Apache2.2\bin\http.exe
raised too many consecutive
exceptions: ‘access violation at
0x00000000: read of address
0x00000000’. Process Stopped. Use Step
or Run to continues”

Event Log:

…
Thread Start: Thread ID: 5652. Process httpd.exe (4212)
Thread Start: Thread ID: 5132. Process httpd.exe (4212)
Thread Start: Thread ID: 5988. Process httpd.exe (4212) 

NOTE: The AV occurs in Thread ID 5988 and 4212 is the Parent httpd.exe process.

  • The windows “libapr-1.dll” does not include “apr_pool_create”, that is why I’m using the “_ex” version. Any idea why apr_pool_create is missing? I see apr_pool_create being used in other successful modules although they are written in ‘C’.

OS: Windows 7 Enterprise 64-bit

Apache: 2.2.17.0

IDE: Delphi XE

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手心的海 2024-11-02 20:43:12

您对函数的翻译正确吗? Delphi XE Version Insight(Subversion 插件)声明如下:

type
  PAprPool = ^TAprPool;
  TAprPool = THandle;
  PAprAllocator = ^TAprAllocator;
  TAprAllocator = THandle;
  TAprAbortFunc = function(retcode: Integer): Integer; stdcall;

var
  apr_pool_create_ex: function(out newpool: PAprPool; parent: PAprPool; abort_fn: TAprAbortFunc;
    allocator: PAprAllocator): TAprStatus; stdcall;

另请检查您的 provider_child_init< /code> 回调实际上应该声明为 cdecl 而不是 stdcall

另外,由于出现空指针访问冲突,还有一些想法。根据apr源代码评论

  • 如果(如您的如果您向它传递一个 nil 分配器,则将使用父池的分配器。我假设如果父池为零,则分配器一定不能为零。
  • 如果池无法分配内存,abort_fn将会被回调。你将其传递为零;也许池试图调用它是因为它无法分配内存?
  • 我不认为你可以从不同的线程访问同一个池。您可能必须为每个线程创建一个单独的池。

Is your translation of the function correct? Delphi XE Version Insight (Subversion plugin) declares it as follows:

type
  PAprPool = ^TAprPool;
  TAprPool = THandle;
  PAprAllocator = ^TAprAllocator;
  TAprAllocator = THandle;
  TAprAbortFunc = function(retcode: Integer): Integer; stdcall;

var
  apr_pool_create_ex: function(out newpool: PAprPool; parent: PAprPool; abort_fn: TAprAbortFunc;
    allocator: PAprAllocator): TAprStatus; stdcall;

Also check if your provider_child_init callback should really be declared as cdecl and not stdcall.

Also, some ideas since you get a null pointer access violation. According to the apr source code comment:

  • if (as in your case) you pass it a nil allocator the allocator of the parent pool will be used. I assume that in case the parent pool is nil the allocator must not be nil.
  • abort_fn will be called back if the pool cannot allocate memory. You're passing it nil; perhaps the pool is trying to call it because it cannot allocate memory?
  • I don't think you can access the same pool from different threads. You probably have to create a separate pool for each thread.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文