Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
nl_private.h File Reference

Some macros and functions used internally by OpenNL. More...

#include "nl.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>

Go to the source code of this file.

Macros

#define NL_DEBUG
 
#define NL_OS_UNIX
 Defined if compiled on a Unix-like platform.
 
#define nl_arg_used(x)   (void)x
 Suppresses unsused argument warnings. More...
 
Memory management
#define NL_NEW(T)   (T*)(calloc(1, sizeof(T)))
 Allocates a new element. More...
 
#define NL_NEW_ARRAY(T, NB)   (T*)(calloc((size_t)(NB),sizeof(T)))
 Allocates a new array of elements. More...
 
#define NL_RENEW_ARRAY(T, x, NB)   (T*)(realloc(x,(size_t)(NB)*sizeof(T)))
 Changes the size of an already allocated array of elements. More...
 
#define NL_DELETE(x)   free(x); x = NULL
 Deallocates an element. More...
 
#define NL_DELETE_ARRAY(x)   free(x); x = NULL
 Deallocates an array. More...
 
#define NL_CLEAR(T, x)   memset(x, 0, sizeof(T))
 Clears an element. More...
 
#define NL_CLEAR_ARRAY(T, x, NB)   memset(x, 0, (size_t)(NB)*sizeof(T))
 Clears an array of elements. More...
 
Integer bounds
#define NL_UINT_MAX   0xffffffff
 Maximum unsigned 32 bits integer.
 
#define NL_USHORT_MAX   0xffff
 Maximum unsigned 16 bits integer.
 

Functions

Error reporting
void nlError (const char *function, const char *message)
 Displays an error message. More...
 
void nlWarning (const char *function, const char *message)
 Displays a warning message. More...
 

Variables

Logging and messages
NLprintfFunc nl_printf
 
NLfprintfFunc nl_fprintf
 

Assertion checks

#define NL_NORETURN   __attribute__((noreturn))
 
#define NL_NORETURN_DECL
 
#define nl_assert(x)
 Tests an assertion and aborts the program if the test fails. More...
 
#define nl_range_assert(x, min_val, max_val)
 Tests a range assertion and aborts the program if the test fails. More...
 
#define nl_assert_not_reached
 Triggers an assertion failure when the execution flow reaches a specific location in the code. More...
 
#define nl_debug_assert(x)   nl_assert(x)
 
#define nl_debug_range_assert(x, min_val, max_val)    nl_range_assert(x,min_val,max_val)
 
#define nl_parano_assert(x)
 
#define nl_parano_range_assert(x, min_val, max_val)
 
NL_NORETURN_DECL void nl_assertion_failed (const char *cond, const char *file, int line) NL_NORETURN
 Displays an error message and aborts the program when an assertion failed. More...
 
NL_NORETURN_DECL void nl_range_assertion_failed (double x, double min_val, double max_val, const char *file, int line) NL_NORETURN
 Displays an error message and aborts the program when a range assertion failed. More...
 
NL_NORETURN_DECL void nl_should_not_have_reached (const char *file, int line) NL_NORETURN
 Displays an error message and aborts the program when the execution flow reached a point it should not have reached. More...
 

OS

#define NL_LINK_NOW   1
 Flag for nlOpenDLL(), resolve all symbols when opening the DLL. More...
 
#define NL_LINK_LAZY   2
 Flag for nlOpenDLL(), resolve symbols only when they are called. More...
 
#define NL_LINK_GLOBAL   4
 Flag for nlOpenDLL(), add all loaded symbols to global namespace.
 
#define NL_LINK_QUIET   8
 Flag for nlOpenDLL(), do not display messages.
 
#define NL_LINK_USE_FALLBACK   16
 Flag for nlOpenDLL(), use fallback geogram numerical library if library is not found in the system.
 
#define MIN(x, y)   (((x) < (y)) ? (x) : (y))
 
#define MAX(x, y)   (((x) > (y)) ? (x) : (y))
 
typedef void * NLdll
 Type for manipulating DLL/shared object/dylib handles.
 
NLdouble nlCurrentTime (void)
 Gets the current time in seconds. More...
 
