Hi J.
You need to init your obstack before using it
Also, you need to declare this before calling obstack_init()
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
So, your code would look like this:
============================================================================
#include <stdio.h>
#include <string.h>
#include <obstack.h>
#include <malloc.h>
#define obstack_chunk_alloc malloc <--- defines needed
#define obstack_chunk_free free <---
struct obstack string_obstack;
char *copystring(char *string);
int main(void) {
char *orig = "to copy this string";
char *str = NULL;
str = copystring(orig);
printf("%s\n", str);
return 0;
}
char *copystring(char *string) {
size_t len = 0;
char *s = NULL;
len = strlen(string) + 1;
obstack_init(&string_obstack); <--- obstack initialization
s = (char *) obstack_alloc(&string_obstack, len);
memcpy(s, string, len);
return s;
}
============================================================================
Hope this helps J. !!
-----Mensaje original-----
De: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] nombre de J.
Enviado el: Miercoles, 23 de Febrero de 2005 09:46 a.m.
Para: [email protected]
Asunto: obstack_alloc & _obstack_newchunk
Wednesday, February 23
Hello, I am looking into the GNU's obstack lib .
Unfortunatly it segfaults. According to a backtrace of the program stack
it goes down at obstack_newchunk_ . To be honest I am kind a stuck here.
There is enough free memory available since I am able to write this
message... The only thing I can come up with is that obstack_alloc trys
to add new memory to the address of string_obstack, which isn't properly
setup by moi.. ?
#include <stdio.h>
#include <string.h>
#include <obstack.h>
struct obstack string_obstack;
char *copystring(char *string);
int main(void) {
char *orig = "to copy this string";
char *str = NULL;
str = copystring(orig);
printf("%s\n", str);
return 0;
}
char *copystring(char *string) {
size_t len = 0;
char *s = NULL;
len = strlen(string) + 1;
s = obstack_alloc(&string_obstack, len);
memcpy(s, string, len);
return s;
}
Thnkx..
J.
--
http://www.rdrs.net/
-
To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html
_______________________________________
Importante
El contenido del presente mensaje y el de sus adjuntos, es privado,
confidencial y de uso exclusivo de los destinatarios a los cuales est�
dirig�do, pudiendo contener informaci�n legalmente protegida.Queda prohibida la
revisi�n, divulgaci�n, publicaci�n, modificaci�n, copia, distribuci�n o acci�n
en relaci�n con esta informaci�n, por personas o entidades distintas al
destinatario.
Las opiniones contenidas son exclusivas de su autor y no representan ni
necesariamente pueden coincidir con las de la entidad.
La transmisi�n de e-mails no garantiza que el correo electr�nico sea seguro o
libre de error. En consecuencia, no manifestamos que la informaci�n sea
completa o precisa. Toda informaci�n est� sujeta a alterarse sin previo aviso.
Si Ud. recibi� este mensaje por error, por favor reenv�elo al remitente y
destruya las copias de papel o grabadas en cualquier medio magn�tico, que pueda
haber realizado.
Muchas Gracias.