Skip to content

Instantly share code, notes, and snippets.

Roi Lipman swilly22

Block or report user

Report or block swilly22

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View longjmp.c
// ExecutionPlan.c
function Query_Execute() {
/* Set an exception-handling breakpoint to capture run-time errors.
* encountered_error will be set to 0 when setjmp is invoked, and will be nonzero if
* a downstream exception returns us to this breakpoint. */
QueryCtx *ctx = pthread_getspecific(_tlsQueryCtxKey);
if(!ctx->breakpoint) ctx->breakpoint = rm_malloc(sizeof(jmp_buf));
int encountered_error = setjmp(*ctx->breakpoint);
if(encountered_error) {
View threadjump.c
function Query_Execute() {
/* Call ExecutionPlan_Execute on a different thread
* and wait for it to exit */
char *error = NULL;
pthread_t thread;
pthread_create(&thread, NULL, ExecutionPlan_Execute, NULL);
pthread_join(thread, &error);
if(error != NULL) {
// Exception been thrown.
View illegaljump.c
function A() {
jump there; // Can't jump outside of current scope.
}
function B() {
there:
...
}
View trycatch.c
try {
// Perform work which might throw an exception
work();
} catch (error *e) {
reportError(e);
}
View trycatch.c
try {
// Perform work which might throw an exception
work();
} catch (error *e) {
reportError(e);
}
View throw.py
if(cond) {
raise Exception("something went wrong")
}
View toUpper.c
SIValue toUpper(SIValue v) {
SIType actual_type = SI_TYPE(v);
if(actual_type != SI_STRING) {
const char *actual_type_str = SIType_ToString(actual_type);
raise("Type mismatch: expected string but was %s", actual_type_str);
}
}
View WithGoTo.c
void f(void) {
void *a = NULL;
void *b = NULL;
void *c = NULL;
a = malloc(32);
//...
if(cond1) goto cleanup;
b = malloc(64);
View WithoutGoto.c
void f(void) {
void *a = NULL;
void *b = NULL;
void *c = NULL;
a = malloc(32);
//...
if(cond1) {
free(a)
return;
@swilly22
swilly22 / dictInit.c
Created Feb 15, 2018
redis dict init
View dictInit.c
uint64_t dictStringHash(const void *key) {
return dictGenHashFunction(key, strlen(key));
}
void *dictStringDup(void *privdata, const void *key) {
DICT_NOTUSED(privdata);
size_t key_len = strlen(key);
char *copy = malloc((key_len + 1) * sizeof(char));
strcpy(copy, key);
copy[key_len] = 0;
You can’t perform that action at this time.