NLuint nlGetNumCores (void)
 Gets the number of cores. More...
 
NLuint nlGetNumThreads (void)
 Gets the number of threads. More...
 
void nlSetNumThreads (NLuint nb_threads)
 Sets the number of threads. More...
 
NLdll nlOpenDLL (const char *filename, NLenum flags)
 Dynamically links a DLL/shared object/dylib to the current process. More...
 
void nlCloseDLL (NLdll handle)
 Closes a DLL/shared object/dylib. More...
 
NLfunc nlFindFunction (NLdll handle, const char *funcname)
 Finds a function in a DLL/shared object/dylib. More...
 

Detailed Description

Some macros and functions used internally by OpenNL.

Definition in file nl_private.h.

Macro Definition Documentation

◆ nl_arg_used

#define nl_arg_used (   x)    (void)x

Suppresses unsused argument warnings.

Some callbacks do not necessary use all their arguments.

Parameters
[in]xthe argument to be tagged as used

Definition at line 86 of file nl_private.h.

◆ nl_assert

#define nl_assert (   x)
Value:
{ \
if(!(x)) { \
nl_assertion_failed(#x,__FILE__, __LINE__) ; \
} \
}

Tests an assertion and aborts the program if the test fails.

Parameters
[in]xthe condition to be tested

Definition at line 147 of file nl_private.h.

◆ nl_assert_not_reached

#define nl_assert_not_reached
Value:
{ \
nl_should_not_have_reached(__FILE__, __LINE__) ; \
}

Triggers an assertion failure when the execution flow reaches a specific location in the code.

Definition at line 171 of file nl_private.h.

◆ NL_CLEAR

#define NL_CLEAR (   T,
 
)    memset(x, 0, sizeof(T))

Clears an element.

Parameters
[in]Ttype of the element to be cleared
[in,out]xa pointer to the element

Definition at line 365 of file nl_private.h.

◆ NL_CLEAR_ARRAY

#define NL_CLEAR_ARRAY (   T,
  x,
  NB 
)    memset(x, 0, (size_t)(NB)*sizeof(T))

Clears an array of elements.

Parameters
[in]Ttype of the element to be cleared
[in,out]xa pointer to the element
[in]NBnumber of elements

Definition at line 373 of file nl_private.h.

◆ NL_DELETE

#define NL_DELETE (   x)    free(x); x = NULL

Deallocates an element.

Parameters
[in,out]xa pointer to the element to be deallocated

Definition at line 351 of file nl_private.h.

◆ NL_DELETE_ARRAY

#define NL_DELETE_ARRAY (   x)    free(x); x = NULL

Deallocates an array.

Parameters
[in,out]xa pointer to the first element of the array to be deallocated

Definition at line 358 of file nl_private.h.

◆ NL_LINK_LAZY

#define NL_LINK_LAZY   2

Flag for nlOpenDLL(), resolve symbols only when they are called.

See also
nlOpenDLL()

Definition at line 261 of file nl_private.h.

◆ NL_LINK_NOW

#define NL_LINK_NOW   1

Flag for nlOpenDLL(), resolve all symbols when opening the DLL.

See also
nlOpenDLL()

Definition at line 255 of file nl_private.h.

◆ NL_NEW

#define NL_NEW (   T)    (T*)(calloc(1, sizeof(T)))

Allocates a new element.

Memory is zeroed after allocation

Parameters
[in]Ttype of the element to be allocated

Definition at line 328 of file nl_private.h.

◆ NL_NEW_ARRAY

#define NL_NEW_ARRAY (   T,
  NB 
)    (T*)(calloc((size_t)(NB),sizeof(T)))

Allocates a new array of elements.

Memory is zeroed after allocation

Parameters
[in]Ttype of the elements
[in]NBnumber of elements

Definition at line 336 of file nl_private.h.

◆ nl_range_assert

#define nl_range_assert (   x,
  min_val,
  max_val 
)
Value:
{ \
if(((int)(x) < (int)(min_val)) || ((int)(x) > (int)(max_val))) { \
nl_range_assertion_failed(x, min_val, max_val, \
__FILE__, __LINE__ \
) ; \
} \
}

Tests a range assertion and aborts the program if the test fails.

Parameters
[in]xthe variable to be tested
[in]min_valthe minimum admissible value for the variable
[in]max_valthe maximum admissible value for the variable

Definition at line 159 of file nl_private.h.

◆ NL_RENEW_ARRAY

#define NL_RENEW_ARRAY (   T,
  x,
  NB 
)    (T*)(realloc(x,(size_t)(NB)*sizeof(T)))

Changes the size of an already allocated array of elements.

Memory is zeroed after allocation

Parameters
[in]Ttype of the elements
[in,out]xa pointer to the array to be resized
[in]NBnumber of elements

Definition at line 345 of file nl_private.h.

Function Documentation

◆ nl_assertion_failed()

NL_NORETURN_DECL void nl_assertion_failed ( const char *  cond,
const char *  file,
int  line 
)

Displays an error message and aborts the program when an assertion failed.

Called by nl_assert() whenever the assertion failed

Parameters
[in]condthe textual representation of the condition
[in]filethe source filename
[in]linethe line number

◆ nl_range_assertion_failed()

NL_NORETURN_DECL void nl_range_assertion_failed ( double  x,
double  min_val,
double  max_val,
const char *  file,
int  line 
)

Displays an error message and aborts the program when a range assertion failed.

Called by nl_range_assert() whenever the assertion failed

Parameters
[in]xthe variable
[in]min_valthe minimum value
[in]max_valthe maximum value
[in]filethe source filename
[in]linethe line number

◆ nl_should_not_have_reached()

NL_NORETURN_DECL void nl_should_not_have_reached ( const char *  file,
int  line 
)

Displays an error message and aborts the program when the execution flow reached a point it should not have reached.

called by nl_assert_not_reached

Parameters
[in]filethe source filename
[in]linethe line number

◆ nlCloseDLL()

void nlCloseDLL ( NLdll  handle)

Closes a DLL/shared object/dylib.

Parameters
[in]handlea handle to a DLL/shared object/dylib that was previously obtained by nlOpenDLL()

◆ nlCurrentTime()

NLdouble nlCurrentTime ( void  )

Gets the current time in seconds.

Returns
the current time in seconds (starting from a given reference time)

◆ nlError()

void nlError ( const char *  function,
const char *  message 
)

Displays an error message.

Parameters
[in]functionname of the function that triggered the error
[in]messageerror message

◆ nlFindFunction()

NLfunc nlFindFunction ( NLdll  handle,
const char *  funcname 
)

Finds a function in a DLL/shared object/dylib.

Parameters
[in]handlea handle to a DLL/shared object/dylib that was previously obtained by nlOpenDLL()
[in]funcnamethe name of the function
Returns
a pointer to the function or NULL if no such function was found

◆ nlGetNumCores()

NLuint nlGetNumCores ( void  )

Gets the number of cores.

Returns
the number of cores obtained from OpenMP if supported, or 1

◆ nlGetNumThreads()

NLuint nlGetNumThreads ( void  )

Gets the number of threads.

Returns
the number of threads used by OpenMP if supported, or 1

◆ nlOpenDLL()

NLdll nlOpenDLL ( const char *  filename,
NLenum  flags 
)

Dynamically links a DLL/shared object/dylib to the current process.

Parameters
[in]filenamethe file name fo the DLL/shared object/dylib.
[in]flagsan or-combination of NL_LINK_NOW, NL_LINK_LAZY, NL_LINK_GLOBAL, NL_LINK_QUIET.
Returns
a handle to the DLL/shared object/dylib or NULL if it could not be found.

◆ nlSetNumThreads()

void nlSetNumThreads ( NLuint  nb_threads)

Sets the number of threads.

Parameters
[in]nb_threadsnumber of threads to be used by OpenMP, ignored if OpenMP is not supported.

◆ nlWarning()

void nlWarning ( const char *  function,
const char *  message 
)

Displays a warning message.

Parameters
[in]functionname of the function that triggered the error
[in]messagewarning message