Skip to content

Instantly share code, notes, and snippets.

View pbackus's full-sized avatar

Paul Backus pbackus

View GitHub Profile
@pbackus
pbackus / alsaseq.d
Created May 29, 2023 19:28
ALSA sequencer bindings for D
/**
Bindings for the ALSA sequencer API.
See http://alsa-project.org/ for documentation.
License: GNU Lesser General Public License version 2.1
Authors: Jaroslav Kysela <perex@perex.cz>, Abramo Bagnara
<abramo@alsa-project.org>, and Takashi Iwai <tiwai@suse.de>.
D bindings by Paul Backus <snarwin@gmail.com>.
issue c zig (release-safe) rust (release) Nim (release) Nim (danger) D (@safe)
out-of-bounds heap read/write none runtime runtime runtime none runtime
null pointer dereference none runtime runtime runtime none runtime¹
type confusion none runtime, partial runtime compile time compile time compile time
integer overflow none runtime runtime runtime none wraps
use after free none none compile time handled by gc handled by gc handled by gc or rc
double free none none compile time handled by gc handled by gc handled by gc or rc
invalid stack read/write none none
@pbackus
pbackus / gensym.d
Last active November 14, 2023 14:12
Gensym for D
// Mixin to generate a new identifier that won't repeat within a scope
enum gensym(string prefix = "_gensym") =
`"` ~ prefix ~ `" ~ __traits(identifier, {})["__lambda".length .. $]`;
// Works multiple times on the same line
unittest
{
enum sym1 = mixin(gensym!()); enum sym2 = mixin(gensym!());
static assert(sym1 != sym2);
/// map over a variadic argument list
template mapArgs(alias fun)
{
auto mapArgs(Args...)(auto ref Args args)
{
import std.typecons: tuple;
import core.lifetime: forward;
import std.meta: Map = staticMap;
auto ref mapArg(alias arg)()
struct Ref(T)
{
T* ptr;
ref inout(T) deref() inout
{
return *ptr;
}
alias deref this;
}
@pbackus
pbackus / tail_unqual.d
Last active April 8, 2022 15:11
TailUnqual - a template that breaks qualifier transitivity
module tail_unqual;
import std.traits: isPointer;
import std.stdint: uintptr_t;
private union HiddenPointer
{
// Stores a pointer, cast to an integer.
uintptr_t address;
@pbackus
pbackus / dlang.mk
Created April 23, 2021 19:47
Basic D suport for GNU Make
DC = gdc
COMPILE.d = $(DC) $(DFLAGS) $(TARGET_ARCH) -c
LINK.d = $(DC) $(DFLAGS) $(TARGET_ARCH)
.d:
$(LINK.d) $^ $(LOADLIBES) $(LDLIBS) -o $@
.d.o:
$(COMPILE.d) $(OUTPUT_OPTION) $<
@pbackus
pbackus / DIP1035.md
Last active September 4, 2020 04:02
Proposed Revisions for DIP 1035

@system Variables

Field Value
DIP: 1035
Review Count: 1
Author: Dennis Korpel dkorpel@gmail.com
Implementation:
Status: Post-Community 1
@pbackus
pbackus / brainfuck.d
Created July 12, 2020 21:00
Arbitrary Source Languages in D
module brainfuck;
/// Brainfuck memory
struct Memory
{
private ubyte[] data;
private void extendTo(size_t i)
{
if (i >= data.length) data.length = i + 1;
@pbackus
pbackus / example.d
Last active June 17, 2020 16:18
"Argument-Dependent Lookup" for D
module example;
import extension;
import lib;
// Can extend types from other modules
bool empty(A a) { return false; }
char front(A a) { return 'a'; }
void popFront(A a) {}