This repository has been archived by the owner on Jun 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce d2c module to handle correct conversion from d strings to c…
… strings. Fix for #40
- Loading branch information
Showing
8 changed files
with
78 additions
and
41 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,46 @@ | ||
module Dgame.Internal.d2c; | ||
|
||
private: | ||
|
||
//import Dgame.Internal.Error; | ||
import Dgame.Internal.m3; | ||
|
||
char[] heapBuffer; | ||
char[256] stackBuffer = void; | ||
|
||
@nogc | ||
char* make_buffer(size_t len) nothrow { | ||
if (stackBuffer.length > len) | ||
return stackBuffer.ptr; | ||
|
||
if (heapBuffer.length > len) | ||
return heapBuffer.ptr; | ||
|
||
//print_fmt("(Re)Order heap buffer: %d\n", len + 1); | ||
heapBuffer = remake(heapBuffer, len + 1); | ||
|
||
return heapBuffer.ptr; | ||
} | ||
|
||
public: | ||
|
||
@nogc | ||
static ~this() nothrow { | ||
//print_fmt("Free heap buffer: %d\n", heapBuffer.length); | ||
unmake(heapBuffer); | ||
} | ||
|
||
@nogc | ||
const(char)* toStringz(string text) nothrow { | ||
if (text.length == 0) | ||
return null; | ||
|
||
if (text[$ - 1] == '\0') | ||
return text.ptr; | ||
|
||
char* ptr = make_buffer(text.length); | ||
ptr[0 .. text.length] = text[]; | ||
ptr[text.length] = '\0'; | ||
|
||
return ptr; | ||
} |
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,10 @@ | ||
<html><head> | ||
<META http-equiv="content-type" content="text/html; charset=utf-8"> | ||
<title>Dgame.Internal.d2c</title> | ||
</head><body> | ||
<h1>Dgame.Internal.d2c</h1> | ||
<!-- Generated by Ddoc from ..\Internal\d2c.d --> | ||
<br><br> | ||
|
||
<hr><small>Page generated by <a href="http://dlang.org/ddoc.html">Ddoc</a>. </small> | ||
</body></html> |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.