Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua James Venter <[email protected]>
  • Loading branch information
jjvraw committed Oct 4, 2024
1 parent c36743b commit 51780b4
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 76 deletions.
14 changes: 8 additions & 6 deletions stdlib/src/python/_cpython.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -1323,15 +1323,15 @@ struct CPython:
fn toPython(inout self, litBool: Bool) -> PyObjectPtr:
return self.PyBool_FromLong(1 if litBool else 0)

fn PyLong_AsLong(inout self, py_object: PyObjectPtr) -> Int:
fn PyLong_AsLong(inout self, py_object_ptr: PyObjectPtr) -> Int:
return self.lib.get_function[fn (PyObjectPtr) -> Int]("PyLong_AsLong")(
py_object
py_object_ptr
)

fn PyFloat_AsDouble(inout self, py_object: PyObjectPtr) -> Float64:
fn PyFloat_AsDouble(inout self, py_object_ptr: PyObjectPtr) -> Float64:
return self.lib.get_function[fn (PyObjectPtr) -> Float64](
"PyFloat_AsDouble"
)(py_object)
)(py_object_ptr)

fn PyFloat_FromDouble(inout self, value: Float64) -> PyObjectPtr:
var r = self.lib.get_function[fn (Float64) -> PyObjectPtr](
Expand Down Expand Up @@ -1393,10 +1393,12 @@ struct CPython:
self._inc_total_rc()
return r

fn PyUnicode_AsUTF8AndSize(inout self, py_object: PyObjectPtr) -> StringRef:
fn PyUnicode_AsUTF8AndSize(
inout self, py_object_ptr: PyObjectPtr
) -> StringRef:
var result = self.lib.get_function[
fn (PyObjectPtr, UnsafePointer[Int]) -> UnsafePointer[c_char]
]("PyUnicode_AsUTF8AndSize")(py_object, UnsafePointer[Int]())
]("PyUnicode_AsUTF8AndSize")(py_object_ptr, UnsafePointer[Int]())
return StringRef(result)

# ===-------------------------------------------------------------------===#
Expand Down
17 changes: 11 additions & 6 deletions stdlib/src/python/python.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ struct Python:
cpython.PyImport_AddModule(name)
)
var dict_obj = PythonObject.from_borrowed_ptr(
cpython.PyModule_GetDict(module.py_object)
cpython.PyModule_GetDict(module.py_object_ptr)
)
if file:
# We compile the code as provided and execute in the module
Expand All @@ -139,7 +139,9 @@ struct Python:
# the module scope for this eval, they should be the same object.
var result = PythonObject(
cpython.PyEval_EvalCode(
code.py_object, dict_obj.py_object, dict_obj.py_object
code.py_object_ptr,
dict_obj.py_object_ptr,
dict_obj.py_object_ptr,
)
)
Python.throw_python_exception_if_error_state(cpython)
Expand All @@ -151,7 +153,10 @@ struct Python:
# all the globals/locals to be discarded. See above re: why the same
# dictionary is being used here for both globals and locals.
var result = cpython.PyRun_String(
expr, dict_obj.py_object, dict_obj.py_object, Py_eval_input
expr,
dict_obj.py_object_ptr,
dict_obj.py_object_ptr,
Py_eval_input,
)
# We no longer need module and dictionary, release them.
Python.throw_python_exception_if_error_state(cpython)
Expand Down Expand Up @@ -362,7 +367,7 @@ struct Python:
Mojo string representing the given Python object.
"""
var cpython = self.impl.cpython()
return cpython.PyUnicode_AsUTF8AndSize(str_obj.py_object)
return cpython.PyUnicode_AsUTF8AndSize(str_obj.py_object_ptr)

@staticmethod
fn throw_python_exception_if_error_state(inout cpython: CPython) raises:
Expand Down Expand Up @@ -413,7 +418,7 @@ struct Python:
True if `x` and `y` are the same object and False otherwise.
"""
var cpython = _get_global_python_itf().cpython()
return cpython.Py_Is(x.py_object, y.py_object)
return cpython.Py_Is(x.py_object_ptr, y.py_object_ptr)

@staticmethod
fn type(obj: PythonObject) -> PythonObject:
Expand All @@ -426,7 +431,7 @@ struct Python:
A PythonObject that holds the type object.
"""
var cpython = _get_global_python_itf().cpython()
return cpython.PyObject_Type(obj.py_object)
return cpython.PyObject_Type(obj.py_object_ptr)

@staticmethod
fn none() -> PythonObject:
Expand Down
Loading

0 comments on commit 51780b4

Please sign in to comment.