Commit 25379407 authored by thomas's avatar thomas
Browse files

no message


git-svn-id: https://svn.grrrr.org/ext/trunk@192 4d9ac71a-51e6-0310-8455-cad1006bcd31
parent 89694a65
......@@ -11,7 +11,7 @@ WARRANTIES, see the file, "license.txt," in this distribution.
// This is all derived from GEM by Mark Danks
#include "flbase.h"
#include <string.h>
#include "flinternal.h"
/////////////////////////////////////////////////////////
//
......@@ -29,7 +29,7 @@ const char *flext_obj::m_holdname;
/////////////////////////////////////////////////////////
flext_obj :: flext_obj()
: x_obj(m_holder)
, m_name(m_holdname)
, m_name(fl_strdup(m_holdname))
, init_ok(true)
{
#ifdef PD
......@@ -45,7 +45,9 @@ flext_obj :: flext_obj()
//
/////////////////////////////////////////////////////////
flext_obj :: ~flext_obj()
{ }
{
if(m_name) delete[] const_cast<char *>(m_name);
}
......@@ -94,30 +96,3 @@ void flext_obj::FreeAligned(void *blk)
/////////////////////////////////////////////////////////
// check if tilde object's name ends with a tilde
//
/////////////////////////////////////////////////////////
#ifdef _DEBUG
bool flext_obj::check_tilde(const char *objname)
{
// int stplen = strlen(setupfun);
bool tilde = true; //!strncmp(setupfun,"_tilde",6);
if((objname[strlen(objname)-1] == '~'?1:0)^(tilde?1:0)) {
if(tilde)
error("flext_obj::check_tilde: %s (no trailing ~) is defined as a tilde object",objname);
else
error("flext_obj::check_tilde: %s is no tilde object",objname);
return true;
}
else
return false;
}
#endif
......@@ -152,11 +152,6 @@ class FLEXT_EXT flext_obj
//! The object's name in the patcher
const char *m_name;
#ifdef _DEBUG
//! check whether the object's name has a trailing tilde
static bool check_tilde(const char *objname);
#endif
// !check whether construction was successful
bool InitOk() const { return init_ok; }
......@@ -180,6 +175,10 @@ class FLEXT_EXT flext_obj
//! This has a dummy arg so that NT won't complain
inline void *operator new(size_t, void *location, void *) { return location; }
const char *fl_extract(const char *name,int ix = 0);
const char *fl_strdup(const char *name);
bool fl_chktilde(const char *name);
// ----------------------------------------
// This should be used in the header
// ----------------------------------------
......@@ -346,7 +345,7 @@ return 0; \
//#define EXTPROTO(LIB) EXTPROTO_ ## LIB
#ifdef _DEBUG
#define CHECK_TILDE(OBJNAME,DSP) if(DSP) flext_obj::check_tilde(OBJNAME)
#define CHECK_TILDE(OBJNAME,DSP) if(DSP) fl_chktilde(OBJNAME)
#else
#define CHECK_TILDE(OBJNAME,DSP) ((void)0)
#endif
......@@ -377,8 +376,6 @@ return 0; \
#define FLEXT_DEFHELP(THIS,NEW_CLASS,DSP)
#endif
const char *extractname(const char *name,int ix = 0);
// ----------------------------------------------------
// These should never be called or used directly!!!
//
......@@ -394,7 +391,7 @@ flext_hdr* class_ ## NEW_CLASS () \
{ \
flext_hdr *obj = new (newobject(NEW_CLASS ## _class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
flext_obj::m_holdname = fl_extract(NAME); \
obj->data = new NEW_CLASS; \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
......@@ -405,13 +402,13 @@ FLEXT_EXP(LIB) void FLEXT_STPF(NEW_CLASS,DSP)() \
{ \
CHECK_TILDE(NAME,DSP); \
NEW_CLASS ## _class = FLEXT_NEWFN( \
FLEXT_CLREF(extractname(NAME),NEW_CLASS ## _class), \
FLEXT_CLREF(fl_extract(NAME),NEW_CLASS ## _class), \
(t_newmethod)class_ ## NEW_CLASS, \
(t_method)&NEW_CLASS::callb_free, \
sizeof(flext_hdr), CLNEW_OPTIONS, \
A_NULL); \
for(int ix = 1; ; ++ix) { \
const char *c = extractname(NAME,ix); if(!c) break; \
const char *c = fl_extract(NAME,ix); if(!c) break; \
FLEXT_ADDALIAS(c,(t_newmethod)class_ ## NEW_CLASS); \
} \
NEW_CLASS::callb_setup(NEW_CLASS ## _class); \
......@@ -422,7 +419,7 @@ flext_hdr* class_ ## NEW_CLASS () \
{ \
flext_hdr *obj = new (newobject(flext_obj::lib_class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
flext_obj::m_holdname = fl_extract(NAME); \
obj->data = new NEW_CLASS; \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
......@@ -446,7 +443,7 @@ flext_hdr* class_ ## NEW_CLASS (t_symbol *,int argc,t_atom *argv) \
{ \
flext_hdr *obj = new (newobject(NEW_CLASS ## _class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
flext_obj::m_holdname = fl_extract(NAME); \
obj->data = new NEW_CLASS(argc,argv); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
......@@ -457,14 +454,14 @@ FLEXT_EXP(LIB) void FLEXT_STPF(NEW_CLASS,DSP)() \
{ \
CHECK_TILDE(NAME,DSP); \
NEW_CLASS ## _class = FLEXT_NEWFN( \
FLEXT_CLREF(extractname(NAME),NEW_CLASS ## _class), \
FLEXT_CLREF(fl_extract(NAME),NEW_CLASS ## _class), \
(t_newmethod)class_ ## NEW_CLASS, \
(t_method)&NEW_CLASS::callb_free, \
sizeof(flext_hdr), CLNEW_OPTIONS, \
A_GIMME, \
A_NULL); \
for(int ix = 1; ; ++ix) { \
const char *c = extractname(NAME,ix); if(!c) break; \
const char *c = fl_extract(NAME,ix); if(!c) break; \
FLEXT_ADDALIAS1(c,(t_newmethod)class_ ## NEW_CLASS,A_GIMME); \
} \
NEW_CLASS::callb_setup(NEW_CLASS ## _class); \
......@@ -475,7 +472,7 @@ flext_hdr* class_ ## NEW_CLASS (t_symbol *,int argc,t_atom *argv) \
{ \
flext_hdr *obj = new (newobject(flext_obj::lib_class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
flext_obj::m_holdname = fl_extract(NAME); \
obj->data = new NEW_CLASS(argc,argv); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
......@@ -499,7 +496,7 @@ flext_hdr* class_ ## NEW_CLASS (CALLBTP(TYPE1) arg1) \
{ \
flext_hdr *obj = new (newobject(NEW_CLASS ## _class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
flext_obj::m_holdname = fl_extract(NAME); \
obj->data = new NEW_CLASS((TYPE1)arg1); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
......@@ -510,14 +507,14 @@ FLEXT_EXP(LIB) void FLEXT_STPF(NEW_CLASS,DSP)() \
{ \
CHECK_TILDE(NAME,DSP); \
NEW_CLASS ## _class = FLEXT_NEWFN( \
FLEXT_CLREF(extractname(NAME),NEW_CLASS ## _class), \
FLEXT_CLREF(fl_extract(NAME),NEW_CLASS ## _class), \
(t_newmethod)class_ ## NEW_CLASS, \
(t_method)&NEW_CLASS::callb_free, \
sizeof(flext_hdr), CLNEW_OPTIONS, \
FLEXTTP(TYPE1), \
A_NULL); \
for(int ix = 1; ; ++ix) { \
const char *c = extractname(NAME,ix); if(!c) break; \
const char *c = fl_extract(NAME,ix); if(!c) break; \
FLEXT_ADDALIAS1(c,(t_newmethod)class_ ## NEW_CLASS,FLEXTTP(TYPE1)); \
} \
NEW_CLASS::callb_setup(NEW_CLASS ## _class); \
......@@ -528,7 +525,7 @@ flext_hdr* class_ ## NEW_CLASS (const flext_obj::lib_arg &arg1) \
{ \
flext_hdr *obj = new (newobject(flext_obj::lib_class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
flext_obj::m_holdname = fl_extract(NAME); \
obj->data = new NEW_CLASS(ARGCAST(arg1,TYPE1)); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
......@@ -552,7 +549,7 @@ flext_hdr* class_ ## NEW_CLASS (CALLBTP(TYPE1) arg1, CALLBTP(TYPE2) arg2) \
{ \
flext_hdr *obj = new (newobject(NEW_CLASS ## _class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
flext_obj::m_holdname = fl_extract(NAME); \
obj->data = new NEW_CLASS((TYPE1)arg1, (TYPE2)arg2); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
......@@ -563,14 +560,14 @@ FLEXT_EXP(LIB) void FLEXT_STPF(NEW_CLASS,DSP)() \
{ \
CHECK_TILDE(NAME,DSP); \
NEW_CLASS ## _class = FLEXT_NEWFN( \
FLEXT_CLREF(extractname(NAME),NEW_CLASS ## _class), \
FLEXT_CLREF(fl_extract(NAME),NEW_CLASS ## _class), \
(t_newmethod)class_ ## NEW_CLASS, \
(t_method)&NEW_CLASS::callb_free, \
sizeof(flext_hdr), CLNEW_OPTIONS, \
FLEXTTP(TYPE1), FLEXTTP(TYPE2), \
A_NULL); \
for(int ix = 1; ; ++ix) { \
const char *c = extractname(NAME,ix); if(!c) break; \
const char *c = fl_extract(NAME,ix); if(!c) break; \
FLEXT_ADDALIAS2(c,(t_newmethod)class_ ## NEW_CLASS,FLEXTTP(TYPE1),FLEXTTP(TYPE2)); \
} \
NEW_CLASS::callb_setup(NEW_CLASS ## _class); \
......@@ -581,7 +578,7 @@ flext_hdr* class_ ## NEW_CLASS (const flext_obj::lib_arg &arg1,const flext_obj::
{ \
flext_hdr *obj = new (newobject(flext_obj::lib_class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
flext_obj::m_holdname = fl_extract(NAME); \
obj->data = new NEW_CLASS(ARGCAST(arg1,TYPE1),ARGCAST(arg2,TYPE2)); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
......@@ -605,7 +602,7 @@ flext_hdr* class_ ## NEW_CLASS (CALLBTP(TYPE1) arg1,CALLBTP(TYPE2) arg2,CALLBTP(
{ \
flext_hdr *obj = new (newobject(NEW_CLASS ## _class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
flext_obj::m_holdname = fl_extract(NAME); \
obj->data = new NEW_CLASS((TYPE1)arg1,(TYPE2)arg2,(TYPE3)arg3); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
......@@ -616,14 +613,14 @@ FLEXT_EXP(LIB) void FLEXT_STPF(NEW_CLASS,DSP)() \
{ \
CHECK_TILDE(NAME,DSP); \
NEW_CLASS ## _class = FLEXT_NEWFN( \
FLEXT_CLREF(extractname(NAME),NEW_CLASS ## _class), \
FLEXT_CLREF(fl_extract(NAME),NEW_CLASS ## _class), \
(t_newmethod)class_ ## NEW_CLASS, \
(t_method)&NEW_CLASS::callb_free, \
sizeof(flext_hdr), CLNEW_OPTIONS, \
FLEXTTP(TYPE1), FLEXTTP(TYPE2),FLEXTTP(TYPE3), \
A_NULL); \
for(int ix = 1; ; ++ix) { \
const char *c = extractname(NAME,ix); if(!c) break; \
const char *c = fl_extract(NAME,ix); if(!c) break; \
FLEXT_ADDALIAS3(c,(t_newmethod)class_ ## NEW_CLASS,FLEXTTP(TYPE1),FLEXTTP(TYPE2),FLEXTTP(TYPE3)); \
} \
NEW_CLASS::callb_setup(NEW_CLASS ## _class); \
......@@ -634,7 +631,7 @@ flext_hdr* class_ ## NEW_CLASS (const flext_obj::lib_arg &arg1,const flext_obj::
{ \
flext_hdr *obj = new (newobject(flext_obj::lib_class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
flext_obj::m_holdname = fl_extract(NAME); \
obj->data = new NEW_CLASS(ARGCAST(arg1,TYPE1),ARGCAST(arg2,TYPE2),ARGCAST(arg3,TYPE3)); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
......@@ -657,7 +654,7 @@ flext_hdr* class_ ## NEW_CLASS (CALLBTP(TYPE1) arg1,CALLBTP(TYPE2) arg2,CALLBTP(
{ \
flext_hdr *obj = new (newobject(NEW_CLASS ## _class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
flext_obj::m_holdname = fl_extract(NAME); \
obj->data = new NEW_CLASS((TYPE1)arg1,(TYPE2)arg2,(TYPE3)arg3,(TYPE4)arg4); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
......@@ -668,14 +665,14 @@ FLEXT_EXP(LIB) void FLEXT_STPF(NEW_CLASS,DSP)() \
{ \
CHECK_TILDE(NAME,DSP); \
NEW_CLASS ## _class = FLEXT_NEWFN( \
FLEXT_CLREF(extractname(NAME),NEW_CLASS ## _class), \
FLEXT_CLREF(fl_extract(NAME),NEW_CLASS ## _class), \
(t_newmethod)class_ ## NEW_CLASS, \
(t_method)&NEW_CLASS::callb_free, \
sizeof(flext_hdr), CLNEW_OPTIONS, \
FLEXTTP(TYPE1), FLEXTTP(TYPE2),FLEXTTP(TYPE3),FLEXTTP(TYPE4), \
A_NULL); \
for(int ix = 1; ; ++ix) { \
const char *c = extractname(NAME,ix); if(!c) break; \
const char *c = fl_extract(NAME,ix); if(!c) break; \
FLEXT_ADDALIAS4(c,(t_newmethod)class_ ## NEW_CLASS,FLEXTTP(TYPE1),FLEXTTP(TYPE2),FLEXTTP(TYPE3),FLEXTTP(TYPE4)); \
} \
NEW_CLASS::callb_setup(NEW_CLASS ## _class); \
......@@ -686,7 +683,7 @@ flext_hdr* class_ ## NEW_CLASS (const flext_obj::lib_arg &arg1,const flext_obj::
{ \
flext_hdr *obj = new (newobject(flext_obj::lib_class),(void *)NULL) flext_hdr; \
flext_obj::m_holder = obj; \
flext_obj::m_holdname = extractname(NAME); \
flext_obj::m_holdname = fl_extract(NAME); \
obj->data = new NEW_CLASS(ARGCAST(arg1,TYPE1),ARGCAST(arg2,TYPE2),ARGCAST(arg3,TYPE3),ARGCAST(arg4,TYPE4)); \
flext_obj::m_holder = NULL; \
if(!obj->data->InitOk()) { NEW_CLASS::callb_free(obj); obj = NULL; } \
......
......@@ -16,8 +16,18 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include <flext.h>
#include <ctype.h>
#include <string.h>
const char *extractname(const char *name,int ix)
const char *fl_strdup(const char *t)
{
if(!t) return NULL;
int len = strlen(t);
char *r = new char[len+1];
memcpy(r,t,len+1);
return r;
}
const char *fl_extract(const char *name,int ix)
{
static char tmp[1024];
const char *n = name;
......@@ -26,7 +36,7 @@ const char *extractname(const char *name,int ix)
char *t;
for(t = tmp; *n && !isspace(*n); ++t,++n) *t = *n;
*t = 0;
return *tmp?tmp:NULL;
return *tmp?strdup(tmp):NULL;
}
else {
while(*n && !isspace(*n)) ++n;
......@@ -37,3 +47,31 @@ const char *extractname(const char *name,int ix)
return NULL;
}
/////////////////////////////////////////////////////////
// check if tilde object's name ends with a tilde
//
/////////////////////////////////////////////////////////
#ifdef _DEBUG
bool fl_chktilde(const char *objname)
{
// int stplen = strlen(setupfun);
bool tilde = true; //!strncmp(setupfun,"_tilde",6);
if((objname[strlen(objname)-1] == '~'?1:0)^(tilde?1:0)) {
if(tilde)
error("flext_obj::check_tilde: %s (no trailing ~) is defined as a tilde object",objname);
else
error("flext_obj::check_tilde: %s is no tilde object",objname);
return true;
}
else
return false;
}
#endif
......@@ -118,8 +118,6 @@ typedef struct clock t_clock;
#define LOG5(s,v1,v2,v3,v4,v5) post(s,v1,v2,v3,v4,v5)
#define ASSERT(b) ((void)(!(b)?(error("Assertion failed: " #b " - in " __FILE__ " line %i",(int)__LINE__),0):0))
#else
/*! If _LOG is not defined avoid logging */
......@@ -129,10 +127,15 @@ typedef struct clock t_clock;
#define LOG3(s,v1,v2,v3) ((void)0)
#define LOG4(s,v1,v2,v3,v4) ((void)0)
#define LOG5(s,v1,v2,v3,v4,v5) ((void)0)
#define ASSERT(b) ((void)0)
#endif
#ifdef _DEBUG
#define ASSERT(b) ((void)(!(b)?(error("Assertion failed: " #b " - in " __FILE__ " line %i",(int)__LINE__),0):0))
#else
#define ASSERT(b) ((void)0)
#endif
#define ERRINTERNAL() error("flext: Internal error in file " __FILE__ ", line %i - please report",(int)__LINE__)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment