Skip to content

Instantly share code, notes, and snippets.

View marler8997's full-sized avatar

Jonathan Marler marler8997

  • Tuple
  • Idaho, United States
View GitHub Profile
@marler8997
marler8997 / classbyvalue.d
Created December 14, 2017 14:25
Dlang classes by value
/**
Value is a template that represents a class object value. This is in contrast to a
normal class object which is a pointer to a class object value.
---
void foo(Value!SomeClass value)
{
// ... use value
}
---
## Script to update json test files
set -x
make test_results/compilable/json2.d.out
cp test_results/compilable/json2.out.sanitized compilable/extra-files/json2.out
make test_results/compilable/jsonCompilerInfo.d.out
cp test_results/compilable/jsonCompilerInfo.out.sanitized compilable/extra-files/jsonCompilerInfo.out
make test_results/compilable/json_nosource.sh.out
void main()
{
int a = 42;
import std.stdio;
import std.conv : text;
//
// Want to create the string "a is 42"
//
void main()
{
int a = 42;
import std.stdio;
import std.conv : text;
//
// Want to create the string "a is 42"
//
const std = @import("std");
pub fn copyVarargs(array: var, args: ...) void {
comptime var i = 0;
inline while (i < args.len) : (i += 1) array[i] = args[i];
}
pub fn allocVarargs(comptime T: type, allocator: *std.mem.Allocator, args: ...) ![]T {
var array = try allocator.alloc(T, args.len);
copyVarargs(array, args);
SUMMARY = "Call openssl-wrapper"
DESCRIPTION = "${SUMMARY}"
LICENSE = "CLOSED"
DEPENDS += "openssl-wrapper-native"
do_configure() {
openssl-wrapper
}
// run with: zig run --library c test.zig
const std = @import("std");
extern "C" fn strlen([*:0]const u8) c_int;
pub fn main() void {
std.debug.warn("strlen(\"abc\") = {}\n", strlen("abc"));
}
@marler8997
marler8997 / interface.zig
Created December 3, 2020 20:57
interface.zig
const std = @import("std");
const Allocator = struct {
pub const Error = error{OutOfMemory};
allocFn: fn (self: *Allocator, len: usize) Error![]u8,
freeFn: fn(self: *Allocator, ptr: []u8) void,
// DOWNSIDE: we have to generate these that handle passing the self ptr
// by hand for every interface
pub fn alloc(self: *Allocator, len: usize) Error![]u8 {
const std = @import("std");
const Allocator = std.mem.Allocator;
const ArrayList = std.ArrayList;
const Mutex = std.Mutex;
const Thread = std.Thread;
fn log(comptime fmt: []const u8, args: anytype) void {
std.debug.warn(fmt ++ "\n", args);
}
Segmentation fault at address 0x7f584e9e1018
/home/marler8997/tmp/zig-scheduler/thread_pool.zig:63:29: 0x234e1c in RunQueue.push (thread_pool)
tail.next = runnable;
^
/home/marler8997/tmp/zig-scheduler/thread_pool.zig:209:32: 0x236978 in ThreadPool.schedule (thread_pool)
self.run_queue.push(runnable);
^
/home/marler8997/tmp/zig-scheduler/thread_pool.zig:198:22: 0x2342ba in ThreadPool.spawn (thread_pool)
self.schedule(&wrapper.runnable);
^