mspack_rb 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f9c40d23c5867b56e2fa1b1960fd31309cfa799
4
- data.tar.gz: 642ae95857d11d712c584a11b2f20ba0b2daeca3
3
+ metadata.gz: 5ca23ebbd613db3fe80bd92522255ba960a7b039
4
+ data.tar.gz: a9f7f8bb5d4be741d535d3c6c4b03ae2430c80d5
5
5
  SHA512:
6
- metadata.gz: 508fd382485b88754746f25ff1bae5006a68306c5ced69a141e52c053470a2c89d6014cb8999f2ea7a261f5e9a535eb4cf5fffd40b46322ef013ca0bc7199f68
7
- data.tar.gz: 64dd35882e4fa5fbfa80c147ad422ec30d83caf27d89df1ea130ec743d2e2bb02889b64287b9855375ebbda35851bf155f095b66b8dae948a10beb83b6ad564b
6
+ metadata.gz: 413f41de3155794d82dcfb7d0e4e5f58319cd4026f652dcaa333ea0b62a300008aa4f27e3edf8d428c3d0d83000becc008b602ad65d98206dc7ab89f6daea72c
7
+ data.tar.gz: 91758d054375b7d19a7de6e6551b5627161e6eb14744858dbf73394f18b7255f115dfe47260ab20cf32312a984fcb1faf44e7e45f45714409fa75d710a79c955
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "mspack_rb"
4
+ require "mspack"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -124,11 +124,11 @@ VALUE chmd_extract_to_path(VALUE self, VALUE file, VALUE outputPath) {
124
124
  struct mschm_decompressor *decom;
125
125
  Data_Get_Struct(self, struct mschm_decompressor, decom);
126
126
 
127
- struct mschmd_file *filePtr;
128
- Data_Get_Struct(file, struct mschmd_file, filePtr);
127
+ struct chmd_file_wrapper *wrapper;
128
+ Data_Get_Struct(file, struct chmd_file_wrapper, wrapper);
129
129
  const char *pathStr = StringValueCStr(outputPath);
130
130
 
131
- int result = decom->extract(decom, filePtr, pathStr);
131
+ int result = decom->extract(decom, wrapper->file, pathStr);
132
132
  return result == MSPACK_ERR_OK ? Qtrue : Qfalse;
133
133
  }
134
134
 
@@ -167,9 +167,11 @@ VALUE chmd_fast_find(VALUE self, VALUE header, VALUE filename) {
167
167
  file->filename = malloc(sizeof(char) * strlen(filenameStr) + 1);
168
168
  strcpy(file->filename, filenameStr);
169
169
 
170
- VALUE fileObj = Data_Wrap_Struct(ChmDFile, NULL, NULL, file);
171
- rb_iv_set(fileObj, "is_fast_find", Qtrue);
172
- return fileObj;
170
+ struct chmd_file_wrapper *wrapper = malloc(sizeof(struct chmd_file_wrapper));
171
+ wrapper->is_fast_find = 1;
172
+ wrapper->file = file;
173
+
174
+ return Data_Wrap_Struct(ChmDFile, NULL, chmd_file_free, wrapper);
173
175
  }
174
176
 
