Hi All, I'm still actively researching this problem (reading R-ext manual), but I hoped that I might be able to get some additional insight from the list given that I'm fairly new at writing R extension code.
Problem: I have some fairly simple code (.Call interface) that makes a call to another shared library, which, in turn, calls routines in an HDF5 shared library. The good news is that everything works (the expected value is returned from the HDF5 call); the problem is that R segfaults when I unload the library. I initially suspected that the HDF5 function might be corrupting the stack/heap, however, if it is, it's not obvious to me. Upon the successful return from the function, R responds well, and a gc() call works without event (only when unloading do I see the problem). In addition, given that the function returns a single (double) value, I passed a much larger array in order to see whether the HDF routine might be writing off the end of the buffer; the pre-initialized buffer looked OK upon return. Interestingly, when I comment out the call to the HDF routine and manually return a double value, the problem disappears. So, something within that particular HDF function (other HDF functions work OK) is messing something up, which is only apparent at unload time. Any idea where I should be looking? The abort output and environment details follow (I don't seem to get a core dump). Please let me know if any other information might be helpful, and what I might try next. Thanks, -Jim --------------------------------------------------- > > detach(package:mniMincIO) Unloading shared library: mniMincIO. Library unload path is /Users/jnikelski/R_libs/2.9/mniMincIO now dyn.unload("/Users/jnikelski/R_libs/2.9/mniMincIO/libs/i386/mniMincIO.so") ... Unloading shared library mniMincIO in R_unload_mniMincIO *** caught segfault *** address 0xcfa5e0, cause 'memory not mapped' Traceback: 1: dyn.unload(file) 2: library.dynam.unload(libName, file.ext = ".so", verbose = TRUE, libpath = libpath) 3: .Last.lib(libpath) 4: doTryCatch(return(expr), name, parentenv, handler) 5: tryCatchOne(expr, names, parentenv, handlers[[1L]]) 6: tryCatchList(expr, classes, parentenv, handlers) 7: tryCatch(expr, error = function(e) { call <- conditionCall(e) if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L) dcall <- deparse(call)[1L] prefix <- paste("Error in", dcall, ": ") LONG <- 75L msg <- conditionMessage(e) sm <- strsplit(msg, "\n")[[1L]] if (14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") > LONG) prefix <- paste(prefix, "\n ", sep = "") } else prefix <- "Error : " msg <- paste(prefix, conditionMessage(e), "\n", sep = "") .Internal(seterrmessage(msg[1L])) if (!silent && identical(getOption("show.error.messages"), TRUE)) { cat(msg, file = stderr()) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error"))}) 8: try(.Last.lib(libpath)) 9: detach(package:mniMincIO) Possible actions: 1: abort (with core dump, if enabled) 2: normal R exit 3: exit R without saving workspace 4: exit R saving workspace Selection: 1 aborting ... Segmentation fault > sessionInfo() R version 2.9.1 (2009-06-26) i386-apple-darwin8.11.1 locale: en_CA.UTF-8/en_CA.UTF-8/C/C/en_CA.UTF-8/en_CA.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base ----------------------------------------------------------------- -- ================================= Jim Nikelski, Ph.D. Postdoctoral Research Fellow Bloomfield Centre for Research in Aging Lady Davis Institute for Medical Research Sir Mortimer B. Davis - Jewish General Hospital McGill University ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel