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 1019 2004-04-10 13:33:21Z twisti $
47 #include <sys/types.h>
55 #include "threads/thread.h"
56 #include "threads/locks.h"
57 #include "toolbox/loging.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 */
467 /* log_text("utf_new entered");*/
472 key = utf_hashkey(text, length);
473 slot = key & (utf_hash.size-1);
474 u = utf_hash.ptr[slot];
476 /* search external hash chain for utf-symbol */
478 if (u->blength == length) {
480 /* compare text of hashtable elements */
481 for (i = 0; i < length; i++)
482 if (text[i] != u->text[i]) goto nomatch;
485 count_utf_new_found++;
487 /* log_text("symbol found in hash table");*/
488 /* symbol found in hashtable */
499 u = u->hashlink; /* next element in external chain */
503 count_utf_len += sizeof(utf) + length;
506 /* location in hashtable found, create new utf element */
508 u->blength = length; /* length in bytes of utfstring */
509 u->hashlink = utf_hash.ptr[slot]; /* link in external hashchain */
510 u->text = mem_alloc(length/*JOWENN*/+1); /* allocate memory for utf-text */
511 memcpy(u->text,text,length); /* copy utf-text */
512 u->text[length] = '\0';/*JOWENN*/
513 utf_hash.ptr[slot] = u; /* insert symbol into table */
515 utf_hash.entries++; /* update number of entries */
517 if (utf_hash.entries > (utf_hash.size * 2)) {
519 /* reorganization of hashtable, average length of
520 the external chains is approx. 2 */
524 hashtable newhash; /* the new hashtable */
526 /* create new hashtable, double the size */
527 init_hashtable(&newhash, utf_hash.size * 2);
528 newhash.entries = utf_hash.entries;
531 count_utf_len += sizeof(utf*) * utf_hash.size;
534 /* transfer elements to new hashtable */
535 for (i = 0; i < utf_hash.size; i++) {
536 u = (utf *) utf_hash.ptr[i];
538 utf *nextu = u->hashlink;
539 u4 slot = utf_hashkey(u->text, u->blength) & (newhash.size - 1);
541 u->hashlink = (utf *) newhash.ptr[slot];
542 newhash.ptr[slot] = u;
544 /* follow link in external hash chain */
549 /* dispose old table */
550 MFREE(utf_hash.ptr, void*, utf_hash.size);
557 utf *utf_new(char *text, u2 length)
560 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
563 r = utf_new_int(text, length);
564 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
571 /********************* function: utf_new_char ********************************
573 creates a new utf symbol, the text for this symbol is passed
574 as a c-string ( = char* )
576 ******************************************************************************/
578 utf *utf_new_char(char *text)
580 return utf_new(text, strlen(text));
584 /********************* function: utf_new_char ********************************
586 creates a new utf symbol, the text for this symbol is passed
587 as a c-string ( = char* )
588 "." characters are going to be replaced by "/". since the above function is
589 used often, this is a separte function, instead of an if
591 ******************************************************************************/
593 utf *utf_new_char_classname(char *text)
595 if (strchr(text, '.')) {
596 char *txt = strdup(text);
597 char *end = txt + strlen(txt);
600 for (c = txt; c < end; c++)
601 if (*c == '.') *c = '/';
602 tmpRes = utf_new(txt, strlen(txt));
607 return utf_new(text, strlen(text));
611 /************************** Funktion: utf_show ******************************
613 writes the utf symbols in the utfhash to stdout and
614 displays the number of external hash chains grouped
615 according to the chainlength
618 *****************************************************************************/
623 #define CHAIN_LIMIT 20 /* limit for seperated enumeration */
625 u4 chain_count[CHAIN_LIMIT]; /* numbers of chains */
626 u4 max_chainlength = 0; /* maximum length of the chains */
627 u4 sum_chainlength = 0; /* sum of the chainlengths */
628 u4 beyond_limit = 0; /* number of utf-symbols in chains with length>=CHAIN_LIMIT-1 */
631 printf ("UTF-HASH:\n");
633 /* show element of utf-hashtable */
634 for (i=0; i<utf_hash.size; i++) {
635 utf *u = utf_hash.ptr[i];
637 printf ("SLOT %d: ", (int) i);
649 printf ("UTF-HASH: %d slots for %d entries\n",
650 (int) utf_hash.size, (int) utf_hash.entries );
653 if (utf_hash.entries == 0)
656 printf("chains:\n chainlength number of chains %% of utfstrings\n");
658 for (i=0;i<CHAIN_LIMIT;i++)
661 /* count numbers of hashchains according to their length */
662 for (i=0; i<utf_hash.size; i++) {
664 utf *u = (utf*) utf_hash.ptr[i];
667 /* determine chainlength */
673 /* update sum of all chainlengths */
674 sum_chainlength+=chain_length;
676 /* determine the maximum length of the chains */
677 if (chain_length>max_chainlength)
678 max_chainlength = chain_length;
680 /* update number of utf-symbols in chains with length>=CHAIN_LIMIT-1 */
681 if (chain_length>=CHAIN_LIMIT) {
682 beyond_limit+=chain_length;
683 chain_length=CHAIN_LIMIT-1;
686 /* update number of hashchains of current length */
687 chain_count[chain_length]++;
690 /* display results */
691 for (i=1;i<CHAIN_LIMIT-1;i++)
692 printf(" %2d %17d %18.2f%%\n",i,chain_count[i],(((float) chain_count[i]*i*100)/utf_hash.entries));
694 printf(" >=%2d %17d %18.2f%%\n",CHAIN_LIMIT-1,chain_count[CHAIN_LIMIT-1],((float) beyond_limit*100)/utf_hash.entries);
697 printf("max. chainlength:%5d\n",max_chainlength);
699 /* avg. chainlength = sum of chainlengths / number of chains */
700 printf("avg. chainlength:%5.2f\n",(float) sum_chainlength / (utf_hash.size-chain_count[0]));
703 /******************************************************************************
704 *********************** Misc support functions ********************************
705 ******************************************************************************/
708 /******************** Function: desc_to_type **********************************
710 Determines the corresponding Java base data type for a given type
713 ******************************************************************************/
715 u2 desc_to_type(utf *descriptor)
717 char *utf_ptr = descriptor->text; /* current position in utf text */
718 char logtext[MAXLOGTEXT];
720 if (descriptor->blength < 1) panic("Type-Descriptor is empty string");
722 switch (*utf_ptr++) {
727 case 'Z': return TYPE_INT;
728 case 'D': return TYPE_DOUBLE;
729 case 'F': return TYPE_FLOAT;
730 case 'J': return TYPE_LONG;
732 case '[': return TYPE_ADDRESS;
735 sprintf(logtext, "Invalid Type-Descriptor: ");
736 utf_sprint(logtext+strlen(logtext), descriptor);
743 /********************** Function: desc_typesize *******************************
745 Calculates the lenght in bytes needed for a data element of the type given
746 by its type descriptor.
748 ******************************************************************************/
750 u2 desc_typesize(utf *descriptor)
752 switch (desc_to_type(descriptor)) {
753 case TYPE_INT: return 4;
754 case TYPE_LONG: return 8;
755 case TYPE_FLOAT: return 4;
756 case TYPE_DOUBLE: return 8;
757 case TYPE_ADDRESS: return sizeof(voidptr);
763 /********************** function: utf_nextu2 *********************************
765 read the next unicode character from the utf string and
766 increment the utf-string pointer accordingly
768 ******************************************************************************/
770 u2 utf_nextu2(char **utf_ptr)
772 /* uncompressed unicode character */
774 /* current position in utf text */
775 unsigned char *utf = (unsigned char *) (*utf_ptr);
776 /* bytes representing the unicode character */
777 unsigned char ch1, ch2, ch3;
778 /* number of bytes used to represent the unicode character */
781 switch ((ch1 = utf[0]) >> 4) {
782 default: /* 1 byte */
786 case 0xD: /* 2 bytes */
787 if (((ch2 = utf[1]) & 0xC0) == 0x80) {
788 unsigned char high = ch1 & 0x1F;
789 unsigned char low = ch2 & 0x3F;
790 unicode_char = (high << 6) + low;
795 case 0xE: /* 2 or 3 bytes */
796 if (((ch2 = utf[1]) & 0xC0) == 0x80) {
797 if (((ch3 = utf[2]) & 0xC0) == 0x80) {
798 unsigned char low = ch3 & 0x3f;
799 unsigned char mid = ch2 & 0x3f;
800 unsigned char high = ch1 & 0x0f;
801 unicode_char = (((high << 6) + mid) << 6) + low;
809 /* update position in utf-text */
810 *utf_ptr = (char *) (utf + len);
815 /********************* function: is_valid_utf ********************************
817 return true if the given string is a valid UTF-8 string
819 utf_ptr...points to first character
820 end_pos...points after last character
822 ******************************************************************************/
824 static unsigned long min_codepoint[6] = {0,1L<<7,1L<<11,1L<<16,1L<<21,1L<<26};
827 is_valid_utf(char *utf_ptr,char *end_pos)
834 if (end_pos < utf_ptr) return false;
835 bytes = end_pos - utf_ptr;
838 /*dolog("%c %02x",c,c);*/
839 if (!c) return false; /* 0x00 is not allowed */
840 if ((c & 0x80) == 0) continue; /* ASCII */
842 if ((c & 0xe0) == 0xc0) len = 1; /* 110x xxxx */
843 else if ((c & 0xf0) == 0xe0) len = 2; /* 1110 xxxx */
844 else if ((c & 0xf8) == 0xf0) len = 3; /* 1111 0xxx */
845 else if ((c & 0xfc) == 0xf8) len = 4; /* 1111 10xx */
846 else if ((c & 0xfe) == 0xfc) len = 5; /* 1111 110x */
847 else return false; /* invalid leading byte */
849 if (len > 2) return false; /* Java limitation */
851 v = (unsigned long)c & (0x3f >> len);
853 if ((bytes -= len) < 0) return false; /* missing bytes */
855 for (i = len; i--; ) {
857 /*dolog(" %c %02x",c,c);*/
858 if ((c & 0xc0) != 0x80) /* 10xx xxxx */
860 v = (v<<6) | (c & 0x3f);
863 /* dolog("v=%d",v);*/
866 if (len != 1) return false; /* Java special */
869 /* Sun Java seems to allow overlong UTF-8 encodings */
871 if (v < min_codepoint[len]) { /* overlong UTF-8 */
873 fprintf(stderr,"WARNING: Overlong UTF-8 sequence found.\n");
874 /* XXX change this to panic? */
878 /* surrogates in UTF-8 seem to be allowed in Java classfiles */
879 /* if (v >= 0xd800 && v <= 0xdfff) return false; */ /* surrogates */
881 /* even these seem to be allowed */
882 /* if (v == 0xfffe || v == 0xffff) return false; */ /* invalid codepoints */
888 /********************* function: is_valid_name *******************************
890 return true if the given string may be used as a class/field/method name.
891 (Currently this only disallows empty strings and control characters.)
893 NOTE: The string is assumed to have passed is_valid_utf!
895 utf_ptr...points to first character
896 end_pos...points after last character
898 ******************************************************************************/
901 is_valid_name(char *utf_ptr,char *end_pos)
903 if (end_pos <= utf_ptr) return false; /* disallow empty names */
905 while (utf_ptr < end_pos) {
906 unsigned char c = *utf_ptr++;
908 if (c < 0x20) return false; /* disallow control characters */
909 if (c == 0xc0 && (unsigned char)*utf_ptr == 0x80) return false; /* disallow zero */
915 is_valid_name_utf(utf *u)
917 return is_valid_name(u->text,utf_end(u));
920 /******************** Function: class_new **************************************
922 searches for the class with the specified name in the classes hashtable,
923 if there is no such class a new classinfo structure is created and inserted
924 into the list of classes to be loaded
926 *******************************************************************************/
928 classinfo *class_new_int(utf *u)
930 classinfo *c; /* hashtable element */
931 u4 key; /* hashkey computed from classname */
932 u4 slot; /* slot in hashtable */
935 key = utf_hashkey(u->text, u->blength);
936 slot = key & (class_hash.size - 1);
937 c = class_hash.ptr[slot];
939 /* search external hash chain for the class */
941 if (c->name->blength == u->blength) {
942 for (i = 0; i < u->blength; i++)
943 if (u->text[i] != c->name->text[i]) goto nomatch;
945 /* class found in hashtable */
950 c = c->hashlink; /* next element in external chain */
953 /* location in hashtable found, create new classinfo structure */
956 count_class_infos += sizeof(classinfo);
959 c = GCNEW(classinfo, 1); /*JOWENN: NEW*/
963 c->packagename = NULL;
970 c->interfacescount = 0;
971 c->interfaces = NULL;
980 c->header.vftbl = NULL;
981 c->innerclasscount = 0;
982 c->innerclass = NULL;
984 c->initialized = false;
985 c->classvftbl = false;
988 c->classloader = NULL;
989 c->sourcefile = NULL;
991 /* prepare loading of the class */
992 list_addlast(&unloadedclasses, c);
994 /* insert class into the hashtable */
995 c->hashlink = class_hash.ptr[slot];
996 class_hash.ptr[slot] = c;
998 /* update number of hashtable-entries */
999 class_hash.entries++;
1001 if (class_hash.entries > (class_hash.size * 2)) {
1003 /* reorganization of hashtable, average length of
1004 the external chains is approx. 2 */
1008 hashtable newhash; /* the new hashtable */
1010 /* create new hashtable, double the size */
1011 init_hashtable(&newhash, class_hash.size * 2);
1012 newhash.entries = class_hash.entries;
1014 /* transfer elements to new hashtable */
1015 for (i = 0; i < class_hash.size; i++) {
1016 c = (classinfo*) class_hash.ptr[i];
1018 classinfo *nextc = c->hashlink;
1019 u4 slot = (utf_hashkey(c->name->text, c->name->blength)) & (newhash.size - 1);
1021 c->hashlink = newhash.ptr[slot];
1022 newhash.ptr[slot] = c;
1028 /* dispose old table */
1029 MFREE(class_hash.ptr, void*, class_hash.size);
1030 class_hash = newhash;
1033 /* Array classes need further initialization. */
1034 if (u->text[0] == '[') {
1036 c->packagename = array_packagename;
1039 /* Find the package name */
1040 /* Classes in the unnamed package keep packagename == NULL. */
1041 char *p = utf_end(c->name) - 1;
1042 char *start = c->name->text;
1043 for (;p > start; --p)
1045 c->packagename = utf_new(start,p-start);
1053 classinfo *class_new(utf *u)
1056 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1059 r = class_new_int(u);
1060 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1067 /******************** Function: class_get **************************************
1069 searches for the class with the specified name in the classes hashtable
1070 if there is no such class NULL is returned
1072 *******************************************************************************/
1074 classinfo *class_get(utf *u)
1076 classinfo *c; /* hashtable element */
1077 u4 key; /* hashkey computed from classname */
1078 u4 slot; /* slot in hashtable */
1081 key = utf_hashkey (u->text, u->blength);
1082 slot = key & (class_hash.size-1);
1083 c = class_hash.ptr[slot];
1086 log_text("class_get: looking for class:");
1088 /* search external hash-chain */
1090 if (c->name->blength == u->blength) {
1092 /* compare classnames */
1093 for (i=0; i<u->blength; i++)
1094 if (u->text[i] != c->name->text[i]) goto nomatch;
1096 log_text("class_get: class found");
1099 utf_display(c->name); */
1100 /* class found in hashtable */
1108 /* class not found */
1112 /***************** Function: class_array_of ***********************************
1114 Returns an array class with the given component class.
1115 The array class is dynamically created if neccessary.
1117 *******************************************************************************/
1119 classinfo *class_array_of(classinfo *component)
1124 /* Assemble the array class name */
1125 namelen = component->name->blength;
1127 if (component->name->text[0] == '[') {
1128 /* the component is itself an array */
1129 namebuf = DMNEW(char,namelen+1);
1131 memcpy(namebuf+1,component->name->text,namelen);
1135 /* the component is a non-array class */
1136 namebuf = DMNEW(char,namelen+3);
1139 memcpy(namebuf+2,component->name->text,namelen);
1140 namebuf[2+namelen] = ';';
1144 return class_new( utf_new(namebuf,namelen) );
1147 /*************** Function: class_multiarray_of ********************************
1149 Returns an array class with the given dimension and element class.
1150 The array class is dynamically created if neccessary.
1152 *******************************************************************************/
1154 classinfo *class_multiarray_of(int dim,classinfo *element)
1160 panic("Invalid array dimension requested");
1162 /* Assemble the array class name */
1163 namelen = element->name->blength;
1165 if (element->name->text[0] == '[') {
1166 /* the element is itself an array */
1167 namebuf = DMNEW(char,namelen+dim);
1168 memcpy(namebuf+dim,element->name->text,namelen);
1172 /* the element is a non-array class */
1173 namebuf = DMNEW(char,namelen+2+dim);
1175 memcpy(namebuf+dim+1,element->name->text,namelen);
1177 namebuf[namelen-1] = ';';
1179 memset(namebuf,'[',dim);
1181 return class_new( utf_new(namebuf,namelen) );
1184 /************************** function: utf_strlen ******************************
1186 determine number of unicode characters in the utf string
1188 *******************************************************************************/
1190 u4 utf_strlen(utf *u)
1192 char *endpos = utf_end(u); /* points behind utf string */
1193 char *utf_ptr = u->text; /* current position in utf text */
1194 u4 len = 0; /* number of unicode characters */
1196 while (utf_ptr < endpos) {
1198 /* next unicode character */
1199 utf_nextu2(&utf_ptr);
1202 if (utf_ptr != endpos)
1203 /* string ended abruptly */
1204 panic("illegal utf string");
1211 * These are local overrides for various environment variables in Emacs.
1212 * Please do not remove this and leave it at the end of the file, where
1213 * Emacs will automagically detect them.
1214 * ---------------------------------------------------------------------
1217 * indent-tabs-mode: t