Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review: Move capsule name macro to header file
  • Loading branch information
Erlend E. Aasland
Erlend E. Aasland committed Jan 5, 2021
commit d54e7d5f9ee038b6a0fa6267fc1bdad8d7e9796a
4 changes: 3 additions & 1 deletion Include/pydecimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ typedef struct {
/* Capsule API */
/****************************************************************************/

#define PyDec_CAPSULE_NAME "_decimal._API"

/* Simple API */
#define PyDec_TypeCheck_INDEX 0
#define PyDec_TypeCheck_RETURN int
Expand Down Expand Up @@ -164,7 +166,7 @@ static void **_decimal_api;
static int
import_decimal(void)
{
_decimal_api = (void **)PyCapsule_Import("_decimal._API", 0);
_decimal_api = (void **)PyCapsule_Import(PyDec_CAPSULE_NAME, 0);
if (_decimal_api == NULL) {
return -1;
}
Expand Down
6 changes: 2 additions & 4 deletions Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -5703,11 +5703,10 @@ free_api(void *capi)
PyMem_Free(capi);
}

#define CAPSULE_NAME "_decimal._API"
static void
destroy_api(PyObject *obj)
{
void *capi = PyCapsule_GetPointer(obj, CAPSULE_NAME);
void *capi = PyCapsule_GetPointer(obj, PyDec_CAPSULE_NAME);
free_api(capi);
}

Expand All @@ -5734,13 +5733,12 @@ init_api(void)
_decimal_api[PyDec_Get_INDEX] = (void *)PyDec_Get;
_decimal_api[PyDec_GetConst_INDEX] = (void *)PyDec_GetConst;

PyObject *capsule = PyCapsule_New(_decimal_api, CAPSULE_NAME, destroy_api);
PyObject *capsule = PyCapsule_New(_decimal_api, PyDec_CAPSULE_NAME, destroy_api);
if (!capsule) {
free_api(_decimal_api);
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
}
return capsule;
}
#undef CAPSULE_NAME


/****************************************************************************/
Expand Down