|
18 | 18 | * All symbols are postfixed with _DL to indicate that they are dynamically
|
19 | 19 | * linked and to prevent conflicts with the original symbol.
|
20 | 20 | *
|
21 |
| - * Link `dart_api_dl.cc` file into your library and invoke |
| 21 | + * Link `dart_api_dl.c` file into your library and invoke |
22 | 22 | * `Dart_InitializeApiDL` with `NativeApi.initializeApiDLData`.
|
23 | 23 | */
|
24 | 24 |
|
25 |
| -intptr_t Dart_InitializeApiDL(void* data); |
| 25 | +#ifdef __cplusplus |
| 26 | +#define DART_EXTERN extern "C" |
| 27 | +#else |
| 28 | +#define DART_EXTERN extern |
| 29 | +#endif |
26 | 30 |
|
| 31 | +DART_EXTERN intptr_t Dart_InitializeApiDL(void* data); |
| 32 | + |
| 33 | +// ============================================================================ |
27 | 34 | // IMPORTANT! Never update these signatures without properly updating
|
28 | 35 | // DART_API_DL_MAJOR_VERSION and DART_API_DL_MINOR_VERSION.
|
29 | 36 | //
|
30 |
| -// Verbatim copy of `dart_native_api.h` and `dart_api.h` symbols to trigger |
31 |
| -// compile-time errors if the sybols in those files are updated without |
32 |
| -// updating these. |
| 37 | +// Verbatim copy of `dart_native_api.h` and `dart_api.h` symbol names and types |
| 38 | +// to trigger compile-time errors if the sybols in those files are updated |
| 39 | +// without updating these. |
33 | 40 | //
|
34 |
| -// Function signatures and typedefs are carbon copied. Structs are typechecked |
35 |
| -// nominally in C/C++, so they are not copied, instead a comment is added to |
36 |
| -// their definition. |
| 41 | +// Function return and argument types, and typedefs are carbon copied. Structs |
| 42 | +// are typechecked nominally in C/C++, so they are not copied, instead a |
| 43 | +// comment is added to their definition. |
37 | 44 | typedef int64_t Dart_Port_DL;
|
38 | 45 |
|
39 | 46 | typedef void (*Dart_NativeMessageHandler_DL)(Dart_Port_DL dest_port_id,
|
40 | 47 | Dart_CObject* message);
|
41 | 48 |
|
42 |
| -DART_EXTERN_C bool (*Dart_PostCObject_DL)(Dart_Port_DL port_id, |
43 |
| - Dart_CObject* message); |
44 |
| - |
45 |
| -DART_EXTERN_C bool (*Dart_PostInteger_DL)(Dart_Port_DL port_id, |
46 |
| - int64_t message); |
47 |
| - |
48 |
| -DART_EXTERN_C Dart_Port_DL (*Dart_NewNativePort_DL)( |
49 |
| - const char* name, |
50 |
| - Dart_NativeMessageHandler_DL handler, |
51 |
| - bool handle_concurrently); |
52 |
| - |
53 |
| -DART_EXTERN_C bool (*Dart_CloseNativePort_DL)(Dart_Port_DL native_port_id); |
54 |
| - |
55 |
| -DART_EXTERN_C bool (*Dart_IsError_DL)(Dart_Handle handle); |
56 |
| - |
57 |
| -DART_EXTERN_C bool (*Dart_IsApiError_DL)(Dart_Handle handle); |
58 |
| - |
59 |
| -DART_EXTERN_C bool (*Dart_IsUnhandledExceptionError_DL)(Dart_Handle handle); |
60 |
| - |
61 |
| -DART_EXTERN_C bool (*Dart_IsCompilationError_DL)(Dart_Handle handle); |
62 |
| - |
63 |
| -DART_EXTERN_C bool (*Dart_IsFatalError_DL)(Dart_Handle handle); |
64 |
| - |
65 |
| -DART_EXTERN_C const char* (*Dart_GetError_DL)(Dart_Handle handle); |
66 |
| - |
67 |
| -DART_EXTERN_C bool (*Dart_ErrorHasException_DL)(Dart_Handle handle); |
68 |
| - |
69 |
| -DART_EXTERN_C Dart_Handle (*Dart_ErrorGetException_DL)(Dart_Handle handle); |
70 |
| - |
71 |
| -DART_EXTERN_C Dart_Handle (*Dart_ErrorGetStackTrace_DL)(Dart_Handle handle); |
72 |
| - |
73 |
| -DART_EXTERN_C Dart_Handle (*Dart_NewApiError_DL)(const char* error); |
74 |
| - |
75 |
| -DART_EXTERN_C Dart_Handle (*Dart_NewCompilationError_DL)(const char* error); |
76 |
| - |
77 |
| -DART_EXTERN_C Dart_Handle (*Dart_NewUnhandledExceptionError_DL)( |
78 |
| - Dart_Handle exception); |
79 |
| - |
80 |
| -DART_EXTERN_C void (*Dart_PropagateError_DL)(Dart_Handle handle); |
81 |
| - |
82 |
| -DART_EXTERN_C Dart_Handle (*Dart_ToString_DL)(Dart_Handle object); |
83 |
| - |
84 |
| -DART_EXTERN_C bool (*Dart_IdentityEquals_DL)(Dart_Handle obj1, |
85 |
| - Dart_Handle obj2); |
86 |
| - |
87 |
| -DART_EXTERN_C Dart_Handle (*Dart_HandleFromPersistent_DL)( |
88 |
| - Dart_PersistentHandle object); |
89 |
| - |
90 |
| -DART_EXTERN_C Dart_Handle (*Dart_HandleFromWeakPersistent_DL)( |
91 |
| - Dart_WeakPersistentHandle object); |
92 |
| - |
93 |
| -DART_EXTERN_C Dart_PersistentHandle (*Dart_NewPersistentHandle_DL)( |
94 |
| - Dart_Handle object); |
95 |
| - |
96 |
| -DART_EXTERN_C void (*Dart_SetPersistentHandle_DL)(Dart_PersistentHandle obj1, |
97 |
| - Dart_Handle obj2); |
98 |
| - |
99 |
| -DART_EXTERN_C void (*Dart_DeletePersistentHandle_DL)( |
100 |
| - Dart_PersistentHandle object); |
101 |
| - |
102 |
| -DART_EXTERN_C Dart_WeakPersistentHandle (*Dart_NewWeakPersistentHandle_DL)( |
103 |
| - Dart_Handle object, |
104 |
| - void* peer, |
105 |
| - intptr_t external_allocation_size, |
106 |
| - Dart_WeakPersistentHandleFinalizer callback); |
107 |
| - |
108 |
| -DART_EXTERN_C void (*Dart_DeleteWeakPersistentHandle_DL)( |
109 |
| - Dart_WeakPersistentHandle object); |
110 |
| - |
111 |
| -DART_EXTERN_C void (*Dart_UpdateExternalSize_DL)( |
112 |
| - Dart_WeakPersistentHandle object, |
113 |
| - intptr_t external_allocation_size); |
114 |
| - |
115 |
| -DART_EXTERN_C Dart_FinalizableHandle (*Dart_NewFinalizableHandle_DL)( |
116 |
| - Dart_Handle object, |
117 |
| - void* peer, |
118 |
| - intptr_t external_allocation_size, |
119 |
| - Dart_HandleFinalizer callback); |
120 |
| - |
121 |
| -DART_EXTERN_C void (*Dart_DeleteFinalizableHandle_DL)( |
122 |
| - Dart_FinalizableHandle object, |
123 |
| - Dart_Handle strong_ref_to_object); |
124 |
| - |
125 |
| -DART_EXTERN_C void (*Dart_UpdateFinalizableExternalSize_DL)( |
126 |
| - Dart_FinalizableHandle object, |
127 |
| - Dart_Handle strong_ref_to_object, |
128 |
| - intptr_t external_allocation_size); |
129 |
| - |
130 |
| -DART_EXTERN_C bool (*Dart_Post_DL)(Dart_Port_DL port_id, Dart_Handle object); |
131 |
| - |
132 |
| -DART_EXTERN_C Dart_Handle (*Dart_NewSendPort_DL)(Dart_Port_DL port_id); |
133 |
| - |
134 |
| -DART_EXTERN_C Dart_Handle (*Dart_SendPortGetId_DL)(Dart_Handle port, |
135 |
| - Dart_Port_DL* port_id); |
136 |
| - |
137 |
| -DART_EXTERN_C void (*Dart_EnterScope_DL)(); |
138 |
| - |
139 |
| -DART_EXTERN_C void (*Dart_ExitScope_DL)(); |
| 49 | +// dart_native_api.h symbols can be called on any thread. |
| 50 | +#define DART_NATIVE_API_DL_SYMBOLS(F) \ |
| 51 | + /***** dart_native_api.h *****/ \ |
| 52 | + /* Dart_Port */ \ |
| 53 | + F(Dart_PostCObject, bool, (Dart_Port_DL port_id, Dart_CObject * message)) \ |
| 54 | + F(Dart_PostInteger, bool, (Dart_Port_DL port_id, int64_t message)) \ |
| 55 | + F(Dart_NewNativePort, Dart_Port_DL, \ |
| 56 | + (const char* name, Dart_NativeMessageHandler_DL handler, \ |
| 57 | + bool handle_concurrently)) \ |
| 58 | + F(Dart_CloseNativePort, bool, (Dart_Port_DL native_port_id)) |
| 59 | + |
| 60 | +// dart_api.h symbols can only be called on Dart threads. |
| 61 | +#define DART_API_DL_SYMBOLS(F) \ |
| 62 | + /***** dart_api.h *****/ \ |
| 63 | + /* Errors */ \ |
| 64 | + F(Dart_IsError, bool, (Dart_Handle handle)) \ |
| 65 | + F(Dart_IsApiError, bool, (Dart_Handle handle)) \ |
| 66 | + F(Dart_IsUnhandledExceptionError, bool, (Dart_Handle handle)) \ |
| 67 | + F(Dart_IsCompilationError, bool, (Dart_Handle handle)) \ |
| 68 | + F(Dart_IsFatalError, bool, (Dart_Handle handle)) \ |
| 69 | + F(Dart_GetError, const char*, (Dart_Handle handle)) \ |
| 70 | + F(Dart_ErrorHasException, bool, (Dart_Handle handle)) \ |
| 71 | + F(Dart_ErrorGetException, Dart_Handle, (Dart_Handle handle)) \ |
| 72 | + F(Dart_ErrorGetStackTrace, Dart_Handle, (Dart_Handle handle)) \ |
| 73 | + F(Dart_NewApiError, Dart_Handle, (const char* error)) \ |
| 74 | + F(Dart_NewCompilationError, Dart_Handle, (const char* error)) \ |
| 75 | + F(Dart_NewUnhandledExceptionError, Dart_Handle, (Dart_Handle exception)) \ |
| 76 | + F(Dart_PropagateError, void, (Dart_Handle handle)) \ |
| 77 | + /* Dart_Handle, Dart_PersistentHandle, Dart_WeakPersistentHandle */ \ |
| 78 | + F(Dart_HandleFromPersistent, Dart_Handle, (Dart_PersistentHandle object)) \ |
| 79 | + F(Dart_HandleFromWeakPersistent, Dart_Handle, \ |
| 80 | + (Dart_WeakPersistentHandle object)) \ |
| 81 | + F(Dart_NewPersistentHandle, Dart_PersistentHandle, (Dart_Handle object)) \ |
| 82 | + F(Dart_SetPersistentHandle, void, \ |
| 83 | + (Dart_PersistentHandle obj1, Dart_Handle obj2)) \ |
| 84 | + F(Dart_DeletePersistentHandle, void, (Dart_PersistentHandle object)) \ |
| 85 | + F(Dart_NewWeakPersistentHandle, Dart_WeakPersistentHandle, \ |
| 86 | + (Dart_Handle object, void* peer, intptr_t external_allocation_size, \ |
| 87 | + Dart_WeakPersistentHandleFinalizer callback)) \ |
| 88 | + F(Dart_DeleteWeakPersistentHandle, void, (Dart_WeakPersistentHandle object)) \ |
| 89 | + F(Dart_UpdateExternalSize, void, \ |
| 90 | + (Dart_WeakPersistentHandle object, intptr_t external_allocation_size)) \ |
| 91 | + F(Dart_NewFinalizableHandle, Dart_FinalizableHandle, \ |
| 92 | + (Dart_Handle object, void* peer, intptr_t external_allocation_size, \ |
| 93 | + Dart_HandleFinalizer callback)) \ |
| 94 | + F(Dart_DeleteFinalizableHandle, void, \ |
| 95 | + (Dart_FinalizableHandle object, Dart_Handle strong_ref_to_object)) \ |
| 96 | + F(Dart_UpdateFinalizableExternalSize, void, \ |
| 97 | + (Dart_FinalizableHandle object, Dart_Handle strong_ref_to_object, \ |
| 98 | + intptr_t external_allocation_size)) \ |
| 99 | + /* Dart_Port */ \ |
| 100 | + F(Dart_Post, bool, (Dart_Port_DL port_id, Dart_Handle object)) \ |
| 101 | + F(Dart_NewSendPort, Dart_Handle, (Dart_Port_DL port_id)) \ |
| 102 | + F(Dart_SendPortGetId, Dart_Handle, \ |
| 103 | + (Dart_Handle port, Dart_Port_DL * port_id)) \ |
| 104 | + /* Scopes */ \ |
| 105 | + F(Dart_EnterScope, void, ()) \ |
| 106 | + F(Dart_ExitScope, void, ()) |
| 107 | + |
| 108 | +#define DART_API_ALL_DL_SYMBOLS(F) \ |
| 109 | + DART_NATIVE_API_DL_SYMBOLS(F) \ |
| 110 | + DART_API_DL_SYMBOLS(F) |
140 | 111 | // IMPORTANT! Never update these signatures without properly updating
|
141 | 112 | // DART_API_DL_MAJOR_VERSION and DART_API_DL_MINOR_VERSION.
|
142 | 113 | //
|
143 | 114 | // End of verbatim copy.
|
| 115 | +// ============================================================================ |
| 116 | + |
| 117 | +#define DART_API_DL_DECLARATIONS(name, R, A) \ |
| 118 | + typedef R(*name##_Type) A; \ |
| 119 | + DART_EXTERN name##_Type name##_DL; |
| 120 | + |
| 121 | +DART_API_ALL_DL_SYMBOLS(DART_API_DL_DECLARATIONS) |
| 122 | + |
| 123 | +#undef DART_API_DL_DEFINITIONS |
| 124 | + |
| 125 | +#undef DART_EXTERN |
144 | 126 |
|
145 | 127 | #endif /* RUNTIME_INCLUDE_DART_API_DL_H_ */ /* NOLINT */
|
0 commit comments