-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
1,215 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ htmlcov/ | |
.coverage | ||
.coverage.* | ||
.cache | ||
.pytest_cache/ | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ Calling routines in Windows DLLs from Python scripts running on unixlike systems | |
Required to run on platform / side: [WINE] | ||
Copyright (C) 2017 Sebastian M. Ernst <[email protected]> | ||
Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
<LICENSE_BLOCK> | ||
The contents of this file are subject to the GNU Lesser General Public License | ||
|
@@ -112,6 +112,18 @@ double __stdcall DEMODLL cookbook_distance( | |
} | ||
|
||
|
||
/* Function involving a C data structure - returning a pointer to a variable */ | ||
double __stdcall DEMODLL *cookbook_distance_pointer( | ||
cookbook_point *p1, | ||
cookbook_point *p2 | ||
) | ||
{ | ||
double *distance_p = (double *)malloc(sizeof(double)); | ||
*distance_p = hypot(p1->x - p2->x, p1->y - p2->y); | ||
return distance_p; | ||
} | ||
|
||
|
||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
// zugbruecke demo | ||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
@@ -187,6 +199,37 @@ void __stdcall DEMODLL gauss_elimination( | |
} | ||
|
||
|
||
vector3d __stdcall DEMODLL *vector3d_add( | ||
vector3d *v1, | ||
vector3d *v2 | ||
) | ||
{ | ||
|
||
vector3d *v3 = malloc(sizeof(vector3d)); | ||
|
||
v3->x = v1->x + v2->x; | ||
v3->y = v1->y + v2->y; | ||
v3->z = v1->z + v2->z; | ||
|
||
return v3; | ||
|
||
} | ||
|
||
|
||
int16_t __stdcall DEMODLL sqrt_int( | ||
int16_t a | ||
) | ||
{ | ||
return a * a; | ||
} | ||
|
||
|
||
int16_t __stdcall DEMODLL get_const_int(void) | ||
{ | ||
return sqrt(49); | ||
} | ||
|
||
|
||
float __stdcall DEMODLL simple_demo_routine( | ||
float param_a, | ||
float param_b | ||
|
@@ -221,6 +264,29 @@ void __stdcall DEMODLL complex_demo_routine( | |
} | ||
|
||
|
||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
// zugbruecke demo: callback | ||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
||
int16_t __stdcall DEMODLL sum_elements_from_callback( | ||
int16_t len, | ||
conveyor_belt get_data | ||
) | ||
{ | ||
|
||
int16_t sum = 0; | ||
int16_t i; | ||
|
||
for(i = 0; i < len; i++) | ||
{ | ||
sum += get_data(i); | ||
} | ||
|
||
return sum; | ||
|
||
} | ||
|
||
|
||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
// DLL infrastructure | ||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ Calling routines in Windows DLLs from Python scripts running on unixlike systems | |
Required to run on platform / side: [WINE] | ||
Copyright (C) 2017 Sebastian M. Ernst <[email protected]> | ||
Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
<LICENSE_BLOCK> | ||
The contents of this file are subject to the GNU Lesser General Public License | ||
|
@@ -88,6 +88,10 @@ double __stdcall DEMODLL cookbook_distance( | |
cookbook_point *p2 | ||
); | ||
|
||
double __stdcall DEMODLL *cookbook_distance_pointer( | ||
cookbook_point *p1, | ||
cookbook_point *p2 | ||
); | ||
|
||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
// zugbruecke demo | ||
|
@@ -109,6 +113,21 @@ void __stdcall DEMODLL gauss_elimination( | |
float (*x)[3] | ||
); | ||
|
||
typedef struct vector3d { | ||
int16_t x, y, z; | ||
} vector3d; | ||
|
||
vector3d __stdcall DEMODLL *vector3d_add( | ||
vector3d *p1, | ||
vector3d *p2 | ||
); | ||
|
||
int16_t __stdcall DEMODLL sqrt_int( | ||
int16_t a | ||
); | ||
|
||
int16_t __stdcall DEMODLL get_const_int(void); | ||
|
||
struct test | ||
{ | ||
char el_char; | ||
|
@@ -132,6 +151,18 @@ void __stdcall DEMODLL complex_demo_routine( | |
); | ||
|
||
|
||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
// zugbruecke demo: callback | ||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
||
typedef int16_t __stdcall (*conveyor_belt)(int16_t index); | ||
|
||
int16_t __stdcall DEMODLL sum_elements_from_callback( | ||
int16_t len, | ||
conveyor_belt get_data | ||
); | ||
|
||
|
||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
// DLL infrastructure | ||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# | ||
# Required to run on platform / side: [UNIX] | ||
# | ||
# Copyright (C) 2017 Sebastian M. Ernst <[email protected]> | ||
# Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
# | ||
# <LICENSE_BLOCK> | ||
# The contents of this file are subject to the GNU Lesser General Public License | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# | ||
# Required to run on platform / side: [UNIX] | ||
# | ||
# Copyright (C) 2017 Sebastian M. Ernst <[email protected]> | ||
# Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
# | ||
# <LICENSE_BLOCK> | ||
# The contents of this file are subject to the GNU Lesser General Public License | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
Required to run on platform / side: [UNIX] | ||
Copyright (C) 2017 Sebastian M. Ernst <[email protected]> | ||
Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
<LICENSE_BLOCK> | ||
The contents of this file are subject to the GNU Lesser General Public License | ||
|
@@ -77,7 +77,7 @@ def fetch_version_string(): | |
|
||
# General information about the project. | ||
project = 'zugbruecke' | ||
copyright = '2017 Sebastian M. Ernst' | ||
copyright = '2017-2018 Sebastian M. Ernst' | ||
author = 'Sebastian M. Ernst' | ||
|
||
# The version info for the project you're documenting, acts as replacement for | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
Required to run on platform / side: [WINE] | ||
Copyright (C) 2017 Sebastian M. Ernst <[email protected]> | ||
Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
<LICENSE_BLOCK> | ||
The contents of this file are subject to the GNU Lesser General Public License | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
ZUGBRUECKE | ||
Calling routines in Windows DLLs from Python scripts running on unixlike systems | ||
https://github.com/pleiszenburg/zugbruecke | ||
examples/test_callback.py: Demonstrates callback routines as arguments | ||
Required to run on platform / side: [UNIX, WINE] | ||
Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
<LICENSE_BLOCK> | ||
The contents of this file are subject to the GNU Lesser General Public License | ||
Version 2.1 ("LGPL" or "License"). You may not use this file except in | ||
compliance with the License. You may obtain a copy of the License at | ||
https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt | ||
https://github.com/pleiszenburg/zugbruecke/blob/master/LICENSE | ||
Software distributed under the License is distributed on an "AS IS" basis, | ||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the | ||
specific language governing rights and limitations under the License. | ||
</LICENSE_BLOCK> | ||
""" | ||
|
||
|
||
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
# IMPORT | ||
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
||
from sys import platform | ||
|
||
if any([platform.startswith(os_name) for os_name in ['linux', 'darwin', 'freebsd']]): | ||
|
||
f = open('.zugbruecke.json', 'w') | ||
f.write('{"log_level": 10}') | ||
f.close() | ||
|
||
import zugbruecke as ctypes | ||
|
||
elif platform.startswith('win'): | ||
|
||
import ctypes | ||
|
||
else: | ||
|
||
raise # TODO unsupported platform | ||
|
||
|
||
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
# RUN | ||
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
||
if __name__ == '__main__': | ||
|
||
DATA = [1, 6, 8, 4, 9, 7, 4, 2, 5, 2] | ||
|
||
conveyor_belt = ctypes.WINFUNCTYPE(ctypes.c_int16, ctypes.c_int16) | ||
|
||
@conveyor_belt | ||
def get_data(index): | ||
print((index, DATA[index])) | ||
return DATA[index] | ||
|
||
dll = ctypes.windll.LoadLibrary('demo_dll.dll') | ||
sum_elements_from_callback = dll.sum_elements_from_callback | ||
sum_elements_from_callback.argtypes = (ctypes.c_int16, conveyor_belt) | ||
sum_elements_from_callback.restype = ctypes.c_int16 | ||
|
||
test_sum = sum_elements_from_callback(len(DATA), get_data) | ||
print(('sum', 48, test_sum)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
Required to run on platform / side: [UNIX, WINE] | ||
Copyright (C) 2017 Sebastian M. Ernst <[email protected]> | ||
Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
<LICENSE_BLOCK> | ||
The contents of this file are subject to the GNU Lesser General Public License | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
Required to run on platform / side: [UNIX, WINE] | ||
Copyright (C) 2017 Sebastian M. Ernst <[email protected]> | ||
Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
<LICENSE_BLOCK> | ||
The contents of this file are subject to the GNU Lesser General Public License | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
Required to run on platform / side: [UNIX, WINE] | ||
Copyright (C) 2017 Sebastian M. Ernst <[email protected]> | ||
Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
<LICENSE_BLOCK> | ||
The contents of this file are subject to the GNU Lesser General Public License | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# | ||
# Required to run on platform / side: [UNIX] | ||
# | ||
# Copyright (C) 2017 Sebastian M. Ernst <[email protected]> | ||
# Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
# | ||
# <LICENSE_BLOCK> | ||
# The contents of this file are subject to the GNU Lesser General Public License | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
# | ||
# Required to run on platform / side: [UNIX] | ||
# | ||
# Copyright (C) 2017 Sebastian M. Ernst <[email protected]> | ||
# Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
# | ||
# <LICENSE_BLOCK> | ||
# The contents of this file are subject to the GNU Lesser General Public License | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
# | ||
# Required to run on platform / side: [UNIX] | ||
# | ||
# Copyright (C) 2017 Sebastian M. Ernst <[email protected]> | ||
# Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
# | ||
# <LICENSE_BLOCK> | ||
# The contents of this file are subject to the GNU Lesser General Public License | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
# | ||
# Required to run on platform / side: [UNIX] | ||
# | ||
# Copyright (C) 2017 Sebastian M. Ernst <[email protected]> | ||
# Copyright (C) 2017-2018 Sebastian M. Ernst <[email protected]> | ||
# | ||
# <LICENSE_BLOCK> | ||
# The contents of this file are subject to the GNU Lesser General Public License | ||
|
Oops, something went wrong.