1 /* 2 * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 // -*- C++ -*- 27 // Small program for unpacking specially compressed Java packages. 28 // John R. Rose 29 30 #include <sys/types.h> 31 32 #include <stdio.h> 33 #include <string.h> 34 #include <stdlib.h> 35 #include <stdarg.h> 36 37 #include "defines.h" 38 #include "bytes.h" 39 #include "utils.h" 40 #include "coding.h" 41 #include "bands.h" 42 43 #include "constants.h" 44 #include "unpack.h" 45 46 inline void band::abort(const char* msg) { u->abort(msg); } 47 inline bool band::aborting() { return u->aborting(); } 48 49 void band::readData(int expectedLength) { 50 CHECK; 51 assert(expectedLength >= 0); 52 assert(vs[0].cmk == cmk_ERROR); 53 if (expectedLength != 0) { 54 assert(length == 0); 55 length = expectedLength; 56 } 57 if (length == 0) { 58 assert((rplimit = cm.vs0.rp = u->rp) != null); 59 return; 60 } 61 assert(length > 0); 62 63 bool is_BYTE1 = (defc->spec == BYTE1_spec); 64 65 if (is_BYTE1) { 66 // No possibility of coding change. Sizing is exact. 67 u->ensure_input(length); 68 } else { 69 // Make a conservatively generous estimate of band size in bytes. 70 // Assume B == 5 everywhere. 71 // Assume awkward pop with all {U} values (2*5 per value) 72 jlong generous = (jlong) length * (B_MAX*3+1) + C_SLOP; 73 u->ensure_input(generous); 74 } 75 76 // Read one value to see what it might be. 77 int XB = _meta_default; 78 int cp1 = 0, cp2 = 0; 79 if (!is_BYTE1) { 80 // must be a variable-length coding 81 assert(defc->B() > 1 && defc->L() > 0); 82 // must have already read from previous band: 83 assert(bn >= BAND_LIMIT || bn <= 0 84 || bn == e_cp_Utf8_big_chars 85 || endsWith(name, "_lo") // preceded by _hi conditional band 86 || bn == e_file_options // preceded by conditional band 87 || u->rp == u->all_bands[bn-1].maxRP() 88 || u->all_bands[bn-1].defc == null); 89 90 value_stream xvs; 91 coding* valc = defc; 92 if (valc->D() != 0) { 93 valc = coding::findBySpec(defc->B(), defc->H(), defc->S()); 94 assert(!valc->isMalloc); 95 } 96 xvs.init(u->rp, u->rplimit, valc); 97 CHECK; 98 int X = xvs.getInt(); 99 if (valc->S() != 0) { 100 assert(valc->min <= -256); 101 XB = -1-X; 102 } else { 103 int L = valc->L(); 104 assert(valc->max >= L+255); 105 XB = X-L; 106 } 107 if (0 <= XB && XB < 256) { 108 // Skip over the escape value. 109 u->rp = xvs.rp; 110 cp1 = 1; 111 } else { 112 // No, it's still default. 113 XB = _meta_default; 114 } 115 } 116 117 if (XB <= _meta_canon_max) { 118 byte XB_byte = (byte) XB; 119 byte* XB_ptr = &XB_byte; 120 cm.init(u->rp, u->rplimit, XB_ptr, 0, defc, length, null); 121 CHECK; 122 } else { 123 NOT_PRODUCT(byte* meta_rp0 = u->meta_rp); 124 assert(u->meta_rp != null); 125 // Scribble the initial byte onto the band. 126 byte* save_meta_rp = --u->meta_rp; 127 byte save_meta_xb = (*save_meta_rp); 128 (*save_meta_rp) = (byte) XB; 129 cm.init(u->rp, u->rplimit, u->meta_rp, 0, defc, length, null); 130 (*save_meta_rp) = save_meta_xb; // put it back, just to be tidy 131 NOT_PRODUCT(cp2 = (int)(u->meta_rp - meta_rp0)); 132 } 133 rplimit = u->rp; 134 135 rewind(); 136 137 #ifndef PRODUCT 138 PRINTCR((3,"readFrom %s at %p [%d values, %d bytes, cp=%d/%d]", 139 (name?name:"(band)"), minRP(), length, size(), cp1, cp2)); 140 if (u->verbose_bands || u->verbose >= 4) dump(); 141 142 if (ix != null && u->verbose != 0 && length > 0) { 143 // Check referential integrity early, for easier debugging. 144 band saved = (*this); // save state 145 for (int i = 0; i < length; i++) { 146 int n = vs[0].getInt() - nullOK; 147 entry *ref = ix->get(n); 148 assert(ref != null || n == -1); 149 } 150 (*this) = saved; 151 } 152 #endif 153 } 154 155 #ifndef PRODUCT 156 void band::dump() { 157 band saved = (*this); // save state 158 const char* b_name = name; 159 char b_name_buf[100]; 160 if (b_name == null) { 161 char* bp = &b_name_buf[0]; 162 b_name = bp; 163 sprintf(bp, "#%d/%d", bn, le_kind); bp += strlen(bp); 164 if (le_bci != 0) { sprintf(bp, "/bci%d", le_bci); bp += strlen(bp); } 165 if (le_back != 0) { sprintf(bp, "/back%d", le_back); bp += strlen(bp); } 166 if (le_len != 0) { sprintf(bp, "/len%d", le_len); bp += strlen(bp); } 167 } 168 fprintf(u->errstrm, "band %s[%d]%s", b_name, length, (length==0?"\n":" {")); 169 if (length > 0) { 170 for (int i = 0; i < length; i++) { 171 const char* eol = (length > 10 && i % 10 == 0) ? "\n" : " "; 172 fprintf(u->errstrm, "%s%d", eol, vs[0].getInt()); 173 } 174 fprintf(u->errstrm, " }\n"); 175 } 176 (*this) = saved; 177 } 178 #endif 179 180 void band::setIndex(cpindex* ix_) { 181 assert(ix_ == null || ixTag == ix_->ixTag); 182 ix = ix_; 183 } 184 void band::setIndexByTag(byte tag) { 185 setIndex(u->cp.getIndex(tag)); 186 } 187 188 entry* band::getRefCommon(cpindex* ix_, bool nullOKwithCaller) { 189 CHECK_0; 190 if (ix_ == NULL) { 191 abort("no index"); 192 return NULL; 193 } 194 assert(ix_->ixTag == ixTag 195 || (ixTag == CONSTANT_Literal 196 && ix_->ixTag >= CONSTANT_Integer 197 && ix_->ixTag <= CONSTANT_String)); 198 int n = vs[0].getInt() - nullOK; 199 // Note: band-local nullOK means null encodes as 0. 200 // But nullOKwithCaller means caller is willing to tolerate a null. 201 entry *ref = ix_->get(n); 202 if (ref == null && !(nullOKwithCaller && n == -1)) 203 abort(n == -1 ? "null ref" : "bad ref"); 204 return ref; 205 } 206 207 jlong band::getLong(band& lo_band, bool have_hi) { 208 band& hi_band = (*this); 209 assert(lo_band.bn == hi_band.bn + 1); 210 uint lo = lo_band.getInt(); 211 if (!have_hi) { 212 assert(hi_band.length == 0); 213 return makeLong(0, lo); 214 } 215 uint hi = hi_band.getInt(); 216 return makeLong(hi, lo); 217 } 218 219 int band::getIntTotal() { 220 CHECK_0; 221 if (length == 0) return 0; 222 if (total_memo > 0) return total_memo-1; 223 int total = getInt(); 224 // overflow checks require that none of the addends are <0, 225 // and that the partial sums never overflow (wrap negative) 226 if (total < 0) { 227 abort("overflow detected"); 228 return 0; 229 } 230 for (int k = length-1; k > 0; k--) { 231 int prev_total = total; 232 total += vs[0].getInt(); 233 if (total < prev_total) { 234 abort("overflow detected"); 235 return 0; 236 } 237 } 238 rewind(); 239 total_memo = total+1; 240 return total; 241 } 242 243 int band::getIntCount(int tag) { 244 CHECK_0; 245 if (length == 0) return 0; 246 if (tag >= HIST0_MIN && tag <= HIST0_MAX) { 247 if (hist0 == null) { 248 // Lazily calculate an approximate histogram. 249 hist0 = U_NEW(int, (HIST0_MAX - HIST0_MIN)+1); 250 CHECK_0; 251 for (int k = length; k > 0; k--) { 252 int x = vs[0].getInt(); 253 if (x >= HIST0_MIN && x <= HIST0_MAX) 254 hist0[x - HIST0_MIN] += 1; 255 } 256 rewind(); 257 } 258 return hist0[tag - HIST0_MIN]; 259 } 260 int total = 0; 261 for (int k = length; k > 0; k--) { 262 total += (vs[0].getInt() == tag) ? 1 : 0; 263 } 264 rewind(); 265 return total; 266 } 267 268 #define INDEX_INIT(tag, nullOK, subindex) \ 269 ((tag) + (subindex)*SUBINDEX_BIT + (nullOK)*256) 270 271 #define INDEX(tag) INDEX_INIT(tag, 0, 0) 272 #define NULL_OR_INDEX(tag) INDEX_INIT(tag, 1, 0) 273 #define SUB_INDEX(tag) INDEX_INIT(tag, 0, 1) 274 #define NO_INDEX 0 275 276 struct band_init { 277 #ifndef PRODUCT 278 int bn; 279 const char* name; 280 #endif 281 int defc; 282 int index; 283 }; 284 285 #ifdef PRODUCT 286 #define BAND_INIT(name, cspec, ix) \ 287 { cspec, ix } 288 #else 289 #define BAND_INIT(name, cspec, ix) \ 290 { e_##name, #name, /*debug only*/ \ 291 cspec, ix } 292 #endif 293 294 const band_init all_band_inits[] = { 295 //BAND_INIT(archive_magic, BYTE1_spec, 0), 296 //BAND_INIT(archive_header, UNSIGNED5_spec, 0), 297 //BAND_INIT(band_headers, BYTE1_spec, 0), 298 BAND_INIT(cp_Utf8_prefix, DELTA5_spec, 0), 299 BAND_INIT(cp_Utf8_suffix, UNSIGNED5_spec, 0), 300 BAND_INIT(cp_Utf8_chars, CHAR3_spec, 0), 301 BAND_INIT(cp_Utf8_big_suffix, DELTA5_spec, 0), 302 BAND_INIT(cp_Utf8_big_chars, DELTA5_spec, 0), 303 BAND_INIT(cp_Int, UDELTA5_spec, 0), 304 BAND_INIT(cp_Float, UDELTA5_spec, 0), 305 BAND_INIT(cp_Long_hi, UDELTA5_spec, 0), 306 BAND_INIT(cp_Long_lo, DELTA5_spec, 0), 307 BAND_INIT(cp_Double_hi, UDELTA5_spec, 0), 308 BAND_INIT(cp_Double_lo, DELTA5_spec, 0), 309 BAND_INIT(cp_String, UDELTA5_spec, INDEX(CONSTANT_Utf8)), 310 BAND_INIT(cp_Class, UDELTA5_spec, INDEX(CONSTANT_Utf8)), 311 BAND_INIT(cp_Signature_form, DELTA5_spec, INDEX(CONSTANT_Utf8)), 312 BAND_INIT(cp_Signature_classes, UDELTA5_spec, INDEX(CONSTANT_Class)), 313 BAND_INIT(cp_Descr_name, DELTA5_spec, INDEX(CONSTANT_Utf8)), 314 BAND_INIT(cp_Descr_type, UDELTA5_spec, INDEX(CONSTANT_Signature)), 315 BAND_INIT(cp_Field_class, DELTA5_spec, INDEX(CONSTANT_Class)), 316 BAND_INIT(cp_Field_desc, UDELTA5_spec, INDEX(CONSTANT_NameandType)), 317 BAND_INIT(cp_Method_class, DELTA5_spec, INDEX(CONSTANT_Class)), 318 BAND_INIT(cp_Method_desc, UDELTA5_spec, INDEX(CONSTANT_NameandType)), 319 BAND_INIT(cp_Imethod_class, DELTA5_spec, INDEX(CONSTANT_Class)), 320 BAND_INIT(cp_Imethod_desc, UDELTA5_spec, INDEX(CONSTANT_NameandType)), 321 BAND_INIT(attr_definition_headers, BYTE1_spec, 0), 322 BAND_INIT(attr_definition_name, UNSIGNED5_spec, INDEX(CONSTANT_Utf8)), 323 BAND_INIT(attr_definition_layout, UNSIGNED5_spec, INDEX(CONSTANT_Utf8)), 324 BAND_INIT(ic_this_class, UDELTA5_spec, INDEX(CONSTANT_Class)), 325 BAND_INIT(ic_flags, UNSIGNED5_spec, 0), 326 BAND_INIT(ic_outer_class, DELTA5_spec, NULL_OR_INDEX(CONSTANT_Class)), 327 BAND_INIT(ic_name, DELTA5_spec, NULL_OR_INDEX(CONSTANT_Utf8)), 328 BAND_INIT(class_this, DELTA5_spec, INDEX(CONSTANT_Class)), 329 BAND_INIT(class_super, DELTA5_spec, INDEX(CONSTANT_Class)), 330 BAND_INIT(class_interface_count, DELTA5_spec, 0), 331 BAND_INIT(class_interface, DELTA5_spec, INDEX(CONSTANT_Class)), 332 BAND_INIT(class_field_count, DELTA5_spec, 0), 333 BAND_INIT(class_method_count, DELTA5_spec, 0), 334 BAND_INIT(field_descr, DELTA5_spec, INDEX(CONSTANT_NameandType)), 335 BAND_INIT(field_flags_hi, UNSIGNED5_spec, 0), 336 BAND_INIT(field_flags_lo, UNSIGNED5_spec, 0), 337 BAND_INIT(field_attr_count, UNSIGNED5_spec, 0), 338 BAND_INIT(field_attr_indexes, UNSIGNED5_spec, 0), 339 BAND_INIT(field_attr_calls, UNSIGNED5_spec, 0), 340 BAND_INIT(field_ConstantValue_KQ, UNSIGNED5_spec, INDEX(CONSTANT_Literal)), 341 BAND_INIT(field_Signature_RS, UNSIGNED5_spec, INDEX(CONSTANT_Signature)), 342 BAND_INIT(field_metadata_bands, -1, -1), 343 BAND_INIT(field_attr_bands, -1, -1), 344 BAND_INIT(method_descr, MDELTA5_spec, INDEX(CONSTANT_NameandType)), 345 BAND_INIT(method_flags_hi, UNSIGNED5_spec, 0), 346 BAND_INIT(method_flags_lo, UNSIGNED5_spec, 0), 347 BAND_INIT(method_attr_count, UNSIGNED5_spec, 0), 348 BAND_INIT(method_attr_indexes, UNSIGNED5_spec, 0), 349 BAND_INIT(method_attr_calls, UNSIGNED5_spec, 0), 350 BAND_INIT(method_Exceptions_N, UNSIGNED5_spec, 0), 351 BAND_INIT(method_Exceptions_RC, UNSIGNED5_spec, INDEX(CONSTANT_Class)), 352 BAND_INIT(method_Signature_RS, UNSIGNED5_spec, INDEX(CONSTANT_Signature)), 353 BAND_INIT(method_metadata_bands, -1, -1), 354 BAND_INIT(method_attr_bands, -1, -1), 355 BAND_INIT(class_flags_hi, UNSIGNED5_spec, 0), 356 BAND_INIT(class_flags_lo, UNSIGNED5_spec, 0), 357 BAND_INIT(class_attr_count, UNSIGNED5_spec, 0), 358 BAND_INIT(class_attr_indexes, UNSIGNED5_spec, 0), 359 BAND_INIT(class_attr_calls, UNSIGNED5_spec, 0), 360 BAND_INIT(class_SourceFile_RUN, UNSIGNED5_spec, NULL_OR_INDEX(CONSTANT_Utf8)), 361 BAND_INIT(class_EnclosingMethod_RC, UNSIGNED5_spec, INDEX(CONSTANT_Class)), 362 BAND_INIT(class_EnclosingMethod_RDN, UNSIGNED5_spec, NULL_OR_INDEX(CONSTANT_NameandType)), 363 BAND_INIT(class_Signature_RS, UNSIGNED5_spec, INDEX(CONSTANT_Signature)), 364 BAND_INIT(class_metadata_bands, -1, -1), 365 BAND_INIT(class_InnerClasses_N, UNSIGNED5_spec, 0), 366 BAND_INIT(class_InnerClasses_RC, UNSIGNED5_spec, INDEX(CONSTANT_Class)), 367 BAND_INIT(class_InnerClasses_F, UNSIGNED5_spec, 0), 368 BAND_INIT(class_InnerClasses_outer_RCN, UNSIGNED5_spec, NULL_OR_INDEX(CONSTANT_Class)), 369 BAND_INIT(class_InnerClasses_name_RUN, UNSIGNED5_spec, NULL_OR_INDEX(CONSTANT_Utf8)), 370 BAND_INIT(class_ClassFile_version_minor_H, UNSIGNED5_spec, 0), 371 BAND_INIT(class_ClassFile_version_major_H, UNSIGNED5_spec, 0), 372 BAND_INIT(class_attr_bands, -1, -1), 373 BAND_INIT(code_headers, BYTE1_spec, 0), 374 BAND_INIT(code_max_stack, UNSIGNED5_spec, 0), 375 BAND_INIT(code_max_na_locals, UNSIGNED5_spec, 0), 376 BAND_INIT(code_handler_count, UNSIGNED5_spec, 0), 377 BAND_INIT(code_handler_start_P, BCI5_spec, 0), 378 BAND_INIT(code_handler_end_PO, BRANCH5_spec, 0), 379 BAND_INIT(code_handler_catch_PO, BRANCH5_spec, 0), 380 BAND_INIT(code_handler_class_RCN, UNSIGNED5_spec, NULL_OR_INDEX(CONSTANT_Class)), 381 BAND_INIT(code_flags_hi, UNSIGNED5_spec, 0), 382 BAND_INIT(code_flags_lo, UNSIGNED5_spec, 0), 383 BAND_INIT(code_attr_count, UNSIGNED5_spec, 0), 384 BAND_INIT(code_attr_indexes, UNSIGNED5_spec, 0), 385 BAND_INIT(code_attr_calls, UNSIGNED5_spec, 0), 386 BAND_INIT(code_StackMapTable_N, UNSIGNED5_spec, 0), 387 BAND_INIT(code_StackMapTable_frame_T, BYTE1_spec, 0), 388 BAND_INIT(code_StackMapTable_local_N, UNSIGNED5_spec, 0), 389 BAND_INIT(code_StackMapTable_stack_N, UNSIGNED5_spec, 0), 390 BAND_INIT(code_StackMapTable_offset, UNSIGNED5_spec, 0), 391 BAND_INIT(code_StackMapTable_T, BYTE1_spec, 0), 392 BAND_INIT(code_StackMapTable_RC, UNSIGNED5_spec, INDEX(CONSTANT_Class)), 393 BAND_INIT(code_StackMapTable_P, BCI5_spec, 0), 394 BAND_INIT(code_LineNumberTable_N, UNSIGNED5_spec, 0), 395 BAND_INIT(code_LineNumberTable_bci_P, BCI5_spec, 0), 396 BAND_INIT(code_LineNumberTable_line, UNSIGNED5_spec, 0), 397 BAND_INIT(code_LocalVariableTable_N, UNSIGNED5_spec, 0), 398 BAND_INIT(code_LocalVariableTable_bci_P, BCI5_spec, 0), 399 BAND_INIT(code_LocalVariableTable_span_O, BRANCH5_spec, 0), 400 BAND_INIT(code_LocalVariableTable_name_RU, UNSIGNED5_spec, INDEX(CONSTANT_Utf8)), 401 BAND_INIT(code_LocalVariableTable_type_RS, UNSIGNED5_spec, INDEX(CONSTANT_Signature)), 402 BAND_INIT(code_LocalVariableTable_slot, UNSIGNED5_spec, 0), 403 BAND_INIT(code_LocalVariableTypeTable_N, UNSIGNED5_spec, 0), 404 BAND_INIT(code_LocalVariableTypeTable_bci_P, BCI5_spec, 0), 405 BAND_INIT(code_LocalVariableTypeTable_span_O, BRANCH5_spec, 0), 406 BAND_INIT(code_LocalVariableTypeTable_name_RU, UNSIGNED5_spec, INDEX(CONSTANT_Utf8)), 407 BAND_INIT(code_LocalVariableTypeTable_type_RS, UNSIGNED5_spec, INDEX(CONSTANT_Signature)), 408 BAND_INIT(code_LocalVariableTypeTable_slot, UNSIGNED5_spec, 0), 409 BAND_INIT(code_attr_bands, -1, -1), 410 BAND_INIT(bc_codes, BYTE1_spec, 0), 411 BAND_INIT(bc_case_count, UNSIGNED5_spec, 0), 412 BAND_INIT(bc_case_value, DELTA5_spec, 0), 413 BAND_INIT(bc_byte, BYTE1_spec, 0), 414 BAND_INIT(bc_short, DELTA5_spec, 0), 415 BAND_INIT(bc_local, UNSIGNED5_spec, 0), 416 BAND_INIT(bc_label, BRANCH5_spec, 0), 417 BAND_INIT(bc_intref, DELTA5_spec, INDEX(CONSTANT_Integer)), 418 BAND_INIT(bc_floatref, DELTA5_spec, INDEX(CONSTANT_Float)), 419 BAND_INIT(bc_longref, DELTA5_spec, INDEX(CONSTANT_Long)), 420 BAND_INIT(bc_doubleref, DELTA5_spec, INDEX(CONSTANT_Double)), 421 BAND_INIT(bc_stringref, DELTA5_spec, INDEX(CONSTANT_String)), 422 BAND_INIT(bc_classref, UNSIGNED5_spec, NULL_OR_INDEX(CONSTANT_Class)), 423 BAND_INIT(bc_fieldref, DELTA5_spec, INDEX(CONSTANT_Fieldref)), 424 BAND_INIT(bc_methodref, UNSIGNED5_spec, INDEX(CONSTANT_Methodref)), 425 BAND_INIT(bc_imethodref, DELTA5_spec, INDEX(CONSTANT_InterfaceMethodref)), 426 BAND_INIT(bc_thisfield, UNSIGNED5_spec, SUB_INDEX(CONSTANT_Fieldref)), 427 BAND_INIT(bc_superfield, UNSIGNED5_spec, SUB_INDEX(CONSTANT_Fieldref)), 428 BAND_INIT(bc_thismethod, UNSIGNED5_spec, SUB_INDEX(CONSTANT_Methodref)), 429 BAND_INIT(bc_supermethod, UNSIGNED5_spec, SUB_INDEX(CONSTANT_Methodref)), 430 BAND_INIT(bc_initref, UNSIGNED5_spec, SUB_INDEX(CONSTANT_Methodref)), 431 BAND_INIT(bc_escref, UNSIGNED5_spec, INDEX(CONSTANT_All)), 432 BAND_INIT(bc_escrefsize, UNSIGNED5_spec, 0), 433 BAND_INIT(bc_escsize, UNSIGNED5_spec, 0), 434 BAND_INIT(bc_escbyte, BYTE1_spec, 0), 435 BAND_INIT(file_name, UNSIGNED5_spec, INDEX(CONSTANT_Utf8)), 436 BAND_INIT(file_size_hi, UNSIGNED5_spec, 0), 437 BAND_INIT(file_size_lo, UNSIGNED5_spec, 0), 438 BAND_INIT(file_modtime, DELTA5_spec, 0), 439 BAND_INIT(file_options, UNSIGNED5_spec, 0), 440 //BAND_INIT(file_bits, BYTE1_spec, 0), 441 #ifndef PRODUCT 442 { 0, 0, 0, 0 } 443 #else 444 { 0, 0 } 445 #endif 446 }; 447 #define NUM_BAND_INITS \ 448 (sizeof(all_band_inits)/sizeof(all_band_inits[0])) 449 450 band* band::makeBands(unpacker* u) { 451 band* tmp_all_bands = U_NEW(band, BAND_LIMIT); 452 for (int i = 0; i < BAND_LIMIT; i++) { 453 assert((byte*)&all_band_inits[i+1] 454 < (byte*)all_band_inits+sizeof(all_band_inits)); 455 const band_init& bi = all_band_inits[i]; 456 band& b = tmp_all_bands[i]; 457 coding* defc = coding::findBySpec(bi.defc); 458 assert((defc == null) == (bi.defc == -1)); // no garbage, please 459 assert(defc == null || !defc->isMalloc); 460 assert(bi.bn == i); // band array consistent w/ band enum 461 b.init(u, i, defc); 462 if (bi.index > 0) { 463 b.nullOK = ((bi.index >> 8) & 1); 464 b.ixTag = (bi.index & 0xFF); 465 } 466 #ifndef PRODUCT 467 b.name = bi.name; 468 #endif 469 } 470 return tmp_all_bands; 471 } 472 473 void band::initIndexes(unpacker* u) { 474 band* tmp_all_bands = u->all_bands; 475 for (int i = 0; i < BAND_LIMIT; i++) { 476 band* scan = &tmp_all_bands[i]; 477 uint tag = scan->ixTag; // Cf. #define INDEX(tag) above 478 if (tag != 0 && tag != CONSTANT_Literal && (tag & SUBINDEX_BIT) == 0) { 479 scan->setIndex(u->cp.getIndex(tag)); 480 } 481 } 482 }