|
10 | 10 | #include <sstream> |
11 | 11 | #include <stdexcept> |
12 | 12 |
|
| 13 | +#ifdef __cplusplus |
13 | 14 | extern "C" { |
14 | | - int wvlet_compile_main(const char*); |
15 | | - const char* wvlet_compile_compile(const char*); |
| 15 | +#endif |
| 16 | + extern int ScalaNativeInit(void); |
| 17 | + |
| 18 | + extern int wvlet_compile_main(const char*); |
| 19 | + extern const char* wvlet_compile_compile(const char*); |
| 20 | + |
| 21 | +#ifdef __cplusplus |
16 | 22 | } |
| 23 | +#endif |
17 | 24 |
|
18 | 25 | namespace duckdb { |
19 | 26 |
|
| 27 | +// EXPERIMENT INIT |
| 28 | +bool InitializeWvletRuntime() { |
| 29 | + try { |
| 30 | + // Set heap sizes via environment variables |
| 31 | + setenv("GC_INITIAL_HEAP_SIZE", "2097152", 1); // 64MB |
| 32 | + setenv("GC_MAXIMUM_HEAP_SIZE", "8388608", 1); // 256MB |
| 33 | + |
| 34 | + // fprintf(stderr, "Initializing Scala Native Runtime...\n"); |
| 35 | + int init_result = ScalaNativeInit(); |
| 36 | + if (init_result != 0) { |
| 37 | + fprintf(stderr, "Failed to initialize Scala Native Runtime: %d\n", init_result); |
| 38 | + return false; |
| 39 | + } |
| 40 | + |
| 41 | + // fprintf(stderr, "Scala Native Runtime initialized successfully!\n"); |
| 42 | + return true; |
| 43 | + } catch (...) { |
| 44 | + fprintf(stderr, "Scala Runtime Initialization failed with exception!\n"); |
| 45 | + return false; |
| 46 | + } |
| 47 | +} |
| 48 | + |
20 | 49 | void WvletScriptFunction::ParseWvletScript(DataChunk &args, ExpressionState &state, Vector &result) { |
21 | 50 | auto &input_vector = args.data[0]; |
22 | 51 | auto input = FlatVector::GetData<string_t>(input_vector); |
@@ -130,6 +159,10 @@ static void LoadInternal(DatabaseInstance &instance) { |
130 | 159 |
|
131 | 160 | void WvletExtension::Load(DuckDB &db) { |
132 | 161 | LoadInternal(*db.instance); |
| 162 | + // EXPERIMENT |
| 163 | + if (!InitializeWvletRuntime()) { |
| 164 | + throw std::runtime_error("Failed to initialize Wvlet runtime"); |
| 165 | + } |
133 | 166 | } |
134 | 167 |
|
135 | 168 | std::string WvletExtension::Name() { |
|
0 commit comments