JDiGz
JDiGz

Reputation: 23

Ada with C function import Seg Faults

I have a program that I am working on in Ada that was recently upgraded from 32bit to 64bit. I didn't write this code I'm just responsible for getting it to work on a 64bit version of RedHat.

I am still working through bugs that were caused by this migration. This code is seg faulting and it wasn't before.

This is the Ada function

function Read_Fields
  (table         : DB_API_Types.DB_Table_Type;
   key           : System.Address;
   return_fields : System.Address;
   function      : Process_DB_Access_Type;
   client        : System.Address)
return C_Types.Int;
pragma Interface(C, Read_Fields);
pragma Import_Function
  (Internal => Read_Fields,
   External => "GetFields",
   Result_Type => C_Types.Int);

Here is the C function

int GetFields ( DB::table_code table_type, char *key,
        char **return_fields, DB::GetFieldCB function,
        void *client) {
  return ( DB::System::Ptr()->get_fields(table_type, key, return_fields, func, client)); 
}

Here is an example call of this function within Ada

DB_Status :=
   Read_Fields
     (table         => table,
      key           => c_types.null_terminated.to_address_or_null_pointer(field),
      return_fields => table_Fields'address,
      function      => Process_Data'access,
      client        => read_Data_Return'address);

This has me a bit stumped, I have my suspicions but I'm not sure how memory addresses work across language interfaces. I assumed that they would all be in one process as machine language so it shouldn't matter at all but I may be missing something.

Any help would be great!

Upvotes: 0

Views: 228

Answers (2)

Jacob Sparre - at CLDK
Jacob Sparre - at CLDK

Reputation: 410

You could regenerate the binding to the C++ function using the -fdump-ada-spec flag for GCC/G++. That way you get a binding which the compiler developers believe will work correctly with that version of GCC. (The official requirement is that you use the same version of GCC for compiling both Ada and C++, but in practice you may get something that works with a slightly wider variety of compiler versions.)

Upvotes: 0

Shark8
Shark8

Reputation: 4198

  1. Clean out everything; delete the objects you have laying around.
  2. Rebuild both; ensure that both C and Ada are built with the same architecture (32-bit vs 64-bit).
  3. If that doesn't work, try using C_Plus_Plus convention in Ada.

Upvotes: 0

Related Questions