Revision: 69126
          http://sourceforge.net/p/brlcad/code/69126
Author:   starseeker
Date:     2016-10-19 00:50:39 +0000 (Wed, 19 Oct 2016)
Log Message:
-----------
Untested as yet, but attempt to disable a too aggressive check by MSVC that 
prevents close operations from working on already closed files.  The cleanup 
function in libbu is *designed* to ensure that temp files are closed, and as a 
consequence is very likely to be doing redundant close operations if the users 
already cleaned up.  Approach identifed by Sean.

Modified Paths:
--------------
    brlcad/trunk/src/libbu/temp.c

Modified: brlcad/trunk/src/libbu/temp.c
===================================================================
--- brlcad/trunk/src/libbu/temp.c       2016-10-19 00:41:17 UTC (rev 69125)
+++ brlcad/trunk/src/libbu/temp.c       2016-10-19 00:50:39 UTC (rev 69126)
@@ -39,7 +39,6 @@
 
 #define _TF_FAIL "WARNING: Unable to create a temporary file\n"
 
-
 /* c99 doesn't declare these */
 #if !defined(_WIN32) || defined(__CYGWIN__)
 #  if !defined(__cplusplus)
@@ -57,15 +56,35 @@
 static int temp_files = 0;
 static struct temp_file_list *TF = NULL;
 
+/* Get Windows to shut up about trying to close an already closed file -
+ * the libbu temp_close_files routine is designed to make sure that any
+ * files the user may not have closed get closed.  The way the MSVC
+ * assertion was working, it would *preclude* the user from using close
+ * on temp files. Disable the parameter handler for just this function
+ * to avoid the issue. */
+#if defined(HAVE_WINDOWS_H)
+static void disable_duplicate_close_check(const wchar_t* UNUSED(expression),
+       const wchar_t* UNUSED(function),
+       const wchar_t* UNUSED(file),
+       unsigned int UNUSED(line),
+       uintptr_t UNUSED(pReserved)) {}
+#endif
 
 HIDDEN void
 temp_close_files(void)
 {
+#if defined(HAVE_WINDOWS_H)
+    _invalid_parameter_handler stdhandler;
+#endif
     struct temp_file_list *popped;
     if (!TF) {
        return;
     }
 
+#if defined(HAVE_WINDOWS_H)
+    stdhandler = _set_invalid_parameter_handler(disable_duplicate_close_check);
+#endif 
+
     /* close all files, free their nodes, and unlink */
     while (BU_LIST_WHILE(popped, temp_file_list, &(TF->l))) {
        if (!popped)
@@ -98,6 +117,12 @@
        bu_vls_free(&TF->fn);
     }
     BU_PUT(TF, struct temp_file_list);
+
+#if defined(HAVE_WINDOWS_H)
+    /* Now that we're done, restore default behavior */
+    (void)_set_invalid_parameter_handler(stdhandler);
+#endif 
+
 }
 
 
@@ -175,7 +200,6 @@
 extern int mkstemp(char *);
 #endif
 
-
 FILE *
 bu_temp_file(char *filepath, size_t len)
 {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to