Skip to content

Commit

Permalink
Merge pull request #1 from chances/betterc
Browse files Browse the repository at this point in the history
Fix compilation with `betterC` flavor of D
  • Loading branch information
chances authored Sep 4, 2023
2 parents 135436a + 9de44c0 commit 3f21e9a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
2 changes: 2 additions & 0 deletions dscanner.ini
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ unused_result="disabled"
cyclomatic_complexity="disabled"
; Maximum cyclomatic complexity after which to issue warnings
max_cyclomatic_complexity="15"
[analysis.config.ModuleFilters]
undocumented_declaration_check = "-shapes"
4 changes: 2 additions & 2 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
],
"license": "MIT",
"copyright": "Copyright © 2022, Chance Snow",
"targetType": "sourceLibrary",
"systemDependencies": "Playdate SDK >= 1.12.1",
"subPackages": [
"./examples/shapes"
],
"systemDependencies": "Playdate SDK >= 1.12.1",
"targetType": "sourceLibrary",
"configurations": [
{
"name": "library",
Expand Down
2 changes: 2 additions & 0 deletions examples/shapes/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ mixin EventHandlerShim;
@nogc nothrow:

int eventHandler(PlaydateAPI* playdate, PDSystemEvent event, uint arg) {
assert(arg >= 0);

final switch (event) {
case PDSystemEvent.init:
pd = playdate;
Expand Down
15 changes: 6 additions & 9 deletions source/playdate/allocator.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import playdate : PlaydateAPI;
///
static PlaydateAPI* pd;

shared static this() {
import std.experimental.allocator: allocatorObject, theAllocator;
theAllocator = allocatorObject(PDAllocator.instance);
}
/// The global instance of this allocator
static PDAllocator theAllocator;

/// Playdate heap allocator.
/// Remarks: Adapted from <a href="https://github.com/dlang/phobos/blob/17b1a11afd74f9f8a69af93d77d4548a557e1b89/std/experimental/allocator/mallocator.d">std.experimental.allocator.mallocator</a>
struct PDAllocator {
import std.experimental.allocator.common: platformAlignment;
import std.algorithm : max;

/// The alignment is a static constant equal to `platformAlignment`, which ensures proper alignment for any D data type.
enum uint alignment = platformAlignment;
///
/// The alignment that is guaranteed to accommodate any D object allocation on the current platform.
enum uint alignment = max(double.alignof, real.alignof);

@nogc nothrow:

Expand Down Expand Up @@ -54,7 +54,4 @@ struct PDAllocator {
b = p[0 .. s];
return true;
}

/// Returns: The global instance of this allocator type.
static PDAllocator instance;
}
6 changes: 2 additions & 4 deletions source/playdate/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,7 @@ struct Graphics {
}

///
int drawText(
Graphics* gfx, string text, int x, int y, PDStringEncoding encoding = PDStringEncoding.asciiEncoding
) {
int drawText(Graphics* gfx, string text, int x, int y, PDStringEncoding encoding = PDStringEncoding.utf8Encoding) {
return gfx.drawText(text.ptr, text.length, encoding, x, y);
}

Expand All @@ -631,7 +629,7 @@ version (unittest) {
extern (C) int drawTextTest(const void* text, size_t len, PDStringEncoding encoding, int x, int y) {
assert(text == txt.ptr);
assert(len == txt.length);
assert(encoding == PDStringEncoding.asciiEncoding);
assert(encoding == PDStringEncoding.utf8Encoding);
assert(x >= 0);
assert(y >= 0);
return 0;
Expand Down

0 comments on commit 3f21e9a

Please sign in to comment.