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 981 2004-03-26 00:34:51Z twisti $
44 #include <sys/types.h>
53 #include "threads/thread.h"
54 #include "threads/locks.h"
55 #include "toolbox/loging.h"
56 #include "toolbox/memory.h"
60 int count_utf_len = 0; /* size of utf hash */
61 int count_utf_new = 0; /* calls of utf_new */
62 int count_utf_new_found = 0; /* calls of utf_new with fast return */
64 hashtable utf_hash; /* hashtable for utf8-symbols */
65 hashtable string_hash; /* hashtable for javastrings */
66 hashtable class_hash; /* hashtable for classes */
68 /******************************************************************************
69 *********************** hashtable functions **********************************
70 ******************************************************************************/
72 /* hashsize must be power of 2 */
74 #define UTF_HASHSTART 16384 /* initial size of utf-hash */
75 #define HASHSTART 2048 /* initial size of javastring and class-hash */
78 /******************** function: init_hashtable ******************************
80 Initializes a hashtable structure and allocates memory.
81 The parameter size specifies the initial size of the hashtable.
83 *****************************************************************************/
85 void init_hashtable(hashtable *hash, u4 size)
91 hash->ptr = MNEW(void*, size);
94 for (i = 0; i < size; i++) hash->ptr[i] = NULL;
98 /*********************** function: tables_init *****************************
100 creates hashtables for symboltables
101 (called once at startup)
103 *****************************************************************************/
107 init_hashtable(&utf_hash, UTF_HASHSTART); /* hashtable for utf8-symbols */
108 init_hashtable(&string_hash, HASHSTART); /* hashtable for javastrings */
109 init_hashtable(&class_hash, HASHSTART); /* hashtable for classes */
112 count_utf_len += sizeof(utf*) * utf_hash.size;
118 /********************** function: tables_close ******************************
120 free memory for hashtables
122 *****************************************************************************/
124 void tables_close(stringdeleter del)
130 /* dispose utf symbols */
131 for (i = 0; i < utf_hash.size; i++) {
134 /* process elements in external hash chain */
135 utf *nextu = u->hashlink;
136 MFREE(u->text, u1, u->blength);
142 /* dispose javastrings */
143 for (i = 0; i < string_hash.size; i++) {
144 s = string_hash.ptr[i];
146 /* process elements in external hash chain */
147 literalstring *nexts = s->hashlink;
149 FREE(s, literalstring);
154 /* dispose hashtable structures */
155 MFREE(utf_hash.ptr, void*, utf_hash.size);
156 MFREE(string_hash.ptr, void*, string_hash.size);
157 MFREE(class_hash.ptr, void*, class_hash.size);
161 /********************* function: utf_display *********************************
163 write utf symbol to stdout (debugging purposes)
165 ******************************************************************************/
167 void utf_display(utf *u)
169 char *endpos = utf_end(u); /* points behind utf string */
170 char *utf_ptr = u->text; /* current position in utf text */
175 while (utf_ptr < endpos) {
176 /* read next unicode character */
177 u2 c = utf_nextu2(&utf_ptr);
178 if (c >= 32 && c <= 127) printf("%c", c);
186 /********************* function: utf_display *********************************
188 write utf symbol to stdout (debugging purposes)
190 ******************************************************************************/
192 void utf_display_classname(utf *u)
194 char *endpos = utf_end(u); /* points behind utf string */
195 char *utf_ptr = u->text; /* current position in utf text */
200 while (utf_ptr < endpos) {
201 /* read next unicode character */
202 u2 c = utf_nextu2(&utf_ptr);
203 if (c == '/') c = '.';
204 if (c >= 32 && c <= 127) printf("%c", c);
212 /************************* function: log_utf *********************************
216 ******************************************************************************/
220 char buf[MAXLOGTEXT];
226 /********************** function: log_plain_utf ******************************
228 log utf symbol (without printing "LOG: " and newline)
230 ******************************************************************************/
232 void log_plain_utf(utf *u)
234 char buf[MAXLOGTEXT];
236 dolog_plain("%s", buf);
240 /************************ function: utf_sprint *******************************
242 write utf symbol into c-string (debugging purposes)
244 ******************************************************************************/
246 void utf_sprint(char *buffer, utf *u)
248 char *endpos = utf_end(u); /* points behind utf string */
249 char *utf_ptr = u->text; /* current position in utf text */
250 u2 pos = 0; /* position in c-string */
252 while (utf_ptr < endpos)
253 /* copy next unicode character */
254 buffer[pos++] = utf_nextu2(&utf_ptr);
256 /* terminate string */
261 /********************* Funktion: utf_fprint **********************************
263 write utf symbol into file
265 ******************************************************************************/
267 void utf_fprint(FILE *file, utf *u)
269 char *endpos = utf_end(u); /* points behind utf string */
270 char *utf_ptr = u->text; /* current position in utf text */
275 while (utf_ptr < endpos) {
276 /* read next unicode character */
277 u2 c = utf_nextu2(&utf_ptr);
279 if (c >= 32 && c <= 127) fprintf(file, "%c", c);
280 else fprintf(file, "?");
285 /****************** internal function: utf_hashkey ***************************
287 The hashkey is computed from the utf-text by using up to 8 characters.
288 For utf-symbols longer than 15 characters 3 characters are taken from
289 the beginning and the end, 2 characters are taken from the middle.
291 ******************************************************************************/
293 #define nbs(val) ((u4) *(++text) << val) /* get next byte, left shift by val */
294 #define fbs(val) ((u4) *( text) << val) /* get first byte, left shift by val */
296 static u4 utf_hashkey(char *text, u4 length)
298 char *start_pos = text; /* pointer to utf text */
303 case 0: /* empty string */
306 case 1: return fbs(0);
307 case 2: return fbs(0) ^ nbs(3);
308 case 3: return fbs(0) ^ nbs(3) ^ nbs(5);
309 case 4: return fbs(0) ^ nbs(2) ^ nbs(4) ^ nbs(6);
310 case 5: return fbs(0) ^ nbs(2) ^ nbs(3) ^ nbs(4) ^ nbs(6);
311 case 6: return fbs(0) ^ nbs(1) ^ nbs(2) ^ nbs(3) ^ nbs(5) ^ nbs(6);
312 case 7: return fbs(0) ^ nbs(1) ^ nbs(2) ^ nbs(3) ^ nbs(4) ^ nbs(5) ^ nbs(6);
313 case 8: return fbs(0) ^ nbs(1) ^ nbs(2) ^ nbs(3) ^ nbs(4) ^ nbs(5) ^ nbs(6) ^ nbs(7);
320 return a ^ nbs(4) ^ nbs(5) ^ nbs(6) ^ nbs(7) ^ nbs(8);
329 return a ^ nbs(6) ^ nbs(7) ^ nbs(8) ^ nbs(9);
338 return a ^ nbs(6) ^ nbs(7) ^ nbs(8) ^ nbs(9) ^ nbs(10);
350 return a ^ nbs(9) ^ nbs(10);
362 return a ^ nbs(9) ^ nbs(10);
373 return a ^ nbs(9) ^ nbs(10) ^ nbs(11);
384 return a ^ nbs(9) ^ nbs(10) ^ nbs(11);
386 default: /* 3 characters from beginning */
392 /* 2 characters from middle */
393 text = start_pos + (length / 2);
398 /* 3 characters from end */
399 text = start_pos + length - 4;
404 return a ^ nbs(10) ^ nbs(11);
409 /*************************** function: utf_hashkey ***************************
411 compute the hashkey of a unicode string
413 ******************************************************************************/
415 u4 unicode_hashkey(u2 *text, u2 len)
417 return utf_hashkey((char*) text, len);
421 /************************ function: utf_new **********************************
423 Creates a new utf-symbol, the text of the symbol is passed as a
424 u1-array. The function searches the utf-hashtable for a utf-symbol
425 with this text. On success the element returned, otherwise a new
426 hashtable element is created.
428 If the number of entries in the hashtable exceeds twice the size of the
429 hashtable slots a reorganization of the hashtable is done and the utf
430 symbols are copied to a new hashtable with doubled size.
432 ******************************************************************************/
434 utf *utf_new(char *text, u2 length)
436 u4 key; /* hashkey computed from utf-text */
437 u4 slot; /* slot in hashtable */
438 utf *u; /* hashtable element */
441 /* log_text("utf_new entered");*/
446 key = utf_hashkey(text, length);
447 slot = key & (utf_hash.size-1);
448 u = utf_hash.ptr[slot];
450 /* search external hash chain for utf-symbol */
452 if (u->blength == length) {
454 /* compare text of hashtable elements */
455 for (i = 0; i < length; i++)
456 if (text[i] != u->text[i]) goto nomatch;
459 count_utf_new_found++;
461 /* log_text("symbol found in hash table");*/
462 /* symbol found in hashtable */
473 u = u->hashlink; /* next element in external chain */
477 count_utf_len += sizeof(utf) + length;
480 /* location in hashtable found, create new utf element */
482 u->blength = length; /* length in bytes of utfstring */
483 u->hashlink = utf_hash.ptr[slot]; /* link in external hashchain */
484 u->text = mem_alloc(length/*JOWENN*/+1); /* allocate memory for utf-text */
485 memcpy(u->text,text,length); /* copy utf-text */
486 u->text[length] = '\0';/*JOWENN*/
487 utf_hash.ptr[slot] = u; /* insert symbol into table */
489 utf_hash.entries++; /* update number of entries */
491 if (utf_hash.entries > (utf_hash.size * 2)) {
493 /* reorganization of hashtable, average length of
494 the external chains is approx. 2 */
498 hashtable newhash; /* the new hashtable */
500 /* create new hashtable, double the size */
501 init_hashtable(&newhash, utf_hash.size * 2);
502 newhash.entries = utf_hash.entries;
505 count_utf_len += sizeof(utf*) * utf_hash.size;
508 /* transfer elements to new hashtable */
509 for (i = 0; i < utf_hash.size; i++) {
510 u = (utf *) utf_hash.ptr[i];
512 utf *nextu = u->hashlink;
513 u4 slot = utf_hashkey(u->text, u->blength) & (newhash.size - 1);
515 u->hashlink = (utf *) newhash.ptr[slot];
516 newhash.ptr[slot] = u;
518 /* follow link in external hash chain */
523 /* dispose old table */
524 MFREE(utf_hash.ptr, void*, utf_hash.size);
532 /********************* function: utf_new_char ********************************
534 creates a new utf symbol, the text for this symbol is passed
535 as a c-string ( = char* )
537 ******************************************************************************/
539 utf *utf_new_char(char *text)
541 return utf_new(text, strlen(text));
545 /********************* function: utf_new_char ********************************
547 creates a new utf symbol, the text for this symbol is passed
548 as a c-string ( = char* )
549 "." characters are going to be replaced by "/". since the above function is
550 used often, this is a separte function, instead of an if
552 ******************************************************************************/
554 utf *utf_new_char_classname(char *text)
556 if (strchr(text, '.')) {
557 char *txt = strdup(text);
558 char *end = txt + strlen(txt);
561 for (c = txt; c < end; c++)
562 if (*c == '.') *c = '/';
563 tmpRes = utf_new(txt, strlen(txt));
568 return utf_new(text, strlen(text));
572 /************************** Funktion: utf_show ******************************
574 writes the utf symbols in the utfhash to stdout and
575 displays the number of external hash chains grouped
576 according to the chainlength
579 *****************************************************************************/
584 #define CHAIN_LIMIT 20 /* limit for seperated enumeration */
586 u4 chain_count[CHAIN_LIMIT]; /* numbers of chains */
587 u4 max_chainlength = 0; /* maximum length of the chains */
588 u4 sum_chainlength = 0; /* sum of the chainlengths */
589 u4 beyond_limit = 0; /* number of utf-symbols in chains with length>=CHAIN_LIMIT-1 */
592 printf ("UTF-HASH:\n");
594 /* show element of utf-hashtable */
595 for (i=0; i<utf_hash.size; i++) {
596 utf *u = utf_hash.ptr[i];
598 printf ("SLOT %d: ", (int) i);
610 printf ("UTF-HASH: %d slots for %d entries\n",
611 (int) utf_hash.size, (int) utf_hash.entries );
614 if (utf_hash.entries == 0)
617 printf("chains:\n chainlength number of chains %% of utfstrings\n");
619 for (i=0;i<CHAIN_LIMIT;i++)
622 /* count numbers of hashchains according to their length */
623 for (i=0; i<utf_hash.size; i++) {
625 utf *u = (utf*) utf_hash.ptr[i];
628 /* determine chainlength */
634 /* update sum of all chainlengths */
635 sum_chainlength+=chain_length;
637 /* determine the maximum length of the chains */
638 if (chain_length>max_chainlength)
639 max_chainlength = chain_length;
641 /* update number of utf-symbols in chains with length>=CHAIN_LIMIT-1 */
642 if (chain_length>=CHAIN_LIMIT) {
643 beyond_limit+=chain_length;
644 chain_length=CHAIN_LIMIT-1;
647 /* update number of hashchains of current length */
648 chain_count[chain_length]++;
651 /* display results */
652 for (i=1;i<CHAIN_LIMIT-1;i++)
653 printf(" %2d %17d %18.2f%%\n",i,chain_count[i],(((float) chain_count[i]*i*100)/utf_hash.entries));
655 printf(" >=%2d %17d %18.2f%%\n",CHAIN_LIMIT-1,chain_count[CHAIN_LIMIT-1],((float) beyond_limit*100)/utf_hash.entries);
658 printf("max. chainlength:%5d\n",max_chainlength);
660 /* avg. chainlength = sum of chainlengths / number of chains */
661 printf("avg. chainlength:%5.2f\n",(float) sum_chainlength / (utf_hash.size-chain_count[0]));
664 /******************************************************************************
665 *********************** Misc support functions ********************************
666 ******************************************************************************/
669 /******************** Function: desc_to_type **********************************
671 Determines the corresponding Java base data type for a given type
674 ******************************************************************************/
676 u2 desc_to_type(utf *descriptor)
678 char *utf_ptr = descriptor->text; /* current position in utf text */
679 char logtext[MAXLOGTEXT];
681 if (descriptor->blength < 1) panic("Type-Descriptor is empty string");
683 switch (*utf_ptr++) {
688 case 'Z': return TYPE_INT;
689 case 'D': return TYPE_DOUBLE;
690 case 'F': return TYPE_FLOAT;
691 case 'J': return TYPE_LONG;
693 case '[': return TYPE_ADDRESS;
696 sprintf(logtext, "Invalid Type-Descriptor: ");
697 utf_sprint(logtext+strlen(logtext), descriptor);
704 /********************** Function: desc_typesize *******************************
706 Calculates the lenght in bytes needed for a data element of the type given
707 by its type descriptor.
709 ******************************************************************************/
711 u2 desc_typesize(utf *descriptor)
713 switch (desc_to_type(descriptor)) {
714 case TYPE_INT: return 4;
715 case TYPE_LONG: return 8;
716 case TYPE_FLOAT: return 4;
717 case TYPE_DOUBLE: return 8;
718 case TYPE_ADDRESS: return sizeof(voidptr);
724 /********************** function: utf_nextu2 *********************************
726 read the next unicode character from the utf string and
727 increment the utf-string pointer accordingly
729 ******************************************************************************/
731 u2 utf_nextu2(char **utf_ptr)
733 /* uncompressed unicode character */
735 /* current position in utf text */
736 unsigned char *utf = (unsigned char *) (*utf_ptr);
737 /* bytes representing the unicode character */
738 unsigned char ch1, ch2, ch3;
739 /* number of bytes used to represent the unicode character */
742 switch ((ch1 = utf[0]) >> 4) {
743 default: /* 1 byte */
747 case 0xD: /* 2 bytes */
748 if (((ch2 = utf[1]) & 0xC0) == 0x80) {
749 unsigned char high = ch1 & 0x1F;
750 unsigned char low = ch2 & 0x3F;
751 unicode_char = (high << 6) + low;
756 case 0xE: /* 2 or 3 bytes */
757 if (((ch2 = utf[1]) & 0xC0) == 0x80) {
758 if (((ch3 = utf[2]) & 0xC0) == 0x80) {
759 unsigned char low = ch3 & 0x3f;
760 unsigned char mid = ch2 & 0x3f;
761 unsigned char high = ch1 & 0x0f;
762 unicode_char = (((high << 6) + mid) << 6) + low;
770 /* update position in utf-text */
771 *utf_ptr = (char *) (utf + len);
776 /********************* function: is_valid_utf ********************************
778 return true if the given string is a valid UTF-8 string
780 utf_ptr...points to first character
781 end_pos...points after last character
783 ******************************************************************************/
785 static unsigned long min_codepoint[6] = {0,1L<<7,1L<<11,1L<<16,1L<<21,1L<<26};
788 is_valid_utf(char *utf_ptr,char *end_pos)
795 if (end_pos < utf_ptr) return false;
796 bytes = end_pos - utf_ptr;
799 /*dolog("%c %02x",c,c);*/
800 if (!c) return false; /* 0x00 is not allowed */
801 if ((c & 0x80) == 0) continue; /* ASCII */
803 if ((c & 0xe0) == 0xc0) len = 1; /* 110x xxxx */
804 else if ((c & 0xf0) == 0xe0) len = 2; /* 1110 xxxx */
805 else if ((c & 0xf8) == 0xf0) len = 3; /* 1111 0xxx */
806 else if ((c & 0xfc) == 0xf8) len = 4; /* 1111 10xx */
807 else if ((c & 0xfe) == 0xfc) len = 5; /* 1111 110x */
808 else return false; /* invalid leading byte */
810 if (len > 2) return false; /* Java limitation */
812 v = (unsigned long)c & (0x3f >> len);
814 if ((bytes -= len) < 0) return false; /* missing bytes */
816 for (i = len; i--; ) {
818 /*dolog(" %c %02x",c,c);*/
819 if ((c & 0xc0) != 0x80) /* 10xx xxxx */
821 v = (v<<6) | (c & 0x3f);
824 /* dolog("v=%d",v);*/
827 if (len != 1) return false; /* Java special */
830 /* Sun Java seems to allow overlong UTF-8 encodings */
832 if (v < min_codepoint[len]) { /* overlong UTF-8 */
834 fprintf(stderr,"WARNING: Overlong UTF-8 sequence found.\n");
835 /* XXX change this to panic? */
839 /* surrogates in UTF-8 seem to be allowed in Java classfiles */
840 /* if (v >= 0xd800 && v <= 0xdfff) return false; */ /* surrogates */
842 /* even these seem to be allowed */
843 /* if (v == 0xfffe || v == 0xffff) return false; */ /* invalid codepoints */
849 /********************* function: is_valid_name *******************************
851 return true if the given string may be used as a class/field/method name.
852 (Currently this only disallows empty strings and control characters.)
854 NOTE: The string is assumed to have passed is_valid_utf!
856 utf_ptr...points to first character
857 end_pos...points after last character
859 ******************************************************************************/
862 is_valid_name(char *utf_ptr,char *end_pos)
864 if (end_pos <= utf_ptr) return false; /* disallow empty names */
866 while (utf_ptr < end_pos) {
867 unsigned char c = *utf_ptr++;
869 if (c < 0x20) return false; /* disallow control characters */
870 if (c == 0xc0 && (unsigned char)*utf_ptr == 0x80) return false; /* disallow zero */
876 is_valid_name_utf(utf *u)
878 return is_valid_name(u->text,utf_end(u));
881 /******************** Function: class_new **************************************
883 searches for the class with the specified name in the classes hashtable,
884 if there is no such class a new classinfo structure is created and inserted
885 into the list of classes to be loaded
887 *******************************************************************************/
889 classinfo *class_new(utf *u)
891 classinfo *c; /* hashtable element */
892 u4 key; /* hashkey computed from classname */
893 u4 slot; /* slot in hashtable */
896 key = utf_hashkey(u->text, u->blength);
897 slot = key & (class_hash.size - 1);
898 c = class_hash.ptr[slot];
900 /* search external hash chain for the class */
902 if (c->name->blength == u->blength) {
903 for (i = 0; i < u->blength; i++)
904 if (u->text[i] != c->name->text[i]) goto nomatch;
906 /* class found in hashtable */
911 c = c->hashlink; /* next element in external chain */
914 /* location in hashtable found, create new classinfo structure */
917 count_class_infos += sizeof(classinfo);
920 c = GCNEW(classinfo, 1); /*JOWENN: NEW*/
924 c->packagename = NULL;
931 c->interfacescount = 0;
932 c->interfaces = NULL;
941 c->header.vftbl = NULL;
942 c->innerclasscount = 0;
943 c->innerclass = NULL;
945 c->initialized = false;
946 c->classvftbl = false;
949 c->classloader = NULL;
950 c->sourcefile = NULL;
952 /* prepare loading of the class */
953 list_addlast(&unloadedclasses, c);
955 /* insert class into the hashtable */
956 c->hashlink = class_hash.ptr[slot];
957 class_hash.ptr[slot] = c;
959 /* update number of hashtable-entries */
960 class_hash.entries++;
962 if (class_hash.entries > (class_hash.size * 2)) {
964 /* reorganization of hashtable, average length of
965 the external chains is approx. 2 */
969 hashtable newhash; /* the new hashtable */
971 /* create new hashtable, double the size */
972 init_hashtable(&newhash, class_hash.size * 2);
973 newhash.entries = class_hash.entries;
975 /* transfer elements to new hashtable */
976 for (i = 0; i < class_hash.size; i++) {
977 c = (classinfo*) class_hash.ptr[i];
979 classinfo *nextc = c->hashlink;
980 u4 slot = (utf_hashkey(c->name->text, c->name->blength)) & (newhash.size - 1);
982 c->hashlink = newhash.ptr[slot];
983 newhash.ptr[slot] = c;
989 /* dispose old table */
990 MFREE(class_hash.ptr, void*, class_hash.size);
991 class_hash = newhash;
994 /* Array classes need further initialization. */
995 if (u->text[0] == '[') {
997 c->packagename = array_packagename;
1000 /* Find the package name */
1001 /* Classes in the unnamed package keep packagename == NULL. */
1002 char *p = utf_end(c->name) - 1;
1003 char *start = c->name->text;
1004 for (;p > start; --p)
1006 c->packagename = utf_new(start,p-start);
1015 /******************** Function: class_get **************************************
1017 searches for the class with the specified name in the classes hashtable
1018 if there is no such class NULL is returned
1020 *******************************************************************************/
1022 classinfo *class_get(utf *u)
1024 classinfo *c; /* hashtable element */
1025 u4 key; /* hashkey computed from classname */
1026 u4 slot; /* slot in hashtable */
1029 key = utf_hashkey (u->text, u->blength);
1030 slot = key & (class_hash.size-1);
1031 c = class_hash.ptr[slot];
1034 log_text("class_get: looking for class:");
1036 /* search external hash-chain */
1038 if (c->name->blength == u->blength) {
1040 /* compare classnames */
1041 for (i=0; i<u->blength; i++)
1042 if (u->text[i] != c->name->text[i]) goto nomatch;
1044 log_text("class_get: class found");
1047 utf_display(c->name); */
1048 /* class found in hashtable */
1056 /* class not found */
1060 /***************** Function: class_array_of ***********************************
1062 Returns an array class with the given component class.
1063 The array class is dynamically created if neccessary.
1065 *******************************************************************************/
1067 classinfo *class_array_of(classinfo *component)
1072 /* Assemble the array class name */
1073 namelen = component->name->blength;
1075 if (component->name->text[0] == '[') {
1076 /* the component is itself an array */
1077 namebuf = DMNEW(char,namelen+1);
1079 memcpy(namebuf+1,component->name->text,namelen);
1083 /* the component is a non-array class */
1084 namebuf = DMNEW(char,namelen+3);
1087 memcpy(namebuf+2,component->name->text,namelen);
1088 namebuf[2+namelen] = ';';
1092 return class_new( utf_new(namebuf,namelen) );
1095 /*************** Function: class_multiarray_of ********************************
1097 Returns an array class with the given dimension and element class.
1098 The array class is dynamically created if neccessary.
1100 *******************************************************************************/
1102 classinfo *class_multiarray_of(int dim,classinfo *element)
1108 panic("Invalid array dimension requested");
1110 /* Assemble the array class name */
1111 namelen = element->name->blength;
1113 if (element->name->text[0] == '[') {
1114 /* the element is itself an array */
1115 namebuf = DMNEW(char,namelen+dim);
1116 memcpy(namebuf+dim,element->name->text,namelen);
1120 /* the element is a non-array class */
1121 namebuf = DMNEW(char,namelen+2+dim);
1123 memcpy(namebuf+dim+1,element->name->text,namelen);
1125 namebuf[namelen-1] = ';';
1127 memset(namebuf,'[',dim);
1129 return class_new( utf_new(namebuf,namelen) );
1132 /************************** function: utf_strlen ******************************
1134 determine number of unicode characters in the utf string
1136 *******************************************************************************/
1138 u4 utf_strlen(utf *u)
1140 char *endpos = utf_end(u); /* points behind utf string */
1141 char *utf_ptr = u->text; /* current position in utf text */
1142 u4 len = 0; /* number of unicode characters */
1144 while (utf_ptr < endpos) {
1146 /* next unicode character */
1147 utf_nextu2(&utf_ptr);
1150 if (utf_ptr != endpos)
1151 /* string ended abruptly */
1152 panic("illegal utf string");
1159 * These are local overrides for various environment variables in Emacs.
1160 * Please do not remove this and leave it at the end of the file, where
1161 * Emacs will automagically detect them.
1162 * ---------------------------------------------------------------------
1165 * indent-tabs-mode: t