pidl: Print actual type names in errors about unknown origins rather than 'HASH(0x...
[ira/wip.git] / pidl / lib / Parse / Pidl / Samba4 / Python.pm
index 81869b0da5c93d652c1bba734914557da95106b6..d27192d6ddb76e31399606ed3eec5c67c51604f3 100644 (file)
@@ -431,7 +431,7 @@ sub PythonFunctionUnpackOut($$$)
        } elsif (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "WERROR") {
                $self->handle_werror("r->out.result", "NULL", undef);
        } elsif (defined($fn->{RETURN_TYPE})) {
-               my $conv = $self->ConvertObjectToPythonData("r", $fn->{RETURN_TYPE}, "r->out.result");
+               my $conv = $self->ConvertObjectToPythonData("r", $fn->{RETURN_TYPE}, "r->out.result", $fn);
                if ($result_size > 1) {
                        $self->pidl("PyTuple_SetItem(result, $i, $conv);");
                } else {
@@ -815,11 +815,11 @@ sub assign($$$)
        }
 }
 
-sub ConvertObjectFromPythonData($$$$$$)
+sub ConvertObjectFromPythonData($$$$$$;$)
 {
-       my ($self, $mem_ctx, $cvar, $ctype, $target, $fail) = @_;
+       my ($self, $mem_ctx, $cvar, $ctype, $target, $fail, $location) = @_;
 
-       die("undef type for $cvar") unless(defined($ctype));
+       fatal($location, "undef type for $cvar") unless(defined($ctype));
 
        $ctype = resolveType($ctype);
 
@@ -839,7 +839,7 @@ sub ConvertObjectFromPythonData($$$$$$)
        if ($actual_ctype->{TYPE} eq "STRUCT" or $actual_ctype->{TYPE} eq "INTERFACE") {
                my $ctype_name = $self->use_type_variable($ctype);
                unless (defined ($ctype_name)) {
-                       error(undef, "Unable to determine origin of type " . mapTypeName($ctype));
+                       error($location, "Unable to determine origin of type `" . mapTypeName($ctype) . "'");
                        $self->assign($target, "NULL");
                        # FIXME:
                        return;
@@ -886,7 +886,7 @@ sub ConvertObjectFromPythonData($$$$$$)
                return;
        }
 
-       fatal($ctype, "unknown type $actual_ctype->{TYPE} for ".mapTypeName($ctype) . ": $cvar");
+       fatal($location, "unknown type `$actual_ctype->{TYPE}' for ".mapTypeName($ctype) . ": $cvar");
 
 }
 
@@ -946,7 +946,7 @@ sub ConvertObjectFromPythonLevel($$$$$$$$)
                if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE})) {
                        $var_name = get_pointer_to($var_name);
                }
-               $self->ConvertObjectFromPythonData($mem_ctx, $py_var, $l->{DATA_TYPE}, $var_name, $fail);
+               $self->ConvertObjectFromPythonData($mem_ctx, $py_var, $l->{DATA_TYPE}, $var_name, $fail, $e->{ORIGINAL});
        } elsif ($l->{TYPE} eq "SWITCH") {
                $var_name = get_pointer_to($var_name);
                my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e);
@@ -954,7 +954,7 @@ sub ConvertObjectFromPythonLevel($$$$$$$$)
        } elsif ($l->{TYPE} eq "SUBCONTEXT") {
                $self->ConvertObjectFromPythonLevel($env, $mem_ctx, $py_var, $e, GetNextLevel($e, $l), $var_name, $fail);
        } else {
-               die("unknown level type $l->{TYPE}");
+               fatal($e->{ORIGINAL}, "unknown level type $l->{TYPE}");
        }
 }
 
@@ -1003,9 +1003,9 @@ sub ConvertScalarToPython($$$)
        die("Unknown scalar type $ctypename");
 }
 
-sub ConvertObjectToPythonData($$$$$)
+sub ConvertObjectToPythonData($$$$$;$)
 {
-       my ($self, $mem_ctx, $ctype, $cvar) = @_;
+       my ($self, $mem_ctx, $ctype, $cvar, $location) = @_;
 
        die("undef type for $cvar") unless(defined($ctype));
 
@@ -1027,13 +1027,13 @@ sub ConvertObjectToPythonData($$$$$)
        } elsif ($actual_ctype->{TYPE} eq "STRUCT" or $actual_ctype->{TYPE} eq "INTERFACE") {
                my $ctype_name = $self->use_type_variable($ctype);
                unless (defined($ctype_name)) {
-                       error(undef, "Unable to determine origin of type " . mapTypeName($ctype));
+                       error($location, "Unable to determine origin of type `" . mapTypeName($ctype) . "'");
                        return "NULL"; # FIXME!
                }
                return "py_talloc_import_ex($ctype_name, $mem_ctx, $cvar)";
        }
 
-       fatal($ctype, "unknown type $actual_ctype->{TYPE} for ".mapTypeName($ctype) . ": $cvar");
+       fatal($location, "unknown type $actual_ctype->{TYPE} for ".mapTypeName($ctype) . ": $cvar");
 }
 
 sub fail_on_null($$$)
@@ -1113,12 +1113,12 @@ sub ConvertObjectToPythonLevel($$$$$$)
                if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE})) {
                        $var_name = get_pointer_to($var_name);
                }
-               my $conv = $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name);
+               my $conv = $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name, $e->{ORIGINAL});
                $self->pidl("$py_var = $conv;");
        } elsif ($l->{TYPE} eq "SUBCONTEXT") {
                $self->ConvertObjectToPythonLevel($mem_ctx, $env, $e, GetNextLevel($e, $l), $var_name, $py_var, $fail);
        } else {
-               die("Unknown level type $l->{TYPE} $var_name");
+               fatal($e->{ORIGINAL}, "Unknown level type $l->{TYPE} $var_name");
        }
 }
 
@@ -1223,7 +1223,7 @@ sub Parse($$$$$)
                } elsif ($cvar =~ /^".*"$/) {
                        $py_obj = "PyString_FromString($cvar)";
                } else {
-                       $py_obj = $self->ConvertObjectToPythonData("NULL", expandAlias($ctype), $cvar);
+                       $py_obj = $self->ConvertObjectToPythonData("NULL", expandAlias($ctype), $cvar, undef);
                }
 
                $self->pidl("PyModule_AddObject(m, \"$name\", $py_obj);");