You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/02/23 14:41:30 UTC
[lucy-commits] svn commit: r1073740 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs
lib/Clownfish/Method.pm src/CFCMethod.c src/CFCMethod.h
Author: marvin
Date: Wed Feb 23 13:41:29 2011
New Revision: 1073740
URL: http://svn.apache.org/viewvc?rev=1073740&view=rev
Log:
Port some CFCMethod symbol generation routines from Perl to C.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm
incubator/lucy/trunk/clownfish/src/CFCMethod.c
incubator/lucy/trunk/clownfish/src/CFCMethod.h
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1073740&r1=1073739&r2=1073740&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Wed Feb 23 13:41:29 2011
@@ -577,6 +577,40 @@ DESTROY(self)
PPCODE:
CFCMethod_destroy(self);
+SV*
+_various_method_syms(self, invoker)
+ CFCMethod *self;
+ const char *invoker;
+ALIAS:
+ short_method_sym = 1
+ full_method_sym = 2
+ full_offset_sym = 3
+CODE:
+ size_t size = 0;
+ switch(ix) {
+ case 1: size = CFCMethod_short_method_sym(self, invoker, NULL, 0);
+ break;
+ case 2: size = CFCMethod_full_method_sym(self, invoker, NULL, 0);
+ break;
+ case 3: size = CFCMethod_full_offset_sym(self, invoker, NULL, 0);
+ break;
+ default: croak("Unexpected ix: %d", ix);
+ }
+ RETVAL = newSV(size);
+ SvPOK_on(RETVAL);
+ char *buf = SvPVX(RETVAL);
+ switch(ix) {
+ case 1: CFCMethod_short_method_sym(self, invoker, buf, size);
+ break;
+ case 2: CFCMethod_full_method_sym(self, invoker, buf, size);
+ break;
+ case 3: CFCMethod_full_offset_sym(self, invoker, buf, size);
+ break;
+ default: croak("Unexpected ix: %d", ix);
+ }
+ SvCUR_set(RETVAL, strlen(buf));
+OUTPUT: RETVAL
+
void
_set_or_get(self, ...)
CFCMethod *self;
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm?rev=1073740&r1=1073739&r2=1073740&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm Wed Feb 23 13:41:29 2011
@@ -73,24 +73,6 @@ sub new {
return $self;
}
-sub short_method_sym {
- my ( $self, $invoker ) = @_;
- confess("Missing invoker") unless $invoker;
- return $invoker . '_' . $self->get_macro_sym;
-}
-
-sub full_method_sym {
- my ( $self, $invoker ) = @_;
- return $self->get_Prefix . $self->short_method_sym($invoker);
-}
-
-# The name of the variable which stores the method's vtable offset.
-sub full_offset_sym {
- my ( $self, $invoker ) = @_;
- confess("Missing invoker") unless $invoker;
- return $self->full_method_sym($invoker) . '_OFFSET';
-}
-
sub override {
my ( $self, $orig ) = @_;
Modified: incubator/lucy/trunk/clownfish/src/CFCMethod.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCMethod.c?rev=1073740&r1=1073739&r2=1073740&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCMethod.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCMethod.c Wed Feb 23 13:41:29 2011
@@ -107,6 +107,48 @@ CFCMethod_destroy(CFCMethod *self)
CFCFunction_destroy((CFCFunction*)self);
}
+size_t
+CFCMethod_short_method_sym(CFCMethod *self, const char *invoker, char *buf,
+ size_t buf_size)
+{
+ CFCUTIL_NULL_CHECK(invoker);
+ size_t needed = strlen(invoker) + 1 + strlen(self->macro_sym) + 1;
+ if (buf_size >= needed) {
+ int check = sprintf(buf, "%s_%s", invoker, self->macro_sym);
+ if (check < 0) { croak("sprintf failed"); }
+ }
+ return needed;
+}
+
+size_t
+CFCMethod_full_method_sym(CFCMethod *self, const char *invoker, char *buf,
+ size_t buf_size)
+{
+ CFCUTIL_NULL_CHECK(invoker);
+ const char *Prefix = CFCSymbol_get_Prefix((CFCSymbol*)self);
+ size_t needed = strlen(Prefix) + strlen(invoker) + 1
+ + strlen(self->macro_sym) + 1;
+ if (buf_size >= needed) {
+ int check = sprintf(buf, "%s%s_%s", Prefix, invoker, self->macro_sym);
+ if (check < 0) { croak("sprintf failed"); }
+ }
+ return needed;
+}
+
+size_t
+CFCMethod_full_offset_sym(CFCMethod *self, const char *invoker, char *buf,
+ size_t buf_size)
+{
+ CFCUTIL_NULL_CHECK(invoker);
+ size_t needed = CFCMethod_full_method_sym(self, invoker, NULL, 0)
+ + strlen("_OFFSET");
+ if (buf_size >= needed) {
+ CFCMethod_full_method_sym(self, invoker, buf, buf_size);
+ strcat(buf, "_OFFSET");
+ }
+ return needed;
+}
+
const char*
CFCMethod_get_macro_sym(CFCMethod *self)
{
Modified: incubator/lucy/trunk/clownfish/src/CFCMethod.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCMethod.h?rev=1073740&r1=1073739&r2=1073740&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCMethod.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCMethod.h Wed Feb 23 13:41:29 2011
@@ -42,6 +42,27 @@ CFCMethod_init(CFCMethod *self, struct C
void
CFCMethod_destroy(CFCMethod *self);
+/**
+ * @return the number of bytes which the symbol would occupy.
+ */
+size_t
+CFCMethod_short_method_sym(CFCMethod *self, const char *invoker, char *buf,
+ size_t buf_size);
+
+/**
+ * @return the number of bytes which the symbol would occupy.
+ */
+size_t
+CFCMethod_full_method_sym(CFCMethod *self, const char *invoker, char *buf,
+ size_t buf_size);
+
+/**
+ * @return the number of bytes which the symbol would occupy.
+ */
+size_t
+CFCMethod_full_offset_sym(CFCMethod *self, const char *invoker, char *buf,
+ size_t buf_size);
+
const char*
CFCMethod_get_macro_sym(CFCMethod *self);