Skip to content

Commit 0c8a467

Browse files
committed
Pass name in to aggregator factory method
We can determine the name of the aggregate function in Ruby, so let's do that.
1 parent 99e8dd3 commit 0c8a467

4 files changed

Lines changed: 6 additions & 12 deletions

File tree

ext/sqlite3/aggregator.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,11 @@ rb_sqlite3_aggregator_final(sqlite3_context * ctx)
203203
* parameter.
204204
*/
205205
VALUE
206-
rb_sqlite3_define_aggregator2(VALUE self, VALUE aggregator)
206+
rb_sqlite3_define_aggregator2(VALUE self, VALUE aggregator, VALUE ruby_name)
207207
{
208208
/* define_aggregator is added as a method to SQLite3::Database in database.c */
209209
sqlite3RubyPtr ctx;
210210
int arity, status;
211-
VALUE ruby_name;
212211
const char *name;
213212
VALUE aw;
214213
VALUE aggregators;
@@ -218,11 +217,6 @@ rb_sqlite3_define_aggregator2(VALUE self, VALUE aggregator)
218217
rb_raise(rb_path2class("SQLite3::Exception"), "cannot use a closed database");
219218
}
220219

221-
/* aggregator is typically a class and testing for :name or :new in class
222-
* is a bit pointless */
223-
224-
ruby_name = rb_funcall(aggregator, rb_intern("name"), 0);
225-
226220
if (rb_respond_to(aggregator, rb_intern("arity"))) {
227221
VALUE ruby_arity = rb_funcall(aggregator, rb_intern("arity"), 0);
228222
arity = NUM2INT(ruby_arity);

ext/sqlite3/aggregator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <sqlite3_ruby.h>
55

66
VALUE
7-
rb_sqlite3_define_aggregator2(VALUE self, VALUE aggregator);
7+
rb_sqlite3_define_aggregator2(VALUE self, VALUE aggregator, VALUE ruby_name);
88

99
void
1010
rb_sqlite3_aggregator_init(void);

ext/sqlite3/database.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ void init_sqlite3_database()
795795
rb_define_method(cSqlite3Database, "define_function_with_flags", define_function_with_flags, 2);
796796
/* public "define_aggregator" is now a shim around define_aggregator2
797797
* implemented in Ruby */
798-
rb_define_private_method(cSqlite3Database, "define_aggregator2", rb_sqlite3_define_aggregator2, 1);
798+
rb_define_private_method(cSqlite3Database, "define_aggregator2", rb_sqlite3_define_aggregator2, 2);
799799
rb_define_method(cSqlite3Database, "interrupt", interrupt, 0);
800800
rb_define_method(cSqlite3Database, "errmsg", errmsg, 0);
801801
rb_define_method(cSqlite3Database, "errcode", errcode_, 0);

lib/sqlite3/database.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def finalize
485485
@ctx.result
486486
end
487487
end
488-
define_aggregator2(proxy)
488+
define_aggregator2(proxy, name)
489489
end
490490

491491
# This is another approach to creating an aggregate function (see
@@ -558,7 +558,7 @@ def finalize
558558
@fp.result
559559
end
560560
end
561-
define_aggregator2(proxy)
561+
define_aggregator2(proxy, proxy.name)
562562
self
563563
end
564564

@@ -604,7 +604,7 @@ def finalize
604604
@klass.finalize
605605
end
606606
end
607-
define_aggregator2(proxy)
607+
define_aggregator2(proxy, name)
608608
self
609609
end
610610

0 commit comments

Comments
 (0)