forked from jnr/jnr-ffi
-
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.
Add support for using versionned symbols
This is a follow-up to jnr/jffi#66 and use the new API to make it possible to access versioned symbols in a shared library.
- Loading branch information
Showing
8 changed files
with
143 additions
and
5 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
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,14 @@ | ||
int | ||
old_answer(void) | ||
{ | ||
return 41; | ||
} | ||
|
||
int | ||
new_answer(void) | ||
{ | ||
return 42; | ||
} | ||
|
||
__asm__(".symver old_answer,answer@VERS_1.0"); | ||
__asm__(".symver new_answer,answer@@VERS_1.1"); |
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,2 @@ | ||
VERS_1.0 {}; | ||
VERS_1.1 {}; |
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,12 @@ | ||
package jnr.ffi.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface Function { | ||
String value(); | ||
} |
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,12 @@ | ||
package jnr.ffi.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface Version { | ||
String value(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package jnr.ffi; | ||
|
||
import jnr.ffi.annotations.Function; | ||
import jnr.ffi.annotations.Version; | ||
|
||
import jnr.ffi.types.*; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
|
||
public class VersionTest { | ||
public VersionTest() { | ||
} | ||
|
||
public static interface TestLib { | ||
public int answer(); | ||
public int old_answer(); | ||
public int new_answer(); | ||
|
||
@Function("answer") | ||
@Version("VERS_1.0") | ||
public int answer_1_0(); | ||
|
||
@Function("answer") | ||
@Version("VERS_1.1") | ||
public int answer_1_1(); | ||
} | ||
static TestLib testlib; | ||
|
||
@BeforeClass | ||
public static void setUpClass() throws Exception { | ||
testlib = TstUtil.loadTestLib(TestLib.class); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDownClass() throws Exception { | ||
} | ||
|
||
@Test | ||
public void testAnswer() { | ||
int res = testlib.answer(); | ||
assertEquals(42, res); | ||
} | ||
|
||
@Test | ||
public void testOldAnswer() { | ||
int res = testlib.old_answer(); | ||
assertEquals(41, res); | ||
} | ||
|
||
@Test | ||
public void testNewAnswer() { | ||
int res = testlib.new_answer(); | ||
assertEquals(42, res); | ||
} | ||
|
||
@Test | ||
public void testAnswer_1_0() { | ||
int res = testlib.answer_1_0(); | ||
assertEquals(41, res); | ||
} | ||
|
||
@Test | ||
public void testAnswer_1_1() { | ||
int res = testlib.answer_1_1(); | ||
assertEquals(42, res); | ||
} | ||
} |