A good memory than a bad pen, today to learn is the android in the ABI directory code. Here is a summary of the basic learning notes.
The first is the description of the header file in include.
In the Cxxabi header file, you need to master the following points:
1. The main function contained in this header file is information based on the type of driver in C + + 2.9.5.
2, the type of drive this is the main definition of such a few categories:
2, 1 __fundamental_type_info basic Drive type information
2, 2 __array_type_info array-driven type information
2, 3 __function_type_info function-driven type information
2, 4 __enum_type_info enumeration of drive type information
2, 5 __class_type_info information about the driver type of a class without a parent class
2, 7 __si_class_type_info is a subclass of __class_type_info, which contains a singleton, a public non-virtual, an offset of 0 pointer to a type of __class_type_info.
Const __class_type_info *__base_type;
In the new header file, you need to master the following several points:
1, mainly the overloading of some operators
2, the operator is overloaded mainly: New, new[], delete, delete[]
2, at the same time, the overloads of each operator are basically declared to throw an exception
The following points need to be mastered in the TypeInfo header file:
1, mainly defines some operations of the type_info (mainly the overloading of some operators) (based on C + + 2.9.3 fragments)
The following is a description of the source code file in src.
1, mainly the implementation of some types of drive information, the vast majority of implementations are some empty implementations, including only a destructor.
2, where the array drive type, class-driven type, enumeration drive type, function-driven type, basic data-driven type, pointer-to-member variable-drive type, pointer-driven type, etc. are all virgin with a destructor of the empty definition, the rest of the source of nothing.
3, the implementation of the delete operator overload is as follows:
Voidoperator Delete (void* ptr) throw () { if (PTR) free (PTR);}
Call the free method to release the storage space that points to.
4. The overloaded method for the new operator is as follows:
Void*operator New (std::size_t size) throw (/*std::bad_alloc*/) { void* ptr = malloc (size), #if 0 if (ptr = = NULL)
throw Std::bad_alloc (); #endif return ptr;}
Call the malloc function to allocate the required storage space if the allocation fails, throwing an exception.
5, in the dynamic_cast source code, need to pay attention to the following several points:
5, 1 to adjust the direction of a pointer by an offset
5, 2 Returns a virtual table with pointers to polymorphic objects pointed by pointers
5, 3 Returns a pointer to a virtual table that points to the class-driven type of information
5, 4 returns the offset in a virtual table relative to an object.
5, 5 How to iterate over the tree of an object's type
const void * Walk_object (const void *object, const abi::__class_type_info *type, const void * Match_object, const abi::__class_type_info *match_type) {//If the current object's type is the same as the current waiting iteration's pointer if (*type = = *MATC H_type) return (Match_object = = NULL | | object = = match_object)? Object:null; Switch (Type->code ()) {case Abi::__class_type_info::class_type_info_code://This isn ' t ' the class ' You ' re looking for. return NULL; Case Abi::__class_type_info::si_class_type_info_code://derived type have a single public base at offset 0. {Const abi::__si_class_type_info* TI = static_cast<const abi::__si_class_type_info*> (type); Return Walk_object (object, Ti->__base_type, Match_object, match_type); } case Abi::__class_type_info::vmi_class_type_info_code: {const void* vtable = Get_vtable (object); Const ABI::__vmi_class_type_info* ti = static_cast<const abi::__vmi_class_type_info*> (type); Look at all direct bases. Const void* result = NULL; for (unsigned i = 0; i < ti->__base_count; ++i) {if (!ti->__base_info[i].is_public ()) Continue const void *subobject = Get_subobject (object, vtable, &ti->__base_info[i]); Const void* Walk_subobject_result = Walk_object (Subobject, Ti->__base_info[i].__base_type, Match_object, Match_type); if (Walk_subobject_result = = Ambiguous_object) return ambiguous_object; else if (walk_subobject_result! = null) {if (result = = null) { result = Walk_subobject_result; } else if (result! = Walk_subobject_result) return Ambiguous_object; }} return result; } default:assert (0); } return NULL; }
Android Kernel source Abi Directory learning notes