Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: swig/swig
...
head fork: swig/swig
Checking mergeability… Don't worry, you can still create the pull request.
  • 8 commits
  • 6 files changed
  • 0 commit comments
  • 3 contributors
Commits on Jul 18, 2014
@yuvalk yuvalk Add support for java.nio.Buffer
including test-suite test case and documentation
093fe2a
Commits on Aug 02, 2014
@gpetrou gpetrou Changed CSharp license header to include auto-generated tag so that S…
…tyleCop ignores the files.
8433539
Commits on Aug 04, 2014
@wsfulton wsfulton Doc/comment improvements in Java various.i 1773726
@wsfulton wsfulton Add changes entry for NIOBUFFER Java typemaps db75148
@wsfulton wsfulton Merge branch 'yuvalk-master' - Java NIOBUFFER typemaps for java.nio.B…
…yteBuffer

* yuvalk-master:
  Add changes entry for NIOBUFFER Java typemaps
  Doc/comment improvements in Java various.i
  Add support for java.nio.Buffer including test-suite test case and documentation
d180908
@wsfulton wsfulton Tweak generated C# .cs files header 69736cc
@wsfulton wsfulton Merge branch 'gpetrou-CSharpLicense' - Add autogenerated xml for Styl…
…eCop.

* gpetrou-CSharpLicense:
  Tweak generated C# .cs files header
  Changed CSharp license header to include auto-generated tag so that StyleCop ignores the files.
e5b98d8
@wsfulton wsfulton Add C# license header changes for StyleCop to changes file 2b71c99
View
8 CHANGES.current
@@ -5,6 +5,14 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.3 (in progress)
===========================
+2014-08-04: wsfulton
+ [C#] Merge patch #200 from gpetrou - Changed CSharp license header to include auto-generated
+ tag so that StyleCop ignores the files.
+
+2014-08-04: wsfulton
+ [Java] Merge patch #198 from Yuval Kashtan - Support for java.nio.ByteBuffer mapping to
+ unsigned char * in various.i in NIOBUFFER typemaps.
+
2014-07-14: ianlancetaylor
[Go] Change struct definition to use void *, not uint8, so
that the type is recorded as possibly containing
View
9 Doc/Manual/Java.html
@@ -5490,6 +5490,15 @@
<td>Use for mapping NULL terminated arrays of C strings to Java String arrays</td>
</tr>
+<tr>
+<td>unsigned char *</td>
+<td>NIOBUFFER</td>
+<td>various.i</td>
+<td>input<br> output</td>
+<td>java.nio.Buffer</td>
+<td>Use for mapping directly allocated buffers to c/c++. useful with directors and long lived memory objects</td>
+</tr>
+
</table>
<H3><a name="Java_typemap_attributes"></a>25.9.6 Java typemap attributes</H3>
View
19 Examples/test-suite/java/java_lib_various_runme.java
@@ -83,6 +83,25 @@ public static void main(String argv[]) {
if (byjove[i] != b[i])
throw new RuntimeException("By jove, it failed: [" + new String(b) + "]");
}
+
+ // NIOBUFFER typemap check
+ java.nio.ByteBuffer buf = java.nio.ByteBuffer.allocateDirect(10);
+ java_lib_various.niobuffer_fill_hello(buf);
+ if (
+ (char)buf.get(0) != 'h' ||
+ (char)buf.get(1) != 'e' ||
+ (char)buf.get(2) != 'l' ||
+ (char)buf.get(3) != 'l' ||
+ (char)buf.get(4) != 'o'
+ )
+ throw new RuntimeException(
+ "nio test failed: " +
+ (char)buf.get(0) +
+ (char)buf.get(1) +
+ (char)buf.get(2) +
+ (char)buf.get(3) +
+ (char)buf.get(4)
+ );
}
}
View
4 Examples/test-suite/java_lib_various.i
@@ -8,6 +8,7 @@
%apply char **STRING_ARRAY { char **languages };
%apply char *BYTE { char *chars };
%apply char **STRING_OUT { char **string_ptr };
+%apply unsigned char *NIOBUFFER { unsigned char *buf };
%typemap(freearg) char **languages "" // don't delete memory when setting global variable
%{
@@ -47,5 +48,8 @@ void char_ptr_ptr_out(char **string_ptr) {
*string_ptr = ret;
}
+void niobuffer_fill_hello(unsigned char *buf) {
+ sprintf ((char*)buf,"hello");
+}
%}
View
38 Lib/java/various.i
@@ -92,6 +92,7 @@
* The returned string appears in the 1st element of the passed in Java String array.
*
* Example usage wrapping:
+ * %apply char **STRING_OUT { char **string_out };
* void foo(char **string_out);
*
* Java usage:
@@ -154,3 +155,40 @@
/* Prevent default freearg typemap from being used */
%typemap(freearg) char *BYTE ""
+/*
+ * unsigned char *NIOBUFFER typemaps.
+ * This is for mapping Java nio buffers to C char arrays.
+ * It is useful for performance critical code as it reduces the memory copy an marshaling overhead.
+ * Note: The Java buffer has to be allocated with allocateDirect.
+ *
+ * Example usage wrapping:
+ * %apply unsigned char *NIOBUFFER { unsigned char *buf };
+ * void foo(unsigned char *buf);
+ *
+ * Java usage:
+ * java.nio.ByteBuffer b = ByteBuffer.allocateDirect(20);
+ * modulename.foo(b);
+ */
+%typemap(jni) unsigned char *NIOBUFFER "jobject"
+%typemap(jtype) unsigned char *NIOBUFFER "java.nio.ByteBuffer"
+%typemap(jstype) unsigned char *NIOBUFFER "java.nio.ByteBuffer"
+%typemap(javain,
+ pre=" assert $javainput.isDirect() : \"Buffer must be allocated direct.\";") unsigned char *NIOBUFFER "$javainput"
+%typemap(javaout) unsigned char *NIOBUFFER {
+ return $jnicall;
+}
+%typemap(in) unsigned char *NIOBUFFER {
+ $1 = (unsigned char *) JCALL1(GetDirectBufferAddress, jenv, $input);
+ if ($1 == NULL) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unable to get address of a java.nio.ByteBuffer direct byte buffer. Buffer must be a direct buffer and not a non-direct buffer.");
+ }
+}
+%typemap(memberin) unsigned char *NIOBUFFER {
+ if ($input) {
+ $1 = $input;
+ } else {
+ $1 = 0;
+ }
+}
+%typemap(freearg) unsigned char *NIOBUFFER ""
+
View
8 Source/Modules/csharp.cxx
@@ -627,9 +627,11 @@ class CSHARP:public Language {
* ----------------------------------------------------------------------------- */
void emitBanner(File *f) {
- Printf(f, "/* ----------------------------------------------------------------------------\n");
- Swig_banner_target_lang(f, " *");
- Printf(f, " * ----------------------------------------------------------------------------- */\n\n");
+ Printf(f, "//------------------------------------------------------------------------------\n");
+ Printf(f, "// <auto-generated />\n");
+ Printf(f, "//\n");
+ Swig_banner_target_lang(f, "//");
+ Printf(f, "//------------------------------------------------------------------------------\n\n");
}
/*-----------------------------------------------------------------------

No commit comments for this range

Something went wrong with that request. Please try again.