Error setbyte_blob_(Stack *S, Stack *scope_arr) { require(3); V blob = popS(); V index = popS(); V value = popS(); Error e = Nothing; if (getType(blob) != T_BLOB || getType(index) != T_NUM || getType(value) != T_NUM) { e = TypeError; goto cleanup; } int num = toNumber(value); if (num < 0 || num > 255) { set_error_msg("Value not in range [0,255]"); e = ValueError; goto cleanup; } int byte = setbyte_blob(blob, toNumber(index), num); if (byte < 0) { set_error_msg("Index out of range"); e = ValueError; goto cleanup; } cleanup: clear_ref(blob); clear_ref(index); clear_ref(value); return e; }
Error ends_with(Stack* S, Stack* scope_arr) { require(2); V haystack = popS(); V needle = popS(); if (getType(needle) != T_STR || getType(haystack) != T_STR) { clear_ref(needle); clear_ref(haystack); return TypeError; } NewString *needle_s = toNewString(needle); NewString *haystack_s = toNewString(haystack); if (needle_s->size > haystack_s->size || memcmp(haystack_s->text + haystack_s->size - needle_s->size, needle_s->text, needle_s->size)) { pushS(add_ref(v_false)); } else { pushS(add_ref(v_true)); } clear_ref(needle); clear_ref(haystack); return Nothing; }
V load_file(V file_name, V global) { if (file_name == NULL || getType(file_name) != T_STR) { clear_ref(file_name); return NULL; } FILE* f = fopen(toNewString(file_name)->text, "rb"); if (f == NULL) { clear_ref(file_name); return NULL; } fseek(f, 0, SEEK_END); size_t length = ftell(f); rewind(f); char *data = malloc(length * sizeof(char)); size_t read = fread(data, sizeof(char), length, f); assert (read == length); V new_file = load_memfile(data, length, file_name, global); free(data); fclose(f); clear_ref(file_name); return new_file; }
Error concat_list(Stack *S, Stack *scope_arr) /* concat [ "a" "b" "c" ] */ { NewString *s1; int i; require(1); V v1 = popS(); if (getType(v1) == T_LIST) { int newlength = 0; int u = toStack(v1)->used; V *n = toStack(v1)->nodes; for (i = u - 1; i >= 0; i--) { if (getType(n[i]) != T_STR) { clear_ref(v1); return TypeError; } newlength += toNewString(n[i])->size; } char *new = malloc(newlength + 1); char *currpoint = new; for (i = u - 1; i >= 0; i--) { s1 = toNewString(n[i]); memcpy(currpoint, s1->text, s1->size); currpoint += s1->size; } *currpoint = '\0'; pushS(str_to_string(newlength, new)); clear_ref(v1); return Nothing; }
static void clear_references (GstVaapiEncoderVP8 * encoder) { clear_ref (encoder, &encoder->last_ref); clear_ref (encoder, &encoder->golden_ref); clear_ref (encoder, &encoder->alt_ref); }
bool delete_hashmap(HashMap *hm, V key) { if (hm->map == NULL) { return false; } Bucket **bprev = &hm->map[get_hash(key) % hm->size]; Bucket *b = *bprev; while (b != NULL) { if (equal(key, b->key)) { *bprev = b->next; clear_ref(b->key); clear_ref(b->value); free(b); hm->used--; if ((hm->used < hm->size / 2) && (hm->size > 16)) { resize_hashmap(hm, hm->size / 2); } return true; } bprev = &(*bprev)->next; b = b->next; } return false; }
Error chr(Stack* S, Stack* scope_arr) { require(1); V v = popS(); if (getType(v) != T_NUM) { clear_ref(v); return TypeError; } pushS(unichar_to_value(toNumber(v))); clear_ref(v); return Nothing; }
Error make_blob(Stack *S, Stack *scope_arr) { require(1); V v = popS(); if (getType(v) != T_NUM) { clear_ref(v); return TypeError; } pushS(new_blob(toNumber(v))); clear_ref(v); return Nothing; }
Error resize_blob_(Stack *S, Stack *scope_arr) { require(2); V blob = popS(); V newsize = popS(); Error e = Nothing; if (getType(blob) != T_BLOB || getType(newsize) != T_NUM) { e = TypeError; goto cleanup; } resize_blob(blob, toNumber(newsize)); cleanup: clear_ref(blob); clear_ref(newsize); return e; }
Error concat(Stack *S, Stack *scope_arr) /* concat( "a" "b" "c" ) */ { NewString *s1; int i; require(1); V v1 = popS(); int newlength = 0; for (i = S->used - 1; i >= 0; i--) { int t = getType(S->nodes[i]); if (t == T_IDENT && S->nodes[i] == get_ident(")")) { break; } else if (t != T_STR) { clear_ref(v1); return TypeError; } newlength += toNewString(S->nodes[i])->size; } char *new = malloc(newlength + 1); char *currpoint = new; for (i = S->used - 1; i >= 0; i--) { if (getType(S->nodes[i]) == T_IDENT && S->nodes[i] == get_ident(")")) { clear_ref(popS()); break; } s1 = toNewString(S->nodes[i]); memcpy(currpoint, s1->text, s1->size); currpoint += s1->size; clear_ref(popS()); } *currpoint = '\0'; pushS(str_to_string(newlength, new)); clear_ref(v1); return Nothing; }
Error ord(Stack* S, Stack* scope_arr) { require(1); V v = popS(); if (getType(v) != T_STR) { clear_ref(v); return TypeError; } NewString *s = toNewString(v); if (s->size == 0) { clear_ref(v); return ValueError; } utf8index n = 0; pushS(int_to_value(decode_codepoint(s->text, &n))); clear_ref(v); return Nothing; }
static void push_reference (GstVaapiEncoderMpeg2 * encoder, GstVaapiSurfaceProxy * ref) { if (encoder->backward) { clear_ref (encoder, &encoder->forward); encoder->forward = encoder->backward; encoder->backward = NULL; } if (encoder->forward) encoder->backward = ref; else encoder->forward = ref; }
static void push_reference (GstVaapiEncoderVP8 * encoder, GstVaapiSurfaceProxy * ref) { if (encoder->last_ref == NULL) { encoder->golden_ref = gst_vaapi_surface_proxy_ref (ref); encoder->alt_ref = gst_vaapi_surface_proxy_ref (ref); } else { clear_ref (encoder, &encoder->alt_ref); encoder->alt_ref = encoder->golden_ref; encoder->golden_ref = encoder->last_ref; } encoder->last_ref = ref; }
Error blit_blob_(Stack *S, Stack *scope_arr) { require(3); V dest = popS(); V src = popS(); V offset = popS(); Error e = Nothing; if (getType(dest) != T_BLOB || getType(src) != T_BLOB || getType(offset) != T_NUM) { e = TypeError; goto cleanup; } if (blit_blob(dest, src, toNumber(offset)) < 0) { set_error_msg("Index out of range"); e = ValueError; goto cleanup; } cleanup: clear_ref(dest); clear_ref(src); clear_ref(offset); return e; }
Error getbyte_blob_(Stack *S, Stack *scope_arr) { require(2); V blob = popS(); V index = popS(); Error e = Nothing; if (getType(blob) != T_BLOB || getType(index) != T_NUM) { e = TypeError; goto cleanup; } int byte = getbyte_blob(blob, toNumber(index)); if (byte < 0) { set_error_msg("Index out of range"); e = ValueError; goto cleanup; } pushS(int_to_value(byte)); cleanup: clear_ref(blob); clear_ref(index); return e; }
Error clone_blob_(Stack *S, Stack *scope_arr) { require(1); V blob = popS(); Error e = Nothing; if (getType(blob) != T_BLOB) { e = TypeError; goto cleanup; } pushS(clone_blob(blob)); cleanup: clear_ref(blob); return e; }
bool change_bucket(Bucket* b, V key, V value) { if (equal(b->key, key)) { V tmp = b->value; b->value = add_ref(value); clear_ref(tmp); return true; } if (b->next == NULL) { return false; } else { return change_bucket(b->next, key, value); } }
Error chars(Stack* S, Stack* scope_arr) { require(1); V source = popS(); if (getType(source) != T_STR) { clear_ref(source); return TypeError; } utf8 chrs = toNewString(source)->text; utf8index index = 0; V list = new_list(); Stack *st = toStack(list); size_t size = toNewString(source)->size; size_t i; for (i = 0; i < size; i++) { push(st, unichar_to_value(decode_codepoint(chrs, &index))); } pushS(list); return Nothing; }
Error count(Stack* S, Stack* scope_arr) { require(2); V haystack = popS(); V needle = popS(); if (getType(haystack) != T_STR || getType(needle) != T_STR) { clear_ref(haystack); clear_ref(needle); return TypeError; } size_t haystack_len = toNewString(haystack)->size; size_t needle_len = toNewString(needle)->size; if (needle_len == 0) { pushS(int_to_value(string_length(toNewString(haystack)) + 1)); clear_ref(haystack); clear_ref(needle); return Nothing; } utf8 haystack_c = toNewString(haystack)->text; utf8 needle_c = toNewString(needle)->text; utf8index ix; int count = 0; for (ix = 0; ix < haystack_len - needle_len + 1; ) { if (!memcmp(haystack_c + ix, needle_c, needle_len)) { count++; ix += needle_len; } else { ix = nextchar(haystack_c, ix); } } pushS(int_to_value(count)); clear_ref(haystack); clear_ref(needle); return Nothing; }
Error find(Stack* S, Stack* scope_arr) { require(2); V haystack = popS(); V needle = popS(); if (getType(needle) != T_STR || getType(haystack) != T_STR) { clear_ref(needle); clear_ref(haystack); return TypeError; } NewString *needle_s = toNewString(needle); NewString *haystack_s = toNewString(haystack); if (string_length(needle_s) <= string_length(haystack_s)) { size_t haystack_len = haystack_s->size; size_t needle_len = needle_s->size; utf8 haystack_c = haystack_s->text; utf8 needle_c = needle_s->text; utf8index ix; int i = 0; for (ix = 0; ix < haystack_len - needle_len + 1; ix = nextchar(haystack_c, ix)) { if (!memcmp(haystack_c + ix, needle_c, needle_len)) { pushS(int_to_value(i)); clear_ref(needle); clear_ref(haystack); return Nothing; } i++; } } pushS(int_to_value(-1)); clear_ref(needle); clear_ref(haystack); return Nothing; }
Error contains(Stack* S, Stack* scope_arr) { require(2); V haystack = popS(); V needle = popS(); if (getType(needle) != T_STR || getType(haystack) != T_STR) { clear_ref(needle); clear_ref(haystack); return TypeError; } NewString *needle_s = toNewString(needle); NewString *haystack_s = toNewString(haystack); if (string_length(needle_s) > string_length(haystack_s)) { pushS(add_ref(v_false)); } else { uint32_t i; utf8index index = 0; for (i = 0; i <= string_length(haystack_s) - string_length(needle_s); i++) { if (!memcmp(haystack_s->text + index, needle_s->text, needle_s->size)) { pushS(add_ref(v_true)); clear_ref(needle); clear_ref(haystack); return Nothing; } index = nextchar(haystack_s->text, index); } pushS(add_ref(v_false)); } clear_ref(needle); clear_ref(haystack); return Nothing; }
static void clear_references (GstVaapiEncoderMpeg2 * encoder) { clear_ref (encoder, &encoder->forward); clear_ref (encoder, &encoder->backward); }