Skip to content

Commit 0dfe191

Browse files
committed
Move calling convention for native imports into Constants
1 parent db9df5a commit 0dfe191

5 files changed

Lines changed: 23 additions & 21 deletions

File tree

src/LibDeflate/Imports/Checksums.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal static class Checksums
1212
/// required initial value for 'adler' is 1. This value is also returned when
1313
/// 'buffer' is specified as NULL.
1414
///</summary>
15-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
15+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
1616
public static extern uint libdeflate_adler32(uint adler, in byte buffer, size_t len);
1717

1818
///<summary>
@@ -21,6 +21,6 @@ internal static class Checksums
2121
/// initial value for 'crc' is 0. This value is also returned when 'buffer' is
2222
/// specified as NULL.
2323
///</summary>
24-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
24+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
2525
public static extern uint libdeflate_crc32(uint crc, in byte buffer, size_t len);
2626
}

src/LibDeflate/Imports/Compression.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ internal static class Compression
2525
/// A single compressor is not safe to use by multiple threads concurrently.
2626
/// However, different threads may use different compressors concurrently.
2727
///</summary>
28-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
28+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
2929
public static extern libdeflate_compressor libdeflate_alloc_compressor(int compression_level);
3030

3131
/// <summary>
3232
/// Like <see cref="libdeflate_alloc_compressor"/> but allows specifying advanced options per-compressor.
3333
/// </summary>
34-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
34+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
3535
public static extern libdeflate_compressor libdeflate_alloc_compressor_ex(int compression_level, in libdeflate_options options);
3636

3737
///<summary>
@@ -41,7 +41,7 @@ internal static class Compression
4141
/// bytes. The return value is the compressed size in bytes, or 0 if the data
4242
/// could not be compressed to 'out_nbytes_avail' bytes or fewer.
4343
///</summary>
44-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
44+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
4545
public static extern size_t libdeflate_deflate_compress(libdeflate_compressor compressor, in byte @in, size_t in_nbytes, ref byte @out, size_t out_nbytes_avail);
4646

4747
///<summary>
@@ -69,44 +69,44 @@ internal static class Compression
6969
/// libdeflate_deflate_compress() returns 0, indicating that the compressed data
7070
/// did not fit into the provided output buffer.
7171
///</summary>
72-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
72+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
7373
public static extern size_t libdeflate_deflate_compress_bound(libdeflate_compressor compressor, size_t in_nbytes);
7474

7575
///<summary>
7676
/// Like libdeflate_deflate_compress(), but stores the data in the zlib wrapper
7777
/// format.
7878
///</summary>
79-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
79+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
8080
public static extern size_t libdeflate_zlib_compress(libdeflate_compressor compressor, in byte @in, size_t in_nbytes, ref byte @out, size_t out_nbytes_avail);
8181

8282
///<summary>
8383
/// Like libdeflate_deflate_compress_bound(), but assumes the data will be
8484
/// compressed with libdeflate_zlib_compress() rather than with
8585
/// libdeflate_deflate_compress().
8686
///</summary>
87-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
87+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
8888
public static extern size_t libdeflate_zlib_compress_bound(libdeflate_compressor compressor, size_t in_nbytes);
8989

9090
///<summary>
9191
/// Like libdeflate_deflate_compress(), but stores the data in the gzip wrapper
9292
/// format.
9393
///</summary>
94-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
94+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
9595
public static extern size_t libdeflate_gzip_compress(libdeflate_compressor compressor, in byte @in, size_t in_nbytes, ref byte @out, size_t out_nbytes_avail);
9696

9797
///<summary>
9898
/// Like libdeflate_deflate_compress_bound(), but assumes the data will be
9999
/// compressed with libdeflate_gzip_compress() rather than with
100100
/// libdeflate_deflate_compress().
101101
///</summary>
102-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
102+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
103103
public static extern size_t libdeflate_gzip_compress_bound(libdeflate_compressor compressor, size_t in_nbytes);
104104

105105
///<summary>
106106
/// libdeflate_free_compressor() frees a compressor that was allocated with
107107
/// libdeflate_alloc_compressor(). If a NULL pointer is passed in, no action is
108108
/// taken.
109109
///</summary>
110-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
110+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
111111
public static extern void libdeflate_free_compressor(libdeflate_compressor compressor);
112112
}

src/LibDeflate/Imports/Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Runtime.CompilerServices;
2+
using System.Runtime.InteropServices;
23

34
[assembly: InternalsVisibleTo($"{nameof(LibDeflate)}.Tests")]
45
[assembly: InternalsVisibleTo($"{nameof(LibDeflate)}.DangerousTests")]
@@ -7,4 +8,5 @@ namespace LibDeflate.Imports;
78
internal static class Constants
89
{
910
public const string DllName = "libdeflate";
11+
public const CallingConvention CallConv = CallingConvention.Cdecl;
1012
}

