Skip to content

Commit

Permalink
Make symbols static (#225)
Browse files Browse the repository at this point in the history
* Made numerous symbols static

+ Added "static" classifier to a few functions
+ Should be enough to fix #224

* Fixed fwd declarations for releasebuffer

+ forward declarations of releasebuffer need to be static as well
  • Loading branch information
Zuzu-Typ authored Oct 30, 2023
1 parent 0a0d2ea commit 552e68f
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 94 deletions.
82 changes: 41 additions & 41 deletions PyGLM/internal_functions/ctypes_pointers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@

#include "../compiler_setup.h"

PyObject* ctypes_float;
PyObject* ctypes_double;
PyObject* ctypes_int64;
PyObject* ctypes_int32;
PyObject* ctypes_int16;
PyObject* ctypes_int8;
PyObject* ctypes_uint64;
PyObject* ctypes_uint32;
PyObject* ctypes_uint16;
PyObject* ctypes_uint8;
PyObject* ctypes_bool;
static PyObject* ctypes_float;
static PyObject* ctypes_double;
static PyObject* ctypes_int64;
static PyObject* ctypes_int32;
static PyObject* ctypes_int16;
static PyObject* ctypes_int8;
static PyObject* ctypes_uint64;
static PyObject* ctypes_uint32;
static PyObject* ctypes_uint16;
static PyObject* ctypes_uint8;
static PyObject* ctypes_bool;

destructor ctypes_dealloc;
static destructor ctypes_dealloc;

PyObject* ctypes_void_p = NULL;
PyObject* ctypes_cast = NULL;
static PyObject* ctypes_void_p = NULL;
static PyObject* ctypes_cast = NULL;

#if defined(_M_IX86) || defined(__i386__)
PyObject* PyGLM_CtypesVoidP_FromVoidP(void* p) {
static PyObject* PyGLM_CtypesVoidP_FromVoidP(void* p) {
PyObject* argList = Py_BuildValue("(K)", (unsigned long)p);
PyObject* out = PyObject_CallObject(ctypes_void_p, argList);
Py_DECREF(argList);
return out;
}
unsigned long PyGLM_UnsignedLongLong_FromCtypesP(PyObject* ptr) {
static unsigned long PyGLM_UnsignedLongLong_FromCtypesP(PyObject* ptr) {
PyObject* ptr_as_c_void_p = PyObject_CallFunctionObjArgs(ctypes_cast, ptr, ctypes_void_p, NULL);
PyObject* ptr_value = PyObject_GetAttrString(ptr_as_c_void_p, "value");
unsigned long out = PyLong_AsUnsignedLong(ptr_value);
Expand All @@ -35,13 +35,13 @@ unsigned long PyGLM_UnsignedLongLong_FromCtypesP(PyObject* ptr) {
return out;
}
#else
PyObject* PyGLM_CtypesVoidP_FromVoidP(void* p) {
static PyObject* PyGLM_CtypesVoidP_FromVoidP(void* p) {
PyObject* argList = Py_BuildValue("(K)", (unsigned long long)p);
PyObject* out = PyObject_CallObject(ctypes_void_p, argList);
Py_DECREF(argList);
return out;
}
unsigned long long PyGLM_UnsignedLongLong_FromCtypesP(PyObject* ptr) {
static unsigned long long PyGLM_UnsignedLongLong_FromCtypesP(PyObject* ptr) {
PyObject* ptr_as_c_void_p = PyObject_CallFunctionObjArgs(ctypes_cast, ptr, ctypes_void_p, NULL);
PyObject* ptr_value = PyObject_GetAttrString(ptr_as_c_void_p, "value");
unsigned long long out = PyLong_AsUnsignedLongLong(ptr_value);
Expand All @@ -53,91 +53,91 @@ unsigned long long PyGLM_UnsignedLongLong_FromCtypesP(PyObject* ptr) {

#if !(PyGLM_BUILD & PyGLM_NO_FUNCTIONS)

PyObject* ctypes_float_p = NULL;
PyObject* ctypes_double_p = NULL;
PyObject* ctypes_int64_p = NULL;
PyObject* ctypes_int32_p = NULL;
PyObject* ctypes_int16_p = NULL;
PyObject* ctypes_int8_p = NULL;
PyObject* ctypes_uint64_p = NULL;
PyObject* ctypes_uint32_p = NULL;
PyObject* ctypes_uint16_p = NULL;
PyObject* ctypes_uint8_p = NULL;
PyObject* ctypes_bool_p = NULL;
static PyObject* ctypes_float_p = NULL;
static PyObject* ctypes_double_p = NULL;
static PyObject* ctypes_int64_p = NULL;
static PyObject* ctypes_int32_p = NULL;
static PyObject* ctypes_int16_p = NULL;
static PyObject* ctypes_int8_p = NULL;
static PyObject* ctypes_uint64_p = NULL;
static PyObject* ctypes_uint32_p = NULL;
static PyObject* ctypes_uint16_p = NULL;
static PyObject* ctypes_uint8_p = NULL;
static PyObject* ctypes_bool_p = NULL;







PyObject* PyGLM_ToCtypesP(float* ptr) {
static PyObject* PyGLM_ToCtypesP(float* ptr) {
PyObject* ptr_as_c_void_p = PyGLM_CtypesVoidP_FromVoidP((void*)ptr);
PyObject* out = PyObject_CallFunctionObjArgs(ctypes_cast, ptr_as_c_void_p, ctypes_float_p, NULL);
Py_DECREF(ptr_as_c_void_p);
return out;
}
PyObject* PyGLM_ToCtypesP(double* ptr) {
static PyObject* PyGLM_ToCtypesP(double* ptr) {
PyObject* ptr_as_c_void_p = PyGLM_CtypesVoidP_FromVoidP((void*)ptr);
PyObject* out = PyObject_CallFunctionObjArgs(ctypes_cast, ptr_as_c_void_p, ctypes_double_p, NULL);
Py_DECREF(ptr_as_c_void_p);
return out;
}
PyObject* PyGLM_ToCtypesP(glm::int64* ptr) {
static PyObject* PyGLM_ToCtypesP(glm::int64* ptr) {
PyObject* ptr_as_c_void_p = PyGLM_CtypesVoidP_FromVoidP((void*)ptr);
PyObject* out = PyObject_CallFunctionObjArgs(ctypes_cast, ptr_as_c_void_p, ctypes_int64_p, NULL);
Py_DECREF(ptr_as_c_void_p);
return out;
}
PyObject* PyGLM_ToCtypesP(glm::int32* ptr) {
static PyObject* PyGLM_ToCtypesP(glm::int32* ptr) {
PyObject* ptr_as_c_void_p = PyGLM_CtypesVoidP_FromVoidP((void*)ptr);
PyObject* out = PyObject_CallFunctionObjArgs(ctypes_cast, ptr_as_c_void_p, ctypes_int32_p, NULL);
Py_DECREF(ptr_as_c_void_p);
return out;
}
PyObject* PyGLM_ToCtypesP(glm::int16* ptr) {
static PyObject* PyGLM_ToCtypesP(glm::int16* ptr) {
PyObject* ptr_as_c_void_p = PyGLM_CtypesVoidP_FromVoidP((void*)ptr);
PyObject* out = PyObject_CallFunctionObjArgs(ctypes_cast, ptr_as_c_void_p, ctypes_int16_p, NULL);
Py_DECREF(ptr_as_c_void_p);
return out;
}
PyObject* PyGLM_ToCtypesP(glm::int8* ptr) {
static PyObject* PyGLM_ToCtypesP(glm::int8* ptr) {
PyObject* ptr_as_c_void_p = PyGLM_CtypesVoidP_FromVoidP((void*)ptr);
PyObject* out = PyObject_CallFunctionObjArgs(ctypes_cast, ptr_as_c_void_p, ctypes_int8_p, NULL);
Py_DECREF(ptr_as_c_void_p);
return out;
}
PyObject* PyGLM_ToCtypesP(glm::uint64* ptr) {
static PyObject* PyGLM_ToCtypesP(glm::uint64* ptr) {
PyObject* ptr_as_c_void_p = PyGLM_CtypesVoidP_FromVoidP((void*)ptr);
PyObject* out = PyObject_CallFunctionObjArgs(ctypes_cast, ptr_as_c_void_p, ctypes_uint64_p, NULL);
Py_DECREF(ptr_as_c_void_p);
return out;
}
PyObject* PyGLM_ToCtypesP(glm::uint32* ptr) {
static PyObject* PyGLM_ToCtypesP(glm::uint32* ptr) {
PyObject* ptr_as_c_void_p = PyGLM_CtypesVoidP_FromVoidP((void*)ptr);
PyObject* out = PyObject_CallFunctionObjArgs(ctypes_cast, ptr_as_c_void_p, ctypes_uint32_p, NULL);
Py_DECREF(ptr_as_c_void_p);
return out;
}
PyObject* PyGLM_ToCtypesP(glm::uint16* ptr) {
static PyObject* PyGLM_ToCtypesP(glm::uint16* ptr) {
PyObject* ptr_as_c_void_p = PyGLM_CtypesVoidP_FromVoidP((void*)ptr);
PyObject* out = PyObject_CallFunctionObjArgs(ctypes_cast, ptr_as_c_void_p, ctypes_uint16_p, NULL);
Py_DECREF(ptr_as_c_void_p);
return out;
}
PyObject* PyGLM_ToCtypesP(glm::uint8* ptr) {
static PyObject* PyGLM_ToCtypesP(glm::uint8* ptr) {
PyObject* ptr_as_c_void_p = PyGLM_CtypesVoidP_FromVoidP((void*)ptr);
PyObject* out = PyObject_CallFunctionObjArgs(ctypes_cast, ptr_as_c_void_p, ctypes_uint8_p, NULL);
Py_DECREF(ptr_as_c_void_p);
return out;
}
PyObject* PyGLM_ToCtypesP(bool* ptr) {
static PyObject* PyGLM_ToCtypesP(bool* ptr) {
PyObject* ptr_as_c_void_p = PyGLM_CtypesVoidP_FromVoidP((void*)ptr);
PyObject* out = PyObject_CallFunctionObjArgs(ctypes_cast, ptr_as_c_void_p, ctypes_bool_p, NULL);
Py_DECREF(ptr_as_c_void_p);
return out;
}
PyObject* PyGLM_ToCtypesP(void* ptr) {
static PyObject* PyGLM_ToCtypesP(void* ptr) {
PyObject* ptr_as_c_void_p = PyGLM_CtypesVoidP_FromVoidP(ptr);
return ptr_as_c_void_p;
}
Expand Down
26 changes: 13 additions & 13 deletions PyGLM/internal_functions/number_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "../compiler_setup.h"

PyObject* PyGLM_GetNumber(PyObject* arg) {
static PyObject* PyGLM_GetNumber(PyObject* arg) {
if (arg->ob_type->tp_as_number->nb_float != NULL) {
return PyNumber_Float(arg);
}
Expand All @@ -16,7 +16,7 @@ PyObject* PyGLM_GetNumber(PyObject* arg) {
return NULL;
}

bool PyGLM_TestNumber(PyObject* arg) {
static bool PyGLM_TestNumber(PyObject* arg) {
PyObject* num = PyGLM_GetNumber(arg);

if (num == NULL) {
Expand All @@ -27,7 +27,7 @@ bool PyGLM_TestNumber(PyObject* arg) {
return true;
}

unsigned long PyLong_AsUnsignedLongAndOverflow(PyObject* arg, int* overflow) {
static unsigned long PyLong_AsUnsignedLongAndOverflow(PyObject* arg, int* overflow) {
unsigned long out = PyLong_AsUnsignedLong(arg);
if (PyErr_Occurred()) {
PyErr_Clear();
Expand All @@ -39,7 +39,7 @@ unsigned long PyLong_AsUnsignedLongAndOverflow(PyObject* arg, int* overflow) {
return out;
}

unsigned long long PyLong_AsUnsignedLongLongAndOverflow(PyObject* arg, int* overflow) {
static unsigned long long PyLong_AsUnsignedLongLongAndOverflow(PyObject* arg, int* overflow) {
unsigned long long out = PyLong_AsUnsignedLongLong(arg);
if (PyErr_Occurred()) {
PyErr_Clear();
Expand All @@ -51,7 +51,7 @@ unsigned long long PyLong_AsUnsignedLongLongAndOverflow(PyObject* arg, int* over
return out;
}

int PyLong_Sign(PyObject* arg) {
static int PyLong_Sign(PyObject* arg) {
int overflow;
long l = PyLong_AsLongAndOverflow(arg, &overflow);
if (overflow) {
Expand All @@ -65,7 +65,7 @@ int PyLong_Sign(PyObject* arg) {
#define PyGLM_Number_Check(arg) (PyFloat_Check(arg) || PyLong_Check(arg) || PyBool_Check(arg) || (PyGLM_COULD_BE_NUMBER(arg) &&PyGLM_TestNumber(arg)))

template<typename T>
T _PyGLM_Long_As_Number_No_Error(PyObject* arg) {
static T _PyGLM_Long_As_Number_No_Error(PyObject* arg) {
if (std::numeric_limits<T>::is_iec559) {
int overflow;
long long ll;
Expand Down Expand Up @@ -121,7 +121,7 @@ T _PyGLM_Long_As_Number_No_Error(PyObject* arg) {
return static_cast<T>(PyLong_AsUnsignedLongLongMask(arg));
}

double PyGLM_Number_AsDouble(PyObject* arg) {
static double PyGLM_Number_AsDouble(PyObject* arg) {
if (PyFloat_Check(arg)) {
return PyFloat_AS_DOUBLE(arg);
}
Expand All @@ -141,7 +141,7 @@ double PyGLM_Number_AsDouble(PyObject* arg) {
return -1.0;
}

long PyGLM_Number_AsLong(PyObject* arg) {
static long PyGLM_Number_AsLong(PyObject* arg) {
if (PyLong_Check(arg)) {
return _PyGLM_Long_As_Number_No_Error<long>(arg);
}
Expand All @@ -161,7 +161,7 @@ long PyGLM_Number_AsLong(PyObject* arg) {
return -1l;
}

unsigned long PyGLM_Number_AsUnsignedLong(PyObject* arg) {
static unsigned long PyGLM_Number_AsUnsignedLong(PyObject* arg) {
if (PyLong_Check(arg)) {
return _PyGLM_Long_As_Number_No_Error<unsigned long>(arg);
}
Expand All @@ -181,7 +181,7 @@ unsigned long PyGLM_Number_AsUnsignedLong(PyObject* arg) {
return (unsigned long) - 1l;
}

long long PyGLM_Number_AsLongLong(PyObject* arg) {
static long long PyGLM_Number_AsLongLong(PyObject* arg) {
if (PyLong_Check(arg)) {
return _PyGLM_Long_As_Number_No_Error<long long>(arg);
}
Expand All @@ -201,7 +201,7 @@ long long PyGLM_Number_AsLongLong(PyObject* arg) {
return -1ll;
}

unsigned long long PyGLM_Number_AsUnsignedLongLong(PyObject* arg) {
static unsigned long long PyGLM_Number_AsUnsignedLongLong(PyObject* arg) {
if (PyLong_Check(arg)) {
return _PyGLM_Long_As_Number_No_Error<unsigned long long>(arg);
}
Expand All @@ -221,7 +221,7 @@ unsigned long long PyGLM_Number_AsUnsignedLongLong(PyObject* arg) {
return (unsigned long long)-1ll;
}

bool PyGLM_Number_AsBool(PyObject* arg) {
static bool PyGLM_Number_AsBool(PyObject* arg) {
if (PyBool_Check(arg)) {
return (arg == Py_True) ? true : false;
}
Expand All @@ -241,7 +241,7 @@ bool PyGLM_Number_AsBool(PyObject* arg) {
return false;
}

float PyGLM_Number_AsFloat(PyObject* arg) {
static float PyGLM_Number_AsFloat(PyObject* arg) {
if (PyFloat_Check(arg)) {
return (float)PyFloat_AS_DOUBLE(arg);
}
Expand Down
Loading

0 comments on commit 552e68f

Please sign in to comment.