diff options
author | Jedidiah Barber <contact@jedbarber.id.au> | 2024-10-08 16:47:13 +1300 |
---|---|---|
committer | Jedidiah Barber <contact@jedbarber.id.au> | 2024-10-08 16:47:13 +1300 |
commit | 3181961ad2eefb3a6d9151db99661411792d4097 (patch) | |
tree | 30cd06dc02cda116f146bd43b42a7132a150faf2 /src | |
parent | 79c1381d198f5b4ae1b75210971a8ccea1049bad (diff) |
Changed System.Address to Integer_Address
Diffstat (limited to 'src')
-rw-r--r-- | src/c_asndfile.c | 4 | ||||
-rw-r--r-- | src/c_asndfile.h | 3 | ||||
-rw-r--r-- | src/libsndfile-commands.adb | 131 | ||||
-rw-r--r-- | src/libsndfile-virtual.adb | 42 | ||||
-rw-r--r-- | src/libsndfile-virtual.ads | 17 | ||||
-rw-r--r-- | src/libsndfile.adb | 62 | ||||
-rw-r--r-- | src/libsndfile.ads | 29 |
7 files changed, 158 insertions, 130 deletions
diff --git a/src/c_asndfile.c b/src/c_asndfile.c index 116fa0c..5424c91 100644 --- a/src/c_asndfile.c +++ b/src/c_asndfile.c @@ -105,6 +105,10 @@ const int err_malformed_file = SF_ERR_MALFORMED_FILE; const int err_unsupported_encoding = SF_ERR_UNSUPPORTED_ENCODING; +size_t c_pointer_size() { + return sizeof(void*); +} + SNDFILE * asf_open(const char * path, int mode, Asf_Info * sfinfo) { SF_INFO actual; diff --git a/src/c_asndfile.h b/src/c_asndfile.h index 8c2a173..4ff7606 100644 --- a/src/c_asndfile.h +++ b/src/c_asndfile.h @@ -106,6 +106,9 @@ extern const int err_malformed_file; extern const int err_unsupported_encoding; +size_t c_pointer_size(); + + typedef struct { int64_t frames; int samplerate; diff --git a/src/libsndfile-commands.adb b/src/libsndfile-commands.adb index 61e5f48..1939cd7 100644 --- a/src/libsndfile-commands.adb +++ b/src/libsndfile-commands.adb @@ -11,8 +11,7 @@ with Ada.Assertions, Ada.Strings.Fixed, - Interfaces.C.Strings, - System; + Interfaces.C.Strings; use type @@ -225,33 +224,33 @@ package body Libsndfile.Commands is ------------------------ function sf_command - (File : in System.Address; + (File : in Storage.Integer_Address; Cmd : in Interfaces.C.int; - Data : in System.Address; + Data : in Storage.Integer_Address; Size : in Interfaces.C.int) return Interfaces.C.int; pragma Import (C, sf_command, "sf_command"); function asfc_get_current_sf_info - (File : in System.Address; + (File : in Storage.Integer_Address; Info : out C_File_Info) return Interfaces.C.int; pragma Import (C, asfc_get_current_sf_info, "asfc_get_current_sf_info"); function asfc_file_truncate - (File : in System.Address; + (File : in Storage.Integer_Address; Pos : in Interfaces.Integer_64) return Interfaces.C.int; pragma Import (C, asfc_file_truncate, "asfc_file_truncate"); function asfc_set_raw_start_offset - (File : in System.Address; + (File : in Storage.Integer_Address; Pos : in Interfaces.Integer_64) return Interfaces.C.int; pragma Import (C, asfc_set_raw_start_offset, "asfc_set_raw_start_offset"); function asfc_get_embed_file_info - (File : in System.Address; + (File : in Storage.Integer_Address; Info : in out C_Embedded_Info) return Interfaces.C.int; pragma Import (C, asfc_get_embed_file_info, "asfc_get_embed_file_info"); @@ -416,9 +415,9 @@ package body Libsndfile.Commands is return Natural is begin return Natural (sf_command - (System.Null_Address, + (Null_Pointer, sfc_get_lib_version, - Buffer'Address, + Storage.To_Integer (Buffer'Address), Buffer'Length)); end Get_Library_String; @@ -430,7 +429,7 @@ package body Libsndfile.Commands is return Natural (sf_command (File.Ptr, sfc_get_log_info, - Buffer'Address, + Storage.To_Integer (Buffer'Address), Buffer'Length)); end Get_Log_Info; @@ -460,7 +459,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_calc_signal_max, - Result'Address, + Storage.To_Integer (Result'Address), Interfaces.C.double'Size / Interfaces.C.CHAR_BIT); if Code /= 0 then Raise_Error (Code); @@ -480,7 +479,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_calc_norm_signal_max, - Result'Address, + Storage.To_Integer (Result'Address), Interfaces.C.double'Size / Interfaces.C.CHAR_BIT); if Code /= 0 then Raise_Error (Code); @@ -501,7 +500,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_calc_max_all_channels, - Result'Address, + Storage.To_Integer (Result'Address), Interfaces.C.double'Size / Interfaces.C.CHAR_BIT * File.Chans); if Code /= 0 then Raise_Error (Code); @@ -522,7 +521,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_calc_norm_max_all_channels, - Result'Address, + Storage.To_Integer (Result'Address), Interfaces.C.double'Size / Interfaces.C.CHAR_BIT * File.Chans); if Code /= 0 then Raise_Error (Code); @@ -542,7 +541,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_signal_max, - Result'Address, + Storage.To_Integer (Result'Address), Interfaces.C.double'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; @@ -563,7 +562,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_max_all_channels, - Result'Address, + Storage.To_Integer (Result'Address), Interfaces.C.double'Size / Interfaces.C.CHAR_BIT * File.Chans); if Code = sf_false then raise Command_Error; @@ -583,7 +582,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_norm_float, - System.Null_Address, + Null_Pointer, (if Value then sf_true else sf_false)); end Set_Normed_Float; @@ -596,7 +595,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_norm_double, - System.Null_Address, + Null_Pointer, (if Value then sf_true else sf_false)); end Set_Normed_Double; @@ -609,7 +608,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_norm_float, - System.Null_Address, + Null_Pointer, 0); if Code = sf_true then return True; @@ -629,7 +628,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_norm_double, - System.Null_Address, + Null_Pointer, 0); if Code = sf_true then return True; @@ -649,7 +648,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_scale_float_int_read, - System.Null_Address, + Null_Pointer, (if Value then sf_true else sf_false)); end Set_Scale_Float_Integer_Read; @@ -662,7 +661,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_scale_int_float_write, - System.Null_Address, + Null_Pointer, (if Value then sf_true else sf_false)); end Set_Scale_Integer_Float_Write; @@ -672,9 +671,9 @@ package body Libsndfile.Commands is Result, Code : Interfaces.C.int; begin Code := sf_command - (System.Null_Address, + (Null_Pointer, sfc_get_simple_format_count, - Result'Address, + Storage.To_Integer (Result'Address), Interfaces.C.int'Size / Interfaces.C.CHAR_BIT); if Result < 0 then raise Program_Error; @@ -694,9 +693,9 @@ package body Libsndfile.Commands is Code : Interfaces.C.int; begin Code := sf_command - (System.Null_Address, + (Null_Pointer, sfc_get_simple_format, - Raw'Address, + Storage.To_Integer (Raw'Address), C_Format_Info'Size / Interfaces.C.CHAR_BIT); if Code /= 0 then raise Command_Error; @@ -716,9 +715,9 @@ package body Libsndfile.Commands is Code : Interfaces.C.int; begin Code := sf_command - (System.Null_Address, + (Null_Pointer, sfc_get_format_info, - Raw'Address, + Storage.To_Integer (Raw'Address), C_Format_Info'Size / Interfaces.C.CHAR_BIT); if Code /= 0 then raise Command_Error; @@ -747,9 +746,9 @@ package body Libsndfile.Commands is Result, Code : Interfaces.C.int; begin Code := sf_command - (System.Null_Address, + (Null_Pointer, sfc_get_format_major_count, - Result'Address, + Storage.To_Integer (Result'Address), Interfaces.C.int'Size / Interfaces.C.CHAR_BIT); return Natural (Result); end Get_Format_Major_Count; @@ -765,9 +764,9 @@ package body Libsndfile.Commands is Code : Interfaces.C.int; begin Code := sf_command - (System.Null_Address, + (Null_Pointer, sfc_get_format_major, - Raw'Address, + Storage.To_Integer (Raw'Address), C_Format_Info'Size / Interfaces.C.CHAR_BIT); if Code /= 0 then raise Command_Error; @@ -782,9 +781,9 @@ package body Libsndfile.Commands is Result, Code : Interfaces.C.int; begin Code := sf_command - (System.Null_Address, + (Null_Pointer, sfc_get_format_subtype_count, - Result'Address, + Storage.To_Integer (Result'Address), Interfaces.C.int'Size / Interfaces.C.CHAR_BIT); return Natural (Result); end Get_Format_Subtype_Count; @@ -800,9 +799,9 @@ package body Libsndfile.Commands is Code : Interfaces.C.int; begin Code := sf_command - (System.Null_Address, + (Null_Pointer, sfc_get_format_subtype, - Raw'Address, + Storage.To_Integer (Raw'Address), C_Format_Info'Size / Interfaces.C.CHAR_BIT); if Code /= 0 then raise Command_Error; @@ -820,7 +819,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_add_peak_chunk, - System.Null_Address, + Null_Pointer, (if Value then sf_true else sf_false)); end Set_Add_Peak_Chunk; @@ -832,7 +831,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_update_header_now, - System.Null_Address, + Null_Pointer, 0); end Update_Header_Now; @@ -845,7 +844,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_update_header_auto, - System.Null_Address, + Null_Pointer, (if Value then sf_true else sf_false)); end Set_Update_Header_Auto; @@ -882,7 +881,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_clipping, - System.Null_Address, + Null_Pointer, (if Value then sf_true else sf_false)); end Set_Clipping; @@ -895,7 +894,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_clipping, - System.Null_Address, + Null_Pointer, 0); if Code = sf_true then return True; @@ -932,7 +931,7 @@ package body Libsndfile.Commands is Result := sf_command (File.Ptr, sfc_wavex_get_ambisonic, - System.Null_Address, + Null_Pointer, 0); if Result = 0 then return Ambisonic_Unsupported; @@ -962,7 +961,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_wavex_set_ambisonic, - System.Null_Address, + Null_Pointer, My_Value); if Code = 0 then raise Command_Error; @@ -982,7 +981,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_vbr_encoding_quality, - My_Value'Address, + Storage.To_Integer (My_Value'Address), Interfaces.C.double'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; @@ -1002,7 +1001,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_ogg_page_latency_ms, - My_Value'Address, + Storage.To_Integer (My_Value'Address), Interfaces.C.double'Size / Interfaces.C.CHAR_BIT); if Code /= 0 then raise Command_Error; @@ -1019,7 +1018,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_ogg_stream_serialno, - Result'Address, + Storage.To_Integer (Result'Address), Interfaces.Integer_32'Size / Interfaces.C.CHAR_BIT); if Code = 0 then return Integer (Result); @@ -1039,7 +1038,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_compression_level, - My_Value'Address, + Storage.To_Integer (My_Value'Address), Interfaces.C.double'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; @@ -1057,7 +1056,7 @@ package body Libsndfile.Commands is Result := sf_command (File.Ptr, sfc_raw_data_needs_endswap, - System.Null_Address, + Null_Pointer, 0); if Result = sf_true then return True; @@ -1078,7 +1077,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_broadcast_info, - Raw'Address, + Storage.To_Integer (Raw'Address), C_Broadcast_Info'Size / Interfaces.C.CHAR_BIT); if Code = sf_true then return Result : Broadcast_Info do @@ -1125,7 +1124,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_broadcast_info, - C_Data'Address, + Storage.To_Integer (C_Data'Address), C_Broadcast_Info'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; @@ -1145,7 +1144,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_channel_map_info, - Raw'Address, + Storage.To_Integer (Raw'Address), Interfaces.C.int'Size / Interfaces.C.CHAR_BIT * File.Chans); if Code = sf_false then raise Command_Error; @@ -1175,7 +1174,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_channel_map_info, - My_Value'Address, + Storage.To_Integer (My_Value'Address), Interfaces.C.int'Size / Interfaces.C.CHAR_BIT * File.Chans); if Code = sf_false then raise Command_Error; @@ -1194,7 +1193,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_cart_info, - Raw'Address, + Storage.To_Integer (Raw'Address), Raw'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; @@ -1270,7 +1269,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_cart_info, - C_Data'Address, + Storage.To_Integer (C_Data'Address), C_Data'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; @@ -1289,7 +1288,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_loop_info, - Raw'Address, + Storage.To_Integer (Raw'Address), C_Loop_Info'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; @@ -1320,7 +1319,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_instrument, - Result.C_Data'Address, + Storage.To_Integer (Result.C_Data'Address), C_Instrument_Info'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; @@ -1340,7 +1339,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_instrument, - Info.C_Data'Address, + Storage.To_Integer (Info.C_Data'Address), C_Instrument_Info'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; @@ -1359,7 +1358,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_cue_count, - Result'Address, + Storage.To_Integer (Result'Address), Interfaces.Unsigned_32'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; @@ -1380,7 +1379,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_cue, - Raw'Address, + Storage.To_Integer (Raw'Address), C_Cue_Info'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; @@ -1429,7 +1428,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_cue, - C_Data'Address, + Storage.To_Integer (C_Data'Address), C_Cue_Info'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; @@ -1447,7 +1446,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_rf64_auto_downgrade, - System.Null_Address, + Null_Pointer, (if Value then sf_true else sf_false)); end RF64_Auto_Downgrade; @@ -1460,7 +1459,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_get_original_samplerate, - Result'Address, + Storage.To_Integer (Result'Address), Interfaces.C.int'Size / Interfaces.C.CHAR_BIT); if Code = sf_true then return Natural (Result); @@ -1479,7 +1478,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_original_samplerate, - My_Value'Address, + Storage.To_Integer (My_Value'Address), Interfaces.C.int'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; @@ -1497,7 +1496,7 @@ package body Libsndfile.Commands is Result := sf_command (File.Ptr, sfc_get_bitrate_mode, - System.Null_Address, + Null_Pointer, 0); if Result = sf_bitrate_mode_constant then return Constant_Mode; @@ -1525,7 +1524,7 @@ package body Libsndfile.Commands is Code := sf_command (File.Ptr, sfc_set_bitrate_mode, - My_Value'Address, + Storage.To_Integer (My_Value'Address), Interfaces.C.int'Size / Interfaces.C.CHAR_BIT); if Code = sf_false then raise Command_Error; diff --git a/src/libsndfile-virtual.adb b/src/libsndfile-virtual.adb index db0bb6e..8a54837 100644 --- a/src/libsndfile-virtual.adb +++ b/src/libsndfile-virtual.adb @@ -14,8 +14,7 @@ with use type - Interfaces.C.int, - System.Address; + Interfaces.C.int; package body Libsndfile.Virtual is @@ -33,8 +32,8 @@ package body Libsndfile.Virtual is function asf_open_virtual (Mode : in Interfaces.C.int; Sfinfo : in out C_File_Info; - Data : in System.Address) - return System.Address; + Data : in Storage.Integer_Address) + return Storage.Integer_Address; pragma Import (C, asf_open_virtual, "asf_open_virtual"); @@ -45,11 +44,11 @@ package body Libsndfile.Virtual is ---------------------- function Ada_Filelen_Hook - (Data : in System.Address) + (Data : in Storage.Integer_Address) return Interfaces.Integer_64 is Virtual : Virt_Conversions.Object_Pointer := - Virt_Conversions.To_Pointer (Data); + Virt_Conversions.To_Pointer (Storage.To_Address (Data)); begin return Interfaces.Integer_64 (Virtual.My_Length.all); end Ada_Filelen_Hook; @@ -58,11 +57,11 @@ package body Libsndfile.Virtual is function Ada_Seek_Hook (Offset : in Interfaces.Integer_64; Whence : in Interfaces.C.int; - Data : in System.Address) + Data : in Storage.Integer_Address) return Interfaces.Integer_64 is Virtual : Virt_Conversions.Object_Pointer := - Virt_Conversions.To_Pointer (Data); + Virt_Conversions.To_Pointer (Storage.To_Address (Data)); My_Whence : Seek_From; begin if Whence = sf_seek_set then @@ -79,15 +78,15 @@ package body Libsndfile.Virtual is function Ada_Read_Hook - (Ptr : in System.Address; + (Ptr : in Storage.Integer_Address; Count : in Interfaces.Integer_64; - Data : in System.Address) + Data : in Storage.Integer_Address) return Interfaces.Integer_64 is Virtual : Virt_Conversions.Object_Pointer := - Virt_Conversions.To_Pointer (Data); + Virt_Conversions.To_Pointer (Storage.To_Address (Data)); Buffer : Raw_Data (1 .. Integer (Count)); - for Buffer'Address use Ptr; + for Buffer'Address use Storage.To_Address (Ptr); pragma Import (Ada, Buffer); begin return Interfaces.Integer_64 (Virtual.My_Read (Buffer, Count_Type (Count))); @@ -95,15 +94,15 @@ package body Libsndfile.Virtual is function Ada_Write_Hook - (Ptr : in System.Address; + (Ptr : in Storage.Integer_Address; Count : in Interfaces.Integer_64; - Data : in System.Address) + Data : in Storage.Integer_Address) return Interfaces.Integer_64 is Virtual : Virt_Conversions.Object_Pointer := - Virt_Conversions.To_Pointer (Data); + Virt_Conversions.To_Pointer (Storage.To_Address (Data)); Buffer : Raw_Data (1 .. Integer (Count)); - for Buffer'Address use Ptr; + for Buffer'Address use Storage.To_Address (Ptr); pragma Import (Ada, Buffer); begin return Interfaces.Integer_64 (Virtual.My_Write (Buffer, Count_Type (Count))); @@ -111,11 +110,11 @@ package body Libsndfile.Virtual is function Ada_Tell_Hook - (Data : in System.Address) + (Data : in Storage.Integer_Address) return Interfaces.Integer_64 is Virtual : Virt_Conversions.Object_Pointer := - Virt_Conversions.To_Pointer (Data); + Virt_Conversions.To_Pointer (Storage.To_Address (Data)); begin return Interfaces.Integer_64 (Virtual.My_Tell.all); end Ada_Tell_Hook; @@ -141,15 +140,16 @@ package body Libsndfile.Virtual is when Read_Only => sfm_read, when Write_Only => sfm_write, when Read_Write => sfm_rdwr); - Result : System.Address; + Result : Storage.Integer_Address; begin File.My_Virtual.My_Length := Length; File.My_Virtual.My_Seek := Seek; File.My_Virtual.My_Read := Read; File.My_Virtual.My_Write := Write; File.My_Virtual.My_Tell := Tell; - Result := asf_open_virtual (Mode_Int, Info.Data, File.My_Virtual'Address); - if Result = System.Null_Address then + Result := asf_open_virtual + (Mode_Int, Info.Data, Storage.To_Integer (File.My_Virtual'Address)); + if Result = Null_Pointer then Raise_Error (sf_error (Result)); raise Program_Error; else diff --git a/src/libsndfile-virtual.ads b/src/libsndfile-virtual.ads index 7c4319a..d0691b9 100644 --- a/src/libsndfile-virtual.ads +++ b/src/libsndfile-virtual.ads @@ -9,8 +9,7 @@ pragma Ada_2012; private with - Interfaces, - System; + Interfaces; package Libsndfile.Virtual is @@ -80,33 +79,33 @@ private function Ada_Filelen_Hook - (Data : in System.Address) + (Data : in Storage.Integer_Address) return Interfaces.Integer_64; pragma Export (C, Ada_Filelen_Hook, "ada_filelen_hook"); function Ada_Seek_Hook (Offset : in Interfaces.Integer_64; Whence : in Interfaces.C.int; - Data : in System.Address) + Data : in Storage.Integer_Address) return Interfaces.Integer_64; pragma Export (C, Ada_Seek_Hook, "ada_seek_hook"); function Ada_Read_Hook - (Ptr : in System.Address; + (Ptr : in Storage.Integer_Address; Count : in Interfaces.Integer_64; - Data : in System.Address) + Data : in Storage.Integer_Address) return Interfaces.Integer_64; pragma Export (C, Ada_Read_Hook, "ada_read_hook"); function Ada_Write_Hook - (Ptr : in System.Address; + (Ptr : in Storage.Integer_Address; Count : in Interfaces.Integer_64; - Data : in System.Address) + Data : in Storage.Integer_Address) return Interfaces.Integer_64; pragma Export (C, Ada_Write_Hook, "ada_write_hook"); function Ada_Tell_Hook - (Data : in System.Address) + (Data : in Storage.Integer_Address) return Interfaces.Integer_64; pragma Export (C, Ada_Tell_Hook, "ada_tell_hook"); diff --git a/src/libsndfile.adb b/src/libsndfile.adb index e5b76b0..7cc9837 100644 --- a/src/libsndfile.adb +++ b/src/libsndfile.adb @@ -10,16 +10,14 @@ pragma Ada_2012; with Ada.Assertions, - Interfaces.C.Strings, - System; + Interfaces.C.Strings; use type Interfaces.Integer_64, Interfaces.Unsigned_8, Interfaces.C.int, - Interfaces.C.Strings.chars_ptr, - System.Address; + Interfaces.C.Strings.chars_ptr; package body Libsndfile is @@ -281,7 +279,7 @@ package body Libsndfile is (Path : in Interfaces.C.char_array; Mode : in Interfaces.C.int; Sfinfo : in out C_File_Info) - return System.Address; + return Storage.Integer_Address; pragma Import (C, asf_open, "asf_open"); function asf_format_check @@ -290,7 +288,7 @@ package body Libsndfile is pragma Import (C, asf_format_check, "asf_format_check"); function asf_seek - (Sndfile : in System.Address; + (Sndfile : in Storage.Integer_Address; Frames : in Interfaces.Integer_64; Whence : in Interfaces.C.int) return Interfaces.Integer_64; @@ -298,16 +296,16 @@ package body Libsndfile is pragma Inline (asf_seek); function sf_close - (File : in System.Address) + (File : in Storage.Integer_Address) return Interfaces.C.int; pragma Import (C, sf_close, "sf_close"); procedure sf_write_sync - (File : in System.Address); + (File : in Storage.Integer_Address); pragma Import (C, sf_write_sync, "sf_write_sync"); function asf_readf_short - (File : in System.Address; + (File : in Storage.Integer_Address; DPtr : out C_Short_Data; Items : in Interfaces.Integer_64) return Interfaces.Integer_64; @@ -315,7 +313,7 @@ package body Libsndfile is pragma Inline (asf_readf_short); function asf_readf_int - (File : in System.Address; + (File : in Storage.Integer_Address; DPtr : out C_Integer_Data; Items : in Interfaces.Integer_64) return Interfaces.Integer_64; @@ -323,7 +321,7 @@ package body Libsndfile is pragma Inline (asf_readf_int); function asf_readf_float - (File : in System.Address; + (File : in Storage.Integer_Address; DPtr : out C_Float_Data; Items : in Interfaces.Integer_64) return Interfaces.Integer_64; @@ -331,7 +329,7 @@ package body Libsndfile is pragma Inline (asf_readf_float); function asf_readf_double - (File : in System.Address; + (File : in Storage.Integer_Address; DPtr : out C_Double_Data; Items : in Interfaces.Integer_64) return Interfaces.Integer_64; @@ -339,7 +337,7 @@ package body Libsndfile is pragma Inline (asf_readf_double); function asf_writef_short - (File : in System.Address; + (File : in Storage.Integer_Address; DPtr : in C_Short_Data; Items : in Interfaces.Integer_64) return Interfaces.Integer_64; @@ -347,7 +345,7 @@ package body Libsndfile is pragma Inline (asf_writef_short); function asf_writef_int - (File : in System.Address; + (File : in Storage.Integer_Address; DPtr : in C_Integer_Data; Items : in Interfaces.Integer_64) return Interfaces.Integer_64; @@ -355,7 +353,7 @@ package body Libsndfile is pragma Inline (asf_writef_int); function asf_writef_float - (File : in System.Address; + (File : in Storage.Integer_Address; DPtr : in C_Float_Data; Items : in Interfaces.Integer_64) return Interfaces.Integer_64; @@ -363,7 +361,7 @@ package body Libsndfile is pragma Inline (asf_writef_float); function asf_writef_double - (File : in System.Address; + (File : in Storage.Integer_Address; DPtr : in C_Double_Data; Items : in Interfaces.Integer_64) return Interfaces.Integer_64; @@ -371,29 +369,29 @@ package body Libsndfile is pragma Inline (asf_writef_double); function asf_read_raw - (File : in System.Address; - DPtr : in System.Address; + (File : in Storage.Integer_Address; + DPtr : in Storage.Integer_Address; Bytes : in Interfaces.Integer_64) return Interfaces.Integer_64; pragma Import (C, asf_read_raw, "asf_read_raw"); pragma Inline (asf_read_raw); function asf_write_raw - (File : in System.Address; - DPtr : in System.Address; + (File : in Storage.Integer_Address; + DPtr : in Storage.Integer_Address; Bytes : in Interfaces.Integer_64) return Interfaces.Integer_64; pragma Import (C, asf_write_raw, "asf_write_raw"); pragma Inline (asf_write_raw); function sf_get_string - (File : in System.Address; + (File : in Storage.Integer_Address; Kind : in Interfaces.C.int) return Interfaces.C.Strings.chars_ptr; pragma Import (C, sf_get_string, "sf_get_string"); function sf_set_string - (File : in System.Address; + (File : in Storage.Integer_Address; Kind : in Interfaces.C.int; Str : in Interfaces.C.char_array) return Interfaces.C.int; @@ -404,7 +402,7 @@ package body Libsndfile is pragma Import (C, sf_version_string, "sf_version_string"); function sf_current_byterate - (File : in System.Address) + (File : in Storage.Integer_Address) return Interfaces.C.int; pragma Import (C, sf_current_byterate, "sf_current_byterate"); @@ -786,7 +784,7 @@ package body Libsndfile is (File : in Sound_File) return Boolean is begin - return File.Ptr /= System.Null_Address; + return File.Ptr /= Null_Pointer; end Is_Open; @@ -806,10 +804,10 @@ package body Libsndfile is when Read_Only => sfm_read, when Write_Only => sfm_write, when Read_Write => sfm_rdwr); - Result : System.Address; + Result : Storage.Integer_Address; begin Result := asf_open (Interfaces.C.To_C (Name), Mode_Int, Info.Data); - if Result = System.Null_Address then + if Result = Null_Pointer then Raise_Error (sf_error (Result)); raise Program_Error; else @@ -875,7 +873,7 @@ package body Libsndfile is if Result /= 0 then Raise_Error (Result); else - File.Ptr := System.Null_Address; + File.Ptr := Null_Pointer; end if; end Close; @@ -1004,7 +1002,10 @@ package body Libsndfile is return Count_Type is begin Ada.Assertions.Assert (Character'Size = 8); - return Count_Type (asf_read_raw (File.Ptr, Data'Address, Interfaces.Integer_64 (Bytes))); + return Count_Type (asf_read_raw + (File.Ptr, + Storage.To_Integer (Data'Address), + Interfaces.Integer_64 (Bytes))); end Read_Raw; function Write_Raw @@ -1014,7 +1015,10 @@ package body Libsndfile is return Count_Type is begin Ada.Assertions.Assert (Character'Size = 8); - return Count_Type (asf_write_raw (File.Ptr, Data'Address, Interfaces.Integer_64 (Bytes))); + return Count_Type (asf_write_raw + (File.Ptr, + Storage.To_Integer (Data'Address), + Interfaces.Integer_64 (Bytes))); end Write_Raw; function Get_Meta diff --git a/src/libsndfile.ads b/src/libsndfile.ads index ad82d0c..65ffeac 100644 --- a/src/libsndfile.ads +++ b/src/libsndfile.ads @@ -14,7 +14,7 @@ with private with Interfaces.C, - System; + System.Storage_Elements; package Libsndfile is @@ -343,8 +343,27 @@ package Libsndfile is private + package Storage renames System.Storage_Elements; + use type Interfaces.C.size_t, Storage.Integer_Address; + + + Null_Pointer : constant Storage.Integer_Address := Storage.To_Integer (System.Null_Address); + + pragma Linker_Options ("-lsndfile"); + + function c_pointer_size + return Interfaces.C.size_t; + pragma Import (C, c_pointer_size, "c_pointer_size"); + + -- If this fails then we are on an architecture that for whatever reason + -- has significant problems interfacing between C and Ada + pragma Assert + (c_pointer_size * Interfaces.C.CHAR_BIT = Storage.Integer_Address'Size, + "Size of C void pointers and size of Ada address values do not match"); + + pragma Inline (Is_Open); pragma Inline (Write_Sync); pragma Inline (Read_Raw); @@ -353,9 +372,9 @@ private type Sound_File is tagged limited record - Ptr : System.Address := System.Null_Address; - FMode : File_Mode := Read_Only; - Chans : Interfaces.C.int := 0; + Ptr : Storage.Integer_Address := Null_Pointer; + FMode : File_Mode := Read_Only; + Chans : Interfaces.C.int := 0; end record; @@ -441,7 +460,7 @@ private function sf_error - (File : in System.Address) + (File : in Storage.Integer_Address) return Interfaces.C.int; pragma Import (C, sf_error, "sf_error"); |