Skip to content

Commit 117fa34

Browse files
committed
Use TypedData when wrapping git_object
This lets us provide more information to the ruby VM about what our objects look like including information about how much memory they use up.
1 parent 0f660b6 commit 117fa34

File tree

9 files changed

+135
-72
lines changed

9 files changed

+135
-72
lines changed

ext/rugged/rugged_blob.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ static ID id_read;
1717
VALUE rb_cRuggedBlob;
1818
VALUE rb_cRuggedBlobSig;
1919

20+
extern const rb_data_type_t rugged_object_type;
21+
2022
/*
2123
* call-seq:
2224
* blob.text(max_lines = -1, encoding = Encoding.default_external) -> string
@@ -38,7 +40,7 @@ static VALUE rb_git_blob_text_GET(int argc, VALUE *argv, VALUE self)
3840
const char *content;
3941
VALUE rb_max_lines, rb_encoding;
4042

41-
Data_Get_Struct(self, git_blob, blob);
43+
TypedData_Get_Struct(self, git_blob, &rugged_object_type, blob);
4244
rb_scan_args(argc, argv, "02", &rb_max_lines, &rb_encoding);
4345

4446
content = git_blob_rawcontent(blob);
@@ -85,7 +87,7 @@ static VALUE rb_git_blob_content_GET(int argc, VALUE *argv, VALUE self)
8587
const char *content;
8688
VALUE rb_max_bytes;
8789

88-
Data_Get_Struct(self, git_blob, blob);
90+
TypedData_Get_Struct(self, git_blob, &rugged_object_type, blob);
8991
rb_scan_args(argc, argv, "01", &rb_max_bytes);
9092

9193
content = git_blob_rawcontent(blob);
@@ -119,7 +121,7 @@ static VALUE rb_git_blob_content_GET(int argc, VALUE *argv, VALUE self)
119121
static VALUE rb_git_blob_rawsize(VALUE self)
120122
{
121123
git_blob *blob;
122-
Data_Get_Struct(self, git_blob, blob);
124+
TypedData_Get_Struct(self, git_blob, &rugged_object_type, blob);
123125

124126
return INT2FIX(git_blob_rawsize(blob));
125127
}
@@ -304,7 +306,7 @@ static VALUE rb_git_blob_loc(VALUE self)
304306
const char *data, *data_end;
305307
size_t loc = 0;
306308

307-
Data_Get_Struct(self, git_blob, blob);
309+
TypedData_Get_Struct(self, git_blob, &rugged_object_type, blob);
308310

309311
data = git_blob_rawcontent(blob);
310312
data_end = data + git_blob_rawsize(blob);
@@ -343,7 +345,7 @@ static VALUE rb_git_blob_sloc(VALUE self)
343345
const char *data, *data_end;
344346
size_t sloc = 0;
345347

346-
Data_Get_Struct(self, git_blob, blob);
348+
TypedData_Get_Struct(self, git_blob, &rugged_object_type, blob);
347349

348350
data = git_blob_rawcontent(blob);
349351
data_end = data + git_blob_rawsize(blob);
@@ -383,7 +385,7 @@ static VALUE rb_git_blob_sloc(VALUE self)
383385
static VALUE rb_git_blob_is_binary(VALUE self)
384386
{
385387
git_blob *blob;
386-
Data_Get_Struct(self, git_blob, blob);
388+
TypedData_Get_Struct(self, git_blob, &rugged_object_type, blob);
387389
return git_blob_is_binary(blob) ? Qtrue : Qfalse;
388390
}
389391

@@ -467,14 +469,14 @@ static VALUE rb_git_blob_diff(int argc, VALUE *argv, VALUE self)
467469
rugged_parse_diff_options(&opts, rb_options);
468470
}
469471

470-
Data_Get_Struct(self, git_blob, blob);
472+
TypedData_Get_Struct(self, git_blob, &rugged_object_type, blob);
471473

472474
if (NIL_P(rb_other)) {
473475
error = git_patch_from_blobs(&patch, blob, old_path, NULL, new_path, &opts);
474476
} else if (rb_obj_is_kind_of(rb_other, rb_cRuggedBlob)) {
475477
git_blob *other_blob;
476478

477-
Data_Get_Struct(rb_other, git_blob, other_blob);
479+
TypedData_Get_Struct(rb_other, git_blob, &rugged_object_type, other_blob);
478480

479481
error = git_patch_from_blobs(&patch, blob, old_path, other_blob, new_path, &opts);
480482
} else if (TYPE(rb_other) == T_STRING) {
@@ -649,7 +651,7 @@ static VALUE rb_git_blob_sig_new(int argc, VALUE *argv, VALUE klass)
649651

650652
if (rb_obj_is_kind_of(rb_blob, rb_cRuggedBlob)) {
651653
git_blob *blob;
652-
Data_Get_Struct(rb_blob, git_blob, blob);
654+
TypedData_Get_Struct(rb_blob, git_blob, &rugged_object_type, blob);
653655

654656
error = git_hashsig_create(&sig,
655657
git_blob_rawcontent(blob),

ext/rugged/rugged_commit.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ extern VALUE rb_cRuggedRepo;
1515
extern VALUE rb_cRuggedSignature;
1616
VALUE rb_cRuggedCommit;
1717

18+
extern const rb_data_type_t rugged_object_type;
19+
1820
/*
1921
* call-seq:
2022
* commit.message -> msg
@@ -35,7 +37,7 @@ static VALUE rb_git_commit_message_GET(VALUE self)
3537
const char *encoding_name;
3638
const char *message;
3739

38-
Data_Get_Struct(self, git_commit, commit);
40+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
3941

4042
message = git_commit_message(commit);
4143
encoding_name = git_commit_message_encoding(commit);
@@ -68,7 +70,7 @@ static VALUE rb_git_commit_trailers_GET(VALUE self)
6870
int error;
6971
size_t i;
7072

71-
Data_Get_Struct(self, git_commit, commit);
73+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
7274

7375
encoding_name = git_commit_message_encoding(commit);
7476
if (encoding_name != NULL)
@@ -118,7 +120,7 @@ static VALUE rb_git_commit_summary_GET(VALUE self)
118120
const char *encoding_name;
119121
const char *summary;
120122

121-
Data_Get_Struct(self, git_commit, commit);
123+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
122124

123125
summary = git_commit_summary(commit);
124126
encoding_name = git_commit_message_encoding(commit);
@@ -147,7 +149,7 @@ static VALUE rb_git_commit_summary_GET(VALUE self)
147149
static VALUE rb_git_commit_committer_GET(VALUE self)
148150
{
149151
git_commit *commit;
150-
Data_Get_Struct(self, git_commit, commit);
152+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
151153

152154
return rugged_signature_new(
153155
git_commit_committer(commit),
@@ -172,7 +174,7 @@ static VALUE rb_git_commit_committer_GET(VALUE self)
172174
static VALUE rb_git_commit_author_GET(VALUE self)
173175
{
174176
git_commit *commit;
175-
Data_Get_Struct(self, git_commit, commit);
177+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
176178

177179
return rugged_signature_new(
178180
git_commit_author(commit),
@@ -192,7 +194,7 @@ static VALUE rb_git_commit_author_GET(VALUE self)
192194
static VALUE rb_git_commit_epoch_time_GET(VALUE self)
193195
{
194196
git_commit *commit;
195-
Data_Get_Struct(self, git_commit, commit);
197+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
196198

197199
return ULONG2NUM(git_commit_time(commit));
198200
}
@@ -213,7 +215,7 @@ static VALUE rb_git_commit_tree_GET(VALUE self)
213215
VALUE owner;
214216
int error;
215217

216-
Data_Get_Struct(self, git_commit, commit);
218+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
217219
owner = rugged_owner(self);
218220

219221
error = git_commit_tree(&tree, commit);
@@ -236,7 +238,7 @@ static VALUE rb_git_commit_tree_id_GET(VALUE self)
236238
git_commit *commit;
237239
const git_oid *tree_id;
238240

239-
Data_Get_Struct(self, git_commit, commit);
241+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
240242

241243
tree_id = git_commit_tree_id(commit);
242244

@@ -262,7 +264,7 @@ static VALUE rb_git_commit_parents_GET(VALUE self)
262264
VALUE ret_arr, owner;
263265
int error;
264266

265-
Data_Get_Struct(self, git_commit, commit);
267+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
266268
owner = rugged_owner(self);
267269

268270
parent_count = git_commit_parentcount(commit);
@@ -295,7 +297,7 @@ static VALUE rb_git_commit_parent_ids_GET(VALUE self)
295297
unsigned int n, parent_count;
296298
VALUE ret_arr;
297299

298-
Data_Get_Struct(self, git_commit, commit);
300+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
299301

300302
parent_count = git_commit_parentcount(commit);
301303
ret_arr = rb_ary_new2((long)parent_count);
@@ -352,7 +354,7 @@ static VALUE rb_git_commit_amend(VALUE self, VALUE rb_data)
352354

353355
Check_Type(rb_data, T_HASH);
354356

355-
Data_Get_Struct(self, git_commit, commit_to_amend);
357+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit_to_amend);
356358

357359
owner = rugged_owner(self);
358360
Data_Get_Struct(owner, git_repository, repo);
@@ -474,7 +476,7 @@ static VALUE parse_commit_options(struct commit_data *out, git_repository *repo,
474476
if (error < GIT_OK)
475477
goto out;
476478
} else if (rb_obj_is_kind_of(p, rb_cRuggedCommit)) {
477-
Data_Get_Struct(p, git_commit, tmp);
479+
TypedData_Get_Struct(p, git_commit, &rugged_object_type, tmp);
478480
if ((error = git_object_dup((git_object **) &parent, (git_object *) tmp)) < 0)
479481
goto out;
480482
} else {
@@ -614,7 +616,7 @@ static VALUE rb_git_commit_to_mbox(int argc, VALUE *argv, VALUE self)
614616
rugged_check_repo(rb_repo);
615617
Data_Get_Struct(rb_repo, git_repository, repo);
616618

617-
Data_Get_Struct(self, git_commit, commit);
619+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
618620

619621
if (!NIL_P(rb_options)) {
620622
Check_Type(rb_options, T_HASH);
@@ -673,7 +675,7 @@ static VALUE rb_git_commit_header_field(VALUE self, VALUE rb_field)
673675
int error;
674676

675677
Check_Type(rb_field, T_STRING);
676-
Data_Get_Struct(self, git_commit, commit);
678+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
677679

678680
error = git_commit_header_field(&header_field, commit, StringValueCStr(rb_field));
679681

@@ -704,7 +706,7 @@ static VALUE rb_git_commit_header(VALUE self)
704706
git_commit *commit;
705707
const char *raw_header;
706708

707-
Data_Get_Struct(self, git_commit, commit);
709+
TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
708710

709711
raw_header = git_commit_raw_header(commit);
710712
return rb_str_new_utf8(raw_header);

ext/rugged/rugged_index.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ extern VALUE rb_cRuggedCommit;
1313
extern VALUE rb_cRuggedDiff;
1414
extern VALUE rb_cRuggedTree;
1515

16+
extern const rb_data_type_t rugged_object_type;
17+
1618
static void rb_git_indexentry_toC(git_index_entry *entry, VALUE rb_entry);
1719
static VALUE rb_git_indexentry_fromC(const git_index_entry *entry);
1820

@@ -658,7 +660,7 @@ static VALUE rb_git_index_readtree(VALUE self, VALUE rb_tree)
658660
int error;
659661

660662
Data_Get_Struct(self, git_index, index);
661-
Data_Get_Struct(rb_tree, git_tree, tree);
663+
TypedData_Get_Struct(rb_tree, git_tree, &rugged_object_type, tree);
662664

663665
if (!rb_obj_is_kind_of(rb_tree, rb_cRuggedTree)) {
664666
rb_raise(rb_eTypeError, "A Rugged::Tree instance is required");
@@ -690,7 +692,7 @@ static VALUE rb_git_diff_tree_to_index(VALUE self, VALUE rb_other, VALUE rb_opti
690692
// the "old file" side of the diff.
691693
opts.flags ^= GIT_DIFF_REVERSE;
692694

693-
Data_Get_Struct(rb_other, git_tree, other_tree);
695+
TypedData_Get_Struct(rb_other, git_tree, &rugged_object_type, other_tree);
694696
error = git_diff_tree_to_index(&diff, repo, other_tree, index, &opts);
695697

696698
xfree(opts.pathspec.strings);

ext/rugged/rugged_note.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
extern VALUE rb_cRuggedRepo;
1111
extern VALUE rb_cRuggedObject;
1212

13+
extern const rb_data_type_t rugged_object_type;
14+
1315
static VALUE rugged_git_note_message(const git_note *note)
1416
{
1517
const char *message;
@@ -59,7 +61,7 @@ static VALUE rb_git_note_lookup(int argc, VALUE *argv, VALUE self)
5961
notes_ref = StringValueCStr(rb_notes_ref);
6062
}
6163

62-
Data_Get_Struct(self, git_object, object);
64+
TypedData_Get_Struct(self, git_object, &rugged_object_type, object);
6365

6466
owner = rugged_owner(self);
6567
Data_Get_Struct(owner, git_repository, repo);
@@ -124,7 +126,7 @@ static VALUE rb_git_note_create(VALUE self, VALUE rb_data)
124126

125127
Check_Type(rb_data, T_HASH);
126128

127-
Data_Get_Struct(self, git_object, target);
129+
TypedData_Get_Struct(self, git_object, &rugged_object_type, target);
128130

129131
owner = rugged_owner(self);
130132
Data_Get_Struct(owner, git_repository, repo);
@@ -207,7 +209,7 @@ static VALUE rb_git_note_remove(int argc, VALUE *argv, VALUE self)
207209
VALUE rb_committer = Qnil;
208210
VALUE owner;
209211

210-
Data_Get_Struct(self, git_object, target);
212+
TypedData_Get_Struct(self, git_object, &rugged_object_type, target);
211213

212214
owner = rugged_owner(self);
213215
Data_Get_Struct(owner, git_repository, repo);

0 commit comments

Comments
 (0)