|
49 | 49 | import org.graalvm.nativeimage.ImageInfo;
|
50 | 50 |
|
51 | 51 | import com.oracle.graal.python.PythonLanguage;
|
| 52 | +import com.oracle.graal.python.annotations.ArgumentClinic; |
52 | 53 | import com.oracle.graal.python.builtins.Builtin;
|
53 | 54 | import com.oracle.graal.python.builtins.CoreFunctions;
|
54 | 55 | import com.oracle.graal.python.builtins.Python3Core;
|
55 | 56 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
56 | 57 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
57 | 58 | import com.oracle.graal.python.builtins.objects.PNone;
|
58 | 59 | import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
|
| 60 | +import com.oracle.graal.python.builtins.objects.bytes.BytesNodes; |
59 | 61 | import com.oracle.graal.python.builtins.objects.bytes.PBytes;
|
60 |
| -import com.oracle.graal.python.builtins.objects.bytes.PBytesLike; |
61 | 62 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ExecModuleNode;
|
62 | 63 | import com.oracle.graal.python.builtins.objects.cext.capi.DynamicObjectNativeWrapper;
|
63 | 64 | import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodesFactory.DefaultCheckFunctionResultNodeGen;
|
|
72 | 73 | import com.oracle.graal.python.builtins.objects.code.PCode;
|
73 | 74 | import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
|
74 | 75 | import com.oracle.graal.python.builtins.objects.ints.IntBuiltins;
|
75 |
| -import com.oracle.graal.python.builtins.objects.ints.PInt; |
76 | 76 | import com.oracle.graal.python.builtins.objects.module.PythonModule;
|
77 | 77 | import com.oracle.graal.python.builtins.objects.object.PythonObject;
|
78 | 78 | import com.oracle.graal.python.builtins.objects.str.PString;
|
|
82 | 82 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
83 | 83 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
84 | 84 | import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
|
| 85 | +import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode; |
| 86 | +import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider; |
85 | 87 | import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
|
86 | 88 | import com.oracle.graal.python.parser.sst.SerializationUtils;
|
87 | 89 | import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
|
@@ -378,30 +380,25 @@ private static void doPostInit(Python3Core core, PythonBuiltins builtins) {
|
378 | 380 | }
|
379 | 381 | }
|
380 | 382 |
|
381 |
| - @Builtin(name = "source_hash", minNumOfPositionalArgs = 2) |
| 383 | + @Builtin(name = "source_hash", minNumOfPositionalArgs = 2, parameterNames = {"key", "source"}) |
| 384 | + @ArgumentClinic(name = "key", conversion = ArgumentClinic.ClinicConversion.Long) |
| 385 | + @ArgumentClinic(name = "source", conversion = ArgumentClinic.ClinicConversion.ReadableBuffer) |
382 | 386 | @GenerateNodeFactory
|
383 |
| - public abstract static class SourceHashNode extends PythonBinaryBuiltinNode { |
| 387 | + public abstract static class SourceHashNode extends PythonBinaryClinicBuiltinNode { |
384 | 388 | @Specialization
|
385 |
| - @TruffleBoundary |
386 |
| - PBytes run(long magicNumber, PBytesLike source) { |
| 389 | + PBytes run(long magicNumber, Object sourceBuffer, |
| 390 | + @Cached BytesNodes.HashBufferNode hashBufferNode) { |
387 | 391 | byte[] hash = new byte[Long.BYTES];
|
388 |
| - long hashCode = magicNumber ^ source.hashCode(); |
| 392 | + long hashCode = magicNumber ^ hashBufferNode.execute(sourceBuffer); |
389 | 393 | for (int i = 0; i < hash.length; i++) {
|
390 | 394 | hash[i] = (byte) (hashCode << (8 * i));
|
391 | 395 | }
|
392 | 396 | return factory().createBytes(hash);
|
393 | 397 | }
|
394 | 398 |
|
395 |
| - @Specialization |
396 |
| - @TruffleBoundary |
397 |
| - PBytes run(PInt magicNumber, PBytesLike source) { |
398 |
| - return run(magicNumber.longValue(), source); |
399 |
| - } |
400 |
| - |
401 |
| - @Specialization |
402 |
| - @TruffleBoundary |
403 |
| - PBytes run(int magicNumber, PBytesLike source) { |
404 |
| - return run((long) magicNumber, source); |
| 399 | + @Override |
| 400 | + protected ArgumentClinicProvider getArgumentClinic() { |
| 401 | + return ImpModuleBuiltinsClinicProviders.SourceHashNodeClinicProviderGen.INSTANCE; |
405 | 402 | }
|
406 | 403 | }
|
407 | 404 |
|
|
0 commit comments