I'm building a C library for python using "python.h", I succefully made one for adding two numbers, build-it and install-it. But now I want to add those numbers using inline asm code in C. But when I build the C file with my setup.py, it gives me an error. Does anyone made something like this and probabily have a solutions? Or do you have another ideas for making it.
Here is my hectorASMmodule.c
#include <Python.h>
#include <stdio.h>
static PyObject *hectorASM_ADD(PyObject *self, PyObject *args) {
int num1, num2;
if (!PyArg_ParseTuple(args, "ii", &num1, &num2)) {
return NULL;
}
// int res = num1 + num2;
int res = 0;
__asm__("add %%ebx, %%eax;" : "=a"(res) : "a"(num1), "b"(num2));
return Py_BuildValue("i", res);
}
static PyMethodDef hectorASM_methods[] = {
// "PythonName" C-function Name argument presentation description
{"ADD", hectorASM_ADD, METH_VARARGS, "Add two integers"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
static PyModuleDef hectorASM_module = {
PyModuleDef_HEAD_INIT,
"hectorASM",
"My own ASM functions for python",
0,
hectorASM_methods
};
PyMODINIT_FUNC PyInit_hectorASM() {
return PyModule_Create(&hectorASM_module);
}
And here is my setup.py
from distutils.core import setup, Extension, DEBUG
module1 = Extension(
'hectorASM',
sources = ['hectorASMmodule.c']
)
setup (
name = 'hectorASM',
version = '1.0',
description = 'My own ASM functions for python',
author = 'hectorrdz98',
url = 'http://sasukector.com',
ext_modules = [module1]
)
Here is the error I got when running python setup.py build
it says that 'asm' is not defined.
hectorASMmodule.c
hectorASMmodule.c(11): warning C4013: '__asm__' sin definir; se supone que extern devuelve como resultado int
hectorASMmodule.c(11): error C2143: error de sintaxis: falta ')' delante de ':'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2