Skip to content

Instantly share code, notes, and snippets.

@weissi
weissi / Makefile
Last active January 9, 2022 09:57
dont free
CFLAGS := -O2 -fPIC
test: libdontfree.dylib test.swift
swiftc -L. -ldontfree test.swift
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $^
libdontfree.dylib: dont-free.o
$(CC) $(LDFLAGS) -shared -o $@ $^
@inline(never)
func searchSlow(_ haystack: UnsafeBufferPointer<UInt8>, needle: UInt8) -> Int? {
print(haystack)
return haystack.firstIndex(of: needle)
}
@inline(never)
func searchFast16(_ ptr: UnsafeBufferPointer<UInt8>, needle: UInt8) -> Int? {
assert(ptr.count % 16 == 0)
docker run -it --rm --cap-add=SYS_PTRACE --security-opt seccomp=unconfined swift:5.1 bash -c 'echo "print(1)" > /tmp/test.swift && cd /tmp && swiftc test.swift && lldb --batch -o "break set -n main" -o run -o cont ./test'
@weissi
weissi / xcode-how-to-backtrace.md
Created December 11, 2019 10:03
xcode-how-to-backtrace.md

@weissi
weissi / run-in-lldb.sh
Created November 13, 2019 10:32
run-in-lldb.sh
lldb --batch -o run -k "image list" -k "register read" -k "bt all" -k "exit 134" ./my-program
import Foundation
public struct SandwichError: Error, Equatable, CustomStringConvertible {
private enum SandwichErrorCode: Int {
case tooLittleSalami = 1
case tooLittleMustard
case noTomatoes
case noBread
}
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2019 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//

Swift compiler 4.0, language mode 4

>=4.0.0
NOT >=4.0.10
NOT >=4.0.50
NOT >=4.0.150
NOT >=4.0.200
NOT >=4.0.250
NOT >=4.1.0
//
// WemoControl.swift
// WemoSchedule
//
// Created by Johannes Weiß on 12/03/2016.
// Copyright © 2016 Johannes Weiß. All rights reserved.
//
import Foundation
#include <dispatch/dispatch.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
int main()
{
int pipes[2] = {0, 0};
int err = pipe(pipes);