Skip to content

Commit 02b2421

Browse files
committed
Merge bug/REL1_6_STABLE/issue471 and port/REL1_6_STABLE/FreeBSD2023
Merges pull requests #476 and #478.
3 parents c7eea1e + 9a1f669 + 99a1daa commit 02b2421

File tree

3 files changed

+64
-35
lines changed

3 files changed

+64
-35
lines changed

pljava-so/pom.xml

+41
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,47 @@
120120
}
121121
},
122122
123+
{
124+
name : "FreeBSD",
125+
126+
object_extension : ".o",
127+
128+
probe: function(os_name) {
129+
return os_name.toLowerCase().contains("freebsd");
130+
},
131+
132+
compile : function(cc, files, output_dir, includes, defines, flags) {
133+
includes.add(java_include.resolve("freebsd").toString());
134+
defines.put("FreeBSD", null);
135+
flags.add("-c");
136+
if(isDebugEnabled)
137+
flags.add("-g");
138+
var compileProcess = utils.processBuilder(function(l) {
139+
l.add(cc);
140+
l.addAll(pgxs.formatDefines(defines));
141+
l.addAll(pgxs.formatIncludes(includes));
142+
l.addAll(flags);
143+
l.addAll(files);
144+
});
145+
compileProcess.directory(output_dir.toFile());
146+
return runCommand(compileProcess);
147+
},
148+
149+
link : function(cc, flags, files, target_path) {
150+
if(isDebugEnabled)
151+
flags.add("-g");
152+
flags.add("-shared-libgcc");
153+
var linkingProcess = utils.processBuilder(function(l) {
154+
l.add(cc);
155+
l.addAll(flags);
156+
l.addAll(of("-shared", "-o", "lib" + library_name + ".so"));
157+
l.addAll(files);
158+
});
159+
linkingProcess.directory(target_path.toFile());
160+
return runCommand(linkingProcess);
161+
}
162+
},
163+
123164
{
124165
name : "Mac OS X",
125166

pljava/src/main/java/org/postgresql/pljava/internal/Portal.java

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004-2019 Tada AB and other contributors, as listed below.
2+
* Copyright (c) 2004-2023 Tada AB and other contributors, as listed below.
33
*
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the The BSD 3-Clause License
@@ -25,28 +25,29 @@
2525
*/
2626
public class Portal
2727
{
28-
/*
29-
* Hold a reference to the Java ExecutionPlan object as long as we might be
30-
* using it, just to make sure Java unreachability doesn't cause it to
31-
* mop up its native plan state while the portal might still be using it.
32-
*/
33-
private ExecutionPlan m_plan;
34-
3528
private final State m_state;
3629

3730
Portal(DualState.Key cookie, long ro, long pointer, ExecutionPlan plan)
3831
{
39-
m_state = new State(cookie, this, ro, pointer);
40-
m_plan = plan;
32+
m_state = new State(cookie, this, ro, pointer, plan);
4133
}
4234

4335
private static class State
4436
extends DualState.SingleSPIcursorClose<Portal>
4537
{
38+
/*
39+
* Hold a reference to the Java ExecutionPlan object as long as we might
40+
* be using it, just to make sure Java unreachability doesn't cause it
41+
* to mop up its native plan state while the portal might still want it.
42+
*/
43+
private ExecutionPlan m_plan;
44+
4645
private State(
47-
DualState.Key cookie, Portal referent, long ro, long portal)
46+
DualState.Key cookie, Portal referent, long ro, long portal,
47+
ExecutionPlan plan)
4848
{
4949
super(cookie, referent, ro, portal);
50+
m_plan = plan;
5051
}
5152

5253
/**
@@ -76,6 +77,13 @@ private long getPortalPtr() throws SQLException
7677
unpin();
7778
}
7879
}
80+
81+
@Override
82+
protected void javaStateReleased(boolean nativeStateLive)
83+
{
84+
super.javaStateReleased(nativeStateLive);
85+
m_plan = null;
86+
}
7987
}
8088

8189
/**
@@ -84,11 +92,7 @@ private long getPortalPtr() throws SQLException
8492
*/
8593
public void close()
8694
{
87-
doInPG(() ->
88-
{
89-
m_state.releaseFromJava();
90-
m_plan = null;
91-
});
95+
m_state.releaseFromJava();
9296
}
9397

9498
/**

src/site/markdown/build/freebsd.md

+3-19
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
# Building on FreeBSD
22

3-
At one time, [FreeBSD][]'s threading library would malfunction if it was
4-
dynamically loaded after the start of a program that did not use threads
5-
itself. That was a problem for PL/Java on FreeBSD, because PostgreSQL
6-
itself does not use threads, but Java does. The only known workaround was
7-
to build PostgreSQL itself from source, with the thread library included
8-
in linking.
9-
10-
The same problem was [reported to affect other PostgreSQL extensions][rep]
11-
such as `plv8` and `imcs` also.
12-
13-
The [manual page for FreeBSD's libthr][manthr] was edited
14-
[in February 2015][thrdif] to remove the statement of that limitation,
15-
and the updated manual page appears first in [FreeBSD 10.2][rel102],
16-
so in FreeBSD 10.2 or later, PL/Java (and other affected extensions)
17-
may work without the need to build PostgreSQL from source.
3+
Building on [FreeBSD][] should proceed just as it does on Linux,
4+
as of late 2023, according to Achilleos Mantzios, who provided the patch
5+
adding the necessary build rules.
186

197
[FreeBSD]: https://www.freebsd.org/
20-
[rep]: https://lists.freebsd.org/pipermail/freebsd-hackers/2014-April/044961.html
21-
[manthr]: https://www.freebsd.org/cgi/man.cgi?query=libthr&amp;apropos=0&amp;sektion=3&amp;manpath=FreeBSD+10.2-RELEASE&amp;arch=default&amp;format=html
22-
[thrdif]: https://svnweb.freebsd.org/base/head/lib/libthr/libthr.3?r1=272153&amp;r2=278627
23-
[rel102]: https://www.freebsd.org/releases/10.2R/announce.html

0 commit comments

Comments
 (0)