gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 20:54:27 25 4
gpt4 key购买 nike

在最近的 AdaCore Gem有一个声明

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.

我需要测试一个私有(private)控制的类型,
   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?);但是有什么方法可以在不更改被测软件的情况下导致多个最终确定?

最佳答案

为了测试的目的,我使用了一个子包。它允许测试私有(private)部分。
假设您的包裹是:

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;

关于ada - 如何引发对 Finalize 的多次调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4740899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com