From 436814572d435f6de4f3b390f07d0124fc4a7105 Mon Sep 17 00:00:00 2001 From: Joseph Sutton Date: Mon, 20 Nov 2023 10:03:59 +1300 Subject: [PATCH] pidl: Add a helper function to determine whether a type is a string type Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- pidl/lib/Parse/Pidl/NDR.pm | 2 +- pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm | 4 ++-- pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm | 8 ++++---- pidl/lib/Parse/Pidl/Typelist.pm | 8 ++++++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/pidl/lib/Parse/Pidl/NDR.pm b/pidl/lib/Parse/Pidl/NDR.pm index 1f95cdfd739..259950959bd 100644 --- a/pidl/lib/Parse/Pidl/NDR.pm +++ b/pidl/lib/Parse/Pidl/NDR.pm @@ -608,7 +608,7 @@ sub ParseStruct($$$) $surrounding = $e; } - if (defined $e->{TYPE} && $e->{TYPE} eq "string" + if (defined $e->{TYPE} && Parse::Pidl::Typelist::is_string_type($e->{TYPE}) && property_matches($e, "flag", ".*LIBNDR_FLAG_STR_CONFORMANT.*")) { $surrounding = $struct->{ELEMENTS}[-1]; } diff --git a/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm b/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm index 58ec389a9f3..84e2bebbb89 100644 --- a/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm +++ b/pidl/lib/Parse/Pidl/Samba4/NDR/Client.pm @@ -763,8 +763,8 @@ sub ParseFunction($$$) # TODO: make this fatal at NDR level if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { if ($e->{LEVELS}[1]->{TYPE} eq "DATA" and - $e->{LEVELS}[1]->{DATA_TYPE} eq "string") { - $reason = "is a pointer to type 'string'"; + Parse::Pidl::Typelist::is_string_type($e->{LEVELS}[1]->{DATA_TYPE})) { + $reason = "is a pointer to a string type"; } elsif ($e->{LEVELS}[1]->{TYPE} eq "ARRAY" and $e->{LEVELS}[1]->{IS_ZERO_TERMINATED}) { next; diff --git a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm index 799b467bc28..859da0a914f 100644 --- a/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm +++ b/pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm @@ -1119,7 +1119,7 @@ sub ParseMemCtxPullFlags($$$$) my $nl = GetNextLevel($e, $l); return undef if ($nl->{TYPE} eq "PIPE"); return undef if ($nl->{TYPE} eq "ARRAY"); - return undef if (($nl->{TYPE} eq "DATA") and ($nl->{DATA_TYPE} eq "string")); + return undef if (($nl->{TYPE} eq "DATA") and (Parse::Pidl::Typelist::is_string_type($nl->{DATA_TYPE}))); if ($l->{LEVEL} eq "TOP") { $mem_flags = "LIBNDR_FLAG_REF_ALLOC"; @@ -1358,7 +1358,7 @@ sub ParsePtrPull($$$$$) my $nl = GetNextLevel($e, $l); my $next_is_array = ($nl->{TYPE} eq "ARRAY"); my $next_is_string = (($nl->{TYPE} eq "DATA") and - ($nl->{DATA_TYPE} eq "string")); + (Parse::Pidl::Typelist::is_string_type($nl->{DATA_TYPE}))); if ($l->{POINTER_TYPE} eq "ref" and $l->{LEVEL} eq "TOP") { @@ -2644,7 +2644,7 @@ sub ParseFunctionPull($$) next unless ($e->{LEVELS}[0]->{TYPE} eq "POINTER" and $e->{LEVELS}[0]->{POINTER_TYPE} eq "ref"); next if (($e->{LEVELS}[1]->{TYPE} eq "DATA") and - ($e->{LEVELS}[1]->{DATA_TYPE} eq "string")); + (Parse::Pidl::Typelist::is_string_type($e->{LEVELS}[1]->{DATA_TYPE}))); next if ($e->{LEVELS}[1]->{TYPE} eq "PIPE"); next if (($e->{LEVELS}[1]->{TYPE} eq "ARRAY") and $e->{LEVELS}[1]->{IS_ZERO_TERMINATED}); @@ -2696,7 +2696,7 @@ sub ParseFunctionPull($$) next unless ($e->{LEVELS}[0]->{TYPE} eq "POINTER" and $e->{LEVELS}[0]->{POINTER_TYPE} eq "ref"); next if (($e->{LEVELS}[1]->{TYPE} eq "DATA") and - ($e->{LEVELS}[1]->{DATA_TYPE} eq "string")); + (Parse::Pidl::Typelist::is_string_type($e->{LEVELS}[1]->{DATA_TYPE}))); next if ($e->{LEVELS}[1]->{TYPE} eq "PIPE"); next if ($e->{LEVELS}[1]->{TYPE} eq "ARRAY"); diff --git a/pidl/lib/Parse/Pidl/Typelist.pm b/pidl/lib/Parse/Pidl/Typelist.pm index f3cb6021847..a0e92a49cf7 100644 --- a/pidl/lib/Parse/Pidl/Typelist.pm +++ b/pidl/lib/Parse/Pidl/Typelist.pm @@ -10,6 +10,7 @@ require Exporter; @EXPORT_OK = qw(hasType getType resolveType mapTypeName mapTypeSpecifier scalar_is_reference expandAlias mapScalarType addType typeIs is_signed is_scalar enum_type_fn bitmap_type_fn mapType typeHasBody is_fixed_size_scalar + is_string_type ); use vars qw($VERSION); $VERSION = '0.01'; @@ -230,6 +231,13 @@ sub scalar_is_reference($) return 0; } +sub is_string_type +{ + my ($t) = @_; + + return ($t eq "string"); +} + sub RegisterScalars() { foreach (keys %scalars) {