From 45feb55decb31602190b1157f36b0813e18f6385 Mon Sep 17 00:00:00 2001 From: James Zern Date: Tue, 21 Feb 2012 13:44:39 -0800 Subject: [PATCH] expose WebPFree function for DLL builds This allows managed code (e.g., C#) to free buffers returned by the API instead of relying on free(). Based on suggestion from Steven (grokys at googlemail dot com). Fixes issue #109. Change-Id: I94826a77f6f4cb6e331c454f994c964e2e448cae --- Makefile.vc | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Makefile.vc b/Makefile.vc index f5075bdf..6c12f6b4 100644 --- a/Makefile.vc +++ b/Makefile.vc @@ -82,6 +82,7 @@ STATICLIBBUILD = TRUE !ELSE IF "$(CFG)" == "debug-static" TARGET = $(LIB_NAME_DEBUG).lib CC = $(CCDEBUG) +RTLIB = $(RTLIBD) STATICLIBBUILD = TRUE !ELSE IF "$(CFG)" == "release-dynamic" TARGETDLL = $(LIB_NAME).dll @@ -92,6 +93,7 @@ DLLBUILD = TRUE TARGETDLL = $(LIB_NAME_DEBUG).dll TARGET = $(IMPLIB_NAME_DEBUG).lib CC = $(CCDEBUG) +RTLIB = $(RTLIBD) DLLBUILD = TRUE !ENDIF @@ -100,9 +102,11 @@ CC = $(CC) $(RTLIB) LNK = $(LNKLIB) /out:$(DIRLIB)\$(TARGET) CFGSET = TRUE !ELSE IF "$(DLLBUILD)" == "TRUE" +DLLC = webp_dll.c DLLINC = webp_dll.h CC = $(CC) /I$(DIROBJ) /FI$(DLLINC) $(RTLIB) /DWEBP_DLL LNK = $(LNKDLL) /out:$(DIRBIN)\$(TARGETDLL) /implib:$(DIRLIB)\$(TARGET) +X_OBJS = $(DIROBJ)\$(DLLC:.c=.obj) CFGSET = TRUE !ENDIF @@ -184,7 +188,7 @@ X_OBJS= \ $(DIROBJ)\utils\quant_levels.obj \ $(DIROBJ)\utils\tcoder.obj \ $(DIROBJ)\utils\thread.obj \ - $(RESOURCE) \ + $(X_OBJS) \ EXAMPLES_OBJS = \ $(DIROBJ)\examples\cwebp.obj \ @@ -211,9 +215,12 @@ $(DIRLIB)\$(TARGET): $(X_OBJS) $(X_OBJS): $(OUTPUT_DIRS) !IF "$(DLLBUILD)" == "TRUE" -$(X_OBJS): $(DIROBJ)\$(DLLINC) +$(X_OBJS): $(DIROBJ)\$(DLLINC) $(DIROBJ)\$(DLLC) + +{$(DIROBJ)}.c{$(DIROBJ)}.obj: + $(CC) $(CFLAGS) /Fo"$@" $< clean:: - @-erase /s $(DIROBJ)\$(DLLINC) 2> NUL + @-erase /s $(DIROBJ)\$(DLLC) $(DIROBJ)\$(DLLINC) 2> NUL !ENDIF $(EXAMPLES_OBJS): $(DIRLIB)\$(TARGET) @@ -228,6 +235,16 @@ $(DIROBJ)\$(DLLINC): @echo #define WEBP_EXTERN(type) __declspec(dllexport) type >> $@ @echo #endif /* WEBP_DLL_H_ */ >> $@ +# expose a WebPFree() function for use in managed code +$(DIROBJ)\$(DLLC): $(DIROBJ)\$(DLLINC) + @echo #include ^ > $@ + @echo #include "webp_dll.h" >> $@ + @echo // This function should be used in place of free() for memory >> $@ + @echo // returned by the WebP API. >> $@ + @echo WEBP_EXTERN(void) WebPFree(void* ptr) { >> $@ + @echo free(ptr); >> $@ + @echo } >> $@ + .SUFFIXES: .c .obj .res .exe {examples}.c{$(DIROBJ)\examples}.obj: $(CC) $(CFLAGS) /Fo"$@" $<