Flutter Engine
The Flutter Engine
third_party
dart-lang
sdk
runtime
bin
ffi_test
ffi_test_dynamic_library.cc
Go to the documentation of this file.
1
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2
// for details. All rights reserved. Use of this source code is governed by a
3
// BSD-style license that can be found in the LICENSE file.
4
5
#include <stdint.h>
6
#include <stdlib.h>
7
#include <string.h>
8
#include <iostream>
9
10
#if defined(_WIN32)
11
#define DART_EXPORT extern "C"
__declspec(dllexport)
12
#else
13
#define DART_EXPORT \
14
extern "C"
__attribute__((visibility("default"))) __attribute((used))
15
#endif
16
17
DART_EXPORT
intptr_t
return42
() {
18
return
42;
19
}
20
21
DART_EXPORT
double
timesFour
(
double
d
) {
22
return
d
* 4.0;
23
}
24
25
// Wrap memmove so we can easily find it on all platforms.
26
//
27
// We use this in our samples to illustrate resource lifetime management.
28
DART_EXPORT
void
MemMove
(
void
* destination,
void
*
source
, intptr_t num_bytes) {
29
memmove(destination,
source
, num_bytes);
30
}
31
32
// Some opaque struct.
33
typedef
struct
{
34
}
some_resource
;
35
36
DART_EXPORT
some_resource
*
AllocateResource
() {
37
void
* pointer =
malloc
(
sizeof
(int64_t));
38
39
// Dummy initialize.
40
static_cast<
int64_t*
>
(pointer)[0] = 10;
41
42
return
static_cast<
some_resource
*
>
(pointer);
43
}
44
45
DART_EXPORT
void
UseResource
(
some_resource
*
resource
) {
46
// Dummy change.
47
reinterpret_cast<
int64_t*
>
(
resource
)[0] += 10;
48
}
49
50
DART_EXPORT
void
ReleaseResource
(
some_resource
*
resource
) {
51
free(
resource
);
52
}
resource
static SkString resource(SkPDFResourceType type, int index)
Definition:
SkPDFResourceDict.cpp:62
d
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition:
main.cc:19
source
SkBitmap source
Definition:
examples.cpp:28
UseResource
DART_EXPORT void UseResource(some_resource *resource)
Definition:
ffi_test_dynamic_library.cc:45
ReleaseResource
DART_EXPORT void ReleaseResource(some_resource *resource)
Definition:
ffi_test_dynamic_library.cc:50
return42
DART_EXPORT intptr_t return42()
Definition:
ffi_test_dynamic_library.cc:17
MemMove
DART_EXPORT void MemMove(void *destination, void *source, intptr_t num_bytes)
Definition:
ffi_test_dynamic_library.cc:28
timesFour
DART_EXPORT double timesFour(double d)
Definition:
ffi_test_dynamic_library.cc:21
AllocateResource
DART_EXPORT some_resource * AllocateResource()
Definition:
ffi_test_dynamic_library.cc:36
DART_EXPORT
#define DART_EXPORT
Definition:
ffi_test_dynamic_library.cc:13
dart::malloc
void * malloc(size_t size)
Definition:
allocation.cc:19
some_resource
Definition:
ffi_test_dynamic_library.cc:33
Generated on Sun Jun 23 2024 21:55:23 for Flutter Engine by
1.9.4