• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef RUNTIME_INCLUDE_TAIHE_OBJECT_ABI_H_
16 #define RUNTIME_INCLUDE_TAIHE_OBJECT_ABI_H_
17 
18 #include <taihe/common.h>
19 
20 #include <stdint.h>
21 #include <stdlib.h>
22 
23 struct DataBlockHead;
24 
25 // IdMapItem
26 // Represents an ID mapping item containing an ID and a vtable pointer.
27 // # Members
28 // - `id`: A constant pointer representing the interface ID.
29 // - `vtbl_ptr`: A pointer to the virtual table associated with the ID.
30 struct IdMapItem {
31     void const *id;
32     void const *vtbl_ptr;
33 };
34 
35 // TypeInfo
36 // Represents metadata information for a type, including version, length, and
37 // function pointers.
38 // # Members
39 // - `version`: A 64-bit unsigned integer representing the version of the type
40 // information.
41 // - `free_fptr`: Pointer to function that frees the data block.
42 // - `hash_fptr`: Pointer to function that computes the hash of a data block.
43 // - `same_fptr`: Pointer to function that compares equality of two data blocks.
44 // - `len`: A 64-bit unsigned integer representing the length of idmap.
45 // - `idmap`: An array of IdMapItem structures representing the ID to vtable
46 //   mapping.
47 struct TypeInfo {
48     uint64_t version;
49     void (*free_fptr)(struct DataBlockHead *);
50     size_t (*hash_fptr)(struct DataBlockHead *);
51     bool (*same_fptr)(struct DataBlockHead *, struct DataBlockHead *);
52     uint64_t len;
53     struct IdMapItem idmap[];
54 };
55 
56 // DataBlockHead
57 // Represents the head of a data block, containing a pointer to the runtime
58 // type information structure and a reference count.
59 // # Members
60 // - `rtti_ptr`: A pointer to the runtime type information structure.
61 // - `m_count`: A reference count for the data block.
62 struct DataBlockHead {
63     struct TypeInfo const *rtti_ptr;
64     TRefCount m_count;
65 };
66 
67 // Initializes the TObject with the given runtime typeinfo.
68 // # Arguments
69 // - `data_ptr`: The data pointer.
70 // - `rtti_ptr`: The runtime typeinfo pointer.
71 TH_EXPORT void tobj_init(struct DataBlockHead *data_ptr, struct TypeInfo const *rtti_ptr);
72 
73 // Increments the reference count of the given TObject.
74 // # Arguments
75 // - `data_ptr`: The data pointer.
76 // # Returns
77 // - The new data pointer.
78 TH_EXPORT struct DataBlockHead *tobj_dup(struct DataBlockHead *data_ptr);
79 
80 // Decrements the reference count of the given TObject. If the reference count
81 // reaches zero, the object is destroyed.
82 // # Arguments
83 // - `tobj`: The data pointer.
84 TH_EXPORT void tobj_drop(struct DataBlockHead *data_ptr);
85 #endif  // RUNTIME_INCLUDE_TAIHE_OBJECT_ABI_H_