static enum BLError Generic_finalize(aSELF) { BL_SELF(Generic); CT_DEBUG(CTLIB, ("(Generic) finalizing bitfield (offset=%d.%d)", (int) self->offset, self->bit_offset)); self->offset += (self->bit_offset + (BITS(1)-1)) / BITS(1); CT_DEBUG(CTLIB, ("(Generic) final offset=%d", (int) self->offset)); return BLE_NO_ERROR; }
void get_basic_type_spec_string(pTHX_ SV **sv, u_32 flags) { struct { u_32 flag; const char *str; } *pSpec, spec[] = { {T_SIGNED, "signed" }, {T_UNSIGNED, "unsigned"}, {T_SHORT, "short" }, {T_LONGLONG, "long" }, {T_LONG, "long" }, {T_VOID, "void" }, {T_CHAR, "char" }, {T_INT , "int" }, {T_FLOAT , "float" }, {T_DOUBLE , "double" }, {0, NULL } }; int first = 1; CT_DEBUG(MAIN, (XSCLASS "::get_basic_type_spec_string( sv=%p, flags=0x%08lX )", sv, (unsigned long) flags)); for (pSpec = spec; pSpec->flag; ++pSpec) { if (pSpec->flag & flags) { if (*sv) sv_catpvf(*sv, first ? "%s" : " %s", pSpec->str); else *sv = newSVpv(CONST_CHAR(pSpec->str), 0); first = 0; } } }
void ctss_free_node_state(CTSS_DSPNode *node) { if (node->state != NULL) { CT_DEBUG("free node state..."); CTSS_FREE(node->state); CTSS_FREE(node->id); } }
long dimtag_eval(pTHX_ const DimensionTag *dim, long avail, SV *self, HV *parent) { assert(dim != NULL); assert(self != NULL); CT_DEBUG(MAIN, ("dimtag_eval(%p(%d), %ld, %p, %p)", dim, (int)dim->type, avail, self, parent)); switch (dim->type) { case DTT_FLEXIBLE: return avail; case DTT_FIXED: return (long) dim->u.fixed; case DTT_MEMBER: return dimension_from_member(aTHX_ dim->u.member, parent); case DTT_HOOK: return dimension_from_hook(aTHX_ dim->u.hook, self, parent); case DTT_NONE: fatal("Invalid dimension tag type in dimtag_get()"); break; default: fatal("Unknown dimension tag type (%d) in dimtag_get()", (int) dim->type); break; } assert(0); return 0; }
int ctss_add_global_lfo(CTSS_Synth *synth, CTSS_DSPNode *lfo) { CT_CHECK(synth->numLFO < CTSS_MAX_LFO, "max LFOs reached: %d", CTSS_MAX_LFO); CT_DEBUG("add LFO: %s (%u)", lfo->id, synth->numLFO); synth->lfo[synth->numLFO] = lfo; synth->numLFO++; return 0; fail: return 1; }
static enum BLError Simple_push(aSELF, const BLPushParam *pParam) { BL_SELF(Simple); BitfieldInfo *bit; assert(pParam->pDecl != NULL); assert(pParam->pDecl->bitfield_flag); bit = &pParam->pDecl->ext.bitfield; if (bit->bits == 0) { self->pos += self->block_size; self->bits_left = BITS(self->block_size); } else { if (bit->bits > self->bits_left) { self->pos += self->block_size; self->bits_left = BITS(self->block_size); } pParam->pDecl->offset = self->offset + self->pos; pParam->pDecl->size = self->block_size; bit->size = (unsigned char) self->block_size; switch (self->byte_order) { case BLPV_LITTLE_ENDIAN: bit->pos = BITS(self->block_size) - self->bits_left; break; case BLPV_BIG_ENDIAN: bit->pos = self->bits_left - bit->bits; break; default: fatal_error("(Simple) invalid byte-order (%d)", self->byte_order); break; } self->bits_left -= bit->bits; CT_DEBUG(CTLIB, ("(Simple) new %s bitfield (%s) at (offset=%d, size=%d, pos=%d, bits=%d), bits_left=%d", BYTE_ORDER_STRING, pParam->pDecl->identifier, pParam->pDecl->offset, pParam->pDecl->size, bit->pos, bit->bits, self->bits_left)); } return BLE_NO_ERROR; }
SV *hook_call(pTHX_ SV *self, const char *id_pre, const char *id, const TypeHooks *pTH, enum HookId hook_id, SV *in, int mortal) { CT_DEBUG(MAIN, ("hook_call(id='%s%s', pTH=%p, in=%p(%d), mortal=%d)", id_pre, id, pTH, in, (int) SvREFCNT(in), mortal)); assert(self != NULL); assert(pTH != NULL); assert(id != NULL); assert(in != NULL); return single_hook_call(aTHX_ self, gs_HookIdStr[hook_id], id_pre, id, &pTH->hooks[hook_id], in, mortal); }
BitfieldLayouter bl_create(const char *class_name) { BitfieldLayouter self; unsigned i; const struct BLClass *pc = NULL; assert(class_name != NULL); CT_DEBUG(CTLIB, ("trying to create new [%s] bitfield layouter", class_name)); for (i = 0; i < sizeof bl_classes / sizeof bl_classes[0]; i++) if (strcmp(class_name, bl_classes[i].name) == 0) { pc = &bl_classes[i]; break; } if (pc == NULL) { CT_DEBUG(CTLIB, ("no such bitfield layouter class [%s]", class_name)); return NULL; } AllocF(BitfieldLayouter, self, pc->size); memset(self, 0, pc->size); self->blc = pc; self->m = pc->vtbl; if (self->m->init) self->m->init(self); CT_DEBUG(CTLIB, ("created new [%s] bitfield layouter", class_name)); return self; }
static long dimension_from_hook(pTHX_ SingleHook *hook, SV *self, HV *parent) { dTHR; dXCPT; SV *sv, *in; long rv; assert(hook != NULL); assert(self != NULL); in = parent ? newRV_inc((SV *) parent) : NULL; sv = NULL; XCPT_TRY_START { sv = single_hook_call(aTHX_ self, "dimension", NULL, NULL, hook, in, 0); } XCPT_TRY_END XCPT_CATCH { if (parent) { CT_DEBUG(MAIN, ("freeing sv @ %p in dimension_from_hook:%d", in, __LINE__)); SvREFCNT_dec(in); } XCPT_RETHROW; } assert(sv != NULL); rv = sv_to_dimension(aTHX_ sv, NULL); SvREFCNT_dec(sv); return rv; }
static enum BLError Microsoft_push(aSELF, const BLPushParam *pParam) { BL_SELF(Microsoft); BitfieldInfo *bit; assert(pParam->pDecl != NULL); assert(pParam->pDecl->bitfield_flag); bit = &pParam->pDecl->ext.bitfield; if (self->cur_type_size != (int) pParam->type_size) { int delta; int align = (int) pParam->type_align < self->max_align ? (int) pParam->type_align : self->max_align; if (align > self->align) self->align = align; if (self->bit_offset > 0) { self->offset += self->cur_type_size; self->bit_offset = 0; } delta = self->offset % align; if (delta) { self->offset += align - delta; self->bit_offset = 0; } self->cur_type_size = pParam->type_size; self->cur_type_align = align; } if (bit->bits == 0) { if (self->bit_offset > 0) { self->offset += self->cur_type_size; self->bit_offset = 0; } } else { if (bit->bits > BITS(self->cur_type_size) - self->bit_offset) { if (bit->bits > BITS(self->cur_type_size)) return BLE_BITFIELD_TOO_WIDE; self->offset += self->cur_type_size; self->bit_offset = 0; } switch (self->byte_order) { case BLPV_LITTLE_ENDIAN: bit->pos = self->bit_offset; break; case BLPV_BIG_ENDIAN: bit->pos = BITS(self->cur_type_size) - self->bit_offset - bit->bits; break; default: fatal_error("(Microsoft) invalid byte-order (%d)", self->byte_order); break; } assert(bit->pos < 64); self->bit_offset += bit->bits; pParam->pDecl->offset = self->offset; pParam->pDecl->size = self->cur_type_size; bit->size = self->cur_type_size; CT_DEBUG(CTLIB, ("(Microsoft) new %s bitfield (%s) at (offset=%d, size=%d, pos=%d, bits=%d), bit_offset=%d", BYTE_ORDER_STRING, pParam->pDecl->identifier, pParam->pDecl->offset, bit->size, bit->pos, bit->bits, self->bit_offset)); } return BLE_NO_ERROR; }
static enum BLError Generic_push(aSELF, const BLPushParam *pParam) { BL_SELF(Generic); BitfieldInfo *bit; assert(pParam->pDecl != NULL); assert(pParam->pDecl->bitfield_flag); bit = &pParam->pDecl->ext.bitfield; CT_DEBUG(CTLIB, ("(Generic) pushing bitfield (%s:%d/s=%d/a=%d), offset=%d.%d, max_align=%d", pParam->pDecl->identifier, bit->bits, pParam->type_size, pParam->type_align, (int) self->offset, self->bit_offset, (int) self->max_align)); if (self->cur_type_size != (int) pParam->type_size) { int align = (int) pParam->type_align < self->max_align ? (int) pParam->type_align : self->max_align; int delta = self->offset % align; if (align > self->align) self->align = align; self->offset -= delta; self->bit_offset += BITS(delta); CT_DEBUG(CTLIB, ("(Generic) type size change: size: %d -> %d, align: %d -> %d, offset=%d.%d", self->cur_type_size, pParam->type_size, self->cur_type_align, align, (int) self->offset, self->bit_offset)); self->cur_type_size = pParam->type_size; self->cur_type_align = align; } while (bit->bits > BITS(self->cur_type_size) - self->bit_offset) { self->offset += self->cur_type_align; if (self->bit_offset > BITS(self->cur_type_align)) self->bit_offset -= BITS(self->cur_type_align); else self->bit_offset = 0; CT_DEBUG(CTLIB, ("(Generic) move offset -> %d.%d", (int) self->offset, self->bit_offset)); } if (bit->bits == 0) { if (self->bit_offset > 0) { self->offset += self->cur_type_size - (self->offset % self->cur_type_size); self->bit_offset = 0; } } else { int used_bytes, new_bit_offset; new_bit_offset = self->bit_offset + bit->bits; if (new_bit_offset <= BITS(1)) used_bytes = 1; else if (new_bit_offset <= BITS(2)) used_bytes = 2; else if (new_bit_offset <= BITS(4)) used_bytes = 4; else if (new_bit_offset <= BITS(8)) used_bytes = 8; assert(used_bytes <= self->cur_type_size); pParam->pDecl->offset = self->offset; pParam->pDecl->size = used_bytes; bit->size = used_bytes; switch (self->byte_order) { case BLPV_LITTLE_ENDIAN: bit->pos = self->bit_offset; break; case BLPV_BIG_ENDIAN: bit->pos = BITS(used_bytes) - self->bit_offset - bit->bits; break; default: fatal_error("(Generic) invalid byte-order (%d)", self->byte_order); break; } assert(bit->pos < 64); self->bit_offset = new_bit_offset; } CT_DEBUG(CTLIB, ("(Generic) new %s bitfield (%s) at (offset=%d, size=%d, pos=%d, bits=%d)", BYTE_ORDER_STRING, pParam->pDecl->identifier, pParam->pDecl->offset, bit->size, bit->pos, bit->bits)); return BLE_NO_ERROR; }
SV *single_hook_call(pTHX_ SV *self, const char *hook_id_str, const char *id_pre, const char *id, const SingleHook *hook, SV *in, int mortal) { dSP; int count; SV *out; CT_DEBUG(MAIN, ("single_hook_call(hid='%s', id='%s%s', hook=%p, in=%p(%d), mortal=%d)", hook_id_str, id_pre, id, hook, in, in ? (int) SvREFCNT(in) : 0, mortal)); assert(self != NULL); assert(hook != NULL); if (hook->sub == NULL) return in; ENTER; SAVETMPS; PUSHMARK(SP); if (hook->arg) { I32 ix, len; len = av_len(hook->arg); for (ix = 0; ix <= len; ++ix) { SV **pSV = av_fetch(hook->arg, ix, 0); SV *sv; if (pSV == NULL) fatal("NULL returned by av_fetch() in single_hook_call()"); if (SvROK(*pSV) && sv_isa(*pSV, ARGTYPE_PACKAGE)) { HookArgType type = (HookArgType) SvIV(SvRV(*pSV)); switch (type) { case HOOK_ARG_SELF: sv = sv_mortalcopy(self); break; case HOOK_ARG_DATA: assert(in != NULL); sv = sv_mortalcopy(in); break; case HOOK_ARG_TYPE: assert(id != NULL); sv = sv_newmortal(); if (id_pre) { sv_setpv(sv, id_pre); sv_catpv(sv, CONST_CHAR(id)); } else sv_setpv(sv, id); break; case HOOK_ARG_HOOK: if (hook_id_str) { sv = sv_newmortal(); sv_setpv(sv, hook_id_str); } else { sv = &PL_sv_undef; } break; default: fatal("Invalid hook argument type (%d) in single_hook_call()", type); break; } } else sv = sv_mortalcopy(*pSV); XPUSHs(sv); } } else { if (in) { /* only push the data argument */ XPUSHs(in); } } PUTBACK; count = call_sv(hook->sub, G_SCALAR); SPAGAIN; if (count != 1) fatal("Hook returned %d elements instead of 1", count); out = POPs; CT_DEBUG(MAIN, ("single_hook_call: in=%p(%d), out=%p(%d)", in, in ? (int) SvREFCNT(in) : 0, out, (int) SvREFCNT(out))); if (!mortal && in != NULL) SvREFCNT_dec(in); SvREFCNT_inc(out); PUTBACK; FREETMPS; LEAVE; if (mortal) sv_2mortal(out); CT_DEBUG(MAIN, ("single_hook_call: out=%p(%d)", out, (int) SvREFCNT(out))); return out; }
static int load_indexed_hash_module_ex(pTHX_ CBC *THIS, const char **modlist, int num) { const char *p = NULL; int i; if (THIS->ixhash != NULL) { /* a module has already been loaded */ return 1; } for (i = 0; i < num; i++) { if (modlist[i]) { SV *sv = newSVpvn("require ", 8); sv_catpv(sv, CONST_CHAR(modlist[i])); CT_DEBUG(MAIN, ("trying to require \"%s\"", modlist[i])); (void) eval_sv(sv, G_DISCARD); SvREFCNT_dec(sv); if ((sv = get_sv("@", 0)) != NULL && strEQ(SvPV_nolen(sv), "")) { p = modlist[i]; break; } if (i == 0) { Perl_warn(aTHX_ "Couldn't load %s for member ordering, " "trying default modules", modlist[i]); } CT_DEBUG(MAIN, ("failed: \"%s\"", sv ? SvPV_nolen(sv) : "[NULL]")); } } if (p == NULL) { SV *sv = newSVpvn("", 0); for (i = 1; i < num; i++) { if (i > 1) { if (i == num-1) sv_catpvn(sv, " or ", 4); else sv_catpvn(sv, ", ", 2); } sv_catpv(sv, CONST_CHAR(modlist[i])); } Perl_warn(aTHX_ "Couldn't load a module for member ordering " "(consider installing %s)", SvPV_nolen(sv)); return 0; } CT_DEBUG(MAIN, ("using \"%s\" for member ordering", p)); THIS->ixhash = p; return 1; }
void ctss_trace_node(CTSS_DSPNode *node) { CT_DEBUG("-- %s --", node->id); for (int i = 0; i < AUDIO_BUFFER_SIZE; i++) { CT_DEBUG("%03d: %f, ", i, node->buf[i]); } }
void ctss_free_node(CTSS_DSPNode *node) { CT_DEBUG("free node: %s", node->id); ctss_free_node_state(node); CTSS_FREE(node); }
static long dimension_from_member(pTHX_ const char *member, HV *parent) { MemberExprWalker walker; int success = 1; SV *sv = NULL; dTHR; dXCPT; assert(member != NULL); if (parent == NULL) { WARN((aTHX_ "Missing parent to look up '%s'", member)); return 0; } CT_DEBUG(MAIN, ("trying to get dimension from member, walking \"%s\"", member)); walker = member_expr_walker_new(aTHX_ member, 0); XCPT_TRY_START { for (;;) { struct me_walk_info mei; member_expr_walker_walk(aTHX_ walker, &mei); if (mei.retval == MERV_END) { break; lookup_failed: success = 0; break; } switch (mei.retval) { case MERV_COMPOUND_MEMBER: { const char *name = mei.u.compound_member.name; HV *hv = parent; SV **psv; CT_DEBUG(MAIN, ("found compound member \"%s\"", name)); if (sv) { SV *hash; if (SvROK(sv) && SvTYPE(hash = SvRV(sv)) == SVt_PVHV) { hv = (HV *) hash; } else { WARN((aTHX_ "Expected a hash reference to look up member '%s'" " in '%s', not %s", name, member, identify_sv(sv))); goto lookup_failed; } } psv = hv_fetch(hv, name, mei.u.compound_member.name_length, 0); if (psv) { SvGETMAGIC(*psv); sv = *psv; } else { WARN((aTHX_ "Cannot find member '%s' in hash (in '%s')", name, member)); goto lookup_failed; } } break; case MERV_ARRAY_INDEX: { long last, index = mei.u.array_index; AV *av; SV *array; SV **psv; assert(sv != NULL); CT_DEBUG(MAIN, ("found array index \"%ld\"", index)); if (SvROK(sv) && SvTYPE(array = SvRV(sv)) == SVt_PVAV) { av = (AV *) array; } else { WARN((aTHX_ "Expected an array reference to look up index '%ld'" " in '%s', not %s", index, member, identify_sv(sv))); goto lookup_failed; } last = (long) av_len(av); if (index > last) { WARN((aTHX_ "Cannot lookup index '%ld' in array of size" " '%ld' (in '%s')", index, last + 1, member)); goto lookup_failed; } psv = av_fetch(av, index, 0); if (psv == NULL) { fatal("cannot find index '%ld' in array of size '%ld' (in '%s')", index, last + 1, member); } SvGETMAGIC(*psv); sv = *psv; } break; default: fatal("unexpected return value (%d) in dimension_from_member('%s')", (int) mei.retval, member); break; } } } XCPT_TRY_END member_expr_walker_delete(aTHX_ walker); XCPT_CATCH { XCPT_RETHROW; } if (success) { assert(sv != NULL); return sv_to_dimension(aTHX_ sv, member); } return 0; }