/* Print a ref */ void debug_print_full_ref(const ref *pref) { unsigned size = r_size(pref); ref nref; dprintf1("(%x)", r_type_attrs(pref)); switch ( r_type(pref) ) { case t_array: dprintf2("array(%u)0x%lx", size, (ulong)pref->value.refs); break; case t_boolean: dprintf1("boolean %x", pref->value.index); break; case t_condition: dprintf1("condition 0x%lx", (ulong)pref->value.pcond); break; case t_device: dprintf1("device 0x%lx", (ulong)pref->value.pdevice); break; case t_dictionary: dprintf3("dict(%u/%u)0x%lx", dict_length(pref), dict_maxlength(pref), (ulong)pref->value.pdict); break; case t_file: dprintf1("file 0x%lx", (ulong)pref->value.pfile); break; case t_gstate: dprintf1("gstate 0x%lx", (ulong)pref->value.pgstate); break; case t_integer: dprintf1("int %ld", pref->value.intval); break; case t_lock: dprintf1("lock 0x%lx", (ulong)pref->value.plock); break; case t_mark: dprintf("mark"); break; case t_mixedarray: dprintf2("mixed packedarray(%u)0x%lx", size, (ulong)pref->value.packed); break; case t_name: dprintf2("name(0x%lx#%x)", (ulong)pref->value.pname, name_index(pref)); debug_print_name(pref); break; case t_null: dprintf("null"); break; case t_oparray: dprintf1("op_array(0x%x)", size); name_index_ref(op_array_nx_table[size - op_def_count], &nref); debug_print_name(&nref); break; case t_operator: dprintf1("op(0x%x", size); if ( size ) dprintf1(":%s", (const char *)(op_def_table[size]->oname + 1)); dprintf1(")0x%lx", (ulong)pref->value.opproc); break; case t_real: dprintf1("real %f", pref->value.realval); break; case t_shortarray: dprintf2("short packedarray(%u)0x%lx", size, (ulong)pref->value.packed); break; case t_string: dprintf2("string(%u)0x%lx", size, (ulong)pref->value.bytes); break; default: dprintf1("type 0x%x", r_type(pref)); } }
void debug_print_packed_ref(const ref_packed *pref) { ushort elt = *pref; ref nref; switch ( elt >> packed_type_shift ) { case pt_executable_operator: dprintf("<op_name>"); elt &= packed_int_mask; op_index_ref(elt, &nref); debug_print_ref(&nref); break; case pt_integer: dprintf1("<int> %d", (int)(elt & packed_int_mask) + packed_min_intval); break; case pt_literal_name: case pt_literal_name+1: dprintf("<lit_name>"); elt &= packed_max_name_index; goto ptn; case pt_executable_name: case pt_executable_name+1: dprintf("<exec_name>"); elt &= packed_max_name_index; ptn: name_index_ref(elt, &nref); dprintf2("(0x%lx#%x)", (ulong)nref.value.pname, elt); debug_print_name(&nref); break; } }
/* * Look up a name on the dictionary stack. * Return the pointer to the value if found, 0 if not. */ ref * dstack_find_name_by_index(dict_stack_t * pds, uint nidx) { ds_ptr pdref = pds->stack.p; /* Since we know the hash function is the identity function, */ /* there's no point in allocating a separate variable for it. */ #define hash dict_name_index_hash(nidx) ref_packed kpack = packed_name_key(nidx); do { dict *pdict = pdref->value.pdict; uint size = npairs(pdict); const gs_memory_t *mem = dict_mem(pdict); #ifdef DEBUG if (gs_debug_c('D')) { ref dnref; name_index_ref(mem, nidx, &dnref); dlputs("[D]lookup "); debug_print_name(mem, &dnref); dprintf3(" in 0x%lx(%u/%u)\n", (ulong) pdict, dict_length(pdref), dict_maxlength(pdref)); } #endif #define INCR_DEPTH(pdref)\ INCR(depth[min(MAX_STATS_DEPTH, pds->stack.p - pdref)]) if (dict_is_packed(pdict)) { packed_search_1(INCR_DEPTH(pdref), return packed_search_value_pointer, DO_NOTHING, goto miss); packed_search_2(INCR_DEPTH(pdref), return packed_search_value_pointer, DO_NOTHING, break); miss:; } else { ref *kbot = pdict->keys.value.refs; register ref *kp; int wrap = 0; /* Search the dictionary */ for (kp = kbot + dict_hash_mod(hash, size) + 2;;) { --kp; if (r_has_type(kp, t_name)) { if (name_index(mem, kp) == nidx) { INCR_DEPTH(pdref); return pdict->values.value.refs + (kp - kbot); } } else if (r_has_type(kp, t_null)) { /* Empty, deleted, or wraparound. */ /* Figure out which. */ if (!r_has_attr(kp, a_executable)) break; if (kp == kbot) { /* wrap */ if (wrap++) break; /* 2 wraps */ kp += size + 1; } } } } #undef INCR_DEPTH }