This repository was archived by the owner on Oct 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +52
-2
lines changed
Expand file tree Collapse file tree 4 files changed +52
-2
lines changed Original file line number Diff line number Diff line change 11include ../common.mak
22
3- TESTS: =array new
3+ TESTS: =array allocator new
44
55.PHONY : all clean
66
Original file line number Diff line number Diff line change 1+ #include < memory>
2+
3+ struct MyStruct
4+ {
5+ int *a;
6+ double *b;
7+ MyStruct *c;
8+ };
9+
10+ MyStruct cpp_alloc ()
11+ {
12+ MyStruct r;
13+ r.a = std::allocator<int >().allocate (42 );
14+ r.b = std::allocator<double >().allocate (42 );
15+ r.c = std::allocator<MyStruct>().allocate (42 );
16+ return r;
17+ }
18+
19+ void cpp_free (MyStruct& s)
20+ {
21+ std::allocator<int >().deallocate (s.a , 43 );
22+ std::allocator<double >().deallocate (s.b , 43 );
23+ std::allocator<MyStruct>().deallocate (s.c , 43 );
24+ }
Original file line number Diff line number Diff line change 1+ import core.stdcpp.allocator ;
2+
3+ extern (C++ ) struct MyStruct
4+ {
5+ int * a;
6+ double * b;
7+ MyStruct* c;
8+ }
9+
10+ extern (C++ ) MyStruct cpp_alloc();
11+ extern (C++ ) void cpp_free(ref MyStruct s);
12+
13+ unittest
14+ {
15+ // alloc in C++, delete in D
16+ MyStruct s = cpp_alloc();
17+ allocator! int ().deallocate(s.a, 42 );
18+ allocator! double ().deallocate(s.b, 42 );
19+ allocator! MyStruct().deallocate(s.c, 42 );
20+
21+ // alloc in D, delete in C++
22+ s.a = allocator! int ().allocate(43 );
23+ s.b = allocator! double ().allocate(43 );
24+ s.c = allocator! MyStruct().allocate(43 );
25+ cpp_free(s);
26+ }
Original file line number Diff line number Diff line change 55DRUNTIMELIB =druntime64.lib
66CC =cl
77
8- TESTS = array new
8+ TESTS = array allocator new
99
1010test : $(TESTS )
1111
You can’t perform that action at this time.
0 commit comments