From 1f65f2366a9a580e314e6159ba1699cfa5dfbece Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Wed, 23 Dec 2020 22:07:29 +0900 Subject: [PATCH 1/4] Refactored parse_signature --- lib/fiddle/cparser.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/fiddle/cparser.rb b/lib/fiddle/cparser.rb index 8a269393..8a9a092b 100644 --- a/lib/fiddle/cparser.rb +++ b/lib/fiddle/cparser.rb @@ -108,16 +108,15 @@ def parse_struct_signature(signature, tymap=nil) # def parse_signature(signature, tymap=nil) tymap ||= {} - case compact(signature) - when /^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/ - func, args = $1, $2 - return [func, TYPE_VOIDP, split_arguments(args).collect {|arg| parse_ctype(arg, tymap)}] - when /^([\w\*\s]+[\*\s])(\w+)\((.*?)\);?$/ - ret, func, args = $1.strip, $2, $3 - return [func, parse_ctype(ret, tymap), split_arguments(args).collect {|arg| parse_ctype(arg, tymap)}] - else - raise(RuntimeError,"can't parse the function prototype: #{signature}") - end + ret, func, args = case compact(signature) + when /^(?:[\w*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/ + [TYPE_VOIDP, $1, $2] + when /^([\w*\s]+[*\s])(\w+)\((.*?)\);?$/ + [$1.strip, $2, $3] + else + raise("can't parse the function prototype: #{signature}") + end + [func, parse_ctype(ret, tymap), split_arguments(args).collect {|arg| parse_ctype(arg, tymap)}] end # Given a String of C type +ty+, returns the corresponding Fiddle constant. From 03ea0777760c27b5b8016e84139084d52fa4af75 Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Wed, 23 Dec 2020 23:09:04 +0900 Subject: [PATCH 2/4] Change ret to ctype --- lib/fiddle/cparser.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fiddle/cparser.rb b/lib/fiddle/cparser.rb index 8a9a092b..a8db71bc 100644 --- a/lib/fiddle/cparser.rb +++ b/lib/fiddle/cparser.rb @@ -108,15 +108,15 @@ def parse_struct_signature(signature, tymap=nil) # def parse_signature(signature, tymap=nil) tymap ||= {} - ret, func, args = case compact(signature) + ctype, func, args = case compact(signature) when /^(?:[\w*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/ [TYPE_VOIDP, $1, $2] when /^([\w*\s]+[*\s])(\w+)\((.*?)\);?$/ - [$1.strip, $2, $3] + [parse_ctype($1.strip), $2, $3] else raise("can't parse the function prototype: #{signature}") end - [func, parse_ctype(ret, tymap), split_arguments(args).collect {|arg| parse_ctype(arg, tymap)}] + [func, ctype, split_arguments(args).collect {|arg| parse_ctype(arg, tymap)}] end # Given a String of C type +ty+, returns the corresponding Fiddle constant. From e1abb46b5592b398cbd92045b1546fdf05c6d2c0 Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Wed, 23 Dec 2020 23:17:06 +0900 Subject: [PATCH 3/4] Fixed regular expression --- lib/fiddle/cparser.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fiddle/cparser.rb b/lib/fiddle/cparser.rb index a8db71bc..43e19370 100644 --- a/lib/fiddle/cparser.rb +++ b/lib/fiddle/cparser.rb @@ -109,9 +109,9 @@ def parse_struct_signature(signature, tymap=nil) def parse_signature(signature, tymap=nil) tymap ||= {} ctype, func, args = case compact(signature) - when /^(?:[\w*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/ + when /^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/ [TYPE_VOIDP, $1, $2] - when /^([\w*\s]+[*\s])(\w+)\((.*?)\);?$/ + when /^([\w\*\s]+[\*\s])(\w+)\((.*?)\);?$/ [parse_ctype($1.strip), $2, $3] else raise("can't parse the function prototype: #{signature}") From 1094a35d7c84885c1a9e60ecb7e64af4abeb20b9 Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Thu, 24 Dec 2020 00:36:31 +0900 Subject: [PATCH 4/4] Pass tymap to parse_ctype --- lib/fiddle/cparser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fiddle/cparser.rb b/lib/fiddle/cparser.rb index 43e19370..69373e89 100644 --- a/lib/fiddle/cparser.rb +++ b/lib/fiddle/cparser.rb @@ -112,7 +112,7 @@ def parse_signature(signature, tymap=nil) when /^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/ [TYPE_VOIDP, $1, $2] when /^([\w\*\s]+[\*\s])(\w+)\((.*?)\);?$/ - [parse_ctype($1.strip), $2, $3] + [parse_ctype($1.strip, tymap), $2, $3] else raise("can't parse the function prototype: #{signature}") end