Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mapserver/mapserver
Browse files Browse the repository at this point in the history
  • Loading branch information
jmckenna committed May 14, 2012
2 parents 1ee03be + fcda217 commit 2d61147
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 36 deletions.
38 changes: 38 additions & 0 deletions classobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,44 @@

MS_CVSID("$Id$")

/*
** Add a label to a classObj (order doesn't matter for labels like it does with styles)
*/
int msAddLabelToClass(classObj *class, labelObj *label) {
if (!label) {
msSetError(MS_CHILDERR, "Can't add a NULL label.", "msAddLabelToClass()");
return MS_FAILURE;
}
if (msGrowClassLabels(class) == NULL) return MS_FAILURE;

class->labels[class->numlabels] = label;
MS_REFCNT_INCR(label);
class->numlabels++;
return MS_SUCCESS;
}

/*
** Remove a label from a classObj.
*/
int msRemoveLabelFromClass(classObj *class, int nLabelIndex) {
int i;
labelObj *label;

if (nLabelIndex < 0 || nLabelIndex >= class->numlabels) {
msSetError(MS_CHILDERR, "Cannot remove label, invalid index %d", "msRemoveLabelFromClass()", nLabelIndex);
return NULL;
} else {
label=class->labels[nLabelIndex];
for (i=nLabelIndex; i<class->numlabels-1; i++) {
class->labels[i]=class->labels[i+1];
}
class->labels[class->numlabels-1]=NULL;
class->numlabels--;
MS_REFCNT_DECR(label);
return label;
}
}

/**
* Move the style up inside the array of styles.
*/
Expand Down
2 changes: 1 addition & 1 deletion mapscript/java/tests/threadtest/MapThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void run() {
}
}
// We use this to test swig's memory management code
System.gc();
//System.gc();
//map.draw().save("/tmp/mapthread"+id+"-"+i+".png", map);
map.draw();

Expand Down
5 changes: 5 additions & 0 deletions mapscript/perl/plmodule.i
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
msFree($1.data);
}

%typemap(out) char[ANY] {
$result = newSVpvn($1, strlen($1));
argvi++;
}

/*
===============================================================================
RFC-24 implementation follows
Expand Down
73 changes: 47 additions & 26 deletions mapscript/swiginc/class.i
Original file line number Diff line number Diff line change
Expand Up @@ -180,41 +180,62 @@
return msCreateLegendIcon(map, layer, self, width, height);
}

/* See Bugzilla issue 548 for more details about the *Style methods */
%newobject getStyle;
styleObj *getStyle(int i) {
if (i >= 0 && i < self->numstyles) {
MS_REFCNT_INCR(self->styles[i]);
return self->styles[i];
} else {
msSetError(MS_CHILDERR, "Invalid index: %d", "getStyle()", i);
return NULL;
}
%newobject getLabel;
labelObj *getLabel(int i) {
if (i >= 0 && i < self->numlabels) {
MS_REFCNT_INCR(self->labels[i]);
return self->labels[i];
} else {
msSetError(MS_CHILDERR, "Invalid index: %d.", "getLabel()", i);
return NULL;
}
}

int addLabel(labelObj *label) {
return msAddLabelToClass(self, label);
}

%newobject removeLabel;
labelObj *removeLabel(int index) {
labelObj* label = (labelObj *) msRemoveLabelFromClass(self, index);
if (label) MS_REFCNT_INCR(label);
return label;
}

/* See Bugzilla issue 548 for more details about the *Style methods */
%newobject getStyle;
styleObj *getStyle(int i) {
if (i >= 0 && i < self->numstyles) {
MS_REFCNT_INCR(self->styles[i]);
return self->styles[i];
} else {
msSetError(MS_CHILDERR, "Invalid index: %d", "getStyle()", i);
return NULL;
}
}

#ifdef SWIGCSHARP
%apply SWIGTYPE *SETREFERENCE {styleObj *style};
#endif
int insertStyle(styleObj *style, int index=-1) {
return msInsertStyle(self, style, index);
}
int insertStyle(styleObj *style, int index=-1) {
return msInsertStyle(self, style, index);
}
#ifdef SWIGCSHARP
%clear styleObj *style;
#endif

%newobject removeStyle;
styleObj *removeStyle(int index) {
styleObj* style = (styleObj *) msRemoveStyle(self, index);
if (style)
MS_REFCNT_INCR(style);
return style;
}
%newobject removeStyle;
styleObj *removeStyle(int index) {
styleObj* style = (styleObj *) msRemoveStyle(self, index);
if (style) MS_REFCNT_INCR(style);
return style;
}

int moveStyleUp(int index) {
return msMoveStyleUp(self, index);
}
int moveStyleUp(int index) {
return msMoveStyleUp(self, index);
}

int moveStyleDown(int index) {
return msMoveStyleDown(self, index);
}
int moveStyleDown(int index) {
return msMoveStyleDown(self, index);
}
}
41 changes: 32 additions & 9 deletions mapserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,28 +454,50 @@ MS_DLL_EXPORT int msImageSetPenGD(gdImagePtr img, colorObj *color);
#define GET_CLASS(map, lid, cid) map->layers[lid]->class[cid]

