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 935 2004-03-05 23:49:12Z 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);
315 case 9: a = fbs(0) ^ nbs(1) ^ nbs(2);
317 return a ^ nbs(4) ^ nbs(5) ^ nbs(6) ^ nbs(7) ^ nbs(8);
321 a^= nbs(2) ^ nbs(3) ^ nbs(4);
323 return a ^ nbs(6) ^ nbs(7) ^ nbs(8) ^ nbs(9);
327 a^= nbs(2) ^ nbs(3) ^ nbs(4);
329 return a ^ nbs(6) ^ nbs(7) ^ nbs(8) ^ nbs(9) ^ nbs(10);
335 a^= nbs(5) ^ nbs(6) ^ nbs(7);
337 return a ^ nbs(9) ^ nbs(10);
339 case 13: a = fbs(0) ^ nbs(1);
345 return a ^ nbs(9) ^ nbs(10);
353 return a ^ nbs(9) ^ nbs(10) ^ nbs(11);
361 return a ^ nbs(9) ^ nbs(10) ^ nbs(11);
363 default: /* 3 characters from beginning */
368 /* 2 characters from middle */
369 text = start_pos + (length / 2);
374 /* 3 characters from end */
375 text = start_pos + length - 4;
380 return a ^ nbs(10) ^ nbs(11);
385 /*************************** function: utf_hashkey ***************************
387 compute the hashkey of a unicode string
389 ******************************************************************************/
391 u4 unicode_hashkey(u2 *text, u2 len)
393 return utf_hashkey((char*) text, len);
397 /************************ function: utf_new **********************************
399 Creates a new utf-symbol, the text of the symbol is passed as a
400 u1-array. The function searches the utf-hashtable for a utf-symbol
401 with this text. On success the element returned, otherwise a new
402 hashtable element is created.
404 If the number of entries in the hashtable exceeds twice the size of the
405 hashtable slots a reorganization of the hashtable is done and the utf
406 symbols are copied to a new hashtable with doubled size.
408 ******************************************************************************/
410 utf *utf_new(char *text, u2 length)
412 u4 key; /* hashkey computed from utf-text */
413 u4 slot; /* slot in hashtable */
414 utf *u; /* hashtable element */
417 /* log_text("utf_new entered");*/
422 key = utf_hashkey(text, length);
423 slot = key & (utf_hash.size-1);
424 u = utf_hash.ptr[slot];
426 /* search external hash chain for utf-symbol */
428 if (u->blength == length) {
430 /* compare text of hashtable elements */
431 for (i = 0; i < length; i++)
432 if (text[i] != u->text[i]) goto nomatch;
435 count_utf_new_found++;
437 /* log_text("symbol found in hash table");*/
438 /* symbol found in hashtable */
449 u = u->hashlink; /* next element in external chain */
453 count_utf_len += sizeof(utf) + length;
456 /* location in hashtable found, create new utf element */
458 u->blength = length; /* length in bytes of utfstring */
459 u->hashlink = utf_hash.ptr[slot]; /* link in external hashchain */
460 u->text = mem_alloc(length/*JOWENN*/+1); /* allocate memory for utf-text */
461 memcpy(u->text,text,length); /* copy utf-text */
462 u->text[length] = '\0';/*JOWENN*/
463 utf_hash.ptr[slot] = u; /* insert symbol into table */
465 utf_hash.entries++; /* update number of entries */
467 if (utf_hash.entries > (utf_hash.size * 2)) {
469 /* reorganization of hashtable, average length of
470 the external chains is approx. 2 */
474 hashtable newhash; /* the new hashtable */
476 /* create new hashtable, double the size */
477 init_hashtable(&newhash, utf_hash.size * 2);
478 newhash.entries = utf_hash.entries;
481 count_utf_len += sizeof(utf*) * utf_hash.size;
484 /* transfer elements to new hashtable */
485 for (i = 0; i < utf_hash.size; i++) {
486 u = (utf *) utf_hash.ptr[i];
488 utf *nextu = u->hashlink;
489 u4 slot = utf_hashkey(u->text, u->blength) & (newhash.size - 1);
491 u->hashlink = (utf *) newhash.ptr[slot];
492 newhash.ptr[slot] = u;
494 /* follow link in external hash chain */
499 /* dispose old table */
500 MFREE(utf_hash.ptr, void*, utf_hash.size);
508 /********************* function: utf_new_char ********************************
510 creates a new utf symbol, the text for this symbol is passed
511 as a c-string ( = char* )
513 ******************************************************************************/
515 utf *utf_new_char(char *text)
517 return utf_new(text, strlen(text));
521 /********************* function: utf_new_char ********************************
523 creates a new utf symbol, the text for this symbol is passed
524 as a c-string ( = char* )
525 "." characters are going to be replaced by "/". since the above function is
526 used often, this is a separte function, instead of an if
528 ******************************************************************************/
530 utf *utf_new_char_classname(char *text)
532 if (strchr(text, '.')) {
533 char *txt = strdup(text);
534 char *end = txt + strlen(txt);
537 for (c = txt; c < end; c++)
538 if (*c == '.') *c = '/';
539 tmpRes = utf_new(txt, strlen(txt));
544 return utf_new(text, strlen(text));
548 /************************** Funktion: utf_show ******************************
550 writes the utf symbols in the utfhash to stdout and
551 displays the number of external hash chains grouped
552 according to the chainlength
555 *****************************************************************************/
560 #define CHAIN_LIMIT 20 /* limit for seperated enumeration */
562 u4 chain_count[CHAIN_LIMIT]; /* numbers of chains */
563 u4 max_chainlength = 0; /* maximum length of the chains */
564 u4 sum_chainlength = 0; /* sum of the chainlengths */
565 u4 beyond_limit = 0; /* number of utf-symbols in chains with length>=CHAIN_LIMIT-1 */
568 printf ("UTF-HASH:\n");
570 /* show element of utf-hashtable */
571 for (i=0; i<utf_hash.size; i++) {
572 utf *u = utf_hash.ptr[i];
574 printf ("SLOT %d: ", (int) i);
586 printf ("UTF-HASH: %d slots for %d entries\n",
587 (int) utf_hash.size, (int) utf_hash.entries );
590 if (utf_hash.entries == 0)
593 printf("chains:\n chainlength number of chains %% of utfstrings\n");
595 for (i=0;i<CHAIN_LIMIT;i++)
598 /* count numbers of hashchains according to their length */
599 for (i=0; i<utf_hash.size; i++) {
601 utf *u = (utf*) utf_hash.ptr[i];
604 /* determine chainlength */
610 /* update sum of all chainlengths */
611 sum_chainlength+=chain_length;
613 /* determine the maximum length of the chains */
614 if (chain_length>max_chainlength)
615 max_chainlength = chain_length;
617 /* update number of utf-symbols in chains with length>=CHAIN_LIMIT-1 */
618 if (chain_length>=CHAIN_LIMIT) {
619 beyond_limit+=chain_length;
620 chain_length=CHAIN_LIMIT-1;
623 /* update number of hashchains of current length */
624 chain_count[chain_length]++;
627 /* display results */
628 for (i=1;i<CHAIN_LIMIT-1;i++)
629 printf(" %2d %17d %18.2f%%\n",i,chain_count[i],(((float) chain_count[i]*i*100)/utf_hash.entries));
631 printf(" >=%2d %17d %18.2f%%\n",CHAIN_LIMIT-1,chain_count[CHAIN_LIMIT-1],((float) beyond_limit*100)/utf_hash.entries);
634 printf("max. chainlength:%5d\n",max_chainlength);
636 /* avg. chainlength = sum of chainlengths / number of chains */
637 printf("avg. chainlength:%5.2f\n",(float) sum_chainlength / (utf_hash.size-chain_count[0]));
640 /******************************************************************************
641 *********************** Misc support functions ********************************
642 ******************************************************************************/
645 /******************** Function: desc_to_type **********************************
647 Determines the corresponding Java base data type for a given type
650 ******************************************************************************/
652 u2 desc_to_type(utf *descriptor)
654 char *utf_ptr = descriptor->text; /* current position in utf text */
655 char logtext[MAXLOGTEXT];
657 if (descriptor->blength < 1) panic("Type-Descriptor is empty string");
659 switch (*utf_ptr++) {
664 case 'Z': return TYPE_INT;
665 case 'D': return TYPE_DOUBLE;
666 case 'F': return TYPE_FLOAT;
667 case 'J': return TYPE_LONG;
669 case '[': return TYPE_ADDRESS;
672 sprintf(logtext, "Invalid Type-Descriptor: ");
673 utf_sprint(logtext+strlen(logtext), descriptor);
680 /********************** Function: desc_typesize *******************************
682 Calculates the lenght in bytes needed for a data element of the type given
683 by its type descriptor.
685 ******************************************************************************/
687 u2 desc_typesize(utf *descriptor)
689 switch (desc_to_type(descriptor)) {
690 case TYPE_INT: return 4;
691 case TYPE_LONG: return 8;
692 case TYPE_FLOAT: return 4;
693 case TYPE_DOUBLE: return 8;
694 case TYPE_ADDRESS: return sizeof(voidptr);
700 /********************** function: utf_nextu2 *********************************
702 read the next unicode character from the utf string and
703 increment the utf-string pointer accordingly
705 ******************************************************************************/
707 u2 utf_nextu2(char **utf_ptr)
709 /* uncompressed unicode character */
711 /* current position in utf text */
712 unsigned char *utf = (unsigned char *) (*utf_ptr);
713 /* bytes representing the unicode character */
714 unsigned char ch1, ch2, ch3;
715 /* number of bytes used to represent the unicode character */
718 switch ((ch1 = utf[0]) >> 4) {
719 default: /* 1 byte */
723 case 0xD: /* 2 bytes */
724 if (((ch2 = utf[1]) & 0xC0) == 0x80) {
725 unsigned char high = ch1 & 0x1F;
726 unsigned char low = ch2 & 0x3F;
727 unicode_char = (high << 6) + low;
732 case 0xE: /* 2 or 3 bytes */
733 if (((ch2 = utf[1]) & 0xC0) == 0x80) {
734 if (((ch3 = utf[2]) & 0xC0) == 0x80) {
735 unsigned char low = ch3 & 0x3f;
736 unsigned char mid = ch2 & 0x3f;
737 unsigned char high = ch1 & 0x0f;
738 unicode_char = (((high << 6) + mid) << 6) + low;
746 /* update position in utf-text */
747 *utf_ptr = (char *) (utf + len);
751 /********************* function: is_valid_utf ********************************
753 return true if the given string is a valid UTF-8 string
755 utf_ptr...points to first character
756 end_pos...points after last character
758 ******************************************************************************/
760 static unsigned long min_codepoint[6] = {0,1L<<7,1L<<11,1L<<16,1L<<21,1L<<26};
763 is_valid_utf(char *utf_ptr,char *end_pos)
770 if (end_pos < utf_ptr) return false;
771 bytes = end_pos - utf_ptr;
774 /*dolog("%c %02x",c,c);*/
775 if (!c) return false; /* 0x00 is not allowed */
776 if ((c & 0x80) == 0) continue; /* ASCII */
778 if ((c & 0xe0) == 0xc0) len = 1; /* 110x xxxx */
779 else if ((c & 0xf0) == 0xe0) len = 2; /* 1110 xxxx */
780 else if ((c & 0xf8) == 0xf0) len = 3; /* 1111 0xxx */
781 else if ((c & 0xfc) == 0xf8) len = 4; /* 1111 10xx */
782 else if ((c & 0xfe) == 0xfc) len = 5; /* 1111 110x */
783 else return false; /* invalid leading byte */
785 if (len > 2) return false; /* Java limitation */
787 v = (unsigned long)c & (0x3f >> len);
789 if ((bytes -= len) < 0) return false; /* missing bytes */
791 for (i = len; i--; ) {
793 /*dolog(" %c %02x",c,c);*/
794 if ((c & 0xc0) != 0x80) /* 10xx xxxx */
796 v = (v<<6) | (c & 0x3f);
799 /* dolog("v=%d",v);*/
802 if (len != 1) return false; /* Java special */
805 /* Sun Java seems to allow overlong UTF-8 encodings */
807 if (v < min_codepoint[len]) { /* overlong UTF-8 */
809 fprintf(stderr,"WARNING: Overlong UTF-8 sequence found.\n");
810 /* XXX change this to panic? */
814 /* surrogates in UTF-8 seem to be allowed in Java classfiles */
815 /* if (v >= 0xd800 && v <= 0xdfff) return false; */ /* surrogates */
817 /* even these seem to be allowed */
818 /* if (v == 0xfffe || v == 0xffff) return false; */ /* invalid codepoints */
824 /********************* function: is_valid_name *******************************
826 return true if the given string may be used as a class/field/method name.
827 (Currently this only disallows empty strings and control characters.)
829 NOTE: The string is assumed to have passed is_valid_utf!
831 utf_ptr...points to first character
832 end_pos...points after last character
834 ******************************************************************************/
837 is_valid_name(char *utf_ptr,char *end_pos)
839 if (end_pos <= utf_ptr) return false; /* disallow empty names */
841 while (utf_ptr < end_pos) {
842 unsigned char c = *utf_ptr++;
844 if (c < 0x20) return false; /* disallow control characters */
845 if (c == 0xc0 && (unsigned char)*utf_ptr == 0x80) return false; /* disallow zero */
851 is_valid_name_utf(utf *u)
853 return is_valid_name(u->text,utf_end(u));
856 /******************** Function: class_new **************************************
858 searches for the class with the specified name in the classes hashtable,
859 if there is no such class a new classinfo structure is created and inserted
860 into the list of classes to be loaded
862 *******************************************************************************/
864 classinfo *class_new(utf *u)
866 classinfo *c; /* hashtable element */
867 u4 key; /* hashkey computed from classname */
868 u4 slot; /* slot in hashtable */
871 key = utf_hashkey(u->text, u->blength);
872 slot = key & (class_hash.size - 1);
873 c = class_hash.ptr[slot];
875 /* search external hash chain for the class */
877 if (c->name->blength == u->blength) {
878 for (i = 0; i < u->blength; i++)
879 if (u->text[i] != c->name->text[i]) goto nomatch;
881 /* class found in hashtable */
886 c = c->hashlink; /* next element in external chain */
889 /* location in hashtable found, create new classinfo structure */
892 count_class_infos += sizeof(classinfo);
895 c = GCNEW(classinfo, 1); /*JOWENN: NEW*/
899 c->packagename = NULL;
906 c->interfacescount = 0;
907 c->interfaces = NULL;
916 c->header.vftbl = NULL;
917 c->innerclasscount = 0;
918 c->innerclass = NULL;
920 c->initialized = false;
921 c->classvftbl = false;
924 c->classloader = NULL;
926 /* prepare loading of the class */
927 list_addlast(&unloadedclasses, c);
929 /* insert class into the hashtable */
930 c->hashlink = class_hash.ptr[slot];
931 class_hash.ptr[slot] = c;
933 /* update number of hashtable-entries */
934 class_hash.entries++;
936 if (class_hash.entries > (class_hash.size * 2)) {
938 /* reorganization of hashtable, average length of
939 the external chains is approx. 2 */
943 hashtable newhash; /* the new hashtable */
945 /* create new hashtable, double the size */
946 init_hashtable(&newhash, class_hash.size * 2);
947 newhash.entries = class_hash.entries;
949 /* transfer elements to new hashtable */
950 for (i = 0; i < class_hash.size; i++) {
951 c = (classinfo*) class_hash.ptr[i];
953 classinfo *nextc = c->hashlink;
954 u4 slot = (utf_hashkey(c->name->text, c->name->blength)) & (newhash.size - 1);
956 c->hashlink = newhash.ptr[slot];
957 newhash.ptr[slot] = c;
963 /* dispose old table */
964 MFREE(class_hash.ptr, void*, class_hash.size);
965 class_hash = newhash;
968 /* Array classes need further initialization. */
969 if (u->text[0] == '[') {
971 c->packagename = array_packagename;
974 /* Find the package name */
975 /* Classes in the unnamed package keep packagename == NULL. */
976 char *p = utf_end(c->name) - 1;
977 char *start = c->name->text;
978 for (;p > start; --p)
980 c->packagename = utf_new(start,p-start);
989 /******************** Function: class_get **************************************
991 searches for the class with the specified name in the classes hashtable
992 if there is no such class NULL is returned
994 *******************************************************************************/
996 classinfo *class_get(utf *u)
998 classinfo *c; /* hashtable element */
999 u4 key; /* hashkey computed from classname */
1000 u4 slot; /* slot in hashtable */
1003 key = utf_hashkey (u->text, u->blength);
1004 slot = key & (class_hash.size-1);
1005 c = class_hash.ptr[slot];
1008 log_text("class_get: looking for class:");
1010 /* search external hash-chain */
1012 if (c->name->blength == u->blength) {
1014 /* compare classnames */
1015 for (i=0; i<u->blength; i++)
1016 if (u->text[i] != c->name->text[i]) goto nomatch;
1018 log_text("class_get: class found");
1021 utf_display(c->name); */
1022 /* class found in hashtable */
1030 /* class not found */
1034 /***************** Function: class_array_of ***********************************
1036 Returns an array class with the given component class.
1037 The array class is dynamically created if neccessary.
1039 *******************************************************************************/
1041 classinfo *class_array_of(classinfo *component)
1046 /* Assemble the array class name */
1047 namelen = component->name->blength;
1049 if (component->name->text[0] == '[') {
1050 /* the component is itself an array */
1051 namebuf = DMNEW(char,namelen+1);
1053 memcpy(namebuf+1,component->name->text,namelen);
1057 /* the component is a non-array class */
1058 namebuf = DMNEW(char,namelen+3);
1061 memcpy(namebuf+2,component->name->text,namelen);
1062 namebuf[2+namelen] = ';';
1066 return class_new( utf_new(namebuf,namelen) );
1069 /*************** Function: class_multiarray_of ********************************
1071 Returns an array class with the given dimension and element class.
1072 The array class is dynamically created if neccessary.
1074 *******************************************************************************/
1076 classinfo *class_multiarray_of(int dim,classinfo *element)
1082 panic("Invalid array dimension requested");
1084 /* Assemble the array class name */
1085 namelen = element->name->blength;
1087 if (element->name->text[0] == '[') {
1088 /* the element is itself an array */
1089 namebuf = DMNEW(char,namelen+dim);
1090 memcpy(namebuf+dim,element->name->text,namelen);
1094 /* the element is a non-array class */
1095 namebuf = DMNEW(char,namelen+2+dim);
1097 memcpy(namebuf+dim+1,element->name->text,namelen);
1099 namebuf[namelen-1] = ';';
1101 memset(namebuf,'[',dim);
1103 return class_new( utf_new(namebuf,namelen) );
1106 /************************** function: utf_strlen ******************************
1108 determine number of unicode characters in the utf string
1110 *******************************************************************************/
1112 u4 utf_strlen(utf *u)
1114 char *endpos = utf_end(u); /* points behind utf string */
1115 char *utf_ptr = u->text; /* current position in utf text */
1116 u4 len = 0; /* number of unicode characters */
1118 while (utf_ptr < endpos) {
1120 /* next unicode character */
1121 utf_nextu2(&utf_ptr);
1124 if (utf_ptr != endpos)
1125 /* string ended abruptly */
1126 panic("illegal utf string");
1133 * These are local overrides for various environment variables in Emacs.
1134 * Please do not remove this and leave it at the end of the file, where
1135 * Emacs will automagically detect them.
1136 * ---------------------------------------------------------------------
1139 * indent-tabs-mode: t