175
177
  void Init_chm_decompressor() {
@@ -4,44 +4,51 @@
4
4
  #include <mspack.h>
5
5
 
6
6
  void chmd_file_free(void *ptr) {
7
- struct mschmd_file *file = (struct mschmd_file *)ptr;
7
+ struct chmd_file_wrapper *wrapper = (struct chmd_file_wrapper *)ptr;
8
8
 
9
- if (file->length == 0) { // only free if it was created in fast_find
10
- //if (file->filename) {
11
- // free(file->filename);
12
- //}
9
+ if (wrapper->is_fast_find) {
10
+ if (wrapper->file->filename) {
11
+ free(wrapper->file->filename);
12
+ }
13
13
 
14
- free(file);
14
+ free(wrapper->file);
15
15
  }
16
+
17
+ free(ptr);
16
18
  }
17
19
 
18
20
  VALUE chmd_file_filename(VALUE self) {
19
- struct mschmd_file *file;
20
- Data_Get_Struct(self, struct mschmd_file, file);
21
+ struct chmd_file_wrapper *wrapper;
22
+ Data_Get_Struct(self, struct chmd_file_wrapper, wrapper);
21
23
 
22
- if (!file->filename) {
24
+ if (!wrapper->file->filename) {
23
25
  return Qnil;
24
26
  }
25
27
 
26
- return rb_str_new2(file->filename);
28
+ return rb_str_new2(wrapper->file->filename);
27
29
  }
28
30
 
29
31
  VALUE chmd_file_next(VALUE self) {
30
- struct mschmd_file *file;
31
- Data_Get_Struct(self, struct mschmd_file, file);
32
- struct mschmd_file *next = file->next;
32
+ struct chmd_file_wrapper *wrapper;
33
+ Data_Get_Struct(self, struct chmd_file_wrapper, wrapper);
34
+ struct mschmd_file *next = wrapper->file->next;
33
35
 
34
36
  if (!next) {
35
37
  return Qnil;
36
38
  }
37
39
 
38
- VALUE nextObj = Data_Wrap_Struct(ChmDFile, NULL, chmd_file_free, next);
39
- rb_iv_set(nextObj, "is_fast_find", Qfalse);
40
- return nextObj;
40
+ struct chmd_file_wrapper *next_wrapper =
41
+ malloc(sizeof(struct chmd_file_wrapper));
42
+ next_wrapper->is_fast_find = 0;
43
+ next_wrapper->file = next;
44
+
45
+ return Data_Wrap_Struct(ChmDFile, NULL, chmd_file_free, next_wrapper);
41
46
  }
42
47
 
43
48
  VALUE chmd_file_is_fast_find(VALUE self) {
44
- return rb_iv_get(self, "is_fast_find");
49
+ struct chmd_file_wrapper *wrapper;
50
+ Data_Get_Struct(self, struct chmd_file_wrapper, wrapper);
51
+ return wrapper->is_fast_find ? Qtrue : Qfalse;
45
52
  }
46
53
 
47
54
  void Init_chm_decompressor_file() {
@@ -3,6 +3,15 @@
3
3
 
4
4
  #include <ruby.h>
5
5
 
6
+ struct mschmd_file;
7
+
8
+ struct chmd_file_wrapper {
9
+ int is_fast_find;
10
+ struct mschmd_file *file;
11
+ };
12
+
13
+ void chmd_file_free(void *ptr);
14
+
6
15
  void Init_chm_decompressor_file();
7
16
 
8
17
  #endif
@@ -1,4 +1,5 @@
1
1
  #include "chm_decompressor_header.h"
2
+ #include "chm_decompressor_file.h"
2
3
  #include "mspack_native.h"
3
4
 
4
5
  #include <mspack.h>
@@ -16,10 +17,12 @@ VALUE chmd_header_files(VALUE self) {
16
17
  if (!header->files) {
17
18
  return Qnil;
18
19
  }
20
+
21
+ struct chmd_file_wrapper *wrapper = malloc(sizeof(struct chmd_file_wrapper));
22
+ wrapper->is_fast_find = 0;
23
+ wrapper->file = header->files;
19
24
 
20
- VALUE file = Data_Wrap_Struct(ChmDFile, NULL, NULL, header->files);
21
- rb_iv_set(file, "is_fast_find", Qfalse);
22
- return file;
25
+ return Data_Wrap_Struct(ChmDFile, NULL, chmd_file_free, wrapper);
23
26
  }
24
27
 
25
28
  VALUE chmd_header_is_fast_open(VALUE self) {
@@ -1,3 +1,3 @@
1
1
  module Mspack
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mspack_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-19 00:00:00.000000000 Z
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler