# Path: pyczmq/_cffi.py
# C = ffi.dlopen('czmq')
# Z = ffi.dlopen('zmq')
# def ptop(typ, val):
# def cdef(decl, returns_string=False, nullable=False):
#     def wrap(f):
#         def inner_f(*args):


from pyczmq._cffi import C, ffi, cdef, ptop
    Sets up signal (SIGINT and SIGTERM) handling so that blocking
    calls such as zmq_recv() and zmq_poll() will return when the user
    presses Ctrl-C.
"""


cdef('typedef struct _zctx_t zctx_t;')


@cdef('zctx_t * zctx_shadow (zctx_t *self);')
def shadow(ctx):
    """
    Create new shadow context, returns context object
    """
    return C.zctx_shadow(ctx)


@cdef('zctx_t * zctx_shadow_zmq_ctx (void *zmqctx);')
def shadow_zmq_ctx(zmqctx):
    """
    Create a new context by shadowing a plain zmq context
    """
    return C.zctx_shadow_zmq_ctx(zmqctx)


def shadow_pyzmq_ctx(pyzmqctx):
    """
    Create a new context by shadowing a pyzmq context
    """
    address = pyzmqctx.underlying

# Path: pyczmq/_cffi.py
# C = ffi.dlopen('czmq')
# Z = ffi.dlopen('zmq')
# def ptop(typ, val):
# def cdef(decl, returns_string=False, nullable=False):
#     def wrap(f):
#         def inner_f(*args):


# Path: pyczmq/zctx.py
from pyczmq._cffi import C, ffi, cdef, ptop

    Sets up signal (SIGINT and SIGTERM) handling so that blocking
    calls such as zmq_recv() and zmq_poll() will return when the user
    presses Ctrl-C.
"""


cdef('typedef struct _zctx_t zctx_t;')


@cdef('zctx_t * zctx_shadow (zctx_t *self);')
def shadow(ctx):
    """
    Create new shadow context, returns context object
    """
    return C.zctx_shadow(ctx)


@cdef('zctx_t * zctx_shadow_zmq_ctx (void *zmqctx);')
def shadow_zmq_ctx(zmqctx):
    """
    Create a new context by shadowing a plain zmq context
    """
    return C.zctx_shadow_zmq_ctx(zmqctx)


def shadow_pyzmq_ctx(pyzmqctx):
    """
    Create a new context by shadowing a pyzmq context
    """
    address = pyzmqctx.underlying

    return shadow_zmq_ctx(ffi.cast('void *', address))