added functionality to ascompose to set XROOTPMAP property while changing root background

--- libAfterImage/apps/ascompose.c
+++ libAfterImage/apps/ascompose.c
@@ -201,6 +201,11 @@
 		"\n"
 		"  -C --clipboard     run ascompose waiting for data being copied into clipboard,\n"
 		"                     and displaying/processing it, if it is xml.\n"
+		" Examples: \n"
+		" To display image.jpg on root window : \n"
+		"   ascompose -r -s \"\""
+		" To display image.jpg on root window scaling it to screen size: \n"
+		"   ascompose -r -s \"<scale width=xroot.width height=proportional></scale>\""
 	);
 }

@@ -262,8 +267,6 @@
 Window make_main_window(Bool on_root, ASComposeWinProps *props);

 int screen = 0, depth = 0;
-
-

 int main(int argc, char** argv) {

@@ -744,6 +747,60 @@
 	return w;
 }

+Bool
+set_root_pixmap_property(long pmap) /* Must have long type to work with XChangeProp on 64 bit machines !!!*/
+{
+	Window root = DefaultRootWindow(dpy);
+	char  *names[2] = {"_XROOTPMAP_ID", "ESETROOT_PMAP_ID"};
+	Atom  atoms[2];
+	int i;
+
+	if (XInternAtoms (dpy, &(names[0]), 2, True, &(atoms[0])) != 0)
+	{
+		Pixmap pmaps[2] = {0, 0};
+	    Atom type;
+    	int format;
+	    unsigned long nitems, after;
+		union
+		{
+			unsigned char *uc_ptr ;
+			long 		  *long_ptr ;
+		}data;
+
+		for (i = 0 ; i < 2 ; ++i)
+			if (atoms[i])
+			{
+				LOCAL_DEBUG_OUT("atoms[%d] = %X", i, atoms[i]);
+				data.long_ptr = NULL ;
+		        XGetWindowProperty(dpy, root, atoms[i], 0L, 1L, False, AnyPropertyType, &type, &format, &nitems, &after, &data.uc_ptr);
+				if (data.long_ptr == NULL)
+					break;
+				pmaps[i] = data.long_ptr[0] ;
+				LOCAL_DEBUG_OUT("pmaps[%d] = %X", i, pmaps[i]);
+				if (format != 32 || nitems == 0|| pmaps[i] == None || pmaps[i] != pmaps[0] || type != XA_PIXMAP)
+					break;
+			}
+		if (i>= 2)
+		{
+			LOCAL_DEBUG_OUT("killing client for pmap %X", pmaps[0]);
+           	XKillClient(dpy, pmaps[0]);
+		}
+    }
+	for (i = 0 ; i < 2 ; ++i)
+	{
+		if (!atoms[i])
+			if ( (atoms[i] = XInternAtom (dpy, names[i], False)) == None)
+				break;
+    	XChangeProperty(dpy, root, atoms[i], XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &pmap, 1);
+	}
+	if (i < 2)
+		return False;
+
+	XSetCloseDownMode(dpy, RetainPermanent);
+	return True;
+}
+
+
 Window showimage(ASImage* im, Bool looping, Window main_window, ASComposeWinProps *props )
 {
 #ifndef X_DISPLAY_MISSING
@@ -756,6 +813,10 @@
 	unsigned int shape_rects_count = 0;
 	XRectangle *shape_rects = NULL ;
 	Bool done = False ;
+	Window root = DefaultRootWindow(dpy);
+	int screen = DefaultScreen(dpy);
+	int root_w = DisplayWidth (dpy, screen);
+	int root_h = DisplayHeight (dpy, screen);

 	if (im == NULL || main_window == None )
 		return None;
@@ -763,7 +824,7 @@
 	width = im->width;
 	height = im->height;

-	if( main_window != DefaultRootWindow(dpy) )
+	if( main_window != root)
 	{
 		Bool move = True ;

@@ -774,16 +835,16 @@

 		if( props->center )
 		{
-			x = (DisplayWidth (dpy, DefaultScreen(dpy)) - width)/2;
-			y = (DisplayHeight (dpy, DefaultScreen(dpy)) - height)/2;
+			x = (root_w - width)/2;
+			y = (root_h - height)/2;
 		}else if( get_flags( props->geom_flags, XValue|YValue) )
 		{
 	 		x = props->geom_x ;
 			y = props->geom_y ;
 			if( get_flags( props->geom_flags, XNegative ) )
-				x = DisplayWidth (dpy, DefaultScreen(dpy)) - width + x ;
+				x = root_w - width + x ;
 			if( get_flags( props->geom_flags, YNegative ) )
-				y = DisplayHeight (dpy, DefaultScreen(dpy)) - height + y ;
+				y = root_h - height + y ;
 		}else
 			move = False ;

@@ -880,28 +941,37 @@
 		}
 	}

-	if( main_window==DefaultRootWindow(dpy)	)
+	if (main_window==root)
 	{
-		XImage *xim = create_visual_scratch_ximage( asv, im->width, im->height, DefaultDepth(dpy,DefaultScreen(dpy)) );
-		p = create_visual_pixmap( asv, DefaultRootWindow(dpy), im->width, im->height,
-							      DefaultDepth(dpy,DefaultScreen(dpy)) );
+		XImage *xim = create_visual_scratch_ximage( asv, im->width, im->height, DefaultDepth(dpy,screen) );
+		p = create_visual_pixmap( asv, root, im->width, im->height, DefaultDepth(dpy,screen) );
 		if( subimage2ximage (asv, im, 0, 0, xim)	)
 		{
-			put_ximage( asv, xim, p, DefaultGC(dpy,DefaultScreen(dpy)), 0, 0, 0, 0, im->width, im->height );
+			put_ximage( asv, xim, p, DefaultGC(dpy,screen), 0, 0, 0, 0, im->width, im->height );
 		}
 		XDestroyImage( xim );
 	}else
 	{
-		p = create_visual_pixmap( asv, DefaultRootWindow(dpy), im->width, im->height, 0 );
+		p = create_visual_pixmap( asv, root, im->width, im->height, 0 );
 		if( get_flags( asv->glx_support, ASGLX_UseForImageTx ) )
-			done = asimage2drawable_gl( asv, p, im, 0, 0, 0, 0,
-        		   						im->width, im->height,
+			done = asimage2drawable_gl( asv, p, im, 0, 0, 0, 0,
+										im->width, im->height,
 				   						im->width, im->height,
 										False );
 		if( !done )
 			asimage2drawable( asv, p, im, NULL, 0, 0, 0, 0, im->width, im->height, True);
 	}
-	p = set_window_background_and_free( main_window, p );
+
+	if (main_window == root && !looping)
+	{
+		set_root_pixmap_property(p);
+		XSetWindowBackgroundPixmap( dpy, root, p);
+		XClearWindow( dpy, root);
+		XSync(dpy, False);
+		return root;
+	}else
+		p = set_window_background_and_free( main_window, p );
+
 	XSync(dpy, False);
 #if 1
 #ifdef SHAPE
@@ -967,7 +1037,7 @@
 		}
 		if( do_close )
 		{
-			if( main_window != DefaultRootWindow(dpy) )
+			if( main_window != root )
 				XDestroyWindow( dpy, main_window );
 			XFlush( dpy );
 			main_window = None ;


Initial version of simplecrypt

Initial version of simplecrypt

error: pathspec 'simplecrypt/simplecrypt.c' did not match any file(s) known to git

--- simplecrypt/simplecrypt.c
+++ simplecrypt/simplecrypt.c
@@ -0,0 +1,24 @@
+/* Simplecrypt - Simple Gmail file obfuscator. Public domain.
+ * Use for executable attachments or archives containing executables.
+ * Written in 2012 by Kirn Gill II <segin2005@gmail.com>
+ */
+
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+	FILE *fd, fd2;
+	if(!(fd = fopen(argv[1], "rb") || !(fd2 = fopen(argv[2], "wb") {
+		if(fd)
+			perror(argv[2]);
+		else
+			perror(argv[1]);
+		exit;
+	}
+	char a;
+	while(fread(&a, 1, 1, fd)) {
+		a ^= 0xFF;
+		fwrite(&a, 1, 1, fd2);
+	}
+	fclose(fd);
+	fclose(fd2);
+}


msm: camera: Prevent using ISPIF when not UP

When ISPIF is not in ISPIF_POWER_UP state, this means that it will not
have register base ioremapped, will not have IRQs reqested and so on. In
this case ISPIF must not be used as it will result in an kernel panic
with the following symptoms:

------------[ cut here ]------------
Unable to handle kernel paging request at virtual address f0d0e248
....
[<c0435738>] (msm_camera_io_w_mb+0x2c/0x44) from [<c044407c>] (msm_ispif_intf_cmd+0x138/0x178)
[<c044407c>] (msm_ispif_intf_cmd+0x138/0x178) from [<c0444f64>] (msm_ispif_subdev_ioctl+0x88c/0x9e0)
[<c0444f64>] (msm_ispif_subdev_ioctl+0x88c/0x9e0) from [<c04648f4>] (subdev_do_ioctl+0x490/0x530)
[<c04648f4>] (subdev_do_ioctl+0x490/0x530) from [<c0459c94>] (video_usercopy+0x360/0x4dc)
[<c0459c94>] (video_usercopy+0x360/0x4dc) from [<c0458edc>] (v4l2_ioctl+0x68/0x114)
[<c0458edc>] (v4l2_ioctl+0x68/0x114) from [<c0154734>] (do_vfs_ioctl+0x4d8/0x54c)
[<c0154734>] (do_vfs_ioctl+0x4d8/0x54c) from [<c01547dc>] (sys_ioctl+0x34/0x54)
[<c01547dc>] (sys_ioctl+0x34/0x54) from [<c000e000>] (ret_fast_syscall+0x0/0x30)
Code: e1a00000 eaffffff e1a00000 e3500000 (e5845000)
---[ end trace 90991692f8caa754 ]---

The above panic can happen when the device have been opened and there
were no ISPIF_INIT cmd, before calling one of the following ISPIF cmds:
  - ISPIF_CFG
  - ISPIF_START_FRAME_BOUNDARY
  - ISPIF_STOP_FRAME_BOUNDARY
  - ISPIF_STOP_IMMEDIATELY

Or there were call to msm_ispif_relese with one of the above commands
called after this.

The only case when the above commands can be issued is between
ISPIF_INIT and ISPIF_RELEASE (or close of the device) calls with
success. In order to prevent usage of the above commands in this
situation, just provide a check for the ISPIF and return -EPERM error
when the ISPIF is not in the correct state.

Change-Id: Ic02794382b301e555a7e9f897ee9c6f67b5818fd
Signed-off-by: Vladislav Hristov <fb41bc2bc5d980f21af6d1b4c4bfb639118fa816@codeaurora.org>

--- drivers/media/platform/msm/camera_v2/ispif/msm_ispif.c
+++ drivers/media/platform/msm/camera_v2/ispif/msm_ispif.c
@@ -503,6 +503,13 @@
 	BUG_ON(!ispif);
 	BUG_ON(!params);

+	if (ispif->ispif_state != ISPIF_POWER_UP) {
+		pr_err("%s: ispif invalid state %d\n", __func__,
+			ispif->ispif_state);
+		rc = -EPERM;
+		return rc;
+	}
+
 	rc = msm_ispif_clk_enable(ispif, params, 1);
 	if (rc < 0) {
 		pr_err("%s: unable to enable clocks", __func__);
@@ -653,6 +660,13 @@
 	BUG_ON(!ispif);
 	BUG_ON(!params);

+	if (ispif->ispif_state != ISPIF_POWER_UP) {
+		pr_err("%s: ispif invalid state %d\n", __func__,
+			ispif->ispif_state);
+		rc = -EPERM;
+		return rc;
+	}
+
 	msm_ispif_intf_cmd(ispif, ISPIF_INTF_CMD_DISABLE_IMMEDIATELY, params);

 	/* after stop the interface we need to unmask the CID enable bits */
@@ -671,6 +685,13 @@
 {
 	int rc;

+	if (ispif->ispif_state != ISPIF_POWER_UP) {
+		pr_err("%s: ispif invalid state %d\n", __func__,
+			ispif->ispif_state);
+		rc = -EPERM;
+		return rc;
+	}
+
 	rc = msm_ispif_clk_enable(ispif, params, 1);
 	if (rc < 0) {
 		pr_err("%s: unable to enable clocks", __func__);
@@ -702,6 +723,13 @@
 	BUG_ON(!ispif);
 	BUG_ON(!params);

+
+	if (ispif->ispif_state != ISPIF_POWER_UP) {
+		pr_err("%s: ispif invalid state %d\n", __func__,
+			ispif->ispif_state);
+		rc = -EPERM;
+		return rc;
+	}

 	rc = msm_ispif_clk_enable(ispif, params, 1);
 	if (rc < 0) {


added missing MRT mode "One-shot bus stall"

--- lib_lpc_chip_8xx/inc/mrt_8xx.h
+++ lib_lpc_chip_8xx/inc/mrt_8xx.h
@@ -77,6 +77,7 @@
 typedef enum MRT_MODE {
 	MRT_MODE_REPEAT =  (0 << 1),	/*!< MRT Repeat interrupt mode */
 	MRT_MODE_ONESHOT = (1 << 1),	/*!< MRT One-shot interrupt mode */
+	MRT_MODE_ONESHOT_BUS_STALL = (2 << 1)		/*!< MRT One-shot bus stall mode */
 } MRT_MODE_T;

 /**


balloon: fix a case where host request stats before service was started.

--- Balloon/sys/Device.c
+++ Balloon/sys/Device.c
@@ -539,13 +539,14 @@
     {
         WDFREQUEST request = devCtx->PendingWriteRequest;

+        devCtx->HandleWriteRequest = TRUE;
+
         if ((request != NULL) &&
             (WdfRequestUnmarkCancelable(request) != STATUS_CANCELLED))
         {
             PVOID buffer;
             size_t length = 0;

-            devCtx->HandleWriteRequest = TRUE;
             devCtx->PendingWriteRequest = NULL;

             WdfRequestRetrieveInputBuffer(request, 0, &buffer, &length);


Staging: comedi: Remove PCRANGE typedef in addi-data

Signed-off-by: Bill Pemberton <6208e3c588e4690c7dfac5e95777d6a902c5fb27@virginia.edu>
Signed-off-by: Greg Kroah-Hartman <4645f7897fd33786a2ee1264d590b3c400559d85@suse.de>

--- drivers/staging/comedi/drivers/addi-data/addi_common.h
+++ drivers/staging/comedi/drivers/addi-data/addi_common.h
@@ -36,10 +36,6 @@
 #define ERROR	-1
 #define SUCCESS	1

-/* variable type definition */
-
-typedef const struct comedi_lrange *PCRANGE;
-
 #define LOBYTE(W)	(unsigned char)((W) & 0xFF)
 #define HIBYTE(W)	(unsigned char)(((W) >> 8) & 0xFF)
 #define MAKEWORD(H, L)	(unsigned short)((L) | ((H) << 8))
@@ -81,15 +77,15 @@
 	int i_NbrAoChannel;	// num of D/A chans
 	int i_AiMaxdata;	// resolution of A/D
 	int i_AoMaxdata;	// resolution of D/A
-	PCRANGE pr_AiRangelist;	// rangelist for A/D
-	PCRANGE pr_AoRangelist;	// rangelist for D/A
+        const struct comedi_lrange *pr_AiRangelist;	/* rangelist for A/D */
+        const struct comedi_lrange *pr_AoRangelist;	/* rangelist for D/A */

 	int i_NbrDiChannel;	// Number of DI channels
 	int i_NbrDoChannel;	// Number of DO channels
 	int i_DoMaxdata;	// data to set all chanels high

 	int i_NbrTTLChannel;	// Number of TTL channels
-	PCRANGE pr_TTLRangelist;	// rangelist for TTL
+	const struct comedi_lrange *pr_TTLRangelist;	/* rangelist for TTL */

 	int i_Dma;		// dma present or not
 	int i_Timer;		//   timer subdevice present or not


Hide global static _dispatch_kq handle

Hide global static _dispatch_kq handle

--- libdispatch/src/queue_kevent.c
+++ libdispatch/src/queue_kevent.c
@@ -31,30 +31,29 @@
 static void *_dispatch_rfd_ptrs[FD_SETSIZE];
 static void *_dispatch_wfd_ptrs[FD_SETSIZE];

-static int _dispatch_kq;
-
 static void
-_dispatch_get_kq_init(void *context DISPATCH_UNUSED)
-{
+_dispatch_get_kq_init(void *context)
+{
+        int *_dispatch_kqp = (int*)context;
 	static const struct kevent kev = {
 		1,                /* .ident */
 		EVFILT_USER,      /* .filter */
 		EV_ADD|EV_CLEAR,  /* .flags */
 	};

-	_dispatch_kq = kqueue();
+	*_dispatch_kqp = kqueue();
 	_dispatch_safe_fork = false;
 	// in case we fall back to select()
-	FD_SET(_dispatch_kq, &_dispatch_rfds);
-
-	if (_dispatch_kq == -1) {
+        FD_SET(*_dispatch_kqp, &_dispatch_rfds);
+
+	if (*_dispatch_kqp == -1) {
 		dispatch_assert_zero(errno);
 	}

 #if defined(__GNUC__)
 	(void)
 #endif
-    dispatch_assume_zero(kevent(_dispatch_kq, &kev, 1, NULL, 0, NULL));
+    dispatch_assume_zero(kevent(*_dispatch_kqp, &kev, 1, NULL, 0, NULL));
     _dispatch_queue_push(_dispatch_mgr_q.do_targetq, (struct dispatch_object_s*)&_dispatch_mgr_q);
 }

@@ -62,8 +61,9 @@
 _dispatch_get_kq(void)
 {
 	static dispatch_once_t pred;
-
-	dispatch_once_f(&pred, NULL, _dispatch_get_kq_init);
+        static int _dispatch_kq;
+
+	dispatch_once_f(&pred, &_dispatch_kq, _dispatch_get_kq_init);

 	return _dispatch_kq;
 }
@@ -95,6 +95,7 @@
 	fd_set tmp_rfds, tmp_wfds;
 	struct kevent kev[1];
 	int k_cnt, k_err, i, r;
+        int _dispatch_kq = _dispatch_get_kq();

 	_dispatch_thread_setspecific(dispatch_queue_key, dq);


libfreerdp-core: fix an trivial mistake in reading codec caps.

--- libfreerdp-core/capabilities.c
+++ libfreerdp-core/capabilities.c
@@ -1381,7 +1381,7 @@
 			stream_read_uint8(s, settings->rfx_codec_id);
 			settings->rfx_codec = True;
 		}
-		if (settings->server_mode && strncmp((char*)stream_get_tail(s),CODEC_GUID_NSCODEC, 16) == 0)
+		else if (settings->server_mode && strncmp((char*)stream_get_tail(s),CODEC_GUID_NSCODEC, 16) == 0)
 		{
 			stream_seek(s, 16); /*codec GUID (16 bytes) */
 			stream_read_uint8(s, settings->ns_codec_id);


Fixed API nonnull warning.

Fixed API nonnull warning.

--- libfreerdp/core/gateway/http.c
+++ libfreerdp/core/gateway/http.c
@@ -330,10 +330,12 @@

 BOOL http_response_parse_header_status_line(HttpResponse* http_response, char* status_line)
 {
-	char* separator;
+	char* separator = NULL;
 	char* status_code;
 	char* reason_phrase;
-	separator = strchr(status_line, ' ');
+
+	if (status_line)
+		separator = strchr(status_line, ' ');

 	if (!separator)
 		return FALSE;
@@ -433,7 +435,10 @@
 		 *                 |     |
 		 *         colon_pos     value
 		 */
-		colon_pos = strchr(line, ':');
+		if (line)
+			colon_pos = strchr(line, ':');
+		else
+			colon_pos = NULL;

 		if ((colon_pos == NULL) || (colon_pos == line))
 			return FALSE;


#ifdef FIXME gnome_selector_get_entry_text().

--- libgnome/gnome-file-selector.c
+++ libgnome/gnome-file-selector.c
@@ -691,7 +691,9 @@
 activate_entry_handler (GnomeSelector *selector)
 {
     GnomeFileSelector *fselector;
+#ifdef FIXME
     gchar *text;
+#endif

     g_return_if_fail (selector != NULL);
     g_return_if_fail (GNOME_IS_FILE_SELECTOR (selector));
@@ -701,9 +703,11 @@
     GNOME_CALL_PARENT_HANDLER (GNOME_SELECTOR_CLASS, activate_entry,
 			       (selector));

+#ifdef FIXME
     text = gnome_selector_get_entry_text (selector);
     gnome_selector_add_uri (selector, NULL, text, 0, FALSE, NULL, NULL);
     g_free (text);
+#endif
 }

 static void


add support for a enum range with strings (ImageFormat)

--- libgphoto2_port/vusb/vcamera.c
+++ libgphoto2_port/vusb/vcamera.c
@@ -339,6 +339,8 @@

 static int ptp_battery_getdesc(vcamera*,PTPDevicePropDesc*);
 static int ptp_battery_getvalue(vcamera*,PTPPropertyValue*);
+static int ptp_imagesize_getdesc(vcamera*,PTPDevicePropDesc*);
+static int ptp_imagesize_getvalue(vcamera*,PTPPropertyValue*);
 static int ptp_datetime_getdesc(vcamera*,PTPDevicePropDesc*);
 static int ptp_datetime_getvalue(vcamera*,PTPPropertyValue*);
 static int ptp_datetime_setvalue(vcamera*,PTPPropertyValue*);
@@ -350,6 +352,7 @@
 	int	(*setvalue)(vcamera *cam, PTPPropertyValue*);
 } ptp_properties[] = {
 	{0x5001,	ptp_battery_getdesc, ptp_battery_getvalue, NULL },
+	{0x5003,	ptp_imagesize_getdesc, ptp_imagesize_getvalue, NULL },
 	{0x5011,	ptp_datetime_getdesc, ptp_datetime_getvalue, ptp_datetime_setvalue },
 };

@@ -1256,8 +1259,10 @@
 		x += put_propval (data+x, desc.DataType, &desc.FORM.Range.MaximumValue);
 		x += put_propval (data+x, desc.DataType, &desc.FORM.Range.StepSize);
 		break;
-	case 2:	/* ENUM */;
-		gp_log (GP_LOG_ERROR, __FUNCTION__, "enum not yet handled\n");
+	case 2:	/* ENUM */
+		x += put_16bit_le (data+x, desc.FORM.Enum.NumberOfValues);
+		for (i=0;i<desc.FORM.Enum.NumberOfValues;i++)
+			x += put_propval (data+x, desc.DataType, &desc.FORM.Enum.SupportedValue[i]);
 		break;
 	}

@@ -1505,6 +1510,31 @@
 ptp_battery_getvalue (vcamera* cam, PTPPropertyValue *val) {
 	val->u8 = 50;
 	ptp_inject_interrupt (cam, 1000, 0x4006, 1, 0x5001, 0xffffffff);
+	return 1;
+}
+
+static int
+ptp_imagesize_getdesc (vcamera* cam, PTPDevicePropDesc *desc) {
+	desc->DevicePropertyCode		= 0x5003;
+	desc->DataType				= 0xffff;	/* STR */
+	desc->GetSet				= 0;		/* Get only */
+	desc->FactoryDefaultValue.str		= strdup("640x480");
+	desc->CurrentValue.str			= strdup("640x480");
+        desc->FormFlag				= 0x02; /* enum */
+	desc->FORM.Enum.NumberOfValues 		= 3;
+	desc->FORM.Enum.SupportedValue 		= malloc(3*sizeof(desc->FORM.Enum.SupportedValue[0]));
+	desc->FORM.Enum.SupportedValue[0].str	= strdup("640x480");
+	desc->FORM.Enum.SupportedValue[1].str	= strdup("1024x768");
+	desc->FORM.Enum.SupportedValue[2].str	= strdup("2048x1536");
+
+	ptp_inject_interrupt (cam, 1000, 0x4006, 1, 0x5003, 0xffffffff);
+	return 1;
+}
+
+static int
+ptp_imagesize_getvalue (vcamera* cam, PTPPropertyValue *val) {
+	val->str = strdup("640x480");
+	ptp_inject_interrupt (cam, 1000, 0x4006, 1, 0x5003, 0xffffffff);
 	return 1;
 }


* minor doc change

* minor doc change


Fixed the BalancedBTreeRebalance

Fixed the BalancedBTreeRebalance

git-svn-id: 798f9e0ce1eefcecf757a5f2b692a26d86a9651c@26 c66dcb5a-e80b-0410-ab0e-bb6a4f3ddef9

--- bot/src/balanced_btree.c
+++ bot/src/balanced_btree.c
@@ -350,10 +350,11 @@
 {
     int     res;

-    res = 0;
     if ( root == NULL ) {
         return( 0 );
     }
+
+    res = 1;

     if( root->left != NULL ) {
         res += BalancedBTreeWeight( root->left );
@@ -443,6 +444,9 @@
                              BalancedBTreeItem_t *root )
 {
     BalancedBTreeItem_t    *item;
+    BalancedBTreeItem_t    *left;
+    BalancedBTreeItem_t    *right;
+    BalancedBTreeItem_t    *parent;
     int                     res;

     if( root == NULL ) {
@@ -450,31 +454,75 @@
     }

     for( res = BalancedBTreeWeight( root->left ) -
-               BalancedBTreeWeight( root->right ); res < -1 || res > 1; ) {
+               BalancedBTreeWeight( root->right ); res < -1 || res > 1;
+         res = BalancedBTreeWeight( root->left ) -
+               BalancedBTreeWeight( root->right ) ) {
+
         /* Too much stuff on either left or right subtree */
-        if( res < -1 ) {
+        if( res > 1 ) {
             /* Too much on left, need to shift to the right */
             item = BalancedBTreeFindGreatest( root->left );
-            item->parent->right = item->left;
+
+            left   = item->left;
+            right  = item->right;   /* This is NULL! */
+            parent = item->parent;
+
             item->parent = root->parent;
+            item->right  = root;
+            if( root->left != item ) {
+                item->left = root->left;
+                if( item->left != NULL ) {
+                    item->left->parent = item;
+                }
+            }
+
             root->parent = item;
-            item->right = root;
-            item->left = root->left;
-            root->left = NULL;
+            root->left   = NULL;
+
+            if( parent != root ) {
+                parent->right = left;
+                if( left != NULL ) {
+                    left->parent = parent;
+                }
+            }
         } else {
             /* Too much on right, need to shift to the left */
             item = BalancedBTreeFindLeast( root->right );
-            item->parent->left = item->right;
+
+            left   = item->left;    /* This is NULL! */
+            right  = item->right;
+            parent = item->parent;
+
             item->parent = root->parent;
+            item->left   = root;
+            if( root->right != item ) {
+                item->right  = root->right;
+                if( item->right != NULL ) {
+                    item->right->parent = item;
+                }
+            }
+
             root->parent = item;
-            item->left = root;
-            item->right = root->right;
-            root->right = NULL;
-        }
-
-        if( item->parent == NULL ) {
+            root->right  = NULL;
+
+            if( parent != root ) {
+                parent->left = right;
+                if( right != NULL ) {
+                    right->parent = parent;
+                }
+            }
+        }
+
+        if( item->parent != NULL ) {
+            if( item->parent->left == root ) {
+                item->parent->left = item;
+            } else {
+                item->parent->right = item;
+            }
+        } else {
             btree->root = item;
         }
+        root = item;
     }

     BalancedBTreeRebalance( btree, root->left );


chunker: add a comment about a potential speedup

--- borg/_chunker.c
+++ borg/_chunker.c
@@ -96,7 +96,7 @@
 static uint32_t
 buzhash_update(uint32_t sum, unsigned char remove, unsigned char add, size_t len, const uint32_t *h)
 {
-    uint32_t lenmod = len & 0x1f;
+    uint32_t lenmod = len & 0x1f;  /* Note: replace by constant to get small speedup */
     return BARREL_SHIFT(sum, 1) ^ BARREL_SHIFT(h[remove], lenmod) ^ h[add];
 }


mensagens atualizadas - ufmt

mensagens atualizadas - ufmt

--- ED-lista_generica/main.c
+++ ED-lista_generica/main.c
@@ -131,12 +131,13 @@
                 v[i+1] = -1;
             }
         }
+        printf("Lista compactada com sucesso!");
     }
 }

 void remover(int *v){
 	if(quant == 0)
-		printf("lista vazia!");
+        printf("Lista vazia!");
 	else{
 		int val;
 		printf("Informe o valor para remover: \n");
@@ -157,7 +158,7 @@

 void mostrar(int *v){
 	if(quant == 0)
-		printf("lista vazia!");
+        printf("Lista vazia!");
 	else{
         int i;
         for(i=0; i<tam; i++){


Fixed typo: 'commond'

Fixed typo: 'commond'

Note that the word 'commond' is wrong,
so that 'commond' should been replaced with 'command'.

--- bsp/lpc176x/drivers/sd.c
+++ bsp/lpc176x/drivers/sd.c
@@ -155,7 +155,7 @@
     Send a Command to Flash card and get a Response
     cmd:  cmd index
     arg: argument for the cmd
-    return the received response of the commond
+    return the received response of the command
 *****************************************************************************/
 static uint8_t LPC17xx_SD_SendCmd(uint8_t cmd, uint32_t arg)
 {


Revert "config: free include path on successful load"

This reverts commit 92450883d7b148d408b42c3553a60340a14771f6.

--- sway/config.c
+++ sway/config.c
@@ -474,7 +474,6 @@
 		list_del(config->config_chain, index);
 		return false;
 	}
-	free(real_path);

 	// restore current_config_path
 	config->current_config_path = parent_config;


fixed uninitialized bar.wrap_scroll

fixed uninitialized bar.wrap_scroll

--- sway/config.c
+++ sway/config.c
@@ -1118,6 +1118,7 @@
 	bar->font = NULL;
 	bar->height = -1;
 	bar->workspace_buttons = true;
+	bar->wrap_scroll = false;
 	bar->separator_symbol = NULL;
 	bar->strip_workspace_numbers = false;
 	bar->binding_mode_indicator = true;


Patch from Ludovic Rousseau to fix display of userdata as void*

--- smartcard/scard/helpers.c
+++ smartcard/scard/helpers.c
@@ -1,1015 +1,1015 @@
-/*==============================================================================
-Copyright 2001-2007 gemalto
-Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com
-
-This file is part of pyscard.
-
-pyscard 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.
-
-pyscard 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 pyscard; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-==============================================================================*/
-#include <assert.h>
-#ifdef WIN32
-    #include <windows.h>
-#endif
-#include <winscard.h>
-#include <Python.h>
-
-#include "helpers.h"
-#include "memlog.h"
-
-extern PyObject* PyExc_SCardError;
-
-#ifdef PCSCLITE
-    #define FALSE (0==1)
-    #define TRUE (1==1)
-    #define lstrlen strlen
-#endif // PCSCLITE
-
-/**==========================================================================**/
-static int _IsAReaderState( PyObject* o)
-/*==============================================================================
-==============================================================================*/
-{
-    PyObject* o2;
-
-    // expecting at least 2 items: reader name and current state
-    if( (PyTuple_Size(o)!=2) && (PyTuple_Size(o)!=3) )
-    {
-        PyErr_SetString( PyExc_TypeError, "Expecting two or three items in tuple." );
-        return 0;
-    }
-
-    o2 = PyTuple_GetItem(o, 0);
-    if(!PyString_Check(o2))
-    {
-        PyErr_SetString( PyExc_TypeError, "Expected a string as reader name." );
-        return 0;
-    }
-    o2 = PyTuple_GetItem(o, 1);
-    if(!PyInt_Check(o2))
-    {
-        PyErr_SetString( PyExc_TypeError, "Expected an Int as second tuple item." );
-        return 0;
-    }
-    if(PyTuple_Size(o)==3)
-    {
-        o2 = PyTuple_GetItem(o, 2);
-        if(!PyList_Check(o2))
-        {
-            PyErr_SetString( PyExc_TypeError, "Expected a list as third tuple item." );
-            return 0;
-        }
-    }
-    return 1;
-}
-
-/**==========================================================================**/
-static int _ReaderStateFromTuple( PyObject* o, READERSTATELIST* prl, unsigned int x )
-/*==============================================================================
-==============================================================================*/
-{
-    char* psz;
-    PyObject* o2;
-
-    // first tuple item is reader name
-    o2=PyTuple_GetItem(o, 0);
-    psz = PyString_AsString(o2);
-    prl->aszReaderNames[x] = mem_Malloc(strlen(psz)+1);
-    if (!prl->aszReaderNames[x])
-    {
-        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
-        return 0;
-    }
-    prl->ars[x].szReader = prl->aszReaderNames[x];
-    strcpy( prl->aszReaderNames[x], psz );
-
-    // second tuple item is current state
-    o2=PyTuple_GetItem(o, 1);
-    prl->ars[x].dwCurrentState = PyInt_AsLong(o2);
-
-    return 1;
-}
-
-
-/**=============================================================================
-                            BYTELIST Helpers
-==============================================================================*/
-
-/**==========================================================================**/
-void SCardHelper_AppendByteListToPyObject(
-    BYTELIST* source, PyObject** ptarget )
-/*==============================================================================
-builds a Python list from a byte list
-==============================================================================*/
-{
-    PyObject* oByteList;
-
-    // create byte list...
-    if( (NULL!=source) && (NULL!=source->ab) )
-    {
-        unsigned int i;
-        oByteList = PyList_New( source->cBytes );
-        for(i=0; i<source->cBytes; i++)
-        {
-            PyObject* pyby;
-            pyby = Py_BuildValue( "b", source->ab[i] );
-            PyList_SetItem( oByteList, i, pyby );
-        }
-    }
-    else
-    {
-        oByteList = PyList_New( 0 );
-    }
-
-    // append list to target
-    if( !*ptarget )
-    {
-        *ptarget = oByteList;
-    }
-    else if( *ptarget == Py_None )
-    {
-        Py_DECREF(Py_None);
-        *ptarget = oByteList;
-    }
-    else
-    {
-        if( !PyList_Check(*ptarget) )
-        {
-            PyObject* o2 = *ptarget;
-            *ptarget = PyList_New(0);
-            PyList_Append(*ptarget,o2);
-            Py_XDECREF(o2);
-        }
-        PyList_Append(*ptarget,oByteList);
-        Py_XDECREF(oByteList);
-    }
-
-}
-
-
-/**==========================================================================**/
-BYTELIST* SCardHelper_PyByteListToBYTELIST(PyObject* source)
-/*==============================================================================
-build a Python byte list from a BYTELIST
-==============================================================================*/
-{
-    int cBytes, x;
-    BYTELIST* pbl;
-
-
-    // sanity check
-    if (!PyList_Check(source))
-    {
-        PyErr_SetString( PyExc_TypeError, "Expected a list object." );
-        return NULL;
-    }
-
-    cBytes = PyList_Size(source);
-    for( x=0; x<cBytes; x++)
-    {
-        PyObject* o = PyList_GetItem( source, x );
-        if( !PyInt_Check(o) )
-        {
-            PyErr_SetString( PyExc_TypeError, "Expected a list of bytes." );
-            return NULL;
-        }
-    }
-
-
-    pbl=mem_Malloc(sizeof(BYTELIST));
-    if( !pbl )
-    {
-        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
-        return NULL;
-    }
-
-    if (cBytes>0)
-    {
-        pbl->ab = mem_Malloc( cBytes*sizeof(unsigned char) );
-        if( !pbl->ab )
-        {
-            PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
-            mem_Free( pbl );
-            return NULL;
-        }
-    }
-    else
-    {
-        pbl->ab=NULL;
-    }
-    pbl->bAllocated=TRUE;
-    pbl->cBytes=cBytes;
-
-
-    for( x=0; x<cBytes; x++ )
-    {
-        PyObject* o = PyList_GetItem(source, x);
-        pbl->ab[x] = (unsigned char)PyInt_AsLong(o);
-    }
-    return (BYTELIST*)pbl;
-}
-
-/**==========================================================================**/
-void SCardHelper_PrintByteList( BYTELIST* apsz )
-/*==============================================================================
-dump a byte list
-==============================================================================*/
-{
-    unsigned long i;
-
-    for(i=0; i<apsz->cBytes; i++)
-    {
-        printf("0x%.2X ", apsz->ab[i] );
-    }
-    printf("\n");
-}
-
-
-/**=============================================================================
-                            ERRORSTRING Helpers
-==============================================================================*/
-
-/**==========================================================================**/
-void SCardHelper_OutErrorStringAsPyObject(
-    ERRORSTRING* source, PyObject** ptarget )
-/*==============================================================================
-Builds a Python string from an ERRORSTRING
-==============================================================================*/
-{
-    PyObject* pystr;
-
-    if( NULL!=source )
-    {
-        pystr = PyString_FromString( (char*)source );
-        *ptarget = pystr;
-    }
-    else
-    {
-        *ptarget = Py_None;
-        Py_INCREF(Py_None);
-    }
-}
-
-/**=============================================================================
-                            GUIDLIST Helpers
-==============================================================================*/
-
-/**==========================================================================**/
-void SCardHelper_AppendGuidListToPyObject(
-    GUIDLIST* source, PyObject** ptarget )
-/*==============================================================================
-build a Python GUID list from a C GUID list
-==============================================================================*/
-{
-    PyObject* oByte;
-    PyObject* oGuildItem;
-    PyObject* oGuidList;
-    unsigned char* pc;
-    unsigned int i, j;
-
-    // create GUID list...
-    for(;;)
-    {
-        if (source!=NULL)
-        {
-
-            // create GUID list
-            oGuidList = PyList_New( source->cGuids );
-            if(NULL==oGuidList)
-            {
-                PyErr_SetString( PyExc_MemoryError, "Unable to allocate GUID list" );
-                break;
-            }
-            for( i=0; i<source->cGuids; i++)
-            {
-                oGuildItem=PyList_New( sizeof(GUID) );
-                if(NULL==oGuildItem)
-                {
-                    PyErr_SetString( PyExc_MemoryError, "Unable to allocate GUID item list" );
-                    break;
-                }
-                pc=(unsigned char*)&source->aguid[i];
-
-                for (j=0; j<sizeof(GUID); j++)
-                {
-                    oByte = Py_BuildValue( "b", pc[j] );
-                    PyList_SetItem( oGuildItem, j, oByte );
-                }
-                PyList_SetItem( oGuidList, i, oGuildItem );
-            }
-        }
-        else
-        {
-            oGuidList = PyList_New( 0 );
-            if(NULL==oGuidList)
-            {
-                PyErr_SetString( PyExc_MemoryError, "Unable to allocate GUID list" );
-                break;
-            }
-        }
-        break;
-    }
-
-    // append list to target
-    if( !*ptarget )
-    {
-        *ptarget = oGuidList;
-    }
-    else if( *ptarget == Py_None )
-    {
-        Py_DECREF(Py_None);
-        *ptarget = oGuidList;
-    }
-    else
-    {
-        if( !PyList_Check(*ptarget) )
-        {
-            PyObject* o2 = *ptarget;
-            *ptarget = PyList_New(0);
-            PyList_Append(*ptarget,o2);
-            Py_XDECREF(o2);
-        }
-        PyList_Append(*ptarget,oGuidList);
-        Py_XDECREF(oGuidList);
-    }
-
-}
-
-/**==========================================================================**/
-GUIDLIST* SCardHelper_PyGuidListToGUIDLIST(PyObject* source)
-/*==============================================================================
-build a Python byte list from a GUIDLIST
-==============================================================================*/
-{
-    int cBytes, cGuids, x;
-    //int iGuid, iByte;
-    GUIDLIST* pgl;
-    unsigned char* p;
-
-
-    // sanity check
-
-    // do we have a list?
-    if (!PyList_Check(source))
-    {
-        PyErr_SetString( PyExc_TypeError, "Expected a list object." );
-        return NULL;
-    }
-
-    // is the list size a multiple of sizeof(GUID)?
-    cBytes = PyList_Size(source);
-    cGuids = cBytes/sizeof(GUID);
-    if( (size_t)cBytes!=sizeof(GUID)*cGuids )
-    {
-        PyErr_SetString( PyExc_TypeError, "Invalid GUID list size." );
-        return NULL;
-    }
-
-    // is it a list of bytes?
-    for( x=0; x<cBytes; x++)
-    {
-        PyObject* o = PyList_GetItem( source, x );
-        if( !PyInt_Check(o) )
-        {
-            PyErr_SetString( PyExc_TypeError, "Expected a list of bytes." );
-            return NULL;
-        }
-    }
-
-
-    // now we can talk
-
-    // allocate GUIDLIST
-    pgl=mem_Malloc(sizeof(GUIDLIST));
-    if( NULL==pgl )
-    {
-        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
-        return NULL;
-    }
-    pgl->bAllocated=TRUE;
-    pgl->cGuids=cGuids;
-    pgl->hcontext=(unsigned long)NULL;
-
-    // allocate GUIDs in GUID list
-    if (cGuids>0)
-    {
-        pgl->aguid = mem_Malloc( cGuids*sizeof(GUID) );
-        if( NULL==pgl->aguid )
-        {
-            PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
-            mem_Free( pgl );
-            return NULL;
-        }
-    }
-    else
-    {
-        pgl->aguid=NULL;
-    }
-
-
-    // fill individual GUIDs
-    /*
-    for( iGuid=0; iGuidx<cGuids; iGuid++ )
-    {
-        p=(unsigned char*)pgl->aguid+iGuid*sizeof(GUID);
-        for( x=0; x<sizeof(GUID); x++)
-        {
-            PyObject* o = PyList_GetItem(source, x);
-            p[x] = (unsigned char)PyInt_AsLong(o);
-        }
-    }
-    */
-
-    p=(unsigned char*)pgl->aguid;
-    for( x=0; x<cBytes; x++ )
-    {
-        PyObject* o = PyList_GetItem(source, x);
-        p[x] = (unsigned char)PyInt_AsLong(o);
-    }
-
-
-    return (GUIDLIST*)pgl;
-}
-
-/**==========================================================================**/
-void SCardHelper_PrintGuidList( GUIDLIST* apsz )
-/*==============================================================================
-dump a GUID list
-==============================================================================*/
-{
-    unsigned long i, j;
-
-    for(i=0; i<apsz->cGuids; i++)
-    {
-        unsigned char* pc=(unsigned char*)&apsz->aguid[i];
-        for (j=0; j<sizeof(GUID); j++)
-        {
-            printf("0x%.2X ", pc[j] );
-        }
-        printf("\n");
-    }
-}
-
-
-/**=============================================================================
-                            READERSTATELIST Helpers
-==============================================================================*/
-
-/**==========================================================================**/
-void SCardHelper_AppendReaderStateListToPyObject(
-    READERSTATELIST* source, PyObject** ptarget )
-/*==============================================================================
-==============================================================================*/
-{
-    PyObject* oRStateList;
-    //PyObject* o;
-    unsigned int i;
-
-    if(source!=NULL)
-    {
-        oRStateList = PyList_New( source->cRStates );
-        for( i=0; i<source->cRStates; i++ )
-        {
-            PyObject* oReader;
-            PyObject* oEventState;
-            PyObject* oAtr;
-            PyObject* oByte;
-            unsigned int j;
-
-            // reader, event state, atr
-            PyObject* ot = PyTuple_New( 3 );
-            oReader = PyString_FromString( source->ars[i].szReader );
-            oEventState = PyInt_FromLong( source->ars[i].dwEventState );
-            oAtr = PyList_New( source->ars[i].cbAtr );
-            for(j=0; j<source->ars[i].cbAtr; j++)
-            {
-                oByte = PyInt_FromLong( source->ars[i].rgbAtr[j] );
-                PyList_SetItem( oAtr, j, oByte );
-            }
-
-            PyTuple_SetItem( ot, 0, oReader );
-            PyTuple_SetItem( ot, 1, oEventState );
-            PyTuple_SetItem( ot, 2, oAtr );
-
-            PyList_SetItem( oRStateList, i, ot );
-
-        }
-    }
-    else
-    {
-        oRStateList = PyList_New( 0 );
-    }
-
-    if( !*ptarget )
-    {
-        *ptarget = oRStateList;
-    }
-    else if( *ptarget == Py_None )
-    {
-        Py_DECREF(Py_None);
-        *ptarget = oRStateList;
-    }
-    else
-    {
-
-        if( !PyList_Check(*ptarget) )
-        {
-            PyObject* o2 = *ptarget;
-            *ptarget = PyList_New(0);
-            PyList_Append(*ptarget,o2);
-            Py_XDECREF(o2);
-        }
-        PyList_Append(*ptarget,oRStateList);
-        Py_XDECREF(oRStateList);
-    }
-}
-
-/**==========================================================================**/
-READERSTATELIST* SCardHelper_PyReaderStateListToREADERSTATELIST(PyObject* source)
-/*==============================================================================
-build a READERSTATELIST from a Python list of reader states
-==============================================================================*/
-{
-    unsigned int cRStates, x;
-    READERSTATELIST* prl;
-
-
-    // sanity check
-    if (!PyList_Check(source))
-    {
-        PyErr_SetString( PyExc_TypeError, "Expected a list object." );
-        return NULL;
-    }
-
-    cRStates = PyList_Size(source);
-    for( x=0; x<cRStates; x++)
-    {
-        PyObject* o = PyList_GetItem( source, x );
-        if( !PyTuple_Check(o) )
-        {
-            PyErr_SetString( PyExc_TypeError, "Expected a list of tuples." );
-            return NULL;
-        }
-
-        if( !_IsAReaderState(o) )
-        {
-            return NULL;
-        }
-
-    }
-
-    prl=mem_Malloc(sizeof(READERSTATELIST));
-    if(!prl)
-    {
-        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
-        return NULL;
-    }
-    //prl->bAllocated=TRUE;
-    prl->cRStates = cRStates;
-
-    prl->ars = mem_Malloc( cRStates*sizeof(SCARD_READERSTATE) );
-    if (!prl->ars)
-    {
-        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
-        mem_Free( prl );
-        return NULL;
-    }
-
-    prl->aszReaderNames = mem_Malloc( cRStates*sizeof(char*) );
-    if (!prl->aszReaderNames)
-    {
-        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
-        mem_Free( prl->ars );
-        mem_Free( prl );
-        return NULL;
-    }
-
-    for( x=0; x<cRStates; x++ )
-    {
-        PyObject* o = PyList_GetItem(source, x);
-
-        int iRes = _ReaderStateFromTuple( o, prl, x );
-        if(!iRes)
-        {
-            unsigned int j;
-            for(j=0; j<x; j++)
-            {
-                mem_Free( prl->aszReaderNames[x] );
-            }
-            mem_Free( prl->ars );
-            mem_Free( prl );
-            return NULL;
-        }
-    }
-    return (READERSTATELIST*)prl;
-}
-
-/**==========================================================================**/
-void SCardHelper_PrintReaderStateList( READERSTATELIST* prl )
-/*==============================================================================
-dump a reader state list
-==============================================================================*/
-{
-    unsigned int i, j;
-
-    for( i=0; prl && i<prl->cRStates; i++ )
-    {
-        printf("%s userdata: %lx current: %lx event: %lx \n",
-            prl->ars[i].szReader,
-            prl->ars[i].pvUserData,
-            prl->ars[i].dwCurrentState,
-            prl->ars[i].dwEventState );
-        for(j=0; j<prl->ars[i].cbAtr; j++ )
-        {
-            printf("0x%.2X ", prl->ars[i].rgbAtr[j] );
-        }
-        printf("\n");
-
-        if(prl->ars[i].dwEventState & SCARD_STATE_UNAWARE)
-        {
-            printf("Card state unaware\n");
-        }
-        if(prl->ars[i].dwEventState & SCARD_STATE_IGNORE)
-        {
-            printf("Card state ignore\n");
-        }
-        if(prl->ars[i].dwEventState & SCARD_STATE_CHANGED)
-        {
-            printf("Card state changed\n");
-        }
-        if(prl->ars[i].dwEventState & SCARD_STATE_UNKNOWN)
-        {
-            printf("Card state unknown\n");
-        }
-        if(prl->ars[i].dwEventState & SCARD_STATE_UNAVAILABLE)
-        {
-            printf("Card state unavailable\n");
-        }
-        if(prl->ars[i].dwEventState & SCARD_STATE_EMPTY)
-        {
-            printf("No card in reader\n");
-        }
-        if(prl->ars[i].dwEventState & SCARD_STATE_PRESENT)
-        {
-            printf("Card in reader\n");
-        }
-        if(prl->ars[i].dwEventState & SCARD_STATE_ATRMATCH)
-        {
-            printf("Card found\n");
-        }
-        if(prl->ars[i].dwEventState & SCARD_STATE_EXCLUSIVE)
-        {
-            printf("Card in reader allocated for exclusive use by another application\n");
-        }
-        if(prl->ars[i].dwEventState & SCARD_STATE_INUSE)
-        {
-            printf("Card in reader is in use but can be shared\n");
-        }
-        if(prl->ars[i].dwEventState & SCARD_STATE_MUTE)
-        {
-            printf("Card in reader is mute\n");
-        }
-    }
-}
-
-/**=============================================================================
-                            STRING Helpers
-==============================================================================*/
-
-/**==========================================================================**/
-void SCardHelper_AppendStringToPyObject(
-    STRING* source, PyObject** ptarget )
-/*==============================================================================
-Builds a Python string from a STRING
-==============================================================================*/
-{
-    PyObject* pystr;
-
-    if(NULL!=source)
-    {
-        if(NULL!=source->sz)
-        {
-            pystr = PyString_FromString( source->sz );
-        }
-        else
-        {
-            pystr = Py_None;
-            Py_INCREF(Py_None);
-        }
-        if( !*ptarget )
-        {
-            *ptarget = pystr;
-        }
-        else if( *ptarget == Py_None )
-        {
-            Py_DECREF(Py_None);
-            *ptarget = pystr;
-        }
-        else
-        {
-
-            if( !PyList_Check(*ptarget) )
-            {
-                PyObject* o2 = *ptarget;
-                *ptarget = PyList_New(0);
-                PyList_Append(*ptarget,o2);
-                Py_XDECREF(o2);
-            }
-            PyList_Append( *ptarget, pystr );
-            Py_XDECREF( pystr );
-        }
-    }
-    else
-    {
-        if( !*ptarget )
-        {
-            *ptarget = Py_None;
-            Py_INCREF(Py_None);
-        }
-    }
-}
-
-/**==========================================================================**/
-STRING* SCardHelper_PyStringToString( PyObject* source )
-/*==============================================================================
-Build a STRING from a Python string; the string is allocated and
-will have to be freed externally to the wrapper
-==============================================================================*/
-{
-    unsigned long ulLength;
-    STRING* pstr=NULL;
-
-    for(;;)
-    {
-        // sanity check
-        if( !PyString_Check( source ) )
-        {
-            PyErr_SetString( PyExc_TypeError, "Expected a string." );
-            break;
-        }
-
-        pstr=(STRING*)mem_Malloc( sizeof(STRING) );
-        if(NULL==pstr)
-        {
-            PyErr_SetString( PyExc_MemoryError, "Unable to allocate STRING" );
-            break;
-        }
-
-        ulLength=strlen( PyString_AsString(source)) + 1 ;
-        pstr->sz=(char*)mem_Malloc( ulLength );
-        if(NULL==pstr->sz)
-        {
-            PyErr_SetString( PyExc_MemoryError, "Unable to allocate STRING buffer" );
-            break;
-        }
-
-        strcpy( pstr->sz, PyString_AsString( source ) );
-        break;
-    }
-
-    return pstr;
-}
-
-/**==========================================================================**/
-void SCardHelper_PrintString( STRING* str )
-/*==============================================================================
-dump a string list
-==============================================================================*/
-{
-    if(NULL!=str)
-    {
-        char* p=str->sz;
-        if( NULL!=p)
-        {
-            printf("%s ", p );
-        }
-    }
-}
-
-/**=============================================================================
-                            STRINGLIST Helpers
-==============================================================================*/
-
-
-/**==========================================================================**/
-void SCardHelper_AppendStringListToPyObject(
-    STRINGLIST* source, PyObject** ptarget )
-/*==============================================================================
-builds a Python list from a STRINGLIST; the multi-string list in the STRINGLIST
-is stored as series of null-terminated strings terminated by a null,
-e.g. item0\0item2\0lastitem\0\0)
-==============================================================================*/
-{
-    unsigned int cStr;
-    char* p=source->ac;
-    PyObject* oStrList;
-    //PyObject* o;
-
-    // count STRs in STRINGLIST list
-    if( NULL!=p )
-    {
-        unsigned int i;
-        for( i=0, cStr=0; ; i+=lstrlen( p+i ) + 1 )
-        {
-            if (lstrlen( p+i ) > 0)
-            {
-                cStr++;
-            }
-            else
-            {
-                break;
-            }
-        }
-    }
-    else
-    {
-        cStr=0;
-    }
-
-    // create STR list...
-    if( NULL!=p )
-    {
-        unsigned int i, j;
-        oStrList = PyList_New( cStr );
-        for( i=0, j=0; ; j++, i+=lstrlen( p+i ) + 1 )
-        {
-            if (lstrlen( p+i ) > 0)
-            {
-                PyObject* pystr;
-                pystr = PyString_FromString( p+i );
-                PyList_SetItem( oStrList, j, pystr );
-            }
-            else
-            {
-                break;
-            }
-        }
-    }
-    else
-    {
-        oStrList = PyList_New( cStr );
-    }
-
-    if( !*ptarget )
-    {
-        *ptarget = oStrList;
-    }
-    else if( *ptarget == Py_None )
-    {
-        Py_DECREF(Py_None);
-        *ptarget = oStrList;
-    }
-    else
-    {
-
-        if( !PyList_Check(*ptarget) )
-        {
-            PyObject* o2 = *ptarget;
-            *ptarget = PyList_New(0);
-            PyList_Append(*ptarget,o2);
-            Py_XDECREF(o2);
-        }
-        PyList_Append(*ptarget,oStrList);
-        Py_XDECREF(oStrList);
-    }
-
-}
-
-/**==========================================================================**/
-STRINGLIST* SCardHelper_PyStringListToStringList(PyObject* source)
-/*==============================================================================
-build a Python string list from a STRINGLIST
-==============================================================================*/
-{
-    int cStrings, cChars, x;
-    STRINGLIST* psl;
-    char* p;
-
-
-    // sanity check
-    if (!PyList_Check(source))
-    {
-        PyErr_SetString( PyExc_TypeError, "Expected a list object." );
-        return NULL;
-    }
-
-    cStrings = PyList_Size(source);
-    for( x=0, cChars=0; x<cStrings; x++)
-    {
-        PyObject* o = PyList_GetItem( source, x );
-        if( !PyString_Check(o) )
-        {
-            PyErr_SetString( PyExc_TypeError, "Expected a list of strings." );
-            return NULL;
-        }
-        cChars += strlen( PyString_AsString(o)) + 1 ;
-    }
-    cChars += 1;
-
-    psl=mem_Malloc(sizeof(STRINGLIST));
-    if(!psl)
-    {
-        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
-        return NULL;
-    }
-    psl->bAllocated=TRUE;
-    psl->hcontext = 0;
-
-    if ( cChars>1 )
-    {
-        psl->ac = mem_Malloc( cChars*sizeof(char) );
-        if (!psl->ac)
-        {
-            PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
-            mem_Free( psl );
-            return NULL;
-        }
-
-        for( x=0, cChars=0, p=psl->ac; x<cStrings; x++ )
-        {
-            PyObject* o = PyList_GetItem(source, x);
-            strcpy( p, PyString_AsString(o) );
-            p += strlen( PyString_AsString(o) ) + 1;
-        }
-        strcpy( p, "\0" );
-    }
-    else
-    {
-        psl->ac=NULL;
-    }
-    return (STRINGLIST*)psl;
-}
-
-
-/**==========================================================================**/
-void SCardHelper_PrintStringList( STRINGLIST* sl )
-/*==============================================================================
-dump a string list
-==============================================================================*/
-{
-    char* p=(char*)sl->ac;
-    unsigned int i;
-
-    for( i=0; ; i+=lstrlen( p+i ) + 1 )
-    {
-        if (lstrlen( p+i ) > 0)
-        {
-            printf("%s ", p+i );
-        }
-        else
-        {
-            printf("\n" );
-            break;
-        }
-    }
-}
-
-#ifdef WIN32
-/**==========================================================================**/
-BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
-/*==============================================================================
-Initialize and clean-up memory logging on process attach and detach
-==============================================================================*/
-{
-    switch(fdwReason)
-    {
-        case DLL_PROCESS_ATTACH:
-            if (!mem_Init())
-            {
-                fprintf( stderr, "Failed to initialize memory logging services!\n" );
-            }
-            break;
-
-        case DLL_THREAD_ATTACH:
-            break;
-
-        case DLL_THREAD_DETACH:
-            break;
-
-        case DLL_PROCESS_DETACH:
-            if (!mem_CleanUp())
-            {
-                fprintf( stderr, "Failed to cleanup memory logging services!\n" );
-            }
-            break;
-    }
-    return TRUE;
-
-    return 1;
-}
-#endif // WIN32
-
-
-
-
+/*==============================================================================
+Copyright 2001-2007 gemalto
+Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com
+
+This file is part of pyscard.
+
+pyscard 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.
+
+pyscard 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 pyscard; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+==============================================================================*/
+#include <assert.h>
+#ifdef WIN32
+    #include <windows.h>
+#endif
+#include <winscard.h>
+#include <Python.h>
+
+#include "helpers.h"
+#include "memlog.h"
+
+extern PyObject* PyExc_SCardError;
+
+#ifdef PCSCLITE
+    #define FALSE (0==1)
+    #define TRUE (1==1)
+    #define lstrlen strlen
+#endif // PCSCLITE
+
+/**==========================================================================**/
+static int _IsAReaderState( PyObject* o)
+/*==============================================================================
+==============================================================================*/
+{
+    PyObject* o2;
+
+    // expecting at least 2 items: reader name and current state
+    if( (PyTuple_Size(o)!=2) && (PyTuple_Size(o)!=3) )
+    {
+        PyErr_SetString( PyExc_TypeError, "Expecting two or three items in tuple." );
+        return 0;
+    }
+
+    o2 = PyTuple_GetItem(o, 0);
+    if(!PyString_Check(o2))
+    {
+        PyErr_SetString( PyExc_TypeError, "Expected a string as reader name." );
+        return 0;
+    }
+    o2 = PyTuple_GetItem(o, 1);
+    if(!PyInt_Check(o2))
+    {
+        PyErr_SetString( PyExc_TypeError, "Expected an Int as second tuple item." );
+        return 0;
+    }
+    if(PyTuple_Size(o)==3)
+    {
+        o2 = PyTuple_GetItem(o, 2);
+        if(!PyList_Check(o2))
+        {
+            PyErr_SetString( PyExc_TypeError, "Expected a list as third tuple item." );
+            return 0;
+        }
+    }
+    return 1;
+}
+
+/**==========================================================================**/
+static int _ReaderStateFromTuple( PyObject* o, READERSTATELIST* prl, unsigned int x )
+/*==============================================================================
+==============================================================================*/
+{
+    char* psz;
+    PyObject* o2;
+
+    // first tuple item is reader name
+    o2=PyTuple_GetItem(o, 0);
+    psz = PyString_AsString(o2);
+    prl->aszReaderNames[x] = mem_Malloc(strlen(psz)+1);
+    if (!prl->aszReaderNames[x])
+    {
+        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
+        return 0;
+    }
+    prl->ars[x].szReader = prl->aszReaderNames[x];
+    strcpy( prl->aszReaderNames[x], psz );
+
+    // second tuple item is current state
+    o2=PyTuple_GetItem(o, 1);
+    prl->ars[x].dwCurrentState = PyInt_AsLong(o2);
+
+    return 1;
+}
+
+
+/**=============================================================================
+                            BYTELIST Helpers
+==============================================================================*/
+
+/**==========================================================================**/
+void SCardHelper_AppendByteListToPyObject(
+    BYTELIST* source, PyObject** ptarget )
+/*==============================================================================
+builds a Python list from a byte list
+==============================================================================*/
+{
+    PyObject* oByteList;
+
+    // create byte list...
+    if( (NULL!=source) && (NULL!=source->ab) )
+    {
+        unsigned int i;
+        oByteList = PyList_New( source->cBytes );
+        for(i=0; i<source->cBytes; i++)
+        {
+            PyObject* pyby;
+            pyby = Py_BuildValue( "b", source->ab[i] );
+            PyList_SetItem( oByteList, i, pyby );
+        }
+    }
+    else
+    {
+        oByteList = PyList_New( 0 );
+    }
+
+    // append list to target
+    if( !*ptarget )
+    {
+        *ptarget = oByteList;
+    }
+    else if( *ptarget == Py_None )
+    {
+        Py_DECREF(Py_None);
+        *ptarget = oByteList;
+    }
+    else
+    {
+        if( !PyList_Check(*ptarget) )
+        {
+            PyObject* o2 = *ptarget;
+            *ptarget = PyList_New(0);
+            PyList_Append(*ptarget,o2);
+            Py_XDECREF(o2);
+        }
+        PyList_Append(*ptarget,oByteList);
+        Py_XDECREF(oByteList);
+    }
+
+}
+
+
+/**==========================================================================**/
+BYTELIST* SCardHelper_PyByteListToBYTELIST(PyObject* source)
+/*==============================================================================
+build a Python byte list from a BYTELIST
+==============================================================================*/
+{
+    int cBytes, x;
+    BYTELIST* pbl;
+
+
+    // sanity check
+    if (!PyList_Check(source))
+    {
+        PyErr_SetString( PyExc_TypeError, "Expected a list object." );
+        return NULL;
+    }
+
+    cBytes = PyList_Size(source);
+    for( x=0; x<cBytes; x++)
+    {
+        PyObject* o = PyList_GetItem( source, x );
+        if( !PyInt_Check(o) )
+        {
+            PyErr_SetString( PyExc_TypeError, "Expected a list of bytes." );
+            return NULL;
+        }
+    }
+
+
+    pbl=mem_Malloc(sizeof(BYTELIST));
+    if( !pbl )
+    {
+        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
+        return NULL;
+    }
+
+    if (cBytes>0)
+    {
+        pbl->ab = mem_Malloc( cBytes*sizeof(unsigned char) );
+        if( !pbl->ab )
+        {
+            PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
+            mem_Free( pbl );
+            return NULL;
+        }
+    }
+    else
+    {
+        pbl->ab=NULL;
+    }
+    pbl->bAllocated=TRUE;
+    pbl->cBytes=cBytes;
+
+
+    for( x=0; x<cBytes; x++ )
+    {
+        PyObject* o = PyList_GetItem(source, x);
+        pbl->ab[x] = (unsigned char)PyInt_AsLong(o);
+    }
+    return (BYTELIST*)pbl;
+}
+
+/**==========================================================================**/
+void SCardHelper_PrintByteList( BYTELIST* apsz )
+/*==============================================================================
+dump a byte list
+==============================================================================*/
+{
+    unsigned long i;
+
+    for(i=0; i<apsz->cBytes; i++)
+    {
+        printf("0x%.2X ", apsz->ab[i] );
+    }
+    printf("\n");
+}
+
+
+/**=============================================================================
+                            ERRORSTRING Helpers
+==============================================================================*/
+
+/**==========================================================================**/
+void SCardHelper_OutErrorStringAsPyObject(
+    ERRORSTRING* source, PyObject** ptarget )
+/*==============================================================================
+Builds a Python string from an ERRORSTRING
+==============================================================================*/
+{
+    PyObject* pystr;
+
+    if( NULL!=source )
+    {
+        pystr = PyString_FromString( (char*)source );
+        *ptarget = pystr;
+    }
+    else
+    {
+        *ptarget = Py_None;
+        Py_INCREF(Py_None);
+    }
+}
+
+/**=============================================================================
+                            GUIDLIST Helpers
+==============================================================================*/
+
+/**==========================================================================**/
+void SCardHelper_AppendGuidListToPyObject(
+    GUIDLIST* source, PyObject** ptarget )
+/*==============================================================================
+build a Python GUID list from a C GUID list
+==============================================================================*/
+{
+    PyObject* oByte;
+    PyObject* oGuildItem;
+    PyObject* oGuidList;
+    unsigned char* pc;
+    unsigned int i, j;
+
+    // create GUID list...
+    for(;;)
+    {
+        if (source!=NULL)
+        {
+
+            // create GUID list
+            oGuidList = PyList_New( source->cGuids );
+            if(NULL==oGuidList)
+            {
+                PyErr_SetString( PyExc_MemoryError, "Unable to allocate GUID list" );
+                break;
+            }
+            for( i=0; i<source->cGuids; i++)
+            {
+                oGuildItem=PyList_New( sizeof(GUID) );
+                if(NULL==oGuildItem)
+                {
+                    PyErr_SetString( PyExc_MemoryError, "Unable to allocate GUID item list" );
+                    break;
+                }
+                pc=(unsigned char*)&source->aguid[i];
+
+                for (j=0; j<sizeof(GUID); j++)
+                {
+                    oByte = Py_BuildValue( "b", pc[j] );
+                    PyList_SetItem( oGuildItem, j, oByte );
+                }
+                PyList_SetItem( oGuidList, i, oGuildItem );
+            }
+        }
+        else
+        {
+            oGuidList = PyList_New( 0 );
+            if(NULL==oGuidList)
+            {
+                PyErr_SetString( PyExc_MemoryError, "Unable to allocate GUID list" );
+                break;
+            }
+        }
+        break;
+    }
+
+    // append list to target
+    if( !*ptarget )
+    {
+        *ptarget = oGuidList;
+    }
+    else if( *ptarget == Py_None )
+    {
+        Py_DECREF(Py_None);
+        *ptarget = oGuidList;
+    }
+    else
+    {
+        if( !PyList_Check(*ptarget) )
+        {
+            PyObject* o2 = *ptarget;
+            *ptarget = PyList_New(0);
+            PyList_Append(*ptarget,o2);
+            Py_XDECREF(o2);
+        }
+        PyList_Append(*ptarget,oGuidList);
+        Py_XDECREF(oGuidList);
+    }
+
+}
+
+/**==========================================================================**/
+GUIDLIST* SCardHelper_PyGuidListToGUIDLIST(PyObject* source)
+/*==============================================================================
+build a Python byte list from a GUIDLIST
+==============================================================================*/
+{
+    int cBytes, cGuids, x;
+    //int iGuid, iByte;
+    GUIDLIST* pgl;
+    unsigned char* p;
+
+
+    // sanity check
+
+    // do we have a list?
+    if (!PyList_Check(source))
+    {
+        PyErr_SetString( PyExc_TypeError, "Expected a list object." );
+        return NULL;
+    }
+
+    // is the list size a multiple of sizeof(GUID)?
+    cBytes = PyList_Size(source);
+    cGuids = cBytes/sizeof(GUID);
+    if( (size_t)cBytes!=sizeof(GUID)*cGuids )
+    {
+        PyErr_SetString( PyExc_TypeError, "Invalid GUID list size." );
+        return NULL;
+    }
+
+    // is it a list of bytes?
+    for( x=0; x<cBytes; x++)
+    {
+        PyObject* o = PyList_GetItem( source, x );
+        if( !PyInt_Check(o) )
+        {
+            PyErr_SetString( PyExc_TypeError, "Expected a list of bytes." );
+            return NULL;
+        }
+    }
+
+
+    // now we can talk
+
+    // allocate GUIDLIST
+    pgl=mem_Malloc(sizeof(GUIDLIST));
+    if( NULL==pgl )
+    {
+        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
+        return NULL;
+    }
+    pgl->bAllocated=TRUE;
+    pgl->cGuids=cGuids;
+    pgl->hcontext=(unsigned long)NULL;
+
+    // allocate GUIDs in GUID list
+    if (cGuids>0)
+    {
+        pgl->aguid = mem_Malloc( cGuids*sizeof(GUID) );
+        if( NULL==pgl->aguid )
+        {
+            PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
+            mem_Free( pgl );
+            return NULL;
+        }
+    }
+    else
+    {
+        pgl->aguid=NULL;
+    }
+
+
+    // fill individual GUIDs
+    /*
+    for( iGuid=0; iGuidx<cGuids; iGuid++ )
+    {
+        p=(unsigned char*)pgl->aguid+iGuid*sizeof(GUID);
+        for( x=0; x<sizeof(GUID); x++)
+        {
+            PyObject* o = PyList_GetItem(source, x);
+            p[x] = (unsigned char)PyInt_AsLong(o);
+        }
+    }
+    */
+
+    p=(unsigned char*)pgl->aguid;
+    for( x=0; x<cBytes; x++ )
+    {
+        PyObject* o = PyList_GetItem(source, x);
+        p[x] = (unsigned char)PyInt_AsLong(o);
+    }
+
+
+    return (GUIDLIST*)pgl;
+}
+
+/**==========================================================================**/
+void SCardHelper_PrintGuidList( GUIDLIST* apsz )
+/*==============================================================================
+dump a GUID list
+==============================================================================*/
+{
+    unsigned long i, j;
+
+    for(i=0; i<apsz->cGuids; i++)
+    {
+        unsigned char* pc=(unsigned char*)&apsz->aguid[i];
+        for (j=0; j<sizeof(GUID); j++)
+        {
+            printf("0x%.2X ", pc[j] );
+        }
+        printf("\n");
+    }
+}
+
+
+/**=============================================================================
+                            READERSTATELIST Helpers
+==============================================================================*/
+
+/**==========================================================================**/
+void SCardHelper_AppendReaderStateListToPyObject(
+    READERSTATELIST* source, PyObject** ptarget )
+/*==============================================================================
+==============================================================================*/
+{
+    PyObject* oRStateList;
+    //PyObject* o;
+    unsigned int i;
+
+    if(source!=NULL)
+    {
+        oRStateList = PyList_New( source->cRStates );
+        for( i=0; i<source->cRStates; i++ )
+        {
+            PyObject* oReader;
+            PyObject* oEventState;
+            PyObject* oAtr;
+            PyObject* oByte;
+            unsigned int j;
+
+            // reader, event state, atr
+            PyObject* ot = PyTuple_New( 3 );
+            oReader = PyString_FromString( source->ars[i].szReader );
+            oEventState = PyInt_FromLong( source->ars[i].dwEventState );
+            oAtr = PyList_New( source->ars[i].cbAtr );
+            for(j=0; j<source->ars[i].cbAtr; j++)
+            {
+                oByte = PyInt_FromLong( source->ars[i].rgbAtr[j] );
+                PyList_SetItem( oAtr, j, oByte );
+            }
+
+            PyTuple_SetItem( ot, 0, oReader );
+            PyTuple_SetItem( ot, 1, oEventState );
+            PyTuple_SetItem( ot, 2, oAtr );
+
+            PyList_SetItem( oRStateList, i, ot );
+
+        }
+    }
+    else
+    {
+        oRStateList = PyList_New( 0 );
+    }
+
+    if( !*ptarget )
+    {
+        *ptarget = oRStateList;
+    }
+    else if( *ptarget == Py_None )
+    {
+        Py_DECREF(Py_None);
+        *ptarget = oRStateList;
+    }
+    else
+    {
+
+        if( !PyList_Check(*ptarget) )
+        {
+            PyObject* o2 = *ptarget;
+            *ptarget = PyList_New(0);
+            PyList_Append(*ptarget,o2);
+            Py_XDECREF(o2);
+        }
+        PyList_Append(*ptarget,oRStateList);
+        Py_XDECREF(oRStateList);
+    }
+}
+
+/**==========================================================================**/
+READERSTATELIST* SCardHelper_PyReaderStateListToREADERSTATELIST(PyObject* source)
+/*==============================================================================
+build a READERSTATELIST from a Python list of reader states
+==============================================================================*/
+{
+    unsigned int cRStates, x;
+    READERSTATELIST* prl;
+
+
+    // sanity check
+    if (!PyList_Check(source))
+    {
+        PyErr_SetString( PyExc_TypeError, "Expected a list object." );
+        return NULL;
+    }
+
+    cRStates = PyList_Size(source);
+    for( x=0; x<cRStates; x++)
+    {
+        PyObject* o = PyList_GetItem( source, x );
+        if( !PyTuple_Check(o) )
+        {
+            PyErr_SetString( PyExc_TypeError, "Expected a list of tuples." );
+            return NULL;
+        }
+
+        if( !_IsAReaderState(o) )
+        {
+            return NULL;
+        }
+
+    }
+
+    prl=mem_Malloc(sizeof(READERSTATELIST));
+    if(!prl)
+    {
+        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
+        return NULL;
+    }
+    //prl->bAllocated=TRUE;
+    prl->cRStates = cRStates;
+
+    prl->ars = mem_Malloc( cRStates*sizeof(SCARD_READERSTATE) );
+    if (!prl->ars)
+    {
+        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
+        mem_Free( prl );
+        return NULL;
+    }
+
+    prl->aszReaderNames = mem_Malloc( cRStates*sizeof(char*) );
+    if (!prl->aszReaderNames)
+    {
+        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
+        mem_Free( prl->ars );
+        mem_Free( prl );
+        return NULL;
+    }
+
+    for( x=0; x<cRStates; x++ )
+    {
+        PyObject* o = PyList_GetItem(source, x);
+
+        int iRes = _ReaderStateFromTuple( o, prl, x );
+        if(!iRes)
+        {
+            unsigned int j;
+            for(j=0; j<x; j++)
+            {
+                mem_Free( prl->aszReaderNames[x] );
+            }
+            mem_Free( prl->ars );
+            mem_Free( prl );
+            return NULL;
+        }
+    }
+    return (READERSTATELIST*)prl;
+}
+
+/**==========================================================================**/
+void SCardHelper_PrintReaderStateList( READERSTATELIST* prl )
+/*==============================================================================
+dump a reader state list
+==============================================================================*/
+{
+    unsigned int i, j;
+
+    for( i=0; prl && i<prl->cRStates; i++ )
+    {
+        printf("%s userdata: %p current: %lx event: %lx \n",
+            prl->ars[i].szReader,
+            prl->ars[i].pvUserData,
+            prl->ars[i].dwCurrentState,
+            prl->ars[i].dwEventState );
+        for(j=0; j<prl->ars[i].cbAtr; j++ )
+        {
+            printf("0x%.2X ", prl->ars[i].rgbAtr[j] );
+        }
+        printf("\n");
+
+        if(prl->ars[i].dwEventState & SCARD_STATE_UNAWARE)
+        {
+            printf("Card state unaware\n");
+        }
+        if(prl->ars[i].dwEventState & SCARD_STATE_IGNORE)
+        {
+            printf("Card state ignore\n");
+        }
+        if(prl->ars[i].dwEventState & SCARD_STATE_CHANGED)
+        {
+            printf("Card state changed\n");
+        }
+        if(prl->ars[i].dwEventState & SCARD_STATE_UNKNOWN)
+        {
+            printf("Card state unknown\n");
+        }
+        if(prl->ars[i].dwEventState & SCARD_STATE_UNAVAILABLE)
+        {
+            printf("Card state unavailable\n");
+        }
+        if(prl->ars[i].dwEventState & SCARD_STATE_EMPTY)
+        {
+            printf("No card in reader\n");
+        }
+        if(prl->ars[i].dwEventState & SCARD_STATE_PRESENT)
+        {
+            printf("Card in reader\n");
+        }
+        if(prl->ars[i].dwEventState & SCARD_STATE_ATRMATCH)
+        {
+            printf("Card found\n");
+        }
+        if(prl->ars[i].dwEventState & SCARD_STATE_EXCLUSIVE)
+        {
+            printf("Card in reader allocated for exclusive use by another application\n");
+        }
+        if(prl->ars[i].dwEventState & SCARD_STATE_INUSE)
+        {
+            printf("Card in reader is in use but can be shared\n");
+        }
+        if(prl->ars[i].dwEventState & SCARD_STATE_MUTE)
+        {
+            printf("Card in reader is mute\n");
+        }
+    }
+}
+
+/**=============================================================================
+                            STRING Helpers
+==============================================================================*/
+
+/**==========================================================================**/
+void SCardHelper_AppendStringToPyObject(
+    STRING* source, PyObject** ptarget )
+/*==============================================================================
+Builds a Python string from a STRING
+==============================================================================*/
+{
+    PyObject* pystr;
+
+    if(NULL!=source)
+    {
+        if(NULL!=source->sz)
+        {
+            pystr = PyString_FromString( source->sz );
+        }
+        else
+        {
+            pystr = Py_None;
+            Py_INCREF(Py_None);
+        }
+        if( !*ptarget )
+        {
+            *ptarget = pystr;
+        }
+        else if( *ptarget == Py_None )
+        {
+            Py_DECREF(Py_None);
+            *ptarget = pystr;
+        }
+        else
+        {
+
+            if( !PyList_Check(*ptarget) )
+            {
+                PyObject* o2 = *ptarget;
+                *ptarget = PyList_New(0);
+                PyList_Append(*ptarget,o2);
+                Py_XDECREF(o2);
+            }
+            PyList_Append( *ptarget, pystr );
+            Py_XDECREF( pystr );
+        }
+    }
+    else
+    {
+        if( !*ptarget )
+        {
+            *ptarget = Py_None;
+            Py_INCREF(Py_None);
+        }
+    }
+}
+
+/**==========================================================================**/
+STRING* SCardHelper_PyStringToString( PyObject* source )
+/*==============================================================================
+Build a STRING from a Python string; the string is allocated and
+will have to be freed externally to the wrapper
+==============================================================================*/
+{
+    unsigned long ulLength;
+    STRING* pstr=NULL;
+
+    for(;;)
+    {
+        // sanity check
+        if( !PyString_Check( source ) )
+        {
+            PyErr_SetString( PyExc_TypeError, "Expected a string." );
+            break;
+        }
+
+        pstr=(STRING*)mem_Malloc( sizeof(STRING) );
+        if(NULL==pstr)
+        {
+            PyErr_SetString( PyExc_MemoryError, "Unable to allocate STRING" );
+            break;
+        }
+
+        ulLength=strlen( PyString_AsString(source)) + 1 ;
+        pstr->sz=(char*)mem_Malloc( ulLength );
+        if(NULL==pstr->sz)
+        {
+            PyErr_SetString( PyExc_MemoryError, "Unable to allocate STRING buffer" );
+            break;
+        }
+
+        strcpy( pstr->sz, PyString_AsString( source ) );
+        break;
+    }
+
+    return pstr;
+}
+
+/**==========================================================================**/
+void SCardHelper_PrintString( STRING* str )
+/*==============================================================================
+dump a string list
+==============================================================================*/
+{
+    if(NULL!=str)
+    {
+        char* p=str->sz;
+        if( NULL!=p)
+        {
+            printf("%s ", p );
+        }
+    }
+}
+
+/**=============================================================================
+                            STRINGLIST Helpers
+==============================================================================*/
+
+
+/**==========================================================================**/
+void SCardHelper_AppendStringListToPyObject(
+    STRINGLIST* source, PyObject** ptarget )
+/*==============================================================================
+builds a Python list from a STRINGLIST; the multi-string list in the STRINGLIST
+is stored as series of null-terminated strings terminated by a null,
+e.g. item0\0item2\0lastitem\0\0)
+==============================================================================*/
+{
+    unsigned int cStr;
+    char* p=source->ac;
+    PyObject* oStrList;
+    //PyObject* o;
+
+    // count STRs in STRINGLIST list
+    if( NULL!=p )
+    {
+        unsigned int i;
+        for( i=0, cStr=0; ; i+=lstrlen( p+i ) + 1 )
+        {
+            if (lstrlen( p+i ) > 0)
+            {
+                cStr++;
+            }
+            else
+            {
+                break;
+            }
+        }
+    }
+    else
+    {
+        cStr=0;
+    }
+
+    // create STR list...
+    if( NULL!=p )
+    {
+        unsigned int i, j;
+        oStrList = PyList_New( cStr );
+        for( i=0, j=0; ; j++, i+=lstrlen( p+i ) + 1 )
+        {
+            if (lstrlen( p+i ) > 0)
+            {
+                PyObject* pystr;
+                pystr = PyString_FromString( p+i );
+                PyList_SetItem( oStrList, j, pystr );
+            }
+            else
+            {
+                break;
+            }
+        }
+    }
+    else
+    {
+        oStrList = PyList_New( cStr );
+    }
+
+    if( !*ptarget )
+    {
+        *ptarget = oStrList;
+    }
+    else if( *ptarget == Py_None )
+    {
+        Py_DECREF(Py_None);
+        *ptarget = oStrList;
+    }
+    else
+    {
+
+        if( !PyList_Check(*ptarget) )
+        {
+            PyObject* o2 = *ptarget;
+            *ptarget = PyList_New(0);
+            PyList_Append(*ptarget,o2);
+            Py_XDECREF(o2);
+        }
+        PyList_Append(*ptarget,oStrList);
+        Py_XDECREF(oStrList);
+    }
+
+}
+
+/**==========================================================================**/
+STRINGLIST* SCardHelper_PyStringListToStringList(PyObject* source)
+/*==============================================================================
+build a Python string list from a STRINGLIST
+==============================================================================*/
+{
+    int cStrings, cChars, x;
+    STRINGLIST* psl;
+    char* p;
+
+
+    // sanity check
+    if (!PyList_Check(source))
+    {
+        PyErr_SetString( PyExc_TypeError, "Expected a list object." );
+        return NULL;
+    }
+
+    cStrings = PyList_Size(source);
+    for( x=0, cChars=0; x<cStrings; x++)
+    {
+        PyObject* o = PyList_GetItem( source, x );
+        if( !PyString_Check(o) )
+        {
+            PyErr_SetString( PyExc_TypeError, "Expected a list of strings." );
+            return NULL;
+        }
+        cChars += strlen( PyString_AsString(o)) + 1 ;
+    }
+    cChars += 1;
+
+    psl=mem_Malloc(sizeof(STRINGLIST));
+    if(!psl)
+    {
+        PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
+        return NULL;
+    }
+    psl->bAllocated=TRUE;
+    psl->hcontext = 0;
+
+    if ( cChars>1 )
+    {
+        psl->ac = mem_Malloc( cChars*sizeof(char) );
+        if (!psl->ac)
+        {
+            PyErr_SetString( PyExc_MemoryError, "Unable to allocate temporary array" );
+            mem_Free( psl );
+            return NULL;
+        }
+
+        for( x=0, cChars=0, p=psl->ac; x<cStrings; x++ )
+        {
+            PyObject* o = PyList_GetItem(source, x);
+            strcpy( p, PyString_AsString(o) );
+            p += strlen( PyString_AsString(o) ) + 1;
+        }
+        strcpy( p, "\0" );
+    }
+    else
+    {
+        psl->ac=NULL;
+    }
+    return (STRINGLIST*)psl;
+}
+
+
+/**==========================================================================**/
+void SCardHelper_PrintStringList( STRINGLIST* sl )
+/*==============================================================================
+dump a string list
+==============================================================================*/
+{
+    char* p=(char*)sl->ac;
+    unsigned int i;
+
+    for( i=0; ; i+=lstrlen( p+i ) + 1 )
+    {
+        if (lstrlen( p+i ) > 0)
+        {
+            printf("%s ", p+i );
+        }
+        else
+        {
+            printf("\n" );
+            break;
+        }
+    }
+}
+
+#ifdef WIN32
+/**==========================================================================**/
+BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
+/*==============================================================================
+Initialize and clean-up memory logging on process attach and detach
+==============================================================================*/
+{
+    switch(fdwReason)
+    {
+        case DLL_PROCESS_ATTACH:
+            if (!mem_Init())
+            {
+                fprintf( stderr, "Failed to initialize memory logging services!\n" );
+            }
+            break;
+
+        case DLL_THREAD_ATTACH:
+            break;
+
+        case DLL_THREAD_DETACH:
+            break;
+
+        case DLL_PROCESS_DETACH:
+            if (!mem_CleanUp())
+            {
+                fprintf( stderr, "Failed to cleanup memory logging services!\n" );
+            }
+            break;
+    }
+    return TRUE;
+
+    return 1;
+}
+#endif // WIN32
+
+
+
+


sway/config: fix use-after-free for end of block

Introduced in 7c810dc344c28d1876c5ee158cb0806289d0f813

--- sway/config.c
+++ sway/config.c
@@ -626,13 +626,13 @@
 				success = false;
 				break;
 			}
+			if (strcmp(block, "bar") == 0) {
+				config->current_bar = NULL;
+			}
+
 			wlr_log(L_DEBUG, "Exiting block '%s'", block);
 			list_del(stack, 0);
 			free(block);
-
-			if (strcmp(block, "bar") == 0) {
-				config->current_bar = NULL;
-			}
 			memset(&config->handler_context, 0,
 					sizeof(config->handler_context));
 		default:;


Enable lazy xwayland

Enable lazy xwayland

--- sway/server.c
+++ sway/server.c
@@ -95,7 +95,7 @@

 	// TODO make xwayland optional
 	server->xwayland =
-		wlr_xwayland_create(server->wl_display, server->compositor, false);
+		wlr_xwayland_create(server->wl_display, server->compositor, true);
 	wl_signal_add(&server->xwayland->events.new_surface,
 		&server->xwayland_surface);
 	server->xwayland_surface.notify = handle_xwayland_surface;


fix the fixed version

fix the fixed version


Check the name of mouse input devices to see if a non-Synaptics mouse device is present

The previous version checked the hid vendor in the device's sysfs. This assumed
mice were HID. Also, older kernels use a different structure for sysfs so this new
method provides compatibility with older kernels.

--- syntouchpad.c
+++ syntouchpad.c
@@ -261,19 +261,28 @@

 	while ((input_dir_entry = readdir(input_dir)) != NULL) {
 		if (strstr(input_dir_entry->d_name, "mouse")) {
-			char buf[PATH_MAX];
-			char devPath[PATH_MAX];
+			char buf[4096];
+			char devNamePath[PATH_MAX];
 			int bus;
 			int vendor;
 			int product;
 			int id;
-
-			snprintf(devPath, PATH_MAX, "/sys/class/input/%s/device/device", input_dir_entry->d_name);
-
-			readlink(devPath, buf, PATH_MAX);
-			sscanf(buf, "../../../%x:%x:%x:%x", &bus, &vendor, &product, &id);
-
-			if (vendor != SYNAPTICS_VENDOR)
+			int fd;
+			size_t count;
+
+			snprintf(devNamePath, PATH_MAX, "/sys/class/input/%s/device/name", input_dir_entry->d_name);
+
+			fd = open(devNamePath, O_RDONLY);
+			if (fd < 0)
+				continue;
+
+			count = read(fd, buf, 4096);
+			if (count < 0)
+				continue;
+
+			buf[count] = 0;
+
+			if (!strstr(buf, "Synaptics"))
 				return 1;
 		}
 	}


Removed some more vestiges of ft.

Removed some more vestiges of ft.

Fixed some style bugs.

--- sys/isa/fdc.h
+++ sys/isa/fdc.h
@@ -50,13 +50,10 @@
 	int	dmachan;
 	int	flags;
 #define FDC_ATTACHED	0x01
-#define FDC_HASFTAPE	0x02
-#define FDC_TAPE_BUSY	0x04
 #define FDC_STAT_VALID	0x08
 #define FDC_HAS_FIFO	0x10
 #define FDC_NEEDS_RESET	0x20
 #define FDC_NODMA	0x40
-#define FDC_UNLOADED	0x80
 	struct	fd_data *fd;
 	int	fdu;		/* the active drive	*/
 	int	state;
@@ -94,8 +91,8 @@
 typedef struct fdc_data *fdc_p;
 typedef enum fdc_type fdc_t;

-#define FDUNIT(s)	(((s)>>6)&03)
-#define FDTYPE(s)	((s)&077)
+#define FDUNIT(s)	(((s) >> 6) & 3)
+#define FDTYPE(s)	((s) & 0x3f)

 /*
  * fdc maintains a set (1!) of ivars per child of each controller.


interger->integer

interger->integer

--- sys/sensors.h
+++ sys/sensors.h
@@ -1,4 +1,4 @@
-/*	$OpenBSD: sensors.h,v 1.4 2004/02/10 19:53:34 grange Exp $	*/
+/*	$OpenBSD: sensors.h,v 1.5 2005/04/08 05:01:47 jolan Exp $	*/

 /*
  * Copyright (c) 2003, 2004 Alexander Yurchenko <grange@openbsd.org>
@@ -40,7 +40,7 @@
 	SENSOR_WATTHOUR,		/* power capacity */
 	SENSOR_AMPHOUR,			/* power capacity */
 	SENSOR_INDICATOR,		/* boolean indicator */
-	SENSOR_INTEGER			/* generic interger value */
+	SENSOR_INTEGER			/* generic integer value */
 };

 /* Sensor data */


scale angle by 1000000 to permit min.sec accuracy

--- sys/sensors.h
+++ sys/sensors.h
@@ -1,4 +1,4 @@
-/*	$OpenBSD: sensors.h,v 1.29 2010/04/21 04:07:11 deraadt Exp $	*/
+/*	$OpenBSD: sensors.h,v 1.30 2010/04/21 19:40:59 deraadt Exp $	*/

 /*
  * Copyright (c) 2003, 2004 Alexander Yurchenko <grange@openbsd.org>
@@ -48,7 +48,7 @@
 	SENSOR_TIMEDELTA,		/* system time error (nSec) */
 	SENSOR_HUMIDITY,		/* humidity (m%RH) */
 	SENSOR_FREQ,			/* frequency (Hz) */
-	SENSOR_ANGLE,			/* degrees */
+	SENSOR_ANGLE,			/* angle (mudegrees) */
 	SENSOR_MAX_TYPES
 };


protos and macros are only for _KERNEL, malliciously pollutes the user name space otherwise

--- sys/timeout.h
+++ sys/timeout.h
@@ -1,4 +1,4 @@
-/*	$OpenBSD: timeout.h,v 1.13 2002/03/14 01:27:14 millert Exp $	*/
+/*	$OpenBSD: timeout.h,v 1.14 2002/06/25 16:25:42 mickey Exp $	*/
 /*
  * Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
  * All rights reserved.
@@ -73,6 +73,7 @@
 #define TIMEOUT_ONQUEUE		2	/* timeout is on the todo queue */
 #define TIMEOUT_INITIALIZED	4	/* timeout is initialized */
 #define TIMEOUT_TRIGGERED       8       /* timeout is running or ran */
+#ifdef _KERNEL
 void timeout_set(struct timeout *, void (*)(void *), void *);
 void timeout_add(struct timeout *, int);
 void timeout_del(struct timeout *);
@@ -94,5 +95,6 @@
  * softclock.
  */
 int timeout_hardclock_update(void);
+#endif /* _KERNEL */

 #endif	/* _SYS_TIMEOUT_H_ */


Future-proof the count of source_fds / target_fds

Thanks to Philip Withnall for the suggestions.

--- bus/at-spi-bus-launcher.c
+++ bus/at-spi-bus-launcher.c
@@ -353,6 +353,7 @@
   char *argv[] = { DBUS_DAEMON, config_path, "--nofork", "--print-address", print_address_fd_param, address_param, NULL };
   gint source_fds[1] = { app->pipefd[1] };
   gint target_fds[1] = { app->pipefd[1] };
+  G_STATIC_ASSERT (G_N_ELEMENTS (source_fds) == G_N_ELEMENTS (target_fds));
   GPid pid;
   char addr_buf[2048];
   GError *error = NULL;
@@ -371,7 +372,7 @@
                                          -1, /* stdout_fd */
                                          source_fds,
                                          target_fds,
-                                         1, /* n_fds in source_fds and target_fds */
+                                         G_N_ELEMENTS (source_fds), /* n_fds in source_fds and target_fds */
                                          &pid,
                                          NULL, /* stdin_pipe_out */
                                          NULL, /* stdout_pipe_out */


Route OTR start directly through "sending"

--- otr-extension/glirc-otr.c
+++ otr-extension/glirc-otr.c
@@ -205,37 +205,6 @@
     return PASS_MESSAGE;
 }

-static void command_entrypoint
-  (struct glirc *G, void *L, const struct glirc_command *cmd)
-{
-        if (cmd->params_n >= 1 &&
-            0 == strncmp(cmd->params[0].str, "start", cmd->params[0].len))
-        {
-                const char *privmsg = "PRIVMSG";
-                const char *body    = "?OTRv23? Attempting to initiate OTR encrypted connection";
-                struct glirc_string params[2] =
-                  { [1] = { .str = body, .len = strlen(body) } };
-                struct glirc_message m = {
-                  .params = params,
-                  .params_n = 2,
-                  .command.str = privmsg,
-                  .command.len = strlen(privmsg),
-                  };
-
-                char *net = NULL;
-                char *tgt = NULL;
-                glirc_current_focus(G, &net, &m.network.len, &tgt, &params[0].len);
-
-                if (net && tgt) {
-                        m.network.str = net;
-                        params[0].str = tgt;
-                        glirc_send_message(G, &m);
-                }
-
-                glirc_free_string(net);
-                glirc_free_string(tgt);
-        }
-}

 static enum process_result chat_entrypoint(struct glirc *G, void *L, const struct glirc_chat *chat)
 {
@@ -267,6 +236,34 @@

         return PASS_MESSAGE;

+}
+
+static void command_entrypoint
+  (struct glirc *G, void *L, const struct glirc_command *cmd)
+{
+        if (cmd->params_n >= 1 &&
+            0 == strncmp(cmd->params[0].str, "start", cmd->params[0].len))
+        {
+                char *net = NULL; size_t netlen = 0;
+                char *tgt = NULL; size_t tgtlen = 0;
+                char *txt = "?OTR?"; size_t txtlen = strlen(txt);
+                glirc_current_focus(G, &net, &netlen, &tgt, &tgtlen);
+
+                if (net && tgt) {
+                        struct glirc_chat chat = {
+                                .network.str = net,
+                                .network.len = netlen,
+                                .target.str  = tgt,
+                                .target.len  = tgtlen,
+                                .message.str = txt,
+                                .message.len = txtlen,
+                        };
+                        chat_entrypoint(G, L, &chat);
+                }
+
+                glirc_free_string(net);
+                glirc_free_string(tgt);
+        }
 }

 struct glirc_extension extension = {


Redirect read_char() error handling to merge with read_string()'s

--- src/cc1/tokenise.c
+++ src/cc1/tokenise.c
@@ -824,22 +824,7 @@
 			goto out;
 		}

-		switch(warn){
-			case 0:
-				break;
-			case E2BIG:
-				cc1_warn_at(NULL, char_toolarge, "ignoring extraneous characters in literal");
-				break;
-			case ERANGE:
-				warn_at_print_error(NULL, "escape character out of range");
-				parse_had_error = 1;
-				break;
-			case EINVAL:
-				cc1_warn_at(NULL, escape_char, "invalid escape character");
-				break;
-			default:
-				assert(0 && "unhandled escape warning");
-		}
+		handle_escape_warn_err(warn, err, NULL);
 	}else{
 		warn_at_print_error(NULL, "no terminating quote to character literal");
 		parse_had_error = 1;


Now able to navigate between homescreen, categories and applications

--- src/desktop.c
+++ src/desktop.c
@@ -358,7 +358,7 @@

 static void _on_popup_new_folder(gpointer data)
 {
-	static char const newfolder[] = "New folder";
+	static char const newfolder[] = N_("New folder");
 	Desktop * desktop = data;
 	String * path;

@@ -636,12 +636,12 @@
 /* desktop_set_layout */
 static void _layout_delete(Desktop * desktop);
 static int _layout_applications(Desktop * desktop);
-static void _layout_applications_open(Desktop * desktop, gpointer data);
 static int _layout_categories(Desktop * desktop);
 static int _layout_files(Desktop * desktop);
 static void _layout_files_add_home(Desktop * desktop);
 static int _layout_homescreen(Desktop * desktop);
-static void _layout_homescreen_open(Desktop * desktop, gpointer data);
+static void _layout_set_categories(Desktop * desktop, gpointer data);
+static void _layout_set_homescreen(Desktop * desktop, gpointer data);

 void desktop_set_layout(Desktop * desktop, DesktopLayout layout)
 {
@@ -698,7 +698,7 @@
 	if(desktop->category != NULL)
 	{
 		desktopicon = desktopicon_new(desktop, _("Back"), NULL);
-		desktopicon_set_callback(desktopicon, _layout_applications_open,
+		desktopicon_set_callback(desktopicon, _layout_set_categories,
 				NULL);
 		icon = gtk_icon_theme_load_icon(desktop->theme, "back",
 				DESKTOPICON_ICON_SIZE, 0, NULL);
@@ -709,18 +709,23 @@
 	return 0;
 }

-static void _layout_applications_open(Desktop * desktop, gpointer data)
-{
-#ifdef DEBUG
-	fprintf(stderr, "DEBUG: %s()\n", __func__);
-#endif
-	desktop_set_layout(desktop, DL_CATEGORIES);
-}
-
 static int _layout_categories(Desktop * desktop)
 {
+	DesktopIcon * desktopicon;
+	GdkPixbuf * icon;
+
 	desktop->category = NULL;
-	return _layout_applications(desktop);
+	_layout_applications(desktop); /* XXX hack */
+	desktopicon = desktopicon_new(desktop, _("Back"), NULL);
+	desktopicon_set_callback(desktopicon, _layout_set_homescreen, NULL);
+	desktopicon_set_first(desktopicon, TRUE);
+	desktopicon_set_immutable(desktopicon, TRUE);
+	icon = gtk_icon_theme_load_icon(desktop->theme, "back",
+			DESKTOPICON_ICON_SIZE, 0, NULL);
+	if(icon != NULL)
+		desktopicon_set_icon(desktopicon, icon);
+	desktop_icon_add(desktop, desktopicon);
+	return 0;
 }

 static int _layout_files(Desktop * desktop)
@@ -794,7 +799,7 @@
 	if((desktopicon = desktopicon_new(desktop, _("Applications"), NULL))
 			== NULL)
 		return desktop_error(NULL, error_get(), 1);
-	desktopicon_set_callback(desktopicon, _layout_homescreen_open, NULL);
+	desktopicon_set_callback(desktopicon, _layout_set_categories, NULL);
 	desktopicon_set_immutable(desktopicon, TRUE);
 	desktop_icon_add(desktop, desktopicon);
 	icon = gtk_icon_theme_load_icon(desktop->theme, "gnome-applications",
@@ -804,12 +809,20 @@
 	return 0;
 }

-static void _layout_homescreen_open(Desktop * desktop, gpointer data)
+static void _layout_set_categories(Desktop * desktop, gpointer data)
 {
 #ifdef DEBUG
 	fprintf(stderr, "DEBUG: %s()\n", __func__);
 #endif
 	desktop_set_layout(desktop, DL_CATEGORIES);
+}
+
+static void _layout_set_homescreen(Desktop * desktop, gpointer data)
+{
+#ifdef DEBUG
+	fprintf(stderr, "DEBUG: %s()\n", __func__);
+#endif
+	desktop_set_layout(desktop, DL_HOMESCREEN);
 }

@@ -852,6 +865,11 @@
 #ifdef DEBUG
 	fprintf(stderr, "DEBUG: %s()\n", __func__);
 #endif
+	if(desktop->path == NULL)
+	{
+		_refresh_current(desktop);
+		return;
+	}
 #ifdef __sun__
 	if((fd = open(desktop->path, O_RDONLY)) < 0
 			|| fstat(fd, &st) != 0
@@ -1116,7 +1134,9 @@
 			desktop_icon_remove(desktop, desktop->icon[i]);
 		else
 			desktopicon_set_updated(desktop->icon[i++], FALSE);
-	closedir(desktop->refresh_dir);
+	if(desktop->refresh_dir != NULL)
+		closedir(desktop->refresh_dir);
+	desktop->refresh_dir = NULL;
 	g_timeout_add(1000, _done_timeout, desktop);
 	return FALSE;
 }


Removed some warnings.

Removed some warnings.

--- mediathread/demuxer_ds.c
+++ mediathread/demuxer_ds.c
@@ -66,7 +66,7 @@
 static int probe(InputStream * i_stream)
 {
     char *ext;
-    uint8 buffer[80], string[80];
+    char buffer[80], string[80];
     int version, n;

     // Check filename extension
@@ -74,7 +74,7 @@
         return RESOURCE_DAMAGED;
     }
     // Read begin of file
-    if (istream_read(i_stream, buffer, 79) <= 0) {
+    if (istream_read(i_stream, (uint8 *) buffer, 79) <= 0) {
         return RESOURCE_DAMAGED;
     }
     buffer[79] = '\0';


Fix kill_server() is called multiple times when interrupted.

--- meinheld/server/server.c
+++ meinheld/server/server.c
@@ -1574,7 +1574,7 @@
 {
     DEBUG("call SIGINT");
     if (!catch_signal) {
-        catch_signal = 1;
+        catch_signal = signum;
     }
 }

@@ -1729,6 +1729,7 @@
     int ret;
     int silent = 0;
     int listen_sock = 0;
+    int interrupted = 0;

     static char *kwlist[] = {"app", "silent", 0};
     if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|i:run",
@@ -1787,6 +1788,10 @@
         fire_timers();
         picoev_loop_once(main_loop, 10);
         if (catch_signal) {
+            if (catch_signal == SIGINT) {
+                interrupted = 1;
+            }
+            catch_signal = 0;
             kill_server(0);
         }
         if (watch_loop) {
@@ -1842,11 +1847,10 @@
     Py_CLEAR(listen_socks);

-    if (!silent &&  catch_signal) {
+    if (!silent && interrupted) {
         //override
         PyErr_Clear();
         PyErr_SetNone(PyExc_KeyboardInterrupt);
-        catch_signal = 0;
         return NULL;
     }
     Py_RETURN_NONE;


Change API: blend_mode to set_blender/get_blender.

Display.blend_mode is deprecated.

--- src/display.c
+++ src/display.c
@@ -12,6 +12,8 @@
 static mrb_sym sym_fullscreen;
 static mrb_sym sym_multisample;
 static mrb_sym sym_icon;
+
+static mrb_sym current_blender;

 static mrb_sym blend_alpha;
 static mrb_sym blend_additive;
@@ -150,7 +152,7 @@
 }

 static mrb_value
-display_blend_mode(mrb_state *mrb, mrb_value self)
+display_set_blender(mrb_state *mrb, mrb_value self)
 {
   mrb_sym mode;

@@ -166,8 +168,16 @@
     al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
   else
     mrb_raisef(mrb, E_ARGUMENT_ERROR, "unknown keyword: %S", mrb_symbol_value(mode));
+
+  current_blender = mode;

   return mrb_nil_value();
+}
+
+static mrb_value
+display_get_blender(mrb_state *mrb, mrb_value self)
+{
+  return mrb_symbol_value(current_blender);
 }

 static mrb_value
@@ -193,7 +203,10 @@
   mrb_define_module_function(mrb, c, "clear", display_clear, MRB_ARGS_OPT(1));
   mrb_define_module_function(mrb, c, "flip", display_flip, MRB_ARGS_NONE());
   mrb_define_module_function(mrb, c, "screenshot", display_screenshot, MRB_ARGS_REQ(1));
-  mrb_define_module_function(mrb, c, "blend_mode", display_blend_mode, MRB_ARGS_REQ(1));
+  mrb_define_module_function(mrb, c, "set_blender", display_set_blender, MRB_ARGS_REQ(1));
+  mrb_define_module_function(mrb, c, "get_blender", display_get_blender, MRB_ARGS_NONE());
+  /* Display.blend_mode is deprecated. */
+  mrb_define_alias(mrb, c->c, "blend_mode", "set_blender");
   mrb_define_module_function(mrb, c, "w", display_get_w, MRB_ARGS_NONE());
   mrb_define_module_function(mrb, c, "h", display_get_h, MRB_ARGS_NONE());

@@ -201,6 +214,8 @@
   blend_additive = mrb_intern_lit(mrb, "additive");
   blend_subtractive = mrb_intern_lit(mrb, "subtractive");
   blend_premultiplied = mrb_intern_lit(mrb, "premultiplied");
+
+  current_blender = blend_alpha;

   sym_title = mrb_intern_lit(mrb, "title");
   sym_vsync = mrb_intern_lit(mrb, "vsync");