Skip to content

Commit 4b3ff36

Browse files
authored
Support FILE* pointers (#195)
1 parent 511a274 commit 4b3ff36

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

examples/types.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,12 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& types)
481481

482482
types.method("neverempty_array", [] () { NeverEmpty n(1); return std::vector({n}); });
483483
types.method("neverempty_deque", [] () { NeverEmpty n(1); return std::deque({n}); });
484+
485+
// Note that when mixing compilers (e.g. MSVC and GCC) the FILE* must be manipulated only from
486+
// within functions compiled with the same compiler. Passing between CRT results in errors.
487+
types.method("makefptr", [] (const std::string& filename) { return fopen(filename.c_str(), "w"); });
488+
types.method("writefptr", [] (FILE* fp) { fprintf(fp, "Hello world!"); });
489+
types.method("closefptr", [] (FILE* fp) { fclose(fp); });
484490
}
485491

486492
JLCXX_MODULE define_types2_module(jlcxx::Module& types2)

include/jlcxx/jlcxx_config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#define JLCXX_VERSION_MAJOR 0
1818
#define JLCXX_VERSION_MINOR 14
19-
#define JLCXX_VERSION_PATCH 6
19+
#define JLCXX_VERSION_PATCH 7
2020

2121
// From https://stackoverflow.com/questions/5459868/concatenate-int-to-string-using-c-preprocessor
2222
#define __JLCXX_STR_HELPER(x) #x

src/jlcxx.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ JLCXX_API void register_core_types()
397397

398398
set_julia_type<jl_datatype_t*>(jl_any_type,false);
399399
set_julia_type<jl_value_t*>(jl_any_type,false);
400+
401+
set_julia_type<FILE*>((jl_datatype_t*)jl_apply_type1((jl_value_t*)jl_pointer_type, julia_type("FILE", "Libc")), false);
400402
registered = true;
401403
}
402404
}

0 commit comments

Comments
 (0)