Skip to content

Commit

Permalink
Use libcpp.optional provided by Cython.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwb committed Jan 28, 2025
1 parent 1a01b40 commit 07b9314
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 53 deletions.
20 changes: 1 addition & 19 deletions python/pyarrow/includes/common.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ from libc.stdint cimport *
from libcpp cimport bool as c_bool, nullptr
from libcpp.functional cimport function
from libcpp.memory cimport shared_ptr, unique_ptr, make_shared
from libcpp.optional cimport optional, nullopt
from libcpp.string cimport string as c_string
from libcpp.utility cimport pair
from libcpp.vector cimport vector
Expand All @@ -36,25 +37,6 @@ cdef extern from * namespace "std" nogil:
cdef shared_ptr[T] static_pointer_cast[T, U](shared_ptr[U])


cdef extern from "<optional>" namespace "std" nogil:
cdef cppclass optional[T]:
ctypedef T value_type
optional()
optional(nullopt_t)
optional(optional&) except +
optional(T&) except +
c_bool has_value()
T& value()
T& value_or[U](U& default_value)
void swap(optional&)
void reset()
T& emplace(...)
T& operator*()
# T* operator->() # Not Supported
optional& operator=(optional&)
optional& operator=[U](U&)


# vendored from the cymove project https://github.com/ozars/cymove
cdef extern from * namespace "cymove" nogil:
"""
Expand Down
35 changes: 1 addition & 34 deletions python/pyarrow/lib.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,11 @@ from cpython cimport PyObject
from libcpp cimport nullptr, bool as c_bool
from libcpp.cast cimport dynamic_cast
from libcpp.memory cimport dynamic_pointer_cast
from libcpp.optional cimport optional
from pyarrow.includes.common cimport *
from pyarrow.includes.libarrow cimport *
from pyarrow.includes.libarrow_python cimport *

# Will be available in Cython 3, not backported
# ref: https://github.com/cython/cython/issues/3293#issuecomment-1223058101
cdef extern from "<optional>" namespace "std" nogil:
cdef cppclass nullopt_t:
nullopt_t()

cdef nullopt_t nullopt

cdef cppclass optional[T]:
ctypedef T value_type
optional()
optional(nullopt_t)
optional(optional&) except +
optional(T&) except +
c_bool has_value()
T& value()
T& value_or[U](U& default_value)
void swap(optional&)
void reset()
T& emplace(...)
T& operator*()
# T* operator->() # Not Supported
optional& operator=(optional&)
optional& operator=[U](U&)
c_bool operator bool()
c_bool operator!()
c_bool operator==[U](optional&, U&)
c_bool operator!=[U](optional&, U&)
c_bool operator<[U](optional&, U&)
c_bool operator>[U](optional&, U&)
c_bool operator<=[U](optional&, U&)
c_bool operator>=[U](optional&, U&)

optional[T] make_optional[T](...) except +

cdef extern from "Python.h":
int PySlice_Check(object)
Expand Down

0 comments on commit 07b9314

Please sign in to comment.