Skip to content

Commit

Permalink
(#354) Roll back the runtime lib changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Aug 5, 2023
1 parent 665c544 commit ec67da2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
10 changes: 4 additions & 6 deletions Cesium.Runtime/StdIoFunctions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.IO;
using System.Runtime.InteropServices;
#if NETSTANDARD
using System.Text;
#endif
Expand Down Expand Up @@ -39,11 +37,11 @@ static StdIoFunctions()
});
}

public static int PutS(CPtr<byte> str)
public static int PutS(byte* str)
{
try
{
Console.WriteLine(RuntimeHelpers.Unmarshal(str.AsPtr()));
Console.WriteLine(RuntimeHelpers.Unmarshal(str));
return 0;
}
catch (Exception) // TODO[#154]: Exception handling.
Expand Down Expand Up @@ -86,9 +84,9 @@ public static int PutC(byte character, void* stream)
}
}

public static int PrintF(CPtr<byte> str, VoidPtr varargs)
public static int PrintF(byte* str, VoidPtr varargs)
{
var formatString = RuntimeHelpers.Unmarshal(str.AsPtr());
var formatString = RuntimeHelpers.Unmarshal(str);
if (formatString == null)
{
return -1;
Expand Down
4 changes: 2 additions & 2 deletions Cesium.Runtime/StdLibFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public static void SRand(uint seed)
shared = new Random((int)seed);
}

public static int System(CPtr<byte> command)
public static int System(byte* command)
{
string? shellCommand = RuntimeHelpers.Unmarshal(command.AsPtr());
string? shellCommand = RuntimeHelpers.Unmarshal(command);
if (shellCommand is null)
{
return 8 /*ENOEXEC*/;
Expand Down
8 changes: 4 additions & 4 deletions Cesium.Runtime/StringFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ namespace Cesium.Runtime;
/// </summary>
public static unsafe class StringFunctions
{
public static nuint StrLen(CPtr<byte> str)
public static nuint StrLen(byte* str)
{
#if NETSTANDARD
if (str.AsPtr() == null)
if (str == null)
{
return 0;
}

Encoding encoding = Encoding.UTF8;
int byteLength = 0;
byte* search = str.AsPtr();
byte* search = str;
while (*search != '\0')
{
byteLength++;
Expand All @@ -31,7 +31,7 @@ public static nuint StrLen(CPtr<byte> str)
int stringLength = encoding.GetCharCount(str.AsPtr(), byteLength);
return (uint)stringLength;
#else
return (uint)(Marshal.PtrToStringUTF8(str.AsIntPtr())?.Length ?? 0);
return (uint)(Marshal.PtrToStringUTF8((IntPtr)str)?.Length ?? 0);
#endif
}
public static byte* StrCpy(byte* dest, byte* src)
Expand Down

0 comments on commit ec67da2

Please sign in to comment.