Skip to content

Commit f27db84

Browse files
committed
[GR-27559] Remove PythonObjectLibrary
PullRequest: graalpython/1997
2 parents 92fefeb + a5e9d6d commit f27db84

File tree

49 files changed

+194
-2313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+194
-2313
lines changed

graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/ArgumentClinic.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,6 @@ enum ClinicConversion {
155155
* Corresponds to CPython's {@code object(subclass_of="&PyTuple_Type"))} converter.
156156
*/
157157
Tuple,
158-
/**
159-
* Deprecated. Legacy converter for PythonObjectLibrary buffers.
160-
*/
161-
Buffer,
162158
/**
163159
* Corresponds to CPython's {@code Py_buffer} converter for a readonly contiguous buffer.
164160
* Returns an opaque buffer object that is accessed using {@code PythonBufferAccessLibrary}.

graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/ConverterFactory.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ public enum Param {
9494
private static ConverterFactory[] BuiltinLong;
9595
private static ConverterFactory[] BuiltinCodePoint;
9696
private static ConverterFactory[] BuiltinTuple;
97-
private static ConverterFactory[] BuiltinBuffer;
9897
private static ConverterFactory[] BuiltinReadableBuffer;
9998
private static ConverterFactory[] BuiltinWritableBuffer;
10099
private static ConverterFactory[] BuiltinIndex;
@@ -145,8 +144,6 @@ public static ConverterFactory[] getBuiltin(ArgumentClinic annotation) {
145144
return BuiltinCodePoint;
146145
case Tuple:
147146
return BuiltinTuple;
148-
case Buffer:
149-
return BuiltinBuffer;
150147
case ReadableBuffer:
151148
return BuiltinReadableBuffer;
152149
case WritableBuffer:
@@ -228,7 +225,6 @@ public static void initBuiltins(Elements elementUtils) throws ProcessingError {
228225
BuiltinDouble = forBuiltin(elementUtils, "JavaDoubleConversionNode");
229226
BuiltinCodePoint = forBuiltin(elementUtils, "CodePointConversionNode");
230227
BuiltinTuple = forBuiltin(elementUtils, "TupleConversionNode");
231-
BuiltinBuffer = forBuiltin(elementUtils, "BufferConversionNode");
232228
BuiltinReadableBuffer = forBuiltin(elementUtils, "ReadableBufferConversionNode");
233229
BuiltinWritableBuffer = forBuiltin(elementUtils, "WritableBufferConversionNode");
234230
BuiltinIndex = forBuiltin(elementUtils, "IndexConversionNode");

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/objects/PythonObjectLibraryTests.java

Lines changed: 0 additions & 135 deletions
This file was deleted.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,20 @@
5151

5252
import com.oracle.graal.python.PythonLanguage;
5353
import com.oracle.graal.python.builtins.modules.GraalHPyDebugModuleBuiltins;
54-
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
5554
import com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor;
56-
import com.oracle.graal.python.builtins.objects.function.PArguments;
57-
import com.oracle.graal.python.builtins.objects.function.PArguments.ThreadState;
58-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
5955
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
60-
import com.oracle.graal.python.runtime.GilNode;
6156
import com.oracle.graal.python.runtime.PythonContext;
6257
import com.oracle.truffle.api.CompilerAsserts;
6358
import com.oracle.truffle.api.CompilerDirectives;
6459
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
65-
import com.oracle.truffle.api.dsl.Cached;
66-
import com.oracle.truffle.api.dsl.Cached.Exclusive;
67-
import com.oracle.truffle.api.dsl.Cached.Shared;
68-
import com.oracle.truffle.api.frame.VirtualFrame;
6960
import com.oracle.truffle.api.interop.TruffleObject;
7061
import com.oracle.truffle.api.library.CachedLibrary;
7162
import com.oracle.truffle.api.library.ExportLibrary;
7263
import com.oracle.truffle.api.library.ExportMessage;
7364
import com.oracle.truffle.api.library.Message;
7465
import com.oracle.truffle.api.library.ReflectionLibrary;
7566
import com.oracle.truffle.api.object.Shape;
76-
import com.oracle.truffle.api.profiles.ConditionProfile;
7767

78-
@ExportLibrary(PythonObjectLibrary.class)
7968
// InteropLibrary is proxied through ReflectionLibrary
8069
@ExportLibrary(ReflectionLibrary.class)
8170
public enum PythonBuiltinClassType implements TruffleObject {
@@ -723,59 +712,7 @@ public Object send(Message message, Object[] args,
723712
return lib.send(PythonContext.get(lib).getCore().lookupType(this), message, args);
724713
}
725714

726-
@ExportMessage
727-
public Object lookupAttributeInternal(ThreadState state, String attribName, boolean strict,
728-
@Cached ConditionProfile gotState,
729-
@Cached.Exclusive @Cached PythonAbstractObject.LookupAttributeNode lookup) {
730-
VirtualFrame frame = null;
731-
if (gotState.profile(state != null)) {
732-
frame = PArguments.frameForCall(state);
733-
}
734-
return lookup.execute(frame, this, attribName, strict);
735-
}
736-
737-
@ExportMessage
738-
@SuppressWarnings("static-method")
739-
public Object lookupAttributeOnTypeInternal(String attributeName, boolean strict,
740-
@Exclusive @Cached PythonAbstractObject.LookupAttributeOnTypeNode lookup,
741-
@Cached.Exclusive @Cached GilNode gil) {
742-
boolean mustRelease = gil.acquire();
743-
try {
744-
return lookup.execute(PythonClass, attributeName, strict);
745-
} finally {
746-
gil.release(mustRelease);
747-
}
748-
}
749-
750-
@ExportMessage
751-
@SuppressWarnings("static-method")
752-
public boolean isCallable() {
753-
return true;
754-
}
755-
756-
@ExportMessage
757-
public Object callObjectWithState(ThreadState state, Object[] arguments,
758-
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
759-
return lib.callObjectWithState(PythonContext.get(lib).getCore().lookupType(this), state, arguments);
760-
}
761-
762715
public static boolean isExceptionType(PythonBuiltinClassType type) {
763716
return type.isException;
764717
}
765-
766-
@ExportMessage
767-
public Object lookupAndCallSpecialMethodWithState(ThreadState state, String methodName, Object[] arguments,
768-
@CachedLibrary("this") PythonObjectLibrary plib,
769-
@Shared("methodLib") @CachedLibrary(limit = "2") PythonObjectLibrary methodLib) {
770-
Object method = plib.lookupAttributeOnTypeStrict(this, methodName);
771-
return methodLib.callUnboundMethodWithState(method, state, this, arguments);
772-
}
773-
774-
@ExportMessage
775-
public Object lookupAndCallRegularMethodWithState(ThreadState state, String methodName, Object[] arguments,
776-
@CachedLibrary("this") PythonObjectLibrary plib,
777-
@Shared("methodLib") @CachedLibrary(limit = "2") PythonObjectLibrary methodLib) {
778-
Object method = plib.lookupAttributeStrictWithState(this, state, methodName);
779-
return methodLib.callObjectWithState(method, state, arguments);
780-
}
781718
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataObject.java

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@
4141
package com.oracle.graal.python.builtins.modules.ctypes;
4242

4343
import com.oracle.graal.python.builtins.modules.ctypes.CtypesNodes.DeRefHandleNode;
44-
import com.oracle.graal.python.builtins.modules.ctypes.PtrValue.ByteArrayStorage;
44+
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
45+
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAcquireLibrary;
4546
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
46-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
4747
import com.oracle.graal.python.builtins.objects.str.PString;
4848
import com.oracle.graal.python.util.PythonUtils;
49+
import com.oracle.truffle.api.CompilerDirectives;
4950
import com.oracle.truffle.api.dsl.Cached;
5051
import com.oracle.truffle.api.interop.InteropLibrary;
5152
import com.oracle.truffle.api.interop.TruffleObject;
@@ -57,7 +58,8 @@
5758
import com.oracle.truffle.api.object.Shape;
5859
import com.oracle.truffle.llvm.spi.NativeTypeLibrary;
5960

60-
@ExportLibrary(PythonObjectLibrary.class)
61+
@ExportLibrary(PythonBufferAcquireLibrary.class)
62+
@ExportLibrary(PythonBufferAccessLibrary.class)
6163
public class CDataObject extends PythonBuiltinObject {
6264

6365
/*
@@ -92,10 +94,21 @@ protected static CDataObjectWrapper createWrapper(StgDictObject dictObject, byte
9294
return new CDataObjectWrapper(dictObject, storage);
9395
}
9496

97+
@ExportMessage
98+
@SuppressWarnings("static-method")
99+
boolean hasBuffer() {
100+
return true;
101+
}
102+
103+
@ExportMessage
104+
Object acquire(@SuppressWarnings("unused") int flags) {
105+
return this;
106+
}
107+
95108
@ExportMessage
96109
@SuppressWarnings("static-method")
97110
boolean isBuffer() {
98-
return b_ptr.ptr instanceof ByteArrayStorage;
111+
return true;
99112
}
100113

101114
@ExportMessage
@@ -104,14 +117,51 @@ int getBufferLength() {
104117
}
105118

106119
@ExportMessage
107-
byte[] getBufferBytes() {
108-
assert isBuffer();
109-
byte[] bytes = ((ByteArrayStorage) b_ptr.ptr).value;
110-
if (b_ptr.offset > 0) {
111-
return PythonUtils.arrayCopyOfRange(bytes, b_ptr.offset, b_size);
120+
byte readByte(int byteIndex,
121+
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib) {
122+
if (b_ptr.ptr != null) {
123+
return bufferLib.readByte(b_ptr.ptr, b_ptr.offset + byteIndex);
124+
}
125+
throw CompilerDirectives.shouldNotReachHere("buffer read from empty CDataObject");
126+
}
127+
128+
@ExportMessage
129+
@SuppressWarnings("static-method")
130+
boolean isReadonly() {
131+
return false;
132+
}
133+
134+
@ExportMessage
135+
void writeByte(int byteIndex, byte value,
136+
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib) {
137+
if (b_ptr.ptr != null) {
138+
bufferLib.writeByte(b_ptr.ptr, b_ptr.offset + byteIndex, value);
112139
}
113-
return bytes;
140+
throw CompilerDirectives.shouldNotReachHere("buffer write to empty CDataObject");
114141
}
142+
143+
@ExportMessage
144+
boolean hasInternalByteArray(
145+
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib) {
146+
if (b_ptr.offset != 0) {
147+
return false;
148+
}
149+
if (b_ptr.ptr != null) {
150+
return bufferLib.hasInternalByteArray(b_ptr.ptr);
151+
}
152+
return true;
153+
}
154+
155+
@ExportMessage
156+
byte[] getInternalByteArray(
157+
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib) {
158+
assert hasInternalByteArray(bufferLib);
159+
if (b_ptr.ptr != null) {
160+
return bufferLib.getInternalByteArray(b_ptr.ptr);
161+
}
162+
return PythonUtils.EMPTY_BYTE_ARRAY;
163+
}
164+
115165
/*-
116166
static int PyCData_NewGetBuffer(Object myself, Py_buffer *view, int flags)
117167
{

0 commit comments

Comments
 (0)