|
51 | 51 | import static com.oracle.graal.python.builtins.objects.cext.capi.NativeMember.OB_REFCNT;
|
52 | 52 | import static com.oracle.graal.python.builtins.objects.cext.capi.NativeMember.OB_TYPE;
|
53 | 53 | import static com.oracle.graal.python.builtins.objects.cext.capi.NativeMember.TP_ALLOC;
|
| 54 | +import static com.oracle.graal.python.builtins.objects.cext.capi.NativeMember.TP_AS_BUFFER; |
54 | 55 | import static com.oracle.graal.python.builtins.objects.cext.capi.NativeMember.TP_BASICSIZE;
|
55 | 56 | import static com.oracle.graal.python.builtins.objects.cext.capi.NativeMember.TP_DEALLOC;
|
56 | 57 | import static com.oracle.graal.python.builtins.objects.cext.capi.NativeMember.TP_DEL;
|
@@ -468,45 +469,9 @@ static Object doTpAsNumber(PythonManagedClass object, @SuppressWarnings("unused"
|
468 | 469 |
|
469 | 470 | @Specialization(guards = "eq(TP_AS_BUFFER, key)")
|
470 | 471 | static Object doTpAsBuffer(PythonManagedClass object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key,
|
471 |
| - @Cached IsSubtypeNode isSubtype, |
472 |
| - @Cached BranchProfile notBytes, |
473 |
| - @Cached BranchProfile notBytearray, |
474 |
| - @Cached BranchProfile notMemoryview, |
475 |
| - @Cached BranchProfile notBuffer, |
476 |
| - @Cached BranchProfile notMmap, |
477 | 472 | @Cached LookupNativeMemberInMRONode lookupTpAsBufferNode,
|
478 | 473 | @Shared("nullToSulongNode") @Cached ToSulongNode toSulongNode) {
|
479 |
| - Python3Core core = PythonContext.get(toSulongNode); |
480 |
| - PythonBuiltinClass pBytes = core.lookupType(PythonBuiltinClassType.PBytes); |
481 |
| - if (isSubtype.execute(object, pBytes)) { |
482 |
| - return new PyBufferProcsWrapper(pBytes); |
483 |
| - } |
484 |
| - notBytes.enter(); |
485 |
| - PythonBuiltinClass pBytearray = core.lookupType(PythonBuiltinClassType.PByteArray); |
486 |
| - if (isSubtype.execute(object, pBytearray)) { |
487 |
| - return new PyBufferProcsWrapper(pBytearray); |
488 |
| - } |
489 |
| - notBytearray.enter(); |
490 |
| - PythonBuiltinClass pMemoryview = core.lookupType(PythonBuiltinClassType.PMemoryView); |
491 |
| - if (isSubtype.execute(object, pMemoryview)) { |
492 |
| - return new PyBufferProcsWrapper(pMemoryview); |
493 |
| - } |
494 |
| - notMemoryview.enter(); |
495 |
| - PythonBuiltinClass pBuffer = core.lookupType(PythonBuiltinClassType.PBuffer); |
496 |
| - if (isSubtype.execute(object, pBuffer)) { |
497 |
| - return new PyBufferProcsWrapper(pBuffer); |
498 |
| - } |
499 |
| - notBuffer.enter(); |
500 |
| - PythonBuiltinClass pMmap = core.lookupType(PythonBuiltinClassType.PMMap); |
501 |
| - if (isSubtype.execute(object, pMmap)) { |
502 |
| - return new PyBufferProcsWrapper(pMmap); |
503 |
| - } |
504 |
| - notMmap.enter(); |
505 |
| - /* |
506 |
| - * Managed classes don't store PyBufferProcs objects and so there is no attribute. This |
507 |
| - * is why we use managedMemberName == "". |
508 |
| - */ |
509 |
| - Object result = lookupTpAsBufferNode.execute(object, NativeMember.TP_AS_BUFFER, ""); |
| 474 | + Object result = lookupTpAsBufferNode.execute(object, NativeMember.TP_AS_BUFFER, TypeBuiltins.TYPE_AS_BUFFER); |
510 | 475 | if (result == PNone.NO_VALUE) {
|
511 | 476 | // NULL pointer
|
512 | 477 | return toSulongNode.execute(PythonContext.get(toSulongNode).getNativeNull());
|
@@ -1440,6 +1405,13 @@ static void doTpFree(Object object, @SuppressWarnings("unused") PythonNativeWrap
|
1440 | 1405 | writeAttrNode.execute(object, TypeBuiltins.TYPE_FREE, asPythonObjectNode.execute(freeFunc));
|
1441 | 1406 | }
|
1442 | 1407 |
|
| 1408 | + @Specialization(guards = {"isPythonClass(object)", "eq(TP_AS_BUFFER, key)"}) |
| 1409 | + static void doTpAsBuffer(Object object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key, Object bufferProcs, |
| 1410 | + @Cached WriteAttributeToObjectNode writeAttrNode, |
| 1411 | + @Cached WrapVoidPtrNode asPythonObjectNode) { |
| 1412 | + writeAttrNode.execute(object, TypeBuiltins.TYPE_AS_BUFFER, asPythonObjectNode.execute(bufferProcs)); |
| 1413 | + } |
| 1414 | + |
1443 | 1415 | @GenerateUncached
|
1444 | 1416 | static final class EachSubclassAdd extends HashingStorageLibrary.ForEachNode<SubclassAddState> {
|
1445 | 1417 |
|
@@ -1616,6 +1588,7 @@ protected boolean isMemberModifiable(String member) {
|
1616 | 1588 | MD_STATE.getMemberName().equals(member) ||
|
1617 | 1589 | TP_DICT.getMemberName().equals(member) ||
|
1618 | 1590 | TP_DICTOFFSET.getMemberName().equals(member) ||
|
| 1591 | + TP_AS_BUFFER.getMemberName().equals(member) || |
1619 | 1592 | MEMORYVIEW_EXPORTS.getMemberName().equals(member);
|
1620 | 1593 | }
|
1621 | 1594 |
|
|
0 commit comments