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 895 2004-01-19 13:53:43Z edwin $
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;
97 /*********************** function: tables_init *****************************
99 creates hashtables for symboltables
100 (called once at startup)
102 *****************************************************************************/
106 init_hashtable(&utf_hash, UTF_HASHSTART); /* hashtable for utf8-symbols */
107 init_hashtable(&string_hash, HASHSTART); /* hashtable for javastrings */
108 init_hashtable(&class_hash, HASHSTART); /* hashtable for classes */
111 count_utf_len += sizeof(utf*) * utf_hash.size;
116 /********************** function: tables_close ******************************
118 free memory for hashtables
120 *****************************************************************************/
122 void tables_close (stringdeleter del)
128 /* dispose utf symbols */
129 for (i=0; i<utf_hash.size; i++) {
132 /* process elements in external hash chain */
133 utf *nextu = u->hashlink;
134 MFREE (u->text, u1, u->blength);
140 /* dispose javastrings */
141 for (i=0; i<string_hash.size; i++) {
142 s = string_hash.ptr[i];
144 /* process elements in external hash chain */
145 literalstring *nexts = s->hashlink;
147 FREE(s, literalstring);
152 /* dispose hashtable structures */
153 MFREE (utf_hash.ptr, void*, utf_hash.size);
154 MFREE (string_hash.ptr, void*, string_hash.size);
155 MFREE (class_hash.ptr, void*, class_hash.size);
159 /********************* function: utf_display *********************************
161 write utf symbol to stdout (debugging purposes)
163 ******************************************************************************/
165 void utf_display(utf *u)
167 char *endpos = utf_end(u); /* points behind utf string */
168 char *utf_ptr = u->text; /* current position in utf text */
173 while (utf_ptr < endpos) {
174 /* read next unicode character */
175 u2 c = utf_nextu2(&utf_ptr);
176 if (c >= 32 && c <= 127) printf("%c", c);
184 /************************* function: log_utf *********************************
188 ******************************************************************************/
192 char buf[MAXLOGTEXT];
197 /********************** function: log_plain_utf ******************************
199 log utf symbol (without printing "LOG: " and newline)
201 ******************************************************************************/
203 void log_plain_utf(utf *u)
205 char buf[MAXLOGTEXT];
207 dolog_plain("%s",buf);
210 /************************ function: utf_sprint *******************************
212 write utf symbol into c-string (debugging purposes)
214 ******************************************************************************/
216 void utf_sprint (char *buffer, utf *u)
218 char *endpos = utf_end(u); /* points behind utf string */
219 char *utf_ptr = u->text; /* current position in utf text */
220 u2 pos = 0; /* position in c-string */
222 while (utf_ptr<endpos)
223 /* copy next unicode character */
224 buffer[pos++] = utf_nextu2(&utf_ptr);
226 /* terminate string */
231 /********************* Funktion: utf_fprint **********************************
233 write utf symbol into file
235 ******************************************************************************/
237 void utf_fprint (FILE *file, utf *u)
239 char *endpos = utf_end(u); /* points behind utf string */
240 char *utf_ptr = u->text; /* current position in utf text */
242 while (utf_ptr<endpos) {
243 /* read next unicode character */
244 u2 c = utf_nextu2(&utf_ptr);
246 if (c>=32 && c<=127) fprintf (file,"%c",c);
247 else fprintf (file,"?");
252 /****************** internal function: utf_hashkey ***************************
254 The hashkey is computed from the utf-text by using up to 8 characters.
255 For utf-symbols longer than 15 characters 3 characters are taken from
256 the beginning and the end, 2 characters are taken from the middle.
258 ******************************************************************************/
260 #define nbs(val) ((u4) *(++text) << val) /* get next byte, left shift by val */
261 #define fbs(val) ((u4) *( text) << val) /* get first byte, left shift by val */
263 static u4 utf_hashkey (char *text, u4 length)
265 char *start_pos = text; /* pointer to utf text */
270 case 0: /* empty string */
273 case 1: return fbs(0);
274 case 2: return fbs(0) ^ nbs(3);
275 case 3: return fbs(0) ^ nbs(3) ^ nbs(5);
276 case 4: return fbs(0) ^ nbs(2) ^ nbs(4) ^ nbs(6);
277 case 5: return fbs(0) ^ nbs(2) ^ nbs(3) ^ nbs(4) ^ nbs(6);
278 case 6: return fbs(0) ^ nbs(1) ^ nbs(2) ^ nbs(3) ^ nbs(5) ^ nbs(6);
279 case 7: return fbs(0) ^ nbs(1) ^ nbs(2) ^ nbs(3) ^ nbs(4) ^ nbs(5) ^ nbs(6);
280 case 8: return fbs(0) ^ nbs(1) ^ nbs(2) ^ nbs(3) ^ nbs(4) ^ nbs(5) ^ nbs(6) ^ nbs(7);
282 case 9: a = fbs(0) ^ nbs(1) ^ nbs(2);
284 return a ^ nbs(4) ^ nbs(5) ^ nbs(6) ^ nbs(7) ^ nbs(8);
288 a^= nbs(2) ^ nbs(3) ^ nbs(4);
290 return a ^ nbs(6) ^ nbs(7) ^ nbs(8) ^ nbs(9);
294 a^= nbs(2) ^ nbs(3) ^ nbs(4);
296 return a ^ nbs(6) ^ nbs(7) ^ nbs(8) ^ nbs(9) ^ nbs(10);
302 a^= nbs(5) ^ nbs(6) ^ nbs(7);
304 return a ^ nbs(9) ^ nbs(10);
306 case 13: a = fbs(0) ^ nbs(1);
312 return a ^ nbs(9) ^ nbs(10);
320 return a ^ nbs(9) ^ nbs(10) ^ nbs(11);
328 return a ^ nbs(9) ^ nbs(10) ^ nbs(11);
330 default: /* 3 characters from beginning */
335 /* 2 characters from middle */
336 text = start_pos + (length / 2);
341 /* 3 characters from end */
342 text = start_pos + length - 4;
347 return a ^ nbs(10) ^ nbs(11);
352 /*************************** function: utf_hashkey ***************************
354 compute the hashkey of a unicode string
356 ******************************************************************************/
358 u4 unicode_hashkey (u2 *text, u2 len)
360 return utf_hashkey((char*) text, len);
363 /************************ function: utf_new **********************************
365 Creates a new utf-symbol, the text of the symbol is passed as a
366 u1-array. The function searches the utf-hashtable for a utf-symbol
367 with this text. On success the element returned, otherwise a new
368 hashtable element is created.
370 If the number of entries in the hashtable exceeds twice the size of the
371 hashtable slots a reorganization of the hashtable is done and the utf
372 symbols are copied to a new hashtable with doubled size.
374 ******************************************************************************/
376 utf *utf_new (char *text, u2 length)
378 u4 key; /* hashkey computed from utf-text */
379 u4 slot; /* slot in hashtable */
380 utf *u; /* hashtable element */
383 /* log_text("utf_new entered");*/
388 key = utf_hashkey (text, length);
389 slot = key & (utf_hash.size-1);
390 u = utf_hash.ptr[slot];
392 /* search external hash chain for utf-symbol */
394 if (u->blength == length) {
396 /* compare text of hashtable elements */
397 for (i=0; i<length; i++)
398 if (text[i] != u->text[i]) goto nomatch;
401 count_utf_new_found++;
403 /* log_text("symbol found in hash table");*/
404 /* symbol found in hashtable */
415 u = u->hashlink; /* next element in external chain */
419 count_utf_len += sizeof(utf) + length;
422 /* location in hashtable found, create new utf element */
424 u->blength = length; /* length in bytes of utfstring */
425 u->hashlink = utf_hash.ptr[slot]; /* link in external hashchain */
426 u->text = mem_alloc(length/*JOWENN*/+1); /* allocate memory for utf-text */
427 memcpy(u->text,text,length); /* copy utf-text */
428 u->text[length]='\0';/*JOWENN*/
429 utf_hash.ptr[slot] = u; /* insert symbol into table */
431 utf_hash.entries++; /* update number of entries */
433 if ( utf_hash.entries > (utf_hash.size*2)) {
435 /* reorganization of hashtable, average length of
436 the external chains is approx. 2 */
440 hashtable newhash; /* the new hashtable */
442 /* create new hashtable, double the size */
443 init_hashtable(&newhash, utf_hash.size*2);
444 newhash.entries=utf_hash.entries;
447 count_utf_len += sizeof(utf*) * utf_hash.size;
450 /* transfer elements to new hashtable */
451 for (i=0; i<utf_hash.size; i++) {
452 u = (utf*) utf_hash.ptr[i];
454 utf *nextu = u -> hashlink;
455 u4 slot = (utf_hashkey(u->text,u->blength)) & (newhash.size-1);
457 u->hashlink = (utf*) newhash.ptr[slot];
458 newhash.ptr[slot] = u;
460 /* follow link in external hash chain */
465 /* dispose old table */
466 MFREE (utf_hash.ptr, void*, utf_hash.size);
474 /********************* function: utf_new_char ********************************
476 creates a new utf symbol, the text for this symbol is passed
477 as a c-string ( = char* )
479 ******************************************************************************/
481 utf *utf_new_char (char *text)
483 return utf_new(text, strlen(text));
487 /********************* function: utf_new_char ********************************
489 creates a new utf symbol, the text for this symbol is passed
490 as a c-string ( = char* )
491 "." characters are going to be replaced by "/". since the above function is
492 used often, this is a separte function, instead of an if
494 ******************************************************************************/
496 utf *utf_new_char_classname (char *text)
498 if (strchr(text,'.')) {
499 char *txt=strdup(text);
500 char *end=txt+strlen(txt);
503 for (c=txt;c<end;c++)
505 tmpRes=utf_new(txt,strlen(txt));
510 return utf_new(text, strlen(text));
513 /************************** Funktion: utf_show ******************************
515 writes the utf symbols in the utfhash to stdout and
516 displays the number of external hash chains grouped
517 according to the chainlength
520 *****************************************************************************/
525 #define CHAIN_LIMIT 20 /* limit for seperated enumeration */
527 u4 chain_count[CHAIN_LIMIT]; /* numbers of chains */
528 u4 max_chainlength = 0; /* maximum length of the chains */
529 u4 sum_chainlength = 0; /* sum of the chainlengths */
530 u4 beyond_limit = 0; /* number of utf-symbols in chains with length>=CHAIN_LIMIT-1 */
533 printf ("UTF-HASH:\n");
535 /* show element of utf-hashtable */
536 for (i=0; i<utf_hash.size; i++) {
537 utf *u = utf_hash.ptr[i];
539 printf ("SLOT %d: ", (int) i);
551 printf ("UTF-HASH: %d slots for %d entries\n",
552 (int) utf_hash.size, (int) utf_hash.entries );
555 if (utf_hash.entries == 0)
558 printf("chains:\n chainlength number of chains %% of utfstrings\n");
560 for (i=0;i<CHAIN_LIMIT;i++)
563 /* count numbers of hashchains according to their length */
564 for (i=0; i<utf_hash.size; i++) {
566 utf *u = (utf*) utf_hash.ptr[i];
569 /* determine chainlength */
575 /* update sum of all chainlengths */
576 sum_chainlength+=chain_length;
578 /* determine the maximum length of the chains */
579 if (chain_length>max_chainlength)
580 max_chainlength = chain_length;
582 /* update number of utf-symbols in chains with length>=CHAIN_LIMIT-1 */
583 if (chain_length>=CHAIN_LIMIT) {
584 beyond_limit+=chain_length;
585 chain_length=CHAIN_LIMIT-1;
588 /* update number of hashchains of current length */
589 chain_count[chain_length]++;
592 /* display results */
593 for (i=1;i<CHAIN_LIMIT-1;i++)
594 printf(" %2d %17d %18.2f%%\n",i,chain_count[i],(((float) chain_count[i]*i*100)/utf_hash.entries));
596 printf(" >=%2d %17d %18.2f%%\n",CHAIN_LIMIT-1,chain_count[CHAIN_LIMIT-1],((float) beyond_limit*100)/utf_hash.entries);
599 printf("max. chainlength:%5d\n",max_chainlength);
601 /* avg. chainlength = sum of chainlengths / number of chains */
602 printf("avg. chainlength:%5.2f\n",(float) sum_chainlength / (utf_hash.size-chain_count[0]));
605 /******************************************************************************
606 *********************** Misc support functions ********************************
607 ******************************************************************************/
610 /******************** Function: desc_to_type **********************************
612 Determines the corresponding Java base data type for a given type
615 ******************************************************************************/
617 u2 desc_to_type(utf *descriptor)
619 char *utf_ptr = descriptor->text; /* current position in utf text */
620 char logtext[MAXLOGTEXT];
622 if (descriptor->blength < 1) panic("Type-Descriptor is empty string");
624 switch (*utf_ptr++) {
629 case 'Z': return TYPE_INT;
630 case 'D': return TYPE_DOUBLE;
631 case 'F': return TYPE_FLOAT;
632 case 'J': return TYPE_LONG;
634 case '[': return TYPE_ADDRESS;
637 sprintf(logtext, "Invalid Type-Descriptor: ");
638 utf_sprint(logtext+strlen(logtext), descriptor);
645 /********************** Function: desc_typesize *******************************
647 Calculates the lenght in bytes needed for a data element of the type given
648 by its type descriptor.
650 ******************************************************************************/
652 u2 desc_typesize (utf *descriptor)
654 switch (desc_to_type(descriptor)) {
655 case TYPE_INT: return 4;
656 case TYPE_LONG: return 8;
657 case TYPE_FLOAT: return 4;
658 case TYPE_DOUBLE: return 8;
659 case TYPE_ADDRESS: return sizeof(voidptr);
665 /********************** function: utf_nextu2 *********************************
667 read the next unicode character from the utf string and
668 increment the utf-string pointer accordingly
670 ******************************************************************************/
672 u2 utf_nextu2(char **utf_ptr)
674 /* uncompressed unicode character */
676 /* current position in utf text */
677 unsigned char *utf = (unsigned char *) (*utf_ptr);
678 /* bytes representing the unicode character */
679 unsigned char ch1, ch2, ch3;
680 /* number of bytes used to represent the unicode character */
683 switch ((ch1 = utf[0]) >> 4) {
684 default: /* 1 byte */
688 case 0xD: /* 2 bytes */
689 if (((ch2 = utf[1]) & 0xC0) == 0x80) {
690 unsigned char high = ch1 & 0x1F;
691 unsigned char low = ch2 & 0x3F;
692 unicode_char = (high << 6) + low;
697 case 0xE: /* 2 or 3 bytes */
698 if (((ch2 = utf[1]) & 0xC0) == 0x80) {
699 if (((ch3 = utf[2]) & 0xC0) == 0x80) {
700 unsigned char low = ch3 & 0x3f;
701 unsigned char mid = ch2 & 0x3f;
702 unsigned char high = ch1 & 0x0f;
703 unicode_char = (((high << 6) + mid) << 6) + low;
711 /* update position in utf-text */
712 *utf_ptr = (char *) (utf + len);
716 /********************* function: is_valid_utf ********************************
718 return true if the given string is a valid UTF-8 string
720 utf_ptr...points to first character
721 end_pos...points after last character
723 ******************************************************************************/
725 static unsigned long min_codepoint[6] = {0,1L<<7,1L<<11,1L<<16,1L<<21,1L<<26};
728 is_valid_utf(char *utf_ptr,char *end_pos)
735 if (end_pos < utf_ptr) return false;
736 bytes = end_pos - utf_ptr;
739 /*dolog("%c %02x",c,c);*/
740 if (!c) return false; /* 0x00 is not allowed */
741 if ((c & 0x80) == 0) continue; /* ASCII */
743 if ((c & 0xe0) == 0xc0) len = 1; /* 110x xxxx */
744 else if ((c & 0xf0) == 0xe0) len = 2; /* 1110 xxxx */
745 else if ((c & 0xf8) == 0xf0) len = 3; /* 1111 0xxx */
746 else if ((c & 0xfc) == 0xf8) len = 4; /* 1111 10xx */
747 else if ((c & 0xfe) == 0xfc) len = 5; /* 1111 110x */
748 else return false; /* invalid leading byte */
750 if (len > 2) return false; /* Java limitation */
752 v = (unsigned long)c & (0x3f >> len);
754 if ((bytes -= len) < 0) return false; /* missing bytes */
756 for (i = len; i--; ) {
758 /*dolog(" %c %02x",c,c);*/
759 if ((c & 0xc0) != 0x80) /* 10xx xxxx */
761 v = (v<<6) | (c & 0x3f);
764 /* dolog("v=%d",v);*/
767 if (len != 1) return false; /* Java special */
770 /* Sun Java seems to allow overlong UTF-8 encodings */
772 if (v < min_codepoint[len]) { /* overlong UTF-8 */
774 fprintf(stderr,"WARNING: Overlong UTF-8 sequence found.\n");
775 /* XXX change this to panic? */
779 /* surrogates in UTF-8 seem to be allowed in Java classfiles */
780 /* if (v >= 0xd800 && v <= 0xdfff) return false; */ /* surrogates */
782 /* even these seem to be allowed */
783 /* if (v == 0xfffe || v == 0xffff) return false; */ /* invalid codepoints */
789 /********************* function: is_valid_name *******************************
791 return true if the given string may be used as a class/field/method name.
792 (Currently this only disallows empty strings and control characters.)
794 NOTE: The string is assumed to have passed is_valid_utf!
796 utf_ptr...points to first character
797 end_pos...points after last character
799 ******************************************************************************/
802 is_valid_name(char *utf_ptr,char *end_pos)
804 if (end_pos <= utf_ptr) return false; /* disallow empty names */
806 while (utf_ptr < end_pos) {
807 unsigned char c = *utf_ptr++;
809 if (c < 0x20) return false; /* disallow control characters */
810 if (c == 0xc0 && (unsigned char)*utf_ptr == 0x80) return false; /* disallow zero */
816 is_valid_name_utf(utf *u)
818 return is_valid_name(u->text,utf_end(u));
821 /******************** Function: class_new **************************************
823 searches for the class with the specified name in the classes hashtable,
824 if there is no such class a new classinfo structure is created and inserted
825 into the list of classes to be loaded
827 *******************************************************************************/
829 classinfo *class_new(utf *u)
831 classinfo *c; /* hashtable element */
832 u4 key; /* hashkey computed from classname */
833 u4 slot; /* slot in hashtable */
836 key = utf_hashkey (u->text, u->blength);
837 slot = key & (class_hash.size-1);
838 c = class_hash.ptr[slot];
840 /* search external hash chain for the class */
842 if (c->name->blength == u->blength) {
843 for (i=0; i<u->blength; i++)
844 if (u->text[i] != c->name->text[i]) goto nomatch;
846 /* class found in hashtable */
851 c = c->hashlink; /* next element in external chain */
854 /* location in hashtable found, create new classinfo structure */
857 count_class_infos += sizeof(classinfo);
860 c = GCNEW(classinfo, 1); /*JOWENN: NEW*/
864 c->packagename = NULL;
871 c->interfacescount = 0;
872 c->interfaces = NULL;
881 c->header.vftbl = NULL;
882 c->innerclasscount = 0;
883 c->innerclass = NULL;
885 c->initialized = false;
886 c->classvftbl = false;
890 /* prepare loading of the class */
891 list_addlast(&unloadedclasses, c);
893 /* insert class into the hashtable */
894 c->hashlink = class_hash.ptr[slot];
895 class_hash.ptr[slot] = c;
897 /* update number of hashtable-entries */
898 class_hash.entries++;
900 if (class_hash.entries > (class_hash.size*2)) {
902 /* reorganization of hashtable, average length of
903 the external chains is approx. 2 */
907 hashtable newhash; /* the new hashtable */
909 /* create new hashtable, double the size */
910 init_hashtable(&newhash, class_hash.size * 2);
911 newhash.entries = class_hash.entries;
913 /* transfer elements to new hashtable */
914 for (i = 0; i < class_hash.size; i++) {
915 c = (classinfo*) class_hash.ptr[i];
917 classinfo *nextc = c->hashlink;
918 u4 slot = (utf_hashkey(c->name->text, c->name->blength)) & (newhash.size - 1);
920 c->hashlink = newhash.ptr[slot];
921 newhash.ptr[slot] = c;
927 /* dispose old table */
928 MFREE(class_hash.ptr, void*, class_hash.size);
929 class_hash = newhash;
932 /* Array classes need further initialization. */
933 if (u->text[0] == '[') {
935 c->packagename = array_packagename;
938 /* Find the package name */
939 /* Classes in the unnamed package keep packagename == NULL. */
940 char *p = utf_end(c->name) - 1;
941 char *start = c->name->text;
942 for (;p > start; --p)
944 c->packagename = utf_new(start,p-start);
952 /******************** Function: class_get **************************************
954 searches for the class with the specified name in the classes hashtable
955 if there is no such class NULL is returned
957 *******************************************************************************/
959 classinfo *class_get(utf *u)
961 classinfo *c; /* hashtable element */
962 u4 key; /* hashkey computed from classname */
963 u4 slot; /* slot in hashtable */
966 key = utf_hashkey (u->text, u->blength);
967 slot = key & (class_hash.size-1);
968 c = class_hash.ptr[slot];
971 log_text("class_get: looking for class:");
973 /* search external hash-chain */
975 if (c->name->blength == u->blength) {
977 /* compare classnames */
978 for (i=0; i<u->blength; i++)
979 if (u->text[i] != c->name->text[i]) goto nomatch;
981 log_text("class_get: class found");
984 utf_display(c->name); */
985 /* class found in hashtable */
993 /* class not found */
997 /***************** Function: class_array_of ***********************************
999 Returns an array class with the given component class.
1000 The array class is dynamically created if neccessary.
1002 *******************************************************************************/
1004 classinfo *class_array_of(classinfo *component)
1009 /* Assemble the array class name */
1010 namelen = component->name->blength;
1012 if (component->name->text[0] == '[') {
1013 /* the component is itself an array */
1014 namebuf = DMNEW(char,namelen+1);
1016 memcpy(namebuf+1,component->name->text,namelen);
1020 /* the component is a non-array class */
1021 namebuf = DMNEW(char,namelen+3);
1024 memcpy(namebuf+2,component->name->text,namelen);
1025 namebuf[2+namelen] = ';';
1029 return class_new( utf_new(namebuf,namelen) );
1032 /*************** Function: class_multiarray_of ********************************
1034 Returns an array class with the given dimension and element class.
1035 The array class is dynamically created if neccessary.
1037 *******************************************************************************/
1039 classinfo *class_multiarray_of(int dim,classinfo *element)
1045 panic("Invalid array dimension requested");
1047 /* Assemble the array class name */
1048 namelen = element->name->blength;
1050 if (element->name->text[0] == '[') {
1051 /* the element is itself an array */
1052 namebuf = DMNEW(char,namelen+dim);
1053 memcpy(namebuf+dim,element->name->text,namelen);
1057 /* the element is a non-array class */
1058 namebuf = DMNEW(char,namelen+2+dim);
1060 memcpy(namebuf+dim+1,element->name->text,namelen);
1062 namebuf[namelen-1] = ';';
1064 memset(namebuf,'[',dim);
1066 return class_new( utf_new(namebuf,namelen) );
1069 /************************** function: utf_strlen ******************************
1071 determine number of unicode characters in the utf string
1073 *******************************************************************************/
1075 u4 utf_strlen(utf *u)
1077 char *endpos = utf_end(u); /* points behind utf string */
1078 char *utf_ptr = u->text; /* current position in utf text */
1079 u4 len = 0; /* number of unicode characters */
1081 while (utf_ptr<endpos) {
1083 /* next unicode character */
1084 utf_nextu2(&utf_ptr);
1087 if (utf_ptr!=endpos)
1088 /* string ended abruptly */
1089 panic("illegal utf string");
1096 * These are local overrides for various environment variables in Emacs.
1097 * Please do not remove this and leave it at the end of the file, where
1098 * Emacs will automagically detect them.
1099 * ---------------------------------------------------------------------
1102 * indent-tabs-mode: t