Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.measure
Commits
be45a924
Commit
be45a924
authored
Jan 29, 2014
by
André Anjos
💬
Browse files
Cleanup, Python 3 support
parent
304bb4c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
xbob/measure/cleanup.h
deleted
100644 → 0
View file @
304bb4c3
/**
* @author Andre Anjos <andre.anjos@idiap.ch>
* @date Wed 11 Dec 08:42:53 2013
*
* @brief Some C++ tricks to make our life dealing with Python references a bit
* easier
*/
#include
<Python.h>
#include
<memory>
/**
* Calls Py_DECREF(x) on the input object x. Usage pattern:
*
* PyObject* x = ... // builds x with a new python reference
* auto protected_x = make_safe(x);
*
* After this point, no need to worry about DECREF'ing x anymore.
* You can still use `x' inside your code, or protected_x.get().
*/
template
<
typename
T
>
std
::
shared_ptr
<
T
>
make_safe
(
T
*
o
)
{
return
std
::
shared_ptr
<
T
>
(
o
,
[
&
](
T
*
p
){
Py_DECREF
(
p
);});
}
/**
* Calls Py_XDECREF(x) on the input object x. Usage pattern:
*
* PyObject* x = ... // builds x with a new python reference, x may be NULL
* auto protected_x = make_xsafe(x);
*
* After this point, no need to worry about XDECREF'ing x anymore.
* You can still use `x' inside your code, or protected_x.get(). Note
* `x' may be NULL with this method.
*/
template
<
typename
T
>
std
::
shared_ptr
<
T
>
make_xsafe
(
T
*
o
)
{
return
std
::
shared_ptr
<
T
>
(
o
,
[
&
](
T
*
p
){
Py_XDECREF
(
p
);});
}
xbob/measure/main.cpp
View file @
be45a924
...
...
@@ -5,11 +5,11 @@
* @brief Bindings to bob::io
*/
#include
"cleanup.h"
#ifdef NO_IMPORT_ARRAY
#undef NO_IMPORT_ARRAY
#endif
#include
<xbob.blitz/cppapi.h>
#include
<xbob.blitz/cleanup.h>
#include
<bob/measure/error.h>
static
int
double1d_converter
(
PyObject
*
o
,
PyBlitzArrayObject
**
a
)
{
...
...
@@ -1085,27 +1085,30 @@ static PyModuleDef module_definition = {
};
#endif
PyMODINIT_FUNC
XBOB_EXT_ENTRY_NAME
(
void
)
{
static
PyObject
*
create_module
(
void
)
{
# if PY_VERSION_HEX >= 0x03000000
PyObject
*
m
=
PyModule_Create
(
&
module_definition
);
if
(
!
m
)
return
0
;
# else
PyObject
*
m
=
Py_InitModule3
(
XBOB_EXT_MODULE_NAME
,
module_methods
,
module_docstr
);
if
(
!
m
)
return
;
PyObject
*
m
=
Py_InitModule3
(
XBOB_EXT_MODULE_NAME
,
module_methods
,
module_docstr
);
# endif
if
(
!
m
)
return
0
;
auto
m_
=
make_safe
(
m
);
///< protects against early returns
PyModule_AddStringConstant
(
m
,
"__version__"
,
XBOB_EXT_MODULE_VERSION
);
if
(
PyModule_AddStringConstant
(
m
,
"__version__"
,
XBOB_EXT_MODULE_VERSION
)
<
0
)
return
0
;
/* imports
the NumPy C-API
*/
import_
array
()
;
/* imports
xbob.blitz C-API + dependencies
*/
if
(
import_
xbob_blitz
()
<
0
)
return
0
;
/* imports xbob.blitz C-API */
import_xbob_blitz
()
;
Py_INCREF
(
m
);
return
m
;
}
PyMODINIT_FUNC
XBOB_EXT_ENTRY_NAME
(
void
)
{
# if PY_VERSION_HEX >= 0x03000000
return
m
;
return
# endif
create_module
();
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment