junkeldat 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/my_malloc/extconf.rb +6 -0
- data/ext/my_malloc/my_malloc.c +73 -0
- data/lib/my_malloc.rb +5 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 802e3ab486e8200c804e10a216e453015065360a
|
4
|
+
data.tar.gz: 92a591b6a0d8f0f5fc687e62bae1adbd1d5ceef9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f02cc2c8e2618e58a470483370eed8b678a6fdefabfc839f93559d5b3193bafb83bd22d3e9ce8f0fbbca3877369ac4bbcce9beaf6baae297aae6d0ec89813bf
|
7
|
+
data.tar.gz: 9ec187fbd74871882ff9feeee1aa843837069a0babdf141f2f902b0e4903f8c3471386e002d92c05a4aa2dea324e9c76bb3f24da8b130c52622251059180f924
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
struct my_malloc {
|
4
|
+
size_t size;
|
5
|
+
void *ptr;
|
6
|
+
};
|
7
|
+
|
8
|
+
static void
|
9
|
+
my_malloc_free(void *p) {
|
10
|
+
struct my_malloc *ptr = p;
|
11
|
+
|
12
|
+
if (ptr->size > 0)
|
13
|
+
free(ptr->ptr);
|
14
|
+
}
|
15
|
+
|
16
|
+
static VALUE
|
17
|
+
my_malloc_alloc(VALUE klass) {
|
18
|
+
VALUE obj;
|
19
|
+
struct my_malloc *ptr;
|
20
|
+
|
21
|
+
obj = Data_Make_Struct(klass, struct my_malloc, NULL, my_malloc_free, ptr);
|
22
|
+
|
23
|
+
ptr->size = 0;
|
24
|
+
ptr->ptr = NULL;
|
25
|
+
|
26
|
+
return obj;
|
27
|
+
}
|
28
|
+
|
29
|
+
static VALUE
|
30
|
+
my_malloc_init(VALUE self, VALUE size) {
|
31
|
+
struct my_malloc *ptr;
|
32
|
+
size_t requested = NUM2SIZET(size);
|
33
|
+
|
34
|
+
if (0 == requested)
|
35
|
+
rb_raise(rb_eArgError, "unable to allocate 0 bytes");
|
36
|
+
|
37
|
+
Data_Get_Struct(self, struct my_malloc, ptr);
|
38
|
+
|
39
|
+
ptr->ptr = malloc(requested);
|
40
|
+
|
41
|
+
if (NULL == ptr->ptr)
|
42
|
+
rb_raise(rb_eNoMemError, "unable to allocate %ld bytes", requested);
|
43
|
+
|
44
|
+
ptr->size = requested;
|
45
|
+
|
46
|
+
return self;
|
47
|
+
}
|
48
|
+
|
49
|
+
static VALUE
|
50
|
+
my_malloc_release(VALUE self) {
|
51
|
+
struct my_malloc *ptr;
|
52
|
+
|
53
|
+
Data_Get_Struct(self, struct my_malloc, ptr);
|
54
|
+
|
55
|
+
if (0 == ptr->size)
|
56
|
+
return self;
|
57
|
+
|
58
|
+
ptr->size = 0;
|
59
|
+
free(ptr->ptr);
|
60
|
+
|
61
|
+
return self;
|
62
|
+
}
|
63
|
+
|
64
|
+
void
|
65
|
+
Init_my_malloc(void) {
|
66
|
+
VALUE cMyMalloc;
|
67
|
+
|
68
|
+
cMyMalloc = rb_const_get(rb_cObject, rb_intern("MyMalloc"));
|
69
|
+
|
70
|
+
rb_define_alloc_func(cMyMalloc, my_malloc_alloc);
|
71
|
+
rb_define_method(cMyMalloc, "initialize", my_malloc_init, 1);
|
72
|
+
rb_define_method(cMyMalloc, "free", my_malloc_release, 0);
|
73
|
+
}
|
data/lib/my_malloc.rb
ADDED
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: junkeldat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- junkeldat
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- ''
|
16
|
+
executables: []
|
17
|
+
extensions:
|
18
|
+
- ext/my_malloc/extconf.rb
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ext/my_malloc/extconf.rb
|
22
|
+
- ext/my_malloc/my_malloc.c
|
23
|
+
- lib/my_malloc.rb
|
24
|
+
homepage: http://pypi.python.org/pypi/junkeldat/
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.6.13
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: The junkeldat software.
|
48
|
+
test_files: []
|