[PATCH 10/14] rpcrt4: Write type format strings for Automation types.

Huw Davies huw at codeweavers.com
Mon Nov 5 04:12:33 CST 2018


On Sat, Nov 03, 2018 at 06:07:22PM -0500, Zebediah Figura wrote:
> Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
> ---
> 
> Automation types (BSTR, VARIANT, LPSAFEARRAY) are user-marshalled,
> which means that they require long format strings to represent the
> wire form of the data. Ideally this should be generated by widl at
> build time. However, we can't just create a dummy idl and retrieve the
> type format string from the generated proxy file, since we have no way
> of retrieving the length of the type format string (and we do need a
> way of copying it, since it must be contiguous with ours). Instead the
> solution I propose is to use a script to parse the type format string
> (and the other parts that we need) into a generated file, to be done
> at build time. Since we need widl to do this, and since it can be done
> very easily in shell script, I have embedded it as a Makefile rule.
> 
>  Makefile.in               |  1 +
>  dlls/rpcrt4/Makefile.in   | 21 ++++++++++++++++++++-
>  dlls/rpcrt4/ndr_typelib.c | 28 ++++++++++++++++++++++++++--
>  3 files changed, 47 insertions(+), 3 deletions(-)
> 
> diff --git a/Makefile.in b/Makefile.in
> index c1242afc01..25f535dc7f 100644
> --- a/Makefile.in
> +++ b/Makefile.in
> @@ -76,6 +76,7 @@ SUBDIRS         = @SUBDIRS@
>  RUNTESTFLAGS    = -q -P wine
>  MAKEDEP         = $(TOOLSDIR)/tools/makedep$(TOOLSEXT)
>  WRC             = $(TOOLSDIR)/tools/wrc/wrc$(TOOLSEXT)
> +WIDL            = $(TOOLSDIR)/tools/widl/widl$(TOOLSEXT)
>  PACKAGE_VERSION = @PACKAGE_VERSION@
>  SED_CMD         = LC_ALL=C sed -e 's, at bindir\@,$(bindir),g' -e 's, at dlldir\@,$(dlldir),g' -e 's, at srcdir\@,$(srcdir),g' -e 's, at PACKAGE_STRING\@, at PACKAGE_STRING@,g' -e 's, at PACKAGE_VERSION\@, at PACKAGE_VERSION@,g'
>  LDRPATH_INSTALL = @LDRPATH_INSTALL@
> diff --git a/dlls/rpcrt4/Makefile.in b/dlls/rpcrt4/Makefile.in
> index ad67edf92e..aa80c2e7c7 100644
> --- a/dlls/rpcrt4/Makefile.in
> +++ b/dlls/rpcrt4/Makefile.in
> @@ -2,7 +2,7 @@ EXTRADEFS = -D_RPCRT4_ -DMSWMSG
>  MODULE    = rpcrt4.dll
>  IMPORTLIB = rpcrt4
>  IMPORTS   = uuid advapi32
> -DELAYIMPORTS = iphlpapi wininet secur32 user32 ws2_32
> +DELAYIMPORTS = iphlpapi wininet secur32 user32 ws2_32 oleaut32
>  
>  C_SRCS = \
>  	cproxy.c \
> @@ -28,3 +28,22 @@ C_SRCS = \
>  RC_SRCS = version.rc
>  
>  IDL_SRCS = epm.idl
> +
> +EXTRA_OBJS = ndr_typelib_generated.o
> +
> +ndr_typelib_generated.c: $(WIDL)
> +	echo > ndr_typelib_generated.c '/* Automatically generated from Makefile.in, do not edit */' && \
> +	echo >> ndr_typelib_generated.c '#include "oaidl.h"' && \
> +	echo >> ndr_typelib_generated.c '#include "rpcproxy.h"' && \
> +	echo > ndr_typelib_generated.idl 'import "oaidl.idl"; [object] interface dummy {void dummy(BSTR a, IUnknown *b, IDispatch *c, VARIANT d, LPSAFEARRAY e); }' && \
> +	$(WIDL) $(WIDLFLAGS) -I $(top_srcdir)/include -p -o ndr_typelib_generated_p.c ndr_typelib_generated.idl && \
> +	echo >> ndr_typelib_generated.c 'const unsigned char oleaut_tfs[] = {' && \
> +	awk '/__MIDL_TypeFormatString =/,/};/' ndr_typelib_generated_p.c | head -n -2 | tail -n +5 >> ndr_typelib_generated.c && \
> +	echo >> ndr_typelib_generated.c '};' && \
> +	sed -n -e 's/#define TYPE_FORMAT_STRING_SIZE \([0-9]\+\)/const size_t oleaut_tfs_size = \1;/p' ndr_typelib_generated_p.c >> ndr_typelib_generated.c && \
> +	echo >> ndr_typelib_generated.c 'const unsigned short oleaut_offsets[] = {' && \
> +	sed -n -e 's/.*&__MIDL_TypeFormatString.Format\[\([0-9]\+\)\].*/    \1,/p' ndr_typelib_generated_p.c | head -n 5 >> ndr_typelib_generated.c && \
> +	echo >> ndr_typelib_generated.c '};' && \
> +	echo >> ndr_typelib_generated.c 'const USER_MARSHAL_ROUTINE_QUADRUPLE oleaut_user_marshal[] = ' && \
> +	awk '/UserMarshalRoutines\[\] =/,/};/' ndr_typelib_generated_p.c | tail -n +2 >> ndr_typelib_generated.c && \
> +	rm ndr_typelib_generated_p.c ndr_typelib_generated.idl

Did you consider adding a magic option to widl that would generate
this table?  IMHO, that would be much cleaner than this hack.

FWIW, "head -n -num" isn't supported by macOS's native head.

Huw.



More information about the wine-devel mailing list