-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPyFunc.cpp
More file actions
59 lines (48 loc) · 1.39 KB
/
PyFunc.cpp
File metadata and controls
59 lines (48 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Copyright (c) 2019, Lawrence Livermore National Security, LLC.
*
* Produced at the Lawrence Livermore National Laboratory
*
* LLNL-CODE-746361
*
* All rights reserved. See COPYRIGHT for details.
*
* This file is part of the GEOSX Simulation Framework.
*
* GEOSX is a free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License (as published by the
* Free Software Foundation) version 2.1 dated February 1999.
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
// Python must be the first include.
#define PY_SSIZE_T_CLEAN
#include <Python.h>
// Source includes
#include "PyFunc.hpp"
namespace LvArray
{
namespace python
{
namespace internal
{
bool err()
{ return PyErr_Occurred() != nullptr; }
void callPyFunc( PyObject * func, PyObjectRef<> * args, long long const argc )
{
Py_ssize_t const argc_ssize = static_cast< Py_ssize_t >( argc );
PyObjectRef<> tup{ PyTuple_New( argc_ssize ) };
if( tup == nullptr )
{
return;
}
for( Py_ssize_t i = 0; i < argc_ssize; ++i )
{
// The references get stolen by PyObject_CallObject.
PyTuple_SET_ITEM( tup.get(), i, args[ i ].release() );
}
Py_XDECREF( PyObject_CallObject( func, tup.get() ) );
}
} // namespace internal
} // namespace python
} // namespace LvArray