dev C
This commit is contained in:
parent
d2e4c2f706
commit
aa9c80b1f4
12
Difficult_Rocket/utils/cprint/build.ps1
Normal file
12
Difficult_Rocket/utils/cprint/build.ps1
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
Write-Output ==========_win-py3.8_==========
|
||||||
|
python3.8.exe ./setup.py build
|
||||||
|
|
||||||
|
Write-Output ==========_win-py3.10_==========
|
||||||
|
python3.10.exe ./setup.py build
|
||||||
|
|
||||||
|
Write-Output ==========_wsl-py3.8_==========
|
||||||
|
wsl.exe python3 setup.py build
|
||||||
|
|
||||||
|
Write-Output ==========_wsl-py3.10_==========
|
||||||
|
wsl.exe python3.10 setup.py build
|
@ -3,6 +3,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#define PY_SSIZE_T_CLEAN
|
#define PY_SSIZE_T_CLEAN
|
||||||
|
#define Py_size long long int
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@ -15,12 +16,49 @@ static PyObject *pycprint_print(PyObject *self, PyObject *args){
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Py_UCS4 *get_ucs4from_unicode(PyObject *unicode){
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
static PyObject *pycpint_printf(PyObject *self, PyObject *args, PyObject *kwargs){
|
static PyObject *pycpint_printf(PyObject *self, PyObject *args, PyObject *kwargs){
|
||||||
PyObject *a;
|
printf("args == NULL: %d\n", args == NULL);
|
||||||
if(!PyArg_ParseTuple(args, "O", &a)){
|
printf("kwargs == NULL: %d\n", kwargs == NULL);
|
||||||
return NULL;
|
|
||||||
|
const char *end = "\n";
|
||||||
|
const char *sep = " ";
|
||||||
|
|
||||||
|
if (args != NULL){ // 传入了字符串
|
||||||
|
Py_ssize_t text_len = PyTuple_Size(args); // 获取字符串的长度
|
||||||
|
PyObject *cache_obj; // 创建一个缓存
|
||||||
|
|
||||||
|
for (Py_ssize_t i = 0; i < text_len; i++){ // for 遍历
|
||||||
|
cache_obj = PyTuple_GetItem(args, i); // 获取一个字符串
|
||||||
|
if (cache_obj == NULL){ return NULL; }; // 出毛病了就报错
|
||||||
|
if (PyUnicode_Check(cache_obj) == 1) { // 他不是个字符串(实际上如果有pyi文件就不需要这个检查)
|
||||||
|
|
||||||
|
} else if (PyList_Check(cache_obj) == 1) {
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
printf("text_len = %lld\n", (Py_size)text_len);
|
||||||
|
|
||||||
};
|
};
|
||||||
Py_ssize_t text_len = PyTuple_Size(args);
|
if(kwargs != NULL){ // 传入了 end 或者 sep
|
||||||
|
Py_ssize_t kwargs_len = PyDict_Size(kwargs);
|
||||||
|
printf("kwargs_len = %lld\n", (Py_size) kwargs_len);;
|
||||||
|
if(PyDict_Contains(kwargs, PyUnicode_FromString("end"))){ // 如果包含 end 的参数
|
||||||
|
PyObject *end_unicode; // 整个缓存
|
||||||
|
end_unicode = PyDict_GetItemString(kwargs, "end"); // 先获取出来 Pyobj
|
||||||
|
if(!PyUnicode_READY(end_unicode)){ return NULL; }; // 确认这个字符串对象可以用宏
|
||||||
|
|
||||||
|
Py_ssize_t end_unicode_len = PyUnicode_GetLength(end_unicode); // 缓存一手长度
|
||||||
|
Py_UCS4 *new_end = malloc(sizeof(char) * end_unicode_len); // 提前分配好不定长度的字符串内存
|
||||||
|
for (Py_ssize_t i = 0; i < end_unicode_len; i++){
|
||||||
|
new_end[i] = PyUnicode_ReadChar(end_unicode, i); // 每一位对应读取
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
printf("%s", end);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,4 +6,12 @@
|
|||||||
|
|
||||||
from build import pycprint
|
from build import pycprint
|
||||||
|
|
||||||
pycprint.print("aaa\n")
|
pycprint.print("a啊a\n")
|
||||||
|
|
||||||
|
pycprint.printf("a啊a\n", "aaa", "aaa", end='')
|
||||||
|
|
||||||
|
print()
|
||||||
|
|
||||||
|
pycprint.printf()
|
||||||
|
|
||||||
|
pycprint.printf("aaa\n", "aaa", "aaa")
|
||||||
|
@ -5,3 +5,5 @@
|
|||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
|
||||||
def print(text: str) -> None: ... # 直接调用fprint
|
def print(text: str) -> None: ... # 直接调用fprint
|
||||||
|
|
||||||
|
def printf(text: str) -> None: ... # 测试中
|
||||||
|
15
Difficult_Rocket/utils/cprint/test.ps1
Normal file
15
Difficult_Rocket/utils/cprint/test.ps1
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
Write-Output ---------------------开始测试---------------------
|
||||||
|
|
||||||
|
Write-Output ==========_win-py3.8_==========
|
||||||
|
python3.8.exe ./py_cprint.py
|
||||||
|
|
||||||
|
Write-Output ==========_win-py3.10_==========
|
||||||
|
python3.10.exe ./py_cprint.py
|
||||||
|
|
||||||
|
Write-Output ==========_wsl-py3.8_==========
|
||||||
|
wsl.exe python3 py_cprint.py
|
||||||
|
|
||||||
|
Write-Output ==========_wsl-py3.10_==========
|
||||||
|
wsl.exe python3.10 ./py_cprint.py
|
||||||
|
|
||||||
|
Write-Output ---------------------结束测试---------------------
|
Loading…
Reference in New Issue
Block a user