Flutter Engine
The Flutter Engine
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
18 return 42;
19}
20
21DART_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.
28DART_EXPORT void MemMove(void* destination, void* source, intptr_t num_bytes) {
29 memmove(destination, source, num_bytes);
30}
31
32// Some opaque struct.
33typedef struct {
35
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
46 // Dummy change.
47 reinterpret_cast<int64_t*>(resource)[0] += 10;
48}
49
51 free(resource);
52}
static SkString resource(SkPDFResourceType type, int index)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
SkBitmap source
Definition: examples.cpp:28
DART_EXPORT void UseResource(some_resource *resource)
DART_EXPORT void ReleaseResource(some_resource *resource)
DART_EXPORT intptr_t return42()
DART_EXPORT void MemMove(void *destination, void *source, intptr_t num_bytes)
DART_EXPORT double timesFour(double d)
DART_EXPORT some_resource * AllocateResource()
#define DART_EXPORT
void * malloc(size_t size)
Definition: allocation.cc:19