[SCM] pd-mrpeach/master: Imported Upstream version 0.1~svn17615
umlaeute at users.alioth.debian.org
umlaeute at users.alioth.debian.org
Fri Apr 15 20:27:14 UTC 2016
The following commit has been merged in the master branch:
commit f7ceca7bdc1bb73883bf8bd9f625cdaa4077bce9
Author: IOhannes m zmölnig <zmoelnig at umlautQ.umlaeute.mur.at>
Date: Fri Apr 15 22:09:36 2016 +0200
Imported Upstream version 0.1~svn17615
diff --git a/net/tcpclient.c b/net/tcpclient.c
index f32f910..f530834 100644
--- a/net/tcpclient.c
+++ b/net/tcpclient.c
@@ -615,12 +615,15 @@ static void tcpclient_free(t_tcpclient *x)
if (x->x_verbosity) post("...tcpclient_free");
}
+#ifndef BUILD_DATE
+# define BUILD_DATE __DATE__ " " __TIME__
+#endif
void tcpclient_setup(void)
{
char aboutStr[MAXPDSTRING];
- snprintf(aboutStr, MAXPDSTRING, "%s: (GPL) 20111103 Martin Peach, compiled for pd-%d.%d on %s %s",
- objName, PD_MAJOR_VERSION, PD_MINOR_VERSION, __DATE__, __TIME__);
+ snprintf(aboutStr, MAXPDSTRING, "%s: (GPL) 20111103 Martin Peach, compiled for pd-%d.%d on %s",
+ objName, PD_MAJOR_VERSION, PD_MINOR_VERSION, BUILD_DATE );
#if PD_MAJOR_VERSION==0 && PD_MINOR_VERSION<43
post(aboutStr);
diff --git a/osc/packOSC.c b/osc/packOSC.c
index f9f30c0..21e23ee 100644
--- a/osc/packOSC.c
+++ b/osc/packOSC.c
@@ -31,6 +31,8 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl
*/
+//#define DEBUG
+
#define SC_BUFFER_SIZE 64000
#include "packingOSC.h"
@@ -222,6 +224,7 @@ typedef struct _packOSC
char *x_bufferForOSCbuf; /*[SC_BUFFER_SIZE];*/
t_atom *x_bufferForOSClist; /*[SC_BUFFER_SIZE];*/
char *x_prefix;
+ int x_reentry_count;
} t_packOSC;
static void *packOSC_new(void);
@@ -252,16 +255,27 @@ static void *packOSC_new(void)
x->x_buflength = SC_BUFFER_SIZE;
x->x_bufferForOSCbuf = (char *)getbytes(sizeof(char)*x->x_buflength);
if(x->x_bufferForOSCbuf == NULL)
- error("packOSC: unable to allocate %lu bytes for x_bufferForOSCbuf", (long)(sizeof(char)*x->x_buflength));
+ {
+ pd_error(x, "packOSC: unable to allocate %lu bytes for x_bufferForOSCbuf", (long)(sizeof(char)*x->x_buflength));
+ goto fail;
+ }
x->x_bufferForOSClist = (t_atom *)getbytes(sizeof(t_atom)*x->x_buflength);
if(x->x_bufferForOSClist == NULL)
- error("packOSC: unable to allocate %lu bytes for x_bufferForOSClist", (long)(sizeof(t_atom)*x->x_buflength));
+ {
+ pd_error(x, "packOSC: unable to allocate %lu bytes for x_bufferForOSClist", (long)(sizeof(t_atom)*x->x_buflength));
+ goto fail;
+ }
if (x->x_oscbuf != NULL)
OSC_initBuffer(x->x_oscbuf, x->x_buflength, x->x_bufferForOSCbuf);
x->x_listout = outlet_new(&x->x_obj, &s_list);
x->x_bdpthout = outlet_new(&x->x_obj, &s_float);
x->x_timeTagOffset = -1; /* immediately */
+ x->x_reentry_count = 0;
return (x);
+fail:
+ if(x->x_bufferForOSCbuf != NULL) freebytes(x->x_bufferForOSCbuf, (long)(sizeof(char)*x->x_buflength));
+ if(x->x_bufferForOSClist != NULL) freebytes(x->x_bufferForOSClist, (long)(sizeof(char)*x->x_buflength));
+ return NULL;
}
static void packOSC_path(t_packOSC *x, t_symbol*s)
@@ -283,6 +297,7 @@ static void packOSC_path(t_packOSC *x, t_symbol*s)
static void packOSC_openbundle(t_packOSC *x)
{
int result;
+ t_float bundledepth=(t_float)x->x_oscbuf->bundleDepth;
if (x->x_timeTagOffset == -1)
result = OSC_openBundle(x->x_oscbuf, OSCTT_Immediately());
else
@@ -293,23 +308,23 @@ static void packOSC_openbundle(t_packOSC *x)
x->x_bundle = 0;
}
else x->x_bundle = 1;
- outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth);
+ outlet_float(x->x_bdpthout, bundledepth);
}
static void packOSC_closebundle(t_packOSC *x)
{
+ t_float bundledepth=(t_float)x->x_oscbuf->bundleDepth;
if (OSC_closeBundle(x->x_oscbuf))
{
- error("packOSC: Problem closing bundle.");
+ pd_error(x, "packOSC: Problem closing bundle.");
return;
}
- outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth);
+ outlet_float(x->x_bdpthout, bundledepth);
/* in bundle mode we send when bundle is closed */
if(!OSC_isBufferEmpty(x->x_oscbuf) > 0 && OSC_isBufferDone(x->x_oscbuf))
{
+ x->x_bundle = 0; /* call this before _sendbuffer() to be ready for recursive calls */
packOSC_sendbuffer(x);
- OSC_initBuffer(x->x_oscbuf, x->x_buflength, x->x_bufferForOSCbuf);
- x->x_bundle = 0;
return;
}
}
@@ -328,10 +343,10 @@ static void packOSC_setbufsize(t_packOSC *x, t_floatarg f)
x->x_buflength = (long)f;
x->x_bufferForOSCbuf = (char *)getbytes(sizeof(char)*x->x_buflength);
if(x->x_bufferForOSCbuf == NULL)
- error("packOSC unable to allocate %lu bytes for x_bufferForOSCbuf", (long)(sizeof(char)*x->x_buflength));
+ pd_error(x, "packOSC unable to allocate %lu bytes for x_bufferForOSCbuf", (long)(sizeof(char)*x->x_buflength));
x->x_bufferForOSClist = (t_atom *)getbytes(sizeof(t_atom)*x->x_buflength);
if(x->x_bufferForOSClist == NULL)
- error("packOSC unable to allocate %lu bytes for x_bufferForOSClist", (long)(sizeof(t_atom)*x->x_buflength));
+ pd_error(x, "packOSC unable to allocate %lu bytes for x_bufferForOSClist", (long)(sizeof(t_atom)*x->x_buflength));
OSC_initBuffer(x->x_oscbuf, x->x_buflength, x->x_bufferForOSCbuf);
post("packOSC: bufsize is now %d",x->x_buflength);
}
@@ -347,7 +362,7 @@ static void packOSC_setTimeTagOffset(t_packOSC *x, t_floatarg f)
static void packOSC_sendtyped(t_packOSC *x, t_symbol *s, int argc, t_atom *argv)
{
char messageName[MAXPDSTRING];
- unsigned int nTypeTags = 0, typeStrTotalSize = 0;
+ unsigned int nTypeTags = 0, typeStrTotalSize = 0;
unsigned int argsSize = sizeof(typedArg)*argc;
char* typeStr = NULL; /* might not be used */
typedArg* args = (typedArg*)getbytes(argsSize);
@@ -355,9 +370,13 @@ static void packOSC_sendtyped(t_packOSC *x, t_symbol *s, int argc, t_atom *argv)
unsigned int m, j, k;
char c;
+#ifdef DEBUG
+ printf("*** packOSC_sendtyped bundle %d reentry %d\n", x->x_bundle, x->x_reentry_count);
+#endif
+ x->x_reentry_count++;
if (args == NULL)
{
- error("packOSC: unable to allocate %lu bytes for args", (long)argsSize);
+ pd_error(x, "packOSC: unable to allocate %lu bytes for args", (long)argsSize);
return;
}
messageName[0] = '\0'; /* empty */
@@ -381,19 +400,19 @@ static void packOSC_sendtyped(t_packOSC *x, t_symbol *s, int argc, t_atom *argv)
typeStr = (char*)getzbytes(typeStrTotalSize);
if (typeStr == NULL)
{
- error("packOSC: unable to allocate %u bytes for typeStr", nTypeTags);
+ pd_error(x, "packOSC: unable to allocate %u bytes for typeStr", nTypeTags);
return;
}
typeStr[0] = ',';
atom_string(&argv[1], &typeStr[1], typeStrTotalSize);
#ifdef DEBUG
- post("typeStr: %s, nTypeTags %lu", typeStr, nTypeTags);
+ printf("packOSC_sendtyped typeStr: %s, nTypeTags %u\n", typeStr, nTypeTags);
#endif
nArgs = argc-2;
for (m = nTagsWithData = blobCount = 0; m < nTypeTags; ++m)
{
#ifdef DEBUG
- post("typeStr[%d] %c", m+1, typeStr[m+1]);
+ printf("packOSC_sendtyped typeStr[%d] %c\n", m+1, typeStr[m+1]);
#endif
if ((c = typeStr[m+1]) == 0) break;
if (!(c == 'T' || c == 'F' || c == 'N' || c == 'I'))
@@ -409,12 +428,12 @@ static void packOSC_sendtyped(t_packOSC *x, t_symbol *s, int argc, t_atom *argv)
}
if (((blobCount == 0)&&(nTagsWithData != nArgs)) || ((blobCount != 0)&&(nTagsWithData > nArgs)))
{
- error("packOSC: Tags count %d doesn't match argument count %d", nTagsWithData, nArgs);
+ pd_error(x, "packOSC: Tags count %d doesn't match argument count %d", nTagsWithData, nArgs);
goto cleanup;
}
if (blobCount > 1)
{
- error("packOSC: Only one blob per packet at the moment...");
+ pd_error(x, "packOSC: Only one blob per packet at the moment...");
goto cleanup;
}
for (j = k = 0; j < m; ++j) /* m is the number of tags */
@@ -424,14 +443,14 @@ static void packOSC_sendtyped(t_packOSC *x, t_symbol *s, int argc, t_atom *argv)
{ /* A blob has to be the last item, until we get more elaborate. */
if (j != m-1)
{
- error("packOSC: Since I don't know how big the blob is, Blob must be the last item in the list");
+ pd_error(x, "packOSC: Since I don't know how big the blob is, Blob must be the last item in the list");
goto cleanup;
}
/* Pack all the remaining arguments as a blob */
for (; k < nArgs; ++k)
{
#ifdef DEBUG
- post("packOSC_blob %d:", nArgs);
+ printf("packOSC_blob %d:\n", nArgs);
#endif
args[k] = packOSC_blob(&argv[k+2]);
/* Make sure it was blobbable */
@@ -446,7 +465,7 @@ static void packOSC_sendtyped(t_packOSC *x, t_symbol *s, int argc, t_atom *argv)
}
if(packOSC_writetypedmessage(x, x->x_oscbuf, messageName, nArgs, args, typeStr))
{
- error("packOSC: usage error, write-msg failed.");
+ pd_error(x, "packOSC: usage error, packOSC_writetypedmessage failed.");
goto cleanup;
}
}
@@ -459,24 +478,28 @@ static void packOSC_sendtyped(t_packOSC *x, t_symbol *s, int argc, t_atom *argv)
switch (args[i].type)
{
case INT_osc:
- post("packOSC: cell-cont: %d\n", args[i].datum.i);
+ printf("packOSC: cell-cont: %d\n", args[i].datum.i);
break;
case FLOAT_osc:
- post("packOSC: cell-cont: %f\n", args[i].datum.f);
+ printf("packOSC: cell-cont: %f\n", args[i].datum.f);
break;
case STRING_osc:
- post("packOSC: cell-cont: %s\n", args[i].datum.s);
+ printf("packOSC: cell-cont: %s\n", args[i].datum.s);
+ break;
+ case BLOB_osc:
+ printf("packOSC: blob\n");
break;
case NOTYPE_osc:
- post("packOSC: unknown type\n");
+ printf("packOSC: unknown type\n");
break;
+
}
- post("packOSC: type-id: %d\n", args[i].type);
+ printf("packOSC: type-id: %d\n", args[i].type);
#endif
}
if(packOSC_writemessage(x, x->x_oscbuf, messageName, i, args))
{
- error("packOSC: usage error, write-msg failed.");
+ pd_error(x, "packOSC: usage error, packOSC_writemessage failed.");
goto cleanup;
}
}
@@ -484,12 +507,12 @@ static void packOSC_sendtyped(t_packOSC *x, t_symbol *s, int argc, t_atom *argv)
if(!x->x_bundle)
{
packOSC_sendbuffer(x);
- OSC_initBuffer(x->x_oscbuf, x->x_buflength, x->x_bufferForOSCbuf);
}
cleanup:
if (typeStr != NULL) freebytes(typeStr, typeStrTotalSize);
if (args != NULL) freebytes(args, argsSize);
+ x->x_reentry_count--;
}
static void packOSC_send_type_forced(t_packOSC *x, t_symbol *s, int argc, t_atom *argv)
@@ -503,7 +526,7 @@ static void packOSC_send(t_packOSC *x, t_symbol *s, int argc, t_atom *argv)
{
if(!argc)
{
- post("packOSC: not sending empty message.");
+ pd_error(x, "packOSC: not sending empty message.");
return;
}
packOSC_sendtyped(x, s, argc, argv);
@@ -572,7 +595,7 @@ static typedArg packOSC_parseatom(t_atom *a)
atom_string(a, buf, MAXPDSTRING);
#ifdef DEBUG
- post("packOSC: atom type %d (%s)", a->a_type, buf);
+ printf("packOSC: atom type %d (%s)\n", a->a_type, buf);
#endif
/* It might be an int, a float, or a string */
switch (a->a_type)
@@ -646,7 +669,7 @@ static typedArg packOSC_forceatom(t_atom *a, char ctype)
#ifdef DEBUG
atom_string(a, buf, MAXPDSTRING);
- post("packOSC: atom type %d (%s)", a->a_type, buf);
+ printf("packOSC: atom type %d (%s)\n", a->a_type, buf);
#endif
/* the atom might be a float, or a symbol */
switch (a->a_type)
@@ -658,14 +681,14 @@ static typedArg packOSC_forceatom(t_atom *a, char ctype)
returnVal.type = INT_osc;
returnVal.datum.i = atom_getint(a);
#ifdef DEBUG
- post("packOSC_forceatom: float to integer %d", returnVal.datum.i);
+ printf("packOSC_forceatom: float to integer %d\n", returnVal.datum.i);
#endif
break;
case 'f':
returnVal.type = FLOAT_osc;
returnVal.datum.f = atom_getfloat(a);
#ifdef DEBUG
- post("packOSC_forceatom: float to float %f", returnVal.datum.f);
+ printf("packOSC_forceatom: float to float %f\n", returnVal.datum.f);
#endif
break;
case 's':
@@ -674,7 +697,7 @@ static typedArg packOSC_forceatom(t_atom *a, char ctype)
returnVal.type = STRING_osc;
returnVal.datum.s = buf;
#ifdef DEBUG
- post("packOSC_forceatom: float to string %s", returnVal.datum.s);
+ printf("packOSC_forceatom: float to string %s\n", returnVal.datum.s);
#endif
break;
default:
@@ -693,7 +716,7 @@ static typedArg packOSC_forceatom(t_atom *a, char ctype)
returnVal.type = INT_osc;
returnVal.datum.i = i;
#ifdef DEBUG
- post("packOSC_forceatom: symbol to integer %d", returnVal.datum.i);
+ printf("packOSC_forceatom: symbol to integer %d\n", returnVal.datum.i);
#endif
break;
case 'f':
@@ -701,14 +724,14 @@ static typedArg packOSC_forceatom(t_atom *a, char ctype)
returnVal.type = FLOAT_osc;
returnVal.datum.f = f;
#ifdef DEBUG
- post("packOSC_forceatom: symbol to float %f", returnVal.datum.f);
+ printf("packOSC_forceatom: symbol to float %f\n", returnVal.datum.f);
#endif
break;
case 's':
returnVal.type = STRING_osc;
returnVal.datum.s = s.s_name;
#ifdef DEBUG
- post("packOSC_forceatom: symbol to string %s", returnVal.datum.s);
+ printf("packOSC_forceatom: symbol to string %s\n", returnVal.datum.s);
#endif
break;
default:
@@ -731,7 +754,13 @@ static typedArg packOSC_forceatom(t_atom *a, char ctype)
static int packOSC_writetypedmessage
(t_packOSC *x, OSCbuf *buf, char *messageName, int numArgs, typedArg *args, char *typeStr)
{
- int i, j, returnVal = OSC_writeAddressAndTypes(buf, messageName, typeStr);
+ int i, j, returnVal;
+
+#ifdef DEBUG
+ printf("packOSC_writetypedmessage: messageName %p (%s) typeStr %p (%s)\n",
+ messageName, messageName, typeStr, typeStr);
+#endif
+ returnVal = OSC_writeAddressAndTypes(buf, messageName, typeStr);
if (returnVal)
{
@@ -743,7 +772,7 @@ static int packOSC_writetypedmessage
while (typeStr[i+1] == 'T' || typeStr[i+1] == 'F' || typeStr[i+1] == 'I' || typeStr[i+1] == 'N')
{
#ifdef DEBUG
- post("packOSC_writetypedmessage: NULL [%c]", typeStr[i+1]);
+ printf("packOSC_writetypedmessage: NULL [%c]\n", typeStr[i+1]);
#endif
returnVal = OSC_writeNullArg(buf, typeStr[i+1]);
++i;
@@ -754,26 +783,26 @@ static int packOSC_writetypedmessage
{
case INT_osc:
#ifdef DEBUG
- post("packOSC_writetypedmessage: int [%d]", args[j].datum.i);
+ printf("packOSC_writetypedmessage: int [%d]\n", args[j].datum.i);
#endif
returnVal = OSC_writeIntArg(buf, args[j].datum.i);
break;
case FLOAT_osc:
#ifdef DEBUG
- post("packOSC_writetypedmessage: float [%f]", args[j].datum.f);
+ printf("packOSC_writetypedmessage: float [%f]\n", args[j].datum.f);
#endif
returnVal = OSC_writeFloatArg(buf, args[j].datum.f);
break;
case STRING_osc:
#ifdef DEBUG
- post("packOSC_writetypedmessage: string [%s]", args[j].datum.s);
+ printf("packOSC_writetypedmessage: string [%s]\n", args[j].datum.s);
#endif
returnVal = OSC_writeStringArg(buf, args[j].datum.s);
break;
case BLOB_osc:
/* write all the blob elements at once */
#ifdef DEBUG
- post("packOSC_writetypedmessage calling OSC_writeBlobArg\n");
+ printf("packOSC_writetypedmessage calling OSC_writeBlobArg\n");
#endif
return OSC_writeBlobArg(buf, &args[j], numArgs-j);
default:
@@ -788,9 +817,15 @@ static int packOSC_writetypedmessage
static int packOSC_writemessage(t_packOSC *x, OSCbuf *buf, char *messageName, int numArgs, typedArg *args)
{
int j, returnVal = 0, numTags;
+#ifdef DEBUG
+ printf("packOSC_writemessage buf %p bufptr %p messageName %s %d args typetags %d\n", buf, buf->bufptr, messageName, numArgs, x->x_typetags);
+#endif
if (!x->x_typetags)
{
+#ifdef DEBUG
+ printf("packOSC_writemessage calling OSC_writeAddress with x->x_typetags %d\n", x->x_typetags);
+#endif
returnVal = OSC_writeAddress(buf, messageName);
if (returnVal)
{
@@ -831,6 +866,9 @@ static int packOSC_writemessage(t_packOSC *x, OSCbuf *buf, char *messageName, in
}
}
typeTags[j+1] = '\0';
+#ifdef DEBUG
+ printf("packOSC_writemessage calling OSC_writeAddressAndTypes with x->x_typetags %d typeTags %p (%s)\n", x->x_typetags, typeTags, typeTags);
+#endif
returnVal = OSC_writeAddressAndTypes(buf, messageName, typeTags);
if (returnVal)
{
@@ -853,7 +891,7 @@ static int packOSC_writemessage(t_packOSC *x, OSCbuf *buf, char *messageName, in
break;
case BLOB_osc:
#ifdef DEBUG
- post ("packOSC_writemessage calling OSC_writeBlobArg\n");
+ printf("packOSC_writemessage calling OSC_writeBlobArg\n");
#endif
return OSC_writeBlobArg(buf, &args[j], numArgs-j); /* All the remaining args are blob */
default:
@@ -868,9 +906,20 @@ static void packOSC_sendbuffer(t_packOSC *x)
int i;
int length;
unsigned char *buf;
+ int reentry_count=x->x_reentry_count; /* must be on stack for recursion */
+ size_t bufsize=sizeof(t_atom)*x->x_buflength; /* must be on stack for recursion */
+ t_atom *atombuffer=x->x_bufferForOSClist; /* must be on stack in the case of recursion */
+
+ if(reentry_count>0) /* if we are recurse, let's move atombuffer to the stack */
+ atombuffer=(t_atom *)getbytes(bufsize);
+
+ if(!atombuffer) {
+ pd_error(x, "packOSC: unable to allocate %lu bytes for atombuffer", (long)bufsize);
+ return;
+ }
#ifdef DEBUG
- post("packOSC_sendbuffer: Sending buffer...\n");
+ printf("packOSC_sendbuffer: Sending buffer...\n");
#endif
if (OSC_isBufferEmpty(x->x_oscbuf))
{
@@ -885,12 +934,21 @@ static void packOSC_sendbuffer(t_packOSC *x)
length = OSC_packetSize(x->x_oscbuf);
buf = (unsigned char *)OSC_getPacket(x->x_oscbuf);
#ifdef DEBUG
- post ("packOSC_sendbuffer: length: %lu", length);
+ printf("packOSC_sendbuffer: length: %u\n", length);
#endif
+
/* convert the bytes in the buffer to floats in a list */
- for (i = 0; i < length; ++i) SETFLOAT(&x->x_bufferForOSClist[i], buf[i]);
+ for (i = 0; i < length; ++i) SETFLOAT(&atombuffer[i], buf[i]);
+
+ /* cleanup the OSCbuffer structure (so we are ready for recursion) */
+ OSC_initBuffer(x->x_oscbuf, x->x_buflength, x->x_bufferForOSCbuf);
+
/* send the list out the outlet */
- outlet_list(x->x_listout, &s_list, length, x->x_bufferForOSClist);
+ outlet_list(x->x_listout, &s_list, length, atombuffer);
+
+ /* cleanup our 'stack'-allocated atombuffer in the case of reentrancy */
+ if(reentry_count>0)
+ freebytes(atombuffer, bufsize);
}
/* The next part is copied and morphed from OSC-client.c. */
@@ -1079,7 +1137,9 @@ static int OSC_closeBundle(OSCbuf *buf)
static int OSC_writeAddress(OSCbuf *buf, char *name)
{
uint32_t paddedLength;
-
+#ifdef DEBUG
+ printf("-->OSC_writeAddress buf %p bufptr %p name %s\n", buf, buf->bufptr, name);
+#endif
if (buf->state == ONE_MSG_ARGS)
{
post("packOSC: This packet is not a bundle, so you can't write another address");
@@ -1095,6 +1155,9 @@ static int OSC_writeAddress(OSCbuf *buf, char *name)
if (CheckTypeTag(buf, '\0')) return 9;
paddedLength = OSC_effectiveStringLength(name);
+#ifdef DEBUG
+ printf("OSC_writeAddress paddedLength %d\n", paddedLength);
+#endif
if (buf->state == EMPTY)
{
@@ -1130,6 +1193,9 @@ static int OSC_writeAddressAndTypes(OSCbuf *buf, char *name, char *types)
int result;
uint32_t paddedLength;
+#ifdef DEBUG
+ printf("OSC_writeAddressAndTypes buf %p name %s types %s\n", buf, name, types);
+#endif
if (buf == NULL) return 10;
if (CheckTypeTag(buf, '\0')) return 9;
@@ -1143,8 +1209,13 @@ static int OSC_writeAddressAndTypes(OSCbuf *buf, char *name, char *types)
buf->typeStringPtr = buf->bufptr + 1; /* skip comma */
buf->bufptr += OSC_padString(buf->bufptr, types);
+#ifdef DEBUG
+ printf("OSC_writeAddressAndTypes buf->typeStringPtr now %p (%s) buf->bufptr now %p (%s)\n",
+ buf->typeStringPtr, buf->typeStringPtr, buf->bufptr, buf->bufptr);
+#endif
buf->gettingFirstUntypedArg = 0;
+ buf->typeStringPtr = 0;// ready for a new type string
return 0;
}
@@ -1154,7 +1225,13 @@ static int CheckTypeTag(OSCbuf *buf, char expectedType)
if (buf->typeStringPtr)
{
+#ifdef DEBUG
+ printf("CheckTypeTag buf->typeStringPtr %p (%s)\n", buf->typeStringPtr, buf->typeStringPtr);
+#endif
c = *(buf->typeStringPtr);
+#ifdef DEBUG
+ printf("CheckTypeTag buf %p expectedType %c c is %c\n", buf, expectedType, c);
+#endif
if (c != expectedType)
{
if (expectedType == '\0')
@@ -1224,7 +1301,7 @@ static int OSC_writeBlobArg(OSCbuf *buf, typedArg *arg, size_t nArgs)
*((uint32_t *) buf->bufptr) = htonl(nArgs);
#ifdef DEBUG
- post ("OSC_writeBlobArg length : %lu", nArgs);
+ printf("OSC_writeBlobArg length : %lu\n", nArgs);
#endif
buf->bufptr += 4;
@@ -1232,12 +1309,12 @@ static int OSC_writeBlobArg(OSCbuf *buf, typedArg *arg, size_t nArgs)
{
if (arg[i].type != BLOB_osc)
{
- error("packOSC: blob element %u not blob type", i);
+ error("packOSC: blob element %lu not blob type", i);
return 9;
}
b = (unsigned char)((arg[i].datum.i)&0x0FF);/* force int to 8-bit byte */
#ifdef DEBUG
- post ("OSC_writeBlobArg : %d, %d", arg[i].datum.i, b);
+ printf("OSC_writeBlobArg : %d, %d\n", arg[i].datum.i, b);
#endif
buf->bufptr[i] = b;
}
diff --git a/osc/unpackOSC.c b/osc/unpackOSC.c
index 24558d3..5f1b059 100644
--- a/osc/unpackOSC.c
+++ b/osc/unpackOSC.c
@@ -75,23 +75,20 @@ typedef struct _unpackOSC
t_object x_obj;
t_outlet *x_data_out;
t_outlet *x_delay_out;
- t_atom x_data_at[MAX_MESG];/* symbols making up the path + payload */
- int x_data_atc;/* number of symbols to be output */
- char x_raw[MAX_MESG];/* bytes making up the entire OSC message */
- int x_raw_c;/* number of bytes in OSC message */
int x_bundle_flag;/* non-zero if we are processing a bundle */
int x_recursion_level;/* number of times we reenter unpackOSC_list */
int x_abort_bundle;/* non-zero if unpackOSC_list is not well formed */
+ int x_reentry_count;
} t_unpackOSC;
void unpackOSC_setup(void);
static void *unpackOSC_new(void);
static void unpackOSC_free(t_unpackOSC *x);
static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv);
-static int unpackOSC_path(t_unpackOSC *x, char *path);
-static void unpackOSC_Smessage(t_unpackOSC *x, void *v, int n);
-static void unpackOSC_PrintTypeTaggedArgs(t_unpackOSC *x, void *v, int n);
-static void unpackOSC_PrintHeuristicallyTypeGuessedArgs(t_unpackOSC *x, void *v, int n, int skipComma);
+static int unpackOSC_path(t_atom *data_at, char *path);
+static void unpackOSC_Smessage(t_atom *data_at, int *data_atc, void *v, int n);
+static void unpackOSC_PrintTypeTaggedArgs(t_atom *data_at, int *data_atc, void *v, int n);
+static void unpackOSC_PrintHeuristicallyTypeGuessedArgs(t_atom *data_at, int *data_atc, void *v, int n, int skipComma);
static char *unpackOSC_DataAfterAlignedString(char *string, char *boundary);
static int unpackOSC_IsNiceString(char *string, char *boundary);
static t_float unpackOSC_DeltaTime(OSCTimeTag tt);
@@ -102,7 +99,6 @@ static void *unpackOSC_new(void)
x = (t_unpackOSC *)pd_new(unpackOSC_class);
x->x_data_out = outlet_new(&x->x_obj, &s_list);
x->x_delay_out = outlet_new(&x->x_obj, &s_float);
- x->x_raw_c = x->x_data_atc = 0;
x->x_bundle_flag = 0;
x->x_recursion_level = 0;
x->x_abort_bundle = 0;
@@ -127,22 +123,26 @@ static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv)
int size, messageLen, i, j;
char *messageName, *args, *buf;
OSCTimeTag tt;
+ t_atom data_at[MAX_MESG] ={{0}};/* symbols making up the path + payload */
+ int data_atc = 0;/* number of symbols to be output */
+ char raw[MAX_MESG];/* bytes making up the entire OSC message */
+ int raw_c;/* number of bytes in OSC message */
#ifdef DEBUG
- printf("unpackOSC_list: %d bytes, abort=%d\n", argc, x->x_abort_bundle);
+ printf(">>> unpackOSC_list: %d bytes, abort=%d, reentry_count %d recursion_level %d\n",
+ argc, x->x_abort_bundle, x->x_reentry_count, x->x_recursion_level);
#endif
if(x->x_abort_bundle) return; /* if backing quietly out of the recursive stack */
+ x->x_reentry_count++;
if ((argc%4) != 0)
{
post("unpackOSC: Packet size (%d) not a multiple of 4 bytes: dropping packet", argc);
- x->x_recursion_level = 0;
- return;
+ goto unpackOSC_list_out;
}
if(argc > MAX_MESG)
{
post("unpackOSC: Packet size (%d) greater than max (%d). Change MAX_MESG and recompile if you want more.", argc, MAX_MESG);
- x->x_recursion_level = 0;
- return;
+ goto unpackOSC_list_out;
}
/* copy the list to a byte buffer, checking for bytes only */
for (i = 0; i < argc; ++i)
@@ -155,24 +155,22 @@ static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv)
/* , so change to this: */
if ((j == argv[i].a_w.w_float) && (j >= -128) && (j <= 255))
{
- x->x_raw[i] = (char)j;
+ raw[i] = (char)j;
}
else
{
post("unpackOSC: Data out of range (%d), dropping packet", argv[i].a_w.w_float);
- x->x_recursion_level = 0;
- return;
+ goto unpackOSC_list_out;
}
}
else
{
post("unpackOSC: Data not float, dropping packet");
- x->x_recursion_level = 0;
- return;
+ goto unpackOSC_list_out;
}
}
- x->x_raw_c = argc;
- buf = x->x_raw;
+ raw_c = argc;
+ buf = raw;
if ((argc >= 8) && (strncmp(buf, "#bundle", 8) == 0))
{ /* This is a bundle message. */
@@ -183,8 +181,7 @@ static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv)
if (argc < 16)
{
post("unpackOSC: Bundle message too small (%d bytes) for time tag", argc);
- x->x_recursion_level = 0;
- return;
+ goto unpackOSC_list_out;
}
x->x_bundle_flag = 1;
@@ -210,15 +207,13 @@ static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv)
if ((size % 4) != 0)
{
post("unpackOSC: Bad size count %d in bundle (not a multiple of 4)", size);
- x->x_recursion_level = 0;
- return;
+ goto unpackOSC_list_out;
}
if ((size + i + 4) > argc)
{
post("unpackOSC: Bad size count %d in bundle (only %d bytes left in entire bundle)",
size, argc-i-4);
- x->x_recursion_level = 0;
- return;
+ goto unpackOSC_list_out;
}
/* Recursively handle element of bundle */
@@ -229,9 +224,8 @@ static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv)
if (x->x_recursion_level > MAX_BUNDLE_NESTING)
{
post("unpackOSC: bundle depth %d exceeded", MAX_BUNDLE_NESTING);
- x->x_recursion_level = 0;
x->x_abort_bundle = 1;/* we need to back out of the recursive stack*/
- return;
+ goto unpackOSC_list_out;
}
#ifdef DEBUG
printf("unpackOSC: bundle calling unpackOSC_list(x=%p, s=%s, size=%d, argv[%d]=%p)\n",
@@ -255,45 +249,44 @@ static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv)
else if ((argc == 24) && (strcmp(buf, "#time") == 0))
{
post("unpackOSC: Time message: %s\n :).\n", buf);
- x->x_recursion_level = 0;
- return;
+ goto unpackOSC_list_out;
}
else
{ /* This is not a bundle message or a time message */
messageName = buf;
#ifdef DEBUG
- printf("unpackOSC: message name string: %s length %d\n", messageName, x->x_raw_c);
+ printf("unpackOSC: message name string: %s length %d\n", messageName, raw_c);
#endif
- args = unpackOSC_DataAfterAlignedString(messageName, buf+x->x_raw_c);
+ args = unpackOSC_DataAfterAlignedString(messageName, buf+raw_c);
if (args == 0)
{
post("unpackOSC: Bad message name string: Dropping entire message.");
- x->x_recursion_level = 0;
- return;
+ goto unpackOSC_list_out;
}
messageLen = args-messageName;
/* put the OSC path into a single symbol */
- x->x_data_atc = unpackOSC_path(x, messageName); /* returns 1 if path OK, else 0 */
- if (x->x_data_atc == 1)
+ data_atc = unpackOSC_path(data_at, messageName); /* returns 1 if path OK, else 0 */
+ if (data_atc == 1)
{
#ifdef DEBUG
- printf("unpackOSC_list calling unpackOSC_Smessage: message length %d\n", x->x_raw_c-messageLen);
+ printf("unpackOSC_list calling unpackOSC_Smessage: message length %d\n", raw_c-messageLen);
#endif
- unpackOSC_Smessage(x, (void *)args, x->x_raw_c-messageLen);
+ unpackOSC_Smessage(data_at, &data_atc, (void *)args, raw_c-messageLen);
if (0 == x->x_bundle_flag)
outlet_float(x->x_delay_out, 0); /* no delay for message not in a bundle */
}
}
- /*if (x->x_data_atc >= 1) outlet_list(x->x_data_out, &s_list, x->x_data_atc, x->x_data_at);*/
- if (x->x_data_atc >= 1)
- outlet_anything(x->x_data_out, atom_getsymbol(x->x_data_at), x->x_data_atc-1, x->x_data_at+1);
- x->x_data_atc = 0;
- x->x_recursion_level = 0;
+ if (data_atc >= 1)
+ outlet_anything(x->x_data_out, atom_getsymbol(data_at), data_atc-1, data_at+1);
+ data_atc = 0;
x->x_abort_bundle = 0;
+unpackOSC_list_out:
+ x->x_recursion_level = 0;
+ x->x_reentry_count--;
}
-static int unpackOSC_path(t_unpackOSC *x, char *path)
+static int unpackOSC_path(t_atom *data_at, char *path)
{
int i;
@@ -308,7 +301,7 @@ static int unpackOSC_path(t_unpackOSC *x, char *path)
{
if (path[i] == '\0')
{ /* the end of the path: turn path into a symbol */
- SETSYMBOL(&x->x_data_at[0],gensym(path));
+ SETSYMBOL(data_at, gensym(path));
return 1;
}
}
@@ -317,7 +310,7 @@ static int unpackOSC_path(t_unpackOSC *x, char *path)
}
#define SMALLEST_POSITIVE_FLOAT 0.000001f
-static void unpackOSC_Smessage(t_unpackOSC *x, void *v, int n)
+static void unpackOSC_Smessage(t_atom *data_at, int *data_atc, void *v, int n)
{
char *chars = v;
@@ -331,7 +324,7 @@ static void unpackOSC_Smessage(t_unpackOSC *x, void *v, int n)
printf("unpackOSC_Smessage calling unpackOSC_PrintTypeTaggedArgs: message length %d\n", n);
#endif
/* This message begins with a type-tag string */
- unpackOSC_PrintTypeTaggedArgs(x, v, n);
+ unpackOSC_PrintTypeTaggedArgs(data_at, data_atc, v, n);
}
else
{
@@ -339,7 +332,7 @@ static void unpackOSC_Smessage(t_unpackOSC *x, void *v, int n)
printf("unpackOSC_Smessage calling unpackOSC_PrintHeuristicallyTypeGuessedArgs: message length %d, skipComma 1\n", n);
#endif
/* Double comma means an escaped real comma, not a type string */
- unpackOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 1);
+ unpackOSC_PrintHeuristicallyTypeGuessedArgs(data_at, data_atc, v, n, 1);
}
}
else
@@ -347,16 +340,16 @@ static void unpackOSC_Smessage(t_unpackOSC *x, void *v, int n)
#ifdef DEBUG
printf("unpackOSC_Smessage calling unpackOSC_PrintHeuristicallyTypeGuessedArgs: message length %d, skipComma 0\n", n);
#endif
- unpackOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 0);
+ unpackOSC_PrintHeuristicallyTypeGuessedArgs(data_at, data_atc, v, n, 0);
}
}
}
-static void unpackOSC_PrintTypeTaggedArgs(t_unpackOSC *x, void *v, int n)
+static void unpackOSC_PrintTypeTaggedArgs(t_atom *data_at, int *data_atc, void *v, int n)
{
char *typeTags, *thisType, *p;
- int myargc = x->x_data_atc;
- t_atom *mya = x->x_data_at;
+ int myargc = *data_atc;
+ t_atom *mya = data_at;
typeTags = v;
@@ -367,7 +360,7 @@ static void unpackOSC_PrintTypeTaggedArgs(t_unpackOSC *x, void *v, int n)
#endif
/* No null-termination, so maybe it wasn't a type tag
string after all */
- unpackOSC_PrintHeuristicallyTypeGuessedArgs(x, v, n, 0);
+ unpackOSC_PrintHeuristicallyTypeGuessedArgs(data_at, data_atc, v, n, 0);
return;
}
@@ -376,7 +369,7 @@ static void unpackOSC_PrintTypeTaggedArgs(t_unpackOSC *x, void *v, int n)
#endif
p = unpackOSC_DataAfterAlignedString(typeTags, typeTags+n);
#ifdef DEBUG
- printf("unpackOSC_PrintTypeTaggedArgs p is %p\n", p);
+ printf("unpackOSC_PrintTypeTaggedArgs p is %p: ", p);
#endif
if (p == NULL) return; /* malformed message */
for (thisType = typeTags + 1; *thisType != 0; ++thisType)
@@ -387,7 +380,7 @@ static void unpackOSC_PrintTypeTaggedArgs(t_unpackOSC *x, void *v, int n)
{
int i, blob_bytes = ntohl(*((int *) p));
#ifdef DEBUG
- post("blob: %lu bytes", blob_bytes);
+ printf("blob: %u bytes\n", blob_bytes);
#endif
p += 4;
for (i = 0; i < blob_bytes; ++i, ++p, ++myargc)
@@ -401,7 +394,7 @@ static void unpackOSC_PrintTypeTaggedArgs(t_unpackOSC *x, void *v, int n)
}
case 'i': case 'r': case 'm': case 'c':
#ifdef DEBUG
- post("integer: %d", ntohl(*((int *) p)));
+ printf("integer: %d\n", ntohl(*((int *) p)));
#endif
SETFLOAT(mya+myargc,(signed)ntohl(*((int *) p)));
myargc++;
@@ -412,7 +405,7 @@ static void unpackOSC_PrintTypeTaggedArgs(t_unpackOSC *x, void *v, int n)
intfloat32 thisif;
thisif.i = ntohl(*((int *) p));
#ifdef DEBUG
- post("float: %f", thisif.f);
+ printf("float: %f\n", thisif.f);
#endif
SETFLOAT(mya+myargc, thisif.f);
myargc++;
@@ -421,14 +414,14 @@ static void unpackOSC_PrintTypeTaggedArgs(t_unpackOSC *x, void *v, int n)
}
case 'h': case 't':
#ifdef DEBUG
- printf("[A 64-bit int] ");
+ printf("[A 64-bit int]\n");
#endif
post("unpackOSC: PrintTypeTaggedArgs: [A 64-bit int] not implemented");
p += 8;
break;
case 'd':
#ifdef DEBUG
- printf("[A 64-bit float] ");
+ printf("[A 64-bit float]\n");
#endif
post("unpackOSC: PrintTypeTaggedArgs: [A 64-bit float] not implemented");
p += 8;
@@ -442,7 +435,7 @@ static void unpackOSC_PrintTypeTaggedArgs(t_unpackOSC *x, void *v, int n)
else
{
#ifdef DEBUG
- post("string: \"%s\"", p);
+ printf("string: \"%s\"\n", p);
#endif
SETSYMBOL(mya+myargc,gensym(p));
myargc++;
@@ -452,28 +445,28 @@ static void unpackOSC_PrintTypeTaggedArgs(t_unpackOSC *x, void *v, int n)
break;
case 'T':
#ifdef DEBUG
- printf("[True] ");
+ printf("[True]\n");
#endif
SETFLOAT(mya+myargc,1.);
myargc++;
break;
case 'F':
#ifdef DEBUG
- printf("[False] ");
+ printf("[False]\n");
#endif
SETFLOAT(mya+myargc,0.);
myargc++;
break;
case 'N':
#ifdef DEBUG
- printf("[Nil]");
+ printf("[Nil]\n");
#endif
SETFLOAT(mya+myargc,0.);
myargc++;
break;
case 'I':
#ifdef DEBUG
- printf("[Infinitum]");
+ printf("[Infinitum]\n");
#endif
SETSYMBOL(mya+myargc,gensym("INF"));
myargc++;
@@ -486,17 +479,17 @@ static void unpackOSC_PrintTypeTaggedArgs(t_unpackOSC *x, void *v, int n)
return;
}
}
- x->x_data_atc = myargc;
+ *data_atc = myargc;
}
-static void unpackOSC_PrintHeuristicallyTypeGuessedArgs(t_unpackOSC *x, void *v, int n, int skipComma)
+static void unpackOSC_PrintHeuristicallyTypeGuessedArgs(t_atom *data_at, int *data_atc, void *v, int n, int skipComma)
{
int i;
int *ints;
intfloat32 thisif;
char *chars, *string, *nextString;
- int myargc= x->x_data_atc;
- t_atom* mya = x->x_data_at;
+ int myargc = *data_atc;
+ t_atom* mya = data_at;
/* Go through the arguments 32 bits at a time */
ints = v;
@@ -543,7 +536,7 @@ static void unpackOSC_PrintHeuristicallyTypeGuessedArgs(t_unpackOSC *x, void *v,
post("unpackOSC: PrintHeuristicallyTypeGuessedArgs: indeterminate type: 0x%x xx", ints[i]);
i++;
}
- x->x_data_atc = myargc;
+ *data_atc = myargc;
}
}
@@ -564,7 +557,7 @@ static char *unpackOSC_DataAfterAlignedString(char *string, char *boundary)
int i;
#ifdef DEBUG
- printf("unpackOSC_DataAfterAlignedString boundary - string = %d\n", boundary-string);
+ printf("unpackOSC_DataAfterAlignedString boundary - string = %ld\n", boundary-string);
#endif
if ((boundary - string) %4 != 0)
{
@@ -613,8 +606,10 @@ static char *unpackOSC_DataAfterAlignedString(char *string, char *boundary)
static int unpackOSC_IsNiceString(char *string, char *boundary)
{
/* Arguments same as DataAfterAlignedString(). Is the given "string"
- really a string? I.e., is it a sequence of isprint() characters
- terminated with 1-4 null characters to align on a 4-byte boundary?
+ really an OSC-string? I.e., is it
+ "A sequence of non-null ASCII characters followed by a null, followed
+ by 0-3 additional null characters to make the total number of bits a
+ multiple of 32"? (OSC 1.0)
Returns 1 if true, else 0. */
int i;
@@ -625,12 +620,13 @@ static int unpackOSC_IsNiceString(char *string, char *boundary)
return 0;
}
- /* anything less than space (0x20) is no good, UTF-8 sequences will be accepted -- not strictly OSC v1.0 */
+ /* any non-zero byte will be accepted, so UTF-8 sequences will also be accepted -- not strictly OSC v1.0 */
for (i = 0; string[i] != '\0'; i++)
/* if ((!isprint(string[i])) || (string + i >= boundary)) return 0; */ /* only ASCII printable chars */
- if ((0==(string[i]&0xE0)) || (string + i >= boundary)) return 0;
- /* If we made it this far, it's a null-terminated sequence of printing characters
- in the given boundary. Now we just make sure it's null padded... */
+ /*if ((0==(string[i]&0xE0)) || (string + i >= boundary)) return 0;*/ /* onl;y ASCII space (0x20) and above */
+ if (string + i >= boundary) return 0; /* anything non-zero */
+ /* If we made it this far, it's a null-terminated sequence of characters
+ within the given boundary. Now we just make sure it's null padded... */
/* Now string[i] is the first null character */
i++;
--
pd-mrpeach packaging
More information about the pkg-multimedia-commits
mailing list