# 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
@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))


@cdef('void zctx_destroy (zctx_t **self_p);')
def destroy(ctx):
    """
    Destroy context and all sockets in it
    """
    #if ctx is not ffi.NULL:

# 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

@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))


@cdef('void zctx_destroy (zctx_t **self_p);')
def destroy(ctx):
    """
    Destroy context and all sockets in it
    """
    #if ctx is not ffi.NULL:

    C.zctx_destroy(ptop('zctx_t', ctx))