Skip to content

Commit 2468f37

Browse files
committed
fix: fix ctypes declaration of _view() functions
1 parent c500751 commit 2468f37

File tree

3 files changed

+27
-35
lines changed

3 files changed

+27
-35
lines changed

src/codegen/internal_lib.py.in

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ igraph_vector_init_array.restype = handle_igraph_error_t
110110
igraph_vector_init_array.argtypes = [POINTER(igraph_vector_t), POINTER(igraph_real_t), igraph_int_t]
111111

112112
igraph_vector_view = _lib.igraph_vector_view
113-
igraph_vector_view.restype = POINTER(igraph_vector_t)
114-
igraph_vector_view.argtypes = [POINTER(igraph_vector_t), POINTER(igraph_real_t), igraph_int_t]
113+
igraph_vector_view.restype = igraph_vector_t
114+
igraph_vector_view.argtypes = [POINTER(igraph_real_t), igraph_int_t]
115115

116116
igraph_vector_clear = _lib.igraph_vector_clear
117117
igraph_vector_clear.restype = None
@@ -160,8 +160,8 @@ igraph_vector_int_init_array.restype = handle_igraph_error_t
160160
igraph_vector_int_init_array.argtypes = [POINTER(igraph_vector_int_t), POINTER(igraph_int_t), igraph_int_t]
161161

162162
igraph_vector_int_view = _lib.igraph_vector_int_view
163-
igraph_vector_int_view.restype = POINTER(igraph_vector_int_t)
164-
igraph_vector_int_view.argtypes = [POINTER(igraph_vector_int_t), POINTER(igraph_int_t), igraph_int_t]
163+
igraph_vector_int_view.restype = igraph_vector_int_t
164+
igraph_vector_int_view.argtypes = [POINTER(igraph_int_t), igraph_int_t]
165165

166166
igraph_vector_int_clear = _lib.igraph_vector_int_clear
167167
igraph_vector_int_clear.restype = None
@@ -210,8 +210,8 @@ igraph_vector_bool_init_array.restype = handle_igraph_error_t
210210
igraph_vector_bool_init_array.argtypes = [POINTER(igraph_vector_bool_t), POINTER(igraph_bool_t), igraph_int_t]
211211

212212
igraph_vector_bool_view = _lib.igraph_vector_bool_view
213-
igraph_vector_bool_view.restype = POINTER(igraph_vector_bool_t)
214-
igraph_vector_bool_view.argtypes = [POINTER(igraph_vector_bool_t), POINTER(igraph_bool_t), igraph_int_t]
213+
igraph_vector_bool_view.restype = igraph_vector_bool_t
214+
igraph_vector_bool_view.argtypes = [POINTER(igraph_bool_t), igraph_int_t]
215215

216216
igraph_vector_bool_clear = _lib.igraph_vector_bool_clear
217217
igraph_vector_bool_clear.restype = None
@@ -322,9 +322,8 @@ igraph_matrix_init_array.argtypes = [
322322
]
323323

