3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5 M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6 P. Tomsich, J. Wenninger
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Reinhard Grafl
32 Contains support functions for:
33 - Reading of Java class files
36 - additional support functions
38 $Id: tables.c 1067 2004-05-18 10:25:51Z stefan $
47 #include <sys/types.h>
55 #include "threads/thread.h"
56 #include "threads/locks.h"
57 #include "toolbox/logging.h"
58 #include "toolbox/memory.h"
62 int count_utf_len = 0; /* size of utf hash */
63 int count_utf_new = 0; /* calls of utf_new */
64 int count_utf_new_found = 0; /* calls of utf_new with fast return */
66 hashtable utf_hash; /* hashtable for utf8-symbols */
67 hashtable string_hash; /* hashtable for javastrings */
68 hashtable class_hash; /* hashtable for classes */
70 /******************************************************************************
71 *********************** hashtable functions **********************************
72 ******************************************************************************/
74 /* hashsize must be power of 2 */
76 #define UTF_HASHSTART 16384 /* initial size of utf-hash */
77 #define HASHSTART 2048 /* initial size of javastring and class-hash */
80 /******************** function: init_hashtable ******************************
82 Initializes a hashtable structure and allocates memory.
83 The parameter size specifies the initial size of the hashtable.
85 *****************************************************************************/
87 void init_hashtable(hashtable *hash, u4 size)
93 hash->ptr = MNEW(void*, size);
96 for (i = 0; i < size; i++) hash->ptr[i] = NULL;
100 /*********************** function: tables_init *****************************
102 creates hashtables for symboltables
103 (called once at startup)
105 *****************************************************************************/
109 init_hashtable(&utf_hash, UTF_HASHSTART); /* hashtable for utf8-symbols */
110 init_hashtable(&string_hash, HASHSTART); /* hashtable for javastrings */
111 init_hashtable(&class_hash, HASHSTART); /* hashtable for classes */
114 count_utf_len += sizeof(utf*) * utf_hash.size;
120 /********************** function: tables_close ******************************
122 free memory for hashtables
124 *****************************************************************************/
126 void tables_close(stringdeleter del)
132 /* dispose utf symbols */
133 for (i = 0; i < utf_hash.size; i++) {
136 /* process elements in external hash chain */
137 utf *nextu = u->hashlink;
138 MFREE(u->text, u1, u->blength);
144 /* dispose javastrings */
145 for (i = 0; i < string_hash.size; i++) {
146 s = string_hash.ptr[i];
148 /* process elements in external hash chain */
149 literalstring *nexts = s->hashlink;
151 FREE(s, literalstring);
156 /* dispose hashtable structures */
157 MFREE(utf_hash.ptr, void*, utf_hash.size);
158 MFREE(string_hash.ptr, void*, string_hash.size);
159 MFREE(class_hash.ptr, void*, class_hash.size);
163 /********************* function: utf_display *********************************
165 write utf symbol to stdout (debugging purposes)
167 ******************************************************************************/
169 void utf_display(utf *u)
171 char *endpos = utf_end(u); /* points behind utf string */
172 char *utf_ptr = u->text; /* current position in utf text */
177 while (utf_ptr < endpos) {
178 /* read next unicode character */
179 u2 c = utf_nextu2(&utf_ptr);
180 if (c >= 32 && c <= 127) printf("%c", c);
188 /********************* function: utf_display *********************************
190 write utf symbol to stdout (debugging purposes)
192 ******************************************************************************/
194 void utf_display_classname(utf *u)
196 char *endpos = utf_end(u); /* points behind utf string */
197 char *utf_ptr = u->text; /* current position in utf text */
202 while (utf_ptr < endpos) {
203 /* read next unicode character */
204 u2 c = utf_nextu2(&utf_ptr);
205 if (c == '/') c = '.';
206 if (c >= 32 && c <= 127) printf("%c", c);
214 /************************* function: log_utf *********************************
218 ******************************************************************************/
222 char buf[MAXLOGTEXT];
228 /********************** function: log_plain_utf ******************************
230 log utf symbol (without printing "LOG: " and newline)
232 ******************************************************************************/
234 void log_plain_utf(utf *u)
236 char buf[MAXLOGTEXT];
238 dolog_plain("%s", buf);
242 /************************ function: utf_sprint *******************************
244 write utf symbol into c-string (debugging purposes)
246 ******************************************************************************/
248 void utf_sprint(char *buffer, utf *u)
250 char *endpos = utf_end(u); /* points behind utf string */
251 char *utf_ptr = u->text; /* current position in utf text */
252 u2 pos = 0; /* position in c-string */
254 while (utf_ptr < endpos)
255 /* copy next unicode character */
256 buffer[pos++] = utf_nextu2(&utf_ptr);
258 /* terminate string */
263 /************************ function: utf_sprint_classname *********************
265 write utf symbol into c-string (debugging purposes)
267 ******************************************************************************/
269 void utf_sprint_classname(char *buffer, utf *u)
271 char *endpos = utf_end(u); /* points behind utf string */
272 char *utf_ptr = u->text; /* current position in utf text */
273 u2 pos = 0; /* position in c-string */
275 while (utf_ptr < endpos) {
276 /* copy next unicode character */
277 u2 c = utf_nextu2(&utf_ptr);
278 if (c == '/') c = '.';
282 /* terminate string */
287 /********************* Funktion: utf_fprint **********************************
289 write utf symbol into file
291 ******************************************************************************/
293 void utf_fprint(FILE *file, utf *u)
295 char *endpos = utf_end(u); /* points behind utf string */
296 char *utf_ptr = u->text; /* current position in utf text */
301 while (utf_ptr < endpos) {
302 /* read next unicode character */
303 u2 c = utf_nextu2(&utf_ptr);
305 if (c >= 32 && c <= 127) fprintf(file, "%c", c);
306 else fprintf(file, "?");
311 /****************** internal function: utf_hashkey ***************************
313 The hashkey is computed from the utf-text by using up to 8 characters.
314 For utf-symbols longer than 15 characters 3 characters are taken from
315 the beginning and the end, 2 characters are taken from the middle.
317 ******************************************************************************/
319 #define nbs(val) ((u4) *(++text) << val) /* get next byte, left shift by val */
320 #define fbs(val) ((u4) *( text) << val) /* get first byte, left shift by val */
322 static u4 utf_hashkey(char *text, u4 length)
324 char *start_pos = text; /* pointer to utf text */
329 case 0: /* empty string */
332 case 1: return fbs(0);
333 case 2: return fbs(0) ^ nbs(3);
334 case 3: return fbs(0) ^ nbs(3) ^ nbs(5);
335 case 4: return fbs(0) ^ nbs(2) ^ nbs(4) ^ nbs(6);
336 case 5: return fbs(0) ^ nbs(2) ^ nbs(3) ^ nbs(4) ^ nbs(6);
337 case 6: return fbs(0) ^ nbs(1) ^ nbs(2) ^ nbs(3) ^ nbs(5) ^ nbs(6);
338 case 7: return fbs(0) ^ nbs(1) ^ nbs(2) ^ nbs(3) ^ nbs(4) ^ nbs(5) ^ nbs(6);
339 case 8: return fbs(0) ^ nbs(1) ^ nbs(2) ^ nbs(3) ^ nbs(4) ^ nbs(5) ^ nbs(6) ^ nbs(7);
346 return a ^ nbs(4) ^ nbs(5) ^ nbs(6) ^ nbs(7) ^ nbs(8);
355 return a ^ nbs(6) ^ nbs(7) ^ nbs(8) ^ nbs(9);
364 return a ^ nbs(6) ^ nbs(7) ^ nbs(8) ^ nbs(9) ^ nbs(10);
376 return a ^ nbs(9) ^ nbs(10);
388 return a ^ nbs(9) ^ nbs(10);
399 return a ^ nbs(9) ^ nbs(10) ^ nbs(11);
410 return a ^ nbs(9) ^ nbs(10) ^ nbs(11);
412 default: /* 3 characters from beginning */
418 /* 2 characters from middle */
419 text = start_pos + (length / 2);
424 /* 3 characters from end */
425 text = start_pos + length - 4;
430 return a ^ nbs(10) ^ nbs(11);
435 /*************************** function: utf_hashkey ***************************
437 compute the hashkey of a unicode string
439 ******************************************************************************/
441 u4 unicode_hashkey(u2 *text, u2 len)
443 return utf_hashkey((char*) text, len);
447 /************************ function: utf_new **********************************
449 Creates a new utf-symbol, the text of the symbol is passed as a
450 u1-array. The function searches the utf-hashtable for a utf-symbol
451 with this text. On success the element returned, otherwise a new
452 hashtable element is created.
454 If the number of entries in the hashtable exceeds twice the size of the
455 hashtable slots a reorganization of the hashtable is done and the utf
456 symbols are copied to a new hashtable with doubled size.
458 ******************************************************************************/
460 utf *utf_new_int(char *text, u2 length)
462 u4 key; /* hashkey computed from utf-text */
463 u4 slot; /* slot in hashtable */
464 utf *u; /* hashtable element */
471 key = utf_hashkey(text, length);
472 slot = key & (utf_hash.size-1);
473 u = utf_hash.ptr[slot];
475 /* search external hash chain for utf-symbol */
477 if (u->blength == length) {
479 /* compare text of hashtable elements */
480 for (i = 0; i < length; i++)
481 if (text[i] != u->text[i]) goto nomatch;
484 count_utf_new_found++;
486 /* log_text("symbol found in hash table");*/
487 /* symbol found in hashtable */
498 u = u->hashlink; /* next element in external chain */
502 count_utf_len += sizeof(utf) + length;
505 /* location in hashtable found, create new utf element */
507 u->blength = length; /* length in bytes of utfstring */
508 u->hashlink = utf_hash.ptr[slot]; /* link in external hashchain */
509 u->text = mem_alloc(length + 1);/* allocate memory for utf-text */
510 memcpy(u->text, text, length); /* copy utf-text */
511 u->text[length] = '\0';
512 utf_hash.ptr[slot] = u; /* insert symbol into table */
514 utf_hash.entries++; /* update number of entries */
516 if (utf_hash.entries > (utf_hash.size * 2)) {
518 /* reorganization of hashtable, average length of
519 the external chains is approx. 2 */
523 hashtable newhash; /* the new hashtable */
525 /* create new hashtable, double the size */
526 init_hashtable(&newhash, utf_hash.size * 2);
527 newhash.entries = utf_hash.entries;
530 count_utf_len += sizeof(utf*) * utf_hash.size;
533 /* transfer elements to new hashtable */
534 for (i = 0; i < utf_hash.size; i++) {
535 u = (utf *) utf_hash.ptr[i];
537 utf *nextu = u->hashlink;
538 u4 slot = utf_hashkey(u->text, u->blength) & (newhash.size - 1);
540 u->hashlink = (utf *) newhash.ptr[slot];
541 newhash.ptr[slot] = u;
543 /* follow link in external hash chain */
548 /* dispose old table */
549 MFREE(utf_hash.ptr, void*, utf_hash.size);
557 utf *utf_new(char *text, u2 length)
561 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
565 r = utf_new_int(text, length);
567 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
575 /********************* function: utf_new_char ********************************
577 creates a new utf symbol, the text for this symbol is passed
578 as a c-string ( = char* )
580 ******************************************************************************/
582 utf *utf_new_char(char *text)
584 return utf_new(text, strlen(text));
588 /********************* function: utf_new_char ********************************
590 creates a new utf symbol, the text for this symbol is passed
591 as a c-string ( = char* )
592 "." characters are going to be replaced by "/". since the above function is
593 used often, this is a separte function, instead of an if
595 ******************************************************************************/
597 utf *utf_new_char_classname(char *text)
599 if (strchr(text, '.')) {
600 char *txt = strdup(text);
601 char *end = txt + strlen(txt);
604 for (c = txt; c < end; c++)
605 if (*c == '.') *c = '/';
606 tmpRes = utf_new(txt, strlen(txt));
611 return utf_new(text, strlen(text));
615 /************************** Funktion: utf_show ******************************
617 writes the utf symbols in the utfhash to stdout and
618 displays the number of external hash chains grouped
619 according to the chainlength
622 *****************************************************************************/
627 #define CHAIN_LIMIT 20 /* limit for seperated enumeration */
629 u4 chain_count[CHAIN_LIMIT]; /* numbers of chains */
630 u4 max_chainlength = 0; /* maximum length of the chains */
631 u4 sum_chainlength = 0; /* sum of the chainlengths */
632 u4 beyond_limit = 0; /* number of utf-symbols in chains with length>=CHAIN_LIMIT-1 */
635 printf ("UTF-HASH:\n");
637 /* show element of utf-hashtable */
638 for (i=0; i<utf_hash.size; i++) {
639 utf *u = utf_hash.ptr[i];
641 printf ("SLOT %d: ", (int) i);
653 printf ("UTF-HASH: %d slots for %d entries\n",
654 (int) utf_hash.size, (int) utf_hash.entries );
657 if (utf_hash.entries == 0)
660 printf("chains:\n chainlength number of chains %% of utfstrings\n");
662 for (i=0;i<CHAIN_LIMIT;i++)
665 /* count numbers of hashchains according to their length */
666 for (i=0; i<utf_hash.size; i++) {
668 utf *u = (utf*) utf_hash.ptr[i];
671 /* determine chainlength */
677 /* update sum of all chainlengths */
678 sum_chainlength+=chain_length;
680 /* determine the maximum length of the chains */
681 if (chain_length>max_chainlength)
682 max_chainlength = chain_length;
684 /* update number of utf-symbols in chains with length>=CHAIN_LIMIT-1 */
685 if (chain_length>=CHAIN_LIMIT) {
686 beyond_limit+=chain_length;
687 chain_length=CHAIN_LIMIT-1;
690 /* update number of hashchains of current length */
691 chain_count[chain_length]++;
694 /* display results */
695 for (i=1;i<CHAIN_LIMIT-1;i++)
696 printf(" %2d %17d %18.2f%%\n",i,chain_count[i],(((float) chain_count[i]*i*100)/utf_hash.entries));
698 printf(" >=%2d %17d %18.2f%%\n",CHAIN_LIMIT-1,chain_count[CHAIN_LIMIT-1],((float) beyond_limit*100)/utf_hash.entries);
701 printf("max. chainlength:%5d\n",max_chainlength);
703 /* avg. chainlength = sum of chainlengths / number of chains */
704 printf("avg. chainlength:%5.2f\n",(float) sum_chainlength / (utf_hash.size-chain_count[0]));
707 /******************************************************************************
708 *********************** Misc support functions ********************************
709 ******************************************************************************/
712 /******************** Function: desc_to_type **********************************
714 Determines the corresponding Java base data type for a given type
717 ******************************************************************************/
719 u2 desc_to_type(utf *descriptor)
721 char *utf_ptr = descriptor->text; /* current position in utf text */
722 char logtext[MAXLOGTEXT];
724 if (descriptor->blength < 1) panic("Type-Descriptor is empty string");
726 switch (*utf_ptr++) {
731 case 'Z': return TYPE_INT;
732 case 'D': return TYPE_DOUBLE;
733 case 'F': return TYPE_FLOAT;
734 case 'J': return TYPE_LONG;
736 case '[': return TYPE_ADDRESS;
739 sprintf(logtext, "Invalid Type-Descriptor: ");
740 utf_sprint(logtext+strlen(logtext), descriptor);
747 /********************** Function: desc_typesize *******************************
749 Calculates the lenght in bytes needed for a data element of the type given
750 by its type descriptor.
752 ******************************************************************************/
754 u2 desc_typesize(utf *descriptor)
756 switch (desc_to_type(descriptor)) {
757 case TYPE_INT: return 4;
758 case TYPE_LONG: return 8;
759 case TYPE_FLOAT: return 4;
760 case TYPE_DOUBLE: return 8;
761 case TYPE_ADDRESS: return sizeof(voidptr);
767 /********************** function: utf_nextu2 *********************************
769 read the next unicode character from the utf string and
770 increment the utf-string pointer accordingly
772 ******************************************************************************/
774 u2 utf_nextu2(char **utf_ptr)
776 /* uncompressed unicode character */
778 /* current position in utf text */
779 unsigned char *utf = (unsigned char *) (*utf_ptr);
780 /* bytes representing the unicode character */
781 unsigned char ch1, ch2, ch3;
782 /* number of bytes used to represent the unicode character */
785 switch ((ch1 = utf[0]) >> 4) {
786 default: /* 1 byte */
790 case 0xD: /* 2 bytes */
791 if (((ch2 = utf[1]) & 0xC0) == 0x80) {
792 unsigned char high = ch1 & 0x1F;
793 unsigned char low = ch2 & 0x3F;
794 unicode_char = (high << 6) + low;
799 case 0xE: /* 2 or 3 bytes */
800 if (((ch2 = utf[1]) & 0xC0) == 0x80) {
801 if (((ch3 = utf[2]) & 0xC0) == 0x80) {
802 unsigned char low = ch3 & 0x3f;
803 unsigned char mid = ch2 & 0x3f;
804 unsigned char high = ch1 & 0x0f;
805 unicode_char = (((high << 6) + mid) << 6) + low;
813 /* update position in utf-text */
814 *utf_ptr = (char *) (utf + len);
819 /********************* function: is_valid_utf ********************************
821 return true if the given string is a valid UTF-8 string
823 utf_ptr...points to first character
824 end_pos...points after last character
826 ******************************************************************************/
828 static unsigned long min_codepoint[6] = {0,1L<<7,1L<<11,1L<<16,1L<<21,1L<<26};
831 is_valid_utf(char *utf_ptr,char *end_pos)
838 if (end_pos < utf_ptr) return false;
839 bytes = end_pos - utf_ptr;
842 /*dolog("%c %02x",c,c);*/
843 if (!c) return false; /* 0x00 is not allowed */
844 if ((c & 0x80) == 0) continue; /* ASCII */
846 if ((c & 0xe0) == 0xc0) len = 1; /* 110x xxxx */
847 else if ((c & 0xf0) == 0xe0) len = 2; /* 1110 xxxx */
848 else if ((c & 0xf8) == 0xf0) len = 3; /* 1111 0xxx */
849 else if ((c & 0xfc) == 0xf8) len = 4; /* 1111 10xx */
850 else if ((c & 0xfe) == 0xfc) len = 5; /* 1111 110x */
851 else return false; /* invalid leading byte */
853 if (len > 2) return false; /* Java limitation */
855 v = (unsigned long)c & (0x3f >> len);
857 if ((bytes -= len) < 0) return false; /* missing bytes */
859 for (i = len; i--; ) {
861 /*dolog(" %c %02x",c,c);*/
862 if ((c & 0xc0) != 0x80) /* 10xx xxxx */
864 v = (v<<6) | (c & 0x3f);
867 /* dolog("v=%d",v);*/
870 if (len != 1) return false; /* Java special */
873 /* Sun Java seems to allow overlong UTF-8 encodings */
875 if (v < min_codepoint[len]) { /* overlong UTF-8 */
877 fprintf(stderr,"WARNING: Overlong UTF-8 sequence found.\n");
878 /* XXX change this to panic? */
882 /* surrogates in UTF-8 seem to be allowed in Java classfiles */
883 /* if (v >= 0xd800 && v <= 0xdfff) return false; */ /* surrogates */
885 /* even these seem to be allowed */
886 /* if (v == 0xfffe || v == 0xffff) return false; */ /* invalid codepoints */
892 /********************* function: is_valid_name *******************************
894 return true if the given string may be used as a class/field/method name.
895 (Currently this only disallows empty strings and control characters.)
897 NOTE: The string is assumed to have passed is_valid_utf!
899 utf_ptr...points to first character
900 end_pos...points after last character
902 ******************************************************************************/
905 is_valid_name(char *utf_ptr,char *end_pos)
907 if (end_pos <= utf_ptr) return false; /* disallow empty names */
909 while (utf_ptr < end_pos) {
910 unsigned char c = *utf_ptr++;
912 if (c < 0x20) return false; /* disallow control characters */
913 if (c == 0xc0 && (unsigned char)*utf_ptr == 0x80) return false; /* disallow zero */
919 is_valid_name_utf(utf *u)
921 return is_valid_name(u->text,utf_end(u));
924 /******************** Function: class_new **************************************
926 searches for the class with the specified name in the classes hashtable,
927 if there is no such class a new classinfo structure is created and inserted
928 into the list of classes to be loaded
930 *******************************************************************************/
932 classinfo *class_new_int(utf *classname)
934 classinfo *c; /* hashtable element */
935 u4 key; /* hashkey computed from classname */
936 u4 slot; /* slot in hashtable */
939 key = utf_hashkey(classname->text, classname->blength);
940 slot = key & (class_hash.size - 1);
941 c = class_hash.ptr[slot];
943 /* search external hash chain for the class */
945 if (c->name->blength == classname->blength) {
946 for (i = 0; i < classname->blength; i++)
947 if (classname->text[i] != c->name->text[i]) goto nomatch;
949 /* class found in hashtable */
954 c = c->hashlink; /* next element in external chain */
957 /* location in hashtable found, create new classinfo structure */
960 count_class_infos += sizeof(classinfo);
964 char logtext[MAXLOGTEXT];
965 sprintf(logtext, "Creating class: ");
966 utf_sprint_classname(logtext + strlen(logtext), classname);
970 c = GCNEW(classinfo, 1); /*JOWENN: NEW*/
974 c->packagename = NULL;
981 c->interfacescount = 0;
982 c->interfaces = NULL;
991 c->header.vftbl = NULL;
992 c->innerclasscount = 0;
993 c->innerclass = NULL;
995 c->initialized = false;
996 c->classvftbl = false;
999 c->classloader = NULL;
1000 c->sourcefile = NULL;
1002 /* insert class into the hashtable */
1003 c->hashlink = class_hash.ptr[slot];
1004 class_hash.ptr[slot] = c;
1006 /* update number of hashtable-entries */
1007 class_hash.entries++;
1009 if (class_hash.entries > (class_hash.size * 2)) {
1011 /* reorganization of hashtable, average length of
1012 the external chains is approx. 2 */
1016 hashtable newhash; /* the new hashtable */
1018 /* create new hashtable, double the size */
1019 init_hashtable(&newhash, class_hash.size * 2);
1020 newhash.entries = class_hash.entries;
1022 /* transfer elements to new hashtable */
1023 for (i = 0; i < class_hash.size; i++) {
1024 c = (classinfo *) class_hash.ptr[i];
1026 classinfo *nextc = c->hashlink;
1027 u4 slot = (utf_hashkey(c->name->text, c->name->blength)) & (newhash.size - 1);
1029 c->hashlink = newhash.ptr[slot];
1030 newhash.ptr[slot] = c;
1036 /* dispose old table */
1037 MFREE(class_hash.ptr, void*, class_hash.size);
1038 class_hash = newhash;
1041 /* Array classes need further initialization. */
1042 if (c->name->text[0] == '[') {
1043 /* Array classes are not loaded from classfiles. */
1046 c->packagename = array_packagename;
1049 /* Find the package name */
1050 /* Classes in the unnamed package keep packagename == NULL. */
1051 char *p = utf_end(c->name) - 1;
1052 char *start = c->name->text;
1053 for (;p > start; --p) {
1055 c->packagename = utf_new(start, p - start);
1065 classinfo *class_new(utf *classname)
1069 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1073 r = class_new_int(classname);
1075 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1083 /******************** Function: class_get **************************************
1085 searches for the class with the specified name in the classes hashtable
1086 if there is no such class NULL is returned
1088 *******************************************************************************/
1090 classinfo *class_get(utf *u)
1092 classinfo *c; /* hashtable element */
1093 u4 key; /* hashkey computed from classname */
1094 u4 slot; /* slot in hashtable */
1097 key = utf_hashkey (u->text, u->blength);
1098 slot = key & (class_hash.size-1);
1099 c = class_hash.ptr[slot];
1101 /* search external hash-chain */
1103 if (c->name->blength == u->blength) {
1105 /* compare classnames */
1106 for (i=0; i<u->blength; i++)
1107 if (u->text[i] != c->name->text[i]) goto nomatch;
1109 /* class found in hashtable */
1117 /* class not found */
1122 /***************** Function: class_array_of ***********************************
1124 Returns an array class with the given component class.
1125 The array class is dynamically created if neccessary.
1127 *******************************************************************************/
1129 classinfo *class_array_of(classinfo *component)
1135 /* Assemble the array class name */
1136 namelen = component->name->blength;
1138 if (component->name->text[0] == '[') {
1139 /* the component is itself an array */
1140 namebuf = DMNEW(char, namelen + 1);
1142 memcpy(namebuf + 1, component->name->text, namelen);
1146 /* the component is a non-array class */
1147 namebuf = DMNEW(char, namelen + 3);
1150 memcpy(namebuf + 2, component->name->text, namelen);
1151 namebuf[2 + namelen] = ';';
1155 /* load this class ;-) and link it */
1156 c = class_new(utf_new(namebuf, namelen));
1163 /*************** Function: class_multiarray_of ********************************
1165 Returns an array class with the given dimension and element class.
1166 The array class is dynamically created if neccessary.
1168 *******************************************************************************/
1170 classinfo *class_multiarray_of(int dim,classinfo *element)
1176 panic("Invalid array dimension requested");
1178 /* Assemble the array class name */
1179 namelen = element->name->blength;
1181 if (element->name->text[0] == '[') {
1182 /* the element is itself an array */
1183 namebuf = DMNEW(char,namelen+dim);
1184 memcpy(namebuf+dim,element->name->text,namelen);
1188 /* the element is a non-array class */
1189 namebuf = DMNEW(char,namelen+2+dim);
1191 memcpy(namebuf+dim+1,element->name->text,namelen);
1193 namebuf[namelen-1] = ';';
1195 memset(namebuf,'[',dim);
1197 return class_new( utf_new(namebuf,namelen) );
1200 /************************** function: utf_strlen ******************************
1202 determine number of unicode characters in the utf string
1204 *******************************************************************************/
1206 u4 utf_strlen(utf *u)
1208 char *endpos = utf_end(u); /* points behind utf string */
1209 char *utf_ptr = u->text; /* current position in utf text */
1210 u4 len = 0; /* number of unicode characters */
1212 while (utf_ptr < endpos) {
1214 /* next unicode character */
1215 utf_nextu2(&utf_ptr);
1218 if (utf_ptr != endpos)
1219 /* string ended abruptly */
1220 panic("illegal utf string");
1227 * These are local overrides for various environment variables in Emacs.
1228 * Please do not remove this and leave it at the end of the file, where
1229 * Emacs will automagically detect them.
1230 * ---------------------------------------------------------------------
1233 * indent-tabs-mode: t