-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix extracting functions with attributes (#22)
- Loading branch information
1 parent
5b396f1
commit 27242e8
Showing
14 changed files
with
175 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"inputFilePath": "./main.c", | ||
"userIncludeDirectories": [ | ||
"../../../production/ffi_helper/include" | ||
], | ||
"ignoredIncludeFiles": [ | ||
"../../../production/ffi_helper/include/ffi_helper.h" | ||
], | ||
"targetPlatforms": { | ||
"windows": { | ||
"x86_64-pc-windows-msvc": {}, | ||
"aarch64-pc-windows-msvc": {} | ||
}, | ||
"macos": { | ||
"aarch64-apple-darwin": {}, | ||
"x86_64-apple-darwin": {}, | ||
}, | ||
"linux": { | ||
"x86_64-unknown-linux-gnu": {}, | ||
"aarch64-unknown-linux-gnu": {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <stdio.h> | ||
#include "ffi_helper.h" | ||
|
||
extern FFI_API_DECL __attribute__((malloc)) void* __cdecl function_attributed(size_t size); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...erators/Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator/LoggerMessage.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/cs/tests/c2ffi.Tests.EndToEnd.Extract/Functions/function_attributed/Test.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. | ||
|
||
using c2ffi.Tests.Library.Models; | ||
using FluentAssertions; | ||
|
||
#pragma warning disable CA1707 | ||
|
||
namespace c2ffi.Tests.EndToEnd.Extract.Functions.function_attributed; | ||
|
||
public class Test : ExtractFfiTest | ||
{ | ||
private const string FunctionName = "function_attributed"; | ||
|
||
[Fact] | ||
public void Function() | ||
{ | ||
var ffis = GetTargetPlatformFfis( | ||
$"src/c/tests/functions/{FunctionName}/config.json"); | ||
Assert.True(ffis.Length > 0); | ||
|
||
foreach (var ffi in ffis) | ||
{ | ||
FfiFunctionExists(ffi); | ||
} | ||
} | ||
|
||
private void FfiFunctionExists(CTestFfiTargetPlatform ffi) | ||
{ | ||
var function = ffi.GetFunction(FunctionName); | ||
function.CallingConvention.Should().Be("cdecl"); | ||
|
||
var returnType = function.ReturnType; | ||
returnType.Name.Should().Be("void *"); | ||
returnType.SizeOf.Should().Be(ffi.PointerSize); | ||
returnType.AlignOf.Should().Be(ffi.PointerSize); | ||
returnType.NodeKind.Should().Be("pointer"); | ||
returnType.InnerType.Should().NotBeNull(); | ||
returnType.InnerType!.Name.Should().Be("void"); | ||
returnType.InnerType!.NodeKind.Should().Be("primitive"); | ||
returnType.InnerType.InnerType.Should().BeNull(); | ||
|
||
function.Parameters.Should().NotBeEmpty(); | ||
function.Parameters.Length.Should().Be(1); | ||
var parameter = function.Parameters[0]; | ||
parameter.Name.Should().Be("size"); | ||
parameter.Type.Name.Should().Be("size_t"); | ||
parameter.Type.InnerType.Should().NotBeNull(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/cs/tests/c2ffi.Tests.EndToEnd.Merge/Functions/function_attributed/Test.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Bottlenose Labs Inc. (https://github.com/bottlenoselabs). All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the Git repository root directory for full license information. | ||
|
||
using c2ffi.Tests.Library.Models; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
#pragma warning disable CA1707 | ||
|
||
namespace c2ffi.Tests.EndToEnd.Merge.Functions.function_attributed; | ||
|
||
public class Test : MergeFfisTest | ||
{ | ||
private const string FunctionName = "function_attributed"; | ||
|
||
[Fact] | ||
public void Function() | ||
{ | ||
var ffi = GetCrossPlatformFfi( | ||
$"src/c/tests/functions/{FunctionName}/ffi"); | ||
FfiFunctionExists(ffi); | ||
} | ||
|
||
private void FfiFunctionExists(CTestFfiCrossPlatform ffi) | ||
{ | ||
var function = ffi.GetFunction(FunctionName); | ||
function.CallingConvention.Should().Be("cdecl"); | ||
|
||
var returnType = function.ReturnType; | ||
returnType.Name.Should().Be("void *"); | ||
returnType.NodeKind.Should().Be("pointer"); | ||
returnType.InnerType.Should().NotBeNull(); | ||
returnType.InnerType!.Name.Should().Be("void"); | ||
returnType.InnerType!.NodeKind.Should().Be("primitive"); | ||
returnType.InnerType.InnerType.Should().BeNull(); | ||
|
||
function.Parameters.Should().NotBeEmpty(); | ||
function.Parameters.Length.Should().Be(1); | ||
var parameter = function.Parameters[0]; | ||
parameter.Name.Should().Be("size"); | ||
parameter.Type.Name.Should().Be("size_t"); | ||
parameter.Type.InnerType.Should().NotBeNull(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters