Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
use limited api
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed May 20, 2024
1 parent 136a1e6 commit b48bd67
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 50 deletions.
44 changes: 1 addition & 43 deletions src/bencode_c/bencode.c
Original file line number Diff line number Diff line change
@@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion src/bencode_c/common.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define Py_LIMITED_API 0x03080000
#include "Python.h"

#ifndef MY_COMMON_H

Expand Down
5 changes: 0 additions & 5 deletions src/bencode_c/decode.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// #include <stdio.h>
// #include <string.h>

#include "Python.h"

#include "common.h"

static PyObject *BencodeDecodeError;
Expand Down
1 change: 0 additions & 1 deletion src/bencode_c/encode.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "stdio.h"
#include "string.h"

#include "Python.h"
#include "common.h"

static PyObject *BencodeEncodeError;
Expand Down

0 comments on commit b48bd67

Please sign in to comment.