Skip to content

Commit 66b3751

Browse files
committed
Move getMemory implementation so we can statically link bdwgc
Also: * Remove the requirement that we build a shared bdwgc library in autotools * Update the check for GC_get_full_gc_total_time. ifndef was the wrong thing to use since it's not a macro. We were *always* declaring it, which wasn't a problem unless we were statically linking bdwgc. Then we got redefinition errors.
1 parent 22b6eb4 commit 66b3751

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

M2/Macaulay2/d/actors5.d

+2-1
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,8 @@ toExternalString(e:Expr):Expr := (
21112111
setupfun("toExternalString0",toExternalString);
21122112
21132113
header "
2114-
#ifndef GC_get_full_gc_total_time /* added in bdwgc 8 */
2114+
/* added in bdwgc 8 */
2115+
#if GC_VERSION_MAJOR < 8
21152116
unsigned long GC_get_full_gc_total_time(void) {return 0;}
21162117
#endif
21172118
#define DEF_GC_FN0(s) static void * s##_0(void *client_data) { (void) client_data; return (void *) (long) s(); }

M2/Macaulay2/d/ffi.d

+16
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,19 @@ ffiFunctionPointerAddress(e:Expr):Expr := (
679679
else WrongArg(1, "a function"))
680680
else WrongNumArgs(2));
681681
setupfun("ffiFunctionPointerAddress", ffiFunctionPointerAddress);
682+
683+
getMemory0(e:Expr):Expr := (
684+
when e
685+
is a:Sequence
686+
do (
687+
when a.0
688+
is n:ZZcell do (
689+
if !isInt(n) then WrongArgSmallInteger(1)
690+
else when a.1
691+
is atomic:Boolean do (
692+
if atomic.v then toExpr(getMemAtomic(toInt(n.v)))
693+
else toExpr(getMem(toInt(n.v))))
694+
else WrongArgBoolean(2))
695+
else WrongArgZZ(1))
696+
else WrongNumArgs(2));
697+
setupfun("getMemory0", getMemory0);

M2/Macaulay2/packages/ForeignFunctions.m2

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
newPackage("ForeignFunctions",
2020
Headline => "foreign function interface",
2121
Version => "0.5",
22-
Date => "March 7, 2025",
22+
Date => "March 8, 2025",
2323
Authors => {{
2424
Name => "Doug Torrance",
2525
Email => "[email protected]",
@@ -33,8 +33,9 @@ newPackage("ForeignFunctions",
3333

3434
-*
3535
36-
0.5 (2025-03-07, M2 1.25.05)
36+
0.5 (2025-03-08, M2 1.25.05)
3737
* make LAPACK example canned since it may be a static library
38+
* move getMemory implementation to ffi.d so we can link bdwgc statically
3839
3940
0.4 (2024-10-01, M2 1.24.11)
4041
* remove redundant Constant methods now that it's a subclass of Number
@@ -153,6 +154,7 @@ importFrom_Core {
153154
"ffiStructAddress",
154155
"ffiUnionType",
155156
"ffiFunctionPointerAddress",
157+
"getMemory0",
156158
"registerFinalizerForPointer",
157159
"toExternalFormat"
158160
}
@@ -671,13 +673,10 @@ foreignSymbol(String, ForeignType) := (symb, T) -> dereference_T dlsym symb
671673
-- working with pointers --
672674
---------------------------
673675

674-
gcMalloc = foreignFunction("GC_malloc", voidstar, ulong)
675-
gcMallocAtomic = foreignFunction("GC_malloc_atomic", voidstar, ulong)
676-
677676
getMemory = method(Options => {Atomic => false}, TypicalValue => voidstar)
678677
getMemory ZZ := o -> n -> (
679-
if n <= 0 then error "expected positive number";
680-
(if o.Atomic then gcMallocAtomic else gcMalloc) n)
678+
if n <= 0 then error "expected positive number"
679+
else voidstar getMemory0(n, o.Atomic))
681680
getMemory ForeignType := o -> T -> getMemory(size T, Atomic => isAtomic T)
682681
getMemory ForeignVoidType := o -> T -> error "can't allocate a void"
683682

M2/libraries/gc/Makefile.in

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ GITURL = https://github.com/ivmai/bdwgc/
66
VERSION = 8.2.8
77
LICENSEFILES = README.QUICK
88
# PATCHFILE = @abs_srcdir@/patch-$(VERSION)
9-
SHARED = yes # the foreign functions package needs this
109
PRECONFIGURE = ./autogen.sh
1110

1211
# We can also get the sources from the home page above or from
@@ -59,7 +58,7 @@ CONFIGOPTIONS += --enable-threads=posix
5958
## always build for large memory configurations
6059
CPPFLAGS += -DMAX_HEAP_SECTS=81920 -DMAXHINCR=4096
6160

62-
ifeq (@SHARED@-SHARED,no-no)
61+
ifeq (@SHARED@,no)
6362
CONFIGOPTIONS += --disable-shared --enable-static
6463
endif
6564

0 commit comments

Comments
 (0)