Hi,

I have been writing a Vapi for the ZeroMQ library: http://www.zeromq.org/. I
would eventually like it to be distributed with Vala itself, and would
propose myself as the maintainer.

See the vapi here:
https://github.com/lgunsch/zmq-vala/blob/master/libzmq.vapi

Although, I am having some trouble getting the MSG.Msg.copy() message copy
function to work correctly. It produces a segmentation fault. I am unsure
how to go about fixing this issue. You can see the docs for the libraries
copy function below.

http://api.zeromq.org/2-1:zmq-msg-copy

Any help is appreciated!

Cheers,
~Lewis
/* libzmq.vala
 *
 * Copyright (C) 2011  Lewis Gunsch <lgun...@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA

 *
 * Author:
 *      Lewis Gunsch <lgun...@gmail.com>
 */

[CCode (lower_case_cprefix = "zmq_", cheader_filename = "zmq.h")]
namespace ZMQ {
	[Compact]
	[CCode (cprefix = "zmq_", cname = "void", free_function = "zmq_term")]
	public class Context {
		[CCode (cname = "zmq_init")]
		public Context (int io_threads);
	}

	[CCode (cprefix = "ZMQ_")]
	namespace VERSION {
		public const int MAJOR;
		public const int MINOR;
		public const int PATCH;

		[CCode (cname = "ZMQ_VERSION")]
		public const int VERSION;
	}
	
	public static void version (out int major, out int minor, out int patch);

	/* ZMQ error numbers, in addition to POSIX error numbers. */
	[CCode (cname = "EFSM")]
	public const int EFSM;
	[CCode (cname = "ENOCOMPATPROTO")]
	public const int ENOCOMPATPROTO;
	[CCode (cname = "ETERM")]
	public const int ETERM;
	[CCode (cname = "EMTHREAD")]
	public const int EMTHREAD;

	public int errno ();
	public unowned string strerror (int errnum);

	namespace MSG {
		[CCode (cname = "ZMQ_MAX_VSM_SIZE")]
		public const int MAX_VSM_SIZE;
		[CCode (cname = "ZMQ_DELIMITER")]
		public const int DELIMITER;
		[CCode (cname = "ZMQ_VSM")]
		public const int VSM;
		public const uchar MORE;
		public const uchar SHARED;

		[CCode (cname = "zmq_free_fn", type = "void (*)(void *, void *)")]
		public delegate void free_fn(void *data); 

		[CCode (cprefix = "zmq_msg_", cname = "zmq_msg_t", destroy_function = "zmq_msg_close", has_copy_function=false)]
		public struct Msg {
			[CCode (cname = "zmq_msg_init")]
			public Msg();
			[CCode (cname = "zmq_msg_init_size")]
			public Msg.size(size_t size);
			[CCode (cname = "zmq_msg_init_data")]
			public Msg.data(owned uint8[] data, free_fn?  ffn = null);
			[CCode (instance_pos = 2)]
			public int copy(Msg? dest);
		}

		public int move(Msg dest, Msg src);
	}

	[CCode (cname = "int", cprefix = "ZMQ_")]
	public enum SocketType {
		PAIR,
		PUB,
		SUB,
		REQ,
		REP,
		DEALER,
		ROUTER,
		PULL,
		PUSH,
		XPUB,
		XSUB
	}
	
	[CCode (cname = "int", cprefix = "ZMQ_")]
	public enum SocketOption {
		HWM,
		SWAP,
		AFFINITY,
		IDENTITY,
		SUBSCRIBE,
		UNSUBSCRIBE,
		RATE,
		RECOVERY_IVL,
		MCAST_LOOP,
		SNDBUF,
		RCVBUF,
		RCVMORE,
		FD,
		EVENTS,
		TYPE,
		LINGER,
		RECONNECT_IVL,
		BACKLOG,
		RECOVERY_IVL_MSEC,
		RECONNECT_IVL_MAX
	}

	[CCode (cname = "int", cprefix = "ZMQ_")]
	public enum SendRecvOption {
		NOBLOCK,
		SNDMORE
	}

	[Compact]
	[CCode (cprefix = "zmq_", cname = "void", free_function = "zmq_close")]
	public class Socket {
		/* how do we deal with errno return in constructor ? */
		[CCode (cname = "zmq_socket")]
		public Socket (Context context, SocketType type);
		[CCode (simple_generics = true)]
		public int setsockopt < T > (SocketOption option, T optval, size_t optvallen); 
		[CCode (simple_generics = true)]
		public int getsockopt < T > (SocketOption option, T optval, size_t optvallen);
		public int bind (string addr);
		public int connect (string addr);
		public int send (MSG.Msg msg, SendRecvOption flags);
		public int recv (MSG.Msg msg, SendRecvOption flags);
	}
}
using ZMQ;

public static void myFunction(void* data) { 
	stdout.printf("Freed!\n");
	delete data;
}

public static void testDataMsg() {
	/* buffered data message */
	var msg = ZMQ.MSG.Msg.data("Hello World".data, myFunction);	

	var msg2 = null;
	int result =  msg.copy(msg2); /* this will produce a segmentation fault */
	stdout.printf("Copy result is %d.", result);
}

public static int main(string[] argv) {
	testDataMsg();
	return 1;
}
_______________________________________________
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to