src/LibDeflate/Imports/CustomMemoryAllocator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ internal static class CustomMemoryAllocator
2020
/// There must not be any libdeflate_compressor or libdeflate_decompressor
2121
/// structures in existence when calling this function.
2222
///</summary>
23-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
23+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
2424
public static extern void libdeflate_set_memory_allocator(malloc_func malloc, free_func free);
2525
}

src/LibDeflate/Imports/Decompression.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public enum libdeflate_result
4848
/// A single decompressor is not safe to use by multiple threads concurrently.
4949
/// However, different threads may use different decompressors concurrently.
5050
///</summary>
51-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
51+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
5252
public static extern libdeflate_decompressor libdeflate_alloc_decompressor();
5353

5454
/// <summary>
5555
/// Like <see cref="libdeflate_alloc_decompressor"/> but allows specifying advanced options per-decompressor.
5656
/// </summary>
57-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
57+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
5858
public static extern libdeflate_decompressor libdeflate_alloc_decompressor_ex(in libdeflate_options options);
5959

6060
///<summary>
@@ -89,7 +89,7 @@ public enum libdeflate_result
8989
/// not large enough but no other problems were encountered, or another
9090
/// nonzero result code if decompression failed for another reason.
9191
///</summary>
92-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
92+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
9393
public static extern libdeflate_result libdeflate_deflate_decompress(libdeflate_decompressor decompressor, in byte @in, size_t in_nbytes, ref byte @out, size_t out_nbytes_avail, out size_t actual_out_nbytes_ret);
9494

9595
///<summary>
@@ -98,7 +98,7 @@ public enum libdeflate_result
9898
/// then the actual compressed size of the DEFLATE stream (aligned to the next
9999
/// byte boundary) is written to *actual_in_nbytes_ret.
100100
///</summary>
101-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
101+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
102102
public static extern libdeflate_result libdeflate_deflate_decompress_ex(libdeflate_decompressor decompressor, in byte @in, size_t in_nbytes, ref byte @out, size_t out_nbytes_avail, out size_t actual_in_nbytes_ret, out size_t actual_out_nbytes_ret);
103103

104104
///<summary>
@@ -109,7 +109,7 @@ public enum libdeflate_result
109109
/// than 'in_nbytes'. If you need to know exactly where the zlib stream ended,
110110
/// use libdeflate_zlib_decompress_ex().
111111
///</summary>
112-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
112+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
113113
public static extern libdeflate_result libdeflate_zlib_decompress(libdeflate_decompressor decompressor, in byte @in, size_t in_nbytes, ref byte @out, size_t out_nbytes_avail, out size_t actual_out_nbytes_ret);
114114

115115
///<summary>
@@ -120,7 +120,7 @@ public enum libdeflate_result
120120
/// than 'in_nbytes'. If you need to know exactly where the zlib stream ended,
121121
/// use libdeflate_zlib_decompress_ex().
122122
///</summary>
123-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
123+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
124124
public static extern libdeflate_result libdeflate_zlib_decompress_ex(libdeflate_decompressor decompressor, in byte @in, size_t in_nbytes, ref byte @out, size_t out_nbytes_avail, out size_t actual_in_nbytes_ret, out size_t actual_out_nbytes_ret);
125125

126126
///<summary>
@@ -131,7 +131,7 @@ public enum libdeflate_result
131131
/// will be decompressed. Use libdeflate_gzip_decompress_ex() if you need
132132
/// multi-member support.
133133
///</summary>
134-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
134+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
135135
public static extern libdeflate_result libdeflate_gzip_decompress(libdeflate_decompressor decompressor, in byte @in, size_t in_nbytes, ref byte @out, size_t out_nbytes_avail, out size_t actual_out_nbytes_ret);
136136

137137
///<summary>
@@ -141,14 +141,14 @@ public enum libdeflate_result
141141
/// buffer was decompressed), then the actual number of input bytes consumed is
142142
/// written to *actual_in_nbytes_ret.
143143
///</summary>
144-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
144+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
145145
public static extern libdeflate_result libdeflate_gzip_decompress_ex(libdeflate_decompressor decompressor, in byte @in, size_t in_nbytes, ref byte @out, size_t out_nbytes_avail, out size_t actual_in_nbytes_ret, out size_t actual_out_nbytes_ret);
146146

147147
///<summary>
148148
/// libdeflate_free_decompressor() frees a decompressor that was allocated with
149149
/// libdeflate_alloc_decompressor(). If a NULL pointer is passed in, no action
150150
/// is taken.
151151
///</summary>
152-
[DllImport(Constants.DllName, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
152+
[DllImport(Constants.DllName, CallingConvention = Constants.CallConv, ExactSpelling = true)]
153153
public static extern void libdeflate_free_decompressor(libdeflate_decompressor decompressor);
154154
}

0 commit comments

Comments
 (0)