Skip to content

Commit

Permalink
Added malloc and family to platform Scaffold.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkie committed May 9, 2010
1 parent ae921bd commit 1d1e5f5
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
38 changes: 38 additions & 0 deletions platform/osx/scaffold/system.d
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,41 @@ LocaleId SystemGetLocaleId() {

return ret;
}

private import binding.c;

ubyte[] malloc(size_t length) {
ubyte* ret = cast(ubyte*)binding.c.malloc(length);

// Error, probably out of memory.
if (ret is null) {
return null;
}

return ret[0..length];
}

ubyte[] realloc(ubyte[] original, size_t length) {
ubyte* ret = cast(ubyte*)binding.c.realloc(original.ptr, length);

if (ret is null) {
return null;
}

return ret[0..length];
}

ubyte[] calloc(size_t length) {
ubyte* ret = cast(ubyte*)binding.c.calloc(length);

// Error, probably out of memory.
if (ret is null) {
return null;
}

return ret[0..length];
}

void free(void[] memory) {
binding.c.free(memory.ptr);
}
38 changes: 38 additions & 0 deletions platform/unix/scaffold/system.d
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,41 @@ LocaleId SystemGetLocaleId() {

return ret;
}

private import binding.c;

ubyte[] malloc(size_t length) {
ubyte* ret = cast(ubyte*)binding.c.malloc(length);

// Error, probably out of memory.
if (ret is null) {
return null;
}

return ret[0..length];
}

ubyte[] realloc(ubyte[] original, size_t length) {
ubyte* ret = cast(ubyte*)binding.c.realloc(original.ptr, length);

if (ret is null) {
return null;
}

return ret[0..length];
}

ubyte[] calloc(size_t length) {
ubyte* ret = cast(ubyte*)binding.c.calloc(length);

// Error, probably out of memory.
if (ret is null) {
return null;
}

return ret[0..length];
}

void free(void[] memory) {
binding.c.free(memory.ptr);
}
40 changes: 39 additions & 1 deletion platform/win/scaffold/system.d
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,42 @@ LocaleId SystemGetLocaleId() {
break;
}
return ret;
}
}

private import binding.c;

ubyte[] malloc(size_t length) {
ubyte* ret = cast(ubyte*)binding.c.malloc(length);

// Error, probably out of memory.
if (ret is null) {
return null;
}

return ret[0..length];
}

ubyte[] realloc(ubyte[] original, size_t length) {
ubyte* ret = cast(ubyte*)binding.c.realloc(original.ptr, length);

if (ret is null) {
return null;
}

return ret[0..length];
}

ubyte[] calloc(size_t length) {
ubyte* ret = cast(ubyte*)binding.c.calloc(length);

// Error, probably out of memory.
if (ret is null) {
return null;
}

return ret[0..length];
}

void free(void[] memory) {
binding.c.free(memory.ptr);
}

0 comments on commit 1d1e5f5

Please sign in to comment.