lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] svn commit: r1056870 - in /incubator/lucy/trunk: clownfish/lib/Clownfish/Binding/Core/ clownfish/lib/Clownfish/Binding/Perl/ perl/lib/Lucy/Analysis/ perl/lib/Lucy/Index/ perl/lib/Lucy/Object/ perl/xs/
Date Sun, 09 Jan 2011 02:49:57 GMT
Author: marvin
Date: Sun Jan  9 02:49:57 2011
New Revision: 1056870

URL: http://svn.apache.org/viewvc?rev=1056870&view=rev
Log:
Have XSBind_allot_params() return a boolean and set Err_error on failure,
rather than throwing exceptions, improving the stack trace.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Aliases.pm
    incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Constructor.pm
    incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm
    incubator/lucy/trunk/perl/lib/Lucy/Analysis/Inversion.pm
    incubator/lucy/trunk/perl/lib/Lucy/Analysis/Token.pm
    incubator/lucy/trunk/perl/lib/Lucy/Index/Indexer.pm
    incubator/lucy/trunk/perl/lib/Lucy/Index/SortCache.pm
    incubator/lucy/trunk/perl/lib/Lucy/Object/I32Array.pm
    incubator/lucy/trunk/perl/xs/XSBind.c
    incubator/lucy/trunk/perl/xs/XSBind.h

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Aliases.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Aliases.pm?rev=1056870&r1=1056869&r2=1056870&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Aliases.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Aliases.pm Sun Jan  9 02:49:57
2011
@@ -63,7 +63,10 @@ our %aliases = (
     CFISH_FLOAT32   => 'LUCY_FLOAT32',
     CFISH_FLOAT64   => 'LUCY_FLOAT64',
 
-    CFISH_ERR => 'LUCY_ERR',
+    CFISH_ERR           => 'LUCY_ERR',
+    cfish_Err_new       => 'lucy_Err_new',
+    cfish_Err_set_error => 'lucy_Err_set_error',
+    cfish_Err_get_error => 'lucy_Err_get_error',
 
     cfish_Hash           => 'lucy_Hash',
     CFISH_HASH           => 'LUCY_HASH',

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Constructor.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Constructor.pm?rev=1056870&r1=1056869&r2=1056870&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Constructor.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Constructor.pm Sun Jan  9 02:49:57
2011
@@ -66,8 +66,8 @@ sub xsub_def {
     my $params_hash_name = $self->perl_name . "_PARAMS";
     my @var_assignments;
     my @refcount_mods;
-    my $allot_params
-        = qq|XSBind_allot_params( &(ST(0)), 1, items, "$params_hash_name",\n|;
+    my $allot_params = qq|chy_bool_t args_ok = XSBind_allot_params(\n|
+        . qq|            &(ST(0)), 1, items, "$params_hash_name",\n|;
 
     # Iterate over args in param list.
     for ( my $i = 1; $i <= $#$arg_vars; $i++ ) {
@@ -106,7 +106,7 @@ sub xsub_def {
             push @refcount_mods, "if ($name) { LUCY_INCREF($name); }";
         }
     }
-    $allot_params .= "            NULL);\n";
+    $allot_params .= "            NULL);";
 
     # Last, so that earlier exceptions while fetching params don't trigger bad
     # DESTROY.
@@ -116,9 +116,8 @@ sub xsub_def {
         qq|self = ($self_type)XSBind_new_blank_obj( ST(0) );|;
 
     # Bundle up variable assignment statments.
-    my $var_assignments
-        = join( "\n        ", $allot_params, @var_assignments );
-    my $refcount_mods = join( "\n        ", @refcount_mods );
+    my $var_assignments = join( "\n        ", @var_assignments );
+    my $refcount_mods   = join( "\n        ", @refcount_mods );
 
     return <<END_STUFF;
 XS($c_name);
@@ -131,6 +130,10 @@ XS($c_name)
     SP -= items;
     {
         $var_declarations
+        $allot_params
+        if (!args_ok) {
+            CFISH_RETHROW(LUCY_INCREF(cfish_Err_get_error()));
+        }
         $var_assignments
         $refcount_mods
         retval = $func_sym($name_list);

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm?rev=1056870&r1=1056869&r2=1056870&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm Sun Jan  9 02:49:57
2011
@@ -208,8 +208,8 @@ sub _xsub_def_labeled_params {
     my $self_assignment
         = _self_assign_statement( $self_type, $self->{method}->micro_sym );
     my @var_assignments;
-    my $allot_params
-        = qq|XSBind_allot_params( &(ST(0)), 1, items, "$params_hash_name", |;
+    my $allot_params = qq|chy_bool_t args_ok = XSBind_allot_params(\n|
+        . qq|            &(ST(0)), 1, items, "$params_hash_name",\n|;
 
     # Iterate over args in param list.
     for ( my $i = 1; $i <= $#$arg_vars; $i++ ) {
@@ -243,9 +243,9 @@ sub _xsub_def_labeled_params {
             push @var_assignments, $assignment;
         }
     }
-    $allot_params .= " NULL);\n";
-    my $var_assignments = join( "\n        ",
-        $self_assignment, $allot_params, @var_assignments, );
+    $allot_params .= "            NULL);";
+    my $var_assignments
+        = join( "\n        ", $self_assignment, @var_assignments, );
 
     return <<END_STUFF;
 XS($c_name);
@@ -259,6 +259,10 @@ XS($c_name)
     {
         /* Extract vars from Perl stack. */
         $var_declarations
+        $allot_params
+        if (!args_ok) {
+            CFISH_RETHROW(LUCY_INCREF(cfish_Err_get_error()));
+        }
         $var_assignments
 
         /* Execute */

Modified: incubator/lucy/trunk/perl/lib/Lucy/Analysis/Inversion.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/lib/Lucy/Analysis/Inversion.pm?rev=1056870&r1=1056869&r2=1056870&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/lib/Lucy/Analysis/Inversion.pm (original)
+++ incubator/lucy/trunk/perl/lib/Lucy/Analysis/Inversion.pm Sun Jan  9 02:49:57 2011
@@ -33,10 +33,13 @@ CODE:
     // parse params, only if there's more than one arg 
     if (items > 1) {
         SV *text_sv = NULL;
-        XSBind_allot_params( &(ST(0)), 1, items, 
-            "Lucy::Analysis::Inversion::new_PARAMS",
+        chy_bool_t args_ok = XSBind_allot_params(
+            &(ST(0)), 1, items, "Lucy::Analysis::Inversion::new_PARAMS",
             &text_sv, "text", 4,
             NULL);
+        if (!args_ok) {
+            CFISH_RETHROW(LUCY_INCREF(cfish_Err_get_error()));
+        }
         if (XSBind_sv_defined(text_sv)) {
             STRLEN len;
             char *text = SvPVutf8(text_sv, len);

Modified: incubator/lucy/trunk/perl/lib/Lucy/Analysis/Token.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/lib/Lucy/Analysis/Token.pm?rev=1056870&r1=1056869&r2=1056870&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/lib/Lucy/Analysis/Token.pm (original)
+++ incubator/lucy/trunk/perl/lib/Lucy/Analysis/Token.pm Sun Jan  9 02:49:57 2011
@@ -36,14 +36,17 @@ CODE:
     SV *pos_inc_sv      = NULL;
     SV *boost_sv        = NULL;
 
-    XSBind_allot_params( &(ST(0)), 1, items, 
-        "Lucy::Analysis::Token::new_PARAMS",
+    chy_bool_t args_ok = XSBind_allot_params(
+        &(ST(0)), 1, items, "Lucy::Analysis::Token::new_PARAMS",
         &text_sv, "text", 4,
         &start_offset_sv, "start_offset", 12, 
         &end_offset_sv, "end_offset", 10, 
         &pos_inc_sv, "pos_inc", 7, 
         &boost_sv, "boost", 5, 
         NULL);
+    if (!args_ok) {
+        CFISH_RETHROW(LUCY_INCREF(cfish_Err_get_error()));
+    }
 
     if (!XSBind_sv_defined(text_sv)) { 
         THROW(LUCY_ERR, "Missing required param 'text'"); 

Modified: incubator/lucy/trunk/perl/lib/Lucy/Index/Indexer.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/lib/Lucy/Index/Indexer.pm?rev=1056870&r1=1056869&r2=1056870&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/lib/Lucy/Index/Indexer.pm (original)
+++ incubator/lucy/trunk/perl/lib/Lucy/Index/Indexer.pm Sun Jan  9 02:49:57 2011
@@ -53,9 +53,14 @@ PPCODE:
     }
     else if (items > 2) {
         SV* boost_sv = NULL; 
-        XSBind_allot_params( &(ST(0)), 1, items, 
-            "Lucy::Index::Indexer::add_doc_PARAMS", &doc_sv, "doc", 3,
-            &boost_sv, "boost", 5, NULL);
+        chy_bool_t args_ok = XSBind_allot_params(
+            &(ST(0)), 1, items, "Lucy::Index::Indexer::add_doc_PARAMS", 
+            &doc_sv, "doc", 3,
+            &boost_sv, "boost", 5, 
+            NULL);
+        if (!args_ok) {
+            CFISH_RETHROW(LUCY_INCREF(cfish_Err_get_error()));
+        }
         if (boost_sv) {
             boost = (float)SvNV(boost_sv);
         }

Modified: incubator/lucy/trunk/perl/lib/Lucy/Index/SortCache.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/lib/Lucy/Index/SortCache.pm?rev=1056870&r1=1056869&r2=1056870&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/lib/Lucy/Index/SortCache.pm (original)
+++ incubator/lucy/trunk/perl/lib/Lucy/Index/SortCache.pm Sun Jan  9 02:49:57 2011
@@ -33,10 +33,13 @@ CODE:
     SV *ord_sv = NULL;
     int32_t ord = 0;
 
-    XSBind_allot_params( &(ST(0)), 1, items, 
-        "Lucy::Index::SortCache::value_PARAMS",
+    chy_bool_t args_ok = XSBind_allot_params(
+        &(ST(0)), 1, items, "Lucy::Index::SortCache::value_PARAMS",
         &ord_sv, "ord", 3, 
         NULL);
+    if (!args_ok) {
+        CFISH_RETHROW(LUCY_INCREF(cfish_Err_get_error()));
+    }
     if (ord_sv) { ord = SvIV(ord_sv); }
     else { THROW(LUCY_ERR, "Missing required param 'ord'"); }
 

Modified: incubator/lucy/trunk/perl/lib/Lucy/Object/I32Array.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/lib/Lucy/Object/I32Array.pm?rev=1056870&r1=1056869&r2=1056870&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/lib/Lucy/Object/I32Array.pm (original)
+++ incubator/lucy/trunk/perl/lib/Lucy/Object/I32Array.pm Sun Jan  9 02:49:57 2011
@@ -34,10 +34,13 @@ CODE:
     AV *ints_av = NULL;
     lucy_I32Array *self = NULL;
 
-    XSBind_allot_params( &(ST(0)), 1, items, 
-        "Lucy::Object::I32Array::new_PARAMS",
+    chy_bool_t args_ok = XSBind_allot_params(
+        &(ST(0)), 1, items, "Lucy::Object::I32Array::new_PARAMS",
         &ints_sv, "ints", 4,
         NULL);
+    if (!args_ok) {
+        CFISH_RETHROW(LUCY_INCREF(cfish_Err_get_error()));
+    }
     if (XSBind_sv_defined(ints_sv) && SvROK(ints_sv)) {
         ints_av = (AV*)SvRV(ints_sv);
     }

Modified: incubator/lucy/trunk/perl/xs/XSBind.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/xs/XSBind.c?rev=1056870&r1=1056869&r2=1056870&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/xs/XSBind.c (original)
+++ incubator/lucy/trunk/perl/xs/XSBind.c Sun Jan  9 02:49:57 2011
@@ -371,7 +371,7 @@ XSBind_enable_overload(void *pobj)
     SvAMAGIC_on(perl_obj);
 }
 
-void
+chy_bool_t
 XSBind_allot_params(SV** stack, int32_t start, int32_t num_stack_elems, 
                     char* params_hash_name, ...)
 {
@@ -383,13 +383,20 @@ XSBind_allot_params(SV** stack, int32_t 
 
     // Retrieve the params hash, which must be a package global. 
     if (params_hash == NULL) {
-        THROW(CFISH_ERR, "Can't find hash named %s", params_hash_name);
+        cfish_CharBuf *mess = CFISH_MAKE_MESS(
+            "Can't find hash named %s", params_hash_name);
+        cfish_Err_set_error(cfish_Err_new(mess));
+        return false;
     }
 
-    // Verify that our args come in pairs. Bail if there are no args. 
-    if (num_stack_elems == start) { return; }
+    // Verify that our args come in pairs. Return success if there are no
+    // args. 
+    if (num_stack_elems == start) { return true; }
     if ((num_stack_elems - start) % 2 != 0) {
-        THROW(CFISH_ERR, "Expecting hash-style params, got odd number of args");
+        cfish_CharBuf *mess = CFISH_MAKE_MESS(
+            "Expecting hash-style params, got odd number of args");
+        cfish_Err_set_error(cfish_Err_new(mess));
+        return false;
     }
 
     // Validate param names. 
@@ -398,7 +405,10 @@ XSBind_allot_params(SV** stack, int32_t 
         STRLEN key_len;
         const char *key = SvPV(key_sv, key_len); // assume ASCII labels 
         if (!hv_exists(params_hash, key, key_len)) {
-            THROW(CFISH_ERR, "Invalid parameter: '%s'", key);
+            cfish_CharBuf *mess = CFISH_MAKE_MESS(
+                "Invalid parameter: '%s'", key);
+            cfish_Err_set_error(cfish_Err_new(mess));
+            return false;
         }
     }
 
@@ -422,6 +432,8 @@ XSBind_allot_params(SV** stack, int32_t 
         }
     }
     va_end(args);
+
+    return true;
 }
 
 

Modified: incubator/lucy/trunk/perl/xs/XSBind.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/xs/XSBind.h?rev=1056870&r1=1056869&r2=1056870&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/xs/XSBind.h (original)
+++ incubator/lucy/trunk/perl/xs/XSBind.h Sun Jan  9 02:49:57 2011
@@ -164,8 +164,9 @@ cfish_XSBind_enable_overload(void *pobj)
  * (generally, the XS variable "items").
  * @param params_hash_name The name of a package global hash.  Any param
  * labels which are not present in this hash will trigger an exception.
+ * @return true on success, false on failure (sets Err_error).
  */
-void
+chy_bool_t
 cfish_XSBind_allot_params(SV** stack, int32_t start, 
                           int32_t num_stack_elems, 
                           char* params_hash_name, ...);



Mime
View raw message