From b48bd67c23bc6dcc4e906baf6771ab8ce5e8a185 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Tue, 21 May 2024 06:10:32 +0800 Subject: [PATCH] use limited api --- src/bencode_c/bencode.c | 44 +---------------------------------------- src/bencode_c/common.h | 2 +- src/bencode_c/decode.h | 5 ----- src/bencode_c/encode.h | 1 - 4 files changed, 2 insertions(+), 50 deletions(-) diff --git a/src/bencode_c/bencode.c b/src/bencode_c/bencode.c index 579df1c..e8788d3 100644 --- a/src/bencode_c/bencode.c +++ b/src/bencode_c/bencode.c @@ -1,51 +1,9 @@ -#include "Python.h" +#define Py_LIMITED_API 0x03080000 // TODO: should use a extern here #include "decode.h" #include "encode.h" -// extern HPyDef bencode; - -// static PyObject *bdecode(PyObject *self, PyObject *obj); - -// extern HPyGlobal BencodeDecodeError; -// extern HPyGlobal BencodeEncodeError; - -// static bool init_exception(HPyContext *ctx, HPy mod, HPyGlobal *global, -// const char *name, const char *attr_name) { -// HPy h = HPyErr_NewException(ctx, name, HPy_NULL, HPy_NULL); -// if (HPy_IsNull(h)) { -// return false; -// } -// HPyGlobal_Store(ctx, global, h); -// int set_attr_failed = HPy_SetAttr_s(ctx, mod, attr_name, h); -// HPy_Close(ctx, h); -// return !set_attr_failed; -// } - -// bool init_exceptions(HPyContext *ctx, HPy mod) { -// init_exception(ctx, mod, &BencodeDecodeError, -// "_bencode.BencodeDecodeError", -// "BencodeDecodeError"); -// return init_exception(ctx, mod, &BencodeEncodeError, -// "_bencode.BencodeEncodeError", "BencodeEncodeError"); -// // return true; -// } - -// HPyDef_SLOT(bencode_exec, -// HPy_mod_exec) static int bencode_exec_impl(HPyContext *ctx, -// HPy module) { -// if (!init_exceptions(ctx, module)) { -// HPyErr_SetString(ctx, ctx->h_RuntimeError, "failed to init exceptions"); -// return 1; -// } -// return 0; -// } - -// static HPyDef *module_defines[] = {&bencode_exec, &bdecode, &bencode, NULL}; - -// module's method table - static PyMethodDef DemoMethods[] = { {"bencode", bencode, METH_O, "encode python object to bytes"}, {"bdecode", bdecode, METH_O, "decode bytes to python object"}, diff --git a/src/bencode_c/common.h b/src/bencode_c/common.h index bc3c644..c8690a0 100644 --- a/src/bencode_c/common.h +++ b/src/bencode_c/common.h @@ -1,4 +1,4 @@ -#define Py_LIMITED_API 0x03080000 +#include "Python.h" #ifndef MY_COMMON_H diff --git a/src/bencode_c/decode.h b/src/bencode_c/decode.h index cd0abe7..8b89dce 100644 --- a/src/bencode_c/decode.h +++ b/src/bencode_c/decode.h @@ -1,8 +1,3 @@ -// #include -// #include - -#include "Python.h" - #include "common.h" static PyObject *BencodeDecodeError; diff --git a/src/bencode_c/encode.h b/src/bencode_c/encode.h index 827e268..99ee1ae 100644 --- a/src/bencode_c/encode.h +++ b/src/bencode_c/encode.h @@ -1,7 +1,6 @@ #include "stdio.h" #include "string.h" -#include "Python.h" #include "common.h" static PyObject *BencodeEncodeError;