From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,XPRIO autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8e5354673d5d3fde,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-09-18 14:22:31 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!btnet-peer1!btnet-peer0!btnet!news5-gui.server.ntli.net!ntli.net!news2-win.server.ntlworld.com.POSTED!not-for-mail From: "martin.m.dowie" Newsgroups: comp.lang.ada Subject: Interfacing access-to-subprograms into a C program X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: Date: Tue, 18 Sep 2001 22:13:18 +0100 NNTP-Posting-Host: 62.253.12.234 X-Complaints-To: abuse@ntlworld.com X-Trace: news2-win.server.ntlworld.com 1000847841 62.253.12.234 (Tue, 18 Sep 2001 22:17:21 BST) NNTP-Posting-Date: Tue, 18 Sep 2001 22:17:21 BST Organization: ntlworld News Service Xref: archiver1.google.com comp.lang.ada:13166 Date: 2001-09-18T22:13:18+01:00 List-Id: I'm writing to provide a C binding for an Ada program but am having trouble getting a good binding for an access-to-subprogram parameter. My current solution isn't particularly good as it would leave open the possibility of blocking another thread (possibly forever!). Here's what I have: with Interfaces.C.Strings; package DLL_Test is type An_Action is access procedure (Item : String; Quit : out Boolean); package C is type A_C_Boolean is new Boolean; pragma Export (C, A_C_Boolean, "dllTestBoolean"); type A_C_Action is access procedure (Item : Interfaces.C.Strings.Chars_Ptr; Quit : out A_C_Boolean); pragma Export (C, A_C_Action, "dllTestAction"); end C; procedure Do_Action (Action : An_Action); private package Private_C is procedure C_Do_Action (Action : Dll_Test.C.A_C_Action); pragma Export (C, C_Do_Action, "dllTestDoAction"); end Private_C; end DLL_Test; package body DLL_Test is procedure Do_Action (Action : An_Action) is begin null; end Do_Action; package Lock is procedure Seize; procedure Release; end Lock; package body Private_C is C_Action : Dll_Test.C.A_C_Action; procedure Do_Ada_Action (Item : String; Quit : out Boolean) is begin C_Action (Item => Interfaces.C.Strings.New_String (Str => Item), Quit => Dll_Test.C.A_C_Boolean (Quit)); end Do_Ada_Action; procedure C_Do_Action (Action : Dll_Test.C.A_C_Action) is begin Lock.Seize; C_Action := Action; Do_Action (Action => Do_Ada_Action'Access); Lock.Release; end C_Do_Action; end Private_C; -- Not real yet package body Lock is procedure Seize is begin null; end; procedure Release is begin null; end; end Lock; end DLL_Test;