Original tweet that started it all
#define lz_safe_free(_var, _freefn) do { \
_freefn((_var)); \
(_var) = NULL; \
} while (0)
Writing efficient parsers for streaming data in C | |
C is known as one of the worst languages to write any type of parsers. | |
Developers usually take one of three roads for parsing data: | |
1. Lexical Analysis & LALR (lex / yacc) utilizing a BNF syntax input. | |
2. Gobs of strstr, strtok, strcmp, and loads of conditionals. | |
3. Regular expressions, which usually involve the same logic in #2 | |
Utilizing Lex & Yacc can be one of the more strict and specific methods of |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdint.h> | |
#include <errno.h> | |
#include <inttypes.h> | |
#include <evhtp.h> | |
static evhtp_res print_data(evhtp_request_t * req, struct evbuffer * buf, void * arg); | |
static evhtp_res print_new_chunk_len(evhtp_request_t * req, uint64_t len, void * arg); |
function Set(list) | |
local set = {} | |
for _, l in ipairs(list) do | |
set[l] = true | |
end | |
return set | |
end |
cmake_minimum_required(VERSION 2.4) | |
add_custom_target(do_always ALL COMMAND yum -y install cmake git gcc gcc-c++ openssl-devel libtool autoconf flex bison zip) | |
include (ExternalProject) | |
ExternalProject_add(gmp | |
URL http://packages.strcpy.net/gmp-5.1.3.tar.bz2 | |
UPDATE_COMMAND "" | |
BUILD_IN_SOURCE 1 |
Original tweet that started it all
#define lz_safe_free(_var, _freefn) do { \
_freefn((_var)); \
(_var) = NULL; \
} while (0)
I hereby claim:
To claim this, I am signing this object:
#!/usr/bin/env bash | |
C_RST='\e[0m' | |
C_BLUE='\e[0;34m' | |
C_RED='\e[0;31m' | |
C_BRED='\e[1;31m' | |
C_BGREEN='\e[1;32m' | |
C_BBLUE='\e[1;34m' | |
C_BMAGENTA='\e[1;35m' |
evhtpexp app = express(); | |
express_cb_s foocb = onGet(app, "/foo", | |
func void(evreq r, void * a) { | |
reply(r, "FOOO"); | |
}); | |
express_cb_s barcb = onGet(app, "/bar", | |
func void(evreq r, void * a) { | |
reply(r, "BARRR"); |
struct query { | |
struct event * r_pipe_ev; | |
int r_pipe; /* response pipe */ | |
int q_pipe; /* query pipe */ | |
int response[256]; | |
}; | |
static void | |
read_response(int sock, short events, void * arg) { | |
struct query * q = (struct query *)arg; |