Skip to content

Commit

Permalink
⬆️ libc7zip, changes for MSVC compat
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Nov 23, 2017
1 parent dc52ca4 commit 6838fc8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -9,7 +9,7 @@ in the executable's folder.

For example

* On Windows, you'll need `foobar.exe`, `libc7zip.dll`, and `7z.dll` in the same directory
* On Windows, you'll need `foobar.exe`, `c7zip.dll`, and `7z.dll` in the same directory
* On Linux, you'll need `foobar`, `libc7zip.so`, and `7z.so` in the same directory
* On macOS, you'll need `foobar`, `libc7zip.dylib`, and `7z.so` in the same directory

Expand Down
5 changes: 5 additions & 0 deletions sz/glue.c
Expand Up @@ -57,6 +57,7 @@ int libc7zip_initialize(char *lib_path) {
LOADSYM(archive_get_item)

LOADSYM(item_get_string_property)
LOADSYM(string_free)
LOADSYM(item_get_uint64_property)
LOADSYM(item_get_bool_property)
LOADSYM(item_free)
Expand Down Expand Up @@ -141,6 +142,10 @@ char *libc7zip_item_get_string_property(item *i, int32_t property_index) {
return item_get_string_property_(i, property_index);
}

void libc7zip_string_free(char *s) {
string_free_(s);
}

uint64_t libc7zip_item_get_uint64_property(item *i, int32_t property_index) {
return item_get_uint64_property_(i, property_index);
}
Expand Down
4 changes: 2 additions & 2 deletions sz/glue.go
Expand Up @@ -72,7 +72,7 @@ func lazyInit() error {
libPath := "unsupported-os"
switch runtime.GOOS {
case "windows":
libPath = "libc7zip.dll"
libPath = "c7zip.dll"
case "linux":
libPath = "libc7zip.so"
case "darwin":
Expand Down Expand Up @@ -365,7 +365,7 @@ func (i *Item) GetStringProperty(id PropertyIndex) string {
return ""
}

defer C.free(unsafe.Pointer(cstr))
defer C.libc7zip_string_free(cstr)
return C.GoString(cstr)
}

Expand Down
5 changes: 5 additions & 0 deletions sz/glue.h
Expand Up @@ -91,6 +91,11 @@ typedef char *(*item_get_string_property_t)(item *i, int32_t property_index);
DECLARE(item_get_string_property)
char *libc7zip_item_get_string_property(item *i, int32_t property_index);

// string_free
typedef void (*string_free_t)(char *s);
DECLARE(string_free)
void libc7zip_string_free(char *s);

// item_get_uint64_property
typedef uint64_t (*item_get_uint64_property_t)(item *i, int32_t property_index);
DECLARE(item_get_uint64_property)
Expand Down
55 changes: 31 additions & 24 deletions sz/libc7zip.h
Expand Up @@ -2,6 +2,12 @@
#ifndef LIBC7ZIP_H
#define LIBC7ZIP_H

#ifdef _MSC_VER
#define MYEXPORT __declspec( dllexport )
#else
#define MYEXPORT
#endif

#include <stdint.h>

#ifdef __cplusplus
Expand All @@ -10,9 +16,9 @@ extern "C" {

struct lib;
typedef struct lib lib;
lib *lib_new();
int32_t lib_get_last_error(lib *l);
void lib_free(lib *l);
MYEXPORT lib *lib_new();
MYEXPORT int32_t lib_get_last_error(lib *l);
MYEXPORT void lib_free(lib *l);

struct in_stream;
typedef struct in_stream in_stream;
Expand Down Expand Up @@ -46,21 +52,21 @@ typedef struct out_stream_def {
write_cb_t write_cb;
} out_stream_def;

in_stream *in_stream_new();
in_stream_def *in_stream_get_def(in_stream *is);
void in_stream_commit_def(in_stream *is);
void in_stream_free(in_stream *is);
MYEXPORT in_stream *in_stream_new();
MYEXPORT in_stream_def *in_stream_get_def(in_stream *is);
MYEXPORT void in_stream_commit_def(in_stream *is);
MYEXPORT void in_stream_free(in_stream *is);

out_stream *out_stream_new();
out_stream_def *out_stream_get_def(out_stream *s);
void out_stream_free(out_stream *s);
MYEXPORT out_stream *out_stream_new();
MYEXPORT out_stream_def *out_stream_get_def(out_stream *s);
MYEXPORT void out_stream_free(out_stream *s);

struct archive;
typedef struct archive archive;
archive *archive_open(lib *l, in_stream *is, int32_t by_signature);
void archive_close(archive *a);
void archive_free(archive *a);
int64_t archive_get_item_count(archive *a);
MYEXPORT archive *archive_open(lib *l, in_stream *is, int32_t by_signature);
MYEXPORT void archive_close(archive *a);
MYEXPORT void archive_free(archive *a);
MYEXPORT int64_t archive_get_item_count(archive *a);

// copied from lib7zip.h so we don't have to include it
enum property_index {
Expand Down Expand Up @@ -108,12 +114,13 @@ enum error_code

struct item;
typedef struct item item;
item *archive_get_item(archive *a, int64_t index);
char *item_get_string_property(item *i, int32_t property_index);
uint64_t item_get_uint64_property(item *i, int32_t property_index);
int32_t item_get_bool_property(item *i, int32_t property_index);
void item_free(item *i);
int archive_extract_item(archive *a, item *i, out_stream *os);
MYEXPORT item *archive_get_item(archive *a, int64_t index);
MYEXPORT char *item_get_string_property(item *i, int32_t property_index);
MYEXPORT void string_free(char *s);
MYEXPORT uint64_t item_get_uint64_property(item *i, int32_t property_index);
MYEXPORT int32_t item_get_bool_property(item *i, int32_t property_index);
MYEXPORT void item_free(item *i);
MYEXPORT int archive_extract_item(archive *a, item *i, out_stream *os);

struct extract_callback;
typedef struct extract_callback extract_callback;
Expand All @@ -126,11 +133,11 @@ typedef struct extract_callback_def {
set_operation_result_cb_t set_operation_result_cb;
} extract_callback_def;

extract_callback *extract_callback_new();
extract_callback_def *extract_callback_get_def(extract_callback *ec);
void extract_callback_free(extract_callback *ec);
MYEXPORT extract_callback *extract_callback_new();
MYEXPORT extract_callback_def *extract_callback_get_def(extract_callback *ec);
MYEXPORT void extract_callback_free(extract_callback *ec);

int archive_extract_several(archive *a, int64_t *indices, int32_t num_indices, extract_callback *ec);
MYEXPORT int archive_extract_several(archive *a, int64_t *indices, int32_t num_indices, extract_callback *ec);

#ifdef __cplusplus
} // extern "C"
Expand Down

0 comments on commit 6838fc8

Please sign in to comment.