Skip to content

Commit 71ff05d

Browse files
committed
Make b_needsfree into boolean
1 parent d6fd4e7 commit 71ff05d

File tree

4 files changed

+6
-44
lines changed

4 files changed

+6
-44
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected abstract static class BNeedsFreeNode extends PythonUnaryBuiltinNode {
115115

116116
@Specialization
117117
Object getBNeedsFree(CDataObject self) {
118-
return self.b_needsfree != 0;
118+
return self.b_needsfree;
119119
}
120120
}
121121

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,14 @@
6464
@ExportLibrary(PythonBufferAccessLibrary.class)
6565
public class CDataObject extends PythonBuiltinObject {
6666

67-
/*
68-
* Hm. Are there CDataObject's which do not need the b_objects member? In this case we probably
69-
* should introduce b_flags to mark it as present... If b_objects is not present/unused b_length
70-
* is unneeded as well.
71-
*/
72-
7367
Pointer b_ptr; /* pointer to memory block */
74-
int b_needsfree; /* need _we_ free the memory? */
68+
boolean b_needsfree; /* need _we_ free the memory? */
7569
CDataObject b_base; /* pointer to base object or NULL */
7670
int b_size; /* size of memory block in bytes */
7771
int b_length; /* number of references we need */
7872
int b_index; /* index of this object into base's b_object list */
7973
Object b_objects; /* dictionary of references we need to keep, or Py_None */
8074

81-
/*
82-
* A default buffer in CDataObject, which can be used for small C types. If this buffer is too
83-
* small, PyMem_Malloc will be called to create a larger one, and this one is not used.
84-
*
85-
* Making CDataObject a variable size object would be a better solution, but more difficult in
86-
* the presence of PyCFuncPtrObject. Maybe later.
87-
*/
88-
// Object b_value;
89-
9075
public CDataObject(Object cls, Shape instanceShape) {
9176
super(cls, instanceShape);
9277
this.b_ptr = Pointer.NULL;

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,9 @@ private static String toHex(int value) {
614614
}
615615

616616
static void PyCData_MallocBuffer(CDataObject obj, StgDictObject dict) {
617-
if (dict.size == 0) {
618-
obj.b_ptr = Pointer.NULL;
619-
} else {
620-
obj.b_ptr = Pointer.allocate(dict.ffi_type_pointer, dict.size);
621-
}
617+
obj.b_ptr = dict.size > 0 ? Pointer.allocate(dict.ffi_type_pointer, dict.size) : Pointer.NULL;
622618
obj.b_size = dict.size;
619+
obj.b_needsfree = true;
623620
}
624621

625622
static CDataObject PyCData_FromBaseObj(Object type, Object base, int index, Pointer adr,
@@ -635,7 +632,7 @@ static CDataObject PyCData_FromBaseObj(Object type, Object base, int index, Poin
635632
cmem.b_size = dict.size;
636633
if (base != null) { /* use base's buffer */
637634
cmem.b_ptr = adr;
638-
cmem.b_needsfree = 0;
635+
cmem.b_needsfree = false;
639636
cmem.b_base = (CDataObject) base;
640637
} else { /* copy contents of adr */
641638
PyCData_MallocBuffer(cmem, dict);

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -622,29 +622,9 @@ Object resize(CDataObject obj, int size,
622622
if (size < dict.size) {
623623
throw raise(ValueError, MINIMUM_SIZE_IS_D, dict.size);
624624
}
625-
if (obj.b_needsfree == 0) {
625+
if (obj.b_needsfree) {
626626
throw raise(ValueError, MEMORY_CANNOT_BE_RESIZED_BECAUSE_THIS_OBJECT_DOESN_T_OWN_IT);
627627
}
628-
/*- TODO
629-
if (size <= sizeof(obj.b_value)) {
630-
// internal default buffer is large enough
631-
obj.b_size = size;
632-
return PNone.NONE;
633-
}
634-
Object ptr;
635-
if (!_CDataObject_HasExternalBuffer(obj)) {
636-
/*
637-
* We are currently using the objects default buffer, but it isn't large enough any
638-
* more.
639-
* /
640-
ptr = PyMem_Malloc(size);
641-
memset(ptr, 0, size);
642-
memmove(ptr, obj.b_ptr, obj.b_size);
643-
} else {
644-
ptr = PyMem_Realloc(obj.b_ptr, size);
645-
}
646-
obj.b_ptr.ptr = ptr;
647-
*/
648628
obj.b_size = size;
649629
return PNone.NONE;
650630
}

0 commit comments

Comments
 (0)