From a219ffc45d68a814bde0eb57fcda1ab5d5c28641 Mon Sep 17 00:00:00 2001
From: Dan Hirsch <thequux@upstandinghackers.com>
Date: Mon, 16 Dec 2013 15:52:24 +0100
Subject: [PATCH] Have a typemap for uint8_t*

---
 src/bindings/dotnet/SConscript | 17 ++++++++++-------
 src/bindings/dotnet/hammer.i   | 29 +++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/src/bindings/dotnet/SConscript b/src/bindings/dotnet/SConscript
index aa486dfa..6448e685 100644
--- a/src/bindings/dotnet/SConscript
+++ b/src/bindings/dotnet/SConscript
@@ -12,7 +12,8 @@ dotnetenv.Append(CCFLAGS=["-fpic", '-DSWIG', '-Wno-all',
               LIBPATH=["../.."],
               SWIGFLAGS=["-DHAMMER_INTERNAL__NO_STDARG_H",
                          "-Isrc/", "-csharp",
-                         "-dllimport","hammer_dotnet"])
+                         "-dllimport","hammer_dotnet",
+                         "-namespace", "Hammer.Internal"])
 import os
 
 swig = ['hammer.i']
@@ -25,23 +26,25 @@ csfiles = os.path.join(thisdir, "*.cs")
 # This also generates a bunch of .cs files, which we'll just use this
 # target to stand in for.
 hammer_wrap = AlwaysBuild(dotnetenv.Command(['hammer_wrap.c'], swig,
-                                            ["rm %s/*.cs" % (thisdir,),
+                                            ["rm %s/*.cs || true" % (thisdir,),
                                              "swig $SWIGFLAGS $SOURCE"]))
 libhammer_dotnet = dotnetenv.SharedLibrary(['hammer_dotnet'], hammer_wrap)
-hammer_dll = AlwaysBuild(dotnetenv.Command(['hammer.dll'], hammer_wrap,
-                                           '$CSC -t:library -out:$TARGET %s/*.cs' %(thisdir,)))
-Depends(hammer_dll, hammer_wrap)
-#hammer_dll = dotnetenv.CLILibrary('hammer.dll', dotnetenv.Glob('*.cs'))
+hammer_dll = AlwaysBuild(dotnetenv.Command(['hammer.dll'], Glob('ext/*.cs'),
+                                           '$CSC -t:library -unsafe -out:$TARGET %s/*.cs $SOURCE' %(thisdir,)))
 Depends(hammer_dll, hammer_wrap)
+#hammer_dll = dotnetenv.CLILibrary('hammer.dll', hammer.cs)
 Default(libhammer_dotnet, hammer_dll)
 
 dotnettestenv = dotnetenv.Clone()
+
 #dotnettestenv['ENV']['LD_LIBRARY_PATH'] = os.path.dirname(str(libhammer_shared[0]))
 #dotnettests = ['t/hammer.t']
+dotnettestenv.Append(CILLIBS=['/usr/lib/cli/nunit.core-2.6/nunit.core.dll','/usr/lib/cli/nunit.util-2.6/nunit.util.dll','/usr/lib/cli/nunit.framework-2.6/nunit.framework.dll','/usr/lib/cli/nunit.core.interfaces-2.6/nunit.core.interfaces.dll',str(hammer_dll[0])])
+dotnettestlib = dotnettestenv.CLILibrary('hammer_test.dll', Glob('test/*.cs'))
 #dotnettestexec = dotnettestenv.Command(None, dotnettests + libhammer_dotnet + libhammer_shared, "make test -C " + targetdir)
 #dotnettest = Alias("testdotnet", [dotnettestexec], dotnettestexec)
 #AlwaysBuild(dotnettestexec)
-#testruns.append(dotnettest)
+testruns.append(dotnettestlib)
 
 #dotnetinstallexec = dotnetenv.Command(None, libhammer_dotnet, "make install -C " + targetdir)
 #dotnetinstall = Alias("installdotnet", [dotnetinstallexec], dotnetinstallexec)
diff --git a/src/bindings/dotnet/hammer.i b/src/bindings/dotnet/hammer.i
index 1c604055..a04a7cc2 100644
--- a/src/bindings/dotnet/hammer.i
+++ b/src/bindings/dotnet/hammer.i
@@ -1,3 +1,32 @@
 %module hammer;
 
+%include "stdint.i"
+
+ // Special attention needs to be paid to:
+ // h_parse
+ // h_token
+ // h_in
+ // h_not_in
+
+ //%typemap(cstype)  uint8_t* "byte[]"
+%typemap(imtype) uint8_t* "IntPtr"
+ //%typemap(csin, pre="unsafe { fixed(byte* temp$csinput = &$csinput[0]) {", terminator="}}") uint8_t* "(IntPtr)temp$csinput"
+ //%typemap(csvarin) uint8_t
+%typemap(cstype) uint8_t* "IntPtr"
+%typemap(csin) uint8_t* "$csinput"
+%typemap(csvarout) uint8_t* %{
+    get {
+      return $imcall;
+    }
+  %}
+
+%ignore h_bit_writer_get_buffer;
+%apply (char *STRING, size_t LENGTH) {(uint8_t* str, size_t len)};
+%apply (uint8_t* str, size_t len) {(const uint8_t* input, size_t length)}
+%apply (uint8_t* str, size_t len) {(const uint8_t* str, const size_t len)}
+%apply (uint8_t* str, size_t len) {(const uint8_t* charset, size_t length)}
+
+%typemap(csclassmodifiers) SWIGTYPE "internal class";
+%csmethodmodifiers "internal";
+
 %include "../swig/hammer.i";
-- 
GitLab