Skip to content

Commit

Permalink
Add core functions in python C extensions.
Browse files Browse the repository at this point in the history
Add common functions to a single file reused by all C extensions.
  • Loading branch information
MilanSkocic committed Oct 24, 2024
1 parent 7aba4ce commit 31f96b2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
10 changes: 6 additions & 4 deletions py/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,29 @@


if __name__ == "__main__":

core_src = f"./src/py{name:s}/_core.c"

mod_g704 = Extension(name=f"py{name:s}._g704",
sources=[f"./src/py{name:s}/_g704.c"],
sources=[f"./src/py{name:s}/_g704.c", core_src],
libraries=libraries,
library_dirs=library_dirs,
runtime_library_dirs=runtime_library_dirs,
extra_objects=extra_objects)
mod_r283 = Extension(name=f"py{name:s}._r283",
sources=[f"./src/py{name:s}/_r283.c"],
sources=[f"./src/py{name:s}/_r283.c", core_src],
libraries=libraries,
library_dirs=library_dirs,
runtime_library_dirs=runtime_library_dirs,
extra_objects=extra_objects)
mod_r797 = Extension(name=f"py{name:s}._r797",
sources=[f"./src/py{name:s}/_r797.c"],
sources=[f"./src/py{name:s}/_r797.c", core_src],
libraries=libraries,
library_dirs=library_dirs,
runtime_library_dirs=runtime_library_dirs,
extra_objects=extra_objects)
mod_version = Extension(name=f"py{name:s}._version",
sources=[f"./src/py{name:s}/_version.c"],
sources=[f"./src/py{name:s}/_version.c", core_src],
libraries=libraries,
library_dirs=library_dirs,
runtime_library_dirs=runtime_library_dirs,
Expand Down
17 changes: 17 additions & 0 deletions py/src/pyiapws/_core.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "_core.h"

Py_buffer newbuffer_like(Py_buffer *buffer){
Py_buffer newbuffer;
newbuffer.buf = PyMem_Malloc(buffer->len);
newbuffer.obj = NULL;
newbuffer.len = buffer->len;
newbuffer.readonly = buffer->readonly;
newbuffer.itemsize = buffer->itemsize;
newbuffer.format = buffer->format;
newbuffer.ndim = buffer->ndim;
newbuffer.shape = buffer->shape;
newbuffer.strides = buffer->strides;
newbuffer.suboffsets = NULL;

return newbuffer;
}
11 changes: 11 additions & 0 deletions py/src/pyiapws/_core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef _CORE_H
#define _CORE_H
#include <Python.h>
#include <stdio.h>
#include <string.h>
#include "iapws.h"

Py_buffer newbuffer_like(Py_buffer *buffer);


#endif

0 comments on commit 31f96b2

Please sign in to comment.