Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation with betterC flavor of D #1

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading