Skip to content

Commit 752a273

Browse files
committed
Build bz2 module for windows
1 parent baf78cf commit 752a273

File tree

6 files changed

+120
-116
lines changed

6 files changed

+120
-116
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_bz2.txt

Lines changed: 92 additions & 90 deletions
Large diffs are not rendered by default.

graalpython/lib-python/3/test/conftest.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,3 @@ selector = [
4747
# when the runner exits. We don't know which tests can trigger this, so we exclude the whole file.
4848
'test_multiprocessing_graalpy',
4949
]
50-
51-
[[test_rules]]
52-
exclude_on = ['win32']
53-
selector = [
54-
# TODO fails to load bz2 library
55-
# java.lang.UnsatisfiedLinkError: ...\lib-graalpython\bz2support.dll GetLastError: 126
56-
'test_bz2',
57-
]

graalpython/lib-python/3/test/test_bz2.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,6 @@ def testCompress4G(self, size):
677677
finally:
678678
data = None
679679

680-
@support.impl_detail("GR-27707: basicsize for native objects not yet supported", graalpy=False)
681680
def testPickle(self):
682681
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
683682
with self.assertRaises(TypeError):
@@ -736,7 +735,6 @@ def testDecompress4G(self, size):
736735
compressed = None
737736
decompressed = None
738737

739-
@support.impl_detail("GR-27707: basicsize for native objects not yet supported", graalpy=False)
740738
def testPickle(self):
741739
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
742740
with self.assertRaises(TypeError):

graalpython/python-libbz2/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ add_library(${TARGET_BZIP2SUPPORT} SHARED)
4444
target_compile_definitions(${TARGET_BZIP2SUPPORT} PRIVATE NDEBUG)
4545

4646
if(WIN32)
47-
target_compile_options(${TARGET_BZIP2SUPPORT} PRIVATE /O2 /WX)
47+
target_compile_options(${TARGET_BZIP2SUPPORT} PRIVATE /O2)
4848
else()
4949
target_compile_options(${TARGET_BZIP2SUPPORT} PRIVATE -Wall -Werror -O3)
5050
endif()
@@ -53,7 +53,9 @@ endif()
5353
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
5454

5555
target_sources(${TARGET_BZIP2SUPPORT} PRIVATE "src/bz2.c")
56-
set_target_properties(${TARGET_BZIP2SUPPORT} PROPERTIES COMPILE_WARNING_AS_ERROR ON)
56+
if(NOT WIN32)
57+
set_target_properties(${TARGET_BZIP2SUPPORT} PROPERTIES COMPILE_WARNING_AS_ERROR ON)
58+
endif()
5759
# variable 'BZIP2_SRC' is provided by file 'libbz2.cmake'
5860
target_include_directories(${TARGET_BZIP2SUPPORT} PRIVATE ${BZIP2_SRC})
5961
target_link_libraries(${TARGET_BZIP2SUPPORT} PRIVATE ${TARGET_LIBBZ2})

graalpython/python-libbz2/src/bz2.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -56,6 +56,14 @@
5656

5757
typedef char Byte; /* 8 bits */
5858

59+
#if defined(_MSC_VER)
60+
#include <BaseTsd.h>
61+
typedef SSIZE_T ssize_t;
62+
#define API_FUNC __declspec(dllexport)
63+
#else
64+
#define API_FUNC
65+
#endif
66+
5967
// Integer.MAX_INT
6068
#define GRAALPYTHON_MAX_SIZE (INT_MAX)
6169

@@ -216,7 +224,7 @@ static void bz_release_buffer(off_heap_buffer *o) {
216224
}
217225

218226
// nfi_function: name('createStream') map('bzst_stream*', 'POINTER')
219-
bzst_stream *bz_create_bzst_stream() {
227+
API_FUNC bzst_stream *bz_create_bzst_stream() {
220228
bzst_stream *bzst = (bzst_stream *) malloc(sizeof(bzst_stream));
221229
bzst->bzs.opaque = NULL;
222230
bzst->bzs.bzalloc = BZ2_Malloc;
@@ -236,7 +244,7 @@ bzst_stream *bz_create_bzst_stream() {
236244
}
237245

238246
// nfi_function: name('getTimeElapsed') map('bzst_stream*', 'POINTER') static(true)
239-
double bz_get_timeElapsed(bzst_stream* zst) {
247+
API_FUNC double bz_get_timeElapsed(bzst_stream* zst) {
240248
#ifdef BENCHMARK
241249
double t = bzst->timeElapsed;
242250
LOG_FINEST("time Elapsed: %.2f\n", t);
@@ -248,7 +256,7 @@ double bz_get_timeElapsed(bzst_stream* zst) {
248256
}
249257

250258
// nfi_function: name('deallocateStream') map('bzst_stream*', 'POINTER')
251-
void bz_free_stream(bzst_stream* bzst) {
259+
API_FUNC void bz_free_stream(bzst_stream* bzst) {
252260
if (!bzst) {
253261
return;
254262
}
@@ -265,27 +273,27 @@ void bz_free_stream(bzst_stream* bzst) {
265273
}
266274

267275
// nfi_function: name('gcReleaseHelper') map('bzst_stream*', 'POINTER') release(true)
268-
void bz_gc_helper(bzst_stream* bzst) {
276+
API_FUNC void bz_gc_helper(bzst_stream* bzst) {
269277
bz_free_stream(bzst);
270278
}
271279

272280
// nfi_function: name('getNextInIndex') map('bzst_stream*', 'POINTER')
273-
ssize_t bz_get_next_in_index(bzst_stream *bzst) {
281+
API_FUNC ssize_t bz_get_next_in_index(bzst_stream *bzst) {
274282
return bzst->next_in_index;
275283
}
276284

277285
// nfi_function: name('getBzsAvailInReal') map('bzst_stream*', 'POINTER')
278-
ssize_t bz_get_bzs_avail_in_real(bzst_stream *bzst) {
286+
API_FUNC ssize_t bz_get_bzs_avail_in_real(bzst_stream *bzst) {
279287
return bzst->bzs_avail_in_real;
280288
}
281289

282290
// nfi_function: name('setBzsAvailInReal') map('bzst_stream*', 'POINTER')
283-
void bz_set_bzs_avail_in_real(bzst_stream *bzst, ssize_t v) {
291+
API_FUNC void bz_set_bzs_avail_in_real(bzst_stream *bzst, ssize_t v) {
284292
bzst->bzs_avail_in_real = v;
285293
}
286294

287295
// nfi_function: name('getOutputBufferSize') map('bzst_stream*', 'POINTER')
288-
size_t bz_get_output_buffer_size(bzst_stream *bzst) {
296+
API_FUNC size_t bz_get_output_buffer_size(bzst_stream *bzst) {
289297
LOG_INFO("bz_get_output_buffer_size(%p)\n", bzst);
290298
size_t size = bzst->output_size;
291299
if (size > GRAALPYTHON_MAX_SIZE) {
@@ -303,7 +311,7 @@ static void clear_output(bzst_stream *bzst) {
303311
}
304312

305313
// nfi_function: name('getOutputBuffer') map('bzst_stream*', 'POINTER')
306-
void bz_get_output_buffer(bzst_stream *bzst, Byte *dest) {
314+
API_FUNC void bz_get_output_buffer(bzst_stream *bzst, Byte *dest) {
307315
LOG_INFO("bz_get_off_heap_buffer(%p)\n", bzst);
308316
off_heap_buffer *buffer = bzst->output;
309317
size_t size = bzst->output_size;
@@ -376,7 +384,7 @@ grow_buffer(bzst_stream *bzst, ssize_t max_length) {
376384

377385

378386
// nfi_function: name('compressInit') map('bzst_stream*', 'POINTER')
379-
int bz_compressor_init(bzst_stream *bzst, int compresslevel) {
387+
API_FUNC int bz_compressor_init(bzst_stream *bzst, int compresslevel) {
380388
LOG_INFO("bz_compressor_init(%p, %d)\n", bzst, compresslevel);
381389
int bzerror = BZ2_bzCompressInit(&bzst->bzs, compresslevel, 0, 0);
382390
if (!isOK(bzerror)) {
@@ -387,7 +395,7 @@ int bz_compressor_init(bzst_stream *bzst, int compresslevel) {
387395
}
388396

389397
// nfi_function: name('compress') map('bzst_stream*', 'POINTER')
390-
int bz_compress(bzst_stream *bzst, Byte *data, ssize_t len, int action, ssize_t bufsize) {
398+
API_FUNC int bz_compress(bzst_stream *bzst, Byte *data, ssize_t len, int action, ssize_t bufsize) {
391399
LOG_INFO("bz_compress(%p, %zd, %d, %zd)\n", bzst, len, action, bufsize);
392400
size_t data_size = 0;
393401

@@ -462,7 +470,7 @@ int bz_compress(bzst_stream *bzst, Byte *data, ssize_t len, int action, ssize_t
462470
************************************************/
463471

464472
// nfi_function: name('decompressInit') map('bzst_stream*', 'POINTER')
465-
int bz_decompress_init(bzst_stream *bzst) {
473+
API_FUNC int bz_decompress_init(bzst_stream *bzst) {
466474
LOG_INFO("bz_decompress_init(%p)\n", bzst);
467475
int bzerror = BZ2_bzDecompressInit(&bzst->bzs, 0, 0);
468476
if (!isOK(bzerror)) {
@@ -479,7 +487,7 @@ int bz_decompress_init(bzst_stream *bzst) {
479487
returned, so some of the input may not be consumed. d->bzs.next_in and
480488
d->bzs_avail_in_real are updated to reflect the consumed input. */
481489
// nfi_function: name('decompress') map('bzst_stream*', 'POINTER')
482-
int bz_decompress(bzst_stream *bzst,
490+
API_FUNC int bz_decompress(bzst_stream *bzst,
483491
Byte *input_buffer, ssize_t offset,
484492
ssize_t max_length,
485493
ssize_t bufsize, ssize_t bzs_avail_in_real) {

mx.graalpython/suite.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@
596596
"bin/<lib:bz2support>",
597597
],
598598
"cmakeConfig": {
599+
"CMAKE_BUILD_TYPE": "Release",
599600
"BZIP2_ROOT": "<path:BZIP2>",
600601
"BZIP2_VERSION_MAJOR": "1",
601602
"BZIP2_VERSION_MINOR": "0",
@@ -1073,6 +1074,7 @@
10731074
"dependency:com.oracle.graal.python.jni/*",
10741075
"dependency:com.oracle.graal.python.cext/bin/*",
10751076
"dependency:com.oracle.graal.python.hpy.llvm/bin/*",
1077+
"dependency:python-libbz2/bin/*",
10761078
]
10771079
},
10781080
},

0 commit comments

Comments
 (0)