Created
January 18, 2014 21:09
-
-
Save haberman/8496487 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fake upb: a fake implementation for a small subset of the | |
// actual upb interface, for testing with Rust. | |
#include <stdint.h> | |
#include <stdbool.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct { | |
uint32_t refcount; | |
uint32_t number; | |
} upb_fielddef; | |
bool upb_fielddef_setnumber(upb_fielddef *f, uint32_t number) { | |
fprintf(stderr, "C: setnumber(%d)\n", number); | |
f->number = number; | |
return true; | |
} | |
uint32_t upb_fielddef_number(const upb_fielddef *f) { | |
fprintf(stderr, "C: number() = %d\n", f->number); | |
return f->number; | |
} | |
upb_fielddef *upb_fielddef_new() { | |
fprintf(stderr, "C: new()\n"); | |
upb_fielddef *f = malloc(sizeof(*f)); | |
f->refcount = 1; | |
f->number = 1; | |
return f; | |
} | |
void upb_fielddef_ref(upb_fielddef *f) { | |
fprintf(stderr, "C: ref() = %d -> %d\n", f->refcount, f->refcount + 1); | |
f->refcount++; | |
} | |
void upb_fielddef_unref(upb_fielddef *f) { | |
fprintf(stderr, "C: unref() = %d -> %d\n", f->refcount, f->refcount - 1); | |
if (--f->refcount == 0) { | |
free(f); | |
} | |
} | |
void upb_fielddef_freeze(upb_fielddef *f) { | |
fprintf(stderr, "C: freeze() = %d\n", f->refcount); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment