From 1ba99737bca1136170f04b3a46659deb042e3fcd Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Tue, 14 Jan 2025 01:54:17 +1300 Subject: Fixed a number of issues with getting the Ada wrapper back given a C++ widget pointer --- src/fltk-widgets-menus.adb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/fltk-widgets-menus.adb') diff --git a/src/fltk-widgets-menus.adb b/src/fltk-widgets-menus.adb index be46a72..28653ec 100644 --- a/src/fltk-widgets-menus.adb +++ b/src/fltk-widgets-menus.adb @@ -6,8 +6,9 @@ with - Interfaces.C.Strings, - Ada.Unchecked_Deallocation; + Ada.Assertions, + Ada.Unchecked_Deallocation, + Interfaces.C.Strings; use type @@ -19,6 +20,11 @@ use type package body FLTK.Widgets.Menus is + package Chk renames Ada.Assertions; + + + + ------------------------ -- Functions From C -- ------------------------ @@ -272,11 +278,15 @@ package body FLTK.Widgets.Menus is procedure Item_Hook (M, U : in Storage.Integer_Address) is - Ada_Widget : access Widget'Class := - Widget_Convert.To_Pointer (Storage.To_Address (fl_widget_get_user_data (M))); + C_Ptr : Storage.Integer_Address := fl_widget_get_user_data (M); + Ada_Widget : access Widget'Class; Action : Widget_Callback := Callback_Convert.To_Access (U); begin + pragma Assert (C_Ptr /= Null_Pointer); + Ada_Widget := Widget_Convert.To_Pointer (Storage.To_Address (C_Ptr)); Action.all (Ada_Widget.all); + exception + when Chk.Assertion_Error => raise Internal_FLTK_Error; end Item_Hook; -- cgit