Skip to content

Instantly share code, notes, and snippets.

@dwbuiten
dwbuiten / gist:5490198
Last active December 16, 2015 20:09
Static Linking Order for C99-to-C89 Clang Libs
lib\libclang.lib lib\clangARCMigrate.lib lib\clangRewriteCore.lib lib\clangFrontend.lib lib\clangDriver.lib lib\clangSerialization.lib lib\clangParse.lib lib\clangSema.lib lib\clangEdit.lib lib\clangAnalysis.lib lib\clangAST.lib lib\clangLex.lib lib\clangBasic.lib lib\LLVMMC.lib lib\LLVMMCParser.lib lib\LLVMObject.lib lib\LLVMSupport.lib ;ib\LLVMBitstreamReader.lib lib\LLVMBitstreamWriter.lib lib\shell32.lib lib\Advapi32.lib
@dwbuiten
dwbuiten / gist:5490255
Last active December 16, 2015 20:09
Hacky script for compiling dynamic MediaInfo
#!/bin/sh -e
# Replace with whatever versions you need
ZEN_VERSION=0.4.29
LIB_VERSION=0.7.63
MED_VERSION=0.7.63
PREFIX=/usr/local
wget http://mediaarea.net/download/source/libzen/${ZEN_VERSION}/libzen_${ZEN_VERSION}.tar.bz2
wget http://mediaarea.net/download/source/libmediainfo/${LIB_VERSION}/libmediainfo_${LIB_VERSION}.tar.bz2
@dwbuiten
dwbuiten / d2vscan.pl
Created May 22, 2013 21:02
Hacky script to generate a d2v file. Lacks many basic features.
#!/usr/bin/env perl
use strict;
use warnings;
use bigint;
use File::Spec;
use JSON::XS;
my $filename = $ARGV[0];
my $data = `ffprobe -show_streams -show_format -show_frames -of json $filename`;
/*
* posix_memalign wrapper with random failurres
*
* Copyright (c) 2013, Derek Buitenhuis
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
@dwbuiten
dwbuiten / fall.go
Created June 24, 2014 16:12
switch idiom
switch mystr {
case "a", "b", "c", "d", "e":
default:
dostuff()
}
// versus
if myster != "a" && mystr != "=" && mystr != "c" && mystr != "d" && mystr != "e" {
dostuff()
@dwbuiten
dwbuiten / ts_extract.c
Created September 17, 2014 14:47
L-SMASH ts extraction
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <lsmash.h>
typedef struct ts {
uint64_t dts;

Problems & Solutions for Interaction Between C and Go

At Vimeo, on the transcoding team, we work a lot with Go, and a lot with C, for various tasks such as media ingest. This means we use CGO quite extensively, and consequently, have run into bits that are perhaps not very well documented, if at all. Below is my effort to document some of the problems we've run into, and how we fixed or worked around them.

Many of these are obviously wrong in retrospect, but hindsight is 20/20, and these problems do exist in many codebases currently.

Some are definitely ugly, and I much welcome better solutions! Tweet me at @daemon404 if you have any, or have your own CGO story/tips, please! I'd love to learn of them.

Table of Contents

@dwbuiten
dwbuiten / cref.go
Created January 30, 2016 20:46
A Little CGO Abomination
// Package cref implements a way to hose your Go garbage collection.
package cref
import (
"fmt"
"unsafe"
)
/*
#include <pthread.h>
draw.c:30: error: CHECKERS_DEAD_CODE
Node not visited: 20
28. static inline char get_char(char c)
29. {
30. > if (c > 31 && c < 127)
31. return c;
32. else
33.
Original code here: https://github.com/dwbuiten/bxd/blob/master/draw.c#L28-34
draw.c:30: error: CHECKERS_DEAD_CODE
Node not visited: 20
28. static inline char get_char(char c)
29. {
30. > if (c > 31 && c < 127)
31. return c;
32. else
33.
Original code is here: https://github.com/dwbuiten/bxd/blob/master/draw.c#L28-34