1 /****************************** native.c ***************************************
3 Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
5 See file COPYRIGHT for information on usage and disclaimer of warranties
7 Contains the tables for native methods.
8 The .hh files created with the header file generator are all included here
9 as are the C functions implementing these methods.
11 Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at
12 Roman Obermaisser EMAIL: cacao@complang.tuwien.ac.at
13 Andreas Krall EMAIL: cacao@complang.tuwien.ac.at
15 Last Change: 1996/11/14
17 *******************************************************************************/
23 #include "nativetypes.hh"
34 #include "threads/thread.h" /* schani */
35 #include "threads/locks.h"
37 /* Include files for IO functions */
41 #include <sys/types.h>
47 #include "../threads/threadio.h"
49 /* searchpath for classfiles */
50 static char *classpath;
52 /* for java-string to char conversion */
53 #define MAXSTRINGSIZE 1000
55 /******************** systemclasses required for native methods ***************/
57 static classinfo *class_java_lang_Class;
58 static classinfo *class_java_lang_Cloneable;
59 static classinfo *class_java_lang_CloneNotSupportedException;
60 static classinfo *class_java_lang_System;
61 static classinfo *class_java_lang_ClassLoader;
62 static classinfo *class_java_lang_ClassNotFoundException;
63 static classinfo *class_java_lang_InstantiationException;
64 static classinfo *class_java_lang_NoSuchMethodError;
65 static classinfo *class_java_lang_NoSuchFieldError;
66 static classinfo *class_java_lang_ClassFormatError;
67 static classinfo *class_java_lang_IllegalArgumentException;
68 static classinfo *class_java_lang_ArrayIndexOutOfBoundsException;
69 static classinfo *class_java_lang_NoSuchFieldException;
70 static classinfo *class_java_io_SyncFailedException;
71 static classinfo *class_java_io_IOException;
72 static classinfo *class_java_io_UnixFileSystem;
73 static classinfo *class_java_security_PrivilegedActionException;
74 static classinfo *class_java_net_UnknownHostException;
75 static classinfo *class_java_net_SocketException;
76 static classinfo *class_java_lang_NoSuchMethodException;
77 static classinfo *class_java_lang_Double;
78 static classinfo *class_java_lang_Float;
79 static classinfo *class_java_lang_Long;
80 static classinfo *class_java_lang_Byte;
81 static classinfo *class_java_lang_Short;
82 static classinfo *class_java_lang_Boolean;
83 static classinfo *class_java_lang_Void;
84 static classinfo *class_java_lang_Character;
85 static classinfo *class_java_lang_Integer;
87 /* the system classloader object */
88 struct java_lang_ClassLoader *SystemClassLoader = NULL;
90 /* for raising exceptions from native methods */
91 java_objectheader* exceptionptr = NULL;
93 /************* use classinfo structure as java.lang.Class object **************/
95 static void use_class_as_object (classinfo *c)
97 vftbl *vt = class_java_lang_Class -> vftbl;
100 c->classvftbl = true;
101 copy_vftbl(&newtbl, vt);
102 newtbl->class = c->header.vftbl->class;
103 newtbl->baseval = c->header.vftbl->baseval;
104 newtbl->diffval = c->header.vftbl->diffval;
105 c->header.vftbl = newtbl;
109 /*********************** include Java Native Interface ************************/
113 /*************************** include native methods ***************************/
115 #include "nat/Object.c"
116 #include "nat/String.c"
117 #include "nat/ClassLoader.c"
118 #include "nat/Class.c"
119 #include "nat/Compiler.c"
120 #include "nat/Double.c"
121 #include "nat/Float.c"
122 #include "nat/Math.c"
123 #include "nat/Package.c"
124 #include "nat/Runtime.c"
125 #include "nat/SecurityManager.c"
126 #include "nat/System.c"
127 #include "nat/Thread.c"
128 #include "nat/Throwable.c"
129 #include "nat/Finalizer.c"
130 #include "nat/Array.c"
131 #include "nat/Constructor.c"
132 #include "nat/Field.c"
133 #include "nat/Method.c"
134 #include "nat/FileDescriptor.c"
135 #include "nat/FileInputStream.c"
136 #include "nat/FileOutputStream.c"
137 #include "nat/FileSystem.c"
138 #include "nat/ObjectInputStream.c"
139 #include "nat/ObjectStreamClass.c"
140 #include "nat/RandomAccessFile.c"
141 #include "nat/ResourceBundle.c"
142 #include "nat/JarFile.c"
143 #include "nat/Adler32.c"
144 #include "nat/CRC32.c"
145 #include "nat/Deflater.c"
146 #include "nat/Inflater.c"
147 #include "nat/ZipEntry.c"
148 #include "nat/ZipFile.c"
149 #include "nat/BigInteger.c"
150 #include "nat/InetAddress.c"
151 #include "nat/InetAddressImpl.c"
152 #include "nat/DatagramPacket.c"
153 #include "nat/PlainDatagramSocketImpl.c"
154 #include "nat/PlainSocketImpl.c"
155 #include "nat/SocketInputStream.c"
156 #include "nat/SocketOutputStream.c"
157 #include "nat/AccessController.c"
158 #include "nat/ClassLoader_NativeLibrary.c"
159 #include "nat/UnixFileSystem.c"
161 /************************** tables for methods ********************************/
163 /* table for locating native methods */
164 static struct nativeref {
172 #include "nativetable.hh"
177 #define NATIVETABLESIZE (sizeof(nativetable)/sizeof(struct nativeref))
179 /* table for fast string comparison */
180 static struct nativecompref {
186 } nativecomptable [NATIVETABLESIZE];
188 /* string comparsion table initialized */
189 static bool nativecompdone = false;
192 /*********************** function: native_loadclasses **************************
194 load classes required for native methods
196 *******************************************************************************/
198 void native_loadclasses()
200 /* class_new adds the class to the list of classes to be loaded */
201 class_java_lang_Cloneable =
202 class_new ( utf_new_char ("java/lang/Cloneable") );
203 class_java_lang_CloneNotSupportedException =
204 class_new ( utf_new_char ("java/lang/CloneNotSupportedException") );
205 class_java_lang_Class =
206 class_new ( utf_new_char ("java/lang/Class") );
207 class_java_io_IOException =
208 class_new ( utf_new_char ("java/io/IOException") );
209 class_java_lang_ClassNotFoundException =
210 class_new ( utf_new_char ("java/lang/ClassNotFoundException") );
211 class_java_lang_InstantiationException =
212 class_new ( utf_new_char ("java/lang/InstantiationException") );
213 class_java_lang_NoSuchMethodError =
214 class_new ( utf_new_char ("java/lang/NoSuchMethodError") );
215 class_java_lang_NoSuchFieldError =
216 class_new ( utf_new_char ("java/lang/NoSuchFieldError") );
217 class_java_lang_ClassFormatError =
218 class_new ( utf_new_char ("java/lang/ClassFormatError") );
219 class_java_io_SyncFailedException =
220 class_new ( utf_new_char ("java/io/SyncFailedException") );
221 class_java_io_UnixFileSystem =
222 class_new ( utf_new_char ("java/io/UnixFileSystem") );
223 class_java_lang_System =
224 class_new ( utf_new_char ("java/lang/System") );
225 class_java_lang_ClassLoader =
226 class_new ( utf_new_char ("java/lang/ClassLoader") );
227 class_java_security_PrivilegedActionException =
228 class_new( utf_new_char("java/security/PrivilegedActionException"));
229 class_java_net_UnknownHostException =
230 loader_load( utf_new_char ("java/net/UnknownHostException") );
231 class_java_net_SocketException =
232 loader_load( utf_new_char ("java/net/SocketException") );
233 class_java_lang_IllegalArgumentException =
234 class_new( utf_new_char("java/lang/IllegalArgumentException"));
235 class_java_lang_ArrayIndexOutOfBoundsException =
236 class_new( utf_new_char ("java/lang/ArrayIndexOutOfBoundsException") );
237 class_java_lang_NoSuchFieldException =
238 class_new( utf_new_char ("java/lang/NoSuchFieldException") );
239 class_java_lang_NoSuchMethodException =
240 class_new( utf_new_char ("java/lang/NoSuchMethodException") );
242 /* load classes for wrapping primitive types */
243 class_java_lang_Double =
244 class_new( utf_new_char ("java/lang/Double") );
245 class_java_lang_Float =
246 class_new( utf_new_char ("java/lang/Float") );
247 class_java_lang_Character =
248 class_new( utf_new_char ("java/lang/Character") );
249 class_java_lang_Integer =
250 class_new( utf_new_char ("java/lang/Integer") );
251 class_java_lang_Long =
252 class_new( utf_new_char ("java/lang/Long") );
253 class_java_lang_Byte =
254 class_new( utf_new_char ("java/lang/Byte") );
255 class_java_lang_Short =
256 class_new( utf_new_char ("java/lang/Short") );
257 class_java_lang_Boolean =
258 class_new( utf_new_char ("java/lang/Boolean") );
259 class_java_lang_Void =
260 class_new( utf_new_char ("java/lang/Void") );
262 /* load to avoid dynamic classloading */
263 class_new(utf_new_char("sun/net/www/protocol/file/Handler"));
264 class_new(utf_new_char("sun/net/www/protocol/jar/Handler"));
265 class_new(utf_new_char("sun/io/CharToByteISO8859_1"));
267 /* start classloader */
268 loader_load(utf_new_char("sun/io/ByteToCharISO8859_1"));
272 /*************** adds a class to the vector of loaded classes ****************/
274 void systemclassloader_addclass(classinfo *c)
278 /* find method addClass of java.lang.ClassLoader */
279 m = class_resolvemethod (
280 class_java_lang_ClassLoader,
281 utf_new_char("addClass"),
282 utf_new_char("(Ljava/lang/Class;)")
285 if (!m) panic("warning: cannot initialize classloader");
287 /* prepare class to be passed as argument */
288 use_class_as_object (c);
290 /* call 'addClass' */
291 asm_calljavamethod(m,
292 (java_objectheader*) SystemClassLoader,
293 (java_objectheader*) c,
299 /*************** adds a library to the vector of loaded libraries *************/
301 void systemclassloader_addlibrary(java_objectheader *o)
305 /* find method addElement of java.util.Vector */
306 m = class_resolvemethod (
307 loader_load ( utf_new_char ("java/util/Vector") ),
308 utf_new_char("addElement"),
309 utf_new_char("(Ljava/lang/Object;)V")
312 if (!m) panic("cannot initialize classloader");
314 /* call 'addElement' */
315 asm_calljavamethod(m,
316 SystemClassLoader->nativeLibraries,
323 /*****************************************************************************
325 create systemclassloader object and initialize instance fields
327 ******************************************************************************/
329 void init_systemclassloader()
331 if (!SystemClassLoader) {
333 /* create object and call initializer */
334 SystemClassLoader = (java_lang_ClassLoader*) native_new_and_init(class_java_lang_ClassLoader);
335 heap_addreference((void**) &SystemClassLoader);
337 /* systemclassloader has no parent */
338 SystemClassLoader->parent = NULL;
339 SystemClassLoader->initialized = true;
344 /********************* add loaded library name *******************************/
346 void systemclassloader_addlibname(java_objectheader *o)
349 java_objectheader *LibraryNameVector;
352 m = class_resolvemethod (
353 loader_load ( utf_new_char ("java/util/Vector") ),
354 utf_new_char("addElement"),
355 utf_new_char("(Ljava/lang/Object;)V")
358 if (!m) panic("cannot initialize classloader");
360 id = env.GetStaticFieldID(&env,class_java_lang_ClassLoader,"loadedLibraryNames","Ljava/util/Vector;");
361 if (!id) panic("can not access ClassLoader");
363 asm_calljavamethod(m,
364 GetStaticObjectField(&env,class_java_lang_ClassLoader,id),
372 /********************* function: native_setclasspath **************************/
374 void native_setclasspath (char *path)
376 /* set searchpath for classfiles */
380 /***************** function: throw_classnotfoundexception *********************/
382 void throw_classnotfoundexception()
384 /* throws a ClassNotFoundException */
385 exceptionptr = native_new_and_init (class_java_lang_ClassNotFoundException);
389 /*********************** Function: native_findfunction *************************
391 Looks up a method (must have the same class name, method name, descriptor
392 and 'static'ness) and returns a function pointer to it.
393 Returns: function pointer or NULL (if there is no such method)
395 Remark: For faster operation, the names/descriptors are converted from C
396 strings to Unicode the first time this function is called.
398 *******************************************************************************/
400 functionptr native_findfunction (utf *cname, utf *mname,
401 utf *desc, bool isstatic)
404 /* entry of table for fast string comparison */
405 struct nativecompref *n;
406 /* for warning message if no function is found */
410 isstatic = isstatic ? true : false;
412 if (!nativecompdone) {
413 for (i = 0; i < NATIVETABLESIZE; i++) {
414 nativecomptable[i].classname =
415 utf_new_char(nativetable[i].classname);
416 nativecomptable[i].methodname =
417 utf_new_char(nativetable[i].methodname);
418 nativecomptable[i].descriptor =
419 utf_new_char(nativetable[i].descriptor);
420 nativecomptable[i].isstatic =
421 nativetable[i].isstatic;
422 nativecomptable[i].func =
425 nativecompdone = true;
428 for (i = 0; i < NATIVETABLESIZE; i++) {
429 n = &(nativecomptable[i]);
431 if (cname == n->classname && mname == n->methodname &&
432 desc == n->descriptor && isstatic == n->isstatic)
436 /* no function was found, display warning */
439 utf_strlen(cname) + utf_strlen(mname) + utf_strlen(desc) + 64;
441 buffer = MNEW(char, buffer_len);
443 strcpy(buffer, "warning: native function ");
444 utf_sprint(buffer+strlen(buffer), mname);
445 strcpy(buffer+strlen(buffer), ": ");
446 utf_sprint(buffer+strlen(buffer), desc);
447 strcpy(buffer+strlen(buffer), " not found in class ");
448 utf_sprint(buffer+strlen(buffer), cname);
452 MFREE(buffer, char, buffer_len);
458 /********************** function: javastring_new *******************************
460 creates a new object of type java/lang/String with the text of
461 the specified utf8-string
463 return: pointer to the string or NULL if memory is exhausted.
465 *******************************************************************************/
467 java_objectheader *javastring_new (utf *u)
469 char *utf_ptr = u->text; /* current utf character in utf string */
470 int utflength = utf_strlen(u); /* length of utf-string if uncompressed */
471 java_lang_String *s; /* result-string */
475 s = (java_lang_String*) builtin_new (class_java_lang_String);
476 a = builtin_newarray_char (utflength);
478 /* javastring or character-array could not be created */
482 /* decompress utf-string */
483 for (i = 0; i < utflength; i++)
484 a->data[i] = utf_nextu2(&utf_ptr);
486 /* set fields of the javastring-object */
489 s -> count = utflength;
491 return (java_objectheader*) s;
494 /********************** function: javastring_new_char **************************
496 creates a new java/lang/String object which contains the convertet
497 C-string passed via text.
499 return: the object pointer or NULL if memory is exhausted.
501 *******************************************************************************/
503 java_objectheader *javastring_new_char (char *text)
506 s4 len = strlen(text); /* length of the string */
507 java_lang_String *s; /* result-string */
510 s = (java_lang_String*) builtin_new (class_java_lang_String);
511 a = builtin_newarray_char (len);
513 /* javastring or character-array could not be created */
514 if ((!a) || (!s)) return NULL;
517 for (i = 0; i < len; i++)
518 a->data[i] = text[i];
520 /* set fields of the javastring-object */
525 return (java_objectheader*) s;
529 /************************* function javastring_tochar **************************
531 converts a Java string into a C string.
533 return: pointer to C string
535 Caution: every call of this function overwrites the previous string !!!
537 *******************************************************************************/
539 static char stringbuffer[MAXSTRINGSIZE];
541 char *javastring_tochar (java_objectheader *so)
543 java_lang_String *s = (java_lang_String*) so;
552 if (s->count > MAXSTRINGSIZE)
554 for (i = 0; i < s->count; i++)
555 stringbuffer[i] = a->data[s->offset+i];
556 stringbuffer[i] = '\0';
561 /****************** function class_findfield_approx ****************************
563 searches in 'classinfo'-structure for a field with the
566 *******************************************************************************/
568 fieldinfo *class_findfield_approx (classinfo *c, utf *name)
571 for (i = 0; i < c->fieldscount; i++) {
572 /* compare field names */
573 if ((c->fields[i].name == name))
574 return &(c->fields[i]);
577 /* field was not found, raise exception */
578 exceptionptr = native_new_and_init(class_java_lang_NoSuchFieldException);
583 /********************** function: native_new_and_init *************************
585 Creates a new object on the heap and calls the initializer.
586 Returns the object pointer or NULL if memory is exhausted.
588 *******************************************************************************/
590 java_objectheader *native_new_and_init (classinfo *c)
593 java_objectheader *o = builtin_new (c); /* create object */
597 /* find initializer */
599 m = class_findmethod(c, utf_new_char("<init>"), utf_new_char("()V"));
601 if (!m) { /* initializer not found */
603 sprintf(logtext, "Warning: class has no instance-initializer: ");
604 utf_sprint(logtext + strlen(logtext), c->name);
610 /* call initializer */
612 asm_calljavamethod (m, o, NULL, NULL, NULL);
616 /******************** function: stringtable_update ****************************
618 traverses the javastring hashtable and sets the vftbl-entries of
619 javastrings which were temporarily set to NULL, because
620 java.lang.Object was not yet loaded
622 *******************************************************************************/
624 void stringtable_update ()
626 java_lang_String *js;
628 literalstring *s; /* hashtable entry */
631 for (i = 0; i < string_hash.size; i++) {
632 s = string_hash.ptr[i];
636 js = (java_lang_String *) s->string;
638 if (!js || !(a = js->value))
639 /* error in hashtable found */
640 panic("invalid literalstring in hashtable");
642 if (!js->header.vftbl)
643 /* vftbl of javastring is NULL */
644 js->header.vftbl = class_java_lang_String -> vftbl;
646 if (!a->header.objheader.vftbl)
647 /* vftbl of character-array is NULL */
648 a->header.objheader.vftbl = class_array -> vftbl;
650 /* follow link in external hash chain */
658 /************************* function: u2_utflength ***************************
660 returns the utf length in bytes of a u2 array
662 *****************************************************************************/
665 u4 u2_utflength(u2 *text, u4 u2_length)
667 u4 result_len = 0; /* utf length in bytes */
668 u2 ch; /* current unicode character */
671 for (len = 0; len < u2_length; len++) {
673 /* next unicode character */
676 /* determine bytes required to store unicode character as utf */
677 if (ch && (ch < 0x80))
688 /********************* function: utf_new_u2 ***********************************
690 make utf symbol from u2 array,
691 if isclassname is true '.' is replaced by '/'
693 *******************************************************************************/
695 utf *utf_new_u2(u2 *unicode_pos, u4 unicode_length, bool isclassname)
697 char *buffer; /* memory buffer for unicode characters */
698 char *pos; /* pointer to current position in buffer */
699 u4 left; /* unicode characters left */
700 u4 buflength; /* utf length in bytes of the u2 array */
701 utf *result; /* resulting utf-string */
704 /* determine utf length in bytes and allocate memory */
705 buflength = u2_utflength(unicode_pos, unicode_length);
706 buffer = MNEW(char,buflength);
708 /* memory allocation failed */
709 if (!buffer) return NULL;
714 for (i = 0; i++ < unicode_length; unicode_pos++) {
715 /* next unicode character */
718 if ((c != 0) && (c < 0x80)) {
721 if ((int) left < 0) break;
722 /* convert classname */
723 if (isclassname && c=='.')
727 } else if (c < 0x800) {
729 unsigned char high = c >> 6;
730 unsigned char low = c & 0x3F;
732 if ((int) left < 0) break;
733 *pos++ = high | 0xC0;
738 char mid = (c >> 6) & 0x3F;
741 if ((int) left < 0) break;
742 *pos++ = high | 0xE0;
748 /* insert utf-string into symbol-table */
749 result = utf_new(buffer,buflength);
750 MFREE(buffer, char, buflength);
754 /********************* function: javastring_toutf *****************************
756 make utf symbol from javastring
758 *******************************************************************************/
760 utf *javastring_toutf(java_lang_String *string, bool isclassname)
762 java_lang_String *str = (java_lang_String *) string;
763 return utf_new_u2(str->value->data,str->count, isclassname);
766 /********************* function: literalstring_u2 *****************************
768 searches for the javastring with the specified u2-array in
769 the string hashtable, if there is no such string a new one is
772 if copymode is true a copy of the u2-array is made
774 *******************************************************************************/
776 java_objectheader *literalstring_u2 (java_chararray *a, u4 length, bool copymode )
778 literalstring *s; /* hashtable element */
779 java_lang_String *js; /* u2-array wrapped in javastring */
780 java_chararray *stringdata; /* copy of u2-array */
785 /* find location in hashtable */
786 key = unicode_hashkey (a->data, length);
787 slot = key & (string_hash.size-1);
788 s = string_hash.ptr[slot];
792 js = (java_lang_String *) s->string;
794 if (js->count == length) {
796 for (i=0; i<length; i++)
797 if (js->value->data[i] != a->data[i]) goto nomatch;
799 /* string already in hashtable, free memory */
801 lit_mem_free(a, sizeof(java_chararray) + sizeof(u2)*(length-1)+10);
803 return (java_objectheader *) js;
807 /* follow link in external hash chain */
812 /* create copy of u2-array for new javastring */
813 u4 arraysize = sizeof(java_chararray) + sizeof(u2)*(length-1)+10;
814 stringdata = lit_mem_alloc ( arraysize );
815 memcpy(stringdata, a, arraysize );
820 /* location in hashtable found, complete arrayheader */
821 if (class_array==NULL) panic("class_array not initialized");
822 stringdata -> header.objheader.vftbl = class_array -> vftbl;
823 stringdata -> header.size = length;
824 stringdata -> header.arraytype = ARRAYTYPE_CHAR;
826 /* create new javastring */
827 js = LNEW (java_lang_String);
828 js -> header.vftbl = class_java_lang_String -> vftbl;
829 js -> value = stringdata;
831 js -> count = length;
833 /* create new literalstring */
834 s = NEW (literalstring);
835 s->hashlink = string_hash.ptr[slot];
836 s->string = (java_objectheader *) js;
837 string_hash.ptr[slot] = s;
839 /* update numbe of hashtable entries */
840 string_hash.entries++;
842 /* reorganization of hashtable */
843 if ( string_hash.entries > (string_hash.size*2)) {
845 /* reorganization of hashtable, average length of
846 the external chains is approx. 2 */
850 hashtable newhash; /* the new hashtable */
852 /* create new hashtable, double the size */
853 init_hashtable(&newhash, string_hash.size*2);
854 newhash.entries=string_hash.entries;
856 /* transfer elements to new hashtable */
857 for (i=0; i<string_hash.size; i++) {
858 s = string_hash.ptr[i];
860 literalstring *nexts = s -> hashlink;
861 js = (java_lang_String*) s->string;
862 slot = (unicode_hashkey(js->value->data,js->count)) & (newhash.size-1);
864 s->hashlink = newhash.ptr[slot];
865 newhash.ptr[slot] = s;
867 /* follow link in external hash chain */
872 /* dispose old table */
873 MFREE (string_hash.ptr, void*, string_hash.size);
874 string_hash = newhash;
877 return (java_objectheader *) js;
880 /******************** Function: literalstring_new *****************************
882 creates a new javastring with the text of the utf-symbol
883 and inserts it into the string hashtable
885 *******************************************************************************/
887 java_objectheader *literalstring_new (utf *u)
889 char *utf_ptr = u->text; /* pointer to current unicode character in utf string */
890 u4 utflength = utf_strlen(u); /* length of utf-string if uncompressed */
891 java_chararray *a; /* u2-array constructed from utf string */
892 java_objectheader *js;
895 /* allocate memory */
896 a = lit_mem_alloc (sizeof(java_chararray) + sizeof(u2)*(utflength-1)+10 );
897 /* convert utf-string to u2-array */
898 for (i=0; i<utflength; i++) a->data[i] = utf_nextu2(&utf_ptr);
900 return literalstring_u2(a, utflength, false);
904 /********************** function: literalstring_free **************************
906 removes a javastring from memory
908 ******************************************************************************/
910 void literalstring_free (java_objectheader* sobj)
912 java_lang_String *s = (java_lang_String*) sobj;
913 java_chararray *a = s->value;
915 log_text("literalstring_free called");
917 /* dispose memory of java.lang.String object */
918 LFREE (s, java_lang_String);
919 /* dispose memory of java-characterarray */
920 LFREE (a, sizeof(java_chararray) + sizeof(u2)*(a->header.size-1)); /* +10 ?? */
926 void copy_vftbl(vftbl **dest, vftbl *src)
928 *dest = mem_alloc(sizeof(vftbl) + sizeof(methodptr)*(src->vftbllength-1));
929 memcpy(*dest, src, sizeof(vftbl) - sizeof(methodptr));
930 memcpy(&(*dest)->table, &src->table, src->vftbllength * sizeof(methodptr));