|
56 | 56 | import java.util.concurrent.TimeUnit;
|
57 | 57 | import java.util.concurrent.atomic.AtomicReference;
|
58 | 58 | import java.util.logging.Level;
|
| 59 | +import java.util.regex.Matcher; |
| 60 | +import java.util.regex.Pattern; |
59 | 61 |
|
60 | 62 | import com.oracle.graal.python.PythonLanguage;
|
61 | 63 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
@@ -131,6 +133,9 @@ public final class GraalHPyContext extends CExtContext {
|
131 | 133 | public static final long SIZEOF_LONG = java.lang.Long.BYTES;
|
132 | 134 | private static final long NATIVE_ARGUMENT_STACK_SIZE = 1 << 15; // 32 kB stack size
|
133 | 135 |
|
| 136 | + // "blah.hpy123[-310].so" |
| 137 | + private static final Pattern SO_NAME_PATTERN = Pattern.compile(".*" + Pattern.quote(HPY_EXT) + "(\\d+)(?:-\\d+)?\\.so$"); |
| 138 | + |
134 | 139 | @TruffleBoundary
|
135 | 140 | public static GraalHPyContext ensureHPyWasLoaded(Node node, PythonContext context, TruffleString name, TruffleString path) throws IOException, ApiInitException, ImportException {
|
136 | 141 | if (!context.hasHPyContext()) {
|
@@ -237,25 +242,16 @@ public static Object loadHPyModule(Node location, PythonContext context, Truffle
|
237 | 242 |
|
238 | 243 | private static void validateABITag(Node location, String shortname, String soname, HPyABIVersion abiVersion) {
|
239 | 244 | // assumes format: "blah.hpy123[-310].so"
|
240 |
| - int hpyExtIdx = soname.lastIndexOf(HPY_EXT); |
241 |
| - int start = hpyExtIdx + HPY_EXT.length(); |
242 |
| - int end = start; |
243 |
| - while (Character.isDigit(soname.charAt(end))) { |
244 |
| - end++; |
245 |
| - } |
246 |
| - if (hpyExtIdx != -1 && end > start) { |
247 |
| - try { |
248 |
| - String abiTagVersion = soname.substring(start, end); |
249 |
| - int abiTag = Integer.parseInt(abiTagVersion); |
250 |
| - if (abiTag != abiVersion.major) { |
251 |
| - throw PRaiseNode.raiseUncached(location, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_ABI_TAG_MISMATCH, |
252 |
| - shortname, soname, abiTag, abiVersion.major, abiVersion.minor); |
253 |
| - } |
254 |
| - // major version fits -> validation successful |
255 |
| - return; |
256 |
| - } catch (NumberFormatException e) { |
257 |
| - // fall through |
| 245 | + Matcher matcher = SO_NAME_PATTERN.matcher(soname); |
| 246 | + if (matcher.matches()) { |
| 247 | + String abiTagVersion = matcher.group(1); |
| 248 | + int abiTag = Integer.parseInt(abiTagVersion); |
| 249 | + if (abiTag != abiVersion.major) { |
| 250 | + throw PRaiseNode.raiseUncached(location, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_ABI_TAG_MISMATCH, |
| 251 | + shortname, soname, abiTag, abiVersion.major, abiVersion.minor); |
258 | 252 | }
|
| 253 | + // major version fits -> validation successful |
| 254 | + return; |
259 | 255 | }
|
260 | 256 | throw PRaiseNode.raiseUncached(location, PythonBuiltinClassType.RuntimeError, ErrorMessages.HPY_NO_ABI_TAG,
|
261 | 257 | shortname, soname, abiVersion.major, abiVersion.minor);
|
|
0 commit comments