324324
igraph_matrix_view = _lib.igraph_matrix_view
325-
igraph_matrix_view.restype = POINTER(igraph_matrix_t)
325+
igraph_matrix_view.restype = igraph_matrix_t
326326
igraph_matrix_view.argtypes = [
327-
POINTER(igraph_matrix_t),
328327
POINTER(igraph_real_t),
329328
igraph_int_t,
330329
igraph_int_t,
@@ -363,9 +362,8 @@ igraph_matrix_int_init_array.argtypes = [
363362
]
364363

365364
igraph_matrix_int_view = _lib.igraph_matrix_int_view
366-
igraph_matrix_int_view.restype = POINTER(igraph_matrix_int_t)
365+
igraph_matrix_int_view.restype = igraph_matrix_int_t
367366
igraph_matrix_int_view.argtypes = [
368-
POINTER(igraph_matrix_int_t),
369367
POINTER(igraph_int_t),
370368
igraph_int_t,
371369
igraph_int_t,

src/igraph_ctypes/_internal/conversion.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,12 @@ def numpy_array_to_igraph_vector_bool_t_view(
621621
provided into the copy.
622622
"""
623623
arr = _force_into_1d_numpy_array(arr, np_type_of_igraph_bool_t, flatten=flatten)
624+
arr_ptr = arr.ctypes.data_as(POINTER(igraph_bool_t))
624625

625-
result = _VectorBool()
626-
igraph_vector_bool_view(
627-
result, arr.ctypes.data_as(POINTER(igraph_bool_t)), arr.shape[0]
628-
)
626+
result = _VectorBool(igraph_vector_bool_view(arr_ptr, arr.shape[0]))
629627

630628
# Destructor must not be called so we never mark result as initialized;
631-
# this is intentional
629+
result.release()
632630

633631
return result
634632

@@ -655,14 +653,12 @@ def numpy_array_to_igraph_vector_int_t_view(
655653
provided into the copy.
656654
"""
657655
arr = _force_into_1d_numpy_array(arr, np_type_of_igraph_int_t, flatten=flatten)
656+
arr_ptr = arr.ctypes.data_as(POINTER(igraph_int_t))
658657

659-
result = _VectorInt()
660-
igraph_vector_int_view(
661-
result, arr.ctypes.data_as(POINTER(igraph_int_t)), arr.shape[0]
662-
)
658+
result = _VectorInt(igraph_vector_int_view(arr_ptr, arr.shape[0]))
663659

664-
# Destructor must not be called so we never mark result as initialized;
665-
# this is intentional
660+
# Destructor must not be called so we need to call .release()
661+
result.release()
666662

667663
return result
668664

@@ -687,12 +683,12 @@ def numpy_array_to_igraph_vector_t_view(
687683
provided into the copy.
688684
"""
689685
arr = _force_into_1d_numpy_array(arr, np_type_of_igraph_real_t, flatten=flatten)
686+
arr_ptr = arr.ctypes.data_as(POINTER(igraph_real_t))
690687

691-
result = _Vector()
692-
igraph_vector_view(result, arr.ctypes.data_as(POINTER(igraph_real_t)), arr.shape[0])
688+
result = _Vector(igraph_vector_view(arr_ptr, arr.shape[0]))
693689

694-
# Destructor must not be called so we never mark result as initialized;
695-
# this is intentional
690+
# Destructor must not be called so we need to call .release()
691+
result.release()
696692

697693
return result
698694

src/igraph_ctypes/_internal/lib.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def _load_libc():
110110
igraph_vector_init_array.argtypes = [POINTER(igraph_vector_t), POINTER(igraph_real_t), igraph_int_t]
111111

112112
igraph_vector_view = _lib.igraph_vector_view
113-
igraph_vector_view.restype = POINTER(igraph_vector_t)
114-
igraph_vector_view.argtypes = [POINTER(igraph_vector_t), POINTER(igraph_real_t), igraph_int_t]
113+
igraph_vector_view.restype = igraph_vector_t
114+
igraph_vector_view.argtypes = [POINTER(igraph_real_t), igraph_int_t]
115115

116116
igraph_vector_clear = _lib.igraph_vector_clear
117117
igraph_vector_clear.restype = None
@@ -160,8 +160,8 @@ def _load_libc():
160160
igraph_vector_int_init_array.argtypes = [POINTER(igraph_vector_int_t), POINTER(igraph_int_t), igraph_int_t]
161161

162162
igraph_vector_int_view = _lib.igraph_vector_int_view
163-
igraph_vector_int_view.restype = POINTER(igraph_vector_int_t)
164-
igraph_vector_int_view.argtypes = [POINTER(igraph_vector_int_t), POINTER(igraph_int_t), igraph_int_t]
163+
igraph_vector_int_view.restype = igraph_vector_int_t
164+
igraph_vector_int_view.argtypes = [POINTER(igraph_int_t), igraph_int_t]
165165

166166
igraph_vector_int_clear = _lib.igraph_vector_int_clear
167167
igraph_vector_int_clear.restype = None
@@ -210,8 +210,8 @@ def _load_libc():
210210
igraph_vector_bool_init_array.argtypes = [POINTER(igraph_vector_bool_t), POINTER(igraph_bool_t), igraph_int_t]
211211

212212
igraph_vector_bool_view = _lib.igraph_vector_bool_view
213-
igraph_vector_bool_view.restype = POINTER(igraph_vector_bool_t)
214-
igraph_vector_bool_view.argtypes = [POINTER(igraph_vector_bool_t), POINTER(igraph_bool_t), igraph_int_t]
213+
igraph_vector_bool_view.restype = igraph_vector_bool_t
214+
igraph_vector_bool_view.argtypes = [POINTER(igraph_bool_t), igraph_int_t]
215215

216216
igraph_vector_bool_clear = _lib.igraph_vector_bool_clear
217217
igraph_vector_bool_clear.restype = None
@@ -322,9 +322,8 @@ def _load_libc():
322322
]
323323

324324
igraph_matrix_view = _lib.igraph_matrix_view
325-
igraph_matrix_view.restype = POINTER(igraph_matrix_t)
325+
igraph_matrix_view.restype = igraph_matrix_t
326326
igraph_matrix_view.argtypes = [
327-
POINTER(igraph_matrix_t),
328327
POINTER(igraph_real_t),
329328
igraph_int_t,
330329
igraph_int_t,
@@ -363,9 +362,8 @@ def _load_libc():
363362
]
364363

365364
igraph_matrix_int_view = _lib.igraph_matrix_int_view
366-
igraph_matrix_int_view.restype = POINTER(igraph_matrix_int_t)
365+
igraph_matrix_int_view.restype = igraph_matrix_int_t
367366
igraph_matrix_int_view.argtypes = [
368-
POINTER(igraph_matrix_int_t),
369367
POINTER(igraph_int_t),
370368
igraph_int_t,
371369
igraph_int_t,

0 commit comments

Comments
 (0)