rubydex 0.2.6 → 0.2.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.
@@ -7,6 +7,12 @@
7
7
  #include "signature.h"
8
8
  #include "ruby/internal/scan_args.h"
9
9
  #include "rustbindings.h"
10
+ #include "utils.h"
11
+
12
+ /*
13
+ * RDoc parser workaround for https://github.com/ruby/rdoc/issues/1744:
14
+ * mRubydex = rb_define_module("Rubydex")
15
+ */
10
16
 
11
17
  static VALUE mRubydex;
12
18
  static VALUE cInclude;
@@ -71,13 +77,15 @@ VALUE rdxi_definition_class_for_kind(DefinitionKind kind) {
71
77
  }
72
78
  }
73
79
 
74
- // Definition#location -> Rubydex::Location
80
+ /*
81
+ * call-seq:
82
+ * location -> Rubydex::Location
83
+ *
84
+ * Returns the source location for this definition.
85
+ */
75
86
  static VALUE rdxr_definition_location(VALUE self) {
76
87
  HandleData *data;
77
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
78
-
79
- void *graph;
80
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
88
+ void *graph = rdxi_graph_from_handle(self, &data);
81
89
 
82
90
  Location *loc = rdx_definition_location(graph, data->id);
83
91
  VALUE location = rdxi_build_location_value(loc);
@@ -86,13 +94,15 @@ static VALUE rdxr_definition_location(VALUE self) {
86
94
  return location;
87
95
  }
88
96
 
89
- // Definition#comments -> [Rubydex::Comment]
97
+ /*
98
+ * call-seq:
99
+ * comments -> Array[Rubydex::Comment]
100
+ *
101
+ * Returns the source comments associated with this definition.
102
+ */
90
103
  static VALUE rdxr_definition_comments(VALUE self) {
91
104
  HandleData *data;
92
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
93
-
94
- void *graph;
95
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
105
+ void *graph = rdxi_graph_from_handle(self, &data);
96
106
 
97
107
  CommentArray *arr = rdx_definition_comments(graph, data->id);
98
108
  if (arr == NULL || arr->len == 0) {
@@ -124,44 +134,44 @@ static VALUE rdxr_definition_comments(VALUE self) {
124
134
  return ary;
125
135
  }
126
136
 
127
- // Definition#name -> String
137
+ /*
138
+ * call-seq:
139
+ * name -> String?
140
+ *
141
+ * Returns the definition name.
142
+ */
128
143
  static VALUE rdxr_definition_name(VALUE self) {
129
144
  HandleData *data;
130
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
131
-
132
- void *graph;
133
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
145
+ void *graph = rdxi_graph_from_handle(self, &data);
134
146
 
135
147
  const char *name = rdx_definition_name(graph, data->id);
136
- if (name == NULL) {
137
- return Qnil;
138
- }
139
- VALUE str = rb_utf8_str_new_cstr(name);
140
- free_c_string(name);
141
- return str;
148
+ return rdxi_owned_c_string_to_ruby(name);
142
149
  }
143
150
 
144
- // Definition#deprecated? -> bool
151
+ /*
152
+ * call-seq:
153
+ * deprecated? -> bool
154
+ *
155
+ * Returns whether this definition is marked as deprecated.
156
+ */
145
157
  static VALUE rdxr_definition_deprecated(VALUE self) {
146
158
  HandleData *data;
147
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
148
-
149
- void *graph;
150
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
159
+ void *graph = rdxi_graph_from_handle(self, &data);
151
160
 
152
161
  bool deprecated = rdx_definition_is_deprecated(graph, data->id);
153
162
  return deprecated ? Qtrue : Qfalse;
154
163
  }
155
164
 
156
- // Definition#name_location -> Rubydex::Location or nil
157
- // For class, module, singleton class, and method definitions, returns the location of just the name
158
- // (e.g., "Bar" in "class Foo::Bar", or "foo" in "def foo"). For other definition types, returns nil.
165
+ /*
166
+ * call-seq:
167
+ * name_location -> Rubydex::Location?
168
+ *
169
+ * For class, module, singleton class, and method definitions, returns the location of just the name, such as "Bar" in
170
+ * "class Foo::Bar" or "foo" in "def foo". For other definition types, returns nil.
171
+ */
159
172
  static VALUE rdxr_definition_name_location(VALUE self) {
160
173
  HandleData *data;
161
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
162
-
163
- void *graph;
164
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
174
+ void *graph = rdxi_graph_from_handle(self, &data);
165
175
 
166
176
  Location *loc = rdx_definition_name_location(graph, data->id);
167
177
  if (loc == NULL) {
@@ -173,15 +183,15 @@ static VALUE rdxr_definition_name_location(VALUE self) {
173
183
  return location;
174
184
  }
175
185
 
176
- // Definition#declaration -> Rubydex::Declaration?
177
- // Returns the declaration this definition belongs to or nil when it cannot be located (for example, before
178
- // `Graph#resolve` has run).
186
+ /*
187
+ * call-seq:
188
+ * declaration -> Rubydex::Declaration?
189
+ *
190
+ * Returns the declaration this definition belongs to or nil when it cannot be located.
191
+ */
179
192
  static VALUE rdxr_definition_declaration(VALUE self) {
180
193
  HandleData *data;
181
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
182
-
183
- void *graph;
184
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
194
+ void *graph = rdxi_graph_from_handle(self, &data);
185
195
 
186
196
  const struct CDeclaration *decl = rdx_definition_declaration(graph, data->id);
187
197
  if (decl == NULL) {
@@ -203,14 +213,15 @@ static VALUE rdxi_build_definition(VALUE graph_obj, void *graph, uint64_t defini
203
213
  return rb_class_new_instance(2, argv, defn_class);
204
214
  }
205
215
 
206
- // Definition#lexical_owner -> Rubydex::Definition?
207
- // Returns the lexically enclosing definition, if any.
216
+ /*
217
+ * call-seq:
218
+ * lexical_owner -> Rubydex::Definition?
219
+ *
220
+ * Returns the lexically enclosing definition, if any.
221
+ */
208
222
  static VALUE rdxr_definition_lexical_owner(VALUE self) {
209
223
  HandleData *data;
210
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
211
-
212
- void *graph;
213
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
224
+ void *graph = rdxi_graph_from_handle(self, &data);
214
225
 
215
226
  const uint64_t *owner_id = rdx_definition_lexical_nesting_id(graph, data->id);
216
227
  if (owner_id == NULL) {
@@ -223,14 +234,15 @@ static VALUE rdxr_definition_lexical_owner(VALUE self) {
223
234
  return owner;
224
235
  }
225
236
 
226
- // Definition#lexical_nesting -> Array<Rubydex::Definition>
227
- // Returns the lexical nesting from the direct owner up to the root.
237
+ /*
238
+ * call-seq:
239
+ * lexical_nesting -> Array[Rubydex::Definition]
240
+ *
241
+ * Returns the lexical nesting from the direct owner up to the root.
242
+ */
228
243
  static VALUE rdxr_definition_lexical_nesting(VALUE self) {
229
244
  HandleData *data;
230
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
231
-
232
- void *graph;
233
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
245
+ void *graph = rdxi_graph_from_handle(self, &data);
234
246
 
235
247
  VALUE nesting = rb_ary_new();
236
248
  uint64_t definition_id = data->id;
@@ -258,13 +270,15 @@ static VALUE rdxi_build_constant_reference(VALUE graph_obj, const CConstantRefer
258
270
  return rb_class_new_instance(2, argv, ref_class);
259
271
  }
260
272
 
261
- // ClassDefinition#superclass -> ConstantReference?
273
+ /*
274
+ * call-seq:
275
+ * superclass -> Rubydex::ConstantReference?
276
+ *
277
+ * Returns the superclass constant reference, or nil if this class definition has no explicit superclass.
278
+ */
262
279
  static VALUE rdxr_class_definition_superclass(VALUE self) {
263
280
  HandleData *data;
264
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
265
-
266
- void *graph;
267
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
281
+ void *graph = rdxi_graph_from_handle(self, &data);
268
282
 
269
283
  const CConstantReference *ref = rdx_class_definition_superclass(graph, data->id);
270
284
  if (ref == NULL) {
@@ -289,13 +303,15 @@ static VALUE rdxi_mixin_class_for_kind(MixinKind kind) {
289
303
  }
290
304
  }
291
305
 
292
- // Definition#mixins -> [Rubydex::Mixin]
306
+ /*
307
+ * call-seq:
308
+ * mixins -> Array[Rubydex::Mixin]
309
+ *
310
+ * Returns mixins attached to this definition.
311
+ */
293
312
  static VALUE rdxr_definition_mixins(VALUE self) {
294
313
  HandleData *data;
295
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
296
-
297
- void *graph;
298
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
314
+ void *graph = rdxi_graph_from_handle(self, &data);
299
315
 
300
316
  MixinsIter *iter = rdx_definition_mixins(graph, data->id);
301
317
  if (iter == NULL) {
@@ -317,40 +333,44 @@ static VALUE rdxr_definition_mixins(VALUE self) {
317
333
  return ary;
318
334
  }
319
335
 
320
- // MethodDefinition#signatures -> [Rubydex::Signature]
336
+ /*
337
+ * call-seq:
338
+ * signatures -> Array[Rubydex::Signature]
339
+ *
340
+ * Returns signatures for this method definition.
341
+ */
321
342
  static VALUE rdxr_method_definition_signatures(VALUE self) {
322
343
  HandleData *data;
323
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
324
-
325
- void *graph;
326
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
344
+ void *graph = rdxi_graph_from_handle(self, &data);
327
345
 
328
346
  SignatureArray *arr = rdx_definition_signatures(graph, data->id);
329
347
  return rdxi_signatures_to_ruby(arr);
330
348
  }
331
349
 
332
- // MethodAliasDefinition#signatures -> [Rubydex::Signature]
350
+ /*
351
+ * call-seq:
352
+ * signatures -> Array[Rubydex::Signature]
353
+ *
354
+ * Returns signatures for this method alias definition.
355
+ */
333
356
  static VALUE rdxr_method_alias_definition_signatures(VALUE self) {
334
357
  HandleData *data;
335
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
336
-
337
- void *graph;
338
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
358
+ void *graph = rdxi_graph_from_handle(self, &data);
339
359
 
340
360
  SignatureArray *arr = rdx_method_alias_definition_signatures(graph, data->id);
341
361
  return rdxi_signatures_to_ruby(arr);
342
362
  }
343
363
 
344
- // MethodAliasDefinition#target -> Rubydex::Method?
345
- // Returns the resolved target method declaration by following the alias chain, or nil if the chain could not be
346
- // resolved (the target name doesn't exist on the owner, or the owner itself never resolved). Raises
347
- // Rubydex::AliasCycleError when the alias chain forms a cycle.
364
+ /*
365
+ * call-seq:
366
+ * target -> Rubydex::Method?
367
+ *
368
+ * Returns the resolved target method declaration by following the alias chain, or nil if the chain could not be
369
+ * resolved. Raises Rubydex::AliasCycleError when the alias chain forms a cycle.
370
+ */
348
371
  static VALUE rdxr_method_alias_definition_target(VALUE self) {
349
372
  HandleData *data;
350
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
351
-
352
- void *graph;
353
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
373
+ void *graph = rdxi_graph_from_handle(self, &data);
354
374
 
355
375
  CMethodAliasTargetResult result = rdx_method_alias_definition_target(graph, data->id);
356
376
 
@@ -1,6 +1,11 @@
1
1
  #include "diagnostic.h"
2
2
  #include "rustbindings.h"
3
3
 
4
+ /*
5
+ * RDoc parser workaround for https://github.com/ruby/rdoc/issues/1744:
6
+ * mRubydex = rb_define_module("Rubydex")
7
+ */
8
+
4
9
  VALUE cDiagnostic;
5
10
 
6
11
  void rdxi_initialize_diagnostic(VALUE mRubydex) { cDiagnostic = rb_define_class_under(mRubydex, "Diagnostic", rb_cObject); }
@@ -5,25 +5,25 @@
5
5
  #include "rustbindings.h"
6
6
  #include "utils.h"
7
7
 
8
+ /*
9
+ * RDoc parser workaround for https://github.com/ruby/rdoc/issues/1744:
10
+ * mRubydex = rb_define_module("Rubydex")
11
+ */
12
+
8
13
  VALUE cDocument;
9
14
 
10
- // Document#uri -> String
15
+ /*
16
+ * call-seq:
17
+ * uri -> String?
18
+ *
19
+ * Returns the document URI.
20
+ */
11
21
  static VALUE rdxr_document_uri(VALUE self) {
12
22
  HandleData *data;
13
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
14
-
15
- void *graph;
16
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
23
+ void *graph = rdxi_graph_from_handle(self, &data);
17
24
  const char *uri = rdx_document_uri(graph, data->id);
18
25
 
19
- if (uri == NULL) {
20
- return Qnil;
21
- }
22
-
23
- VALUE str = rb_utf8_str_new_cstr(uri);
24
- free_c_string(uri);
25
-
26
- return str;
26
+ return rdxi_owned_c_string_to_ruby(uri);
27
27
  }
28
28
 
29
29
  // Body function for rb_ensure in Document#definitions
@@ -56,10 +56,7 @@ static VALUE document_definitions_ensure(VALUE args) {
56
56
  // Size function for the Document#definitions enumerator
57
57
  static VALUE document_definitions_size(VALUE self, VALUE _args, VALUE _eobj) {
58
58
  HandleData *data;
59
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
60
-
61
- void *graph;
62
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
59
+ void *graph = rdxi_graph_from_handle(self, &data);
63
60
  struct DefinitionsIter *iter = rdx_document_definitions_iter_new(graph, data->id);
64
61
  size_t len = rdx_definitions_iter_len(iter);
65
62
  rdx_definitions_iter_free(iter);
@@ -67,18 +64,19 @@ static VALUE document_definitions_size(VALUE self, VALUE _args, VALUE _eobj) {
67
64
  return SIZET2NUM(len);
68
65
  }
69
66
 
70
- // Document#definitions: () -> Enumerator[Definition]
71
- // Returns an enumerator that yields all definitions for this document lazily
67
+ /*
68
+ * call-seq:
69
+ * definitions -> Enumerator[Rubydex::Definition]
70
+ *
71
+ * Returns an enumerator that yields all definitions for this document lazily.
72
+ */
72
73
  static VALUE rdxr_document_definitions(VALUE self) {
73
74
  if (!rb_block_given_p()) {
74
75
  return rb_enumeratorize_with_size(self, rb_str_new2("definitions"), 0, NULL, document_definitions_size);
75
76
  }
76
77
 
77
78
  HandleData *data;
78
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
79
-
80
- void *graph;
81
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
79
+ void *graph = rdxi_graph_from_handle(self, &data);
82
80
  void *iter = rdx_document_definitions_iter_new(graph, data->id);
83
81
  VALUE args = rb_ary_new_from_args(2, self, ULL2NUM((uintptr_t)iter));
84
82
  rb_ensure(document_definitions_yield, args, document_definitions_ensure, args);
@@ -89,10 +87,7 @@ static VALUE rdxr_document_definitions(VALUE self) {
89
87
  // Size function for the Document#method_references enumerator
90
88
  static VALUE document_method_references_size(VALUE self, VALUE _args, VALUE _eobj) {
91
89
  HandleData *data;
92
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
93
-
94
- void *graph;
95
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
90
+ void *graph = rdxi_graph_from_handle(self, &data);
96
91
  struct MethodReferencesIter *iter = rdx_document_method_references_iter_new(graph, data->id);
97
92
  size_t len = rdx_method_references_iter_len(iter);
98
93
  rdx_method_references_iter_free(iter);
@@ -109,10 +104,7 @@ static VALUE rdxr_document_method_references(VALUE self) {
109
104
  }
110
105
 
111
106
  HandleData *data;
112
- TypedData_Get_Struct(self, HandleData, &handle_type, data);
113
-
114
- void *graph;
115
- TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);
107
+ void *graph = rdxi_graph_from_handle(self, &data);
116
108
  void *iter = rdx_document_method_references_iter_new(graph, data->id);
117
109
  VALUE args = rb_ary_new_from_args(2, data->graph_obj, ULL2NUM((uintptr_t)iter));
118
110
  rb_ensure(rdxi_method_references_yield, args, rdxi_method_references_ensure, args);
@@ -78,7 +78,7 @@ cargo_command = if ENV["SANITIZER"]
78
78
  ENV["RUSTFLAGS"] = "-Zsanitizer=#{ENV["SANITIZER"]}"
79
79
  "cargo +nightly build -Zbuild-std #{cargo_args.join(" ")}".strip
80
80
  else
81
- "cargo build #{cargo_args.join(" ")}".strip
81
+ "cargo build --features rubydex/jemalloc_dylib #{cargo_args.join(" ")}".strip
82
82
  end
83
83
 
84
84
  lib_dir = gem_dir.join("lib").join("rubydex")