Skip to content

Commit da13302

Browse files
committed
added support for CxxWrap v0.17.x and made runtime check of libcxxwrap release more strict
1 parent 9f2d953 commit da13302

File tree

3 files changed

+48
-19
lines changed

3 files changed

+48
-19
lines changed

src/CodeTree.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,18 @@ std::string CodeTree::wrapper_classsname(const std::string& classname) const{
186186

187187
std::ostream&
188188
CodeTree::generate_version_check_cxx(std::ostream& o) const{
189-
auto [jllmin, jllmax] = version_libcxxwrap_bounds(cxxwrap_version_);
189+
auto [sjllmin, sjllmax] = version_libcxxwrap_static_bounds(cxxwrap_version_);
190190

191191
indent(o,0) << "//method from libcxxwrap returning its version\n";
192192
indent(o,0) << "extern \"C\" JLCXX_API const char* cxxwrap_version_string();\n\n";
193193
indent(o, 0) << "//Check the code is compiled with a compatible version of libcxxwrap:\n";
194194
indent(o,0) << "static_assert(1000*1000*JLCXX_VERSION_MAJOR "
195-
" + 1000 * JLCXX_VERSION_MINOR + JLCXX_VERSION_PATCH >= " << jllmin << "\n";
195+
" + 1000 * JLCXX_VERSION_MINOR + JLCXX_VERSION_PATCH >= " << sjllmin << "\n";
196196
indent(o, 1) << "&& 1000 * 1000 * JLCXX_VERSION_MAJOR "
197-
" + 1000 * JLCXX_VERSION_MINOR + JLCXX_VERSION_PATCH < " << jllmax << ",\n";
197+
" + 1000 * JLCXX_VERSION_MINOR + JLCXX_VERSION_PATCH < " << sjllmax << ",\n";
198198
indent(o,1) << "\"The code was generated with WrapIt! for \"\n";
199199
indent(o,1) << "\"a different CxxWrap version (controlled with the cxxwrap_version parameter).\");\n\n";
200-
indent(o, 0) << "//Check the version of loaded libcxxwrap library:\n";
200+
indent(o, 0) << "//Check the version of loaded libcxxrap library:\n";
201201
indent(o,0) << "void throw_if_version_incompatibility(){\n";
202202
indent(o,1) << "std::string version_str = cxxwrap_version_string();\n";
203203
indent(o,1) << "static std::regex r(\"([[:digit:]]{1,3})\\\\.([[:digit:]]{1,3})\\\\.([[:digit:]]{1,3})\");\n";
@@ -208,13 +208,15 @@ CodeTree::generate_version_check_cxx(std::ostream& o) const{
208208
indent(o,2) << "long version_int = 1000*1000*strtol(matches[1].str().c_str(), 0, 10)\n";
209209
indent(o,2) << " + 1000*strtol(matches[2].str().c_str(), 0, 10)\n";
210210
indent(o,2) << " + strtol(matches[3].str().c_str(), 0, 10);\n";
211-
indent(o,2) << "if(version_int < " << jllmin << " || version_int >= " << jllmax << "){\n";
211+
indent(o,2) << "long jllmin = 1000*1000*JLCXX_VERSION_MAJOR + 1000 * JLCXX_VERSION_MINOR;\n";
212+
indent(o,2) << "long jllmax = 1000*1000*JLCXX_VERSION_MAJOR + 1000 * (JLCXX_VERSION_MINOR + 1);\n";
213+
indent(o,2) << "if(version_int < jllmin || version_int >= jllmax){\n";
212214
indent(o,3) << "throw std::runtime_error(std::string(\"Found libcxxwrap_jll version \")\n";
213-
indent(o,3) << " + version_str + \", while module " << module_name_ << " requires a version in \"\n";
214-
indent(o,3) << "\"[" << version_int_to_string(jllmin) << ", " << version_int_to_string(jllmax) << ").\"\n";
215-
indent(o,3) << "\" Note: if the module was installed with the package manager, the Project.toml file \"\n";
216-
indent(o,3) << "\"of the package is probably missing a compat specification that would have prevented \"\n";
217-
indent(o,3) << "\"the inconsistency.\");\n";
215+
indent(o,4) << "+ version_str + \", while module " << module_name_ << " requires version \"\n";
216+
indent(o,4) << "+ std::to_string(JLCXX_VERSION_MAJOR) + \".\" + std::to_string(JLCXX_VERSION_MINOR) + \".x.\"\n";
217+
indent(o,4) << "\" Note: if the module was installed with the package manager, the Project.toml file \"\n";
218+
indent(o,4) << "\"of the package is probably missing a compat specification that would have prevented \"\n";
219+
indent(o,4) << "\"the inconsistency.\");\n";
218220
indent(o,2) << "}\n";
219221
indent(o,1) << "}\n";
220222
indent(o,0) << "}\n";
@@ -3052,6 +3054,11 @@ CodeTree::gen_apply_stl(std::ostream& o, int indent_depth,
30523054
const TypeRcd& type_rcd,
30533055
const std::string& add_type_param) const{
30543056

3057+
if(cxxwrap_version_ >= cxxwrap_v0_17){
3058+
//apply_stl not relevant for CxxWrap 0.17+
3059+
return o;
3060+
}
3061+
30553062
if(type_rcd.stl){
30563063
indent(o, indent_depth) << "jlcxx::stl::apply_stl<" << add_type_param
30573064
<< ">(jlModule);\n";

src/cxxwrap_version.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
#include "cxxwrap_version.h"
22

33
//according to https://github.com/JuliaInterop/libcxxwrap-julia/releases
4-
//we have breaking changes with libcxxwrap_jll versions,
4+
//we have following CxxWrap/libcxxwrap version mapping
55
//v0.10.0 (not used by any CxxWrap release),
6-
//v0.11.0 (CxxWrap v0.14.0),
7-
//v0.12.0 (CxxWrap v0.15.0)
8-
//v0.13.0 (not breaking, see https://github.com/JuliaInterop/CxxWrap.jl/releases/tag/v0.16.0)
9-
std::tuple<long, long> version_libcxxwrap_bounds(long cxxwrap_version){
6+
//v0.11.0 (CxxWrap v0.14.0)
7+
//v0.12.0 (CxxWrap v0.15.0) change in generated code
8+
//v0.13.0 (CxxWrap v0.16.0)
9+
//v0.14.0 (CxxWrap v0.17.0) change in generated code
10+
11+
12+
std::tuple<long, long> version_libcxxwrap_static_bounds(long cxxwrap_version){
1013
if(cxxwrap_version < cxxwrap_v0_15){
1114
return std::tuple<long, long>(11*1000, 12*1000);
12-
} else{
15+
} else if(cxxwrap_version < cxxwrap_v0_17){
1316
return std::tuple<long, long>(12*1000, 14*1000);
17+
} else{
18+
return std::tuple<long, long>(14*1000, 15*1000);
19+
}
20+
}
21+
22+
std::tuple<long, long> version_libcxxwrap_runtime_bounds(long cxxwrap_version){
23+
if(cxxwrap_version < cxxwrap_v0_15){ //CxxWrap v0.14
24+
return std::tuple<long, long>(11*1000, 12*1000);
25+
} else if(cxxwrap_version < 16 * 1000){ //CxxWrap v0.15
26+
return std::tuple<long, long>(12*1000, 13*1000);
27+
} else if(cxxwrap_version < 17 * 1000){ //CxxWrap v0.16
28+
return std::tuple<long, long>(13*1000, 14*1000);
29+
} else{ //CxxWrap v0.17+
30+
return std::tuple<long, long>(14*1000, 15*1000);
1431
}
1532
}

src/cxxwrap_version.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
#include <tuple>
22

33
//Default value for the cxxwrap_version config parameter
4-
static const char* default_cxxwrap_version = "0.16.0";
4+
static const char* default_cxxwrap_version = "0.17.0";
55

6-
static const char* supported_cxxwrap_versions = "0.14.x, 0.15.x, 0.16.x";
6+
static const char* supported_cxxwrap_versions = "0.14.x, 0.15.x, 0.16.x, 0.17.x";
77

88
static int cxxwrap_v0_15 = 15 * 1000; //v0.15
9+
static int cxxwrap_v0_17 = 17 * 1000; //v0.17
910

10-
std::tuple<long, long> version_libcxxwrap_bounds(long cxxwrap_version);
11+
//get libcxxwrap release interval for which code generated code is valid
12+
std::tuple<long, long> version_libcxxwrap_static_bounds(long cxxwrap_version);
13+
14+
//get libcxxwrap release interval the library was built for
15+
std::tuple<long, long> version_libcxxwrap_runtime_bounds(long cxxwrap_version);
1116

0 commit comments

Comments
 (0)