#if defined(USE_THREAD) && (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) >= 40102

// __sync* appeared in GCC 4.1.2
#define MS_REFCNT_INCR(obj) __sync_fetch_and_add(&obj->refcount, +1)
#define MS_REFCNT_DECR(obj) __sync_sub_and_fetch(&obj->refcount, +1)
#define MS_REFCNT_INIT(obj) obj->refcount=1, __sync_synchronize()

/*
* TODO: fix it
* This particular piece of code provides a locking mechanism around the
* the reference counter macro so that multiple threads can safely incr/decr
* the same counter using a MS VC utility function.
*
* Unfortunately it does not work (it builds, but hangs) and since building mapserver on Windows
* is a b***h I'm going to leave it as it is and hope someone else might step up to the challenge.
*
* https://github.com/mapserver/mapserver/issues/4231
*
#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
#pragma intrinsic (_InterlockedExchangeAdd)
#if defined(_MSC_VER) && (_MSC_VER <= 1200)
#define MS_REFCNT_INCR(obj) InterlockedExchangeAdd((LONG*)&obj->refcount, (LONG)+1)
#define MS_REFCNT_DECR(obj) InterlockedExchangeAdd((LONG*)&obj->refcount, (LONG)+1)
#define MS_REFCNT_INCR(obj) ( _InterlockedExchangeAdd((long*)(&obj->refcount), (long)(+1)) +1 )
#define MS_REFCNT_DECR(obj) ( _InterlockedExchangeAdd((long*)(&obj->refcount), (long)(-1)) -1 )
#define MS_REFCNT_INIT(obj) obj->refcount=1
#else
#define MS_REFCNT_INCR(obj) InterlockedExchangeAdd((volatile LONG*)&obj->refcount, (LONG)+1)
#define MS_REFCNT_DECR(obj) InterlockedExchangeAdd((volatile LONG*)&obj->refcount, (LONG)+1)
#define MS_REFCNT_INCR(obj) ( _InterlockedExchangeAdd((volatile long*)(&obj->refcount), (long)(+1)) +1 )
#define MS_REFCNT_DECR(obj) ( _InterlockedExchangeAdd((volatile long*)(&obj->refcount), (long)(-1)) -1 )
#define MS_REFCNT_INIT(obj) obj->refcount=1
#endif
#elif defined(__MINGW32__) && defined(__i386__)
#define MS_REFCNT_INCR(obj) InterlockedExchangeAdd((LONG*)&obj->refcount, (LONG)+1)
#define MS_REFCNT_DECR(obj) InterlockedExchangeAdd((LONG*)&obj->refcount, (LONG)+1)
#define MS_REFCNT_INCR(obj) ( InterlockedExchangeAdd((long*)(&obj->refcount), (long)(+1)) +1 )
#define MS_REFCNT_DECR(obj) ( InterlockedExchangeAdd((long*)(&obj->refcount), (long)(-1)) -1 )
#define MS_REFCNT_INIT(obj) obj->refcount=1
*/

#else

#define MS_REFCNT_INCR(obj) obj->refcount++
#define MS_REFCNT_DECR(obj) (--(obj->refcount))
#define MS_REFCNT_INIT(obj) obj->refcount=1

#endif
#define MS_REFCNT_DECR_IS_NOT_ZERO(obj) (MS_REFCNT_DECR(obj))>0
#define MS_REFCNT_DECR_IS_ZERO(obj) (MS_REFCNT_DECR(obj))<=0
Expand Down Expand Up @@ -2377,11 +2399,12 @@ MS_DLL_EXPORT int msMoveClassUp(layerObj *layer, int nClassIndex);
MS_DLL_EXPORT int msMoveClassDown(layerObj *layer, int nClassIndex);

/* classobject.c */
MS_DLL_EXPORT int msAddLabelToClass(classObj *classo, labelObj *label);
MS_DLL_EXPORT int msRemoveLabelFromClass(classObj *classo, int nLabelIndex);
MS_DLL_EXPORT int msMoveStyleUp(classObj *classo, int nStyleIndex);
MS_DLL_EXPORT int msMoveStyleDown(classObj *classo, int nStyleIndex);
MS_DLL_EXPORT int msDeleteStyle(classObj *classo, int iStyleIndex);
MS_DLL_EXPORT int msInsertStyle(classObj *classo, styleObj *style,
int nStyleIndex);
MS_DLL_EXPORT int msDeleteStyle(classObj *classo, int nStyleIndex);
MS_DLL_EXPORT int msInsertStyle(classObj *classo, styleObj *style, int nStyleIndex);
MS_DLL_EXPORT styleObj *msRemoveStyle(classObj *classo, int index);

/* maplabel.c */
Expand Down

0 comments on commit 2d61147

Please sign in to comment.