diff options
author | adam <adamansky@gmail.com> | 2013-08-16 15:18:50 +0700 |
---|---|---|
committer | adam <adamansky@gmail.com> | 2013-08-16 15:18:50 +0700 |
commit | fa030237e64d9d725533b731f3a66f08b4bc5fdc (patch) | |
tree | a4a3dbf48c24b165f80a7eec703b155d06df3e47 /nejdb | |
parent | 721691e20a05e34922a8d40909d162a9bf94a59b (diff) | |
download | ejdb-fa030237e64d9d725533b731f3a66f08b4bc5fdc.tar.gz ejdb-fa030237e64d9d725533b731f3a66f08b4bc5fdc.tar.bz2 ejdb-fa030237e64d9d725533b731f3a66f08b4bc5fdc.zip |
#92 removed MonoPosix dependency
Diffstat (limited to 'nejdb')
-rw-r--r-- | nejdb/Ejdb.DB/EJDB.cs | 28 | ||||
-rw-r--r-- | nejdb/Ejdb.DB/EJDBQuery.cs | 4 | ||||
-rw-r--r-- | nejdb/Ejdb.Utils/Native.cs | 48 | ||||
-rw-r--r-- | nejdb/nejdb.csproj | 2 | ||||
-rw-r--r-- | nejdb/nejdb.sln | 2 | ||||
-rw-r--r-- | nejdb/nejdb.userprefs | 38 |
6 files changed, 72 insertions, 50 deletions
diff --git a/nejdb/Ejdb.DB/EJDB.cs b/nejdb/Ejdb.DB/EJDB.cs index 01b1253..99c5a5d 100644 --- a/nejdb/Ejdb.DB/EJDB.cs +++ b/nejdb/Ejdb.DB/EJDB.cs @@ -15,9 +15,9 @@ // ============================================================================================ using System; using System.Runtime.InteropServices; -using Mono.Unix; using System.Text; using Ejdb.BSON; +using Ejdb.Utils; namespace Ejdb.DB { @@ -163,11 +163,11 @@ namespace Ejdb.DB { internal static extern bool _ejdbopen([In] IntPtr db, [In] IntPtr path, int mode); internal static bool _ejdbopen(IntPtr db, string path, int mode) { - IntPtr pptr = UnixMarshal.StringToHeap(path, Encoding.UTF8); + IntPtr pptr = Native.NativeUtf8FromString(path); //UnixMarshal.StringToHeap(path, Encoding.UTF8); try { return _ejdbopen(db, pptr, mode); } finally { - UnixMarshal.FreeHeap(pptr); + Marshal.FreeHGlobal(pptr); //UnixMarshal.FreeHeap(pptr); } } @@ -187,11 +187,11 @@ namespace Ejdb.DB { internal static extern IntPtr _ejdbgetcoll([In] IntPtr db, [In] IntPtr cname); internal static IntPtr _ejdbgetcoll(IntPtr db, string cname) { - IntPtr cptr = UnixMarshal.StringToHeap(cname, Encoding.UTF8); + IntPtr cptr = Native.NativeUtf8FromString(cname); //UnixMarshal.StringToHeap(cname, Encoding.UTF8); try { return _ejdbgetcoll(db, cptr); } finally { - UnixMarshal.FreeHeap(cptr); + Marshal.FreeHGlobal(cptr); //UnixMarshal.FreeHeap(cptr); } } @@ -202,7 +202,7 @@ namespace Ejdb.DB { internal static extern IntPtr _ejdbcreatecoll([In] IntPtr db, [In] IntPtr cname, ref EJDBCollectionOptionsN opts); internal static IntPtr _ejdbcreatecoll(IntPtr db, String cname, EJDBCollectionOptionsN? opts) { - IntPtr cptr = UnixMarshal.StringToHeap(cname, Encoding.UTF8); + IntPtr cptr = Native.NativeUtf8FromString(cname);//UnixMarshal.StringToHeap(cname, Encoding.UTF8); try { if (opts == null) { return _ejdbcreatecoll(db, cptr, IntPtr.Zero); @@ -211,7 +211,7 @@ namespace Ejdb.DB { return _ejdbcreatecoll(db, cptr, ref nopts); } } finally { - UnixMarshal.FreeHeap(cptr); + Marshal.FreeHGlobal(cptr); //UnixMarshal.FreeHeap(cptr); } } //EJDB_EXPORT bool ejdbrmcoll(EJDB *jb, const char *colname, bool unlinkfile); @@ -219,11 +219,11 @@ namespace Ejdb.DB { internal static extern bool _ejdbrmcoll([In] IntPtr db, [In] IntPtr cname, bool unlink); internal static bool _ejdbrmcoll(IntPtr db, string cname, bool unlink) { - IntPtr cptr = UnixMarshal.StringToHeap(cname, Encoding.UTF8); + IntPtr cptr = Native.NativeUtf8FromString(cname);//UnixMarshal.StringToHeap(cname, Encoding.UTF8); try { return _ejdbrmcoll(db, cptr, unlink); } finally { - UnixMarshal.FreeHeap(cptr); + Marshal.FreeHGlobal(cptr); //UnixMarshal.FreeHeap(cptr); } } //EJDB_EXPORT bson* ejdbcommand(EJDB *jb, bson *cmd); @@ -273,11 +273,11 @@ namespace Ejdb.DB { internal static extern IntPtr _ejdbversion(); internal static bool _ejdbsetindex(IntPtr coll, string ipath, int flags) { - IntPtr ipathptr = UnixMarshal.StringToHeap(ipath, Encoding.UTF8); + IntPtr ipathptr = Native.NativeUtf8FromString(ipath); //UnixMarshal.StringToHeap(ipath, Encoding.UTF8); try { return _ejdbsetindex(coll, ipathptr, flags); } finally { - UnixMarshal.FreeHeap(ipathptr); + Marshal.FreeHGlobal(ipathptr); //UnixMarshal.FreeHeap(ipathptr); } } #endregion @@ -314,7 +314,7 @@ namespace Ejdb.DB { if (ecode == null) { return null; } - return UnixMarshal.PtrToString(_ejdberrmsg((int) ecode), Encoding.UTF8); + return Native.StringFromNativeUtf8(_ejdberrmsg((int) ecode)); //UnixMarshal.PtrToString(_ejdberrmsg((int) ecode), Encoding.UTF8); } } @@ -369,7 +369,7 @@ namespace Ejdb.DB { if (vres == IntPtr.Zero) { throw new Exception("Unable to get ejdb library version"); } - _LIBVERSION = UnixMarshal.PtrToString(vres, Encoding.UTF8); + _LIBVERSION = Native.StringFromNativeUtf8(vres); //UnixMarshal.PtrToString(vres, Encoding.UTF8); } return _LIBVERSION; } @@ -402,7 +402,7 @@ namespace Ejdb.DB { /// </summary> /// <param name="path">The main database file path.</param> /// <param name="omode">Open mode.</param> - public EJDB(string path, int omode=DEFAULT_OPEN_MODE) { + public EJDB(string path, int omode=DEFAULT_OPEN_MODE) { if (EJDB.LibHexVersion < 0x1113) { throw new EJDBException("EJDB library version must be at least '1.1.13' or greater"); } diff --git a/nejdb/Ejdb.DB/EJDBQuery.cs b/nejdb/Ejdb.DB/EJDBQuery.cs index 6a948f8..2c20178 100644 --- a/nejdb/Ejdb.DB/EJDBQuery.cs +++ b/nejdb/Ejdb.DB/EJDBQuery.cs @@ -16,8 +16,8 @@ using System; using Ejdb.BSON; using System.Runtime.InteropServices; -using Mono.Unix; using System.Text; +using Ejdb.Utils; namespace Ejdb.DB { @@ -188,7 +188,7 @@ namespace Ejdb.DB { if (cur != null) { //static extern IntPtr _tcxstrptr([In] IntPtr strptr); IntPtr sbptr = _tcxstrptr(logsptr); - cur.Log = UnixMarshal.PtrToString(sbptr, Encoding.UTF8); + cur.Log = Native.StringFromNativeUtf8(sbptr); //UnixMarshal.PtrToString(sbptr, Encoding.UTF8); } } finally { //static extern IntPtr _tcxstrdel([In] IntPtr strptr); diff --git a/nejdb/Ejdb.Utils/Native.cs b/nejdb/Ejdb.Utils/Native.cs new file mode 100644 index 0000000..c263443 --- /dev/null +++ b/nejdb/Ejdb.Utils/Native.cs @@ -0,0 +1,48 @@ +// ============================================================================================ +// .NET API for EJDB database library http://ejdb.org +// Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com> +// +// This file is part of EJDB. +// EJDB is free software; you can redistribute it and/or modify it under the terms of +// the GNU Lesser General Public License as published by the Free Software Foundation; either +// version 2.1 of the License or any later version. EJDB is distributed in the hope +// that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License for more details. +// You should have received a copy of the GNU Lesser General Public License along with EJDB; +// if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, +// Boston, MA 02111-1307 USA. +// ============================================================================================ +using System; +using System.Text; +using System.Runtime.InteropServices; + +namespace Ejdb.Utils { + + public class Native { + static Native() { + } + + public static IntPtr NativeUtf8FromString(string managedString) { + int len = Encoding.UTF8.GetByteCount(managedString); + byte[] buffer = new byte[len + 1]; + Encoding.UTF8.GetBytes(managedString, 0, managedString.Length, buffer, 0); + IntPtr nativeUtf8 = Marshal.AllocHGlobal(buffer.Length); + Marshal.Copy(buffer, 0, nativeUtf8, buffer.Length); + return nativeUtf8; + } + + public static string StringFromNativeUtf8(IntPtr nativeUtf8) { + int len = 0; + for (; Marshal.ReadByte(nativeUtf8, len) != 0; ++len) { + } + if (len == 0) { + return string.Empty; + } + byte[] buffer = new byte[len]; + Marshal.Copy(nativeUtf8, buffer, 0, buffer.Length); + return Encoding.UTF8.GetString(buffer); + } + } +} + diff --git a/nejdb/nejdb.csproj b/nejdb/nejdb.csproj index 01b6cb0..b6b82b2 100644 --- a/nejdb/nejdb.csproj +++ b/nejdb/nejdb.csproj @@ -52,7 +52,6 @@ <ItemGroup> <Reference Include="System" /> <Reference Include="System.Core" /> - <Reference Include="Mono.Posix" /> <Reference Include="nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"> <Private>False</Private> </Reference> @@ -84,6 +83,7 @@ <Compile Include="Ejdb.DB\EJDBQCursor.cs" /> <Compile Include="Ejdb.BSON\BSONull.cs" /> <Compile Include="Ejdb.BSON\BSONUndefined.cs" /> + <Compile Include="Ejdb.Utils\Native.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ItemGroup> diff --git a/nejdb/nejdb.sln b/nejdb/nejdb.sln index ff96e43..bf8330a 100644 --- a/nejdb/nejdb.sln +++ b/nejdb/nejdb.sln @@ -38,7 +38,7 @@ Global GlobalSection(NestedProjects) = preSolution EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = sample\sample.csproj + StartupItem = nejdb.csproj Policies = $0 $0.StandardHeader = $1 $1.Text = @============================================================================================\n .NET API for EJDB database library http://ejdb.org\n Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>\n\n This file is part of EJDB.\n EJDB is free software; you can redistribute it and/or modify it under the terms of\n the GNU Lesser General Public License as published by the Free Software Foundation; either\n version 2.1 of the License or any later version. EJDB is distributed in the hope\n that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public\n License for more details.\n You should have received a copy of the GNU Lesser General Public License along with EJDB;\n if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,\n Boston, MA 02111-1307 USA.\n============================================================================================ diff --git a/nejdb/nejdb.userprefs b/nejdb/nejdb.userprefs index 9da185b..b667d54 100644 --- a/nejdb/nejdb.userprefs +++ b/nejdb/nejdb.userprefs @@ -1,25 +1,9 @@ <Properties> - <MonoDevelop.Ide.Workspace ActiveConfiguration="ReleaseUnix" /> - <MonoDevelop.Ide.Workbench ActiveDocument="Ejdb.BSON/BSONIterator.cs"> - <Files> - <File FileName="Ejdb.Tests/TestEJDB.cs" Line="155" Column="30" /> - <File FileName="Ejdb.Tests/TestBSON.cs" Line="1" Column="1" /> - <File FileName="Ejdb.BSON/BSONDocument.cs" Line="129" Column="1" /> - <File FileName="Ejdb.DB/EJDB.cs" Line="133" Column="16" /> - <File FileName="Ejdb.BSON/BSONIterator.cs" Line="230" Column="18" /> - <File FileName="Ejdb.DB/EJDBQuery.cs" Line="158" Column="3" /> - </Files> + <MonoDevelop.Ide.Workspace ActiveConfiguration="DebugUnix" /> + <MonoDevelop.Ide.Workbench> <Pads> <Pad Id="ProjectPad"> - <State expanded="True"> - <Node name="nejdb" expanded="True" selected="True"> - <Node name="References" expanded="True" /> - <Node name="Ejdb.BSON" expanded="True" /> - <Node name="Ejdb.DB" expanded="True" /> - <Node name="Ejdb.Tests" expanded="True" /> - </Node> - <Node name="sample" expanded="True" /> - </State> + <State expanded="True" /> </Pad> <Pad Id="ClassPad"> <State expanded="True" selected="True" /> @@ -31,24 +15,14 @@ <State selected="True" /> </Pad> <Pad Id="MonoDevelop.NUnit.TestPad"> - <State expanded="True" selected="True"> - <Node name="nejdb" expanded="True"> - <Node name="Ejdb" expanded="True"> - <Node name="Tests" expanded="True"> - <Node name="TestEJDB" expanded="True" /> - </Node> - </Node> - </Node> + <State expanded="True"> + <Node name="nejdb" expanded="True" selected="True" /> </State> </Pad> </Pads> </MonoDevelop.Ide.Workbench> <MonoDevelop.Ide.DebuggingService.Breakpoints> - <BreakpointStore> - <Breakpoint file="/home/adam/Projects/softmotions/ejdb/nejdb/Ejdb.Tests/TestBSON.cs" line="279" column="1" /> - <Breakpoint file="/home/adam/Projects/softmotions/ejdb/nejdb/Ejdb.Tests/TestEJDB.cs" line="155" column="34" /> - <Breakpoint file="/home/adam/Projects/softmotions/ejdb/nejdb/Ejdb.BSON/BSONIterator.cs" line="154" column="1" /> - </BreakpointStore> + <BreakpointStore /> </MonoDevelop.Ide.DebuggingService.Breakpoints> <MonoDevelop.Ide.DebuggingService.PinnedWatches /> </Properties>
\ No newline at end of file |