如何引发对 Finalize 的多次调用?

发布于 2024-10-13 14:52:52 字数 618 浏览 3 评论 0原文

在最近的 AdaCore Gem< /a> 有一个声明

Finalize 的实现稍微复杂一些:Ada 参考手册指出 Finalize 过程应该始终是幂等的。 Ada 编译器可以对同一对象多次调用 Finalize,特别是在发生异常时。

我需要测试私有控制的类型,

   type T is private;
private
   type T is new Ada.Finalization.Controlled with ...

我可以更改源以使类型受到可见控制

   type T is new Ada.Finalization.Controlled with private;

,然后只需调用 Finalize (My_T); (甚至是 My_T.Finalize? );但是有什么方法可以在不对被测软件进行这种更改的情况下导致多次最终确定吗?

In a recent AdaCore Gem there's a statement

The implementation of Finalize is slightly more complicated: the Ada reference manual indicates that a Finalize procedure should always be idempotent. An Ada compiler is free to call Finalize multiple times on the same object, in particular when exceptions occur.

I need to test a privately controlled type,

   type T is private;
private
   type T is new Ada.Finalization.Controlled with ...

I can change the source to make the type visibly controlled

   type T is new Ada.Finalization.Controlled with private;

and then just call Finalize (My_T); (or even My_T.Finalize?); but is there any way I can cause multiple finalizations without this change to the software-under-test?

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

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

发布评论

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

评论(1

九八野马 2024-10-20 14:52:52

出于测试目的,我使用了子包。它允许测试私人部分。
假设你的包裹是:

package A is
   type T is private;
private
   type T is new Ada.Finalization.Controlled with ...
end A;

我会用类似的东西进行测试:

package body A.Test is
   procedure Test_Finalize is
       My_T : T;
   begin
       My_T.Finalize;
   end Test_Finalize;
end A.Test;

For the purpose of testing, I use a child package. It allows to tests the private part.
Assuming your package is:

package A is
   type T is private;
private
   type T is new Ada.Finalization.Controlled with ...
end A;

I would test with something like:

package body A.Test is
   procedure Test_Finalize is
       My_T : T;
   begin
       My_T.Finalize;
   end Test_Finalize;
end A.Test;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文