HL-HDF
pyhlcompat.h File Reference

Python compability file for making it possible to compile rave for both python >2.6 and python3. More...

#include "Python.h"

Go to the source code of this file.

Macros

#define PY_ATTRO_NAME_TO_STRING   PyString_AsString
 
#define PY_COMPARE_ATTRO_NAME_WITH_STRING(ptr, name)   PyHlhdfAPI_CompareWithASCIIString(ptr, name)
 
#define PY_COMPARE_STRING_WITH_ATTRO_NAME(name, ptr)   PyHlhdfAPI_CompareWithASCIIString(ptr, name)
 
#define MOD_INIT_ERROR
 
#define MOD_INIT_SUCCESS(val)
 
#define MOD_INIT(name)   void init##name(void)
 
#define MOD_INIT_DEF(ob, name, doc, methods)    ob = Py_InitModule3(name, methods, doc);
 
#define MOD_INIT_SETUP_TYPE(itype, otype)   itype.ob_type = otype
 
#define MOD_INIT_VERIFY_TYPE_READY(type)
 
#define MOD_DIR_FORWARD_DECLARE(name)   static PyObject* _##name##__dir__(name *self)
 Macros that can be used to simplify way of generating dir content that is necessary for executing dir() on an object.
 
#define MOD_DIR_REFERENCE(name)   _##name##__dir__
 
#define MOD_DIR_APPEND(list, str)
 
#define MOD_DIR_FUNCTION(name, method_listing)
 

Functions

int PyHlhdfAPI_CompareWithASCIIString (PyObject *ptr, const char *name)
 Tests if a python object string (or unicode) is equal to name.
 
PyObject * PyHlhdf_StringOrUnicode_FromASCII (const char *buffer, Py_ssize_t size)
 Tries to get same behaviour for the result returned when getting a string from the data node.
 

Detailed Description

Python compability file for making it possible to compile rave for both python >2.6 and python3.

Author
Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
Date
2017-02-23

Macro Definition Documentation

◆ MOD_DIR_APPEND

#define MOD_DIR_APPEND ( list,
str )
Value:
do { \
PyObject *o = PyUnicode_FromString(str); \
if (o != NULL) \
PyList_Append(list, o); \
Py_XDECREF(o); \
} while (0)

◆ MOD_DIR_FORWARD_DECLARE

#define MOD_DIR_FORWARD_DECLARE ( name)    static PyObject* _##name##__dir__(name *self)

Macros that can be used to simplify way of generating dir content that is necessary for executing dir() on an object.

◆ MOD_DIR_FUNCTION

#define MOD_DIR_FUNCTION ( name,
method_listing )
Value:
static PyObject * _##name##__dir__(name *self) { \
int i=0; \
PyObject* rc = PyList_New(0); \
if (!rc) \
return NULL; \
\
while (method_listing[i].ml_name != NULL) { \
MOD_DIR_APPEND(rc, method_listing[i++].ml_name); \
} \
\
return rc; \
}

Function Documentation

◆ PyHlhdf_StringOrUnicode_FromASCII()

PyObject * PyHlhdf_StringOrUnicode_FromASCII ( const char * buffer,
Py_ssize_t size )

Tries to get same behaviour for the result returned when getting a string from the data node.

For 2.7 PyString_FromStringAndSize is used, for 3.x a variant of _PyUnicode_FromASCII.

◆ PyHlhdfAPI_CompareWithASCIIString()

int PyHlhdfAPI_CompareWithASCIIString ( PyObject * ptr,
const char * name )

Tests if a python object string (or unicode) is equal to name.

Parameters
[in]ptr- the python string or unicode
[in]name- the string to compare with
Returns
0, -1 or 1