简体   繁体   English

具有C函数的Ada导入段故障

[英]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. 我有一个正在Ada上工作的程序,该程序最近已从32位升级到64位。 I didn't write this code I'm just responsible for getting it to work on a 64bit version of RedHat. 我没有编写此代码,我只是负责使其在RedHat的64位版本上工作。

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 这是Ada功能

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 这是C函数

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 这是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! 任何帮助将是巨大的!

You could regenerate the binding to the C++ function using the -fdump-ada-spec flag for GCC/G++. 您可以使用GCC / G ++的-fdump-ada-spec标志重新生成与C ++函数的绑定。 That way you get a binding which the compiler developers believe will work correctly with that version of GCC. 这样,您将获得绑定,编译器开发人员认为该绑定可以在该版本的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.) (官方要求您使用同一版本的GCC来编译Ada和C ++,但实际上,您可能会获得与更广泛的编译器版本兼容的功能。)

  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). 确保C和Ada都使用相同的体系结构(32位和64位)构建。
  3. If that doesn't work, try using C_Plus_Plus convention in Ada. 如果这不起作用,请尝试在Ada中使用C_Plus_Plus约定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM