Skip to content

Commit

Permalink
Adds version constants to the C module
Browse files Browse the repository at this point in the history
Signed-off-by: Gora Khargosh <gora.khargosh@gmail.com>
  • Loading branch information
gorakhargosh committed Dec 30, 2010
1 parent 8245638 commit 34dbd60
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
22 changes: 21 additions & 1 deletion src/_watchdog_fsevents.c
Expand Up @@ -215,12 +215,18 @@ static PyMethodDef _watchdog_fseventsmethods[] =


/**
* Adds all the module attributes.
* Adds all the _watchdog_fsevents module attributes and is meant only to be
* called within the module initialization function.
*
* :param module:
* The module to which attributes will be added.
* :type module:
* A pointer to a Python object representing a module.
*
* Attributes added:
* __version__: tuple denoting the version number of the module.
* VERSION_INFO: tuple denoting the version number of the module.
* VERSION_STRING: string denoting the version number of the module.
*/
static void
Watchdog_AddModuleAttributes(PyObject *module)
Expand All @@ -236,16 +242,30 @@ Watchdog_AddModuleAttributes(PyObject *module)
PyModule_AddIntConstant(module,
MODULE_CONSTANT_NAME_POLLOUT,
kCFFileDescriptorWriteCallBack);
/* Version tuple */
PyModule_AddObject(module,
MODULE_ATTRIBUTE_NAME_VERSION,
version_tuple);
PyModule_AddObject(module,
MODULE_ATTRIBUTE_NAME_VERSION_INFO,
version_tuple);
/* Version string */
PyModule_AddObject(module,
MODULE_ATTRIBUTE_NAME_VERSION_STRING,
Py_BuildValue("s",
WATCHDOG_VERSION_STRING));
/* major version */
PyModule_AddIntConstant(module,
MODULE_CONSTANT_NAME_VERSION_MAJOR,
WATCHDOG_VERSION_MAJOR);
/* minor version */
PyModule_AddIntConstant(module,
MODULE_CONSTANT_NAME_VERSION_MINOR,
WATCHDOG_VERSION_MINOR);
/* build version */
PyModule_AddIntConstant(module,
MODULE_CONSTANT_NAME_VERSION_BUILD,
WATCHDOG_VERSION_BUILD);
}


Expand Down
24 changes: 17 additions & 7 deletions src/_watchdog_fsevents.h
Expand Up @@ -57,6 +57,9 @@ typedef int Py_ssize_t;
#define MODULE_NAME "_watchdog_fsevents"
#define MODULE_CONSTANT_NAME_POLLIN "POLLIN"
#define MODULE_CONSTANT_NAME_POLLOUT "POLLOUT"
#define MODULE_CONSTANT_NAME_VERSION_MAJOR "VERSION_MAJOR"
#define MODULE_CONSTANT_NAME_VERSION_MINOR "VERSION_MINOR"
#define MODULE_CONSTANT_NAME_VERSION_BUILD "VERSION_BUILD"
#define MODULE_ATTRIBUTE_NAME_VERSION "__version__"
#define MODULE_ATTRIBUTE_NAME_VERSION_INFO "VERSION_INFO"
#define MODULE_ATTRIBUTE_NAME_VERSION_STRING "VERSION_STRING"
Expand Down Expand Up @@ -90,7 +93,8 @@ typedef struct _StreamCallbackInfo
} StreamCallbackInfo;

/**
* Macro that forces returning NULL if given argument is NULL.
* Macro that forces returning NULL from the caller function if given argument
* is NULL.
*/
#define RETURN_NULL_IF_NULL(o) \
do \
Expand All @@ -100,7 +104,8 @@ typedef struct _StreamCallbackInfo
while(0)

/**
* Macro that forces returning NULL if given argument is true.
* Macro that forces returning NULL from the caller function if given argument
* is truthy.
*/
#define RETURN_NULL_IF(c) \
do \
Expand All @@ -110,7 +115,8 @@ typedef struct _StreamCallbackInfo
while(0)

/**
* Macro that forces returning NULL if given argument is false.
* Macro that forces returning NULL from the caller function if given argument
* is falsy.
*/
#define RETURN_NULL_IF_NOT(c) \
do \
Expand All @@ -120,7 +126,8 @@ typedef struct _StreamCallbackInfo
while(0)

/**
* Macro that forces returning if given argument is true.
* Macro that forces returning from the caller function if given argument is
* truthy.
*/
#define RETURN_IF(c) \
do \
Expand All @@ -130,7 +137,8 @@ typedef struct _StreamCallbackInfo
while(0)

/**
* Macro that forces returning if given argument is false.
* Macro that forces returning from the caller function if given argument is
* falsy.
*/
#define RETURN_IF_NOT(c) \
do \
Expand All @@ -139,13 +147,15 @@ typedef struct _StreamCallbackInfo
} \
while(0)

/**
* Latency (float) for the event streams registered with the FSEvents API.
*/
#define FS_EVENT_STREAM_LATENCY (0.01)

/* Initialization. */
/* Initializes internal data structures when the module is initialized. */
void
Watchdog_FSEvents_Init(void);


/* CFRunLoopForEmitter global dict functions. */
CFRunLoopRef
Watchdog_CFRunLoopForEmitter_GetItem(PyObject *emitter_thread);
Expand Down

0 comments on commit 34dbd60

Please sign in to comment.